@diso.io/hype 0.0.0-stage → 1.0.0-beta.1

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 CHANGED
@@ -1,3 +1,156 @@
1
- # Temporary Holding Version
1
+ # @diso.io/hype
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Signals, `html` templates and custom elements, drawn in the page or written to a
4
+ string. No dependencies, no compiler, about 4 KB gzipped.
5
+
6
+ ```ts
7
+ import { define, html, signal } from "@diso.io/hype";
8
+
9
+ define("x-counter", { props: { start: 0 } }, ({ start }) => {
10
+ const count = signal(start.value);
11
+ return html`
12
+ <button @click=${() => count.value++}>clicked ${() => count.value} times</button>
13
+ `;
14
+ });
15
+ ```
16
+
17
+ ```html
18
+ <x-counter start="3"></x-counter>
19
+ ```
20
+
21
+ ## Signals
22
+
23
+ A signal holds a value. Anything that reads it inside an effect or a template is
24
+ rerun when the value changes.
25
+
26
+ ```ts
27
+ import { computed, effect, onCleanup, signal } from "@diso.io/hype";
28
+
29
+ const name = signal("Ada");
30
+ const shout = computed(() => name.value.toUpperCase());
31
+
32
+ const stop = effect(() => {
33
+ console.log(shout.value);
34
+ onCleanup(() => console.log("before the next run, and on stop"));
35
+ });
36
+
37
+ name.value = "Grace";
38
+ ```
39
+
40
+ | | |
41
+ | --- | --- |
42
+ | `signal(value)` | A value to read and set through `.value`. |
43
+ | `computed(fn)` | A value worked out from other signals. Its readers rerun only when the result changes. |
44
+ | `effect(fn)` | Runs `fn` now and after any signal it read changes. Returns a function that stops it. |
45
+ | `onCleanup(fn)` | Inside an effect or an element: runs `fn` before the next run and on stop. |
46
+
47
+ Changes are batched: setting several signals in a row reruns each effect once,
48
+ in a microtask. An effect made inside another effect or an element stops with it.
49
+
50
+ ## Templates
51
+
52
+ `html` takes HTML with values in it. A value that is a **function** is live: it
53
+ is called again whenever a signal it reads changes, and only that place in the
54
+ page is updated. Any other value is placed once.
55
+
56
+ ```ts
57
+ html`<p class=${kind}>${() => count.value}</p>`;
58
+ ```
59
+
60
+ | Written | Does |
61
+ | --- | --- |
62
+ | `${value}` between tags | Content: text, a template, a DOM node, or a list of these. `null`, `undefined` and `false` draw nothing. |
63
+ | `name=${value}` | An attribute. `null` or `undefined` removes it. |
64
+ | `name="a ${value} b"` | An attribute made of text and values. |
65
+ | `?name=${value}` | A boolean attribute, present when the value is truthy. |
66
+ | `.name=${value}` | A property of the element. Use it to pass objects to a custom element. To pass a function itself, wrap it: `.name=${() => fn}`. |
67
+ | `@name=${handler}` | An event listener. |
68
+
69
+ `svg` is the same for a piece of SVG that goes inside an `<svg>`. `nothing` is a
70
+ value that draws nothing.
71
+
72
+ A function that returns a template rebuilds that piece each time it reruns. Keep
73
+ state such as a text input out of pieces that rebuild, by having the function
74
+ read a `computed` that changes less often and placing narrower functions inside:
75
+
76
+ ```ts
77
+ const failed = computed(() => error.value !== "");
78
+ html`${() => (failed.value ? html`<p role="alert">${() => error.value}</p>` : nothing)}`;
79
+ ```
80
+
81
+ A template is checked the first time it is drawn. A value where one cannot go —
82
+ as a tag name, loose inside a tag, inside a comment, or inside `<textarea>`,
83
+ `<style>`, `<script>` or `<title>` — throws an error that says so. A custom
84
+ element must be closed with its own closing tag.
85
+
86
+ `render(value, container)` draws a value into a container and returns a function
87
+ that stops its effects.
88
+
89
+ ## Elements
90
+
91
+ `define(name, options, setup)` defines a custom element. `setup` runs each time
92
+ the element enters the page and returns what to draw.
93
+
94
+ ```ts
95
+ import { css, define, html, onMount } from "@diso.io/hype";
96
+
97
+ define(
98
+ "x-card",
99
+ {
100
+ props: { heading: "", wide: false, item: null as Item | null },
101
+ styles: css`
102
+ h2 { margin: 0; }
103
+ `,
104
+ },
105
+ ({ heading, wide, item }, host) => {
106
+ onMount(() => host.querySelector("h2")?.focus());
107
+ return html`<h2>${() => heading.value}</h2><slot></slot>`;
108
+ },
109
+ );
110
+ ```
111
+
112
+ - **`props`** names the element's props and gives their defaults. `setup`
113
+ receives each one as a signal. A prop can be set as a property, or as an
114
+ attribute named in kebab-case (`videoId` is `video-id`). An attribute is read
115
+ as the type of the prop's default: a boolean is whether the attribute is
116
+ present, a number is parsed, anything else is the attribute's text.
117
+ - **`styles`** is CSS for the element alone. Giving it draws the element in a
118
+ shadow root, where content placed inside the element shows through `<slot>`.
119
+ `shadow: true` does the same without styles.
120
+ - Without `styles` or `shadow` the element draws directly inside itself, where
121
+ the page's own CSS applies, and replaces anything written inside it.
122
+ - **`onMount(fn)`** runs once the content is in the page. Call `onCleanup`
123
+ inside it to undo what it did.
124
+ - `host` is the element. It does not exist when rendering to a string, so use it
125
+ only inside `onMount` and event handlers.
126
+
127
+ Signals read directly in `setup` are not followed; `setup` runs once. An element
128
+ moved within the page keeps its state. One that leaves the page stops, and
129
+ starts again if it comes back.
130
+
131
+ ## Rendering to a string
132
+
133
+ `renderToString(value)` returns markup with every defined element's content
134
+ written inside it. It needs no DOM, so it runs in Node or a Worker.
135
+
136
+ ```ts
137
+ import { html, renderToString } from "@diso.io/hype";
138
+ import "./components";
139
+
140
+ const page = renderToString(html`<x-card heading="Hello">Welcome.</x-card>`);
141
+ ```
142
+
143
+ Its purpose is to give crawlers and first paint something to read. The page is
144
+ still an app: when the script loads, each element draws over what was written
145
+ for it. An element in a shadow root is written as a
146
+ [declarative shadow root](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template#shadowrootmode)
147
+ with its styles.
148
+
149
+ When rendering to a string, `setup` runs and `onCleanup` runs after it;
150
+ `onMount`, event listeners and effects that rerun belong to the page and do not.
151
+
152
+ ## What it does not do
153
+
154
+ - Reorder a list in place. A list drawn from a signal is redrawn when the signal
155
+ changes.
156
+ - Pass content into an element that has no shadow root.
@@ -0,0 +1,87 @@
1
+ /** A value that remembers the effects that read it and reruns them when it changes. */
2
+ interface Signal<T> {
3
+ value: T;
4
+ }
5
+ /** A value worked out from signals. */
6
+ interface Computed<T> {
7
+ readonly value: T;
8
+ }
9
+ export declare function signal<T>(initial: T): Signal<T>;
10
+ /**
11
+ * Run `fn` now, and again after any signal it read changes. Returns a function
12
+ * that stops it. An effect made inside another effect or an element stops with it.
13
+ */
14
+ export declare function effect(fn: () => void): () => void;
15
+ /**
16
+ * A value worked out from other signals. Its readers rerun only when the result
17
+ * changes, and a reader never sees a result older than the signals it came from.
18
+ */
19
+ export declare function computed<T>(fn: () => T): Computed<T>;
20
+ /** Run `fn` when the surrounding effect reruns or stops, or its element leaves the page. */
21
+ export declare function onCleanup(fn: () => void): void;
22
+ /** A custom element's props as signals, one for each name in its `props`. */
23
+ type Props<P> = { readonly [K in keyof P]: Signal<P[K]>; };
24
+ /**
25
+ * Runs each time the element enters the page and returns what to draw. `host`
26
+ * is the element itself; it does not exist when rendering to a string, so use
27
+ * it only inside `onMount` and event handlers.
28
+ */
29
+ type Setup<P> = (props: Props<P>, host: HTMLElement) => unknown;
30
+ interface Options<P> {
31
+ /**
32
+ * The element's props and their defaults. Each can be set as a property, or
33
+ * as an attribute named in kebab-case (`videoId` is `video-id`). An attribute
34
+ * is read as the type of its default: a boolean is whether the attribute is
35
+ * present, a number is parsed, anything else is the attribute's text.
36
+ */
37
+ props?: P;
38
+ /** CSS for the element alone. Giving it draws the element in a shadow root. */
39
+ styles?: string;
40
+ /** Draw in a shadow root, so content placed inside the element shows through `<slot>`. */
41
+ shadow?: boolean;
42
+ }
43
+ /**
44
+ * Run `fn` once the element's content is in the page. Call it inside `define`'s
45
+ * setup. It never runs when rendering to a string.
46
+ */
47
+ export declare function onMount(fn: () => void): void;
48
+ /** CSS as a string. A tag so editors highlight it; it does nothing else. */
49
+ export declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
50
+ /**
51
+ * Define a custom element. `setup` returns what to draw, and reads the
52
+ * element's props as signals.
53
+ *
54
+ * ```ts
55
+ * define("x-count", { props: { start: 0 } }, ({ start }) => {
56
+ * const count = signal(start.value);
57
+ * return html`<button @click=${() => count.value++}>${() => count.value}</button>`;
58
+ * });
59
+ * ```
60
+ */
61
+ export declare function define(name: string, setup: Setup<Record<never, never>>): void;
62
+ export declare function define<P extends Record<string, unknown>>(name: string, options: Options<P>, setup: Setup<P>): void;
63
+ /**
64
+ * Draw a value inside `container`, replacing what was there. Returns a function
65
+ * that stops its effects.
66
+ */
67
+ export declare function render(value: unknown, container: ParentNode): () => void;
68
+ /**
69
+ * A value as markup, with every defined element's own content written inside
70
+ * it. Needs no DOM. When the page loads, each element draws over what was
71
+ * written for it.
72
+ */
73
+ export declare function renderToString(value: unknown): string;
74
+ /** What `html` and `svg` return: the literal text of a template and the values between it. */
75
+ interface Template {
76
+ strings: TemplateStringsArray;
77
+ values: unknown[];
78
+ kind: "html" | "svg";
79
+ }
80
+ /** A template of HTML. A value that is a function is called again whenever a signal it reads changes. */
81
+ export declare function html(strings: TemplateStringsArray, ...values: unknown[]): Template;
82
+ /** A template of SVG elements to place inside an `<svg>`. */
83
+ export declare function svg(strings: TemplateStringsArray, ...values: unknown[]): Template;
84
+ /** A value that draws nothing. */
85
+ export declare const nothing: null;
86
+ export type { Computed, Options, Props, Setup, Signal, Template };
87
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/signals.ts","../src/define.ts","../src/dom.ts","../src/string.ts","../src/template.ts"],"mappings":";UAeiB,OAAO;EACvB,OAAO;;;UAIS,SAAS;WAChB,OAAO;;wBAgDD,OAAO,GAAG,SAAS,IAAI,OAAO;;;;;wBAmE9B,OAAO;;;;;wBAQP,SAAS,GAAG,UAAU,IAAI,SAAS;;wBAenC,UAAU;;KC3Jd,MAAM,iBAAiB,WAAW,IAAI,OAAO,EAAE;;;;;;KAO/C,MAAM,MAAM,OAAO,MAAM,IAAI,MAAM;UAE9B,QAAQ;;;;;;;EAOxB,QAAQ;;EAER;;EAEA;;;;;;wBAwCe,QAAQ;;wBAKR,IACf,SAAS,yBACN;;;;;;;;;;;;wBAgBY,OAAO,cAAc,OAAO,MAAM;wBAClC,OAAO,UAAU,yBAChC,cACA,SAAS,QAAQ,IACjB,OAAO,MAAM;;;;;wBCiEE,OAAO,gBAAgB,WAAW;;;;;;wBC7BlC,eAAe;;UC9Hd;EAChB,SAAS;EACT;EACA;;;wBAIe,KACf,SAAS,yBACN,oBACD;;wBAKa,IACf,SAAS,yBACN,oBACD;;qBAKU"}
package/dist/index.js ADDED
@@ -0,0 +1,729 @@
1
+ // src/signals.ts
2
+ /** The scope whose code is running now. */
3
+ let running = null;
4
+ /** Scopes waiting to rerun. Several changes in a row rerun each one once, in a microtask. */
5
+ const pending = /* @__PURE__ */ new Set();
6
+ let flushing = false;
7
+ /** How many reruns one flush may make before it is taken to be a loop. */
8
+ const LIMIT = 1e4;
9
+ function schedule(scope) {
10
+ if (pending.size === 0 && !flushing) queueMicrotask(flush);
11
+ pending.add(scope);
12
+ }
13
+ function flush() {
14
+ flushing = true;
15
+ let runs = 0;
16
+ let failed = false;
17
+ let failure;
18
+ try {
19
+ for (const scope of pending) {
20
+ pending.delete(scope);
21
+ runs += 1;
22
+ if (runs > LIMIT) {
23
+ pending.clear();
24
+ throw new Error("hype: effects keep changing the signals they read");
25
+ }
26
+ try {
27
+ scope.run();
28
+ } catch (error) {
29
+ if (!failed) {
30
+ failed = true;
31
+ failure = error;
32
+ }
33
+ }
34
+ }
35
+ } finally {
36
+ flushing = false;
37
+ }
38
+ if (failed) throw failure;
39
+ }
40
+ function signal(initial) {
41
+ let value = initial;
42
+ const readers = /* @__PURE__ */ new Set();
43
+ return {
44
+ get value() {
45
+ if (running?.tracks) {
46
+ readers.add(running);
47
+ running.reads.add(readers);
48
+ }
49
+ return value;
50
+ },
51
+ set value(next) {
52
+ if (Object.is(next, value)) return;
53
+ value = next;
54
+ for (const reader of readers) schedule(reader);
55
+ }
56
+ };
57
+ }
58
+ /**
59
+ * Make a scope and run it once. It belongs to `owner`, which stops it when the
60
+ * owner reruns or stops; with no owner it runs until `stop` is called.
61
+ */
62
+ function createScope(fn, tracks, owner = running) {
63
+ const clear = () => {
64
+ for (const readers of scope.reads) readers.delete(scope);
65
+ scope.reads.clear();
66
+ for (const inner of scope.inner.splice(0)) inner.stop();
67
+ for (const cleanup of scope.cleanups.splice(0)) cleanup();
68
+ };
69
+ const scope = {
70
+ tracks,
71
+ reads: /* @__PURE__ */ new Set(),
72
+ inner: [],
73
+ cleanups: [],
74
+ stopped: false,
75
+ run() {
76
+ if (scope.stopped) return;
77
+ clear();
78
+ const outer = running;
79
+ running = scope;
80
+ try {
81
+ fn();
82
+ } finally {
83
+ running = outer;
84
+ }
85
+ },
86
+ stop() {
87
+ if (scope.stopped) return;
88
+ scope.stopped = true;
89
+ pending.delete(scope);
90
+ clear();
91
+ }
92
+ };
93
+ owner?.inner.push(scope);
94
+ scope.run();
95
+ return scope;
96
+ }
97
+ /**
98
+ * Run `fn` now, and again after any signal it read changes. Returns a function
99
+ * that stops it. An effect made inside another effect or an element stops with it.
100
+ */
101
+ function effect(fn) {
102
+ return createScope(fn, true).stop;
103
+ }
104
+ /**
105
+ * A value worked out from other signals. Its readers rerun only when the result
106
+ * changes, and a reader never sees a result older than the signals it came from.
107
+ */
108
+ function computed(fn) {
109
+ const result = signal(void 0);
110
+ const scope = createScope(() => {
111
+ result.value = fn();
112
+ }, true);
113
+ return { get value() {
114
+ if (pending.delete(scope)) scope.run();
115
+ return result.value;
116
+ } };
117
+ }
118
+ /** Run `fn` when the surrounding effect reruns or stops, or its element leaves the page. */
119
+ function onCleanup(fn) {
120
+ running?.cleanups.push(fn);
121
+ }
122
+ // src/template.ts
123
+ /** A template of HTML. A value that is a function is called again whenever a signal it reads changes. */
124
+ function html(strings, ...values) {
125
+ return {
126
+ strings,
127
+ values,
128
+ kind: "html"
129
+ };
130
+ }
131
+ /** A template of SVG elements to place inside an `<svg>`. */
132
+ function svg(strings, ...values) {
133
+ return {
134
+ strings,
135
+ values,
136
+ kind: "svg"
137
+ };
138
+ }
139
+ /** A value that draws nothing. */
140
+ const nothing = null;
141
+ function isTemplate(value) {
142
+ return typeof value === "object" && value !== null && "strings" in value && "values" in value;
143
+ }
144
+ const compiled = /* @__PURE__ */ new WeakMap();
145
+ /** Elements whose content is text, where a value cannot be placed. */
146
+ const TEXT_ELEMENTS = /* @__PURE__ */ new Set([
147
+ "script",
148
+ "style",
149
+ "textarea",
150
+ "title"
151
+ ]);
152
+ const SPACE = /\s/;
153
+ const NAME_START = /[a-zA-Z]/;
154
+ const ENTITIES = {
155
+ amp: "&",
156
+ lt: "<",
157
+ gt: ">",
158
+ quot: "\"",
159
+ apos: "'"
160
+ };
161
+ const decode = (text) => text.replace(/&(amp|lt|gt|quot|apos|#39);/g, (_, name) => ENTITIES[name] ?? "'");
162
+ /**
163
+ * Read a template's literal text once and work out what each value is: content,
164
+ * or all or part of an attribute, a `?boolean`, a `.property` or an `@event`.
165
+ * Both renderers draw from the result.
166
+ */
167
+ function compile(strings) {
168
+ const cached = compiled.get(strings);
169
+ if (cached) return cached;
170
+ const tokens = [];
171
+ const parts = [];
172
+ const open = [];
173
+ let out = "";
174
+ let state = "text";
175
+ /** The text element we are inside, if any. */
176
+ let textElement = "";
177
+ let tagName = "";
178
+ let closing = false;
179
+ let attrs = {};
180
+ let tagParts = [];
181
+ /** Where in `tokens` the end of a custom element's content would go. */
182
+ let closeAt = 0;
183
+ let name = "";
184
+ let nameAt = 0;
185
+ let quote = "";
186
+ let valueText = "";
187
+ /** The literal pieces of the value so far, once it has a value in it. */
188
+ let pieces = null;
189
+ let valueAt = 0;
190
+ const fail = (message, index) => {
191
+ const before = strings.slice(0, index + 1).join("${…}");
192
+ throw new Error(`hype: ${message}, after: ${before.slice(-60)}`);
193
+ };
194
+ const flush = () => {
195
+ if (out) tokens.push(out);
196
+ out = "";
197
+ };
198
+ const endAttr = (index) => {
199
+ if (!pieces) {
200
+ attrs[name] = decode(valueText);
201
+ return;
202
+ }
203
+ pieces.push(valueText);
204
+ out = out.slice(0, nameAt);
205
+ flush();
206
+ const prefix = name[0];
207
+ if (prefix === "@" || prefix === "." || prefix === "?") {
208
+ if (pieces.length !== 2 || pieces[0] !== "" || pieces[1] !== "") fail(`${name} takes one value and nothing else`, index);
209
+ const kind = prefix === "@" ? "event" : prefix === "." ? "prop" : "bool";
210
+ parts.push({
211
+ kind,
212
+ name: name.slice(1),
213
+ at: valueAt
214
+ });
215
+ } else parts.push({
216
+ kind: "attr",
217
+ name,
218
+ at: valueAt,
219
+ strings: pieces
220
+ });
221
+ tagParts.push(parts.length - 1);
222
+ tokens.push({ part: parts.length - 1 });
223
+ pieces = null;
224
+ };
225
+ const endTag = (index) => {
226
+ out += ">";
227
+ state = "text";
228
+ const lower = tagName.toLowerCase();
229
+ if (closing) {
230
+ if (!lower.includes("-")) return;
231
+ const tag = open.pop();
232
+ if (tag?.name !== lower) fail(tag ? `<${tag.name}> is never closed` : `</${lower}> closes nothing`, index);
233
+ tokens.splice(closeAt, 0, { close: tag });
234
+ return;
235
+ }
236
+ if (TEXT_ELEMENTS.has(lower)) textElement = lower;
237
+ if (lower.includes("-")) {
238
+ const tag = {
239
+ name: lower,
240
+ attrs,
241
+ parts: tagParts
242
+ };
243
+ flush();
244
+ tokens.push({ open: tag });
245
+ open.push(tag);
246
+ }
247
+ };
248
+ strings.forEach((string, index) => {
249
+ for (let i = 0; i < string.length; i++) {
250
+ const char = string[i];
251
+ switch (state) {
252
+ case "text": {
253
+ if (char !== "<") {
254
+ out += char;
255
+ break;
256
+ }
257
+ if (textElement) {
258
+ const end = `</${textElement}`;
259
+ if (string.slice(i, i + end.length).toLowerCase() !== end) {
260
+ out += char;
261
+ break;
262
+ }
263
+ textElement = "";
264
+ }
265
+ const next = string[i + 1];
266
+ if (string.startsWith("!--", i + 1)) {
267
+ state = "comment";
268
+ out += char;
269
+ } else if (next === "/" || next && NAME_START.test(next)) {
270
+ closing = next === "/";
271
+ if (closing) {
272
+ flush();
273
+ closeAt = tokens.length;
274
+ }
275
+ state = "tag-name";
276
+ tagName = "";
277
+ attrs = {};
278
+ tagParts = [];
279
+ out += char;
280
+ } else if (next === void 0 && index < strings.length - 1) fail("a value cannot be a tag name", index);
281
+ else out += char;
282
+ break;
283
+ }
284
+ case "comment":
285
+ out += char;
286
+ if (char === ">" && out.endsWith("-->")) state = "text";
287
+ break;
288
+ case "tag-name":
289
+ if (char === ">") endTag(index);
290
+ else if (SPACE.test(char)) {
291
+ state = "in-tag";
292
+ out += char;
293
+ } else {
294
+ if (char !== "/") tagName += char;
295
+ out += char;
296
+ }
297
+ break;
298
+ case "in-tag":
299
+ case "after-name":
300
+ if (char === ">") endTag(index);
301
+ else if (char === "=" && state === "after-name") {
302
+ delete attrs[name];
303
+ state = "before-value";
304
+ out += char;
305
+ } else if (SPACE.test(char) || char === "/") out += char;
306
+ else {
307
+ state = "attr-name";
308
+ name = char;
309
+ nameAt = out.length;
310
+ out += char;
311
+ }
312
+ break;
313
+ case "attr-name":
314
+ if (char === "=") {
315
+ state = "before-value";
316
+ out += char;
317
+ } else if (char === ">") {
318
+ attrs[name] = "";
319
+ endTag(index);
320
+ } else if (SPACE.test(char) || char === "/") {
321
+ attrs[name] = "";
322
+ state = "after-name";
323
+ out += char;
324
+ } else {
325
+ name += char;
326
+ out += char;
327
+ }
328
+ break;
329
+ case "before-value":
330
+ if (char === ">") {
331
+ attrs[name] = "";
332
+ endTag(index);
333
+ } else if (SPACE.test(char)) out += char;
334
+ else {
335
+ state = "value";
336
+ quote = char === "\"" || char === "'" ? char : "";
337
+ valueText = quote ? "" : char;
338
+ out += char;
339
+ }
340
+ break;
341
+ case "value": if (quote ? char === quote : SPACE.test(char) || char === ">") {
342
+ const hadValues = pieces !== null;
343
+ endAttr(index);
344
+ state = "in-tag";
345
+ if (char === ">") endTag(index);
346
+ else if (!(hadValues && quote)) out += char;
347
+ } else {
348
+ valueText += char;
349
+ out += char;
350
+ }
351
+ }
352
+ }
353
+ if (index === strings.length - 1) return;
354
+ switch (state) {
355
+ case "text":
356
+ if (textElement) fail(`a value cannot go inside <${textElement}>; set a property such as .value or .textContent on it`, index);
357
+ flush();
358
+ parts.push({
359
+ kind: "node",
360
+ at: index
361
+ });
362
+ tokens.push({ part: parts.length - 1 });
363
+ break;
364
+ case "before-value":
365
+ state = "value";
366
+ quote = "";
367
+ valueText = "";
368
+ pieces = [""];
369
+ valueAt = index;
370
+ break;
371
+ case "value":
372
+ if (!pieces) valueAt = index;
373
+ pieces = [...pieces ?? [], valueText];
374
+ valueText = "";
375
+ break;
376
+ case "comment":
377
+ fail("a value cannot go inside a comment", index);
378
+ break;
379
+ case "tag-name":
380
+ fail("a value cannot be a tag name", index);
381
+ break;
382
+ default: fail("a value in a tag must be the value of an attribute, as in name=${value}", index);
383
+ }
384
+ });
385
+ if (state !== "text") fail("the template ends inside a tag", strings.length - 1);
386
+ if (open.length > 0) fail(`<${open[0]?.name}> is never closed`, strings.length - 1);
387
+ flush();
388
+ const joined = [];
389
+ for (const token of tokens) {
390
+ const last = joined.at(-1);
391
+ if (typeof token === "string" && typeof last === "string") joined[joined.length - 1] = last + token;
392
+ else joined.push(token);
393
+ }
394
+ const result = {
395
+ tokens: joined,
396
+ parts
397
+ };
398
+ compiled.set(strings, result);
399
+ return result;
400
+ }
401
+ /** Text for the page from any value. */
402
+ const text = (value) => typeof value === "string" ? value : String(value);
403
+ /** The values that belong to one part. */
404
+ const own = (part, values) => values.slice(part.at, part.at + (part.kind === "attr" ? part.strings.length - 1 : 1));
405
+ /**
406
+ * An attribute's value from its literal pieces and its own values. A lone value
407
+ * is kept as it is, so `null` can mean "no attribute"; otherwise they are joined.
408
+ */
409
+ function attributeValue(strings, values) {
410
+ if (strings.length === 2 && strings[0] === "" && strings[1] === "") return values[0];
411
+ return strings.reduce((joined, piece, i) => joined + text(values[i - 1] ?? "") + piece);
412
+ }
413
+ // src/dom.ts
414
+ /** The attribute that marks an element with a part on it, until the part is bound. */
415
+ const MARK = "hype:";
416
+ function element(template) {
417
+ const compiled = compile(template.strings);
418
+ if (compiled.element) return compiled.element;
419
+ const markup = compiled.tokens.map((token) => {
420
+ if (typeof token === "string") return token;
421
+ if (!("part" in token)) return "";
422
+ return compiled.parts[token.part]?.kind === "node" ? `<!--${MARK}${token.part}-->` : `${MARK}${token.part} `;
423
+ }).join("");
424
+ const made = document.createElement("template");
425
+ if (template.kind === "svg") {
426
+ made.innerHTML = `<svg>${markup}</svg>`;
427
+ const wrapper = made.content.firstChild;
428
+ wrapper.replaceWith(...wrapper.childNodes);
429
+ } else made.innerHTML = markup;
430
+ compiled.element = made;
431
+ return made;
432
+ }
433
+ /** A fresh copy of a template's elements with its values bound to them. */
434
+ function instantiate(template) {
435
+ const { parts } = compile(template.strings);
436
+ const fragment = document.importNode(element(template).content, true);
437
+ const targets = [];
438
+ const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
439
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
440
+ if (node.nodeType === Node.COMMENT_NODE) {
441
+ const { data } = node;
442
+ if (data.startsWith(MARK)) targets[Number(data.slice(5))] = node;
443
+ continue;
444
+ }
445
+ const marked = node;
446
+ for (const name of marked.getAttributeNames()) {
447
+ if (!name.startsWith(MARK)) continue;
448
+ targets[Number(name.slice(5))] = node;
449
+ marked.removeAttribute(name);
450
+ }
451
+ }
452
+ parts.forEach((part, index) => bind(targets[index], part, template.values));
453
+ return fragment;
454
+ }
455
+ const isFunction = (value) => typeof value === "function";
456
+ /** Apply a value now or, when it is a function, now and after any signal it reads changes. */
457
+ function follow(value, apply) {
458
+ if (isFunction(value)) effect(() => apply(value()));
459
+ else apply(value);
460
+ }
461
+ function bind(target, part, values) {
462
+ if (part.kind === "node") {
463
+ content(target, values[part.at]);
464
+ return;
465
+ }
466
+ const host = target;
467
+ const value = values[part.at];
468
+ if (part.kind === "event") {
469
+ if (value) host.addEventListener(part.name, value);
470
+ } else if (part.kind === "prop") follow(value, (next) => {
471
+ host[part.name] = next;
472
+ });
473
+ else if (part.kind === "bool") follow(value, (next) => host.toggleAttribute(part.name, Boolean(next)));
474
+ else {
475
+ const mine = own(part, values);
476
+ const apply = (now) => {
477
+ const next = attributeValue(part.strings, now);
478
+ if (next == null) host.removeAttribute(part.name);
479
+ else host.setAttribute(part.name, text(next));
480
+ };
481
+ if (mine.some(isFunction)) effect(() => apply(mine.map((v) => isFunction(v) ? v() : v)));
482
+ else apply(mine);
483
+ }
484
+ }
485
+ const isText = (value) => typeof value === "string" || typeof value === "number" || typeof value === "bigint";
486
+ /**
487
+ * Put a value before `end`. A function's output is replaced after any signal it
488
+ * reads changes; when it is text both times, the text node is kept and updated.
489
+ */
490
+ function content(end, value) {
491
+ if (!isFunction(value)) {
492
+ end.before(...nodes(value));
493
+ return;
494
+ }
495
+ const start = document.createComment("");
496
+ end.before(start);
497
+ effect(() => {
498
+ const next = value();
499
+ const only = start.nextSibling;
500
+ if (isText(next) && only.nodeType === Node.TEXT_NODE && only.nextSibling === end) {
501
+ only.data = text(next);
502
+ return;
503
+ }
504
+ while (start.nextSibling !== end) start.nextSibling.remove();
505
+ end.before(...nodes(next));
506
+ });
507
+ }
508
+ /** The nodes a value draws as. */
509
+ function nodes(value) {
510
+ if (value == null || value === false) return [];
511
+ if (value instanceof Node) return [value];
512
+ if (Array.isArray(value)) return value.flatMap(nodes);
513
+ if (isTemplate(value)) return [...instantiate(value).childNodes];
514
+ if (!isFunction(value)) return [document.createTextNode(text(value))];
515
+ const fragment = document.createDocumentFragment();
516
+ content(fragment.appendChild(document.createComment("")), value);
517
+ return [...fragment.childNodes];
518
+ }
519
+ /**
520
+ * Draw a value inside `container`, replacing what was there. Returns a function
521
+ * that stops its effects.
522
+ */
523
+ function render(value, container) {
524
+ return createScope(() => container.replaceChildren(...nodes(value)), false, null).stop;
525
+ }
526
+ // src/define.ts
527
+ /** Every element defined, by tag name. The string renderer draws from it. */
528
+ const definitions = /* @__PURE__ */ new Map();
529
+ const kebab = (name) => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
530
+ const camel = (name) => name.replace(/-(\w)/g, (_, letter) => letter.toUpperCase());
531
+ /** A prop's value from an attribute's text, read as the type of the prop's default. */
532
+ function fromAttribute(text, fallback) {
533
+ if (typeof fallback === "boolean") return text !== null;
534
+ if (text === null) return fallback;
535
+ if (typeof fallback === "number") return Number(text);
536
+ return text;
537
+ }
538
+ function makeProps(defaults) {
539
+ return Object.fromEntries(Object.entries(defaults).map(([name, value]) => [name, signal(value)]));
540
+ }
541
+ let mounts = null;
542
+ /**
543
+ * Run `fn` once the element's content is in the page. Call it inside `define`'s
544
+ * setup. It never runs when rendering to a string.
545
+ */
546
+ function onMount(fn) {
547
+ mounts?.push(fn);
548
+ }
549
+ /** CSS as a string. A tag so editors highlight it; it does nothing else. */
550
+ function css(strings, ...values) {
551
+ return String.raw({ raw: strings }, ...values);
552
+ }
553
+ function define(name, first, second) {
554
+ const options = typeof first === "function" ? {} : first;
555
+ const setup = typeof first === "function" ? first : second;
556
+ const defaults = options.props ?? {};
557
+ const styles = options.styles ?? "";
558
+ const shadow = options.shadow ?? styles !== "";
559
+ definitions.set(name, {
560
+ defaults,
561
+ styles,
562
+ shadow,
563
+ setup
564
+ });
565
+ if (typeof customElements === "undefined") return;
566
+ const names = Object.keys(defaults);
567
+ let sheet;
568
+ /** Each element's props. Kept here so the property accessors below can reach them. */
569
+ const all = /* @__PURE__ */ new WeakMap();
570
+ const propsOf = (host) => all.get(host);
571
+ class Host extends HTMLElement {
572
+ static observedAttributes = names.map(kebab);
573
+ #stop;
574
+ constructor() {
575
+ super();
576
+ all.set(this, makeProps(defaults));
577
+ }
578
+ attributeChangedCallback(attribute, _, value) {
579
+ const name = camel(attribute);
580
+ const prop = propsOf(this)[name];
581
+ if (prop) prop.value = fromAttribute(value, defaults[name]);
582
+ }
583
+ connectedCallback() {
584
+ if (this.#stop) return;
585
+ if (this.ownerDocument.readyState === "loading") {
586
+ this.ownerDocument.addEventListener("DOMContentLoaded", () => {
587
+ if (this.isConnected) this.connectedCallback();
588
+ }, { once: true });
589
+ return;
590
+ }
591
+ const self = this;
592
+ for (const name of names) {
593
+ if (!Object.hasOwn(this, name)) continue;
594
+ const value = self[name];
595
+ delete self[name];
596
+ self[name] = value;
597
+ }
598
+ const root = shadow ? this.shadowRoot ?? this.attachShadow({ mode: "open" }) : this;
599
+ if (styles && root instanceof ShadowRoot) {
600
+ if (!sheet) {
601
+ sheet = new CSSStyleSheet();
602
+ sheet.replaceSync(styles);
603
+ }
604
+ root.adoptedStyleSheets = [sheet];
605
+ }
606
+ this.#stop = createScope(() => {
607
+ const outer = mounts;
608
+ const mounted = [];
609
+ mounts = mounted;
610
+ let drawn;
611
+ try {
612
+ drawn = setup(propsOf(this), this);
613
+ } finally {
614
+ mounts = outer;
615
+ }
616
+ root.replaceChildren(...nodes(drawn));
617
+ for (const fn of mounted) fn();
618
+ }, false, null).stop;
619
+ }
620
+ disconnectedCallback() {
621
+ queueMicrotask(() => {
622
+ if (this.isConnected) return;
623
+ this.#stop?.();
624
+ this.#stop = void 0;
625
+ });
626
+ }
627
+ }
628
+ for (const name of names) Object.defineProperty(Host.prototype, name, {
629
+ get() {
630
+ return propsOf(this)[name]?.value;
631
+ },
632
+ set(value) {
633
+ const prop = propsOf(this)[name];
634
+ if (prop) prop.value = value;
635
+ }
636
+ });
637
+ customElements.define(name, Host);
638
+ }
639
+ // src/string.ts
640
+ const ESCAPES = {
641
+ "&": "&amp;",
642
+ "<": "&lt;",
643
+ ">": "&gt;",
644
+ "\"": "&quot;"
645
+ };
646
+ const escape = (value) => text(value).replace(/[&<>"]/g, (char) => ESCAPES[char]);
647
+ /** A value on a tag as it is now: a function is called for what it returns. */
648
+ const read = (value) => typeof value === "function" ? value() : value;
649
+ function markup(value) {
650
+ let now = value;
651
+ while (typeof now === "function") now = now();
652
+ if (now == null || now === false) return "";
653
+ if (Array.isArray(now)) return now.map(markup).join("");
654
+ if (!isTemplate(now)) return escape(now);
655
+ return templateMarkup(now);
656
+ }
657
+ function partMarkup(part, values) {
658
+ if (part.kind === "node") return markup(values[part.at]);
659
+ if (part.kind === "event" || part.kind === "prop") return "";
660
+ if (part.kind === "bool") return read(values[part.at]) ? part.name : "";
661
+ const value = attributeValue(part.strings, own(part, values).map(read));
662
+ if (value == null) return "";
663
+ return `${part.name}="${escape(value)}"`;
664
+ }
665
+ /** The props a custom element would have in the page, from what is written on its tag. */
666
+ function tagProps(tag, parts, values, { defaults }) {
667
+ const props = makeProps(defaults);
668
+ const setAttribute = (name, value) => {
669
+ const prop = props[camel(name)];
670
+ if (prop) prop.value = fromAttribute(value, defaults[camel(name)]);
671
+ };
672
+ for (const [name, value] of Object.entries(tag.attrs)) setAttribute(name, value);
673
+ for (const index of tag.parts) {
674
+ const part = parts[index];
675
+ if (part.kind === "event" || part.kind === "node") continue;
676
+ if (part.kind === "prop") {
677
+ const prop = props[part.name];
678
+ if (prop) prop.value = read(values[part.at]);
679
+ } else if (part.kind === "bool") setAttribute(part.name, read(values[part.at]) ? "" : null);
680
+ else {
681
+ const value = attributeValue(part.strings, own(part, values).map(read));
682
+ setAttribute(part.name, value == null ? null : text(value));
683
+ }
684
+ }
685
+ return props;
686
+ }
687
+ function templateMarkup(template) {
688
+ const { tokens, parts } = compile(template.strings);
689
+ let out = "";
690
+ /** The element whose written content is being left out, because it draws its own. */
691
+ let replacing = null;
692
+ for (const token of tokens) {
693
+ if (replacing) {
694
+ if (typeof token === "object" && "close" in token && token.close === replacing) replacing = null;
695
+ continue;
696
+ }
697
+ if (typeof token === "string") out += token;
698
+ else if ("part" in token) out += partMarkup(parts[token.part], template.values);
699
+ else if ("open" in token) {
700
+ const definition = definitions.get(token.open.name);
701
+ if (!definition) continue;
702
+ const props = tagProps(token.open, parts, template.values, definition);
703
+ const drawn = markup(definition.setup(props, void 0));
704
+ if (definition.shadow) {
705
+ const style = definition.styles ? `<style>${definition.styles}</style>` : "";
706
+ out += `<template shadowrootmode="open">${style}${drawn}</template>`;
707
+ } else {
708
+ out += drawn;
709
+ replacing = token.open;
710
+ }
711
+ }
712
+ }
713
+ return out;
714
+ }
715
+ /**
716
+ * A value as markup, with every defined element's own content written inside
717
+ * it. Needs no DOM. When the page loads, each element draws over what was
718
+ * written for it.
719
+ */
720
+ function renderToString(value) {
721
+ let out = "";
722
+ createScope(() => {
723
+ out = markup(value);
724
+ }, false, null).stop();
725
+ return out;
726
+ }
727
+ export { computed, css, define, effect, html, nothing, onCleanup, onMount, render, renderToString, signal, svg };
728
+
729
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/signals.ts","../src/template.ts","../src/dom.ts","../src/define.ts","../src/string.ts"],"sourcesContent":["/** Code that reruns: an effect, a computed value, or the root of an element. */\nexport interface Scope {\n\t/** Whether reading a signal inside it subscribes it to that signal. */\n\ttracks: boolean;\n\t/** The reader sets of the signals it read on its last run. */\n\treads: Set<Set<Scope>>;\n\t/** Scopes created while it ran. They stop when it reruns or stops. */\n\tinner: Scope[];\n\tcleanups: Array<() => void>;\n\tstopped: boolean;\n\trun: () => void;\n\tstop: () => void;\n}\n\n/** A value that remembers the effects that read it and reruns them when it changes. */\nexport interface Signal<T> {\n\tvalue: T;\n}\n\n/** A value worked out from signals. */\nexport interface Computed<T> {\n\treadonly value: T;\n}\n\n/** The scope whose code is running now. */\nlet running: Scope | null = null;\n\n/** Scopes waiting to rerun. Several changes in a row rerun each one once, in a microtask. */\nconst pending = new Set<Scope>();\nlet flushing = false;\n\n/** How many reruns one flush may make before it is taken to be a loop. */\nconst LIMIT = 10_000;\n\nfunction schedule(scope: Scope): void {\n\tif (pending.size === 0 && !flushing) queueMicrotask(flush);\n\tpending.add(scope);\n}\n\nfunction flush(): void {\n\tflushing = true;\n\tlet runs = 0;\n\tlet failed = false;\n\tlet failure: unknown;\n\ttry {\n\t\t// A scope scheduled while this runs joins the same pass.\n\t\tfor (const scope of pending) {\n\t\t\tpending.delete(scope);\n\t\t\truns += 1;\n\t\t\tif (runs > LIMIT) {\n\t\t\t\tpending.clear();\n\t\t\t\tthrow new Error(\"hype: effects keep changing the signals they read\");\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tscope.run();\n\t\t\t} catch (error) {\n\t\t\t\t// One failing effect does not stop the others; the first failure is reported.\n\t\t\t\tif (!failed) {\n\t\t\t\t\tfailed = true;\n\t\t\t\t\tfailure = error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} finally {\n\t\tflushing = false;\n\t}\n\tif (failed) throw failure;\n}\n\nexport function signal<T>(initial: T): Signal<T> {\n\tlet value = initial;\n\tconst readers = new Set<Scope>();\n\treturn {\n\t\tget value() {\n\t\t\tif (running?.tracks) {\n\t\t\t\treaders.add(running);\n\t\t\t\trunning.reads.add(readers);\n\t\t\t}\n\t\t\treturn value;\n\t\t},\n\t\tset value(next) {\n\t\t\tif (Object.is(next, value)) return;\n\t\t\tvalue = next;\n\t\t\tfor (const reader of readers) schedule(reader);\n\t\t},\n\t};\n}\n\n/**\n * Make a scope and run it once. It belongs to `owner`, which stops it when the\n * owner reruns or stops; with no owner it runs until `stop` is called.\n */\nexport function createScope(\n\tfn: () => void,\n\ttracks: boolean,\n\towner: Scope | null = running,\n): Scope {\n\tconst clear = (): void => {\n\t\tfor (const readers of scope.reads) readers.delete(scope);\n\t\tscope.reads.clear();\n\t\tfor (const inner of scope.inner.splice(0)) inner.stop();\n\t\tfor (const cleanup of scope.cleanups.splice(0)) cleanup();\n\t};\n\tconst scope: Scope = {\n\t\ttracks,\n\t\treads: new Set(),\n\t\tinner: [],\n\t\tcleanups: [],\n\t\tstopped: false,\n\t\trun() {\n\t\t\tif (scope.stopped) return;\n\t\t\tclear();\n\t\t\tconst outer = running;\n\t\t\trunning = scope;\n\t\t\ttry {\n\t\t\t\tfn();\n\t\t\t} finally {\n\t\t\t\trunning = outer;\n\t\t\t}\n\t\t},\n\t\tstop() {\n\t\t\tif (scope.stopped) return;\n\t\t\tscope.stopped = true;\n\t\t\tpending.delete(scope);\n\t\t\tclear();\n\t\t},\n\t};\n\towner?.inner.push(scope);\n\tscope.run();\n\treturn scope;\n}\n\n/**\n * Run `fn` now, and again after any signal it read changes. Returns a function\n * that stops it. An effect made inside another effect or an element stops with it.\n */\nexport function effect(fn: () => void): () => void {\n\treturn createScope(fn, true).stop;\n}\n\n/**\n * A value worked out from other signals. Its readers rerun only when the result\n * changes, and a reader never sees a result older than the signals it came from.\n */\nexport function computed<T>(fn: () => T): Computed<T> {\n\tconst result = signal<T>(undefined as T);\n\tconst scope = createScope(() => {\n\t\tresult.value = fn();\n\t}, true);\n\treturn {\n\t\tget value() {\n\t\t\t// A signal it read has changed and it has not rerun yet: work it out now.\n\t\t\tif (pending.delete(scope)) scope.run();\n\t\t\treturn result.value;\n\t\t},\n\t};\n}\n\n/** Run `fn` when the surrounding effect reruns or stops, or its element leaves the page. */\nexport function onCleanup(fn: () => void): void {\n\trunning?.cleanups.push(fn);\n}\n","/** What `html` and `svg` return: the literal text of a template and the values between it. */\nexport interface Template {\n\tstrings: TemplateStringsArray;\n\tvalues: unknown[];\n\tkind: \"html\" | \"svg\";\n}\n\n/** A template of HTML. A value that is a function is called again whenever a signal it reads changes. */\nexport function html(\n\tstrings: TemplateStringsArray,\n\t...values: unknown[]\n): Template {\n\treturn { strings, values, kind: \"html\" };\n}\n\n/** A template of SVG elements to place inside an `<svg>`. */\nexport function svg(\n\tstrings: TemplateStringsArray,\n\t...values: unknown[]\n): Template {\n\treturn { strings, values, kind: \"svg\" };\n}\n\n/** A value that draws nothing. */\nexport const nothing = null;\n\nexport function isTemplate(value: unknown): value is Template {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"strings\" in value &&\n\t\t\"values\" in value\n\t);\n}\n\n/** One place in a template that takes values. `at` is the index of its first value. */\nexport type Part =\n\t| { kind: \"node\"; at: number }\n\t/** An attribute. `strings` are the literal pieces of its value; a value goes between each pair. */\n\t| { kind: \"attr\"; name: string; at: number; strings: string[] }\n\t/** `?name`: an attribute that is present or absent. */\n\t| { kind: \"bool\"; name: string; at: number }\n\t/** `.name`: a property of the element. */\n\t| { kind: \"prop\"; name: string; at: number }\n\t/** `@name`: an event listener. */\n\t| { kind: \"event\"; name: string; at: number };\n\n/** A custom element's opening tag, as written in a template. */\nexport interface Tag {\n\tname: string;\n\t/** Attributes written literally, with no values in them. */\n\tattrs: Record<string, string>;\n\t/** Indexes of the parts on this tag. */\n\tparts: number[];\n}\n\n/**\n * A template in order: literal text, the parts, and where each custom\n * element's content begins (`open`) and ends (`close`).\n */\nexport type Token = string | { part: number } | { open: Tag } | { close: Tag };\n\nexport interface Compiled {\n\ttokens: Token[];\n\tparts: Part[];\n\t/** The template as an element, made by the page renderer the first time it is drawn. */\n\telement?: HTMLTemplateElement;\n}\n\nconst compiled = new WeakMap<TemplateStringsArray, Compiled>();\n\n/** Elements whose content is text, where a value cannot be placed. */\nconst TEXT_ELEMENTS = new Set([\"script\", \"style\", \"textarea\", \"title\"]);\n\nconst SPACE = /\\s/;\nconst NAME_START = /[a-zA-Z]/;\n\nconst ENTITIES: Record<string, string> = {\n\tamp: \"&\",\n\tlt: \"<\",\n\tgt: \">\",\n\tquot: '\"',\n\tapos: \"'\",\n};\nconst decode = (text: string): string =>\n\ttext.replace(\n\t\t/&(amp|lt|gt|quot|apos|#39);/g,\n\t\t(_, name: string) => ENTITIES[name] ?? \"'\",\n\t);\n\ntype State =\n\t| \"text\"\n\t| \"comment\"\n\t| \"tag-name\"\n\t| \"in-tag\"\n\t| \"attr-name\"\n\t| \"after-name\"\n\t| \"before-value\"\n\t| \"value\";\n\n/**\n * Read a template's literal text once and work out what each value is: content,\n * or all or part of an attribute, a `?boolean`, a `.property` or an `@event`.\n * Both renderers draw from the result.\n */\nexport function compile(strings: TemplateStringsArray): Compiled {\n\tconst cached = compiled.get(strings);\n\tif (cached) return cached;\n\n\tconst tokens: Token[] = [];\n\tconst parts: Part[] = [];\n\tconst open: Tag[] = [];\n\tlet out = \"\";\n\tlet state: State = \"text\";\n\t/** The text element we are inside, if any. */\n\tlet textElement = \"\";\n\n\t// The tag being read.\n\tlet tagName = \"\";\n\tlet closing = false;\n\tlet attrs: Record<string, string> = {};\n\tlet tagParts: number[] = [];\n\t/** Where in `tokens` the end of a custom element's content would go. */\n\tlet closeAt = 0;\n\n\t// The attribute being read.\n\tlet name = \"\";\n\tlet nameAt = 0;\n\tlet quote = \"\";\n\tlet valueText = \"\";\n\t/** The literal pieces of the value so far, once it has a value in it. */\n\tlet pieces: string[] | null = null;\n\tlet valueAt = 0;\n\n\tconst fail = (message: string, index: number): never => {\n\t\tconst before = strings.slice(0, index + 1).join(\"${…}\");\n\t\tthrow new Error(`hype: ${message}, after: ${before.slice(-60)}`);\n\t};\n\n\tconst flush = (): void => {\n\t\tif (out) tokens.push(out);\n\t\tout = \"\";\n\t};\n\n\tconst endAttr = (index: number): void => {\n\t\tif (!pieces) {\n\t\t\tattrs[name] = decode(valueText);\n\t\t\treturn;\n\t\t}\n\t\tpieces.push(valueText);\n\t\t// Leave the attribute out of the literal text: the renderers write it.\n\t\tout = out.slice(0, nameAt);\n\t\tflush();\n\t\tconst prefix = name[0];\n\t\tif (prefix === \"@\" || prefix === \".\" || prefix === \"?\") {\n\t\t\tif (pieces.length !== 2 || pieces[0] !== \"\" || pieces[1] !== \"\") {\n\t\t\t\tfail(`${name} takes one value and nothing else`, index);\n\t\t\t}\n\t\t\tconst kind = prefix === \"@\" ? \"event\" : prefix === \".\" ? \"prop\" : \"bool\";\n\t\t\tparts.push({ kind, name: name.slice(1), at: valueAt });\n\t\t} else {\n\t\t\tparts.push({ kind: \"attr\", name, at: valueAt, strings: pieces });\n\t\t}\n\t\ttagParts.push(parts.length - 1);\n\t\ttokens.push({ part: parts.length - 1 });\n\t\tpieces = null;\n\t};\n\n\tconst endTag = (index: number): void => {\n\t\tout += \">\";\n\t\tstate = \"text\";\n\t\tconst lower = tagName.toLowerCase();\n\t\tif (closing) {\n\t\t\tif (!lower.includes(\"-\")) return;\n\t\t\tconst tag = open.pop();\n\t\t\tif (tag?.name !== lower) {\n\t\t\t\tfail(\n\t\t\t\t\ttag ? `<${tag.name}> is never closed` : `</${lower}> closes nothing`,\n\t\t\t\t\tindex,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Nothing has been added since the \"<\" of this tag, so this is where the content ends.\n\t\t\ttokens.splice(closeAt, 0, { close: tag as Tag });\n\t\t\treturn;\n\t\t}\n\t\tif (TEXT_ELEMENTS.has(lower)) textElement = lower;\n\t\tif (lower.includes(\"-\")) {\n\t\t\tconst tag: Tag = { name: lower, attrs, parts: tagParts };\n\t\t\tflush();\n\t\t\ttokens.push({ open: tag });\n\t\t\topen.push(tag);\n\t\t}\n\t};\n\n\tstrings.forEach((string, index) => {\n\t\tfor (let i = 0; i < string.length; i++) {\n\t\t\tconst char = string[i] as string;\n\t\t\tswitch (state) {\n\t\t\t\tcase \"text\": {\n\t\t\t\t\tif (char !== \"<\") {\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (textElement) {\n\t\t\t\t\t\tconst end = `</${textElement}`;\n\t\t\t\t\t\tif (string.slice(i, i + end.length).toLowerCase() !== end) {\n\t\t\t\t\t\t\tout += char;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttextElement = \"\";\n\t\t\t\t\t}\n\t\t\t\t\tconst next = string[i + 1];\n\t\t\t\t\tif (string.startsWith(\"!--\", i + 1)) {\n\t\t\t\t\t\tstate = \"comment\";\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else if (next === \"/\" || (next && NAME_START.test(next))) {\n\t\t\t\t\t\tclosing = next === \"/\";\n\t\t\t\t\t\tif (closing) {\n\t\t\t\t\t\t\tflush();\n\t\t\t\t\t\t\tcloseAt = tokens.length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate = \"tag-name\";\n\t\t\t\t\t\ttagName = \"\";\n\t\t\t\t\t\tattrs = {};\n\t\t\t\t\t\ttagParts = [];\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else if (next === undefined && index < strings.length - 1) {\n\t\t\t\t\t\tfail(\"a value cannot be a tag name\", index);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"comment\":\n\t\t\t\t\tout += char;\n\t\t\t\t\tif (char === \">\" && out.endsWith(\"-->\")) state = \"text\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"tag-name\":\n\t\t\t\t\tif (char === \">\") endTag(index);\n\t\t\t\t\telse if (SPACE.test(char)) {\n\t\t\t\t\t\tstate = \"in-tag\";\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (char !== \"/\") tagName += char;\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"in-tag\":\n\t\t\t\tcase \"after-name\":\n\t\t\t\t\tif (char === \">\") endTag(index);\n\t\t\t\t\telse if (char === \"=\" && state === \"after-name\") {\n\t\t\t\t\t\tdelete attrs[name];\n\t\t\t\t\t\tstate = \"before-value\";\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else if (SPACE.test(char) || char === \"/\") {\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate = \"attr-name\";\n\t\t\t\t\t\tname = char;\n\t\t\t\t\t\tnameAt = out.length;\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"attr-name\":\n\t\t\t\t\tif (char === \"=\") {\n\t\t\t\t\t\tstate = \"before-value\";\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else if (char === \">\") {\n\t\t\t\t\t\tattrs[name] = \"\";\n\t\t\t\t\t\tendTag(index);\n\t\t\t\t\t} else if (SPACE.test(char) || char === \"/\") {\n\t\t\t\t\t\tattrs[name] = \"\";\n\t\t\t\t\t\tstate = \"after-name\";\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tname += char;\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"before-value\":\n\t\t\t\t\tif (char === \">\") {\n\t\t\t\t\t\tattrs[name] = \"\";\n\t\t\t\t\t\tendTag(index);\n\t\t\t\t\t} else if (SPACE.test(char)) {\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate = \"value\";\n\t\t\t\t\t\tquote = char === '\"' || char === \"'\" ? char : \"\";\n\t\t\t\t\t\tvalueText = quote ? \"\" : char;\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"value\":\n\t\t\t\t\tif (quote ? char === quote : SPACE.test(char) || char === \">\") {\n\t\t\t\t\t\tconst hadValues = pieces !== null;\n\t\t\t\t\t\tendAttr(index);\n\t\t\t\t\t\tstate = \"in-tag\";\n\t\t\t\t\t\tif (char === \">\") endTag(index);\n\t\t\t\t\t\telse if (!(hadValues && quote)) out += char;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueText += char;\n\t\t\t\t\t\tout += char;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index === strings.length - 1) return;\n\n\t\t// A value goes here.\n\t\tswitch (state) {\n\t\t\tcase \"text\":\n\t\t\t\tif (textElement) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\t`a value cannot go inside <${textElement}>; set a property such as .value or .textContent on it`,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tflush();\n\t\t\t\tparts.push({ kind: \"node\", at: index });\n\t\t\t\ttokens.push({ part: parts.length - 1 });\n\t\t\t\tbreak;\n\t\t\tcase \"before-value\":\n\t\t\t\tstate = \"value\";\n\t\t\t\tquote = \"\";\n\t\t\t\tvalueText = \"\";\n\t\t\t\tpieces = [\"\"];\n\t\t\t\tvalueAt = index;\n\t\t\t\tbreak;\n\t\t\tcase \"value\":\n\t\t\t\tif (!pieces) valueAt = index;\n\t\t\t\tpieces = [...(pieces ?? []), valueText];\n\t\t\t\tvalueText = \"\";\n\t\t\t\tbreak;\n\t\t\tcase \"comment\":\n\t\t\t\tfail(\"a value cannot go inside a comment\", index);\n\t\t\t\tbreak;\n\t\t\tcase \"tag-name\":\n\t\t\t\tfail(\"a value cannot be a tag name\", index);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tfail(\n\t\t\t\t\t\"a value in a tag must be the value of an attribute, as in name=${value}\",\n\t\t\t\t\tindex,\n\t\t\t\t);\n\t\t}\n\t});\n\n\tif (state !== \"text\")\n\t\tfail(\"the template ends inside a tag\", strings.length - 1);\n\tif (open.length > 0) {\n\t\tfail(`<${open[0]?.name}> is never closed`, strings.length - 1);\n\t}\n\tflush();\n\n\t// Literal text that was cut where a closing tag began reads as one piece again.\n\tconst joined: Token[] = [];\n\tfor (const token of tokens) {\n\t\tconst last = joined.at(-1);\n\t\tif (typeof token === \"string\" && typeof last === \"string\") {\n\t\t\tjoined[joined.length - 1] = last + token;\n\t\t} else {\n\t\t\tjoined.push(token);\n\t\t}\n\t}\n\n\tconst result: Compiled = { tokens: joined, parts };\n\tcompiled.set(strings, result);\n\treturn result;\n}\n\n/** Text for the page from any value. */\nexport const text = (value: unknown): string =>\n\ttypeof value === \"string\" ? value : String(value as number);\n\n/** The values that belong to one part. */\nexport const own = (part: Part, values: unknown[]): unknown[] =>\n\tvalues.slice(\n\t\tpart.at,\n\t\tpart.at + (part.kind === \"attr\" ? part.strings.length - 1 : 1),\n\t);\n\n/**\n * An attribute's value from its literal pieces and its own values. A lone value\n * is kept as it is, so `null` can mean \"no attribute\"; otherwise they are joined.\n */\nexport function attributeValue(strings: string[], values: unknown[]): unknown {\n\tif (strings.length === 2 && strings[0] === \"\" && strings[1] === \"\") {\n\t\treturn values[0];\n\t}\n\treturn strings.reduce(\n\t\t(joined, piece, i) => joined + text(values[i - 1] ?? \"\") + piece,\n\t);\n}\n","import { createScope, effect } from \"./signals\";\nimport {\n\tattributeValue,\n\tcompile,\n\tisTemplate,\n\town,\n\ttype Part,\n\ttype Template,\n\ttext,\n} from \"./template\";\n\n/** The attribute that marks an element with a part on it, until the part is bound. */\nconst MARK = \"hype:\";\n\nfunction element(template: Template): HTMLTemplateElement {\n\tconst compiled = compile(template.strings);\n\tif (compiled.element) return compiled.element;\n\tconst markup = compiled.tokens\n\t\t.map((token) => {\n\t\t\tif (typeof token === \"string\") return token;\n\t\t\tif (!(\"part\" in token)) return \"\";\n\t\t\treturn compiled.parts[token.part]?.kind === \"node\"\n\t\t\t\t? `<!--${MARK}${token.part}-->`\n\t\t\t\t: `${MARK}${token.part} `;\n\t\t})\n\t\t.join(\"\");\n\tconst made = document.createElement(\"template\");\n\tif (template.kind === \"svg\") {\n\t\t// Parsed inside an <svg> so the elements are SVG elements, then lifted out of it.\n\t\tmade.innerHTML = `<svg>${markup}</svg>`;\n\t\tconst wrapper = made.content.firstChild as Element;\n\t\twrapper.replaceWith(...wrapper.childNodes);\n\t} else {\n\t\tmade.innerHTML = markup;\n\t}\n\tcompiled.element = made;\n\treturn made;\n}\n\n/** A fresh copy of a template's elements with its values bound to them. */\nfunction instantiate(template: Template): DocumentFragment {\n\tconst { parts } = compile(template.strings);\n\t// importNode, not cloneNode: custom elements are upgraded before their properties are set.\n\tconst fragment = document.importNode(element(template).content, true);\n\tconst targets: Node[] = [];\n\tconst walker = document.createTreeWalker(\n\t\tfragment,\n\t\tNodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT,\n\t);\n\tfor (let node = walker.nextNode(); node; node = walker.nextNode()) {\n\t\tif (node.nodeType === Node.COMMENT_NODE) {\n\t\t\tconst { data } = node as Comment;\n\t\t\tif (data.startsWith(MARK))\n\t\t\t\ttargets[Number(data.slice(MARK.length))] = node;\n\t\t\tcontinue;\n\t\t}\n\t\tconst marked = node as Element;\n\t\tfor (const name of marked.getAttributeNames()) {\n\t\t\tif (!name.startsWith(MARK)) continue;\n\t\t\ttargets[Number(name.slice(MARK.length))] = node;\n\t\t\tmarked.removeAttribute(name);\n\t\t}\n\t}\n\tparts.forEach((part, index) =>\n\t\tbind(targets[index] as Node, part, template.values),\n\t);\n\treturn fragment;\n}\n\nconst isFunction = (value: unknown): value is (...args: never[]) => unknown =>\n\ttypeof value === \"function\";\n\n/** Apply a value now or, when it is a function, now and after any signal it reads changes. */\nfunction follow(value: unknown, apply: (value: unknown) => void): void {\n\tif (isFunction(value)) effect(() => apply(value()));\n\telse apply(value);\n}\n\nfunction bind(target: Node, part: Part, values: unknown[]): void {\n\tif (part.kind === \"node\") {\n\t\tcontent(target as Comment, values[part.at]);\n\t\treturn;\n\t}\n\tconst host = target as Element;\n\tconst value = values[part.at];\n\tif (part.kind === \"event\") {\n\t\tif (value) host.addEventListener(part.name, value as EventListener);\n\t} else if (part.kind === \"prop\") {\n\t\tfollow(value, (next) => {\n\t\t\t(host as unknown as Record<string, unknown>)[part.name] = next;\n\t\t});\n\t} else if (part.kind === \"bool\") {\n\t\tfollow(value, (next) => host.toggleAttribute(part.name, Boolean(next)));\n\t} else {\n\t\tconst mine = own(part, values);\n\t\tconst apply = (now: unknown[]): void => {\n\t\t\tconst next = attributeValue(part.strings, now);\n\t\t\tif (next == null) host.removeAttribute(part.name);\n\t\t\telse host.setAttribute(part.name, text(next));\n\t\t};\n\t\tif (mine.some(isFunction)) {\n\t\t\teffect(() => apply(mine.map((v) => (isFunction(v) ? v() : v))));\n\t\t} else {\n\t\t\tapply(mine);\n\t\t}\n\t}\n}\n\nconst isText = (value: unknown): value is string | number | bigint =>\n\ttypeof value === \"string\" ||\n\ttypeof value === \"number\" ||\n\ttypeof value === \"bigint\";\n\n/**\n * Put a value before `end`. A function's output is replaced after any signal it\n * reads changes; when it is text both times, the text node is kept and updated.\n */\nfunction content(end: Comment, value: unknown): void {\n\tif (!isFunction(value)) {\n\t\tend.before(...nodes(value));\n\t\treturn;\n\t}\n\tconst start = document.createComment(\"\");\n\tend.before(start);\n\teffect(() => {\n\t\tconst next = value();\n\t\tconst only = start.nextSibling as Node;\n\t\tif (\n\t\t\tisText(next) &&\n\t\t\tonly.nodeType === Node.TEXT_NODE &&\n\t\t\tonly.nextSibling === end\n\t\t) {\n\t\t\t(only as Text).data = text(next);\n\t\t\treturn;\n\t\t}\n\t\twhile (start.nextSibling !== end) (start.nextSibling as ChildNode).remove();\n\t\tend.before(...nodes(next));\n\t});\n}\n\n/** The nodes a value draws as. */\nexport function nodes(value: unknown): Node[] {\n\tif (value == null || value === false) return [];\n\tif (value instanceof Node) return [value];\n\tif (Array.isArray(value)) return value.flatMap(nodes);\n\tif (isTemplate(value)) return [...instantiate(value).childNodes];\n\tif (!isFunction(value)) return [document.createTextNode(text(value))];\n\tconst fragment = document.createDocumentFragment();\n\tcontent(fragment.appendChild(document.createComment(\"\")), value);\n\treturn [...fragment.childNodes];\n}\n\n/**\n * Draw a value inside `container`, replacing what was there. Returns a function\n * that stops its effects.\n */\nexport function render(value: unknown, container: ParentNode): () => void {\n\treturn createScope(\n\t\t() => container.replaceChildren(...nodes(value)),\n\t\tfalse,\n\t\tnull,\n\t).stop;\n}\n","import { nodes } from \"./dom\";\nimport { createScope, type Signal, signal } from \"./signals\";\n\n/** A custom element's props as signals, one for each name in its `props`. */\nexport type Props<P> = { readonly [K in keyof P]: Signal<P[K]> };\n\n/**\n * Runs each time the element enters the page and returns what to draw. `host`\n * is the element itself; it does not exist when rendering to a string, so use\n * it only inside `onMount` and event handlers.\n */\nexport type Setup<P> = (props: Props<P>, host: HTMLElement) => unknown;\n\nexport interface Options<P> {\n\t/**\n\t * The element's props and their defaults. Each can be set as a property, or\n\t * as an attribute named in kebab-case (`videoId` is `video-id`). An attribute\n\t * is read as the type of its default: a boolean is whether the attribute is\n\t * present, a number is parsed, anything else is the attribute's text.\n\t */\n\tprops?: P;\n\t/** CSS for the element alone. Giving it draws the element in a shadow root. */\n\tstyles?: string;\n\t/** Draw in a shadow root, so content placed inside the element shows through `<slot>`. */\n\tshadow?: boolean;\n}\n\nexport interface Definition {\n\tdefaults: Record<string, unknown>;\n\tstyles: string;\n\tshadow: boolean;\n\tsetup: Setup<Record<string, unknown>>;\n}\n\n/** Every element defined, by tag name. The string renderer draws from it. */\nexport const definitions = new Map<string, Definition>();\n\nconst kebab = (name: string): string =>\n\tname.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\nexport const camel = (name: string): string =>\n\tname.replace(/-(\\w)/g, (_, letter: string) => letter.toUpperCase());\n\n/** A prop's value from an attribute's text, read as the type of the prop's default. */\nexport function fromAttribute(text: string | null, fallback: unknown): unknown {\n\tif (typeof fallback === \"boolean\") return text !== null;\n\tif (text === null) return fallback;\n\tif (typeof fallback === \"number\") return Number(text);\n\treturn text;\n}\n\nexport function makeProps(\n\tdefaults: Record<string, unknown>,\n): Record<string, Signal<unknown>> {\n\treturn Object.fromEntries(\n\t\tObject.entries(defaults).map(([name, value]) => [name, signal(value)]),\n\t);\n}\n\nlet mounts: Array<() => void> | null = null;\n\n/**\n * Run `fn` once the element's content is in the page. Call it inside `define`'s\n * setup. It never runs when rendering to a string.\n */\nexport function onMount(fn: () => void): void {\n\tmounts?.push(fn);\n}\n\n/** CSS as a string. A tag so editors highlight it; it does nothing else. */\nexport function css(\n\tstrings: TemplateStringsArray,\n\t...values: unknown[]\n): string {\n\treturn String.raw({ raw: strings }, ...values);\n}\n\n/**\n * Define a custom element. `setup` returns what to draw, and reads the\n * element's props as signals.\n *\n * ```ts\n * define(\"x-count\", { props: { start: 0 } }, ({ start }) => {\n * const count = signal(start.value);\n * return html`<button @click=${() => count.value++}>${() => count.value}</button>`;\n * });\n * ```\n */\nexport function define(name: string, setup: Setup<Record<never, never>>): void;\nexport function define<P extends Record<string, unknown>>(\n\tname: string,\n\toptions: Options<P>,\n\tsetup: Setup<P>,\n): void;\nexport function define(\n\tname: string,\n\tfirst: Options<Record<string, unknown>> | Setup<Record<string, unknown>>,\n\tsecond?: Setup<Record<string, unknown>>,\n): void {\n\tconst options = typeof first === \"function\" ? {} : first;\n\tconst setup = (typeof first === \"function\" ? first : second) as Setup<\n\t\tRecord<string, unknown>\n\t>;\n\tconst defaults = options.props ?? {};\n\tconst styles = options.styles ?? \"\";\n\tconst shadow = options.shadow ?? styles !== \"\";\n\tdefinitions.set(name, { defaults, styles, shadow, setup });\n\tif (typeof customElements === \"undefined\") return;\n\n\tconst names = Object.keys(defaults);\n\tlet sheet: CSSStyleSheet | undefined;\n\t/** Each element's props. Kept here so the property accessors below can reach them. */\n\tconst all = new WeakMap<HTMLElement, Record<string, Signal<unknown>>>();\n\tconst propsOf = (host: HTMLElement): Record<string, Signal<unknown>> =>\n\t\tall.get(host) as Record<string, Signal<unknown>>;\n\n\tclass Host extends HTMLElement {\n\t\tstatic observedAttributes = names.map(kebab);\n\t\t#stop?: () => void;\n\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tall.set(this, makeProps(defaults));\n\t\t}\n\n\t\tattributeChangedCallback(\n\t\t\tattribute: string,\n\t\t\t_: string | null,\n\t\t\tvalue: string | null,\n\t\t): void {\n\t\t\tconst name = camel(attribute);\n\t\t\tconst prop = propsOf(this)[name];\n\t\t\tif (prop) prop.value = fromAttribute(value, defaults[name]);\n\t\t}\n\n\t\tconnectedCallback(): void {\n\t\t\t// Moved within the page: it never stopped.\n\t\t\tif (this.#stop) return;\n\t\t\t// The page is still being read, so markup written for this element may not\n\t\t\t// all be here yet. Draw once it is, so that drawing replaces all of it.\n\t\t\tif (this.ownerDocument.readyState === \"loading\") {\n\t\t\t\tthis.ownerDocument.addEventListener(\n\t\t\t\t\t\"DOMContentLoaded\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (this.isConnected) this.connectedCallback();\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A property set before the element was defined sits on the element itself, hiding the prop.\n\t\t\tconst self = this as unknown as Record<string, unknown>;\n\t\t\tfor (const name of names) {\n\t\t\t\tif (!Object.hasOwn(this, name)) continue;\n\t\t\t\tconst value = self[name];\n\t\t\t\tdelete self[name];\n\t\t\t\tself[name] = value;\n\t\t\t}\n\t\t\tconst root = shadow\n\t\t\t\t? (this.shadowRoot ?? this.attachShadow({ mode: \"open\" }))\n\t\t\t\t: this;\n\t\t\tif (styles && root instanceof ShadowRoot) {\n\t\t\t\tif (!sheet) {\n\t\t\t\t\tsheet = new CSSStyleSheet();\n\t\t\t\t\tsheet.replaceSync(styles);\n\t\t\t\t}\n\t\t\t\troot.adoptedStyleSheets = [sheet];\n\t\t\t}\n\t\t\tthis.#stop = createScope(\n\t\t\t\t() => {\n\t\t\t\t\tconst outer = mounts;\n\t\t\t\t\tconst mounted: Array<() => void> = [];\n\t\t\t\t\tmounts = mounted;\n\t\t\t\t\tlet drawn: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdrawn = setup(propsOf(this), this);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tmounts = outer;\n\t\t\t\t\t}\n\t\t\t\t\t// Replaces markup the string renderer wrote here, and anything else inside.\n\t\t\t\t\troot.replaceChildren(...nodes(drawn));\n\t\t\t\t\tfor (const fn of mounted) fn();\n\t\t\t\t},\n\t\t\t\tfalse,\n\t\t\t\tnull,\n\t\t\t).stop;\n\t\t}\n\n\t\tdisconnectedCallback(): void {\n\t\t\t// A move is a removal followed at once by an insertion, so wait to see which this is.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (this.isConnected) return;\n\t\t\t\tthis.#stop?.();\n\t\t\t\tthis.#stop = undefined;\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const name of names) {\n\t\tObject.defineProperty(Host.prototype, name, {\n\t\t\tget(this: Host) {\n\t\t\t\treturn propsOf(this)[name]?.value;\n\t\t\t},\n\t\t\tset(this: Host, value: unknown) {\n\t\t\t\tconst prop = propsOf(this)[name];\n\t\t\t\tif (prop) prop.value = value;\n\t\t\t},\n\t\t});\n\t}\n\tcustomElements.define(name, Host);\n}\n","import {\n\tcamel,\n\ttype Definition,\n\tdefinitions,\n\tfromAttribute,\n\tmakeProps,\n} from \"./define\";\nimport { createScope, type Signal } from \"./signals\";\nimport {\n\tattributeValue,\n\tcompile,\n\tisTemplate,\n\town,\n\ttype Part,\n\ttype Tag,\n\ttype Template,\n\ttext,\n} from \"./template\";\n\nconst ESCAPES: Record<string, string> = {\n\t\"&\": \"&amp;\",\n\t\"<\": \"&lt;\",\n\t\">\": \"&gt;\",\n\t'\"': \"&quot;\",\n};\nconst escape = (value: unknown): string =>\n\ttext(value).replace(/[&<>\"]/g, (char) => ESCAPES[char] as string);\n\n/** A value on a tag as it is now: a function is called for what it returns. */\nconst read = (value: unknown): unknown =>\n\ttypeof value === \"function\" ? (value as () => unknown)() : value;\n\nfunction markup(value: unknown): string {\n\t// Content may be a function that returns a function, as the page renderer allows.\n\tlet now = value;\n\twhile (typeof now === \"function\") now = (now as () => unknown)();\n\tif (now == null || now === false) return \"\";\n\tif (Array.isArray(now)) return now.map(markup).join(\"\");\n\tif (!isTemplate(now)) return escape(now);\n\treturn templateMarkup(now);\n}\n\nfunction partMarkup(part: Part, values: unknown[]): string {\n\tif (part.kind === \"node\") return markup(values[part.at]);\n\t// Listeners and properties exist only in the page.\n\tif (part.kind === \"event\" || part.kind === \"prop\") return \"\";\n\tif (part.kind === \"bool\") return read(values[part.at]) ? part.name : \"\";\n\tconst value = attributeValue(part.strings, own(part, values).map(read));\n\tif (value == null) return \"\";\n\treturn `${part.name}=\"${escape(value)}\"`;\n}\n\n/** The props a custom element would have in the page, from what is written on its tag. */\nfunction tagProps(\n\ttag: Tag,\n\tparts: Part[],\n\tvalues: unknown[],\n\t{ defaults }: Definition,\n): Record<string, Signal<unknown>> {\n\tconst props = makeProps(defaults);\n\tconst setAttribute = (name: string, value: string | null): void => {\n\t\tconst prop = props[camel(name)];\n\t\tif (prop) prop.value = fromAttribute(value, defaults[camel(name)]);\n\t};\n\tfor (const [name, value] of Object.entries(tag.attrs)) {\n\t\tsetAttribute(name, value);\n\t}\n\tfor (const index of tag.parts) {\n\t\tconst part = parts[index] as Part;\n\t\tif (part.kind === \"event\" || part.kind === \"node\") continue;\n\t\tif (part.kind === \"prop\") {\n\t\t\tconst prop = props[part.name];\n\t\t\tif (prop) prop.value = read(values[part.at]);\n\t\t} else if (part.kind === \"bool\") {\n\t\t\tsetAttribute(part.name, read(values[part.at]) ? \"\" : null);\n\t\t} else {\n\t\t\tconst value = attributeValue(part.strings, own(part, values).map(read));\n\t\t\tsetAttribute(part.name, value == null ? null : text(value));\n\t\t}\n\t}\n\treturn props;\n}\n\nfunction templateMarkup(template: Template): string {\n\tconst { tokens, parts } = compile(template.strings);\n\tlet out = \"\";\n\t/** The element whose written content is being left out, because it draws its own. */\n\tlet replacing: Tag | null = null;\n\tfor (const token of tokens) {\n\t\tif (replacing) {\n\t\t\tif (\n\t\t\t\ttypeof token === \"object\" &&\n\t\t\t\t\"close\" in token &&\n\t\t\t\ttoken.close === replacing\n\t\t\t) {\n\t\t\t\treplacing = null;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof token === \"string\") {\n\t\t\tout += token;\n\t\t} else if (\"part\" in token) {\n\t\t\tout += partMarkup(parts[token.part] as Part, template.values);\n\t\t} else if (\"open\" in token) {\n\t\t\tconst definition = definitions.get(token.open.name);\n\t\t\tif (!definition) continue;\n\t\t\tconst props = tagProps(token.open, parts, template.values, definition);\n\t\t\tconst drawn = markup(definition.setup(props, undefined as never));\n\t\t\tif (definition.shadow) {\n\t\t\t\tconst style = definition.styles\n\t\t\t\t\t? `<style>${definition.styles}</style>`\n\t\t\t\t\t: \"\";\n\t\t\t\tout += `<template shadowrootmode=\"open\">${style}${drawn}</template>`;\n\t\t\t} else {\n\t\t\t\tout += drawn;\n\t\t\t\treplacing = token.open;\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n * A value as markup, with every defined element's own content written inside\n * it. Needs no DOM. When the page loads, each element draws over what was\n * written for it.\n */\nexport function renderToString(value: unknown): string {\n\tlet out = \"\";\n\t// Effects and computed values made while rendering stop when it is done.\n\tcreateScope(\n\t\t() => {\n\t\t\tout = markup(value);\n\t\t},\n\t\tfalse,\n\t\tnull,\n\t).stop();\n\treturn out;\n}\n"],"mappings":";;AAyBA,IAAI,UAAwB;;AAG5B,MAAM,0BAAU,IAAI,IAAW;AAC/B,IAAI,WAAW;;AAGf,MAAM,QAAQ;AAEd,SAAS,SAAS,OAAoB;CACrC,IAAI,QAAQ,SAAS,KAAK,CAAC,UAAU,eAAe,KAAK;CACzD,QAAQ,IAAI,KAAK;AAClB;AAEA,SAAS,QAAc;CACtB,WAAW;CACX,IAAI,OAAO;CACX,IAAI,SAAS;CACb,IAAI;CACJ,IAAI;EAEH,KAAK,MAAM,SAAS,SAAS;GAC5B,QAAQ,OAAO,KAAK;GACpB,QAAQ;GACR,IAAI,OAAO,OAAO;IACjB,QAAQ,MAAM;IACd,MAAM,IAAI,MAAM,mDAAmD;GACpE;GACA,IAAI;IACH,MAAM,IAAI;GACX,SAAS,OAAO;IAEf,IAAI,CAAC,QAAQ;KACZ,SAAS;KACT,UAAU;IACX;GACD;EACD;CACD,UAAU;EACT,WAAW;CACZ;CACA,IAAI,QAAQ,MAAM;AACnB;AAEA,SAAgB,OAAU,SAAuB;CAChD,IAAI,QAAQ;CACZ,MAAM,0BAAU,IAAI,IAAW;CAC/B,OAAO;EACN,IAAI,QAAQ;GACX,IAAI,SAAS,QAAQ;IACpB,QAAQ,IAAI,OAAO;IACnB,QAAQ,MAAM,IAAI,OAAO;GAC1B;GACA,OAAO;EACR;EACA,IAAI,MAAM,MAAM;GACf,IAAI,OAAO,GAAG,MAAM,KAAK,GAAG;GAC5B,QAAQ;GACR,KAAK,MAAM,UAAU,SAAS,SAAS,MAAM;EAC9C;CACD;AACD;;;;;AAMA,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CAAC,IAAI,IAAI,CAAC;GACtE,aAAa,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,KAAK,CAAC;EAC3D;CACD;CACA,OAAO;AACR;AAEA,SAAS,eAAe,UAA4B;CACnD,MAAM,EAAE,QAAQ,UAAU,QAAQ,SAAS,OAAO;CAClD,IAAI,MAAM;;CAEV,IAAI,YAAwB;CAC5B,KAAK,MAAM,SAAS,QAAQ;EAC3B,IAAI,WAAW;GACd,IACC,OAAO,UAAU,YACjB,WAAW,SACX,MAAM,UAAU,WAEhB,YAAY;GAEb;EACD;EACA,IAAI,OAAO,UAAU,UACpB,OAAO;OACD,IAAI,UAAU,OACpB,OAAO,WAAW,MAAM,MAAM,OAAe,SAAS,MAAM;OACtD,IAAI,UAAU,OAAO;GAC3B,MAAM,aAAa,YAAY,IAAI,MAAM,KAAK,IAAI;GAClD,IAAI,CAAC,YAAY;GACjB,MAAM,QAAQ,SAAS,MAAM,MAAM,OAAO,SAAS,QAAQ,UAAU;GACrE,MAAM,QAAQ,OAAO,WAAW,MAAM,OAAO,KAAA,CAAkB,CAAC;GAChE,IAAI,WAAW,QAAQ;IACtB,MAAM,QAAQ,WAAW,SACtB,UAAU,WAAW,OAAO,YAC5B;IACH,OAAO,mCAAmC,QAAQ,MAAM;GACzD,OAAO;IACN,OAAO;IACP,YAAY,MAAM;GACnB;EACD;CACD;CACA,OAAO;AACR;;;;;;AAOA,SAAgB,eAAe,OAAwB;CACtD,IAAI,MAAM;CAEV,kBACO;EACL,MAAM,OAAO,KAAK;CACnB,GACA,OACA,IACD,CAAC,CAAC,KAAK;CACP,OAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@diso.io/hype",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Signals, html templates and custom elements that draw in the page or to a string",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "Stephen Handley",
9
+ "email": "stephen@hello10.com",
10
+ "url": "https://hello10.com"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/Hello10/diso.git",
15
+ "directory": "packages/hype"
16
+ },
17
+ "keywords": [
18
+ "signals",
19
+ "templates",
20
+ "web-components",
21
+ "custom-elements",
22
+ "static-rendering",
23
+ "diso"
24
+ ],
25
+ "sideEffects": false,
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "main": "./dist/index.js",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "devDependencies": {
39
+ "happy-dom": "^21.0.4"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "vp pack",
46
+ "dev": "vp pack --watch",
47
+ "test": "vp test"
48
+ }
6
49
  }