@b9g/crank 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/crank.cjs +5 -2
- package/crank.cjs.map +1 -1
- package/crank.d.ts +8 -4
- package/crank.js +5 -3
- package/crank.js.map +1 -1
- package/dom.cjs +18 -13
- package/dom.cjs.map +1 -1
- package/dom.d.ts +1 -1
- package/dom.js +18 -13
- package/dom.js.map +1 -1
- package/html.cjs +10 -2
- package/html.cjs.map +1 -1
- package/html.d.ts +1 -1
- package/html.js +10 -2
- package/html.js.map +1 -1
- package/index.cjs +1 -0
- package/index.cjs.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +1 -1
- package/package.json +7 -9
- package/umd.d.ts +3 -3
- package/umd.js +28 -16
- package/umd.js.map +1 -1
package/dom.cjs
CHANGED
|
@@ -8,16 +8,13 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
|
8
8
|
const impl = {
|
|
9
9
|
parse(text) {
|
|
10
10
|
if (typeof document.createRange === "function") {
|
|
11
|
-
|
|
11
|
+
const fragment = document.createRange().createContextualFragment(text);
|
|
12
|
+
return Array.from(fragment.childNodes);
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
|
-
const fragment = document.createDocumentFragment();
|
|
15
15
|
const childNodes = new DOMParser().parseFromString(text, "text/html").body
|
|
16
16
|
.childNodes;
|
|
17
|
-
|
|
18
|
-
fragment.appendChild(childNodes[i]);
|
|
19
|
-
}
|
|
20
|
-
return fragment;
|
|
17
|
+
return Array.from(childNodes);
|
|
21
18
|
}
|
|
22
19
|
},
|
|
23
20
|
scope(scope, tag) {
|
|
@@ -109,16 +106,24 @@ const impl = {
|
|
|
109
106
|
// falsy properties, so we use attributes in this case.
|
|
110
107
|
!(typeof value === "string" &&
|
|
111
108
|
typeof node[name] === "boolean")) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
// walk up the object's prototype chain to find the owner of the
|
|
110
|
+
// named property
|
|
111
|
+
let obj = node;
|
|
112
|
+
do {
|
|
113
|
+
if (Object.prototype.hasOwnProperty.call(obj, name)) {
|
|
114
|
+
break;
|
|
115
115
|
}
|
|
116
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
117
|
+
// get the descriptor for the named property and check whether it
|
|
118
|
+
// implies that the property is writable
|
|
119
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, name);
|
|
120
|
+
if (descriptor != null &&
|
|
121
|
+
(descriptor.writable === true || descriptor.set !== undefined)) {
|
|
122
|
+
node[name] = value;
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// attributes
|
|
121
|
-
}
|
|
125
|
+
// if the property wasn't writable, fall through to the code below
|
|
126
|
+
// which uses setAttribute() instead of assigning directly.
|
|
122
127
|
}
|
|
123
128
|
if (value === true) {
|
|
124
129
|
value = "";
|
package/dom.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.cjs","sources":["../src/dom.ts"],"sourcesContent":["import {\n\tChildren,\n\tContext,\n\tElementValue,\n\tPortal,\n\tRenderer,\n\tRendererImpl,\n} from \"./crank\";\n\nconst SVG_NAMESPACE = \"http://www.w3.org/2000/svg\";\n\nexport const impl: Partial<RendererImpl<Node, string>> = {\n\tparse(text: string): DocumentFragment {\n\t\tif (typeof document.createRange === \"function\") {\n\t\t\treturn document.createRange().createContextualFragment(text);\n\t\t} else {\n\t\t\tconst fragment = document.createDocumentFragment();\n\t\t\tconst childNodes = new DOMParser().parseFromString(text, \"text/html\").body\n\t\t\t\t.childNodes;\n\t\t\tfor (let i = 0; i < childNodes.length; i++) {\n\t\t\t\tfragment.appendChild(childNodes[i]);\n\t\t\t}\n\n\t\t\treturn fragment;\n\t\t}\n\t},\n\n\tscope(scope: string, tag: string | symbol): string | undefined {\n\t\t// TODO: Should we handle xmlns???\n\t\tswitch (tag) {\n\t\t\tcase Portal:\n\t\t\tcase \"foreignObject\":\n\t\t\t\treturn undefined;\n\t\t\tcase \"svg\":\n\t\t\t\treturn SVG_NAMESPACE;\n\t\t\tdefault:\n\t\t\t\treturn scope;\n\t\t}\n\t},\n\n\tcreate(tag: string | symbol, _props: unknown, ns: string | undefined): Node {\n\t\tif (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t} else if (tag.toLowerCase() === \"svg\") {\n\t\t\tns = SVG_NAMESPACE;\n\t\t}\n\n\t\treturn ns ? document.createElementNS(ns, tag) : document.createElement(tag);\n\t},\n\n\tpatch(\n\t\t_tag: string | symbol,\n\t\t// TODO: Why does this assignment work?\n\t\tnode: HTMLElement | SVGElement,\n\t\tname: string,\n\t\t// TODO: Stricter typings?\n\t\tvalue: unknown,\n\t\toldValue: unknown,\n\t\tscope: string | undefined,\n\t): void {\n\t\tconst isSVG = scope === SVG_NAMESPACE;\n\t\tswitch (name) {\n\t\t\tcase \"style\": {\n\t\t\t\tconst style: CSSStyleDeclaration = node.style;\n\t\t\t\tif (style == null) {\n\t\t\t\t\tnode.setAttribute(\"style\", value as string);\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(\"style\");\n\t\t\t\t} else if (value === true) {\n\t\t\t\t\tnode.setAttribute(\"style\", \"\");\n\t\t\t\t} else if (typeof value === \"string\") {\n\t\t\t\t\tif (style.cssText !== value) {\n\t\t\t\t\t\tstyle.cssText = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (typeof oldValue === \"string\") {\n\t\t\t\t\t\tstyle.cssText = \"\";\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const styleName in {...(oldValue as {}), ...(value as {})}) {\n\t\t\t\t\t\tconst styleValue = value && (value as any)[styleName];\n\t\t\t\t\t\tif (styleValue == null) {\n\t\t\t\t\t\t\tstyle.removeProperty(styleName);\n\t\t\t\t\t\t} else if (style.getPropertyValue(styleName) !== styleValue) {\n\t\t\t\t\t\t\tstyle.setProperty(styleName, styleValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"class\":\n\t\t\tcase \"className\":\n\t\t\t\tif (value === true) {\n\t\t\t\t\tnode.setAttribute(\"class\", \"\");\n\t\t\t\t} else if (value == null) {\n\t\t\t\t\tnode.removeAttribute(\"class\");\n\t\t\t\t} else if (!isSVG) {\n\t\t\t\t\tif (node.className !== value) {\n\t\t\t\t\t\t(node as any)[\"className\"] = value;\n\t\t\t\t\t}\n\t\t\t\t} else if (node.getAttribute(\"class\") !== value) {\n\t\t\t\t\tnode.setAttribute(\"class\", value as string);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"innerHTML\":\n\t\t\t\tif (value !== oldValue) {\n\t\t\t\t\tnode.innerHTML = value as any;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (\n\t\t\t\t\tname in node &&\n\t\t\t\t\t// boolean properties will coerce strings, but sometimes they map to\n\t\t\t\t\t// enumerated attributes, where truthy strings (\"false\", \"no\") map to\n\t\t\t\t\t// falsy properties, so we use attributes in this case.\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof value === \"string\" &&\n\t\t\t\t\t\ttypeof (node as any)[name] === \"boolean\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif ((node as any)[name] !== value) {\n\t\t\t\t\t\t\t(node as any)[name] = value;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t// some properties are readonly so we fallback to setting them as\n\t\t\t\t\t\t// attributes\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (value === true) {\n\t\t\t\t\tvalue = \"\";\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(name);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.getAttribute(name) !== value) {\n\t\t\t\t\tnode.setAttribute(name, value as any);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Element | string>,\n\t\t_oldProps: Record<string, any> | undefined,\n\t\toldChildren: Array<Element | string> | undefined,\n\t): void {\n\t\tif (tag === Portal && (node == null || typeof node.nodeType !== \"number\")) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Portal root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\tnode && node.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!(\"innerHTML\" in props) &&\n\t\t\t// We don’t want to update elements without explicit children (<div/>),\n\t\t\t// because these elements sometimes have child nodes added via raw\n\t\t\t// DOM manipulations.\n\t\t\t// However, if an element has previously rendered children, we clear the\n\t\t\t// them because it would be surprising not to clear Crank managed\n\t\t\t// children, even if the new element does not have explicit children.\n\t\t\t(\"children\" in props || (oldChildren && oldChildren.length))\n\t\t) {\n\t\t\tif (children.length === 0) {\n\t\t\t\tnode.textContent = \"\";\n\t\t\t} else {\n\t\t\t\tlet oldChild = node.firstChild;\n\t\t\t\tlet i = 0;\n\t\t\t\twhile (oldChild !== null && i < children.length) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tif (oldChild === newChild) {\n\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (typeof newChild === \"string\") {\n\t\t\t\t\t\tif (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\t\tif ((oldChild as Text).data !== newChild) {\n\t\t\t\t\t\t\t\t(oldChild as Text).data = newChild;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.insertBefore(document.createTextNode(newChild), oldChild);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.insertBefore(newChild, oldChild);\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t// TODO: This is an optimization but we need to think a little more about other cases like prepending.\n\t\t\t\t\t\tif (oldChild !== children[i]) {\n\t\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// remove excess DOM nodes\n\t\t\t\twhile (oldChild !== null) {\n\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t}\n\n\t\t\t\t// append excess children\n\t\t\t\tfor (; i < children.length; i++) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tnode.appendChild(\n\t\t\t\t\t\ttypeof newChild === \"string\"\n\t\t\t\t\t\t\t? document.createTextNode(newChild)\n\t\t\t\t\t\t\t: newChild,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n};\n\nexport class DOMRenderer extends Renderer<Node, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n\n\trender(\n\t\tchildren: Children,\n\t\troot: Node,\n\t\tctx?: Context,\n\t): Promise<ElementValue<Node>> | ElementValue<Node> {\n\t\tif (root == null || typeof root.nodeType !== \"number\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Render root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\troot && root.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn super.render(children, root, ctx);\n\t}\n}\n\nexport const renderer = new DOMRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":["Portal","Renderer"],"mappings":";;;;;;AASA,MAAM,aAAa,GAAG,4BAA4B,CAAC;MAEtC,IAAI,GAAwC;IACxD,KAAK,CAAC,IAAY;QACjB,IAAI,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU,EAAE;YAC/C,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC7D;aAAM;YACN,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;YACnD,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,IAAI;iBACxE,UAAU,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC3C,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;aACpC;YAED,OAAO,QAAQ,CAAC;SAChB;KACD;IAED,KAAK,CAAC,KAAa,EAAE,GAAoB;;QAExC,QAAQ,GAAG;YACV,KAAKA,YAAM,CAAC;YACZ,KAAK,eAAe;gBACnB,OAAO,SAAS,CAAC;YAClB,KAAK,KAAK;gBACT,OAAO,aAAa,CAAC;YACtB;gBACC,OAAO,KAAK,CAAC;SACd;KACD;IAED,MAAM,CAAC,GAAoB,EAAE,MAAe,EAAE,EAAsB;QACnE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;SAClD;aAAM,IAAI,GAAG,CAAC,WAAW,EAAE,KA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AK,QAAQ;0BACzB,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC;0BACjC,QAAQ,CACX,CAAC;iBACF;aACD;SACD;KACD;EACA;MAEW,WAAY,SAAQC,cAAsB;IACtD;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;KACZ;IAED,MAAM,CACL,QAAkB,EAClB,IAAU,EACV,GAAa;QAEb,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACtD,MAAM,IAAI,SAAS,CAClB,wCAAwC,IAAI,CAAC,SAAS,CACrD,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CACvB,EAAE,CACH,CAAC;SACF;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;KACzC;CACD;MAEY,QAAQ,GAAG,IAAI,WAAW;;;;;;"}
|
|
1
|
+
{"version":3,"file":"dom.cjs","sources":["../src/dom.ts"],"sourcesContent":["import {\n\tChildren,\n\tContext,\n\tElementValue,\n\tPortal,\n\tRenderer,\n\tRendererImpl,\n} from \"./crank.js\";\n\nconst SVG_NAMESPACE = \"http://www.w3.org/2000/svg\";\n\nexport const impl: Partial<RendererImpl<Node, string>> = {\n\tparse(text: string): ElementValue<Node> {\n\t\tif (typeof document.createRange === \"function\") {\n\t\t\tconst fragment = document.createRange().createContextualFragment(text);\n\t\t\treturn Array.from(fragment.childNodes);\n\t\t} else {\n\t\t\tconst childNodes = new DOMParser().parseFromString(text, \"text/html\").body\n\t\t\t\t.childNodes;\n\t\t\treturn Array.from(childNodes);\n\t\t}\n\t},\n\n\tscope(scope: string, tag: string | symbol): string | undefined {\n\t\t// TODO: Should we handle xmlns???\n\t\tswitch (tag) {\n\t\t\tcase Portal:\n\t\t\tcase \"foreignObject\":\n\t\t\t\treturn undefined;\n\t\t\tcase \"svg\":\n\t\t\t\treturn SVG_NAMESPACE;\n\t\t\tdefault:\n\t\t\t\treturn scope;\n\t\t}\n\t},\n\n\tcreate(tag: string | symbol, _props: unknown, ns: string | undefined): Node {\n\t\tif (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t} else if (tag.toLowerCase() === \"svg\") {\n\t\t\tns = SVG_NAMESPACE;\n\t\t}\n\n\t\treturn ns ? document.createElementNS(ns, tag) : document.createElement(tag);\n\t},\n\n\tpatch(\n\t\t_tag: string | symbol,\n\t\t// TODO: Why does this assignment work?\n\t\tnode: HTMLElement | SVGElement,\n\t\tname: string,\n\t\t// TODO: Stricter typings?\n\t\tvalue: unknown,\n\t\toldValue: unknown,\n\t\tscope: string | undefined,\n\t): void {\n\t\tconst isSVG = scope === SVG_NAMESPACE;\n\t\tswitch (name) {\n\t\t\tcase \"style\": {\n\t\t\t\tconst style: CSSStyleDeclaration = node.style;\n\t\t\t\tif (style == null) {\n\t\t\t\t\tnode.setAttribute(\"style\", value as string);\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(\"style\");\n\t\t\t\t} else if (value === true) {\n\t\t\t\t\tnode.setAttribute(\"style\", \"\");\n\t\t\t\t} else if (typeof value === \"string\") {\n\t\t\t\t\tif (style.cssText !== value) {\n\t\t\t\t\t\tstyle.cssText = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (typeof oldValue === \"string\") {\n\t\t\t\t\t\tstyle.cssText = \"\";\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const styleName in {...(oldValue as {}), ...(value as {})}) {\n\t\t\t\t\t\tconst styleValue = value && (value as any)[styleName];\n\t\t\t\t\t\tif (styleValue == null) {\n\t\t\t\t\t\t\tstyle.removeProperty(styleName);\n\t\t\t\t\t\t} else if (style.getPropertyValue(styleName) !== styleValue) {\n\t\t\t\t\t\t\tstyle.setProperty(styleName, styleValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"class\":\n\t\t\tcase \"className\":\n\t\t\t\tif (value === true) {\n\t\t\t\t\tnode.setAttribute(\"class\", \"\");\n\t\t\t\t} else if (value == null) {\n\t\t\t\t\tnode.removeAttribute(\"class\");\n\t\t\t\t} else if (!isSVG) {\n\t\t\t\t\tif (node.className !== value) {\n\t\t\t\t\t\t(node as any)[\"className\"] = value;\n\t\t\t\t\t}\n\t\t\t\t} else if (node.getAttribute(\"class\") !== value) {\n\t\t\t\t\tnode.setAttribute(\"class\", value as string);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"innerHTML\":\n\t\t\t\tif (value !== oldValue) {\n\t\t\t\t\tnode.innerHTML = value as any;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (\n\t\t\t\t\tname in node &&\n\t\t\t\t\t// boolean properties will coerce strings, but sometimes they map to\n\t\t\t\t\t// enumerated attributes, where truthy strings (\"false\", \"no\") map to\n\t\t\t\t\t// falsy properties, so we use attributes in this case.\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof value === \"string\" &&\n\t\t\t\t\t\ttypeof (node as any)[name] === \"boolean\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\t// walk up the object's prototype chain to find the owner of the\n\t\t\t\t\t// named property\n\t\t\t\t\tlet obj = node;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (Object.prototype.hasOwnProperty.call(obj, name)) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while ((obj = Object.getPrototypeOf(obj)));\n\n\t\t\t\t\t// get the descriptor for the named property and check whether it\n\t\t\t\t\t// implies that the property is writable\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(obj, name);\n\t\t\t\t\tif (\n\t\t\t\t\t\tdescriptor != null &&\n\t\t\t\t\t\t(descriptor.writable === true || descriptor.set !== undefined)\n\t\t\t\t\t) {\n\t\t\t\t\t\t(node as any)[name] = value;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// if the property wasn't writable, fall through to the code below\n\t\t\t\t\t// which uses setAttribute() instead of assigning directly.\n\t\t\t\t}\n\n\t\t\t\tif (value === true) {\n\t\t\t\t\tvalue = \"\";\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(name);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.getAttribute(name) !== value) {\n\t\t\t\t\tnode.setAttribute(name, value as any);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Element | string>,\n\t\t_oldProps: Record<string, any> | undefined,\n\t\toldChildren: Array<Element | string> | undefined,\n\t): void {\n\t\tif (tag === Portal && (node == null || typeof node.nodeType !== \"number\")) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Portal root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\tnode && node.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!(\"innerHTML\" in props) &&\n\t\t\t// We don’t want to update elements without explicit children (<div/>),\n\t\t\t// because these elements sometimes have child nodes added via raw\n\t\t\t// DOM manipulations.\n\t\t\t// However, if an element has previously rendered children, we clear the\n\t\t\t// them because it would be surprising not to clear Crank managed\n\t\t\t// children, even if the new element does not have explicit children.\n\t\t\t(\"children\" in props || (oldChildren && oldChildren.length))\n\t\t) {\n\t\t\tif (children.length === 0) {\n\t\t\t\tnode.textContent = \"\";\n\t\t\t} else {\n\t\t\t\tlet oldChild = node.firstChild;\n\t\t\t\tlet i = 0;\n\t\t\t\twhile (oldChild !== null && i < children.length) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tif (oldChild === newChild) {\n\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (typeof newChild === \"string\") {\n\t\t\t\t\t\tif (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\t\tif ((oldChild as Text).data !== newChild) {\n\t\t\t\t\t\t\t\t(oldChild as Text).data = newChild;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.insertBefore(document.createTextNode(newChild), oldChild);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.insertBefore(newChild, oldChild);\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t// TODO: This is an optimization but we need to think a little more about other cases like prepending.\n\t\t\t\t\t\tif (oldChild !== children[i]) {\n\t\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// remove excess DOM nodes\n\t\t\t\twhile (oldChild !== null) {\n\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t}\n\n\t\t\t\t// append excess children\n\t\t\t\tfor (; i < children.length; i++) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tnode.appendChild(\n\t\t\t\t\t\ttypeof newChild === \"string\"\n\t\t\t\t\t\t\t? document.createTextNode(newChild)\n\t\t\t\t\t\t\t: newChild,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n};\n\nexport class DOMRenderer extends Renderer<Node, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n\n\trender(\n\t\tchildren: Children,\n\t\troot: Node,\n\t\tctx?: Context,\n\t): Promise<ElementValue<Node>> | ElementValue<Node> {\n\t\tif (root == null || typeof root.nodeType !== \"number\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Render root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\troot && root.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn super.render(children, root, ctx);\n\t}\n}\n\nexport const renderer = new DOMRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":["Portal","Renderer"],"mappings":";;;;;;AASA,MAAM,aAAa,GAAG,4BAA4B,CAAC;MAEtC,IAAI,GAAwC;IACxD,KAAK,CAAC,IAAY;QACjB,IAAI,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU,EAAE;YAC/C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACvC;aAAM;YACN,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,IAAI;iBACxE,UAAU,CAAC;YACb,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC9B;KACD;IAED,KAAK,CAAC,KAAa,EAAE,GAAoB;;QAExC,QAAQ,GAAG;YACV,KAAKA,YAAM,CAAC;YACZ,KAAK,eAAe;gBACnB,OAAO,SAAS,CAAC;YAClB,KAAK,KAAK;gBACT,OAAO,aAAa,CAAC;YACtB;gBACC,OAAO,KAAK,CAAC;SACd;KACD;IAED,MAAM,CAAC,GAAoB,EAAE,MAAe,EAAE,EAAsB;QACnE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC5B,MAAM,IAAI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,CAAC,QAAQ,CAAC,CAAC;4BAC3B,QAAQ,GAAG,WAAW,CAAC;yBACvB;qBACD;iBACD;;gBAGD,OAAO,QAAQ,KAAK,IAAI,EAAE;oBACzB,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;oBACzC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBAC3B,QAAQ,GAAG,WAAW,CAAC;iBACvB;;gBAGD,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;oBAC7B,IAAI,CAAC,WAAW,CACf,OAAO,QAAQ,KAAK,QAAQ;0BACzB,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC;0BACjC,QAAQ,CACX,CAAC;iBACF;aACD;SACD;KACD;EACA;MAEW,WAAY,SAAQC,cAAsB;IACtD;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;KACZ;IAED,MAAM,CACL,QAAkB,EAClB,IAAU,EACV,GAAa;QAEb,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACtD,MAAM,IAAI,SAAS,CAClB,wCAAwC,IAAI,CAAC,SAAS,CACrD,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CACvB,EAAE,CACH,CAAC;SACF;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;KACzC;CACD;MAEY,QAAQ,GAAG,IAAI,WAAW;;;;;;"}
|
package/dom.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children, Context, ElementValue, Renderer, RendererImpl } from "./crank";
|
|
1
|
+
import { Children, Context, ElementValue, Renderer, RendererImpl } from "./crank.js";
|
|
2
2
|
export declare const impl: Partial<RendererImpl<Node, string>>;
|
|
3
3
|
export declare class DOMRenderer extends Renderer<Node, string> {
|
|
4
4
|
constructor();
|
package/dom.js
CHANGED
|
@@ -5,16 +5,13 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
|
5
5
|
const impl = {
|
|
6
6
|
parse(text) {
|
|
7
7
|
if (typeof document.createRange === "function") {
|
|
8
|
-
|
|
8
|
+
const fragment = document.createRange().createContextualFragment(text);
|
|
9
|
+
return Array.from(fragment.childNodes);
|
|
9
10
|
}
|
|
10
11
|
else {
|
|
11
|
-
const fragment = document.createDocumentFragment();
|
|
12
12
|
const childNodes = new DOMParser().parseFromString(text, "text/html").body
|
|
13
13
|
.childNodes;
|
|
14
|
-
|
|
15
|
-
fragment.appendChild(childNodes[i]);
|
|
16
|
-
}
|
|
17
|
-
return fragment;
|
|
14
|
+
return Array.from(childNodes);
|
|
18
15
|
}
|
|
19
16
|
},
|
|
20
17
|
scope(scope, tag) {
|
|
@@ -106,16 +103,24 @@ const impl = {
|
|
|
106
103
|
// falsy properties, so we use attributes in this case.
|
|
107
104
|
!(typeof value === "string" &&
|
|
108
105
|
typeof node[name] === "boolean")) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
// walk up the object's prototype chain to find the owner of the
|
|
107
|
+
// named property
|
|
108
|
+
let obj = node;
|
|
109
|
+
do {
|
|
110
|
+
if (Object.prototype.hasOwnProperty.call(obj, name)) {
|
|
111
|
+
break;
|
|
112
112
|
}
|
|
113
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
114
|
+
// get the descriptor for the named property and check whether it
|
|
115
|
+
// implies that the property is writable
|
|
116
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, name);
|
|
117
|
+
if (descriptor != null &&
|
|
118
|
+
(descriptor.writable === true || descriptor.set !== undefined)) {
|
|
119
|
+
node[name] = value;
|
|
113
120
|
return;
|
|
114
121
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// attributes
|
|
118
|
-
}
|
|
122
|
+
// if the property wasn't writable, fall through to the code below
|
|
123
|
+
// which uses setAttribute() instead of assigning directly.
|
|
119
124
|
}
|
|
120
125
|
if (value === true) {
|
|
121
126
|
value = "";
|
package/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sources":["../src/dom.ts"],"sourcesContent":["import {\n\tChildren,\n\tContext,\n\tElementValue,\n\tPortal,\n\tRenderer,\n\tRendererImpl,\n} from \"./crank\";\n\nconst SVG_NAMESPACE = \"http://www.w3.org/2000/svg\";\n\nexport const impl: Partial<RendererImpl<Node, string>> = {\n\tparse(text: string): DocumentFragment {\n\t\tif (typeof document.createRange === \"function\") {\n\t\t\treturn document.createRange().createContextualFragment(text);\n\t\t} else {\n\t\t\tconst fragment = document.createDocumentFragment();\n\t\t\tconst childNodes = new DOMParser().parseFromString(text, \"text/html\").body\n\t\t\t\t.childNodes;\n\t\t\tfor (let i = 0; i < childNodes.length; i++) {\n\t\t\t\tfragment.appendChild(childNodes[i]);\n\t\t\t}\n\n\t\t\treturn fragment;\n\t\t}\n\t},\n\n\tscope(scope: string, tag: string | symbol): string | undefined {\n\t\t// TODO: Should we handle xmlns???\n\t\tswitch (tag) {\n\t\t\tcase Portal:\n\t\t\tcase \"foreignObject\":\n\t\t\t\treturn undefined;\n\t\t\tcase \"svg\":\n\t\t\t\treturn SVG_NAMESPACE;\n\t\t\tdefault:\n\t\t\t\treturn scope;\n\t\t}\n\t},\n\n\tcreate(tag: string | symbol, _props: unknown, ns: string | undefined): Node {\n\t\tif (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t} else if (tag.toLowerCase() === \"svg\") {\n\t\t\tns = SVG_NAMESPACE;\n\t\t}\n\n\t\treturn ns ? document.createElementNS(ns, tag) : document.createElement(tag);\n\t},\n\n\tpatch(\n\t\t_tag: string | symbol,\n\t\t// TODO: Why does this assignment work?\n\t\tnode: HTMLElement | SVGElement,\n\t\tname: string,\n\t\t// TODO: Stricter typings?\n\t\tvalue: unknown,\n\t\toldValue: unknown,\n\t\tscope: string | undefined,\n\t): void {\n\t\tconst isSVG = scope === SVG_NAMESPACE;\n\t\tswitch (name) {\n\t\t\tcase \"style\": {\n\t\t\t\tconst style: CSSStyleDeclaration = node.style;\n\t\t\t\tif (style == null) {\n\t\t\t\t\tnode.setAttribute(\"style\", value as string);\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(\"style\");\n\t\t\t\t} else if (value === true) {\n\t\t\t\t\tnode.setAttribute(\"style\", \"\");\n\t\t\t\t} else if (typeof value === \"string\") {\n\t\t\t\t\tif (style.cssText !== value) {\n\t\t\t\t\t\tstyle.cssText = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (typeof oldValue === \"string\") {\n\t\t\t\t\t\tstyle.cssText = \"\";\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const styleName in {...(oldValue as {}), ...(value as {})}) {\n\t\t\t\t\t\tconst styleValue = value && (value as any)[styleName];\n\t\t\t\t\t\tif (styleValue == null) {\n\t\t\t\t\t\t\tstyle.removeProperty(styleName);\n\t\t\t\t\t\t} else if (style.getPropertyValue(styleName) !== styleValue) {\n\t\t\t\t\t\t\tstyle.setProperty(styleName, styleValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"class\":\n\t\t\tcase \"className\":\n\t\t\t\tif (value === true) {\n\t\t\t\t\tnode.setAttribute(\"class\", \"\");\n\t\t\t\t} else if (value == null) {\n\t\t\t\t\tnode.removeAttribute(\"class\");\n\t\t\t\t} else if (!isSVG) {\n\t\t\t\t\tif (node.className !== value) {\n\t\t\t\t\t\t(node as any)[\"className\"] = value;\n\t\t\t\t\t}\n\t\t\t\t} else if (node.getAttribute(\"class\") !== value) {\n\t\t\t\t\tnode.setAttribute(\"class\", value as string);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"innerHTML\":\n\t\t\t\tif (value !== oldValue) {\n\t\t\t\t\tnode.innerHTML = value as any;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (\n\t\t\t\t\tname in node &&\n\t\t\t\t\t// boolean properties will coerce strings, but sometimes they map to\n\t\t\t\t\t// enumerated attributes, where truthy strings (\"false\", \"no\") map to\n\t\t\t\t\t// falsy properties, so we use attributes in this case.\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof value === \"string\" &&\n\t\t\t\t\t\ttypeof (node as any)[name] === \"boolean\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif ((node as any)[name] !== value) {\n\t\t\t\t\t\t\t(node as any)[name] = value;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t// some properties are readonly so we fallback to setting them as\n\t\t\t\t\t\t// attributes\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (value === true) {\n\t\t\t\t\tvalue = \"\";\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(name);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.getAttribute(name) !== value) {\n\t\t\t\t\tnode.setAttribute(name, value as any);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Element | string>,\n\t\t_oldProps: Record<string, any> | undefined,\n\t\toldChildren: Array<Element | string> | undefined,\n\t): void {\n\t\tif (tag === Portal && (node == null || typeof node.nodeType !== \"number\")) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Portal root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\tnode && node.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!(\"innerHTML\" in props) &&\n\t\t\t// We don’t want to update elements without explicit children (<div/>),\n\t\t\t// because these elements sometimes have child nodes added via raw\n\t\t\t// DOM manipulations.\n\t\t\t// However, if an element has previously rendered children, we clear the\n\t\t\t// them because it would be surprising not to clear Crank managed\n\t\t\t// children, even if the new element does not have explicit children.\n\t\t\t(\"children\" in props || (oldChildren && oldChildren.length))\n\t\t) {\n\t\t\tif (children.length === 0) {\n\t\t\t\tnode.textContent = \"\";\n\t\t\t} else {\n\t\t\t\tlet oldChild = node.firstChild;\n\t\t\t\tlet i = 0;\n\t\t\t\twhile (oldChild !== null && i < children.length) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tif (oldChild === newChild) {\n\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (typeof newChild === \"string\") {\n\t\t\t\t\t\tif (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\t\tif ((oldChild as Text).data !== newChild) {\n\t\t\t\t\t\t\t\t(oldChild as Text).data = newChild;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.insertBefore(document.createTextNode(newChild), oldChild);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.insertBefore(newChild, oldChild);\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t// TODO: This is an optimization but we need to think a little more about other cases like prepending.\n\t\t\t\t\t\tif (oldChild !== children[i]) {\n\t\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// remove excess DOM nodes\n\t\t\t\twhile (oldChild !== null) {\n\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t}\n\n\t\t\t\t// append excess children\n\t\t\t\tfor (; i < children.length; i++) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tnode.appendChild(\n\t\t\t\t\t\ttypeof newChild === \"string\"\n\t\t\t\t\t\t\t? document.createTextNode(newChild)\n\t\t\t\t\t\t\t: newChild,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n};\n\nexport class DOMRenderer extends Renderer<Node, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n\n\trender(\n\t\tchildren: Children,\n\t\troot: Node,\n\t\tctx?: Context,\n\t): Promise<ElementValue<Node>> | ElementValue<Node> {\n\t\tif (root == null || typeof root.nodeType !== \"number\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Render root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\troot && root.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn super.render(children, root, ctx);\n\t}\n}\n\nexport const renderer = new DOMRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":[],"mappings":";;;AASA,MAAM,aAAa,GAAG,4BAA4B,CAAC;MAEtC,IAAI,GAAwC;IACxD,KAAK,CAAC,IAAY;QACjB,IAAI,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU,EAAE;YAC/C,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC7D;aAAM;YACN,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;YACnD,MAAM,UAAU,GAAG,IAAI,SAAS,EAA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Y,QAAQ,GAAG,IAAI,WAAW;;"}
|
|
1
|
+
{"version":3,"file":"dom.js","sources":["../src/dom.ts"],"sourcesContent":["import {\n\tChildren,\n\tContext,\n\tElementValue,\n\tPortal,\n\tRenderer,\n\tRendererImpl,\n} from \"./crank.js\";\n\nconst SVG_NAMESPACE = \"http://www.w3.org/2000/svg\";\n\nexport const impl: Partial<RendererImpl<Node, string>> = {\n\tparse(text: string): ElementValue<Node> {\n\t\tif (typeof document.createRange === \"function\") {\n\t\t\tconst fragment = document.createRange().createContextualFragment(text);\n\t\t\treturn Array.from(fragment.childNodes);\n\t\t} else {\n\t\t\tconst childNodes = new DOMParser().parseFromString(text, \"text/html\").body\n\t\t\t\t.childNodes;\n\t\t\treturn Array.from(childNodes);\n\t\t}\n\t},\n\n\tscope(scope: string, tag: string | symbol): string | undefined {\n\t\t// TODO: Should we handle xmlns???\n\t\tswitch (tag) {\n\t\t\tcase Portal:\n\t\t\tcase \"foreignObject\":\n\t\t\t\treturn undefined;\n\t\t\tcase \"svg\":\n\t\t\t\treturn SVG_NAMESPACE;\n\t\t\tdefault:\n\t\t\t\treturn scope;\n\t\t}\n\t},\n\n\tcreate(tag: string | symbol, _props: unknown, ns: string | undefined): Node {\n\t\tif (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t} else if (tag.toLowerCase() === \"svg\") {\n\t\t\tns = SVG_NAMESPACE;\n\t\t}\n\n\t\treturn ns ? document.createElementNS(ns, tag) : document.createElement(tag);\n\t},\n\n\tpatch(\n\t\t_tag: string | symbol,\n\t\t// TODO: Why does this assignment work?\n\t\tnode: HTMLElement | SVGElement,\n\t\tname: string,\n\t\t// TODO: Stricter typings?\n\t\tvalue: unknown,\n\t\toldValue: unknown,\n\t\tscope: string | undefined,\n\t): void {\n\t\tconst isSVG = scope === SVG_NAMESPACE;\n\t\tswitch (name) {\n\t\t\tcase \"style\": {\n\t\t\t\tconst style: CSSStyleDeclaration = node.style;\n\t\t\t\tif (style == null) {\n\t\t\t\t\tnode.setAttribute(\"style\", value as string);\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(\"style\");\n\t\t\t\t} else if (value === true) {\n\t\t\t\t\tnode.setAttribute(\"style\", \"\");\n\t\t\t\t} else if (typeof value === \"string\") {\n\t\t\t\t\tif (style.cssText !== value) {\n\t\t\t\t\t\tstyle.cssText = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (typeof oldValue === \"string\") {\n\t\t\t\t\t\tstyle.cssText = \"\";\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const styleName in {...(oldValue as {}), ...(value as {})}) {\n\t\t\t\t\t\tconst styleValue = value && (value as any)[styleName];\n\t\t\t\t\t\tif (styleValue == null) {\n\t\t\t\t\t\t\tstyle.removeProperty(styleName);\n\t\t\t\t\t\t} else if (style.getPropertyValue(styleName) !== styleValue) {\n\t\t\t\t\t\t\tstyle.setProperty(styleName, styleValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"class\":\n\t\t\tcase \"className\":\n\t\t\t\tif (value === true) {\n\t\t\t\t\tnode.setAttribute(\"class\", \"\");\n\t\t\t\t} else if (value == null) {\n\t\t\t\t\tnode.removeAttribute(\"class\");\n\t\t\t\t} else if (!isSVG) {\n\t\t\t\t\tif (node.className !== value) {\n\t\t\t\t\t\t(node as any)[\"className\"] = value;\n\t\t\t\t\t}\n\t\t\t\t} else if (node.getAttribute(\"class\") !== value) {\n\t\t\t\t\tnode.setAttribute(\"class\", value as string);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"innerHTML\":\n\t\t\t\tif (value !== oldValue) {\n\t\t\t\t\tnode.innerHTML = value as any;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (\n\t\t\t\t\tname in node &&\n\t\t\t\t\t// boolean properties will coerce strings, but sometimes they map to\n\t\t\t\t\t// enumerated attributes, where truthy strings (\"false\", \"no\") map to\n\t\t\t\t\t// falsy properties, so we use attributes in this case.\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof value === \"string\" &&\n\t\t\t\t\t\ttypeof (node as any)[name] === \"boolean\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\t// walk up the object's prototype chain to find the owner of the\n\t\t\t\t\t// named property\n\t\t\t\t\tlet obj = node;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (Object.prototype.hasOwnProperty.call(obj, name)) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while ((obj = Object.getPrototypeOf(obj)));\n\n\t\t\t\t\t// get the descriptor for the named property and check whether it\n\t\t\t\t\t// implies that the property is writable\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(obj, name);\n\t\t\t\t\tif (\n\t\t\t\t\t\tdescriptor != null &&\n\t\t\t\t\t\t(descriptor.writable === true || descriptor.set !== undefined)\n\t\t\t\t\t) {\n\t\t\t\t\t\t(node as any)[name] = value;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// if the property wasn't writable, fall through to the code below\n\t\t\t\t\t// which uses setAttribute() instead of assigning directly.\n\t\t\t\t}\n\n\t\t\t\tif (value === true) {\n\t\t\t\t\tvalue = \"\";\n\t\t\t\t} else if (value == null || value === false) {\n\t\t\t\t\tnode.removeAttribute(name);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.getAttribute(name) !== value) {\n\t\t\t\t\tnode.setAttribute(name, value as any);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Element | string>,\n\t\t_oldProps: Record<string, any> | undefined,\n\t\toldChildren: Array<Element | string> | undefined,\n\t): void {\n\t\tif (tag === Portal && (node == null || typeof node.nodeType !== \"number\")) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Portal root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\tnode && node.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!(\"innerHTML\" in props) &&\n\t\t\t// We don’t want to update elements without explicit children (<div/>),\n\t\t\t// because these elements sometimes have child nodes added via raw\n\t\t\t// DOM manipulations.\n\t\t\t// However, if an element has previously rendered children, we clear the\n\t\t\t// them because it would be surprising not to clear Crank managed\n\t\t\t// children, even if the new element does not have explicit children.\n\t\t\t(\"children\" in props || (oldChildren && oldChildren.length))\n\t\t) {\n\t\t\tif (children.length === 0) {\n\t\t\t\tnode.textContent = \"\";\n\t\t\t} else {\n\t\t\t\tlet oldChild = node.firstChild;\n\t\t\t\tlet i = 0;\n\t\t\t\twhile (oldChild !== null && i < children.length) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tif (oldChild === newChild) {\n\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (typeof newChild === \"string\") {\n\t\t\t\t\t\tif (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\t\tif ((oldChild as Text).data !== newChild) {\n\t\t\t\t\t\t\t\t(oldChild as Text).data = newChild;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\toldChild = oldChild.nextSibling;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.insertBefore(document.createTextNode(newChild), oldChild);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else if (oldChild.nodeType === Node.TEXT_NODE) {\n\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.insertBefore(newChild, oldChild);\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t// TODO: This is an optimization but we need to think a little more about other cases like prepending.\n\t\t\t\t\t\tif (oldChild !== children[i]) {\n\t\t\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// remove excess DOM nodes\n\t\t\t\twhile (oldChild !== null) {\n\t\t\t\t\tconst nextSibling = oldChild.nextSibling;\n\t\t\t\t\tnode.removeChild(oldChild);\n\t\t\t\t\toldChild = nextSibling;\n\t\t\t\t}\n\n\t\t\t\t// append excess children\n\t\t\t\tfor (; i < children.length; i++) {\n\t\t\t\t\tconst newChild = children[i];\n\t\t\t\t\tnode.appendChild(\n\t\t\t\t\t\ttypeof newChild === \"string\"\n\t\t\t\t\t\t\t? document.createTextNode(newChild)\n\t\t\t\t\t\t\t: newChild,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n};\n\nexport class DOMRenderer extends Renderer<Node, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n\n\trender(\n\t\tchildren: Children,\n\t\troot: Node,\n\t\tctx?: Context,\n\t): Promise<ElementValue<Node>> | ElementValue<Node> {\n\t\tif (root == null || typeof root.nodeType !== \"number\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Render root is not a node. Received: ${JSON.stringify(\n\t\t\t\t\troot && root.toString(),\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn super.render(children, root, ctx);\n\t}\n}\n\nexport const renderer = new DOMRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":[],"mappings":";;;AASA,MAAM,aAAa,GAAG,4BAA4B,CAAC;MAEtC,IAAI,GAAwC;IACxD,KAAK,CAAC,IAAY;QACjB,IAAI,OAAO,QAAQ,CAAC,WAAW,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AY,SAAQ,QAAsB;IACtD;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;KACZ;IAED,MAAM,CACL,QAAkB,EAClB,IAAU,EACV,GAAa;QAEb,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACtD,MAAM,IAAI,SAAS,CAClB,wCAAwC,IAAI,CAAC,SAAS,CACrD,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CACvB,EAAE,CACH,CAAC;SACF;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;KACzC;CACD;MAEY,QAAQ,GAAG,IAAI,WAAW;;"}
|
package/html.cjs
CHANGED
|
@@ -56,14 +56,22 @@ function printAttrs(props) {
|
|
|
56
56
|
case name === "children":
|
|
57
57
|
case name === "innerHTML":
|
|
58
58
|
break;
|
|
59
|
-
case name === "style":
|
|
59
|
+
case name === "style": {
|
|
60
60
|
if (typeof value === "string") {
|
|
61
61
|
attrs.push(`style="${escape(value)}"`);
|
|
62
62
|
}
|
|
63
|
-
else {
|
|
63
|
+
else if (typeof value === "object") {
|
|
64
64
|
attrs.push(`style="${escape(printStyleObject(value))}"`);
|
|
65
65
|
}
|
|
66
66
|
break;
|
|
67
|
+
}
|
|
68
|
+
case name === "className": {
|
|
69
|
+
if ("class" in props || typeof value !== "string") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
attrs.push(`class="${escape(value)}"`);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
67
75
|
case typeof value === "string":
|
|
68
76
|
attrs.push(`${escape(name)}="${escape(value)}"`);
|
|
69
77
|
break;
|
package/html.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.cjs","sources":["../src/html.ts"],"sourcesContent":["import {ElementValue, Portal, Renderer, RendererImpl} from \"./crank\";\n\nconst voidTags = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"command\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"keygen\",\n\t\"link\",\n\t\"meta\",\n\t\"param\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\nfunction escape(text: string): string {\n\treturn text.replace(/[&<>\"']/g, (match) => {\n\t\tswitch (match) {\n\t\t\tcase \"&\":\n\t\t\t\treturn \"&\";\n\t\t\tcase \"<\":\n\t\t\t\treturn \"<\";\n\t\t\tcase \">\":\n\t\t\t\treturn \">\";\n\t\t\tcase '\"':\n\t\t\t\treturn \""\";\n\t\t\tcase \"'\":\n\t\t\t\treturn \"'\";\n\t\t\tdefault:\n\t\t\t\treturn \"\";\n\t\t}\n\t});\n}\n\nfunction printStyleObject(style: Record<string, any>): string {\n\tconst cssStrings = [];\n\tfor (const [name, value] of Object.entries(style)) {\n\t\tif (value != null) {\n\t\t\tcssStrings.push(`${name}:${value};`);\n\t\t}\n\t}\n\n\treturn cssStrings.join(\"\");\n}\n\nfunction printAttrs(props: Record<string, any>): string {\n\tconst attrs: string[] = [];\n\tfor (const [name, value] of Object.entries(props)) {\n\t\tswitch (true) {\n\t\t\tcase name === \"children\":\n\t\t\tcase name === \"innerHTML\":\n\t\t\t\tbreak;\n\t\t\tcase name === \"style\"
|
|
1
|
+
{"version":3,"file":"html.cjs","sources":["../src/html.ts"],"sourcesContent":["import {ElementValue, Portal, Renderer, RendererImpl} from \"./crank.js\";\n\nconst voidTags = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"command\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"keygen\",\n\t\"link\",\n\t\"meta\",\n\t\"param\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\nfunction escape(text: string): string {\n\treturn text.replace(/[&<>\"']/g, (match) => {\n\t\tswitch (match) {\n\t\t\tcase \"&\":\n\t\t\t\treturn \"&\";\n\t\t\tcase \"<\":\n\t\t\t\treturn \"<\";\n\t\t\tcase \">\":\n\t\t\t\treturn \">\";\n\t\t\tcase '\"':\n\t\t\t\treturn \""\";\n\t\t\tcase \"'\":\n\t\t\t\treturn \"'\";\n\t\t\tdefault:\n\t\t\t\treturn \"\";\n\t\t}\n\t});\n}\n\nfunction printStyleObject(style: Record<string, any>): string {\n\tconst cssStrings = [];\n\tfor (const [name, value] of Object.entries(style)) {\n\t\tif (value != null) {\n\t\t\tcssStrings.push(`${name}:${value};`);\n\t\t}\n\t}\n\n\treturn cssStrings.join(\"\");\n}\n\nfunction printAttrs(props: Record<string, any>): string {\n\tconst attrs: string[] = [];\n\tfor (const [name, value] of Object.entries(props)) {\n\t\tswitch (true) {\n\t\t\tcase name === \"children\":\n\t\t\tcase name === \"innerHTML\":\n\t\t\t\tbreak;\n\t\t\tcase name === \"style\": {\n\t\t\t\tif (typeof value === \"string\") {\n\t\t\t\t\tattrs.push(`style=\"${escape(value)}\"`);\n\t\t\t\t} else if (typeof value === \"object\") {\n\t\t\t\t\tattrs.push(`style=\"${escape(printStyleObject(value))}\"`);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase name === \"className\": {\n\t\t\t\tif (\"class\" in props || typeof value !== \"string\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tattrs.push(`class=\"${escape(value)}\"`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase typeof value === \"string\":\n\t\t\t\tattrs.push(`${escape(name)}=\"${escape(value)}\"`);\n\t\t\t\tbreak;\n\t\t\tcase typeof value === \"number\":\n\t\t\t\tattrs.push(`${escape(name)}=\"${value}\"`);\n\t\t\t\tbreak;\n\t\t\tcase value === true:\n\t\t\t\tattrs.push(`${escape(name)}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn attrs.join(\" \");\n}\n\ninterface Node {\n\tvalue: string;\n}\n\nfunction join(children: Array<Node | string>): string {\n\tlet result = \"\";\n\tfor (let i = 0; i < children.length; i++) {\n\t\tconst child = children[i];\n\t\tresult += typeof child === \"string\" ? child : child.value;\n\t}\n\n\treturn result;\n}\n\nexport const impl: Partial<RendererImpl<Node, undefined, any, string>> = {\n\tcreate(): Node {\n\t\treturn {value: \"\"};\n\t},\n\n\tescape(text: string): string {\n\t\treturn escape(text);\n\t},\n\n\tread(value: ElementValue<Node>): string {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn join(value);\n\t\t} else if (typeof value === \"undefined\") {\n\t\t\treturn \"\";\n\t\t} else if (typeof value === \"string\") {\n\t\t\treturn value;\n\t\t} else {\n\t\t\treturn value.value;\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Node | string>,\n\t): void {\n\t\tif (tag === Portal) {\n\t\t\treturn;\n\t\t} else if (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t}\n\n\t\tconst attrs = printAttrs(props);\n\t\tconst open = `<${tag}${attrs.length ? \" \" : \"\"}${attrs}>`;\n\t\tlet result: string;\n\t\tif (voidTags.has(tag)) {\n\t\t\tresult = open;\n\t\t} else {\n\t\t\tconst close = `</${tag}>`;\n\t\t\tconst contents =\n\t\t\t\t\"innerHTML\" in props ? props[\"innerHTML\"] : join(children);\n\t\t\tresult = `${open}${contents}${close}`;\n\t\t}\n\n\t\tnode.value = result;\n\t},\n};\n\nexport class HTMLRenderer extends Renderer<Node, undefined, any, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n}\n\nexport const renderer = new HTMLRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":["Portal","Renderer"],"mappings":";;;;;;AAEA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACxB,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,SAAS;IACT,OAAO;IAC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C5D,MAAM,GAAG,GAAG,IAAI,GAAG,QAAQ,GAAG,KAAK,EAAE,CAAC;SACtC;QAED,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;KACpB;EACA;MAEW,YAAa,SAAQC,cAAsC;IACvE;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;KACZ;CACD;MAEY,QAAQ,GAAG,IAAI,YAAY;;;;;;"}
|
package/html.d.ts
CHANGED
package/html.js
CHANGED
|
@@ -53,14 +53,22 @@ function printAttrs(props) {
|
|
|
53
53
|
case name === "children":
|
|
54
54
|
case name === "innerHTML":
|
|
55
55
|
break;
|
|
56
|
-
case name === "style":
|
|
56
|
+
case name === "style": {
|
|
57
57
|
if (typeof value === "string") {
|
|
58
58
|
attrs.push(`style="${escape(value)}"`);
|
|
59
59
|
}
|
|
60
|
-
else {
|
|
60
|
+
else if (typeof value === "object") {
|
|
61
61
|
attrs.push(`style="${escape(printStyleObject(value))}"`);
|
|
62
62
|
}
|
|
63
63
|
break;
|
|
64
|
+
}
|
|
65
|
+
case name === "className": {
|
|
66
|
+
if ("class" in props || typeof value !== "string") {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
attrs.push(`class="${escape(value)}"`);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
64
72
|
case typeof value === "string":
|
|
65
73
|
attrs.push(`${escape(name)}="${escape(value)}"`);
|
|
66
74
|
break;
|
package/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sources":["../src/html.ts"],"sourcesContent":["import {ElementValue, Portal, Renderer, RendererImpl} from \"./crank\";\n\nconst voidTags = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"command\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"keygen\",\n\t\"link\",\n\t\"meta\",\n\t\"param\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\nfunction escape(text: string): string {\n\treturn text.replace(/[&<>\"']/g, (match) => {\n\t\tswitch (match) {\n\t\t\tcase \"&\":\n\t\t\t\treturn \"&\";\n\t\t\tcase \"<\":\n\t\t\t\treturn \"<\";\n\t\t\tcase \">\":\n\t\t\t\treturn \">\";\n\t\t\tcase '\"':\n\t\t\t\treturn \""\";\n\t\t\tcase \"'\":\n\t\t\t\treturn \"'\";\n\t\t\tdefault:\n\t\t\t\treturn \"\";\n\t\t}\n\t});\n}\n\nfunction printStyleObject(style: Record<string, any>): string {\n\tconst cssStrings = [];\n\tfor (const [name, value] of Object.entries(style)) {\n\t\tif (value != null) {\n\t\t\tcssStrings.push(`${name}:${value};`);\n\t\t}\n\t}\n\n\treturn cssStrings.join(\"\");\n}\n\nfunction printAttrs(props: Record<string, any>): string {\n\tconst attrs: string[] = [];\n\tfor (const [name, value] of Object.entries(props)) {\n\t\tswitch (true) {\n\t\t\tcase name === \"children\":\n\t\t\tcase name === \"innerHTML\":\n\t\t\t\tbreak;\n\t\t\tcase name === \"style\"
|
|
1
|
+
{"version":3,"file":"html.js","sources":["../src/html.ts"],"sourcesContent":["import {ElementValue, Portal, Renderer, RendererImpl} from \"./crank.js\";\n\nconst voidTags = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"command\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"keygen\",\n\t\"link\",\n\t\"meta\",\n\t\"param\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\nfunction escape(text: string): string {\n\treturn text.replace(/[&<>\"']/g, (match) => {\n\t\tswitch (match) {\n\t\t\tcase \"&\":\n\t\t\t\treturn \"&\";\n\t\t\tcase \"<\":\n\t\t\t\treturn \"<\";\n\t\t\tcase \">\":\n\t\t\t\treturn \">\";\n\t\t\tcase '\"':\n\t\t\t\treturn \""\";\n\t\t\tcase \"'\":\n\t\t\t\treturn \"'\";\n\t\t\tdefault:\n\t\t\t\treturn \"\";\n\t\t}\n\t});\n}\n\nfunction printStyleObject(style: Record<string, any>): string {\n\tconst cssStrings = [];\n\tfor (const [name, value] of Object.entries(style)) {\n\t\tif (value != null) {\n\t\t\tcssStrings.push(`${name}:${value};`);\n\t\t}\n\t}\n\n\treturn cssStrings.join(\"\");\n}\n\nfunction printAttrs(props: Record<string, any>): string {\n\tconst attrs: string[] = [];\n\tfor (const [name, value] of Object.entries(props)) {\n\t\tswitch (true) {\n\t\t\tcase name === \"children\":\n\t\t\tcase name === \"innerHTML\":\n\t\t\t\tbreak;\n\t\t\tcase name === \"style\": {\n\t\t\t\tif (typeof value === \"string\") {\n\t\t\t\t\tattrs.push(`style=\"${escape(value)}\"`);\n\t\t\t\t} else if (typeof value === \"object\") {\n\t\t\t\t\tattrs.push(`style=\"${escape(printStyleObject(value))}\"`);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase name === \"className\": {\n\t\t\t\tif (\"class\" in props || typeof value !== \"string\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tattrs.push(`class=\"${escape(value)}\"`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase typeof value === \"string\":\n\t\t\t\tattrs.push(`${escape(name)}=\"${escape(value)}\"`);\n\t\t\t\tbreak;\n\t\t\tcase typeof value === \"number\":\n\t\t\t\tattrs.push(`${escape(name)}=\"${value}\"`);\n\t\t\t\tbreak;\n\t\t\tcase value === true:\n\t\t\t\tattrs.push(`${escape(name)}`);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn attrs.join(\" \");\n}\n\ninterface Node {\n\tvalue: string;\n}\n\nfunction join(children: Array<Node | string>): string {\n\tlet result = \"\";\n\tfor (let i = 0; i < children.length; i++) {\n\t\tconst child = children[i];\n\t\tresult += typeof child === \"string\" ? child : child.value;\n\t}\n\n\treturn result;\n}\n\nexport const impl: Partial<RendererImpl<Node, undefined, any, string>> = {\n\tcreate(): Node {\n\t\treturn {value: \"\"};\n\t},\n\n\tescape(text: string): string {\n\t\treturn escape(text);\n\t},\n\n\tread(value: ElementValue<Node>): string {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn join(value);\n\t\t} else if (typeof value === \"undefined\") {\n\t\t\treturn \"\";\n\t\t} else if (typeof value === \"string\") {\n\t\t\treturn value;\n\t\t} else {\n\t\t\treturn value.value;\n\t\t}\n\t},\n\n\tarrange(\n\t\ttag: string | symbol,\n\t\tnode: Node,\n\t\tprops: Record<string, any>,\n\t\tchildren: Array<Node | string>,\n\t): void {\n\t\tif (tag === Portal) {\n\t\t\treturn;\n\t\t} else if (typeof tag !== \"string\") {\n\t\t\tthrow new Error(`Unknown tag: ${tag.toString()}`);\n\t\t}\n\n\t\tconst attrs = printAttrs(props);\n\t\tconst open = `<${tag}${attrs.length ? \" \" : \"\"}${attrs}>`;\n\t\tlet result: string;\n\t\tif (voidTags.has(tag)) {\n\t\t\tresult = open;\n\t\t} else {\n\t\t\tconst close = `</${tag}>`;\n\t\t\tconst contents =\n\t\t\t\t\"innerHTML\" in props ? props[\"innerHTML\"] : join(children);\n\t\t\tresult = `${open}${contents}${close}`;\n\t\t}\n\n\t\tnode.value = result;\n\t},\n};\n\nexport class HTMLRenderer extends Renderer<Node, undefined, any, string> {\n\tconstructor() {\n\t\tsuper(impl);\n\t}\n}\n\nexport const renderer = new HTMLRenderer();\n\ndeclare global {\n\tmodule Crank {\n\t\tinterface EventMap extends GlobalEventHandlersEventMap {}\n\t}\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACxB,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,SAAS;IACT,OAAO;IACP,IAAI;IACJ,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,KAAK;CACL,CAAC,CAAC;AAEH,SAAS,MAAM,CAAC,IAAY;IAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,C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QAAQ,GAAG,IAAI,YAAY;;"}
|
package/index.cjs
CHANGED
|
@@ -15,5 +15,6 @@ exports.Raw = crank.Raw;
|
|
|
15
15
|
exports.Renderer = crank.Renderer;
|
|
16
16
|
exports.cloneElement = crank.cloneElement;
|
|
17
17
|
exports.createElement = crank.createElement;
|
|
18
|
+
exports["default"] = crank["default"];
|
|
18
19
|
exports.isElement = crank.isElement;
|
|
19
20
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./crank";
|
|
1
|
+
export * from "./crank.js";
|
|
2
|
+
export { default } from "./crank.js";
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="index.d.ts" />
|
|
2
|
-
export { Context, Copy, Element, Fragment, Portal, Raw, Renderer, cloneElement, createElement, isElement } from './crank.js';
|
|
2
|
+
export { Context, Copy, Element, Fragment, Portal, Raw, Renderer, cloneElement, createElement, default, isElement } from './crank.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/crank",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Write JSX-driven components with functions, promises and generators.",
|
|
5
5
|
"homepage": "https://crank.js.org",
|
|
6
6
|
"bugs": {
|
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
|
-
"./": "./",
|
|
17
16
|
".": {
|
|
18
|
-
"import": "./
|
|
19
|
-
"require": "./
|
|
17
|
+
"import": "./crank.js",
|
|
18
|
+
"require": "./crank.cjs"
|
|
20
19
|
},
|
|
21
20
|
"./crank": {
|
|
22
21
|
"import": "./crank.js",
|
|
@@ -58,15 +57,14 @@
|
|
|
58
57
|
"require": "./umd.js"
|
|
59
58
|
}
|
|
60
59
|
},
|
|
61
|
-
"main": "
|
|
62
|
-
"module": "
|
|
63
|
-
"types": "
|
|
60
|
+
"main": "crank.cjs",
|
|
61
|
+
"module": "crank.js",
|
|
62
|
+
"types": "crank.d.ts",
|
|
64
63
|
"devDependencies": {
|
|
65
64
|
"@arkweid/lefthook": "^0.7.7",
|
|
66
65
|
"@types/jest": "^26.0.23",
|
|
67
66
|
"@typescript-eslint/eslint-plugin": "^4.31.2",
|
|
68
67
|
"@typescript-eslint/parser": "^4.31.2",
|
|
69
|
-
"core-js": "^3.18.0",
|
|
70
68
|
"eslint": "^7.32.0",
|
|
71
69
|
"eslint-config-prettier": "^8.3.0",
|
|
72
70
|
"eslint-plugin-jest": "^24.4.2",
|
|
@@ -79,7 +77,7 @@
|
|
|
79
77
|
"rollup-plugin-typescript2": "^0.30.0",
|
|
80
78
|
"shx": "^0.3.3",
|
|
81
79
|
"ts-jest": "^26.5.6",
|
|
82
|
-
"ts-
|
|
80
|
+
"ts-jest-resolver": "^2.0.0",
|
|
83
81
|
"typescript": "^4.4.3"
|
|
84
82
|
},
|
|
85
83
|
"publishConfig": {
|
package/umd.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./crank";
|
|
2
|
-
export * as dom from "./dom";
|
|
3
|
-
export * as html from "./html";
|
|
1
|
+
export * from "./crank.js";
|
|
2
|
+
export * as dom from "./dom.js";
|
|
3
|
+
export * as html from "./html.js";
|
package/umd.js
CHANGED
|
@@ -128,7 +128,6 @@
|
|
|
128
128
|
let static_ = false;
|
|
129
129
|
const props1 = {};
|
|
130
130
|
if (props != null) {
|
|
131
|
-
// TODO: deprecate crank-whatever props
|
|
132
131
|
for (const name in props) {
|
|
133
132
|
switch (name) {
|
|
134
133
|
case "crank-key":
|
|
@@ -1642,16 +1641,13 @@
|
|
|
1642
1641
|
const impl$1 = {
|
|
1643
1642
|
parse(text) {
|
|
1644
1643
|
if (typeof document.createRange === "function") {
|
|
1645
|
-
|
|
1644
|
+
const fragment = document.createRange().createContextualFragment(text);
|
|
1645
|
+
return Array.from(fragment.childNodes);
|
|
1646
1646
|
}
|
|
1647
1647
|
else {
|
|
1648
|
-
const fragment = document.createDocumentFragment();
|
|
1649
1648
|
const childNodes = new DOMParser().parseFromString(text, "text/html").body
|
|
1650
1649
|
.childNodes;
|
|
1651
|
-
|
|
1652
|
-
fragment.appendChild(childNodes[i]);
|
|
1653
|
-
}
|
|
1654
|
-
return fragment;
|
|
1650
|
+
return Array.from(childNodes);
|
|
1655
1651
|
}
|
|
1656
1652
|
},
|
|
1657
1653
|
scope(scope, tag) {
|
|
@@ -1743,16 +1739,24 @@
|
|
|
1743
1739
|
// falsy properties, so we use attributes in this case.
|
|
1744
1740
|
!(typeof value === "string" &&
|
|
1745
1741
|
typeof node[name] === "boolean")) {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1742
|
+
// walk up the object's prototype chain to find the owner of the
|
|
1743
|
+
// named property
|
|
1744
|
+
let obj = node;
|
|
1745
|
+
do {
|
|
1746
|
+
if (Object.prototype.hasOwnProperty.call(obj, name)) {
|
|
1747
|
+
break;
|
|
1749
1748
|
}
|
|
1749
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
1750
|
+
// get the descriptor for the named property and check whether it
|
|
1751
|
+
// implies that the property is writable
|
|
1752
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, name);
|
|
1753
|
+
if (descriptor != null &&
|
|
1754
|
+
(descriptor.writable === true || descriptor.set !== undefined)) {
|
|
1755
|
+
node[name] = value;
|
|
1750
1756
|
return;
|
|
1751
1757
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
// attributes
|
|
1755
|
-
}
|
|
1758
|
+
// if the property wasn't writable, fall through to the code below
|
|
1759
|
+
// which uses setAttribute() instead of assigning directly.
|
|
1756
1760
|
}
|
|
1757
1761
|
if (value === true) {
|
|
1758
1762
|
value = "";
|
|
@@ -1908,14 +1912,22 @@
|
|
|
1908
1912
|
case name === "children":
|
|
1909
1913
|
case name === "innerHTML":
|
|
1910
1914
|
break;
|
|
1911
|
-
case name === "style":
|
|
1915
|
+
case name === "style": {
|
|
1912
1916
|
if (typeof value === "string") {
|
|
1913
1917
|
attrs.push(`style="${escape(value)}"`);
|
|
1914
1918
|
}
|
|
1915
|
-
else {
|
|
1919
|
+
else if (typeof value === "object") {
|
|
1916
1920
|
attrs.push(`style="${escape(printStyleObject(value))}"`);
|
|
1917
1921
|
}
|
|
1918
1922
|
break;
|
|
1923
|
+
}
|
|
1924
|
+
case name === "className": {
|
|
1925
|
+
if ("class" in props || typeof value !== "string") {
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
attrs.push(`class="${escape(value)}"`);
|
|
1929
|
+
break;
|
|
1930
|
+
}
|
|
1919
1931
|
case typeof value === "string":
|
|
1920
1932
|
attrs.push(`${escape(name)}="${escape(value)}"`);
|
|
1921
1933
|
break;
|