@oddkin/workbench 0.0.0-stage → 1.0.0-beta.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 +21 -0
- package/README.md +66 -2
- package/dist/app/card-previews.d.ts +14 -0
- package/dist/app/card-previews.d.ts.map +1 -0
- package/dist/app/card-previews.js +140 -0
- package/dist/app/card-previews.js.map +1 -0
- package/dist/app/copy.d.ts +48 -0
- package/dist/app/copy.d.ts.map +1 -0
- package/dist/app/copy.js +52 -0
- package/dist/app/copy.js.map +1 -0
- package/dist/app/define.d.ts +3 -0
- package/dist/app/define.d.ts.map +1 -0
- package/dist/app/define.js +10 -0
- package/dist/app/define.js.map +1 -0
- package/dist/app/details.d.ts +22 -0
- package/dist/app/details.d.ts.map +1 -0
- package/dist/app/details.js +17 -0
- package/dist/app/details.js.map +1 -0
- package/dist/app/index.d.ts +12 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +9 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/routes.d.ts +26 -0
- package/dist/app/routes.d.ts.map +1 -0
- package/dist/app/routes.js +96 -0
- package/dist/app/routes.js.map +1 -0
- package/dist/app/search.d.ts +17 -0
- package/dist/app/search.d.ts.map +1 -0
- package/dist/app/search.js +52 -0
- package/dist/app/search.js.map +1 -0
- package/dist/app/shell.d.ts +29 -0
- package/dist/app/shell.d.ts.map +1 -0
- package/dist/app/shell.js +478 -0
- package/dist/app/shell.js.map +1 -0
- package/dist/app/styles.d.ts +2 -0
- package/dist/app/styles.d.ts.map +1 -0
- package/dist/app/styles.js +356 -0
- package/dist/app/styles.js.map +1 -0
- package/dist/app/theme-studio.d.ts +12 -0
- package/dist/app/theme-studio.d.ts.map +1 -0
- package/dist/app/theme-studio.js +14 -0
- package/dist/app/theme-studio.js.map +1 -0
- package/dist/app/views.d.ts +38 -0
- package/dist/app/views.d.ts.map +1 -0
- package/dist/app/views.js +252 -0
- package/dist/app/views.js.map +1 -0
- package/dist/config/index.d.ts +170 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +148 -0
- package/dist/config/index.js.map +1 -0
- package/dist/conformance/button.d.ts +2 -0
- package/dist/conformance/button.d.ts.map +1 -0
- package/dist/conformance/button.js +233 -0
- package/dist/conformance/button.js.map +1 -0
- package/dist/conformance/index.d.ts +107 -0
- package/dist/conformance/index.d.ts.map +1 -0
- package/dist/conformance/index.js +60 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/data/build.d.ts +36 -0
- package/dist/data/build.d.ts.map +1 -0
- package/dist/data/build.js +260 -0
- package/dist/data/build.js.map +1 -0
- package/dist/data/import-map.d.ts +59 -0
- package/dist/data/import-map.d.ts.map +1 -0
- package/dist/data/import-map.js +195 -0
- package/dist/data/import-map.js.map +1 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +10 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/theme-studio.d.ts +21 -0
- package/dist/data/theme-studio.d.ts.map +1 -0
- package/dist/data/theme-studio.js +112 -0
- package/dist/data/theme-studio.js.map +1 -0
- package/dist/data/types.d.ts +187 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/data/types.js +4 -0
- package/dist/data/types.js.map +1 -0
- package/dist/examples/index.d.ts +101 -0
- package/dist/examples/index.d.ts.map +1 -0
- package/dist/examples/index.js +106 -0
- package/dist/examples/index.js.map +1 -0
- package/dist/frame/index.d.ts +9 -0
- package/dist/frame/index.d.ts.map +1 -0
- package/dist/frame/index.js +482 -0
- package/dist/frame/index.js.map +1 -0
- package/dist/internal/diagnostics.d.ts +17 -0
- package/dist/internal/diagnostics.d.ts.map +1 -0
- package/dist/internal/diagnostics.js +19 -0
- package/dist/internal/diagnostics.js.map +1 -0
- package/dist/node/bin.d.ts +3 -0
- package/dist/node/bin.d.ts.map +1 -0
- package/dist/node/bin.js +12 -0
- package/dist/node/bin.js.map +1 -0
- package/dist/node/cli.d.ts +17 -0
- package/dist/node/cli.d.ts.map +1 -0
- package/dist/node/cli.js +198 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/config.d.ts +28 -0
- package/dist/node/config.d.ts.map +1 -0
- package/dist/node/config.js +80 -0
- package/dist/node/config.js.map +1 -0
- package/dist/node/example-modules.d.ts +8 -0
- package/dist/node/example-modules.d.ts.map +1 -0
- package/dist/node/example-modules.js +28 -0
- package/dist/node/example-modules.js.map +1 -0
- package/dist/node/generated.d.ts +19 -0
- package/dist/node/generated.d.ts.map +1 -0
- package/dist/node/generated.js +109 -0
- package/dist/node/generated.js.map +1 -0
- package/dist/node/html.d.ts +35 -0
- package/dist/node/html.d.ts.map +1 -0
- package/dist/node/html.js +51 -0
- package/dist/node/html.js.map +1 -0
- package/dist/node/index.d.ts +24 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +15 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/inputs.d.ts +26 -0
- package/dist/node/inputs.d.ts.map +1 -0
- package/dist/node/inputs.js +282 -0
- package/dist/node/inputs.js.map +1 -0
- package/dist/node/packages.d.ts +35 -0
- package/dist/node/packages.d.ts.map +1 -0
- package/dist/node/packages.js +87 -0
- package/dist/node/packages.js.map +1 -0
- package/dist/node/preload.d.ts +10 -0
- package/dist/node/preload.d.ts.map +1 -0
- package/dist/node/preload.js +61 -0
- package/dist/node/preload.js.map +1 -0
- package/dist/node/server.d.ts +42 -0
- package/dist/node/server.d.ts.map +1 -0
- package/dist/node/server.js +410 -0
- package/dist/node/server.js.map +1 -0
- package/dist/node/static.d.ts +43 -0
- package/dist/node/static.d.ts.map +1 -0
- package/dist/node/static.js +157 -0
- package/dist/node/static.js.map +1 -0
- package/dist/node/workbench.d.ts +43 -0
- package/dist/node/workbench.d.ts.map +1 -0
- package/dist/node/workbench.js +204 -0
- package/dist/node/workbench.js.map +1 -0
- package/dist/pages/build.d.ts +22 -0
- package/dist/pages/build.d.ts.map +1 -0
- package/dist/pages/build.js +363 -0
- package/dist/pages/build.js.map +1 -0
- package/dist/pages/defaults.d.ts +16 -0
- package/dist/pages/defaults.d.ts.map +1 -0
- package/dist/pages/defaults.js +88 -0
- package/dist/pages/defaults.js.map +1 -0
- package/dist/pages/index.d.ts +14 -0
- package/dist/pages/index.d.ts.map +1 -0
- package/dist/pages/index.js +10 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/navigation.d.ts +48 -0
- package/dist/pages/navigation.d.ts.map +1 -0
- package/dist/pages/navigation.js +83 -0
- package/dist/pages/navigation.js.map +1 -0
- package/dist/pages/types.d.ts +148 -0
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/pages/types.js +3 -0
- package/dist/pages/types.js.map +1 -0
- package/dist/panels/catalog-define.d.ts +3 -0
- package/dist/panels/catalog-define.d.ts.map +1 -0
- package/dist/panels/catalog-define.js +7 -0
- package/dist/panels/catalog-define.js.map +1 -0
- package/dist/panels/catalog-layout-styles.d.ts +2 -0
- package/dist/panels/catalog-layout-styles.d.ts.map +1 -0
- package/dist/panels/catalog-layout-styles.js +54 -0
- package/dist/panels/catalog-layout-styles.js.map +1 -0
- package/dist/panels/catalog-styles.d.ts +2 -0
- package/dist/panels/catalog-styles.d.ts.map +1 -0
- package/dist/panels/catalog-styles.js +106 -0
- package/dist/panels/catalog-styles.js.map +1 -0
- package/dist/panels/catalog.d.ts +37 -0
- package/dist/panels/catalog.d.ts.map +1 -0
- package/dist/panels/catalog.js +74 -0
- package/dist/panels/catalog.js.map +1 -0
- package/dist/panels/component-define.d.ts +3 -0
- package/dist/panels/component-define.d.ts.map +1 -0
- package/dist/panels/component-define.js +6 -0
- package/dist/panels/component-define.js.map +1 -0
- package/dist/panels/component-detail.d.ts +49 -0
- package/dist/panels/component-detail.d.ts.map +1 -0
- package/dist/panels/component-detail.js +1352 -0
- package/dist/panels/component-detail.js.map +1 -0
- package/dist/panels/component.d.ts +17 -0
- package/dist/panels/component.d.ts.map +1 -0
- package/dist/panels/component.js +10 -0
- package/dist/panels/component.js.map +1 -0
- package/dist/panels/example-styles.d.ts +2 -0
- package/dist/panels/example-styles.d.ts.map +1 -0
- package/dist/panels/example-styles.js +343 -0
- package/dist/panels/example-styles.js.map +1 -0
- package/dist/panels/foundation-define.d.ts +3 -0
- package/dist/panels/foundation-define.d.ts.map +1 -0
- package/dist/panels/foundation-define.js +6 -0
- package/dist/panels/foundation-define.js.map +1 -0
- package/dist/panels/foundation-detail.d.ts +23 -0
- package/dist/panels/foundation-detail.d.ts.map +1 -0
- package/dist/panels/foundation-detail.js +216 -0
- package/dist/panels/foundation-detail.js.map +1 -0
- package/dist/panels/foundation.d.ts +15 -0
- package/dist/panels/foundation.d.ts.map +1 -0
- package/dist/panels/foundation.js +9 -0
- package/dist/panels/foundation.js.map +1 -0
- package/dist/panels/model.d.ts +184 -0
- package/dist/panels/model.d.ts.map +1 -0
- package/dist/panels/model.js +488 -0
- package/dist/panels/model.js.map +1 -0
- package/dist/panels/styles.d.ts +3 -0
- package/dist/panels/styles.d.ts.map +1 -0
- package/dist/panels/styles.js +265 -0
- package/dist/panels/styles.js.map +1 -0
- package/dist/panels/theme-model.d.ts +69 -0
- package/dist/panels/theme-model.d.ts.map +1 -0
- package/dist/panels/theme-model.js +166 -0
- package/dist/panels/theme-model.js.map +1 -0
- package/dist/panels/theme-studio.d.ts +32 -0
- package/dist/panels/theme-studio.d.ts.map +1 -0
- package/dist/panels/theme-studio.js +375 -0
- package/dist/panels/theme-studio.js.map +1 -0
- package/dist/preview/frame.d.ts +44 -0
- package/dist/preview/frame.d.ts.map +1 -0
- package/dist/preview/frame.js +260 -0
- package/dist/preview/frame.js.map +1 -0
- package/dist/preview/index.d.ts +26 -0
- package/dist/preview/index.d.ts.map +1 -0
- package/dist/preview/index.js +58 -0
- package/dist/preview/index.js.map +1 -0
- package/dist/preview/theme-generation.d.ts +33 -0
- package/dist/preview/theme-generation.d.ts.map +1 -0
- package/dist/preview/theme-generation.js +48 -0
- package/dist/preview/theme-generation.js.map +1 -0
- package/dist/protocol/index.d.ts +222 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +272 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/testing/index.d.ts +47 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +145 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +118 -4
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { presets, registrationOf } from '../panels/model.js';
|
|
2
|
+
import { DATA_VERSION, PAGE_FORMAT, } from './types.js';
|
|
3
|
+
/** The default `theme-specimen` recipe's roles, in display order, with their captions. */
|
|
4
|
+
export const SPECIMEN_ROLES = {
|
|
5
|
+
surface: 'Surface',
|
|
6
|
+
heading: 'Heading',
|
|
7
|
+
bodyText: 'Body text',
|
|
8
|
+
link: 'Link',
|
|
9
|
+
badge: 'Badge',
|
|
10
|
+
textInput: 'Text input',
|
|
11
|
+
checkbox: 'Checkbox',
|
|
12
|
+
switch: 'Switch',
|
|
13
|
+
primaryAction: 'Primary action',
|
|
14
|
+
secondaryAction: 'Secondary action',
|
|
15
|
+
navigation: 'Navigation',
|
|
16
|
+
};
|
|
17
|
+
const roleId = (value) => value.replace(/^role:/, '');
|
|
18
|
+
export function themeStudioPage(id, components, config, input, out) {
|
|
19
|
+
const role = (name, page, exampleName, source) => {
|
|
20
|
+
const entry = registrationOf(page);
|
|
21
|
+
const all = presets(page);
|
|
22
|
+
const example = exampleName
|
|
23
|
+
? all.find((p) => p.name === exampleName)
|
|
24
|
+
: (all.find((p) => p.name === 'default') ?? all.find((p) => p.state && !p.incorrect));
|
|
25
|
+
if (!entry || !example?.state)
|
|
26
|
+
return undefined;
|
|
27
|
+
return {
|
|
28
|
+
role: name,
|
|
29
|
+
label: SPECIMEN_ROLES[name] ?? name,
|
|
30
|
+
tag: page.tag,
|
|
31
|
+
registration: entry,
|
|
32
|
+
example: example.id,
|
|
33
|
+
properties: example.state.properties,
|
|
34
|
+
attributes: example.state.attributes,
|
|
35
|
+
slots: example.state.slots,
|
|
36
|
+
source,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
// Roles claimed by examples; a role claimed by two components stays unmapped.
|
|
40
|
+
const claims = new Map();
|
|
41
|
+
for (const page of components)
|
|
42
|
+
for (const example of page.examples) {
|
|
43
|
+
const roles = example['previewRoles'];
|
|
44
|
+
const name = example['name'];
|
|
45
|
+
if (!Array.isArray(roles) || typeof name !== 'string')
|
|
46
|
+
continue;
|
|
47
|
+
for (const r of roles)
|
|
48
|
+
if (typeof r === 'string')
|
|
49
|
+
claims.set(roleId(r), [...(claims.get(roleId(r)) ?? []), { page, example: name }]);
|
|
50
|
+
}
|
|
51
|
+
const missing = [];
|
|
52
|
+
const byTag = new Map(components.map((page) => [page.tag, page]));
|
|
53
|
+
const mapped = new Map();
|
|
54
|
+
for (const [name, target] of Object.entries(config.themeStudio.preview.roles ?? {})) {
|
|
55
|
+
const tag = typeof target === 'string' ? target : target.component;
|
|
56
|
+
const page = byTag.get(tag);
|
|
57
|
+
const resolved = page && role(name, page, typeof target === 'string' ? undefined : target.example, 'config');
|
|
58
|
+
if (resolved)
|
|
59
|
+
mapped.set(name, resolved);
|
|
60
|
+
else
|
|
61
|
+
out.warn('data.themeStudio.role', `themeStudio.preview.roles.${name}: <${tag}> is not a documented component with a registration entry and that example.`, `/themeStudio/preview/roles/${name}`);
|
|
62
|
+
}
|
|
63
|
+
for (const [name, claimants] of claims) {
|
|
64
|
+
if (mapped.has(name))
|
|
65
|
+
continue;
|
|
66
|
+
const tags = [...new Set(claimants.map((c) => c.page.tag))];
|
|
67
|
+
const only = claimants[0];
|
|
68
|
+
if (tags.length === 1 && claimants.length === 1 && only) {
|
|
69
|
+
const resolved = role(name, only.page, only.example, 'example');
|
|
70
|
+
if (resolved)
|
|
71
|
+
mapped.set(name, resolved);
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
missing.push({
|
|
75
|
+
item: `role:${name}`,
|
|
76
|
+
supply: `themeStudio.preview.roles.${name} (claimed by ${claimants.map((c) => `${c.page.tag}/${c.example}`).join(', ')})`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const order = Object.keys(SPECIMEN_ROLES);
|
|
80
|
+
const rank = (name) => (order.includes(name) ? order.indexOf(name) : order.length);
|
|
81
|
+
const roles = [...mapped.values()].sort((a, b) => rank(a.role) - rank(b.role) || a.role.localeCompare(b.role));
|
|
82
|
+
for (const name of order)
|
|
83
|
+
if (!mapped.has(name) && !claims.has(name))
|
|
84
|
+
missing.push({
|
|
85
|
+
item: `role:${name}`,
|
|
86
|
+
supply: `an example with previewRoles: ['${name}'], or themeStudio.preview.roles.${name}`,
|
|
87
|
+
});
|
|
88
|
+
if (!input.config)
|
|
89
|
+
missing.unshift({
|
|
90
|
+
item: 'config',
|
|
91
|
+
supply: 'themeStudio.themeConfig (a theme configuration file)',
|
|
92
|
+
});
|
|
93
|
+
if (!input.worker)
|
|
94
|
+
missing.unshift({
|
|
95
|
+
item: 'generator',
|
|
96
|
+
supply: 'a documented package that depends on @oddkin/tokens (its ./generate export)',
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
format: PAGE_FORMAT,
|
|
100
|
+
version: DATA_VERSION,
|
|
101
|
+
id,
|
|
102
|
+
kind: 'tool',
|
|
103
|
+
studio: {
|
|
104
|
+
...(input.config ? { config: input.config } : {}),
|
|
105
|
+
...(input.source ? { source: input.source } : {}),
|
|
106
|
+
...(input.worker ? { worker: input.worker } : {}),
|
|
107
|
+
roles,
|
|
108
|
+
missing,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=theme-studio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-studio.js","sourceRoot":"","sources":["../../src/data/theme-studio.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,YAAY,EACZ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I,CAAC;gBACX,IAAI,EAAE,QAAQ,IAAI,EAAE;gBACpB,MAAM,EAAE,mCAAmC,IAAI,oCAAoC,IAAI,EAAE;aAC1F,CAAC,CAAC;IACP,IAAI,CAAC,KAAK,CAAC,MAAM;QACf,OAAO,CAAC,OAAO,CAAC;YACd,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,sDAAsD;SAC/D,CAAC,CAAC;IACL,IAAI,CAAC,KAAK,CAAC,MAAM;QACf,OAAO,CAAC,OAAO,CAAC;YACd,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,6EAA6E;SACtF,CAAC,CAAC;IAEL,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,YAAY;QACrB,EAAE;QACF,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE;YACN,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,KAAK;YACL,OAAO;SACR;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workbench data files (workbench.md §2.1): a small index the shell loads first, and one data
|
|
3
|
+
* file per page that its route loads lazily. Internal formats shared by the Node tooling and the
|
|
4
|
+
* browser shell of the same Workbench version; `version` changes when a shape changes.
|
|
5
|
+
*/
|
|
6
|
+
import type { WorkbenchDiagnostic } from '../internal/diagnostics.js';
|
|
7
|
+
import type { JsonValue } from '../protocol/index.js';
|
|
8
|
+
import type { CemPackage, OddkinMetadataLike, PageKind, PageRegistry } from '../pages/types.js';
|
|
9
|
+
export declare const INDEX_FORMAT = "oddkin.workbench-index";
|
|
10
|
+
export declare const PAGE_FORMAT = "oddkin.workbench-page";
|
|
11
|
+
export declare const DATA_VERSION = 1;
|
|
12
|
+
/** A JSON object as read from a published file. */
|
|
13
|
+
export type JsonObject = {
|
|
14
|
+
readonly [key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
/** One documented package and its published outputs. */
|
|
17
|
+
export interface LibraryInput {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly version: string;
|
|
20
|
+
/** Its standard Custom Elements Manifest (`customElements`). */
|
|
21
|
+
readonly cem?: CemPackage;
|
|
22
|
+
/** Its `oddkin.metadata.json`, when the package publishes Oddkin enrichment. */
|
|
23
|
+
readonly metadata?: OddkinMetadataLike;
|
|
24
|
+
/** Authored example sets as data (`toExamplesJSON()` of each `defineExamples` module). */
|
|
25
|
+
readonly examples?: readonly ExampleSetLike[];
|
|
26
|
+
/**
|
|
27
|
+
* Tag → the import specifier of the module that registers it, from the standard CEM: the module
|
|
28
|
+
* whose exports hold the tag's `custom-element-definition`, as the package's `exports` reach it.
|
|
29
|
+
* Used when the Oddkin enrichment names no `registration`.
|
|
30
|
+
*/
|
|
31
|
+
readonly registrations?: Readonly<Record<string, string>>;
|
|
32
|
+
}
|
|
33
|
+
/** One component's examples as plain data (`@oddkin/workbench/examples` `ExamplesJSON`). */
|
|
34
|
+
export interface ExampleSetLike {
|
|
35
|
+
readonly component: string;
|
|
36
|
+
readonly examples: Readonly<Record<string, JsonObject>>;
|
|
37
|
+
}
|
|
38
|
+
/** A token as published by a token inspection (`@oddkin/tokens/inspect/*.json`). */
|
|
39
|
+
export interface InspectedTokenLike {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly cssVariable?: string;
|
|
42
|
+
readonly category?: string;
|
|
43
|
+
readonly type?: string;
|
|
44
|
+
readonly origin?: string;
|
|
45
|
+
readonly definition?: unknown;
|
|
46
|
+
readonly value?: unknown;
|
|
47
|
+
readonly description?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface TokenInspectionLike {
|
|
50
|
+
readonly theme?: string;
|
|
51
|
+
readonly tokens: readonly InspectedTokenLike[];
|
|
52
|
+
}
|
|
53
|
+
export interface WorkbenchBranding {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly logo?: string;
|
|
56
|
+
readonly links: readonly {
|
|
57
|
+
readonly label: string;
|
|
58
|
+
readonly href: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
export interface WorkbenchIndex {
|
|
62
|
+
readonly format: typeof INDEX_FORMAT;
|
|
63
|
+
readonly version: typeof DATA_VERSION;
|
|
64
|
+
readonly branding: WorkbenchBranding;
|
|
65
|
+
/** The documented packages, in configuration order. */
|
|
66
|
+
readonly libraries: readonly {
|
|
67
|
+
readonly name: string;
|
|
68
|
+
readonly version: string;
|
|
69
|
+
readonly prefix?: string;
|
|
70
|
+
}[];
|
|
71
|
+
readonly registry: PageRegistry;
|
|
72
|
+
/** Page id → its data file, relative to the index. Visible pages only. */
|
|
73
|
+
readonly pages: Readonly<Record<string, string>>;
|
|
74
|
+
/** Component pages whose element has a registration: the catalog shows each live in its card. */
|
|
75
|
+
readonly previews?: readonly string[];
|
|
76
|
+
readonly diagnostics: readonly WorkbenchDiagnostic[];
|
|
77
|
+
}
|
|
78
|
+
interface PageDataBase {
|
|
79
|
+
readonly format: typeof PAGE_FORMAT;
|
|
80
|
+
readonly version: typeof DATA_VERSION;
|
|
81
|
+
readonly id: string;
|
|
82
|
+
}
|
|
83
|
+
/** A component page: its published facts, verbatim, for the detail panels to present. */
|
|
84
|
+
export interface ComponentPageData extends PageDataBase {
|
|
85
|
+
readonly kind: 'component';
|
|
86
|
+
readonly tag: string;
|
|
87
|
+
/** The package whose manifest declares the element. */
|
|
88
|
+
readonly package: string;
|
|
89
|
+
/** The CEM module that declares it. */
|
|
90
|
+
readonly module: string;
|
|
91
|
+
/** The CEM declaration, verbatim. */
|
|
92
|
+
readonly declaration: JsonObject;
|
|
93
|
+
/** The Oddkin enrichment entry, verbatim, when published. */
|
|
94
|
+
readonly enrichment?: JsonObject;
|
|
95
|
+
/**
|
|
96
|
+
* The module that registers the element, as an import specifier, when the enrichment names none:
|
|
97
|
+
* from the standard CEM's `custom-element-definition` export (`LibraryInput.registrations`).
|
|
98
|
+
*/
|
|
99
|
+
readonly registration?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Authored examples for the element (metadata `examples`), verbatim, with their ids. When the
|
|
102
|
+
* example set was loaded, `definition` holds its values (label, props, attributes, slots,
|
|
103
|
+
* preset, guidance, incorrect, `hasFixture`).
|
|
104
|
+
*/
|
|
105
|
+
readonly examples: readonly JsonObject[];
|
|
106
|
+
/**
|
|
107
|
+
* URL of the element's example module as preview frames load it, when its examples have
|
|
108
|
+
* fixtures and their source was found: frames run the fixture of the example they mount.
|
|
109
|
+
*/
|
|
110
|
+
readonly exampleModule?: string;
|
|
111
|
+
/**
|
|
112
|
+
* The tokens the component reads (`tokenReads`), resolved from the token inspection in their
|
|
113
|
+
* order. A token missing from the inspection keeps only its name (`missing: true`).
|
|
114
|
+
*/
|
|
115
|
+
readonly tokens?: readonly (InspectedTokenLike & {
|
|
116
|
+
readonly missing?: true;
|
|
117
|
+
})[];
|
|
118
|
+
/**
|
|
119
|
+
* Authored content for the page (`oddkin.docs.ts`): intended use and section guidance. Absent
|
|
120
|
+
* when nothing is authored.
|
|
121
|
+
*/
|
|
122
|
+
readonly authored?: {
|
|
123
|
+
readonly useFor?: readonly string[];
|
|
124
|
+
readonly notFor?: readonly string[];
|
|
125
|
+
readonly guidance?: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** A foundation page: its metadata and the referenced tokens from the token inspection. */
|
|
129
|
+
export interface FoundationPageData extends PageDataBase {
|
|
130
|
+
readonly kind: 'foundation';
|
|
131
|
+
/** The foundation's metadata entry, verbatim. */
|
|
132
|
+
readonly foundation: JsonObject;
|
|
133
|
+
/**
|
|
134
|
+
* The tokens the foundation lists, in its order. A token missing from the inspection keeps
|
|
135
|
+
* only its name (`missing: true`); its value is never guessed.
|
|
136
|
+
*/
|
|
137
|
+
readonly tokens: readonly (InspectedTokenLike & {
|
|
138
|
+
readonly missing?: true;
|
|
139
|
+
})[];
|
|
140
|
+
}
|
|
141
|
+
/** Overview, tool, products, and home pages: their content comes from the index for now. */
|
|
142
|
+
export interface BasicPageData extends PageDataBase {
|
|
143
|
+
readonly kind: Exclude<PageKind, 'component' | 'foundation'>;
|
|
144
|
+
}
|
|
145
|
+
/** A specimen role played by a documented component in one of its examples. */
|
|
146
|
+
export interface SpecimenRole {
|
|
147
|
+
readonly role: string;
|
|
148
|
+
/** Visible caption. */
|
|
149
|
+
readonly label: string;
|
|
150
|
+
readonly tag: string;
|
|
151
|
+
/** The component's published registration entry. */
|
|
152
|
+
readonly registration: string;
|
|
153
|
+
/** The example whose values the specimen uses. */
|
|
154
|
+
readonly example: `example:${string}/${string}`;
|
|
155
|
+
readonly properties: Readonly<Record<string, JsonValue>>;
|
|
156
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
157
|
+
readonly slots: Readonly<Record<string, string>>;
|
|
158
|
+
/** Mapped by `themeStudio.preview.roles` or claimed by the example (`previewRoles`). */
|
|
159
|
+
readonly source: 'config' | 'example';
|
|
160
|
+
}
|
|
161
|
+
/** Theme Studio (workbench.md ?6): the baseline configuration, its generator, and specimens. */
|
|
162
|
+
export interface ThemeStudioPageData extends PageDataBase {
|
|
163
|
+
readonly kind: 'tool';
|
|
164
|
+
readonly studio: {
|
|
165
|
+
/** The baseline theme configuration's JSON model. */
|
|
166
|
+
readonly config?: JsonObject;
|
|
167
|
+
/** The configuration file, as `themeStudio.themeConfig` names it. */
|
|
168
|
+
readonly source?: string;
|
|
169
|
+
/** URL of the generation worker (the library's own `@oddkin/tokens/generate`). */
|
|
170
|
+
readonly worker?: string;
|
|
171
|
+
readonly roles: readonly SpecimenRole[];
|
|
172
|
+
/** Absent inputs, each with what supplies it; shown on the page, never guessed. */
|
|
173
|
+
readonly missing: readonly {
|
|
174
|
+
readonly item: string;
|
|
175
|
+
readonly supply: string;
|
|
176
|
+
}[];
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export type PageData = ComponentPageData | FoundationPageData | ThemeStudioPageData | BasicPageData;
|
|
180
|
+
export interface WorkbenchData {
|
|
181
|
+
readonly index: WorkbenchIndex;
|
|
182
|
+
/** Page id → data, for every entry of `index.pages`. */
|
|
183
|
+
readonly pages: Readonly<Record<string, PageData>>;
|
|
184
|
+
}
|
|
185
|
+
/** Re-exported for callers that build the registry input themselves. */
|
|
186
|
+
export type { CemPackage, OddkinMetadataLike };
|
|
187
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/data/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEhG,eAAO,MAAM,YAAY,2BAA2B,CAAC;AACrD,eAAO,MAAM,WAAW,0BAA0B,CAAC;AACnD,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE7D,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,QAAQ,CAAC,GAAG,CAAC,EAAE,U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AK,EAAE,cAAc,CAAC;IAC/B,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;CACpD;AAED,wEAAwE;AACxE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/data/types.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,YAAY,GAAG,wBAAwB,CAAC;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AACnD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@oddkin/workbench/examples` — authored examples, defined once and reused by Workbench,
|
|
3
|
+
* documentation, browser tests, Theme Studio, and agents (ADR 0021). DOM-free: importing
|
|
4
|
+
* this entry never touches the DOM; fixtures run only inside preview frames and tests.
|
|
5
|
+
*/
|
|
6
|
+
import type { Scope } from '@oddkin/core';
|
|
7
|
+
import { type WorkbenchDiagnostic } from '../internal/diagnostics.js';
|
|
8
|
+
export type { WorkbenchDiagnostic } from '../internal/diagnostics.js';
|
|
9
|
+
type DataKeys<E> = {
|
|
10
|
+
[K in keyof E]-?: E[K] extends (...args: never[]) => unknown ? never : K;
|
|
11
|
+
}[keyof E];
|
|
12
|
+
/** Public data properties of an element type, excluding those every `HTMLElement` has. */
|
|
13
|
+
export type ElementProps<E> = Partial<Pick<E, Exclude<DataKeys<E>, keyof HTMLElement>>>;
|
|
14
|
+
/** The element type for a tag: from `HTMLElementTagNameMap` when registered there. */
|
|
15
|
+
export type ElementFor<T extends string> = T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : HTMLElement & {
|
|
16
|
+
[property: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
export interface ExampleFixtureContext<E extends Element = Element> {
|
|
19
|
+
/** Owns listeners, timers, and effects; disposed when the preview or test ends. */
|
|
20
|
+
readonly scope: Scope;
|
|
21
|
+
/** The example's element, already created with its props, attributes, and slots. */
|
|
22
|
+
readonly element: E;
|
|
23
|
+
/** Render more content into the preview root; returns its first element. */
|
|
24
|
+
mount(content: unknown): Element;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Marks an example as a common mistake. It is never offered as a preset or recommendation; it
|
|
28
|
+
* explains what goes wrong, names the diagnostic `validateUsage` reports for it, and points at
|
|
29
|
+
* the correct example in the same set.
|
|
30
|
+
*/
|
|
31
|
+
export interface IncorrectUsage {
|
|
32
|
+
readonly explanation: string;
|
|
33
|
+
/** Diagnostic code `validateUsage` reports, e.g. `usage.attribute.propertyOnly`. */
|
|
34
|
+
readonly diagnostic: string;
|
|
35
|
+
/** Name of the correct example in the same set. */
|
|
36
|
+
readonly correct: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ExampleDefinition<E extends Element = HTMLElement> {
|
|
39
|
+
readonly label?: string;
|
|
40
|
+
/** Property values, checked against the element type (TypeScript) or metadata (checkExamples). */
|
|
41
|
+
readonly props?: ElementProps<E>;
|
|
42
|
+
readonly attributes?: Readonly<Record<string, string | null>>;
|
|
43
|
+
/** Plain-text slot content keyed by slot name; `default` is the default slot. */
|
|
44
|
+
readonly slots?: Readonly<Record<string, string>>;
|
|
45
|
+
readonly previewRoles?: readonly string[];
|
|
46
|
+
/** Offered as a preset on the component page. */
|
|
47
|
+
readonly preset?: boolean;
|
|
48
|
+
readonly recommended?: boolean;
|
|
49
|
+
readonly guidance?: string;
|
|
50
|
+
/** A common mistake, explained (see `IncorrectUsage`). */
|
|
51
|
+
readonly incorrect?: IncorrectUsage;
|
|
52
|
+
/** Owned setup code; runs only in preview frames and tests. */
|
|
53
|
+
readonly fixture?: (context: ExampleFixtureContext<E>) => void | Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export interface ExampleSet<E extends Element = HTMLElement> {
|
|
56
|
+
readonly component: string;
|
|
57
|
+
readonly examples: Readonly<Record<string, ExampleDefinition<E>>>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Define the examples for one component. With TypeScript and a registered tag
|
|
61
|
+
* (`HTMLElementTagNameMap`), unknown property keys and wrong value types are compile errors.
|
|
62
|
+
*/
|
|
63
|
+
export declare function defineExamples<T extends string>(tag: T, examples: Readonly<Record<string, ExampleDefinition<ElementFor<T>>>>): ExampleSet<ElementFor<T>>;
|
|
64
|
+
export declare const EXAMPLES_SCHEMA = "https://oddkin.dev/schemas/examples/v1.json";
|
|
65
|
+
/** The serializable layer (`examples.v1`); fixtures appear only as `hasFixture`. */
|
|
66
|
+
export interface ExamplesJSON {
|
|
67
|
+
readonly schema: typeof EXAMPLES_SCHEMA;
|
|
68
|
+
readonly component: string;
|
|
69
|
+
readonly examples: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
70
|
+
}
|
|
71
|
+
export declare function toExamplesJSON<E extends Element>(set: ExampleSet<E>): ExamplesJSON;
|
|
72
|
+
/** Example id shared with metadata, docs content, and agents: `example:<tag>/<name>`. */
|
|
73
|
+
export declare const exampleId: (tag: string, name: string) => string;
|
|
74
|
+
/** The parts of a component contract that examples are checked against (e.g. from CEM). */
|
|
75
|
+
export interface ExampleContract {
|
|
76
|
+
readonly properties?: readonly string[];
|
|
77
|
+
readonly slots?: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check names and, when a contract is given, property keys and slot names. Plain JavaScript
|
|
81
|
+
* authors get the same checks TypeScript gives at compile time.
|
|
82
|
+
*/
|
|
83
|
+
export declare function checkExamples<E extends Element>(set: ExampleSet<E>, contract?: ExampleContract): WorkbenchDiagnostic[];
|
|
84
|
+
/** What `validateUsage` checks examples against: the published contract of the element. */
|
|
85
|
+
export interface UsageContract {
|
|
86
|
+
/** Public writable properties; `attribute` is absent for property-only ones (`.items`). */
|
|
87
|
+
readonly properties: readonly {
|
|
88
|
+
name: string;
|
|
89
|
+
type?: string | undefined;
|
|
90
|
+
attribute?: string | undefined;
|
|
91
|
+
}[];
|
|
92
|
+
readonly slots: readonly string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Diagnostics for how each example uses the element, from its published contract: rich data
|
|
96
|
+
* written as an attribute, `"false"` on a boolean attribute, values outside an enum, unknown
|
|
97
|
+
* attributes, and unknown slots. Correct examples produce none; an incorrect example produces
|
|
98
|
+
* the diagnostic it declares.
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateUsage<E extends Element>(set: ExampleSet<E>, contract: UsageContract): WorkbenchDiagnostic[];
|
|
101
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtF,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,KAAK,QAAQ,CAAC,CAAC,IAAI;KAChB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GAAG,KAAK,GAAG,CAAC;CACzE,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,0FAA0F;AAC1F,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;AAExF,sFAAsF;AACtF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,qBAAqB,GAC5E,qBAAqB,CAAC,C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AAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAKD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAClB,QAAQ,CAAC,EAAE,eAAe,GACzB,mBAAmB,EAAE,CAgEvB;AAED,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAC5B,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,SAAS;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAChC,EAAE,CAAC;IACJ,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAUD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAClB,QAAQ,EAAE,aAAa,GACtB,mBAAmB,EAAE,CAkDvB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DiagnosticList } from '../internal/diagnostics.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define the examples for one component. With TypeScript and a registered tag
|
|
4
|
+
* (`HTMLElementTagNameMap`), unknown property keys and wrong value types are compile errors.
|
|
5
|
+
*/
|
|
6
|
+
export function defineExamples(tag, examples) {
|
|
7
|
+
return Object.freeze({ component: tag, examples: Object.freeze({ ...examples }) });
|
|
8
|
+
}
|
|
9
|
+
export const EXAMPLES_SCHEMA = 'https://oddkin.dev/schemas/examples/v1.json';
|
|
10
|
+
export function toExamplesJSON(set) {
|
|
11
|
+
const examples = {};
|
|
12
|
+
for (const [name, example] of Object.entries(set.examples)) {
|
|
13
|
+
const { fixture, ...rest } = example;
|
|
14
|
+
examples[name] = {
|
|
15
|
+
...JSON.parse(JSON.stringify(rest)),
|
|
16
|
+
...(fixture ? { hasFixture: true } : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { schema: EXAMPLES_SCHEMA, component: set.component, examples };
|
|
20
|
+
}
|
|
21
|
+
/** Example id shared with metadata, docs content, and agents: `example:<tag>/<name>`. */
|
|
22
|
+
export const exampleId = (tag, name) => `example:${tag}/${name}`;
|
|
23
|
+
const TAG = /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/;
|
|
24
|
+
const NAME = /^[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
25
|
+
/**
|
|
26
|
+
* Check names and, when a contract is given, property keys and slot names. Plain JavaScript
|
|
27
|
+
* authors get the same checks TypeScript gives at compile time.
|
|
28
|
+
*/
|
|
29
|
+
export function checkExamples(set, contract) {
|
|
30
|
+
const out = new DiagnosticList();
|
|
31
|
+
if (!TAG.test(set.component)) {
|
|
32
|
+
out.error('examples.component.invalid', `"${set.component}" is not a valid custom element name.`, '/component');
|
|
33
|
+
}
|
|
34
|
+
const properties = contract?.properties ? new Set(contract.properties) : undefined;
|
|
35
|
+
const slots = contract?.slots ? new Set(contract.slots.map((s) => s || 'default')) : undefined;
|
|
36
|
+
for (const [name, example] of Object.entries(set.examples)) {
|
|
37
|
+
const path = `/examples/${name}`;
|
|
38
|
+
if (!NAME.test(name)) {
|
|
39
|
+
out.error('examples.name.invalid', `Example name "${name}" must start with a letter and use letters, digits, and hyphens.`, path);
|
|
40
|
+
}
|
|
41
|
+
// An incorrect example breaks the contract on purpose; validateUsage reports how.
|
|
42
|
+
const checked = example.incorrect ? {} : example;
|
|
43
|
+
for (const key of Object.keys(checked.props ?? {})) {
|
|
44
|
+
if (properties && !properties.has(key)) {
|
|
45
|
+
out.error('examples.prop.unknown', `<${set.component}> has no public property "${key}" (example "${name}").`, `${path}/props/${key}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const slot of Object.keys(checked.slots ?? {})) {
|
|
49
|
+
if (slots && !slots.has(slot)) {
|
|
50
|
+
out.error('examples.slot.unknown', `<${set.component}> declares no slot "${slot}" (example "${name}").`, `${path}/slots/${slot}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const incorrect = example.incorrect;
|
|
54
|
+
if (incorrect) {
|
|
55
|
+
const correct = set.examples[incorrect.correct];
|
|
56
|
+
if (!correct || correct.incorrect)
|
|
57
|
+
out.error('examples.incorrect.correct', `Incorrect example "${name}" must name a correct example of <${set.component}>, not "${incorrect.correct}".`, `${path}/incorrect/correct`);
|
|
58
|
+
if (!incorrect.explanation.trim() || !/^[a-z]+(\.[a-zA-Z-]+)+$/.test(incorrect.diagnostic))
|
|
59
|
+
out.error('examples.incorrect.explanation', `Incorrect example "${name}" needs an explanation and a diagnostic code.`, `${path}/incorrect`);
|
|
60
|
+
if (example.preset || example.recommended || example.previewRoles?.length)
|
|
61
|
+
out.error('examples.incorrect.recommended', `Incorrect example "${name}" cannot be a preset, a recommendation, or a preview role.`, path);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out.items;
|
|
65
|
+
}
|
|
66
|
+
// Attributes every element accepts.
|
|
67
|
+
const GLOBAL_ATTRIBUTE = /^(?:id|class|style|slot|part|lang|dir|title|hidden|inert|tabindex|role|autofocus|exportparts|data-.+|aria-.+)$/;
|
|
68
|
+
const unionOf = (type) => type && /^"[^"]*"( \| "[^"]*")*$/.test(type)
|
|
69
|
+
? [...type.matchAll(/"([^"]*)"/g)].map((m) => m[1])
|
|
70
|
+
: undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Diagnostics for how each example uses the element, from its published contract: rich data
|
|
73
|
+
* written as an attribute, `"false"` on a boolean attribute, values outside an enum, unknown
|
|
74
|
+
* attributes, and unknown slots. Correct examples produce none; an incorrect example produces
|
|
75
|
+
* the diagnostic it declares.
|
|
76
|
+
*/
|
|
77
|
+
export function validateUsage(set, contract) {
|
|
78
|
+
const out = new DiagnosticList();
|
|
79
|
+
const byAttribute = new Map(contract.properties.filter((p) => p.attribute).map((p) => [p.attribute, p]));
|
|
80
|
+
const slots = new Set(contract.slots.map((s) => s || 'default'));
|
|
81
|
+
const tag = set.component;
|
|
82
|
+
for (const [name, example] of Object.entries(set.examples)) {
|
|
83
|
+
const path = `/examples/${name}`;
|
|
84
|
+
for (const [attribute, value] of Object.entries(example.attributes ?? {})) {
|
|
85
|
+
const at = `${path}/attributes/${attribute}`;
|
|
86
|
+
const property = byAttribute.get(attribute);
|
|
87
|
+
const named = contract.properties.find((p) => p.name === attribute);
|
|
88
|
+
if (!property && named && !named.attribute)
|
|
89
|
+
out.error('usage.attribute.propertyOnly', `<${tag}> reads "${attribute}" only as a property; set .${attribute} with a value, not an attribute string.`, at);
|
|
90
|
+
else if (!property && !GLOBAL_ATTRIBUTE.test(attribute))
|
|
91
|
+
out.error('usage.attribute.unknown', `<${tag}> has no attribute "${attribute}"${named ? `; use "${named.attribute}"` : ''}.`, at);
|
|
92
|
+
else if (property?.type === 'boolean' && value === 'false')
|
|
93
|
+
out.error('usage.boolean.false', `[${attribute}="false"] still turns ${property.name} on: the attribute's presence means true. Remove the attribute instead.`, at);
|
|
94
|
+
else {
|
|
95
|
+
const allowed = unionOf(property?.type);
|
|
96
|
+
if (value !== null && allowed && !allowed.includes(value))
|
|
97
|
+
out.error('usage.attribute.value', `<${tag}> ${attribute}="${value}" is not one of ${allowed.join(', ')}; the default is used.`, at);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const slot of Object.keys(example.slots ?? {}))
|
|
101
|
+
if (!slots.has(slot))
|
|
102
|
+
out.error('usage.slot.unknown', `<${tag}> declares no slot "${slot}"; the content is not shown.`, `${path}/slots/${slot}`);
|
|
103
|
+
}
|
|
104
|
+
return out.items;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mapp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AC,wBAAwB,EAC5F,EAAE,CACH,CAAC;YACN,CAAC;QACH,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;YACjD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;gBAClB,GAAG,CAAC,KAAK,CACP,oBAAoB,EACpB,IAAI,GAAG,uBAAuB,IAAI,8BAA8B,EAChE,GAAG,IAAI,UAAU,IAAI,EAAE,CACxB,CAAC;IACR,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JsonValue } from '../protocol/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A plain-JSON summary of an event detail: cycles, DOM nodes, functions, `Map`/`Set`, errors,
|
|
4
|
+
* and class instances are described rather than transferred, and the result is size-capped.
|
|
5
|
+
*/
|
|
6
|
+
export declare function summarizeDetail(value: unknown): JsonValue;
|
|
7
|
+
/** Install the runtime on a frame's own Window. Exported for controlled browser tests. */
|
|
8
|
+
export declare function installFrameRuntime(win?: Window): void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/frame/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAYL,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAC;AA8N9B;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAuDzD;AAiHD,0FAA0F;AAC1F,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAe,GAAG,IAAI,CAwG9D"}
|