@serene-pub/sdk 0.6.0-pr-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/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a component may import (§3.5, R23, R35).
|
|
3
|
+
*
|
|
4
|
+
* A component's source imports `svelte`, the component client and the
|
|
5
|
+
* unstyled controls — and places `sp-*` elements (`hostElements.ts`). It
|
|
6
|
+
* never imports `@remote-dom/*`: the generated worker bootstrap installs the
|
|
7
|
+
* polyfill and the host owns the receiver, so the renderer can be swapped
|
|
8
|
+
* without a modder rebuilding anything.
|
|
9
|
+
*
|
|
10
|
+
* Enforced three times, and this list is the first:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Compile** — the CLI and the in-app compiler resolve a bare specifier
|
|
13
|
+
* against this list only; relative imports inside the package are fine.
|
|
14
|
+
* Anything else is a compile error that names the list.
|
|
15
|
+
* 2. **Package** — a CLI build may bundle a third-party dependency into the
|
|
16
|
+
* package's own module (the worker is the security, not the list), but the
|
|
17
|
+
* built package carries no `@remote-dom/*`, no hand-written worker and no
|
|
18
|
+
* unresolved bare specifier.
|
|
19
|
+
* 3. **Runtime** — the worker's own CSP and the bootstrap's stripped network
|
|
20
|
+
* globals.
|
|
21
|
+
*
|
|
22
|
+
* Preact, the React alias and `htm` arrive after 1.0 (R35); the list grows,
|
|
23
|
+
* it never shrinks.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Bare specifiers a component may import. A trailing `/*` admits subpaths.
|
|
27
|
+
*
|
|
28
|
+
* The last seven are experimental (C6 P1, owner ruling 2026-09-25 Q4): the
|
|
29
|
+
* SDK's component subpath and core's UI kit — the helpers core's own
|
|
30
|
+
* components are written against — so a clone of a core component compiles
|
|
31
|
+
* in-app from its source, and a CLI modder has the same kit. Each names ONE
|
|
32
|
+
* module (no `/*`): nothing else of the SDK's or core-catalog's is admitted.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
export declare const COMPONENT_IMPORTS: readonly ['svelte', 'svelte/*', '@serene-pub/component-client', '@serene-pub/component-client/*', '@serene-pub/controls', '@serene-pub/sdk/component', '@serene-pub/core-catalog/conversation', '@serene-pub/core-catalog/lore-entries', '@serene-pub/core-catalog/scene-portraits', '@serene-pub/core-catalog/session-state', '@serene-pub/core-catalog/widgets', '@serene-pub/core-catalog/authors-note'];
|
|
36
|
+
/**
|
|
37
|
+
* Specifiers no component may import, however it is built — the renderer is
|
|
38
|
+
* the host's (R23), and so is the worker runtime that installs it.
|
|
39
|
+
* @experimental
|
|
40
|
+
*/
|
|
41
|
+
export declare const COMPONENT_FORBIDDEN_IMPORTS: readonly ['@remote-dom/*', '@serene-pub/component-client/worker-runtime'];
|
|
42
|
+
/**
|
|
43
|
+
* Why a component may not import this specifier, or `undefined` if it may.
|
|
44
|
+
* `bundled: true` is the CLI's package step, which may inline third-party
|
|
45
|
+
* code; everything else (the in-app compiler, a clone) may not.
|
|
46
|
+
* @experimental
|
|
47
|
+
*/
|
|
48
|
+
export declare function componentImportFinding(specifier: string, opts?: {
|
|
49
|
+
bundled?: boolean;
|
|
50
|
+
}): string | undefined;
|
|
51
|
+
//# sourceMappingURL=componentImports.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a component may import (§3.5, R23, R35).
|
|
3
|
+
*
|
|
4
|
+
* A component's source imports `svelte`, the component client and the
|
|
5
|
+
* unstyled controls — and places `sp-*` elements (`hostElements.ts`). It
|
|
6
|
+
* never imports `@remote-dom/*`: the generated worker bootstrap installs the
|
|
7
|
+
* polyfill and the host owns the receiver, so the renderer can be swapped
|
|
8
|
+
* without a modder rebuilding anything.
|
|
9
|
+
*
|
|
10
|
+
* Enforced three times, and this list is the first:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Compile** — the CLI and the in-app compiler resolve a bare specifier
|
|
13
|
+
* against this list only; relative imports inside the package are fine.
|
|
14
|
+
* Anything else is a compile error that names the list.
|
|
15
|
+
* 2. **Package** — a CLI build may bundle a third-party dependency into the
|
|
16
|
+
* package's own module (the worker is the security, not the list), but the
|
|
17
|
+
* built package carries no `@remote-dom/*`, no hand-written worker and no
|
|
18
|
+
* unresolved bare specifier.
|
|
19
|
+
* 3. **Runtime** — the worker's own CSP and the bootstrap's stripped network
|
|
20
|
+
* globals.
|
|
21
|
+
*
|
|
22
|
+
* Preact, the React alias and `htm` arrive after 1.0 (R35); the list grows,
|
|
23
|
+
* it never shrinks.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Bare specifiers a component may import. A trailing `/*` admits subpaths.
|
|
27
|
+
*
|
|
28
|
+
* The last seven are experimental (C6 P1, owner ruling 2026-09-25 Q4): the
|
|
29
|
+
* SDK's component subpath and core's UI kit — the helpers core's own
|
|
30
|
+
* components are written against — so a clone of a core component compiles
|
|
31
|
+
* in-app from its source, and a CLI modder has the same kit. Each names ONE
|
|
32
|
+
* module (no `/*`): nothing else of the SDK's or core-catalog's is admitted.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
export const COMPONENT_IMPORTS = [
|
|
36
|
+
'svelte',
|
|
37
|
+
'svelte/*',
|
|
38
|
+
'@serene-pub/component-client',
|
|
39
|
+
'@serene-pub/component-client/*',
|
|
40
|
+
'@serene-pub/controls',
|
|
41
|
+
'@serene-pub/sdk/component',
|
|
42
|
+
'@serene-pub/core-catalog/conversation',
|
|
43
|
+
'@serene-pub/core-catalog/lore-entries',
|
|
44
|
+
'@serene-pub/core-catalog/scene-portraits',
|
|
45
|
+
'@serene-pub/core-catalog/session-state',
|
|
46
|
+
'@serene-pub/core-catalog/widgets',
|
|
47
|
+
// 🚧 2026-10-02 (AN1): the author's note widget's plain half — appended,
|
|
48
|
+
// so the list only grows.
|
|
49
|
+
'@serene-pub/core-catalog/authors-note',
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Specifiers no component may import, however it is built — the renderer is
|
|
53
|
+
* the host's (R23), and so is the worker runtime that installs it.
|
|
54
|
+
* @experimental
|
|
55
|
+
*/
|
|
56
|
+
export const COMPONENT_FORBIDDEN_IMPORTS = ['@remote-dom/*', '@serene-pub/component-client/worker-runtime'];
|
|
57
|
+
const matches = (specifier, pattern) => pattern.endsWith('/*')
|
|
58
|
+
? specifier.startsWith(pattern.slice(0, -1))
|
|
59
|
+
: specifier === pattern;
|
|
60
|
+
/** A relative path inside the package — the package's own business. */
|
|
61
|
+
const isPath = (specifier) => specifier.startsWith('./') || specifier.startsWith('../');
|
|
62
|
+
/**
|
|
63
|
+
* A `.` or `..` segment anywhere but a relative specifier's leading `./` or
|
|
64
|
+
* `../…/` — `svelte/../../x` names a listed package and reaches past it.
|
|
65
|
+
*/
|
|
66
|
+
function componentSpecifierTraverses(specifier) {
|
|
67
|
+
const segments = specifier.split('/');
|
|
68
|
+
let i = 0;
|
|
69
|
+
if (segments[0] === '.')
|
|
70
|
+
i = 1;
|
|
71
|
+
else
|
|
72
|
+
while (segments[i] === '..')
|
|
73
|
+
i++;
|
|
74
|
+
return segments.slice(i).some((s) => s === '.' || s === '..');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Why a component may not import this specifier, or `undefined` if it may.
|
|
78
|
+
* `bundled: true` is the CLI's package step, which may inline third-party
|
|
79
|
+
* code; everything else (the in-app compiler, a clone) may not.
|
|
80
|
+
* @experimental
|
|
81
|
+
*/
|
|
82
|
+
export function componentImportFinding(specifier, opts = {}) {
|
|
83
|
+
// Anywhere in the specifier: `./node_modules/@remote-dom/core` is the same renderer.
|
|
84
|
+
if (specifier === '@serene-pub/component-client/worker-runtime')
|
|
85
|
+
return `'${specifier}' is the host's worker runtime — a component is started by it, never imports it`;
|
|
86
|
+
if (COMPONENT_FORBIDDEN_IMPORTS.some((p) => matches(specifier, p)) || specifier.includes('@remote-dom/'))
|
|
87
|
+
return (`'${specifier}' is the host's renderer — a component never imports it; ` +
|
|
88
|
+
`place sp-* elements and let the host mirror them (R23)`);
|
|
89
|
+
// In every mode: a listed prefix (`svelte/*`) is not a licence to walk out of it.
|
|
90
|
+
if (specifier.includes('\0') || specifier.includes('\\'))
|
|
91
|
+
return `'${specifier.replace(/\0/g, '\\0')}' holds a NUL or a backslash — a component's imports are plain forward-slash paths`;
|
|
92
|
+
if (componentSpecifierTraverses(specifier))
|
|
93
|
+
return `'${specifier}' has a '.' or '..' segment past its start — a component's imports never walk out of what they name`;
|
|
94
|
+
if (specifier.startsWith('/') || /^[a-z]+:/i.test(specifier))
|
|
95
|
+
return `'${specifier}' is an absolute path or URL — a component imports its own files relatively`;
|
|
96
|
+
if (isPath(specifier))
|
|
97
|
+
return undefined;
|
|
98
|
+
if (COMPONENT_IMPORTS.some((p) => matches(specifier, p)))
|
|
99
|
+
return undefined;
|
|
100
|
+
if (opts.bundled)
|
|
101
|
+
return undefined;
|
|
102
|
+
return (`'${specifier}' is not something a component may import — ` +
|
|
103
|
+
`the list is ${COMPONENT_IMPORTS.map((p) => `'${p}'`).join(', ')}` +
|
|
104
|
+
` (a CLI build may bundle other packages into the component's own module)`);
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=componentImports.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @experimental */
|
|
2
|
+
export interface ComponentModuleFindings {
|
|
3
|
+
errors: string[];
|
|
4
|
+
advisories: string[];
|
|
5
|
+
}
|
|
6
|
+
/** @experimental */
|
|
7
|
+
export declare function componentModuleFindings(code: string): ComponentModuleFindings;
|
|
8
|
+
//# sourceMappingURL=componentModule.d.ts.map
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a BUILT component module may carry (§3.5, C4 / C30) — judged on the
|
|
3
|
+
* module's text, as a host judges a package it is handed and the CLI judges
|
|
4
|
+
* what it just wrote.
|
|
5
|
+
*
|
|
6
|
+
* - **Errors:** the host's renderer bundled in (`@remote-dom`); a worker of
|
|
7
|
+
* its own (`new Worker`, `SharedWorker`, `importScripts`, however named) —
|
|
8
|
+
* a component runs in the one worker the host starts, and never starts
|
|
9
|
+
* another; an import the worker cannot resolve — a bare specifier
|
|
10
|
+
* (`import 'lodash'`), a Node built-in (`node:fs`), a URL (`https:`): a
|
|
11
|
+
* built module is self-contained, and the worker loads nothing but the
|
|
12
|
+
* app's own paths.
|
|
13
|
+
* - **Advisories:** element names the module creates that the vocabulary
|
|
14
|
+
* does not hold. The runtime allowlist is the law (a refused element is
|
|
15
|
+
* dropped, and said); this only says so before anyone mounts it.
|
|
16
|
+
*
|
|
17
|
+
* The module is LEXED, not grepped: code, strings, templates, comments and
|
|
18
|
+
* regular expressions are told apart, so a sentence in a string ("new
|
|
19
|
+
* Worker( is bad") is not code, and minified output (`import{a}from"x"`)
|
|
20
|
+
* is read as the import it is. The CSP of the page's worker is the wall;
|
|
21
|
+
* this says so at build time.
|
|
22
|
+
*/
|
|
23
|
+
import { isHostElement } from './hostElements.js';
|
|
24
|
+
/** Keywords after which a `/` starts a regular expression, not a division. */
|
|
25
|
+
const REGEX_AFTER = new Set(['return', 'typeof', 'instanceof', 'in', 'of', 'new', 'delete', 'void', 'throw', 'case', 'do', 'else', 'yield', 'await']);
|
|
26
|
+
/** Code tokens, and the comments beside them (esbuild's `// node_modules/…` path markers live there). */
|
|
27
|
+
function lex(code) {
|
|
28
|
+
const tokens = [];
|
|
29
|
+
const comments = [];
|
|
30
|
+
let i = 0;
|
|
31
|
+
const n = code.length;
|
|
32
|
+
const regexAllowed = () => {
|
|
33
|
+
const last = tokens[tokens.length - 1];
|
|
34
|
+
if (!last)
|
|
35
|
+
return true;
|
|
36
|
+
if (last.k === 'id')
|
|
37
|
+
return REGEX_AFTER.has(last.v);
|
|
38
|
+
if (last.k === 'punct')
|
|
39
|
+
return !(last.v === ')' || last.v === ']' || last.v === '}');
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
while (i < n) {
|
|
43
|
+
const c = code[i];
|
|
44
|
+
if (c === '/' && code[i + 1] === '/') {
|
|
45
|
+
const end = code.indexOf('\n', i);
|
|
46
|
+
comments.push(code.slice(i, end < 0 ? n : end));
|
|
47
|
+
i = end < 0 ? n : end;
|
|
48
|
+
}
|
|
49
|
+
else if (c === '/' && code[i + 1] === '*') {
|
|
50
|
+
const end = code.indexOf('*/', i + 2);
|
|
51
|
+
comments.push(code.slice(i, end < 0 ? n : end + 2));
|
|
52
|
+
i = end < 0 ? n : end + 2;
|
|
53
|
+
}
|
|
54
|
+
else if (c === '"' || c === "'") {
|
|
55
|
+
let j = i + 1;
|
|
56
|
+
let v = '';
|
|
57
|
+
while (j < n && code[j] !== c) {
|
|
58
|
+
if (code[j] === '\\') {
|
|
59
|
+
v += code[j + 1] ?? '';
|
|
60
|
+
j += 2;
|
|
61
|
+
}
|
|
62
|
+
else
|
|
63
|
+
v += code[j++];
|
|
64
|
+
}
|
|
65
|
+
tokens.push({ k: 'str', v });
|
|
66
|
+
i = j + 1;
|
|
67
|
+
}
|
|
68
|
+
else if (c === '`') {
|
|
69
|
+
let j = i + 1;
|
|
70
|
+
let v = '';
|
|
71
|
+
let dynamic = false;
|
|
72
|
+
let depth = 0;
|
|
73
|
+
while (j < n) {
|
|
74
|
+
const d = code[j];
|
|
75
|
+
if (depth === 0 && d === '`')
|
|
76
|
+
break;
|
|
77
|
+
if (d === '\\') {
|
|
78
|
+
v += code[j + 1] ?? '';
|
|
79
|
+
j += 2;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (depth === 0 && d === '$' && code[j + 1] === '{') {
|
|
83
|
+
dynamic = true;
|
|
84
|
+
depth = 1;
|
|
85
|
+
j += 2;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (depth > 0) {
|
|
89
|
+
if (d === '{')
|
|
90
|
+
depth++;
|
|
91
|
+
else if (d === '}')
|
|
92
|
+
depth--;
|
|
93
|
+
j++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
v += d;
|
|
97
|
+
j++;
|
|
98
|
+
}
|
|
99
|
+
tokens.push({ k: 'tpl', v, dynamic });
|
|
100
|
+
i = j + 1;
|
|
101
|
+
}
|
|
102
|
+
else if (c === '/' && regexAllowed()) {
|
|
103
|
+
// A regular expression literal: skipped whole (its text is not code).
|
|
104
|
+
let j = i + 1;
|
|
105
|
+
let inClass = false;
|
|
106
|
+
while (j < n && code[j] !== '\n') {
|
|
107
|
+
const d = code[j];
|
|
108
|
+
if (d === '\\') {
|
|
109
|
+
j += 2;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (d === '[')
|
|
113
|
+
inClass = true;
|
|
114
|
+
else if (d === ']')
|
|
115
|
+
inClass = false;
|
|
116
|
+
else if (d === '/' && !inClass)
|
|
117
|
+
break;
|
|
118
|
+
j++;
|
|
119
|
+
}
|
|
120
|
+
j++;
|
|
121
|
+
while (j < n && /[a-z]/i.test(code[j]))
|
|
122
|
+
j++;
|
|
123
|
+
tokens.push({ k: 'punct', v: 'regex' });
|
|
124
|
+
i = j;
|
|
125
|
+
}
|
|
126
|
+
else if (/[A-Za-z_$]/.test(c)) {
|
|
127
|
+
let j = i + 1;
|
|
128
|
+
while (j < n && /[\w$]/.test(code[j]))
|
|
129
|
+
j++;
|
|
130
|
+
tokens.push({ k: 'id', v: code.slice(i, j) });
|
|
131
|
+
i = j;
|
|
132
|
+
}
|
|
133
|
+
else if (/\s/.test(c))
|
|
134
|
+
i++;
|
|
135
|
+
else if (/[0-9]/.test(c)) {
|
|
136
|
+
let j = i + 1;
|
|
137
|
+
while (j < n && /[\w.]/.test(code[j]))
|
|
138
|
+
j++;
|
|
139
|
+
tokens.push({ k: 'id', v: code.slice(i, j) });
|
|
140
|
+
i = j;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
tokens.push({ k: 'punct', v: c });
|
|
144
|
+
i++;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { tokens, comments };
|
|
148
|
+
}
|
|
149
|
+
/** A specifier the worker can load: the module's own relative files, the app's own absolute paths, inline data. */
|
|
150
|
+
const LOADABLE = /^(\.{1,2}\/|\/(?!\/)|data:)/i;
|
|
151
|
+
/** The specifiers a module imports, and whether it computes one. */
|
|
152
|
+
function imports(tokens) {
|
|
153
|
+
const specs = [];
|
|
154
|
+
let computed = false;
|
|
155
|
+
const literal = (t) => t && (t.k === 'str' || (t.k === 'tpl' && !t.dynamic)) ? t.v : undefined;
|
|
156
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
157
|
+
const t = tokens[i];
|
|
158
|
+
if (t.k !== 'id')
|
|
159
|
+
continue;
|
|
160
|
+
const prev = tokens[i - 1];
|
|
161
|
+
// A property (`x.import`) is not the keyword.
|
|
162
|
+
if (prev?.k === 'punct' && prev.v === '.')
|
|
163
|
+
continue;
|
|
164
|
+
if (t.v === 'import' || t.v === 'require') {
|
|
165
|
+
const next = tokens[i + 1];
|
|
166
|
+
if (next?.k === 'punct' && next.v === '(') {
|
|
167
|
+
const s = literal(tokens[i + 2]);
|
|
168
|
+
if (s !== undefined)
|
|
169
|
+
specs.push(s);
|
|
170
|
+
else if (t.v === 'import')
|
|
171
|
+
computed = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (t.v !== 'import')
|
|
175
|
+
continue;
|
|
176
|
+
// `import.meta` is not an import.
|
|
177
|
+
if (next?.k === 'punct' && next.v === '.')
|
|
178
|
+
continue;
|
|
179
|
+
const direct = literal(next);
|
|
180
|
+
if (direct !== undefined) {
|
|
181
|
+
specs.push(direct);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (t.v === 'import' || t.v === 'export') {
|
|
186
|
+
// Up to the statement's `from "x"` — or its end, for a declaration.
|
|
187
|
+
for (let j = i + 1; j < tokens.length && j < i + 400; j++) {
|
|
188
|
+
const u = tokens[j];
|
|
189
|
+
if (u.k === 'punct' && (u.v === ';' || u.v === '=' || u.v === '('))
|
|
190
|
+
break;
|
|
191
|
+
if (u.k === 'id' && (u.v === 'function' || u.v === 'class' || u.v === 'const' || u.v === 'let' || u.v === 'var' || u.v === 'default'))
|
|
192
|
+
break;
|
|
193
|
+
if (u.k === 'id' && u.v === 'from') {
|
|
194
|
+
const s = literal(tokens[j + 1]);
|
|
195
|
+
if (s !== undefined)
|
|
196
|
+
specs.push(s);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { specs, computed };
|
|
203
|
+
}
|
|
204
|
+
/** A worker the module starts, however it names the constructor. */
|
|
205
|
+
function startsWorker(tokens) {
|
|
206
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
207
|
+
const t = tokens[i];
|
|
208
|
+
if (t.k !== 'id')
|
|
209
|
+
continue;
|
|
210
|
+
if (t.v === 'importScripts' && tokens[i + 1]?.k === 'punct' && tokens[i + 1].v === '(')
|
|
211
|
+
return true;
|
|
212
|
+
// `Worker` / `SharedWorker` named in code at all — constructed, aliased
|
|
213
|
+
// or reached through `globalThis.`: a component has no reason to name
|
|
214
|
+
// either (a string saying the word is not code, and is not read).
|
|
215
|
+
if (t.v === 'Worker' || t.v === 'SharedWorker')
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
/** Element names the module asks the DOM for, or writes into a compiled template. */
|
|
221
|
+
function elementNames(tokens) {
|
|
222
|
+
const out = new Set();
|
|
223
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
224
|
+
const t = tokens[i];
|
|
225
|
+
if (t.k !== 'id')
|
|
226
|
+
continue;
|
|
227
|
+
if ((t.v === 'createElement' || t.v === 'createElementNS') && tokens[i + 1]?.v === '(') {
|
|
228
|
+
// `createElementNS(ns, name)`: the name follows the first comma.
|
|
229
|
+
let at = i + 2;
|
|
230
|
+
if (t.v === 'createElementNS') {
|
|
231
|
+
const comma = tokens.findIndex((u, k) => k > i + 1 && k < i + 40 && u.k === 'punct' && u.v === ',');
|
|
232
|
+
at = comma < 0 ? -1 : comma + 1;
|
|
233
|
+
}
|
|
234
|
+
const name = at < 0 ? undefined : tokens[at];
|
|
235
|
+
if (name && (name.k === 'str' || (name.k === 'tpl' && !name.dynamic)) && /^[a-z][\w-]*$/i.test(name.v))
|
|
236
|
+
out.add(name.v.toLowerCase());
|
|
237
|
+
}
|
|
238
|
+
// Svelte's compiled templates (`from_html(\`<div>…\`)`) — markup, not a sentence.
|
|
239
|
+
if (/^from_(?:html|svg|mathml)$/.test(t.v) && tokens[i + 1]?.v === '(') {
|
|
240
|
+
const tpl = tokens[i + 2];
|
|
241
|
+
if (tpl && (tpl.k === 'tpl' || tpl.k === 'str'))
|
|
242
|
+
for (const m of tpl.v.matchAll(/<([a-zA-Z][\w-]*)[\s/>]/g))
|
|
243
|
+
out.add(m[1].toLowerCase());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return [...out];
|
|
247
|
+
}
|
|
248
|
+
/** @experimental */
|
|
249
|
+
export function componentModuleFindings(code) {
|
|
250
|
+
const errors = [];
|
|
251
|
+
const advisories = [];
|
|
252
|
+
const { tokens, comments } = lex(code);
|
|
253
|
+
// The renderer, bundled: esbuild's path marker for it, or its own classes.
|
|
254
|
+
if (comments.some((c) => /node_modules\/@remote-dom\//.test(c)) ||
|
|
255
|
+
tokens.some((t) => t.k === 'id' && (t.v === 'RemoteRootElement' || t.v === 'BatchingRemoteConnection')))
|
|
256
|
+
errors.push("the module carries @remote-dom — the host's renderer is never part of a component");
|
|
257
|
+
if (startsWorker(tokens))
|
|
258
|
+
errors.push('the module reaches for a worker of its own — a component runs in the one worker the host starts');
|
|
259
|
+
const { specs } = imports(tokens);
|
|
260
|
+
for (const spec of new Set(specs))
|
|
261
|
+
if (spec.includes('@remote-dom/'))
|
|
262
|
+
errors.push(`the module imports '${spec}' — the host's renderer is never part of a component`);
|
|
263
|
+
else if (!LOADABLE.test(spec))
|
|
264
|
+
errors.push(`the module imports '${spec}' — the worker loads nothing but the module's own files and the app's paths; bundle it`);
|
|
265
|
+
for (const name of elementNames(tokens))
|
|
266
|
+
if (name !== 'template' && !isHostElement(name))
|
|
267
|
+
advisories.push(`<${name}> is not in the host-element vocabulary — the page will drop it`);
|
|
268
|
+
return { errors, advisories };
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=componentModule.js.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component wire (§3.5, C2/C3b): what crosses between a page and its UI
|
|
3
|
+
* worker, beside each mount's own widget-protocol port — and the worker
|
|
4
|
+
* side of that port, the {@link ComponentContext} a component is handed.
|
|
5
|
+
*
|
|
6
|
+
* Shared by the app's page and worker, and by the component harness
|
|
7
|
+
* (`@serene-pub/cli/testing`), so the three cannot drift.
|
|
8
|
+
*
|
|
9
|
+
* Remote DOM's mutation records carry FUNCTIONS (event listeners), which
|
|
10
|
+
* `postMessage` cannot clone. They cross as handles instead — `{ [FN]: id }`
|
|
11
|
+
* — and the host calls a handle back with a small, host-chosen event
|
|
12
|
+
* summary (`RemoteEventDetail`), never the live DOM event.
|
|
13
|
+
*
|
|
14
|
+
* What a component sends on its port (an `invoke`, a request, `ready`)
|
|
15
|
+
* leaves the worker on this channel too, as `wire`: one channel, so it
|
|
16
|
+
* cannot overtake the DOM changes of the turn that sent it.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
import type { ComponentContext } from './componentClient.js';
|
|
21
|
+
import type { RequestDeclineCode } from './surfaces.js';
|
|
22
|
+
/** The handle key a function is replaced by on the wire. @experimental */
|
|
23
|
+
export declare const FN = "__spFn";
|
|
24
|
+
/** @experimental */
|
|
25
|
+
export type FnHandle = {
|
|
26
|
+
[FN]: number;
|
|
27
|
+
};
|
|
28
|
+
/** @experimental */
|
|
29
|
+
export declare const isFnHandle: (v: unknown) => v is FnHandle;
|
|
30
|
+
/** What a remote listener receives: the declared `detail`, or a control's value. @experimental */
|
|
31
|
+
export interface RemoteEventDetail {
|
|
32
|
+
type: string;
|
|
33
|
+
/** The sp element's declared detail (`{ value }`, `{ open }`, …), cloned. */
|
|
34
|
+
detail?: unknown;
|
|
35
|
+
/** A plain control's value, for `input` / `change`. */
|
|
36
|
+
value?: string;
|
|
37
|
+
/** A checkbox's state, for `change`. */
|
|
38
|
+
checked?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Host → worker. @experimental */
|
|
41
|
+
export type HostToWorker = {
|
|
42
|
+
k: 'mount';
|
|
43
|
+
mountId: string;
|
|
44
|
+
/** The component's module, same-origin (`/plugin-ui/<owner>/<entry>`). */
|
|
45
|
+
entry: string;
|
|
46
|
+
/**
|
|
47
|
+
* Rides the transfer list: this mount's widget-protocol port. What
|
|
48
|
+
* the component sends back rides the worker channel instead
|
|
49
|
+
* (`wire`), in order with its DOM changes.
|
|
50
|
+
*/
|
|
51
|
+
port: ComponentPort;
|
|
52
|
+
} | {
|
|
53
|
+
k: 'unmount';
|
|
54
|
+
mountId: string;
|
|
55
|
+
} | {
|
|
56
|
+
k: 'fn';
|
|
57
|
+
mountId: string;
|
|
58
|
+
id: number;
|
|
59
|
+
detail: RemoteEventDetail;
|
|
60
|
+
};
|
|
61
|
+
/** Worker → host. @experimental */
|
|
62
|
+
export type WorkerToHost = {
|
|
63
|
+
k: 'mutate';
|
|
64
|
+
mountId: string;
|
|
65
|
+
records: unknown[];
|
|
66
|
+
} | {
|
|
67
|
+
k: 'failed';
|
|
68
|
+
mountId: string;
|
|
69
|
+
message: string;
|
|
70
|
+
}
|
|
71
|
+
/** A mounted component threw while handling an event: said, and the mount lives on. */
|
|
72
|
+
| {
|
|
73
|
+
k: 'error';
|
|
74
|
+
mountId: string;
|
|
75
|
+
message: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A message the component sent on its widget-protocol port, delivered on
|
|
79
|
+
* the worker channel after every mutation of the turn that sent it — so
|
|
80
|
+
* the page sees the DOM change a handler made before the message the
|
|
81
|
+
* same handler sent next (a menu closes, THEN the host's dialog opens; the
|
|
82
|
+
* other way round, the closing menu hands focus back to its trigger and
|
|
83
|
+
* the dialog dismisses itself). The page handles `msg` as one that arrived
|
|
84
|
+
* on the mount's port; the port itself carries page → worker only.
|
|
85
|
+
*/
|
|
86
|
+
| {
|
|
87
|
+
k: 'wire';
|
|
88
|
+
mountId: string;
|
|
89
|
+
msg: unknown;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* 🚧 The error a component's `request` rejects with when the host declines:
|
|
93
|
+
* the host's sentence as `message`, and its {@link RequestDeclineCode} as
|
|
94
|
+
* `code` when it gave one (`unmounted` for every request still pending when
|
|
95
|
+
* the component is unmounted). Test `code`, never the sentence.
|
|
96
|
+
* @experimental
|
|
97
|
+
*/
|
|
98
|
+
export declare class RequestDeclined extends Error {
|
|
99
|
+
readonly code?: RequestDeclineCode;
|
|
100
|
+
constructor(message: string, code?: RequestDeclineCode);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Replace every function in a value with a handle, registering it. Walks
|
|
104
|
+
* arrays and plain objects; everything else passes as is.
|
|
105
|
+
* @experimental
|
|
106
|
+
*/
|
|
107
|
+
export declare function encodeFns(value: unknown, register: (fn: (...a: unknown[]) => unknown) => number): unknown;
|
|
108
|
+
/** The one port a mount's context speaks over — a DOM or Node `MessagePort`. @experimental */
|
|
109
|
+
export interface ComponentPort {
|
|
110
|
+
/**
|
|
111
|
+
* Only ever ASSIGNED here (never called), and a DOM port's handler takes a
|
|
112
|
+
* full `MessageEvent` — so the parameter is `never`, which either port's
|
|
113
|
+
* handler type accepts; the handler this module assigns reads `data` only.
|
|
114
|
+
*/
|
|
115
|
+
onmessage: ((e: never) => void) | null;
|
|
116
|
+
postMessage(message: unknown): void;
|
|
117
|
+
close(): void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The worker side of a mount's widget-protocol port: the same sections a
|
|
121
|
+
* native widget reads off its context and a frame is posted, and the same
|
|
122
|
+
* verbs back. Runs where the component runs — no page, no network, nothing
|
|
123
|
+
* but this port.
|
|
124
|
+
* @experimental
|
|
125
|
+
*/
|
|
126
|
+
export declare function createComponentContext(port: ComponentPort): ComponentContext & {
|
|
127
|
+
ready(): void;
|
|
128
|
+
close(): void;
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=componentWire.d.ts.map
|