@webority/canvas-kit 0.87.0 → 0.87.2
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/build.js +3 -3
- package/dist/declarations.js +1 -1
- package/dist/manifest.js +1 -1
- package/dist/phone.js +1 -1
- package/package.json +2 -2
package/dist/build.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import{KIT_MODULE_EXTERNALS as r}from"./kitModule.js";import{libraryFiles as i,readManifest as a}from"./manifest.js";import{checkFleetFolder as o,digest as s,writeReleaseFolder as c}from"./release.js";import{existsSync as l}from"node:fs";import{dirname as u,join as d,resolve as f}from"node:path";import{fileURLToPath as p}from"node:url";import{build as m}from"vite";var h=19,g=[`react-redux`,`react-router-dom`,`axios`],_=[`kit`,`platform`,`entry`,`libraryPackage`,`rolesFile`,`rendererProtocolVersion`],v=[`kit`,`platform`,`libraryPackage`,`rendererProtocolVersion`],y=`canvas-kit:entry`,b=`\0${y}`,x=d(u(p(import.meta.url)),`kitModule.js`)
|
|
2
|
-
`)}function
|
|
3
|
-
`);return{script:f.code,styles:
|
|
1
|
+
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import{KIT_MODULE_EXTERNALS as r}from"./kitModule.js";import{libraryFiles as i,readManifest as a}from"./manifest.js";import{checkFleetFolder as o,digest as s,writeReleaseFolder as c}from"./release.js";import{existsSync as l}from"node:fs";import{dirname as u,join as d,resolve as f}from"node:path";import{fileURLToPath as p}from"node:url";import{build as m}from"vite";var h=19,g=[`react-redux`,`react-router-dom`,`axios`],_=[`kit`,`platform`,`entry`,`libraryPackage`,`rolesFile`,`rendererProtocolVersion`],v=[`kit`,`platform`,`libraryPackage`,`rendererProtocolVersion`],y=`canvas-kit:entry`,b=`\0${y}`,x=d(u(p(import.meta.url)),`kitModule.js`),S={"process.env.NODE_ENV":JSON.stringify(`production`),"process.env":`{}`,__DEV__:`false`},C=/(?<![\w$."'`])(process\.env|__DEV__)(?![\w$])/;function w(e){let n=t(e);if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`${e} must be a JSON object.`);for(let t of Object.keys(n))if(!_.includes(t))throw Error(`${e} has the unknown key ${t}. The keys are ${_.join(`, `)}.`);for(let t of v)if(n[t]===void 0)throw Error(`${e} needs the key ${t}.`);for(let t of[`kit`,`platform`,`libraryPackage`])if(typeof n[t]!=`string`)throw Error(`${e}: ${t} must be a string.`);for(let t of[`entry`,`rolesFile`])if(n[t]!==void 0&&typeof n[t]!=`string`)throw Error(`${e}: ${t} must be a string path.`);return n}function T(n){let r=e(n,`react`);if(!r)throw Error(`react is not installed for ${n}. Run pnpm install there.`);let{version:i}=t(d(r,`package.json`));if(Number(String(i).split(`.`)[0])!==h)throw Error(`The product uses React ${i}; the Canvas renderer runs React ${h}. Pin react to ${h}.x and rebuild.`)}function E(e){let{version:n}=t(d(e,`package.json`));if(!n)throw Error(`${d(e,`package.json`)} needs a version; the release is stamped with it.`);return n}function D({entryFile:e,libraryFile:t,manifest:r,libraryNames:i,productNames:a}){let o=[`import { defineKit } from ${JSON.stringify(n(x))};`];e!==void 0&&o.push(`import * as product from ${JSON.stringify(n(e))};`),i.length>0&&o.push(`import { ${i.join(`, `)} } from ${JSON.stringify(n(t))};`);let s=[...i,...a.map(e=>`${e}: product.${e}`)],c=Object.fromEntries(r.components.filter(({marker:e})=>e!==null).map(({name:e,marker:t})=>[e,t]));return o.push(`export default defineKit({ components: { ${s.join(`, `)} }, markers: ${JSON.stringify(c)}, tokenValues: ${JSON.stringify(r.tokenValues)}, manifest: ${JSON.stringify(r)} });`,``),o.join(`
|
|
2
|
+
`)}function O(e){return{name:`canvas-kit-entry`,resolveId(e){return e===y?b:null},load(t){return t===b?e:null}}}function k(e){let t=`${n(d(e,`src`,`services`))}/`;return{name:`canvas-kit-banned-imports`,transform(e,r){let i=n(r.split(`?`)[0]),a=g.find(e=>i.includes(`/node_modules/${e}/`));if(a)throw Error(`The kit imports ${a} (${i}). A kit draws from its props only; the container that renders it holds the state and the calls.`);if(i.startsWith(t))throw Error(`The kit imports ${i}, which is in src/services. A kit draws from its props only; move the call into the container.`);return null}}}async function A({root:e,kit:t,platform:n,entryFile:i,libraryFile:a,libraryNames:o,productNames:s,manifest:c}){let l=r[n],u=await m({configFile:!1,root:e,logLevel:`warn`,publicDir:!1,envDir:!1,define:S,plugins:[O(D({entryFile:i,libraryFile:a,manifest:c,libraryNames:o,productNames:s})),k(e)],esbuild:{jsx:`automatic`,jsxImportSource:`react`,include:/\.[cm]?[jt]sx?$/},build:{write:!1,minify:!0,target:`es2022`,cssCodeSplit:!1,lib:{entry:y,formats:[`es`],fileName:()=>`kit.js`},rollupOptions:{input:y,external:e=>l.some(t=>e===t||e.startsWith(`${t}/`)),output:{inlineDynamicImports:!0}}}}),d=(Array.isArray(u)?u:[u]).flatMap(e=>e.output),f=d.find(e=>e.type===`chunk`&&e.isEntry);if(!f)throw Error(`The bundle of ${t} has no entry module.`);let p=C.exec(f.code);if(p)throw Error(`The bundle of ${t} still reads ${p[1]}, which the renderer does not define.`);let h=d.filter(e=>e.type===`chunk`&&!e.isEntry);if(h.length>0)throw Error(`The bundle of ${t} split ${h.map(e=>e.fileName).join(`, `)} out of kit.js; a kit must be one file.`);let g=d.filter(e=>e.type===`asset`&&e.fileName.endsWith(`.css`)).map(e=>typeof e.source==`string`?e.source:Buffer.from(e.source).toString(`utf8`)).join(`
|
|
3
|
+
`);return{script:f.code,styles:g}}async function j({configFile:e,outDir:t,styleKeysFile:n,phoneRendererSupportFile:r}){let d=f(e),p=f(t);if(l(p))throw Error(`${p} already exists. A release folder is never overwritten; choose a new folder.`);let m=w(d),h=u(d),g=m.entry===void 0,_=g?void 0:f(h,m.entry);if(_!==void 0&&!l(_))throw Error(`The kit entry ${_} does not exist.`);if(g&&n===void 0)throw Error(`A library-only kit needs --style-keys: the style key table the renderer draws from.`);if(m.platform===`Phone`&&r===void 0)throw Error(`A Phone kit needs --phone-renderer-support: the phone renderer's support file.`);if(m.platform!==`Phone`&&r!==void 0)throw Error(`Only a Phone kit reads --phone-renderer-support; a Web kit takes no phone support file.`);T(h);let v=m.rolesFile===void 0?void 0:f(h,m.rolesFile),{manifest:y,warnings:b}=a({projectRoot:h,kit:m.kit,platform:m.platform,entry:_,libraryPackage:m.libraryPackage,rolesFile:v,rendererProtocolVersion:m.rendererProtocolVersion,phoneRendererSupportFile:r===void 0?void 0:f(r),styleKeysFile:n===void 0?void 0:f(n)}),x=i(h,m.libraryPackage),S=g?x.pkg.version:E(h);g&&o(p,m.kit,S);let C=y.components.filter(({source:e})=>e===m.libraryPackage).map(({name:e})=>e),D=y.components.filter(({source:e})=>e!==m.libraryPackage).map(({name:e})=>e),{script:O,styles:k}=await A({root:h,kit:m.kit,platform:m.platform,entryFile:_,libraryFile:x.entryFile,libraryNames:C,productNames:D,manifest:y}),j={"manifest.json":`${JSON.stringify(y,null,2)}\n`,"kit.js":O,"kit.css":k},M={name:m.kit,version:S,platform:m.platform,kitModuleVersion:2,rendererProtocolVersion:m.rendererProtocolVersion,library:y.library,files:Object.fromEntries(Object.entries(j).map(([e,t])=>[e,s(t)]))};return c(p,j,M),{outDir:p,release:M,manifest:y,warnings:b}}export{j as buildKitRelease,w as readConfig};
|
package/dist/declarations.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readText as e}from"./files.js";import{existsSync as t}from"node:fs";import{dirname as n,join as r,resolve as i}from"node:path";import a from"@babel/parser";var o=`function`,s=8,c=2,l=120,u=[`ForwardRefExoticComponent`,`FC`,`FunctionComponent`,`ComponentType`,`MemoExoticComponent`],d=[`Array`,`ReadonlyArray`,`Set`,`ReadonlySet`],f=/(^i|I)con$/,p=/(Href|href|Url|url)$/,m=new Map,h=new Set;function g(e,t){return e<t?-1:+(e>t)}function _(e){return[...new Set(e)].sort(g)}function v(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function y(e){let t=e.type===`TSImportType`?e.qualifier:e.typeName;return t?t.type===`TSQualifiedName`?t.right.name:t.name:null}function b(e){switch(e.type){case`TSDeclareFunction`:case`FunctionDeclaration`:case`TSInterfaceDeclaration`:case`TSTypeAliasDeclaration`:return[[e.id.name,e]];case`VariableDeclaration`:return e.declarations.filter(e=>e.id.type===`Identifier`).map(e=>[e.id.name,e]);default:return[]}}function x(t){if(m.has(t))return m.get(t);let n=e(t),r=a.parse(n,{sourceType:`module`,plugins:[`typescript`]}),i={declarations:new Map,imports:new Map,exports:[],defaultDeclaration:null,source:n};for(let e of r.program.body)if(e.type===`ImportDeclaration`)for(let t of e.specifiers)t.type===`ImportSpecifier`&&i.imports.set(t.local.name,{source:e.source.value,imported:v(t.imported)});else if(e.type===`ExportAllDeclaration`)i.exports.push({star:!0,source:e.source.value});else if(e.type===`ExportDefaultDeclaration`)i.defaultDeclaration=e.declaration,i.exports.push({name:`default`,local:`default`});else if(e.type===`ExportNamedDeclaration`&&e.source)for(let t of e.specifiers)i.exports.push({name:t.exported.name,local:t.local.name,source:e.source.value});else{let t=e.type===`ExportNamedDeclaration`,n=t?e.declaration:e;for(let[e,r]of n?b(n):[])i.declarations.set(e,r),t&&i.exports.push({name:e,local:e});if(t)for(let t of e.specifiers)i.exports.push({name:t.exported.name,local:t.local.name})}return m.set(t,i),i}function S(e,a){if(!a.startsWith(`.`))return null;let o=i(n(e),a).replace(/\.(jsx?|tsx?)$/,``);for(let e of[`${o}.d.ts`,r(o,`index.d.ts`)])if(t(e))return e;throw Error(`Cannot resolve ${a} from ${e}`)}function C(e,t=new Set){let n=new Map;if(t.has(e))return n;t.add(e);for(let r of x(e).exports){if(r.star){let i=S(e,r.source);for(let[e,r]of i?C(i,t):[])e!=="default"&&!n.has(e)&&n.set(e,r);continue}let i=r.source===void 0?e:S(e,r.source);i&&n.set(r.name,{file:i,local:r.local})}return n}function w(e,t=new Set){let n=`${e.file}#${e.local}`;if(t.has(n))return null;t.add(n);let r=x(e.file);if(r.declarations.has(e.local))return e;let i=r.exports.find(t=>t.name===e.local&&t.source!==void 0),a=i&&S(e.file,i.source);return a?w({file:a,local:i.local},t):null}function T(e){return e.local==="default"?e:w(e)}function E(e){let t=T(e);if(!t)return null;let{declarations:n,defaultDeclaration:r}=x(t.file),i=t.local==="default"?r?.type===`Identifier`?n.get(r.name):r:n.get(t.local);return i?.type===`TSDeclareFunction`||i?.type===`FunctionDeclaration`?i:null}function D(e,t,n){let r=e.params[0];if(!r)return[];let i=(r.type===`AssignmentPattern`?r.left:r).typeAnnotation?.typeAnnotation;if(!i)return null;if(i.type===`TSTypeLiteral`)return i.members;let a=y(i);if(i.type!==`TSTypeReference`||!a?.endsWith(`Props`))return null;let o=x(t.file).declarations.get(a);if(o?.type===`TSInterfaceDeclaration`)return o.body.body;if(o?.type===`TSTypeAliasDeclaration`&&o.typeAnnotation.type===`TSTypeLiteral`)return o.typeAnnotation.members;throw Error(`${n}: ${a} is not an object type in ${t.file}`)}function O(e,t){let n=x(e),r=n.declarations.get(t);if(r)return{file:e,declared:r};let i=n.imports.get(t),a=i&&S(e,i.source);if(!a)return null;let o=w({file:a,local:i.imported});return o?{file:o.file,declared:x(o.file).declarations.get(o.local)}:null}function k(e,t,n){if(e===`ReactNode`||e===`ReactElement`)return{type:`node`};if(d.includes(e))return{type:`array`};if(e===`Record`)return{type:`object`};if(e===`Date`)return{type:`string`};if(e===`Function`)return o;if(e===`SlotIcon`)return{type:`node`};if(!t||n>=s)return null;let r=O(t,e);return r?.declared?.type===`TSTypeAliasDeclaration`?R(r.declared.typeAnnotation,r.file,n+1):r?.declared?.type===`TSInterfaceDeclaration`?V(r.declared.body.body,r.file):null}function A(e){return e.type===`TSBooleanKeyword`||e.type===`TSLiteralType`&&e.literal.type===`BooleanLiteral`}function j(e){return e.type===`TSLiteralType`&&e.literal.type===`StringLiteral`}function M(e){return e.type===`TSObjectKeyword`||e.type===`TSTypeLiteral`}function N(e){return e?.type===`TSQualifiedName`&&e.left.type===`Identifier`&&e.left.name===`JSX`&&e.right.name===`Element`}function P(e){return e.type===`TSTypeReference`&&[`File`,`Blob`].includes(y(e))}function F(e,t,n){let r=e.filter(e=>e.type!==`TSNullKeyword`&&e.type!==`TSUndefinedKeyword`&&!P(e)),i=e=>r.every(t=>t.type===`TSLiteralType`&&t.literal.type===e);if(r.length===0)return null;if(i(`StringLiteral`))return{type:`enum`,enum:_(r.map(e=>e.literal.value))};if(i(`BooleanLiteral`)||r.some(A)&&r.every(e=>A(e)||j(e)||M(e)))return{type:`boolean`};if(i(`NumericLiteral`))return{type:`number`};if(r.length===1&&r[0].type!==`TSLiteralType`)return R(r[0],t,n);let a=r.flatMap(e=>I(e,t,n));if(a.length>0&&!a.includes(null))return{type:`enum`,enum:_(a)};let s=new Set(r.map(e=>L(e,t,n)));return s.has(`node`)?{type:`node`}:s.size===2&&s.has(`string`)&&s.has(`number`)?{type:`stringOrNumber`}:s.size===1&&!s.has(null)?{type:[...s][0]}:r.every(e=>e.type!==`TSLiteralType`)&&r.map(e=>R(e,t,n)).every(e=>e&&e!==o&&[`object`,`array`].includes(e.type))?{type:`any`}:null}function I(e,t,n){if(e.type===`TSLiteralType`)return e.literal.type===`StringLiteral`?[e.literal.value]:[null];let r=R(e,t,n);return r?.type===`enum`?r.enum:[null]}function L(e,t,n){if(e.type===`TSLiteralType`){let t=e.literal.type;return t===`StringLiteral`?`string`:t===`NumericLiteral`?`number`:t===`BooleanLiteral`?`boolean`:null}let r=R(e,t,n);return r?.type===`enum`?`string`:r&&r!==o&&[`node`,`string`,`number`,`boolean`].includes(r.type)?r.type:null}function R(e,t,n=0){switch(e.type){case`TSParenthesizedType`:return R(e.typeAnnotation,t,n);case`TSAnyKeyword`:case`TSUnknownKeyword`:return{type:`any`,anyUnknown:!0};case`TSStringKeyword`:return{type:`string`};case`TSNumberKeyword`:return{type:`number`};case`TSBooleanKeyword`:return{type:`boolean`};case`TSArrayType`:return H(e.elementType,t,n);case`TSTypeLiteral`:return V(e.members,t);case`TSFunctionType`:return o;case`TSLiteralType`:return F([e],t,n);case`TSUnionType`:return F(e.types,t,n);case`TSTypeReference`:return N(e.typeName)?{type:`node`}:d.includes(y(e))&&e.typeParameters?.params.length===1?H(e.typeParameters.params[0],t,n):k(y(e),t,n);case`TSImportType`:return N(e.qualifier)?{type:`node`}:k(y(e),null,n);default:return null}}function z(e,t){return p.test(e)&&(t===`string`||t===`any`)?`url`:t}function B(e,t){if(h.size>=c||h.has(e))return null;h.add(e);try{return U(e,t)}finally{h.delete(e)}}function V(e,t){let n=B(e,t);return n?{type:`object`,fields:n.props,skippedFields:n.skippedProps}:{type:`object`}}function H(e,t,n){let r=R(e,t,n);return r?.fields?{type:`array`,itemFields:r.fields,skippedFields:r.skippedFields}:{type:`array`}}function U(e,t){let n=[],r=[],i=!1;for(let a of e){if(a.type!==`TSPropertySignature`)continue;let e=v(a.key);if(!e)continue;if(e===`children`){i=!0;continue}let s=a.typeAnnotation?.typeAnnotation??{type:`TSAnyKeyword`},c=R(s,t);if(c===o)continue;if(!c){r.push({name:e,type:W(s,t)});continue}let{type:l,enum:u,anyUnknown:d,fields:p,itemFields:m,skippedFields:h=[]}=c;for(let t of h)r.push({...t,name:`${e}${l===`array`?`[]`:``}.${t.name}`});n.push({name:e,type:z(e,l===`node`&&f.test(e)?`icon`:l),...u?{enum:u}:{},...p?{fields:p}:{},...m?{itemFields:m}:{},required:!a.optional&&!d})}return n.sort((e,t)=>g(e.name,t.name)),{props:n,acceptsChildren:i,skippedProps:r}}function W(e,t){let n=t?x(t).source:null;if(!n)return e.type;let r=n.slice(e.start,e.end).replace(/\s+/g,` `);return r.length>l?`${r.slice(0,l)}...`:r}function G(e,t){return!e||typeof e!=`object`?!1:e.type===`TSTypeReference`&&y(e)===t||Object.entries(e).some(([e,n])=>e!==`loc`&&(Array.isArray(n)?n.some(e=>G(e,t)):G(n,t)))}function K(e){if(!e||![`TSTypeReference`,`TSImportType`].includes(e.type)||y(e)!==`ForwardRefExoticComponent`)return null;let[t]=(e.typeParameters??e.typeArguments)?.params??[],n=(t?.type===`TSIntersectionType`?t.types:[t]).filter(e=>e?.type===`TSTypeLiteral`);return n.length?n.flatMap(e=>e.members):null}function q(e){let t=T(e);if(!t)return null;let{declarations:n,defaultDeclaration:r}=x(t.file),i=t.local==="default"?r?.type===`Identifier`&&n.get(r.name):n.get(t.local);return i?.type===`VariableDeclarator`?{node:i,declarations:n}:null}function J(e){let t=q(e)?.node.id.typeAnnotation?.typeAnnotation;return[`TSTypeReference`,`TSImportType`].includes(t?.type)&&u.includes(y(t))}function Y(e,t){let n=q(e);if(!n)return null;let{node:r,declarations:i}=n,a=`${t}Props`;if(!G(r.id.typeAnnotation,a))return K(r.id.typeAnnotation?.typeAnnotation);let o=i.get(a);return o?.type===`TSInterfaceDeclaration`?o.body.body:o?.type===`TSTypeAliasDeclaration`&&o.typeAnnotation.type===`TSTypeLiteral`?o.typeAnnotation.members:null}function X(e,{namedConsts:t=!1,kit:n=``}={}){m=new Map,h.clear();let r=[],i=[];for(let[a,o]of C(e)){if(!/^[A-Z][A-Za-z0-9]*$/.test(a))continue;let s=E(o),c=T(o),l=s?D(s,c,a):t?Y(o,a):null;if(!l){(s||t&&J(o))&&i.push(`Component left out, its props could not be read: ${n} ${a}`);continue}let u=U(l,c?.file);if(u.skippedProps.length>0){let e=u.skippedProps.map(({name:e,type:t})=>`${e} (${t})`).join(`, `);i.push(`Skipped props, no manifest type: ${n} ${a}: ${e}`)}r.push({name:a,acceptsChildren:u.acceptsChildren,props:u.props,file:c?.file??e})}return r.sort((e,t)=>g(e.name,t.name)),{components:r,warnings:i}}export{X as collectComponents};
|
|
1
|
+
import{readText as e}from"./files.js";import{existsSync as t}from"node:fs";import{dirname as n,join as r,resolve as i}from"node:path";import a from"@babel/parser";var o=`function`,s=8,c=2,l=120,u=[`ForwardRefExoticComponent`,`FC`,`FunctionComponent`,`ComponentType`,`MemoExoticComponent`],d=[`Array`,`ReadonlyArray`,`Set`,`ReadonlySet`],f=/(^i|I)con$/,p=/(Href|href|Url|url)$/,m=new Map,h=new Set,g=new Set,_=[];function v(e,t){return e<t?-1:+(e>t)}function y(e){return[...new Set(e)].sort(v)}function b(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function x(e){let t=e.type===`TSImportType`?e.qualifier:e.typeName;return t?t.type===`TSQualifiedName`?t.right.name:t.name:null}function ee(e){switch(e.type){case`TSDeclareFunction`:case`FunctionDeclaration`:case`TSInterfaceDeclaration`:case`TSTypeAliasDeclaration`:return[[e.id.name,e]];case`VariableDeclaration`:return e.declarations.filter(e=>e.id.type===`Identifier`).map(e=>[e.id.name,e]);default:return[]}}function S(t){if(m.has(t))return m.get(t);let n=e(t),r=a.parse(n,{sourceType:`module`,plugins:[`typescript`]}),i={declarations:new Map,imports:new Map,exports:[],defaultDeclaration:null,source:n};for(let e of r.program.body)if(e.type===`ImportDeclaration`)for(let t of e.specifiers)t.type===`ImportSpecifier`&&i.imports.set(t.local.name,{source:e.source.value,imported:b(t.imported)});else if(e.type===`ExportAllDeclaration`)i.exports.push({star:!0,source:e.source.value});else if(e.type===`ExportDefaultDeclaration`)i.defaultDeclaration=e.declaration,i.exports.push({name:`default`,local:`default`});else if(e.type===`ExportNamedDeclaration`&&e.source)for(let t of e.specifiers)i.exports.push({name:t.exported.name,local:t.local.name,source:e.source.value});else{let t=e.type===`ExportNamedDeclaration`,n=t?e.declaration:e;for(let[e,r]of n?ee(n):[])i.declarations.set(e,r),t&&i.exports.push({name:e,local:e});if(t)for(let t of e.specifiers)i.exports.push({name:t.exported.name,local:t.local.name})}return m.set(t,i),i}function C(e,a){if(!a.startsWith(`.`))return null;let o=i(n(e),a).replace(/\.(jsx?|tsx?)$/,``);for(let e of[`${o}.d.ts`,r(o,`index.d.ts`)])if(t(e))return e;throw Error(`Cannot resolve ${a} from ${e}`)}function w(e,t=new Set){let n=new Map;if(t.has(e))return n;t.add(e);for(let r of S(e).exports){if(r.star){let i=C(e,r.source);for(let[e,r]of i?w(i,t):[])e!=="default"&&!n.has(e)&&n.set(e,r);continue}let i=r.source===void 0?e:C(e,r.source);i&&n.set(r.name,{file:i,local:r.local})}return n}function T(e,t=new Set){let n=`${e.file}#${e.local}`;if(t.has(n))return null;t.add(n);let r=S(e.file);if(r.declarations.has(e.local))return e;let i=r.exports.find(t=>t.name===e.local&&t.source!==void 0),a=i&&C(e.file,i.source);return a?T({file:a,local:i.local},t):null}function E(e){return e.local==="default"?e:T(e)}function te(e){let t=E(e);if(!t)return null;let{declarations:n,defaultDeclaration:r}=S(t.file),i=t.local==="default"?r?.type===`Identifier`?n.get(r.name):r:n.get(t.local);return i?.type===`TSDeclareFunction`||i?.type===`FunctionDeclaration`?i:null}function ne(e,t,n){let r=e.params[0];if(!r)return[];let i=(r.type===`AssignmentPattern`?r.left:r).typeAnnotation?.typeAnnotation;if(!i)return null;let a=F(i,t.file,new Map,0);if(a)return a;let o=x(i);if(i.type===`TSTypeReference`&&o?.endsWith(`Props`)&&S(t.file).declarations.has(o))throw Error(`${n}: ${o} is not an object type in ${t.file}`);return null}function D(e,t){let n=S(e),r=n.declarations.get(t);if(r)return{file:e,declared:r};let i=n.imports.get(t),a=i&&C(e,i.source);if(!a)return null;let o=T({file:a,local:i.imported});return o?{file:o.file,declared:S(o.file).declarations.get(o.local)}:null}function O(e,t,n,r,i){let a=new Map;return(e.typeParameters?.params??[]).forEach((e,o)=>{let s=t[o];s?a.set(e.name,{node:s,file:n,env:r}):e.default?a.set(e.name,{node:e.default,file:i,env:a}):a.set(e.name,{node:{type:`TSUnknownKeyword`},file:i,env:new Map})}),a}function k(e){if(!e?.expression)return null;let t=(e.typeParameters??e.typeArguments)?.params;return{type:`TSTypeReference`,typeName:e.expression,...t?{typeParameters:{params:t}}:{}}}function A(e,t,n){if(e.type===`TSImportType`){let t=e.argument?.value;return typeof t!=`string`||!t.startsWith(`.`)}let r=n?S(n).imports.get(t):null;return!!(r&&!r.source.startsWith(`.`))}function j(e,t,n){if(!e)return null;let r=e.type===`TSUnionType`?e.types:[e],i=[];for(let e of r){if(e.type===`TSNullKeyword`||e.type===`TSUndefinedKeyword`)continue;let r=U(e,t,n);if(r.length===0||r.includes(null))return null;i.push(...r)}return i.length>0?i:null}function M(e,t,n,r){let i=e.filter(e=>e.type!==`TSNullKeyword`&&e.type!==`TSUndefinedKeyword`);if(i.length===1)return F(i[0],t,n,r);let a=[];for(let e of i){let i=F(e,t,n,r);if(!i)return null;a.push(i)}let o=[],s=new Map;for(let e of a)for(let t of e){let e=s.get(t.name);e||(e={name:t.name,count:0,requiredEverywhere:!0,branches:[]},s.set(t.name,e),o.push(t.name)),e.count+=1,e.requiredEverywhere=e.requiredEverywhere&&!t.optional,e.branches.push(...t.branches)}return o.map(e=>{let t=s.get(e);return{name:e,optional:!(t.count===a.length&&t.requiredEverywhere),branches:t.branches}})}function N(e,t,n,r,i,a){let o=O(e,t,n,r,i),s=[],c=new Map;for(let t of e.extends??[]){let e=F(k(t),i,o,a+1);if(!e)return null;for(let t of e)c.has(t.name)||s.push(t.name),c.set(t.name,t)}let l=F({type:`TSTypeLiteral`,members:e.body.body},i,o,a);if(!l)return null;for(let e of l){let t=s.indexOf(e.name);t>=0&&s.splice(t,1),s.push(e.name),c.set(e.name,e)}return s.map(e=>c.get(e))}function P(e,t,n,r){let i=x(e),a=(e.typeParameters??e.typeArguments)?.params??[];if(i&&n.has(i)){let e=n.get(i);return F(e.node,e.file,e.env,r+1)}if(i===`RefAttributes`)return[];if([`Partial`,`Required`,`Readonly`].includes(i)&&a.length===1){let e=F(a[0],t,n,r);return e?i===`Partial`?e.map(e=>({...e,optional:!0})):i===`Required`?e.map(e=>({...e,optional:!1})):e:null}if((i===`Omit`||i===`Pick`)&&a.length===2){let e=F(a[0],t,n,r);if(!e)return null;let o=j(a[1],t,r);if(!o)return i===`Omit`?e:null;let s=new Set(o);return i===`Omit`?e.filter(e=>!s.has(e.name)):e.filter(e=>s.has(e.name))}if(A(e,i,t))return i&&g.add(i),[];let o=D(t,i);if(!o?.declared)return null;if(o.declared.type===`TSInterfaceDeclaration`)return N(o.declared,a,t,n,o.file,r);if(o.declared.type===`TSTypeAliasDeclaration`){let e=O(o.declared,a,t,n,o.file);return F(o.declared.typeAnnotation,o.file,e,r+1)}return null}function F(e,t,n,r){if(!e||r>=s)return null;switch(e.type){case`TSParenthesizedType`:return F(e.typeAnnotation,t,n,r);case`TSTypeLiteral`:return e.members.filter(e=>e.type===`TSPropertySignature`&&b(e.key)!==null).map(e=>({name:b(e.key),optional:e.optional===!0,branches:[{node:e.typeAnnotation?.typeAnnotation??{type:`TSAnyKeyword`},file:t,env:n}]}));case`TSIntersectionType`:{let i=[],a=new Map;for(let o of e.types){let e=F(o,t,n,r);if(!e)return null;for(let t of e)a.has(t.name)||i.push(t.name),a.set(t.name,t)}return i.map(e=>a.get(e))}case`TSUnionType`:return M(e.types,t,n,r);case`TSTypeReference`:case`TSImportType`:return P(e,t,n,r);default:return null}}function I(e,t,n){if(e===`ReactNode`||e===`ReactElement`)return{type:`node`};if(d.includes(e))return{type:`array`};if(e===`Record`)return{type:`object`};if(e===`Date`)return{type:`string`};if(e===`Function`)return o;if(e===`SlotIcon`)return{type:`node`};if(!t||n>=s)return null;let r=D(t,e);if(r?.declared?.type===`TSTypeAliasDeclaration`)return G(r.declared.typeAnnotation,r.file,n+1);if(r?.declared?.type===`TSInterfaceDeclaration`){let i=F({type:`TSTypeReference`,typeName:{type:`Identifier`,name:e}},t,_.at(-1)??new Map,n+1);return i?J(i,r.declared):null}return null}function L(e){return e.type===`TSBooleanKeyword`||e.type===`TSLiteralType`&&e.literal.type===`BooleanLiteral`}function R(e){return e.type===`TSLiteralType`&&e.literal.type===`StringLiteral`}function z(e){return e.type===`TSObjectKeyword`||e.type===`TSTypeLiteral`}function B(e){return e?.type===`TSQualifiedName`&&e.left.type===`Identifier`&&e.left.name===`JSX`&&e.right.name===`Element`}function V(e){return e.type===`TSTypeReference`&&[`File`,`Blob`].includes(x(e))}function H(e,t,n){let r=e.filter(e=>e.type!==`TSNullKeyword`&&e.type!==`TSUndefinedKeyword`&&!V(e)),i=e=>r.every(t=>t.type===`TSLiteralType`&&t.literal.type===e);if(r.length===0)return null;if(i(`StringLiteral`))return{type:`enum`,enum:y(r.map(e=>e.literal.value))};if(i(`BooleanLiteral`)||r.some(L)&&r.every(e=>L(e)||R(e)||z(e)))return{type:`boolean`};if(i(`NumericLiteral`))return{type:`number`};if(r.length===1&&r[0].type!==`TSLiteralType`)return G(r[0],t,n);let a=r.flatMap(e=>U(e,t,n));if(a.length>0&&!a.includes(null))return{type:`enum`,enum:y(a)};let s=new Set(r.map(e=>W(e,t,n)));return s.has(`node`)?{type:`node`}:s.size===2&&s.has(`string`)&&s.has(`number`)?{type:`stringOrNumber`}:s.size===1&&!s.has(null)?{type:[...s][0]}:r.every(e=>e.type!==`TSLiteralType`)&&r.map(e=>G(e,t,n)).every(e=>e&&e!==o&&[`object`,`array`].includes(e.type))?{type:`any`}:null}function U(e,t,n){if(e.type===`TSLiteralType`)return e.literal.type===`StringLiteral`?[e.literal.value]:[null];let r=G(e,t,n);return r?.type===`enum`?r.enum:[null]}function W(e,t,n){if(e.type===`TSLiteralType`){let t=e.literal.type;return t===`StringLiteral`?`string`:t===`NumericLiteral`?`number`:t===`BooleanLiteral`?`boolean`:null}let r=G(e,t,n);return r?.type===`enum`?`string`:r&&r!==o&&[`node`,`string`,`number`,`boolean`].includes(r.type)?r.type:null}function G(e,t,n=0){switch(e.type){case`TSParenthesizedType`:return G(e.typeAnnotation,t,n);case`TSAnyKeyword`:case`TSUnknownKeyword`:return{type:`any`,anyUnknown:!0};case`TSStringKeyword`:return{type:`string`};case`TSNumberKeyword`:return{type:`number`};case`TSBooleanKeyword`:return{type:`boolean`};case`TSArrayType`:return X(e.elementType,t,n);case`TSTypeLiteral`:return Y(e.members,t);case`TSFunctionType`:return o;case`TSLiteralType`:return H([e],t,n);case`TSUnionType`:return H(e.types,t,n);case`TSTypeReference`:{let r=x(e),i=_.at(-1);if(r&&i?.has(r)){let e=i.get(r);_.push(e.env);try{return G(e.node,e.file,n+1)}finally{_.pop()}}return B(e.typeName)?{type:`node`}:d.includes(r)&&e.typeParameters?.params.length===1?X(e.typeParameters.params[0],t,n):I(r,t,n)}case`TSImportType`:return B(e.qualifier)?{type:`node`}:I(x(e),null,n);default:return null}}function K(e,t){return p.test(e)&&(t===`string`||t===`any`)?`url`:t}function q(e,t=e){if(h.size>=c||h.has(t))return null;h.add(t);try{return Z(e)}finally{h.delete(t)}}function J(e,t=e){let n=q(e,t);return n?{type:`object`,fields:n.props,skippedFields:n.skippedProps,...n.hasHandler?{handler:!0}:{}}:{type:`object`}}function Y(e,t){let n=F({type:`TSTypeLiteral`,members:e},t,_.at(-1)??new Map,0);return n?J(n):{type:`object`}}function X(e,t,n){let r=G(e,t,n);return r?.fields?{type:`array`,itemFields:r.fields,skippedFields:r.skippedFields,...r.handler?{itemHandler:!0}:{}}:{type:`array`}}function re(e){_.push(e.env);try{return G(e.node,e.file)}finally{_.pop()}}function ie(e){let t=e.branches.map(e=>Q(e.node,e.file));return t.length===1?t[0]:t.join(` | `)}function Z(e){let t=[],n=[],r=!1,i=!1;for(let a of e){let e=a.name;if(e===`children`){r=!0;continue}let s=a.branches.map(e=>re(e));if(s.every(e=>e===o)){i=!0;continue}let c=a.branches[0],l;if(s.every(e=>e!==null&&JSON.stringify(e)===JSON.stringify(s[0])))l=s[0];else if(a.branches.every(e=>e.file===c.file&&e.env===c.env)){let e={type:`TSUnionType`,types:a.branches.map(e=>e.node)};_.push(c.env);try{l=G(e,c.file)}finally{_.pop()}}if(l===o){i=!0;continue}if(!l){n.push({name:e,type:ie(a)});continue}let{type:u,enum:d,anyUnknown:p,fields:m,itemFields:h,skippedFields:g=[]}=l;for(let t of g)n.push({...t,name:`${e}${u===`array`?`[]`:``}.${t.name}`});t.push({name:e,type:K(e,u===`node`&&f.test(e)?`icon`:u),...l.handler?{handler:!0}:{},...l.itemHandler?{itemHandler:!0}:{},...d?{enum:d}:{},...m?{fields:m}:{},...h?{itemFields:h}:{},required:!a.optional&&!p})}return t.sort((e,t)=>v(e.name,t.name)),{props:t,acceptsChildren:r,skippedProps:n,hasHandler:i}}function Q(e,t){if(e.start===void 0)return e.type===`TSUnionType`?e.types.map(e=>Q(e,t)).join(` | `):e.type;let n=t?S(t).source:null;if(!n)return e.type;let r=n.slice(e.start,e.end).replace(/\s+/g,` `);return r.length>l?`${r.slice(0,l)}...`:r}function $(e){let t=E(e);if(!t)return null;let{declarations:n,defaultDeclaration:r}=S(t.file),i=t.local==="default"?r?.type===`Identifier`&&n.get(r.name):n.get(t.local);return i?.type===`VariableDeclarator`?{node:i,declarations:n}:null}function ae(e){let t=$(e)?.node.id.typeAnnotation?.typeAnnotation;return[`TSTypeReference`,`TSImportType`].includes(t?.type)&&u.includes(x(t))}function oe(e){let t=$(e);if(!t)return null;let n=E(e)?.file,r=t.node.id.typeAnnotation?.typeAnnotation;for(;r;){if(![`TSTypeReference`,`TSImportType`].includes(r.type)||!u.includes(x(r)))return null;let e=(r.typeParameters??r.typeArguments)?.params??[];if(e.length===0)return[];if(r=e[0],![`TSTypeReference`,`TSImportType`].includes(r.type)||!u.includes(x(r)))return F(r,n,new Map,0)}return null}function se(e,{namedConsts:t=!1,kit:n=``}={}){m=new Map,h.clear(),g.clear(),_.length=0;let r=[],i=[];for(let[a,o]of w(e)){if(!/^[A-Z][A-Za-z0-9]*$/.test(a))continue;let s=te(o),c=E(o),l=s?ne(s,c,a):t?oe(o):null;if(!l){(s||t&&ae(o))&&i.push(`Component left out, its props could not be read: ${n} ${a}`);continue}let u=Z(l);if(u.skippedProps.length>0){let e=u.skippedProps.map(({name:e,type:t})=>`${e} (${t})`).join(`, `);i.push(`Skipped props, no manifest type: ${n} ${a}: ${e}`)}r.push({name:a,acceptsChildren:u.acceptsChildren,props:u.props,file:c?.file??e})}return r.sort((e,t)=>v(e.name,t.name)),g.size>0&&i.push(`Props inherited from outside the kit were not read: ${n} ${y(g).join(`, `)}`),{components:r,warnings:i}}export{se as collectComponents};
|
package/dist/manifest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findPackageDir as e,readJson as t,readText as n,toPosix as r}from"./files.js";import"./kitModule.js";import{collectComponents as i}from"./declarations.js";import{PHONE_EXCLUDED_COMPONENTS as a,applyPhoneActions as o,phoneIcons as s,phoneTokenValues as c,phoneTokens as l}from"./phone.js";import{colourMeanings as u,webIcons as d,webTokenValues as
|
|
1
|
+
import{findPackageDir as e,readJson as t,readText as n,toPosix as r}from"./files.js";import"./kitModule.js";import{collectComponents as i}from"./declarations.js";import{PHONE_EXCLUDED_COMPONENTS as a,applyPhoneActions as o,phoneIcons as s,phoneTokenValues as c,phoneTokens as l}from"./phone.js";import{colourMeanings as u,webIcons as d,webTokenValues as ee,webTokens as te}from"./tokens.js";import{createRequire as f}from"node:module";import{existsSync as p,mkdtempSync as m,rmSync as h}from"node:fs";import{dirname as g,join as _,relative as v,resolve as y}from"node:path";import{execFileSync as b}from"node:child_process";import{tmpdir as x}from"node:os";import S from"@babel/parser";var C=/^[a-z][a-z0-9-]{1,39}$/,w=[`Web`,`Phone`],T=[`title`,`navigation`],E=_(g(f(import.meta.url).resolve(`typescript/package.json`)),`bin`,`tsc`),D=[`.jsx`,`.js`,`.tsx`,`.ts`,`.mjs`],O=/^App[A-Z]/,k={Web:`WeborityWeb`,Phone:`WeborityPhone`};function A(n,r){let i=e(n,r);if(!i)throw Error(`${r} is not installed for ${n}. Run pnpm install there.`);let a=t(_(i,`package.json`)),o=(e,t)=>{if(typeof e==`string`)return t==="default"?e:void 0;if(!(!e||typeof e!=`object`))return typeof e[t]==`string`?e[t]:o(e.import,t)??o(e.default,t)},s=a.exports?.[`.`],c=a.types??o(s,`types`),l=o(s,`default`)??a.main;if(!c)throw Error(`${r} declares no types, and the manifest reads its declaration files.`);if(!l)throw Error(`${r} declares no entry file for its runtime.`);return{dir:i,pkg:a,typesFile:_(i,c),entryFile:_(i,l)}}function j(t){let n=e(t,`@webority/theme`);if(!n)throw Error(`@webority/theme is not installed for ${t}. Run pnpm install.`);return n}function M(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 N(e,t){let n=m(_(x(),`canvas-kit-declarations-`));try{b(process.execPath,[E,`--allowJs`,`--declaration`,`--emitDeclarationOnly`,`--jsx`,`react-jsx`,`--module`,`esnext`,`--moduleResolution`,`bundler`,`--target`,`es2022`,`--skipLibCheck`,`--rootDir`,e,`--outDir`,n,t],{cwd:e,encoding:`utf8`,stdio:`pipe`})}catch(e){throw h(n,{recursive:!0,force:!0}),Error(`Could not read the declarations of ${t}: ${e.stdout||e.stderr||e.message}`)}return n}function P(e,t,n){let i=v(t,n).replace(/\.d\.ts$/,``);for(let t of D)if(p(_(e,`${i}${t}`)))return r(`${i}${t}`);throw Error(`No source file for the declarations in ${n}`)}function ne(e,t,r){let i=/\.tsx?$/.test(t)?[`jsx`,`typescript`]:[`jsx`],a=S.parse(n(_(e,t)),{sourceType:`module`,plugins:i});for(let e of a.program.body){let t=e.type===`ExpressionStatement`?e.expression:null;if(t?.type===`AssignmentExpression`&&t.left.type===`MemberExpression`&&!t.left.computed&&t.left.object.type===`Identifier`&&t.left.object.name===r&&t.left.property.name===`displayName`&&t.right.type===`StringLiteral`)return t.right.value}return null}function re(e){return e.filter(e=>e.type===`array`&&(e.itemFields??[]).some(e=>[`href`,`to`].includes(e.name))).map(e=>e.name)}function F(e,t){return e.filter(e=>e[t]===!0).map(e=>e.name)}function I(e){return e.map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==`handler`&&e!==`itemHandler`).map(([e,t])=>[e,Array.isArray(t)&&(e===`fields`||e===`itemFields`)?I(t):t])))}function L(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(!T.includes(i))throw Error(`${n}: ${t} has role ${JSON.stringify(i)}; a role is title or navigation.`);r.role=i}}function R(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 z(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 B(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 V(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}))}function H({projectRoot:e,kit:r,platform:f,entry:p,libraryPackage:m,rolesFile:g,rendererProtocolVersion:b,phoneRendererSupportFile:x,styleKeysFile:S}){if(!C.test(r??``))throw Error(`kit ${JSON.stringify(r)} must be 2 to 40 characters: lowercase letters, digits and hyphens, starting with a letter.`);if(!w.includes(f))throw Error(`platform must be Web or Phone, not ${JSON.stringify(f)}.`);if(!Number.isInteger(b)||b<1)throw Error(`rendererProtocolVersion must be a positive integer, not ${JSON.stringify(b)}.`);if(f===`Phone`&&!x)throw Error(`A Phone kit needs phoneRendererSupportFile, the phone renderer's support file.`);let T=y(e),E=A(T,m);M(T,m,E.pkg.version);let D=x?z(x):null,H=f===`Phone`?D:null,U=S?R(S):null;U&&D&&B(U,D.flags,x);let W=i(E.typesFile,{namedConsts:!0,kit:m}),G=f===`Phone`?W.components.filter(({name:e})=>!a.has(e)):W.components,K={components:[],warnings:[]},q=new Map;if(p!==void 0){let e=y(p);if(v(T,e).startsWith(`..`))throw Error(`The kit entry ${e} is outside the product folder ${T}.`);let t=N(T,e);try{K=i(_(t,v(T,e)).replace(/\.[^./\\]+$/,`.d.ts`),{kit:r}),q=new Map(K.components.map(e=>[e.name,P(T,t,e.file)]))}finally{h(t,{recursive:!0,force:!0})}}let J=new Set(G.map(({name:e})=>e)),Y=K.components.filter(({name:e})=>J.has(e)).map(({name:e})=>e);if(Y.length>0)throw Error(`The kit names ${Y.join(`, `)} as ${m} already has them; rename the product components.`);let X=[...G.map(e=>({...e,source:m,marker:O.test(e.name)?e.name:null})),...K.components.map(e=>{let t=q.get(e.name);return{...e,source:t,marker:ne(T,t,e.name)}})].sort((e,t)=>e.name<t.name?-1:+(e.name>t.name)).map(({name:e,marker:t,acceptsChildren:n,props:r,source:i})=>({name:e,marker:t,acceptsChildren:n,props:I(r),itemsTakeAction:f===`Web`?re(r):F(r,`itemHandler`),takesAction:f===`Web`?[]:F(r,`handler`),source:i}));H&&o(X,H.itemActions),L(X,g);let Z,Q,$;if(f===`Web`){let e=j(T);Z=te(n(_(e,`scss`,`_tokens.scss`))),Z.colorMeanings=u(Z.color,t(_(e,`token-meanings.json`))),Q=ee(_(e,`dist`,`published-theme.json`),Z),$=d(_(E.dir,`dist`))}else{let e=_(E.dir,`lib`,`module`,`theme`,`tokens.js`);Z=l(e),Q=c(e),$=s(_(E.dir,`lib`,`typescript`,`module`,`components`,`AppIcon`,`catalog.g.d.ts`))}return{manifest:{kind:p===void 0?k[f]:`Product`,library:{name:E.pkg.name,version:E.pkg.version},rendererProtocolVersion:b,platform:f,kitModuleVersion:2,productKit:null,components:X,tokens:Z,tokenValues:Q,icons:$,...U?{styleKeys:V(U,D?D.flags:null)}:{}},warnings:[...W.warnings,...K.warnings]}}export{A as libraryFiles,H as readManifest,z as readPhoneSupport};
|
package/dist/phone.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readText as e}from"./files.js";import t from"@babel/parser";var n=new Set([`Form`,`NetworkStatusBanner`,`SkeletonClockProvider`,`SkeletonProvider`,`SkeletonSkip`,`ThemeProvider`,`ToastProvider`,`Box`,`Text`]),r=[`sans`],i=`System`;function a(n){return t.parse(e(n),{sourceType:`module`,plugins:[`typescript`]})}function o(e){return[...new Set(e)].sort((e,t)=>e<t?-1:+(e>t))}function s(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function c(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 l(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 u(e,t,n,r){let i=n.properties.find(e=>e.type===`ObjectProperty`&&s(e.key)===r);if(!i)throw Error(`${r} is missing from the theme in ${t}`);return l(e,i.value,t)}function d(e){return e.properties.filter(e=>e.type===`ObjectProperty`).map(e=>s(e.key))}function f(e,t,n,r=``){return n.properties.flatMap(n=>{if(n.type!==`ObjectProperty`)return[];let i=`${r}${s(n.key)}`,a=l(e,n.value,t);return a.type===`StringLiteral`?[i]:a.type===`ObjectExpression`?f(e,t,a,`${i}.`):[]})}function p(e){let t=c(a(e));if(!t.has(`lightTheme`))throw Error(`lightTheme is not declared in ${e}`);let n=l(t,t.get(`lightTheme`),e),i=u(t,e,n,`typography`);return{color:o(f(t,e,u(t,e,n,`colors`))),space:o(d(u(t,e,n,`spacing`))),radius:o(d(u(t,e,n,`radius`))),shadow:o(d(u(t,e,n,`shadows`))),font:r,text:o(d(u(t,e,i,`fontSize`)))}}function m(e,t,n){let r=l(e,t,n);if(r.type===`StringLiteral`||r.type===`NumericLiteral`)return r.value;if(r.type===`UnaryExpression`&&r.operator===`-`&&r.argument.type===`NumericLiteral`)return-r.argument.value;if(r.type===`ObjectExpression`)return Object.fromEntries(r.properties.map(t=>{if(t.type!==`ObjectProperty`)throw Error(`${n} spreads an object the reader cannot follow.`);return[s(t.key),m(e,t.value,n)]}));throw Error(`${n} has a ${r.type} the reader cannot read as a value.`)}function h(e,t,n){for(let r of[[`typography`,`fontFamily`,`sans`],[`fontFamily`,`sans`]])try{let i=g(e,t,n,r);if(typeof i==`string`&&i!==``)return i}catch{}return`System`}function g(e,t,n,r){let i=l(e,n,t);for(let n of r)i=u(e,t,i,n);return m(e,i,t)}function _(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>{if(typeof r!=`number`)throw Error(`${t}.${e} in ${n} is not a number.`);return[e,r]}))}function v(e,t,n){if(Object.keys(e).length===0)return`none`;let{shadowColor:r,shadowOffset:i,shadowOpacity:a,shadowRadius:o}=e,s=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(typeof r==`string`?r:``);if(!s||typeof i?.width!=`number`||typeof i?.height!=`number`||typeof a!=`number`||typeof o!=`number`)throw Error(`shadows.${t} in ${n} is not a shadow the reader can draw.`);let c=s[1].length===3?[...s[1]].map(e=>e+e).join(``):s[1],[l,u,d]=[0,2,4].map(e=>Number.parseInt(c.slice(e,e+2),16));return`${i.width}px ${i.height}px ${o}px rgba(${l}, ${u}, ${d}, ${a})`}function y(e){let t=c(a(e));for(let n of[`lightTheme`,`darkTheme`])if(!t.has(n))throw Error(`${n} is not declared in ${e}; the phone kit's token values need the light and dark themes.`);let n=t.get(`lightTheme`),r=t.get(`darkTheme`),o=u(t,e,l(t,n,e),`colors`),s=u(t,e,l(t,r,e),`colors`),d=h(t,e,n);return{color:Object.fromEntries(f(t,e,o).map(n=>{let r=n.split(`.`);return[n,{light:g(t,e,o,r),dark:g(t,e,s,r)}]})),space:_(g(t,e,n,[`spacing`]),`spacing`,e),radius:_(g(t,e,n,[`radius`]),`radius`,e),shadow:Object.fromEntries(Object.entries(g(t,e,n,[`shadows`])).map(([t,n])=>[t,v(n,t,e)])),font:{sans:{family:d,fallback:i}},text:Object.fromEntries(Object.entries(_(g(t,e,n,[`typography`,`fontSize`]),`fontSize`,e)).map(([e,t])=>[e,{size:t,lineHeight:null,weight:null}]))}}function b(e){let t=a(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 o(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 x(e,t){for(let[n,r]of[[`itemsTakeAction`,`array`],[`takesAction`,`object`]])for(let[i,a]of Object.entries(t[n]??{})){let t=e.find(({name:e})=>e===i);if(!t)throw Error(`phoneStyleSupport.json ${n} names ${i}, which the kit does not have.`);for(let e of a)if(t.props.find(({name:t})=>t===e)?.type!==r)throw Error(`phoneStyleSupport.json ${n} names ${i}.${e}, which is not a prop of type ${r} in the kit.`);t[n]=o(a)}}export{n as PHONE_EXCLUDED_COMPONENTS,x as applyPhoneActions,b as phoneIcons,y as phoneTokenValues,p as phoneTokens};
|
|
1
|
+
import{readText as e}from"./files.js";import t from"@babel/parser";var n=new Set([`Form`,`NetworkStatusBanner`,`SkeletonClockProvider`,`SkeletonProvider`,`SkeletonSkip`,`ThemeProvider`,`ToastProvider`,`Box`,`Text`]),r=[`sans`],i=`System`;function a(n){return t.parse(e(n),{sourceType:`module`,plugins:[`typescript`]})}function o(e){return[...new Set(e)].sort((e,t)=>e<t?-1:+(e>t))}function s(e){return e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:null}function c(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 l(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 u(e,t,n,r){let i=n.properties.find(e=>e.type===`ObjectProperty`&&s(e.key)===r);if(!i)throw Error(`${r} is missing from the theme in ${t}`);return l(e,i.value,t)}function d(e){return e.properties.filter(e=>e.type===`ObjectProperty`).map(e=>s(e.key))}function f(e,t,n,r=``){return n.properties.flatMap(n=>{if(n.type!==`ObjectProperty`)return[];let i=`${r}${s(n.key)}`,a=l(e,n.value,t);return a.type===`StringLiteral`?[i]:a.type===`ObjectExpression`?f(e,t,a,`${i}.`):[]})}function p(e){let t=c(a(e));if(!t.has(`lightTheme`))throw Error(`lightTheme is not declared in ${e}`);let n=l(t,t.get(`lightTheme`),e),i=u(t,e,n,`typography`);return{color:o(f(t,e,u(t,e,n,`colors`))),space:o(d(u(t,e,n,`spacing`))),radius:o(d(u(t,e,n,`radius`))),shadow:o(d(u(t,e,n,`shadows`))),font:r,text:o(d(u(t,e,i,`fontSize`)))}}function m(e,t,n){let r=l(e,t,n);if(r.type===`StringLiteral`||r.type===`NumericLiteral`)return r.value;if(r.type===`UnaryExpression`&&r.operator===`-`&&r.argument.type===`NumericLiteral`)return-r.argument.value;if(r.type===`ObjectExpression`)return Object.fromEntries(r.properties.map(t=>{if(t.type!==`ObjectProperty`)throw Error(`${n} spreads an object the reader cannot follow.`);return[s(t.key),m(e,t.value,n)]}));throw Error(`${n} has a ${r.type} the reader cannot read as a value.`)}function h(e,t,n){for(let r of[[`typography`,`fontFamily`,`sans`],[`fontFamily`,`sans`]])try{let i=g(e,t,n,r);if(typeof i==`string`&&i!==``)return i}catch{}return`System`}function g(e,t,n,r){let i=l(e,n,t);for(let n of r)i=u(e,t,i,n);return m(e,i,t)}function _(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>{if(typeof r!=`number`)throw Error(`${t}.${e} in ${n} is not a number.`);return[e,r]}))}function v(e,t,n){if(Object.keys(e).length===0)return`none`;let{shadowColor:r,shadowOffset:i,shadowOpacity:a,shadowRadius:o}=e,s=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(typeof r==`string`?r:``);if(!s||typeof i?.width!=`number`||typeof i?.height!=`number`||typeof a!=`number`||typeof o!=`number`)throw Error(`shadows.${t} in ${n} is not a shadow the reader can draw.`);let c=s[1].length===3?[...s[1]].map(e=>e+e).join(``):s[1],[l,u,d]=[0,2,4].map(e=>Number.parseInt(c.slice(e,e+2),16));return`${i.width}px ${i.height}px ${o}px rgba(${l}, ${u}, ${d}, ${a})`}function y(e){let t=c(a(e));for(let n of[`lightTheme`,`darkTheme`])if(!t.has(n))throw Error(`${n} is not declared in ${e}; the phone kit's token values need the light and dark themes.`);let n=t.get(`lightTheme`),r=t.get(`darkTheme`),o=u(t,e,l(t,n,e),`colors`),s=u(t,e,l(t,r,e),`colors`),d=h(t,e,n);return{color:Object.fromEntries(f(t,e,o).map(n=>{let r=n.split(`.`);return[n,{light:g(t,e,o,r),dark:g(t,e,s,r)}]})),space:_(g(t,e,n,[`spacing`]),`spacing`,e),radius:_(g(t,e,n,[`radius`]),`radius`,e),shadow:Object.fromEntries(Object.entries(g(t,e,n,[`shadows`])).map(([t,n])=>[t,v(n,t,e)])),font:{sans:{family:d,fallback:i}},text:Object.fromEntries(Object.entries(_(g(t,e,n,[`typography`,`fontSize`]),`fontSize`,e)).map(([e,t])=>[e,{size:t,lineHeight:null,weight:null}]))}}function b(e){let t=a(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 o(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 x(e,t){for(let[n,r]of[[`itemsTakeAction`,`array`],[`takesAction`,`object`]])for(let[i,a]of Object.entries(t[n]??{})){let t=e.find(({name:e})=>e===i);if(!t)throw Error(`phoneStyleSupport.json ${n} names ${i}, which the kit does not have.`);for(let e of a)if(t.props.find(({name:t})=>t===e)?.type!==r)throw Error(`phoneStyleSupport.json ${n} names ${i}.${e}, which is not a prop of type ${r} in the kit.`);t[n]=o([...new Set([...t[n],...a])])}}export{n as PHONE_EXCLUDED_COMPONENTS,x as applyPhoneActions,b as phoneIcons,y as phoneTokenValues,p as phoneTokens};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/canvas-kit",
|
|
3
|
-
"version": "0.87.
|
|
3
|
+
"version": "0.87.2",
|
|
4
4
|
"description": "Builds product kits for Webority Canvas: a kit bundle, its manifest, and the spec shape the renderers answer.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"react": "^19.2.6",
|
|
26
|
-
"@webority/ui-react": "0.87.
|
|
26
|
+
"@webority/ui-react": "0.87.2"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "vite build --config vite.cli.config.js",
|