ajo 0.1.29 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/html.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./context.cjs"),m=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),b=Symbol.for("ajo.args"),p=e=>e.replace(/[&<>"']/g,r=>`&#${r.charCodeAt(0)};`),o=()=>{},v=e=>[...y(e)].join(""),y=function*(e,{alloc:r=o,push:t=o,placeholder:n=o}={}){for(e of f(e,{alloc:r,push:t,placeholder:n}))typeof e=="string"?yield p(e):yield*w(e,{alloc:r,push:t,placeholder:n})},w=function*({nodeName:e,children:r,...t},n){let l="";for(const i in t)i.startsWith("set:")||t[i]==null||t[i]===!1||(t[i]===!0?l+=` ${i}`:l+=` ${i}="${p(String(t[i]))}"`);m.has(e)?yield`<${e}${l}>`:(yield`<${e}${l}>`,r!=null&&(yield*y(r,n)),yield`</${e}>`)},f=function*(e,r){if(e==null)return;const t=typeof e;if(t!="boolean")if(t=="string")yield e;else if(t=="number"||t=="bigint")yield String(e);else if(Symbol.iterator in e)for(e of e)yield*f(e,r);else"nodeName"in e?typeof e.nodeName=="function"?yield*$(e,r):yield a(e,r):yield String(e)},$=function*({nodeName:e,fallback:r=e.fallback,...t},n){const l=e.constructor.name;e.src?yield S(e.src,t,n):l=="GeneratorFunction"?yield x(e,t,n):l=="AsyncGeneratorFunction"?yield A(e,r,t,n):(t=e(t),typeof t?.then=="function"?yield j(r,t,n):yield*f(t,n))},S=(e,r,t)=>{const n=t.alloc();return t.push({id:n,src:e,h:a(r,t),done:!0}),t.placeholder(n)},x=(e,r,t)=>{const n={...e.attrs},l={...e.args};for(const c in r)c.startsWith("attr:")?n[c.slice(5)]=r[c]:c=="key"||c=="skip"||c=="memo"||c=="ref"||c.startsWith("set:")?n[c]=r[c]:l[c]=r[c];const i={[u.Context]:Object.create(u.current()?.[u.Context]??null),[b]:l,next:o,return:o,throw:c=>{throw c}},s=e.call(i,l),g=u.current();u.current(i);const d=c=>({...n,nodeName:e.is??"div",...a({children:c},t)});try{return d(s.next().value)}catch(c){return d(s.throw(c).value)}finally{s.return?.(),u.current(g)}},A=(e,r,t,n)=>{const l=n.alloc();return Promise.resolve().then(async()=>{const i=e(t);n={...n,alloc:(s=l)=>n.alloc(s)};try{for(t=await i.next();!t.done;)n.push({id:l,h:a(t.value,n),done:!1}),t=await i.next();n.push({id:l,h:a(t.value,n),done:!0})}catch(s){n.push({id:l,h:a(s,n),done:!0})}finally{i.return?.()}}),n.placeholder(l,r)},j=(e,r,t)=>{const n=t.alloc();return r.then(l=>t.push({id:n,h:a(l,{...t,alloc:(i=n)=>t.alloc(i)}),done:!0})),t.placeholder(n,e)},a=({key:e,skip:r,memo:t,ref:n,...l},i)=>{if("children"in l){const s=[...f(l.children,i)];s.length?l.children=s.length==1?s[0]:s:delete l.children}return l};exports.html=y;exports.render=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./context.cjs"),m=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),b=Symbol.for("ajo.args"),y=e=>e.replace(/[&<>"']/g,r=>`&#${r.charCodeAt(0)};`),f=()=>{},p=e=>[...a(e)].join(""),a=function*(e){for(e of c(e))typeof e=="string"?yield y(e):yield*k(e)},k=function*({nodeName:e,children:r,...i}){let o="";for(const n in i)n.startsWith("set:")||i[n]==null||i[n]===!1||(i[n]===!0?o+=` ${n}`:o+=` ${n}="${y(String(i[n]))}"`);m.has(e)?yield`<${e}${o}>`:(yield`<${e}${o}>`,r!=null&&(yield*a(r)),yield`</${e}>`)},c=function*(e){if(e==null)return;const r=typeof e;if(r!="boolean")if(r=="string")yield e;else if(r=="number"||r=="bigint")yield String(e);else if(Symbol.iterator in e)for(e of e)yield*c(e);else"nodeName"in e?typeof e.nodeName=="function"?yield*$(e):yield d(e):yield String(e)},$=function*({nodeName:e,fallback:r=e.fallback,...i}){e.constructor.name=="GeneratorFunction"?yield S(e,i):yield*c(e(i))},S=(e,r)=>{const i={...e.attrs},o={...e.args};for(const t in r)t.startsWith("attr:")?i[t.slice(5)]=r[t]:t=="key"||t=="skip"||t=="memo"||t=="ref"||t.startsWith("set:")?i[t]=r[t]:o[t]=r[t];const n={[s.Context]:Object.create(s.current()?.[s.Context]??null),[b]:o,next:f,return:f,throw:t=>{throw t}},l=e.call(n,o),g=s.current();s.current(n);const u=t=>({...i,nodeName:e.is??"div",...d({children:t})});try{return u(l.next().value)}catch(t){return u(l.throw(t).value)}finally{l.return?.(),s.current(g)}},d=({key:e,skip:r,memo:i,ref:o,...n})=>{if("children"in n){const l=[...c(n.children)];l.length?n.children=l.length==1?l[0]:l:delete n.children}return n};exports.html=a;exports.render=p;
package/dist/html.js CHANGED
@@ -1,75 +1,53 @@
1
- import { Context as d, current as o } from "./context.js";
2
- const b = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), w = /* @__PURE__ */ Symbol.for("ajo.args"), p = (e) => e.replace(/[&<>"']/g, (r) => `&#${r.charCodeAt(0)};`), u = () => {
3
- }, W = (e) => [...g(e)].join(""), g = function* (e, { alloc: r = u, push: t = u, placeholder: n = u } = {}) {
4
- for (e of f(e, { alloc: r, push: t, placeholder: n }))
5
- typeof e == "string" ? yield p(e) : yield* $(e, { alloc: r, push: t, placeholder: n });
6
- }, $ = function* ({ nodeName: e, children: r, ...t }, n) {
7
- let l = "";
8
- for (const i in t)
9
- i.startsWith("set:") || t[i] == null || t[i] === !1 || (t[i] === !0 ? l += ` ${i}` : l += ` ${i}="${p(String(t[i]))}"`);
10
- b.has(e) ? yield `<${e}${l}>` : (yield `<${e}${l}>`, r != null && (yield* g(r, n)), yield `</${e}>`);
11
- }, f = function* (e, r) {
1
+ import { Context as f, current as s } from "./context.js";
2
+ const p = /* @__PURE__ */ new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]), b = /* @__PURE__ */ Symbol.for("ajo.args"), y = (e) => e.replace(/[&<>"']/g, (n) => `&#${n.charCodeAt(0)};`), u = () => {
3
+ }, v = (e) => [...d(e)].join(""), d = function* (e) {
4
+ for (e of c(e))
5
+ typeof e == "string" ? yield y(e) : yield* k(e);
6
+ }, k = function* ({ nodeName: e, children: n, ...i }) {
7
+ let o = "";
8
+ for (const r in i)
9
+ r.startsWith("set:") || i[r] == null || i[r] === !1 || (i[r] === !0 ? o += ` ${r}` : o += ` ${r}="${y(String(i[r]))}"`);
10
+ p.has(e) ? yield `<${e}${o}>` : (yield `<${e}${o}>`, n != null && (yield* d(n)), yield `</${e}>`);
11
+ }, c = function* (e) {
12
12
  if (e == null) return;
13
- const t = typeof e;
14
- if (t != "boolean")
15
- if (t == "string") yield e;
16
- else if (t == "number" || t == "bigint") yield String(e);
17
- else if (Symbol.iterator in e) for (e of e) yield* f(e, r);
18
- else "nodeName" in e ? typeof e.nodeName == "function" ? yield* v(e, r) : yield a(e, r) : yield String(e);
19
- }, v = function* ({ nodeName: e, fallback: r = e.fallback, ...t }, n) {
20
- const l = e.constructor.name;
21
- e.src ? yield x(e.src, t, n) : l == "GeneratorFunction" ? yield S(e, t, n) : l == "AsyncGeneratorFunction" ? yield A(e, r, t, n) : (t = e(t), typeof t?.then == "function" ? yield G(r, t, n) : yield* f(t, n));
22
- }, x = (e, r, t) => {
23
- const n = t.alloc();
24
- return t.push({ id: n, src: e, h: a(r, t), done: !0 }), t.placeholder(n);
25
- }, S = (e, r, t) => {
26
- const n = { ...e.attrs }, l = { ...e.args };
27
- for (const c in r)
28
- c.startsWith("attr:") ? n[c.slice(5)] = r[c] : c == "key" || c == "skip" || c == "memo" || c == "ref" || c.startsWith("set:") ? n[c] = r[c] : l[c] = r[c];
29
- const i = {
30
- [d]: Object.create(o()?.[d] ?? null),
31
- [w]: l,
13
+ const n = typeof e;
14
+ if (n != "boolean")
15
+ if (n == "string") yield e;
16
+ else if (n == "number" || n == "bigint") yield String(e);
17
+ else if (Symbol.iterator in e) for (e of e) yield* c(e);
18
+ else "nodeName" in e ? typeof e.nodeName == "function" ? yield* $(e) : yield m(e) : yield String(e);
19
+ }, $ = function* ({ nodeName: e, fallback: n = e.fallback, ...i }) {
20
+ e.constructor.name == "GeneratorFunction" ? yield w(e, i) : yield* c(e(i));
21
+ }, w = (e, n) => {
22
+ const i = { ...e.attrs }, o = { ...e.args };
23
+ for (const t in n)
24
+ t.startsWith("attr:") ? i[t.slice(5)] = n[t] : t == "key" || t == "skip" || t == "memo" || t == "ref" || t.startsWith("set:") ? i[t] = n[t] : o[t] = n[t];
25
+ const r = {
26
+ [f]: Object.create(s()?.[f] ?? null),
27
+ [b]: o,
32
28
  next: u,
33
29
  return: u,
34
- throw: (c) => {
35
- throw c;
30
+ throw: (t) => {
31
+ throw t;
36
32
  }
37
- }, s = e.call(i, l), m = o();
38
- o(i);
39
- const y = (c) => ({ ...n, nodeName: e.is ?? "div", ...a({ children: c }, t) });
33
+ }, l = e.call(r, o), g = s();
34
+ s(r);
35
+ const a = (t) => ({ ...i, nodeName: e.is ?? "div", ...m({ children: t }) });
40
36
  try {
41
- return y(s.next().value);
42
- } catch (c) {
43
- return y(s.throw(c).value);
37
+ return a(l.next().value);
38
+ } catch (t) {
39
+ return a(l.throw(t).value);
44
40
  } finally {
45
- s.return?.(), o(m);
41
+ l.return?.(), s(g);
46
42
  }
47
- }, A = (e, r, t, n) => {
48
- const l = n.alloc();
49
- return Promise.resolve().then(async () => {
50
- const i = e(t);
51
- n = { ...n, alloc: (s = l) => n.alloc(s) };
52
- try {
53
- for (t = await i.next(); !t.done; )
54
- n.push({ id: l, h: a(t.value, n), done: !1 }), t = await i.next();
55
- n.push({ id: l, h: a(t.value, n), done: !0 });
56
- } catch (s) {
57
- n.push({ id: l, h: a(s, n), done: !0 });
58
- } finally {
59
- i.return?.();
60
- }
61
- }), n.placeholder(l, r);
62
- }, G = (e, r, t) => {
63
- const n = t.alloc();
64
- return r.then((l) => t.push({ id: n, h: a(l, { ...t, alloc: (i = n) => t.alloc(i) }), done: !0 })), t.placeholder(n, e);
65
- }, a = ({ key: e, skip: r, memo: t, ref: n, ...l }, i) => {
66
- if ("children" in l) {
67
- const s = [...f(l.children, i)];
68
- s.length ? l.children = s.length == 1 ? s[0] : s : delete l.children;
43
+ }, m = ({ key: e, skip: n, memo: i, ref: o, ...r }) => {
44
+ if ("children" in r) {
45
+ const l = [...c(r.children)];
46
+ l.length ? r.children = l.length == 1 ? l[0] : l : delete r.children;
69
47
  }
70
- return l;
48
+ return r;
71
49
  };
72
50
  export {
73
- g as html,
74
- W as render
51
+ d as html,
52
+ v as render
75
53
  };
package/package.json CHANGED
@@ -1,60 +1,55 @@
1
1
  {
2
- "name": "ajo",
3
- "version": "0.1.29",
4
- "description": "ajo is a JavaScript view library for building user interfaces",
5
- "type": "module",
6
- "types": "./types.ts",
7
- "module": "./dist/index.js",
8
- "main": "./dist/index.cjs",
9
- "exports": {
10
- ".": {
11
- "types": "./types.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- },
15
- "./context": {
16
- "types": "./types.ts",
17
- "import": "./dist/context.js",
18
- "require": "./dist/context.cjs"
19
- },
20
- "./html": {
21
- "types": "./types.ts",
22
- "import": "./dist/html.js",
23
- "require": "./dist/html.cjs"
24
- },
25
- "./stream": {
26
- "types": "./types.ts",
27
- "import": "./dist/stream.js",
28
- "require": "./dist/stream.cjs"
29
- }
30
- },
31
- "files": [
32
- "dist",
33
- "types.ts"
34
- ],
35
- "devDependencies": {
36
- "@types/node": "25.0.9",
37
- "happy-dom": "20.3.1",
38
- "vite": "7.3.1",
39
- "vite-tsconfig-paths": "6.0.4",
40
- "vitest": "4.0.17"
41
- },
42
- "keywords": [
43
- "ui",
44
- "frontend",
45
- "web",
46
- "dom",
47
- "jsx"
48
- ],
49
- "repository": "cristianfalcone/ajo",
50
- "author": "Cristian Falcone",
51
- "license": "ISC",
52
- "bugs": "https://github.com/cristianfalcone/ajo/issues",
53
- "homepage": "https://github.com/cristianfalcone/ajo#readme",
54
- "scripts": {
55
- "test": "vitest --run",
56
- "build": "vite build",
57
- "bump": "pnpm version patch && git push && git push --tags",
58
- "release": "pnpm test && pnpm build && pnpm bump && pnpm publish"
59
- }
60
- }
2
+ "name": "ajo",
3
+ "version": "0.1.30",
4
+ "description": "ajo is a JavaScript view library for building user interfaces",
5
+ "type": "module",
6
+ "types": "./types.ts",
7
+ "module": "./dist/index.js",
8
+ "main": "./dist/index.cjs",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./context": {
16
+ "types": "./types.ts",
17
+ "import": "./dist/context.js",
18
+ "require": "./dist/context.cjs"
19
+ },
20
+ "./html": {
21
+ "types": "./types.ts",
22
+ "import": "./dist/html.js",
23
+ "require": "./dist/html.cjs"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "types.ts"
29
+ ],
30
+ "scripts": {
31
+ "test": "vitest --run",
32
+ "build": "vite build",
33
+ "bump": "pnpm version patch && git push && git push --tags",
34
+ "release": "pnpm test && pnpm build && pnpm bump && pnpm publish"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "25.2.3",
38
+ "happy-dom": "20.6.1",
39
+ "vite": "7.3.1",
40
+ "vite-tsconfig-paths": "6.1.1",
41
+ "vitest": "4.0.18"
42
+ },
43
+ "keywords": [
44
+ "ui",
45
+ "frontend",
46
+ "web",
47
+ "dom",
48
+ "jsx"
49
+ ],
50
+ "repository": "cristianfalcone/ajo",
51
+ "author": "Cristian Falcone",
52
+ "license": "ISC",
53
+ "bugs": "https://github.com/cristianfalcone/ajo/issues",
54
+ "homepage": "https://github.com/cristianfalcone/ajo#readme"
55
+ }
package/readme.md CHANGED
@@ -13,11 +13,10 @@
13
13
  </a>
14
14
  </div>
15
15
 
16
- A modern JavaScript library for building user interfaces with generator-based state management, efficient DOM updates, and streaming server-side rendering.
16
+ A modern JavaScript library for building user interfaces with generator-based state management and efficient DOM updates.
17
17
 
18
18
  - **Generator-Based Components**: Use `function*` for stateful components with built-in lifecycle
19
19
  - **Efficient DOM Updates**: In-place reconciliation minimizes DOM manipulation
20
- - **Streaming SSR**: Progressive rendering with selective hydration (islands)
21
20
 
22
21
  ## Quick Start
23
22
 
@@ -29,6 +28,7 @@ npm install ajo
29
28
  import { render } from 'ajo'
30
29
 
31
30
  function* Counter() {
31
+
32
32
  let count = 0
33
33
 
34
34
  while (true) yield (
@@ -91,6 +91,7 @@ Generator functions with automatic wrapper elements. The structure provides a na
91
91
 
92
92
  ```javascript
93
93
  function* TodoList() {
94
+
94
95
  let todos = []
95
96
  let text = ''
96
97
 
@@ -102,6 +103,7 @@ function* TodoList() {
102
103
  })
103
104
 
104
105
  while (true) {
106
+
105
107
  const count = todos.length
106
108
 
107
109
  yield (
@@ -127,6 +129,7 @@ Call `this.next()` to trigger a re-render. The optional callback receives curren
127
129
 
128
130
  ```javascript
129
131
  function* Stepper(args) {
132
+
130
133
  let count = 0
131
134
 
132
135
  // Access current props in callback
@@ -159,7 +162,9 @@ Use `try...finally` for cleanup when the component unmounts:
159
162
 
160
163
  ```javascript
161
164
  function* Clock() {
165
+
162
166
  let time = new Date()
167
+
163
168
  const interval = setInterval(() => this.next(() => time = new Date()), 1000)
164
169
 
165
170
  try {
@@ -223,6 +228,7 @@ function* ErrorBoundary(args) {
223
228
 
224
229
  ```javascript
225
230
  function* AutoFocus() {
231
+
226
232
  let input = null
227
233
 
228
234
  while (true) yield (
@@ -251,6 +257,7 @@ timer?.next() // trigger re-render from outside
251
257
 
252
258
  ```javascript
253
259
  function* Chart(args) {
260
+
254
261
  let chart = null
255
262
 
256
263
  while (true) yield (
@@ -292,6 +299,7 @@ const Card = ({ title }) => {
292
299
 
293
300
  // Stateful - write inside loop (updates each render)
294
301
  function* ThemeProvider(args) {
302
+
295
303
  let theme = 'light'
296
304
 
297
305
  while (true) {
@@ -318,6 +326,7 @@ function* FixedTheme(args) {
318
326
 
319
327
  ```javascript
320
328
  function* UserProfile(args) {
329
+
321
330
  let data = null, error = null, loading = true
322
331
 
323
332
  fetch(`/api/users/${args.id}`)
@@ -336,41 +345,8 @@ function* UserProfile(args) {
336
345
  ## Server-Side Rendering
337
346
 
338
347
  ```javascript
339
- // Static
340
348
  import { render } from 'ajo/html'
341
349
  const html = render(<App />)
342
-
343
- // Streaming
344
- import { stream } from 'ajo/stream'
345
- for await (const chunk of stream(<App />)) res.write(chunk)
346
-
347
- // Hydration (client-side)
348
- import { hydrate } from 'ajo/stream'
349
- window.$stream = { push: hydrate }
350
- ```
351
-
352
- ### Islands Architecture
353
-
354
- ```javascript
355
- function* Interactive() {
356
- let count = 0
357
- while (true) yield (
358
- <button set:onclick={() => this.next(() => count++)}>
359
- {count}
360
- </button>
361
- )
362
- }
363
-
364
- Interactive.src = '/islands/interactive.js' // hydrate on client
365
-
366
- const Page = () => (
367
- <html>
368
- <body>
369
- <p>Static content</p>
370
- <Interactive fallback={<button>0</button>} />
371
- </body>
372
- </html>
373
- )
374
350
  ```
375
351
 
376
352
  ## TypeScript
@@ -388,6 +364,7 @@ const Card: Stateless<CardProps> = ({ title, children }) => (
388
364
  type CounterProps = { initial: number; step?: number }
389
365
 
390
366
  const Counter: Stateful<CounterProps, 'section'> = function* (args) {
367
+
391
368
  let count = args.initial
392
369
 
393
370
  while (true) {
@@ -423,12 +400,6 @@ let ref: ThisParameterType<typeof Counter> | null = null
423
400
  |--------|-------------|
424
401
  | `render(children)` | Render to HTML string |
425
402
 
426
- ### `ajo/stream`
427
- | Export | Description |
428
- |--------|-------------|
429
- | `stream(children)` | Async iterator for streaming SSR |
430
- | `hydrate(patch)` | Apply streamed patch on client |
431
-
432
403
  ### Stateful `this`
433
404
  | Method | Description |
434
405
  |--------|-------------|
package/types.ts CHANGED
@@ -80,27 +80,8 @@ declare module 'ajo/context' {
80
80
  }
81
81
 
82
82
  declare module 'ajo/html' {
83
-
84
- type Patch = {
85
- id: string,
86
- h: import('ajo').Children,
87
- src?: string,
88
- done: boolean,
89
- }
90
-
91
- type Hooks = {
92
- alloc?: (parentId: string) => string,
93
- placeholder?: (id: string, children: import('ajo').Children) => unknown,
94
- push?: (patch: Patch) => void,
95
- }
96
-
97
83
  function render(h: import('ajo').Children): string
98
- function html(h: import('ajo').Children, hooks?: Hooks): IterableIterator<string>
99
- }
100
-
101
- declare module 'ajo/stream' {
102
- function stream(h: import('ajo').Children): AsyncIterableIterator<string>
103
- function hydrate(patch: import('ajo/html').Patch): Promise<void>
84
+ function html(h: import('ajo').Children): IterableIterator<string>
104
85
  }
105
86
 
106
87
  declare namespace JSX {
package/dist/stream.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index.cjs"),m=require("./html.cjs"),y=async function*(o,n=""){const s=new Map([[n,0]]),t=new Set,i=[],r=(e=n)=>(s.set(e,(s.get(e)??0)+1),e?`${e}:${s.get(e)-1}`:String(s.get(e)-1)),h=(e,c)=>({nodeName:"div","data-ssr":e,children:c}),f=e=>{const c=Promise.resolve(`<script>window.$stream?.push(${JSON.stringify(e)})<\/script>`);t.add(c),c.then(u=>i.push(u)).finally(()=>t.delete(c))};for(const e of m.html(o,{alloc:r,placeholder:h,push:f}))yield e;for(;t.size||i.length;){for(;i.length;)yield i.shift();t.size&&await Promise.race(t)}},d=new Set;async function l({id:o,src:n,h:s}){const t=document.querySelector(`[data-ssr="${o}"]`);if(!t)return d.add({id:o,src:n,h:s});n?a.render(a.h((await import(n)).default,s),t):a.render(s,t);const i=o+":";for(const r of d)r.id.startsWith(i)&&(d.delete(r),l(r))}exports.hydrate=l;exports.stream=y;
package/dist/stream.js DELETED
@@ -1,24 +0,0 @@
1
- import { render as l, h as m } from "./index.js";
2
- import { html as u } from "./html.js";
3
- const y = async function* (i, n = "") {
4
- const s = /* @__PURE__ */ new Map([[n, 0]]), e = /* @__PURE__ */ new Set(), o = [], c = (t = n) => (s.set(t, (s.get(t) ?? 0) + 1), t ? `${t}:${s.get(t) - 1}` : String(s.get(t) - 1)), d = (t, r) => ({ nodeName: "div", "data-ssr": t, children: r }), f = (t) => {
5
- const r = Promise.resolve(`<script>window.$stream?.push(${JSON.stringify(t)})<\/script>`);
6
- e.add(r), r.then((h) => o.push(h)).finally(() => e.delete(r));
7
- };
8
- for (const t of u(i, { alloc: c, placeholder: d, push: f })) yield t;
9
- for (; e.size || o.length; ) {
10
- for (; o.length; ) yield o.shift();
11
- e.size && await Promise.race(e);
12
- }
13
- }, a = /* @__PURE__ */ new Set();
14
- async function p({ id: i, src: n, h: s }) {
15
- const e = document.querySelector(`[data-ssr="${i}"]`);
16
- if (!e) return a.add({ id: i, src: n, h: s });
17
- n ? l(m((await import(n)).default, s), e) : l(s, e);
18
- const o = i + ":";
19
- for (const c of a) c.id.startsWith(o) && (a.delete(c), p(c));
20
- }
21
- export {
22
- p as hydrate,
23
- y as stream
24
- };