From 4f8e69c38aadc406771db7bccefbd1d97b54f56a Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Fri, 13 Oct 2023 13:56:25 -0500 Subject: [PATCH] Add very basic SVG package It is incomplete, but our website will type check --- deps.ts | 2 +- jsx-runtime.ts | 9 ++- svg.ts | 161 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 svg.ts diff --git a/deps.ts b/deps.ts index e4e43d9..b5b9590 100644 --- a/deps.ts +++ b/deps.ts @@ -1 +1 @@ -export type * from "https://esm.sh/v127/@types/hast@2.3.4/index.d.ts"; +export type * from "npm:@types/hast@2.3.4"; diff --git a/jsx-runtime.ts b/jsx-runtime.ts index cf04fbe..39cbf91 100644 --- a/jsx-runtime.ts +++ b/jsx-runtime.ts @@ -1,5 +1,6 @@ import type * as hast from "./deps.ts"; import type * as html from "./html.ts"; +import type * as svg from "./svg.ts"; export type Element = hast.Element; @@ -26,10 +27,12 @@ export interface JSXElementConstructor { declare global { namespace JSX { type Element = JSXElement; - type ElementType = keyof html.HTMLElements | JSXElementConstructor; + type ElementType = + | keyof html.HTMLElements + | keyof svg.SVGElements + | JSXElementConstructor; - //deno-lint-ignore no-empty-interface - interface IntrinsicElements extends html.HTMLElements {} + interface IntrinsicElements extends html.HTMLElements, svg.SVGElements {} interface ElementChildrenAttribute { //deno-lint-ignore ban-types children: {}; diff --git a/svg.ts b/svg.ts new file mode 100644 index 0000000..d2c8bfd --- /dev/null +++ b/svg.ts @@ -0,0 +1,161 @@ +import type * as hast from "./deps.ts"; + +export type SVGChild = + | string + | number + | boolean + | hast.Element + | hast.Root + | hast.Text; + +export type SVGChildren = SVGChild | Iterable; + +export interface SVGElement extends SVGAttributes, SVGPresentationAttributes { + children?: SVGChildren; +} + +export interface SVGAttributes { + // accesskey?: string; + // autocapitalize?: "off" | "none" | "on" | "setences" | "words" | "characters"; + class?: string; + // contenteditable?: "true" | "false" | "plaintext-only"; + // dir?: "ltr" | "rtl" | "auto"; + // draggable?: "true" | "false"; + // enterkeyhint?: + // | "enter" + // | "done" + // | "go" + // | "next" + // | "previous" + // | "search" + // | "send"; + // hidden?: "hidden" | "until-found"; + id?: string; + // inert?: boolean; + // inputmode?: + // | "none" + // | "text" + // | "decimal" + // | "numeric" + // | "tel" + // | "search" + // | "email" + // | "url"; + // is?: string; + // itemid?: string; + // itemprop?: string; + // itemref?: string; + // itemscope?: string; + // itemtype?: string; + // lang?: string; + // nonce?: string; + // spellcheck?: "true" | "false" | "default"; + style?: string; + tabindex?: number; + // title?: string; + // translate?: "yes" | "no"; +} + +export interface SVGPresentationAttributes extends SVGAttributes { + "clip-path"?: string; + "lip-rule"?: string; + color?: string; + "color-interpolation"?: string; + "color-rendering"?: string; + cursor?: + | "auto" + | "crosshair" + | "default" + | "pointer" + | "move" + | "e-resize" + | "ne-resize" + | "nw-resize" + | "n-resize" + | "se-resize" + | "sw-resize" + | "s-resize" + | "w-resize" + | "text" + | "wait" + | "help" + | "inherit" + | string; + display?: string; + fill?: string; + "fill-rule"?: string; + filter?: string; + mask?: string; + opacity?: string; + "pointer-events"?: + | "bounding-box" + | "visiblePainted" + | "visibleFill" + | "visibleStroke" + | "visible" + | "painted" + | "fill" + | "stroke" + | "all" + | "none"; + "shape-rendering"?: + | "auto" + | "optimizeSpeed" + | "crispEdges" + | "geometricPrecision"; + stroke?: string; + "stroke-dasharray"?: string; + "stroke-dashoffset"?: string; + "stroke-linecap"?: "butt" | "round" | "square"; + "stroke-linejoin"?: "arcs" | "bevel" | "miter" | "miter-clip" | "round"; + "stroke-miterlimit"?: string | number; + "stroke-opacity"?: string | number; + "stroke-width"?: string | number; + transform?: string; + "vector-effect"?: + | "none" + | "non-scaling-stroke" + | "non-scaling-size" + | "non-rotation" + | "fixed-position"; + visibility?: "visible" | "hidden" | "collapse"; +} + +export interface SVGSVG extends SVGElement { + xmlns?: "http://www.w3.org/2000/svg"; + height?: string; + preserveAspectRation?: string; + viewBox?: string; + width?: string; + x?: string; + y?: string; +} + +export interface SVGAnimate extends SVGElement { + begin?: string; +} + +export interface SVGPath extends SVGElement { + d: string; + pathLength?: number; +} + +export interface SVGRect extends SVGElement { + height?: string | number; + width?: string | number; + x?: string | number; + y?: string | number; + rx?: string | number; + ry?: string | number; + pathLength?: string | number; +} + +export interface SVGElements { + svg: SVGSVG; + animate: SVGAnimate; + path: SVGPath; + g: SVGElement; + defs: SVGElement; + clipPath: SVGElement; + rect: SVGRect; +}