@verajs/renderer 0.2.1 → 0.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 (90) hide show
  1. package/README.md +729 -226
  2. package/dist/development/vera-renderer-elements.d.ts +39 -0
  3. package/dist/development/vera-renderer-elements.d.ts.map +1 -0
  4. package/dist/development/vera-renderer-elements.js +193 -0
  5. package/dist/development/vera-renderer-elements.js.map +1 -0
  6. package/dist/development/vera-renderer-hydrate-slots.d.ts +94 -0
  7. package/dist/development/vera-renderer-hydrate-slots.d.ts.map +1 -0
  8. package/dist/development/vera-renderer-hydrate-slots.js +325 -0
  9. package/dist/development/vera-renderer-hydrate-slots.js.map +1 -0
  10. package/dist/development/vera-renderer-hydration.d.ts +332 -0
  11. package/dist/development/vera-renderer-hydration.d.ts.map +1 -0
  12. package/dist/development/vera-renderer-hydration.js +864 -0
  13. package/dist/development/vera-renderer-hydration.js.map +1 -0
  14. package/dist/development/vera-renderer-keyed.d.ts +25 -8
  15. package/dist/development/vera-renderer-keyed.d.ts.map +1 -1
  16. package/dist/development/vera-renderer-keyed.js +843 -268
  17. package/dist/development/vera-renderer-keyed.js.map +1 -1
  18. package/dist/development/vera-renderer-multi-window.d.ts +5 -0
  19. package/dist/development/vera-renderer-multi-window.d.ts.map +1 -0
  20. package/dist/development/vera-renderer-multi-window.js +40 -0
  21. package/dist/development/vera-renderer-multi-window.js.map +1 -0
  22. package/dist/development/vera-renderer-namespaces.d.ts +64 -0
  23. package/dist/development/vera-renderer-namespaces.d.ts.map +1 -0
  24. package/dist/development/vera-renderer-namespaces.js +94 -0
  25. package/dist/development/vera-renderer-namespaces.js.map +1 -0
  26. package/dist/development/vera-renderer-native-elements.d.ts +13 -0
  27. package/dist/development/vera-renderer-native-elements.d.ts.map +1 -0
  28. package/dist/development/vera-renderer-native-elements.js +231 -0
  29. package/dist/development/vera-renderer-native-elements.js.map +1 -0
  30. package/dist/development/vera-renderer-portal.d.ts +29 -0
  31. package/dist/development/vera-renderer-portal.d.ts.map +1 -0
  32. package/dist/development/vera-renderer-portal.js +167 -0
  33. package/dist/development/vera-renderer-portal.js.map +1 -0
  34. package/dist/development/vera-renderer-profiler.d.ts +113 -138
  35. package/dist/development/vera-renderer-profiler.d.ts.map +1 -1
  36. package/dist/development/vera-renderer-profiler.js +2428 -2101
  37. package/dist/development/vera-renderer-profiler.js.map +1 -1
  38. package/dist/development/vera-renderer-slots.d.ts +88 -92
  39. package/dist/development/vera-renderer-slots.d.ts.map +1 -1
  40. package/dist/development/vera-renderer-slots.js +1834 -1237
  41. package/dist/development/vera-renderer-slots.js.map +1 -1
  42. package/dist/development/vera-renderer-spread.d.ts +8 -29
  43. package/dist/development/vera-renderer-spread.d.ts.map +1 -1
  44. package/dist/development/vera-renderer-spread.js +542 -461
  45. package/dist/development/vera-renderer-spread.js.map +1 -1
  46. package/dist/development/vera-renderer-tag.d.ts +12 -3
  47. package/dist/development/vera-renderer-tag.d.ts.map +1 -1
  48. package/dist/development/vera-renderer-tag.js +671 -494
  49. package/dist/development/vera-renderer-tag.js.map +1 -1
  50. package/dist/development/vera-renderer-until.d.ts +24 -0
  51. package/dist/development/vera-renderer-until.d.ts.map +1 -0
  52. package/dist/development/vera-renderer-until.js +83 -0
  53. package/dist/development/vera-renderer-until.js.map +1 -0
  54. package/dist/development/vera-renderer.d.ts +77 -96
  55. package/dist/development/vera-renderer.d.ts.map +1 -1
  56. package/dist/development/vera-renderer.js +2401 -2061
  57. package/dist/development/vera-renderer.js.map +1 -1
  58. package/dist/vera-renderer-elements.min.js +2 -0
  59. package/dist/vera-renderer-elements.min.js.map +1 -0
  60. package/dist/vera-renderer-hydrate-slots.min.js +2 -0
  61. package/dist/vera-renderer-hydrate-slots.min.js.map +1 -0
  62. package/dist/vera-renderer-hydration.min.js +3 -0
  63. package/dist/vera-renderer-hydration.min.js.map +1 -0
  64. package/dist/vera-renderer-keyed.min.js +1 -1
  65. package/dist/vera-renderer-keyed.min.js.map +1 -1
  66. package/dist/vera-renderer-multi-window.min.js +2 -0
  67. package/dist/vera-renderer-multi-window.min.js.map +1 -0
  68. package/dist/vera-renderer-namespaces.min.js +2 -0
  69. package/dist/vera-renderer-namespaces.min.js.map +1 -0
  70. package/dist/vera-renderer-native-elements.min.js +2 -0
  71. package/dist/vera-renderer-native-elements.min.js.map +1 -0
  72. package/dist/vera-renderer-portal.min.js +2 -0
  73. package/dist/vera-renderer-portal.min.js.map +1 -0
  74. package/dist/vera-renderer-slots.min.js +1 -1
  75. package/dist/vera-renderer-slots.min.js.map +1 -1
  76. package/dist/vera-renderer-spread.min.js +1 -1
  77. package/dist/vera-renderer-spread.min.js.map +1 -1
  78. package/dist/vera-renderer-tag.min.js +1 -1
  79. package/dist/vera-renderer-tag.min.js.map +1 -1
  80. package/dist/vera-renderer-until.min.js +2 -0
  81. package/dist/vera-renderer-until.min.js.map +1 -0
  82. package/dist/vera-renderer.min.js +1 -1
  83. package/dist/vera-renderer.min.js.map +1 -1
  84. package/package.json +52 -9
  85. package/dist/development/vera-renderer-hydrate.d.ts +0 -118
  86. package/dist/development/vera-renderer-hydrate.d.ts.map +0 -1
  87. package/dist/development/vera-renderer-hydrate.js +0 -3092
  88. package/dist/development/vera-renderer-hydrate.js.map +0 -1
  89. package/dist/vera-renderer-hydrate.min.js +0 -2
  90. package/dist/vera-renderer-hydrate.min.js.map +0 -1
@@ -1,103 +1,99 @@
1
1
  /**
2
- * Light-DOM slots — the `'slot'` insert the renderer's seam consults. Wire it beside the renderer
3
- * and every light-rendered template's `<slot name="…">` distributes the host's own children,
4
- * exactly as shadow DOM would have:
5
- *
6
- * ```js
7
- * import { renderer } from '@verajs/renderer';
8
- * import { slots } from '@verajs/renderer/slots';
9
- * wire([renderer, slots]);
10
- * ```
11
- *
12
- * ```html
13
- * <my-card><h2 slot="header">Hello</h2>Body text</my-card>
14
- * ```
15
- *
16
- * **Additive entry** (the `keyed`/`spread` family): imports nothing, reaches the renderer only
17
- * through the wired seam, safe alongside any renderer entry on a CDN page.
18
- *
19
- * **Wire it at the app entry, before anything renders.** The renderer resolves this seam once per
20
- * TEMPLATE, and templates are cached per call site for the life of the page — so a component that
21
- * rendered before the wiring keeps a slotless template forever. That is the same contract every
22
- * insert carries; the alternative (re-checking the registry per instance) would put a lookup on
23
- * the hot path of every app, slots or not.
24
- *
25
- * The semantics contract is the platform's own assignment algorithm: elements go to the slot
26
- * their `slot` attribute names, text nodes (whitespace included) to the default slot, comments
27
- * are never slottables (which also keeps the renderer's root marker out of capture), duplicate
28
- * slot names — first in mount order wins and later ones show fallback, fallback renders only
29
- * while nothing is assigned and comes back when a slot empties, and capture takes the host's
30
- * DIRECT children only, so nested components compose.
31
- *
32
- * **Post-render additions are NATIVE, and the mechanism is ownership, not position.** The host's
33
- * childList holds both the user's content and the component's output, and the old rules told them
34
- * apart by where a node sat — which made bare text unreachable at the tail and a late insertion
35
- * join its slot out of order. Now the renderer stamps everything it emits at a captured host's
36
- * top level (a non-enumerable `_$own$` property: `true` for a root part's own output — the
37
- * structural `_end === null` test, so async commits are covered — and the placing part for
38
- * content from an outer template). An unstamped top-level addition is therefore knowably the
39
- * user's: captured with full native semantics, text included, no `slot` attribute required
40
- * (`slot=""`/`slot="name"` still route). Ordering reads the same fact — placed content extends
41
- * its part's own group; an unstamped node before the boundary takes its document position ahead
42
- * of content distributed away, and past it, appends. **Re-slotting keeps that answer**: a node
43
- * whose `slot` attribute changes has not moved in the light tree, so it rejoins by a rank taken
44
- * when it was first captured rather than by arrival — otherwise an item toggled into a "pinned"
45
- * slot jumped to the end of the pinned list instead of holding its place.
46
- *
47
- * **What remains is reach, not order** — the earlier note here said hand-edits among several
48
- * `${…}` parts' content ordered "approximately", which measurement does not support: every
49
- * position a user can actually reach orders exactly as the platform does, and every order light
50
- * produces is one a shadow root also produces. What light has FEWER of is positions. A distributed
51
- * child is no longer a direct child of the host, so `host.insertBefore(node, thatChild)` throws
52
- * `NotFoundError` where a shadow host accepts it, and positions among an already-distributed
53
- * group cannot be named at the host's top level at all. `child.before(node)` / `child.after(node)`
54
- * go through the node's current parent and work identically in both modes; that is what the README
55
- * teaches, and `tests/renderer-slots.test.mjs` pins both the throw and the answer. And one parity note: whitespace appended to a
56
- * light host now suppresses the default fallback, because it does exactly that in a shadow root
57
- * (measured). `tests/slots-transition-parity.test.mjs` holds the matrix.
58
- *
59
- * **A `<slot>` cannot sit inside table markup**, in either mode: the parser's table insertion mode
60
- * rejects the element and foster-parents it out, so the slot lands before the `<table>` and takes
61
- * its distributed content with it. Measured against a shadow root given the same markup — it does
62
- * the same thing, so the modes agree and this is the platform's rule rather than this module's.
63
- * Ordinary bindings are fine (`<tbody>${rows}</tbody>` renders correctly) because the renderer's
64
- * anchor is a COMMENT, which table parsing permits where it rejects elements.
65
- *
66
- * **Pop-out rule.** Every *document* touch derives from the node itself (`ownerDocument`), so a
67
- * component rendered into a second window creates its nodes in that window's document.
68
- *
69
- * The one global read is `MutationObserver`, deliberately: an observer is not bound to the realm
70
- * of the nodes it watches, so deriving the constructor from `ownerDocument.defaultView` would buy
71
- * nothing and cost bytes on every capture. **Measured, not assumed** — `tests/browser/
72
- * slots-realm.test.js` renders a host in a second same-origin document and asserts that live
73
- * additions, `slot` changes and removals all reach their slots, on Chromium, Firefox and WebKit.
74
- * Behaviour the platform decides is not settled under jsdom.
2
+ * A light unit: a static child the page wrote (`a === z`), which moves as itself; or a RUN one of its template's
3
+ * bindings writes, between this module's own two comments, which never leaves holding — the renderer walks it there,
4
+ * contiguous, and each node of it a slot takes leaves a STAND-IN comment at its place. Every light node goes to the
5
+ * slot its own `slot` names, exactly as the platform assigns.
75
6
  */
76
- /** What the seam holds per taken-over slot; `_$park$` rescues the user's nodes before the
77
- * instance's DOM is bulk-discarded on a branch-away, and un-registers the binding. */
78
- type SeamState = {
79
- _$park$: () => void;
7
+ type Unit = {
8
+ a: Node;
9
+ z: Node;
80
10
  };
11
+ /** One `<slot>` of a light host: while it has content, `rs`/`re` stand in its place and the element is out. */
12
+ type Rec = {
13
+ slot: Kept;
14
+ light: Light;
15
+ rs: Comment | null;
16
+ re: Comment | null;
17
+ shown: Node[];
18
+ queued: boolean;
19
+ };
20
+ /** `_$region$`: a filled slot's region handed over before it mounts — by hydration, the server's two markers. */
21
+ type Kept = HTMLSlotElement & {
22
+ $rec?: Rec;
23
+ _$region$?: [Comment, Comment];
24
+ };
25
+ /** A host's light children, by unit, in the order the page wrote them, and its slots. */
81
26
  /**
82
- * What the user slotted, by name — the component-internal accessor that answers identically in
83
- * both modes. Shadow: the native assignment. Light: the capture map, in document order (a fresh
84
- * array; membership is live, so ask again after mutations). `''`/omitted is the default slot.
27
+ * `wait`: captured by a template that placed runs into this host during hydration, before the host's own slots exist —
28
+ * nothing distributes until the first of them mounts, so the nodes stay exactly where the server put them.
85
29
  */
30
+ type Light = {
31
+ host: Element;
32
+ units: Unit[];
33
+ holding?: HTMLElement;
34
+ recs: Rec[];
35
+ dirty: boolean;
36
+ fresh: boolean;
37
+ late: boolean;
38
+ wait: boolean;
39
+ obs?: MutationObserver;
40
+ ex?: boolean;
41
+ hw?: boolean;
42
+ ho?: boolean;
43
+ cw?: boolean;
44
+ hh?: boolean;
45
+ };
46
+ /** The slotted nodes a light host shows in its slot of `name` — or a shadow host's, from the platform. */
86
47
  declare const slotted: (host: Element, name?: string) => Node[];
87
- /**
88
- * The insert descriptor — `wire([renderer, slots])` and light-DOM slots exist.
89
- *
90
- * `fn` no longer needs a cast: `'slot'` is a declared insert point now, so this is checked against
91
- * `SlotInsert` rather than asserted past the type system. It used to be `as never`, which is what a
92
- * missing insert type looks like from the inside — and from the OUTSIDE it looked like
93
- * `wire([renderer, slots])` failing to compile for every TypeScript consumer.
94
- */
95
- declare const slots: {
48
+ declare const slotDiscovery: ((((registry: Map<string, unknown[]>) => void) | {
96
49
  name: string;
97
- on: "slot";
98
- fn: (slot: Element, root: Node, name: string) => SeamState | null;
50
+ on: "template";
51
+ fn: (built: object, _result: unknown, _readScope: unknown, root: Node) => void;
99
52
  priority: number;
53
+ })[] | ((registry: Map<string, unknown[]>) => void) | {
54
+ name: string;
55
+ on: "init";
56
+ fn: (element: Element, options: object | undefined) => void;
57
+ priority: number;
58
+ } | {
59
+ name: string;
60
+ on: "element";
61
+ fn: (el: Element) => {
62
+ mount: (slot: Element, context: {
63
+ root: Node | null;
64
+ }) => Rec | undefined;
65
+ /** Torn down: its content goes back to holding first, and the element back in its place, before the renderer removes it. */
66
+ unmount: (rec: Rec) => void;
67
+ } | {
68
+ mount: (element: Element, { root }: {
69
+ root: Node | null;
70
+ }) => void;
71
+ create: (element: Element, adopted: boolean) => void;
72
+ } | undefined;
73
+ priority: number;
74
+ })[];
75
+ /** What `wire` hands a connector: the registry (told apart from options by its `get`) and `wire` itself. */
76
+ type Registry = {
77
+ get(name: never): unknown;
78
+ };
79
+ type Wire = (item: never) => void;
80
+ type ObserveSlots = 'lazy' | 'eager';
81
+ type SlotsOptions = {
82
+ observeSlots?: ObserveSlots;
83
+ };
84
+ type SlotsConnector = (registry: Registry, wire: Wire) => void;
85
+ /** Two call signatures: as `wire` calls it (bare), and as an app calls it (with options) — both a module to `wire`. */
86
+ type SlotsModule = {
87
+ (options?: SlotsOptions): SlotsConnector;
88
+ (registry: Registry, wire: Wire): void;
100
89
  };
90
+ declare const slots: SlotsModule;
91
+ /** Its option's type, where slots is imported: `init({ host, observeSlots: 'eager' }, …)` (core's `VeraInitOptions`). */
92
+ declare global {
93
+ interface VeraInitOptions {
94
+ observeSlots?: 'lazy' | 'eager';
95
+ }
96
+ }
101
97
 
102
- export { slots, slotted };
98
+ export { slotDiscovery, slots, slotted };
103
99
  //# sourceMappingURL=vera-renderer-slots.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vera-renderer-slots.d.ts","sources":["../../src/slots.ts"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EG;AA4IH;AACA;AACA,KAAA,SAAY;AACZ;AACA;AACA;;;;;;;;;AASG;AACH;AAEA;;;;AAIG;AACH;AAEA,eAAA,OAAA,QAAA,IAAA,mBAAA,SAAA;;;;;;","names":[]}
1
+ {"version":3,"file":"vera-renderer-slots.d.ts","sources":["../../src/slots.ts"],"mappings":"AAAA;;;;;;;;;;;;;;;AAeG,QAAA,OAAA;AACH,WAAS,IAAA;AACT;AACA;AACA;AAEA,KAAA,IAAA,GAAA,eAAA;AACA;AAsBA,iBAAA,OAAA,EAAA,OAAA;;;;;;;;;;;;;AAaG;AACH;AACA;AACA,UAAU,gBAAoB;AAC5B;AACA;AAAuC;;AAEvC;AACF;AACA;;;AAGG;AACH;AACE,qEAA8B,IAAA;;mBACI,GAAA;AAClC;AAA4E;AAAyB,kBAAA,OAAY;;AAEnH;AAEA;;;;;;AAMG;AACH,uBAAuB,GAAA;AAEvB;yBACwC,OAAM;kBACrB,IAAE;AACzB;AACG,iCAA4B;;AAE/B;AACG;;KAEH,QAAA;AACF;AACA;AACA,KAAA,IAAA;AACA,KAAA,YAAc;AACd,KAAA,YAAiB;AACjB,mBAAA,YAAA;AACA;AACA,KAAA,cAAA,cAAA,QAAA,QAAA,IAAA;;;;AAIG,eAAA,QAAA,QAAA,IAAA;AACH;AAEA,cAAA,KAAA,EAAA,WAAA;AACA;;AAEE;AACE;AAAuB;;;;;","names":[]}