@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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widgets as a package declares them, and genres as they subtract and lay
|
|
3
|
+
* them out (R71, ruled 2026-09-24).
|
|
4
|
+
*
|
|
5
|
+
* - A **package** — a plugin, or core in `core-catalog` — declares its
|
|
6
|
+
* widgets once (`defineExtension({ widgets })`), each optionally scoped to
|
|
7
|
+
* genres by value (`widget({ genres: [myGenre] })`; absent = every genre).
|
|
8
|
+
* - A **genre** withholds any package's widgets (`omitWidgets`, by value) and
|
|
9
|
+
* ships its layouts (`layouts`, the first its default).
|
|
10
|
+
*
|
|
11
|
+
* A session of a genre is offered every widget scoped to it or to all,
|
|
12
|
+
* minus the genre's `omitWidgets`.
|
|
13
|
+
*
|
|
14
|
+
* **Whose a widget is** is recorded when its package declares it — core's by
|
|
15
|
+
* `core-catalog`, a plugin's by `defineExtension` — so a genre that names
|
|
16
|
+
* another package's widget by value names the id the page knows it by
|
|
17
|
+
* (`widgetRef`): core's bare (`stats`), a plugin's under its package
|
|
18
|
+
* (`acme.dice:tray`, the `pluginWidgetId` grammar).
|
|
19
|
+
*/
|
|
20
|
+
import type { WidgetDecl } from './layout.js';
|
|
21
|
+
import { type SessionLayoutV1 } from './sessionLayout.js';
|
|
22
|
+
import { type I18n } from './i18n.js';
|
|
23
|
+
import { type WidgetBaseSection } from './widgets.js';
|
|
24
|
+
/** Record whose widgets these are. Core's `core-catalog` and `defineExtension` call it; nothing else should. @internal */
|
|
25
|
+
export declare function ownWidgets(owner: string, widgets: readonly WidgetDecl[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Core's widget ids, as far as core's catalogue has been loaded. A package's
|
|
28
|
+
* widget may not take one: a layout names core's widgets and the package's
|
|
29
|
+
* own by bare id, so the two sets never overlap.
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
export declare const coreWidgetIds: () => ReadonlySet<string>;
|
|
33
|
+
/** The package that declared this widget value, if one has. @experimental */
|
|
34
|
+
export declare const widgetOwner: (w: WidgetDecl) => string | undefined;
|
|
35
|
+
/** The id a page, a layout row and a genre's `omitWidgets` know this widget by. @experimental */
|
|
36
|
+
export declare function widgetRef(w: WidgetDecl): string;
|
|
37
|
+
/** A genre as a widget's `genres` names it: the genre value, or `use('<id>')` for one declared elsewhere. @experimental */
|
|
38
|
+
export type GenreLike = {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
};
|
|
41
|
+
/** @experimental */
|
|
42
|
+
export interface WidgetInput extends Omit<WidgetDecl, 'genres'> {
|
|
43
|
+
/** The genres whose sessions offer it, by value. Absent = every genre. */
|
|
44
|
+
genres?: readonly GenreLike[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The base sections a widget reads (R75): its `reads`, or every base section
|
|
48
|
+
* when it declares none — what its host sends it. A host asks this rather
|
|
49
|
+
* than reading `reads`, so the default lives in one place.
|
|
50
|
+
*
|
|
51
|
+
* Clamped, as a host must clamp what an install stored verbatim: a name that
|
|
52
|
+
* is not a base section (a scoped one, junk) never comes back, and each name
|
|
53
|
+
* comes back once.
|
|
54
|
+
* @experimental
|
|
55
|
+
*/
|
|
56
|
+
export declare function widgetReads(w: Pick<WidgetDecl, 'reads'>): readonly WidgetBaseSection[];
|
|
57
|
+
/**
|
|
58
|
+
* What is wrong with a widget's `reads` (R75), one sentence each, each led by
|
|
59
|
+
* `at` (where it was written): a name that is not a base section is refused
|
|
60
|
+
* where it is declared, rather than naming a section the widget would
|
|
61
|
+
* silently never receive.
|
|
62
|
+
* @experimental
|
|
63
|
+
*/
|
|
64
|
+
export declare function widgetReadsFindings(reads: unknown, at: string): string[];
|
|
65
|
+
/** Declare a widget — the value a package lists in `widgets` and a genre names in `omitWidgets` or a layout. @experimental */
|
|
66
|
+
export declare function widget(d: WidgetInput): WidgetDecl;
|
|
67
|
+
/**
|
|
68
|
+
* A layout a genre ships (R71): a **session layout** under a slug and a name.
|
|
69
|
+
* The first is the genre's default — its **genre default layout**.
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
72
|
+
export interface GenreLayoutDecl {
|
|
73
|
+
/** Unique within the genre; `default` for the first. */
|
|
74
|
+
slug: string;
|
|
75
|
+
name: I18n;
|
|
76
|
+
description?: I18n;
|
|
77
|
+
/**
|
|
78
|
+
* The session layout, with the widget settings and style pins that come
|
|
79
|
+
* with it. It places widgets by the id the page knows them by —
|
|
80
|
+
* `someWidget.id` for one of this package's, `coreWidgets.x.id` for core's
|
|
81
|
+
* — or a copy of one (`messages#sanctum`); the packager puts a plugin's own
|
|
82
|
+
* widget ids under its namespace.
|
|
83
|
+
*/
|
|
84
|
+
preset: SessionLayoutV1;
|
|
85
|
+
}
|
|
86
|
+
/** Declare a layout a genre ships. Refused unless `validateSessionLayout` finds no error in it. @experimental */
|
|
87
|
+
export declare function layout(d: GenreLayoutDecl): GenreLayoutDecl;
|
|
88
|
+
//# sourceMappingURL=widgetDecls.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { validateSessionLayout } from './sessionLayout.js';
|
|
2
|
+
import { i18nFindings } from './i18n.js';
|
|
3
|
+
import { WIDGET_BASE_SECTIONS, isWidgetScopedSectionName } from './widgets.js';
|
|
4
|
+
/**
|
|
5
|
+
* One registry per process, however many copies of the SDK a package's
|
|
6
|
+
* dependencies resolved: a genre that names core's widget from one copy and
|
|
7
|
+
* a core-catalog built against another still agree whose it is.
|
|
8
|
+
*/
|
|
9
|
+
const REGISTRY = (globalThis[Symbol.for('serene-pub.widget-owners')] ??= {
|
|
10
|
+
owners: new WeakMap(),
|
|
11
|
+
coreIds: new Set(),
|
|
12
|
+
});
|
|
13
|
+
const OWNERS = REGISTRY.owners;
|
|
14
|
+
/** Record whose widgets these are. Core's `core-catalog` and `defineExtension` call it; nothing else should. @internal */
|
|
15
|
+
export function ownWidgets(owner, widgets) {
|
|
16
|
+
for (const w of widgets) {
|
|
17
|
+
const held = OWNERS.get(w);
|
|
18
|
+
if (held && held !== owner)
|
|
19
|
+
throw new Error(`widget '${w.id}' is already ${held}'s — a widget belongs to the one package that declares it`);
|
|
20
|
+
OWNERS.set(w, owner);
|
|
21
|
+
if (owner === 'core')
|
|
22
|
+
REGISTRY.coreIds.add(w.id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Core's widget ids, as far as core's catalogue has been loaded. A package's
|
|
27
|
+
* widget may not take one: a layout names core's widgets and the package's
|
|
28
|
+
* own by bare id, so the two sets never overlap.
|
|
29
|
+
* @experimental
|
|
30
|
+
*/
|
|
31
|
+
export const coreWidgetIds = () => REGISTRY.coreIds;
|
|
32
|
+
/** The package that declared this widget value, if one has. @experimental */
|
|
33
|
+
export const widgetOwner = (w) => OWNERS.get(w);
|
|
34
|
+
/** The id a page, a layout row and a genre's `omitWidgets` know this widget by. @experimental */
|
|
35
|
+
export function widgetRef(w) {
|
|
36
|
+
const owner = OWNERS.get(w);
|
|
37
|
+
if (!owner)
|
|
38
|
+
throw new Error(`widget '${w?.id}' belongs to no package yet — name a widget value from core (\`coreWidgets\`) ` +
|
|
39
|
+
`or from a package's \`defineExtension({ widgets })\``);
|
|
40
|
+
return owner === 'core' ? w.id : `${owner}:${w.id}`;
|
|
41
|
+
}
|
|
42
|
+
const WIDGET_ID = /^[a-z][a-z0-9-]*$/;
|
|
43
|
+
/**
|
|
44
|
+
* The base sections a widget reads (R75): its `reads`, or every base section
|
|
45
|
+
* when it declares none — what its host sends it. A host asks this rather
|
|
46
|
+
* than reading `reads`, so the default lives in one place.
|
|
47
|
+
*
|
|
48
|
+
* Clamped, as a host must clamp what an install stored verbatim: a name that
|
|
49
|
+
* is not a base section (a scoped one, junk) never comes back, and each name
|
|
50
|
+
* comes back once.
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
export function widgetReads(w) {
|
|
54
|
+
if (!Array.isArray(w?.reads))
|
|
55
|
+
return WIDGET_BASE_SECTIONS;
|
|
56
|
+
return [
|
|
57
|
+
...new Set(w.reads.filter((name) => WIDGET_BASE_SECTIONS.includes(name))),
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What is wrong with a widget's `reads` (R75), one sentence each, each led by
|
|
62
|
+
* `at` (where it was written): a name that is not a base section is refused
|
|
63
|
+
* where it is declared, rather than naming a section the widget would
|
|
64
|
+
* silently never receive.
|
|
65
|
+
* @experimental
|
|
66
|
+
*/
|
|
67
|
+
export function widgetReadsFindings(reads, at) {
|
|
68
|
+
if (reads === undefined)
|
|
69
|
+
return [];
|
|
70
|
+
const names = WIDGET_BASE_SECTIONS.map((s) => `'${s}'`).join(', ');
|
|
71
|
+
if (!Array.isArray(reads))
|
|
72
|
+
return [`${at}: a list of base section names — any of ${names}`];
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const name of reads) {
|
|
75
|
+
if (WIDGET_BASE_SECTIONS.includes(name))
|
|
76
|
+
continue;
|
|
77
|
+
out.push(isWidgetScopedSectionName(name)
|
|
78
|
+
? `${at}: '${name}' is a scoped section — ask for it in \`scopes\`, never in \`reads\``
|
|
79
|
+
: `${at}: '${String(name)}' is not a base section — one of ${names}`);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** Declare a widget — the value a package lists in `widgets` and a genre names in `omitWidgets` or a layout. @experimental */
|
|
84
|
+
export function widget(d) {
|
|
85
|
+
const problems = [];
|
|
86
|
+
if (!WIDGET_ID.test(d.id ?? ''))
|
|
87
|
+
problems.push(`'${d.id}' is not a widget id — lowercase letters, digits and '-' (the package supplies the namespace)`);
|
|
88
|
+
problems.push(...i18nFindings(d.title, `widget '${d.id}' title`, { required: true }));
|
|
89
|
+
if (typeof d.component !== 'string' || !d.component)
|
|
90
|
+
problems.push(`widget '${d.id}' names no component — give \`component\`, the slug of a component this package declares`);
|
|
91
|
+
if (d.surface !== undefined)
|
|
92
|
+
problems.push(`widget '${d.id}': \`surface\` is gone — name a component, and place an \`sp-frame\` inside it for a document`);
|
|
93
|
+
problems.push(...widgetReadsFindings(d.reads, `widget '${d.id}' reads`));
|
|
94
|
+
if (d.maxInstances !== undefined && !(Number.isInteger(d.maxInstances) && d.maxInstances > 0))
|
|
95
|
+
problems.push(`widget '${d.id}' maxInstances: a positive whole number, or leave it out for no cap`);
|
|
96
|
+
const genres = d.genres?.map((g) => g?.id);
|
|
97
|
+
if (genres?.some((g) => typeof g !== 'string' || !g))
|
|
98
|
+
problems.push(`widget '${d.id}' genres: each is a genre value (or use('<id>')), never a bare string`);
|
|
99
|
+
if (problems.length)
|
|
100
|
+
throw new Error(problems.join('\n'));
|
|
101
|
+
const { genres: _g, ...rest } = d;
|
|
102
|
+
return Object.freeze({ ...rest, ...(genres?.length ? { genres: [...new Set(genres)] } : {}) });
|
|
103
|
+
}
|
|
104
|
+
const LAYOUT_SLUG = /^[a-z][a-z0-9-]*$/;
|
|
105
|
+
/** Declare a layout a genre ships. Refused unless `validateSessionLayout` finds no error in it. @experimental */
|
|
106
|
+
export function layout(d) {
|
|
107
|
+
const problems = [];
|
|
108
|
+
if (!LAYOUT_SLUG.test(d.slug ?? ''))
|
|
109
|
+
problems.push(`'${d.slug}' is not a layout slug — lowercase letters, digits and '-'`);
|
|
110
|
+
problems.push(...i18nFindings(d.name, `layout '${d.slug}' name`, { required: true }));
|
|
111
|
+
problems.push(...i18nFindings(d.description, `layout '${d.slug}' description`));
|
|
112
|
+
const verdict = validateSessionLayout(d.preset);
|
|
113
|
+
for (const e of verdict.errors)
|
|
114
|
+
problems.push(`layout '${d.slug}' preset: ${e}`);
|
|
115
|
+
if (problems.length)
|
|
116
|
+
throw new Error(problems.join('\n'));
|
|
117
|
+
return Object.freeze({ ...d });
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=widgetDecls.js.map
|