@webority/canvas-kit 0.139.4 → 0.140.1
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/meta.d.ts +2 -0
- package/dist/metas.js +1 -1
- package/package.json +1 -1
package/dist/meta.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface ComponentUsage {
|
|
|
67
67
|
do: readonly MetaPractice[];
|
|
68
68
|
dont: readonly MetaPractice[];
|
|
69
69
|
a11y: readonly string[];
|
|
70
|
+
keyboard?: readonly { key: string; does: string; notes: string }[];
|
|
71
|
+
contrast?: readonly { pair: string; light: string; dark: string }[];
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export interface ComponentMeta {
|
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`,`h1`,`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`]);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};
|
|
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`]),e.keyboard!==void 0&&(Array.isArray(e.keyboard)?e.keyboard.forEach((e,t)=>{for(let r of[`key`,`does`,`notes`])q(e)&&Y(e[r])||n.push([`usage.keyboard[${t}].${r}`,`is empty`])}):n.push([`usage.keyboard`,`must be a list`])),e.contrast!==void 0&&(Array.isArray(e.contrast)?e.contrast.forEach((e,t)=>{for(let r of[`pair`,`light`,`dark`])q(e)&&Y(e[r])||n.push([`usage.contrast[${t}].${r}`,`is empty`])}):n.push([`usage.contrast`,`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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/canvas-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.140.1",
|
|
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,
|