@verajs/renderer 0.3.0 → 0.3.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 +52 -6
- package/dist/development/vera-renderer-elements.js.map +1 -1
- package/dist/development/vera-renderer-hydrate-slots.js +1 -1
- package/dist/development/vera-renderer-hydrate-slots.js.map +1 -1
- package/dist/development/vera-renderer-hydration.d.ts.map +1 -1
- package/dist/development/vera-renderer-hydration.js +42 -4
- package/dist/development/vera-renderer-hydration.js.map +1 -1
- package/dist/development/vera-renderer-portal.js +1 -1
- package/dist/development/vera-renderer-portal.js.map +1 -1
- package/dist/development/vera-renderer-profiler.d.ts.map +1 -1
- package/dist/development/vera-renderer-profiler.js +304 -97
- package/dist/development/vera-renderer-profiler.js.map +1 -1
- package/dist/development/vera-renderer-slots.js +1 -1
- package/dist/development/vera-renderer-slots.js.map +1 -1
- package/dist/development/vera-renderer-spread.js.map +1 -1
- package/dist/development/vera-renderer-tag.js.map +1 -1
- package/dist/development/vera-renderer.d.ts.map +1 -1
- package/dist/development/vera-renderer.js +304 -97
- package/dist/development/vera-renderer.js.map +1 -1
- package/dist/vera-renderer-elements.min.js.map +1 -1
- package/dist/vera-renderer-hydrate-slots.min.js +1 -1
- package/dist/vera-renderer-hydrate-slots.min.js.map +1 -1
- package/dist/vera-renderer-hydration.min.js +1 -1
- package/dist/vera-renderer-hydration.min.js.map +1 -1
- package/dist/vera-renderer-portal.min.js +1 -1
- package/dist/vera-renderer-portal.min.js.map +1 -1
- package/dist/vera-renderer-slots.min.js +1 -1
- package/dist/vera-renderer-slots.min.js.map +1 -1
- package/dist/vera-renderer-spread.min.js.map +1 -1
- package/dist/vera-renderer-tag.min.js.map +1 -1
- package/dist/vera-renderer.min.js +1 -1
- package/dist/vera-renderer.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vera-renderer-portal.js","sources":["../../../shared-utils/src/diagnostic.ts","../../src/kinds.ts","../../src/portal-diagnostics.ts","../../src/portal.ts"],"sourcesContent":["/**\n * **Where every diagnostic code is explained.** The URL is permanent: a released bundle is immutable, so every version\n * published points here for ever — the domain cannot lapse and `/e/` cannot be reorganized without breaking links in\n * code nobody can edit; the docs site redirects instead. `scripts/sync-diagnostics.mjs` imports this constant, so the\n * pages and the bundles can never disagree about where they are.\n */\nexport const DOCS = 'https://verajs.dev/e/';\n\n/**\n * **What this copy of the framework has already said** (Brian's ruling, 2026-11-12): the ONE memory behind `warnOnce`, `errorOnce`\n * and `hasWarned`, for DEVELOPMENT-ONLY warnings. It replaced the hand-written once-flags every package kept\n * (`saidLists`, `warnedDrop`, per-element WeakSets, per-key Sets: two naming styles, Brian: no names). **A warning that\n * ships to production keeps its memory at its site** (bytes, measured 2026-11-12: the shared memory costs +80–145 B gz\n * per bundle); development-only warnings use warnOnce. Module state by necessity, since \"once\" spans every call on the\n * page. One per BUNDLE COPY, exactly the scope each flag had, because this package is inlined into every bundle.\n * A code, or `code key` for a string key, in a Set. An object key (an element, a setup function) in a WeakMap, so its\n * entry goes with the object. Marked pure, so a bundle that never prints once drops both.\n */\nconst printed = /* @__PURE__ */ new Set<string>();\nconst printedOn = /* @__PURE__ */ new WeakMap<object, Map<string, Set<unknown>>>();\n/**\n * A once's KEY: none (once per page), a string (once per that string), an object (once per that object: an element, a\n * class, a setup function), or the PAIR `[object, value]`, a value key on that object (a store write: the object and its\n * property; a keyed list: the list and the duplicate key, compared as the list compares them, by value, so `1` and `'1'`\n * stay apart). A pair is the only array a key may be.\n */\ntype OnceKey = string | object | readonly [object, unknown];\n/** Where an object key's (code, value) lives: the value set for that code on that object, made on demand. */\nconst valuesOn = (on: object, code: string, make: boolean): Set<unknown> | undefined => {\n let codes = printedOn.get(on);\n if (codes === undefined) {\n if (!make) return undefined;\n printedOn.set(on, (codes = new Map()));\n }\n let values = codes.get(code);\n if (values === undefined && make) codes.set(code, (values = new Set()));\n return values;\n};\n/** The object and value of an object or pair key. */\nconst split = (key: object): readonly [object, unknown] => (Array.isArray(key) ? (key as unknown as readonly [object, unknown]) : [key, undefined]);\n/** Whether (code, key) is new, recording it if so. */\nconst firstTime = (code: string, key?: OnceKey): boolean => {\n if (key === undefined || typeof key === 'string') {\n const entry = key === undefined ? code : `${code} ${key}`;\n if (printed.has(entry)) return false;\n printed.add(entry);\n return true;\n }\n const [on, sub] = split(key);\n const values = valuesOn(on, code, true)!;\n if (values.has(sub)) return false;\n values.add(sub);\n return true;\n};\n\n/**\n * **One shape for every diagnostic the framework prints** — the short line production keeps, the whole sentence\n * development adds — so a package converting its messages writes a table and a call, never its own format.\n *\n * production `[vera] hydration: element: found <i> — https://verajs.dev/e/hydration-fallback`\n * development `[vera] hydration: element: found <i> — fell back to a client render: … (hydration-fallback)`\n *\n * `subject` is the free information — what the code already has at hand, naming the problem area — the same in both\n * builds. `prose` is development only: the package's table entry (`Prose`), called behind `__DEV__` at the call site so\n * the table goes unreferenced in production and rollup drops it whole. Production prints the code inside the link, so\n * the reader is one click from the explanation, which `scripts/sync-diagnostics.mjs` publishes from the same tables.\n *\n * **Every production message is coded** (Brian, 2026-11-11; this supersedes \"convert where smaller\", 2026-10-02):\n * consistency over a few bytes, so no package keeps a hand-written production line beside its table.\n */\n/*\n * The parameter names are deliberately unlike anything a caller holds: terser will not inline a function whose\n * parameter shadows a name at the call site (measured 2026-10-02 — directives passes its own `code`, and a parameter\n * called `code` left `((e,t,n)=>`…`)(0,t,n)` in its bundle, +8 B; renamed, the call folds to the bare template).\n */\n/**\n * **A misused API, named by its function** — the thrown-error twin of `diagnostic()`: `untrack: expected a function …\n * (untrack-not-function)`, function-first because a stack already names the source and the sweep reads that shape. The\n * prose comes from a package's table, behind `__DEV__`, so a development-only guard costs production nothing.\n */\nexport const misuse = (forName: string, withCode: string, andProse?: false | readonly [string, string?]) =>\n __DEV__ && andProse\n ? `${forName}: ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `${forName}: ${DOCS}${withCode}`;\n\n/**\n * **A misused API and what it was misused ABOUT** — `misuse()` with a subject, in `diagnostic()`'s ` — ` separator:\n * `parseFrontmatter: line 3 — https://verajs.dev/e/cms-frontmatter-unsupported`. The subject is the free information\n * (a line, a URL and its status) and prints in both builds. A sibling rather than an optional parameter on `misuse()`,\n * because `misuse()` is inlined into every bundle that throws and a conditional subject would tax all of them for a\n * shape few need; a sibling is tree-shaken where unused.\n */\nexport const misuseAbout = (forName: string, aboutSubject: string, withCode: string, andProse?: false | readonly [string, string?]) =>\n __DEV__ && andProse\n ? `${forName}: ${aboutSubject} — ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `${forName}: ${aboutSubject} — ${DOCS}${withCode}`;\n\nexport const diagnostic = (\n inArea: string,\n bySubject: string,\n withCode: string,\n andProse?: false | readonly [string, string?]\n) =>\n /** `__DEV__` HERE as well as at the call: production folds this to the one-line form, branch and all. */\n __DEV__ && andProse\n ? `[vera] ${inArea}: ${bySubject} — ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `[vera] ${inArea}: ${bySubject} — ${DOCS}${withCode}`;\n\n/**\n * **Text from outside — a file path, a YAML key, a URL, an error's message — quoted before it reaches a line.** A log is a\n * pipeline, and such text can be shaped by an author or a request: a newline in it forges a line, an ESC sequence hides\n * one (log injection). `JSON.stringify` escapes both; cut to 80 characters so one value cannot fill the log. @verajs/ssr\n * keeps a twin (it cannot import this), held equal by tests/ssr-coded-diagnostics.\n */\n/**\n * `max` caps the length (80 by default); `Infinity` keeps the whole text for a value worth reading in full — a site\n * owner's own path — which is still ESCAPED: truncation and escaping are separate jobs, and a path is not free of control\n * characters just because its owner wrote it (2026-10-09).\n */\nexport const quoted = (text: string, max = 80): string => JSON.stringify(text.length > max ? `${text.slice(0, max)}…` : text);\n\n/**\n * **The errors a package constructs, marked as its own** — so a wrapper that reports an inner refusal (cms's\n * `generateManifest` around a frontmatter line) carries it as it is: already formatted, its outside text already\n * quoted. Anything else is foreign, and quoted. Identity, never a shape test: a message can imitate ours, an identity\n * cannot. @verajs/ssr keeps a twin (it cannot import this).\n */\nconst ours = /* @__PURE__ */ new WeakSet<object>();\nexport const own = <E extends Error>(error: E): E => {\n ours.add(error);\n return error;\n};\nexport const isOwn = (error: unknown): boolean => typeof error === 'object' && error !== null && ours.has(error);\n\n/**\n * **Whether this copy has already said `code` (for `key`)**: for a GUARD only, where deciding to warn costs work worth\n * skipping once the warning is out (development's whole-tree walk for unwired directive attributes, an event-name\n * guess over every property of an element). A site that only prints calls `warnOnce`. Asks, never records.\n */\nexport const hasWarned = (code: string, key?: OnceKey): boolean => {\n if (key === undefined || typeof key === 'string') return printed.has(key === undefined ? code : `${code} ${key}`);\n const [on, sub] = split(key);\n return valuesOn(on, code, false)?.has(sub) === true;\n};\n\ntype Detail = false | readonly [string, string?] | (() => readonly [string, string?] | undefined);\n/**\n * The printer behind both, on one level. `andDetail` is `diagnostic()`'s prose, or a function returning it where building\n * the sentence costs something: it is called only the first time. `...andMore` rides beside the line behind '%s' (an\n * element, a thrown error), never inside it, so text from outside cannot forge a line. The console method is read at the\n * call, so a test that replaces `console.warn` sees it.\n */\nconst sayOnce =\n (level: 'warn' | 'error') =>\n (inArea: string, bySubject: string, withCode: string, andDetail?: Detail, forKey?: OnceKey, ...andMore: unknown[]): void => {\n if (!firstTime(withCode, forKey)) return;\n const line = diagnostic(inArea, bySubject, withCode, typeof andDetail === 'function' ? andDetail() : andDetail);\n if (andMore.length) console[level]('%s', line, ...andMore);\n else console[level](line);\n };\n/**\n * **A diagnostic said once per page** (per key, where one is given: a string, or an object such as the element it is\n * about): `diagnostic()`'s arguments, then the key, then what rides beside the line. Coded in production exactly as\n * `diagnostic()` is, because it IS `diagnostic()`. `errorOnce` is its twin on `console.error`, for a refusal a page should\n * not miss.\n */\nexport const warnOnce = /* @__PURE__ */ sayOnce('warn');\nexport const errorOnce = /* @__PURE__ */ sayOnce('error');\n","/**\n * **The renderer's binding kinds and child-part modes** — numbers both `renderer.ts` and the separately bundled\n * `hydration.ts` read, from ONE source (each bundle inlines them; they are literals in the output). A change here\n * changes the hand-off's protocol: bump `$V` in `renderer.ts`.\n */\n/** A binding's kind, resolved once per template. */\nexport const IGNORED = 0; // consumed, nothing rendered: inside a comment, the later values of a multi-part attribute\nexport const CHILD = 1; // anchored on a primed empty text node the template carries\nexport const SOLE = 2; // its element's only content: no anchor in the template, the first commit writes `textContent`\nexport const ATTR = 3;\nexport const PROPERTY = 4;\nexport const BOOLEAN = 5;\n/** `EVENT` through `ADOPT` hold a `Slot` record in their node slot — one range test, in `instantiate` and `commit`. */\nexport const EVENT = 6;\n/** An element-position expression: a ref, or a value that applies itself (`_$apply$`). */\nexport const REF = 7;\n/** An element-position expression ON a `<select>`: a value applying itself there (a spread) waits for `flush`. */\nexport const SELECT_REF = 8;\n/** `.name` on a custom element — see `adoptProperty` in shared-utils. */\nexport const ADOPT = 9;\n/**\n * Kinds from here on re-assert on EVERY render, so the update loop never skips them as unchanged:\n * `!name` writes from the live DOM's point of view (a sibling radio's click unchecks this one with no\n * event on it), and a `<select>`'s selection is re-applied after its options exist — see `flush`.\n */\nexport const LIVE = 10;\n/** A `<select>`'s selection — `value` or `selectedIndex` (`isSelection`) — written when the pass ends: see `flush`. */\nexport const SELECT = 11;\n/** `!name` on a custom element: compared against the LIVE value — read through `untracked`, it is the component's getter. */\nexport const LIVE_CUSTOM = 12;\n/** A binding that must never write — and, from here on, the kinds `commit` handles before anything is computed. */\nexport const REFUSED = 13;\n/** A `<select>`'s `selectedIndex` — the rare spelling of its selection, queued as `SELECT` is (see `flush`). */\nexport const SELECT_INDEX = 14;\n\n\n/** A child part's mode: what its range currently holds. */\nexport const EMPTY = 0;\nexport const TEXT = 1;\nexport const TEMPLATE = 2;\nexport const LIST = 3;\nexport const NODE = 4;\n\n/**\n * **The hydration hand-off's positions** — the renderer sets `$H` to an array at `connect`, and `hydration.ts` reads\n * it by these. An array, not an object of named fields: the names cost every app bytes (−35 B gzipped measured,\n * 2026-10-02), and these constants inline to literals in both bundles. The first two are FROZEN across protocols — a\n * hydration from another release reads the protocol at 0 and, on a mismatch, can still install its clearing hook at 1.\n * Any other change here is a protocol change: bump `PROTOCOL`.\n */\n/**\n * **The protocol of this package's first-party seams** — the renderer's hand-off (`$H`, at `HANDOFF_PROTOCOL`) and slots'\n * capture (`_$capture$`), both read by hydration. One number for both: the three ship in one package, and a change to\n * either seam bumps it. A hydration that meets another number declines (the page renders fresh) and says so.\n */\nexport const PROTOCOL = 1;\n/** The protocol number — FROZEN at 0. */\nexport const HANDOFF_PROTOCOL = 0;\n/** The first-render hook's setter — FROZEN at 1. */\nexport const HANDOFF_ADOPTER = 1;\nexport const HANDOFF_GET_TEMPLATE = 2;\nexport const HANDOFF_CHILD_PART = 3;\nexport const HANDOFF_INSTANCE = 4;\nexport const HANDOFF_SLOT = 5;\nexport const HANDOFF_UNSET = 6;\nexport const HANDOFF_UPGRADED = 7;\nexport const HANDOFF_COMMIT = 8;\nexport const HANDOFF_COMMIT_AS = 9;\nexport const HANDOFF_HOOK_UP = 10;\nexport const HANDOFF_RESOLVE = 11;\nexport const HANDOFF_ROOTS = 12;\nexport const HANDOFF_TO_TEXT = 13;\nexport const HANDOFF_REMOVAL_WORK = 14;\n","/** **`@verajs/renderer/portal`'s diagnostics — DEVELOPMENT ONLY.** Its bundle's own table, merged into the renderer's json. */\nimport type { Prose } from '@verajs/shared-utils';\n\nexport const PROSE: Record<string, Prose> = {\n 'portal-no-renderer': () => [\n 'a portal has no renderer of this release to draw with, so it drew nothing.',\n 'Wire the renderer once at your entry — `wire([renderer])` — from the same release as `@verajs/renderer/portal`.',\n ],\n};\n","import { effect, inserts, untrack } from '@verajs/core';\nimport { diagnostic } from '@verajs/shared-utils';\nimport { HANDOFF_CHILD_PART, HANDOFF_COMMIT_AS, HANDOFF_PROTOCOL, PROTOCOL } from './kinds.js';\nimport { PROSE } from './portal-diagnostics.js';\nimport type { ChildPart } from './renderer.js';\n\n/** Whether `portal-no-renderer` has been printed: once per page, in every build (a warning that ships to production keeps its memory at its site: the shared memory costs +80–145 B gz per bundle, measured 2026-11-12). */\nlet printedPortal = false;\n\n/** What this entry reads off core's registry: the renderer's hand-off and core's settle. `$`-named — never mangled. */\ntype Registry = {\n $H?: unknown[];\n $so?: (hook: unknown, all?: boolean) => void;\n};\ntype Part = new (start: Comment, end: Comment) => ChildPart;\ntype CommitAs = (root: Node, part: ChildPart, value: unknown) => void;\n\n/**\n * **A server registers nothing** — `@verajs/ssr` sets this public flag at import, before anything renders (the renderer\n * reads it the same way). A server turn runs a setup's effects, and with no client renderer there every request said\n * `portal-no-renderer` (measured 2026-10-22); a portal has nothing to draw there, and hydration nothing to adopt.\n */\nconst onServer = (globalThis as { __veraSsrShimmed?: boolean }).__veraSsrShimmed === true;\n\n/**\n * **`portal(target, template)` — draws into ANOTHER element, from a component's setup** (2026-10-22, the API\n * distillation: it replaced `useRender`'s one job no returned render can do). A modal on `document.body`, a tooltip\n * in an overlay layer, a row in another component's light DOM.\n *\n * - **Its own range.** Two comments, appended to `target`, bound what it draws, so any number share one target (two\n * components drawing into `document.body` with `renderInto` — one root per container — replaced each other).\n * - **The render's slot.** It runs at the render's priority (50): a keyed `.map` keeps its rows with their items, it is\n * drawn before the component's layout effects, and what its draw made and no longer reaches (an automatic list, a\n * computed) is freed after each draw, as the component's own render frees it.\n * - **Owned by the component being set up**, whose removal takes its content and markers out of `target`; a paused\n * component (`persist`) takes them out too, and draws afresh when it is back. A cross-window MOVE of the component\n * leaves it where it is: `target` is where it was asked to draw.\n * - **Light DOM.** `target` itself, never its shadow root: into a shadow host it is the host's light content, slotted\n * where the host's template says.\n * - **The client only.** A server renders a component's own template; a portal registers nothing there, so hydration\n * finds no range to adopt and the client draws it once.\n * - **A target FUNCTION follows** (Brian, 2026-10-25): `portal(() => host.ownerDocument.body, …)` is evaluated at setup\n * and again whenever what it reads changes or its component moves into another window (a cross-window move re-runs effect\n * priority), and a different answer MOVES the drawn range into the new target — never a redraw, so components inside\n * keep their state. A popped-out panel's modal then opens in the pop-out. A plain element target never moves.\n *\n * Additive, like `hydration`: it imports no renderer and reaches the one wired through its hand-off (`$H`).\n */\ntype Target = Element | DocumentFragment;\n/**\n * **No target, or a dead one, leaves the range WHERE IT IS** (2026-10-25): a falsy answer, or a target whose window is gone\n * (a closed pop-out: no live `defaultView`), moves nothing — so nothing is removed and the components inside keep their\n * state (holding the range in a detached fragment would be a REMOVAL, which tears them down) — and the next real target\n * gets it. Nothing throws.\n */\nconst usable = (t: Target | null | undefined): t is Target => {\n const view = t?.ownerDocument?.defaultView;\n return view != null && !view.closed;\n};\nexport const portal = (target: Target | (() => Target | null | undefined), template: unknown): void => {\n if (onServer) return;\n let part: ChildPart | undefined;\n /** Where it draws now: a function target is read once here, untracked, so the draw does not subscribe to it. */\n let current: Target;\n if (typeof target === 'function') {\n const first = untrack(target);\n /** No usable target yet: drawn into a fragment of THIS realm's document until one exists — portal is handed no element to take one from. */\n current = usable(first) ? first : document.createDocumentFragment();\n } else current = target;\n /** The last value drawn, for a redraw when the range was destroyed (below). */\n let last: unknown;\n const registry = inserts as unknown as Registry;\n /**\n * **The range is INTACT while both markers sit in one parent** (2026-10-25). User code clearing the target —\n * `container.innerHTML = ''`, a router swapping a container's children, an overlay library emptying its root — or a dead\n * window taking its document's nodes (jsdom) removes them, and a draw into detached markers would be invisible (and a\n * cleanup into them threw). The ONE check every path asks: the first draw, every draw, a target change, the removal.\n */\n /** …and a range in a document whose WINDOW is gone is not intact either: core's release retired its components. */\n const intact = () => part !== undefined && part.$s!.parentNode !== null && part.$s!.parentNode === part.$e!.parentNode && usable(part.$s!.parentNode as Target);\n /** A fresh range at the end of `into`, drawn with `value` — the first draw, and the redraw of a destroyed range. */\n const fresh = (handoff: unknown[], into: Target, value: unknown) => {\n const doc = into.ownerDocument!;\n part = new (handoff[HANDOFF_CHILD_PART] as Part)(doc.createComment(''), doc.createComment(''));\n into.append(part.$s!, part.$e!);\n (handoff[HANDOFF_COMMIT_AS] as CommitAs)(into, part, value);\n };\n const hook = effect(\n (change) => {\n const handoff = registry.$H;\n if (handoff === undefined || handoff[HANDOFF_PROTOCOL] !== PROTOCOL) {\n /**\n * Once per page, in every build: a portal with no renderer of this release wired draws nothing (core's own\n * `no-renderer` covers a component's render, not this).\n */\n if (!printedPortal) {\n printedPortal = true;\n console.warn(__DEV__ ? diagnostic('renderer', 'portal', 'portal-no-renderer', __DEV__ && PROSE['portal-no-renderer']()) : '[vera] portal-no-renderer');\n }\n return;\n }\n const value = (last = typeof template === 'function' ? (template as (change: unknown) => unknown)(change) : template);\n if (intact()) (handoff[HANDOFF_COMMIT_AS] as CommitAs)(current, part!, value);\n else fresh(handoff, current, value);\n registry.$so?.(hook);\n },\n { priority: 50 }\n );\n /**\n * The removal: a second hook, reading nothing, whose cleanup runs only when the owner retires or pauses. At 50 too —\n * a cross-window move re-runs the layout (60) and effect (75) priorities, and this must not run then.\n */\n effect(\n () => () => {\n if (part === undefined) return;\n if (intact()) (registry.$H![HANDOFF_COMMIT_AS] as CommitAs)(current, part, null);\n part.$s!.remove();\n (part.$e as ChildNode).remove();\n part = undefined;\n },\n { priority: 50 }\n );\n /**\n * **A function target follows** — only then: a third hook, at EFFECT priority (75) so a cross-window move re-runs it,\n * re-reads the target (tracked, so a store it reads moves it too) and, when the answer changed, moves the range — the\n * markers and what lies between them — into it. Moving keeps every node, components included.\n */\n if (typeof target === 'function')\n effect(() => {\n const next = target();\n if (!usable(next) || next === current) return;\n const from = current;\n current = next;\n if (part === undefined) return;\n /** A destroyed range is drawn afresh into the new target from the last value (its components set up again). */\n if (!intact()) return fresh(registry.$H!, next, last);\n const nodes: Node[] = [];\n for (let n: Node | null = part.$s!; n !== null; n = n.nextSibling) {\n nodes.push(n);\n if (n === part.$e) break;\n }\n /**\n * Within ONE document, `moveBefore` (Chromium, Firefox) keeps what an insertion would reset — focus, a playing media\n * element, an iframe — so a reactive target switching containers loses none of it. Across documents, or where it is\n * absent (WebKit), `append`: a cross-document insertion adopts.\n */\n const move = (next as Partial<{ moveBefore: (n: Node, c: Node | null) => void }>).moveBefore;\n if (move !== undefined && from.isConnected && next.isConnected && part.$s!.getRootNode() === next.getRootNode())\n for (const n of nodes) move.call(next, n, null);\n else next.append(...nodes);\n });\n};\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACI,MAAM,IAAI,GAAG,uBAAuB;AA2FpC,MAAM,UAAU,GAAG,CACxB,MAAc,EACd,SAAiB,EACjB,QAAgB,EAChB,QAA6C;AAE7C;AACA,OAAO,IAAI;AACT,MAAE,CAAA,OAAA,EAAU,MAAM,CAAA,EAAA,EAAK,SAAS,CAAA,GAAA,EAAM,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAA,CAAA,EAAI,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAE,GAAG,EAAE,CAAA,EAAA,EAAK,QAAQ,CAAA,CAAA;MACnG,CAAA,OAAA,EAAU,MAAM,CAAA,EAAA,EAAK,SAAS,MAAM,IAAI,CAAA,EAAG,QAAQ,CAAA,CAAE;;AC1G3D;;;;AAIG;AACH;AAsCA;;;;;;AAMG;AACH;;;;AAIG;AACI,MAAM,QAAQ,GAAG,CAAC;AACzB;AACO,MAAM,gBAAgB,GAAG,CAAC;AAI1B,MAAM,kBAAkB,GAAG,CAAC;AAM5B,MAAM,iBAAiB,GAAG,CAAC;;AChE3B,MAAM,KAAK,GAA0B;IAC1C,oBAAoB,EAAE,MAAM;QAC1B,4EAA4E;QAC5E,iHAAiH;AAClH,KAAA;CACF;;ACFD;AACA,IAAI,aAAa,GAAG,KAAK;AAUzB;;;;AAIG;AACH,MAAM,QAAQ,GAAI,UAA6C,CAAC,gBAAgB,KAAK,IAAI;AA2BzF;;;;;AAKG;AACH,MAAM,MAAM,GAAG,CAAC,CAA4B,KAAiB;AAC3D,IAAA,MAAM,IAAI,GAAG,CAAC,EAAE,aAAa,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C9B,MAAM,CAAC,MAAK;AACV,YAAA,MAAM,IAAI,GAAG,MAAM,EAAE;YACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,OAAO;gBAAE;YACvC,MAAM,IAAI,GAAG,OAAO;YACpB,OAAO,GAAG,IAAI;YACd,IAAI,IAAI,KAAK,SAAS;gBAAE;;YAExB,IAAI,CAAC,MAAM,EAAE;gBAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAG,EAAE,IAAI,EAAE,IAAI,CAAC;YACrD,MAAM,KAAK,GAAW,EAAE;AACxB,YAAA,KAAK,IAAI,CAAC,GAAgB,IAAI,CAAC,EAAG,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE;AACjE,gBAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,gBAAA,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE;oBAAE;YACrB;AACA;;;;AAIG;AACH,YAAA,MAAM,IAAI,GAAI,IAAmE,CAAC,UAAU;YAC5F,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,EAAG,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE;gBAC7G,KAAK,MAAM,CAAC,IAAI,KAAK;oBAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC;;AAC5C,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;AAC5B,QAAA,CAAC,CAAC;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"vera-renderer-portal.js","sources":["../../../shared-utils/src/diagnostic.ts","../../src/kinds.ts","../../src/portal-diagnostics.ts","../../src/portal.ts"],"sourcesContent":["/**\n * **Where every diagnostic code is explained.** The URL is permanent: a released bundle is immutable, so every version\n * published points here for ever — the domain cannot lapse and `/e/` cannot be reorganized without breaking links in\n * code nobody can edit; the docs site redirects instead. `scripts/sync-diagnostics.mjs` imports this constant, so the\n * pages and the bundles can never disagree about where they are.\n */\nexport const DOCS = 'https://verajs.dev/e/';\n\n/**\n * **What this copy of the framework has already said** (Brian's ruling, 2026-11-12): the ONE memory behind `warnOnce`, `errorOnce`\n * and `hasWarned`, for DEVELOPMENT-ONLY warnings. It replaced the hand-written once-flags every package kept\n * (`saidLists`, `warnedDrop`, per-element WeakSets, per-key Sets: two naming styles, Brian: no names). **A warning that\n * ships to production keeps its memory at its site** (bytes, measured 2026-11-12: the shared memory costs +80–145 B gz\n * per bundle); development-only warnings use warnOnce. Module state by necessity, since \"once\" spans every call on the\n * page. One per BUNDLE COPY, exactly the scope each flag had, because this package is inlined into every bundle.\n * A code, or `code key` for a string key, in a Set. An object key (an element, a setup function) in a WeakMap, so its\n * entry goes with the object. Marked pure, so a bundle that never prints once drops both.\n */\nconst printed = /* @__PURE__ */ new Set<string>();\nconst printedOn = /* @__PURE__ */ new WeakMap<object, Map<string, Set<unknown>>>();\n/**\n * A once's KEY: none (once per page), a string (once per that string), an object (once per that object: an element, a\n * class, a setup function), or the PAIR `[object, value]`, a value key on that object (a store write: the object and its\n * property; a keyed list: the list and the duplicate key, compared as the list compares them, by value, so `1` and `'1'`\n * stay apart). A pair is the only array a key may be.\n */\ntype OnceKey = string | object | readonly [object, unknown];\n/** Where an object key's (code, value) lives: the value set for that code on that object, made on demand. */\nconst valuesOn = (on: object, code: string, make: boolean): Set<unknown> | undefined => {\n let codes = printedOn.get(on);\n if (codes === undefined) {\n if (!make) return undefined;\n printedOn.set(on, (codes = new Map()));\n }\n let values = codes.get(code);\n if (values === undefined && make) codes.set(code, (values = new Set()));\n return values;\n};\n/** The object and value of an object or pair key. */\nconst split = (key: object): readonly [object, unknown] => (Array.isArray(key) ? (key as unknown as readonly [object, unknown]) : [key, undefined]);\n/** Whether (code, key) is new, recording it if so. */\nconst firstTime = (code: string, key?: OnceKey): boolean => {\n if (key === undefined || typeof key === 'string') {\n const entry = key === undefined ? code : `${code} ${key}`;\n if (printed.has(entry)) return false;\n printed.add(entry);\n return true;\n }\n const [on, sub] = split(key);\n const values = valuesOn(on, code, true)!;\n if (values.has(sub)) return false;\n values.add(sub);\n return true;\n};\n\n/**\n * **One shape for every diagnostic the framework prints** — the short line production keeps, the whole sentence\n * development adds — so a package converting its messages writes a table and a call, never its own format.\n *\n * production `[vera] hydration: element: found <i> — https://verajs.dev/e/hydration-fallback`\n * development `[vera] hydration: element: found <i> — fell back to a client render: … (hydration-fallback)`\n *\n * `subject` is the free information — what the code already has at hand, naming the problem area — the same in both\n * builds. `prose` is development only: the package's table entry (`Prose`), called behind `__DEV__` at the call site so\n * the table goes unreferenced in production and rollup drops it whole. Production prints the code inside the link, so\n * the reader is one click from the explanation, which `scripts/sync-diagnostics.mjs` publishes from the same tables.\n *\n * **Every production message is coded** (Brian, 2026-11-11; this supersedes \"convert where smaller\", 2026-10-02):\n * consistency over a few bytes, so no package keeps a hand-written production line beside its table.\n */\n/*\n * The parameter names are deliberately unlike anything a caller holds: terser will not inline a function whose\n * parameter shadows a name at the call site (measured 2026-10-02 — directives passes its own `code`, and a parameter\n * called `code` left `((e,t,n)=>`…`)(0,t,n)` in its bundle, +8 B; renamed, the call folds to the bare template).\n */\n/**\n * **A misused API, named by its function** — the thrown-error twin of `diagnostic()`: `untrack: expected a function …\n * (untrack-not-function)`, function-first because a stack already names the source and the sweep reads that shape. The\n * prose comes from a package's table, behind `__DEV__`, so a development-only guard costs production nothing.\n */\nexport const misuse = (forName: string, withCode: string, andProse?: false | readonly [string, string?]) =>\n __DEV__ && andProse\n ? `${forName}: ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `${forName}: ${DOCS}${withCode}`;\n\n/**\n * **A misused API and what it was misused ABOUT** — `misuse()` with a subject, in `diagnostic()`'s ` — ` separator:\n * `parseFrontmatter: line 3 — https://verajs.dev/e/cms-frontmatter-unsupported`. The subject is the free information\n * (a line, a URL and its status) and prints in both builds. A sibling rather than an optional parameter on `misuse()`,\n * because `misuse()` is inlined into every bundle that throws and a conditional subject would tax all of them for a\n * shape few need; a sibling is tree-shaken where unused.\n */\nexport const misuseAbout = (forName: string, aboutSubject: string, withCode: string, andProse?: false | readonly [string, string?]) =>\n __DEV__ && andProse\n ? `${forName}: ${aboutSubject} — ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `${forName}: ${aboutSubject} — ${DOCS}${withCode}`;\n\nexport const diagnostic = (\n inArea: string,\n bySubject: string,\n withCode: string,\n andProse?: false | readonly [string, string?]\n) =>\n /** `__DEV__` HERE as well as at the call: production folds this to the one-line form, branch and all. */\n __DEV__ && andProse\n ? `[vera] ${inArea}: ${bySubject} — ${andProse[0]}${andProse[1] ? ` ${andProse[1]}` : ''} (${withCode})`\n : `[vera] ${inArea}: ${bySubject} — ${DOCS}${withCode}`;\n\n/**\n * **Text from outside — a file path, a YAML key, a URL, an error's message — quoted before it reaches a line.** A log is a\n * pipeline, and such text can be shaped by an author or a request: a newline in it forges a line, an ESC sequence hides\n * one (log injection). `JSON.stringify` escapes both; cut to 80 characters so one value cannot fill the log. @verajs/ssr\n * keeps a twin (it cannot import this), held equal by tests/ssr-coded-diagnostics.\n */\n/**\n * `max` caps the length (80 by default); `Infinity` keeps the whole text for a value worth reading in full — a site\n * owner's own path — which is still ESCAPED: truncation and escaping are separate jobs, and a path is not free of control\n * characters just because its owner wrote it (2026-10-09).\n */\nexport const quoted = (text: string, max = 80): string => JSON.stringify(text.length > max ? `${text.slice(0, max)}…` : text);\n\n/**\n * **The errors a package constructs, marked as its own** — so a wrapper that reports an inner refusal (cms's\n * `generateManifest` around a frontmatter line) carries it as it is: already formatted, its outside text already\n * quoted. Anything else is foreign, and quoted. Identity, never a shape test: a message can imitate ours, an identity\n * cannot. @verajs/ssr keeps a twin (it cannot import this).\n */\nconst ours = /* @__PURE__ */ new WeakSet<object>();\nexport const own = <E extends Error>(error: E): E => {\n ours.add(error);\n return error;\n};\nexport const isOwn = (error: unknown): boolean => typeof error === 'object' && error !== null && ours.has(error);\n\n/**\n * **Whether this copy has already said `code` (for `key`)**: for a GUARD only, where deciding to warn costs work worth\n * skipping once the warning is out (development's whole-tree walk for unwired directive attributes, an event-name\n * guess over every property of an element). A site that only prints calls `warnOnce`. Asks, never records.\n */\nexport const hasWarned = (code: string, key?: OnceKey): boolean => {\n if (key === undefined || typeof key === 'string') return printed.has(key === undefined ? code : `${code} ${key}`);\n const [on, sub] = split(key);\n return valuesOn(on, code, false)?.has(sub) === true;\n};\n\ntype Detail = false | readonly [string, string?] | (() => readonly [string, string?] | undefined);\n/**\n * The printer behind both, on one level. `andDetail` is `diagnostic()`'s prose, or a function returning it where building\n * the sentence costs something: it is called only the first time. `...andMore` rides beside the line behind '%s' (an\n * element, a thrown error), never inside it, so text from outside cannot forge a line. The console method is read at the\n * call, so a test that replaces `console.warn` sees it.\n */\nconst sayOnce =\n (level: 'warn' | 'error') =>\n (inArea: string, bySubject: string, withCode: string, andDetail?: Detail, forKey?: OnceKey, ...andMore: unknown[]): void => {\n if (!firstTime(withCode, forKey)) return;\n const line = diagnostic(inArea, bySubject, withCode, typeof andDetail === 'function' ? andDetail() : andDetail);\n if (andMore.length) console[level]('%s', line, ...andMore);\n else console[level](line);\n };\n/**\n * **A diagnostic said once per page** (per key, where one is given: a string, or an object such as the element it is\n * about): `diagnostic()`'s arguments, then the key, then what rides beside the line. Coded in production exactly as\n * `diagnostic()` is, because it IS `diagnostic()`. `errorOnce` is its twin on `console.error`, for a refusal a page should\n * not miss.\n */\nexport const warnOnce = /* @__PURE__ */ sayOnce('warn');\nexport const errorOnce = /* @__PURE__ */ sayOnce('error');\n","/**\n * **The renderer's binding kinds and child-part modes** — numbers both `renderer.ts` and the separately bundled\n * `hydration.ts` read, from ONE source (each bundle inlines them; they are literals in the output). A change here\n * changes the hand-off's protocol: bump `$V` in `renderer.ts`.\n */\n/** A binding's kind, resolved once per template. */\nexport const IGNORED = 0; // consumed, nothing rendered: inside a comment, the later values of a multi-part attribute\nexport const CHILD = 1; // anchored on a primed empty text node the template carries\nexport const SOLE = 2; // its element's only content: no anchor in the template, the first commit writes `textContent`\nexport const ATTR = 3;\nexport const PROPERTY = 4;\nexport const BOOLEAN = 5;\n/** `EVENT` through `ADOPT` hold a `Slot` record in their node slot — one range test, in `instantiate` and `commit`. */\nexport const EVENT = 6;\n/** An element-position expression: a ref, or a value that applies itself (`_$apply$`). */\nexport const REF = 7;\n/** An element-position expression ON a `<select>`: a value applying itself there (a spread) waits for `flush`. */\nexport const SELECT_REF = 8;\n/** `.name` on a custom element — see `adoptProperty` in shared-utils. */\nexport const ADOPT = 9;\n/**\n * Kinds from here on re-assert on EVERY render, so the update loop never skips them as unchanged:\n * `!name` writes from the live DOM's point of view (a sibling radio's click unchecks this one with no\n * event on it), and a `<select>`'s selection is re-applied after its options exist — see `flush`.\n */\nexport const LIVE = 10;\n/** A `<select>`'s selection — `value` or `selectedIndex` (`isSelection`) — written when the pass ends: see `flush`. */\nexport const SELECT = 11;\n/** `!name` on a custom element: compared against the LIVE value — read through `untracked`, it is the component's getter. */\nexport const LIVE_CUSTOM = 12;\n/** A binding that must never write — and, from here on, the kinds `commit` handles before anything is computed. */\nexport const REFUSED = 13;\n/** A `<select>`'s `selectedIndex` — the rare spelling of its selection, queued as `SELECT` is (see `flush`). */\nexport const SELECT_INDEX = 14;\n/**\n * **An HTML `<style>`'s or JSON data block's whole text** — ONE binding (the element's first value; the others are\n * consumed, as a multi-part attribute's are) composes the statics and values and writes the element's text when it\n * changed. Its text is serialized VERBATIM (BROWSER-LEDGER), so it is written unable to end its element, as the server\n * writes it: in a style each `</style` as `<\\/style`, in a JSON block every `<` as `\\u003c` — on the COMPOSED text, since\n * a closer can form across a hole. Committed in `commit`'s cold branch: the hot text line is untouched.\n */\nexport const RAW_STYLE = 15;\nexport const RAW_JSON = 16;\n/**\n * **An element whose content is never shown** (`<iframe>`, `<noscript>`, `<xmp>`, `<noembed>`, `<noframes>`,\n * `<plaintext>`): its statics and its values composed as text, each VALUE fully encoded (every ASCII non-word character\n * as a character reference), so a page saved from the DOM and parsed again — with scripting on (raw text) or off\n * (markup) — holds no value that can end the element or add an attribute.\n */\nexport const RAW_ENCODED = 17;\n\n\n/** A child part's mode: what its range currently holds. */\nexport const EMPTY = 0;\nexport const TEXT = 1;\nexport const TEMPLATE = 2;\nexport const LIST = 3;\nexport const NODE = 4;\n\n/**\n * **The hydration hand-off's positions** — the renderer sets `$H` to an array at `connect`, and `hydration.ts` reads\n * it by these. An array, not an object of named fields: the names cost every app bytes (−35 B gzipped measured,\n * 2026-10-02), and these constants inline to literals in both bundles. The first two are FROZEN across protocols — a\n * hydration from another release reads the protocol at 0 and, on a mismatch, can still install its clearing hook at 1.\n * Any other change here is a protocol change: bump `PROTOCOL`.\n */\n/**\n * **The protocol of this package's first-party seams** — the renderer's hand-off (`$H`, at `HANDOFF_PROTOCOL`) and slots'\n * capture (`_$capture$`), both read by hydration. One number for both: the three ship in one package, and a change to\n * either seam bumps it. A hydration that meets another number declines (the page renders fresh) and says so.\n */\nexport const PROTOCOL = 2;\n/** The protocol number — FROZEN at 0. */\nexport const HANDOFF_PROTOCOL = 0;\n/** The first-render hook's setter — FROZEN at 1. */\nexport const HANDOFF_ADOPTER = 1;\nexport const HANDOFF_GET_TEMPLATE = 2;\nexport const HANDOFF_CHILD_PART = 3;\nexport const HANDOFF_INSTANCE = 4;\nexport const HANDOFF_SLOT = 5;\nexport const HANDOFF_UNSET = 6;\nexport const HANDOFF_UPGRADED = 7;\nexport const HANDOFF_COMMIT = 8;\nexport const HANDOFF_COMMIT_AS = 9;\nexport const HANDOFF_HOOK_UP = 10;\nexport const HANDOFF_RESOLVE = 11;\nexport const HANDOFF_ROOTS = 12;\nexport const HANDOFF_TO_TEXT = 13;\nexport const HANDOFF_REMOVAL_WORK = 14;\n","/** **`@verajs/renderer/portal`'s diagnostics — DEVELOPMENT ONLY.** Its bundle's own table, merged into the renderer's json. */\nimport type { Prose } from '@verajs/shared-utils';\n\nexport const PROSE: Record<string, Prose> = {\n 'portal-no-renderer': () => [\n 'a portal has no renderer of this release to draw with, so it drew nothing.',\n 'Wire the renderer once at your entry — `wire([renderer])` — from the same release as `@verajs/renderer/portal`.',\n ],\n};\n","import { effect, inserts, untrack } from '@verajs/core';\nimport { diagnostic } from '@verajs/shared-utils';\nimport { HANDOFF_CHILD_PART, HANDOFF_COMMIT_AS, HANDOFF_PROTOCOL, PROTOCOL } from './kinds.js';\nimport { PROSE } from './portal-diagnostics.js';\nimport type { ChildPart } from './renderer.js';\n\n/** Whether `portal-no-renderer` has been printed: once per page, in every build (a warning that ships to production keeps its memory at its site: the shared memory costs +80–145 B gz per bundle, measured 2026-11-12). */\nlet printedPortal = false;\n\n/** What this entry reads off core's registry: the renderer's hand-off and core's settle. `$`-named — never mangled. */\ntype Registry = {\n $H?: unknown[];\n $so?: (hook: unknown, all?: boolean) => void;\n};\ntype Part = new (start: Comment, end: Comment) => ChildPart;\ntype CommitAs = (root: Node, part: ChildPart, value: unknown) => void;\n\n/**\n * **A server registers nothing** — `@verajs/ssr` sets this public flag at import, before anything renders (the renderer\n * reads it the same way). A server turn runs a setup's effects, and with no client renderer there every request said\n * `portal-no-renderer` (measured 2026-10-22); a portal has nothing to draw there, and hydration nothing to adopt.\n */\nconst onServer = (globalThis as { __veraSsrShimmed?: boolean }).__veraSsrShimmed === true;\n\n/**\n * **`portal(target, template)` — draws into ANOTHER element, from a component's setup** (2026-10-22, the API\n * distillation: it replaced `useRender`'s one job no returned render can do). A modal on `document.body`, a tooltip\n * in an overlay layer, a row in another component's light DOM.\n *\n * - **Its own range.** Two comments, appended to `target`, bound what it draws, so any number share one target (two\n * components drawing into `document.body` with `renderInto` — one root per container — replaced each other).\n * - **The render's slot.** It runs at the render's priority (50): a keyed `.map` keeps its rows with their items, it is\n * drawn before the component's layout effects, and what its draw made and no longer reaches (an automatic list, a\n * computed) is freed after each draw, as the component's own render frees it.\n * - **Owned by the component being set up**, whose removal takes its content and markers out of `target`; a paused\n * component (`persist`) takes them out too, and draws afresh when it is back. A cross-window MOVE of the component\n * leaves it where it is: `target` is where it was asked to draw.\n * - **Light DOM.** `target` itself, never its shadow root: into a shadow host it is the host's light content, slotted\n * where the host's template says.\n * - **The client only.** A server renders a component's own template; a portal registers nothing there, so hydration\n * finds no range to adopt and the client draws it once.\n * - **A target FUNCTION follows** (Brian, 2026-10-25): `portal(() => host.ownerDocument.body, …)` is evaluated at setup\n * and again whenever what it reads changes or its component moves into another window (a cross-window move re-runs effect\n * priority), and a different answer MOVES the drawn range into the new target — never a redraw, so components inside\n * keep their state. A popped-out panel's modal then opens in the pop-out. A plain element target never moves.\n *\n * Additive, like `hydration`: it imports no renderer and reaches the one wired through its hand-off (`$H`).\n */\ntype Target = Element | DocumentFragment;\n/**\n * **No target, or a dead one, leaves the range WHERE IT IS** (2026-10-25): a falsy answer, or a target whose window is gone\n * (a closed pop-out: no live `defaultView`), moves nothing — so nothing is removed and the components inside keep their\n * state (holding the range in a detached fragment would be a REMOVAL, which tears them down) — and the next real target\n * gets it. Nothing throws.\n */\nconst usable = (t: Target | null | undefined): t is Target => {\n const view = t?.ownerDocument?.defaultView;\n return view != null && !view.closed;\n};\nexport const portal = (target: Target | (() => Target | null | undefined), template: unknown): void => {\n if (onServer) return;\n let part: ChildPart | undefined;\n /** Where it draws now: a function target is read once here, untracked, so the draw does not subscribe to it. */\n let current: Target;\n if (typeof target === 'function') {\n const first = untrack(target);\n /** No usable target yet: drawn into a fragment of THIS realm's document until one exists — portal is handed no element to take one from. */\n current = usable(first) ? first : document.createDocumentFragment();\n } else current = target;\n /** The last value drawn, for a redraw when the range was destroyed (below). */\n let last: unknown;\n const registry = inserts as unknown as Registry;\n /**\n * **The range is INTACT while both markers sit in one parent** (2026-10-25). User code clearing the target —\n * `container.innerHTML = ''`, a router swapping a container's children, an overlay library emptying its root — or a dead\n * window taking its document's nodes (jsdom) removes them, and a draw into detached markers would be invisible (and a\n * cleanup into them threw). The ONE check every path asks: the first draw, every draw, a target change, the removal.\n */\n /** …and a range in a document whose WINDOW is gone is not intact either: core's release retired its components. */\n const intact = () => part !== undefined && part.$s!.parentNode !== null && part.$s!.parentNode === part.$e!.parentNode && usable(part.$s!.parentNode as Target);\n /** A fresh range at the end of `into`, drawn with `value` — the first draw, and the redraw of a destroyed range. */\n const fresh = (handoff: unknown[], into: Target, value: unknown) => {\n const doc = into.ownerDocument!;\n part = new (handoff[HANDOFF_CHILD_PART] as Part)(doc.createComment(''), doc.createComment(''));\n into.append(part.$s!, part.$e!);\n (handoff[HANDOFF_COMMIT_AS] as CommitAs)(into, part, value);\n };\n const hook = effect(\n (change) => {\n const handoff = registry.$H;\n if (handoff === undefined || handoff[HANDOFF_PROTOCOL] !== PROTOCOL) {\n /**\n * Once per page, in every build: a portal with no renderer of this release wired draws nothing (core's own\n * `no-renderer` covers a component's render, not this).\n */\n if (!printedPortal) {\n printedPortal = true;\n console.warn(__DEV__ ? diagnostic('renderer', 'portal', 'portal-no-renderer', __DEV__ && PROSE['portal-no-renderer']()) : '[vera] portal-no-renderer');\n }\n return;\n }\n const value = (last = typeof template === 'function' ? (template as (change: unknown) => unknown)(change) : template);\n if (intact()) (handoff[HANDOFF_COMMIT_AS] as CommitAs)(current, part!, value);\n else fresh(handoff, current, value);\n registry.$so?.(hook);\n },\n { priority: 50 }\n );\n /**\n * The removal: a second hook, reading nothing, whose cleanup runs only when the owner retires or pauses. At 50 too —\n * a cross-window move re-runs the layout (60) and effect (75) priorities, and this must not run then.\n */\n effect(\n () => () => {\n if (part === undefined) return;\n if (intact()) (registry.$H![HANDOFF_COMMIT_AS] as CommitAs)(current, part, null);\n part.$s!.remove();\n (part.$e as ChildNode).remove();\n part = undefined;\n },\n { priority: 50 }\n );\n /**\n * **A function target follows** — only then: a third hook, at EFFECT priority (75) so a cross-window move re-runs it,\n * re-reads the target (tracked, so a store it reads moves it too) and, when the answer changed, moves the range — the\n * markers and what lies between them — into it. Moving keeps every node, components included.\n */\n if (typeof target === 'function')\n effect(() => {\n const next = target();\n if (!usable(next) || next === current) return;\n const from = current;\n current = next;\n if (part === undefined) return;\n /** A destroyed range is drawn afresh into the new target from the last value (its components set up again). */\n if (!intact()) return fresh(registry.$H!, next, last);\n const nodes: Node[] = [];\n for (let n: Node | null = part.$s!; n !== null; n = n.nextSibling) {\n nodes.push(n);\n if (n === part.$e) break;\n }\n /**\n * Within ONE document, `moveBefore` (Chromium, Firefox) keeps what an insertion would reset — focus, a playing media\n * element, an iframe — so a reactive target switching containers loses none of it. Across documents, or where it is\n * absent (WebKit), `append`: a cross-document insertion adopts.\n */\n const move = (next as Partial<{ moveBefore: (n: Node, c: Node | null) => void }>).moveBefore;\n if (move !== undefined && from.isConnected && next.isConnected && part.$s!.getRootNode() === next.getRootNode())\n for (const n of nodes) move.call(next, n, null);\n else next.append(...nodes);\n });\n};\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACI,MAAM,IAAI,GAAG,uBAAuB;AA2FpC,MAAM,UAAU,GAAG,CACxB,MAAc,EACd,SAAiB,EACjB,QAAgB,EAChB,QAA6C;AAE7C;AACA,OAAO,IAAI;AACT,MAAE,CAAA,OAAA,EAAU,MAAM,CAAA,EAAA,EAAK,SAAS,CAAA,GAAA,EAAM,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAA,CAAA,EAAI,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAE,GAAG,EAAE,CAAA,EAAA,EAAK,QAAQ,CAAA,CAAA;MACnG,CAAA,OAAA,EAAU,MAAM,CAAA,EAAA,EAAK,SAAS,MAAM,IAAI,CAAA,EAAG,QAAQ,CAAA,CAAE;;AC1G3D;;;;AAIG;AACH;AAsDA;;;;;;AAMG;AACH;;;;AAIG;AACI,MAAM,QAAQ,GAAG,CAAC;AACzB;AACO,MAAM,gBAAgB,GAAG,CAAC;AAI1B,MAAM,kBAAkB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I,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC;;AAC5C,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;AAC5B,QAAA,CAAC,CAAC;AACN;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vera-renderer-profiler.d.ts","sources":["../../src/types.ts","../../src/renderer.ts","../../src/profiler.ts"],"mappings":"AAAA;;;;;;;;;;;;;;;;;AAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACjBH;;;;;;;;;;;;;;;;AAgBG;;
|
|
1
|
+
{"version":3,"file":"vera-renderer-profiler.d.ts","sources":["../../src/types.ts","../../src/renderer.ts","../../src/profiler.ts"],"mappings":"AAAA;;;;;;;;;;;;;;;;;AAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACjBH;;;;;;;;;;;;;;;;AAgBG;;AA2PC;;;;AAIG;AACH;AACA;AACA;;cAEE,IAAI;sBACM;AACV;AAYC,cAAA,UAAA,+BAAA,IAAA;AACH,KAAA;;;;;;;AAOE;AACA;;;AAEA;mBACI;yCACU,cAAA;;AAEd,gBAAI,cAA8B,aAAA,QAAA;AAClC;AACE;;qBACsC,QAAM;AAC5C;AACA;AACE;;AACK;;;AAEH;AACE;;;;AAIG;AACH;;;sCAGE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACnSb;AACH;AASA;AAKA;AAIA,cAAa,YAAM,aAAA,cAAA;AACnB;AACA,cAAc,YAAE,WAAA,aAAA;;;;","names":[]}
|