@metamorph-labs/polymorph-screen 1.0.17 → 1.0.18
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/CHANGELOG.md +44 -0
- package/dist/card.js +1 -1
- package/dist/check.js +1 -1
- package/dist/chunks/{card-DbGNeT3m.js → card-CVzvz0j_.js} +2 -2
- package/dist/chunks/{card-DbGNeT3m.js.map → card-CVzvz0j_.js.map} +1 -1
- package/dist/chunks/{check-DDXOiNKG.js → check-BB8y9DW3.js} +259 -147
- package/dist/chunks/check-BB8y9DW3.js.map +1 -0
- package/dist/chunks/{vocabulary-uhojNKy_.js → vocabulary-C8KzYJUx.js} +6 -3
- package/dist/chunks/vocabulary-C8KzYJUx.js.map +1 -0
- package/dist/index.js +5 -5
- package/dist/types/_internal/registry/screen-table.d.ts +5 -1
- package/dist/types/_internal/spec/validate.d.ts +8 -1
- package/dist/vocabulary.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/check-DDXOiNKG.js.map +0 -1
- package/dist/chunks/vocabulary-uhojNKy_.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-DDXOiNKG.js","names":["validateShape","surfaceOf","validate","keyTooLong","sharedNameFault","surfaceOf$1","shippedParts","allowedMembers","memberFault","INHERITED_NAMES","formPropOf","inheritedNameFault","typeTooLong","notOneElement","takesNode","undeclaredField","tooDeep","fieldOf","isActionType","objectName","withoutElements","dataField","holdsData","unreceivedCallback","elementIn","itemOf","callbackOf","takesElement","isCallback","isObjectValue","addressFaults","isBinding","BINDING_PATH","SCREEN_SHAPE","ADDRESS_KEYS","isElement","VOCABULARY","SPEC_RUNGS","RESERVED","line","PATCH_PROP","PLAIN_OBJECT","validateSpec","expressions","bindingFaults","document","components","registry","component","primitives","primitive","outside","propsOutsideProps","surfaceOf","name","shapeFaults","path","rest","message","said","spec","platform","framework","options","faults","inputs","input","used","composed","checkInputNames","checkInputTypes","judges","checkTypeImports","walkValue","value","drawn","rendered","item","index","head","key","walkElement","props","element","known","withNativeProps","partsOfOwner","nearest","checkPlatform","checkFramework","absent","partFault","suggestProp","declared","fault","valueFault","checkGrid","checkIcons","child","checkScreenName","screenImports","isNativePlatform","checkNativeScreen","seen","listed","items","abbreviated","flat","text","record","binding","\"$\"","ELEMENT_FIELDS","surface","found","\"component\"","member","judge","IDENTIFIER","MODULE","NO_NAMESPACE","module","names","angularClassName","ANGULAR_CORE_IMPORTS","imports","taken","written","origin","LANGUAGE","TOOLKIT","PENDING_LIST","FRAME","ARCHETYPES","STATUS_OWNED","RETRY","SWIFT_KEYWORDS","KOTLIN_KEYWORDS","KOTLIN_TAKEN","screenStem","nativeDeclarations","stem","PLATFORM_NAMES","ownsLoadStatus","types","language","actions","unparsed","intoActions","walk","isOwner","at","declaredType","checkCell","children","childrenType","texts","declaredTypes","grid","variant","\"variant\"","tone","\"tone\"","matches","cellVariant","tones","cellTone","cell","given","missing","typesOf","map","prop","direct","segments","owner","part","compound","candidate","composableParts","recorded","partNames","shipped","entry","substitute","instead","printed","parts","checkable","arrayForm","partIsCheckable","scalarMatches","quoted","icon","\"icon\"","roles","role","near","checkException","needed","fold","wanted","byName","lowered","byPurpose","n","SUGGESTION_FLOOR","checkScreen","deep","TOO_DEEP","vocabulary","all","runTimeFaults","isRecord","isElementValue","address","validated","named","\"name\"","before","callbacks","\"inputs\"","type","\"type\"","visit","receiver","unnamed","allowed","\"props\"","lacks","silent","\"children\"","fields","\"$object\"","field","held","kept","\"root\""],"sources":["../../../spec/src/validate.ts","../../src/check.ts"],"sourcesContent":["// The value imports use the pure subpaths, because the browser validates\n// documents too. The types come from the root and are erased at compile time.\nimport {\n DEFAULT_FRAMEWORK,\n shippedParts,\n type Framework,\n type FrameworkStatus,\n} from '@polymorph/registry/frameworks'\nimport {\n DEFAULT_PLATFORM,\n NO_SUBSTITUTE,\n type Platform,\n type PlatformStatus,\n} from '@polymorph/registry/platforms'\nimport { validate as validateShape } from '@polymorph/registry/shape'\n\nimport { isActionType } from './action-type'\nimport {\n BINDING_PATH,\n isBinding,\n isElement,\n isObjectValue,\n SCREEN_SHAPE,\n type ScreenInput,\n type ScreenSpec,\n type SpecElement,\n type SpecValue,\n} from './schema'\n\n// Whether a printed type is a callback is read by the emitters and the run-time walk too, from a\n// module that holds nothing else.\nexport { EVENT_HANDLER_ALIAS, isActionType } from './action-type'\n\n/**\n * Checks whether a spec is lawful.\n *\n * There are two passes, and the second matters more.\n *\n * **Shape** checks whether this is a screen spec at all. `SCREEN_SHAPE` decides,\n * and it is the same object published as JSON Schema, so an agent's own\n * validator and this one reach the same result.\n *\n * **Meaning** checks whether this is a screen in *this* system. Does the\n * component exist, and does it render on the screen's platform and in the\n * framework it is emitted for (an option, `SpecOptions`); does every prop\n * exist on it, does the grid have the variant × tone cell, is a declared\n * exception at the right rung with a reason.\n * All of it is read from the registry, and none from a list here. A validator\n * with its own copy of Button's props would be the second source of truth the\n * registry exists to prevent, and it would go stale the first time a prop was\n * renamed.\n *\n * The second pass is why a spec format is useful. A schema alone accepts\n * `{\"component\": \"Buton\", \"props\": {\"clasName\": \"big\"}}`, which is well-formed\n * but meaningless. Checked against the registry, both mistakes are faults with\n * a path, before any TSX is written.\n */\n\nexport interface SpecFault {\n path: string\n message: string\n}\n\n/* -------------------------------------------------------------------------- */\n/* What the validator reads of the registry */\n/* -------------------------------------------------------------------------- */\n\n/** A prop as the validator reads it: its name, its printed type, and whether it may be left out. */\nexport interface SpecProp {\n readonly name: string\n readonly type: string\n readonly optional: boolean\n}\n\n/** A member's entry on one platform: its status, and for an absent one, why and what instead. */\nexport interface SpecPlatformEntry {\n readonly status: PlatformStatus\n readonly reason?: string\n readonly substitute?: string\n}\n\n/**\n * A member's entry in one web framework: its status, why it is absent, and\n * the files its shell declares there, of which `shippedParts` reads the names.\n */\nexport interface SpecFrameworkEntry {\n readonly status: FrameworkStatus\n readonly reason?: string\n readonly shell?: { readonly sources: readonly string[] }\n}\n\n/** A member as the validator reads it. */\nexport interface SpecMember {\n readonly name: string\n readonly tier: string\n /** Searched for a correction when a name is unknown (`Modal` finds Dialog's purpose). */\n readonly purpose: string\n /** Its own props, and the props of the parts a native contract carries, named `Part.prop`. */\n readonly props: readonly SpecProp[]\n readonly parts: readonly { readonly name: string; readonly props: readonly SpecProp[] }[]\n readonly grid: Readonly<Record<string, readonly string[]>> | null\n readonly platforms: Readonly<Record<Platform, SpecPlatformEntry>>\n readonly frameworks: Readonly<Record<Framework, SpecFrameworkEntry>>\n}\n\n/** An exception primitive as the validator reads it: a member that is a rung of the ladder. */\nexport interface SpecPrimitive {\n readonly name: string\n readonly rung: number\n readonly props: readonly SpecProp[]\n readonly platforms: Readonly<Record<Platform, SpecPlatformEntry>>\n readonly frameworks: Readonly<Record<Framework, SpecFrameworkEntry>>\n}\n\n/**\n * Exactly what `validateSpec` reads of the vocabulary: the members, the\n * exception primitives and the icon roles. The registry is one\n * (`@polymorph/registry`'s `Registry`). The run-time vocabulary table\n * (`@polymorph/screen`), which holds only these fields, is another, so a page\n * checks a document with no registry in it and gets the same faults.\n */\nexport interface SpecVocabulary {\n readonly components: readonly SpecMember[]\n readonly exceptions: { readonly primitives: readonly SpecPrimitive[] }\n readonly icons: { readonly roles: readonly { readonly name: string }[] }\n}\n\nexport interface SpecValidation {\n ok: boolean\n faults: SpecFault[]\n}\n\n/** Rungs a *screen* can take. 1 is not an exception, and 5 is a promotion, not a node. */\nconst SPEC_RUNGS = [2, 3, 4]\n\n/**\n * The words a parameter cannot be named.\n *\n * `emit.ts` writes every input name into a binding pattern\n * (`function View({ draft, onSave }: ViewProps)`). So an input named `class`\n * causes a Prettier parse error inside the emitter, and nothing in that error\n * points back at `$.inputs[n]`. The schema cannot express this:\n * `^[a-z][A-Za-z0-9]*$` describes the *shape* of an identifier, and a reserved\n * word has a valid shape.\n *\n * The list comes from the language, not from preference: ECMAScript's reserved\n * words, the words reserved only under strict mode (an emitted module is always\n * strict), and the two names strict mode refuses to bind.\n */\nconst RESERVED = new Set(\n [\n // Always reserved.\n 'break case catch class const continue debugger default delete do else enum export extends',\n 'false finally for function if import in instanceof new null return super switch this throw',\n 'true try typeof var void while with',\n // Reserved under strict mode and in modules, and an emitted file is a module.\n 'await implements interface let package private protected public static yield',\n // Not reserved words, but strict mode still refuses to bind them.\n 'arguments eval',\n ].flatMap((line) => line.split(' ')),\n)\n\n/** The only keys a rung-3 patch may carry, read from the props it lands on. */\nconst PATCH_PROP = 'patch'\n\n/**\n * The checks that cannot run everywhere.\n *\n * This module is the half the browser runs, so it has no compiler. Whether an\n * input's `type` is one TypeScript type is a question for the compiler's\n * parser, and a caller that has one passes it in. `lawful.ts` does, and the\n * package's root entry (and so `pnpm emit` and the MCP server) uses\n * `lawful.ts`. Without it, types are left to whoever has a compiler.\n */\nexport interface SpecJudges {\n /** Why a string is not one TypeScript type, as the end of a sentence, or `null`. */\n inputType?: (type: string) => string | null\n /**\n * Why an input's type has no type on the screen's native platform by the\n * native screen contract's table, as the end of a sentence, or `null`.\n * Asked of an `ios` or `android` screen's inputs whose type `inputType`\n * accepts.\n */\n nativeType?: (input: ScreenInput, spec: ScreenSpec) => string | null\n /**\n * Whether the native platform's member package draws a member or a\n * compound part. A screen that uses one it does not draw would not compile,\n * so each such node is a fault. Left out where the member package is not at\n * hand, as in the browser.\n */\n renders?: (component: string) => boolean\n}\n\n/** How a spec is checked, beyond the document itself. */\nexport interface SpecOptions {\n /**\n * The web framework the screen will be emitted for. A member that\n * framework's vocabulary does not ship is a fault that gives the reason.\n * `react` when absent.\n */\n framework?: Framework\n /**\n * The member package of the screen's native platform (`readNativePackage`\n * in `emit-native.ts`). With it, an `ios` or `android` screen's types are\n * checked against the names the package declares and its members against\n * the ones it draws. The root entry's `validateSpec` (`lawful.ts`) reads\n * it; this module only types it.\n */\n native?: NativePackage\n}\n\n/** A platform a native screen emitter writes. */\nexport type NativePlatform = Exclude<Platform, 'web'>\n\n/**\n * A native platform's member package, as the emitters and the validator read\n * it: the generated contract every member's props are declared in, and the\n * members the package draws.\n */\nexport interface NativePackage {\n platform: NativePlatform\n /** The text of the generated contract: `Contracts.swift` or `Contracts.kt`. */\n contract: string\n /**\n * What the package draws, by the name a screen calls: `PMButton` on both\n * platforms, and a compound part joined on Android (`PMSettingsRowGroup`).\n */\n rendered: readonly string[]\n}\n\n/** What the shape check adds where a value is an object of no form the format has. */\nconst PLAIN_OBJECT =\n 'a binding is `{ \"$\": \"anInput\" }`, an element is `{ \"component\": … }`, and a plain object, ' +\n 'such as a column or an option, is written `{ \"$object\": { … } }`'\n\nexport function validateSpec(\n registry: SpecVocabulary,\n document: unknown,\n judges: SpecJudges = {},\n options: SpecOptions = {},\n): SpecValidation {\n // This runs before the shape check because of how the shape check would\n // report it. A binding that is not a path fails the schema's pattern, and a\n // value is a union, so the fault would be the union's best guess (\"expected a\n // string\") for a document whose author wrote an expression where a name goes.\n const expressions = bindingFaults(document, '$')\n if (expressions.length > 0) return { ok: false, faults: expressions }\n\n const components = new Map<string, SpecMember>(\n registry.components.map((component) => [component.name, component]),\n )\n const primitives = new Map<string, SpecPrimitive>(\n registry.exceptions.primitives.map((primitive) => [primitive.name, primitive]),\n )\n\n // A prop written beside `props` is a key the schema lacks. The shape check\n // would list the element's four fields. This says what the key is.\n const outside = propsOutsideProps(document, '$', (name) =>\n surfaceOf(name, components, primitives),\n )\n const shapeFaults = validateShape(SCREEN_SHAPE, document).map((message) => {\n const [path = '$', ...rest] = message.split(': ')\n const said = rest.join(': ')\n // The one union in the format is a value, and the object a value is most\n // often miswritten as is a plain one.\n return {\n path,\n message:\n outside.get(path) ??\n (said.startsWith('an object here has ') ? `${said} — ${PLAIN_OBJECT}` : said),\n }\n })\n if (shapeFaults.length > 0) return { ok: false, faults: shapeFaults }\n\n const spec = document as ScreenSpec\n const platform = spec.platform ?? DEFAULT_PLATFORM\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const faults: SpecFault[] = []\n\n // A web framework writes web screens. A phone platform has its own vocabulary.\n if (framework !== DEFAULT_FRAMEWORK && platform !== DEFAULT_PLATFORM) {\n faults.push({\n path: '$.platform',\n message:\n `${/^[aeiou]/.test(framework) ? 'an' : 'a'} ${framework} screen runs on the web, and ` +\n `this one names ${platform} — remove ` +\n '`platform`, or validate it without a framework',\n })\n }\n const inputs = new Set(spec.inputs.map((input) => input.name))\n /** Every identifier the emitted file imports from the vocabulary, by the emitter's rule. */\n const used = new Set<string>()\n /** Every member and compound part the tree composes, by its full name. */\n const composed = new Set<string>()\n\n checkInputNames(spec, faults)\n checkInputTypes(spec, faults, judges.inputType)\n checkTypeImports(spec, faults)\n\n /* ---- the walk --------------------------------------------------------- */\n\n /**\n * `rendered` says whether React draws the value: a child, or an item of a\n * list in a prop that holds an element, which the emitter writes as a\n * fragment. A string, a binding and an element can all be drawn. A\n * structured object cannot, and one in that position would be emitted as a\n * pair of braces that is neither a child nor an expression.\n */\n const walkValue = (value: SpecValue, path: string, rendered: boolean): void => {\n if (Array.isArray(value)) {\n const drawn = rendered || value.some((item) => !Array.isArray(item) && isElement(item))\n value.forEach((item, index) => walkValue(item, `${path}[${index}]`, drawn))\n return\n }\n if (isBinding(value)) {\n // The schema requires a binding to be a path. What remains is whether the\n // path's head is a declared input.\n const [head] = value.$.split('.')\n if (head === undefined || !inputs.has(head)) {\n faults.push({\n path,\n message: `\\`${value.$}\\` binds to \"${head}\", which the screen does not declare as an input`,\n })\n }\n return\n }\n if (isObjectValue(value)) {\n if (rendered) {\n faults.push({\n path,\n message:\n 'a structured object is data, and this is a place where things are drawn — a child, ' +\n 'or a list that holds an element. Pass it to the prop that takes it',\n })\n return\n }\n // A structured prop can also hold an icon role. `emptyState` takes one, as\n // a string in an object, not as a prop on a component. The closed role\n // set must be enforced in both positions, or it is not closed.\n checkIcons(registry, value.$object, path, faults)\n for (const [key, item] of Object.entries(value.$object)) {\n walkValue(item, `${path}.${key}`, false)\n }\n return\n }\n if (isElement(value)) walkElement(value, path)\n }\n\n const walkElement = (element: SpecElement, path: string): void => {\n const props = element.props ?? {}\n const known = withNativeProps(\n surfaceOf(element.component, components, primitives),\n element.component,\n platform,\n )\n // Same as the emitter: a compound part adds its owner, whether or not the\n // registry knows the name.\n used.add(element.component.split('.')[0] ?? element.component)\n composed.add(element.component)\n\n if (known === null) {\n faults.push({\n path,\n message:\n `no component called \\`${element.component}\\`` +\n (partsOfOwner(element.component, components, platform, framework) ??\n nearest(registry, element.component, components, primitives)),\n })\n } else {\n checkPlatform(element, known, platform, path, faults)\n checkFramework(element, known, framework, path, faults)\n const absent = partFault(element.component, known, platform, framework)\n if (absent !== null) faults.push({ path, message: absent })\n\n /*\n * The prop check is the style law. `className`, `style` and `css` are\n * absent from every governed component's public surface by design, so\n * they fail here as \"no such prop\", the same fault a typo gets. Nothing\n * in this file names them, so the law is not a denylist someone has to\n * maintain.\n */\n for (const name of Object.keys(props)) {\n if (!known.props.has(name)) {\n faults.push({\n path: `${path}.props.${name}`,\n message: `\\`${element.component}\\` has no prop \\`${name}\\`${suggestProp(name, known.props)}`,\n })\n }\n }\n\n /*\n * The value check. Checking names alone accepts `label: 42` and\n * `size: \"xxl\"`, and an agent's most likely mistake is a value, not a\n * name. The registry's printed types decide, and only what they can decide\n * is checked. Literal unions and scalar primitives fault on a mismatch. A\n * type with a member that cannot be checked (`ReactNode`, functions,\n * object shapes) accepts the value, because a validator that guesses is\n * worse than one that abstains.\n */\n for (const [name, value] of Object.entries(props)) {\n const declared = known.types.get(name)\n if (!declared) continue\n const fault = valueFault(declared.type, value)\n if (fault !== null) {\n faults.push({\n path: `${path}.props.${name}`,\n message: `\\`${element.component}\\` prop \\`${name}\\` wants \\`${declared.type}\\`, got ${fault}`,\n })\n }\n }\n\n // A required prop the emitter cannot default breaks the screen at emit\n // time. Validation reports it earlier, which is its purpose.\n for (const [name, declared] of known.types) {\n if (declared.optional || name === 'children') continue\n if (name in props) continue\n faults.push({\n path,\n message: `\\`${element.component}\\` is missing its required prop \\`${name}\\``,\n })\n }\n\n // The grid is the member's. A part has no variant × tone cell of its own.\n if (known.component && known.part === undefined) {\n checkGrid(known.component, props, path, faults)\n }\n checkIcons(registry, props, path, faults)\n if (element.children !== undefined && !known.props.has('children')) {\n faults.push({ path, message: `\\`${element.component}\\` takes no children` })\n }\n }\n\n checkException(element, known, path, faults)\n\n for (const [name, value] of Object.entries(props)) {\n walkValue(value, `${path}.props.${name}`, false)\n }\n ;(element.children ?? []).forEach((child, index) =>\n walkValue(child, `${path}.children[${index}]`, true),\n )\n }\n\n walkElement(spec.root, '$.root')\n checkScreenName(spec, screenImports(used, composed, framework), faults)\n if (isNativePlatform(platform)) {\n checkNativeScreen(spec, platform, components, primitives, faults, judges)\n }\n return { ok: faults.length === 0, faults }\n}\n\n/* -------------------------------------------------------------------------- */\n/* The identifiers the emitted file will hold */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Input names, checked as the emitted *parameter list*, not as strings.\n *\n * There are two faults about the same names. A reserved word cannot be a\n * binding at all. Two inputs with one name become one entry in the props\n * interface and two identifiers in the destructuring, which is `TS2300` from a\n * generated file about a document that validated cleanly. The names are\n * checked in order and each repeat is reported where it appears, so the path\n * names the *second* `onSave`, not the first.\n */\nfunction checkInputNames(spec: ScreenSpec, faults: SpecFault[]): void {\n const seen = new Set<string>()\n spec.inputs.forEach((input, index) => {\n const path = `$.inputs[${index}].name`\n if (RESERVED.has(input.name)) {\n faults.push({\n path,\n message:\n `\\`${input.name}\\` is a word the language has taken — the emitted component ` +\n 'destructures its inputs, and no parameter can be called that',\n })\n }\n if (seen.has(input.name)) {\n faults.push({\n path,\n message:\n `\\`${input.name}\\` is declared twice — the props interface would hold one field and ` +\n 'the destructuring two identifiers of the same name',\n })\n }\n seen.add(input.name)\n })\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nfunction listed(items: string[]): string {\n return items.length <= 1\n ? items.join('')\n : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1] as string}`\n}\n\n/** Long enough to recognise what was written, short enough to stay one line of a fault. */\nfunction abbreviated(text: string): string {\n const flat = text.replace(/\\s+/g, ' ')\n return flat.length <= 60 ? flat : `${flat.slice(0, 57)}…`\n}\n\n/**\n * Every binding in a document that is not a path, found before any other\n * check.\n *\n * A binding is the one value the emitter prints as code. If a binding were\n * checked only on its first segment, `items.map((item) => <button …>)` would\n * pass, because its head is a valid input. That would add an expression\n * language to the format, and give a spec one place to write a raw element or\n * a style. The schema's pattern forbids it. This walk reports it in words, at\n * the node, to the author.\n *\n * It reads plain JSON, not a spec, because it runs before the document is known\n * to be one.\n */\nfunction bindingFaults(value: unknown, path: string): SpecFault[] {\n if (Array.isArray(value)) {\n return value.flatMap((item, index) => bindingFaults(item, `${path}[${index}]`))\n }\n if (typeof value !== 'object' || value === null) return []\n\n const record = value as Record<string, unknown>\n const binding = record['$']\n if (typeof binding === 'string' && !BINDING_PATH.test(binding)) {\n return [\n {\n path,\n message:\n `\\`${abbreviated(binding)}\\` is not a binding — a binding names an input and, with ` +\n 'dots, a path into it (`draft.subject`). It cannot hold an expression: a call, an ' +\n 'index, a condition or an element is computed by the container that renders this ' +\n 'screen, and handed in as an input',\n },\n ]\n }\n\n return Object.entries(record).flatMap(([key, item]) => bindingFaults(item, `${path}.${key}`))\n}\n\n/** The fields of an element, as `ELEMENT` in the schema lists them. */\nconst ELEMENT_FIELDS = new Set(['component', 'props', 'children', 'exception'])\n\n/**\n * Every prop written as a field of its element, beside `props`, by the path\n * the shape check reports it at, with what to say there.\n *\n * `{\"component\": \"AuthPage\", \"props\": {…}, \"cardFooter\": …}` closes `props` one\n * prop early. The key is a prop the member has, so the fault can name the slip\n * where the shape check knows only that an element has no such field.\n *\n * It reads plain JSON, not a spec, because it runs before the document is known\n * to be one.\n */\nfunction propsOutsideProps(\n value: unknown,\n path: string,\n surface: (name: string) => Surface | null,\n found = new Map<string, string>(),\n): Map<string, string> {\n if (Array.isArray(value)) {\n value.forEach((item, index) => propsOutsideProps(item, `${path}[${index}]`, surface, found))\n return found\n }\n if (typeof value !== 'object' || value === null) return found\n\n const record = value as Record<string, unknown>\n const name = record['component']\n const props = typeof name === 'string' ? surface(name)?.props : undefined\n for (const [key, item] of Object.entries(record)) {\n if (props?.has(key) === true && !ELEMENT_FIELDS.has(key)) {\n const member = abbreviated(String(name))\n found.set(\n `${path}.${key}`,\n `\\`${key}\\` is a prop of \\`${member}\\`, written here as a field of the element — a prop ` +\n `goes inside \\`props\\`: \\`{ \"component\": \"${member}\", \"props\": { \"${key}\": … } }\\``,\n )\n }\n propsOutsideProps(item, `${path}.${key}`, surface, found)\n }\n return found\n}\n\n/**\n * An input's type, passed to the check that understands types.\n *\n * The format has no model of TypeScript, and `tsc` decides whether `Ticket[]`\n * means anything. But the emitter prints the type into the middle of an\n * interface, so before that it must be exactly one type that stays where it\n * was put. That is the compiler's question. This module runs in the browser\n * and has no compiler, so a caller that has one supplies the check\n * (`SpecJudges`).\n */\nfunction checkInputTypes(\n spec: ScreenSpec,\n faults: SpecFault[],\n judge: SpecJudges['inputType'],\n): void {\n if (judge === undefined) return\n spec.inputs.forEach((input, index) => {\n const fault = judge(input.type)\n if (fault === null) return\n faults.push({\n path: `$.inputs[${index}].type`,\n message:\n `\\`${abbreviated(input.type)}\\` ${fault} — an input's type is one TypeScript type, ` +\n 'written into the props interface as it stands',\n })\n })\n}\n\n/** A name the emitted file can import: an identifier, and nothing around it. */\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/** A module specifier, as it sits between the quotes of an import. */\nconst MODULE = /^[^\\s'\"`\\\\]+$/\n\n/** What a `types` entry written as a default or a namespace import is told. */\nconst NO_NAMESPACE =\n 'A spec has no default or namespace import: name the type itself (`ReactNode`), and write ' +\n 'it in the input’s type without the namespace (`ReactNode`, not `React.ReactNode`)'\n\n/**\n * The `types` block, checked as the import lines it becomes.\n *\n * `import type { Ticket } from './types'` is built from a key and a list of\n * names, and both are printed verbatim. A name that is not an identifier, or a\n * module that contains a quote, adds a second statement to that line.\n */\nfunction checkTypeImports(spec: ScreenSpec, faults: SpecFault[]): void {\n for (const [module, names] of Object.entries(spec.types ?? {})) {\n if (!MODULE.test(module)) {\n faults.push({\n path: `$.types.${abbreviated(module)}`,\n message:\n 'is not a module specifier — it is written between the quotes of an import, so it ' +\n 'holds no quote, backslash or space',\n })\n }\n names.forEach((name, index) => {\n // A reserved word has the shape of a name and cannot be imported as one.\n if (IDENTIFIER.test(name) && !RESERVED.has(name)) return\n faults.push({\n path: `$.types.${abbreviated(module)}[${index}]`,\n message:\n `\\`${abbreviated(name)}\\` is not a type name — an import names identifiers` +\n (/\\bas\\b|\\*/.test(name) ? `. ${NO_NAMESPACE}` : ''),\n })\n })\n }\n}\n\n/** `SettingsRowGroup` for `SettingsRow.Group`: the class an Angular member or part is exported as. */\nexport const angularClassName = (component: string): string => component.replace('.', '')\n\n/** What an emitted Angular screen imports from `@angular/core`. */\nconst ANGULAR_CORE_IMPORTS = ['Component', 'input']\n\n/**\n * The identifiers the emitted file imports, beside the types, each with where\n * it comes from. Every emitter imports the members by the React emitter's\n * rule (`used`: a compound part adds its owner). An Angular screen also\n * imports `Component` and `input` from Angular, and each member and part by\n * its class (`TabsContent` for `Tabs.Content`).\n */\nfunction screenImports(\n used: Set<string>,\n composed: Set<string>,\n framework: Framework,\n): Map<string, string> {\n const imports = new Map<string, string>()\n for (const member of used) imports.set(member, 'a member this screen composes')\n if (framework !== 'angular') return imports\n for (const name of ANGULAR_CORE_IMPORTS) imports.set(name, 'a name from `@angular/core`')\n for (const component of composed) {\n imports.set(angularClassName(component), 'a member or part this screen composes')\n }\n return imports\n}\n\n/**\n * The screen's own name, checked against the names the emitted file already\n * has.\n *\n * The emitter writes two identifiers of its own, `Screen` and `ScreenProps`,\n * into a file that already imports every member the tree composes and every\n * type the `types` block declares. A collision is not a harmless shadowed\n * variable. `{\"name\": \"Stack\"}` on a tree containing a Stack emits a component\n * that renders itself until the call stack overflows. That happens at runtime,\n * in the consumer's app, from a document that passed every other law here. In\n * an Angular module the same collision is a duplicate identifier, and the\n * module does not compile.\n */\nfunction checkScreenName(\n spec: ScreenSpec,\n imports: Map<string, string>,\n faults: SpecFault[],\n): void {\n const taken = new Map(imports)\n for (const [module, names] of Object.entries(spec.types ?? {})) {\n for (const name of names) taken.set(name, `a type it imports from \\`${module}\\``)\n }\n\n for (const written of [spec.name, `${spec.name}Props`]) {\n const origin = taken.get(written)\n if (origin === undefined) continue\n faults.push({\n path: '$.name',\n message:\n `the emitted file would both declare \\`${written}\\` and import it as ${origin} — ` +\n 'the declaration shadows the import, so name the screen something the file does not ' +\n 'already hold',\n })\n }\n}\n\n/* -------------------------------------------------------------------------- */\n/* The native screen contract */\n/* -------------------------------------------------------------------------- */\n\n/** Whether a platform is one a native screen emitter writes, held to the native screen contract. */\nexport const isNativePlatform = (platform: Platform): platform is NativePlatform =>\n platform === 'ios' || platform === 'android'\n\n/** The language each native platform's screen is written in, for a fault. */\nconst LANGUAGE: Readonly<Record<NativePlatform, string>> = { ios: 'Swift', android: 'Kotlin' }\n\n/** The toolkit each native platform's members are drawn with, for a fault. */\nconst TOOLKIT: Readonly<Record<NativePlatform, string>> = { ios: 'SwiftUI', android: 'Compose' }\n\n/** Where each native platform lists the members it does not draw yet. */\nconst PENDING_LIST: Readonly<Record<NativePlatform, string>> = {\n ios: 'packages/native/src/pending.ts',\n android: 'packages/native/src/kotlin-pending.ts',\n}\n\n/** The page archetype that frames an app's router rather than being a screen. */\nconst FRAME = 'AppShell'\n\n/** The tier of the page archetypes, which own the four load states on a native platform. */\nconst ARCHETYPES = 'archetypes'\n\n/** A page archetype's web state props, which `loadStatus` sets on a native platform. */\nconst STATUS_OWNED = ['empty', 'pending']\n\n/**\n * The action every page archetype takes on a native platform beside the\n * registry's props: loading again after it failed.\n */\nconst RETRY: SpecProp = { name: 'onRetry', type: '(() => void) | undefined', optional: true }\n\n/**\n * Words Swift has taken, which an input of an `ios` screen cannot be named,\n * because each input is a field of the model or the actions. `async` and\n * `await` are contextual, and taken too: the emitter's law reads them in the\n * file as asynchronous calls.\n */\nexport const SWIFT_KEYWORDS = new Set(\n [\n 'Any Self Type as associatedtype async await break case catch class continue default defer',\n 'deinit do else enum extension fallthrough false fileprivate for func guard if import in init',\n 'inout internal is let nil operator private protocol public repeat rethrows return self static',\n 'struct subscript super switch throw throws true try typealias var where while',\n ].flatMap((line) => line.split(' ')),\n)\n\n/**\n * Kotlin's hard keywords, which no property or function can be named\n * unescaped. An input of an `android` screen cannot take one, nor a name of\n * `Any`'s three functions, which every action interface already has.\n */\nexport const KOTLIN_KEYWORDS = new Set(\n [\n 'as break class continue do else false for fun if in interface is null object package return',\n 'super this throw true try typealias typeof val var when while',\n ].flatMap((line) => line.split(' ')),\n)\nconst KOTLIN_TAKEN = new Set([...KOTLIN_KEYWORDS, 'equals', 'hashCode', 'toString'])\n\n/** `InboxView` and `InboxScreen` → `Inbox`; a name with neither suffix is used whole. */\nexport function screenStem(name: string): string {\n return name.replace(/(View|Screen)$/, '')\n}\n\n/**\n * The names a native screen's file declares: the model, the actions and the\n * view on iOS; on Android also the inert actions, an object.\n */\nexport function nativeDeclarations(platform: NativePlatform, name: string): string[] {\n const stem = screenStem(name)\n return platform === 'ios'\n ? [`${stem}Model`, `${stem}Actions`, `${stem}View`]\n : [`${stem}Model`, `${stem}Actions`, `${stem}Screen`, `${stem}Inert`]\n}\n\n/**\n * Names the emitted file already uses from its platform, which a declaration\n * would shadow: every SwiftUI body draws through `AnyView` and `EmptyView`.\n */\nconst PLATFORM_NAMES: Readonly<Record<NativePlatform, ReadonlySet<string>>> = {\n ios: new Set(['AnyView', 'EmptyView', 'Group', 'Text', 'View']),\n android: new Set(['Composable', 'Text']),\n}\n\n/** A page archetype that owns the four load states: every archetype but the app's frame. */\nconst ownsLoadStatus = (component: SpecMember | undefined) =>\n component !== undefined && component.tier === ARCHETYPES && component.name !== FRAME\n\n/**\n * A member's props on the platform: on a natively emitted platform, a page\n * archetype also takes `onRetry`, which the native contract adds.\n */\nfunction withNativeProps(\n known: Surface | null,\n component: string,\n platform: Platform,\n): Surface | null {\n if (known === null || !isNativePlatform(platform)) return known\n if (!ownsLoadStatus(known.component) || component !== known.component?.name) return known\n if (known.props.has(RETRY.name)) return known\n const types = new Map(known.types)\n types.set(RETRY.name, RETRY)\n return { ...known, props: new Set(types.keys()), types }\n}\n\n/**\n * The native screen contract's faults (`design/native/screen-contract.md`),\n * each at the input or node it concerns, with what to do instead. One rule\n * holds on both native platforms; where its words differ, the platform's\n * language supplies them.\n *\n * - `loadStatus` is the model's first field, so no input takes the name, and\n * no input takes a word the platform's language has taken.\n * - Every input's type maps by the contract's table (`judges.nativeType`,\n * which needs the TypeScript parser and is left out where there is none).\n * - The root is a page archetype other than `AppShell`, because the archetype\n * draws the four load states.\n * - Every member the screen uses is one the platform's member package draws\n * (`judges.renders`, left out where the package is not at hand), because\n * the emitted file calls each and would not compile otherwise.\n * - A page archetype's `empty` and `pending` are unbound: the status sets them.\n * - A prop the registry types as a function is an event and is bound to an\n * action; any other prop, and every child, holds model data; no binding is a\n * path into an action, which has no fields.\n * - A grid member's `variant` and `tone` are one lawful cell on a native\n * platform, so they are literals and name one cell between them.\n * - A member whose children the registry types `string` takes one text.\n * - The file's declarations are not names `types` already gives it, nor a\n * name the file uses from its platform.\n */\nfunction checkNativeScreen(\n spec: ScreenSpec,\n platform: NativePlatform,\n components: Map<string, SpecMember>,\n primitives: Map<string, SpecPrimitive>,\n faults: SpecFault[],\n judges: SpecJudges,\n): void {\n const language = LANGUAGE[platform]\n const taken = platform === 'ios' ? SWIFT_KEYWORDS : KOTLIN_TAKEN\n const actions = new Set(\n spec.inputs.filter((input) => isActionType(input.type)).map((input) => input.name),\n )\n\n spec.inputs.forEach((input, index) => {\n const path = `$.inputs[${index}]`\n if (input.name === 'loadStatus') {\n faults.push({\n path: `${path}.name`,\n message:\n '`loadStatus` is the model’s first field, which the root archetype draws the four load ' +\n 'states from — name the input something else, and set the status in the app’s store',\n })\n } else if (taken.has(input.name)) {\n faults.push({\n path: `${path}.name`,\n message: `\\`${input.name}\\` is a word ${language} has taken — every input is a field of the model or the actions, and no field can be called that`,\n })\n }\n // A type that is not one TypeScript type has its fault already.\n const unparsed = judges.inputType === undefined ? null : judges.inputType(input.type)\n if (judges.nativeType === undefined || unparsed !== null) return\n const fault = judges.nativeType(input, spec)\n if (fault !== null) {\n faults.push({ path: `${path}.type`, message: `\\`${abbreviated(input.type)}\\` ${fault}` })\n }\n })\n\n const root = components.get(spec.root.component)\n if (!ownsLoadStatus(root)) {\n faults.push({\n path: '$.root',\n message:\n `a native screen’s root is a page archetype that draws the four load states, and ` +\n `\\`${spec.root.component}\\` is not one — use ListPage, DetailPage, FormPage, Dashboard, ` +\n 'SettingsPage, MasterDetailPage, SearchPage, ConversationPage or AuthPage' +\n (spec.root.component === FRAME ? '; AppShell is the app’s frame around its router' : ''),\n })\n }\n\n /** Every binding in a value that is a path into an action. */\n const intoActions = (value: SpecValue, path: string): void => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => intoActions(item, `${path}[${index}]`))\n } else if (isBinding(value)) {\n const [head = value.$, ...rest] = value.$.split('.')\n if (rest.length > 0 && actions.has(head)) {\n faults.push({\n path,\n message: `\\`${value.$}\\` is a path into the action \\`${head}\\`, and an action has no fields — bind \\`${head}\\` itself, or a model input`,\n })\n }\n } else if (isObjectValue(value)) {\n for (const [key, item] of Object.entries(value.$object)) intoActions(item, `${path}.${key}`)\n } else if (isElement(value)) {\n walk(value, path)\n }\n }\n\n const walk = (element: SpecElement, path: string): void => {\n const surface = withNativeProps(\n surfaceOf(element.component, components, primitives),\n element.component,\n platform,\n )\n const component = surface?.component\n const isOwner = component !== undefined && element.component === component.name\n const props = element.props ?? {}\n\n // A member the registry does not know has its fault already, and so has a\n // part the platform does not carry.\n if (\n surface !== null &&\n partFault(element.component, surface, platform, DEFAULT_FRAMEWORK) === null &&\n judges.renders !== undefined &&\n !judges.renders(element.component)\n ) {\n faults.push({\n path,\n message:\n `\\`${element.component}\\` has no ${TOOLKIT[platform]} rendering yet ` +\n `(\\`${PENDING_LIST[platform]}\\`), so a screen for ${platform} that uses it would not ` +\n 'compile — leave it out until it is drawn, or compose the screen from members that are',\n })\n }\n\n for (const [name, value] of Object.entries(props)) {\n const at = `${path}.props.${name}`\n intoActions(value, at)\n if (isOwner && ownsLoadStatus(component) && STATUS_OWNED.includes(name)) {\n faults.push({\n path: at,\n message: `\\`${element.component}\\`’s \\`${name}\\` is set from \\`loadStatus\\` on a native screen — remove it, and set the model’s \\`loadStatus\\` in the app’s store`,\n })\n continue\n }\n const declaredType = surface?.types.get(name)?.type\n if (declaredType === undefined) continue\n if (isActionType(declaredType)) {\n if (!isBinding(value)) {\n faults.push({\n path: at,\n message: `\\`${name}\\` is an event, and an event is handed an action — bind it to a function-typed input`,\n })\n } else if (!actions.has(value.$.split('.')[0] ?? value.$)) {\n faults.push({\n path: at,\n message: `\\`${name}\\` is an event, and \\`${value.$}\\` is model data — bind it to a function-typed input, an action`,\n })\n }\n } else if (isBinding(value) && actions.has(value.$)) {\n faults.push({\n path: at,\n message: `\\`${name}\\` holds data, and \\`${value.$}\\` is an action — bind it to a model input`,\n })\n }\n }\n\n if (isOwner && component.grid !== null) checkCell(component, props, path, faults)\n\n const children = element.children ?? []\n children.forEach((child, index) => {\n const at = `${path}.children[${index}]`\n if (isBinding(child) && actions.has(child.$)) {\n faults.push({\n path: at,\n message: `a child is drawn, and \\`${child.$}\\` is an action — bind a model input`,\n })\n }\n intoActions(child, at)\n })\n const childrenType = surface?.types.get('children')?.type\n const texts = (children.flat(Infinity as 1) as SpecValue[]).filter((child) => child !== null)\n if (\n childrenType !== undefined &&\n /^string( \\| undefined)?$/.test(childrenType) &&\n texts.length > 1\n ) {\n faults.push({\n path: `${path}.children`,\n message: `\\`${element.component}\\` takes its children as one text on a native screen, and this has ${texts.length} — join them in the app’s store and bind one input`,\n })\n }\n }\n walk(spec.root, '$.root')\n\n const declaredTypes = new Map<string, string>()\n for (const [module, names] of Object.entries(spec.types ?? {})) {\n for (const name of names) declaredTypes.set(name, module)\n }\n const stem = screenStem(spec.name)\n const written = nativeDeclarations(platform, spec.name)\n if (stem === '') {\n faults.push({\n path: '$.name',\n message: `\\`${spec.name}\\` leaves no name once its suffix is gone, and the file declares ${listed(written.map((name) => `\\`<Name>${name}\\``))} — name the screen for what it shows`,\n })\n return\n }\n for (const name of written) {\n const module = declaredTypes.get(name)\n if (module !== undefined) {\n faults.push({\n path: '$.name',\n message: `the emitted file declares \\`${name}\\`, which \\`types\\` also names from \\`${module}\\` — name the screen something else`,\n })\n }\n if (PLATFORM_NAMES[platform].has(name)) {\n faults.push({\n path: '$.name',\n message: `the emitted file declares \\`${name}\\`, which it also uses from ${TOOLKIT[platform]} — name the screen something else`,\n })\n }\n }\n}\n\n/**\n * A grid member's `variant` and `tone` on a native platform: one lawful cell,\n * written as literals, that the two name between them. Given alone, a half\n * must pair with one tone or variant only.\n */\nfunction checkCell(\n component: SpecMember,\n props: Record<string, SpecValue>,\n path: string,\n faults: SpecFault[],\n): void {\n const grid = component.grid as Readonly<Record<string, readonly string[]>>\n const variant = props['variant']\n const tone = props['tone']\n for (const [name, value] of [\n ['variant', variant],\n ['tone', tone],\n ] as const) {\n if (value !== undefined && typeof value !== 'string') {\n faults.push({\n path: `${path}.props.${name}`,\n message: `\\`${component.name}\\`’s variant and tone are one lawful cell on a native screen, chosen in the spec — write \\`${name}\\` as a literal`,\n })\n return\n }\n }\n if ((variant === undefined) === (tone === undefined)) return\n const cells = Object.entries(grid).flatMap(([cellVariant, tones]) =>\n tones.map((cellTone) => ({ variant: cellVariant, tone: cellTone })),\n )\n const matches = cells.filter((cell) =>\n variant === undefined ? cell.tone === tone : cell.variant === variant,\n )\n if (matches.length <= 1) return\n const [given, missing] = variant === undefined ? ['tone', 'variant'] : ['variant', 'tone']\n faults.push({\n path: `${path}.props.${given}`,\n message: `\\`${component.name}\\`’s variant and tone are one lawful cell on a native screen, and \\`${String(variant ?? tone)}\\` pairs with ${matches.map((cell) => `\\`${variant === undefined ? cell.variant : cell.tone}\\``).join(', ')} — give \\`${missing}\\` too`,\n })\n}\n\n/* -------------------------------------------------------------------------- */\n/* What a name resolves to */\n/* -------------------------------------------------------------------------- */\n\ninterface Surface {\n props: Set<string>\n /** The full prop records by name: the types the values are checked against. */\n types: Map<string, SpecProp>\n /** Present for a vocabulary member; absent for an exception primitive. */\n component?: SpecMember\n primitive?: SpecPrimitive\n /** Present for a compound part: its name in its member (`Panel` for `Dashboard.Panel`). */\n part?: string\n}\n\n/** A member's own props by name. A part's props, which `props` lists with the part's name, are left out. */\nfunction typesOf(props: readonly SpecProp[]): Map<string, SpecProp> {\n const map = new Map<string, SpecProp>()\n for (const prop of props) {\n if (!prop.name.includes('.')) map.set(prop.name, prop)\n }\n return map\n}\n\n/**\n * A component name, a compound part, or an exception primitive.\n *\n * A compound part is `SettingsRow.Group`, `Table.Row` or `Dashboard.Panel`:\n * a part the member's export carries, which the registry lists in `parts`\n * with the props its function takes. Whether the screen's framework or\n * platform carries the part is a second question, which `partFault` answers,\n * so a part React has is never reported as a name nobody knows.\n */\nfunction surfaceOf(\n name: string,\n components: Map<string, SpecMember>,\n primitives: Map<string, SpecPrimitive>,\n): Surface | null {\n const primitive = primitives.get(name)\n if (primitive) {\n const types = typesOf(primitive.props)\n return { props: new Set(types.keys()), types, primitive }\n }\n\n const direct = components.get(name)\n if (direct) {\n const types = typesOf(direct.props)\n return { props: new Set(types.keys()), types, component: direct }\n }\n\n // Exactly two segments. The name is printed as the element's tag, so anything\n // after a second dot would be unchecked text in a code position.\n const segments = name.split('.')\n const [owner, part] = segments\n const compound = owner === undefined ? undefined : components.get(owner)\n if (segments.length !== 2 || compound === undefined || part === undefined) return null\n\n const found = compound.parts.find((candidate) => candidate.name === part)\n if (found === undefined) return null\n const types = new Map(found.props.map((prop) => [prop.name, prop]))\n return { props: new Set(types.keys()), types, component: compound, part }\n}\n\n/**\n * The parts of a member a screen may compose where it is drawn: the ones the\n * framework or platform carries and the registry records the props of. The\n * registry reads a part's props from the React member, so a part only another\n * framework has (`Toast.Viewport`) has no record, and a spec cannot be checked\n * against it.\n */\nfunction composableParts(\n component: SpecMember,\n platform: Platform,\n framework: Framework,\n): string[] {\n const recorded = new Set(component.parts.map((part) => part.name))\n return shippedParts(component, platform, framework)\n .map((part) => part.name)\n .filter((name) => recorded.has(name))\n}\n\n/** `Table.Row`, `Table.Cell`: the parts of a member a screen may name, as a fault lists them. */\nfunction partNames(component: SpecMember, platform: Platform, framework: Framework): string {\n const names = composableParts(component, platform, framework).map(\n (part) => `\\`${component.name}.${part}\\``,\n )\n return names.length === 0\n ? `\\`${component.name}\\` has no parts`\n : `\\`${component.name}\\`’s parts are ${names.join(', ')}`\n}\n\n/**\n * A compound part the screen's framework or platform does not carry, as the\n * fault's message, or `null`.\n *\n * The system card lists a member's parts by the same rule (`shippedParts`).\n * React carries every part. A generated vocabulary carries the parts its\n * shell's files declare. A native platform carries the parts its contract\n * declares, so a screen that named another would not compile. The fault lists\n * the parts the member has there, because a bare refusal leaves the author to\n * guess the next name.\n */\nfunction partFault(\n name: string,\n known: Surface,\n platform: Platform,\n framework: Framework,\n): string | null {\n const { component, part } = known\n if (component === undefined || part === undefined) return null\n if (composableParts(component, platform, framework).includes(part)) return null\n const where = platform === DEFAULT_PLATFORM ? `in ${framework}` : `on ${platform}`\n return `\\`${name}\\` is not a part ${where} — ${partNames(component, platform, framework)} there`\n}\n\n/**\n * What to say of a name that is a known member and a part it does not have:\n * the parts it does have. `null` when the name is not that.\n */\nfunction partsOfOwner(\n name: string,\n components: Map<string, SpecMember>,\n platform: Platform,\n framework: Framework,\n): string | null {\n const segments = name.split('.')\n const [owner, part] = segments\n const component = owner === undefined ? undefined : components.get(owner)\n if (segments.length !== 2 || component === undefined) return null\n if (shippedParts(component, platform, framework).some((shipped) => shipped.name === part)) {\n return (\n ` — it is a part in ${framework} whose props the registry does not record, so a spec ` +\n 'cannot compose it'\n )\n }\n return ` — ${partNames(component, platform, framework)}`\n}\n\n/* -------------------------------------------------------------------------- */\n/* The platform */\n/* -------------------------------------------------------------------------- */\n\n/**\n * A member with no rendering on the screen's platform.\n *\n * The registry carries each member's entry on each platform, and an `absent`\n * entry names what to use instead. The fault names that substitute and gives\n * the entry's reason, because a fault that only said no would leave the author\n * to guess, and a guess is how a hand-built component starts. An `adapted`\n * member is lawful: it renders, only differently.\n *\n * A compound part answers through its owner, and only the owner is reported.\n * `Table.Row` sits inside a Table, so reporting every row of an absent Table\n * would repeat one fault once per row.\n */\nfunction checkPlatform(\n element: SpecElement,\n known: Surface,\n platform: Platform,\n path: string,\n faults: SpecFault[],\n): void {\n const owner = known.component ?? known.primitive\n if (owner === undefined || element.component !== owner.name) return\n\n const entry = owner.platforms[platform]\n if (entry.status !== 'absent') return\n\n const substitute = entry.substitute\n const instead =\n substitute === undefined || substitute === NO_SUBSTITUTE\n ? 'it has no substitute, so leave it out'\n : `use \\`${substitute}\\` instead`\n faults.push({\n path,\n message:\n `\\`${owner.name}\\` is absent on ${platform} — ${instead}` +\n (entry.reason === undefined ? '' : `. ${entry.reason}`),\n })\n}\n\n/**\n * A member the framework's vocabulary does not ship.\n *\n * The registry carries each member's entry in each web framework, and an\n * `absent` one says why. The fault gives that reason, so an author knows\n * whether to wait for a shell or compose something the framework has. As on a\n * platform, a compound part answers through its owner, once.\n */\nfunction checkFramework(\n element: SpecElement,\n known: Surface,\n framework: Framework,\n path: string,\n faults: SpecFault[],\n): void {\n const owner = known.component ?? known.primitive\n if (owner === undefined || element.component !== owner.name) return\n\n const entry = owner.frameworks[framework]\n if (entry.status !== 'absent') return\n faults.push({\n path,\n message:\n `\\`${owner.name}\\` is absent in ${framework}` +\n (entry.reason === undefined ? '' : ` — ${entry.reason}`),\n })\n}\n\n/* -------------------------------------------------------------------------- */\n/* Values against printed types */\n/* -------------------------------------------------------------------------- */\n\n/**\n * `null` when the value satisfies the printed type, or when the type is beyond\n * what a JSON validator can check. Otherwise the value, printed for the fault.\n *\n * Checkable parts: `string`/`number`/`boolean`, `null`, `true`/`false`, quoted\n * and numeric literals, and arrays of any of those. A structural print (parens,\n * braces, an arrow) or an unrecognised name (`ReactNode`) makes the whole union\n * uncheckable, so the value passes. Bindings, `$object`s and nested elements are\n * runtime shapes and pass through unchecked.\n *\n * **`null` is a value, not an absence.** If it were treated as a non-array\n * object, it would take the uncheckable-structure exit before the printed type\n * was consulted. Then `label: null` would validate against `string` on every\n * component in the vocabulary, and the emitted screen would render a Button\n * with no name. It is a scalar like any other, and it matches exactly one part:\n * `null`. `undefined` stays filtered out, because absence is the optional\n * flag's concern and the required-prop check above handles it. An explicit\n * `null` in a JSON document is something the author wrote.\n */\nfunction valueFault(printed: string, value: SpecValue): string | null {\n const scalar =\n value === null ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n if (!scalar) {\n if (!Array.isArray(value)) return null\n if (!value.every((item) => ['string', 'number', 'boolean'].includes(typeof item))) return null\n }\n if (/[(){}=>]/.test(printed)) return null\n\n const parts = printed\n .split('|')\n .map((part) => part.trim())\n .filter((part) => part !== '' && part !== 'undefined')\n\n let checkable = 0\n for (const part of parts) {\n const arrayForm = /^(readonly\\s+)?(.+)\\[\\]$/.exec(part)\n const element = arrayForm ? (arrayForm[2] as string) : null\n if (element !== null) {\n if (!partIsCheckable(element)) return null\n checkable += 1\n if (Array.isArray(value) && value.every((item) => scalarMatches(element, item))) return null\n continue\n }\n if (!partIsCheckable(part)) return null\n checkable += 1\n if (!Array.isArray(value) && scalarMatches(part, value)) {\n return null\n }\n }\n\n return checkable === 0 ? null : JSON.stringify(value)\n}\n\nfunction partIsCheckable(part: string): boolean {\n // `null` must be checkable. Otherwise a printed `string | null` could not check\n // its second part and would skip the *whole* union, which would open a wider\n // gap: `value: 42` on a nullable prop would pass.\n if (['string', 'number', 'boolean', 'null', 'true', 'false'].includes(part)) return true\n if (/^[\"'].*[\"']$/.test(part)) return true\n if (/^-?\\d+(\\.\\d+)?$/.test(part)) return true\n return false\n}\n\nfunction scalarMatches(part: string, value: unknown): boolean {\n if (part === 'string') return typeof value === 'string'\n if (part === 'number') return typeof value === 'number'\n if (part === 'boolean') return typeof value === 'boolean'\n if (part === 'null') return value === null\n if (part === 'true') return value === true\n if (part === 'false') return value === false\n const quoted = /^[\"'](.*)[\"']$/.exec(part)\n if (quoted) return value === quoted[1]\n if (/^-?\\d+(\\.\\d+)?$/.test(part)) return value === Number(part)\n return false\n}\n\n/* -------------------------------------------------------------------------- */\n/* The grid */\n/* -------------------------------------------------------------------------- */\n\n/**\n * The lawful cells, checked as data.\n *\n * A grid maps each variant to the tones lawful with it. Button has no neutral\n * *filled* cell, and at a call site that is a type error, not an ugly button. A\n * spec is not typechecked when it is written, so the same law is checked here.\n * This check is a main reason to validate a spec before emitting it, because\n * `variant: \"solid\", tone: \"neutral\"` is exactly the plausible combination an\n * agent invents.\n */\nfunction checkGrid(\n component: SpecMember,\n props: Record<string, SpecValue>,\n path: string,\n faults: SpecFault[],\n): void {\n const grid = component.grid\n if (!grid) return\n\n const variant = props['variant']\n const tone = props['tone']\n if (typeof variant !== 'string') return\n\n const tones = grid[variant]\n if (tones === undefined) {\n faults.push({\n path: `${path}.props.variant`,\n message: `\\`${component.name}\\` has no variant \\`${variant}\\` — it has ${Object.keys(grid).join(', ')}`,\n })\n return\n }\n\n if (typeof tone === 'string' && !tones.includes(tone)) {\n faults.push({\n path: `${path}.props.tone`,\n message: `\\`${component.name}\\` has no \\`${variant}\\` × \\`${tone}\\` cell — ${variant} takes ${tones.join(', ')}`,\n })\n }\n}\n\n/**\n * Icon roles, checked against the closed enum.\n *\n * This case is why the enum exists: *the closed role vocabulary kills a top\n * agent failure mode — hallucinated icon names become type errors*. In TSX they\n * are. In a spec they would be unchecked strings, and the screen would render\n * with a missing glyph. So the check must exist here too, or the guarantee\n * stops at the language boundary.\n *\n * The prop is found by the name `icon`, because every component that takes an\n * icon uses that name.\n */\nfunction checkIcons(\n registry: SpecVocabulary,\n props: Record<string, SpecValue>,\n path: string,\n faults: SpecFault[],\n): void {\n const icon = props['icon']\n if (typeof icon !== 'string') return\n\n const roles = registry.icons.roles.map((role) => role.name)\n if (roles.includes(icon)) return\n\n const near = roles.filter((role) => role.includes(icon) || icon.includes(role)).slice(0, 3)\n faults.push({\n path: `${path}.props.icon`,\n message:\n `\\`${icon}\\` is not an icon role — the set is closed` +\n (near.length === 0 ? '' : `, did you mean ${near.map((role) => `\\`${role}\\``).join(', ')}?`),\n })\n}\n\n/* -------------------------------------------------------------------------- */\n/* The ladder */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Declared exceptions, checked in both directions.\n *\n * An *undeclared* exception is the fault the exception ladder cares about. A\n * scope, bespoke zone or patch without a written reason is invisible deviation,\n * which the ladder exists to prevent. The reverse is also a fault. An\n * `exception` on a node that takes none makes the inventory overstate how far a\n * codebase has climbed, and an inventory nobody trusts is not read.\n */\nfunction checkException(\n element: SpecElement,\n known: Surface | null,\n path: string,\n faults: SpecFault[],\n): void {\n const needed = known?.primitive?.rung ?? (element.props?.[PATCH_PROP] !== undefined ? 3 : null)\n const declared = element.exception\n\n if (declared === undefined) {\n if (needed !== null) {\n faults.push({\n path,\n message:\n `\\`${element.component}\\` is a rung-${needed} exception and is not declared — add ` +\n `\"exception\": { \"rung\": ${needed}, \"because\": \"…\" }`,\n })\n }\n return\n }\n\n if (needed === null) {\n faults.push({\n path: `${path}.exception`,\n message: `\\`${element.component}\\` takes no exception — nothing here deviates from the vocabulary`,\n })\n return\n }\n\n if (!SPEC_RUNGS.includes(declared.rung)) {\n faults.push({\n path: `${path}.exception.rung`,\n message: `rung ${declared.rung} is not something a screen can declare — ${SPEC_RUNGS.join(', ')} are`,\n })\n } else if (declared.rung !== needed) {\n faults.push({\n path: `${path}.exception.rung`,\n message: `\\`${element.component}\\` is rung ${needed}, declared as rung ${declared.rung}`,\n })\n }\n\n // A reason that says nothing is effectively an undeclared exception. The\n // threshold is deliberately low but above zero.\n if (declared.because.trim().split(/\\s+/).length < 4) {\n faults.push({\n path: `${path}.exception.because`,\n message: 'say why the vocabulary was not enough — this is read by whoever finds it later',\n })\n }\n}\n\n/* -------------------------------------------------------------------------- */\n/* Corrections */\n/* -------------------------------------------------------------------------- */\n\nconst fold = (name: string) => name.replace(/[^a-z0-9]/gi, '').toLowerCase()\n\n/**\n * The same approach as the MCP server's. An agent told \"no\" with no alternative\n * builds its own, and a home-built component is invisible deviation.\n *\n * There are two lookups, because a wrong name arrives in two ways. A near miss\n * (`VStack`, `Dialogue`) is a substring away from the right name. An *industry*\n * term (`Modal`, `Snackbar`) is not, since no edit distance connects `Modal` to\n * `Dialog`. The purpose text connects them, because Dialog's opens \"Modal\n * interruption\". So the purposes are searched too.\n */\nfunction nearest(\n registry: SpecVocabulary,\n name: string,\n components: Map<string, SpecMember>,\n primitives: Map<string, SpecPrimitive>,\n): string {\n const wanted = fold(name)\n\n const byName = [...components.keys(), ...primitives.keys()].filter(\n (candidate) => fold(candidate).includes(wanted) || wanted.includes(fold(candidate)),\n )\n const lowered = name.toLowerCase()\n const byPurpose = registry.components\n .filter((component) => component.purpose.toLowerCase().includes(lowered))\n .map((component) => component.name)\n\n const near = [...new Set([...byName, ...byPurpose])].slice(0, 3)\n return near.length === 0 ? '' : ` — did you mean ${near.map((n) => `\\`${n}\\``).join(', ')}?`\n}\n\n/**\n * Long enough that `as` is not offered as a correction for `className`, which is\n * what an unbounded substring match does: \"classname\" contains \"as\".\n */\nconst SUGGESTION_FLOOR = 4\n\nfunction suggestProp(name: string, props: Set<string>): string {\n const wanted = fold(name)\n const near = [...props].filter((prop) => {\n const candidate = fold(prop)\n if (Math.min(candidate.length, wanted.length) < SUGGESTION_FLOOR) return false\n return candidate.includes(wanted) || wanted.includes(candidate)\n })\n return near.length === 0 ? '' : ` — did you mean \\`${near[0] as string}\\`?`\n}\n","import { validateSpec, type SpecFault } from '@polymorph/spec/validate'\n\nimport { isCallback, MAX_TYPE_LENGTH, typeTooLong } from './actions'\nimport { tooDeep, TOO_DEEP } from './depth'\nimport {\n allowedMembers,\n formPropOf,\n INHERITED_NAMES,\n inheritedNameFault,\n keyTooLong,\n MAX_KEY_LENGTH,\n memberFault,\n sharedNameFault,\n surfaceOf,\n type MemberOptions,\n type ScreenVocabulary,\n} from './members'\nimport {\n callbackOf,\n dataField,\n elementIn,\n fieldOf,\n holdsData,\n itemOf,\n notOneElement,\n objectName,\n takesElement,\n takesNode,\n undeclaredField,\n unreceivedCallback,\n withoutElements,\n type Receiver,\n} from './receivers'\nimport { addressFaults, ADDRESS_KEYS } from './urls'\nimport { VOCABULARY } from './vocabulary'\n\n/**\n * Whether a document is a screen a host may draw at run time.\n *\n * It is `validateSpec` (`packages/spec/src/validate.ts`) bound to the\n * run-time vocabulary table, so a page gets the faults the registry would\n * give with no registry in it, and the faults the walk adds for the document,\n * in the same shape and voice:\n *\n * - a member the host does not allow (`members`), with the reason when it\n * is one that hosts another library's code;\n * - an address a screen may not hold (`urls.ts`), at a prop or an object\n * key that takes one, by the walk's rule: text, or a flat list of text;\n * - a control's name that the screen's `values` cannot hold: one a control\n * before it in document order has, or one every object has (`__proto__`);\n * - an input type longer than `MAX_TYPE_LENGTH`;\n * - a callback input bound where no callback receives it, and an element in\n * a structured object's field that takes no node (`receivers.ts`).\n *\n * What the walk checks of the host's data (an address, a function) it checks\n * when it draws, as this reads only the document.\n *\n * A document nested deeper than `MAX_DEPTH` (`depth.ts`) is one fault, and is\n * not validated, as the validator reads it by recursion.\n *\n * It runs in a page and in Node alike. It reads only the document, and never\n * runs or inserts anything it holds.\n */\n\nexport interface ScreenCheckOptions extends MemberOptions {\n /** The vocabulary to check against. The generated table when absent. */\n vocabulary?: ScreenVocabulary\n}\n\nexport interface ScreenCheck {\n ok: boolean\n faults: SpecFault[]\n}\n\nexport function checkScreen(document: unknown, options: ScreenCheckOptions = {}): ScreenCheck {\n // The validator reads a document by recursion, so one nested deeper than any screen is refused\n // before it is read (`depth.ts`).\n const deep = tooDeep(document)\n if (deep !== null) return { ok: false, faults: [{ path: deep, message: TOO_DEEP }] }\n const vocabulary = options.vocabulary ?? VOCABULARY\n const { faults } = validateSpec(\n vocabulary,\n document,\n {},\n {\n ...(options.framework === undefined ? {} : { framework: options.framework }),\n },\n )\n const all = [\n ...faults,\n ...runTimeFaults(\n vocabulary,\n document,\n allowedMembers(vocabulary, options),\n new Set(faults.map(({ path }) => path)),\n ),\n ]\n return { ok: all.length === 0, faults: all }\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** Whether a value the document writes is an element. */\nconst isElementValue = (value: unknown): boolean =>\n isRecord(value) && typeof value['component'] === 'string'\n\n/**\n * The run-time faults of a document, in document order, by the validator's\n * paths (`$.root.props.emptyState.href`). It reads plain JSON, as a document\n * that fails the shape check is still read. `validated` holds the paths the\n * validator faults.\n */\nfunction runTimeFaults(\n vocabulary: ScreenVocabulary,\n document: unknown,\n allowed: ReadonlySet<string>,\n validated: ReadonlySet<string>,\n): SpecFault[] {\n const faults: SpecFault[] = []\n\n /**\n * A value at a key that takes an address, by the walk's rule (`addressFaults`): text that is an\n * address a screen may hold, or a flat list of such text. A binding is the host's data, which\n * the walk checks when it draws, and a value the validator faults already (one of the wrong\n * type) is not faulted twice.\n */\n const address = (key: string, value: unknown, path: string): void => {\n if (isRecord(value) && typeof value['$'] === 'string') return\n for (const fault of addressFaults(key, value, path)) {\n if (!validated.has(fault.path)) faults.push(fault)\n }\n }\n\n /** Where the control that holds each name is, in document order. */\n const named = new Map<string, string>()\n\n /**\n * A control's name, by the walk's rule: a name every object has is a fault, and so is a name a\n * control before it in document order has. A name the host's data gives is the walk's to check.\n */\n const name = (component: string, props: Record<string, unknown>, path: string): void => {\n const surface = surfaceOf(vocabulary, component)\n const given = props['name']\n if (surface === null || formPropOf(surface) === null) return\n if (typeof given !== 'string' || given === '') return\n const at = `${path}.props.name`\n if (INHERITED_NAMES.has(given)) {\n faults.push({ path: at, message: inheritedNameFault(given) })\n return\n }\n const before = named.get(given)\n if (before !== undefined) faults.push({ path: at, message: sharedNameFault(given, before) })\n named.set(given, path)\n }\n\n /** A run-time fault, unless the validator faults the same path already. */\n const fault = (path: string, message: string): void => {\n if (!validated.has(path)) faults.push({ path, message })\n }\n\n // The callback inputs, which the walk hands only to a callback receiver (`receivers.ts`), and\n // the types too long to read, which are data with no value.\n const callbacks = new Set<string>()\n const inputs = isRecord(document) ? document['inputs'] : undefined\n if (Array.isArray(inputs)) {\n inputs.forEach((input, at) => {\n if (!isRecord(input) || typeof input['name'] !== 'string') return\n const type = input['type']\n if (typeof type !== 'string') return\n if (type.length > MAX_TYPE_LENGTH) {\n fault(`$.inputs[${at}].type`, typeTooLong(input['name'], type.length))\n } else if (isCallback(type)) callbacks.add(input['name'])\n })\n }\n\n /** A value written at `path`, where `receiver` is the type that receives it. */\n /**\n * A value written at `path`, where `receiver` is the type that receives it. `unnamed` is set\n * below an element the walk does not draw for a prop it requires and was never written, whose\n * controls hold no name in `values`.\n */\n const visit = (value: unknown, path: string, receiver: Receiver, unnamed = false): void => {\n if (Array.isArray(value)) {\n const item = itemOf(vocabulary, receiver)\n value.forEach((entry, index) => visit(entry, `${path}[${index}]`, item, unnamed))\n return\n }\n if (!isRecord(value)) return\n if (typeof value['$'] === 'string') {\n const binding = value['$']\n if (callbacks.has(binding) && callbackOf(vocabulary, receiver) === null) {\n fault(path, unreceivedCallback(binding))\n }\n return\n }\n if (typeof value['component'] === 'string') {\n const component = value['component']\n const member = memberFault(vocabulary, component, allowed)\n if (member !== null) faults.push({ path, message: member })\n const surface = surfaceOf(vocabulary, component)\n const types = new Map((surface?.props ?? []).map((prop) => [prop.name, prop.type]))\n const props = isRecord(value['props']) ? value['props'] : {}\n // The walk does not draw an element that lacks a required data prop or a required prop\n // that takes one element (a SettingsRow's control).\n const lacks = (surface?.props ?? []).some(\n (prop) =>\n !prop.optional &&\n prop.name !== 'children' &&\n !isCallback(prop.type) &&\n (!takesNode(vocabulary, prop.type) || takesElement(vocabulary, prop.type)) &&\n !Object.prototype.hasOwnProperty.call(props, prop.name),\n )\n const silent = unnamed || lacks\n // In document order an element comes before what its props and children hold.\n if (!silent) name(component, props, path)\n for (const [key, item] of Object.entries(props)) {\n if (key.length > MAX_KEY_LENGTH) {\n fault(path, keyTooLong(key.length))\n continue\n }\n const at = `${path}.props.${key}`\n // A prop that takes one element is handed only an element; the walk leaves anything else\n // out, a binding included, as the host's data holds no element.\n if (takesElement(vocabulary, types.get(key) ?? null) && !isElementValue(item)) {\n fault(at, notOneElement(key))\n }\n if (ADDRESS_KEYS.has(key)) address(key, item, at)\n visit(item, at, types.get(key) ?? null, silent)\n }\n visit(value['children'], `${path}.children`, types.get('children') ?? null, silent)\n return\n }\n const fields = value['$object']\n if (isRecord(fields)) {\n for (const [key, item] of Object.entries(fields)) {\n if (key.length > MAX_KEY_LENGTH) {\n fault(path, keyTooLong(key.length))\n continue\n }\n const at = `${path}.${key}`\n const field = fieldOf(vocabulary, receiver, key)\n let held: unknown = item\n if (field !== null && !takesNode(vocabulary, field?.type ?? 'never')) {\n const type = objectName(vocabulary, receiver)\n const message = field === undefined ? undeclaredField(key, type) : dataField(key, type)\n if (holdsData(vocabulary, field)) {\n const kept = withoutElements(item)\n if (kept.removed) fault(at, message)\n if (kept.value === undefined) continue\n held = kept.value\n } else if (elementIn(item)) {\n fault(at, message)\n continue\n }\n }\n if (ADDRESS_KEYS.has(key)) address(key, held, at)\n visit(held, at, field?.type ?? null, unnamed)\n }\n }\n }\n\n if (isRecord(document)) visit(document['root'], '$.root', null)\n return faults\n}\n"],"mappings":";;;;;AAqIA,IAAMqC,IAAa;CAAC;CAAG;CAAG;AAAC,GAgBrBC,IAAW,IAAI,IACnB;CAEE;CACA;CACA;CAEA;CAEA;AACF,CAAC,CAAC,SAAS,MAASC,EAAK,MAAM,GAAG,CAAC,CACrC,GAGMC,KAAa,SAoEbC,KACJ;AAGF,SAAgBC,GACd,GACA,GACA,IAAqB,CAAC,GACtB,IAAuB,CAAC,GACR;CAKhB,IAAMC,IAAcC,EAAcC,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