@webority/canvas-kit 0.98.0 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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(`
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
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
3
  `)}`):(D.sort((e,t)=>e.owner-t.owner||e.rank-t.rank),Error(D.map(e=>e.text).join(`
4
4
  `)))}finally{i(f,{recursive:!0,force:!0})}}export{u as TSC,b as checkMetaTypes,g as specifierOf};
package/dist/metas.js CHANGED
@@ -1,2 +1,2 @@
1
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]*$/,u=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,d=/^App[A-Za-z0-9]*$/,f=/^on[A-Z][A-Za-z0-9]*$/,p=/^[a-z][A-Za-z0-9]*$/,m=/[\u2013\u2014]/,h=[`string`,`number`,`stringOrNumber`,`boolean`,`enum`,`enumOrNumber`,`url`,`icon`,`node`,`array`,`object`,`any`],g=[`.jsx`,`.tsx`,`.js`,`.ts`];async function _({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(H),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 v(l,{knownNames:r,icons:i}),l.sort((e,t)=>H(e.meta.name,t.meta.name))}function v(e,{knownNames:t=[],icons:n}={}){let r=new Map;for(let{meta:t}of e)U(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=[];x(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 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&&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};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/canvas-kit",
3
- "version": "0.98.0",
3
+ "version": "0.100.0",
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,