@webority/canvas-kit 0.101.1 → 0.101.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/manifest.js +1 -1
- package/dist/meta.d.ts +6 -0
- package/dist/metas.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The flags are:
|
|
|
19
19
|
| Flag | Meaning |
|
|
20
20
|
| --- | --- |
|
|
21
21
|
| `--style-keys <file>` | Optional. The style key table the renderer draws from. The manifest carries `styleKeys` only when this flag is given. |
|
|
22
|
-
| `--phone-renderer-support <file>` | The phone renderer's support file: each style key's `phoneSupported` flag and the
|
|
22
|
+
| `--phone-renderer-support <file>` | The phone renderer's support file: each style key's `phoneSupported` flag and action lists applied to every entry on top of the metas' own `takesAction` and `itemsTakeAction`. A Phone product kit needs it; a phone library's own kit takes the lists from its metas. |
|
|
23
23
|
|
|
24
24
|
Flag paths are relative to the working directory.
|
|
25
25
|
|
|
@@ -69,6 +69,9 @@ A meta module imports only `defineMeta` from `@webority/canvas-kit/meta` and exp
|
|
|
69
69
|
| `props` | Each prop has a `type`, one of `string`, `number`, `stringOrNumber`, `boolean`, `enum`, `enumOrNumber`, `url`, `icon`, `node`, `array`, `object` or `any`, and a `description`. An enum or enumOrNumber lists its `values`; numbers are allowed in an enum, and an enumOrNumber lists its named values only and also takes any number. Optional `default` (never on a required prop), `required`, `fields` on an object and `itemFields` on an array of objects. |
|
|
70
70
|
| `omit` | Optional. Design props deliberately not described. |
|
|
71
71
|
| `actions` | Optional, web only. Handler name to action stand-in prop name, such as `{ onConfirm: "confirmAction" }`. The manifest lists each stand-in as an object prop with no fields and names it in `takesAction`. |
|
|
72
|
+
| `role` | Optional. `title` or `navigation`: the part's role in the manifest. |
|
|
73
|
+
| `takesAction` | Optional, phone only. Names of object props that each carry one action, such as `leftAction`. Each must be an `object` prop. |
|
|
74
|
+
| `itemsTakeAction` | Optional, phone only. Names of array props whose items each carry an action, such as `tabs`. Each must be an `array` prop. |
|
|
72
75
|
| `examples` | Each has an `id`, a `title`, `props`, optional `children` and optional `wrap`. The id is the name for the base example and `<name>.<case>` for the others. |
|
|
73
76
|
| `usage` | `when` lines, `whenNot` entries with `text` and optional `instead`, `do` and `dont` pairs of `note` and `example` matched by index, and `a11y` lines. |
|
|
74
77
|
|
|
@@ -99,6 +102,7 @@ covers Web metas; a phone meta is proven by mobile-ui's own type check.
|
|
|
99
102
|
- has an empty `when`, `do` and `dont` lists of different lengths, or an `instead` that names an unknown component;
|
|
100
103
|
- has an `icon` outside the kit's icons;
|
|
101
104
|
- has `actions` that are not `on<Event>` names, a stand-in name that is malformed, repeated or also a prop, or `actions` without `web` in `platforms`;
|
|
105
|
+
- has a `role` that is neither `title` nor `navigation`, or `takesAction` or `itemsTakeAction` that is empty, repeats a name, names a prop of the wrong type or lists a name in both, or is on a meta whose `platforms` is not exactly `phone`;
|
|
102
106
|
- has an em or en dash in any string.
|
|
103
107
|
|
|
104
108
|
## Guidance file
|
package/dist/manifest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import"./kitModule.js";import{checkMetaTypes as r}from"./metaCheck.js";import{NOT_DRAWN_FILE as i,checkDrawn as a,componentExports as o,readNotDrawn as s}from"./drawn.js";import{
|
|
1
|
+
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import"./kitModule.js";import{checkMetaTypes as r}from"./metaCheck.js";import{NOT_DRAWN_FILE as i,checkDrawn as a,componentExports as o,readNotDrawn as s}from"./drawn.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{tokensFromV2 as m,webIcons as h}from"./tokens.js";import{existsSync as g}from"node:fs";import{join as _,relative as te,resolve as v}from"node:path";var ne=/^[a-z][a-z0-9-]{1,39}$/,y=[`Web`,`Phone`],b={Web:`WeborityWeb`,Phone:`WeborityPhone`},x={Web:`web`,Phone:`phone`};function S(n,r){let i=_(n,`package.json`),a=g(i)&&t(i).name===r,o=a?n:e(n,r);if(!o)throw Error(`${r} is not installed for ${n}. Run pnpm install there.`);let s=t(_(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(`${r} declares no types, and the manifest reads its declaration files.`);if(!d)throw Error(`${r} declares no entry file for its runtime.`);let f=c(s.exports?.[`./canvasKit`],`default`);return{dir:o,pkg:s,isSelf:a,typesFile:_(o,u),entryFile:_(o,d),canvasKitFile:f?_(o,f):null}}function C(e,n,r){let i=t(_(e,`package.json`)),a=i.dependencies?.[n]??i.devDependencies?.[n];if(/^\d+\.\d+\.\d+$/.test(a??``)&&a!==r)throw Error(`${n} is pinned to ${a} in package.json but ${r} is installed. Run pnpm install first.`)}function w(e,n,r){let i=e.pkg.exports?.[`./canvas-kit/*`];if(typeof i!=`string`)throw Error(`${n} exports no ./canvas-kit/*; a product kit takes the library's components from its kit release.`);let a=_(e.dir,i.replace(`*`,`manifest.json`)),o=t(a);if(!(o?.kind===b[r]&&o.platform===r&&Array.isArray(o.components)&&Array.isArray(o.icons)))throw Error(`${a} is not a ${r} library kit release.`);return o}function T(e,t){let n=x[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 E(e,n){if(!n)return;let r=t(n);if(typeof r!=`object`||!r||Array.isArray(r))throw Error(`${n} must be an object from component name to role.`);for(let[t,i]of Object.entries(r)){let r=e.find(e=>e.name===t);if(!r)throw Error(`${n} names ${t}, which the kit does not have.`);if(!c.includes(i))throw Error(`${n}: ${t} has role ${JSON.stringify(i)}; a role is title or navigation.`);r.role=i}}function re(e){let n=t(e);if(!Array.isArray(n)||n.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 n}function D(e){let n=t(e);if(n?.schema!==1)throw Error(`${e} has schema ${n?.schema}; this reader reads schema 1.`);if(!n.itemActions)throw Error(`${e} has no itemActions; the phone kit's action lists come from it.`);return{flags:n.styleKeys??{},itemActions:n.itemActions}}function O(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 k(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 A=(e,t)=>e.name<t.name?-1:+(e.name>t.name);async function j({projectRoot:t,kit:c,platform:g,entry:x,components:j,tokens:M,libraryPackage:N,rolesFile:P,rendererProtocolVersion:F,phoneRendererSupportFile:I,styleKeysFile:L}){if(!ne.test(c??``))throw Error(`kit ${JSON.stringify(c)} must be 2 to 40 characters: lowercase letters, digits and hyphens, starting with a letter.`);if(!y.includes(g))throw Error(`platform must be Web or Phone, not ${JSON.stringify(g)}.`);if(!Number.isInteger(F)||F<1)throw Error(`rendererProtocolVersion must be a positive integer, not ${JSON.stringify(F)}.`);if(x!==void 0)throw Error(`A kit lists its components with components, a glob of .meta.js files; entry is retired.`);if(typeof j!=`string`||j===``||typeof M!=`string`||M===``)throw Error(`A kit needs components, a glob of .meta.js files, and tokens, the path of its webority-theme-tokens/2 file.`);let R=v(t),z=S(R,N),B=z.isSelf;if(g===`Phone`&&!I&&!B)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.`);B||C(R,N,z.pkg.version);let V=I?D(I):null,H=g===`Phone`?V:null,U=L?re(L):null;U&&V&&O(U,V.flags,I);let W=B?null:w(z,N,g),G;G=B?g===`Web`?h(_(z.dir,`dist`)):p(_(z.dir,`lib`,`typescript`,`module`,`components`,`AppIcon`,`catalog.g.d.ts`)):W.icons;let K=[];B&&(K=await d({root:R,components:j,icons:G}),T(K,g),a({libraryPackage:N,exported:o({root:R,typesFile:z.typesFile}),drawnNames:K.map(({meta:e})=>({name:e.name,component:e.component??e.name})),notDrawn:s(_(z.dir,i))}),g===`Web`&&r({root:R,metas:K,componentOf:()=>z.typesFile}));let q=[],J=new Map;if(!B){let e=W.components.map(({name:e})=>e);q=await d({root:R,components:j,knownNames:e,icons:G}),T(q,g);let t=q.map(({meta:e})=>e.name).filter(t=>e.includes(t));if(t.length>0)throw Error(`The kit names ${t.join(`, `)} as ${N} already has them; rename the product components.`);g===`Web`&&r({root:R,metas:q,componentOf:(e,t)=>l(e,t)});for(let{meta:e,file:t}of q)J.set(e.name,{module:l(t,e.component??e.name),exportName:e.component??e.name,fixedProps:e.fixedProps})}let Y=[];if(g===`Phone`){if(!z.canvasKitFile)throw Error(`${N} exports no ./canvasKit subpath; a Phone kit takes the device frame parts from it.`);Y=ee(z.canvasKitFile,N)}if(B&&g===`Phone`){let e=new Set(K.map(({meta:e})=>e.name)),t=Y.filter(({name:t})=>e.has(t)).map(({name:e})=>e);if(t.length>0)throw Error(`${N} exports ${t.join(`, `)} from both its main entry and ./canvasKit.`)}let X=B?K.map(({meta:e})=>u(e,{platform:g,source:N})):W.components,ie=q.map(({meta:e})=>u(e,{platform:g,source:n(te(R,J.get(e.name).module))})),Z=[...X,...B?Y:[],...ie].sort(A);H&&f(Z,H.itemActions),E(Z,P);let Q=e(R,`@webority/tokens`);if(!Q)throw Error(`@webority/tokens is not installed for ${R}. Run pnpm install there.`);let $=m(v(R,M),_(Q,`dist`,`meanings.json`),g);return{manifest:{kind:B?b[g]:`Product`,library:{name:z.pkg.name,version:z.pkg.version},rendererProtocolVersion:F,platform:g,kitModuleVersion:2,productKit:null,components:Z,tokens:$.tokens,tokenValues:$.tokenValues,icons:G,...U?{styleKeys:k(U,H?H.flags:null)}:{}},warnings:[],phoneChromeNames:Y.map(({name:e})=>e),productModules:J,metas:B?K:q}}export{S as libraryFiles,j as readManifest,D as readPhoneSupport};
|
package/dist/meta.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export interface ComponentMeta {
|
|
|
82
82
|
props: Readonly<Record<string, MetaProp>>;
|
|
83
83
|
/** 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. */
|
|
84
84
|
actions?: Readonly<Record<string, string>>;
|
|
85
|
+
/** The part's role in the manifest: a screen title or a navigation bar. */
|
|
86
|
+
role?: "title" | "navigation";
|
|
87
|
+
/** 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. */
|
|
88
|
+
takesAction?: readonly string[];
|
|
89
|
+
/** Phone only. Names of array props whose items each carry an action, such as AppBar `rightActions` or BottomNavigation `tabs`. */
|
|
90
|
+
itemsTakeAction?: readonly string[];
|
|
85
91
|
/** Design props deliberately not shown in the kit, such as a render prop no kit type fits. The type check accepts them unlisted. */
|
|
86
92
|
omit?: readonly string[];
|
|
87
93
|
examples: readonly MetaExample[];
|
package/dist/metas.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toPosix as e}from"./files.js";import{existsSync as t,globSync as n}from"node:fs";import{basename as r,dirname as i,join as a,resolve as o}from"node:path";import{pathToFileURL as s}from"node:url";var c=Object.freeze([`a`,`b`,`button`,`div`,`img`,`kbd`,`li`,`p`,`span`,`strong`,`table`,`tbody`,`td`,`th`,`thead`,`tr`,`ul`]),l=/^[A-Z][A-Za-z0-9]*$/,
|
|
2
|
-
`))}function y(e,{platform:t,source:n}){let r=Object.keys(e.props).sort(H),i=t===`Web`&&U(e.actions)?Object.values(e.actions):[];return{name:e.name,marker:e.marker,acceptsChildren:e.acceptsChildren,props:[...r.map(t=>I(t,e.props[t])),...i.map(e=>({name:e,type:`object`,fields:[],required:!1}))].sort((e,t)=>H(e.name,t.name)),itemsTakeAction:t===`Web`?r.filter(t=>z(e.props[t])):[],takesAction:[...i].sort(H),source:n,...e.component===void 0?{}:{component:e.component},...e.fixedProps===void 0?{}:{fixedProps:e.fixedProps},usage:e.usage}}function b(n,o){let s=n.replace(/\.meta\.[jt]s$/,``),c=r(s)===o?s:a(i(s),o);for(let n of g)if(t(c+n))return e(c+n);throw Error(`no component module for ${o} beside ${n}`)}function x(e,t,n,r,i,a){if(!U(e)){a.push([`meta`,`must be an object`]);return}let{name:o}=e;typeof o!=`string`||!l.test(o)?a.push([`name`,`"${o}" is not a catalogue name; start with a capital letter and use letters and digits`]):n.has(o)?a.push([`name`,`"${o}" is also the name in ${n.get(o)}`]):n.set(o,t),e.component!==void 0&&(G(e.component)?e.component===o&&a.push([`component`,`"${e.component}" is the name; leave component out when the meta draws its own export`]):a.push([`component`,`must name an export as text`]));let{platforms:s}=e;Array.isArray(s)&&s.length>0&&s.every(e=>e===`web`||e===`phone`)||a.push([`platforms`,`must list web, phone or both`]),e.marker!==null&&typeof e.marker!=`string`&&a.push([`marker`,`must be a string or null`]),typeof e.acceptsChildren!=`boolean`&&a.push([`acceptsChildren`,`must be true or false`]),e.omit!==void 0&&(!Array.isArray(e.omit)||!e.omit.every(e=>typeof e==`string`))&&a.push([`omit`,`must be a list of prop names`]),e.actions!==void 0&&S(e,a);let c=U(e.props)?e.props:{};if(!U(e.props))a.push([`props`,`must be an object`]);else for(let[t,n]of Object.entries(e.props))C(n,`props.${t}`,i,a);let u=new Set;if(e.fixedProps!==void 0)if(e.component===void 0&&a.push([`fixedProps`,`needs component, the export the fixed props go to`]),!U(e.fixedProps)||Object.keys(e.fixedProps).length===0)a.push([`fixedProps`,`must be an object of the props the kit sets`]);else{let t=Array.isArray(e.omit)?e.omit:[];for(let n of Object.keys(e.fixedProps))u.add(n),Object.hasOwn(c,n)?a.push([`fixedProps.${n}`,`is also a prop; a fixed prop is set by the kit, not the panel`]):t.includes(n)&&a.push([`fixedProps.${n}`,`is listed in omit; a prop is fixed or omitted, not both`])}i.fixed={name:o,keys:u},Array.isArray(e.examples)?e.examples.forEach((n,o)=>{j(n,`examples[${o}]`,e,c,t,r,i,a)}):a.push([`examples`,`must be a list`]),M(e.usage,i,a),i.fixed=null,F(e,``,a)}function S(e,t){let{actions:n}=e;if(!U(n)||Object.keys(n).length===0){t.push([`actions`,`must be an object of handler name to action prop name`]);return}(!Array.isArray(e.platforms)||!e.platforms.includes(`web`))&&t.push([`actions`,`only a web component takes actions; add web to platforms or remove actions`]);let r=U(e.props)?e.props:{},i=U(e.fixedProps)?e.fixedProps:{},a=new Map;for(let[e,o]of Object.entries(n)){let n=`actions.${e}`;f.test(e)||t.push([n,`"${e}" is not a handler name (on<Event>)`]),typeof o!=`string`||!p.test(o)?t.push([n,`${V(o)} is not an action prop name; start with a lower-case letter and use letters and digits`]):Object.hasOwn(r,o)||Object.hasOwn(i,o)?t.push([n,`"${o}" is also a prop; an action stand-in is not a library prop`]):a.has(o)?t.push([n,`"${o}" is also the action prop of ${a.get(o)}`]):a.set(o,e)}}function C(e,t,n,r){if(!U(e)){r.push([t,`is not a prop`]);return}if(!h.includes(e.type)){r.push([`${t}.type`,`${V(e.type)} is not a prop type`]);return}if(e.type===`enum`||e.type===`enumOrNumber`?w(e,t,r):e.values!==void 0&&r.push([`${t}.values`,`only an enum or an enumOrNumber has values`]),e.fields!==void 0)if(e.type!==`object`)r.push([`${t}.fields`,`only an object has fields`]);else for(let[i,a]of Object.entries(e.fields))C(a,`${t}.fields.${i}`,n,r);if(e.itemFields!==void 0)if(e.type!==`array`)r.push([`${t}.itemFields`,`only an array has itemFields`]);else for(let[i,a]of Object.entries(e.itemFields))C(a,`${t}.itemFields.${i}`,n,r);if(G(e.description)||r.push([`${t}.description`,`is empty`]),e.required!==void 0&&typeof e.required!=`boolean`&&r.push([`${t}.required`,`must be true or false`]),e.nullable!==void 0&&typeof e.nullable!=`boolean`&&r.push([`${t}.nullable`,`must be true or false`]),e.default!==void 0)if(e.required===!0)r.push([`${t}.default`,`a required prop has no default`]);else{let i=[];T(e.default,e,t,n,i),i.length>0&&r.push([`${t}.default`,`${V(e.default)} does not fit ${e.type}`])}}function w(e,t,n){let{type:r,values:i}=e;if(!Array.isArray(i)||i.length===0){n.push([`${t}.values`,`an ${r} lists its values`]);return}let a=new Set;for(let e of i)(r===`enum`?typeof e==`string`||W(e):typeof e==`string`)?a.has(e)&&n.push([`${t}.values`,`"${e}" is listed twice`]):n.push([`${t}.values`,`${V(e)} is not allowed here`]),a.add(e)}function T(e,t,n,r,i){if(!U(t)||e===null&&(t.nullable===!0||t.type===`node`||t.type===`icon`))return;let a=Array.isArray(t.values)?t.values:[];switch(t.type){case`string`:case`url`:typeof e!=`string`&&B(e,t.type,n,i);return;case`number`:W(e)||B(e,t.type,n,i);return;case`boolean`:typeof e!=`boolean`&&B(e,t.type,n,i);return;case`stringOrNumber`:typeof e!=`string`&&!W(e)&&B(e,t.type,n,i);return;case`enum`:a.includes(e)||i.push([n,`${V(e)} is not one of ${V(a)}`]);return;case`enumOrNumber`:!W(e)&&!a.includes(e)&&i.push([n,`${V(e)} is not one of ${V(a)}`]);return;case`icon`:K(e)?O(e,n,r,i):typeof e==`string`?Array.isArray(r.icons)&&!r.icons.includes(e)&&i.push([n,`"${e}" is not an icon of the kit`]):B(e,t.type,n,i);return;case`node`:Array.isArray(e)?e.forEach((e,t)=>{E(e,`${n}[${t}]`,r,i)}):E(e,n,r,i);return;case`array`:Array.isArray(e)?t.itemFields!==void 0&&e.forEach((e,a)=>{U(e)?D(e,t.itemFields,`${n}[${a}]`,r,i):i.push([`${n}[${a}]`,`${V(e)} is not an object`])}):B(e,t.type,n,i);return;case`object`:U(e)?t.fields!==void 0&&D(e,t.fields,n,r,i):B(e,t.type,n,i);return;default:return}}function E(e,t,n,r){K(e)?O(e,t,n,r):typeof e!=`string`&&!W(e)&&r.push([t,`${V(e)} is not a node`])}function D(e,t,n,r,i){for(let a of Object.keys(e))Object.hasOwn(t,a)?T(e[a],t[a],`${n}.${a}`,r,i):i.push([`${n}.${a}`,`not a field`]);for(let[r,a]of Object.entries(t))U(a)&&a.required===!0&&!Object.hasOwn(e,r)&&i.push([`${n}.${r}`,`missing, the field is required`])}function O(e,t,n,r){let{component:i}=e,a=n.byName.get(i);if(!a&&!n.knownNames.has(i)&&!c.includes(i)&&r.push([`${t}.component`,`"${i}" is neither a component of the kit nor one of the HTML tags`]),a&&e.props!==void 0)if(!U(e.props))r.push([`${t}.props`,`must be an object`]);else{let o=U(a.props)?a.props:{};for(let[a,s]of Object.entries(e.props))n.fixed&&n.fixed.name===i&&n.fixed.keys.has(a)?r.push([`${t}.props.${a}`,`is a fixed prop; the kit sets it`]):Object.hasOwn(o,a)?T(s,o[a],`${t}.props.${a}`,n,r):r.push([`${t}.props.${a}`,`not a prop of ${i}`])}e.children!==void 0&&(a&&a.acceptsChildren===!1&&r.push([`${t}.children`,`${i} takes no children`]),A(e.children,`${t}.children`,n,r)),e.handlers!==void 0&&k(e.handlers,`${t}.handlers`,i,a,r)}function k(e,t,n,r,i){if(!Array.isArray(e)||!e.every(e=>typeof e==`string`)){i.push([t,`must be a list of handler names`]);return}if(c.includes(n)){i.push([t,`handlers need a kit component`]);return}if(e.length===0){i.push([t,`omit handlers when empty`]);return}let a=new Set;for(let o of e)f.test(o)?a.has(o)?i.push([t,`"${o}" is listed twice`]):r&&U(r.props)&&Object.hasOwn(r.props,o)&&i.push([t,`"${o}" is a data prop of ${n}, set it in props`]):i.push([t,`"${o}" is not a handler name (on<Event>)`]),a.add(o)}function A(e,t,n,r){if(typeof e!=`string`){if(!Array.isArray(e)){r.push([t,`is text or a list of text and placed elements`]);return}e.forEach((e,i)=>{typeof e!=`string`&&(K(e)?O(e,`${t}[${i}]`,n,r):r.push([`${t}[${i}]`,`is neither text nor a placed element`]))})}}function j(e,t,n,r,i,a,o,s){if(!U(e)){s.push([t,`is not an example`]);return}let{name:c}=n,{id:l}=e;if(typeof l==`string`&&(l===c||l.startsWith(`${c}.`)&&u.test(l.slice(c.length+1)))?a.has(l)?s.push([`${t}.id`,`"${l}" is also used in ${a.get(l)}`]):a.set(l,i):s.push([`${t}.id`,`"${l}" must be ${c} or ${c}.<case>`]),G(e.title)||s.push([`${t}.title`,`is empty`]),!U(e.props))s.push([`${t}.props`,`must be an object`]);else{for(let[n,i]of Object.entries(e.props))o.fixed?.keys.has(n)?s.push([`${t}.props.${n}`,`is a fixed prop; the kit sets it`]):Object.hasOwn(r,n)?T(i,r[n],`${t}.props.${n}`,o,s):s.push([`${t}.props.${n}`,`not a prop of ${c}`]);for(let[n,i]of Object.entries(r))U(i)&&i.required===!0&&!Object.hasOwn(e.props,n)&&s.push([`${t}.props.${n}`,`missing, the prop is required`])}e.children!==void 0&&(n.acceptsChildren===!1&&s.push([`${t}.children`,`${c} takes no children`]),A(e.children,`${t}.children`,o,s)),e.wrap!==void 0&&(K(e.wrap)?O(e.wrap,`${t}.wrap`,o,s):s.push([`${t}.wrap`,`is not a placed element`])),e.handlers!==void 0&&k(e.handlers,`${t}.handlers`,c,n,s)}function M(e,t,n){if(!U(e)){n.push([`usage`,`must be an object`]);return}(!Array.isArray(e.when)||e.when.length===0||!e.when.every(G))&&n.push([`usage.when`,`lists nothing; write at least one line`]),Array.isArray(e.whenNot)?e.whenNot.forEach((e,r)=>{N(e,`usage.whenNot[${r}]`,t,n)}):n.push([`usage.whenNot`,`must be a list`]),Array.isArray(e.do)||n.push([`usage.do`,`must be a list`]),Array.isArray(e.dont)||n.push([`usage.dont`,`must be a list`]),Array.isArray(e.do)&&Array.isArray(e.dont)&&(e.do.length!==e.dont.length&&n.push([`usage`,`${e.do.length} do against ${e.dont.length} dont; they pair up one to one`]),e.do.forEach((e,r)=>{P(e,`usage.do[${r}]`,t,n)}),e.dont.forEach((e,r)=>{P(e,`usage.dont[${r}]`,t,n)})),Array.isArray(e.a11y)?e.a11y.forEach((e,t)=>{G(e)||n.push([`usage.a11y[${t}]`,`is empty`])}):n.push([`usage.a11y`,`must be a list`])}function N(e,t,n,r){if(!U(e)){r.push([t,`is not an object`]);return}G(e.text)||r.push([`${t}.text`,`is empty`]),e.instead!==void 0&&(typeof e.instead==`string`?d.test(e.instead)&&!n.byName.has(e.instead)&&!n.knownNames.has(e.instead)&&r.push([`${t}.instead`,`"${e.instead}" is not a component of the kit`]):r.push([`${t}.instead`,`must be text`]))}function P(e,t,n,r){if(!U(e)){r.push([t,`is not a practice`]);return}if(G(e.note)||r.push([`${t}.note`,`is empty`]),!Array.isArray(e.example)||e.example.length===0){r.push([`${t}.example`,`needs at least one placed element`]);return}e.example.forEach((e,i)=>{let a=`${t}.example[${i}]`;K(e)?O(e,a,n,r):r.push([a,`is not a placed element`])})}function F(e,t,n){if(typeof e==`string`)m.test(e)&&n.push([t,`contains an em or en dash; use a comma, colon or period`]);else if(Array.isArray(e))e.forEach((e,r)=>{F(e,`${t}[${r}]`,n)});else if(U(e))for(let[r,i]of Object.entries(e))F(i,t?`${t}.${r}`:r,n)}function I(e,t){let n={name:e,type:t.type};return(t.type===`enum`||t.type===`enumOrNumber`)&&(n.enum=R(t.values)),t.fields!==void 0&&(n.fields=L(t.fields)),t.itemFields!==void 0&&(n.itemFields=L(t.itemFields)),n.required=t.required===!0,t.nullable===!0&&(n.nullable=!0),t.description!==void 0&&(n.description=t.description),t.default!==void 0&&(n.default=t.default),n}function L(e){return Object.keys(e).sort(H).map(t=>I(t,e[t]))}function R(e){return[...e].sort((e,t)=>{let n=typeof e==`number`,r=typeof t==`number`;return n&&r?e-t:n===r?H(e,t):n?-1:1})}function z(e){return e.type===`array`&&Object.keys(e.itemFields??{}).some(e=>e===`href`||e===`to`)}function B(e,t,n,r){r.push([n,`${V(e)} is not a ${t}`])}function V(e){return JSON.stringify(e)}function H(e,t){return e<t?-1:+(e>t)}function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function W(e){return typeof e==`number`&&Number.isFinite(e)}function G(e){return typeof e==`string`&&e.trim()!==``}function K(e){return U(e)&&typeof e.component==`string`}export{c as HTML_TAGS,v as checkMetas,b as componentModuleOf,y as manifestComponent,_ as readMetas};
|
|
1
|
+
import{toPosix as e}from"./files.js";import{existsSync as t,globSync as n}from"node:fs";import{basename as r,dirname as i,join as a,resolve as o}from"node:path";import{pathToFileURL as s}from"node:url";var c=Object.freeze([`a`,`b`,`button`,`div`,`img`,`kbd`,`li`,`p`,`span`,`strong`,`table`,`tbody`,`td`,`th`,`thead`,`tr`,`ul`]),l=Object.freeze([`title`,`navigation`]),u=/^[A-Z][A-Za-z0-9]*$/,d=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,f=/^App[A-Za-z0-9]*$/,p=/^on[A-Z][A-Za-z0-9]*$/,m=/^[a-z][A-Za-z0-9]*$/,h=/[\u2013\u2014]/,g=[`string`,`number`,`stringOrNumber`,`boolean`,`enum`,`enumOrNumber`,`url`,`icon`,`node`,`array`,`object`,`any`],_=[`.jsx`,`.tsx`,`.js`,`.ts`];async function v({root:e,components:t,knownNames:r,icons:i}){let a=n(t,{cwd:e});if(a.length===0)throw Error(`${e}: no component metadata matches ${t}`);let c=a.map(t=>o(e,t)).sort(G),l=[];for(let e of c){let t=await import(s(e).href);if(!(`meta`in t))throw Error(`${e}: exports no meta; write export const meta = defineMeta({...})`);l.push({meta:t.meta,file:e})}return y(l,{knownNames:r,icons:i}),l.sort((e,t)=>G(e.meta.name,t.meta.name))}function y(e,{knownNames:t=[],icons:n}={}){let r=new Map;for(let{meta:t}of e)K(t)&&typeof t.name==`string`&&!r.has(t.name)&&r.set(t.name,t);let i={byName:r,knownNames:new Set(t),icons:n},a=new Map,o=new Map,s=[];for(let{meta:t,file:n}of e){let e=[];S(t,n,a,o,i,e);for(let[t,r]of e)s.push(`${n}: ${t}: ${r}`)}if(s.length>0)throw Error(s.join(`
|
|
2
|
+
`))}function b(e,{platform:t,source:n}){let r=Object.keys(e.props).sort(G),i=t===`Web`&&K(e.actions)?Object.values(e.actions):[];return{name:e.name,marker:e.marker,acceptsChildren:e.acceptsChildren,props:[...r.map(t=>z(t,e.props[t])),...i.map(e=>({name:e,type:`object`,fields:[],required:!1}))].sort((e,t)=>G(e.name,t.name)),itemsTakeAction:t===`Web`?r.filter(t=>H(e.props[t])):[...e.itemsTakeAction??[]].sort(G),takesAction:t===`Web`?[...i].sort(G):[...e.takesAction??[]].sort(G),source:n,...e.component===void 0?{}:{component:e.component},...e.fixedProps===void 0?{}:{fixedProps:e.fixedProps},...e.role===void 0?{}:{role:e.role},usage:e.usage}}function x(n,o){let s=n.replace(/\.meta\.[jt]s$/,``),c=r(s)===o?s:a(i(s),o);for(let n of _)if(t(c+n))return e(c+n);throw Error(`no component module for ${o} beside ${n}`)}function S(e,t,n,r,i,a){if(!K(e)){a.push([`meta`,`must be an object`]);return}let{name:o}=e;typeof o!=`string`||!u.test(o)?a.push([`name`,`"${o}" is not a catalogue name; start with a capital letter and use letters and digits`]):n.has(o)?a.push([`name`,`"${o}" is also the name in ${n.get(o)}`]):n.set(o,t),e.component!==void 0&&(J(e.component)?e.component===o&&a.push([`component`,`"${e.component}" is the name; leave component out when the meta draws its own export`]):a.push([`component`,`must name an export as text`]));let{platforms:s}=e;Array.isArray(s)&&s.length>0&&s.every(e=>e===`web`||e===`phone`)||a.push([`platforms`,`must list web, phone or both`]),e.marker!==null&&typeof e.marker!=`string`&&a.push([`marker`,`must be a string or null`]),typeof e.acceptsChildren!=`boolean`&&a.push([`acceptsChildren`,`must be true or false`]),e.omit!==void 0&&(!Array.isArray(e.omit)||!e.omit.every(e=>typeof e==`string`))&&a.push([`omit`,`must be a list of prop names`]),e.actions!==void 0&&C(e,a),e.role!==void 0&&!l.includes(e.role)&&a.push([`role`,`must be "title" or "navigation"`]),T(e,a);let c=K(e.props)?e.props:{};if(!K(e.props))a.push([`props`,`must be an object`]);else for(let[t,n]of Object.entries(e.props))E(n,`props.${t}`,i,a);let d=new Set;if(e.fixedProps!==void 0)if(e.component===void 0&&a.push([`fixedProps`,`needs component, the export the fixed props go to`]),!K(e.fixedProps)||Object.keys(e.fixedProps).length===0)a.push([`fixedProps`,`must be an object of the props the kit sets`]);else{let t=Array.isArray(e.omit)?e.omit:[];for(let n of Object.keys(e.fixedProps))d.add(n),Object.hasOwn(c,n)?a.push([`fixedProps.${n}`,`is also a prop; a fixed prop is set by the kit, not the panel`]):t.includes(n)&&a.push([`fixedProps.${n}`,`is listed in omit; a prop is fixed or omitted, not both`])}i.fixed={name:o,keys:d},Array.isArray(e.examples)?e.examples.forEach((n,o)=>{P(n,`examples[${o}]`,e,c,t,r,i,a)}):a.push([`examples`,`must be a list`]),F(e.usage,i,a),i.fixed=null,R(e,``,a)}function C(e,t){let{actions:n}=e;if(!K(n)||Object.keys(n).length===0){t.push([`actions`,`must be an object of handler name to action prop name`]);return}(!Array.isArray(e.platforms)||!e.platforms.includes(`web`))&&t.push([`actions`,`only a web component takes actions; add web to platforms or remove actions`]);let r=K(e.props)?e.props:{},i=K(e.fixedProps)?e.fixedProps:{},a=new Map;for(let[e,o]of Object.entries(n)){let n=`actions.${e}`;p.test(e)||t.push([n,`"${e}" is not a handler name (on<Event>)`]),typeof o!=`string`||!m.test(o)?t.push([n,`${W(o)} is not an action prop name; start with a lower-case letter and use letters and digits`]):Object.hasOwn(r,o)||Object.hasOwn(i,o)?t.push([n,`"${o}" is also a prop; an action stand-in is not a library prop`]):a.has(o)?t.push([n,`"${o}" is also the action prop of ${a.get(o)}`]):a.set(o,e)}}var w=[[`takesAction`,`object`],[`itemsTakeAction`,`array`]];function T(e,t){let n=K(e.props)?e.props:{},r=new Map,i=!1;for(let[a,o]of w){let s=e[a];if(s===void 0)continue;if(i=!0,!Array.isArray(s)||s.length===0||!s.every(e=>typeof e==`string`)){t.push([a,`must be a non-empty list of prop names`]);continue}let c=new Set;for(let e of s)c.has(e)?t.push([a,`"${e}" is listed twice`]):r.has(e)?t.push([a,`"${e}" is also in ${r.get(e)}`]):(!Object.hasOwn(n,e)||!K(n[e])||n[e].type!==o)&&t.push([a,`"${e}" is not ${o===`object`?`an object`:`an array`} prop`]),c.add(e),r.has(e)||r.set(e,a)}let a=Array.isArray(e.platforms)&&e.platforms.length===1&&e.platforms[0]===`phone`;i&&!a&&t.push([`takesAction`,`only a phone component declares takesAction and itemsTakeAction; a web component uses actions`])}function E(e,t,n,r){if(!K(e)){r.push([t,`is not a prop`]);return}if(!g.includes(e.type)){r.push([`${t}.type`,`${W(e.type)} is not a prop type`]);return}if(e.type===`enum`||e.type===`enumOrNumber`?D(e,t,r):e.values!==void 0&&r.push([`${t}.values`,`only an enum or an enumOrNumber has values`]),e.fields!==void 0)if(e.type!==`object`)r.push([`${t}.fields`,`only an object has fields`]);else for(let[i,a]of Object.entries(e.fields))E(a,`${t}.fields.${i}`,n,r);if(e.itemFields!==void 0)if(e.type!==`array`)r.push([`${t}.itemFields`,`only an array has itemFields`]);else for(let[i,a]of Object.entries(e.itemFields))E(a,`${t}.itemFields.${i}`,n,r);if(J(e.description)||r.push([`${t}.description`,`is empty`]),e.required!==void 0&&typeof e.required!=`boolean`&&r.push([`${t}.required`,`must be true or false`]),e.nullable!==void 0&&typeof e.nullable!=`boolean`&&r.push([`${t}.nullable`,`must be true or false`]),e.default!==void 0)if(e.required===!0)r.push([`${t}.default`,`a required prop has no default`]);else{let i=[];O(e.default,e,t,n,i),i.length>0&&r.push([`${t}.default`,`${W(e.default)} does not fit ${e.type}`])}}function D(e,t,n){let{type:r,values:i}=e;if(!Array.isArray(i)||i.length===0){n.push([`${t}.values`,`an ${r} lists its values`]);return}let a=new Set;for(let e of i)(r===`enum`?typeof e==`string`||q(e):typeof e==`string`)?a.has(e)&&n.push([`${t}.values`,`"${e}" is listed twice`]):n.push([`${t}.values`,`${W(e)} is not allowed here`]),a.add(e)}function O(e,t,n,r,i){if(!K(t)||e===null&&(t.nullable===!0||t.type===`node`||t.type===`icon`))return;let a=Array.isArray(t.values)?t.values:[];switch(t.type){case`string`:case`url`:typeof e!=`string`&&U(e,t.type,n,i);return;case`number`:q(e)||U(e,t.type,n,i);return;case`boolean`:typeof e!=`boolean`&&U(e,t.type,n,i);return;case`stringOrNumber`:typeof e!=`string`&&!q(e)&&U(e,t.type,n,i);return;case`enum`:a.includes(e)||i.push([n,`${W(e)} is not one of ${W(a)}`]);return;case`enumOrNumber`:!q(e)&&!a.includes(e)&&i.push([n,`${W(e)} is not one of ${W(a)}`]);return;case`icon`:Y(e)?j(e,n,r,i):typeof e==`string`?Array.isArray(r.icons)&&!r.icons.includes(e)&&i.push([n,`"${e}" is not an icon of the kit`]):U(e,t.type,n,i);return;case`node`:Array.isArray(e)?e.forEach((e,t)=>{k(e,`${n}[${t}]`,r,i)}):k(e,n,r,i);return;case`array`:Array.isArray(e)?t.itemFields!==void 0&&e.forEach((e,a)=>{K(e)?A(e,t.itemFields,`${n}[${a}]`,r,i):i.push([`${n}[${a}]`,`${W(e)} is not an object`])}):U(e,t.type,n,i);return;case`object`:K(e)?t.fields!==void 0&&A(e,t.fields,n,r,i):U(e,t.type,n,i);return;default:return}}function k(e,t,n,r){Y(e)?j(e,t,n,r):typeof e!=`string`&&!q(e)&&r.push([t,`${W(e)} is not a node`])}function A(e,t,n,r,i){for(let a of Object.keys(e))Object.hasOwn(t,a)?O(e[a],t[a],`${n}.${a}`,r,i):i.push([`${n}.${a}`,`not a field`]);for(let[r,a]of Object.entries(t))K(a)&&a.required===!0&&!Object.hasOwn(e,r)&&i.push([`${n}.${r}`,`missing, the field is required`])}function j(e,t,n,r){let{component:i}=e,a=n.byName.get(i);if(!a&&!n.knownNames.has(i)&&!c.includes(i)&&r.push([`${t}.component`,`"${i}" is neither a component of the kit nor one of the HTML tags`]),a&&e.props!==void 0)if(!K(e.props))r.push([`${t}.props`,`must be an object`]);else{let o=K(a.props)?a.props:{};for(let[a,s]of Object.entries(e.props))n.fixed&&n.fixed.name===i&&n.fixed.keys.has(a)?r.push([`${t}.props.${a}`,`is a fixed prop; the kit sets it`]):Object.hasOwn(o,a)?O(s,o[a],`${t}.props.${a}`,n,r):r.push([`${t}.props.${a}`,`not a prop of ${i}`])}e.children!==void 0&&(a&&a.acceptsChildren===!1&&r.push([`${t}.children`,`${i} takes no children`]),N(e.children,`${t}.children`,n,r)),e.handlers!==void 0&&M(e.handlers,`${t}.handlers`,i,a,r)}function M(e,t,n,r,i){if(!Array.isArray(e)||!e.every(e=>typeof e==`string`)){i.push([t,`must be a list of handler names`]);return}if(c.includes(n)){i.push([t,`handlers need a kit component`]);return}if(e.length===0){i.push([t,`omit handlers when empty`]);return}let a=new Set;for(let o of e)p.test(o)?a.has(o)?i.push([t,`"${o}" is listed twice`]):r&&K(r.props)&&Object.hasOwn(r.props,o)&&i.push([t,`"${o}" is a data prop of ${n}, set it in props`]):i.push([t,`"${o}" is not a handler name (on<Event>)`]),a.add(o)}function N(e,t,n,r){if(typeof e!=`string`){if(!Array.isArray(e)){r.push([t,`is text or a list of text and placed elements`]);return}e.forEach((e,i)=>{typeof e!=`string`&&(Y(e)?j(e,`${t}[${i}]`,n,r):r.push([`${t}[${i}]`,`is neither text nor a placed element`]))})}}function P(e,t,n,r,i,a,o,s){if(!K(e)){s.push([t,`is not an example`]);return}let{name:c}=n,{id:l}=e;if(typeof l==`string`&&(l===c||l.startsWith(`${c}.`)&&d.test(l.slice(c.length+1)))?a.has(l)?s.push([`${t}.id`,`"${l}" is also used in ${a.get(l)}`]):a.set(l,i):s.push([`${t}.id`,`"${l}" must be ${c} or ${c}.<case>`]),J(e.title)||s.push([`${t}.title`,`is empty`]),!K(e.props))s.push([`${t}.props`,`must be an object`]);else{for(let[n,i]of Object.entries(e.props))o.fixed?.keys.has(n)?s.push([`${t}.props.${n}`,`is a fixed prop; the kit sets it`]):Object.hasOwn(r,n)?O(i,r[n],`${t}.props.${n}`,o,s):s.push([`${t}.props.${n}`,`not a prop of ${c}`]);for(let[n,i]of Object.entries(r))K(i)&&i.required===!0&&!Object.hasOwn(e.props,n)&&s.push([`${t}.props.${n}`,`missing, the prop is required`])}e.children!==void 0&&(n.acceptsChildren===!1&&s.push([`${t}.children`,`${c} takes no children`]),N(e.children,`${t}.children`,o,s)),e.wrap!==void 0&&(Y(e.wrap)?j(e.wrap,`${t}.wrap`,o,s):s.push([`${t}.wrap`,`is not a placed element`])),e.handlers!==void 0&&M(e.handlers,`${t}.handlers`,c,n,s)}function F(e,t,n){if(!K(e)){n.push([`usage`,`must be an object`]);return}(!Array.isArray(e.when)||e.when.length===0||!e.when.every(J))&&n.push([`usage.when`,`lists nothing; write at least one line`]),Array.isArray(e.whenNot)?e.whenNot.forEach((e,r)=>{I(e,`usage.whenNot[${r}]`,t,n)}):n.push([`usage.whenNot`,`must be a list`]),Array.isArray(e.do)||n.push([`usage.do`,`must be a list`]),Array.isArray(e.dont)||n.push([`usage.dont`,`must be a list`]),Array.isArray(e.do)&&Array.isArray(e.dont)&&(e.do.length!==e.dont.length&&n.push([`usage`,`${e.do.length} do against ${e.dont.length} dont; they pair up one to one`]),e.do.forEach((e,r)=>{L(e,`usage.do[${r}]`,t,n)}),e.dont.forEach((e,r)=>{L(e,`usage.dont[${r}]`,t,n)})),Array.isArray(e.a11y)?e.a11y.forEach((e,t)=>{J(e)||n.push([`usage.a11y[${t}]`,`is empty`])}):n.push([`usage.a11y`,`must be a list`])}function I(e,t,n,r){if(!K(e)){r.push([t,`is not an object`]);return}J(e.text)||r.push([`${t}.text`,`is empty`]),e.instead!==void 0&&(typeof e.instead==`string`?f.test(e.instead)&&!n.byName.has(e.instead)&&!n.knownNames.has(e.instead)&&r.push([`${t}.instead`,`"${e.instead}" is not a component of the kit`]):r.push([`${t}.instead`,`must be text`]))}function L(e,t,n,r){if(!K(e)){r.push([t,`is not a practice`]);return}if(J(e.note)||r.push([`${t}.note`,`is empty`]),!Array.isArray(e.example)||e.example.length===0){r.push([`${t}.example`,`needs at least one placed element`]);return}e.example.forEach((e,i)=>{let a=`${t}.example[${i}]`;Y(e)?j(e,a,n,r):r.push([a,`is not a placed element`])})}function R(e,t,n){if(typeof e==`string`)h.test(e)&&n.push([t,`contains an em or en dash; use a comma, colon or period`]);else if(Array.isArray(e))e.forEach((e,r)=>{R(e,`${t}[${r}]`,n)});else if(K(e))for(let[r,i]of Object.entries(e))R(i,t?`${t}.${r}`:r,n)}function z(e,t){let n={name:e,type:t.type};return(t.type===`enum`||t.type===`enumOrNumber`)&&(n.enum=V(t.values)),t.fields!==void 0&&(n.fields=B(t.fields)),t.itemFields!==void 0&&(n.itemFields=B(t.itemFields)),n.required=t.required===!0,t.nullable===!0&&(n.nullable=!0),t.description!==void 0&&(n.description=t.description),t.default!==void 0&&(n.default=t.default),n}function B(e){return Object.keys(e).sort(G).map(t=>z(t,e[t]))}function V(e){return[...e].sort((e,t)=>{let n=typeof e==`number`,r=typeof t==`number`;return n&&r?e-t:n===r?G(e,t):n?-1:1})}function H(e){return e.type===`array`&&Object.keys(e.itemFields??{}).some(e=>e===`href`||e===`to`)}function U(e,t,n,r){r.push([n,`${W(e)} is not a ${t}`])}function W(e){return JSON.stringify(e)}function G(e,t){return e<t?-1:+(e>t)}function K(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function q(e){return typeof e==`number`&&Number.isFinite(e)}function J(e){return typeof e==`string`&&e.trim()!==``}function Y(e){return K(e)&&typeof e.component==`string`}export{c as HTML_TAGS,l as ROLES,y as checkMetas,x as componentModuleOf,b as manifestComponent,v as readMetas};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/canvas-kit",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.4",
|
|
4
4
|
"description": "Builds product kits for Webority Canvas: a kit bundle, its manifest, and the spec shape the renderers answer.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"private": false,
|