@webority/canvas-kit 0.121.0 → 0.124.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/ids.js CHANGED
@@ -1 +1 @@
1
- import{basename as e,dirname as t,extname as n,join as r,relative as i,sep as a}from"node:path";import o from"@babel/parser";import{readFile as s,readdir as c,writeFile as l}from"node:fs/promises";var u=new Set([`node_modules`,`dist`,`build`]),d=new Set([`.jsx`,`.tsx`,`.js`]),f=[`react-native`,`@webority/mobile-ui`],p=new Set([`@webority/ui-react`,`@webority/mobile-ui`]),m=new Set([`section`,`form`,`header`,`nav`,`main`,`aside`,`article`,`fieldset`]),h=[`aria-label`,`name`,`id`,`title`,`label`,`placeholder`],g=new Set([`ArrowFunctionExpression`,`FunctionExpression`,`FunctionDeclaration`,`ObjectMethod`,`ClassMethod`]),_=new Set([`loc`,`start`,`end`,`comments`,`leadingComments`,`trailingComments`,`innerComments`,`tokens`,`extra`,`errors`]),v=40,y=new Set([`Fragment`,`React.Fragment`]);async function b(e,{write:t=!1}={}){let n=[],r=[],o=[],c=new Map;for(let t of await C(e)){let l=i(e,t).split(a).join(`/`),u=await s(t,`utf8`),d=w({source:u,file:t,label:l,phone:await x(t,c)});n.push(...d.proposals),r.push(...d.noKey),d.insertions.length>0&&o.push({file:t,source:u,insertions:d.insertions})}let u=0;if(t)for(let e of o){let t=e.source;for(let n of[...e.insertions].sort((e,t)=>t.offset-e.offset))t=`${t.slice(0,n.offset)}${n.text}${t.slice(n.offset)}`;await l(e.file,t,`utf8`),u+=e.insertions.length}return{proposals:n,noKey:r,written:u}}async function x(e,n){let i=[],a=t(e),o;for(;;){if(n.has(a)){o=n.get(a);break}i.push(a);let s=await S(r(a,`package.json`));if(s!==null){o=f.some(e=>s.dependencies?.[e]||s.peerDependencies?.[e]);break}let c=t(a);if(c===a)throw Error(`no package.json above ${e}`);a=c}for(let e of i)n.set(e,o);return o}async function S(e){try{return JSON.parse(await s(e,`utf8`))}catch(e){if(e.code===`ENOENT`)return null;throw e}}async function C(e){let t=await c(e,{withFileTypes:!0});t.sort((e,t)=>e.name<t.name?-1:1);let i=[];for(let a of t){let t=r(e,a.name);a.isDirectory()?u.has(a.name)||i.push(...await C(t)):a.isFile()&&d.has(n(a.name))&&!a.name.includes(`.test.`)&&i.push(t)}return i}function w({source:e,file:t,label:n,phone:r}){let i;try{i=o.parse(e,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch(e){throw Error(`${n}: ${e.message}`)}let a=new Set;for(let e of i.program.body){if(e.type!==`ImportDeclaration`)continue;let t=e.source.value;if(p.has(t))for(let t of e.specifiers)t.type===`ImportSpecifier`&&a.add(t.local.name)}let s=r?`testID`:`data-canvas`,c=new Map,l=[];T(i.program,null,c,l);let u=L(t),d=t=>e.slice(t.start,t.end),f=new Map,m=[],h=[];for(let e of l){let t=e.openingElement,r=P(t,s),i=j(t,a),o=E(e,c);if(i!==null&&o===null&&A(f,e,i,r,c),!r)if(o!==null){let r=t.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===`key`)?.value,i=r?.type===`JSXExpressionContainer`?r.expression:null,a=o.params[1]?.type===`Identifier`?o.params[1].name:null,c=y.has(d(t.name))?D(e,d):e;c===null||i===null||i.type===`JSXEmptyExpression`||V(i)||i.type===`Identifier`&&i.name===a?h.push({start:e.start,entry:{file:n,line:e.loc.start.line,element:d(t.name)}}):(c===e||!P(c.openingElement,s))&&m.push({element:c,kind:`list`,keyExpression:i})}else i===null&&M(t)&&m.push({element:e,kind:`block`})}for(let e of f.values())for(let t of e.values())if(t.length>1&&t.some(e=>e.conditional))for(let e of t)e.skipped||m.push({element:e.element,kind:`sibling`});m.sort((e,t)=>e.element.start-t.element.start);let g=new Set,_=[],v=[];for(let e of m){let{element:t,kind:r}=e,i=t.openingElement,o=d(i.name),c=j(i,a),l=`${u}.${I(t,c===null?o:R(c))}`,f=r===`list`?`${l}.\${${d(e.keyExpression)}}`:l,p=f;if(g.has(p)){let e=2;for(;g.has(`${f}-${e}`);)e+=1;p=`${f}-${e}`}g.add(p);let m=r===`list`?` ${s}={\`${p}\`}`:` ${s}="${p}"`;_.push({file:n,line:t.loc.start.line,element:o,key:p}),v.push({offset:i.name.end,text:m})}return{proposals:_,noKey:h.sort((e,t)=>e.start-t.start).map(e=>e.entry),insertions:v}}function T(e,t,n,r){t!==null&&n.set(e,t),e.type===`JSXElement`&&r.push(e);for(let t of Object.keys(e)){if(_.has(t))continue;let i=e[t];for(let t of Array.isArray(i)?i:[i])typeof t==`object`&&t&&typeof t.type==`string`&&T(t,e,n,r)}}function E(e,t){let n=t.get(e),r=null;if(n?.type===`ArrowFunctionExpression`&&n.body===e)r=n;else if(n?.type===`ReturnStatement`){let e=t.get(n),i=t.get(e);e?.type===`BlockStatement`&&g.has(i?.type)&&i.body===e&&(r=i)}if(r===null)return null;let i=t.get(r);return i?.type===`CallExpression`&&i.arguments[0]===r&&i.callee.type===`MemberExpression`&&!i.callee.computed&&i.callee.property.type===`Identifier`&&i.callee.property.name===`map`?r:null}function D(e,t){for(let n of e.children)if(n.type===`JSXFragment`||n.type===`JSXElement`&&y.has(t(n.openingElement.name))){let e=D(n,t);if(e!==null)return e}else if(n.type===`JSXElement`)return n;return null}function O(e,t){for(let n=t.get(e);n!==void 0;n=t.get(n)){if(n.type===`JSXElement`||n.type===`JSXFragment`)return n;if(g.has(n.type))return null}return null}function k(e,t,n){for(let r=n.get(e);r!==t;r=n.get(r))if(r.type===`ConditionalExpression`||r.type===`LogicalExpression`&&r.operator===`&&`)return!0;return!1}function A(e,t,n,r,i){let a=O(t,i);if(a===null)return;e.has(a)||e.set(a,new Map);let o=e.get(a);o.has(n)||o.set(n,[]),o.get(n).push({element:t,skipped:r,conditional:k(t,a,i)})}function j(e,t){return e.name.type===`JSXIdentifier`&&t.has(e.name.name)?e.name.name:null}function M(e){if(e.name.type!==`JSXIdentifier`)return!1;let t=e.name.name;return m.has(t)||t===`div`&&(N(e,`id`)||N(e,`aria-label`))}function N(e,t){return e.attributes.some(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)}function P(e,t){return e.attributes.some(e=>e.type===`JSXSpreadAttribute`)||N(e,t)}function F(e,t){let n=e.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)?.value;if(n){if(n.type===`StringLiteral`)return n.value;if(n.type===`JSXExpressionContainer`){let e=n.expression;if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`&&e.expressions.length===0)return e.quasis[0].value.cooked??void 0}}}function I(e,t){for(let t of h){let n=F(e.openingElement,t),r=n===void 0?``:B(z(n));if(r!==``)return r}let n=e.children.filter(e=>e.type===`JSXText`&&e.value.trim()!==``);if(n.length===1){let e=B(z(n[0].value));if(e!==``)return e}return B(z(t))}function L(t){return z(e(t,n(t))).replace(/-(screen|page)$/,``)}function R(e){return e.replace(/^App(?=[A-Z])/,``)}function z(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function B(e){if(e.length<=v)return e;let t=e.slice(0,41).lastIndexOf(`-`);return t>0?e.slice(0,t):e.slice(0,v)}function V(e){return e.type===`TemplateLiteral`?e.expressions.length===0:/Literal$/.test(e.type)}export{b as proposeCanvasKeys};
1
+ import{basename as e,dirname as t,extname as n,join as r,relative as i,sep as a}from"node:path";import o from"@babel/parser";import{readFile as s,readdir as c,writeFile as l}from"node:fs/promises";var u=new Set([`node_modules`,`dist`,`build`]),d=new Set([`.jsx`,`.tsx`,`.js`]),f=[`react-native`,`@webority/mobile-ui`],p=new Set([`@webority/ui-react`,`@webority/mobile-ui`]),m=new Set([`section`,`form`,`header`,`nav`,`main`,`aside`,`article`,`fieldset`]),h=[`aria-label`,`name`,`id`,`title`,`label`,`placeholder`],g=new Set([`ArrowFunctionExpression`,`FunctionExpression`,`FunctionDeclaration`,`ObjectMethod`,`ClassMethod`]),_=new Set([`loc`,`start`,`end`,`comments`,`leadingComments`,`trailingComments`,`innerComments`,`tokens`,`extra`,`errors`]),v=40,y=new Set([`Fragment`,`React.Fragment`]);async function b(e,{write:t=!1}={}){let n=[],r=[],o=[],c=new Map;for(let t of await C(e)){let l=i(e,t).split(a).join(`/`),u=await s(t,`utf8`),d=w({source:u,file:t,label:l,phone:await x(t,c)});n.push(...d.proposals),r.push(...d.noKey),d.insertions.length>0&&o.push({file:t,source:u,insertions:d.insertions})}let u=0;if(t)for(let e of o){let t=e.source;for(let n of[...e.insertions].sort((e,t)=>t.offset-e.offset))t=`${t.slice(0,n.offset)}${n.text}${t.slice(n.offset)}`;await l(e.file,t,`utf8`),u+=e.insertions.length}return{proposals:n,noKey:r,written:u}}async function x(e,n){let i=[],a=t(e),o;for(;;){if(n.has(a)){o=n.get(a);break}i.push(a);let s=await S(r(a,`package.json`));if(s!==null){o=f.some(e=>s.dependencies?.[e]||s.peerDependencies?.[e]);break}let c=t(a);if(c===a)throw Error(`no package.json above ${e}`);a=c}for(let e of i)n.set(e,o);return o}async function S(e){try{return JSON.parse(await s(e,`utf8`))}catch(e){if(e.code===`ENOENT`)return null;throw e}}async function C(e){let t=await c(e,{withFileTypes:!0});t.sort((e,t)=>e.name<t.name?-1:1);let i=[];for(let a of t){let t=r(e,a.name);a.isDirectory()?u.has(a.name)||i.push(...await C(t)):a.isFile()&&d.has(n(a.name))&&!a.name.includes(`.test.`)&&i.push(t)}return i}function w({source:e,file:t,label:n,phone:r}){let i;try{i=o.parse(e,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch(e){throw Error(`${n}: ${e.message}`)}let a=new Set;for(let e of i.program.body){if(e.type!==`ImportDeclaration`)continue;let t=e.source.value;if(p.has(t))for(let t of e.specifiers)t.type===`ImportSpecifier`&&a.add(t.local.name)}let s=r?`testID`:`data-canvas`,c=new Map,l=[];T(i.program,null,c,l);let u=L(t),d=t=>e.slice(t.start,t.end),f=new Map,m=[],h=[];for(let e of l){let t=e.openingElement,r=P(t,s),i=j(t,a),o=E(e,c);if(i!==null&&o===null&&A(f,e,i,r,c),!r){if(o!==null){let r=t.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===`key`)?.value,i=r?.type===`JSXExpressionContainer`?r.expression:null,a=o.params[1]?.type===`Identifier`?o.params[1].name:null,c=y.has(d(t.name))?D(e,d):e;c===null||i===null||i.type===`JSXEmptyExpression`||V(i)||i.type===`Identifier`&&i.name===a?h.push({start:e.start,entry:{file:n,line:e.loc.start.line,element:d(t.name)}}):c!==e&&P(c.openingElement,s)||m.push({element:c,kind:`list`,keyExpression:i})}else i===null&&M(t)&&m.push({element:e,kind:`block`})}}for(let e of f.values())for(let t of e.values())if(t.length>1&&t.some(e=>e.conditional))for(let e of t)e.skipped||m.push({element:e.element,kind:`sibling`});m.sort((e,t)=>e.element.start-t.element.start);let g=new Set,_=[],v=[];for(let e of m){let{element:t,kind:r}=e,i=t.openingElement,o=d(i.name),c=j(i,a),l=`${u}.${I(t,c===null?o:R(c))}`,f=r===`list`?`${l}.\${${d(e.keyExpression)}}`:l,p=f;if(g.has(p)){let e=2;for(;g.has(`${f}-${e}`);)e+=1;p=`${f}-${e}`}g.add(p);let m=r===`list`?` ${s}={\`${p}\`}`:` ${s}="${p}"`;_.push({file:n,line:t.loc.start.line,element:o,key:p}),v.push({offset:i.name.end,text:m})}return{proposals:_,noKey:h.sort((e,t)=>e.start-t.start).map(e=>e.entry),insertions:v}}function T(e,t,n,r){t!==null&&n.set(e,t),e.type===`JSXElement`&&r.push(e);for(let t of Object.keys(e)){if(_.has(t))continue;let i=e[t];for(let t of Array.isArray(i)?i:[i])typeof t==`object`&&t&&typeof t.type==`string`&&T(t,e,n,r)}}function E(e,t){let n=t.get(e),r=null;if(n?.type===`ArrowFunctionExpression`&&n.body===e)r=n;else if(n?.type===`ReturnStatement`){let e=t.get(n),i=t.get(e);e?.type===`BlockStatement`&&g.has(i?.type)&&i.body===e&&(r=i)}if(r===null)return null;let i=t.get(r);return i?.type===`CallExpression`&&i.arguments[0]===r&&i.callee.type===`MemberExpression`&&!i.callee.computed&&i.callee.property.type===`Identifier`&&i.callee.property.name===`map`?r:null}function D(e,t){for(let n of e.children)if(n.type===`JSXFragment`||n.type===`JSXElement`&&y.has(t(n.openingElement.name))){let e=D(n,t);if(e!==null)return e}else if(n.type===`JSXElement`)return n;return null}function O(e,t){for(let n=t.get(e);n!==void 0;n=t.get(n)){if(n.type===`JSXElement`||n.type===`JSXFragment`)return n;if(g.has(n.type))return null}return null}function k(e,t,n){for(let r=n.get(e);r!==t;r=n.get(r))if(r.type===`ConditionalExpression`||r.type===`LogicalExpression`&&r.operator===`&&`)return!0;return!1}function A(e,t,n,r,i){let a=O(t,i);if(a===null)return;e.has(a)||e.set(a,new Map);let o=e.get(a);o.has(n)||o.set(n,[]),o.get(n).push({element:t,skipped:r,conditional:k(t,a,i)})}function j(e,t){return e.name.type===`JSXIdentifier`&&t.has(e.name.name)?e.name.name:null}function M(e){if(e.name.type!==`JSXIdentifier`)return!1;let t=e.name.name;return m.has(t)||t===`div`&&(N(e,`id`)||N(e,`aria-label`))}function N(e,t){return e.attributes.some(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)}function P(e,t){return e.attributes.some(e=>e.type===`JSXSpreadAttribute`)||N(e,t)}function F(e,t){let n=e.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)?.value;if(n){if(n.type===`StringLiteral`)return n.value;if(n.type===`JSXExpressionContainer`){let e=n.expression;if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`&&e.expressions.length===0)return e.quasis[0].value.cooked??void 0}}}function I(e,t){for(let t of h){let n=F(e.openingElement,t),r=n===void 0?``:B(z(n));if(r!==``)return r}let n=e.children.filter(e=>e.type===`JSXText`&&e.value.trim()!==``);if(n.length===1){let e=B(z(n[0].value));if(e!==``)return e}return B(z(t))}function L(t){return z(e(t,n(t))).replace(/-(screen|page)$/,``)}function R(e){return e.replace(/^App(?=[A-Z])/,``)}function z(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function B(e){if(e.length<=v)return e;let t=e.slice(0,41).lastIndexOf(`-`);return t>0?e.slice(0,t):e.slice(0,v)}function V(e){return e.type===`TemplateLiteral`?e.expressions.length===0:/Literal$/.test(e.type)}export{b as proposeCanvasKeys};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{KIT_MODULE_EXTERNALS as e,defineKit as t,kitModuleVersion as n}from"./kitModule.js";import{checkMetaTypes as r}from"./metaCheck.js";import{HTML_TAGS as i,readMetas as a}from"./metas.js";import{readManifest as o}from"./manifest.js";import{readReleaseManifest as s}from"./release.js";import{buildKitRelease as c,readConfig as l}from"./build.js";import{guidanceOf as u,writeGuidance as d}from"./guidance.js";export{i as HTML_TAGS,e as KIT_MODULE_EXTERNALS,c as buildKitRelease,r as checkMetaTypes,t as defineKit,u as guidanceOf,n as kitModuleVersion,l as readConfig,o as readManifest,a as readMetas,s as readReleaseManifest,d as writeGuidance};
1
+ import{buildKitRelease as e,readConfig as t}from"./build.js";import{guidanceOf as n,writeGuidance as r}from"./guidance.js";import{KIT_MODULE_EXTERNALS as i,defineKit as a,kitModuleVersion as o}from"./kitModule.js";import{readManifest as s}from"./manifest.js";import{checkMetaTypes as c}from"./metaCheck.js";import{HTML_TAGS as l,readMetas as u}from"./metas.js";import{readReleaseManifest as d}from"./release.js";export{l as HTML_TAGS,i as KIT_MODULE_EXTERNALS,e as buildKitRelease,c as checkMetaTypes,a as defineKit,n as guidanceOf,o as kitModuleVersion,t as readConfig,s as readManifest,u as readMetas,d as readReleaseManifest,r as writeGuidance};
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{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};
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{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(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 C(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 w(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===b[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 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,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 re(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 D(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 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:a,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(a),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),t({libraryPackage:N,exported:n({root:R,typesFile:z.typesFile}),drawnNames:K.map(({meta:e})=>({name:e.name,component:e.component??e.name})),notDrawn:r(_(z.dir,e))}),g===`Web`&&s({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`&&s({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:o(te(R,J.get(e.name).module))})),Z=[...X,...B?Y:[],...ie].sort(A);H&&f(Z,H.itemActions),E(Z,P);let Q=i(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/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=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=/^(?:aria|data)-[a-z0-9-]+$/,m=/^on[A-Z][A-Za-z0-9]*$/,h=/^[a-z][A-Za-z0-9]*$/,g=/[\u2013\u2014]/,_=[`string`,`number`,`stringOrNumber`,`boolean`,`enum`,`enumOrNumber`,`url`,`icon`,`node`,`array`,`object`,`any`],v=[`.jsx`,`.tsx`,`.js`,`.ts`];async function y({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(K),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 b(l,{knownNames:r,icons:i}),l.sort((e,t)=>K(e.meta.name,t.meta.name))}function b(e,{knownNames:t=[],icons:n}={}){let r=new Map;for(let{meta:t}of e)q(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=[];C(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 x(e,{platform:t,source:n}){let r=Object.keys(e.props).sort(K),i=t===`Web`&&q(e.actions)?Object.values(e.actions):[];return{name:e.name,marker:e.marker,acceptsChildren:e.acceptsChildren,props:[...r.map(t=>B(t,e.props[t])),...i.map(e=>({name:e,type:`object`,fields:[],required:!1}))].sort((e,t)=>K(e.name,t.name)),itemsTakeAction:t===`Web`?r.filter(t=>U(e.props[t])):[...e.itemsTakeAction??[]].sort(K),takesAction:t===`Web`?[...i].sort(K):[...e.takesAction??[]].sort(K),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 S(n,o){let s=n.replace(/\.meta\.[jt]s$/,``),c=r(s)===o?s:a(i(s),o);for(let n of v)if(t(c+n))return e(c+n);throw Error(`no component module for ${o} beside ${n}`)}function C(e,t,n,r,i,a){if(!q(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&&(Y(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&&w(e,a),e.role!==void 0&&!l.includes(e.role)&&a.push([`role`,`must be "title" or "navigation"`]),E(e,a);let c=q(e.props)?e.props:{};if(!q(e.props))a.push([`props`,`must be an object`]);else for(let[t,n]of Object.entries(e.props))D(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`]),!q(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)=>{F(n,`examples[${o}]`,e,c,t,r,i,a)}):a.push([`examples`,`must be a list`]),I(e.usage,i,a),i.fixed=null,z(e,``,a)}function w(e,t){let{actions:n}=e;if(!q(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=q(e.props)?e.props:{},i=q(e.fixedProps)?e.fixedProps:{},a=new Map;for(let[e,o]of Object.entries(n)){let n=`actions.${e}`;m.test(e)||t.push([n,`"${e}" is not a handler name (on<Event>)`]),typeof o!=`string`||!h.test(o)?t.push([n,`${G(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 T=[[`takesAction`,`object`],[`itemsTakeAction`,`array`]];function E(e,t){let n=q(e.props)?e.props:{},r=new Map,i=!1;for(let[a,o]of T){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)||!q(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 D(e,t,n,r){if(!q(e)){r.push([t,`is not a prop`]);return}if(!_.includes(e.type)){r.push([`${t}.type`,`${G(e.type)} is not a prop type`]);return}if(e.type===`enum`||e.type===`enumOrNumber`?O(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))D(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))D(a,`${t}.itemFields.${i}`,n,r);if(Y(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=[];k(e.default,e,t,n,i),i.length>0&&r.push([`${t}.default`,`${G(e.default)} does not fit ${e.type}`])}}function O(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`||J(e):typeof e==`string`)?a.has(e)&&n.push([`${t}.values`,`"${e}" is listed twice`]):n.push([`${t}.values`,`${G(e)} is not allowed here`]),a.add(e)}function k(e,t,n,r,i){if(!q(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`&&W(e,t.type,n,i);return;case`number`:J(e)||W(e,t.type,n,i);return;case`boolean`:typeof e!=`boolean`&&W(e,t.type,n,i);return;case`stringOrNumber`:typeof e!=`string`&&!J(e)&&W(e,t.type,n,i);return;case`enum`:a.includes(e)||i.push([n,`${G(e)} is not one of ${G(a)}`]);return;case`enumOrNumber`:!J(e)&&!a.includes(e)&&i.push([n,`${G(e)} is not one of ${G(a)}`]);return;case`icon`:X(e)?M(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`]):W(e,t.type,n,i);return;case`node`:Array.isArray(e)?e.forEach((e,t)=>{A(e,`${n}[${t}]`,r,i)}):A(e,n,r,i);return;case`array`:Array.isArray(e)?t.itemFields!==void 0&&e.forEach((e,a)=>{q(e)?j(e,t.itemFields,`${n}[${a}]`,r,i):i.push([`${n}[${a}]`,`${G(e)} is not an object`])}):W(e,t.type,n,i);return;case`object`:q(e)?t.fields!==void 0&&j(e,t.fields,n,r,i):W(e,t.type,n,i);return;default:return}}function A(e,t,n,r){X(e)?M(e,t,n,r):typeof e!=`string`&&!J(e)&&r.push([t,`${G(e)} is not a node`])}function j(e,t,n,r,i){for(let a of Object.keys(e))Object.hasOwn(t,a)?k(e[a],t[a],`${n}.${a}`,r,i):i.push([`${n}.${a}`,`not a field`]);for(let[r,a]of Object.entries(t))q(a)&&a.required===!0&&!Object.hasOwn(e,r)&&i.push([`${n}.${r}`,`missing, the field is required`])}function M(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(!q(e.props))r.push([`${t}.props`,`must be an object`]);else{let o=q(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)?k(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`]),P(e.children,`${t}.children`,n,r)),e.handlers!==void 0&&N(e.handlers,`${t}.handlers`,i,a,r)}function N(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)m.test(o)?a.has(o)?i.push([t,`"${o}" is listed twice`]):r&&q(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 P(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`&&(X(e)?M(e,`${t}[${i}]`,n,r):r.push([`${t}[${i}]`,`is neither text nor a placed element`]))})}}function F(e,t,n,r,i,a,o,s){if(!q(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>`]),Y(e.title)||s.push([`${t}.title`,`is empty`]),!q(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)&&p.test(n)&&Y(i)||(Object.hasOwn(r,n)?k(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))q(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`]),P(e.children,`${t}.children`,o,s)),e.wrap!==void 0&&(X(e.wrap)?M(e.wrap,`${t}.wrap`,o,s):s.push([`${t}.wrap`,`is not a placed element`])),e.handlers!==void 0&&N(e.handlers,`${t}.handlers`,c,n,s)}function I(e,t,n){if(!q(e)){n.push([`usage`,`must be an object`]);return}(!Array.isArray(e.when)||e.when.length===0||!e.when.every(Y))&&n.push([`usage.when`,`lists nothing; write at least one line`]),Array.isArray(e.whenNot)?e.whenNot.forEach((e,r)=>{L(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)=>{R(e,`usage.do[${r}]`,t,n)}),e.dont.forEach((e,r)=>{R(e,`usage.dont[${r}]`,t,n)})),Array.isArray(e.a11y)?e.a11y.forEach((e,t)=>{Y(e)||n.push([`usage.a11y[${t}]`,`is empty`])}):n.push([`usage.a11y`,`must be a list`])}function L(e,t,n,r){if(!q(e)){r.push([t,`is not an object`]);return}Y(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 R(e,t,n,r){if(!q(e)){r.push([t,`is not a practice`]);return}if(Y(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}]`;X(e)?M(e,a,n,r):r.push([a,`is not a placed element`])})}function z(e,t,n){if(typeof e==`string`)g.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)=>{z(e,`${t}[${r}]`,n)});else if(q(e))for(let[r,i]of Object.entries(e))z(i,t?`${t}.${r}`:r,n)}function B(e,t){let n={name:e,type:t.type};return(t.type===`enum`||t.type===`enumOrNumber`)&&(n.enum=H(t.values)),t.fields!==void 0&&(n.fields=V(t.fields)),t.itemFields!==void 0&&(n.itemFields=V(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 V(e){return Object.keys(e).sort(K).map(t=>B(t,e[t]))}function H(e){return[...e].sort((e,t)=>{let n=typeof e==`number`,r=typeof t==`number`;return n&&r?e-t:n===r?K(e,t):n?-1:1})}function U(e){return e.type===`array`&&Object.keys(e.itemFields??{}).some(e=>e===`href`||e===`to`)}function W(e,t,n,r){r.push([n,`${G(e)} is not a ${t}`])}function G(e){return JSON.stringify(e)}function K(e,t){return e<t?-1:+(e>t)}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function J(e){return typeof e==`number`&&Number.isFinite(e)}function Y(e){return typeof e==`string`&&e.trim()!==``}function X(e){return q(e)&&typeof e.component==`string`}export{c as HTML_TAGS,l as ROLES,b as checkMetas,S as componentModuleOf,x as manifestComponent,y as readMetas};
2
+ `))}function x(e,{platform:t,source:n}){let r=Object.keys(e.props).sort(K),i=t===`Web`&&q(e.actions)?Object.values(e.actions):[];return{name:e.name,marker:e.marker,acceptsChildren:e.acceptsChildren,props:[...r.map(t=>B(t,e.props[t])),...i.map(e=>({name:e,type:`object`,fields:[],required:!1}))].sort((e,t)=>K(e.name,t.name)),itemsTakeAction:t===`Web`?r.filter(t=>U(e.props[t])):[...e.itemsTakeAction??[]].sort(K),takesAction:t===`Web`?[...i].sort(K):[...e.takesAction??[]].sort(K),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 S(n,o){let s=n.replace(/\.meta\.[jt]s$/,``),c=r(s)===o?s:a(i(s),o);for(let n of v)if(t(c+n))return e(c+n);throw Error(`no component module for ${o} beside ${n}`)}function C(e,t,n,r,i,a){if(!q(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&&(Y(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&&w(e,a),e.role!==void 0&&!l.includes(e.role)&&a.push([`role`,`must be "title" or "navigation"`]),E(e,a);let c=q(e.props)?e.props:{};if(!q(e.props))a.push([`props`,`must be an object`]);else for(let[t,n]of Object.entries(e.props))D(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`]),!q(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)=>{F(n,`examples[${o}]`,e,c,t,r,i,a)}):a.push([`examples`,`must be a list`]),I(e.usage,i,a),i.fixed=null,z(e,``,a)}function w(e,t){let{actions:n}=e;if(!q(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=q(e.props)?e.props:{},i=q(e.fixedProps)?e.fixedProps:{},a=new Map;for(let[e,o]of Object.entries(n)){let n=`actions.${e}`;m.test(e)||t.push([n,`"${e}" is not a handler name (on<Event>)`]),typeof o!=`string`||!h.test(o)?t.push([n,`${G(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 T=[[`takesAction`,`object`],[`itemsTakeAction`,`array`]];function E(e,t){let n=q(e.props)?e.props:{},r=new Map,i=!1;for(let[a,o]of T){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)&&q(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 D(e,t,n,r){if(!q(e))r.push([t,`is not a prop`]);else if(!_.includes(e.type))r.push([`${t}.type`,`${G(e.type)} is not a prop type`]);else{if(e.type===`enum`||e.type===`enumOrNumber`?O(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))D(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))D(a,`${t}.itemFields.${i}`,n,r)}if(Y(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=[];k(e.default,e,t,n,i),i.length>0&&r.push([`${t}.default`,`${G(e.default)} does not fit ${e.type}`])}}}}function O(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`||J(e):typeof e==`string`)?a.has(e)&&n.push([`${t}.values`,`"${e}" is listed twice`]):n.push([`${t}.values`,`${G(e)} is not allowed here`]),a.add(e)}function k(e,t,n,r,i){if(!q(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`&&W(e,t.type,n,i);return;case`number`:J(e)||W(e,t.type,n,i);return;case`boolean`:typeof e!=`boolean`&&W(e,t.type,n,i);return;case`stringOrNumber`:typeof e!=`string`&&!J(e)&&W(e,t.type,n,i);return;case`enum`:a.includes(e)||i.push([n,`${G(e)} is not one of ${G(a)}`]);return;case`enumOrNumber`:!J(e)&&!a.includes(e)&&i.push([n,`${G(e)} is not one of ${G(a)}`]);return;case`icon`:X(e)?M(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`]):W(e,t.type,n,i);return;case`node`:Array.isArray(e)?e.forEach((e,t)=>{A(e,`${n}[${t}]`,r,i)}):A(e,n,r,i);return;case`array`:Array.isArray(e)?t.itemFields!==void 0&&e.forEach((e,a)=>{q(e)?j(e,t.itemFields,`${n}[${a}]`,r,i):i.push([`${n}[${a}]`,`${G(e)} is not an object`])}):W(e,t.type,n,i);return;case`object`:q(e)?t.fields!==void 0&&j(e,t.fields,n,r,i):W(e,t.type,n,i);return;default:return}}function A(e,t,n,r){X(e)?M(e,t,n,r):typeof e!=`string`&&!J(e)&&r.push([t,`${G(e)} is not a node`])}function j(e,t,n,r,i){for(let a of Object.keys(e))Object.hasOwn(t,a)?k(e[a],t[a],`${n}.${a}`,r,i):i.push([`${n}.${a}`,`not a field`]);for(let[r,a]of Object.entries(t))q(a)&&a.required===!0&&!Object.hasOwn(e,r)&&i.push([`${n}.${r}`,`missing, the field is required`])}function M(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(!q(e.props))r.push([`${t}.props`,`must be an object`]);else{let o=q(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)?k(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`]),P(e.children,`${t}.children`,n,r)),e.handlers!==void 0&&N(e.handlers,`${t}.handlers`,i,a,r)}function N(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)m.test(o)?a.has(o)?i.push([t,`"${o}" is listed twice`]):r&&q(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 P(e,t,n,r){typeof e!=`string`&&(Array.isArray(e)?e.forEach((e,i)=>{typeof e!=`string`&&(X(e)?M(e,`${t}[${i}]`,n,r):r.push([`${t}[${i}]`,`is neither text nor a placed element`]))}):r.push([t,`is text or a list of text and placed elements`]))}function F(e,t,n,r,i,a,o,s){if(!q(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>`]),Y(e.title)||s.push([`${t}.title`,`is empty`]),!q(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)&&p.test(n)&&Y(i)||(Object.hasOwn(r,n)?k(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))q(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`]),P(e.children,`${t}.children`,o,s)),e.wrap!==void 0&&(X(e.wrap)?M(e.wrap,`${t}.wrap`,o,s):s.push([`${t}.wrap`,`is not a placed element`])),e.handlers!==void 0&&N(e.handlers,`${t}.handlers`,c,n,s)}function I(e,t,n){q(e)?(Array.isArray(e.when)&&e.when.length!==0&&e.when.every(Y)||n.push([`usage.when`,`lists nothing; write at least one line`]),Array.isArray(e.whenNot)?e.whenNot.forEach((e,r)=>{L(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)=>{R(e,`usage.do[${r}]`,t,n)}),e.dont.forEach((e,r)=>{R(e,`usage.dont[${r}]`,t,n)})),Array.isArray(e.a11y)?e.a11y.forEach((e,t)=>{Y(e)||n.push([`usage.a11y[${t}]`,`is empty`])}):n.push([`usage.a11y`,`must be a list`])):n.push([`usage`,`must be an object`])}function L(e,t,n,r){q(e)?(Y(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`]))):r.push([t,`is not an object`])}function R(e,t,n,r){q(e)?(Y(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`]):e.example.forEach((e,i)=>{let a=`${t}.example[${i}]`;X(e)?M(e,a,n,r):r.push([a,`is not a placed element`])})):r.push([t,`is not a practice`])}function z(e,t,n){if(typeof e==`string`)g.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)=>{z(e,`${t}[${r}]`,n)});else if(q(e))for(let[r,i]of Object.entries(e))z(i,t?`${t}.${r}`:r,n)}function B(e,t){let n={name:e,type:t.type};return(t.type===`enum`||t.type===`enumOrNumber`)&&(n.enum=H(t.values)),t.fields!==void 0&&(n.fields=V(t.fields)),t.itemFields!==void 0&&(n.itemFields=V(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 V(e){return Object.keys(e).sort(K).map(t=>B(t,e[t]))}function H(e){return[...e].sort((e,t)=>{let n=typeof e==`number`,r=typeof t==`number`;return n&&r?e-t:n===r?K(e,t):n?-1:1})}function U(e){return e.type===`array`&&Object.keys(e.itemFields??{}).some(e=>e===`href`||e===`to`)}function W(e,t,n,r){r.push([n,`${G(e)} is not a ${t}`])}function G(e){return JSON.stringify(e)}function K(e,t){return e<t?-1:+(e>t)}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function J(e){return typeof e==`number`&&Number.isFinite(e)}function Y(e){return typeof e==`string`&&e.trim()!==``}function X(e){return q(e)&&typeof e.component==`string`}export{c as HTML_TAGS,l as ROLES,b as checkMetas,S as componentModuleOf,x as manifestComponent,y as readMetas};
package/dist/phone.js CHANGED
@@ -1 +1 @@
1
- import{readText as e}from"./files.js";import t from"@babel/parser";function n(n){return t.parse(e(n),{sourceType:`module`,plugins:[`typescript`]})}function r(e){return[...new Set(e)].sort((e,t)=>e<t?-1:+(e>t))}function i(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function a(e){let t=new Map;for(let n of e.program.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.set(n.id.name,n.init)}return t}function o(e,t,n){let r=t;for(let t=0;r?.type===`Identifier`;t+=1){if(t>10||!e.has(r.name))throw Error(`${r.name} in ${n} is not a constant the reader can follow.`);r=e.get(r.name)}return r}function s(e){let t=n(e).program.body.map(e=>e.type===`ExportNamedDeclaration`?e.declaration:e).find(e=>e?.type===`TSTypeAliasDeclaration`&&e.id.name===`IconName`);if(t?.typeAnnotation.type!==`TSUnionType`)throw Error(`IconName union not found in ${e}`);return r(t.typeAnnotation.types.map(t=>{if(t.type!==`TSLiteralType`||t.literal.type!==`StringLiteral`)throw Error(`IconName in ${e} has a member that is not a string literal`);return t.literal.value}))}function c(e,t,n){let r=o(e,t,n);switch(r.type){case`StringLiteral`:case`NumericLiteral`:case`BooleanLiteral`:return r.value;case`UnaryExpression`:if(r.operator===`!`&&r.argument.type===`NumericLiteral`)return!r.argument.value;break;case`ArrayExpression`:return r.elements.map(t=>c(e,t,n));case`ObjectExpression`:return Object.fromEntries(r.properties.map(t=>{if(t.type!==`ObjectProperty`||t.computed)throw Error(`phoneChromeEntries in ${n} has an object member the reader cannot follow.`);return[i(t.key),c(e,t.value,n)]}));case`MemberExpression`:if(!r.computed&&r.property.type===`Identifier`){let t=c(e,r.object,n);if(typeof t==`object`&&t&&r.property.name in t)return t[r.property.name]}break}throw Error(`phoneChromeEntries in ${n} has a ${r.type} the reader cannot read as data.`)}function l(e){return new Set(e.program.body.filter(e=>e.type===`ExportNamedDeclaration`&&e.declaration).flatMap(({declaration:e})=>e.type===`VariableDeclaration`?e.declarations.map(e=>e.id.name):[e.id?.name]))}function u(n,r){let i=t.parse(e(n),{sourceType:`module`,plugins:[`jsx`]}),o=a(i);if(!o.has(`phoneChromeEntries`))throw Error(`phoneChromeEntries is not declared in ${n}; the phone kit's frame parts come from it.`);let s=c(o,o.get(`phoneChromeEntries`),n),u=l(i);if(!Array.isArray(s)||s.length===0)throw Error(`phoneChromeEntries in ${n} must be a list of manifest entries.`);return s.map(e=>{let{name:t,marker:i,acceptsChildren:a,props:o,itemsTakeAction:s,takesAction:c,source:l}=e??{};if(typeof t!=`string`||typeof i!=`string`||typeof a!=`boolean`||!Array.isArray(o)||!Array.isArray(s)||!Array.isArray(c))throw Error(`phoneChromeEntries in ${n} has an entry that is not a manifest component: ${JSON.stringify(e)}`);if(l!==r)throw Error(`phoneChromeEntries in ${n}: ${t} names the source ${l}, not ${r}.`);if(!u.has(t))throw Error(`phoneChromeEntries in ${n} lists ${t}, which the module does not export.`);return{name:t,marker:i,acceptsChildren:a,props:o,itemsTakeAction:s,takesAction:c,source:l}})}function d(e,t){for(let[n,i]of[[`itemsTakeAction`,`array`],[`takesAction`,`object`]])for(let[a,o]of Object.entries(t[n]??{})){let t=e.find(({name:e})=>e===a);if(!t)throw Error(`phoneStyleSupport.json ${n} names ${a}, which the kit does not have.`);for(let e of o)if(t.props.find(({name:t})=>t===e)?.type!==i)throw Error(`phoneStyleSupport.json ${n} names ${a}.${e}, which is not a prop of type ${i} in the kit.`);t[n]=r([...new Set([...t[n],...o])])}}export{d as applyPhoneActions,u as phoneChromeEntries,s as phoneIcons};
1
+ import{readText as e}from"./files.js";import t from"@babel/parser";function n(n){return t.parse(e(n),{sourceType:`module`,plugins:[`typescript`]})}function r(e){return[...new Set(e)].sort((e,t)=>e<t?-1:+(e>t))}function i(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function a(e){let t=new Map;for(let n of e.program.body){let e=n.type===`ExportNamedDeclaration`?n.declaration:n;if(e?.type===`VariableDeclaration`)for(let n of e.declarations)n.id.type===`Identifier`&&t.set(n.id.name,n.init)}return t}function o(e,t,n){let r=t;for(let t=0;r?.type===`Identifier`;t+=1){if(t>10||!e.has(r.name))throw Error(`${r.name} in ${n} is not a constant the reader can follow.`);r=e.get(r.name)}return r}function s(e){let t=n(e).program.body.map(e=>e.type===`ExportNamedDeclaration`?e.declaration:e).find(e=>e?.type===`TSTypeAliasDeclaration`&&e.id.name===`IconName`);if(t?.typeAnnotation.type!==`TSUnionType`)throw Error(`IconName union not found in ${e}`);return r(t.typeAnnotation.types.map(t=>{if(t.type!==`TSLiteralType`||t.literal.type!==`StringLiteral`)throw Error(`IconName in ${e} has a member that is not a string literal`);return t.literal.value}))}function c(e,t,n){let r=o(e,t,n);switch(r.type){case`StringLiteral`:case`NumericLiteral`:case`BooleanLiteral`:return r.value;case`UnaryExpression`:if(r.operator===`!`&&r.argument.type===`NumericLiteral`)return!r.argument.value;break;case`ArrayExpression`:return r.elements.map(t=>c(e,t,n));case`ObjectExpression`:return Object.fromEntries(r.properties.map(t=>{if(t.type!==`ObjectProperty`||t.computed)throw Error(`phoneChromeEntries in ${n} has an object member the reader cannot follow.`);return[i(t.key),c(e,t.value,n)]}));case`MemberExpression`:if(!r.computed&&r.property.type===`Identifier`){let t=c(e,r.object,n);if(typeof t==`object`&&t&&r.property.name in t)return t[r.property.name]}}throw Error(`phoneChromeEntries in ${n} has a ${r.type} the reader cannot read as data.`)}function l(e){return new Set(e.program.body.filter(e=>e.type===`ExportNamedDeclaration`&&e.declaration).flatMap(({declaration:e})=>e.type===`VariableDeclaration`?e.declarations.map(e=>e.id.name):[e.id?.name]))}function u(n,r){let i=t.parse(e(n),{sourceType:`module`,plugins:[`jsx`]}),o=a(i);if(!o.has(`phoneChromeEntries`))throw Error(`phoneChromeEntries is not declared in ${n}; the phone kit's frame parts come from it.`);let s=c(o,o.get(`phoneChromeEntries`),n),u=l(i);if(!Array.isArray(s)||s.length===0)throw Error(`phoneChromeEntries in ${n} must be a list of manifest entries.`);return s.map(e=>{let{name:t,marker:i,acceptsChildren:a,props:o,itemsTakeAction:s,takesAction:c,source:l}=e??{};if(typeof t!=`string`||typeof i!=`string`||typeof a!=`boolean`||!Array.isArray(o)||!Array.isArray(s)||!Array.isArray(c))throw Error(`phoneChromeEntries in ${n} has an entry that is not a manifest component: ${JSON.stringify(e)}`);if(l!==r)throw Error(`phoneChromeEntries in ${n}: ${t} names the source ${l}, not ${r}.`);if(!u.has(t))throw Error(`phoneChromeEntries in ${n} lists ${t}, which the module does not export.`);return{name:t,marker:i,acceptsChildren:a,props:o,itemsTakeAction:s,takesAction:c,source:l}})}function d(e,t){for(let[n,i]of[[`itemsTakeAction`,`array`],[`takesAction`,`object`]])for(let[a,o]of Object.entries(t[n]??{})){let t=e.find(({name:e})=>e===a);if(!t)throw Error(`phoneStyleSupport.json ${n} names ${a}, which the kit does not have.`);for(let e of o)if(t.props.find(({name:t})=>t===e)?.type!==i)throw Error(`phoneStyleSupport.json ${n} names ${a}.${e}, which is not a prop of type ${i} in the kit.`);t[n]=r([...new Set([...t[n],...o])])}}export{d as applyPhoneActions,u as phoneChromeEntries,s as phoneIcons};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/canvas-kit",
3
- "version": "0.121.0",
3
+ "version": "0.124.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,