@niscorp/nova 0.1.3 → 0.2.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.
- package/ADAPTER.md +6 -0
- package/CHANGELOG.md +44 -0
- package/README.md +53 -0
- package/dist/adapters/dom/components/index.d.cts +2 -2
- package/dist/adapters/dom/components/index.d.ts +2 -2
- package/dist/adapters/dom/index.cjs +227 -4
- package/dist/adapters/dom/index.cjs.map +1 -1
- package/dist/adapters/dom/index.d.cts +2 -2
- package/dist/adapters/dom/index.d.ts +2 -2
- package/dist/adapters/dom/index.js +7 -7
- package/dist/adapters/dom/server.cjs +10 -1
- package/dist/adapters/dom/server.cjs.map +1 -1
- package/dist/adapters/dom/server.d.cts +2 -2
- package/dist/adapters/dom/server.d.ts +2 -2
- package/dist/adapters/dom/server.js +7 -7
- package/dist/adapters/react/components/index.cjs +30 -10
- package/dist/adapters/react/components/index.cjs.map +1 -1
- package/dist/adapters/react/components/index.d.cts +4 -4
- package/dist/adapters/react/components/index.d.ts +4 -4
- package/dist/adapters/react/components/index.js +9 -5
- package/dist/adapters/react/index.cjs +400 -99
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.d.cts +4 -4
- package/dist/adapters/react/index.d.ts +4 -4
- package/dist/adapters/react/index.js +9 -5
- package/dist/adapters/tty/components/index.d.cts +2 -2
- package/dist/adapters/tty/components/index.d.ts +2 -2
- package/dist/adapters/tty/index.cjs +6 -1
- package/dist/adapters/tty/index.cjs.map +1 -1
- package/dist/adapters/tty/index.d.cts +2 -2
- package/dist/adapters/tty/index.d.ts +2 -2
- package/dist/adapters/tty/index.js +12 -1
- package/dist/adapters/tty/index.js.map +1 -1
- package/dist/adapters/vue/components/index.cjs +30 -1
- package/dist/adapters/vue/components/index.cjs.map +1 -1
- package/dist/adapters/vue/components/index.d.cts +9 -9
- package/dist/adapters/vue/components/index.d.ts +9 -9
- package/dist/adapters/vue/components/index.js +9 -5
- package/dist/adapters/vue/index.cjs +347 -23
- package/dist/adapters/vue/index.cjs.map +1 -1
- package/dist/adapters/vue/index.d.cts +4 -4
- package/dist/adapters/vue/index.d.ts +4 -4
- package/dist/adapters/vue/index.js +10 -9
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/agent/index.d.cts +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/{chunk-IGLCWXQ3.js → chunk-3JRTELLC.js} +3 -3
- package/dist/{chunk-IGLCWXQ3.js.map → chunk-3JRTELLC.js.map} +1 -1
- package/dist/{chunk-GVBBL36G.js → chunk-DIFE573X.js} +196 -4
- package/dist/chunk-DIFE573X.js.map +1 -0
- package/dist/{chunk-FQAJ24KA.js → chunk-MHW5VEIM.js} +33 -8
- package/dist/chunk-MHW5VEIM.js.map +1 -0
- package/dist/chunk-OE4E6IBD.js +25 -0
- package/dist/chunk-OE4E6IBD.js.map +1 -0
- package/dist/{chunk-3HGE3VWK.js → chunk-QXQCPH33.js} +33 -11
- package/dist/chunk-QXQCPH33.js.map +1 -0
- package/dist/chunk-RFBIGRCI.js +127 -0
- package/dist/chunk-RFBIGRCI.js.map +1 -0
- package/dist/{chunk-6N4WRC5V.js → chunk-RYIIIXDX.js} +85 -12
- package/dist/chunk-RYIIIXDX.js.map +1 -0
- package/dist/{chunk-7S5BNPUS.js → chunk-UDCXGDLQ.js} +36 -4
- package/dist/chunk-UDCXGDLQ.js.map +1 -0
- package/dist/chunk-V4BPFFFV.js +152 -0
- package/dist/chunk-V4BPFFFV.js.map +1 -0
- package/dist/{chunk-4ZID7UX5.js → chunk-VU6NNCEJ.js} +52 -8
- package/dist/{chunk-4ZID7UX5.js.map → chunk-VU6NNCEJ.js.map} +1 -1
- package/dist/{chunk-V32EVEVM.js → chunk-Y6XVPRYH.js} +316 -5
- package/dist/chunk-Y6XVPRYH.js.map +1 -0
- package/dist/devtools/index.d.cts +2 -2
- package/dist/devtools/index.d.ts +2 -2
- package/dist/devtools/index.js +4 -5
- package/dist/devtools/index.js.map +1 -1
- package/dist/document/index.cjs +308 -0
- package/dist/document/index.cjs.map +1 -0
- package/dist/document/index.d.cts +22 -0
- package/dist/document/index.d.ts +22 -0
- package/dist/document/index.js +6 -0
- package/dist/document/index.js.map +1 -0
- package/dist/head-CAzfTnpV.d.cts +25 -0
- package/dist/head-DRpbbj-l.d.ts +25 -0
- package/dist/i18n/index.d.cts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/index.cjs +191 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +5 -6
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
- package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
- package/dist/reflect/index.d.cts +2 -2
- package/dist/reflect/index.d.ts +2 -2
- package/dist/reflect/index.js +4 -5
- package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
- package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
- package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
- package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
- package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
- package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
- package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
- package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
- package/package.json +13 -3
- package/dist/chunk-3HGE3VWK.js.map +0 -1
- package/dist/chunk-6N4WRC5V.js.map +0 -1
- package/dist/chunk-7S5BNPUS.js.map +0 -1
- package/dist/chunk-FQAJ24KA.js.map +0 -1
- package/dist/chunk-GVBBL36G.js.map +0 -1
- package/dist/chunk-PF4OJTYU.js +0 -199
- package/dist/chunk-PF4OJTYU.js.map +0 -1
- package/dist/chunk-RQB4PRPV.js +0 -285
- package/dist/chunk-RQB4PRPV.js.map +0 -1
- package/dist/chunk-V32EVEVM.js.map +0 -1
- package/dist/chunk-ZITHBBF3.js +0 -85
- package/dist/chunk-ZITHBBF3.js.map +0 -1
- package/dist/{primitive-props-BH_EJWIe.d.ts → primitive-props-CGoJvmcH.d.cts} +4 -4
- package/dist/{primitive-props-BH_EJWIe.d.cts → primitive-props-CGoJvmcH.d.ts} +4 -4
package/ADAPTER.md
CHANGED
|
@@ -44,6 +44,12 @@ Map `RenderNode[]` to framework elements:
|
|
|
44
44
|
adapter renders a `<span data-nova-error>`; match that convention).
|
|
45
45
|
- `component` → look the name up in the registry; unknown names render an
|
|
46
46
|
error marker with code `COMPONENT_NOT_FOUND`, never throw.
|
|
47
|
+
- a head (`isHeadNode(node)`, the component named `HEAD_NAME`) → **nothing**,
|
|
48
|
+
and nothing for its children. It is the document's, not the screen's: it is
|
|
49
|
+
never looked up in the registry, and never handed to its parent component as
|
|
50
|
+
a child (a kit that gives every child a cell would give it an empty one). An
|
|
51
|
+
adapter for a surface with a head of its own keeps that head on
|
|
52
|
+
`headOf(api)` — in a page, `createHeadKeeper` from `@niscorp/nova/document`.
|
|
47
53
|
|
|
48
54
|
Inject framework props from the node using the core constants:
|
|
49
55
|
`node.model` → `NOVA_MODEL_PROP` (`{ ref, path }`), `node.ref` →
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @niscorp/nova
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f1cec45: A Prism config that validates no longer names an op Prism does not have. `validate` accepted `{ card: { $fetch: … } }` and `{ $eval: "…" }`: the plain-object branch refused only the names of ops that exist, so any other `$` key passed as a template key. Such a config could be stored — an endpoint request, a vex mapping, a strata migration — and then failed every time it was evaluated (`E_NODE_SHAPE`, "Unsupported node shape").
|
|
8
|
+
|
|
9
|
+
A key that starts with `$` is now an op's name and nothing else. The template branch refuses every `$` key — the rule the evaluator already held — so `validate` reports it with the key and where it is (`card.$fetch: Not a Prism op. A key that starts with "$" names an op; data with such a key goes in $const.`), and `evaluate` and `compile` fail with `E_SCHEMA` before anything runs. An op's name used as a template key keeps its own message. `E_NODE_SHAPE` is left for a tree that never went through the schema: an IR handed to `execute`. Adding an op no longer takes a key away from templates.
|
|
10
|
+
- **prism** — the change, and a grammar narrowing: `nisc.prism` 2, a marker with no document step (a key that never evaluated has nothing to be rewritten to). `$` keys that are data are untouched: a `$const` payload, `$with` names, `$renameKeys` and `$fromEntries` keys. The JSON Schema's template key pattern is `^(?!\$)` instead of a list of every op.
|
|
11
|
+
- **nova, vex, moss, loom, cli, nisc** — no change of their own. They depend on prism and are released with it, so the set installs together; the configs they hand to prism (endpoint `request` and `response`, `$prism` bindings, vex mappings) are held to the same rule.
|
|
12
|
+
- **create-nisc** — the templates' sources are recorded at `nisc.prism` 2.
|
|
13
|
+
|
|
14
|
+
**What to change:** in a config with a `$`-prefixed key that is not a Prism op, remove the key — or put the object in `$const` if it is literal data. An app that keeps a `strata.lock.json` runs `pnpm strata upgrade`, then `pnpm strata verify`; there is nothing to edit unless it has such a config. Everything else: nothing.
|
|
15
|
+
|
|
16
|
+
BREAKING — approved by moccadroid, 2026-10-04: a config with a `$`-prefixed key that is not a Prism op no longer validates, compiles or evaluates — also where evaluation never reached the key (an untaken `$case` branch, a short-circuited `$or`, a `$map` body over an empty array), which used to work. A vex seed mapping with one fails when it is seeded, at boot, instead of on each replay. Code that matched `E_NODE_SHAPE` from `evaluate` gets `E_SCHEMA`. The `@niscorp` packages that depend on prism move with it, so an app moves them together (`@niscorp/nisc` 0.3.0).
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- de6d980: A fix for the last fix: `nova:head` is the document's `<head>`, and holds what a head holds. 0.1.4 gave it five props (`title`, `description`, `image`, `kind`, `structured`) and wrote tags from them, which closed a head to whatever nova had been taught: no `og:image:alt`, no `og:type` but two, no whole address inside structured data. That was wrong, and it is replaced, not extended. The maintainer withdrew 0.1.4's props on 2026-10-04; this ships as a patch on that decision.
|
|
21
|
+
|
|
22
|
+
**What to change** (only an app that used 0.1.4's props): a `nova:head` node no longer takes props. Write its children instead — `nova:title`, `nova:meta`, `nova:link`, `nova:script` — each with the element's attributes as its props. `{ title: X }` becomes `{ component: 'nova:title', children: X }`; `description` becomes `nova:meta` with `name: 'description'`; `image` and `kind` become `nova:meta` with `property: 'og:image'` and `property: 'og:type'`; `structured` becomes `nova:script` with `type: 'application/ld+json'` and `data`. `og:title` and `og:description` are no longer written from the title and description: say them if they are wanted. An address is written as given — a picture's is not made whole from `site`. Code that called `headOf`, `placeHead` or `createTitleKeeper`, or read `head` off `renderDocument`'s result or a route report, takes the new shapes below.
|
|
23
|
+
- **nova** — a head's children are the elements a head holds, named as HTML names them, and **a child's props are that element's attributes, written as given**: nova keeps no list of them, so any `name`, `property` or `rel` can be said. Nothing in a head is drawn on the screen and no name has to be registered. With more than one head on a screen they are read in the order the screen is drawn, and an element that says the same thing as an earlier one (the title, a `<meta>` of that name or property, the canonical address) takes its place; anything else stands beside its like. What runs or styles is refused, left out and named: a script a browser would execute (`nova:script` is a data block — a JSON `type`, never a `src`), a stylesheet, `http-equiv`, a handler attribute. `headOf(api)` returns `{ elements, actions, refused }`. In `@niscorp/nova/document`, `placeHead(html, elements, { site, path })` writes them — an element takes the place of the tag that said the same thing, where it stood; what it wrote is marked `data-nova-head`, and a tag that gave way is kept inert in a `<template data-nova-own>` — and `createHeadKeeper(document)` replaces `createTitleKeeper`: the whole head follows the screen in the page, and the document's own tags come back when the screen stops saying them. Removed: the five props, the `Head` and `HeadProps` types, `createTitleKeeper`.
|
|
24
|
+
- **cli** — `build`, `export` and `start` write each path's head from those elements. A head that holds what it may not fails the path, like any other check. `site` still gives every path its own canonical address and `og:url`; it no longer touches a picture's address.
|
|
25
|
+
- **moss** — `renderDocument` and `exportDocuments` do the same from the snapshot (`head` on the result is `{ elements, actions, refused }`; a refusal is logged and left out), and the terminal keeps the whole head off the wire.
|
|
26
|
+
- **create-nisc** — the two own-shell templates write their welcome screen's head this way.
|
|
27
|
+
|
|
28
|
+
**Where a script goes:** in the app's own `index.html`, which holds anything and from which every page is written, or in the kit component that needs it. A layout is data and does not carry one.
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [f1cec45]
|
|
31
|
+
- @niscorp/prism@0.2.0
|
|
32
|
+
|
|
33
|
+
## 0.1.4
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- af903c6: A page's head is its screen's own. `nisc export` wrote every path with the built `index.html`'s `<head>`, so a site with more than one page shipped each of them under the front page's title, description, preview card and canonical address.
|
|
38
|
+
|
|
39
|
+
What a screen says about itself is now a node in a layout: nova's `nova:head`, with `title`, `description`, `image`, `kind` and `structured` bound to the action's data like any other node's props. It draws nothing — no adapter builds an element for it, no registry has to hold it, and a component is never handed one as a child — and it rides in the render tree, so it reaches a shell in the page, a snapshot a server drew and the trees on a wire alike. `headOf(api)` reads it off any of them; with more than one on the screen the last one speaks.
|
|
40
|
+
- **nova** — `HEAD_NAME`, `HeadPropsSchema`, `HEAD_META`, `headOf`, `isHeadNode`; and `@niscorp/nova/document`: `placeHead` writes a head into an HTML document (the tag that said the same thing is replaced, a missing one is added before `</head>`, everything else is left as it was; values are escaped) and `createTitleKeeper` keeps a tab's title on it. The DOM, React and Vue adapters keep the title on the head as the screen moves, and give the page's own back when the screen has none.
|
|
41
|
+
- **cli** — `build`, `export` and `start` write each path's document with its screen's head. "Same twice" also fails a boot that says a different head the second time, and the route table says whose head each path goes out with once an app has one. New config field `site`: the address the site is served at. With it every path says its own canonical address (`<link rel="canonical">`, `og:url`) and a head's picture gets a whole address; a build with several paths, a canonical tag in `index.html` and no `site` says so.
|
|
42
|
+
- **moss** — `renderDocument` and `exportDocuments` do the same from the snapshot (`site` on the config, `head` on the result), and the terminal keeps the tab's title off the wire for every render target.
|
|
43
|
+
- **create-nisc** — the two own-shell templates say their welcome screen's head.
|
|
44
|
+
|
|
45
|
+
**What to change:** nothing. An app with no `nova:head` node and no `site` is built, served and drawn exactly as before. An app that rewrote its exported files to give each page a head can delete that step: put the node in the layout and set `site`.
|
|
46
|
+
|
|
3
47
|
## 0.1.3
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -229,6 +229,59 @@ canvas, drives lifecycle hooks via the runtime, composes any `with`
|
|
|
229
229
|
fragments into the action at push/replace time, and routes navigation
|
|
230
230
|
effects emitted from action steps back into shell calls.
|
|
231
231
|
|
|
232
|
+
### The head
|
|
233
|
+
|
|
234
|
+
`nova:head` is the document's `<head>`, as a node in a layout. Its children
|
|
235
|
+
are the elements a head holds, named as HTML names them, and bound to the
|
|
236
|
+
action's data like anything else in the layout:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
{ component: 'nova:head', children: [
|
|
240
|
+
{ component: 'nova:title', children: '{{$.page.title}} · the site' },
|
|
241
|
+
{ component: 'nova:meta', props: { name: 'description', content: '$.page.lead' } },
|
|
242
|
+
{ component: 'nova:meta', props: { property: 'og:image:alt', content: '$.page.title' } },
|
|
243
|
+
{ component: 'nova:link', props: { rel: 'alternate', hreflang: 'de', href: '$.page.german' } },
|
|
244
|
+
{ component: 'nova:script', props: { type: 'application/ld+json', data: '$.page.about' } },
|
|
245
|
+
]}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**A child's props are that element's attributes, written as given.** Nova
|
|
249
|
+
keeps no list of them: any `name`, `property` or `rel` there is — or will be —
|
|
250
|
+
can be said without nova learning it. `nova:title`'s text is its children;
|
|
251
|
+
`nova:script` takes a `type` and its `data` (any JSON). Loops and conditions
|
|
252
|
+
work in a head as they do anywhere in a layout.
|
|
253
|
+
|
|
254
|
+
**Nothing in it is drawn on the screen.** No adapter builds an element for a
|
|
255
|
+
head or for what it holds, no registry has to have the names, and a component
|
|
256
|
+
is never handed a head as a child. It rides in the render tree, so it reaches
|
|
257
|
+
every place a screen does — a shell in the page, a snapshot a server drew, the
|
|
258
|
+
trees on a wire — and `headOf(api)` reads it off any of them:
|
|
259
|
+
`{ elements, actions, refused }`.
|
|
260
|
+
|
|
261
|
+
A screen can hold more than one head: the shell's chrome says what holds on
|
|
262
|
+
every screen, an action says its own, a dialog opens over a page. They are
|
|
263
|
+
read in the order the screen is drawn, and an element that says the same thing
|
|
264
|
+
as an earlier one — the title, a `<meta>` of that name or property, the
|
|
265
|
+
canonical address — takes its place. Anything else stands beside its like. An
|
|
266
|
+
element whose value is not answered yet (no `content`, no `href`, no text) is
|
|
267
|
+
left out.
|
|
268
|
+
|
|
269
|
+
**What a head does not hold is what runs or styles**: a script a browser would
|
|
270
|
+
execute (`nova:script` is a data block — a JSON `type`, never a `src`), a
|
|
271
|
+
stylesheet, `http-equiv`, a handler attribute. A layout is data, and data that
|
|
272
|
+
reaches every page must not be able to run. Such an element is left out and
|
|
273
|
+
named in `refused`. Those belong in the app's own `index.html`, which holds
|
|
274
|
+
anything, or in the kit component that needs them.
|
|
275
|
+
|
|
276
|
+
`@niscorp/nova/document` is the surface that has a `<head>`. `placeHead`
|
|
277
|
+
writes the elements into an HTML document being drawn to a string (what
|
|
278
|
+
`@niscorp/cli` and moss's `renderDocument` call): an element takes the place
|
|
279
|
+
of the tag that said the same thing, and anything else is added. In the page,
|
|
280
|
+
the DOM, React and Vue adapters keep `document.head` on the screen
|
|
281
|
+
(`createHeadKeeper`): its elements go in, the document's own tags give way to
|
|
282
|
+
them and come back when the screen stops saying them. To offer the names to a
|
|
283
|
+
layout agent, register them with `HEAD_META` so the palette lists them.
|
|
284
|
+
|
|
232
285
|
---
|
|
233
286
|
|
|
234
287
|
## Authoring
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as ComponentRegistry } from '../../../types-
|
|
1
|
+
import { C as ComponentRegistry } from '../../../types-j290XhCn.cjs';
|
|
2
2
|
import { DomComponent } from '../index.cjs';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../../../schemas-DPdeFlCT.cjs';
|
|
5
5
|
import '../../../schemas-pMyyuXV7.cjs';
|
|
6
|
-
import '../../../types-
|
|
6
|
+
import '../../../types-qkzTfSye.cjs';
|
|
7
7
|
import '../../../index-caZoXSwr.cjs';
|
|
8
8
|
import '../../../effects-CndX9K7D.cjs';
|
|
9
9
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as ComponentRegistry } from '../../../types-
|
|
1
|
+
import { C as ComponentRegistry } from '../../../types-qnKMx0_V.js';
|
|
2
2
|
import { DomComponent } from '../index.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../../../schemas-DPdeFlCT.js';
|
|
5
5
|
import '../../../schemas-pMyyuXV7.js';
|
|
6
|
-
import '../../../types-
|
|
6
|
+
import '../../../types-D23TRvqe.js';
|
|
7
7
|
import '../../../index-CNfzSBe2.js';
|
|
8
8
|
import '../../../effects-CndX9K7D.js';
|
|
9
9
|
|
|
@@ -12,14 +12,155 @@ var renderNodeKey = (node, index) => {
|
|
|
12
12
|
return `e:${node.code}:${index}`;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// src/layout/head.ts
|
|
16
|
+
var HEAD_NAME = "nova:head";
|
|
17
|
+
var HEAD_TITLE_NAME = "nova:title";
|
|
18
|
+
var HEAD_META_NAME = "nova:meta";
|
|
19
|
+
var HEAD_LINK_NAME = "nova:link";
|
|
20
|
+
var HEAD_SCRIPT_NAME = "nova:script";
|
|
21
|
+
var headKeyOf = (element) => {
|
|
22
|
+
const said = (name) => {
|
|
23
|
+
const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
|
|
24
|
+
return found === void 0 || found === "" ? void 0 : found;
|
|
25
|
+
};
|
|
26
|
+
if (element.tag === "title") return "title";
|
|
27
|
+
if (element.tag === "meta") {
|
|
28
|
+
const [name, property] = [said("name"), said("property")];
|
|
29
|
+
if (name !== void 0) return `meta name ${name}`;
|
|
30
|
+
return property === void 0 ? void 0 : `meta property ${property}`;
|
|
31
|
+
}
|
|
32
|
+
if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
|
|
33
|
+
return void 0;
|
|
34
|
+
};
|
|
35
|
+
|
|
15
36
|
// src/shell/slot-names.ts
|
|
37
|
+
var CANVAS_SLOT_NAME = "CanvasSlot";
|
|
16
38
|
var ACTION_SLOT_NAME = "ActionSlot";
|
|
17
39
|
|
|
40
|
+
// src/shell/head.ts
|
|
41
|
+
var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
|
|
42
|
+
var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
|
|
43
|
+
var written = (value) => {
|
|
44
|
+
if (typeof value === "string") return value.trim() === "" ? void 0 : value;
|
|
45
|
+
if (typeof value === "number") return String(value);
|
|
46
|
+
return value === true ? "" : void 0;
|
|
47
|
+
};
|
|
48
|
+
var attributesOf = (what, props, skip = []) => {
|
|
49
|
+
const attributes = {};
|
|
50
|
+
for (const [name, value] of Object.entries(props)) {
|
|
51
|
+
if (skip.includes(name)) continue;
|
|
52
|
+
if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
|
|
53
|
+
if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
|
|
54
|
+
const text = written(value);
|
|
55
|
+
if (text !== void 0) attributes[name] = text;
|
|
56
|
+
}
|
|
57
|
+
return { attributes };
|
|
58
|
+
};
|
|
59
|
+
var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
|
|
60
|
+
var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
|
|
61
|
+
var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
|
|
62
|
+
var titleOf = (node) => {
|
|
63
|
+
const text = textOf(node.children).trim();
|
|
64
|
+
return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
|
|
65
|
+
};
|
|
66
|
+
var metaOf = (node) => {
|
|
67
|
+
const read = attributesOf(HEAD_META_NAME, node.props);
|
|
68
|
+
if ("refused" in read) return read;
|
|
69
|
+
if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
|
|
70
|
+
return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
|
|
71
|
+
};
|
|
72
|
+
var linkOf = (node) => {
|
|
73
|
+
const read = attributesOf(HEAD_LINK_NAME, node.props);
|
|
74
|
+
if ("refused" in read) return read;
|
|
75
|
+
if (valueOf(read.attributes, "rel").toLowerCase().split(/\s+/).includes("stylesheet")) return { refused: `${HEAD_LINK_NAME}: a stylesheet styles the page, and a layout does not` };
|
|
76
|
+
return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
|
|
77
|
+
};
|
|
78
|
+
var scriptOf = (node) => {
|
|
79
|
+
const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
|
|
80
|
+
if ("refused" in read) return read;
|
|
81
|
+
if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
|
|
82
|
+
const type = valueOf(read.attributes, "type");
|
|
83
|
+
if (!DATA_TYPE.test(type)) return { refused: `${HEAD_SCRIPT_NAME}: only a data block may be written (a JSON \`type\`), and "${type}" is not one` };
|
|
84
|
+
const data = node.props["data"];
|
|
85
|
+
if (data === void 0 || data === null || data === "") return void 0;
|
|
86
|
+
return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
|
|
87
|
+
};
|
|
88
|
+
var READERS = {
|
|
89
|
+
[HEAD_TITLE_NAME]: titleOf,
|
|
90
|
+
[HEAD_META_NAME]: metaOf,
|
|
91
|
+
[HEAD_LINK_NAME]: linkOf,
|
|
92
|
+
[HEAD_SCRIPT_NAME]: scriptOf
|
|
93
|
+
};
|
|
94
|
+
var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
|
|
95
|
+
var headOf = (api) => {
|
|
96
|
+
let heads = 0;
|
|
97
|
+
const said = [];
|
|
98
|
+
const refused = [];
|
|
99
|
+
const open = /* @__PURE__ */ new Set();
|
|
100
|
+
const hold = (nodes, action) => {
|
|
101
|
+
for (const node of nodes) {
|
|
102
|
+
if (node.type === "fragment") {
|
|
103
|
+
hold(node.children, action);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (node.type === "error") {
|
|
107
|
+
refused.push(`${HEAD_NAME}: ${node.message}`);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (node.type !== "component") continue;
|
|
111
|
+
const read = READERS[node.name];
|
|
112
|
+
if (read === void 0) {
|
|
113
|
+
refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const found = read(node);
|
|
117
|
+
if (found === void 0) continue;
|
|
118
|
+
if ("refused" in found) {
|
|
119
|
+
refused.push(found.refused);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const key = headKeyOf(found.element);
|
|
123
|
+
const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
|
|
124
|
+
if (earlier >= 0) said.splice(earlier, 1);
|
|
125
|
+
said.push({ element: found.element, action });
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const walk = (nodes, action) => {
|
|
129
|
+
for (const node of nodes) {
|
|
130
|
+
if (node.type === "fragment") {
|
|
131
|
+
walk(node.children, action);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (node.type !== "component") continue;
|
|
135
|
+
if (node.name === HEAD_NAME) {
|
|
136
|
+
heads += 1;
|
|
137
|
+
hold(node.children, action);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (node.name === CANVAS_SLOT_NAME) {
|
|
141
|
+
const canvasId = node.props["canvasId"];
|
|
142
|
+
if (typeof canvasId !== "string" || canvasId === "" || open.has(canvasId)) continue;
|
|
143
|
+
open.add(canvasId);
|
|
144
|
+
walk(api.canvasTree(canvasId), void 0);
|
|
145
|
+
open.delete(canvasId);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const definitionId = node.name === ACTION_SLOT_NAME ? node.props["definitionId"] : void 0;
|
|
149
|
+
walk(node.children, typeof definitionId === "string" ? definitionId : action);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
walk(api.frame(), void 0);
|
|
153
|
+
if (heads === 0) return void 0;
|
|
154
|
+
const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
|
|
155
|
+
return { elements: said.map((one) => one.element), actions, refused };
|
|
156
|
+
};
|
|
157
|
+
|
|
18
158
|
// src/shell/view.ts
|
|
19
159
|
var hasVisibleContent = (nodes) => nodes.some((node) => {
|
|
20
160
|
if (node.type === "text") return node.value !== "";
|
|
21
161
|
if (node.type === "fragment") return hasVisibleContent(node.children);
|
|
22
162
|
if (node.type === "component" && node.name === ACTION_SLOT_NAME) return hasVisibleContent(node.children);
|
|
163
|
+
if (isHeadNode(node)) return false;
|
|
23
164
|
return true;
|
|
24
165
|
});
|
|
25
166
|
var canvasTreeOf = (shell, canvasId) => {
|
|
@@ -61,6 +202,65 @@ var shellView = (shell) => ({
|
|
|
61
202
|
}
|
|
62
203
|
});
|
|
63
204
|
|
|
205
|
+
// src/document/place-head.ts
|
|
206
|
+
var HEAD_MARK = "data-nova-head";
|
|
207
|
+
var OWN_MARK = "data-nova-own";
|
|
208
|
+
|
|
209
|
+
// src/document/head-keeper.ts
|
|
210
|
+
var TAGS2 = ["title", "meta", "link"];
|
|
211
|
+
var keyOfNode = (node) => {
|
|
212
|
+
const tag = TAGS2.find((name) => name === node.tagName.toLowerCase());
|
|
213
|
+
if (tag !== "title" && tag !== "meta" && tag !== "link") return void 0;
|
|
214
|
+
return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });
|
|
215
|
+
};
|
|
216
|
+
var createHeadKeeper = (doc) => {
|
|
217
|
+
let mine = [];
|
|
218
|
+
let away = [];
|
|
219
|
+
let said;
|
|
220
|
+
const built = (element) => {
|
|
221
|
+
const node = doc.createElement(element.tag);
|
|
222
|
+
for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);
|
|
223
|
+
node.setAttribute(HEAD_MARK, "");
|
|
224
|
+
if (element.text !== void 0) node.textContent = element.text;
|
|
225
|
+
return node;
|
|
226
|
+
};
|
|
227
|
+
const adopt = () => {
|
|
228
|
+
mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];
|
|
229
|
+
const view = doc.defaultView;
|
|
230
|
+
for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {
|
|
231
|
+
if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;
|
|
232
|
+
for (const child of [...stash.content.children]) {
|
|
233
|
+
const key = keyOfNode(child);
|
|
234
|
+
if (key !== void 0) away.push({ key, node: doc.importNode(child, true), before: null });
|
|
235
|
+
}
|
|
236
|
+
stash.remove();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return (elements) => {
|
|
240
|
+
const now = elements ?? [];
|
|
241
|
+
const next = JSON.stringify(now);
|
|
242
|
+
if (said === void 0) {
|
|
243
|
+
if (now.length === 0) return;
|
|
244
|
+
adopt();
|
|
245
|
+
}
|
|
246
|
+
if (next === said) return;
|
|
247
|
+
said = next;
|
|
248
|
+
for (const node of mine) node.remove();
|
|
249
|
+
mine = now.map(built);
|
|
250
|
+
const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));
|
|
251
|
+
for (const node of [...doc.head.children]) {
|
|
252
|
+
const key = keyOfNode(node);
|
|
253
|
+
if (key === void 0 || !keys.has(key)) continue;
|
|
254
|
+
away.push({ key, node, before: node.nextSibling });
|
|
255
|
+
node.remove();
|
|
256
|
+
}
|
|
257
|
+
const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];
|
|
258
|
+
for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);
|
|
259
|
+
away = still;
|
|
260
|
+
doc.head.append(...mine);
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
|
|
64
264
|
// src/adapters/dom/index.ts
|
|
65
265
|
var CANVAS_SLOT = "CanvasSlot";
|
|
66
266
|
var ACTION_SLOT = "ActionSlot";
|
|
@@ -251,7 +451,7 @@ var createDomView = (root, registry, api, options = {}) => {
|
|
|
251
451
|
for (const kid of kids) drop(kid);
|
|
252
452
|
return leaf(node, ctx, errorEl("COMPONENT_NOT_FOUND", node.name));
|
|
253
453
|
}
|
|
254
|
-
const children = kids.map((kid) => {
|
|
454
|
+
const children = kids.filter((kid) => !isHeadNode(kid.node)).map((kid) => {
|
|
255
455
|
const [only] = kid.dom;
|
|
256
456
|
if (kid.node.type !== "fragment" && only !== void 0) return only;
|
|
257
457
|
const fragment = document.createDocumentFragment();
|
|
@@ -296,6 +496,7 @@ var createDomView = (root, registry, api, options = {}) => {
|
|
|
296
496
|
host.append(...flat(kids));
|
|
297
497
|
return { node, ctx: canvasCtx, dom: [host], kids, host, cleanups: [], field: { stale: false } };
|
|
298
498
|
}
|
|
499
|
+
if (isHeadNode(node)) return { node, ctx, dom: [], kids: [], host: void 0, cleanups: [], field: { stale: false } };
|
|
299
500
|
if (builderOf(node, ctx) === void 0) return leaf(node, ctx, errorEl("COMPONENT_NOT_FOUND", node.name));
|
|
300
501
|
return assemble(node, ctx, node.children.map((child) => build(child, ctx)));
|
|
301
502
|
};
|
|
@@ -370,6 +571,10 @@ var createDomView = (root, registry, api, options = {}) => {
|
|
|
370
571
|
}
|
|
371
572
|
if (prev.type !== "component" || next.type !== "component") return equal(prev, next) ? old : afresh();
|
|
372
573
|
if (prev.name !== next.name || !Object.is(slotOf(prev), slotOf(next))) return afresh();
|
|
574
|
+
if (isHeadNode(next)) {
|
|
575
|
+
old.node = next;
|
|
576
|
+
return old;
|
|
577
|
+
}
|
|
373
578
|
if (next.name === CANVAS_SLOT) {
|
|
374
579
|
const host = old.host;
|
|
375
580
|
if (host === void 0) return afresh();
|
|
@@ -452,9 +657,27 @@ var createDomView = (root, registry, api, options = {}) => {
|
|
|
452
657
|
};
|
|
453
658
|
var mountShell = (root, registry, shell, options = {}) => {
|
|
454
659
|
const view = shellView(shell);
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
660
|
+
let read = { trees: /* @__PURE__ */ new Map() };
|
|
661
|
+
const api = {
|
|
662
|
+
...view.api,
|
|
663
|
+
frame: () => read.frame ??= view.api.frame(),
|
|
664
|
+
canvasTree: (canvasId) => {
|
|
665
|
+
const held = read.trees.get(canvasId);
|
|
666
|
+
if (held !== void 0) return held;
|
|
667
|
+
const tree = view.api.canvasTree(canvasId);
|
|
668
|
+
read.trees.set(canvasId, tree);
|
|
669
|
+
return tree;
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
const dom = createDomView(root, registry, api, options);
|
|
673
|
+
const keepHead = createHeadKeeper(root.ownerDocument);
|
|
674
|
+
const render = () => {
|
|
675
|
+
read = { trees: /* @__PURE__ */ new Map() };
|
|
676
|
+
dom.render();
|
|
677
|
+
if (root.isConnected) keepHead(headOf(api)?.elements);
|
|
678
|
+
};
|
|
679
|
+
render();
|
|
680
|
+
const stop = view.subscribe(render);
|
|
458
681
|
return {
|
|
459
682
|
destroy: () => {
|
|
460
683
|
stop();
|