@colixsystems/widget-sdk 0.324.0 → 0.326.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/README.md CHANGED
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.324.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**.
94
+ `v0.326.1` — 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
+
96
+ ### What's new in 0.326.1 (contract 1.265.1)
97
+
98
+ **`group-ids-as-text` passes a setting about a group.** A `string` setting whose name ends in `name`, `prefix`, `description`, `mode`, `size`, `count`, `color` / `colour`, `icon` or `type`, such as `groupName` or `groupColor`, holds no group ids, so the linter no longer refuses it.
95
99
 
96
100
  ### What's new in 0.324.0 (contract 1.264.0)
97
101
 
@@ -2612,7 +2616,7 @@ Additive — one new hook, one new optional context-slice member; no existing ex
2612
2616
 
2613
2617
  **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
2618
 
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.
2619
+ - **`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
2620
  - **`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
2621
 
2618
2622
  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 +4079,7 @@ const wiring = lintStyleWiring(manifest, { "widget.jsx": source });
4075
4079
  const editability = lintEditability(manifest, { "widget.jsx": source });
4076
4080
  ```
4077
4081
 
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*.
4082
+ 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
4083
 
4080
4084
  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
4085
 
package/dist/contract.cjs CHANGED
@@ -7030,7 +7030,11 @@ 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
- version: "1.264.0",
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
+ // 1.265.1: narrower lint — `group-ids-as-text` passes a group's name,
7036
+ // prefix, description, mode, size, count, colour, icon or type.
7037
+ version: "1.265.1",
7034
7038
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7035
7039
  hooks: HOOKS,
7036
7040
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -7025,7 +7025,11 @@ 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
- version: "1.264.0",
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
+ // 1.265.1: narrower lint — `group-ids-as-text` passes a group's name,
7031
+ // prefix, description, mode, size, count, colour, icon or type.
7032
+ version: "1.265.1",
7029
7033
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7030
7034
  hooks: HOOKS,
7031
7035
  primitives: PRIMITIVES,
@@ -0,0 +1,49 @@
1
+ // GENERATED from group-id-text.js by scripts/generate-cjs.js — DO NOT EDIT.
2
+ // Change group-id-text.js, then run `npm run generate:cjs` in packages/widget-sdk.
3
+ "use strict";
4
+
5
+ // Typed group ids hide the groups and break on Copy Workspace. One matcher
6
+ // for widget and Action settings; each caller supplies its own usage signal.
7
+ const GROUP_WORD = /group|grupp/i;
8
+ const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
9
+ // Settings about a group, not naming one: its display text, name, look or count.
10
+ const NOT_A_GROUP_REF_NAME =
11
+ /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text|name|prefix|description|mode|size|count|colou?r|icon|type)$/i;
12
+
13
+ function _holdsGroupIds(name, def) {
14
+ if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
15
+ const wording = `${def.label ?? ""} ${def.description ?? ""}`;
16
+ return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
17
+ }
18
+
19
+ function _groupIdTextFields(schema, prefix, out) {
20
+ if (!schema || typeof schema !== "object") return out;
21
+ for (const [name, def] of Object.entries(schema)) {
22
+ if (!def || typeof def !== "object") continue;
23
+ const path = prefix + name;
24
+ const items = def.items && typeof def.items === "object" ? def.items : null;
25
+ const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
26
+ if (isText && _holdsGroupIds(name, def)) out.push(path);
27
+ if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
28
+ if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
29
+ }
30
+ return out;
31
+ }
32
+
33
+ /** A finding per text setting, at any depth, that holds user group ids. */
34
+ function groupIdTextFindings(propertySchema) {
35
+ return _groupIdTextFields(propertySchema, "", []).map((path) => ({
36
+ rule: "group-ids-as-text",
37
+ severity: "error",
38
+ label:
39
+ `propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
40
+ "and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
41
+ "{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
42
+ "so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
43
+ line: 0,
44
+ snippet: "",
45
+ }));
46
+ }
47
+ module.exports = {
48
+ groupIdTextFindings,
49
+ };
@@ -0,0 +1,42 @@
1
+ // Typed group ids hide the groups and break on Copy Workspace. One matcher
2
+ // for widget and Action settings; each caller supplies its own usage signal.
3
+ const GROUP_WORD = /group|grupp/i;
4
+ const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
5
+ // Settings about a group, not naming one: its display text, name, look or count.
6
+ const NOT_A_GROUP_REF_NAME =
7
+ /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text|name|prefix|description|mode|size|count|colou?r|icon|type)$/i;
8
+
9
+ function _holdsGroupIds(name, def) {
10
+ if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
11
+ const wording = `${def.label ?? ""} ${def.description ?? ""}`;
12
+ return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
13
+ }
14
+
15
+ function _groupIdTextFields(schema, prefix, out) {
16
+ if (!schema || typeof schema !== "object") return out;
17
+ for (const [name, def] of Object.entries(schema)) {
18
+ if (!def || typeof def !== "object") continue;
19
+ const path = prefix + name;
20
+ const items = def.items && typeof def.items === "object" ? def.items : null;
21
+ const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
22
+ if (isText && _holdsGroupIds(name, def)) out.push(path);
23
+ if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
24
+ if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
25
+ }
26
+ return out;
27
+ }
28
+
29
+ /** A finding per text setting, at any depth, that holds user group ids. */
30
+ export function groupIdTextFindings(propertySchema) {
31
+ return _groupIdTextFields(propertySchema, "", []).map((path) => ({
32
+ rule: "group-ids-as-text",
33
+ severity: "error",
34
+ label:
35
+ `propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
36
+ "and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
37
+ "{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
38
+ "so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
39
+ line: 0,
40
+ snippet: "",
41
+ }));
42
+ }
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
@@ -22,6 +22,8 @@ export type WidgetPropertyType =
22
22
  | "number"
23
23
  | "boolean"
24
24
  | "color"
25
+ // A font family picker; both hosts load the family it names.
26
+ | "font"
25
27
  | "icon"
26
28
  | "image"
27
29
  | "select"
package/dist/linter.cjs CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  const { CONTRACT, normaliseActionTriggerTypes } = require("./contract.cjs");
6
6
  const { LUCIDE_ICON_NAMES, LUCIDE_VERSION } = require("./lucideIconNames.cjs");
7
+ const { groupIdTextFindings } = require("./group-id-text.cjs");
7
8
  const { stripNonCode: _stripNonCode } = require("./source-mask.cjs");
8
9
 
9
10
  // Static-analysis linter per docs/architecture/widget-marketplace.md §3.1.
@@ -1035,46 +1036,13 @@ function _manifestActionRules(manifest) {
1035
1036
  return findings;
1036
1037
  }
1037
1038
 
1038
- // Typed group ids hide the groups and break on Copy Workspace.
1039
+ // A widget's settings hold user groups only when its source reads them.
1039
1040
  const READS_USER_GROUPS = /\bgroupIds\b|\buseGroups\s*\(/;
1040
- const GROUP_WORD = /group|grupp/i;
1041
- const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
1042
- const NOT_A_GROUP_REF_NAME = /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text)$/i;
1043
-
1044
- function _holdsGroupIds(name, def) {
1045
- if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
1046
- const wording = `${def.label ?? ""} ${def.description ?? ""}`;
1047
- return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
1048
- }
1049
-
1050
- function _groupIdTextFields(schema, prefix, out) {
1051
- if (!schema || typeof schema !== "object") return out;
1052
- for (const [name, def] of Object.entries(schema)) {
1053
- if (!def || typeof def !== "object") continue;
1054
- const path = prefix + name;
1055
- const items = def.items && typeof def.items === "object" ? def.items : null;
1056
- const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
1057
- if (isText && _holdsGroupIds(name, def)) out.push(path);
1058
- if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
1059
- if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
1060
- }
1061
- return out;
1062
- }
1063
1041
 
1064
1042
  function _groupIdTextRules(source, manifest) {
1065
1043
  if (!manifest || typeof manifest !== "object") return [];
1066
1044
  if (!READS_USER_GROUPS.test(_stripNonCode(source))) return [];
1067
- return _groupIdTextFields(manifest.propertySchema, "", []).map((path) => ({
1068
- rule: "group-ids-as-text",
1069
- severity: "error",
1070
- label:
1071
- `propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
1072
- "and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
1073
- "{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
1074
- "so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
1075
- line: 0,
1076
- snippet: "",
1077
- }));
1045
+ return groupIdTextFindings(manifest.propertySchema);
1078
1046
  }
1079
1047
 
1080
1048
  // sc-1366 — invalid lucide icon import gate. lucide-react-native is a vetted
@@ -3073,7 +3041,17 @@ function narrowManifestForFile(manifest, filename) {
3073
3041
  const _DESIGN_HEX_RE =
3074
3042
  /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![0-9a-fA-F])/;
3075
3043
  const _DESIGN_FUNC_COLOR_RE = /\b(?:rgba?|hsla?)\s*\(/;
3076
- const _DESIGN_FONT_FAMILY_RE = /\bfontFamily\s*:\s*["'`]\s*\S/;
3044
+ // The quoted value after `fontFamily:`, or (sc-17364) after `||` / `??` on a
3045
+ // font read such as `style.titleFont`, `style["titleFont"]?.trim()`, across
3046
+ // lines. fontWeight / fontSize never match.
3047
+ const _DESIGN_FONT_LITERAL_RE =
3048
+ /(?:\bfontFamily\s*:|[Ff]ont(?:Family)?(?:\?\.\w+\(\)|["'\])])*\s*(?:\|\||\?\?))\s*(["'`])([^"'`\n]*)/g;
3049
+ // Faces every host already has; naming one loads nothing.
3050
+ const _DESIGN_FONT_GENERIC = new Set([
3051
+ "serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "math",
3052
+ "emoji", "fangsong", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded",
3053
+ "-apple-system", "inherit", "initial", "unset", "revert", "revert-layer",
3054
+ ]);
3077
3055
  const _DESIGN_FONT_SIZE_RE = /\bfontSize\s*:\s*-?\d/;
3078
3056
  const _DESIGN_RADIUS_RE =
3079
3057
  /\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 +3101,55 @@ function _designExemptLines(source) {
3123
3101
  return exempt;
3124
3102
  }
3125
3103
 
3104
+ const _DESIGN_FONT_LABEL =
3105
+ "a font-family name in the source never loads: the web Player and the " +
3106
+ "exported app load only the workspace's fonts and the families a " +
3107
+ "`type: \"font\"` field names, so this text renders a fallback face and " +
3108
+ "no theme change reaches it. Use theme.typography.fontFamily or " +
3109
+ "theme.typography.headingFontFamily. To override the workspace font, " +
3110
+ "declare a styleSchema field { type: \"font\" } and read " +
3111
+ "props.style.<field> || theme.typography.headingFontFamily; its default " +
3112
+ "may name the family. appstudio-design-ok does not license a font.";
3113
+
3114
+ /** Lines (1-based) where the source names a font family to load. */
3115
+ function _namedFontLines(code) {
3116
+ const lines = new Set();
3117
+ for (const m of code.matchAll(_DESIGN_FONT_LITERAL_RE)) {
3118
+ const value = m[2].trim();
3119
+ if (value.startsWith("${")) continue;
3120
+ const first = value.split(",")[0].trim().replace(/^["']|["']$/g, "").toLowerCase();
3121
+ if (!/[a-z]/.test(first) || _DESIGN_FONT_GENERIC.has(first)) continue;
3122
+ const at = m.index + m[0].length - m[2].length;
3123
+ lines.add(code.slice(0, at).split("\n").length);
3124
+ }
3125
+ return lines;
3126
+ }
3127
+
3126
3128
  function _hardcodedDesignRules(source) {
3127
3129
  // Comments blanked, string CONTENT kept — a colour literal IS a string.
3128
- const code = _stripNonCode(source, { keepStrings: true }).split(/\r?\n/);
3130
+ const stripped = _stripNonCode(source, { keepStrings: true }).replace(/\r\n/g, "\n");
3131
+ const code = stripped.split("\n");
3129
3132
  const sourceLines = source.split(/\r?\n/);
3130
3133
  const exempt = _designExemptLines(source);
3134
+ const fontLines = _namedFontLines(stripped);
3131
3135
  const findings = [];
3132
3136
  for (let i = 0; i < code.length; i += 1) {
3133
- if (exempt.has(i + 1)) continue;
3134
3137
  const line = code[i];
3138
+ // sc-17364: a font named in the source never loads on either host, so
3139
+ // no marker can license it.
3140
+ if (fontLines.has(i + 1)) {
3141
+ findings.push({
3142
+ rule: "no-hardcoded-design",
3143
+ severity: "warning",
3144
+ label: _DESIGN_FONT_LABEL,
3145
+ line: i + 1,
3146
+ snippet: (sourceLines[i] || "").trim().slice(0, 200),
3147
+ });
3148
+ }
3149
+ if (exempt.has(i + 1)) continue;
3135
3150
  let what = null;
3136
3151
  if (_DESIGN_HEX_RE.test(line) || _DESIGN_FUNC_COLOR_RE.test(line)) {
3137
3152
  what = "a colour literal";
3138
- } else if (_DESIGN_FONT_FAMILY_RE.test(line)) {
3139
- what = "a font-family name";
3140
3153
  } else if (
3141
3154
  _DESIGN_FONT_SIZE_RE.test(line) &&
3142
3155
  !_DESIGN_TOKEN_REF_RE.test(line)
package/dist/linter.js CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  import { CONTRACT, normaliseActionTriggerTypes } from "./contract.js";
10
10
  import { LUCIDE_ICON_NAMES, LUCIDE_VERSION } from "./lucideIconNames.js";
11
+ import { groupIdTextFindings } from "./group-id-text.js";
11
12
 
12
13
  // Per-identifier match rule, run over the whole masked source. Most banned
13
14
  // identifiers compile to a whole-word match.
@@ -1030,46 +1031,13 @@ function _manifestActionRules(manifest) {
1030
1031
  return findings;
1031
1032
  }
1032
1033
 
1033
- // Typed group ids hide the groups and break on Copy Workspace.
1034
+ // A widget's settings hold user groups only when its source reads them.
1034
1035
  const READS_USER_GROUPS = /\bgroupIds\b|\buseGroups\s*\(/;
1035
- const GROUP_WORD = /group|grupp/i;
1036
- const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
1037
- const NOT_A_GROUP_REF_NAME = /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text)$/i;
1038
-
1039
- function _holdsGroupIds(name, def) {
1040
- if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
1041
- const wording = `${def.label ?? ""} ${def.description ?? ""}`;
1042
- return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
1043
- }
1044
-
1045
- function _groupIdTextFields(schema, prefix, out) {
1046
- if (!schema || typeof schema !== "object") return out;
1047
- for (const [name, def] of Object.entries(schema)) {
1048
- if (!def || typeof def !== "object") continue;
1049
- const path = prefix + name;
1050
- const items = def.items && typeof def.items === "object" ? def.items : null;
1051
- const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
1052
- if (isText && _holdsGroupIds(name, def)) out.push(path);
1053
- if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
1054
- if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
1055
- }
1056
- return out;
1057
- }
1058
1036
 
1059
1037
  function _groupIdTextRules(source, manifest) {
1060
1038
  if (!manifest || typeof manifest !== "object") return [];
1061
1039
  if (!READS_USER_GROUPS.test(_stripNonCode(source))) return [];
1062
- return _groupIdTextFields(manifest.propertySchema, "", []).map((path) => ({
1063
- rule: "group-ids-as-text",
1064
- severity: "error",
1065
- label:
1066
- `propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
1067
- "and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
1068
- "{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
1069
- "so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
1070
- line: 0,
1071
- snippet: "",
1072
- }));
1040
+ return groupIdTextFindings(manifest.propertySchema);
1073
1041
  }
1074
1042
 
1075
1043
  // sc-1366 — invalid lucide icon import gate. lucide-react-native is a vetted
@@ -3068,7 +3036,17 @@ export function narrowManifestForFile(manifest, filename) {
3068
3036
  const _DESIGN_HEX_RE =
3069
3037
  /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![0-9a-fA-F])/;
3070
3038
  const _DESIGN_FUNC_COLOR_RE = /\b(?:rgba?|hsla?)\s*\(/;
3071
- const _DESIGN_FONT_FAMILY_RE = /\bfontFamily\s*:\s*["'`]\s*\S/;
3039
+ // The quoted value after `fontFamily:`, or (sc-17364) after `||` / `??` on a
3040
+ // font read such as `style.titleFont`, `style["titleFont"]?.trim()`, across
3041
+ // lines. fontWeight / fontSize never match.
3042
+ const _DESIGN_FONT_LITERAL_RE =
3043
+ /(?:\bfontFamily\s*:|[Ff]ont(?:Family)?(?:\?\.\w+\(\)|["'\])])*\s*(?:\|\||\?\?))\s*(["'`])([^"'`\n]*)/g;
3044
+ // Faces every host already has; naming one loads nothing.
3045
+ const _DESIGN_FONT_GENERIC = new Set([
3046
+ "serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "math",
3047
+ "emoji", "fangsong", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded",
3048
+ "-apple-system", "inherit", "initial", "unset", "revert", "revert-layer",
3049
+ ]);
3072
3050
  const _DESIGN_FONT_SIZE_RE = /\bfontSize\s*:\s*-?\d/;
3073
3051
  const _DESIGN_RADIUS_RE =
3074
3052
  /\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 +3096,55 @@ function _designExemptLines(source) {
3118
3096
  return exempt;
3119
3097
  }
3120
3098
 
3099
+ const _DESIGN_FONT_LABEL =
3100
+ "a font-family name in the source never loads: the web Player and the " +
3101
+ "exported app load only the workspace's fonts and the families a " +
3102
+ "`type: \"font\"` field names, so this text renders a fallback face and " +
3103
+ "no theme change reaches it. Use theme.typography.fontFamily or " +
3104
+ "theme.typography.headingFontFamily. To override the workspace font, " +
3105
+ "declare a styleSchema field { type: \"font\" } and read " +
3106
+ "props.style.<field> || theme.typography.headingFontFamily; its default " +
3107
+ "may name the family. appstudio-design-ok does not license a font.";
3108
+
3109
+ /** Lines (1-based) where the source names a font family to load. */
3110
+ function _namedFontLines(code) {
3111
+ const lines = new Set();
3112
+ for (const m of code.matchAll(_DESIGN_FONT_LITERAL_RE)) {
3113
+ const value = m[2].trim();
3114
+ if (value.startsWith("${")) continue;
3115
+ const first = value.split(",")[0].trim().replace(/^["']|["']$/g, "").toLowerCase();
3116
+ if (!/[a-z]/.test(first) || _DESIGN_FONT_GENERIC.has(first)) continue;
3117
+ const at = m.index + m[0].length - m[2].length;
3118
+ lines.add(code.slice(0, at).split("\n").length);
3119
+ }
3120
+ return lines;
3121
+ }
3122
+
3121
3123
  function _hardcodedDesignRules(source) {
3122
3124
  // Comments blanked, string CONTENT kept — a colour literal IS a string.
3123
- const code = _stripNonCode(source, { keepStrings: true }).split(/\r?\n/);
3125
+ const stripped = _stripNonCode(source, { keepStrings: true }).replace(/\r\n/g, "\n");
3126
+ const code = stripped.split("\n");
3124
3127
  const sourceLines = source.split(/\r?\n/);
3125
3128
  const exempt = _designExemptLines(source);
3129
+ const fontLines = _namedFontLines(stripped);
3126
3130
  const findings = [];
3127
3131
  for (let i = 0; i < code.length; i += 1) {
3128
- if (exempt.has(i + 1)) continue;
3129
3132
  const line = code[i];
3133
+ // sc-17364: a font named in the source never loads on either host, so
3134
+ // no marker can license it.
3135
+ if (fontLines.has(i + 1)) {
3136
+ findings.push({
3137
+ rule: "no-hardcoded-design",
3138
+ severity: "warning",
3139
+ label: _DESIGN_FONT_LABEL,
3140
+ line: i + 1,
3141
+ snippet: (sourceLines[i] || "").trim().slice(0, 200),
3142
+ });
3143
+ }
3144
+ if (exempt.has(i + 1)) continue;
3130
3145
  let what = null;
3131
3146
  if (_DESIGN_HEX_RE.test(line) || _DESIGN_FUNC_COLOR_RE.test(line)) {
3132
3147
  what = "a colour literal";
3133
- } else if (_DESIGN_FONT_FAMILY_RE.test(line)) {
3134
- what = "a font-family name";
3135
3148
  } else if (
3136
3149
  _DESIGN_FONT_SIZE_RE.test(line) &&
3137
3150
  !_DESIGN_TOKEN_REF_RE.test(line)
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.324.0",
3
+ "version": "0.326.1",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -7025,7 +7025,11 @@ 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
- version: "1.264.0",
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
+ // 1.265.1: narrower lint — `group-ids-as-text` passes a group's name,
7031
+ // prefix, description, mode, size, count, colour, icon or type.
7032
+ version: "1.265.1",
7029
7033
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7030
7034
  hooks: HOOKS,
7031
7035
  primitives: PRIMITIVES,