@adminiumjs/skin-kit 0.0.0-stage → 0.3.82
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 +44 -2
- package/dist/contract.d.ts +90 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +216 -0
- package/dist/contract.js.map +1 -0
- package/dist/css.d.ts +51 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +690 -0
- package/dist/css.js.map +1 -0
- package/dist/diff.d.ts +11 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +122 -0
- package/dist/diff.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +92 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +199 -0
- package/dist/loader.js.map +1 -0
- package/dist/react.d.ts +87 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +346 -0
- package/dist/react.js.map +1 -0
- package/dist/testing.d.ts +39 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +107 -0
- package/dist/testing.js.map +1 -0
- package/dist/tokens.d.ts +149 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +367 -0
- package/dist/tokens.js.map +1 -0
- package/dist/validate.d.ts +154 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +621 -0
- package/dist/validate.js.map +1 -0
- package/dist/version.d.ts +22 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +41 -0
- package/dist/version.js.map +1 -0
- package/package.json +50 -4
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE RENDERER: a skin's block trees drawn as React elements.
|
|
3
|
+
*
|
|
4
|
+
* - Each slot renders inside its own wrapper (`data-kit-slot`) and error
|
|
5
|
+
* boundary; a throw draws the app's own part, and a second one in a view
|
|
6
|
+
* drops the skin for that view.
|
|
7
|
+
* - The allow-list is checked again here, at render: tags, types, levels,
|
|
8
|
+
* reused slots and depth, not only when the package was attached.
|
|
9
|
+
* - Holes are text nodes; a figure prop is drawn in the app's own face.
|
|
10
|
+
* - Hosts are the app's own elements in a wrapper the skin places by area
|
|
11
|
+
* only; every block above a host is marked, so the guard keeps it whole.
|
|
12
|
+
* Before paint each required host group must have one host that is drawn,
|
|
13
|
+
* big enough, inside its slot and not covered; otherwise the slot falls
|
|
14
|
+
* back to the app's own.
|
|
15
|
+
* - On a bare screen no slot draws; on a rules screen only the contract's
|
|
16
|
+
* rules slots do.
|
|
17
|
+
*/
|
|
18
|
+
import { type ReactNode } from 'react';
|
|
19
|
+
import type { SkinContract } from './contract.js';
|
|
20
|
+
import { type SkinPackage } from './validate.js';
|
|
21
|
+
/** What a link the skin draws is given; the app draws it with its own router. */
|
|
22
|
+
export interface SkinLinkProps {
|
|
23
|
+
/** A route id (`shop`), an app-checked target (`https:…`, `mailto:…`), or `#sk-<anchor>`. */
|
|
24
|
+
to: string;
|
|
25
|
+
external: boolean;
|
|
26
|
+
className?: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/** One run of rich text, or a list of them. */
|
|
31
|
+
export interface RichRun {
|
|
32
|
+
text: string;
|
|
33
|
+
strong?: boolean;
|
|
34
|
+
em?: boolean;
|
|
35
|
+
to?: string;
|
|
36
|
+
}
|
|
37
|
+
export type RichBlock = {
|
|
38
|
+
p: RichRun[];
|
|
39
|
+
} | {
|
|
40
|
+
ul: RichRun[][];
|
|
41
|
+
} | {
|
|
42
|
+
ol: RichRun[][];
|
|
43
|
+
};
|
|
44
|
+
/** A picture prop's value. */
|
|
45
|
+
export interface PictureValue {
|
|
46
|
+
url: string;
|
|
47
|
+
alt?: string;
|
|
48
|
+
w?: number;
|
|
49
|
+
h?: number;
|
|
50
|
+
decorative?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** A host the app draws as off (a closed surface's search), which still satisfies its group. */
|
|
53
|
+
export declare const HOST_OFF: unique symbol;
|
|
54
|
+
export interface SkinRuntime {
|
|
55
|
+
skin: SkinPackage;
|
|
56
|
+
contract: SkinContract;
|
|
57
|
+
/** The skin's file folder (the config's `base`). */
|
|
58
|
+
base: string;
|
|
59
|
+
/** The shopper's language, for the skin's own words. */
|
|
60
|
+
language: string;
|
|
61
|
+
/** Which kind of screen is showing: from `screenKind`. */
|
|
62
|
+
screen: 'free' | 'rules' | 'bare';
|
|
63
|
+
/** The app's words for a slot (`t`), in the shopper's language. */
|
|
64
|
+
words: (slot: string) => Readonly<Record<string, string>>;
|
|
65
|
+
renderLink: (props: SkinLinkProps) => ReactNode;
|
|
66
|
+
renderIcon: (name: string, className: string | undefined) => ReactNode;
|
|
67
|
+
/** The app's own controls: what each host draws (or HOST_OFF). */
|
|
68
|
+
hosts: Readonly<Record<string, () => ReactNode | typeof HOST_OFF>>;
|
|
69
|
+
}
|
|
70
|
+
/** The kind of screen a view is, by the contract. */
|
|
71
|
+
export declare function screenKind(contract: Pick<SkinContract, 'screens'>, view: string): 'free' | 'rules' | 'bare';
|
|
72
|
+
/**
|
|
73
|
+
* Give the slots below a loaded skin, or null for the app's own look. A new
|
|
74
|
+
* `viewKey` (the route) gives the view a fresh error count.
|
|
75
|
+
*/
|
|
76
|
+
export declare function SkinProvider({ runtime, viewKey, children }: {
|
|
77
|
+
runtime: SkinRuntime | null;
|
|
78
|
+
viewKey: string;
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}): ReactNode;
|
|
81
|
+
/** Draw a slot of the skin, or `fallback` (the app's own part) when there is none, or it can't draw here. */
|
|
82
|
+
export declare function SkinSlot({ name, props, fallback }: {
|
|
83
|
+
name: string;
|
|
84
|
+
props: Readonly<Record<string, unknown>>;
|
|
85
|
+
fallback: ReactNode;
|
|
86
|
+
}): ReactNode;
|
|
87
|
+
//# sourceMappingURL=react.d.ts.map
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@ -0,0 +1,346 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* THE RENDERER: a skin's block trees drawn as React elements.
|
|
5
|
+
*
|
|
6
|
+
* - Each slot renders inside its own wrapper (`data-kit-slot`) and error
|
|
7
|
+
* boundary; a throw draws the app's own part, and a second one in a view
|
|
8
|
+
* drops the skin for that view.
|
|
9
|
+
* - The allow-list is checked again here, at render: tags, types, levels,
|
|
10
|
+
* reused slots and depth, not only when the package was attached.
|
|
11
|
+
* - Holes are text nodes; a figure prop is drawn in the app's own face.
|
|
12
|
+
* - Hosts are the app's own elements in a wrapper the skin places by area
|
|
13
|
+
* only; every block above a host is marked, so the guard keeps it whole.
|
|
14
|
+
* Before paint each required host group must have one host that is drawn,
|
|
15
|
+
* big enough, inside its slot and not covered; otherwise the slot falls
|
|
16
|
+
* back to the app's own.
|
|
17
|
+
* - On a bare screen no slot draws; on a rules screen only the contract's
|
|
18
|
+
* rules slots do.
|
|
19
|
+
*/
|
|
20
|
+
import { Component, createContext, Fragment, useContext, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
21
|
+
import { BLOCK_TYPES, CONTAINER_TAGS, LIMITS, parseTemplate, specAt } from './validate.js';
|
|
22
|
+
/** A host the app draws as off (a closed surface's search), which still satisfies its group. */
|
|
23
|
+
export const HOST_OFF = Symbol('kit-host-off');
|
|
24
|
+
/** The kind of screen a view is, by the contract. */
|
|
25
|
+
export function screenKind(contract, view) {
|
|
26
|
+
if (contract.screens.bare.includes(view))
|
|
27
|
+
return 'bare';
|
|
28
|
+
if (contract.screens.rules.includes(view))
|
|
29
|
+
return 'rules';
|
|
30
|
+
return 'free';
|
|
31
|
+
}
|
|
32
|
+
const RuntimeContext = createContext(null);
|
|
33
|
+
/**
|
|
34
|
+
* Give the slots below a loaded skin, or null for the app's own look. A new
|
|
35
|
+
* `viewKey` (the route) gives the view a fresh error count.
|
|
36
|
+
*/
|
|
37
|
+
export function SkinProvider({ runtime, viewKey, children }) {
|
|
38
|
+
const [droppedFor, setDroppedFor] = useState(null);
|
|
39
|
+
const counter = useRef({ key: viewKey, errors: 0 });
|
|
40
|
+
if (counter.current.key !== viewKey)
|
|
41
|
+
counter.current = { key: viewKey, errors: 0 };
|
|
42
|
+
const value = useMemo(() => ({
|
|
43
|
+
runtime,
|
|
44
|
+
view: {
|
|
45
|
+
get errors() {
|
|
46
|
+
return counter.current.errors;
|
|
47
|
+
},
|
|
48
|
+
dropped: droppedFor === viewKey,
|
|
49
|
+
drop: () => {
|
|
50
|
+
counter.current.errors += 1;
|
|
51
|
+
if (counter.current.errors >= 2)
|
|
52
|
+
setDroppedFor(viewKey);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}), [runtime, droppedFor, viewKey]);
|
|
56
|
+
return _jsx(RuntimeContext.Provider, { value: value, children: children });
|
|
57
|
+
}
|
|
58
|
+
class SlotBoundary extends Component {
|
|
59
|
+
state = { failed: false };
|
|
60
|
+
static getDerivedStateFromError() {
|
|
61
|
+
return { failed: true };
|
|
62
|
+
}
|
|
63
|
+
componentDidCatch() {
|
|
64
|
+
this.props.onError();
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
return this.state.failed ? this.props.fallback : this.props.children;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Draw a slot of the skin, or `fallback` (the app's own part) when there is none, or it can't draw here. */
|
|
71
|
+
export function SkinSlot({ name, props, fallback }) {
|
|
72
|
+
const context = useContext(RuntimeContext);
|
|
73
|
+
const runtime = context?.runtime ?? null;
|
|
74
|
+
if (runtime === null || context === null || context.view.dropped)
|
|
75
|
+
return fallback;
|
|
76
|
+
if (runtime.screen === 'bare')
|
|
77
|
+
return fallback;
|
|
78
|
+
if (runtime.screen === 'rules' && !runtime.contract.rulesSlots.includes(name))
|
|
79
|
+
return fallback;
|
|
80
|
+
const tree = runtime.skin.slots[name];
|
|
81
|
+
if (tree === undefined)
|
|
82
|
+
return fallback;
|
|
83
|
+
return (_jsx(SlotBoundary, { fallback: fallback, onError: context.view.drop, children: _jsx(SlotFrame, { runtime: runtime, slot: name, tree: tree, props: props, fallback: fallback, depth: 0 }) }));
|
|
84
|
+
}
|
|
85
|
+
/** Hosts are visible, big enough, inside the slot and on top. */
|
|
86
|
+
function hostReads(host, frame) {
|
|
87
|
+
if (host.hasAttribute('data-kit-host-off'))
|
|
88
|
+
return true;
|
|
89
|
+
if (!host.checkVisibility({ opacityProperty: true, visibilityProperty: true }))
|
|
90
|
+
return false;
|
|
91
|
+
const rect = host.getBoundingClientRect();
|
|
92
|
+
if (rect.width < 24 || rect.height < 24)
|
|
93
|
+
return false;
|
|
94
|
+
if (rect.left < frame.left - 0.5 || rect.top < frame.top - 0.5 || rect.right > frame.right + 0.5 || rect.bottom > frame.bottom + 0.5)
|
|
95
|
+
return false;
|
|
96
|
+
const x = rect.left + rect.width / 2;
|
|
97
|
+
const y = rect.top + rect.height / 2;
|
|
98
|
+
if (x >= 0 && y >= 0 && x < (globalThis.innerWidth ?? 0) && y < (globalThis.innerHeight ?? 0)) {
|
|
99
|
+
const hit = host.ownerDocument.elementFromPoint(x, y);
|
|
100
|
+
if (hit !== null && !host.contains(hit))
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
function SlotFrame({ runtime, slot, tree, props, fallback, depth }) {
|
|
106
|
+
const frame = useRef(null);
|
|
107
|
+
const [failed, setFailed] = useState(false);
|
|
108
|
+
const groups = runtime.contract.slots[slot]?.requiredHosts ?? [];
|
|
109
|
+
useLayoutEffect(() => {
|
|
110
|
+
const element = frame.current;
|
|
111
|
+
if (element === null || groups.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
const check = () => {
|
|
114
|
+
if (typeof element.checkVisibility !== 'function')
|
|
115
|
+
return;
|
|
116
|
+
const box = element.getBoundingClientRect();
|
|
117
|
+
if (box.width === 0 && box.height === 0)
|
|
118
|
+
return;
|
|
119
|
+
const ok = groups.every((group) => group.some((name) => {
|
|
120
|
+
const host = element.querySelector(`[data-kit-host="${name}"]`);
|
|
121
|
+
return host !== null && hostReads(host, box);
|
|
122
|
+
}));
|
|
123
|
+
if (!ok)
|
|
124
|
+
setFailed(true);
|
|
125
|
+
};
|
|
126
|
+
check();
|
|
127
|
+
if (typeof ResizeObserver !== 'function')
|
|
128
|
+
return;
|
|
129
|
+
const observer = new ResizeObserver(check);
|
|
130
|
+
observer.observe(element);
|
|
131
|
+
return () => observer.disconnect();
|
|
132
|
+
}, [groups]);
|
|
133
|
+
if (failed)
|
|
134
|
+
return fallback;
|
|
135
|
+
const words = runtime.words(slot);
|
|
136
|
+
const scope = { slot, props, words, loops: {}, loopSpecs: {} };
|
|
137
|
+
return (_jsx("div", { ref: frame, "data-kit-slot": slot, children: renderBlock(runtime, tree, scope, depth, null) }));
|
|
138
|
+
}
|
|
139
|
+
function valueAt(runtime, scope, path) {
|
|
140
|
+
const [root, ...rest] = path;
|
|
141
|
+
if (root === 't')
|
|
142
|
+
return scope.words[rest[0] ?? ''] ?? '';
|
|
143
|
+
if (root === 'w') {
|
|
144
|
+
const words = runtime.skin.words ?? {};
|
|
145
|
+
const lang = runtime.language;
|
|
146
|
+
const base = lang.split('-')[0] ?? lang;
|
|
147
|
+
return words[lang]?.[rest[0] ?? ''] ?? words[base]?.[rest[0] ?? ''] ?? words[runtime.skin.defaultLanguage ?? '']?.[rest[0] ?? ''] ?? '';
|
|
148
|
+
}
|
|
149
|
+
let value = root !== undefined && root in scope.loops ? scope.loops[root] : scope.props[root ?? ''];
|
|
150
|
+
for (const seg of rest)
|
|
151
|
+
value = typeof value === 'object' && value !== null ? value[seg] : undefined;
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
function truthy(value) {
|
|
155
|
+
if (Array.isArray(value))
|
|
156
|
+
return value.length > 0;
|
|
157
|
+
return value !== null && value !== undefined && value !== false && value !== '';
|
|
158
|
+
}
|
|
159
|
+
function holds(runtime, scope, when) {
|
|
160
|
+
const m = /^(!?)([a-zA-Z][a-zA-Z0-9.]*)(?:=([a-z0-9-]{1,32}))?$/.exec(when);
|
|
161
|
+
if (m === null)
|
|
162
|
+
throw new Error('when');
|
|
163
|
+
const value = valueAt(runtime, scope, (m[2] ?? '').split('.'));
|
|
164
|
+
const result = m[3] !== undefined ? value === m[3] : truthy(value);
|
|
165
|
+
return m[1] === '!' ? !result : result;
|
|
166
|
+
}
|
|
167
|
+
/** A text template drawn as text nodes; a figure in the app's own face. */
|
|
168
|
+
function renderTemplate(runtime, scope, template, keyBase) {
|
|
169
|
+
const pieces = parseTemplate(template);
|
|
170
|
+
if (typeof pieces === 'string')
|
|
171
|
+
throw new Error(pieces);
|
|
172
|
+
return pieces.map((piece, i) => {
|
|
173
|
+
if ('text' in piece)
|
|
174
|
+
return _jsx(Fragment, { children: piece.text }, `${keyBase}${String(i)}`);
|
|
175
|
+
const value = valueAt(runtime, scope, piece.hole);
|
|
176
|
+
const spec = specAt(runtime.contract, scope.slot, scope.loopSpecs, piece.hole);
|
|
177
|
+
if (spec?.kind === 'rich')
|
|
178
|
+
return _jsx(Fragment, { children: renderRich(runtime, value) }, `${keyBase}${String(i)}`);
|
|
179
|
+
const text = typeof value === 'string' || typeof value === 'number' ? String(value) : '';
|
|
180
|
+
return spec?.kind === 'figure' ? (_jsx("span", { className: "kit-figure", children: text }, `${keyBase}${String(i)}`)) : (_jsx(Fragment, { children: text }, `${keyBase}${String(i)}`));
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** Template text as one string (an accessible name, an alt). */
|
|
184
|
+
function templateText(runtime, scope, template) {
|
|
185
|
+
const pieces = parseTemplate(template);
|
|
186
|
+
if (typeof pieces === 'string')
|
|
187
|
+
throw new Error(pieces);
|
|
188
|
+
return pieces.map((piece) => ('text' in piece ? piece.text : String(valueAt(runtime, scope, piece.hole) ?? ''))).join('');
|
|
189
|
+
}
|
|
190
|
+
function renderRuns(runtime, runs) {
|
|
191
|
+
if (!Array.isArray(runs))
|
|
192
|
+
return null;
|
|
193
|
+
return runs.map((run, i) => {
|
|
194
|
+
if (typeof run !== 'object' || run === null || typeof run.text !== 'string')
|
|
195
|
+
return null;
|
|
196
|
+
const r = run;
|
|
197
|
+
let node = r.text;
|
|
198
|
+
if (r.em === true)
|
|
199
|
+
node = _jsx("em", { children: node });
|
|
200
|
+
if (r.strong === true)
|
|
201
|
+
node = _jsx("strong", { children: node });
|
|
202
|
+
if (typeof r.to === 'string')
|
|
203
|
+
node = runtime.renderLink({ to: r.to, external: /^(https|mailto|tel):/.test(r.to), children: node });
|
|
204
|
+
return _jsx(Fragment, { children: node }, i);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/** Rich text, drawn by the kit's own fixed renderer: paragraphs and lists. */
|
|
208
|
+
function renderRich(runtime, value) {
|
|
209
|
+
if (!Array.isArray(value))
|
|
210
|
+
return null;
|
|
211
|
+
return value.map((block, i) => {
|
|
212
|
+
if (typeof block !== 'object' || block === null)
|
|
213
|
+
return null;
|
|
214
|
+
const b = block;
|
|
215
|
+
if (Array.isArray(b['p']))
|
|
216
|
+
return _jsx("p", { children: renderRuns(runtime, b['p']) }, i);
|
|
217
|
+
const list = Array.isArray(b['ul']) ? 'ul' : Array.isArray(b['ol']) ? 'ol' : null;
|
|
218
|
+
if (list === null)
|
|
219
|
+
return null;
|
|
220
|
+
const items = b[list].map((runs, j) => _jsx("li", { children: renderRuns(runtime, runs) }, j));
|
|
221
|
+
return list === 'ul' ? _jsx("ul", { children: items }, i) : _jsx("ol", { children: items }, i);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const cls = (slot, names) => names === undefined ? undefined : names.split(/\s+/).filter(Boolean).map((name) => `sk-${slot.replace(/\./g, '-')}-${name}`).join(' ');
|
|
225
|
+
function hasHost(block) {
|
|
226
|
+
return block.t === 'host' || (block.c ?? []).some(hasHost);
|
|
227
|
+
}
|
|
228
|
+
/** Draw one block; throws on anything the allow-list doesn't hold (the boundary draws the app's part). */
|
|
229
|
+
function renderBlock(runtime, block, scope, depth, ground, key) {
|
|
230
|
+
if (depth > LIMITS.depth || !BLOCK_TYPES.includes(block.t))
|
|
231
|
+
throw new Error('a block outside the vocabulary');
|
|
232
|
+
if (block.when !== undefined && !holds(runtime, scope, block.when))
|
|
233
|
+
return null;
|
|
234
|
+
const on = block.on ?? null;
|
|
235
|
+
const here = on ?? ground;
|
|
236
|
+
const className = cls(scope.slot, block.cls);
|
|
237
|
+
const onAttr = on === null ? {} : { 'data-kit-on': on };
|
|
238
|
+
switch (block.t) {
|
|
239
|
+
case 'stack':
|
|
240
|
+
case 'row':
|
|
241
|
+
case 'grid': {
|
|
242
|
+
const tag = block.tag ?? 'div';
|
|
243
|
+
if (!CONTAINER_TAGS.includes(tag))
|
|
244
|
+
throw new Error('a tag outside the vocabulary');
|
|
245
|
+
const Tag = tag;
|
|
246
|
+
const pathAttr = hasHost(block) ? { 'data-kit-hostpath': '' } : {};
|
|
247
|
+
const label = block.label === undefined ? {} : { 'aria-label': templateText(runtime, scope, block.label) };
|
|
248
|
+
let children;
|
|
249
|
+
if (block.each !== undefined) {
|
|
250
|
+
const list = valueAt(runtime, scope, block.each.split('.'));
|
|
251
|
+
const items = Array.isArray(list) ? list.slice(0, LIMITS.eachDrawn) : [];
|
|
252
|
+
const loop = block.as ?? 'item';
|
|
253
|
+
const spec = specAt(runtime.contract, scope.slot, scope.loopSpecs, block.each.split('.'));
|
|
254
|
+
children = items.map((element, i) => {
|
|
255
|
+
if (typeof block.item === 'string') {
|
|
256
|
+
const target = block.item.slice(1);
|
|
257
|
+
const reused = runtime.skin.slots[target];
|
|
258
|
+
if (runtime.contract.slots[target]?.reusable !== true || reused === undefined || target === scope.slot)
|
|
259
|
+
throw new Error('a reused slot outside the contract');
|
|
260
|
+
return (_jsx(SlotBoundary, { fallback: null, onError: () => undefined, children: _jsx(SlotFrame, { runtime: runtime, slot: target, tree: reused, props: { item: element }, fallback: null, depth: depth + 1 }) }, i));
|
|
261
|
+
}
|
|
262
|
+
if (block.item === undefined)
|
|
263
|
+
return null;
|
|
264
|
+
const inner = { ...scope, loops: { ...scope.loops, [loop]: element }, loopSpecs: { ...scope.loopSpecs, ...(spec?.of === undefined ? {} : { [loop]: spec.of }) } };
|
|
265
|
+
return renderBlock(runtime, block.item, inner, depth + 1, here, i);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
else
|
|
269
|
+
children = (block.c ?? []).map((child, i) => renderBlock(runtime, child, scope, depth + 1, here, i));
|
|
270
|
+
return (_jsx(Tag, { className: className, ...onAttr, ...pathAttr, ...label, children: children }, key));
|
|
271
|
+
}
|
|
272
|
+
case 'heading': {
|
|
273
|
+
const level = block.level ?? 2;
|
|
274
|
+
if (!Number.isInteger(level) || level < 1 || level > 6)
|
|
275
|
+
throw new Error('a heading level outside 1–6');
|
|
276
|
+
const Tag = `h${String(level)}`;
|
|
277
|
+
const id = block.id === undefined ? {} : { id: `sk-${block.id.startsWith('{') ? String(valueAt(runtime, scope, block.id.slice(1, -1).split('.')) ?? '') : block.id}` };
|
|
278
|
+
return (_jsx(Tag, { className: className, ...id, children: block.parts !== undefined ? renderParts(runtime, scope, block.parts) : renderTemplate(runtime, scope, block.text ?? '', 'h') }, key));
|
|
279
|
+
}
|
|
280
|
+
case 'text': {
|
|
281
|
+
const content = block.parts !== undefined ? renderParts(runtime, scope, block.parts) : renderTemplate(runtime, scope, block.text ?? '', 't');
|
|
282
|
+
// A rich hole draws its own paragraphs: wrap it in a div, never a p.
|
|
283
|
+
const rich = block.text !== undefined && specAt(runtime.contract, scope.slot, scope.loopSpecs, (/^\{([^}]+)\}$/.exec(block.text)?.[1] ?? '').split('.'))?.kind === 'rich';
|
|
284
|
+
if (rich)
|
|
285
|
+
return _jsx("div", { className: className, children: content }, key);
|
|
286
|
+
return block.inline === true ? _jsx("span", { className: className, children: content }, key) : _jsx("p", { className: className, children: content }, key);
|
|
287
|
+
}
|
|
288
|
+
case 'image': {
|
|
289
|
+
const src = block.src ?? '';
|
|
290
|
+
if (src.startsWith('asset:')) {
|
|
291
|
+
const file = src.slice('asset:'.length);
|
|
292
|
+
const alt = block.decorative === true ? '' : templateText(runtime, scope, block.alt ?? '');
|
|
293
|
+
return _jsx("img", { className: className, src: `${runtime.base}${file}`, alt: alt, loading: "lazy", decoding: "async" }, key);
|
|
294
|
+
}
|
|
295
|
+
const value = valueAt(runtime, scope, src.slice(1, -1).split('.'));
|
|
296
|
+
if (value === null || value === undefined || typeof value.url !== 'string')
|
|
297
|
+
return null;
|
|
298
|
+
const alt = block.decorative === true || value.decorative === true ? '' : block.alt !== undefined ? templateText(runtime, scope, block.alt) : (value.alt ?? '');
|
|
299
|
+
return _jsx("img", { className: className, src: value.url, alt: alt, loading: "lazy", decoding: "async", ...(value.w === undefined ? {} : { width: value.w }), ...(value.h === undefined ? {} : { height: value.h }) }, key);
|
|
300
|
+
}
|
|
301
|
+
case 'link': {
|
|
302
|
+
const raw = block.to ?? '';
|
|
303
|
+
let to = raw;
|
|
304
|
+
if (raw.startsWith('{')) {
|
|
305
|
+
const path = raw.slice(1, -1).split('.');
|
|
306
|
+
const value = valueAt(runtime, scope, path);
|
|
307
|
+
if (typeof value !== 'string' || value === '')
|
|
308
|
+
return null;
|
|
309
|
+
const spec = specAt(runtime.contract, scope.slot, scope.loopSpecs, path);
|
|
310
|
+
to = spec?.kind === 'anchor' ? `#sk-${value}` : value;
|
|
311
|
+
if (spec?.kind === 'target' && /^[a-z]+:/.test(to) && !/^(https|mailto|tel):/.test(to))
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
const external = /^(https|mailto|tel):/.test(to);
|
|
315
|
+
const children = block.c !== undefined ? block.c.map((child, i) => renderBlock(runtime, child, scope, depth + 1, here, i)) : block.parts !== undefined ? renderParts(runtime, scope, block.parts) : renderTemplate(runtime, scope, block.text ?? '', 'l');
|
|
316
|
+
return (_jsx(Fragment, { children: runtime.renderLink({
|
|
317
|
+
to,
|
|
318
|
+
external,
|
|
319
|
+
...(className === undefined ? {} : { className }),
|
|
320
|
+
...(block.label === undefined ? {} : { label: templateText(runtime, scope, block.label) }),
|
|
321
|
+
children: on === null ? children : _jsx("span", { ...onAttr, children: children }),
|
|
322
|
+
}) }, key));
|
|
323
|
+
}
|
|
324
|
+
case 'icon': {
|
|
325
|
+
const name = block.name?.startsWith('{') === true ? String(valueAt(runtime, scope, block.name.slice(1, -1).split('.')) ?? '') : (block.name ?? '');
|
|
326
|
+
if (!(runtime.contract.icons ?? []).includes(name))
|
|
327
|
+
return null;
|
|
328
|
+
return _jsx(Fragment, { children: runtime.renderIcon(name, className) }, key);
|
|
329
|
+
}
|
|
330
|
+
case 'host': {
|
|
331
|
+
const name = block.name ?? '';
|
|
332
|
+
if (!(runtime.contract.slots[scope.slot]?.hosts ?? []).includes(name))
|
|
333
|
+
throw new Error('a host outside the slot');
|
|
334
|
+
const drawn = runtime.hosts[name]?.() ?? HOST_OFF;
|
|
335
|
+
const off = drawn === HOST_OFF ? { 'data-kit-host-off': '' } : {};
|
|
336
|
+
return (_jsx("span", { className: "kit-host", "data-kit-host": name, ...off, ...(here === null ? {} : { 'data-kit-on': here }), style: { '--kit-area': block.area ?? 'auto' }, children: drawn === HOST_OFF ? null : drawn }, key));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function renderParts(runtime, scope, parts) {
|
|
341
|
+
return parts.map((part, i) => {
|
|
342
|
+
const content = renderTemplate(runtime, scope, part.text, `p${String(i)}-`);
|
|
343
|
+
return part.mono === true ? (_jsx("span", { className: "kit-mono", children: content }, i)) : (_jsx(Fragment, { children: content }, i));
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;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AK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,IAAI,MAAM,EAAE,YACjK,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IADzB,GAAG,CAEP,CACR,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,OAAoB,EAAE,KAAY,EAAE,KAAkD;IACzG,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAC1B,eAAc,SAAS,EAAC,UAAU,YAC/B,OAAO,IADC,CAAC,CAEL,CACR,CAAC,CAAC,CAAC,CACF,KAAC,QAAQ,cAAU,OAAO,IAAX,CAAC,CAAsB,CACvC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SkinContract } from './contract.js';
|
|
2
|
+
import type { Dropped, KeptRule } from './css.js';
|
|
3
|
+
import { type SkinProblem } from './validate.js';
|
|
4
|
+
export { assertAdditive, diffContracts } from './diff.js';
|
|
5
|
+
/** The engine's and the browser's verdict on a package's data. */
|
|
6
|
+
export declare function checkSkin(contract: SkinContract, skinJson: unknown, files: readonly string[]): {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
problems: SkinProblem[];
|
|
9
|
+
};
|
|
10
|
+
/** A CSS attack, by slot, and what must come of it. */
|
|
11
|
+
export interface HostileCss {
|
|
12
|
+
name: string;
|
|
13
|
+
css: string;
|
|
14
|
+
/** Text that must not appear in any kept rule (a selector, a property or a value). */
|
|
15
|
+
mustNotKeep: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/** T08b's CSS cases: each one tries a route out of its slot. */
|
|
18
|
+
export declare const HOSTILE_CSS: readonly HostileCss[];
|
|
19
|
+
export type BrowserName = 'chromium' | 'webkit' | 'firefox';
|
|
20
|
+
/**
|
|
21
|
+
* Filter CSS in a real browser and hand back what was kept and dropped, per
|
|
22
|
+
* slot. Needs `@playwright/test` (or `playwright`) and the browser installed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function filterInBrowser(slots: Readonly<Record<string, string>>, context: {
|
|
25
|
+
container: string;
|
|
26
|
+
appColors?: readonly string[];
|
|
27
|
+
}, browserName?: BrowserName): Promise<{
|
|
28
|
+
kept: Record<string, KeptRule[]>;
|
|
29
|
+
dropped: Dropped[];
|
|
30
|
+
sheetText: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** A package's CSS, read as a shopper's browser reads it: what each slot keeps, and every drop with why. */
|
|
33
|
+
export declare function checkSkinCss(contract: SkinContract, skinJson: {
|
|
34
|
+
styles?: Record<string, string>;
|
|
35
|
+
}, readFile: (path: string) => string, browserName?: BrowserName): Promise<{
|
|
36
|
+
dropped: Dropped[];
|
|
37
|
+
sheetText: string;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1D,kEAAkE;AAClE,wBAAgB,SAAS,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ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* THE CONFORMANCE HARNESS, for skin authors and for each app's CI.
|
|
4
|
+
*
|
|
5
|
+
* - `checkSkin(contract, skinJson, files)`: what the engine and the browser
|
|
6
|
+
* will say of a package's data, with every problem's place.
|
|
7
|
+
* - `assertAdditive(prev, next)`: a contract minor only adds (each app runs it
|
|
8
|
+
* over its released contracts).
|
|
9
|
+
* - `checkSkinCss(contract, skinJson, readFile)`: the CSS read the way a
|
|
10
|
+
* shopper's browser reads it (Chromium, WebKit or Firefox through
|
|
11
|
+
* Playwright), listing every rule and declaration left out and why.
|
|
12
|
+
* - `HOSTILE_CSS` and `hostileSkins(base)`: T08b's attacks as data, one per
|
|
13
|
+
* escape route the designer's sketch left open, each
|
|
14
|
+
* with what must happen to it.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { dirname, join } from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { validateSkin } from './validate.js';
|
|
20
|
+
export { assertAdditive, diffContracts } from './diff.js';
|
|
21
|
+
/** The engine's and the browser's verdict on a package's data. */
|
|
22
|
+
export function checkSkin(contract, skinJson, files) {
|
|
23
|
+
const result = validateSkin(skinJson, contract, { files });
|
|
24
|
+
return { ok: result.ok, problems: result.problems };
|
|
25
|
+
}
|
|
26
|
+
/** T08b's CSS cases: each one tries a route out of its slot. */
|
|
27
|
+
export const HOSTILE_CSS = [
|
|
28
|
+
{ name: 'nesting reaches siblings', css: '.wrap{color:var(--fg); & ~ *{display:none}}', mustNotKeep: ['~', 'display'] },
|
|
29
|
+
{ name: ':has keylogging', css: '.wrap:has(~ main [value^="a"]){background-color:var(--bg);color:var(--fg)}', mustNotKeep: [':has', 'value'] },
|
|
30
|
+
{ name: 'sibling combinator', css: '.wrap ~ .x{display:none} .wrap + .x{display:none}', mustNotKeep: ['~', '+'] },
|
|
31
|
+
{ name: 'element selector', css: 'main{display:none} body .wrap{display:none} *{display:none}', mustNotKeep: ['main', 'body', '*'] },
|
|
32
|
+
{ name: 'attribute and id selectors', css: '[data-kit-band]{display:none} #main{display:none} .a[href]{color:var(--fg)}', mustNotKeep: ['data-kit-band', '#main', 'href'] },
|
|
33
|
+
{ name: ':root and :is/:not/:where', css: ':root{--fg:#000000} .a:is(.b){color:var(--fg)} .a:not(.b){color:var(--fg)} .a:where(.b){color:var(--fg)}', mustNotKeep: [':root', ':is', ':not', ':where', '#000000'] },
|
|
34
|
+
{ name: 'url and image-set', css: '.a{background-image:url(https://evil.example/x.gif)} .b{background-image:image-set("https://evil.example/y.gif" 1x)} .c{background:url(x)}', mustNotKeep: ['url', 'image-set', 'evil'] },
|
|
35
|
+
{ name: 'escaped url', css: '.a{background-image:\\75 rl(https://evil.example/x)}', mustNotKeep: ['evil', 'background-image'] },
|
|
36
|
+
{ name: '@import, @font-face, @keyframes, @layer', css: '@import url(https://evil.example/a.css); @font-face{font-family:x;src:url(https://evil.example/f.woff2)} @keyframes k{from{opacity:0}} @layer app{.a{color:var(--fg)}}', mustNotKeep: ['evil', 'font-face', 'keyframes', 'opacity'] },
|
|
37
|
+
{ name: 'fixed overlay', css: '.a{position:fixed;inset:0;z-index:999} .b{position:/**/fixed} .c{posit\\69 on:fixed}', mustNotKeep: ['fixed', '999'] },
|
|
38
|
+
{ name: 'huge z-index and outline cover', css: '.a{z-index:50} .b{box-shadow:0 0 0 100vmax var(--bg)} .c{outline:100vmax solid var(--bg)}', mustNotKeep: ['50', '100vmax'] },
|
|
39
|
+
{ name: 'pseudo-element text', css: '.a::before{content:"Pay by bank transfer to DE00 0000"} .b{content:""}', mustNotKeep: ['Pay by bank'] },
|
|
40
|
+
{ name: 'literal colours', css: '.a{color:#ffffff} .b{color:red} .c{color:rgb(0 0 0)} .d{color:color-mix(in srgb, red, blue)} .e{color:lab(50% 0 0)} .f{color:light-dark(white, black)} .g{color:Canvas}', mustNotKeep: ['#ffffff', 'red', 'rgb', 'color-mix', 'lab(', 'light-dark', 'Canvas'] },
|
|
41
|
+
{ name: 'custom properties', css: '.a{--fg-muted:var(--surface);color:var(--fg)} .b{color:var(--fg, #ff0000)} .c{color:var(--app-secret)}', mustNotKeep: ['--fg-muted:', '#ff0000', '--app-secret'] },
|
|
42
|
+
{ name: 'parser desync with braces in strings and comments', css: '.a{content:"}";} .b /* { */ {color:var(--fg)} main{display:none}', mustNotKeep: ['main'] },
|
|
43
|
+
{ name: 'focus ring removed', css: '.a:focus-visible{outline:none !important}', mustNotKeep: ['!important'] },
|
|
44
|
+
{ name: 'physical sides', css: '.a{margin-left:10px;padding-right:4px;left:0;float:left;text-align:left}', mustNotKeep: ['margin-left', 'padding-right', 'float', 'text-align'] },
|
|
45
|
+
{ name: 'hidden hosts through properties a skin may not set', css: '.a{opacity:0} .b{filter:opacity(0)} .c{clip-path:inset(50%)} .d{visibility:hidden} .e{pointer-events:none} .f{mask:none}', mustNotKeep: ['opacity', 'filter', 'clip-path', 'visibility', 'pointer-events', 'mask'] },
|
|
46
|
+
{ name: 'a ground without its text colour', css: '.a{background-color:var(--accent);color:var(--fg-muted)}', mustNotKeep: ['--accent)'] },
|
|
47
|
+
{ name: 'a hover movement under reduced motion', css: '.a:hover{transform:scale(1.2)}', mustNotKeep: ['scale(1.2)'] },
|
|
48
|
+
{ name: 'media and container queries outside the list', css: '@media print{.a{display:none}} @media (hover:hover){.a{display:none}} @container other (max-width: 10px){.a{display:none}}', mustNotKeep: ['display'] },
|
|
49
|
+
{ name: 'nth-child of a selector', css: '.a:nth-child(2 of [value]){color:var(--fg)}', mustNotKeep: ['value'] },
|
|
50
|
+
];
|
|
51
|
+
/** The path of the built browser module, beside this file. */
|
|
52
|
+
function distDir() {
|
|
53
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Filter CSS in a real browser and hand back what was kept and dropped, per
|
|
57
|
+
* slot. Needs `@playwright/test` (or `playwright`) and the browser installed.
|
|
58
|
+
*/
|
|
59
|
+
export async function filterInBrowser(slots, context, browserName = 'chromium') {
|
|
60
|
+
const playwright = (await import('@playwright/test').catch(() => import('playwright')));
|
|
61
|
+
const browser = await playwright[browserName].launch();
|
|
62
|
+
try {
|
|
63
|
+
const page = await browser.newPage();
|
|
64
|
+
const root = distDir();
|
|
65
|
+
await page.route('http://kit.test/**', async (route) => {
|
|
66
|
+
const path = new URL(route.request().url()).pathname;
|
|
67
|
+
if (path === '/')
|
|
68
|
+
return route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>kit</title>' });
|
|
69
|
+
const file = join(root, path.replace(/^\//, ''));
|
|
70
|
+
if (!file.startsWith(root))
|
|
71
|
+
return route.abort();
|
|
72
|
+
try {
|
|
73
|
+
return route.fulfill({ contentType: 'text/javascript', body: readFileSync(file, 'utf8') });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return route.fulfill({ status: 404, body: '' });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
await page.goto('http://kit.test/');
|
|
80
|
+
return await page.evaluate(async ({ slots: input, ctx }) => {
|
|
81
|
+
const css = (await import('/css.js'));
|
|
82
|
+
const kept = {};
|
|
83
|
+
const dropped = [];
|
|
84
|
+
for (const [slot, text] of Object.entries(input)) {
|
|
85
|
+
const result = css.filterSlotCss(slot, text, ctx);
|
|
86
|
+
kept[slot] = result.rules;
|
|
87
|
+
dropped.push(...result.dropped);
|
|
88
|
+
}
|
|
89
|
+
const built = css.buildSheet(Object.values(kept).flat());
|
|
90
|
+
dropped.push(...built.dropped);
|
|
91
|
+
const sheetText = Array.from(built.sheet.cssRules).map((r) => r.cssText).join('\n');
|
|
92
|
+
return { kept, dropped, sheetText };
|
|
93
|
+
}, { slots, ctx: { container: context.container, appColors: [...(context.appColors ?? [])] } });
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
await browser.close();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** A package's CSS, read as a shopper's browser reads it: what each slot keeps, and every drop with why. */
|
|
100
|
+
export async function checkSkinCss(contract, skinJson, readFile, browserName = 'chromium') {
|
|
101
|
+
const slots = {};
|
|
102
|
+
for (const [slot, path] of Object.entries(skinJson.styles ?? {}))
|
|
103
|
+
slots[slot] = readFile(path);
|
|
104
|
+
const { dropped, sheetText } = await filterInBrowser(slots, { container: contract.container, appColors: Object.keys(contract.derived ?? {}) }, browserName);
|
|
105
|
+
return { dropped, sheetText };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=testing.js.map
|