@wyw-in-js/processor-utils 0.1.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 (92) hide show
  1. package/LICENSE +21 -0
  2. package/esm/BaseProcessor.js +70 -0
  3. package/esm/BaseProcessor.js.map +1 -0
  4. package/esm/TaggedTemplateProcessor.js +43 -0
  5. package/esm/TaggedTemplateProcessor.js.map +1 -0
  6. package/esm/index.js +7 -0
  7. package/esm/index.js.map +1 -0
  8. package/esm/types.js +2 -0
  9. package/esm/types.js.map +1 -0
  10. package/esm/utils/buildSlug.js +6 -0
  11. package/esm/utils/buildSlug.js.map +1 -0
  12. package/esm/utils/getClassNameAndSlug.js +42 -0
  13. package/esm/utils/getClassNameAndSlug.js.map +1 -0
  14. package/esm/utils/getVariableName.js +12 -0
  15. package/esm/utils/getVariableName.js.map +1 -0
  16. package/esm/utils/stripLines.js +16 -0
  17. package/esm/utils/stripLines.js.map +1 -0
  18. package/esm/utils/templateProcessor.js +125 -0
  19. package/esm/utils/templateProcessor.js.map +1 -0
  20. package/esm/utils/throwIfInvalid.js +29 -0
  21. package/esm/utils/throwIfInvalid.js.map +1 -0
  22. package/esm/utils/toCSS.js +50 -0
  23. package/esm/utils/toCSS.js.map +1 -0
  24. package/esm/utils/toValidCSSIdentifier.js +4 -0
  25. package/esm/utils/toValidCSSIdentifier.js.map +1 -0
  26. package/esm/utils/types.js +2 -0
  27. package/esm/utils/types.js.map +1 -0
  28. package/esm/utils/units.js +65 -0
  29. package/esm/utils/units.js.map +1 -0
  30. package/esm/utils/validateParams.js +40 -0
  31. package/esm/utils/validateParams.js.map +1 -0
  32. package/lib/BaseProcessor.js +78 -0
  33. package/lib/BaseProcessor.js.map +1 -0
  34. package/lib/TaggedTemplateProcessor.js +51 -0
  35. package/lib/TaggedTemplateProcessor.js.map +1 -0
  36. package/lib/index.js +67 -0
  37. package/lib/index.js.map +1 -0
  38. package/lib/types.js +2 -0
  39. package/lib/types.js.map +1 -0
  40. package/lib/utils/buildSlug.js +12 -0
  41. package/lib/utils/buildSlug.js.map +1 -0
  42. package/lib/utils/getClassNameAndSlug.js +49 -0
  43. package/lib/utils/getClassNameAndSlug.js.map +1 -0
  44. package/lib/utils/getVariableName.js +18 -0
  45. package/lib/utils/getVariableName.js.map +1 -0
  46. package/lib/utils/stripLines.js +22 -0
  47. package/lib/utils/stripLines.js.map +1 -0
  48. package/lib/utils/templateProcessor.js +135 -0
  49. package/lib/utils/templateProcessor.js.map +1 -0
  50. package/lib/utils/throwIfInvalid.js +35 -0
  51. package/lib/utils/throwIfInvalid.js.map +1 -0
  52. package/lib/utils/toCSS.js +58 -0
  53. package/lib/utils/toCSS.js.map +1 -0
  54. package/lib/utils/toValidCSSIdentifier.js +10 -0
  55. package/lib/utils/toValidCSSIdentifier.js.map +1 -0
  56. package/lib/utils/types.js +2 -0
  57. package/lib/utils/types.js.map +1 -0
  58. package/lib/utils/units.js +71 -0
  59. package/lib/utils/units.js.map +1 -0
  60. package/lib/utils/validateParams.js +54 -0
  61. package/lib/utils/validateParams.js.map +1 -0
  62. package/package.json +40 -0
  63. package/types/BaseProcessor.d.ts +66 -0
  64. package/types/BaseProcessor.js +59 -0
  65. package/types/TaggedTemplateProcessor.d.ts +20 -0
  66. package/types/TaggedTemplateProcessor.js +40 -0
  67. package/types/index.d.ts +9 -0
  68. package/types/index.js +29 -0
  69. package/types/types.d.ts +32 -0
  70. package/types/types.js +2 -0
  71. package/types/utils/buildSlug.d.ts +3 -0
  72. package/types/utils/buildSlug.js +9 -0
  73. package/types/utils/getClassNameAndSlug.d.ts +5 -0
  74. package/types/utils/getClassNameAndSlug.js +43 -0
  75. package/types/utils/getVariableName.d.ts +2 -0
  76. package/types/utils/getVariableName.js +15 -0
  77. package/types/utils/stripLines.d.ts +5 -0
  78. package/types/utils/stripLines.js +18 -0
  79. package/types/utils/templateProcessor.d.ts +10 -0
  80. package/types/utils/templateProcessor.js +140 -0
  81. package/types/utils/throwIfInvalid.d.ts +5 -0
  82. package/types/utils/throwIfInvalid.js +32 -0
  83. package/types/utils/toCSS.d.ts +3 -0
  84. package/types/utils/toCSS.js +61 -0
  85. package/types/utils/toValidCSSIdentifier.d.ts +1 -0
  86. package/types/utils/toValidCSSIdentifier.js +7 -0
  87. package/types/utils/types.d.ts +9 -0
  88. package/types/utils/types.js +2 -0
  89. package/types/utils/units.d.ts +44 -0
  90. package/types/utils/units.js +94 -0
  91. package/types/utils/validateParams.d.ts +16 -0
  92. package/types/utils/validateParams.js +39 -0
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const isLikeError = value => typeof value === 'object' && value !== null && 'stack' in value && 'message' in value;
8
+
9
+ // Throw if we can't handle the interpolated value
10
+ function throwIfInvalid(checker, value, ex, source) {
11
+ // We can't use instanceof here so let's use duck typing
12
+ if (isLikeError(value) && value.stack && value.message) {
13
+ throw ex.buildCodeFrameError(`An error occurred when evaluating the expression:
14
+
15
+ > ${value.message}.
16
+
17
+ Make sure you are not using a browser or Node specific API and all the variables are available in static context.
18
+ Linaria have to extract pieces of your code to resolve the interpolated values.
19
+ Defining styled component or class will not work inside:
20
+ - function,
21
+ - class,
22
+ - method,
23
+ - loop,
24
+ because it cannot be statically determined in which context you use them.
25
+ That's why some variables may be not defined during evaluation.
26
+ `);
27
+ }
28
+ if (checker(value)) {
29
+ return;
30
+ }
31
+ const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value);
32
+ throw ex.buildCodeFrameError(`The expression evaluated to '${stringified}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${source})'.`);
33
+ }
34
+ var _default = exports.default = throwIfInvalid;
35
+ //# sourceMappingURL=throwIfInvalid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throwIfInvalid.js","names":["isLikeError","value","throwIfInvalid","checker","ex","source","stack","message","buildCodeFrameError","stringified","JSON","stringify","String","_default","exports","default"],"sources":["../../src/utils/throwIfInvalid.ts"],"sourcesContent":["import type { BuildCodeFrameErrorFn } from '@wyw-in-js/shared';\n\nconst isLikeError = (value: unknown): value is Error =>\n typeof value === 'object' &&\n value !== null &&\n 'stack' in value &&\n 'message' in value;\n\n// Throw if we can't handle the interpolated value\nfunction throwIfInvalid<T>(\n checker: (value: unknown) => value is T,\n value: Error | unknown,\n ex: { buildCodeFrameError: BuildCodeFrameErrorFn },\n source: string\n): asserts value is T {\n // We can't use instanceof here so let's use duck typing\n if (isLikeError(value) && value.stack && value.message) {\n throw ex.buildCodeFrameError(\n `An error occurred when evaluating the expression:\n\n > ${value.message}.\n\n Make sure you are not using a browser or Node specific API and all the variables are available in static context.\n Linaria have to extract pieces of your code to resolve the interpolated values.\n Defining styled component or class will not work inside:\n - function,\n - class,\n - method,\n - loop,\n because it cannot be statically determined in which context you use them.\n That's why some variables may be not defined during evaluation.\n `\n );\n }\n\n if (checker(value)) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n throw ex.buildCodeFrameError(\n `The expression evaluated to '${stringified}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${source})'.`\n );\n}\n\nexport default throwIfInvalid;\n"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAIC,KAAc,IACjC,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAO,IAAIA,KAAK,IAChB,SAAS,IAAIA,KAAK;;AAEpB;AACA,SAASC,cAAcA,CACrBC,OAAuC,EACvCF,KAAsB,EACtBG,EAAkD,EAClDC,MAAc,EACM;EACpB;EACA,IAAIL,WAAW,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACK,KAAK,IAAIL,KAAK,CAACM,OAAO,EAAE;IACtD,MAAMH,EAAE,CAACI,mBAAmB,CACzB;AACP;AACA,MAAMP,KAAK,CAACM,OAAQ;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OACI,CAAC;EACH;EAEA,IAAIJ,OAAO,CAACF,KAAK,CAAC,EAAE;IAClB;EACF;EAEA,MAAMQ,WAAW,GACf,OAAOR,KAAK,KAAK,QAAQ,GAAGS,IAAI,CAACC,SAAS,CAACV,KAAK,CAAC,GAAGW,MAAM,CAACX,KAAK,CAAC;EAEnE,MAAMG,EAAE,CAACI,mBAAmB,CACzB,gCAA+BC,WAAY,8IAA6IJ,MAAO,KAClM,CAAC;AACH;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcb,cAAc"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toCSS;
7
+ exports.isCSSable = void 0;
8
+ var _shared = require("@wyw-in-js/shared");
9
+ var _units = require("./units");
10
+ const isCSSPropertyValue = o => {
11
+ return (0, _shared.isBoxedPrimitive)(o) || typeof o === 'string' || typeof o === 'number' && Number.isFinite(o);
12
+ };
13
+ const isCSSable = o => {
14
+ if (isCSSPropertyValue(o)) {
15
+ return true;
16
+ }
17
+ if (Array.isArray(o)) {
18
+ return o.every(isCSSable);
19
+ }
20
+ if (typeof o === 'object') {
21
+ return o !== null && Object.values(o).every(isCSSable);
22
+ }
23
+ return false;
24
+ };
25
+ exports.isCSSable = isCSSable;
26
+ const hyphenate = s => {
27
+ if (s.startsWith('--')) {
28
+ // It's a custom property which is already well formatted.
29
+ return s;
30
+ }
31
+ return s
32
+ // Hyphenate CSS property names from camelCase version from JS string
33
+ .replace(/([A-Z])/g, (match, p1) => `-${p1.toLowerCase()}`)
34
+ // Special case for `-ms` because in JS it starts with `ms` unlike `Webkit`
35
+ .replace(/^ms-/, '-ms-');
36
+ };
37
+
38
+ // Some tools such as polished.js output JS objects
39
+ // To support them transparently, we convert JS objects to CSS strings
40
+ function toCSS(o) {
41
+ if (Array.isArray(o)) {
42
+ return o.map(toCSS).join('\n');
43
+ }
44
+ if (isCSSPropertyValue(o)) {
45
+ return o.valueOf().toString();
46
+ }
47
+ return Object.entries(o).filter(([, value]) =>
48
+ // Ignore all falsy values except numbers
49
+ typeof value === 'number' || value).map(([key, value]) => {
50
+ if (!isCSSPropertyValue(value)) {
51
+ return `${key} { ${toCSS(value)} }`;
52
+ }
53
+ return `${hyphenate(key)}: ${typeof value === 'number' && value !== 0 &&
54
+ // Strip vendor prefixes when checking if the value is unitless
55
+ !(key.replace(/^(Webkit|Moz|O|ms)([A-Z])(.+)$/, (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`) in _units.unitless) ? `${value}px` : value};`;
56
+ }).join(' ');
57
+ }
58
+ //# sourceMappingURL=toCSS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toCSS.js","names":["_shared","require","_units","isCSSPropertyValue","o","isBoxedPrimitive","Number","isFinite","isCSSable","Array","isArray","every","Object","values","exports","hyphenate","s","startsWith","replace","match","p1","toLowerCase","toCSS","map","join","valueOf","toString","entries","filter","value","key","p2","p3","unitless"],"sources":["../../src/utils/toCSS.ts"],"sourcesContent":["import { isBoxedPrimitive } from '@wyw-in-js/shared';\n\nimport type { CSSPropertyValue, CSSable } from '../types';\n\nimport { unitless } from './units';\n\nconst isCSSPropertyValue = (o: unknown): o is CSSPropertyValue => {\n return (\n isBoxedPrimitive(o) ||\n typeof o === 'string' ||\n (typeof o === 'number' && Number.isFinite(o))\n );\n};\n\nexport const isCSSable = (o: unknown): o is CSSable => {\n if (isCSSPropertyValue(o)) {\n return true;\n }\n\n if (Array.isArray(o)) {\n return o.every(isCSSable);\n }\n\n if (typeof o === 'object') {\n return o !== null && Object.values(o).every(isCSSable);\n }\n\n return false;\n};\n\nconst hyphenate = (s: string) => {\n if (s.startsWith('--')) {\n // It's a custom property which is already well formatted.\n return s;\n }\n return (\n s\n // Hyphenate CSS property names from camelCase version from JS string\n .replace(/([A-Z])/g, (match, p1) => `-${p1.toLowerCase()}`)\n // Special case for `-ms` because in JS it starts with `ms` unlike `Webkit`\n .replace(/^ms-/, '-ms-')\n );\n};\n\n// Some tools such as polished.js output JS objects\n// To support them transparently, we convert JS objects to CSS strings\nexport default function toCSS(o: CSSable): string {\n if (Array.isArray(o)) {\n return o.map(toCSS).join('\\n');\n }\n\n if (isCSSPropertyValue(o)) {\n return o.valueOf().toString();\n }\n\n return Object.entries(o)\n .filter(\n ([, value]) =>\n // Ignore all falsy values except numbers\n typeof value === 'number' || value\n )\n .map(([key, value]) => {\n if (!isCSSPropertyValue(value)) {\n return `${key} { ${toCSS(value)} }`;\n }\n\n return `${hyphenate(key)}: ${\n typeof value === 'number' &&\n value !== 0 &&\n // Strip vendor prefixes when checking if the value is unitless\n !(\n key.replace(\n /^(Webkit|Moz|O|ms)([A-Z])(.+)$/,\n (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`\n ) in unitless\n )\n ? `${value}px`\n : value\n };`;\n })\n .join(' ');\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,kBAAkB,GAAIC,CAAU,IAA4B;EAChE,OACE,IAAAC,wBAAgB,EAACD,CAAC,CAAC,IACnB,OAAOA,CAAC,KAAK,QAAQ,IACpB,OAAOA,CAAC,KAAK,QAAQ,IAAIE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAE;AAEjD,CAAC;AAEM,MAAMI,SAAS,GAAIJ,CAAU,IAAmB;EACrD,IAAID,kBAAkB,CAACC,CAAC,CAAC,EAAE;IACzB,OAAO,IAAI;EACb;EAEA,IAAIK,KAAK,CAACC,OAAO,CAACN,CAAC,CAAC,EAAE;IACpB,OAAOA,CAAC,CAACO,KAAK,CAACH,SAAS,CAAC;EAC3B;EAEA,IAAI,OAAOJ,CAAC,KAAK,QAAQ,EAAE;IACzB,OAAOA,CAAC,KAAK,IAAI,IAAIQ,MAAM,CAACC,MAAM,CAACT,CAAC,CAAC,CAACO,KAAK,CAACH,SAAS,CAAC;EACxD;EAEA,OAAO,KAAK;AACd,CAAC;AAACM,OAAA,CAAAN,SAAA,GAAAA,SAAA;AAEF,MAAMO,SAAS,GAAIC,CAAS,IAAK;EAC/B,IAAIA,CAAC,CAACC,UAAU,CAAC,IAAI,CAAC,EAAE;IACtB;IACA,OAAOD,CAAC;EACV;EACA,OACEA;EACE;EAAA,CACCE,OAAO,CAAC,UAAU,EAAE,CAACC,KAAK,EAAEC,EAAE,KAAM,IAAGA,EAAE,CAACC,WAAW,CAAC,CAAE,EAAC;EAC1D;EAAA,CACCH,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;AAE9B,CAAC;;AAED;AACA;AACe,SAASI,KAAKA,CAAClB,CAAU,EAAU;EAChD,IAAIK,KAAK,CAACC,OAAO,CAACN,CAAC,CAAC,EAAE;IACpB,OAAOA,CAAC,CAACmB,GAAG,CAACD,KAAK,CAAC,CAACE,IAAI,CAAC,IAAI,CAAC;EAChC;EAEA,IAAIrB,kBAAkB,CAACC,CAAC,CAAC,EAAE;IACzB,OAAOA,CAAC,CAACqB,OAAO,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC/B;EAEA,OAAOd,MAAM,CAACe,OAAO,CAACvB,CAAC,CAAC,CACrBwB,MAAM,CACL,CAAC,GAAGC,KAAK,CAAC;EACR;EACA,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KACjC,CAAC,CACAN,GAAG,CAAC,CAAC,CAACO,GAAG,EAAED,KAAK,CAAC,KAAK;IACrB,IAAI,CAAC1B,kBAAkB,CAAC0B,KAAK,CAAC,EAAE;MAC9B,OAAQ,GAAEC,GAAI,MAAKR,KAAK,CAACO,KAAK,CAAE,IAAG;IACrC;IAEA,OAAQ,GAAEd,SAAS,CAACe,GAAG,CAAE,KACvB,OAAOD,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,CAAC;IACX;IACA,EACEC,GAAG,CAACZ,OAAO,CACT,gCAAgC,EAChC,CAACC,KAAK,EAAEC,EAAE,EAAEW,EAAE,EAAEC,EAAE,KAAM,GAAED,EAAE,CAACV,WAAW,CAAC,CAAE,GAAEW,EAAG,EAClD,CAAC,IAAIC,eAAQ,CACd,GACI,GAAEJ,KAAM,IAAG,GACZA,KACL,GAAE;EACL,CAAC,CAAC,CACDL,IAAI,CAAC,GAAG,CAAC;AACd"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toValidCSSIdentifier = toValidCSSIdentifier;
7
+ function toValidCSSIdentifier(s) {
8
+ return s.replace(/[^-_a-z0-9\u00A0-\uFFFF]/gi, '_').replace(/^\d/, '_');
9
+ }
10
+ //# sourceMappingURL=toValidCSSIdentifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toValidCSSIdentifier.js","names":["toValidCSSIdentifier","s","replace"],"sources":["../../src/utils/toValidCSSIdentifier.ts"],"sourcesContent":["export function toValidCSSIdentifier(s: string) {\n return s.replace(/[^-_a-z0-9\\u00A0-\\uFFFF]/gi, '_').replace(/^\\d/, '_');\n}\n"],"mappings":";;;;;;AAAO,SAASA,oBAAoBA,CAACC,CAAS,EAAE;EAC9C,OAAOA,CAAC,CAACC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACzE"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { TransformOptions } from '@babel/core';\n\nimport type { ClassNameFn, VariableNameFn } from '@wyw-in-js/shared';\n\nexport interface IOptions {\n classNameSlug?: string | ClassNameFn;\n displayName: boolean;\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":""}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.units = exports.unitless = void 0;
7
+ // https://www.w3.org/TR/css-values-4/
8
+ const units = exports.units = [
9
+ // font relative lengths
10
+ 'em', 'ex', 'cap', 'ch', 'ic', 'rem', 'lh', 'rlh',
11
+ // viewport percentage lengths
12
+ 'vw', 'vh', 'vi', 'vb', 'vmin', 'vmax',
13
+ // absolute lengths
14
+ 'cm', 'mm', 'Q', 'in', 'pc', 'pt', 'px',
15
+ // angle units
16
+ 'deg', 'grad', 'rad', 'turn',
17
+ // duration units
18
+ 's', 'ms',
19
+ // frequency units
20
+ 'Hz', 'kHz',
21
+ // resolution units
22
+ 'dpi', 'dpcm', 'dppx', 'x',
23
+ // https://www.w3.org/TR/css-grid-1/#fr-unit
24
+ 'fr',
25
+ // percentages
26
+ '%'];
27
+ const unitless = exports.unitless = {
28
+ animationIterationCount: true,
29
+ borderImageOutset: true,
30
+ borderImageSlice: true,
31
+ borderImageWidth: true,
32
+ boxFlex: true,
33
+ boxFlexGroup: true,
34
+ boxOrdinalGroup: true,
35
+ columnCount: true,
36
+ columns: true,
37
+ flex: true,
38
+ flexGrow: true,
39
+ flexPositive: true,
40
+ flexShrink: true,
41
+ flexNegative: true,
42
+ flexOrder: true,
43
+ gridRow: true,
44
+ gridRowEnd: true,
45
+ gridRowSpan: true,
46
+ gridRowStart: true,
47
+ gridColumn: true,
48
+ gridColumnEnd: true,
49
+ gridColumnSpan: true,
50
+ gridColumnStart: true,
51
+ fontWeight: true,
52
+ lineClamp: true,
53
+ lineHeight: true,
54
+ opacity: true,
55
+ order: true,
56
+ orphans: true,
57
+ tabSize: true,
58
+ widows: true,
59
+ zIndex: true,
60
+ zoom: true,
61
+ // SVG-related properties
62
+ fillOpacity: true,
63
+ floodOpacity: true,
64
+ stopOpacity: true,
65
+ strokeDasharray: true,
66
+ strokeDashoffset: true,
67
+ strokeMiterlimit: true,
68
+ strokeOpacity: true,
69
+ strokeWidth: true
70
+ };
71
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","names":["units","exports","unitless","animationIterationCount","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"],"sources":["../../src/utils/units.ts"],"sourcesContent":["// https://www.w3.org/TR/css-values-4/\nexport const units = [\n // font relative lengths\n 'em',\n 'ex',\n 'cap',\n 'ch',\n 'ic',\n 'rem',\n 'lh',\n 'rlh',\n\n // viewport percentage lengths\n 'vw',\n 'vh',\n 'vi',\n 'vb',\n 'vmin',\n 'vmax',\n\n // absolute lengths\n 'cm',\n 'mm',\n 'Q',\n 'in',\n 'pc',\n 'pt',\n 'px',\n\n // angle units\n 'deg',\n 'grad',\n 'rad',\n 'turn',\n\n // duration units\n 's',\n 'ms',\n\n // frequency units\n 'Hz',\n 'kHz',\n\n // resolution units\n 'dpi',\n 'dpcm',\n 'dppx',\n 'x',\n\n // https://www.w3.org/TR/css-grid-1/#fr-unit\n 'fr',\n\n // percentages\n '%',\n];\n\nexport const unitless = {\n animationIterationCount: true,\n borderImageOutset: true,\n borderImageSlice: true,\n borderImageWidth: true,\n boxFlex: true,\n boxFlexGroup: true,\n boxOrdinalGroup: true,\n columnCount: true,\n columns: true,\n flex: true,\n flexGrow: true,\n flexPositive: true,\n flexShrink: true,\n flexNegative: true,\n flexOrder: true,\n gridRow: true,\n gridRowEnd: true,\n gridRowSpan: true,\n gridRowStart: true,\n gridColumn: true,\n gridColumnEnd: true,\n gridColumnSpan: true,\n gridColumnStart: true,\n fontWeight: true,\n lineClamp: true,\n lineHeight: true,\n opacity: true,\n order: true,\n orphans: true,\n tabSize: true,\n widows: true,\n zIndex: true,\n zoom: true,\n\n // SVG-related properties\n fillOpacity: true,\n floodOpacity: true,\n stopOpacity: true,\n strokeDasharray: true,\n strokeDashoffset: true,\n strokeMiterlimit: true,\n strokeOpacity: true,\n strokeWidth: true,\n};\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,KAAK,GAAAC,OAAA,CAAAD,KAAA,GAAG;AACnB;AACA,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK;AAEL;AACA,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,MAAM;AAEN;AACA,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI;AAEJ;AACA,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM;AAEN;AACA,GAAG,EACH,IAAI;AAEJ;AACA,IAAI,EACJ,KAAK;AAEL;AACA,KAAK,EACL,MAAM,EACN,MAAM,EACN,GAAG;AAEH;AACA,IAAI;AAEJ;AACA,GAAG,CACJ;AAEM,MAAME,QAAQ,GAAAD,OAAA,CAAAC,QAAA,GAAG;EACtBC,uBAAuB,EAAE,IAAI;EAC7BC,iBAAiB,EAAE,IAAI;EACvBC,gBAAgB,EAAE,IAAI;EACtBC,gBAAgB,EAAE,IAAI;EACtBC,OAAO,EAAE,IAAI;EACbC,YAAY,EAAE,IAAI;EAClBC,eAAe,EAAE,IAAI;EACrBC,WAAW,EAAE,IAAI;EACjBC,OAAO,EAAE,IAAI;EACbC,IAAI,EAAE,IAAI;EACVC,QAAQ,EAAE,IAAI;EACdC,YAAY,EAAE,IAAI;EAClBC,UAAU,EAAE,IAAI;EAChBC,YAAY,EAAE,IAAI;EAClBC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE,IAAI;EACbC,UAAU,EAAE,IAAI;EAChBC,WAAW,EAAE,IAAI;EACjBC,YAAY,EAAE,IAAI;EAClBC,UAAU,EAAE,IAAI;EAChBC,aAAa,EAAE,IAAI;EACnBC,cAAc,EAAE,IAAI;EACpBC,eAAe,EAAE,IAAI;EACrBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE,IAAI;EACfC,UAAU,EAAE,IAAI;EAChBC,OAAO,EAAE,IAAI;EACbC,KAAK,EAAE,IAAI;EACXC,OAAO,EAAE,IAAI;EACbC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,IAAI,EAAE,IAAI;EAEV;EACAC,WAAW,EAAE,IAAI;EACjBC,YAAY,EAAE,IAAI;EAClBC,WAAW,EAAE,IAAI;EACjBC,eAAe,EAAE,IAAI;EACrBC,gBAAgB,EAAE,IAAI;EACtBC,gBAAgB,EAAE,IAAI;EACtBC,aAAa,EAAE,IAAI;EACnBC,WAAW,EAAE;AACf,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isValidParams = isValidParams;
7
+ exports.validateParams = validateParams;
8
+ // ParamMapping maps each ParamName to its corresponding Param type.
9
+
10
+ // GetParamByName returns the Param type based on the input type T.
11
+
12
+ // If T is none of the above, return never.
13
+
14
+ // MapParams iteratively maps the input ParamConstraints to their corresponding Param types.
15
+
16
+ // If TNames is an empty tuple, return the result tuple.
17
+
18
+ function isValidParams(params, constraints) {
19
+ const length = Math.max(params.length, constraints.length);
20
+ for (let i = 0; i < length; i++) {
21
+ var _params$i2;
22
+ if (params[i] === undefined || constraints[i] === undefined) {
23
+ return false;
24
+ }
25
+ const constraint = constraints[i];
26
+ if (constraint === '...') {
27
+ return true;
28
+ }
29
+ if (constraint === '*') {
30
+ if (params[i] === undefined) {
31
+ return false;
32
+ }
33
+ } else if (Array.isArray(constraint)) {
34
+ if (constraint.every(c => {
35
+ var _params$i;
36
+ return c !== ((_params$i = params[i]) === null || _params$i === void 0 ? void 0 : _params$i[0]);
37
+ })) {
38
+ return false;
39
+ }
40
+ } else if (constraint !== ((_params$i2 = params[i]) === null || _params$i2 === void 0 ? void 0 : _params$i2[0])) {
41
+ return false;
42
+ }
43
+ }
44
+ return true;
45
+ }
46
+ function validateParams(params, constraints, messageOrError) {
47
+ if (!isValidParams(params, constraints)) {
48
+ if (typeof messageOrError === 'string') {
49
+ throw new Error(messageOrError);
50
+ }
51
+ throw messageOrError;
52
+ }
53
+ }
54
+ //# sourceMappingURL=validateParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateParams.js","names":["isValidParams","params","constraints","length","Math","max","i","_params$i2","undefined","constraint","Array","isArray","every","c","_params$i","validateParams","messageOrError","Error"],"sources":["../../src/utils/validateParams.ts"],"sourcesContent":["import type { Param, Params } from '../types';\n\ntype ParamName = Param[0];\ntype ParamConstraint = ParamName | [...ParamName[]] | '*';\n\nexport type ParamConstraints =\n | [...ParamConstraint[]]\n | [...ParamConstraint[], '...'];\n\n// ParamMapping maps each ParamName to its corresponding Param type.\ntype ParamMapping = {\n [K in ParamName]: Extract<Param, readonly [K, ...unknown[]]>; // For each ParamName K, extract the corresponding Param type.\n};\n\n// GetParamByName returns the Param type based on the input type T.\ntype GetParamByName<T> = T extends '*'\n ? Param // If T is '*', return Param type.\n : T extends keyof ParamMapping // If T is a key in ParamMapping (i.e., a ParamName).\n ? ParamMapping[T] // Return the corresponding Param type from ParamMapping.\n : T extends Array<infer TNames> // If T is an array of names.\n ? TNames extends ParamName // If TNames is a ParamName.\n ? Extract<Param, readonly [TNames, ...unknown[]]> // Return the corresponding Param type.\n : never // If TNames is not a ParamName, return never.\n : never; // If T is none of the above, return never.\n\n// MapParams iteratively maps the input ParamConstraints to their corresponding Param types.\nexport type MapParams<\n TNames extends ParamConstraints,\n TRes extends Param[] = [],\n> = TNames extends [infer THead, ...infer TTail] // If TNames is a non-empty tuple.\n ? THead extends '...' // If the first element in the tuple is '...'.\n ? [...TRes, ...Params] // Append all Params to the result tuple.\n : MapParams<\n Extract<TTail, ParamConstraints>, // Extract the remaining ParamConstraints.\n [...TRes, GetParamByName<Extract<THead, ParamName | '*' | ParamName[]>>] // Append the mapped Param to the result tuple and recurse.\n >\n : TRes; // If TNames is an empty tuple, return the result tuple.\n\nexport function isValidParams<T extends ParamConstraints>(\n params: Params,\n constraints: T\n): params is MapParams<T> {\n const length = Math.max(params.length, constraints.length);\n for (let i = 0; i < length; i++) {\n if (params[i] === undefined || constraints[i] === undefined) {\n return false;\n }\n\n const constraint = constraints[i];\n if (constraint === '...') {\n return true;\n }\n\n if (constraint === '*') {\n if (params[i] === undefined) {\n return false;\n }\n } else if (Array.isArray(constraint)) {\n if (constraint.every((c) => c !== params[i]?.[0])) {\n return false;\n }\n } else if (constraint !== params[i]?.[0]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function validateParams<T extends ParamConstraints>(\n params: Params,\n constraints: T,\n messageOrError: unknown\n): asserts params is MapParams<T> {\n if (!isValidParams(params, constraints)) {\n if (typeof messageOrError === 'string') {\n throw new Error(messageOrError);\n }\n\n throw messageOrError;\n }\n}\n"],"mappings":";;;;;;;AASA;;AAKA;;AASW;;AAEX;;AAWU;;AAEH,SAASA,aAAaA,CAC3BC,MAAc,EACdC,WAAc,EACU;EACxB,MAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,CAACJ,MAAM,CAACE,MAAM,EAAED,WAAW,CAACC,MAAM,CAAC;EAC1D,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,EAAEG,CAAC,EAAE,EAAE;IAAA,IAAAC,UAAA;IAC/B,IAAIN,MAAM,CAACK,CAAC,CAAC,KAAKE,SAAS,IAAIN,WAAW,CAACI,CAAC,CAAC,KAAKE,SAAS,EAAE;MAC3D,OAAO,KAAK;IACd;IAEA,MAAMC,UAAU,GAAGP,WAAW,CAACI,CAAC,CAAC;IACjC,IAAIG,UAAU,KAAK,KAAK,EAAE;MACxB,OAAO,IAAI;IACb;IAEA,IAAIA,UAAU,KAAK,GAAG,EAAE;MACtB,IAAIR,MAAM,CAACK,CAAC,CAAC,KAAKE,SAAS,EAAE;QAC3B,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,EAAE;MACpC,IAAIA,UAAU,CAACG,KAAK,CAAEC,CAAC;QAAA,IAAAC,SAAA;QAAA,OAAKD,CAAC,OAAAC,SAAA,GAAKb,MAAM,CAACK,CAAC,CAAC,cAAAQ,SAAA,uBAATA,SAAA,CAAY,CAAC,CAAC;MAAA,EAAC,EAAE;QACjD,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIL,UAAU,OAAAF,UAAA,GAAKN,MAAM,CAACK,CAAC,CAAC,cAAAC,UAAA,uBAATA,UAAA,CAAY,CAAC,CAAC,GAAE;MACxC,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAI;AACb;AAEO,SAASQ,cAAcA,CAC5Bd,MAAc,EACdC,WAAc,EACdc,cAAuB,EACS;EAChC,IAAI,CAAChB,aAAa,CAACC,MAAM,EAAEC,WAAW,CAAC,EAAE;IACvC,IAAI,OAAOc,cAAc,KAAK,QAAQ,EAAE;MACtC,MAAM,IAAIC,KAAK,CAACD,cAAc,CAAC;IACjC;IAEA,MAAMA,cAAc;EACtB;AACF"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@wyw-in-js/processor-utils",
3
+ "version": "0.1.0",
4
+ "dependencies": {
5
+ "@babel/generator": "^7.23.0",
6
+ "@wyw-in-js/shared": "0.1.0"
7
+ },
8
+ "devDependencies": {
9
+ "@babel/types": "^7.23.0",
10
+ "@types/babel__core": "^7.20.2",
11
+ "@types/babel__generator": "^7.6.5",
12
+ "@types/node": "^16.18.55",
13
+ "typescript": "^5.2.2",
14
+ "@wyw-in-js/babel-config": "0.1.0",
15
+ "@wyw-in-js/eslint-config": "0.1.0",
16
+ "@wyw-in-js/ts-config": "0.1.0"
17
+ },
18
+ "engines": {
19
+ "node": ">=16.0.0"
20
+ },
21
+ "files": [
22
+ "types/",
23
+ "lib/",
24
+ "esm/"
25
+ ],
26
+ "license": "MIT",
27
+ "main": "lib/index.js",
28
+ "module": "esm/index.js",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "types": "types/index.d.ts",
33
+ "scripts": {
34
+ "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
35
+ "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
36
+ "build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
37
+ "lint": "eslint --ext .js,.ts .",
38
+ "test": "jest --config ./jest.config.js --rootDir src"
39
+ }
40
+ }
@@ -0,0 +1,66 @@
1
+ import type { types as t } from '@babel/core';
2
+ import type { Expression, Identifier, SourceLocation, MemberExpression } from '@babel/types';
3
+ import type { Artifact, ExpressionValue } from '@wyw-in-js/shared';
4
+ import type { IInterpolation, Params, Value, ValueCache } from './types';
5
+ import type { IFileContext, IOptions } from './utils/types';
6
+ export { Expression };
7
+ export type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;
8
+ export type TailProcessorParams = ProcessorParams extends [Params, ...infer T] ? T : never;
9
+ export type TagSource = {
10
+ imported: string;
11
+ source: string;
12
+ };
13
+ export declare abstract class BaseProcessor {
14
+ tagSource: TagSource;
15
+ protected readonly astService: typeof t & {
16
+ addDefaultImport: (source: string, nameHint?: string) => Identifier;
17
+ addNamedImport: (name: string, source: string, nameHint?: string) => Identifier;
18
+ };
19
+ readonly location: SourceLocation | null;
20
+ protected readonly replacer: (replacement: Expression, isPure: boolean) => void;
21
+ readonly displayName: string;
22
+ readonly isReferenced: boolean;
23
+ protected readonly idx: number;
24
+ protected readonly options: IOptions;
25
+ protected readonly context: IFileContext;
26
+ static SKIP: symbol;
27
+ readonly artifacts: Artifact[];
28
+ readonly className: string;
29
+ readonly dependencies: ExpressionValue[];
30
+ interpolations: IInterpolation[];
31
+ readonly slug: string;
32
+ protected callee: Identifier | MemberExpression;
33
+ protected evaluated: Record<'dependencies' | 'expression', Value[]> | undefined;
34
+ constructor(params: Params, tagSource: TagSource, astService: typeof t & {
35
+ addDefaultImport: (source: string, nameHint?: string) => Identifier;
36
+ addNamedImport: (name: string, source: string, nameHint?: string) => Identifier;
37
+ }, location: SourceLocation | null, replacer: (replacement: Expression, isPure: boolean) => void, displayName: string, isReferenced: boolean, idx: number, options: IOptions, context: IFileContext);
38
+ /**
39
+ * A replacement for tag referenced in a template literal.
40
+ */
41
+ abstract get asSelector(): string;
42
+ /**
43
+ * A replacement for the tag in evaluation time.
44
+ * For example, `css` tag will be replaced with its className,
45
+ * whereas `styled` tag will be replaced with an object with metadata.
46
+ */
47
+ abstract get value(): Expression;
48
+ isValidValue(value: unknown): value is Value;
49
+ toString(): string;
50
+ protected tagSourceCode(): string;
51
+ abstract build(values: ValueCache): void;
52
+ /**
53
+ * Perform a replacement for the tag in evaluation time.
54
+ * For example, `css` tag will be replaced with its className,
55
+ * whereas `styled` tag will be replaced with an object with metadata.
56
+ */
57
+ abstract doEvaltimeReplacement(): void;
58
+ /**
59
+ * Perform a replacement for the tag with its runtime version.
60
+ * For example, `css` tag will be replaced with its className,
61
+ * whereas `styled` tag will be replaced with a component.
62
+ * If some parts require evaluated data for render,
63
+ * they will be replaced with placeholders.
64
+ */
65
+ abstract doRuntimeReplacement(): void;
66
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseProcessor = void 0;
7
+ const generator_1 = __importDefault(require("@babel/generator"));
8
+ const shared_1 = require("@wyw-in-js/shared");
9
+ const getClassNameAndSlug_1 = __importDefault(require("./utils/getClassNameAndSlug"));
10
+ const toCSS_1 = require("./utils/toCSS");
11
+ const validateParams_1 = require("./utils/validateParams");
12
+ class BaseProcessor {
13
+ tagSource;
14
+ astService;
15
+ location;
16
+ replacer;
17
+ displayName;
18
+ isReferenced;
19
+ idx;
20
+ options;
21
+ context;
22
+ static SKIP = Symbol('skip');
23
+ artifacts = [];
24
+ className;
25
+ dependencies = [];
26
+ interpolations = [];
27
+ slug;
28
+ callee;
29
+ evaluated;
30
+ constructor(params, tagSource, astService, location, replacer, displayName, isReferenced, idx, options, context) {
31
+ this.tagSource = tagSource;
32
+ this.astService = astService;
33
+ this.location = location;
34
+ this.replacer = replacer;
35
+ this.displayName = displayName;
36
+ this.isReferenced = isReferenced;
37
+ this.idx = idx;
38
+ this.options = options;
39
+ this.context = context;
40
+ (0, validateParams_1.validateParams)(params, ['callee'], 'Unknown error: a callee param is not specified');
41
+ const { className, slug } = (0, getClassNameAndSlug_1.default)(this.displayName, this.idx, this.options, this.context);
42
+ this.className = className;
43
+ this.slug = slug;
44
+ [[, this.callee]] = params;
45
+ }
46
+ isValidValue(value) {
47
+ return (typeof value === 'function' || (0, toCSS_1.isCSSable)(value) || (0, shared_1.hasEvalMeta)(value));
48
+ }
49
+ toString() {
50
+ return this.tagSourceCode();
51
+ }
52
+ tagSourceCode() {
53
+ if (this.callee.type === 'Identifier') {
54
+ return this.callee.name;
55
+ }
56
+ return (0, generator_1.default)(this.callee).code;
57
+ }
58
+ }
59
+ exports.BaseProcessor = BaseProcessor;
@@ -0,0 +1,20 @@
1
+ import type { Expression, SourceLocation } from '@babel/types';
2
+ import type { TailProcessorParams } from './BaseProcessor';
3
+ import { BaseProcessor } from './BaseProcessor';
4
+ import type { ValueCache, Rules, Params } from './types';
5
+ export declare abstract class TaggedTemplateProcessor extends BaseProcessor {
6
+ #private;
7
+ protected constructor(params: Params, ...args: TailProcessorParams);
8
+ build(values: ValueCache): void;
9
+ toString(): string;
10
+ /**
11
+ * It is called for each resolved expression in a template literal.
12
+ * @param node
13
+ * @param precedingCss
14
+ * @param source
15
+ * @param unit
16
+ * @return chunk of CSS that should be added to extracted CSS
17
+ */
18
+ abstract addInterpolation(node: Expression, precedingCss: string, source: string, unit?: string): string;
19
+ abstract extractRules(valueCache: ValueCache, cssText: string, loc?: SourceLocation | null): Rules;
20
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TaggedTemplateProcessor = void 0;
7
+ const shared_1 = require("@wyw-in-js/shared");
8
+ const BaseProcessor_1 = require("./BaseProcessor");
9
+ const templateProcessor_1 = __importDefault(require("./utils/templateProcessor"));
10
+ const validateParams_1 = require("./utils/validateParams");
11
+ class TaggedTemplateProcessor extends BaseProcessor_1.BaseProcessor {
12
+ #template;
13
+ constructor(params, ...args) {
14
+ // Should have at least two params and the first one should be a callee.
15
+ (0, validateParams_1.validateParams)(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);
16
+ (0, validateParams_1.validateParams)(params, ['callee', 'template'], 'Invalid usage of template tag');
17
+ const [tag, [, template]] = params;
18
+ super([tag], ...args);
19
+ template.forEach((element) => {
20
+ if ('kind' in element && element.kind !== shared_1.ValueType.FUNCTION) {
21
+ this.dependencies.push(element);
22
+ }
23
+ });
24
+ this.#template = template;
25
+ }
26
+ build(values) {
27
+ if (this.artifacts.length > 0) {
28
+ // FIXME: why it was called twice?
29
+ throw new Error('Tag is already built');
30
+ }
31
+ const artifact = (0, templateProcessor_1.default)(this, this.#template, values, this.options.variableNameConfig);
32
+ if (artifact) {
33
+ this.artifacts.push(['css', artifact]);
34
+ }
35
+ }
36
+ toString() {
37
+ return `${super.toString()}\`…\``;
38
+ }
39
+ }
40
+ exports.TaggedTemplateProcessor = TaggedTemplateProcessor;
@@ -0,0 +1,9 @@
1
+ export { BaseProcessor } from './BaseProcessor';
2
+ export type { Expression, TagSource, ProcessorParams, TailProcessorParams, } from './BaseProcessor';
3
+ export * from './types';
4
+ export { buildSlug } from './utils/buildSlug';
5
+ export type { IOptions, IFileContext } from './utils/types';
6
+ export { isValidParams, validateParams } from './utils/validateParams';
7
+ export type { MapParams, ParamConstraints } from './utils/validateParams';
8
+ export { TaggedTemplateProcessor } from './TaggedTemplateProcessor';
9
+ export { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';
package/types/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.toValidCSSIdentifier = exports.TaggedTemplateProcessor = exports.validateParams = exports.isValidParams = exports.buildSlug = exports.BaseProcessor = void 0;
18
+ var BaseProcessor_1 = require("./BaseProcessor");
19
+ Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return BaseProcessor_1.BaseProcessor; } });
20
+ __exportStar(require("./types"), exports);
21
+ var buildSlug_1 = require("./utils/buildSlug");
22
+ Object.defineProperty(exports, "buildSlug", { enumerable: true, get: function () { return buildSlug_1.buildSlug; } });
23
+ var validateParams_1 = require("./utils/validateParams");
24
+ Object.defineProperty(exports, "isValidParams", { enumerable: true, get: function () { return validateParams_1.isValidParams; } });
25
+ Object.defineProperty(exports, "validateParams", { enumerable: true, get: function () { return validateParams_1.validateParams; } });
26
+ var TaggedTemplateProcessor_1 = require("./TaggedTemplateProcessor");
27
+ Object.defineProperty(exports, "TaggedTemplateProcessor", { enumerable: true, get: function () { return TaggedTemplateProcessor_1.TaggedTemplateProcessor; } });
28
+ var toValidCSSIdentifier_1 = require("./utils/toValidCSSIdentifier");
29
+ Object.defineProperty(exports, "toValidCSSIdentifier", { enumerable: true, get: function () { return toValidCSSIdentifier_1.toValidCSSIdentifier; } });
@@ -0,0 +1,32 @@
1
+ import type { Expression, Identifier, TemplateElement, MemberExpression } from '@babel/types';
2
+ import type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';
3
+ export type CSSPropertyValue = string | number;
4
+ export type ObjectWithSelectors = {
5
+ [key: string]: ObjectWithSelectors | CSSPropertyValue | (ObjectWithSelectors | CSSPropertyValue)[];
6
+ };
7
+ export type CSSable = ObjectWithSelectors[string];
8
+ export type Value = (() => void) | WYWEvalMeta | CSSable;
9
+ export type ValueCache = Map<string | number | boolean | null, unknown>;
10
+ export interface ICSSRule {
11
+ atom?: boolean;
12
+ className: string;
13
+ cssText: string;
14
+ displayName: string;
15
+ start: Location | null | undefined;
16
+ }
17
+ export interface IInterpolation {
18
+ id: string;
19
+ node: Expression;
20
+ source: string;
21
+ unit: string;
22
+ }
23
+ export type Rules = Record<string, ICSSRule>;
24
+ export type CalleeParam = readonly ['callee', Identifier | MemberExpression];
25
+ export type CallParam = readonly ['call', ...ExpressionValue[]];
26
+ export type MemberParam = readonly ['member', string];
27
+ export type TemplateParam = readonly [
28
+ 'template',
29
+ (TemplateElement | ExpressionValue)[]
30
+ ];
31
+ export type Param = CalleeParam | CallParam | MemberParam | TemplateParam;
32
+ export type Params = readonly Param[];
package/types/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare function buildSlug<TArgs extends Record<string, {
2
+ toString(): string;
3
+ }>>(pattern: string, args: TArgs): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSlug = void 0;
4
+ const PLACEHOLDER = /\[(.*?)]/g;
5
+ const isValidArgName = (key, args) => key in args;
6
+ function buildSlug(pattern, args) {
7
+ return pattern.replace(PLACEHOLDER, (_, name) => isValidArgName(name, args) ? args[name].toString() : '');
8
+ }
9
+ exports.buildSlug = buildSlug;
@@ -0,0 +1,5 @@
1
+ import type { IFileContext, IOptions } from './types';
2
+ export default function getClassNameAndSlug(displayName: string, idx: number, options: IOptions, context: IFileContext): {
3
+ className: string;
4
+ slug: string;
5
+ };