@webority/canvas-kit 0.148.0 → 0.150.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,69 +1,32 @@
1
- import type { ComponentUsage } from "./meta.js";
2
-
3
- // The manifest a kit release folder carries as manifest.json. build.js writes it for a product kit, and
4
- // publish-fleet-kit.mjs writes it for a fleet kit. The release row holds the same JSON, and the CLI reads an offline copy.
5
-
6
- // Which kit a document's root carries. A product kit is "Product"; the two fleet kits are the Webority kits.
1
+ import type { ComponentUsage } from "./meta.ts";
2
+ import { type MetaEntry } from "./metas.ts";
7
3
  export type CanvasKitKind = "WeborityWeb" | "WeborityPhone" | "Product";
8
-
9
4
  export type CanvasKitPlatform = "Web" | "Phone";
10
-
11
- // The type a prop takes in the manifest. A "url" is a string prop named like a link; an "icon" is a node slot that
12
- // takes a library icon.
13
- export type CanvasManifestPropType =
14
- | "any"
15
- | "array"
16
- | "boolean"
17
- | "enum"
18
- | "enumOrNumber"
19
- | "icon"
20
- | "node"
21
- | "number"
22
- | "object"
23
- | "string"
24
- | "stringOrNumber"
25
- | "url";
26
-
5
+ export type CanvasManifestPropType = "any" | "array" | "boolean" | "enum" | "enumOrNumber" | "icon" | "node" | "number" | "object" | "string" | "stringOrNumber" | "url";
27
6
  export interface CanvasManifestProp {
28
7
  name: string;
29
8
  type: CanvasManifestPropType;
30
- // The values an enum prop takes: strings, numbers (a numeric literal union, sorted), or both. On an enumOrNumber
31
- // prop, its named values; the prop also takes any number.
32
- enum?: (string | number)[];
33
- // The fields of an object prop.
34
- fields?: CanvasManifestProp[];
35
- // The fields of each item of an array prop. A list whose items carry href or to takes the action on the Web.
36
- itemFields?: CanvasManifestProp[];
9
+ enum?: (string | number)[] | undefined;
10
+ fields?: CanvasManifestProp[] | undefined;
11
+ itemFields?: CanvasManifestProp[] | undefined;
37
12
  required: boolean;
38
- // The prop takes null as a value. Written only when it does.
39
- nullable?: true;
40
- description?: string;
41
- // The value the component applies when the prop is left out, as JSON.
13
+ nullable?: true | undefined;
14
+ description?: string | undefined;
42
15
  default?: unknown;
43
16
  }
44
-
45
17
  export interface CanvasManifestComponent {
46
- // The component's name as a document places it.
47
18
  name: string;
48
- // The data-wui value the importer matches: the App* name on the component's outermost element. Null means the
49
- // importer never places this component.
50
19
  marker: string | null;
51
20
  acceptsChildren: boolean;
52
21
  props: CanvasManifestProp[];
53
22
  itemsTakeAction: string[];
54
23
  takesAction: string[];
55
- // The package the component comes from. A product's own component names its source file.
56
24
  source: string;
57
- // The export the component draws, when it is not its name.
58
- component?: string;
59
- // Props the kit sets on every placement; code export writes them on the export.
60
- fixedProps?: Record<string, unknown>;
61
- role?: "title" | "navigation";
62
- // Present on every Web component; absent on Phone until its metas carry usage.
63
- usage?: ComponentUsage;
64
- }
65
-
66
- // The token names of a kit's vocabulary, by group. The colour names carry their meanings from the theme.
25
+ component?: string | undefined;
26
+ fixedProps?: Record<string, unknown> | undefined;
27
+ role?: "title" | "navigation" | undefined;
28
+ usage?: ComponentUsage | undefined;
29
+ }
67
30
  export interface CanvasManifestTokens {
68
31
  color: string[];
69
32
  space: string[];
@@ -71,13 +34,9 @@ export interface CanvasManifestTokens {
71
34
  shadow: string[];
72
35
  font: string[];
73
36
  text: string[];
74
- // The line height roles, such as heading and body.
75
37
  leading: string[];
76
- colorMeanings?: Record<string, string>;
38
+ colorMeanings?: Record<string, string> | undefined;
77
39
  }
78
-
79
- // Each token's value, so the importer can draw a kit's values into a file's theme. Null on a release built before
80
- // this field existed; a token lift from such a release is refused until the release is rebuilt.
81
40
  export interface CanvasManifestTokenValues {
82
41
  color: Record<string, CanvasManifestColorValue>;
83
42
  space: Record<string, number>;
@@ -85,47 +44,37 @@ export interface CanvasManifestTokenValues {
85
44
  shadow: Record<string, CanvasShadow | null>;
86
45
  font: Record<string, CanvasManifestFontValue>;
87
46
  text: Record<string, CanvasManifestTextValue>;
88
- // Unitless line height per role.
89
47
  leading: Record<string, number>;
90
48
  }
91
-
92
- // Lengths in px at scale 1. `color` is the resolved colour with its opacity in the alpha.
93
49
  export interface CanvasShadow {
94
50
  x: number;
95
51
  y: number;
96
52
  blur: number;
97
53
  spread: number;
98
54
  color: string;
99
- // Phone only: the Android elevation, when the token sets one.
100
- elevation?: number;
55
+ elevation?: number | undefined;
101
56
  }
102
-
103
57
  export interface CanvasManifestColorValue {
104
58
  light: string;
105
59
  dark: string;
106
60
  }
107
-
108
61
  export interface CanvasManifestFontValue {
109
62
  family: string;
110
63
  fallback: string;
111
64
  }
112
-
113
65
  export interface CanvasManifestTextValue {
114
66
  size: number;
115
- weight?: number | null;
67
+ weight?: number | null | undefined;
116
68
  }
117
-
118
69
  export interface CanvasManifestStyleKey {
119
70
  name: string;
120
71
  type: string;
121
72
  values: string[];
122
73
  appliesTo: string;
123
- phoneSupported: boolean;
74
+ phoneSupported?: boolean | undefined;
124
75
  description: string;
125
76
  }
126
-
127
77
  export interface CanvasManifest {
128
- // The document kind the release serves: a fleet kit's kind, or "Product" for a product kit.
129
78
  kind: CanvasKitKind;
130
79
  library: {
131
80
  name: string;
@@ -139,42 +88,27 @@ export interface CanvasManifest {
139
88
  tokens: CanvasManifestTokens;
140
89
  tokenValues: CanvasManifestTokenValues | null;
141
90
  icons: string[];
142
- // A product release no longer carries style keys; the embedded Webority manifests keep them as the renderer's table.
143
- styleKeys?: CanvasManifestStyleKey[];
144
- // Present on every release built by a canvas-kit that reads rename tables; absent on older releases.
145
- renames?: CanvasManifestRename[];
146
- }
147
-
148
- // A component rename of one library release, as Canvas applies it to a stored document. `name` is the component's name before
149
- // the release; `to` its name after it when the release renamed it. `props` maps old prop names to new. `values` maps, per new
150
- // prop name, old literal values to new. `added` lists props the release sets on a converted element that lacks them. `removed`
151
- // lists props the release dropped, with the table's hint; Canvas drops them on a move and reports the hint.
91
+ styleKeys?: CanvasManifestStyleKey[] | undefined;
92
+ renames?: CanvasManifestRename[] | undefined;
93
+ }
152
94
  export interface CanvasManifestComponentRename {
153
95
  name: string;
154
- to?: string;
96
+ to?: string | undefined;
155
97
  props: Record<string, string>;
156
98
  values: Record<string, Record<string, string>>;
157
99
  added: Record<string, string | number | boolean>;
158
100
  removed: Record<string, string>;
159
101
  }
160
-
161
- // The renames of one library release, projected from its rename table for this kit's package. `values` holds the table's
162
- // component-independent value renames, keyed by prop name. A manifest lists one entry per table at or below its library version.
163
102
  export interface CanvasManifestRename {
164
103
  version: string;
165
104
  components: CanvasManifestComponentRename[];
166
105
  values: Record<string, Record<string, string>>;
167
106
  }
168
-
169
107
  export interface CanvasReleaseFileStamp {
170
108
  sha256: string;
171
109
  bytes: number;
172
110
  }
173
-
174
- // release.json: stamps each content file with its SHA-256 and byte count. A file that no longer matches its stamp
175
- // makes the release unreadable, because a published release never changes.
176
111
  export interface CanvasReleaseStamp {
177
- // The kit key, which is also the release folder's first level under Webority.Canvas.Kits.
178
112
  name: string;
179
113
  version: string;
180
114
  platform: CanvasKitPlatform;
@@ -190,3 +124,59 @@ export interface CanvasReleaseStamp {
190
124
  "kit.css": CanvasReleaseFileStamp;
191
125
  };
192
126
  }
127
+ type Obj = Record<string, unknown>;
128
+ interface PackageJson {
129
+ name: string;
130
+ version: string;
131
+ main?: string | undefined;
132
+ types?: string | undefined;
133
+ exports?: Obj | undefined;
134
+ dependencies?: Record<string, string> | undefined;
135
+ devDependencies?: Record<string, string> | undefined;
136
+ peerDependencies?: Record<string, string> | undefined;
137
+ }
138
+ interface LibraryFiles {
139
+ dir: string;
140
+ pkg: PackageJson;
141
+ isSelf: boolean;
142
+ typesFile: string;
143
+ entryFile: string;
144
+ canvasKitFile: string | null;
145
+ }
146
+ type PhoneItemActions = Partial<Record<"itemsTakeAction" | "takesAction", Record<string, string[]>>>;
147
+ interface PhoneSupport {
148
+ flags: Record<string, boolean>;
149
+ itemActions: PhoneItemActions;
150
+ }
151
+ interface ProductModule {
152
+ module: string;
153
+ exportName: string;
154
+ fixedProps: Readonly<Record<string, unknown>> | undefined;
155
+ }
156
+ export interface ReadManifestResult {
157
+ manifest: CanvasManifest;
158
+ warnings: string[];
159
+ phoneChromeNames: string[];
160
+ productModules: Map<string, ProductModule>;
161
+ metas: MetaEntry[];
162
+ }
163
+ export declare function libraryFiles(root: string, libraryPackage: string): LibraryFiles;
164
+ export declare function readPhoneSupport(file: string): PhoneSupport;
165
+ export interface ReadManifestOptions {
166
+ projectRoot: string;
167
+ kit?: string | undefined;
168
+ platform: string;
169
+ entry?: unknown;
170
+ components?: string | undefined;
171
+ tokens?: string | undefined;
172
+ libraryPackage: string;
173
+ rolesFile?: string | undefined;
174
+ rendererProtocolVersion: number;
175
+ phoneRendererSupportFile?: string | undefined;
176
+ styleKeysFile?: string | undefined;
177
+ renamesDir?: string | undefined;
178
+ }
179
+ export declare function readManifest({ projectRoot, kit, platform, entry, components, tokens, libraryPackage, rolesFile, rendererProtocolVersion, phoneRendererSupportFile, styleKeysFile, renamesDir, }: ReadManifestOptions): Promise<ReadManifestResult>;
180
+ export declare function parseCanvasReleaseStamp(value: unknown, file: string): CanvasReleaseStamp;
181
+ export declare function parseCanvasManifest(value: unknown, file: string): CanvasManifest;
182
+ export {};
package/dist/manifest.js CHANGED
@@ -1 +1 @@
1
- import{NOT_DRAWN_FILE as e,checkDrawn as t,componentExports as n,readNotDrawn as r}from"./drawn.js";import{findPackageDir as i,readJson as a,toPosix as o}from"./files.js";import"./kitModule.js";import{checkMetaTypes as s}from"./metaCheck.js";import{ROLES as c,componentModuleOf as l,manifestComponent as u,readMetas as d}from"./metas.js";import{applyPhoneActions as f,phoneChromeEntries as ee,phoneIcons as p}from"./phone.js";import{readRenamesWithWarnings as te}from"./renames.js";import{tokensFromV2 as m,webIcons as h}from"./tokens.js";import{existsSync as g}from"node:fs";import{join as _,relative as ne,resolve as v}from"node:path";var y=/^[a-z][a-z0-9-]{1,39}$/,b=[`Web`,`Phone`],x={Web:`WeborityWeb`,Phone:`WeborityPhone`},S={Web:`web`,Phone:`phone`};function C(e,t){let n=_(e,`package.json`),r=g(n)&&a(n).name===t,o=r?e:i(e,t);if(!o)throw Error(`${t} is not installed for ${e}. Run pnpm install there.`);let s=a(_(o,`package.json`)),c=(e,t)=>{if(typeof e==`string`)return t==="default"?e:void 0;if(e&&typeof e==`object`)return typeof e[t]==`string`?e[t]:c(e.import,t)??c(e.default,t)},l=s.exports?.[`.`],u=s.types??c(l,`types`),d=c(l,`default`)??s.main;if(!u)throw Error(`${t} declares no types, and the manifest reads its declaration files.`);if(!d)throw Error(`${t} declares no entry file for its runtime.`);let f=c(s.exports?.[`./canvasKit`],`default`);return{dir:o,pkg:s,isSelf:r,typesFile:_(o,u),entryFile:_(o,d),canvasKitFile:f?_(o,f):null}}function re(e,t,n){let r=a(_(e,`package.json`)),i=r.dependencies?.[t]??r.devDependencies?.[t];if(/^\d+\.\d+\.\d+$/.test(i??``)&&i!==n)throw Error(`${t} is pinned to ${i} in package.json but ${n} is installed. Run pnpm install first.`)}function ie(e,t,n){let r=e.pkg.exports?.[`./canvas-kit/*`];if(typeof r!=`string`)throw Error(`${t} exports no ./canvas-kit/*; a product kit takes the library's components from its kit release.`);let i=_(e.dir,r.replace(`*`,`manifest.json`)),o=a(i);if(!(o?.kind===x[n]&&o.platform===n&&Array.isArray(o.components)&&Array.isArray(o.icons)))throw Error(`${i} is not a ${n} library kit release.`);return o}function w(e,t){let n=S[t];for(let{meta:r,file:i}of e)if(!r.platforms?.includes(n))throw Error(`${i}: platforms: a ${t} kit lists only components that list ${n}`)}function T(e,t){if(!t)return;let n=a(t);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`${t} must be an object from component name to role.`);for(let[r,i]of Object.entries(n)){let n=e.find(e=>e.name===r);if(!n)throw Error(`${t} names ${r}, which the kit does not have.`);if(!c.includes(i))throw Error(`${t}: ${r} has role ${JSON.stringify(i)}; a role is title or navigation.`);n.role=i}}function ae(e){let t=a(e);if(!Array.isArray(t)||t.some(e=>typeof e?.name!=`string`))throw Error(`${e} must be the style key table: a list of style keys, each with a name.`);return t}function E(e){let t=a(e);if(t?.schema!==1)throw Error(`${e} has schema ${t?.schema}; this reader reads schema 1.`);if(!t.itemActions)throw Error(`${e} has no itemActions; the phone kit's action lists come from it.`);return{flags:t.styleKeys??{},itemActions:t.itemActions}}function D(e,t,n){let r=e.map(({name:e})=>e),i=r.filter(e=>typeof t[e]!=`boolean`),a=Object.keys(t).filter(e=>!r.includes(e));if(i.length>0||a.length>0)throw Error(`${n} must list exactly the style keys of the style key table, each true or false. Missing or not a boolean: ${i.join(`, `)||`none`}. Not in the table: ${a.join(`, `)||`none`}.`)}function O(e,t){return e.map(({name:e,type:n,values:r,appliesTo:i,description:a})=>({name:e,type:n,values:r,appliesTo:i,...t?{phoneSupported:t[e]}:{},description:a}))}var oe=(e,t)=>e.name<t.name?-1:+(e.name>t.name);async function k({projectRoot:a,kit:c,platform:g,entry:S,components:k,tokens:A,libraryPackage:j,rolesFile:M,rendererProtocolVersion:N,phoneRendererSupportFile:P,styleKeysFile:F,renamesDir:I}){if(!y.test(c??``))throw Error(`kit ${JSON.stringify(c)} must be 2 to 40 characters: lowercase letters, digits and hyphens, starting with a letter.`);if(!b.includes(g))throw Error(`platform must be Web or Phone, not ${JSON.stringify(g)}.`);if(!Number.isInteger(N)||N<1)throw Error(`rendererProtocolVersion must be a positive integer, not ${JSON.stringify(N)}.`);if(S!==void 0)throw Error(`A kit lists its components with components, a glob of .meta.js files; entry is retired.`);if(typeof k!=`string`||k===``||typeof A!=`string`||A===``)throw Error(`A kit needs components, a glob of .meta.js files, and tokens, the path of its webority-theme-tokens/2 file.`);let L=v(a),R=C(L,j),z=R.isSelf;if(g===`Phone`&&!P&&!z)throw Error(`A Phone product kit needs phoneRendererSupportFile, the phone renderer's support file; only a phone library's own kit release builds without it.`);z||re(L,j,R.pkg.version);let B=P?E(P):null,V=g===`Phone`?B:null,H=F?ae(F):null;H&&B&&D(H,B.flags,P);let U=z?null:ie(R,j,g),W;W=z?g===`Web`?h(_(R.dir,`dist`)):p(_(R.dir,`lib`,`typescript`,`module`,`components`,`AppIcon`,`catalog.g.d.ts`)):U.icons;let G=[];z&&(G=await d({root:L,components:k,icons:W}),w(G,g),t({libraryPackage:j,exported:n({root:L,typesFile:R.typesFile}),drawnNames:G.map(({meta:e})=>({name:e.name,component:e.component??e.name})),notDrawn:r(_(R.dir,e))}),g===`Web`&&s({root:L,metas:G,componentOf:()=>R.typesFile}));let K=[],q=new Map;if(!z){let e=U.components.map(({name:e})=>e);K=await d({root:L,components:k,knownNames:e,icons:W}),w(K,g);let t=K.map(({meta:e})=>e.name).filter(t=>e.includes(t));if(t.length>0)throw Error(`The kit names ${t.join(`, `)} as ${j} already has them; rename the product components.`);g===`Web`&&s({root:L,metas:K,componentOf:(e,t)=>l(e,t)});for(let{meta:e,file:t}of K)q.set(e.name,{module:l(t,e.component??e.name),exportName:e.component??e.name,fixedProps:e.fixedProps})}let J=[];if(g===`Phone`){if(!R.canvasKitFile)throw Error(`${j} exports no ./canvasKit subpath; a Phone kit takes the device frame parts from it.`);J=ee(R.canvasKitFile,j)}if(z&&g===`Phone`){let e=new Set(G.map(({meta:e})=>e.name)),t=J.filter(({name:t})=>e.has(t)).map(({name:e})=>e);if(t.length>0)throw Error(`${j} exports ${t.join(`, `)} from both its main entry and ./canvasKit.`)}let se=z?G.map(({meta:e})=>u(e,{platform:g,source:j})):U.components,ce=K.map(({meta:e})=>u(e,{platform:g,source:o(ne(L,q.get(e.name).module))})),Y=[...se,...z?J:[],...ce].sort(oe);V&&f(Y,V.itemActions),T(Y,M);let X=i(L,`@webority/tokens`);if(!X)throw Error(`@webority/tokens is not installed for ${L}. Run pnpm install there.`);let Z=m(v(L,A),_(X,`dist`,`meanings.json`),g),Q={kind:z?x[g]:`Product`,library:{name:R.pkg.name,version:R.pkg.version},rendererProtocolVersion:N,platform:g,kitModuleVersion:2,productKit:null,components:Y,tokens:Z.tokens,tokenValues:Z.tokenValues,icons:W,...H?{styleKeys:O(H,V?V.flags:null)}:{}},$=[];if(I!==void 0){let e=te(I,j,R.pkg.version,Y);Q.renames=e.renames,$.push(...e.warnings)}return{manifest:Q,warnings:$,phoneChromeNames:J.map(({name:e})=>e),productModules:q,metas:z?G:K}}export{C as libraryFiles,k as readManifest,E as readPhoneSupport};
1
+ import{NOT_DRAWN_FILE as e,checkDrawn as t,componentExports as n,readNotDrawn as r}from"./drawn.js";import{findPackageDir as i,isRecord as a,readJson as o,toPosix as s}from"./files.js";import"./kitModule.js";import{checkMetaTypes as c}from"./metaCheck.js";import{ROLES as l,componentModuleOf as u,manifestComponent as d,readMetas as f}from"./metas.js";import{applyPhoneActions as ee,phoneChromeEntries as te,phoneIcons as ne,toManifestComponent as re}from"./phone.js";import{readRenamesWithWarnings as ie}from"./renames.js";import{tokensFromV2 as ae,webIcons as oe}from"./tokens.js";import{existsSync as p}from"node:fs";import{join as m,relative as se,resolve as h}from"node:path";var ce=/^[a-z][a-z0-9-]{1,39}$/,g=[`Web`,`Phone`],_={Web:`WeborityWeb`,Phone:`WeborityPhone`},v={Web:`web`,Phone:`phone`},y=[`WeborityWeb`,`WeborityPhone`,`Product`],b=[`any`,`array`,`boolean`,`enum`,`enumOrNumber`,`icon`,`node`,`number`,`object`,`string`,`stringOrNumber`,`url`];function x(e){return y.some(t=>t===e)}function S(e){return b.some(t=>t===e)}function C(e){return g.some(t=>t===e)}function w(e){return l.some(t=>t===e)}function T(e,t){if(typeof e==`string`)return t==="default"?e:void 0;if(!a(e))return;let n=e[t];return typeof n==`string`?n:T(e.import,t)??T(e.default,t)}function E(e,t){let n=m(e,`package.json`),r=p(n)&&$(o(n),n).name===t,a=r?e:i(e,t);if(!a)throw Error(`${t} is not installed for ${e}. Run pnpm install there.`);let s=m(a,`package.json`),c=$(o(s),s),l=c.exports?.[`.`],u=c.types??T(l,`types`),d=T(l,`default`)??c.main;if(!u)throw Error(`${t} declares no types, and the manifest reads its declaration files.`);if(!d)throw Error(`${t} declares no entry file for its runtime.`);let f=T(c.exports?.[`./canvasKit`],`default`);return{dir:a,pkg:c,isSelf:r,typesFile:m(a,u),entryFile:m(a,d),canvasKitFile:f?m(a,f):null}}function le(e,t,n){let r=m(e,`package.json`),i=$(o(r),r),a=i.dependencies?.[t]??i.devDependencies?.[t];if(/^\d+\.\d+\.\d+$/.test(a??``)&&a!==n)throw Error(`${t} is pinned to ${a} in package.json but ${n} is installed. Run pnpm install first.`)}function ue(e,t,n){let r=e.pkg.exports?.[`./canvas-kit/*`];if(typeof r!=`string`)throw Error(`${t} exports no ./canvas-kit/*; a product kit takes the library's components from its kit release.`);let i=m(e.dir,r.replace(`*`,`manifest.json`)),a=Re(o(i),i);if(a.kind!==_[n]||a.platform!==n)throw Error(`${i} is not a ${n} library kit release.`);return a}function D(e,t){let n=v[t];for(let{meta:r,file:i}of e)if(!r.platforms?.includes(n))throw Error(`${i}: platforms: a ${t} kit lists only components that list ${n}`)}function de(e,t){if(!t)return;let n=o(t);if(!a(n)||Array.isArray(n))throw Error(`${t} must be an object from component name to role.`);for(let[r,i]of Object.entries(n)){let n=e.find(e=>e.name===r);if(!n)throw Error(`${t} names ${r}, which the kit does not have.`);if(typeof i!=`string`||!w(i))throw Error(`${t}: ${r} has role ${JSON.stringify(i)}; a role is title or navigation.`);n.role=i}}function fe(e){return ze(o(e),e)}function O(e){let t=Ve(o(e),e);if(t.schema!==1)throw Error(`${e} has schema ${t.schema}; this reader reads schema 1.`);if(!t.itemActions)throw Error(`${e} has no itemActions; the phone kit's action lists come from it.`);return{flags:t.styleKeys??{},itemActions:t.itemActions}}function pe(e,t,n){let r=e.map(({name:e})=>e),i=r.filter(e=>typeof t[e]!=`boolean`),a=Object.keys(t).filter(e=>!r.includes(e));if(i.length>0||a.length>0)throw Error(`${n} must list exactly the style keys of the style key table, each true or false. Missing or not a boolean: ${i.join(`, `)||`none`}. Not in the table: ${a.join(`, `)||`none`}.`)}function me(e,t){return e.map(({name:e,type:n,values:r,appliesTo:i,description:a})=>({name:e,type:n,values:r,appliesTo:i,...t?{phoneSupported:t[e]}:{},description:a}))}var he=(e,t)=>e.name<t.name?-1:+(e.name>t.name);async function k({projectRoot:a,kit:o,platform:l,entry:p,components:g,tokens:v,libraryPackage:y,rolesFile:b,rendererProtocolVersion:x,phoneRendererSupportFile:S,styleKeysFile:w,renamesDir:T}){if(!ce.test(o??``))throw Error(`kit ${JSON.stringify(o)} must be 2 to 40 characters: lowercase letters, digits and hyphens, starting with a letter.`);if(!C(l))throw Error(`platform must be Web or Phone, not ${JSON.stringify(l)}.`);if(!Number.isInteger(x)||x<1)throw Error(`rendererProtocolVersion must be a positive integer, not ${JSON.stringify(x)}.`);if(p!==void 0)throw Error(`A kit lists its components with components, a glob of .meta.js files; entry is retired.`);if(typeof g!=`string`||g===``||typeof v!=`string`||v===``)throw Error(`A kit needs components, a glob of .meta.js files, and tokens, the path of its webority-theme-tokens/2 file.`);let k=h(a),A=E(k,y),j=A.isSelf;if(l===`Phone`&&!S&&!j)throw Error(`A Phone product kit needs phoneRendererSupportFile, the phone renderer's support file; only a phone library's own kit release builds without it.`);j||le(k,y,A.pkg.version);let M=S?O(S):null,N=l===`Phone`?M:null,P=w?fe(w):null;P&&M&&pe(P,M.flags,S);let F=j?null:ue(A,y,l),I;I=F?F.icons:l===`Web`?oe(m(A.dir,`dist`)):ne(m(A.dir,`lib`,`typescript`,`module`,`components`,`AppIcon`,`catalog.g.d.ts`));let L=[];j&&(L=await f({root:k,components:g,icons:I}),D(L,l),t({libraryPackage:y,exported:n({root:k,typesFile:A.typesFile}),drawnNames:L.map(({meta:e})=>({name:e.name,component:e.component??e.name})),notDrawn:r(m(A.dir,e))}),l===`Web`&&c({root:k,metas:L,componentOf:()=>A.typesFile}));let R=[],z=new Map;if(F){let e=F.components.map(({name:e})=>e);R=await f({root:k,components:g,knownNames:e,icons:I}),D(R,l);let t=R.map(({meta:e})=>e.name).filter(t=>e.includes(t));if(t.length>0)throw Error(`The kit names ${t.join(`, `)} as ${y} already has them; rename the product components.`);l===`Web`&&c({root:k,metas:R,componentOf:(e,t)=>u(e,t)});for(let{meta:e,file:t}of R)z.set(e.name,{module:u(t,e.component??e.name),exportName:e.component??e.name,fixedProps:e.fixedProps})}let B=[];if(l===`Phone`){if(!A.canvasKitFile)throw Error(`${y} exports no ./canvasKit subpath; a Phone kit takes the device frame parts from it.`);B=te(A.canvasKitFile,y)}if(j&&l===`Phone`){let e=new Set(L.map(({meta:e})=>e.name)),t=B.filter(({name:t})=>e.has(t)).map(({name:e})=>e);if(t.length>0)throw Error(`${y} exports ${t.join(`, `)} from both its main entry and ./canvasKit.`)}let V=F?F.components:L.map(({meta:e})=>d(e,{platform:l,source:y})),H=R.map(({meta:e})=>{let t=z.get(e.name);if(t===void 0)throw Error(`canvas-kit: the module of ${e.name} is missing.`);return d(e,{platform:l,source:s(se(k,t.module))})}),U=[...V,...j?B.map(re):[],...H].sort(he);N&&ee(U,N.itemActions),de(U,b);let W=i(k,`@webority/tokens`);if(!W)throw Error(`@webority/tokens is not installed for ${k}. Run pnpm install there.`);let G=ae(h(k,v),m(W,`dist`,`meanings.json`),l),K={kind:j?_[l]:`Product`,library:{name:A.pkg.name,version:A.pkg.version},rendererProtocolVersion:x,platform:l,kitModuleVersion:2,productKit:null,components:U,tokens:G.tokens,tokenValues:G.tokenValues,icons:I,...P?{styleKeys:me(P,N?N.flags:null)}:{}},q=[];if(T!==void 0){let e=ie(T,y,A.pkg.version,U);K.renames=e.renames,q.push(...e.warnings)}return{manifest:K,warnings:q,phoneChromeNames:B.map(({name:e})=>e),productModules:z,metas:j?L:R}}function A(e,t){return e===``?t:`${e}.${t}`}function j(e,t,n){return Error(t===``?`${e} must be ${n}.`:`${e}: ${t} must be ${n}.`)}function M(e,t,n){if(!a(n))throw j(e,t,`an object`);return n}function N(e,t,n,r,i){return i(e,A(t,r),n[r])}function P(e){return(t,n,r)=>{if(!Array.isArray(r))throw j(t,n,`a list`);return r.map((r,i)=>e(t,`${n}[${i}]`,r))}}function F(e){return(t,n,r)=>{let i=M(t,n,r),a={};for(let[r,o]of Object.entries(i))a[r]=e(t,A(n,r),o);return a}}function I(e,t,n,r,i){let a={},o=n[r];return o!==void 0&&(a[r]=i(e,A(t,r),o)),a}function L(e){return(t,n,r)=>r===null?null:e(t,n,r)}function R(e,t,n){if(typeof n!=`string`)throw j(e,t,`a string`);return n}function z(e,t,n){if(typeof n!=`number`)throw j(e,t,`a number`);return n}function B(e,t,n){if(typeof n!=`boolean`)throw j(e,t,`a boolean`);return n}function V(e,t,n){if(n!==!0)throw j(e,t,`true`);return n}function H(e,t,n){if(n!==null)throw j(e,t,`null`);return n}function U(e,t,n){return n}function W(e,t,n){if(typeof n!=`string`&&typeof n!=`number`)throw j(e,t,`a string or a number`);return n}function G(e,t,n){if(typeof n!=`string`&&typeof n!=`number`&&typeof n!=`boolean`)throw j(e,t,`a string, a number or a boolean`);return n}function K(e,t,n){if(typeof n!=`string`||!x(n))throw j(e,t,`WeborityWeb, WeborityPhone or Product`);return n}function q(e,t,n){if(typeof n!=`string`||!C(n))throw j(e,t,`Web or Phone`);return n}function ge(e,t,n){if(typeof n!=`string`||!S(n))throw j(e,t,`one of the prop types the manifest lists`);return n}function _e(e,t,n){if(typeof n!=`string`||!w(n))throw j(e,t,`title or navigation`);return n}function J(e,t,n){let r=M(e,t,n);return{name:N(e,t,r,`name`,R),type:N(e,t,r,`type`,ge),...I(e,t,r,`enum`,P(W)),...I(e,t,r,`fields`,P(J)),...I(e,t,r,`itemFields`,P(J)),required:N(e,t,r,`required`,B),...I(e,t,r,`nullable`,V),...I(e,t,r,`description`,R),default:r.default}}function ve(e,t,n){let r=M(e,t,n);return{text:N(e,t,r,`text`,R),...I(e,t,r,`instead`,R)}}function ye(e,t,n){return typeof n==`string`?n:P(be)(e,t,n)}function be(e,t,n){return typeof n==`string`?n:Y(e,t,n)}function Y(e,t,n){let r=M(e,t,n);return{component:N(e,t,r,`component`,R),...I(e,t,r,`props`,F(U)),...I(e,t,r,`children`,ye),...I(e,t,r,`handlers`,P(R))}}function X(e,t,n){let r=M(e,t,n);return{...I(e,t,r,`title`,R),note:N(e,t,r,`note`,R),example:N(e,t,r,`example`,P(Y))}}function xe(e,t,n){let r=M(e,t,n);return{key:N(e,t,r,`key`,R),does:N(e,t,r,`does`,R),notes:N(e,t,r,`notes`,R)}}function Se(e,t,n){let r=M(e,t,n);return{pair:N(e,t,r,`pair`,R),light:N(e,t,r,`light`,R),dark:N(e,t,r,`dark`,R)}}function Ce(e,t,n){let r=M(e,t,n);return{when:N(e,t,r,`when`,P(R)),whenNot:N(e,t,r,`whenNot`,P(ve)),do:N(e,t,r,`do`,P(X)),dont:N(e,t,r,`dont`,P(X)),a11y:N(e,t,r,`a11y`,P(R)),...I(e,t,r,`keyboard`,P(xe)),...I(e,t,r,`contrast`,P(Se))}}function we(e,t,n){let r=M(e,t,n);return{name:N(e,t,r,`name`,R),marker:N(e,t,r,`marker`,L(R)),acceptsChildren:N(e,t,r,`acceptsChildren`,B),props:N(e,t,r,`props`,P(J)),itemsTakeAction:N(e,t,r,`itemsTakeAction`,P(R)),takesAction:N(e,t,r,`takesAction`,P(R)),source:N(e,t,r,`source`,R),...I(e,t,r,`component`,R),...I(e,t,r,`fixedProps`,F(U)),...I(e,t,r,`role`,_e),...I(e,t,r,`usage`,Ce)}}function Te(e,t,n){let r=M(e,t,n);return{color:N(e,t,r,`color`,P(R)),space:N(e,t,r,`space`,P(R)),radius:N(e,t,r,`radius`,P(R)),shadow:N(e,t,r,`shadow`,P(R)),font:N(e,t,r,`font`,P(R)),text:N(e,t,r,`text`,P(R)),leading:N(e,t,r,`leading`,P(R)),...I(e,t,r,`colorMeanings`,F(R))}}function Ee(e,t,n){let r=M(e,t,n);return{x:N(e,t,r,`x`,z),y:N(e,t,r,`y`,z),blur:N(e,t,r,`blur`,z),spread:N(e,t,r,`spread`,z),color:N(e,t,r,`color`,R),...I(e,t,r,`elevation`,z)}}function De(e,t,n){let r=M(e,t,n);return{light:N(e,t,r,`light`,R),dark:N(e,t,r,`dark`,R)}}function Oe(e,t,n){let r=M(e,t,n);return{family:N(e,t,r,`family`,R),fallback:N(e,t,r,`fallback`,R)}}function ke(e,t,n){let r=M(e,t,n);return{size:N(e,t,r,`size`,z),...I(e,t,r,`weight`,L(z))}}function Ae(e,t,n){let r=M(e,t,n);return{color:N(e,t,r,`color`,F(De)),space:N(e,t,r,`space`,F(z)),radius:N(e,t,r,`radius`,F(z)),shadow:N(e,t,r,`shadow`,F(L(Ee))),font:N(e,t,r,`font`,F(Oe)),text:N(e,t,r,`text`,F(ke)),leading:N(e,t,r,`leading`,F(z))}}function Z(e,t,n){let r=M(e,t,n);return{name:N(e,t,r,`name`,R),type:N(e,t,r,`type`,R),values:N(e,t,r,`values`,P(R)),appliesTo:N(e,t,r,`appliesTo`,R),description:N(e,t,r,`description`,R)}}function je(e,t,n){let r=Z(e,t,n),i=M(e,t,n);return{...r,...I(e,t,i,`phoneSupported`,B)}}function Me(e,t,n){let r=M(e,t,n);return{name:N(e,t,r,`name`,R),...I(e,t,r,`to`,R),props:N(e,t,r,`props`,F(R)),values:N(e,t,r,`values`,F(F(R))),added:N(e,t,r,`added`,F(G)),removed:N(e,t,r,`removed`,F(R))}}function Ne(e,t,n){let r=M(e,t,n);return{version:N(e,t,r,`version`,R),components:N(e,t,r,`components`,P(Me)),values:N(e,t,r,`values`,F(F(R)))}}function Pe(e,t,n){let r=M(e,t,n);return{name:N(e,t,r,`name`,R),version:N(e,t,r,`version`,R)}}function Q(e,t,n){let r=M(e,t,n);return{sha256:N(e,t,r,`sha256`,R),bytes:N(e,t,r,`bytes`,z)}}function Fe(e,t,n){let r=M(e,t,n);return{"manifest.json":N(e,t,r,`manifest.json`,Q),"kit.js":N(e,t,r,`kit.js`,Q),"kit.css":N(e,t,r,`kit.css`,Q)}}function Ie(e,t){let n=M(t,``,e);return{name:N(t,``,n,`name`,R),version:N(t,``,n,`version`,R),platform:N(t,``,n,`platform`,q),kitModuleVersion:N(t,``,n,`kitModuleVersion`,z),rendererProtocolVersion:N(t,``,n,`rendererProtocolVersion`,z),library:N(t,``,n,`library`,Pe),files:N(t,``,n,`files`,Fe)}}function Le(e,t){let n=M(t,``,e);return{kind:N(t,``,n,`kind`,K),library:N(t,``,n,`library`,Pe),rendererProtocolVersion:N(t,``,n,`rendererProtocolVersion`,z),platform:N(t,``,n,`platform`,q),kitModuleVersion:N(t,``,n,`kitModuleVersion`,z),productKit:N(t,``,n,`productKit`,H),components:N(t,``,n,`components`,P(we)),tokens:N(t,``,n,`tokens`,Te),tokenValues:N(t,``,n,`tokenValues`,L(Ae)),icons:N(t,``,n,`icons`,P(R)),...I(t,``,n,`styleKeys`,P(je)),...I(t,``,n,`renames`,P(Ne))}}function $(e,t){let n=M(t,``,e);return{name:N(t,``,n,`name`,R),version:N(t,``,n,`version`,R),...I(t,``,n,`main`,R),...I(t,``,n,`types`,R),...I(t,``,n,`exports`,M),...I(t,``,n,`dependencies`,F(R)),...I(t,``,n,`devDependencies`,F(R)),...I(t,``,n,`peerDependencies`,F(R))}}function Re(e,t){let n=M(t,``,e);return{kind:N(t,``,n,`kind`,R),platform:N(t,``,n,`platform`,R),components:N(t,``,n,`components`,P(we)),icons:N(t,``,n,`icons`,P(R))}}function ze(e,t){return P(Z)(t,``,e)}function Be(e,t,n){let r=M(e,t,n),i=r.itemsTakeAction,a=r.takesAction;return{...i===void 0?{}:{itemsTakeAction:F(P(R))(e,A(t,`itemsTakeAction`),i)},...a===void 0?{}:{takesAction:F(P(R))(e,A(t,`takesAction`),a)}}}function Ve(e,t){let n=M(t,``,e);return{schema:N(t,``,n,`schema`,z),...I(t,``,n,`styleKeys`,F(B)),...I(t,``,n,`itemActions`,Be)}}export{E as libraryFiles,Le as parseCanvasManifest,Ie as parseCanvasReleaseStamp,k as readManifest,O as readPhoneSupport};
package/dist/meta.d.ts CHANGED
@@ -1,101 +1,93 @@
1
1
  /** A prop type, in the kit manifest wire names (CanvasManifestProp.Type). Event handlers are never described: DesignKeys leaves them out. */
2
- export type MetaPropType =
3
- | "string"
4
- | "number"
5
- | "stringOrNumber"
6
- | "boolean"
7
- | "enum"
8
- | "enumOrNumber"
9
- | "url"
10
- | "icon"
11
- | "node"
12
- | "array"
13
- | "object"
14
- | "any";
15
-
2
+ export type MetaPropType = "string" | "number" | "stringOrNumber" | "boolean" | "enum" | "enumOrNumber" | "url" | "icon" | "node" | "array" | "object" | "any";
16
3
  export interface MetaProp {
17
4
  type: MetaPropType;
18
5
  /**
19
6
  * The values of an enum, in the order the component lists them; a numeric literal union lists numbers.
20
7
  * On an enumOrNumber, the named values only: the prop also takes any number. Only on these two types, and required there.
21
8
  */
22
- values?: readonly (string | number)[];
9
+ values?: readonly (string | number)[] | undefined;
23
10
  /** The value the component applies when the prop is left out, as JSON. Never on a required prop. */
24
11
  default?: unknown;
25
- required?: boolean;
12
+ required?: boolean | undefined;
26
13
  /** The component takes null for it: a value that is always sent and may be empty. Examples may then set null. */
27
- nullable?: boolean;
14
+ nullable?: boolean | undefined;
28
15
  description: string;
29
16
  /** The fields of an object prop. Only on an object. */
30
- fields?: Readonly<Record<string, MetaProp>>;
17
+ fields?: Readonly<Record<string, MetaProp>> | undefined;
31
18
  /** The fields of each item of a list whose items are objects. Only on an array. */
32
- itemFields?: Readonly<Record<string, MetaProp>>;
19
+ itemFields?: Readonly<Record<string, MetaProp>> | undefined;
33
20
  }
34
-
35
21
  /** A placed element: a component of the kit, or one of the HTML tags in HTML_TAGS. A node or icon prop value may be a MetaNode. */
36
22
  export interface MetaNode {
37
23
  component: string;
38
- props?: Readonly<Record<string, unknown>>;
24
+ props?: Readonly<Record<string, unknown>> | undefined;
39
25
  /** Text, or a list of placed elements and text items. */
40
- children?: string | readonly (MetaNode | string)[];
26
+ children?: string | readonly (MetaNode | string)[] | undefined;
41
27
  /** Function props a renderer attaches as a no-op so the demo draws complete (a remove button, a retry action). Each must be a function prop of the component. */
42
- handlers?: readonly string[];
28
+ handlers?: readonly string[] | undefined;
43
29
  }
44
-
45
30
  export interface MetaExample {
46
31
  /** The parity case id: the component name for its base example, "<name>.<case>" for the others. */
47
32
  id: string;
48
33
  title: string;
49
34
  props: Readonly<Record<string, unknown>>;
50
- children?: string | readonly (MetaNode | string)[];
35
+ children?: string | readonly (MetaNode | string)[] | undefined;
51
36
  /** An element the example is placed inside, for a component that only renders within a parent. */
52
- wrap?: MetaNode;
37
+ wrap?: MetaNode | undefined;
53
38
  /** Function props a renderer attaches as a no-op so the demo draws complete (a remove button, a retry action). Each must be a function prop of the component. */
54
- handlers?: readonly string[];
39
+ handlers?: readonly string[] | undefined;
55
40
  }
56
-
57
41
  /** One side of a do and dont pair; do[i] is shown beside dont[i]. Example props may be scalars, icons, nodes, or arrays and objects checked against the prop's itemFields or fields. */
58
42
  export interface MetaPractice {
59
- title?: string;
43
+ title?: string | undefined;
60
44
  note: string;
61
45
  example: readonly MetaNode[];
62
46
  }
63
-
64
47
  export interface ComponentUsage {
65
48
  when: readonly string[];
66
- whenNot: readonly { text: string; instead?: string }[];
49
+ whenNot: readonly {
50
+ text: string;
51
+ instead?: string | undefined;
52
+ }[];
67
53
  do: readonly MetaPractice[];
68
54
  dont: readonly MetaPractice[];
69
55
  a11y: readonly string[];
70
- keyboard?: readonly { key: string; does: string; notes: string }[];
71
- contrast?: readonly { pair: string; light: string; dark: string }[];
56
+ keyboard?: readonly {
57
+ key: string;
58
+ does: string;
59
+ notes: string;
60
+ }[] | undefined;
61
+ contrast?: readonly {
62
+ pair: string;
63
+ light: string;
64
+ dark: string;
65
+ }[] | undefined;
72
66
  }
73
-
74
67
  export interface ComponentMeta {
75
68
  /** The catalogue name, such as AppButton. */
76
69
  name: string;
77
70
  /** The export this description draws, when it is not `name`: one export described once per fixed setup, such as a picker per mode. */
78
- component?: string;
71
+ component?: string | undefined;
79
72
  /** Props the kit sets on every placement, over any stored value; never shown in the panel. Only with `component`. */
80
- fixedProps?: Readonly<Record<string, unknown>>;
73
+ fixedProps?: Readonly<Record<string, unknown>> | undefined;
81
74
  /** The data-wui value the component renders, or null when it renders none. */
82
75
  marker: string | null;
83
76
  platforms: readonly ("web" | "phone")[];
84
77
  acceptsChildren: boolean;
85
78
  props: Readonly<Record<string, MetaProp>>;
86
79
  /** The action stand-in each event handler is drawn as, by handler name, such as { onConfirm: "confirmAction" }. A design cannot send a function, so the manifest lists each stand-in as an object prop and names it in takesAction; in play the handler runs the stored action. Only on a meta whose platforms list web. */
87
- actions?: Readonly<Record<string, string>>;
80
+ actions?: Readonly<Record<string, string>> | undefined;
88
81
  /** The part's role in the manifest: a screen title or a navigation bar. */
89
- role?: "title" | "navigation";
82
+ role?: "title" | "navigation" | undefined;
90
83
  /** Phone only. Names of object props that each carry one action, such as AppBar `leftAction`. In play a tap on it runs the stored action. */
91
- takesAction?: readonly string[];
84
+ takesAction?: readonly string[] | undefined;
92
85
  /** Phone only. Names of array props whose items each carry an action, such as AppBar `rightActions` or BottomNavigation `tabs`. */
93
- itemsTakeAction?: readonly string[];
86
+ itemsTakeAction?: readonly string[] | undefined;
94
87
  /** Design props deliberately not shown in the kit, such as a render prop no kit type fits. The type check accepts them unlisted. */
95
- omit?: readonly string[];
88
+ omit?: readonly string[] | undefined;
96
89
  examples: readonly MetaExample[];
97
90
  usage: ComponentUsage;
98
91
  }
99
-
100
92
  /** Returns the meta unchanged; the const parameter keeps literal types for the type check. */
101
93
  export declare function defineMeta<const M extends ComponentMeta>(meta: M): M;
@@ -1,122 +1,8 @@
1
- // Type rules that prove a meta equals its component's typed props. P is the props type (React ComponentProps of
2
- // the component), N is React's ReactNode, both supplied by the generated check file so this file imports no react.
3
- import type { ComponentMeta, MetaProp } from "./meta.js";
4
-
5
- type IsAny<T> = 0 extends 1 & T ? true : false;
6
- type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
7
- type Handler = (...args: never[]) => unknown;
8
- // React's ElementType and ComponentType both carry a class constructor member; a render prop never does.
9
- type Constructor = abstract new (...args: never[]) => unknown;
10
- type Defined<T> = Exclude<T, null | undefined>;
11
- type Shape = Readonly<Record<string, MetaProp>>;
12
-
13
- /** Every field a design sets at any depth: all but event handlers and component-typed fields. */
14
- type FieldKeys<P> = {
15
- [K in keyof P]-?: IsAny<P[K]> extends true
16
- ? K
17
- : [Defined<P[K]>] extends [Handler]
18
- ? never
19
- : [Extract<Defined<P[K]>, Constructor>] extends [never]
20
- ? K
21
- : never;
22
- }[keyof P] &
23
- string;
24
-
25
- /** Every prop a design sets: the field keys, less React's children, ref and key (a nested data field may be named key). */
26
- export type DesignKeys<P> = Exclude<FieldKeys<P>, "children" | "ref" | "key">;
27
-
28
- /** Every event handler prop of the component: the names a meta's handlers list may use. */
29
- export type HandlerKeys<P> = { [K in keyof P]-?: NonNullable<P[K]> extends Handler ? K : never }[keyof P] & string;
30
-
31
- type RequiredKeys<P> = { [K in keyof P]-?: Partial<Pick<P, K>> extends Pick<P, K> ? never : K }[keyof P];
32
- type ItemOf<T> = Defined<T> extends readonly (infer I)[] ? I : Defined<T> extends ReadonlySet<infer I> ? I : never;
33
-
34
- // "any" is a meta's explicit opt-out for a value no meta type can state (a union of a File, an object and an array):
35
- // Canvas passes it through unchanged, so only its presence and required flag are checked.
36
- type ValueOk<T, M extends MetaProp, N> = M["type"] extends "any"
37
- ? true
38
- : IsAny<T> extends true
39
- ? false
40
- : M["type"] extends "enum"
41
- ? Same<Defined<T>, NonNullable<M["values"]>[number]>
42
- : M["type"] extends "enumOrNumber"
43
- ? Same<Defined<T>, NonNullable<M["values"]>[number] | number>
44
- : M["type"] extends "boolean"
45
- ? Same<Defined<T>, boolean>
46
- : M["type"] extends "number"
47
- ? Same<Defined<T>, number>
48
- : M["type"] extends "stringOrNumber"
49
- ? // A Date prop is written as an ISO string in a meta, so string | number | Date is a stringOrNumber too.
50
- Same<Defined<T>, string | number> extends true
51
- ? true
52
- : Same<Defined<T>, string | number | Date>
53
- : M["type"] extends "string" | "url"
54
- ? Same<Defined<T>, string>
55
- : M["type"] extends "icon"
56
- ? string extends Defined<T>
57
- ? true
58
- : false
59
- : M["type"] extends "node"
60
- ? Defined<N> extends Defined<T>
61
- ? true
62
- : false
63
- : M["type"] extends "array"
64
- ? [Defined<T>] extends [readonly unknown[] | ReadonlySet<unknown>]
65
- ? true
66
- : false
67
- : M["type"] extends "object"
68
- ? [Defined<T>] extends [readonly unknown[] | ReadonlySet<unknown> | Handler]
69
- ? false
70
- : [Defined<T>] extends [object]
71
- ? true
72
- : false
73
- : false;
74
-
75
- type RequiredOk<P, K extends keyof P, M extends MetaProp> = Same<
76
- K extends RequiredKeys<P> ? true : false,
77
- M["required"] extends true ? true : false
78
- >;
79
-
80
- // ReactNode carries null itself, so a prop that takes any node (a node, or an icon given as a name or a node) is
81
- // empty-able by its type, not nullable in its own right. "any" opts out: its value is passed through unchecked.
82
- type OwnNull<T, N> = null extends T ? (Defined<N> extends Defined<T> ? false : true) : false;
83
- type NullableOk<T, M extends MetaProp, N> = M["type"] extends "any" ? true : Same<OwnNull<T, N>, M["nullable"] extends true ? true : false>;
84
-
85
- type NestedOk<T, M extends MetaProp, N> = M["type"] extends "object"
86
- ? M["fields"] extends Shape
87
- ? ShapeOk<Defined<T>, M["fields"], N>
88
- : true
89
- : M["type"] extends "array"
90
- ? M["itemFields"] extends Shape
91
- ? ShapeOk<ItemOf<T>, M["itemFields"], N>
92
- : true
93
- : true;
94
-
95
- type ShapeOk<T, F extends Shape, N> =
96
- Same<FieldKeys<T>, keyof F & string> extends true ? ([PropsMismatch<T, F, N>] extends [never] ? true : false) : false;
97
-
98
- /** The names of meta props whose type, required or nullable flag, or nested fields differ from the component's. */
99
- export type PropsMismatch<P, F extends Shape, N> = {
100
- [K in keyof F & keyof P & string]: ValueOk<P[K], F[K], N> extends true
101
- ? RequiredOk<P, K, F[K]> extends true
102
- ? NullableOk<P[K], F[K], N> extends true
103
- ? NestedOk<P[K], F[K], N> extends true
104
- ? never
105
- : K
106
- : K
107
- : K
108
- : K;
109
- }[keyof F & keyof P & string];
110
-
111
- // A meta with no omit list would make NonNullable<M["omit"]>[number] collapse ExtraProps to never.
112
- type OmitOf<M extends ComponentMeta> = M extends { readonly omit: infer O extends readonly string[] } ? O[number] : never;
113
- // The props a meta fixes are set by the kit, not the panel, so they are not extra props.
114
- type FixedOf<M extends ComponentMeta> = M extends { readonly fixedProps: infer F extends Readonly<Record<string, unknown>> }
115
- ? keyof F & string
116
- : never;
117
- /** Props the component takes that the meta neither lists, omits nor fixes. */
118
- export type ExtraProps<P, M extends ComponentMeta> = Exclude<DesignKeys<P>, keyof M["props"] | OmitOf<M> | FixedOf<M>>;
119
- /** Props the meta lists that the component does not take. */
120
- export type MissingProps<P, M extends ComponentMeta> = Exclude<keyof M["props"] & string, DesignKeys<P>>;
121
- export type MismatchedProps<P, M extends ComponentMeta, N> = PropsMismatch<P, M["props"], N>;
122
- export type ChildrenOk<P, M extends ComponentMeta> = Same<"children" extends keyof P ? true : false, M["acceptsChildren"]>;
1
+ import type { MetaEntry } from "./metas.ts";
2
+ export declare const TSC: string;
3
+ export declare function specifierOf(file: string): string;
4
+ export declare function checkMetaTypes({ root, metas, componentOf, }: {
5
+ root: string;
6
+ metas: MetaEntry[];
7
+ componentOf: (file: string, name: string) => string;
8
+ }): void;
package/dist/metaCheck.js CHANGED
@@ -1,4 +1,4 @@
1
- import{toPosix as e}from"./files.js";import{createRequire as t}from"node:module";import{mkdirSync as n,realpathSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import{execFileSync as l}from"node:child_process";var u=s(o(t(import.meta.url).resolve(`typescript/package.json`)),`bin`,`tsc`),d=s(o(c(import.meta.url)),`metaCheck.js`),f=/^check\.ts\((\d+),\d+\): error TS\d+: (.*)$/,p=/^(.+?)\(\d+,\d+\): error TS\d+: (.*)$/,m=[`propsNotInMeta`,`metaPropsNotOnComponent`,`propsThatDiffer`,`children`,`fixedProps`],h={propsNotInMeta:`props the component takes that the meta does not list`,metaPropsNotOnComponent:`props the meta lists that the component does not take`,propsThatDiffer:`props whose type, required or nullable flag, or nested fields differ from the component`,fixedProps:`fixed props whose value does not fit the component's prop`};function g(t){let n=e(t);return/\.d\.ts$/.test(n)?n.replace(/\.d\.ts$/,``):n.replace(/\.(jsx|tsx|js|ts|mjs)$/,``)}function _(e){let t=[];for(let n of e.split(/\r?\n/)){let e=f.exec(n);if(e){t.push({line:Number(e[1]),file:null,message:e[2]});continue}let r=p.exec(n);r&&t.push({line:null,file:r[1],message:r[2]})}return t}function v(e){let t=/Type '(\{[^']*\})'/.exec(e);return t?[...t[1].matchAll(/: "([^"]+)"/g)].map(e=>e[1]):[]}function y(e){let t=new Map,n=(e,n,r,i)=>{let a=`${e} ${n}`;t.has(a)||t.set(a,{component:e,handler:n,path:r,owner:i})},r=(e,t,i)=>{if(typeof e==`object`&&e){for(let r of e.handlers??[])n(e.component,r,t,i);Array.isArray(e.children)&&e.children.forEach((e,n)=>{r(e,`${t}.children[${n}]`,i)})}};return e.forEach(({meta:e},t)=>{(e.examples??[]).forEach((i,a)=>{let o=`examples[${a}]`;for(let r of i.handlers??[])n(e.name,r,o,t);r({children:i.children},o,t),r(i.wrap,`${o}.wrap`,t)});for(let r of Object.keys(e.actions??{}))n(e.name,r,`actions.${r}`,t);for(let n of[`do`,`dont`])(e.usage?.[n]??[]).forEach((e,i)=>{(e.example??[]).forEach((e,a)=>{r(e,`usage.${n}[${i}].example[${a}]`,t)})})}),t}function b({root:t,metas:o,componentOf:c}){let f=s(r(t),`node_modules`,`.canvas-kit-check-${process.pid}`);try{n(f,{recursive:!0});let t=o.map(({meta:e,file:t})=>({component:g(c(t,e.component??e.name)),meta:g(t)})),r=[],i=new Map,p=new Map,b=(e,t=-1,n=null)=>{r.push(e);let a=r.length;t>=0&&i.set(a,t),n&&p.set(a,n)};b(`import type { ExtraProps, MissingProps, MismatchedProps, ChildrenOk, HandlerKeys } from "${e(d)}";`),b(`type N = import("react").ReactNode;`),b(`type Empty = { [key: string]: never };`),o.forEach((e,n)=>{b(`import type * as C${n} from "${t[n].component}";`,n),b(`import type { meta as M${n} } from "${t[n].meta}";`,n)});let x=e=>`{ [K in ${e}]: K }`;o.forEach(({meta:e},t)=>{let n=e.name,r=e.component??e.name;b(`type P${t} = import("react").ComponentProps<typeof C${t}.${r}>;`,t),b(`export const ${n}__propsNotInMeta: Empty = null as unknown as ${x(`ExtraProps<P${t}, typeof M${t}>`)};`,t,`propsNotInMeta`),b(`export const ${n}__metaPropsNotOnComponent: Empty = null as unknown as ${x(`MissingProps<P${t}, typeof M${t}>`)};`,t,`metaPropsNotOnComponent`),b(`export const ${n}__propsThatDiffer: Empty = null as unknown as ${x(`MismatchedProps<P${t}, typeof M${t}, N>`)};`,t,`propsThatDiffer`),b(`export const ${n}__children: true = null as unknown as ChildrenOk<P${t}, typeof M${t}>;`,t,`children`),e.fixedProps!==void 0&&b(`export const ${n}__fixedProps: Partial<P${t}> = null as unknown as NonNullable<(typeof M${t})["fixedProps"]>;`,t,`fixedProps`)});let S=new Map(o.map(({meta:e},t)=>[e.name,t])),C=new Map,w=0;for(let{component:t,handler:n,path:i,owner:a}of y(o).values()){let s=S.get(t);s!==void 0&&(w+=1,b(`export const ${t.replace(/[^A-Za-z0-9_]/g,`_`)}__handler_${n}_${w}: Empty = null as unknown as { [K in Exclude<"${n}", HandlerKeys<P${s}>>]: K };`),C.set(r.length,{owner:a,where:`${e(o[a].file)}: ${i}`,component:t,handler:n}))}a(s(f,`check.ts`),`${r.join(`
2
- `)}\n`),a(s(f,`tsconfig.json`),JSON.stringify({compilerOptions:{strict:!0,noEmit:!0,allowJs:!0,checkJs:!1,jsx:`react-jsx`,module:`esnext`,moduleResolution:`bundler`,target:`es2022`,skipLibCheck:!0,noErrorTruncation:!0,types:[]},files:[`check.ts`]},null,2));let T;try{l(process.execPath,[u,`-p`,s(f,`tsconfig.json`),`--pretty`,`false`],{cwd:f,encoding:`utf8`,stdio:`pipe`});return}catch(e){T=String(e.stdout??``)+String(e.stderr??``)}let E=new Map,D=[];for(let n of _(T)){let r=n.line===null?void 0:C.get(n.line);if(r){D.push({owner:r.owner,rank:m.length,text:`${r.where}: "${r.handler}" is not a function prop of ${r.component}`});continue}let a=n.line!==null&&i.has(n.line)?i.get(n.line):void 0,s=n.line===null?void 0:p.get(n.line);if(s&&a!==void 0){let e=`${a}:${s}`;if(E.has(e)||E.set(e,{owner:a,kind:s,names:new Set}),s!==`children`)for(let t of v(n.message))E.get(e).names.add(t);continue}let c=a??t.findIndex(e=>[n.file,n.message].some(t=>t&&(t.includes(e.component)||t.includes(e.meta)))),l=n.line===null?`${e(n.file)}: `:``;D.push({owner:c,rank:-1,text:`${c>=0?o[c].meta.name:`metaCheck`}: tsc could not read the check file: ${l}${n.message}`})}for(let{owner:e,kind:t,names:n}of E.values()){let{meta:r}=o[e],i=t===`children`?`${r.name}: acceptsChildren is ${r.acceptsChildren} but the component ${r.acceptsChildren?`does not take`:`takes`} children`:n.size>0?`${r.name}: ${h[t]}: ${[...n].sort().join(`, `)}`:`${r.name}: ${h[t]}: see the meta against the component's props`;D.push({owner:e,rank:m.indexOf(t),text:i})}throw D.length===0?Error(`metaCheck: tsc failed: ${T.split(/\r?\n/).slice(0,20).join(`
3
- `)}`):(D.sort((e,t)=>e.owner-t.owner||e.rank-t.rank),Error(D.map(e=>e.text).join(`
4
- `)))}finally{i(f,{recursive:!0,force:!0})}}export{u as TSC,b as checkMetaTypes,g as specifierOf};
1
+ import{toPosix as e}from"./files.js";import{createRequire as t}from"node:module";import{mkdirSync as n,realpathSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import{execFileSync as l}from"node:child_process";var u=s(o(t(import.meta.url).resolve(`typescript/package.json`)),`bin`,`tsc`),d=s(o(c(import.meta.url)),`metaRules`),f=/^check\.ts\((\d+),\d+\): error TS\d+: (.*)$/,p=/^(.+?)\(\d+,\d+\): error TS\d+: (.*)$/,m=[`propsNotInMeta`,`metaPropsNotOnComponent`,`propsThatDiffer`,`children`,`fixedProps`],h={propsNotInMeta:`props the component takes that the meta does not list`,metaPropsNotOnComponent:`props the meta lists that the component does not take`,propsThatDiffer:`props whose type, required or nullable flag, or nested fields differ from the component`,fixedProps:`fixed props whose value does not fit the component's prop`};function g(e){return Object.hasOwn(h,e)}function _(t){let n=e(t);return/\.d\.ts$/.test(n)?n.replace(/\.d\.ts$/,``):n.replace(/\.(jsx|tsx|js|ts|mjs)$/,``)}function v(e){let t=[];for(let n of e.split(/\r?\n/)){let e=f.exec(n);if(e){t.push({line:Number(e[1]),file:null,message:e[2]??``});continue}let r=p.exec(n);r&&t.push({line:null,file:r[1]??null,message:r[2]??``})}return t}function y(e){let t=/Type '(\{[^']*\})'/.exec(e);return t?[...(t[1]??``).matchAll(/: "([^"]+)"/g)].map(e=>e[1]??``):[]}function b(e){return typeof e==`object`&&!!e}function x(e){let t=new Map,n=(e,n,r,i)=>{let a=`${e} ${n}`;t.has(a)||t.set(a,{component:e,handler:n,path:r,owner:i})},r=(e,t,i)=>{if(!b(e))return;let a=e.handlers??[];if(!Array.isArray(a))throw Error(`handlerPairs: the handlers at ${t} are not a list`);for(let r of a)n(String(e.component),String(r),t,i);Array.isArray(e.children)&&e.children.forEach((e,n)=>{r(e,`${t}.children[${n}]`,i)})};return e.forEach(({meta:e},t)=>{(e.examples??[]).forEach((i,a)=>{let o=`examples[${a}]`;for(let r of i.handlers??[])n(e.name,r,o,t);r({children:i.children},o,t),r(i.wrap,`${o}.wrap`,t)});for(let r of Object.keys(e.actions??{}))n(e.name,r,`actions.${r}`,t);for(let n of[`do`,`dont`])(e.usage?.[n]??[]).forEach((e,i)=>{(e.example??[]).forEach((e,a)=>{r(e,`usage.${n}[${i}].example[${a}]`,t)})})}),t}function S(e){let t=``;return typeof e==`object`&&e&&`stdout`in e&&(t+=String(e.stdout??``)),typeof e==`object`&&e&&`stderr`in e&&(t+=String(e.stderr??``)),t}function C({root:t,metas:o,componentOf:c}){let f=s(r(t),`node_modules`,`.canvas-kit-check-${process.pid}`);try{n(f,{recursive:!0});let t=o.map(({meta:e,file:t})=>({component:_(c(t,e.component??e.name)),meta:_(t)})),r=[],i=new Map,p=new Map,b=(e,t=-1,n=null)=>{r.push(e);let a=r.length;t>=0&&i.set(a,t),n&&p.set(a,n)};b(`import type { ExtraProps, MissingProps, MismatchedProps, ChildrenOk, HandlerKeys, Flatten } from "${e(d)}";`),b(`type N = import("react").ReactNode;`),b(`type D = { "html attributes": import("react").AllHTMLAttributes<HTMLElement>; "svg attributes": import("react").SVGAttributes<SVGElement> } & import("react").JSX.IntrinsicElements;`),b(`type Empty = { [key: string]: never };`),o.forEach((e,n)=>{b(`import type * as C${n} from "${t[n]?.component}";`,n),b(`import type { meta as M${n} } from "${t[n]?.meta}";`,n)});let C=e=>`{ [K in ${e}]: K }`;o.forEach(({meta:e},t)=>{let n=e.name,r=e.component??e.name;b(`type P${t} = Flatten<import("react").ComponentProps<typeof C${t}.${r}>>;`,t),b(`export const ${n}__propsNotInMeta: Empty = null as unknown as ${C(`ExtraProps<P${t}, typeof M${t}, D>`)};`,t,`propsNotInMeta`),b(`export const ${n}__metaPropsNotOnComponent: Empty = null as unknown as ${C(`MissingProps<P${t}, typeof M${t}>`)};`,t,`metaPropsNotOnComponent`),b(`export const ${n}__propsThatDiffer: Empty = null as unknown as ${C(`MismatchedProps<P${t}, typeof M${t}, N>`)};`,t,`propsThatDiffer`),b(`export const ${n}__children: true = null as unknown as ChildrenOk<P${t}, typeof M${t}, D>;`,t,`children`),e.fixedProps!==void 0&&b(`export const ${n}__fixedProps: Partial<P${t}> = null as unknown as NonNullable<(typeof M${t})["fixedProps"]>;`,t,`fixedProps`)});let w=new Map(o.map(({meta:e},t)=>[e.name,t])),T=new Map,E=0;for(let{component:t,handler:n,path:i,owner:a}of x(o).values()){let s=w.get(t);s!==void 0&&(E+=1,b(`export const ${t.replace(/[^A-Za-z0-9_]/g,`_`)}__handler_${n}_${E}: Empty = null as unknown as { [K in Exclude<"${n}", HandlerKeys<P${s}>>]: K };`),T.set(r.length,{owner:a,where:`${e(o[a]?.file??``)}: ${i}`,component:t,handler:n}))}a(s(f,`check.ts`),`${r.join(`
2
+ `)}\n`),a(s(f,`tsconfig.json`),JSON.stringify({compilerOptions:{strict:!0,noEmit:!0,allowJs:!0,checkJs:!1,jsx:`react-jsx`,module:`esnext`,moduleResolution:`bundler`,allowImportingTsExtensions:!0,target:`es2022`,skipLibCheck:!0,noErrorTruncation:!0,types:[]},files:[`check.ts`]},null,2));let D;try{l(process.execPath,[u,`-p`,s(f,`tsconfig.json`),`--pretty`,`false`],{cwd:f,encoding:`utf8`,stdio:`pipe`});return}catch(e){D=S(e)}let O=new Map,k=[];for(let n of v(D)){let r=n.line===null?void 0:T.get(n.line);if(r){k.push({owner:r.owner,rank:m.length,text:`${r.where}: "${r.handler}" is not a function prop of ${r.component}`});continue}let a=n.line===null?void 0:i.get(n.line),s=n.line===null?void 0:p.get(n.line);if(s&&a!==void 0){let e=`${a}:${s}`;if(O.has(e)||O.set(e,{owner:a,kind:s,names:new Set}),s!==`children`)for(let t of y(n.message))O.get(e)?.names.add(t);continue}let c=a??t.findIndex(e=>[n.file,n.message].some(t=>t&&(t.includes(e.component)||t.includes(e.meta)))),l=n.line===null?`${e(n.file??``)}: `:``;k.push({owner:c,rank:-1,text:`${c>=0?o[c]?.meta.name:`metaCheck`}: tsc could not read the check file: ${l}${n.message}`})}for(let{owner:e,kind:t,names:n}of O.values()){let r=o[e];if(!r)throw Error(`checkMetaTypes: no meta at index ${e} to report on`);let{meta:i}=r,a;if(t===`children`)a=`${i.name}: acceptsChildren is ${i.acceptsChildren} but the component ${i.acceptsChildren?`does not take`:`takes`} children`;else{if(!g(t))throw Error(`metaCheck: no sentence for finding kind ${t}`);a=n.size>0?`${i.name}: ${h[t]}: ${[...n].sort().join(`, `)}`:`${i.name}: ${h[t]}: see the meta against the component's props`}k.push({owner:e,rank:m.indexOf(t),text:a})}throw k.length===0?Error(`metaCheck: tsc failed: ${D.split(/\r?\n/).slice(0,20).join(`
3
+ `)}`):(k.sort((e,t)=>e.owner-t.owner||e.rank-t.rank),Error(k.map(e=>e.text).join(`
4
+ `)))}finally{i(f,{recursive:!0,force:!0})}}export{u as TSC,C as checkMetaTypes,_ as specifierOf};