@solidjs/html 2.0.0-experimental.15 → 2.0.0-experimental.16
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/dist/html.cjs +4 -24
- package/dist/html.js +5 -25
- package/package.json +3 -3
- package/types/lit.d.ts +34 -1
package/dist/html.cjs
CHANGED
|
@@ -161,14 +161,14 @@ const cache = new Map();
|
|
|
161
161
|
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
162
162
|
const spaces = " \\f\\n\\r\\t";
|
|
163
163
|
const almostEverything = "[^" + spaces + "\\/>\"'=]+";
|
|
164
|
-
const attrName = "[ " + spaces + "]+
|
|
164
|
+
const attrName = "[ " + spaces + "]+" + almostEverything;
|
|
165
165
|
const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
|
|
166
166
|
const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
|
|
167
167
|
const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
|
|
168
168
|
const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi");
|
|
169
169
|
const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
|
|
170
170
|
const marker = "<!--#-->";
|
|
171
|
-
const reservedNameSpaces = new Set(["class", "on", "style", "
|
|
171
|
+
const reservedNameSpaces = new Set(["class", "on", "style", "prop"]);
|
|
172
172
|
function attrReplacer($0, $1, $2, $3) {
|
|
173
173
|
return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
|
|
174
174
|
}
|
|
@@ -178,14 +178,6 @@ function replaceAttributes($0, $1, $2) {
|
|
|
178
178
|
function fullClosing($0, $1, $2) {
|
|
179
179
|
return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
|
|
180
180
|
}
|
|
181
|
-
function parseDirective(name, value, tag, options) {
|
|
182
|
-
if (name === "use:###" && value === "###") {
|
|
183
|
-
const count = options.counter++;
|
|
184
|
-
options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`);
|
|
185
|
-
} else {
|
|
186
|
-
throw new Error(`Not support syntax ${name} must be use:{function}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
181
|
function createHTML(r, {
|
|
190
182
|
delegateEvents = true,
|
|
191
183
|
functionBuilder = (...args) => new Function(...args)
|
|
@@ -271,7 +263,7 @@ function createHTML(r, {
|
|
|
271
263
|
options.exprs.push(`${tag}.addEventListener("${name.slice(3)}",exprs[${options.counter++}])`);
|
|
272
264
|
}
|
|
273
265
|
} else if (name === "ref") {
|
|
274
|
-
options.exprs.push(`exprs[${options.counter++}]
|
|
266
|
+
options.exprs.push(`r.ref(() => exprs[${options.counter++}], ${tag})`);
|
|
275
267
|
} else {
|
|
276
268
|
const childOptions = Object.assign({}, options, {
|
|
277
269
|
exprs: []
|
|
@@ -366,11 +358,6 @@ function createHTML(r, {
|
|
|
366
358
|
} else if (value === "###") {
|
|
367
359
|
props.push(`"${name}": exprs[${options.counter++}]`);
|
|
368
360
|
} else props.push(`"${name}": "${value}"`);
|
|
369
|
-
} else if (type === 'directive') {
|
|
370
|
-
const tag = `_$el${uuid++}`;
|
|
371
|
-
const topDecl = !options.decl.length;
|
|
372
|
-
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
373
|
-
parseDirective(name, value, tag, options);
|
|
374
361
|
}
|
|
375
362
|
}
|
|
376
363
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -472,8 +459,6 @@ function createHTML(r, {
|
|
|
472
459
|
} else {
|
|
473
460
|
newAttrs.push(node.attrs[i]);
|
|
474
461
|
}
|
|
475
|
-
} else if (type === "directive") {
|
|
476
|
-
parseDirective(name, value, tag, options);
|
|
477
462
|
}
|
|
478
463
|
}
|
|
479
464
|
node.attrs = newAttrs;
|
|
@@ -488,11 +473,7 @@ function createHTML(r, {
|
|
|
488
473
|
name,
|
|
489
474
|
value
|
|
490
475
|
} = node.attrs[i];
|
|
491
|
-
if (type === "
|
|
492
|
-
parseDirective(name, value, tag, options);
|
|
493
|
-
node.attrs.splice(i, 1);
|
|
494
|
-
i--;
|
|
495
|
-
} else if (type === "attr") {
|
|
476
|
+
if (type === "attr") {
|
|
496
477
|
if (value.includes("###")) {
|
|
497
478
|
node.attrs.splice(i, 1);
|
|
498
479
|
i--;
|
|
@@ -576,7 +557,6 @@ const html = createHTML({
|
|
|
576
557
|
setAttribute: web.setAttribute,
|
|
577
558
|
setAttributeNS: web.setAttributeNS,
|
|
578
559
|
addEventListener: web.addEventListener,
|
|
579
|
-
getPropAlias: web.getPropAlias,
|
|
580
560
|
Properties: web.Properties,
|
|
581
561
|
ChildProperties: web.ChildProperties,
|
|
582
562
|
DelegatedEvents: web.DelegatedEvents,
|
package/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SVGNamespace, SVGElements, DelegatedEvents, ChildProperties, Properties,
|
|
1
|
+
import { SVGNamespace, SVGElements, DelegatedEvents, ChildProperties, Properties, addEventListener, setAttributeNS, setAttribute, dynamicProperty, mergeProps, className, delegateEvents, createComponent, spread, untrack, insert, style, effect } from '@solidjs/web';
|
|
2
2
|
|
|
3
3
|
const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
|
4
4
|
const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
|
|
@@ -159,14 +159,14 @@ const cache = new Map();
|
|
|
159
159
|
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
160
160
|
const spaces = " \\f\\n\\r\\t";
|
|
161
161
|
const almostEverything = "[^" + spaces + "\\/>\"'=]+";
|
|
162
|
-
const attrName = "[ " + spaces + "]+
|
|
162
|
+
const attrName = "[ " + spaces + "]+" + almostEverything;
|
|
163
163
|
const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
|
|
164
164
|
const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
|
|
165
165
|
const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
|
|
166
166
|
const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi");
|
|
167
167
|
const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
|
|
168
168
|
const marker = "<!--#-->";
|
|
169
|
-
const reservedNameSpaces = new Set(["class", "on", "style", "
|
|
169
|
+
const reservedNameSpaces = new Set(["class", "on", "style", "prop"]);
|
|
170
170
|
function attrReplacer($0, $1, $2, $3) {
|
|
171
171
|
return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
|
|
172
172
|
}
|
|
@@ -176,14 +176,6 @@ function replaceAttributes($0, $1, $2) {
|
|
|
176
176
|
function fullClosing($0, $1, $2) {
|
|
177
177
|
return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
|
|
178
178
|
}
|
|
179
|
-
function parseDirective(name, value, tag, options) {
|
|
180
|
-
if (name === "use:###" && value === "###") {
|
|
181
|
-
const count = options.counter++;
|
|
182
|
-
options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`);
|
|
183
|
-
} else {
|
|
184
|
-
throw new Error(`Not support syntax ${name} must be use:{function}`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
179
|
function createHTML(r, {
|
|
188
180
|
delegateEvents = true,
|
|
189
181
|
functionBuilder = (...args) => new Function(...args)
|
|
@@ -269,7 +261,7 @@ function createHTML(r, {
|
|
|
269
261
|
options.exprs.push(`${tag}.addEventListener("${name.slice(3)}",exprs[${options.counter++}])`);
|
|
270
262
|
}
|
|
271
263
|
} else if (name === "ref") {
|
|
272
|
-
options.exprs.push(`exprs[${options.counter++}]
|
|
264
|
+
options.exprs.push(`r.ref(() => exprs[${options.counter++}], ${tag})`);
|
|
273
265
|
} else {
|
|
274
266
|
const childOptions = Object.assign({}, options, {
|
|
275
267
|
exprs: []
|
|
@@ -364,11 +356,6 @@ function createHTML(r, {
|
|
|
364
356
|
} else if (value === "###") {
|
|
365
357
|
props.push(`"${name}": exprs[${options.counter++}]`);
|
|
366
358
|
} else props.push(`"${name}": "${value}"`);
|
|
367
|
-
} else if (type === 'directive') {
|
|
368
|
-
const tag = `_$el${uuid++}`;
|
|
369
|
-
const topDecl = !options.decl.length;
|
|
370
|
-
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
371
|
-
parseDirective(name, value, tag, options);
|
|
372
359
|
}
|
|
373
360
|
}
|
|
374
361
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -470,8 +457,6 @@ function createHTML(r, {
|
|
|
470
457
|
} else {
|
|
471
458
|
newAttrs.push(node.attrs[i]);
|
|
472
459
|
}
|
|
473
|
-
} else if (type === "directive") {
|
|
474
|
-
parseDirective(name, value, tag, options);
|
|
475
460
|
}
|
|
476
461
|
}
|
|
477
462
|
node.attrs = newAttrs;
|
|
@@ -486,11 +471,7 @@ function createHTML(r, {
|
|
|
486
471
|
name,
|
|
487
472
|
value
|
|
488
473
|
} = node.attrs[i];
|
|
489
|
-
if (type === "
|
|
490
|
-
parseDirective(name, value, tag, options);
|
|
491
|
-
node.attrs.splice(i, 1);
|
|
492
|
-
i--;
|
|
493
|
-
} else if (type === "attr") {
|
|
474
|
+
if (type === "attr") {
|
|
494
475
|
if (value.includes("###")) {
|
|
495
476
|
node.attrs.splice(i, 1);
|
|
496
477
|
i--;
|
|
@@ -574,7 +555,6 @@ const html = createHTML({
|
|
|
574
555
|
setAttribute,
|
|
575
556
|
setAttributeNS,
|
|
576
557
|
addEventListener,
|
|
577
|
-
getPropAlias,
|
|
578
558
|
Properties,
|
|
579
559
|
ChildProperties,
|
|
580
560
|
DelegatedEvents,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/html",
|
|
3
3
|
"description": "Build-less Tagged-Template-Literal Templating for Solid",
|
|
4
|
-
"version": "2.0.0-experimental.
|
|
4
|
+
"version": "2.0.0-experimental.16",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"./dist/*": "./dist/*"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@solidjs/web": "^2.0.0-experimental.
|
|
34
|
+
"@solidjs/web": "^2.0.0-experimental.16"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@solidjs/web": "2.0.0-experimental.
|
|
37
|
+
"@solidjs/web": "2.0.0-experimental.16"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "npm-run-all -nl build:*",
|
package/types/lit.d.ts
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
|
2
|
+
type ClassList = Record<string, boolean> | Array<string | number | boolean | null | undefined | Record<string, boolean>>;
|
|
3
|
+
interface Runtime {
|
|
4
|
+
effect<T>(fn: (prev?: T) => T, effect: (value: T, prev?: T) => void, init?: T): void;
|
|
5
|
+
untrack<T>(fn: () => T): T;
|
|
6
|
+
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
|
|
7
|
+
spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
|
|
8
|
+
createComponent(Comp: (props: any) => any, props: any): any;
|
|
9
|
+
addEventListener(node: Element, name: string, handler: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions), delegate: boolean): void;
|
|
10
|
+
delegateEvents(eventNames: string[]): void;
|
|
11
|
+
className(node: Element, value: string | ClassList, isSVG?: boolean, prev?: string | ClassList): void;
|
|
12
|
+
style(node: Element, value: {
|
|
13
|
+
[k: string]: string;
|
|
14
|
+
}, prev?: {
|
|
15
|
+
[k: string]: string;
|
|
16
|
+
}): void;
|
|
17
|
+
mergeProps(...sources: unknown[]): unknown;
|
|
18
|
+
dynamicProperty(props: any, key: string): any;
|
|
19
|
+
setAttribute(node: Element, name: string, value: any): void;
|
|
20
|
+
setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
|
|
21
|
+
Properties: Set<string>;
|
|
22
|
+
ChildProperties: Set<string>;
|
|
23
|
+
DelegatedEvents: Set<string>;
|
|
24
|
+
SVGElements: Set<string>;
|
|
25
|
+
SVGNamespace: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
export type HTMLTag = {
|
|
28
|
+
(statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
|
|
29
|
+
};
|
|
30
|
+
export declare function createHTML(r: Runtime, { delegateEvents, functionBuilder }?: {
|
|
31
|
+
delegateEvents?: boolean;
|
|
32
|
+
functionBuilder?: (...args: string[]) => Function;
|
|
33
|
+
}): HTMLTag;
|
|
34
|
+
export {};
|