@fluixi/template-parser 1.0.0-alpha.108 → 1.0.0-alpha.110

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.
@@ -0,0 +1,80 @@
1
+ // src/a11y.ts
2
+ var INTERACTIVE = /* @__PURE__ */ new Set([
3
+ "a",
4
+ "button",
5
+ "input",
6
+ "select",
7
+ "textarea",
8
+ "summary",
9
+ "details",
10
+ "option",
11
+ "label"
12
+ ]);
13
+ var KEY_EVENTS = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
14
+ function attributeNamed(node, name) {
15
+ return node.attributes.find((a) => "name" in a && a.name === name);
16
+ }
17
+ function hasSpread(node) {
18
+ return node.attributes.some((a) => a.kind === "Spread");
19
+ }
20
+ function staticValue(node, name) {
21
+ const attribute = attributeNamed(node, name);
22
+ if (!attribute || attribute.kind !== "Attribute" || !attribute.value) return void 0;
23
+ const value = attribute.value;
24
+ return value.kind === "static" ? value.value : void 0;
25
+ }
26
+ function isPresentational(node) {
27
+ const role = staticValue(node, "role");
28
+ if (role === "presentation" || role === "none") return true;
29
+ return staticValue(node, "aria-hidden") === "true";
30
+ }
31
+ function hasEvent(node, predicate) {
32
+ return node.attributes.some((a) => a.kind === "EventBinding" && predicate(a.name));
33
+ }
34
+ function checkAccessibility(root) {
35
+ const out = [];
36
+ const report = (node, code, message) => {
37
+ out.push({ code, message, severity: "warning", loc: node.loc });
38
+ };
39
+ const visit = (nodes) => {
40
+ for (const node of nodes) {
41
+ if (node.kind === "Element") check(node, report);
42
+ const children = "children" in node ? node.children : void 0;
43
+ if (children) visit(children);
44
+ }
45
+ };
46
+ visit(root.children);
47
+ return out;
48
+ }
49
+ function check(node, report) {
50
+ if (hasSpread(node)) return;
51
+ const tag = node.tag.toLowerCase();
52
+ if (tag === "img" && !attributeNamed(node, "alt") && !isPresentational(node)) {
53
+ report(node, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.');
54
+ }
55
+ if (tag === "a" && !attributeNamed(node, "href") && !attributeNamed(node, "role")) {
56
+ report(node, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action.");
57
+ }
58
+ if (tag === "iframe" && !attributeNamed(node, "title")) {
59
+ report(node, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
60
+ }
61
+ const tabindex = staticValue(node, "tabindex") ?? staticValue(node, "tabIndex");
62
+ if (tabindex !== void 0 && Number(tabindex) > 0) {
63
+ report(
64
+ node,
65
+ "a11y-positive-tabindex",
66
+ "A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."
67
+ );
68
+ }
69
+ if (!INTERACTIVE.has(tag) && hasEvent(node, (name) => name === "click") && !attributeNamed(node, "role") && !hasEvent(node, (name) => KEY_EVENTS.has(name))) {
70
+ report(
71
+ node,
72
+ "a11y-click-without-keyboard",
73
+ `A click handler on \`${tag}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`
74
+ );
75
+ }
76
+ }
77
+
78
+ export {
79
+ checkAccessibility
80
+ };
@@ -0,0 +1,192 @@
1
+ // src/directives.ts
2
+ var EVENT_MODIFIERS = /* @__PURE__ */ new Set(["capture", "once", "passive", "prevent", "stop", "self"]);
3
+ function requireHole(raw, what) {
4
+ if (raw.value && raw.value.kind === "hole") return raw.value.hole;
5
+ raw.report("invalid-binding", `${what} requires an expression value: ${raw.name}=\${…}`);
6
+ return -1;
7
+ }
8
+ var attribute = (raw, boolean) => ({
9
+ kind: "Attribute",
10
+ name: boolean ? raw.name.slice(1) : raw.name,
11
+ value: raw.value,
12
+ boolean,
13
+ loc: raw.loc
14
+ });
15
+ var CORE_DIRECTIVES = [
16
+ // Events: `@click=${h}`, `on:click=${h}` (native), `onClick=${h}`, each with
17
+ // optional dotted modifiers (`@click.capture.once`, `on:input.passive`).
18
+ {
19
+ id: "event",
20
+ match: (n) => n[0] === "@" || n.startsWith("on:") || /^on[A-Z]/.test(n),
21
+ build: (raw) => {
22
+ let syntax;
23
+ let rest;
24
+ if (raw.name[0] === "@") {
25
+ syntax = "at";
26
+ rest = raw.name.slice(1);
27
+ } else if (raw.name.startsWith("on:")) {
28
+ syntax = "colon";
29
+ rest = raw.name.slice(3);
30
+ } else {
31
+ syntax = "on";
32
+ rest = raw.name.slice(2);
33
+ }
34
+ const [raw_name, ...modifiers] = rest.split(".");
35
+ const name = raw_name.toLowerCase();
36
+ for (const m of modifiers) {
37
+ if (!EVENT_MODIFIERS.has(m)) {
38
+ raw.report("invalid-directive", `Unknown event modifier ".${m}" — expected one of ${[...EVENT_MODIFIERS].join(", ")}`);
39
+ }
40
+ }
41
+ return {
42
+ kind: "EventBinding",
43
+ name,
44
+ syntax,
45
+ modifiers,
46
+ hole: requireHole(raw, "event binding"),
47
+ loc: raw.loc
48
+ };
49
+ }
50
+ },
51
+ // Two-way binding: `bind:value=${signal}`.
52
+ {
53
+ id: "bind",
54
+ elementOnly: true,
55
+ match: (n) => n.startsWith("bind:"),
56
+ build: (raw) => ({
57
+ kind: "BindDirective",
58
+ name: raw.name.slice("bind:".length),
59
+ hole: requireHole(raw, "two-way binding"),
60
+ loc: raw.loc
61
+ })
62
+ },
63
+ // Dynamic class toggle: `class:active=${flag}`.
64
+ {
65
+ id: "class-directive",
66
+ elementOnly: true,
67
+ match: (n) => n.startsWith("class:"),
68
+ build: (raw) => ({
69
+ kind: "ClassDirective",
70
+ name: raw.name.slice("class:".length),
71
+ hole: requireHole(raw, "class directive"),
72
+ loc: raw.loc
73
+ })
74
+ },
75
+ // Dynamic style: `style:color=${c}`.
76
+ {
77
+ id: "style-directive",
78
+ elementOnly: true,
79
+ match: (n) => n.startsWith("style:"),
80
+ build: (raw) => ({
81
+ kind: "StyleDirective",
82
+ name: raw.name.slice("style:".length),
83
+ hole: requireHole(raw, "style directive"),
84
+ loc: raw.loc
85
+ })
86
+ },
87
+ // Load strategy: `load:visible[="200px"]`. Components only, an intrinsic element
88
+ // has no module to defer.
89
+ {
90
+ id: "load",
91
+ match: (n) => n.startsWith("load:"),
92
+ build: (raw) => {
93
+ if (raw.value && raw.value.kind !== "static") {
94
+ raw.report("invalid-binding", `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
95
+ }
96
+ return {
97
+ kind: "LoadDirective",
98
+ strategy: raw.name.slice("load:".length),
99
+ modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
100
+ ...raw.value && raw.value.kind !== "static" ? { dynamic: true } : {},
101
+ loc: raw.loc
102
+ };
103
+ }
104
+ },
105
+ // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
106
+ {
107
+ id: "use",
108
+ match: (n) => n === "use" || n.startsWith("use:"),
109
+ build: (raw) => {
110
+ const named = raw.name.startsWith("use:");
111
+ return {
112
+ kind: "UseDirective",
113
+ name: named ? raw.name.slice("use:".length) : null,
114
+ hole: raw.value && raw.value.kind === "hole" ? raw.value.hole : null,
115
+ loc: raw.loc
116
+ };
117
+ }
118
+ },
119
+ // Conditional rendering: `if=${cond}`.
120
+ {
121
+ id: "if",
122
+ elementOnly: true,
123
+ match: (n) => n === "if",
124
+ build: (raw) => ({
125
+ kind: "IfDirective",
126
+ hole: requireHole(raw, "if directive"),
127
+ loc: raw.loc
128
+ })
129
+ },
130
+ // Loop rendering: `each=${items}` (a sibling `key` folds in at parse time).
131
+ {
132
+ id: "each",
133
+ elementOnly: true,
134
+ match: (n) => n === "each",
135
+ build: (raw) => ({
136
+ kind: "EachDirective",
137
+ hole: requireHole(raw, "each directive"),
138
+ key: null,
139
+ loc: raw.loc
140
+ })
141
+ },
142
+ // `else` (valueless).
143
+ {
144
+ id: "else",
145
+ elementOnly: true,
146
+ match: (n) => n === "else",
147
+ build: (raw) => {
148
+ if (raw.value !== null) raw.report("invalid-directive", "`else` takes no value");
149
+ return { kind: "ElseDirective", loc: raw.loc };
150
+ }
151
+ },
152
+ // Ref binding: `ref=${el}`.
153
+ {
154
+ id: "ref",
155
+ match: (n) => n === "ref",
156
+ build: (raw) => ({
157
+ kind: "RefBinding",
158
+ hole: requireHole(raw, "ref binding"),
159
+ loc: raw.loc
160
+ })
161
+ },
162
+ // Property binding: `.currentTime=${t}`.
163
+ {
164
+ id: "property",
165
+ match: (n) => n[0] === ".",
166
+ build: (raw) => ({
167
+ kind: "PropertyBinding",
168
+ name: raw.name.slice(1),
169
+ hole: requireHole(raw, "property binding"),
170
+ loc: raw.loc
171
+ })
172
+ },
173
+ // Boolean attribute (lit `?disabled`): a plain attribute flagged boolean.
174
+ {
175
+ id: "boolean",
176
+ match: (n) => n[0] === "?",
177
+ build: (raw) => attribute(raw, true)
178
+ }
179
+ ];
180
+ function resolveAttribute(raw, directives = CORE_DIRECTIVES, ctx = { component: false }) {
181
+ for (const d of directives) {
182
+ if (d.elementOnly && ctx.component) continue;
183
+ if (d.match(raw.name)) return d.build(raw);
184
+ }
185
+ return attribute(raw, false);
186
+ }
187
+
188
+ export {
189
+ EVENT_MODIFIERS,
190
+ CORE_DIRECTIVES,
191
+ resolveAttribute
192
+ };
@@ -0,0 +1,26 @@
1
+ // src/ast.ts
2
+ function setParents(root) {
3
+ const visit = (node, parent) => {
4
+ node.parent = parent;
5
+ const kids = childrenOf(node);
6
+ for (const child of kids) visit(child, node);
7
+ };
8
+ visit(root, null);
9
+ return root;
10
+ }
11
+ function childrenOf(node) {
12
+ switch (node.kind) {
13
+ case "Root":
14
+ case "Element":
15
+ case "Component":
16
+ case "Fragment":
17
+ return node.children;
18
+ default:
19
+ return [];
20
+ }
21
+ }
22
+
23
+ export {
24
+ setParents,
25
+ childrenOf
26
+ };
@@ -0,0 +1,111 @@
1
+ // src/reader.ts
2
+ var Reader = class {
3
+ // offset within the current static piece
4
+ constructor(pieces) {
5
+ this.pieces = pieces;
6
+ this.pi = 0;
7
+ // current piece index
8
+ this.oi = 0;
9
+ this.normalize();
10
+ }
11
+ /** Skip fully-consumed static pieces so `current()` is live text or a hole. */
12
+ normalize() {
13
+ while (this.pi < this.pieces.length) {
14
+ const p = this.pieces[this.pi];
15
+ if (p.kind === "static" && this.oi >= p.text.length) {
16
+ this.pi++;
17
+ this.oi = 0;
18
+ continue;
19
+ }
20
+ break;
21
+ }
22
+ }
23
+ eof() {
24
+ return this.pi >= this.pieces.length;
25
+ }
26
+ /** Where the cursor is, to come back to with `reset`. */
27
+ mark() {
28
+ return [this.pi, this.oi];
29
+ }
30
+ /** Back to a position `mark` returned. */
31
+ reset([pi, oi]) {
32
+ this.pi = pi;
33
+ this.oi = oi;
34
+ }
35
+ /** Absolute source offset of the cursor. */
36
+ pos() {
37
+ if (this.eof()) {
38
+ const last = this.pieces[this.pieces.length - 1];
39
+ return last ? last.kind === "static" ? last.start + last.text.length : last.end : 0;
40
+ }
41
+ const p = this.pieces[this.pi];
42
+ return p.kind === "static" ? p.start + this.oi : p.start;
43
+ }
44
+ /** True when the cursor sits exactly on a hole marker. */
45
+ atHole() {
46
+ return !this.eof() && this.pieces[this.pi].kind === "hole";
47
+ }
48
+ /** True when advancing one char would land on a hole (e.g. the `<` in `<${Tag}`). */
49
+ holeFollows() {
50
+ if (this.eof()) return false;
51
+ const p = this.pieces[this.pi];
52
+ if (p.kind !== "static") return false;
53
+ if (this.oi + 1 < p.text.length) return false;
54
+ const next = this.pieces[this.pi + 1];
55
+ return next !== void 0 && next.kind === "hole";
56
+ }
57
+ /** Consume the hole at the cursor. Caller must have checked {@link atHole}. */
58
+ takeHole() {
59
+ const p = this.pieces[this.pi];
60
+ if (p.kind !== "hole") throw new Error("takeHole called off a hole");
61
+ this.pi++;
62
+ this.oi = 0;
63
+ this.normalize();
64
+ return { index: p.index, loc: { start: p.start, end: p.end } };
65
+ }
66
+ /** Char `k` ahead within the current static segment, or '' at a boundary/hole. */
67
+ peek(k = 0) {
68
+ if (this.eof()) return "";
69
+ const p = this.pieces[this.pi];
70
+ if (p.kind !== "static") return "";
71
+ return p.text[this.oi + k] ?? "";
72
+ }
73
+ /** Whether the current static segment starts with `s` at the cursor. */
74
+ startsWith(s) {
75
+ if (this.eof()) return false;
76
+ const p = this.pieces[this.pi];
77
+ if (p.kind !== "static") return false;
78
+ return p.text.startsWith(s, this.oi);
79
+ }
80
+ /** Advance one character inside the current static segment. */
81
+ advance() {
82
+ if (this.eof()) return "";
83
+ const p = this.pieces[this.pi];
84
+ if (p.kind !== "static") return "";
85
+ const ch = p.text[this.oi++] ?? "";
86
+ this.normalize();
87
+ return ch;
88
+ }
89
+ /** Advance while `pred` holds and we stay inside one static segment. */
90
+ readWhile(pred) {
91
+ let out = "";
92
+ while (!this.eof() && !this.atHole()) {
93
+ const ch = this.peek();
94
+ if (ch === "" || !pred(ch)) break;
95
+ out += ch;
96
+ this.oi++;
97
+ }
98
+ this.normalize();
99
+ return out;
100
+ }
101
+ skipWhitespace() {
102
+ this.readWhile((ch) => /\s/.test(ch));
103
+ }
104
+ span(start) {
105
+ return { start, end: this.pos() };
106
+ }
107
+ };
108
+
109
+ export {
110
+ Reader
111
+ };
@@ -115,12 +115,18 @@ var CORE_DIRECTIVES = [
115
115
  {
116
116
  id: "load",
117
117
  match: (n) => n.startsWith("load:"),
118
- build: (raw) => ({
119
- kind: "LoadDirective",
120
- strategy: raw.name.slice("load:".length),
121
- modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
122
- loc: raw.loc
123
- })
118
+ build: (raw) => {
119
+ if (raw.value && raw.value.kind !== "static") {
120
+ raw.report("invalid-binding", `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
121
+ }
122
+ return {
123
+ kind: "LoadDirective",
124
+ strategy: raw.name.slice("load:".length),
125
+ modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
126
+ ...raw.value && raw.value.kind !== "static" ? { dynamic: true } : {},
127
+ loc: raw.loc
128
+ };
129
+ }
124
130
  },
125
131
  // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
126
132
  {
@@ -1 +1 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../src/directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,iBAAiB,EAEjB,SAAS,EAGT,UAAU,EACV,cAAc,EAOd,UAAU,EAIX,MAAM,UAAU,CAAC;AAElB,mFAAmF;AACnF,eAAO,MAAM,eAAe,aAAqE,CAAC;AAElG,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC;IACpB,kCAAkC;IAClC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,UAAU,CAAC;IAChB,0DAA0D;IAC1D,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,iBAAiB,CAAC;CAC7C;AAED,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAkBD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,mBAAmB,EA4JhD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,YAAY,EACjB,UAAU,GAAE,mBAAmB,EAAoB,EACnD,GAAG,GAAE,WAAkC,GACtC,iBAAiB,CAMnB;AAED,YAAY,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../src/directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,iBAAiB,EAEjB,SAAS,EAGT,UAAU,EACV,cAAc,EAOd,UAAU,EAIX,MAAM,UAAU,CAAC;AAElB,mFAAmF;AACnF,eAAO,MAAM,eAAe,aAAqE,CAAC;AAElG,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC;IACpB,kCAAkC;IAClC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,UAAU,CAAC;IAChB,0DAA0D;IAC1D,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,iBAAiB,CAAC;CAC7C;AAED,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAkBD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,mBAAmB,EAoKhD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,YAAY,EACjB,UAAU,GAAE,mBAAmB,EAAoB,EACnD,GAAG,GAAE,WAAkC,GACtC,iBAAiB,CAMnB;AAED,YAAY,EAAE,UAAU,EAAE,CAAC"}
@@ -103,12 +103,20 @@ export const CORE_DIRECTIVES = [
103
103
  {
104
104
  id: 'load',
105
105
  match: (n) => n.startsWith('load:'),
106
- build: (raw) => ({
107
- kind: 'LoadDirective',
108
- strategy: raw.name.slice('load:'.length),
109
- modifier: raw.value && raw.value.kind === 'static' ? raw.value.value : null,
110
- loc: raw.loc,
111
- }),
106
+ build: (raw) => {
107
+ // The strategy is fixed at compile time: a hole would be dropped without a word, the
108
+ // way `load:visible=\${margin}` once lost its margin. Same rule, same words as in JSX.
109
+ if (raw.value && raw.value.kind !== 'static') {
110
+ raw.report('invalid-binding', `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
111
+ }
112
+ return {
113
+ kind: 'LoadDirective',
114
+ strategy: raw.name.slice('load:'.length),
115
+ modifier: raw.value && raw.value.kind === 'static' ? raw.value.value : null,
116
+ ...(raw.value && raw.value.kind !== 'static' ? { dynamic: true } : {}),
117
+ loc: raw.loc,
118
+ };
119
+ },
112
120
  },
113
121
  // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
114
122
  {
@@ -1,183 +1,8 @@
1
- // src/directives.ts
2
- var EVENT_MODIFIERS = /* @__PURE__ */ new Set(["capture", "once", "passive", "prevent", "stop", "self"]);
3
- function requireHole(raw, what) {
4
- if (raw.value && raw.value.kind === "hole") return raw.value.hole;
5
- raw.report("invalid-binding", `${what} requires an expression value: ${raw.name}=\${…}`);
6
- return -1;
7
- }
8
- var attribute = (raw, boolean) => ({
9
- kind: "Attribute",
10
- name: boolean ? raw.name.slice(1) : raw.name,
11
- value: raw.value,
12
- boolean,
13
- loc: raw.loc
14
- });
15
- var CORE_DIRECTIVES = [
16
- // Events: `@click=${h}`, `on:click=${h}` (native), `onClick=${h}`, each with
17
- // optional dotted modifiers (`@click.capture.once`, `on:input.passive`).
18
- {
19
- id: "event",
20
- match: (n) => n[0] === "@" || n.startsWith("on:") || /^on[A-Z]/.test(n),
21
- build: (raw) => {
22
- let syntax;
23
- let rest;
24
- if (raw.name[0] === "@") {
25
- syntax = "at";
26
- rest = raw.name.slice(1);
27
- } else if (raw.name.startsWith("on:")) {
28
- syntax = "colon";
29
- rest = raw.name.slice(3);
30
- } else {
31
- syntax = "on";
32
- rest = raw.name.slice(2);
33
- }
34
- const [raw_name, ...modifiers] = rest.split(".");
35
- const name = raw_name.toLowerCase();
36
- for (const m of modifiers) {
37
- if (!EVENT_MODIFIERS.has(m)) {
38
- raw.report("invalid-directive", `Unknown event modifier ".${m}" — expected one of ${[...EVENT_MODIFIERS].join(", ")}`);
39
- }
40
- }
41
- return {
42
- kind: "EventBinding",
43
- name,
44
- syntax,
45
- modifiers,
46
- hole: requireHole(raw, "event binding"),
47
- loc: raw.loc
48
- };
49
- }
50
- },
51
- // Two-way binding: `bind:value=${signal}`.
52
- {
53
- id: "bind",
54
- elementOnly: true,
55
- match: (n) => n.startsWith("bind:"),
56
- build: (raw) => ({
57
- kind: "BindDirective",
58
- name: raw.name.slice("bind:".length),
59
- hole: requireHole(raw, "two-way binding"),
60
- loc: raw.loc
61
- })
62
- },
63
- // Dynamic class toggle: `class:active=${flag}`.
64
- {
65
- id: "class-directive",
66
- elementOnly: true,
67
- match: (n) => n.startsWith("class:"),
68
- build: (raw) => ({
69
- kind: "ClassDirective",
70
- name: raw.name.slice("class:".length),
71
- hole: requireHole(raw, "class directive"),
72
- loc: raw.loc
73
- })
74
- },
75
- // Dynamic style: `style:color=${c}`.
76
- {
77
- id: "style-directive",
78
- elementOnly: true,
79
- match: (n) => n.startsWith("style:"),
80
- build: (raw) => ({
81
- kind: "StyleDirective",
82
- name: raw.name.slice("style:".length),
83
- hole: requireHole(raw, "style directive"),
84
- loc: raw.loc
85
- })
86
- },
87
- // Load strategy: `load:visible[="200px"]`. Components only, an intrinsic element
88
- // has no module to defer.
89
- {
90
- id: "load",
91
- match: (n) => n.startsWith("load:"),
92
- build: (raw) => ({
93
- kind: "LoadDirective",
94
- strategy: raw.name.slice("load:".length),
95
- modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
96
- loc: raw.loc
97
- })
98
- },
99
- // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
100
- {
101
- id: "use",
102
- match: (n) => n === "use" || n.startsWith("use:"),
103
- build: (raw) => {
104
- const named = raw.name.startsWith("use:");
105
- return {
106
- kind: "UseDirective",
107
- name: named ? raw.name.slice("use:".length) : null,
108
- hole: raw.value && raw.value.kind === "hole" ? raw.value.hole : null,
109
- loc: raw.loc
110
- };
111
- }
112
- },
113
- // Conditional rendering: `if=${cond}`.
114
- {
115
- id: "if",
116
- elementOnly: true,
117
- match: (n) => n === "if",
118
- build: (raw) => ({
119
- kind: "IfDirective",
120
- hole: requireHole(raw, "if directive"),
121
- loc: raw.loc
122
- })
123
- },
124
- // Loop rendering: `each=${items}` (a sibling `key` folds in at parse time).
125
- {
126
- id: "each",
127
- elementOnly: true,
128
- match: (n) => n === "each",
129
- build: (raw) => ({
130
- kind: "EachDirective",
131
- hole: requireHole(raw, "each directive"),
132
- key: null,
133
- loc: raw.loc
134
- })
135
- },
136
- // `else` (valueless).
137
- {
138
- id: "else",
139
- elementOnly: true,
140
- match: (n) => n === "else",
141
- build: (raw) => {
142
- if (raw.value !== null) raw.report("invalid-directive", "`else` takes no value");
143
- return { kind: "ElseDirective", loc: raw.loc };
144
- }
145
- },
146
- // Ref binding: `ref=${el}`.
147
- {
148
- id: "ref",
149
- match: (n) => n === "ref",
150
- build: (raw) => ({
151
- kind: "RefBinding",
152
- hole: requireHole(raw, "ref binding"),
153
- loc: raw.loc
154
- })
155
- },
156
- // Property binding: `.currentTime=${t}`.
157
- {
158
- id: "property",
159
- match: (n) => n[0] === ".",
160
- build: (raw) => ({
161
- kind: "PropertyBinding",
162
- name: raw.name.slice(1),
163
- hole: requireHole(raw, "property binding"),
164
- loc: raw.loc
165
- })
166
- },
167
- // Boolean attribute (lit `?disabled`): a plain attribute flagged boolean.
168
- {
169
- id: "boolean",
170
- match: (n) => n[0] === "?",
171
- build: (raw) => attribute(raw, true)
172
- }
173
- ];
174
- function resolveAttribute(raw, directives = CORE_DIRECTIVES, ctx = { component: false }) {
175
- for (const d of directives) {
176
- if (d.elementOnly && ctx.component) continue;
177
- if (d.match(raw.name)) return d.build(raw);
178
- }
179
- return attribute(raw, false);
180
- }
1
+ import {
2
+ CORE_DIRECTIVES,
3
+ EVENT_MODIFIERS,
4
+ resolveAttribute
5
+ } from "./chunk-IP5F3OXX.mjs";
181
6
  export {
182
7
  CORE_DIRECTIVES,
183
8
  EVENT_MODIFIERS,