@colixsystems/widget-sdk 0.324.0 → 0.326.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/contract.cjs +3 -1
- package/dist/contract.js +3 -1
- package/dist/host.d.ts +10 -0
- package/dist/host.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/linter.cjs +50 -5
- package/dist/linter.js +50 -5
- package/dist/property-schema.js +3 -0
- package/dist/widget-font-families.cjs +47 -0
- package/dist/widget-font-families.js +40 -0
- package/package.json +1 -1
- package/src/contract.js +3 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.326.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
95
95
|
|
|
96
96
|
### What's new in 0.324.0 (contract 1.264.0)
|
|
97
97
|
|
|
@@ -2612,7 +2612,7 @@ Additive — one new hook, one new optional context-slice member; no existing ex
|
|
|
2612
2612
|
|
|
2613
2613
|
**Two linter rules make the styling contract checkable, and `lintStyleWiring` joins the linter export (sc-6455).** Every visual value a widget writes reaches the app's owner through one of exactly two channels — a **theme token** (`useTheme()`), which is the app-wide default and follows a look change, or a **`styleSchema` field** read off `props.style`, which the Studio offers per instance in the widget editor *and* app-wide under **Design → Widget appearance**. A literal reaches neither: it outranks the theme permanently and no control on either surface can move it, so the owner finds a corner of their app they cannot restyle. Until now that rule was documentation only.
|
|
2614
2614
|
|
|
2615
|
-
- **`no-hardcoded-design`** flags a colour literal (`#rgb` / `#rrggbb` / `#rrggbbaa`, `rgb()`, `rgba()`, `hsl()`, `hsla()`), a `fontFamily` string literal, a numeric `fontSize`, or (since 0.165.0) a literal non-zero corner radius (`borderRadius: 12`, any per-corner spelling). A `fontSize` resolved off a theme token or a style field (`style.valueSize ?? 18`) is *not* flagged — a literal `default` beside a declared field is the contract working — and neither is a computed radius (`size / 2`) or `0`. Raw `padding` / `margin` numbers are deliberately out of scope: measured layout legitimately carries them, so a spacing rule would be noise.
|
|
2615
|
+
- **`no-hardcoded-design`** flags a colour literal (`#rgb` / `#rrggbb` / `#rrggbbaa`, `rgb()`, `rgba()`, `hsl()`, `hsla()`), a `fontFamily` string literal or (since 0.326.0) a family named as the fallback of a font read (`style.titleFont || "Lora"`), a numeric `fontSize`, or (since 0.165.0) a literal non-zero corner radius (`borderRadius: 12`, any per-corner spelling). A `fontSize` resolved off a theme token or a style field (`style.valueSize ?? 18`) is *not* flagged — a literal `default` beside a declared field is the contract working — and neither is a computed radius (`size / 2`) or `0`. Raw `padding` / `margin` numbers are deliberately out of scope: measured layout legitimately carries them, so a spacing rule would be noise.
|
|
2616
2616
|
- **`style-field-unread`** flags a `styleSchema` field whose name appears nowhere in the widget's source — a dead control the author moves to no effect. It runs over the WHOLE bundle, not per file, so a split-impl widget that reads a field in `widget.web.jsx` and not in `widget.native.jsx` is correctly counted as wired.
|
|
2617
2617
|
|
|
2618
2618
|
A value that genuinely cannot be a token — a categorical series palette, a video letterbox, a scannable QR plate — is licensed with a preceding comment. **The reason is mandatory**; a bare marker licenses nothing. A marker on its own line covers the whole statement below it (bracket-balanced, so one marker covers a multi-line palette); a trailing marker covers only its own line.
|
|
@@ -4075,7 +4075,7 @@ const wiring = lintStyleWiring(manifest, { "widget.jsx": source });
|
|
|
4075
4075
|
const editability = lintEditability(manifest, { "widget.jsx": source });
|
|
4076
4076
|
```
|
|
4077
4077
|
|
|
4078
|
-
Two rules keep a widget's look reachable from the Studio. `no-hardcoded-design` flags a colour literal, a `fontFamily` string, or a numeric `fontSize` — values that outrank the theme permanently and that no control can move. `style-field-unread` flags a `styleSchema` field the source never reads, which renders a control that does nothing. Both are warnings for a human author and blocking for the AI widget agent. License a genuinely un-tokenizable value with a preceding `// appstudio-design-ok: <reason>` (the reason is required); see *What's new in 0.110.0*.
|
|
4078
|
+
Two rules keep a widget's look reachable from the Studio. `no-hardcoded-design` flags a colour literal, a `fontFamily` string, or a numeric `fontSize` — values that outrank the theme permanently and that no control can move. `style-field-unread` flags a `styleSchema` field the source never reads, which renders a control that does nothing. Both are warnings for a human author and blocking for the AI widget agent. License a genuinely un-tokenizable value with a preceding `// appstudio-design-ok: <reason>` (the reason is required); see *What's new in 0.110.0*. A font family is never licensed (since 0.326.0): one written in the source never loads on either host, so use the workspace's fonts or a `{ type: "font" }` style field read with the theme font as its fallback.
|
|
4079
4079
|
|
|
4080
4080
|
Three more rules keep a widget EDITABLE once it ships, via the bundle-level `lintEditability(manifest, files)`. `style-group-missing` flags a `styleSchema` field with no `ui.group` — or one under a catch-all name — so a long Style section reads as labelled per-element fieldsets. `style-elements-uncovered` flags a multi-element widget whose Style section still only restyles the widget as a whole. `text-literal-unexposed` flags copy pinned in a `<Text>` — wording no control can change and no locale can translate. All three are warnings here and blocking for the AI widget agent; see *What's new in 0.140.0*.
|
|
4081
4081
|
|
package/dist/contract.cjs
CHANGED
|
@@ -7030,7 +7030,9 @@ const CONTRACT = deepFreeze({
|
|
|
7030
7030
|
// 1.264.0: additive (sc-17317) — `<MarkdownInput editorRef>` is filled
|
|
7031
7031
|
// with `{ insertText(text) }`, inserting plain text at the caret, and
|
|
7032
7032
|
// `editable={false}` locks the field and its toolbar.
|
|
7033
|
-
|
|
7033
|
+
// 1.265.0: `font` is a field type, and a font named in the source is
|
|
7034
|
+
// `no-hardcoded-design` with no licence (sc-17364).
|
|
7035
|
+
version: "1.265.0",
|
|
7034
7036
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7035
7037
|
hooks: HOOKS,
|
|
7036
7038
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -7025,7 +7025,9 @@ const CONTRACT = deepFreeze({
|
|
|
7025
7025
|
// 1.264.0: additive (sc-17317) — `<MarkdownInput editorRef>` is filled
|
|
7026
7026
|
// with `{ insertText(text) }`, inserting plain text at the caret, and
|
|
7027
7027
|
// `editable={false}` locks the field and its toolbar.
|
|
7028
|
-
|
|
7028
|
+
// 1.265.0: `font` is a field type, and a font named in the source is
|
|
7029
|
+
// `no-hardcoded-design` with no licence (sc-17364).
|
|
7030
|
+
version: "1.265.0",
|
|
7029
7031
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7030
7032
|
hooks: HOOKS,
|
|
7031
7033
|
primitives: PRIMITIVES,
|
package/dist/host.d.ts
CHANGED
|
@@ -136,6 +136,16 @@ export function applyThemeComponentStyle<T = Record<string, unknown>>(
|
|
|
136
136
|
styleSchema?: Record<string, unknown> | null,
|
|
137
137
|
): T;
|
|
138
138
|
|
|
139
|
+
/**
|
|
140
|
+
* sc-17349: every family a manifest `font` field resolves to (the instance
|
|
141
|
+
* value, else the field default, at any depth), for each host to load.
|
|
142
|
+
*/
|
|
143
|
+
export function widgetFontFamilies(input?: {
|
|
144
|
+
propertySchema?: Record<string, unknown> | null;
|
|
145
|
+
styleSchema?: Record<string, unknown> | null;
|
|
146
|
+
props?: Record<string, unknown> | null;
|
|
147
|
+
}): string[];
|
|
148
|
+
|
|
139
149
|
/** One text role's validated fields (REQ-THEME-ROLE). */
|
|
140
150
|
export type TypographyRole = Record<string, string | number>;
|
|
141
151
|
|
package/dist/host.js
CHANGED
|
@@ -159,6 +159,9 @@ export {
|
|
|
159
159
|
resolveLoginTextVisibility,
|
|
160
160
|
} from "./theme-background.js";
|
|
161
161
|
|
|
162
|
+
// sc-17349: the families a widget's `font` fields name, which each host must load.
|
|
163
|
+
export { widgetFontFamilies } from "./widget-font-families.js";
|
|
164
|
+
|
|
162
165
|
// REQ-THEME-APPEARANCE (sc-12335): an app's light and dark palettes. Each host
|
|
163
166
|
// resolves the mode it shows and the theme it renders through these, so a dark
|
|
164
167
|
// palette and the choice of palette mean the same thing on web and native.
|
package/dist/index.d.ts
CHANGED
package/dist/linter.cjs
CHANGED
|
@@ -3073,7 +3073,17 @@ function narrowManifestForFile(manifest, filename) {
|
|
|
3073
3073
|
const _DESIGN_HEX_RE =
|
|
3074
3074
|
/#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![0-9a-fA-F])/;
|
|
3075
3075
|
const _DESIGN_FUNC_COLOR_RE = /\b(?:rgba?|hsla?)\s*\(/;
|
|
3076
|
-
|
|
3076
|
+
// The quoted value after `fontFamily:`, or (sc-17364) after `||` / `??` on a
|
|
3077
|
+
// font read such as `style.titleFont`, `style["titleFont"]?.trim()`, across
|
|
3078
|
+
// lines. fontWeight / fontSize never match.
|
|
3079
|
+
const _DESIGN_FONT_LITERAL_RE =
|
|
3080
|
+
/(?:\bfontFamily\s*:|[Ff]ont(?:Family)?(?:\?\.\w+\(\)|["'\])])*\s*(?:\|\||\?\?))\s*(["'`])([^"'`\n]*)/g;
|
|
3081
|
+
// Faces every host already has; naming one loads nothing.
|
|
3082
|
+
const _DESIGN_FONT_GENERIC = new Set([
|
|
3083
|
+
"serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "math",
|
|
3084
|
+
"emoji", "fangsong", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded",
|
|
3085
|
+
"-apple-system", "inherit", "initial", "unset", "revert", "revert-layer",
|
|
3086
|
+
]);
|
|
3077
3087
|
const _DESIGN_FONT_SIZE_RE = /\bfontSize\s*:\s*-?\d/;
|
|
3078
3088
|
const _DESIGN_RADIUS_RE =
|
|
3079
3089
|
/\bborder(?:Top|Bottom|Start|End)?(?:Left|Right|Start|End)?Radius\s*:\s*(?:0*[1-9]\d*(?:\.\d+)?|0\.\d*[1-9]\d*)\s*(?=[,}]|$)/;
|
|
@@ -3123,20 +3133,55 @@ function _designExemptLines(source) {
|
|
|
3123
3133
|
return exempt;
|
|
3124
3134
|
}
|
|
3125
3135
|
|
|
3136
|
+
const _DESIGN_FONT_LABEL =
|
|
3137
|
+
"a font-family name in the source never loads: the web Player and the " +
|
|
3138
|
+
"exported app load only the workspace's fonts and the families a " +
|
|
3139
|
+
"`type: \"font\"` field names, so this text renders a fallback face and " +
|
|
3140
|
+
"no theme change reaches it. Use theme.typography.fontFamily or " +
|
|
3141
|
+
"theme.typography.headingFontFamily. To override the workspace font, " +
|
|
3142
|
+
"declare a styleSchema field { type: \"font\" } and read " +
|
|
3143
|
+
"props.style.<field> || theme.typography.headingFontFamily; its default " +
|
|
3144
|
+
"may name the family. appstudio-design-ok does not license a font.";
|
|
3145
|
+
|
|
3146
|
+
/** Lines (1-based) where the source names a font family to load. */
|
|
3147
|
+
function _namedFontLines(code) {
|
|
3148
|
+
const lines = new Set();
|
|
3149
|
+
for (const m of code.matchAll(_DESIGN_FONT_LITERAL_RE)) {
|
|
3150
|
+
const value = m[2].trim();
|
|
3151
|
+
if (value.startsWith("${")) continue;
|
|
3152
|
+
const first = value.split(",")[0].trim().replace(/^["']|["']$/g, "").toLowerCase();
|
|
3153
|
+
if (!/[a-z]/.test(first) || _DESIGN_FONT_GENERIC.has(first)) continue;
|
|
3154
|
+
const at = m.index + m[0].length - m[2].length;
|
|
3155
|
+
lines.add(code.slice(0, at).split("\n").length);
|
|
3156
|
+
}
|
|
3157
|
+
return lines;
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3126
3160
|
function _hardcodedDesignRules(source) {
|
|
3127
3161
|
// Comments blanked, string CONTENT kept — a colour literal IS a string.
|
|
3128
|
-
const
|
|
3162
|
+
const stripped = _stripNonCode(source, { keepStrings: true }).replace(/\r\n/g, "\n");
|
|
3163
|
+
const code = stripped.split("\n");
|
|
3129
3164
|
const sourceLines = source.split(/\r?\n/);
|
|
3130
3165
|
const exempt = _designExemptLines(source);
|
|
3166
|
+
const fontLines = _namedFontLines(stripped);
|
|
3131
3167
|
const findings = [];
|
|
3132
3168
|
for (let i = 0; i < code.length; i += 1) {
|
|
3133
|
-
if (exempt.has(i + 1)) continue;
|
|
3134
3169
|
const line = code[i];
|
|
3170
|
+
// sc-17364: a font named in the source never loads on either host, so
|
|
3171
|
+
// no marker can license it.
|
|
3172
|
+
if (fontLines.has(i + 1)) {
|
|
3173
|
+
findings.push({
|
|
3174
|
+
rule: "no-hardcoded-design",
|
|
3175
|
+
severity: "warning",
|
|
3176
|
+
label: _DESIGN_FONT_LABEL,
|
|
3177
|
+
line: i + 1,
|
|
3178
|
+
snippet: (sourceLines[i] || "").trim().slice(0, 200),
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
if (exempt.has(i + 1)) continue;
|
|
3135
3182
|
let what = null;
|
|
3136
3183
|
if (_DESIGN_HEX_RE.test(line) || _DESIGN_FUNC_COLOR_RE.test(line)) {
|
|
3137
3184
|
what = "a colour literal";
|
|
3138
|
-
} else if (_DESIGN_FONT_FAMILY_RE.test(line)) {
|
|
3139
|
-
what = "a font-family name";
|
|
3140
3185
|
} else if (
|
|
3141
3186
|
_DESIGN_FONT_SIZE_RE.test(line) &&
|
|
3142
3187
|
!_DESIGN_TOKEN_REF_RE.test(line)
|
package/dist/linter.js
CHANGED
|
@@ -3068,7 +3068,17 @@ export function narrowManifestForFile(manifest, filename) {
|
|
|
3068
3068
|
const _DESIGN_HEX_RE =
|
|
3069
3069
|
/#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![0-9a-fA-F])/;
|
|
3070
3070
|
const _DESIGN_FUNC_COLOR_RE = /\b(?:rgba?|hsla?)\s*\(/;
|
|
3071
|
-
|
|
3071
|
+
// The quoted value after `fontFamily:`, or (sc-17364) after `||` / `??` on a
|
|
3072
|
+
// font read such as `style.titleFont`, `style["titleFont"]?.trim()`, across
|
|
3073
|
+
// lines. fontWeight / fontSize never match.
|
|
3074
|
+
const _DESIGN_FONT_LITERAL_RE =
|
|
3075
|
+
/(?:\bfontFamily\s*:|[Ff]ont(?:Family)?(?:\?\.\w+\(\)|["'\])])*\s*(?:\|\||\?\?))\s*(["'`])([^"'`\n]*)/g;
|
|
3076
|
+
// Faces every host already has; naming one loads nothing.
|
|
3077
|
+
const _DESIGN_FONT_GENERIC = new Set([
|
|
3078
|
+
"serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "math",
|
|
3079
|
+
"emoji", "fangsong", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded",
|
|
3080
|
+
"-apple-system", "inherit", "initial", "unset", "revert", "revert-layer",
|
|
3081
|
+
]);
|
|
3072
3082
|
const _DESIGN_FONT_SIZE_RE = /\bfontSize\s*:\s*-?\d/;
|
|
3073
3083
|
const _DESIGN_RADIUS_RE =
|
|
3074
3084
|
/\bborder(?:Top|Bottom|Start|End)?(?:Left|Right|Start|End)?Radius\s*:\s*(?:0*[1-9]\d*(?:\.\d+)?|0\.\d*[1-9]\d*)\s*(?=[,}]|$)/;
|
|
@@ -3118,20 +3128,55 @@ function _designExemptLines(source) {
|
|
|
3118
3128
|
return exempt;
|
|
3119
3129
|
}
|
|
3120
3130
|
|
|
3131
|
+
const _DESIGN_FONT_LABEL =
|
|
3132
|
+
"a font-family name in the source never loads: the web Player and the " +
|
|
3133
|
+
"exported app load only the workspace's fonts and the families a " +
|
|
3134
|
+
"`type: \"font\"` field names, so this text renders a fallback face and " +
|
|
3135
|
+
"no theme change reaches it. Use theme.typography.fontFamily or " +
|
|
3136
|
+
"theme.typography.headingFontFamily. To override the workspace font, " +
|
|
3137
|
+
"declare a styleSchema field { type: \"font\" } and read " +
|
|
3138
|
+
"props.style.<field> || theme.typography.headingFontFamily; its default " +
|
|
3139
|
+
"may name the family. appstudio-design-ok does not license a font.";
|
|
3140
|
+
|
|
3141
|
+
/** Lines (1-based) where the source names a font family to load. */
|
|
3142
|
+
function _namedFontLines(code) {
|
|
3143
|
+
const lines = new Set();
|
|
3144
|
+
for (const m of code.matchAll(_DESIGN_FONT_LITERAL_RE)) {
|
|
3145
|
+
const value = m[2].trim();
|
|
3146
|
+
if (value.startsWith("${")) continue;
|
|
3147
|
+
const first = value.split(",")[0].trim().replace(/^["']|["']$/g, "").toLowerCase();
|
|
3148
|
+
if (!/[a-z]/.test(first) || _DESIGN_FONT_GENERIC.has(first)) continue;
|
|
3149
|
+
const at = m.index + m[0].length - m[2].length;
|
|
3150
|
+
lines.add(code.slice(0, at).split("\n").length);
|
|
3151
|
+
}
|
|
3152
|
+
return lines;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3121
3155
|
function _hardcodedDesignRules(source) {
|
|
3122
3156
|
// Comments blanked, string CONTENT kept — a colour literal IS a string.
|
|
3123
|
-
const
|
|
3157
|
+
const stripped = _stripNonCode(source, { keepStrings: true }).replace(/\r\n/g, "\n");
|
|
3158
|
+
const code = stripped.split("\n");
|
|
3124
3159
|
const sourceLines = source.split(/\r?\n/);
|
|
3125
3160
|
const exempt = _designExemptLines(source);
|
|
3161
|
+
const fontLines = _namedFontLines(stripped);
|
|
3126
3162
|
const findings = [];
|
|
3127
3163
|
for (let i = 0; i < code.length; i += 1) {
|
|
3128
|
-
if (exempt.has(i + 1)) continue;
|
|
3129
3164
|
const line = code[i];
|
|
3165
|
+
// sc-17364: a font named in the source never loads on either host, so
|
|
3166
|
+
// no marker can license it.
|
|
3167
|
+
if (fontLines.has(i + 1)) {
|
|
3168
|
+
findings.push({
|
|
3169
|
+
rule: "no-hardcoded-design",
|
|
3170
|
+
severity: "warning",
|
|
3171
|
+
label: _DESIGN_FONT_LABEL,
|
|
3172
|
+
line: i + 1,
|
|
3173
|
+
snippet: (sourceLines[i] || "").trim().slice(0, 200),
|
|
3174
|
+
});
|
|
3175
|
+
}
|
|
3176
|
+
if (exempt.has(i + 1)) continue;
|
|
3130
3177
|
let what = null;
|
|
3131
3178
|
if (_DESIGN_HEX_RE.test(line) || _DESIGN_FUNC_COLOR_RE.test(line)) {
|
|
3132
3179
|
what = "a colour literal";
|
|
3133
|
-
} else if (_DESIGN_FONT_FAMILY_RE.test(line)) {
|
|
3134
|
-
what = "a font-family name";
|
|
3135
3180
|
} else if (
|
|
3136
3181
|
_DESIGN_FONT_SIZE_RE.test(line) &&
|
|
3137
3182
|
!_DESIGN_TOKEN_REF_RE.test(line)
|
package/dist/property-schema.js
CHANGED
|
@@ -8,6 +8,8 @@ import { isPlainObject } from "./plain-object.js";
|
|
|
8
8
|
const VALID_TYPES = new Set([
|
|
9
9
|
"string", "number", "boolean",
|
|
10
10
|
"color", "icon", "image",
|
|
11
|
+
// sc-17364: a font family picker; both hosts load the family it names.
|
|
12
|
+
"font",
|
|
11
13
|
"select", "multiselect",
|
|
12
14
|
"tableRef", "columnRef", "recordBinding",
|
|
13
15
|
// REQ-WDG-VALUEREF: `valueRef` is a composite "single value from the
|
|
@@ -157,6 +159,7 @@ function coerceLeaf(def, value, path, errors) {
|
|
|
157
159
|
switch (t) {
|
|
158
160
|
case "string":
|
|
159
161
|
case "color":
|
|
162
|
+
case "font":
|
|
160
163
|
case "icon":
|
|
161
164
|
case "image":
|
|
162
165
|
case "tableRef":
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// GENERATED from widget-font-families.js by scripts/generate-cjs.js — DO NOT EDIT.
|
|
2
|
+
// Change widget-font-families.js, then run `npm run generate:cjs` in packages/widget-sdk.
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// The font families a widget instance names through its manifest's `font`
|
|
6
|
+
// fields. Each host must fetch (web) or embed (native) these faces, or a
|
|
7
|
+
// picked font renders as the platform's fallback face. One reading, shared by
|
|
8
|
+
// the web host and the compiler, so both hosts load the same set (CLAUDE.md §8).
|
|
9
|
+
|
|
10
|
+
const isBlank = (value) => value === undefined || value === null || (typeof value === "string" && !value.trim());
|
|
11
|
+
|
|
12
|
+
// The Studio offers a font picker at any depth: inside an object's
|
|
13
|
+
// `properties` and each element of an array's `items`.
|
|
14
|
+
function collectField(field, value, into) {
|
|
15
|
+
if (!field || typeof field !== "object") return;
|
|
16
|
+
const resolved = isBlank(value) ? field.default : value;
|
|
17
|
+
if (field.type === "font") {
|
|
18
|
+
const family = typeof resolved === "string" ? resolved.trim() : "";
|
|
19
|
+
if (family && !into.includes(family)) into.push(family);
|
|
20
|
+
} else if (field.type === "object") {
|
|
21
|
+
collectFields(field.properties, resolved, into);
|
|
22
|
+
} else if (field.type === "array" && Array.isArray(resolved)) {
|
|
23
|
+
for (const item of resolved) collectField(field.items, item, into);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function collectFields(schema, values, into) {
|
|
28
|
+
if (!schema || typeof schema !== "object") return;
|
|
29
|
+
const record = values && typeof values === "object" ? values : {};
|
|
30
|
+
for (const [key, field] of Object.entries(schema)) collectField(field, record[key], into);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Every family a `type: "font"` field resolves to: the instance's value, else
|
|
35
|
+
* the field's `default`, at any depth. Property fields read `props`, style
|
|
36
|
+
* fields read `props.style`. Unfiltered: each host keeps its catalog allowlist.
|
|
37
|
+
*/
|
|
38
|
+
function widgetFontFamilies({ propertySchema, styleSchema, props } = {}) {
|
|
39
|
+
const families = [];
|
|
40
|
+
const instance = props && typeof props === "object" ? props : {};
|
|
41
|
+
collectFields(propertySchema, instance, families);
|
|
42
|
+
collectFields(styleSchema, instance.style, families);
|
|
43
|
+
return families;
|
|
44
|
+
}
|
|
45
|
+
module.exports = {
|
|
46
|
+
widgetFontFamilies,
|
|
47
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The font families a widget instance names through its manifest's `font`
|
|
2
|
+
// fields. Each host must fetch (web) or embed (native) these faces, or a
|
|
3
|
+
// picked font renders as the platform's fallback face. One reading, shared by
|
|
4
|
+
// the web host and the compiler, so both hosts load the same set (CLAUDE.md §8).
|
|
5
|
+
|
|
6
|
+
const isBlank = (value) => value === undefined || value === null || (typeof value === "string" && !value.trim());
|
|
7
|
+
|
|
8
|
+
// The Studio offers a font picker at any depth: inside an object's
|
|
9
|
+
// `properties` and each element of an array's `items`.
|
|
10
|
+
function collectField(field, value, into) {
|
|
11
|
+
if (!field || typeof field !== "object") return;
|
|
12
|
+
const resolved = isBlank(value) ? field.default : value;
|
|
13
|
+
if (field.type === "font") {
|
|
14
|
+
const family = typeof resolved === "string" ? resolved.trim() : "";
|
|
15
|
+
if (family && !into.includes(family)) into.push(family);
|
|
16
|
+
} else if (field.type === "object") {
|
|
17
|
+
collectFields(field.properties, resolved, into);
|
|
18
|
+
} else if (field.type === "array" && Array.isArray(resolved)) {
|
|
19
|
+
for (const item of resolved) collectField(field.items, item, into);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function collectFields(schema, values, into) {
|
|
24
|
+
if (!schema || typeof schema !== "object") return;
|
|
25
|
+
const record = values && typeof values === "object" ? values : {};
|
|
26
|
+
for (const [key, field] of Object.entries(schema)) collectField(field, record[key], into);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Every family a `type: "font"` field resolves to: the instance's value, else
|
|
31
|
+
* the field's `default`, at any depth. Property fields read `props`, style
|
|
32
|
+
* fields read `props.style`. Unfiltered: each host keeps its catalog allowlist.
|
|
33
|
+
*/
|
|
34
|
+
export function widgetFontFamilies({ propertySchema, styleSchema, props } = {}) {
|
|
35
|
+
const families = [];
|
|
36
|
+
const instance = props && typeof props === "object" ? props : {};
|
|
37
|
+
collectFields(propertySchema, instance, families);
|
|
38
|
+
collectFields(styleSchema, instance.style, families);
|
|
39
|
+
return families;
|
|
40
|
+
}
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -7025,7 +7025,9 @@ const CONTRACT = deepFreeze({
|
|
|
7025
7025
|
// 1.264.0: additive (sc-17317) — `<MarkdownInput editorRef>` is filled
|
|
7026
7026
|
// with `{ insertText(text) }`, inserting plain text at the caret, and
|
|
7027
7027
|
// `editable={false}` locks the field and its toolbar.
|
|
7028
|
-
|
|
7028
|
+
// 1.265.0: `font` is a field type, and a font named in the source is
|
|
7029
|
+
// `no-hardcoded-design` with no licence (sc-17364).
|
|
7030
|
+
version: "1.265.0",
|
|
7029
7031
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7030
7032
|
hooks: HOOKS,
|
|
7031
7033
|
primitives: PRIMITIVES,
|