@torpor/view 1.2.5 → 1.3.0

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.
Files changed (44) hide show
  1. package/dist/{AsyncOptions-ClS1_ERX.d.mts → AsyncOptions-BDtArmeL.d.mts} +2 -8
  2. package/dist/AsyncOptions-BDtArmeL.d.mts.map +1 -0
  3. package/dist/{AsyncOptions-BtMe2PAd.d.cts → AsyncOptions-C_7mWR6F.d.cts} +2 -8
  4. package/dist/AsyncOptions-C_7mWR6F.d.cts.map +1 -0
  5. package/dist/{Effect-DazmAdyC.d.mts → Effect-99HYQdzZ.d.mts} +50 -33
  6. package/dist/Effect-99HYQdzZ.d.mts.map +1 -0
  7. package/dist/{Effect-Dewn7MLc.d.cts → Effect-Bf8fz_zC.d.cts} +50 -33
  8. package/dist/Effect-Bf8fz_zC.d.cts.map +1 -0
  9. package/dist/compile.cjs +1509 -120
  10. package/dist/compile.d.cts +268 -1
  11. package/dist/compile.d.cts.map +1 -1
  12. package/dist/compile.d.mts +268 -1
  13. package/dist/compile.d.mts.map +1 -1
  14. package/dist/compile.mjs +1506 -121
  15. package/dist/compile.mjs.map +1 -1
  16. package/dist/dev.d.cts +1 -1
  17. package/dist/dev.d.mts +1 -1
  18. package/dist/{fromWebSocket-DrN-IduP.cjs → fromWebSocket-Cdoghvmh.cjs} +15 -0
  19. package/dist/{fromWebSocket-CFGoMkV2.mjs → fromWebSocket-ERhd9KZR.mjs} +11 -2
  20. package/dist/fromWebSocket-ERhd9KZR.mjs.map +1 -0
  21. package/dist/index.cjs +223 -158
  22. package/dist/index.d.cts +24 -8
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +24 -8
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +223 -158
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/runtime.iife.js +1 -0
  29. package/dist/slotAutoClose-BbKfzpkz.cjs +177 -0
  30. package/dist/slotAutoClose-CgDkf8fM.mjs +156 -0
  31. package/dist/slotAutoClose-CgDkf8fM.mjs.map +1 -0
  32. package/dist/ssr.cjs +57 -3
  33. package/dist/ssr.d.cts +53 -2
  34. package/dist/ssr.d.cts.map +1 -1
  35. package/dist/ssr.d.mts +53 -2
  36. package/dist/ssr.d.mts.map +1 -1
  37. package/dist/ssr.mjs +51 -2
  38. package/dist/ssr.mjs.map +1 -1
  39. package/package.json +8 -5
  40. package/dist/AsyncOptions-BtMe2PAd.d.cts.map +0 -1
  41. package/dist/AsyncOptions-ClS1_ERX.d.mts.map +0 -1
  42. package/dist/Effect-DazmAdyC.d.mts.map +0 -1
  43. package/dist/Effect-Dewn7MLc.d.cts.map +0 -1
  44. package/dist/fromWebSocket-CFGoMkV2.mjs.map +0 -1
package/dist/dev.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as ProxySignal, n as Region, r as Computed, t as Effect } from "./Effect-Dewn7MLc.cjs";
1
+ import { i as ProxySignal, n as Region, r as Computed, t as Effect } from "./Effect-Bf8fz_zC.cjs";
2
2
  //#region src/types/ProxyData.d.ts
3
3
  interface ProxyData {
4
4
  target: Record<PropertyKey, any>;
package/dist/dev.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as ProxySignal, n as Region, r as Computed, t as Effect } from "./Effect-DazmAdyC.mjs";
1
+ import { i as ProxySignal, n as Region, r as Computed, t as Effect } from "./Effect-99HYQdzZ.mjs";
2
2
  //#region src/types/ProxyData.d.ts
3
3
  interface ProxyData {
4
4
  target: Record<PropertyKey, any>;
@@ -1,5 +1,14 @@
1
1
  //#region src/watch/symbols.ts
2
2
  const proxyDataSymbol = Symbol.for("torp.ProxyData");
3
+ /**
4
+ * Signal key for a watched object's key-set membership (`ownKeys`). Tracked by
5
+ * the proxy's `ownKeys` trap — so `Object.keys`/`values`/`entries`, spread,
6
+ * `for…in` and `JSON.stringify` re-run when a key is added or deleted — and
7
+ * propagated by the `set`/`deleteProperty` traps (and the array mutation
8
+ * handles) when the key set actually changes. A Symbol so it can't collide
9
+ * with a user property name.
10
+ */
11
+ const proxyKeysSymbol = Symbol.for("torp.ProxyKeys");
3
12
  //#endregion
4
13
  //#region src/watch/$unwrap.ts
5
14
  /**
@@ -182,3 +191,9 @@ Object.defineProperty(exports, "proxyDataSymbol", {
182
191
  return proxyDataSymbol;
183
192
  }
184
193
  });
194
+ Object.defineProperty(exports, "proxyKeysSymbol", {
195
+ enumerable: true,
196
+ get: function() {
197
+ return proxyKeysSymbol;
198
+ }
199
+ });
@@ -1,5 +1,14 @@
1
1
  //#region src/watch/symbols.ts
2
2
  const proxyDataSymbol = Symbol.for("torp.ProxyData");
3
+ /**
4
+ * Signal key for a watched object's key-set membership (`ownKeys`). Tracked by
5
+ * the proxy's `ownKeys` trap — so `Object.keys`/`values`/`entries`, spread,
6
+ * `for…in` and `JSON.stringify` re-run when a key is added or deleted — and
7
+ * propagated by the `set`/`deleteProperty` traps (and the array mutation
8
+ * handles) when the key set actually changes. A Symbol so it can't collide
9
+ * with a user property name.
10
+ */
11
+ const proxyKeysSymbol = Symbol.for("torp.ProxyKeys");
3
12
  //#endregion
4
13
  //#region src/watch/$unwrap.ts
5
14
  /**
@@ -134,6 +143,6 @@ function fromWebSocket(url) {
134
143
  };
135
144
  }
136
145
  //#endregion
137
- export { buildStyles as a, proxyDataSymbol as c, formatText as i, fromServer as n, buildClasses as o, fromElement as r, $unwrap as s, fromWebSocket as t };
146
+ export { buildStyles as a, proxyDataSymbol as c, formatText as i, proxyKeysSymbol as l, fromServer as n, buildClasses as o, fromElement as r, $unwrap as s, fromWebSocket as t };
138
147
 
139
- //# sourceMappingURL=fromWebSocket-CFGoMkV2.mjs.map
148
+ //# sourceMappingURL=fromWebSocket-ERhd9KZR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromWebSocket-ERhd9KZR.mjs","names":[],"sources":["../src/watch/symbols.ts","../src/watch/$unwrap.ts","../src/render/buildClasses.ts","../src/render/buildStyles.ts","../src/render/formatText.ts","../src/stream/fromElement.ts","../src/stream/fromServer.ts","../src/stream/fromWebSocket.ts"],"sourcesContent":["const proxyDataSymbol: unique symbol = Symbol.for(\"torp.ProxyData\");\n\n/**\n * Signal key for a watched object's key-set membership (`ownKeys`). Tracked by\n * the proxy's `ownKeys` trap — so `Object.keys`/`values`/`entries`, spread,\n * `for…in` and `JSON.stringify` re-run when a key is added or deleted — and\n * propagated by the `set`/`deleteProperty` traps (and the array mutation\n * handles) when the key set actually changes. A Symbol so it can't collide\n * with a user property name.\n */\nconst proxyKeysSymbol: unique symbol = Symbol.for(\"torp.ProxyKeys\");\n\nexport { proxyDataSymbol, proxyKeysSymbol };\n","import { proxyDataSymbol } from \"./symbols\";\n\n/**\n * Returns the target object of a proxy\n *\n * @param object The proxy object\n */\nexport default function $unwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object !== undefined && object !== null && object[proxyDataSymbol] !== undefined\n\t\t? (object[proxyDataSymbol].target ?? object)\n\t\t: object;\n}\n","import ClassValue from \"../types/ClassValue\";\nimport $unwrap from \"../watch/$unwrap\";\n\nexport default function buildClasses(value: ClassValue, styleHash?: string): string {\n\tif (typeof value === \"string\") {\n\t\tif (styleHash !== undefined) {\n\t\t\tvalue += \" \" + styleHash;\n\t\t}\n\t\treturn value;\n\t} else {\n\t\tlet classes: string[] = [];\n\t\tgatherClasses(\"\", value, classes);\n\t\tif (styleHash !== undefined) {\n\t\t\tclasses.push(styleHash);\n\t\t}\n\t\treturn classes.join(\" \");\n\t}\n}\n\nfunction gatherClasses(name: string, value: unknown, classes: string[]) {\n\tif (value) {\n\t\t// Unwrap watched values before iterating: component props are\n\t\t// deep-wrapped, and iterating a watched array disables the active\n\t\t// effect (see the array iterator in proxyGet), which would break\n\t\t// tracking of reads later in the same effect. Per-element tracking is\n\t\t// unnecessary here anyway -- the caller has already subscribed to the\n\t\t// property read that produced the value\n\t\tvalue = $unwrap(value as Record<PropertyKey, any>);\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherClasses(v as string, v, classes);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\t// Use `for-in` instead of `Object.entries(value)`. The entries\n\t\t\t// call allocates a new array (plus a [k, v] pair per entry) on\n\t\t\t// every invocation; `for-in` allocates nothing. Object literals\n\t\t\t// (the dominant case — e.g. `{ danger: bool }` in the row\n\t\t\t// template) have no inherited enumerable properties, so the two\n\t\t\t// are equivalent for our usage. This is on the per-effect re-run\n\t\t\t// hot path: a `select` op re-runs every row effect, each calling\n\t\t\t// `buildClasses({ danger: ... })`.\n\t\t\tfor (const n in value) {\n\t\t\t\tgatherClasses(n, (value as Record<string, unknown>)[n], classes);\n\t\t\t}\n\t\t} else {\n\t\t\tclasses.push(name);\n\t\t}\n\t}\n}\n","import type StyleValue from \"../types/StyleValue\";\n\nconst CAMEL_TO_DASH = /[A-Z]+(?![a-z])|[A-Z]/g;\n\nexport default function buildStyles(value: StyleValue): string {\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t} else {\n\t\tlet styles: string[] = [];\n\t\tgatherStyles(value, styles);\n\t\treturn styles.join(\"; \");\n\t}\n}\n\nfunction gatherStyles(value: unknown, styles: string[]) {\n\tif (value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherStyles(v, styles);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\tfor (let [n, v] of Object.entries(value)) {\n\t\t\t\tif (v === null || v === undefined) continue;\n\t\t\t\tconst key = n.replace(CAMEL_TO_DASH, (char, i) => (i > 0 ? \"-\" : \"\") + char.toLowerCase());\n\t\t\t\tstyles.push(`${key}: ${v}`);\n\t\t\t}\n\t\t} else {\n\t\t\t// oxlint-disable-next-line typescript/no-base-to-string\n\t\t\tstyles.push(String(value));\n\t\t}\n\t}\n}\n","import $unwrap from \"../watch/$unwrap\";\n\nexport default function formatText(value: any): string {\n\t// We could have anything in value, so we need to\n\t// - use String(...) because Symbols can't be implicitly converted\n\t// - use $unwrap because Proxies can't be converted to a string\n\tif (value === undefined || value === null) {\n\t\treturn \"\";\n\t}\n\t// Fast path: strings already satisfy both concerns above. Skipping the\n\t// `String($unwrap(value))` pair saves two function calls per text\n\t// interpolation on the dominant `typeof value === \"string\"` branch —\n\t// e.g. row labels in js-framework-bench hit this on every effect run.\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\treturn String($unwrap(value));\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * The element to listen on, or a getter returning it. Use a getter for\n * `&ref`-bound variables — they are only assigned once the element is\n * created, and subscriptions start at mount time:\n *\n * ```torp\n * let saveButton: HTMLButtonElement;\n *\n * $stream(fromElement(() => saveButton, \"click\"), () => save());\n * ```\n */\ntype EventTargetInput = HTMLElement | (() => HTMLElement | null | undefined);\n\n/**\n * Creates a StreamSource that pushes DOM events of the given type from an\n * element.\n *\n * ```torp\n * $stream(fromElement(() => saveButton, \"click\"), (e) => {\n * \t$state.clicks.push(e);\n * });\n * ```\n */\nexport default function fromElement<E extends Event = Event>(\n\ttarget: EventTargetInput,\n\ttype: string,\n): StreamSource<E> {\n\treturn (push) => {\n\t\tconst el = typeof target === \"function\" ? target() : target;\n\t\tif (!el) {\n\t\t\tthrow new Error(\n\t\t\t\t'fromElement: element not found. When passing a &ref variable, wrap it in a getter: fromElement(() => buttonEl, \"click\")',\n\t\t\t);\n\t\t}\n\t\tconst listener = push as EventListener;\n\t\tel.addEventListener(type, listener);\n\t\treturn () => {\n\t\t\tel.removeEventListener(type, listener);\n\t\t};\n\t};\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Creates a StreamSource that receives `message` events from a server-sent\n * events endpoint. The URL may be a getter, so reactive state can be read\n * inside it — when it changes, the connection is closed and re-opened:\n *\n * ```torp\n * $stream(fromServer(`/sse/${$props.id}`), (e) => {\n * \t$state.messages.push(e.data);\n * });\n * ```\n *\n * Reconnection is handled by `EventSource` itself; errors are not pushed —\n * a source that can fail should surface errors as values.\n */\nexport default function fromServer(url: string | (() => string)): StreamSource<MessageEvent> {\n\treturn (push) => {\n\t\tconst eventSource = new EventSource(typeof url === \"function\" ? url() : url);\n\t\teventSource.onmessage = push;\n\t\treturn () => {\n\t\t\teventSource.close();\n\t\t};\n\t};\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Creates a StreamSource that receives `message` events from a WebSocket.\n * The URL may be a getter, so reactive state can be read inside it — when\n * it changes, the socket is closed and re-opened:\n *\n * ```torp\n * $stream(fromWebSocket(`/ws/${$props.id}`), (e) => {\n * \t$state.inbox.push(e.data);\n * });\n * ```\n *\n * Errors are not pushed — a source that can fail should surface errors as\n * values and own its own reconnection.\n */\nexport default function fromWebSocket(url: string | (() => string)): StreamSource<MessageEvent> {\n\treturn (push) => {\n\t\tconst socket = new WebSocket(typeof url === \"function\" ? url() : url);\n\t\tsocket.onmessage = push;\n\t\treturn () => {\n\t\t\tsocket.close();\n\t\t};\n\t};\n}\n"],"mappings":";AAAA,MAAM,kBAAiC,OAAO,IAAI,gBAAgB;;;;;;;;;AAUlE,MAAM,kBAAiC,OAAO,IAAI,gBAAgB;;;;;;;;ACHlE,SAAwB,QAA4C,QAAc;CACjF,OAAO,WAAW,KAAA,KAAa,WAAW,QAAQ,OAAO,qBAAqB,KAAA,IAC1E,OAAO,gBAAgB,CAAC,UAAU,SACnC;AACJ;;;ACRA,SAAwB,aAAa,OAAmB,WAA4B;CACnF,IAAI,OAAO,UAAU,UAAU;EAC9B,IAAI,cAAc,KAAA,GACjB,SAAS,MAAM;EAEhB,OAAO;CACR,OAAO;EACN,IAAI,UAAoB,CAAC;EACzB,cAAc,IAAI,OAAO,OAAO;EAChC,IAAI,cAAc,KAAA,GACjB,QAAQ,KAAK,SAAS;EAEvB,OAAO,QAAQ,KAAK,GAAG;CACxB;AACD;AAEA,SAAS,cAAc,MAAc,OAAgB,SAAmB;CACvE,IAAI,OAAO;EAOV,QAAQ,QAAQ,KAAiC;EACjD,IAAI,MAAM,Q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