@webority/tokens 0.149.0 → 0.152.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.
Files changed (76) hide show
  1. package/dist/brand.d.ts +39 -25
  2. package/dist/brand.js +2 -2
  3. package/dist/build.d.ts +41 -0
  4. package/dist/build.js +5 -5
  5. package/dist/canvas/webority-phone.json +12 -12
  6. package/dist/canvas/webority-web-390.json +35 -3
  7. package/dist/canvas/webority-web.json +35 -3
  8. package/dist/check.d.ts +37 -0
  9. package/dist/check.js +3 -3
  10. package/dist/cli.d.ts +15 -96
  11. package/dist/cli.js +1 -1
  12. package/dist/emit/canvas.d.ts +8 -0
  13. package/dist/emit/canvas.js +1 -1
  14. package/dist/emit/email.d.ts +32 -0
  15. package/dist/emit/email.js +2 -2
  16. package/dist/emit/meanings.d.ts +3 -0
  17. package/dist/emit/phone.d.ts +26 -0
  18. package/dist/emit/phone.js +3 -3
  19. package/dist/emit/web.d.ts +18 -0
  20. package/dist/emit/web.js +14 -14
  21. package/dist/guards.d.ts +3 -0
  22. package/dist/guards.js +1 -0
  23. package/dist/index.d.ts +7 -7
  24. package/dist/meanings.json +97 -1
  25. package/dist/model/colour.d.ts +8 -0
  26. package/dist/model/colour.js +1 -1
  27. package/dist/model/contrast.d.ts +26 -0
  28. package/dist/model/contrast.js +1 -1
  29. package/dist/model/index.d.ts +52 -0
  30. package/dist/model/length.d.ts +21 -0
  31. package/dist/model/length.js +1 -1
  32. package/dist/model/load.d.ts +32 -0
  33. package/dist/model/load.js +1 -1
  34. package/dist/model/references.d.ts +3 -0
  35. package/dist/model/references.js +1 -1
  36. package/dist/model/resolve.d.ts +4 -0
  37. package/dist/model/resolve.js +2 -2
  38. package/dist/names.d.ts +1 -11
  39. package/dist/names.js +1 -1
  40. package/dist/outputs.d.ts +51 -102
  41. package/dist/present.d.ts +1 -0
  42. package/dist/present.js +1 -0
  43. package/dist/ramp.d.ts +8 -0
  44. package/dist/ramp.js +1 -1
  45. package/dist/source/meaning.tokens.json +144 -0
  46. package/dist/source/palette.tokens.json +9 -9
  47. package/dist/source/scale.tokens.json +39 -2
  48. package/dist/upgrade/classes.d.ts +13 -0
  49. package/dist/upgrade/classes.js +2 -2
  50. package/dist/upgrade/components.d.ts +19 -0
  51. package/dist/upgrade/components.js +3 -3
  52. package/dist/upgrade/css.d.ts +28 -0
  53. package/dist/upgrade/css.js +2 -2
  54. package/dist/upgrade/index.d.ts +64 -0
  55. package/dist/upgrade/index.js +2 -2
  56. package/dist/upgrade/razorAttributes.d.ts +19 -0
  57. package/dist/upgrade/razorAttributes.js +2 -2
  58. package/dist/upgrade/razorTags.d.ts +19 -0
  59. package/dist/upgrade/razorTags.js +2 -2
  60. package/dist/upgrade/razorValueSplits.d.ts +19 -0
  61. package/dist/upgrade/razorValueSplits.js +2 -2
  62. package/dist/upgrade/source.d.ts +19 -0
  63. package/dist/upgrade/source.js +3 -3
  64. package/dist/upgrade/tagScan.d.ts +7 -0
  65. package/dist/upgrade/tagScan.js +1 -1
  66. package/dist/upgrade/themeReads.d.ts +55 -0
  67. package/dist/upgrade/themeReads.js +2 -2
  68. package/dist/upgrade/valueSplits.d.ts +23 -0
  69. package/dist/upgrade/valueSplits.js +3 -3
  70. package/dist/upgrade/wrapperValues.d.ts +71 -0
  71. package/dist/upgrade/wrapperValues.js +1 -1
  72. package/dist/webority.d.ts +1 -0
  73. package/package.json +8 -3
  74. package/renames/0.130.0.json +15 -0
  75. package/renames/0.152.0.json +30 -0
  76. package/renames/renames.d.ts +1 -1
@@ -768,7 +768,7 @@
768
768
  },
769
769
  "phone-link": {
770
770
  "$type": "color",
771
- "$value": "#5B5BD6",
771
+ "$value": "#4F46E5",
772
772
  "$extensions": {
773
773
  "com.webority": {
774
774
  "platforms": ["phone"]
@@ -795,7 +795,7 @@
795
795
  },
796
796
  "phone-focus-ring": {
797
797
  "$type": "color",
798
- "$value": "#5B5BD6",
798
+ "$value": "#4F46E5",
799
799
  "$extensions": {
800
800
  "com.webority": {
801
801
  "platforms": ["phone"]
@@ -849,7 +849,7 @@
849
849
  },
850
850
  "phone-primary": {
851
851
  "$type": "color",
852
- "$value": "#5B5BD6",
852
+ "$value": "#4F46E5",
853
853
  "$extensions": {
854
854
  "com.webority": {
855
855
  "platforms": ["phone"]
@@ -858,7 +858,7 @@
858
858
  },
859
859
  "phone-primary-hover": {
860
860
  "$type": "color",
861
- "$value": "#4F4FBF",
861
+ "$value": "#4338CA",
862
862
  "$extensions": {
863
863
  "com.webority": {
864
864
  "platforms": ["phone"]
@@ -867,7 +867,7 @@
867
867
  },
868
868
  "phone-primary-soft": {
869
869
  "$type": "color",
870
- "$value": "#EEEEFC",
870
+ "$value": "#E0E7FF",
871
871
  "$extensions": {
872
872
  "com.webority": {
873
873
  "platforms": ["phone"]
@@ -876,7 +876,7 @@
876
876
  },
877
877
  "phone-primary-text": {
878
878
  "$type": "color",
879
- "$value": "#4F4FD3",
879
+ "$value": "#4F46E5",
880
880
  "$extensions": {
881
881
  "com.webority": {
882
882
  "platforms": ["phone"]
@@ -1038,7 +1038,7 @@
1038
1038
  },
1039
1039
  "phone-primary-pressed": {
1040
1040
  "$type": "color",
1041
- "$value": "#4040A8",
1041
+ "$value": "#3730A3",
1042
1042
  "$extensions": {
1043
1043
  "com.webority": {
1044
1044
  "platforms": ["phone"]
@@ -1083,7 +1083,7 @@
1083
1083
  },
1084
1084
  "phone-surface-selected": {
1085
1085
  "$type": "color",
1086
- "$value": "rgba(91, 91, 214, 0.1)",
1086
+ "$value": "rgba(79, 70, 229, 0.1)",
1087
1087
  "$extensions": {
1088
1088
  "com.webority": {
1089
1089
  "platforms": ["phone"]
@@ -1272,7 +1272,7 @@
1272
1272
  },
1273
1273
  "phone-avatar-1": {
1274
1274
  "$type": "color",
1275
- "$value": "#5B5BD6",
1275
+ "$value": "#4F46E5",
1276
1276
  "$extensions": {
1277
1277
  "com.webority": {
1278
1278
  "platforms": ["phone"]
@@ -586,6 +586,16 @@
586
586
  "platforms": ["web"]
587
587
  }
588
588
  }
589
+ },
590
+ "linear": {
591
+ "$type": "cubicBezier",
592
+ "$value": [0, 0, 1, 1],
593
+ "$description": "Constant-speed curve for spinners, marquees and scroll-linked motion.",
594
+ "$extensions": {
595
+ "com.webority": {
596
+ "platforms": ["web"]
597
+ }
598
+ }
589
599
  }
590
600
  }
591
601
  },
@@ -664,6 +674,19 @@
664
674
  }
665
675
  }
666
676
  },
677
+ "touch-target": {
678
+ "$type": "dimension",
679
+ "$value": {
680
+ "value": 44,
681
+ "unit": "px"
682
+ },
683
+ "$description": "Smallest tap area of a button on a touch screen; small, text and icon-only buttons grow to it.",
684
+ "$extensions": {
685
+ "com.webority": {
686
+ "platforms": ["web"]
687
+ }
688
+ }
689
+ },
667
690
  "container-max": {
668
691
  "$type": "dimension",
669
692
  "$value": {
@@ -683,16 +706,30 @@
683
706
  "value": 88,
684
707
  "unit": "px"
685
708
  },
686
- "$description": "Side padding of the page container at desktop width.",
709
+ "$description": "Side padding of the page container: 24px on a phone, 64px from 768px, 88px from 1200px.",
687
710
  "$extensions": {
688
711
  "com.webority": {
689
712
  "platforms": ["web"],
690
713
  "breakpoints": {
691
- "md": "{space.4xl}"
714
+ "md": "{space.4xl}",
715
+ "xl": "{size.container-pad-xl}"
692
716
  }
693
717
  }
694
718
  }
695
719
  },
720
+ "container-pad-xl": {
721
+ "$type": "dimension",
722
+ "$value": {
723
+ "value": 88,
724
+ "unit": "px"
725
+ },
726
+ "$description": "Side padding the page container takes from 1200px; no space step is 88px.",
727
+ "$extensions": {
728
+ "com.webority": {
729
+ "platforms": ["web"]
730
+ }
731
+ }
732
+ },
696
733
  "table-pad": {
697
734
  "$type": "dimension",
698
735
  "$value": {
@@ -0,0 +1,13 @@
1
+ import type { ClassRename } from "../../renames/renames.d.ts";
2
+ export type ClassHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type ClassResult = {
8
+ text: string;
9
+ hits: ClassHit[];
10
+ findings: never[];
11
+ };
12
+ /** @param file repo-relative, forward slashes */
13
+ export declare function applyClasses(source: string, file: string, rules: ClassRename[]): ClassResult;
@@ -1,2 +1,2 @@
1
- var e=new Set([`.css`,`.scss`,`.sass`,`.less`]),t=new Set([`.cshtml`,`.razor`,`.html`]),n=new Set([`.js`,`.jsx`,`.ts`,`.tsx`,`.mjs`,`.cjs`,`.mts`,`.cts`]),r=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},a=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
- `&&t.push(n+1);return t},o=(e,t)=>{let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n+1},s=(e,t)=>e<t?-1:+(e>t);function c(c,l,u){let d=i(l),f=e.has(d)?`selector`:t.has(d)?`attribute`:n.has(d)?`literal`:void 0;if(u.length===0||f===void 0)return{text:c,hits:[],findings:[]};let p=new Map(u),m=[...p.keys()].sort((e,t)=>t.length-e.length).map(r).join(`|`),h=RegExp(`(?<![\\w-])(${m})(?![\\w-])`,`g`),g=a(c),_=[],v=(e,t)=>e.replace(h,(e,n,r)=>{let i=p.get(e);return _.push({line:o(g,t+r),from:e,to:i}),i}),y=c;return y=f===`selector`?c.replace(RegExp(`\\.(${m})(?![\\w-])`,`g`),(e,t,n)=>{let r=p.get(t);return _.push({line:o(g,n),from:`.${t}`,to:`.${r}`}),`.${r}`}):f===`attribute`?c.replace(/(?<=\s)class\s*=\s*(["'])([^"'\n]*)\1/g,(e,t,n,r)=>{let i=v(n,r+e.length-1-n.length);return`${e.slice(0,e.length-1-n.length)}${i}${t}`}):c.replace(/(["'`])([^"'`\n]*)\1/g,(e,t,n,r)=>`${t}${v(n,r+1)}${t}`),_.sort((e,t)=>e.line-t.line||s(e.from,t.from)),{text:y,hits:_,findings:[]}}export{c as applyClasses};
1
+ import{present as e}from"../present.js";var t=new Set([`.css`,`.scss`,`.sass`,`.less`]),n=new Set([`.cshtml`,`.razor`,`.html`]),r=new Set([`.js`,`.jsx`,`.ts`,`.tsx`,`.mjs`,`.cjs`,`.mts`,`.cts`]),i=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},o=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
+ `&&t.push(n+1);return t},s=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`the line start offset`)<=n?r=a:i=a-1}return r+1},c=(e,t)=>e<t?-1:+(e>t);function l(l,u,d){let f=a(u),p=t.has(f)?`selector`:n.has(f)?`attribute`:r.has(f)?`literal`:void 0;if(d.length===0||p===void 0)return{text:l,hits:[],findings:[]};let m=new Map(d),h=[...m.keys()].sort((e,t)=>t.length-e.length).map(i).join(`|`),g=RegExp(`(?<![\\w-])(${h})(?![\\w-])`,`g`),_=o(l),v=[],y=(t,n)=>t.replace(g,(t,r,i)=>{let a=e(m.get(t),`the rename for the class ${t}`);return v.push({line:s(_,n+i),from:t,to:a}),a}),b=l;return b=p===`selector`?l.replace(RegExp(`\\.(${h})(?![\\w-])`,`g`),(e,t,n)=>{let r=m.get(t);return v.push({line:s(_,n),from:`.${t}`,to:`.${r}`}),`.${r}`}):p===`attribute`?l.replace(/(?<=\s)class\s*=\s*(["'])([^"'\n]*)\1/g,(e,t,n,r)=>{let i=y(n,r+e.length-1-n.length);return`${e.slice(0,e.length-1-n.length)}${i}${t}`}):l.replace(/(["'`])([^"'`\n]*)\1/g,(e,t,n,r)=>`${t}${y(n,r+1)}${t}`),v.sort((e,t)=>e.line-t.line||c(e.from,t.from)),{text:b,hits:v,findings:[]}}export{l as applyClasses};
@@ -0,0 +1,19 @@
1
+ import type { ComponentRule } from "../../renames/renames.d.ts";
2
+ export type ComponentHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type ComponentFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type ComponentResult = {
14
+ text: string;
15
+ hits: ComponentHit[];
16
+ findings: ComponentFinding[];
17
+ };
18
+ /** @param file repo-relative, forward slashes */
19
+ export declare function applyComponents(source: string, file: string, rules: ComponentRule[]): ComponentResult;
@@ -1,3 +1,3 @@
1
- var e=new Set([`.js`,`.jsx`,`.ts`,`.tsx`]),t=`[A-Za-z_$][\\w$]*`,n=RegExp(`^(type\\s+)?(${t})(?:\\s+as\\s+(${t}))?$`),r=/[A-Za-z_$][\w$:.-]*/y,i=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},o=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
- `&&t.push(n+1);return t},s=(e,t)=>{let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n+1},c=(e,t)=>e<t?-1:+(e>t),l=e=>`${e.typeKw}${e.name}${e.alias===void 0?``:` as ${e.alias}`}`;function u(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``).map(e=>{let t=n.exec(e);if(t===null)throw Error(`cannot read the import specifier "${e}"`);return{typeKw:t[1]===void 0?``:`type `,name:t[2],alias:t[3]}})}function d(e,n){let r=RegExp(`\\bimport\\s+(type\\s+)?(?:(${t})\\s*,\\s*)?\\{([^{}]*)\\}\\s*from\\s*(["'])${i(n)}\\4(;?)`,`g`);return[...e.matchAll(r)].map(e=>({start:e.index,end:e.index+e[0].length,typeKw:e[1]===void 0?``:`type `,defaultName:e[2],specs:u(e[3]),quote:e[4],semi:e[5],pkg:n}))}function f(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`)n--;else if(t===`>`&&n===0)return i}return-1}function p(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return i+1}throw Error(`unbalanced braces in a JSX attribute`)}function m(e,t,n){let i=[],a=t;for(;a<n;){let t=e[a];if(/\s/.test(t)){a++;continue}if(t===`{`){a=p(e,a);continue}r.lastIndex=a;let n=r.exec(e);if(n===null)break;let o=a,s=a+n[0].length,c=s;for(;/\s/.test(e[c]??``);)c++;if(e[c]!==`=`){i.push({name:n[0],nameStart:o,nameEnd:s,kind:`none`}),a=s;continue}for(c++;/\s/.test(e[c]??``);)c++;let l=e[c];if(l===`"`||l===`'`){let t=e.indexOf(l,c+1);if(t===-1)throw Error(`unterminated value of JSX attribute "${n[0]}"`);i.push({name:n[0],nameStart:o,nameEnd:s,kind:`quoted`,innerStart:c+1,innerEnd:t,inner:e.slice(c+1,t)}),a=t+1}else if(l===`{`){let t=p(e,c);i.push({name:n[0],nameStart:o,nameEnd:s,kind:`braced`,innerStart:c+1,innerEnd:t-1,inner:e.slice(c+1,t-1)}),a=t}else throw Error(`cannot read the value of JSX attribute "${n[0]}"`)}return i}function h(e){if(e.kind===`quoted`)return{start:e.innerStart,end:e.innerEnd,value:e.inner};if(e.kind===`braced`){let t=/^(\s*)(["'])([^"'\n]*)\2\s*$/.exec(e.inner);if(t!==null){let n=e.innerStart+t[1].length+1;return{start:n,end:n+t[3].length,value:t[3]}}}}function g(e,t){let n=[],r=`<${t}`;for(let t=e.indexOf(r);t!==-1;t=e.indexOf(r,t+1)){let i=t+r.length;/[\s/>]/.test(e[i]??``)&&n.push({nameEnd:i,end:f(e,i)})}return n}function _(e,t,n){let r=d(e,n.package),a=r.flatMap(e=>e.specs.filter(e=>e.name===n.from).map(t=>({st:e,spec:t})))[0];if(a===void 0)return{text:e,hits:[],findings:[]};let{st:c,spec:u}=a,f=u.alias??n.from,p=u.alias??n.to,_=p!==f,v=n.from!==n.to&&u.alias===void 0&&r.some(e=>e.specs.some(e=>e!==u&&e.name===n.to&&e.alias===void 0)),y=o(e),b=[],x=[],S=[],C=g(e,f),w=C.filter(e=>e.end===-1);if(w.length>0){for(let{nameEnd:e}of w)S.push({file:t,line:s(y,e),path:`<${f}>`,message:`the element could not be read (a quote or brace does not pair up); rename it by hand`});return{text:e,hits:[],findings:S}}if(n.from!==n.to){let t=v?c.specs.filter(e=>e!==u):c.specs.map(e=>e===u?{...e,name:n.to}:e),r=[];if(c.defaultName!==void 0&&r.push(c.defaultName),t.length>0&&r.push(`{ ${t.map(l).join(`, `)} }`),r.length===0){let t=e[c.end]===`
3
- `?c.end+1:c.end;b.push({start:c.start,end:t,text:``})}else b.push({start:c.start,end:c.end,text:`import ${c.typeKw}${r.join(`, `)} from ${c.quote}${c.pkg}${c.quote}${c.semi}`});x.push({line:s(y,c.start),from:n.from,to:n.to})}let T=e=>Object.hasOwn(n.renameProps,e)?n.renameProps[e]:e;for(let{nameEnd:r,end:i}of C){let a=s(y,r),o=m(e,r,i);for(let e of o){let t=T(e.name);t!==e.name&&(b.push({start:e.nameStart,end:e.nameEnd,text:t}),x.push({line:s(y,e.nameStart),from:e.name,to:t}))}let c=o.map(e=>T(e.name));for(let e of o){let t=T(e.name);if(!Object.hasOwn(n.valueMaps,t))continue;let r=h(e);if(r!==void 0&&Object.hasOwn(n.valueMaps[t],r.value)){let e=n.valueMaps[t][r.value];b.push({start:r.start,end:r.end,text:e}),x.push({line:s(y,r.start),from:`${t}="${r.value}"`,to:`${t}="${e}"`})}}let l=Object.entries(n.addProps).filter(([e])=>!c.includes(e)).map(([e,t])=>` ${e}=${typeof t==`string`?`"${t}"`:`{${t}}`}`);l.length>0&&b.push({start:r,end:r,text:l.join(``)}),(_||l.length>0)&&x.push({line:a,from:`<${f}`,to:`<${p}${l.join(``)}`}),_&&b.push({start:r-f.length,end:r,text:p});for(let[e,r]of Object.entries(n.removeProps))o.some(t=>t.name===e)&&S.push({file:t,line:a,path:`<${n.from}> ${e}`,message:r})}if(_)for(let t of e.matchAll(RegExp(`</${i(f)}(?=\\s*>)`,`g`))){let e=t.index+2;b.push({start:e,end:e+f.length,text:p}),x.push({line:s(y,e),from:`</${f}`,to:`</${p}`})}b.sort((e,t)=>t.start-e.start||t.end-e.end);let E=e;for(let e of b)E=E.slice(0,e.start)+e.text+E.slice(e.end);return{text:E,hits:x,findings:S}}function v(t,n,r){if(r.length===0||!e.has(a(n)))return{text:t,hits:[],findings:[]};let i=t,o=[],s=[];for(let e of r){let t=_(i,n,e);i=t.text,o.push(...t.hits),s.push(...t.findings)}return o.sort((e,t)=>e.line-t.line||c(e.from,t.from)),s.sort((e,t)=>e.line-t.line||c(e.path,t.path)),{text:i,hits:o,findings:s}}export{v as applyComponents};
1
+ import{present as e}from"../present.js";var t=new Set([`.js`,`.jsx`,`.ts`,`.tsx`]),n=`[A-Za-z_$][\\w$]*`,r=RegExp(`^(type\\s+)?(${n})(?:\\s+as\\s+(${n}))?$`),i=/[A-Za-z_$][\w$:.-]*/y,a=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
+ `&&t.push(n+1);return t},c=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`the line start offset`)<=n?r=a:i=a-1}return r+1},l=(e,t)=>e<t?-1:+(e>t),u=e=>`${e.typeKw}${e.name}${e.alias===void 0?``:` as ${e.alias}`}`;function d(t){return t.split(`,`).map(e=>e.trim()).filter(e=>e!==``).map(t=>{let n=r.exec(t);if(n===null)throw Error(`cannot read the import specifier "${t}"`);return{typeKw:n[1]===void 0?``:`type `,name:e(n[2],`the import specifier name`),alias:n[3]}})}function f(t,r){let i=RegExp(`\\bimport\\s+(type\\s+)?(?:(${n})\\s*,\\s*)?\\{([^{}]*)\\}\\s*from\\s*(["'])${a(r)}\\4(;?)`,`g`);return[...t.matchAll(i)].map(t=>({start:t.index,end:t.index+t[0].length,typeKw:t[1]===void 0?``:`type `,defaultName:t[2],specs:d(e(t[3],`the import specifier list`)),quote:e(t[4],`the import quote`),semi:e(t[5],`the import semicolon`),pkg:r}))}function p(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`)n--;else if(t===`>`&&n===0)return i}return-1}function m(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r)t===`\\`?i++:t===r&&(r=``);else if(t===`"`||t===`'`||t==="`")r=t;else if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return i+1}throw Error(`unbalanced braces in a JSX attribute`)}function h(t,n,r){let a=[],o=n;for(;o<r;){let n=e(t[o],`the JSX attribute character`);if(/\s/.test(n)){o++;continue}if(n===`{`){o=m(t,o);continue}i.lastIndex=o;let r=i.exec(t);if(r===null)break;let s=o,c=o+r[0].length,l=c;for(;/\s/.test(t[l]??``);)l++;if(t[l]!==`=`){a.push({name:r[0],nameStart:s,nameEnd:c,kind:`none`}),o=c;continue}for(l++;/\s/.test(t[l]??``);)l++;let u=t[l];if(u===`"`||u===`'`){let e=t.indexOf(u,l+1);if(e===-1)throw Error(`unterminated value of JSX attribute "${r[0]}"`);a.push({name:r[0],nameStart:s,nameEnd:c,kind:`quoted`,innerStart:l+1,innerEnd:e,inner:t.slice(l+1,e)}),o=e+1}else if(u===`{`){let e=m(t,l);a.push({name:r[0],nameStart:s,nameEnd:c,kind:`braced`,innerStart:l+1,innerEnd:e-1,inner:t.slice(l+1,e-1)}),o=e}else throw Error(`cannot read the value of JSX attribute "${r[0]}"`)}return a}function g(t){if(t.kind===`quoted`)return{start:t.innerStart,end:t.innerEnd,value:t.inner};if(t.kind===`braced`){let n=/^(\s*)(["'])([^"'\n]*)\2\s*$/.exec(t.inner);if(n!==null){let r=e(n[1],`the leading space of a JSX attribute value`),i=e(n[3],`the text of a JSX attribute value`),a=t.innerStart+r.length+1;return{start:a,end:a+i.length,value:i}}}}function _(e,t){let n=[],r=`<${t}`;for(let t=e.indexOf(r);t!==-1;t=e.indexOf(r,t+1)){let i=t+r.length;/[\s/>]/.test(e[i]??``)&&n.push({nameEnd:i,end:p(e,i)})}return n}function v(t,n,r){let i=f(t,r.package),o=i.flatMap(e=>e.specs.filter(e=>e.name===r.from).map(t=>({st:e,spec:t})))[0];if(o===void 0)return{text:t,hits:[],findings:[]};let{st:l,spec:d}=o,p=d.alias??r.from,m=d.alias??r.to,v=m!==p,y=r.from!==r.to&&d.alias===void 0&&i.some(e=>e.specs.some(e=>e!==d&&e.name===r.to&&e.alias===void 0)),b=s(t),x=[],S=[],C=[],w=_(t,p),T=w.filter(e=>e.end===-1);if(T.length>0){for(let{nameEnd:e}of T)C.push({file:n,line:c(b,e),path:`<${p}>`,message:`the element could not be read (a quote or brace does not pair up); rename it by hand`});return{text:t,hits:[],findings:C}}if(r.from!==r.to){let e=y?l.specs.filter(e=>e!==d):l.specs.map(e=>e===d?{...e,name:r.to}:e),n=[];if(l.defaultName!==void 0&&n.push(l.defaultName),e.length>0&&n.push(`{ ${e.map(u).join(`, `)} }`),n.length===0){let e=t[l.end]===`
3
+ `?l.end+1:l.end;x.push({start:l.start,end:e,text:``})}else x.push({start:l.start,end:l.end,text:`import ${l.typeKw}${n.join(`, `)} from ${l.quote}${l.pkg}${l.quote}${l.semi}`});S.push({line:c(b,l.start),from:r.from,to:r.to})}let E=t=>Object.hasOwn(r.renameProps,t)?e(r.renameProps[t],`the new name of prop ${t}`):t;for(let{nameEnd:i,end:a}of w){let o=c(b,i),s=h(t,i,a);for(let e of s){let t=E(e.name);t!==e.name&&(x.push({start:e.nameStart,end:e.nameEnd,text:t}),S.push({line:c(b,e.nameStart),from:e.name,to:t}))}let l=s.map(e=>E(e.name));for(let t of s){let n=E(t.name),i=Object.hasOwn(r.valueMaps,n)?r.valueMaps[n]:void 0;if(i===void 0)continue;let a=g(t);if(a!==void 0&&Object.hasOwn(i,a.value)){let t=e(i[a.value],`the value that ${n}="${a.value}" maps to`);x.push({start:a.start,end:a.end,text:t}),S.push({line:c(b,a.start),from:`${n}="${a.value}"`,to:`${n}="${t}"`})}}let u=Object.entries(r.addProps).filter(([e])=>!l.includes(e)).map(([e,t])=>` ${e}=${typeof t==`string`?`"${t}"`:`{${t}}`}`);u.length>0&&x.push({start:i,end:i,text:u.join(``)}),(v||u.length>0)&&S.push({line:o,from:`<${p}`,to:`<${m}${u.join(``)}`}),v&&x.push({start:i-p.length,end:i,text:m});for(let[e,t]of Object.entries(r.removeProps))s.some(t=>t.name===e)&&C.push({file:n,line:o,path:`<${r.from}> ${e}`,message:t})}if(v)for(let e of t.matchAll(RegExp(`</${a(p)}(?=\\s*>)`,`g`))){let t=e.index+2;x.push({start:t,end:t+p.length,text:m}),S.push({line:c(b,t),from:`</${p}`,to:`</${m}`})}x.sort((e,t)=>t.start-e.start||t.end-e.end);let D=t;for(let e of x)D=D.slice(0,e.start)+e.text+D.slice(e.end);return{text:D,hits:S,findings:C}}function y(e,n,r){if(r.length===0||!t.has(o(n)))return{text:e,hits:[],findings:[]};let i=e,a=[],s=[];for(let e of r){let t=v(i,n,e);i=t.text,a.push(...t.hits),s.push(...t.findings)}return a.sort((e,t)=>e.line-t.line||l(e.from,t.from)),s.sort((e,t)=>e.line-t.line||l(e.path,t.path)),{text:i,hits:a,findings:s}}export{y as applyComponents};
@@ -0,0 +1,28 @@
1
+ import type { RenameTable } from "../../renames/renames.d.ts";
2
+ export type CssHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type CssChoose = {
8
+ line: number;
9
+ name: string;
10
+ hint: string;
11
+ };
12
+ export type CssResult = {
13
+ text: string;
14
+ hits: CssHit[];
15
+ choose: CssChoose[];
16
+ checkRole: CssHit[];
17
+ };
18
+ export declare const CSS_TARGET_EXTENSIONS: Set<string>;
19
+ /** @param relPath repo-relative path, forward or back slashes */
20
+ export declare function isCssTarget(relPath: string): boolean;
21
+ /**
22
+ * The table's ownable names that this text declares (`--radius: 4px`).
23
+ */
24
+ export declare function ownDeclarations(text: string, fileName: string, table: RenameTable): Set<string>;
25
+ /**
26
+ * @param ownDeclared ownable names the product declares in any file: each stays as written and its declarations are reported
27
+ */
28
+ export declare function applyCssTable(text: string, fileName: string, table: RenameTable, ownDeclared?: Set<string>): CssResult;
@@ -1,2 +1,2 @@
1
- var e=new Set([`.css`,`.scss`,`.sass`,`.less`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.ts`,`.tsx`,`.mts`,`.cts`,`.cshtml`,`.razor`,`.html`,`.vue`,`.json`]),t=new Set([`node_modules`,`dist`,`bin`,`obj`,`.git`,`.next`,`coverage`]);function n(e,t,n){for(let r=0;r+1<e.length;r++)if(e[r]===t&&e[r+1]===n)return!0;return!1}function r(r){let i=r.replace(/\\/g,`/`).split(`/`);if(i.some(e=>t.has(e))||n(i,`wwwroot`,`lib`))return!1;let a=i[i.length-1].match(/\.[^.]+$/),o=a?a[0].toLowerCase():``;return o===`.css`&&n(i,`wwwroot`,`css`)?!1:e.has(o)}var i=/^\s*:/;function a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function o(e){return[...e].sort((e,t)=>t.length-e.length).map(a).join(`|`)}function s(e,t,n){let i=n.css.ownable??[];if(i.length===0||!r(t))return new Set;let a=RegExp(`(?<![\\w-])(${o(i)})\\s*:`,`g`);return new Set(Array.from(e.matchAll(a),e=>e[1]))}function c(e,t,n,a=new Set){if(!r(t))return{text:e,hits:[],choose:[],checkRole:[]};let{rename:s,reads:c,choose:l,checkRole:u}=n.css,d=new Map;for(let[e,t]of c)d.set(e,t);for(let[e,t]of s)d.set(e,t);let f=new Set(c.map(([e])=>e)),p=new Set([...s.map(([e])=>e),...Object.keys(l)]),m=[];if(f.size>0&&m.push(`(?<=var\\(\\s*)(${o(f)})(?![\\w-])`),p.size>0&&m.push(`(?<![\\w-])(${o(p)})(?![\\w-])`),m.length===0)return{text:e,hits:[],choose:[],checkRole:[]};let h=new RegExp(m.join(`|`),`g`),g=new Set(u),_=new Set(n.css.ownable??[]),v=[],y=[],b=[],x=1,S=0;return{text:e.replace(h,(t,...n)=>{let r=n[n.length-2];for(;S<r;S++)e[S]===`
2
- `&&x++;if(Object.hasOwn(l,t))return y.push({line:x,name:t,hint:l[t]}),t;let o=d.get(t);return _.has(t)&&a.has(t)?(i.test(e.slice(r+t.length))&&y.push({line:x,name:t,hint:`The product declares its own ${t}, so it and its reads were left as written. If it overrides the library token, rename it to ${o} by hand.`}),t):(v.push({line:x,from:t,to:o}),g.has(o)&&b.push({line:x,from:t,to:o}),o)}),hits:v,choose:y,checkRole:b}}export{e as CSS_TARGET_EXTENSIONS,c as applyCssTable,r as isCssTarget,s as ownDeclarations};
1
+ import{present as e}from"../present.js";var t=new Set([`.css`,`.scss`,`.sass`,`.less`,`.js`,`.jsx`,`.mjs`,`.cjs`,`.ts`,`.tsx`,`.mts`,`.cts`,`.cshtml`,`.razor`,`.html`,`.vue`,`.json`]),n=new Set([`node_modules`,`dist`,`bin`,`obj`,`.git`,`.next`,`coverage`]);function r(e,t,n){for(let r=0;r+1<e.length;r++)if(e[r]===t&&e[r+1]===n)return!0;return!1}function i(i){let a=i.replace(/\\/g,`/`).split(`/`);if(a.some(e=>n.has(e))||r(a,`wwwroot`,`lib`))return!1;let o=e(a[a.length-1],`file name of the path`).match(/\.[^.]+$/),s=o?o[0].toLowerCase():``;return s===`.css`&&r(a,`wwwroot`,`css`)?!1:t.has(s)}var a=/^\s*:/;function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function s(e){return[...e].sort((e,t)=>t.length-e.length).map(o).join(`|`)}function c(t,n,r){let a=r.css.ownable??[];if(a.length===0||!i(n))return new Set;let o=RegExp(`(?<![\\w-])(${s(a)})\\s*:`,`g`);return new Set(Array.from(t.matchAll(o),t=>e(t[1],`ownable name in a declaration`)))}function l(t,n,r,o=new Set){if(!i(n))return{text:t,hits:[],choose:[],checkRole:[]};let{rename:c,reads:l,choose:u,checkRole:d}=r.css,f=new Map;for(let[e,t]of l)f.set(e,t);for(let[e,t]of c)f.set(e,t);let p=new Set(l.map(([e])=>e)),m=new Set([...c.map(([e])=>e),...Object.keys(u)]),h=[];if(p.size>0&&h.push(`(?<=var\\(\\s*)(${s(p)})(?![\\w-])`),m.size>0&&h.push(`(?<![\\w-])(${s(m)})(?![\\w-])`),h.length===0)return{text:t,hits:[],choose:[],checkRole:[]};let g=new RegExp(h.join(`|`),`g`),_=new Set(d),v=new Set(r.css.ownable??[]),y=[],b=[],x=[],S=1,C=0;return{text:t.replace(g,(n,...r)=>{let i=e(r[r.length-2],`match offset`);if(typeof i!=`number`)throw Error(`webority-tokens: match offset is missing.`);for(;C<i;C++)t[C]===`
2
+ `&&S++;if(Object.hasOwn(u,n))return b.push({line:S,name:n,hint:e(u[n],`the choose hint for ${n}`)}),n;let s=e(f.get(n),`the rename target of ${n}`);return v.has(n)&&o.has(n)?(a.test(t.slice(i+n.length))&&b.push({line:S,name:n,hint:`The product declares its own ${n}, so it and its reads were left as written. If it overrides the library token, rename it to ${s} by hand.`}),n):(y.push({line:S,from:n,to:s}),_.has(s)&&x.push({line:S,from:n,to:s}),s)}),hits:y,choose:b,checkRole:x}}export{t as CSS_TARGET_EXTENSIONS,l as applyCssTable,i as isCssTarget,c as ownDeclarations};
@@ -0,0 +1,64 @@
1
+ /** The options `upgrade` takes; the command line passes the same shape. */
2
+ export interface UpgradeOptions {
3
+ version: string;
4
+ dryRun?: boolean;
5
+ /** An app folder inside the repo, relative to root. */
6
+ app?: string;
7
+ paths?: string[];
8
+ /** Wrapper package name to the library package its rules name: `{ "@acme/ui": "@webority/ui-react" }`. */
9
+ aliases?: Record<string, string>;
10
+ /** Path of a JSON file for the command line to write the UpgradeResult to; upgrade() ignores it. */
11
+ report?: string;
12
+ /** Defaults to process.cwd(). */
13
+ root?: string;
14
+ }
15
+ /** One rewrite upgrade made, or would make on a dry run. */
16
+ export interface UpgradeHit {
17
+ file: string;
18
+ line: number;
19
+ from: string;
20
+ to: string;
21
+ }
22
+ /** A use upgrade cannot rewrite on its own; a person picks the new name. */
23
+ export interface UpgradeChoice {
24
+ file: string;
25
+ line: number;
26
+ name: string;
27
+ hint: string;
28
+ }
29
+ export interface UpgradeResult {
30
+ hits: UpgradeHit[];
31
+ choose: UpgradeChoice[];
32
+ changedFiles: string[];
33
+ }
34
+ type Log = (line: string) => void;
35
+ type RunResult = {
36
+ status: number | null;
37
+ };
38
+ type CommandRunner = (cmd: string, args: string[], opts: {
39
+ cwd: string;
40
+ }) => RunResult | Promise<RunResult>;
41
+ type ReenterArgs = {
42
+ appRoot: string;
43
+ designRoot: string;
44
+ app: string | undefined;
45
+ version: string;
46
+ dryRun: boolean;
47
+ from: string;
48
+ aliases: Record<string, string>;
49
+ };
50
+ export interface UpgradeDeps {
51
+ run?: CommandRunner;
52
+ reenter?: (arg: ReenterArgs) => Promise<UpgradeResult>;
53
+ brand?: (arg: {
54
+ root: string;
55
+ }) => Promise<unknown>;
56
+ log?: Log;
57
+ renamesDir?: string;
58
+ ownVersion?: () => string;
59
+ }
60
+ /**
61
+ * @param deps test seams: the install runner, the second stage, the brand step, the log sink, the renames folder and the tool's own version.
62
+ */
63
+ export declare function upgrade(options: UpgradeOptions, deps?: UpgradeDeps): Promise<UpgradeResult>;
64
+ export {};
@@ -1,5 +1,5 @@
1
- import{brand as e}from"../build.js";import{applyClasses as t}from"./classes.js";import{applyComponents as n}from"./components.js";import{applyCssTable as r,isCssTarget as i,ownDeclarations as a}from"./css.js";import{applyRazorAttributes as o}from"./razorAttributes.js";import{applyRazorTags as s}from"./razorTags.js";import{applyRazorValueSplits as c}from"./razorValueSplits.js";import{applyMarkup as l,applySource as u}from"./source.js";import{applyComponentProps as d,applyPropSplits as f,applyPropValues as p,applyProps as m,applyThemeReads as h}from"./themeReads.js";import{applyValueSplits as g}from"./valueSplits.js";import{applyWrapperValues as _,findWrappers as v}from"./wrapperValues.js";import{createRequire as y}from"node:module";import{existsSync as b,readFileSync as x,readdirSync as S,realpathSync as C,writeFileSync as w}from"node:fs";import{dirname as T,isAbsolute as E,join as D,relative as O,resolve as k,sep as A}from"node:path";import{fileURLToPath as j,pathToFileURL as M}from"node:url";import{spawnSync as N}from"node:child_process";var P=/^\d+\.\d+\.\d+$/,F=/^(?:workspace:|file:|link:)/,I=`WEBORITY_UPGRADE_FROM`;function L(e){if(typeof e!=`string`||!P.test(e))throw Error(`invalid version "${e}"`)}function R(e,t){L(e),L(t);let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function z(){let e=T(j(import.meta.url));for(;;){let t=D(e,`package.json`);if(b(t)&&JSON.parse(x(t,`utf8`)).name===`@webority/tokens`)return e;let n=T(e);if(n===e)throw Error(`cannot find the @webority/tokens package folder`);e=n}}function B(){return JSON.parse(x(D(z(),`package.json`),`utf8`)).version}function V(e){let t=[];for(let n of S(e)){if(!n.endsWith(`.json`))continue;let r=n.slice(0,-5);P.test(r)&&t.push({version:r,table:JSON.parse(x(D(e,n),`utf8`))})}return t.sort((e,t)=>R(e.version,t.version))}function H(e,t){let n=N(`git`,[`ls-files`,`-z`,`--`,...t],{cwd:e,encoding:`utf8`,windowsHide:!0,maxBuffer:67108864});if(n.status!==0)throw Error(`not a git repository: ${e}`);let r=n.stdout.split(`\0`).filter(Boolean).map(e=>e.split(`\\`).join(`/`)).filter(t=>b(D(e,t)));return[...new Set(r)]}function U(e,t){let n=H(e,t??[`.`]);if(t!==void 0&&n.length===0)throw Error(`no tracked files under ${t.join(`, `)}`);return n}function W(e){return e.split(`/`).includes(`node_modules`)}var G=new Set([`node_modules`,`vendor`,`vendors`,`external`]),K=/\.(?:min|bundle)\.(?:js|css)$/,q=new Set([`lib`,`theme`]);function J(e){let t=e.split(`/`);return t.some(e=>G.has(e))||t.some((e,n)=>e===`wwwroot`&&q.has(t[n+1]))?!0:K.test(e)}function Y(e,t){return[...new Set([...e,...t])]}function X(e,t,n){return V(e).filter(e=>R(e.version,t)>0&&R(e.version,n)<=0).map(e=>e.table)}function Z(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=(e,t)=>e.flatMap(e=>[e,...n.filter(([,n])=>e[t]===n).map(([n])=>({...e,[t]:n}))]),i={...e};for(let t of[`props`,`componentProps`,`propValues`,`propSplits`,`valueSplits`,`components`])e[t]!==void 0&&(i[t]=r(e[t],`package`));return e.source!==void 0&&(i.source={...e.source,flags:r(e.source.flags,`importedFrom`)}),i}function Q(e,y,b,S,C,T={}){S&&C(`dry run: nothing written`);let E=b.map(e=>Z(e,T)),O=[],k=[],A=[],j=y.filter(e=>i(e)&&!J(e)),M=E.map(()=>new Set);if(E.some(e=>(e.css.ownable??[]).length>0))for(let t of j){let n=x(D(e,t),`utf8`);E.forEach((e,r)=>{for(let i of a(n,t,e))M[r].add(i)})}let N=H(e,[`package.json`,`:(glob)**/package.json`]).filter(e=>!W(e)),P=new Map,F=E.map(t=>v(e,[...j,...N],t,P));for(let i of j){let a=x(D(e,i),`utf8`),v=a,y=e=>{for(let t of e)t.from!==t.to&&(O.push({file:i,line:t.line,from:t.from,to:t.to}),C(`${i}:${t.line} ${t.from} -> ${t.to}`))},b=e=>{k.push({file:i,line:e.line,name:e.name,hint:e.hint}),C(`choose ${i}:${e.line} ${e.name}: ${e.hint}`)},T=e=>{for(let t of e)t.message.startsWith(`skipped, it does not parse`)?C(`skipped ${i}: ${t.message}`):b({line:t.line,name:t.path,hint:t.message})};for(let[e,a]of E.entries()){let x=r(v,i,a,M[e]);v=x.text,y(x.hits);for(let e of x.choose)b(e);for(let e of x.checkRole)C(`verify ${i}:${e.line} ${e.from} -> ${e.to}`);let S=h(v,i,a.themeReads);v=S.text,y(S.hits),T(S.findings);let w=[t=>_(t,i,F[e]),e=>m(e,i,a.props),e=>d(e,i,a.componentProps),e=>p(e,i,a.propValues),e=>g(e,i,a.valueSplits??[]),e=>f(e,i,a.propSplits),e=>o(e,i,a.razorAttributes),e=>n(e,i,a.components??[]),e=>s(e,i,a.razorTags??[]),e=>c(e,i,a.razorValueSplits??[]),e=>t(e,i,a.classes??[]),e=>l(e,i,a.markup),e=>u(e,i,a.source)];for(let e of w){let t=e(v);v=t.text,y(t.hits),T(t.findings)}}v!==a&&(A.push(i),S||w(D(e,i),v,`utf8`))}return{hits:O,choose:k,changedFiles:A}}function $(e){let t=/^([ \t]+)\S/m.exec(e);return t?t[1]:4}function ee(e,t,n,r,i){let a=[];for(let o of H(e,[`package.json`,`:(glob)**/package.json`])){if(W(o))continue;let s=x(D(e,o),`utf8`),c=JSON.parse(s),l=!1;for(let e of[`dependencies`,`devDependencies`]){let r=c[e];if(r)for(let e of n.npm){if(!Object.hasOwn(r,e))continue;let n=r[e];F.test(n)||n===t||(r[e]=t,l=!0,i(`pin ${o}: ${e} ${n} -> ${t}`))}}if(l&&(a.push(o),r)){let t=JSON.stringify(c,null,$(s));s.endsWith(`
1
+ import{brand as e}from"../build.js";import{present as t}from"../present.js";import{applyClasses as n}from"./classes.js";import{applyComponents as r}from"./components.js";import{applyCssTable as i,isCssTarget as a,ownDeclarations as o}from"./css.js";import{applyRazorAttributes as s}from"./razorAttributes.js";import{applyRazorTags as c}from"./razorTags.js";import{applyRazorValueSplits as l}from"./razorValueSplits.js";import{applyMarkup as u,applySource as d}from"./source.js";import{applyComponentProps as f,applyPropSplits as p,applyPropValues as m,applyProps as h,applyThemeReads as g}from"./themeReads.js";import{applyValueSplits as _}from"./valueSplits.js";import{applyWrapperValues as v,findWrappers as y}from"./wrapperValues.js";import{createRequire as b}from"node:module";import{existsSync as x,readFileSync as S,readdirSync as C,realpathSync as w,writeFileSync as T}from"node:fs";import{dirname as E,isAbsolute as D,join as O,relative as k,resolve as A,sep as j}from"node:path";import{fileURLToPath as M,pathToFileURL as N}from"node:url";import{spawnSync as P}from"node:child_process";var F=/^\d+\.\d+\.\d+$/,I=/^(?:workspace:|file:|link:)/,L=`WEBORITY_UPGRADE_FROM`;function R(e){if(typeof e!=`string`||!F.test(e))throw Error(`invalid version "${e}"`)}function z(e,n){R(e),R(n);let r=e.split(`.`).map(Number),i=n.split(`.`).map(Number);for(let e=0;e<3;e++)if(r[e]!==i[e])return t(r[e],`version part`)-t(i[e],`version part`);return 0}function B(){let e=E(M(import.meta.url));for(;;){let t=O(e,`package.json`);if(x(t)&&JSON.parse(S(t,`utf8`)).name===`@webority/tokens`)return e;let n=E(e);if(n===e)throw Error(`cannot find the @webority/tokens package folder`);e=n}}function V(){return JSON.parse(S(O(B(),`package.json`),`utf8`)).version}function H(e){let t=[];for(let n of C(e)){if(!n.endsWith(`.json`))continue;let r=n.slice(0,-5);F.test(r)&&t.push({version:r,table:JSON.parse(S(O(e,n),`utf8`))})}return t.sort((e,t)=>z(e.version,t.version))}function U(e,t){let n=P(`git`,[`ls-files`,`-z`,`--`,...t],{cwd:e,encoding:`utf8`,windowsHide:!0,maxBuffer:67108864});if(n.status!==0)throw Error(`not a git repository: ${e}`);let r=n.stdout.split(`\0`).filter(Boolean).map(e=>e.split(`\\`).join(`/`)).filter(t=>x(O(e,t)));return[...new Set(r)]}function W(e,t){let n=U(e,t??[`.`]);if(t!==void 0&&n.length===0)throw Error(`no tracked files under ${t.join(`, `)}`);return n}function G(e){return e.split(`/`).includes(`node_modules`)}var K=new Set([`node_modules`,`vendor`,`vendors`,`external`]),q=/\.(?:min|bundle)\.(?:js|css)$/,J=new Set([`lib`,`theme`]);function Y(e){let t=e.split(`/`);return t.some(e=>K.has(e))||t.some((e,n)=>{let r=t[n+1];return e===`wwwroot`&&r!==void 0&&J.has(r)})?!0:q.test(e)}function X(e,t){return[...new Set([...e,...t])]}function Z(e,t,n){return H(e).filter(e=>z(e.version,t)>0&&z(e.version,n)<=0).map(e=>e.table)}function ee(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=(e,t)=>e.flatMap(e=>[e,...n.filter(([,n])=>e[t]===n).map(([n])=>({...e,[t]:n}))]),i={...e};return e.props!==void 0&&(i.props=r(e.props,`package`)),e.componentProps!==void 0&&(i.componentProps=r(e.componentProps,`package`)),e.propValues!==void 0&&(i.propValues=r(e.propValues,`package`)),e.propSplits!==void 0&&(i.propSplits=r(e.propSplits,`package`)),e.valueSplits!==void 0&&(i.valueSplits=r(e.valueSplits,`package`)),e.components!==void 0&&(i.components=r(e.components,`package`)),e.source!==void 0&&(i.source={...e.source,flags:r(e.source.flags,`importedFrom`)}),i}function Q(e,b,x,C,w,E={}){C&&w(`dry run: nothing written`);let D=x.map(e=>ee(e,E)),k=[],A=[],j=[],M=b.filter(e=>a(e)&&!Y(e)),N=D.map(()=>new Set);if(D.some(e=>(e.css.ownable??[]).length>0))for(let n of M){let r=S(O(e,n),`utf8`);D.forEach((e,i)=>{for(let a of o(r,n,e))t(N[i],`own declarations of a rename table`).add(a)})}let P=U(e,[`package.json`,`:(glob)**/package.json`]).filter(e=>!G(e)),F=new Map,I=D.map(t=>y(e,[...M,...P],t,F));for(let a of M){let o=S(O(e,a),`utf8`),y=o,b=e=>{for(let t of e)t.from!==t.to&&(k.push({file:a,line:t.line,from:t.from,to:t.to}),w(`${a}:${t.line} ${t.from} -> ${t.to}`))},x=e=>{A.push({file:a,line:e.line,name:e.name,hint:e.hint}),w(`choose ${a}:${e.line} ${e.name}: ${e.hint}`)},E=e=>{for(let t of e)t.message.startsWith(`skipped, it does not parse`)?w(`skipped ${a}: ${t.message}`):x({line:t.line,name:t.path,hint:t.message})};for(let[e,o]of D.entries()){let S=i(y,a,o,N[e]);y=S.text,b(S.hits);for(let e of S.choose)x(e);for(let e of S.checkRole)w(`verify ${a}:${e.line} ${e.from} -> ${e.to}`);let C=g(y,a,o.themeReads);y=C.text,b(C.hits),E(C.findings);let T=[n=>v(n,a,t(I[e],`wrapper index of a rename table`)),e=>h(e,a,o.props),e=>f(e,a,o.componentProps),e=>m(e,a,o.propValues),e=>_(e,a,o.valueSplits??[]),e=>p(e,a,o.propSplits),e=>s(e,a,o.razorAttributes),e=>r(e,a,o.components??[]),e=>c(e,a,o.razorTags??[]),e=>l(e,a,o.razorValueSplits??[]),e=>n(e,a,o.classes??[]),e=>u(e,a,o.markup),e=>d(e,a,o.source)];for(let e of T){let t=e(y);y=t.text,b(t.hits),E(t.findings)}}y!==o&&(j.push(a),C||T(O(e,a),y,`utf8`))}return{hits:k,choose:A,changedFiles:j}}function te(e){let n=/^([ \t]+)\S/m.exec(e);return n?t(n[1],`indentation of a package.json`):4}function ne(e,t,n,r,i){let a=[];for(let o of U(e,[`package.json`,`:(glob)**/package.json`])){if(G(o))continue;let s=S(O(e,o),`utf8`),c=JSON.parse(s),l=!1;for(let e of[`dependencies`,`devDependencies`]){let r=c[e];if(r)for(let e of n.npm){if(!Object.hasOwn(r,e))continue;let n=r[e];I.test(n)||n===t||(r[e]=t,l=!0,i(`pin ${o}: ${e} ${n} -> ${t}`))}}if(l&&(a.push(o),r)){let t=JSON.stringify(c,null,te(s));s.endsWith(`
2
2
  `)&&(t+=`
3
3
  `),s.includes(`\r
4
4
  `)&&(t=t.replace(/\n/g,`\r
5
- `)),w(D(e,o),t,`utf8`)}}return a}function te(e,t,n,r,i){let a=[];for(let o of H(e,[`Directory.Packages.props`,`:(glob)**/Directory.Packages.props`])){if(W(o))continue;let s=x(D(e,o),`utf8`),c=!1,l=s.replace(/<PackageVersion\b[^>]*>/g,e=>{let r=/\sInclude="([^"]*)"/.exec(e)?.[1],a=/\sVersion="([^"]*)"/.exec(e)?.[1];if(r===void 0||a===void 0)return e;let s=/^\[([^\]]*)\]$/.exec(a),l=s?s[1]:a,u=s?`[${t}]`:t;return!n.nuget.includes(r)||l===t?e:(i(`pin ${o}: ${r} ${a} -> ${u}`),c=!0,e.replace(/(\sVersion=")[^"]*(")/,`$1${u}$2`))});c&&(a.push(o),r&&w(D(e,o),l,`utf8`))}return a}function ne(e){let t;try{t=y(D(e,`package.json`)).resolve(`@webority/repo-checks/lockstep.json`)}catch{throw Error(`add @webority/repo-checks at the lockstep version and run again`)}return JSON.parse(x(t,`utf8`))}var re=[{file:`pnpm-lock.yaml`,manager:`pnpm`,command:[`corepack`,`pnpm`,`install`]},{file:`package-lock.json`,manager:`npm`,command:[`npm`,`install`]}];function ie(e){let t=re.filter(t=>b(D(e,t.file)));if(t.length===0)throw Error(`no pnpm-lock.yaml or package-lock.json in ${e}`);if(t.length>1)throw Error(`${e} has both ${t[0].file} and ${t[1].file}; keep one lockfile`);return t[0]}function ae(e,t){let n=k(e,t),r=O(e,n);if(r===``||E(r)||r.split(A)[0]===`..`)throw Error(`--app ${t}: give a folder inside the repo root`);if(!b(D(n,`package.json`)))throw Error(`--app ${t}: no package.json in that folder`);return n}function oe(e,t,n){return N(e,t,{cwd:n.cwd,env:process.env,stdio:`inherit`,windowsHide:!0,shell:process.platform===`win32`})}async function se({appRoot:e,designRoot:t,app:n,version:r,from:i,aliases:a}){let o=C.native(D(e,`node_modules`,`@webority`,`tokens`)),s=JSON.parse(x(D(o,`package.json`),`utf8`))?.exports?.[`.`],c=typeof s==`string`?s:s?.default;if(typeof c!=`string`)throw Error(`cannot find the installed @webority/tokens entry`);process.env[I]=i;try{return await(await import(M(D(o,c)).href)).upgrade({root:t,app:n,version:r,dryRun:!1,aliases:a})}finally{delete process.env[I]}}async function ce({root:e,designRoot:t,version:n,dryRun:r,from:i,dir:a,log:o,brandFn:s,aliases:c}){let l=X(a,i,n),u=Q(e,U(e),l,r,o,c);return r||await s({root:t}),u}async function le({root:e,designRoot:t,app:n,version:r,dryRun:i,deps:a,log:o,aliases:s}){let c=D(e,`node_modules`,`@webority`,`tokens`,`package.json`);if(!b(c))throw Error(`@webority/tokens is not installed; add it at the lockstep version and run again`);let l=JSON.parse(x(c,`utf8`)).version,u=ne(e),d=i?null:ie(e),f=[...ee(e,r,u,!i,o),...te(e,r,u,!i,o)];if(i){o(`dry run: install skipped; tables are those of the installed ${l}`);let t=X(a.renamesDir??D(e,`node_modules`,`@webority`,`tokens`,`renames`),l,r),n=Q(e,U(e),t,!0,o,s);return{...n,changedFiles:Y(f,n.changedFiles)}}let p=a.run??oe,[m,...h]=d.command,{status:g}=await p(m,h,{cwd:e});if(g!==0)throw Error(`${d.manager} install failed with exit code ${g}`);let _=await(a.reenter??se)({appRoot:e,designRoot:t,app:n,version:r,dryRun:!1,from:l,aliases:s});return{..._,changedFiles:Y(f,_.changedFiles)}}async function ue(t,n={}){let r=t.version;L(r);let i=t.root??process.cwd(),a=t.app===void 0?i:ae(i,t.app),o=t.dryRun??!1,s=t.aliases??{},c=n.log??console.log,l=()=>n.renamesDir??D(z(),`renames`);if(Array.isArray(t.paths)&&t.paths.length>0){let e=V(l()).filter(e=>e.version===r).map(e=>e.table);if(e.length===0&&r!==(n.ownVersion??B)())throw Error(`no rename table for ${r}`);return Q(a,U(a,t.paths),e,o,c,s)}if(!b(D(i,`.webority`,`design.json`)))throw Error(`write .webority/design.json (design-map.md) and run again`);let u=process.env[I];return u?ce({root:a,designRoot:i,version:r,dryRun:o,from:u,dir:l(),log:c,brandFn:n.brand??e,aliases:s}):le({root:a,designRoot:i,app:t.app,version:r,dryRun:o,deps:n,log:c,aliases:s})}export{ue as upgrade};
5
+ `)),T(O(e,o),t,`utf8`)}}return a}function re(e,t,n,r,i){let a=[];for(let o of U(e,[`Directory.Packages.props`,`:(glob)**/Directory.Packages.props`])){if(G(o))continue;let s=S(O(e,o),`utf8`),c=!1,l=s.replace(/<PackageVersion\b[^>]*>/g,e=>{let r=/\sInclude="([^"]*)"/.exec(e)?.[1],a=/\sVersion="([^"]*)"/.exec(e)?.[1];if(r===void 0||a===void 0)return e;let s=/^\[([^\]]*)\]$/.exec(a),l=s?s[1]:a,u=s?`[${t}]`:t;return!n.nuget.includes(r)||l===t?e:(i(`pin ${o}: ${r} ${a} -> ${u}`),c=!0,e.replace(/(\sVersion=")[^"]*(")/,`$1${u}$2`))});c&&(a.push(o),r&&T(O(e,o),l,`utf8`))}return a}function ie(e){let t;try{t=b(O(e,`package.json`)).resolve(`@webority/repo-checks/lockstep.json`)}catch{throw Error(`add @webority/repo-checks at the lockstep version and run again`)}let n=JSON.parse(S(t,`utf8`));if(!ae(n))throw Error(`${t} must hold { npm: string[], nuget: string[] }`);return n}function $(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function ae(e){return typeof e!=`object`||!e||!(`npm`in e)||!(`nuget`in e)?!1:$(e.npm)&&$(e.nuget)}var oe=[{file:`pnpm-lock.yaml`,manager:`pnpm`,command:[`corepack`,`pnpm`,`install`]},{file:`package-lock.json`,manager:`npm`,command:[`npm`,`install`]}];function se(e){let n=oe.filter(t=>x(O(e,t.file)));if(n.length===0)throw Error(`no pnpm-lock.yaml or package-lock.json in ${e}`);if(n.length>1)throw Error(`${e} has both ${t(n[0],`first lockfile entry`).file} and ${t(n[1],`second lockfile entry`).file}; keep one lockfile`);return t(n[0],`lockfile entry`)}function ce(e,t){let n=A(e,t),r=k(e,n);if(r===``||D(r)||r.split(j)[0]===`..`)throw Error(`--app ${t}: give a folder inside the repo root`);if(!x(O(n,`package.json`)))throw Error(`--app ${t}: no package.json in that folder`);return n}function le(e,t,n){return P(e,t,{cwd:n.cwd,env:process.env,stdio:`inherit`,windowsHide:!0,shell:process.platform===`win32`})}async function ue({appRoot:e,designRoot:t,app:n,version:r,from:i,aliases:a}){let o=w.native(O(e,`node_modules`,`@webority`,`tokens`)),s=JSON.parse(S(O(o,`package.json`),`utf8`))?.exports?.[`.`],c=typeof s==`string`?s:s?.default;if(typeof c!=`string`)throw Error(`cannot find the installed @webority/tokens entry`);process.env[L]=i;try{return await(await import(N(O(o,c)).href)).upgrade({root:t,app:n,version:r,dryRun:!1,aliases:a})}finally{delete process.env[L]}}async function de({root:e,designRoot:t,version:n,dryRun:r,from:i,dir:a,log:o,brandFn:s,aliases:c}){let l=Z(a,i,n),u=Q(e,W(e),l,r,o,c);return r||await s({root:t}),u}async function fe({root:e,designRoot:n,app:r,version:i,dryRun:a,deps:o,log:s,aliases:c}){let l=O(e,`node_modules`,`@webority`,`tokens`,`package.json`);if(!x(l))throw Error(`@webority/tokens is not installed; add it at the lockstep version and run again`);let u=JSON.parse(S(l,`utf8`)).version,d=ie(e),f=a?null:se(e),p=[...ne(e,i,d,!a,s),...re(e,i,d,!a,s)];if(a){s(`dry run: install skipped; tables are those of the installed ${u}`);let t=Z(o.renamesDir??O(e,`node_modules`,`@webority`,`tokens`,`renames`),u,i),n=Q(e,W(e),t,!0,s,c);return{...n,changedFiles:X(p,n.changedFiles)}}if(f===null)throw Error(`webority-tokens: package manager is missing.`);let m=o.run??le,[h,...g]=f.command,{status:_}=await m(t(h,`install command`),g,{cwd:e});if(_!==0)throw Error(`${f.manager} install failed with exit code ${_}`);let v=await(o.reenter??ue)({appRoot:e,designRoot:n,app:r,version:i,dryRun:!1,from:u,aliases:c});return{...v,changedFiles:X(p,v.changedFiles)}}async function pe(t,n={}){let r=t.version;R(r);let i=t.root??process.cwd(),a=t.app===void 0?i:ce(i,t.app),o=t.dryRun??!1,s=t.aliases??{},c=n.log??(e=>process.stdout.write(`${e}\n`)),l=()=>n.renamesDir??O(B(),`renames`);if(Array.isArray(t.paths)&&t.paths.length>0){let e=H(l()).filter(e=>e.version===r).map(e=>e.table);if(e.length===0&&r!==(n.ownVersion??V)())throw Error(`no rename table for ${r}`);return Q(a,W(a,t.paths),e,o,c,s)}if(!x(O(i,`.webority`,`design.json`)))throw Error(`write .webority/design.json (design-map.md) and run again`);let u=process.env[L];return u?de({root:a,designRoot:i,version:r,dryRun:o,from:u,dir:l(),log:c,brandFn:n.brand??e,aliases:s}):fe({root:a,designRoot:i,app:t.app,version:r,dryRun:o,deps:n,log:c,aliases:s})}export{pe as upgrade};
@@ -0,0 +1,19 @@
1
+ import type { RenameTable } from "../../renames/renames.d.ts";
2
+ export type RazorAttributeHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type RazorAttributeFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type RazorAttributeResult = {
14
+ text: string;
15
+ hits: RazorAttributeHit[];
16
+ findings: RazorAttributeFinding[];
17
+ };
18
+ /** @param file repo-relative, forward slashes */
19
+ export declare function applyRazorAttributes(source: string, file: string, rules: RenameTable["razorAttributes"]): RazorAttributeResult;
@@ -1,3 +1,3 @@
1
- import{tagOccurrences as e}from"./tagScan.js";var t=new Set([`.cshtml`,`.razor`]);function n(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function r(e){let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``}function i(e){let t=[];for(let n=e.indexOf(`
1
+ import{present as e}from"../present.js";import{tagOccurrences as t}from"./tagScan.js";var n=new Set([`.cshtml`,`.razor`]);function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function i(e){let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``}function a(e){let t=[];for(let n=e.indexOf(`
2
2
  `);n!==-1;n=e.indexOf(`
3
- `,n+1))t.push(n);return t}function a(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n+1}function o(e,t){return e<t?-1:+(e>t)}function s(s,c,l){if(l.length===0||!t.has(r(c)))return{text:s,hits:[],findings:[]};let u=i(s),d=[],f=[],p=[];for(let t of l){let r=t.attribute,i=n(r),o=RegExp(`(?<=\\s)${i}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`,`g`),l=RegExp(`(?<=\\s)${i}(?=[\\s/]|$)(?!\\s*=)`,`g`),m=(e,n)=>({file:c,line:n,path:`<${e}> ${r}`,message:`${r} takes a named value such as "${t.values.true}" or "${t.values.false}" now, not a boolean; set it by hand`});for(let n of t.tags)for(let{nameEnd:i,end:h}of e(s,n)){if(h===-1){p.push({file:c,line:a(u,i),path:`<${n}> ${r}`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let e=s.slice(i,h);for(let s of e.matchAll(o)){let e=i+s.index,o=a(u,e),c=s[1]??s[2],l=e+s[0].length-1,h=l-c.length,g=c.toLowerCase();if(Object.hasOwn(t.values,g)){let e=t.values[g];d.push({start:h,end:l,text:e}),f.push({line:o,from:`${r}="${c}"`,to:`${r}="${e}"`})}else c.startsWith(`@`)&&p.push(m(n,o))}for(let t of e.matchAll(l))p.push(m(n,a(u,i+t.index)))}}d.sort((e,t)=>t.start-e.start);let m=s;for(let e of d)m=m.slice(0,e.start)+e.text+m.slice(e.end);return f.sort((e,t)=>e.line-t.line||o(e.from,t.from)),p.sort((e,t)=>e.line-t.line||o(e.path,t.path)),{text:m,hits:f,findings:p}}export{s as applyRazorAttributes};
3
+ `,n+1))t.push(n);return t}function o(t,n){let r=0,i=t.length;for(;r<i;){let a=r+i>>1;e(t[a],`newline offset`)<n?r=a+1:i=a}return r+1}function s(e,t){return e<t?-1:+(e>t)}function c(c,l,u){if(u.length===0||!n.has(i(l)))return{text:c,hits:[],findings:[]};let d=a(c),f=[],p=[],m=[];for(let n of u){let i=n.attribute,a=n.values,s=r(i),u=RegExp(`(?<=\\s)${s}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`,`g`),h=RegExp(`(?<=\\s)${s}(?=[\\s/]|$)(?!\\s*=)`,`g`),g=(e,t)=>({file:l,line:t,path:`<${e}> ${i}`,message:`${i} takes a named value such as "${n.values.true}" or "${n.values.false}" now, not a boolean; set it by hand`});for(let r of n.tags)for(let{nameEnd:n,end:s}of t(c,r)){if(s===-1){m.push({file:l,line:o(d,n),path:`<${r}> ${i}`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c.slice(n,s);for(let s of t.matchAll(u)){let t=n+s.index,c=o(d,t),l=e(s[1]??s[2],`Razor attribute value`),u=t+s[0].length-1,h=u-l.length,_=l.toLowerCase();if(Object.hasOwn(a,_)){let t=e(a[_],`the razor attribute value`);f.push({start:h,end:u,text:t}),p.push({line:c,from:`${i}="${l}"`,to:`${i}="${t}"`})}else l.startsWith(`@`)&&m.push(g(r,c))}for(let e of t.matchAll(h))m.push(g(r,o(d,n+e.index)))}}f.sort((e,t)=>t.start-e.start);let h=c;for(let e of f)h=h.slice(0,e.start)+e.text+h.slice(e.end);return p.sort((e,t)=>e.line-t.line||s(e.from,t.from)),m.sort((e,t)=>e.line-t.line||s(e.path,t.path)),{text:h,hits:p,findings:m}}export{c as applyRazorAttributes};
@@ -0,0 +1,19 @@
1
+ import type { RazorTagRule } from "../../renames/renames.d.ts";
2
+ export type RazorTagHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type RazorTagFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type RazorTagResult = {
14
+ text: string;
15
+ hits: RazorTagHit[];
16
+ findings: RazorTagFinding[];
17
+ };
18
+ /** @param file repo-relative, forward slashes */
19
+ export declare function applyRazorTags(source: string, file: string, rules: RazorTagRule[]): RazorTagResult;
@@ -1,2 +1,2 @@
1
- import{findQuoteEnd as e,tagOccurrences as t}from"./tagScan.js";var n=new Set([`.cshtml`,`.razor`]),r=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,i=/[^\s"'>]+/y,a=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
- `&&t.push(n+1);return t},c=(e,t)=>{let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n+1},l=(e,t)=>e<t?-1:+(e>t);function u(t,n,a){let o=[],s=n;for(;;){r.lastIndex=s;let n=r.exec(t);if(n===null)break;let c=n.index+n[1].length,l=c+n[2].length,u={name:n[2],nameStart:c,nameEnd:l,wsStart:n.index,kind:`none`,attrEnd:l},d=n.index+n[0].length;if(n[3]!==void 0&&(t[d]===`"`||t[d]===`'`)){let n=e(t,d);if(n===-1)break;u.kind=`quoted`,u.value=t.slice(d+1,n),u.valueStart=d+1,u.valueEnd=n,u.attrEnd=n+1}else if(n[3]!==void 0){i.lastIndex=d;let e=i.exec(t);e!==null&&(u.kind=`bare`,u.attrEnd=d+e[0].length)}if(u.attrEnd>a)break;o.push(u),s=u.attrEnd}return o}function d(e,n,r,i){let o=[],s=[],l=[],d=e=>Object.hasOwn(n.renameAttributes,e)?n.renameAttributes[e]:e,f=n.from!==n.to,p=t(e,n.from),m=p.filter(e=>e.end===-1);if(m.length>0){for(let{nameEnd:e}of m)l.push({file:i,line:c(r,e),path:`<${n.from}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); rename it by hand`});return{edits:[],hits:[],findings:l}}for(let{nameEnd:t,end:a}of p){let p=c(r,t),m=e.slice(t,a).trimEnd().endsWith(`/`),h=u(e,t,a);for(let[e,t]of Object.entries(n.removeAttributes))h.some(t=>t.name===e)&&l.push({file:i,line:p,path:`<${n.from}> ${e}`,message:t});let g=[];for(let e of h){let t=d(e.name);t!==e.name&&(o.push({start:e.nameStart,end:e.nameEnd,text:t}),s.push({line:c(r,e.nameStart),from:e.name,to:t}))}let _=h.map(e=>d(e.name));for(let e of h){let t=d(e.name);if(e.kind!==`quoted`||!Object.hasOwn(n.valueMaps,t)||!Object.hasOwn(n.valueMaps[t],e.value))continue;let i=n.valueMaps[t][e.value];o.push({start:e.valueStart,end:e.valueEnd,text:i}),s.push({line:c(r,e.valueStart),from:`${t}="${e.value}"`,to:`${t}="${i}"`})}for(let[e,t]of Object.entries(n.addAttributes))_.includes(e)||g.push(` ${e}="${t}"`);g.length>0&&o.push({start:t,end:t,text:g.join(``)}),(f||g.length>0)&&s.push({line:p,from:`<${n.from}`,to:`<${n.to}${g.join(``)}`}),f&&o.push({start:t-n.from.length,end:t,text:n.to});let v=n.attributeToContent===void 0?void 0:h.find(e=>e.name===n.attributeToContent);if(v===void 0)continue;if(v.kind!==`quoted`){l.push({file:i,line:p,path:`<${n.from}> ${v.name}`,message:`${v.name} must hold a value that becomes the element content; set it by hand`});continue}if(o.push({start:v.wsStart,end:v.attrEnd,text:``}),s.push({line:p,from:`${v.name}="${v.value}"`,to:`element content`}),m){let t=e.lastIndexOf(`/`,a);for(;/\s/.test(e[t-1]??``);)t--;o.push({start:t,end:a+1,text:`>${v.value}</${n.to}>`});continue}let y=e.indexOf(`</${n.from}`,a+1);if(y===-1)throw Error(`no closing </${n.from}> for the element at ${i}:${p}`);e.slice(a+1,y).trim()===``?o.push({start:a+1,end:y,text:v.value}):(l.push({file:i,line:p,path:`<${n.from}> ${v.name}`,message:`the element already has content; move ${v.name} into it by hand`}),o.pop(),s.pop())}if(f)for(let t of e.matchAll(RegExp(`</${a(n.from)}(?=\\s*>)`,`g`))){let e=t.index+2;o.push({start:e,end:e+n.from.length,text:n.to}),s.push({line:c(r,e),from:`</${n.from}`,to:`</${n.to}`})}return{edits:o,hits:s,findings:l}}function f(e,t,n){let{edits:r,hits:i,findings:a}=d(e,n,s(e),t);r.sort((e,t)=>t.start-e.start||t.end-e.end);let o=e;for(let e of r)o=o.slice(0,e.start)+e.text+o.slice(e.end);return{text:o,hits:i,findings:a}}function p(e,t,r){if(r.length===0||!n.has(o(t)))return{text:e,hits:[],findings:[]};let i=e,a=[],s=[];for(let e of r){let n=f(i,t,e);i=n.text,a.push(...n.hits),s.push(...n.findings)}return a.sort((e,t)=>e.line-t.line||l(e.from,t.from)),s.sort((e,t)=>e.line-t.line||l(e.path,t.path)),{text:i,hits:a,findings:s}}export{p as applyRazorTags};
1
+ import{present as e}from"../present.js";import{findQuoteEnd as t,tagOccurrences as n}from"./tagScan.js";var r=new Set([`.cshtml`,`.razor`]),i=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,a=/[^\s"'>]+/y,o=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),s=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},c=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
+ `&&t.push(n+1);return t},l=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`line start`)<=n?r=a:i=a-1}return r+1},u=(e,t)=>e<t?-1:+(e>t);function d(n,r,o){let s=[],c=r;for(;;){i.lastIndex=c;let r=i.exec(n);if(r===null)break;let l=e(r[2],`the attribute name`),u=r.index+e(r[1],`the whitespace before the attribute name`).length,d=u+l.length,f={name:l,nameStart:u,nameEnd:d,wsStart:r.index,kind:`none`,attrEnd:d},p=r.index+r[0].length;if(r[3]!==void 0&&(n[p]===`"`||n[p]===`'`)){let e=t(n,p);if(e===-1)break;f.kind=`quoted`,f.value=n.slice(p+1,e),f.valueStart=p+1,f.valueEnd=e,f.attrEnd=e+1}else if(r[3]!==void 0){a.lastIndex=p;let e=a.exec(n);e!==null&&(f.kind=`bare`,f.attrEnd=p+e[0].length)}if(f.attrEnd>o)break;s.push(f),c=f.attrEnd}return s}function f(t,r,i,a){let s=[],c=[],u=[],f=t=>Object.hasOwn(r.renameAttributes,t)?e(r.renameAttributes[t],`the renamed attribute`):t,p=r.from!==r.to,m=n(t,r.from),h=m.filter(e=>e.end===-1);if(h.length>0){for(let{nameEnd:e}of h)u.push({file:a,line:l(i,e),path:`<${r.from}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); rename it by hand`});return{edits:[],hits:[],findings:u}}for(let{nameEnd:n,end:o}of m){let m=l(i,n),h=t.slice(n,o).trimEnd().endsWith(`/`),g=d(t,n,o);for(let[e,t]of Object.entries(r.removeAttributes))g.some(t=>t.name===e)&&u.push({file:a,line:m,path:`<${r.from}> ${e}`,message:t});let _=[];for(let e of g){let t=f(e.name);t!==e.name&&(s.push({start:e.nameStart,end:e.nameEnd,text:t}),c.push({line:l(i,e.nameStart),from:e.name,to:t}))}let v=g.map(e=>f(e.name));for(let t of g){let n=f(t.name),a=Object.hasOwn(r.valueMaps,n)?r.valueMaps[n]:void 0;if(t.kind!==`quoted`||a===void 0||t.value===void 0||!Object.hasOwn(a,t.value))continue;let o=e(a[t.value],`the mapped value`),u=e(t.valueStart,`the start of the quoted value`);s.push({start:u,end:e(t.valueEnd,`the end of the quoted value`),text:o}),c.push({line:l(i,u),from:`${n}="${t.value}"`,to:`${n}="${o}"`})}for(let[e,t]of Object.entries(r.addAttributes))v.includes(e)||_.push(` ${e}="${t}"`);_.length>0&&s.push({start:n,end:n,text:_.join(``)}),(p||_.length>0)&&c.push({line:m,from:`<${r.from}`,to:`<${r.to}${_.join(``)}`}),p&&s.push({start:n-r.from.length,end:n,text:r.to});let y=r.attributeToContent===void 0?void 0:g.find(e=>e.name===r.attributeToContent);if(y===void 0)continue;if(y.kind!==`quoted`){u.push({file:a,line:m,path:`<${r.from}> ${y.name}`,message:`${y.name} must hold a value that becomes the element content; set it by hand`});continue}if(s.push({start:y.wsStart,end:y.attrEnd,text:``}),c.push({line:m,from:`${y.name}="${y.value}"`,to:`element content`}),h){let e=t.lastIndexOf(`/`,o);for(;/\s/.test(t[e-1]??``);)e--;s.push({start:e,end:o+1,text:`>${y.value}</${r.to}>`});continue}let b=t.indexOf(`</${r.from}`,o+1);if(b===-1)throw Error(`no closing </${r.from}> for the element at ${a}:${m}`);t.slice(o+1,b).trim()===``?s.push({start:o+1,end:b,text:e(y.value,`the value of the moved attribute`)}):(u.push({file:a,line:m,path:`<${r.from}> ${y.name}`,message:`the element already has content; move ${y.name} into it by hand`}),s.pop(),c.pop())}if(p)for(let e of t.matchAll(RegExp(`</${o(r.from)}(?=\\s*>)`,`g`))){let t=e.index+2;s.push({start:t,end:t+r.from.length,text:r.to}),c.push({line:l(i,t),from:`</${r.from}`,to:`</${r.to}`})}return{edits:s,hits:c,findings:u}}function p(e,t,n){let{edits:r,hits:i,findings:a}=f(e,n,c(e),t);r.sort((e,t)=>t.start-e.start||t.end-e.end);let o=e;for(let e of r)o=o.slice(0,e.start)+e.text+o.slice(e.end);return{text:o,hits:i,findings:a}}function m(e,t,n){if(n.length===0||!r.has(s(t)))return{text:e,hits:[],findings:[]};let i=e,a=[],o=[];for(let e of n){let n=p(i,t,e);i=n.text,a.push(...n.hits),o.push(...n.findings)}return a.sort((e,t)=>e.line-t.line||u(e.from,t.from)),o.sort((e,t)=>e.line-t.line||u(e.path,t.path)),{text:i,hits:a,findings:o}}export{m as applyRazorTags};
@@ -0,0 +1,19 @@
1
+ import type { RazorValueSplitRule } from "../../renames/renames.d.ts";
2
+ export type RazorValueSplitHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type RazorValueSplitFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type RazorValueSplitResult = {
14
+ text: string;
15
+ hits: RazorValueSplitHit[];
16
+ findings: RazorValueSplitFinding[];
17
+ };
18
+ /** @param file repo-relative, forward slashes */
19
+ export declare function applyRazorValueSplits(source: string, file: string, rules: RazorValueSplitRule[]): RazorValueSplitResult;
@@ -1,2 +1,2 @@
1
- import{findQuoteEnd as e,tagOccurrences as t}from"./tagScan.js";import{applyEdits as n}from"./themeReads.js";import{separatorAt as r}from"./valueSplits.js";var i=new Set([`.cshtml`,`.razor`]),a=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=(e,t)=>e.slice(0,t).split(`
2
- `).length;function c(t,n,r){let i=[],o=n;for(;;){a.lastIndex=o;let n=a.exec(t);if(n===null)break;let s=n.index+n[1].length,c={name:n[2],nameStart:s,nameEnd:s+n[2].length,wsStart:n.index,kind:`none`,attrEnd:s+n[2].length},l=n.index+n[0].length;if(n[3]!==void 0&&(t[l]===`"`||t[l]===`'`)){let n=e(t,l);if(n===-1)break;c.kind=`quoted`,c.value=t.slice(l+1,n),c.attrEnd=n+1}else n[3]!==void 0&&(c.kind=`bare`,c.attrEnd=l+/[^\s"'>]*/y.exec(t.slice(l))[0].length);if(c.attrEnd>r)break;i.push(c),o=c.attrEnd}return i}function l(e,a,l){if(l.length===0||!i.has(o(a)))return{text:e,hits:[],findings:[]};let u=[],d=[],f=[];for(let n of l)for(let i of n.tags)for(let{nameEnd:o,end:l}of t(e,i)){if(l===-1){f.push({file:a,line:s(e,o),path:`<${i}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c(e,o,l),p=new Set(t.map(e=>e.name));for(let o of t){if(o.name!==n.attribute)continue;let t=s(e,o.nameStart),c=`<${i}> ${n.attribute}`,l=o.kind===`none`?`true`:o.kind===`quoted`?o.value.toLowerCase():void 0;if(l!==void 0&&!Object.hasOwn(n.values,l)&&n.keep?.includes(l))continue;if(l===void 0||!Object.hasOwn(n.values,l)){f.push({file:a,line:t,path:c,message:n.flag});continue}let m=Object.entries(n.values[l]).filter(([,e])=>e!==null),h=m.map(([e])=>e).filter(e=>e!==n.attribute&&p.has(e));if(h.length>0){f.push({file:a,line:t,path:c,message:`<${i}> already sets ${h.join(` and `)}; merge ${n.attribute} into it by hand`});continue}let g=m.map(([e,t])=>`${e}="${t}"`).join(r(e,o.nameStart));if(n.skipWritten&&g===e.slice(o.nameStart,o.attrEnd))continue;let _=m.length===0?o.wsStart:o.nameStart;u.push({start:_,end:o.attrEnd,text:g}),d.push({line:t,from:e.slice(o.nameStart,o.attrEnd),to:g.replace(/\n\s*/g,` `)})}}return d.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),f.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:n(e,u,a),hits:d,findings:f}}export{l as applyRazorValueSplits};
1
+ import{present as e}from"../present.js";import{findQuoteEnd as t,tagOccurrences as n}from"./tagScan.js";import{applyEdits as r}from"./themeReads.js";import{separatorAt as i}from"./valueSplits.js";var a=new Set([`.cshtml`,`.razor`]),o=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,s=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},c=(e,t)=>e.slice(0,t).split(`
2
+ `).length;function l(n,r,i){let a=[],s=r;for(;;){o.lastIndex=s;let r=o.exec(n);if(r===null)break;let c=e(r[2],`the attribute name`),l=r.index+e(r[1],`the whitespace before an attribute`).length,u={name:c,nameStart:l,nameEnd:l+c.length,wsStart:r.index,kind:`none`,attrEnd:l+c.length},d=r.index+r[0].length;if(r[3]!==void 0&&(n[d]===`"`||n[d]===`'`)){let e=t(n,d);if(e===-1)break;u.kind=`quoted`,u.value=n.slice(d+1,e),u.attrEnd=e+1}else if(r[3]!==void 0){u.kind=`bare`;let e=/[^\s"'>]*/y.exec(n.slice(d));if(e===null)throw Error(`webority-tokens: bare attribute value is missing.`);u.attrEnd=d+e[0].length}if(u.attrEnd>i)break;a.push(u),s=u.attrEnd}return a}function u(t,o,u){if(u.length===0||!a.has(s(o)))return{text:t,hits:[],findings:[]};let d=[],f=[],p=[];for(let r of u)for(let a of r.tags)for(let{nameEnd:s,end:u}of n(t,a)){if(u===-1){p.push({file:o,line:c(t,s),path:`<${a}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let n=l(t,s,u),m=new Set(n.map(e=>e.name));for(let s of n){if(s.name!==r.attribute)continue;let n=c(t,s.nameStart),l=`<${a}> ${r.attribute}`,u=s.kind===`none`?`true`:s.kind===`quoted`&&s.value!==void 0?s.value.toLowerCase():void 0;if(u!==void 0&&!Object.hasOwn(r.values,u)&&r.keep?.includes(u))continue;if(u===void 0||!Object.hasOwn(r.values,u)){p.push({file:o,line:n,path:l,message:r.flag});continue}let h=Object.entries(e(r.values[u],`the table's values for the attribute`)).filter(([,e])=>e!==null),g=h.map(([e])=>e).filter(e=>e!==r.attribute&&m.has(e));if(g.length>0){p.push({file:o,line:n,path:l,message:`<${a}> already sets ${g.join(` and `)}; merge ${r.attribute} into it by hand`});continue}let _=h.map(([e,t])=>`${e}="${t}"`).join(i(t,s.nameStart));if(r.skipWritten&&_===t.slice(s.nameStart,s.attrEnd))continue;let v=h.length===0?s.wsStart:s.nameStart;d.push({start:v,end:s.attrEnd,text:_}),f.push({line:n,from:t.slice(s.nameStart,s.attrEnd),to:_.replace(/\n\s*/g,` `)})}}return f.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),p.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:r(t,d,o),hits:f,findings:p}}export{u as applyRazorValueSplits};
@@ -0,0 +1,19 @@
1
+ import type { MarkupRules, SourceRules } from "../../renames/renames.d.ts";
2
+ export type SourceHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type SourceFinding = {
8
+ line: number;
9
+ path: string;
10
+ message: string;
11
+ };
12
+ export type SourceResult = {
13
+ text: string;
14
+ hits: SourceHit[];
15
+ findings: SourceFinding[];
16
+ };
17
+ export declare const SOURCE_EXTENSIONS: Set<string>;
18
+ export declare function applySource(text: string, file: string, rules: SourceRules | undefined): SourceResult;
19
+ export declare function applyMarkup(text: string, file: string, rules: MarkupRules | undefined): SourceResult;