@wyw-in-js/shared 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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/esm/IVariableContext.js +2 -0
  3. package/esm/IVariableContext.js.map +1 -0
  4. package/esm/asyncResolveFallback.js +38 -0
  5. package/esm/asyncResolveFallback.js.map +1 -0
  6. package/esm/babel.js +2 -0
  7. package/esm/babel.js.map +1 -0
  8. package/esm/hasEvalMeta.js +4 -0
  9. package/esm/hasEvalMeta.js.map +1 -0
  10. package/esm/index.js +9 -0
  11. package/esm/index.js.map +1 -0
  12. package/esm/isBoxedPrimitive.js +9 -0
  13. package/esm/isBoxedPrimitive.js.map +1 -0
  14. package/esm/logger.js +26 -0
  15. package/esm/logger.js.map +1 -0
  16. package/esm/options/isFeatureEnabled.js +30 -0
  17. package/esm/options/isFeatureEnabled.js.map +1 -0
  18. package/esm/options/types.js +2 -0
  19. package/esm/options/types.js.map +1 -0
  20. package/esm/slugify.js +62 -0
  21. package/esm/slugify.js.map +1 -0
  22. package/esm/types.js +11 -0
  23. package/esm/types.js.map +1 -0
  24. package/lib/IVariableContext.js +2 -0
  25. package/lib/IVariableContext.js.map +1 -0
  26. package/lib/asyncResolveFallback.js +47 -0
  27. package/lib/asyncResolveFallback.js.map +1 -0
  28. package/lib/babel.js +2 -0
  29. package/lib/babel.js.map +1 -0
  30. package/lib/hasEvalMeta.js +10 -0
  31. package/lib/hasEvalMeta.js.map +1 -0
  32. package/lib/index.js +74 -0
  33. package/lib/index.js.map +1 -0
  34. package/lib/isBoxedPrimitive.js +15 -0
  35. package/lib/isBoxedPrimitive.js.map +1 -0
  36. package/lib/logger.js +35 -0
  37. package/lib/logger.js.map +1 -0
  38. package/lib/options/isFeatureEnabled.js +37 -0
  39. package/lib/options/isFeatureEnabled.js.map +1 -0
  40. package/lib/options/types.js +2 -0
  41. package/lib/options/types.js.map +1 -0
  42. package/lib/slugify.js +68 -0
  43. package/lib/slugify.js.map +1 -0
  44. package/lib/types.js +16 -0
  45. package/lib/types.js.map +1 -0
  46. package/package.json +40 -0
  47. package/types/IVariableContext.d.ts +10 -0
  48. package/types/IVariableContext.js +2 -0
  49. package/types/asyncResolveFallback.d.ts +2 -0
  50. package/types/asyncResolveFallback.js +45 -0
  51. package/types/babel.d.ts +2 -0
  52. package/types/babel.js +2 -0
  53. package/types/hasEvalMeta.d.ts +2 -0
  54. package/types/hasEvalMeta.js +7 -0
  55. package/types/index.d.ts +10 -0
  56. package/types/index.js +19 -0
  57. package/types/isBoxedPrimitive.d.ts +1 -0
  58. package/types/isBoxedPrimitive.js +13 -0
  59. package/types/logger.d.ts +3 -0
  60. package/types/logger.js +33 -0
  61. package/types/options/isFeatureEnabled.d.ts +4 -0
  62. package/types/options/isFeatureEnabled.js +30 -0
  63. package/types/options/types.d.ts +57 -0
  64. package/types/options/types.js +2 -0
  65. package/types/slugify.d.ts +4 -0
  66. package/types/slugify.js +66 -0
  67. package/types/types.d.ts +59 -0
  68. package/types/types.js +9 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Anton Evzhakov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IVariableContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IVariableContext.js","names":[],"sources":["../src/IVariableContext.ts"],"sourcesContent":["export interface IVariableContext {\n componentName: string;\n componentSlug: string;\n index: number;\n precedingCss: string;\n processor: string;\n source: string;\n unit: string;\n valueSlug: string;\n}\n"],"mappings":""}
@@ -0,0 +1,38 @@
1
+ import path from 'path';
2
+ const safeResolve = (name, where) => {
3
+ try {
4
+ return require.resolve(name, {
5
+ paths: where
6
+ });
7
+ } catch (e) {
8
+ return e;
9
+ }
10
+ };
11
+ const suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc, ext) => {
12
+ acc.push(`/index${ext}`);
13
+ acc.push(ext);
14
+ return acc;
15
+ }, []);
16
+ export const syncResolve = (what, importer, stack) => {
17
+ const where = [importer, ...stack].map(p => path.dirname(p));
18
+ const resolved = safeResolve(what, where);
19
+ if (!(resolved instanceof Error)) {
20
+ return resolved;
21
+ }
22
+
23
+ // eslint-disable-next-line no-restricted-syntax
24
+ for (const suffix of suffixes) {
25
+ const resolvedWithSuffix = safeResolve(what + suffix, where);
26
+ if (resolvedWithSuffix instanceof Error) {
27
+ // eslint-disable-next-line no-continue
28
+ continue;
29
+ }
30
+ return resolvedWithSuffix;
31
+ }
32
+ throw resolved;
33
+ };
34
+ export const asyncResolveFallback = (what, importer, stack) => {
35
+ const resolved = syncResolve(what, importer, stack);
36
+ return Promise.resolve(resolved);
37
+ };
38
+ //# sourceMappingURL=asyncResolveFallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncResolveFallback.js","names":["path","safeResolve","name","where","require","resolve","paths","e","suffixes","reduce","acc","ext","push","syncResolve","what","importer","stack","map","p","dirname","resolved","Error","suffix","resolvedWithSuffix","asyncResolveFallback","Promise"],"sources":["../src/asyncResolveFallback.ts"],"sourcesContent":["import path from 'path';\n\nconst safeResolve = (name: string, where: string[]): string | Error => {\n try {\n return require.resolve(name, {\n paths: where,\n });\n } catch (e: unknown) {\n return e as Error;\n }\n};\n\nconst suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc: string[], ext) => {\n acc.push(`/index${ext}`);\n acc.push(ext);\n return acc;\n}, []);\n\nexport const syncResolve = (\n what: string,\n importer: string,\n stack: string[]\n): string => {\n const where = [importer, ...stack].map((p) => path.dirname(p));\n const resolved = safeResolve(what, where);\n if (!(resolved instanceof Error)) {\n return resolved;\n }\n\n // eslint-disable-next-line no-restricted-syntax\n for (const suffix of suffixes) {\n const resolvedWithSuffix = safeResolve(what + suffix, where);\n if (resolvedWithSuffix instanceof Error) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n return resolvedWithSuffix;\n }\n\n throw resolved;\n};\n\nexport const asyncResolveFallback = (\n what: string,\n importer: string,\n stack: string[]\n): Promise<string> => {\n const resolved = syncResolve(what, importer, stack);\n return Promise.resolve(resolved);\n};\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,MAAMC,WAAW,GAAGA,CAACC,IAAY,EAAEC,KAAe,KAAqB;EACrE,IAAI;IACF,OAAOC,OAAO,CAACC,OAAO,CAACH,IAAI,EAAE;MAC3BI,KAAK,EAAEH;IACT,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOI,CAAU,EAAE;IACnB,OAAOA,CAAC;EACV;AACF,CAAC;AAED,MAAMC,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAACC,MAAM,CAAC,CAACC,GAAa,EAAEC,GAAG,KAAK;EAC7ED,GAAG,CAACE,IAAI,CAAE,SAAQD,GAAI,EAAC,CAAC;EACxBD,GAAG,CAACE,IAAI,CAACD,GAAG,CAAC;EACb,OAAOD,GAAG;AACZ,CAAC,EAAE,EAAE,CAAC;AAEN,OAAO,MAAMG,WAAW,GAAGA,CACzBC,IAAY,EACZC,QAAgB,EAChBC,KAAe,KACJ;EACX,MAAMb,KAAK,GAAG,CAACY,QAAQ,EAAE,GAAGC,KAAK,CAAC,CAACC,GAAG,CAAEC,CAAC,IAAKlB,IAAI,CAACmB,OAAO,CAACD,CAAC,CAAC,CAAC;EAC9D,MAAME,QAAQ,GAAGnB,WAAW,CAACa,IAAI,EAAEX,KAAK,CAAC;EACzC,IAAI,EAAEiB,QAAQ,YAAYC,KAAK,CAAC,EAAE;IAChC,OAAOD,QAAQ;EACjB;;EAEA;EACA,KAAK,MAAME,MAAM,IAAId,QAAQ,EAAE;IAC7B,MAAMe,kBAAkB,GAAGtB,WAAW,CAACa,IAAI,GAAGQ,MAAM,EAAEnB,KAAK,CAAC;IAC5D,IAAIoB,kBAAkB,YAAYF,KAAK,EAAE;MACvC;MACA;IACF;IAEA,OAAOE,kBAAkB;EAC3B;EAEA,MAAMH,QAAQ;AAChB,CAAC;AAED,OAAO,MAAMI,oBAAoB,GAAGA,CAClCV,IAAY,EACZC,QAAgB,EAChBC,KAAe,KACK;EACpB,MAAMI,QAAQ,GAAGP,WAAW,CAACC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,CAAC;EACnD,OAAOS,OAAO,CAACpB,OAAO,CAACe,QAAQ,CAAC;AAClC,CAAC"}
package/esm/babel.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=babel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.js","names":[],"sources":["../src/babel.ts"],"sourcesContent":["import type core from '@babel/core';\n\nexport type Core = typeof core;\n"],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export function hasEvalMeta(value) {
2
+ return typeof value === 'object' && value !== null && '__wyw_meta' in value;
3
+ }
4
+ //# sourceMappingURL=hasEvalMeta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasEvalMeta.js","names":["hasEvalMeta","value"],"sources":["../src/hasEvalMeta.ts"],"sourcesContent":["import type { WYWEvalMeta } from './types';\n\nexport function hasEvalMeta(value: unknown): value is WYWEvalMeta {\n return typeof value === 'object' && value !== null && '__wyw_meta' in value;\n}\n"],"mappings":"AAEA,OAAO,SAASA,WAAWA,CAACC,KAAc,EAAwB;EAChE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,IAAI,YAAY,IAAIA,KAAK;AAC7E"}
package/esm/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { Debugger } from 'debug';
2
+ export { asyncResolveFallback, syncResolve } from './asyncResolveFallback';
3
+ export { hasEvalMeta } from './hasEvalMeta';
4
+ export { isBoxedPrimitive } from './isBoxedPrimitive';
5
+ export { enableDebug, logger } from './logger';
6
+ export { isFeatureEnabled } from './options/isFeatureEnabled';
7
+ export { slugify } from './slugify';
8
+ export { ValueType } from './types';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Debugger","asyncResolveFallback","syncResolve","hasEvalMeta","isBoxedPrimitive","enableDebug","logger","isFeatureEnabled","slugify","ValueType"],"sources":["../src/index.ts"],"sourcesContent":["export { Debugger } from 'debug';\n\nexport { asyncResolveFallback, syncResolve } from './asyncResolveFallback';\nexport { hasEvalMeta } from './hasEvalMeta';\nexport { isBoxedPrimitive } from './isBoxedPrimitive';\nexport { enableDebug, logger } from './logger';\nexport { isFeatureEnabled } from './options/isFeatureEnabled';\nexport { slugify } from './slugify';\nexport { ValueType } from './types';\n\nexport type {\n ClassNameSlugVars,\n ClassNameFn,\n StrictOptions,\n EvalRule,\n Evaluator,\n FeatureFlag,\n EvaluatorConfig,\n FeatureFlags,\n VariableNameFn,\n} from './options/types';\nexport type {\n Artifact,\n BuildCodeFrameErrorFn,\n ConstValue,\n ExpressionValue,\n FunctionValue,\n ICSSRule,\n LazyValue,\n Location,\n Replacement,\n Replacements,\n Rules,\n WYWEvalMeta,\n} from './types';\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,OAAO;AAEhC,SAASC,oBAAoB,EAAEC,WAAW,QAAQ,wBAAwB;AAC1E,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,WAAW,EAAEC,MAAM,QAAQ,UAAU;AAC9C,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,SAAS,QAAQ,SAAS"}
@@ -0,0 +1,9 @@
1
+ // There is a problem with using boxed numbers and strings in TS,
2
+ // so we cannot just use `instanceof` here
3
+
4
+ const constructors = ['Number', 'String'];
5
+ export function isBoxedPrimitive(o) {
6
+ if (typeof o !== 'object' || o === null) return false;
7
+ return constructors.includes(o.constructor.name) && typeof o?.valueOf() !== 'object';
8
+ }
9
+ //# sourceMappingURL=isBoxedPrimitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isBoxedPrimitive.js","names":["constructors","isBoxedPrimitive","o","includes","constructor","name","valueOf"],"sources":["../src/isBoxedPrimitive.ts"],"sourcesContent":["// There is a problem with using boxed numbers and strings in TS,\n// so we cannot just use `instanceof` here\n\nconst constructors = ['Number', 'String'];\nexport function isBoxedPrimitive(o: unknown): o is number | string {\n if (typeof o !== 'object' || o === null) return false;\n return (\n constructors.includes(o.constructor.name) &&\n typeof o?.valueOf() !== 'object'\n );\n}\n"],"mappings":"AAAA;AACA;;AAEA,MAAMA,YAAY,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACzC,OAAO,SAASC,gBAAgBA,CAACC,CAAU,EAAwB;EACjE,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,KAAK,IAAI,EAAE,OAAO,KAAK;EACrD,OACEF,YAAY,CAACG,QAAQ,CAACD,CAAC,CAACE,WAAW,CAACC,IAAI,CAAC,IACzC,OAAOH,CAAC,EAAEI,OAAO,CAAC,CAAC,KAAK,QAAQ;AAEpC"}
package/esm/logger.js ADDED
@@ -0,0 +1,26 @@
1
+ import genericDebug from 'debug';
2
+ const BASE_NAMESPACE = 'wyw-in-js';
3
+ export const logger = genericDebug(BASE_NAMESPACE);
4
+ const loggers = new Map();
5
+ function gerOrCreate(namespace) {
6
+ if (!namespace) return logger;
7
+ const lastIndexOf = namespace.lastIndexOf(':');
8
+ if (!loggers.has(namespace)) {
9
+ loggers.set(namespace, gerOrCreate(namespace.substring(0, lastIndexOf)).extend(namespace.substring(lastIndexOf + 1)));
10
+ }
11
+ return loggers.get(namespace);
12
+ }
13
+ genericDebug.formatters.r = ref => {
14
+ const namespace = typeof ref === 'string' ? ref : ref.namespace;
15
+ const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;
16
+ const color = parseInt(gerOrCreate(namespace).color, 10);
17
+ const colorCode = `\u001B[3${color < 8 ? color : `8;5;${color}`}`;
18
+ return `${colorCode};1m${text}\u001B[0m`;
19
+ };
20
+ genericDebug.formatters.f = function f(fn) {
21
+ return JSON.stringify(fn());
22
+ };
23
+ export function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
24
+ genericDebug.enable(namespace);
25
+ }
26
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","names":["genericDebug","BASE_NAMESPACE","logger","loggers","Map","gerOrCreate","namespace","lastIndexOf","has","set","substring","extend","get","formatters","r","ref","text","color","parseInt","colorCode","f","fn","JSON","stringify","enableDebug","enable"],"sources":["../src/logger.ts"],"sourcesContent":["import genericDebug from 'debug';\nimport type { Debugger } from 'debug';\n\nconst BASE_NAMESPACE = 'wyw-in-js';\n\nexport const logger = genericDebug(BASE_NAMESPACE);\n\nconst loggers = new Map<string, Debugger>();\n\nfunction gerOrCreate(namespace: string | null | undefined): Debugger {\n if (!namespace) return logger;\n const lastIndexOf = namespace.lastIndexOf(':');\n if (!loggers.has(namespace)) {\n loggers.set(\n namespace,\n gerOrCreate(namespace.substring(0, lastIndexOf)).extend(\n namespace.substring(lastIndexOf + 1)\n )\n );\n }\n\n return loggers.get(namespace)!;\n}\n\ngenericDebug.formatters.r = (\n ref: string | { namespace: string; text?: string }\n) => {\n const namespace = typeof ref === 'string' ? ref : ref.namespace;\n const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;\n const color = parseInt(gerOrCreate(namespace).color, 10);\n const colorCode = `\\u001B[3${color < 8 ? color : `8;5;${color}`}`;\n return `${colorCode};1m${text}\\u001B[0m`;\n};\n\ngenericDebug.formatters.f = function f(fn: () => unknown) {\n return JSON.stringify(fn());\n};\n\nexport function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {\n genericDebug.enable(namespace);\n}\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,OAAO;AAGhC,MAAMC,cAAc,GAAG,WAAW;AAElC,OAAO,MAAMC,MAAM,GAAGF,YAAY,CAACC,cAAc,CAAC;AAElD,MAAME,OAAO,GAAG,IAAIC,GAAG,CAAmB,CAAC;AAE3C,SAASC,WAAWA,CAACC,SAAoC,EAAY;EACnE,IAAI,CAACA,SAAS,EAAE,OAAOJ,MAAM;EAC7B,MAAMK,WAAW,GAAGD,SAAS,CAACC,WAAW,CAAC,GAAG,CAAC;EAC9C,IAAI,CAACJ,OAAO,CAACK,GAAG,CAACF,SAAS,CAAC,EAAE;IAC3BH,OAAO,CAACM,GAAG,CACTH,SAAS,EACTD,WAAW,CAACC,SAAS,CAACI,SAAS,CAAC,CAAC,EAAEH,WAAW,CAAC,CAAC,CAACI,MAAM,CACrDL,SAAS,CAACI,SAAS,CAACH,WAAW,GAAG,CAAC,CACrC,CACF,CAAC;EACH;EAEA,OAAOJ,OAAO,CAACS,GAAG,CAACN,SAAS,CAAC;AAC/B;AAEAN,YAAY,CAACa,UAAU,CAACC,CAAC,GACvBC,GAAkD,IAC/C;EACH,MAAMT,SAAS,GAAG,OAAOS,GAAG,KAAK,QAAQ,GAAGA,GAAG,GAAGA,GAAG,CAACT,SAAS;EAC/D,MAAMU,IAAI,GAAG,OAAOD,GAAG,KAAK,QAAQ,GAAGT,SAAS,GAAGS,GAAG,CAACC,IAAI,IAAIV,SAAS;EACxE,MAAMW,KAAK,GAAGC,QAAQ,CAACb,WAAW,CAACC,SAAS,CAAC,CAACW,KAAK,EAAE,EAAE,CAAC;EACxD,MAAME,SAAS,GAAI,WAAUF,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAI,OAAMA,KAAM,EAAE,EAAC;EACjE,OAAQ,GAAEE,SAAU,MAAKH,IAAK,WAAU;AAC1C,CAAC;AAEDhB,YAAY,CAACa,UAAU,CAACO,CAAC,GAAG,SAASA,CAACA,CAACC,EAAiB,EAAE;EACxD,OAAOC,IAAI,CAACC,SAAS,CAACF,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,OAAO,SAASG,WAAWA,CAAClB,SAAS,GAAI,GAAEL,cAAe,IAAG,EAAE;EAC7DD,YAAY,CAACyB,MAAM,CAACnB,SAAS,CAAC;AAChC"}
@@ -0,0 +1,30 @@
1
+ import { Minimatch } from 'minimatch';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+
5
+ const cachedMatchers = new Map();
6
+ export const isFeatureEnabled = (features, featureName, filename) => {
7
+ const value = features?.[featureName] ?? false;
8
+ if (typeof value === 'boolean') {
9
+ return value;
10
+ }
11
+
12
+ // Fast check for glob patterns
13
+ if (value === '*' || value === '**/*') {
14
+ return true;
15
+ }
16
+ const array = Array.isArray(value) ? value : [value];
17
+
18
+ /**
19
+ * Check rule by rule like .gitignore
20
+ */
21
+ return array.map(pattern => {
22
+ let matcher = cachedMatchers.get(pattern);
23
+ if (!matcher) {
24
+ matcher = [pattern.startsWith('!'), new Minimatch(pattern)];
25
+ cachedMatchers.set(pattern, matcher);
26
+ }
27
+ return [matcher[0], matcher[1].match(filename)];
28
+ }).reduce((acc, [negated, match]) => negated ? acc && match : acc || match, false);
29
+ };
30
+ //# sourceMappingURL=isFeatureEnabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isFeatureEnabled.js","names":["Minimatch","cachedMatchers","Map","isFeatureEnabled","features","featureName","filename","value","array","Array","isArray","map","pattern","matcher","get","startsWith","set","match","reduce","acc","negated"],"sources":["../../src/options/isFeatureEnabled.ts"],"sourcesContent":["import { Minimatch } from 'minimatch';\n\nimport type { FeatureFlag } from './types';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype NoInfer<T> = [T][T extends any ? 0 : never];\n\nconst cachedMatchers = new Map<\n string,\n [nagated: boolean, matcher: Minimatch]\n>();\n\nexport const isFeatureEnabled = <T extends string>(\n features:\n | {\n [K in T]?: FeatureFlag;\n }\n | undefined,\n featureName: NoInfer<T>,\n filename: string\n) => {\n const value = features?.[featureName] ?? false;\n if (typeof value === 'boolean') {\n return value;\n }\n\n // Fast check for glob patterns\n if (value === '*' || value === '**/*') {\n return true;\n }\n\n const array: string[] = Array.isArray(value) ? value : [value];\n\n /**\n * Check rule by rule like .gitignore\n */\n return array\n .map((pattern) => {\n let matcher = cachedMatchers.get(pattern);\n if (!matcher) {\n matcher = [pattern.startsWith('!'), new Minimatch(pattern)];\n cachedMatchers.set(pattern, matcher);\n }\n\n return [matcher[0], matcher[1].match(filename)];\n })\n .reduce(\n (acc, [negated, match]) => (negated ? acc && match : acc || match),\n false\n );\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,WAAW;;AAIrC;;AAGA,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAG5B,CAAC;AAEH,OAAO,MAAMC,gBAAgB,GAAGA,CAC9BC,QAIa,EACbC,WAAuB,EACvBC,QAAgB,KACb;EACH,MAAMC,KAAK,GAAGH,QAAQ,GAAGC,WAAW,CAAC,IAAI,KAAK;EAC9C,IAAI,OAAOE,KAAK,KAAK,SAAS,EAAE;IAC9B,OAAOA,KAAK;EACd;;EAEA;EACA,IAAIA,KAAK,KAAK,GAAG,IAAIA,KAAK,KAAK,MAAM,EAAE;IACrC,OAAO,IAAI;EACb;EAEA,MAAMC,KAAe,GAAGC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC;;EAE9D;AACF;AACA;EACE,OAAOC,KAAK,CACTG,GAAG,CAAEC,OAAO,IAAK;IAChB,IAAIC,OAAO,GAAGZ,cAAc,CAACa,GAAG,CAACF,OAAO,CAAC;IACzC,IAAI,CAACC,OAAO,EAAE;MACZA,OAAO,GAAG,CAACD,OAAO,CAACG,UAAU,CAAC,GAAG,CAAC,EAAE,IAAIf,SAAS,CAACY,OAAO,CAAC,CAAC;MAC3DX,cAAc,CAACe,GAAG,CAACJ,OAAO,EAAEC,OAAO,CAAC;IACtC;IAEA,OAAO,CAACA,OAAO,CAAC,CAAC,CAAC,EAAEA,OAAO,CAAC,CAAC,CAAC,CAACI,KAAK,CAACX,QAAQ,CAAC,CAAC;EACjD,CAAC,CAAC,CACDY,MAAM,CACL,CAACC,GAAG,EAAE,CAACC,OAAO,EAAEH,KAAK,CAAC,KAAMG,OAAO,GAAGD,GAAG,IAAIF,KAAK,GAAGE,GAAG,IAAIF,KAAM,EAClE,KACF,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/options/types.ts"],"sourcesContent":["import type { Context as VmContext } from 'vm';\n\nimport type { TransformOptions } from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { IVariableContext } from '../IVariableContext';\nimport type { Core } from '../babel';\n\nexport type ClassNameSlugVars = {\n dir: string;\n ext: string;\n file: string;\n hash: string;\n name: string;\n title: string;\n};\n\nexport type ClassNameFn = (\n hash: string,\n title: string,\n args: ClassNameSlugVars\n) => string;\n\nexport type VariableNameFn = (context: IVariableContext) => string;\n\nexport type EvaluatorConfig = {\n features: StrictOptions['features'];\n highPriorityPlugins: string[];\n onlyExports: string[];\n};\n\nexport type Evaluator = (\n evalConfig: TransformOptions,\n ast: File,\n code: string,\n config: EvaluatorConfig,\n babel: Core\n) => [\n ast: File,\n code: string,\n imports: Map<string, string[]> | null,\n exports?: string[] | null,\n];\n\nexport type EvalRule = {\n action: Evaluator | 'ignore' | string;\n babelOptions?: TransformOptions;\n test?: RegExp | ((path: string, code: string) => boolean);\n};\n\nexport type FeatureFlag = boolean | string | string[];\n\ntype AllFeatureFlags = {\n dangerousCodeRemover: FeatureFlag;\n globalCache: FeatureFlag;\n happyDOM: FeatureFlag;\n softErrors: FeatureFlag;\n useBabelConfigs: FeatureFlag;\n};\n\nexport type FeatureFlags<\n TOnly extends keyof AllFeatureFlags = keyof AllFeatureFlags,\n> = Pick<AllFeatureFlags, TOnly>;\n\nexport type StrictOptions = {\n babelOptions: TransformOptions;\n classNameSlug?: string | ClassNameFn;\n displayName: boolean;\n evaluate: boolean;\n extensions: string[];\n features: FeatureFlags;\n highPriorityPlugins: string[];\n ignore?: RegExp;\n overrideContext?: (\n context: Partial<VmContext>,\n filename: string\n ) => Partial<VmContext>;\n rules: EvalRule[];\n tagResolver?: (source: string, tag: string) => string | null;\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n};\n"],"mappings":""}
package/esm/slugify.js ADDED
@@ -0,0 +1,62 @@
1
+ /* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */
2
+ /**
3
+ * This file contains a utility to generate hashes to be used as generated class names
4
+ */
5
+
6
+ /**
7
+ * murmurhash2 via https://gist.github.com/raycmorgan/588423
8
+ */
9
+
10
+ function UInt32(str, pos) {
11
+ return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8) + (str.charCodeAt(pos++) << 16) + (str.charCodeAt(pos) << 24);
12
+ }
13
+ function UInt16(str, pos) {
14
+ return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);
15
+ }
16
+ function Umul32(n, m) {
17
+ n |= 0;
18
+ m |= 0;
19
+ const nlo = n & 0xffff;
20
+ const nhi = n >>> 16;
21
+ return nlo * m + ((nhi * m & 0xffff) << 16) | 0;
22
+ }
23
+ function doHash(str, seed = 0) {
24
+ const m = 0x5bd1e995;
25
+ const r = 24;
26
+ let h = seed ^ str.length;
27
+ let length = str.length;
28
+ let currentIndex = 0;
29
+ while (length >= 4) {
30
+ let k = UInt32(str, currentIndex);
31
+ k = Umul32(k, m);
32
+ k ^= k >>> r;
33
+ k = Umul32(k, m);
34
+ h = Umul32(h, m);
35
+ h ^= k;
36
+ currentIndex += 4;
37
+ length -= 4;
38
+ }
39
+ switch (length) {
40
+ case 3:
41
+ h ^= UInt16(str, currentIndex);
42
+ h ^= str.charCodeAt(currentIndex + 2) << 16;
43
+ h = Umul32(h, m);
44
+ break;
45
+ case 2:
46
+ h ^= UInt16(str, currentIndex);
47
+ h = Umul32(h, m);
48
+ break;
49
+ case 1:
50
+ h ^= str.charCodeAt(currentIndex);
51
+ h = Umul32(h, m);
52
+ break;
53
+ }
54
+ h ^= h >>> 13;
55
+ h = Umul32(h, m);
56
+ h ^= h >>> 15;
57
+ return h >>> 0;
58
+ }
59
+ export function slugify(code) {
60
+ return doHash(code).toString(36);
61
+ }
62
+ //# sourceMappingURL=slugify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.js","names":["UInt32","str","pos","charCodeAt","UInt16","Umul32","n","m","nlo","nhi","doHash","seed","r","h","length","currentIndex","k","slugify","code","toString"],"sources":["../src/slugify.ts"],"sourcesContent":["/* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */\n/**\n * This file contains a utility to generate hashes to be used as generated class names\n */\n\n/**\n * murmurhash2 via https://gist.github.com/raycmorgan/588423\n */\n\nfunction UInt32(str: string, pos: number) {\n return (\n str.charCodeAt(pos++) +\n (str.charCodeAt(pos++) << 8) +\n (str.charCodeAt(pos++) << 16) +\n (str.charCodeAt(pos) << 24)\n );\n}\n\nfunction UInt16(str: string, pos: number) {\n return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);\n}\n\nfunction Umul32(n: number, m: number) {\n n |= 0;\n m |= 0;\n const nlo = n & 0xffff;\n const nhi = n >>> 16;\n return (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0;\n}\n\nfunction doHash(str: string, seed = 0) {\n const m = 0x5bd1e995;\n const r = 24;\n let h = seed ^ str.length;\n let length = str.length;\n let currentIndex = 0;\n\n while (length >= 4) {\n let k = UInt32(str, currentIndex);\n\n k = Umul32(k, m);\n k ^= k >>> r;\n k = Umul32(k, m);\n\n h = Umul32(h, m);\n h ^= k;\n\n currentIndex += 4;\n length -= 4;\n }\n\n switch (length) {\n case 3:\n h ^= UInt16(str, currentIndex);\n h ^= str.charCodeAt(currentIndex + 2) << 16;\n h = Umul32(h, m);\n break;\n\n case 2:\n h ^= UInt16(str, currentIndex);\n h = Umul32(h, m);\n break;\n\n case 1:\n h ^= str.charCodeAt(currentIndex);\n h = Umul32(h, m);\n break;\n }\n\n h ^= h >>> 13;\n h = Umul32(h, m);\n h ^= h >>> 15;\n\n return h >>> 0;\n}\n\nexport function slugify(code: string) {\n return doHash(code).toString(36);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,SAASA,MAAMA,CAACC,GAAW,EAAEC,GAAW,EAAE;EACxC,OACED,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IACpBD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,IAC3BD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,IAC5BD,GAAG,CAACE,UAAU,CAACD,GAAG,CAAC,IAAI,EAAE,CAAC;AAE/B;AAEA,SAASE,MAAMA,CAACH,GAAW,EAAEC,GAAW,EAAE;EACxC,OAAOD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAID,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAC7D;AAEA,SAASG,MAAMA,CAACC,CAAS,EAAEC,CAAS,EAAE;EACpCD,CAAC,IAAI,CAAC;EACNC,CAAC,IAAI,CAAC;EACN,MAAMC,GAAG,GAAGF,CAAC,GAAG,MAAM;EACtB,MAAMG,GAAG,GAAGH,CAAC,KAAK,EAAE;EACpB,OAAQE,GAAG,GAAGD,CAAC,IAAI,CAAEE,GAAG,GAAGF,CAAC,GAAI,MAAM,KAAK,EAAE,CAAC,GAAI,CAAC;AACrD;AAEA,SAASG,MAAMA,CAACT,GAAW,EAAEU,IAAI,GAAG,CAAC,EAAE;EACrC,MAAMJ,CAAC,GAAG,UAAU;EACpB,MAAMK,CAAC,GAAG,EAAE;EACZ,IAAIC,CAAC,GAAGF,IAAI,GAAGV,GAAG,CAACa,MAAM;EACzB,IAAIA,MAAM,GAAGb,GAAG,CAACa,MAAM;EACvB,IAAIC,YAAY,GAAG,CAAC;EAEpB,OAAOD,MAAM,IAAI,CAAC,EAAE;IAClB,IAAIE,CAAC,GAAGhB,MAAM,CAACC,GAAG,EAAEc,YAAY,CAAC;IAEjCC,CAAC,GAAGX,MAAM,CAACW,CAAC,EAAET,CAAC,CAAC;IAChBS,CAAC,IAAIA,CAAC,KAAKJ,CAAC;IACZI,CAAC,GAAGX,MAAM,CAACW,CAAC,EAAET,CAAC,CAAC;IAEhBM,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;IAChBM,CAAC,IAAIG,CAAC;IAEND,YAAY,IAAI,CAAC;IACjBD,MAAM,IAAI,CAAC;EACb;EAEA,QAAQA,MAAM;IACZ,KAAK,CAAC;MACJD,CAAC,IAAIT,MAAM,CAACH,GAAG,EAAEc,YAAY,CAAC;MAC9BF,CAAC,IAAIZ,GAAG,CAACE,UAAU,CAACY,YAAY,GAAG,CAAC,CAAC,IAAI,EAAE;MAC3CF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;IAEF,KAAK,CAAC;MACJM,CAAC,IAAIT,MAAM,CAACH,GAAG,EAAEc,YAAY,CAAC;MAC9BF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;IAEF,KAAK,CAAC;MACJM,CAAC,IAAIZ,GAAG,CAACE,UAAU,CAACY,YAAY,CAAC;MACjCF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;EACJ;EAEAM,CAAC,IAAIA,CAAC,KAAK,EAAE;EACbA,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;EAChBM,CAAC,IAAIA,CAAC,KAAK,EAAE;EAEb,OAAOA,CAAC,KAAK,CAAC;AAChB;AAEA,OAAO,SAASI,OAAOA,CAACC,IAAY,EAAE;EACpC,OAAOR,MAAM,CAACQ,IAAI,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC;AAClC"}
package/esm/types.js ADDED
@@ -0,0 +1,11 @@
1
+ export let ValueType = /*#__PURE__*/function (ValueType) {
2
+ ValueType[ValueType["LAZY"] = 0] = "LAZY";
3
+ ValueType[ValueType["FUNCTION"] = 1] = "FUNCTION";
4
+ ValueType[ValueType["CONST"] = 2] = "CONST";
5
+ return ValueType;
6
+ }({});
7
+
8
+ /**
9
+ * CSS-related types
10
+ */
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":["ValueType"],"sources":["../src/types.ts"],"sourcesContent":["import type {\n BigIntLiteral,\n BooleanLiteral,\n DecimalLiteral,\n Identifier,\n NullLiteral,\n NumericLiteral,\n StringLiteral,\n} from '@babel/types';\n\nexport type Artifact = [name: string, data: unknown];\n\nexport type BuildCodeFrameErrorFn = <TError extends Error>(\n msg: string,\n Error?: new (innerMsg: string) => TError\n) => TError;\n\nexport enum ValueType {\n LAZY,\n FUNCTION,\n CONST,\n}\n\nexport type LazyValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.LAZY;\n source: string;\n};\n\nexport type FunctionValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.FUNCTION;\n source: string;\n};\n\nexport type ConstValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex:\n | StringLiteral\n | NumericLiteral\n | NullLiteral\n | BooleanLiteral\n | BigIntLiteral\n | DecimalLiteral;\n kind: ValueType.CONST;\n source: string;\n value: string | number | boolean | null;\n};\n\nexport type ExpressionValue = LazyValue | FunctionValue | ConstValue;\n\nexport type WYWEvalMeta = {\n __wyw_meta: {\n className: string;\n extends: WYWEvalMeta;\n };\n};\n\nexport type Location = {\n column: number;\n line: number;\n};\n\nexport type Replacement = {\n length: number;\n original: { end: Location; start: Location };\n};\n\nexport type Replacements = Array<Replacement>;\n\n/**\n * CSS-related types\n */\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n"],"mappings":"AAiBA,WAAYA,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;;AAyDrB;AACA;AACA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=IVariableContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IVariableContext.js","names":[],"sources":["../src/IVariableContext.ts"],"sourcesContent":["export interface IVariableContext {\n componentName: string;\n componentSlug: string;\n index: number;\n precedingCss: string;\n processor: string;\n source: string;\n unit: string;\n valueSlug: string;\n}\n"],"mappings":""}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.syncResolve = exports.asyncResolveFallback = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ const safeResolve = (name, where) => {
10
+ try {
11
+ return require.resolve(name, {
12
+ paths: where
13
+ });
14
+ } catch (e) {
15
+ return e;
16
+ }
17
+ };
18
+ const suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc, ext) => {
19
+ acc.push(`/index${ext}`);
20
+ acc.push(ext);
21
+ return acc;
22
+ }, []);
23
+ const syncResolve = (what, importer, stack) => {
24
+ const where = [importer, ...stack].map(p => _path.default.dirname(p));
25
+ const resolved = safeResolve(what, where);
26
+ if (!(resolved instanceof Error)) {
27
+ return resolved;
28
+ }
29
+
30
+ // eslint-disable-next-line no-restricted-syntax
31
+ for (const suffix of suffixes) {
32
+ const resolvedWithSuffix = safeResolve(what + suffix, where);
33
+ if (resolvedWithSuffix instanceof Error) {
34
+ // eslint-disable-next-line no-continue
35
+ continue;
36
+ }
37
+ return resolvedWithSuffix;
38
+ }
39
+ throw resolved;
40
+ };
41
+ exports.syncResolve = syncResolve;
42
+ const asyncResolveFallback = (what, importer, stack) => {
43
+ const resolved = syncResolve(what, importer, stack);
44
+ return Promise.resolve(resolved);
45
+ };
46
+ exports.asyncResolveFallback = asyncResolveFallback;
47
+ //# sourceMappingURL=asyncResolveFallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncResolveFallback.js","names":["_path","_interopRequireDefault","require","obj","__esModule","default","safeResolve","name","where","resolve","paths","e","suffixes","reduce","acc","ext","push","syncResolve","what","importer","stack","map","p","path","dirname","resolved","Error","suffix","resolvedWithSuffix","exports","asyncResolveFallback","Promise"],"sources":["../src/asyncResolveFallback.ts"],"sourcesContent":["import path from 'path';\n\nconst safeResolve = (name: string, where: string[]): string | Error => {\n try {\n return require.resolve(name, {\n paths: where,\n });\n } catch (e: unknown) {\n return e as Error;\n }\n};\n\nconst suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc: string[], ext) => {\n acc.push(`/index${ext}`);\n acc.push(ext);\n return acc;\n}, []);\n\nexport const syncResolve = (\n what: string,\n importer: string,\n stack: string[]\n): string => {\n const where = [importer, ...stack].map((p) => path.dirname(p));\n const resolved = safeResolve(what, where);\n if (!(resolved instanceof Error)) {\n return resolved;\n }\n\n // eslint-disable-next-line no-restricted-syntax\n for (const suffix of suffixes) {\n const resolvedWithSuffix = safeResolve(what + suffix, where);\n if (resolvedWithSuffix instanceof Error) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n return resolvedWithSuffix;\n }\n\n throw resolved;\n};\n\nexport const asyncResolveFallback = (\n what: string,\n importer: string,\n stack: string[]\n): Promise<string> => {\n const resolved = syncResolve(what, importer, stack);\n return Promise.resolve(resolved);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAExB,MAAMG,WAAW,GAAGA,CAACC,IAAY,EAAEC,KAAe,KAAqB;EACrE,IAAI;IACF,OAAON,OAAO,CAACO,OAAO,CAACF,IAAI,EAAE;MAC3BG,KAAK,EAAEF;IACT,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOG,CAAU,EAAE;IACnB,OAAOA,CAAC;EACV;AACF,CAAC;AAED,MAAMC,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAACC,MAAM,CAAC,CAACC,GAAa,EAAEC,GAAG,KAAK;EAC7ED,GAAG,CAACE,IAAI,CAAE,SAAQD,GAAI,EAAC,CAAC;EACxBD,GAAG,CAACE,IAAI,CAACD,GAAG,CAAC;EACb,OAAOD,GAAG;AACZ,CAAC,EAAE,EAAE,CAAC;AAEC,MAAMG,WAAW,GAAGA,CACzBC,IAAY,EACZC,QAAgB,EAChBC,KAAe,KACJ;EACX,MAAMZ,KAAK,GAAG,CAACW,QAAQ,EAAE,GAAGC,KAAK,CAAC,CAACC,GAAG,CAAEC,CAAC,IAAKC,aAAI,CAACC,OAAO,CAACF,CAAC,CAAC,CAAC;EAC9D,MAAMG,QAAQ,GAAGnB,WAAW,CAACY,IAAI,EAAEV,KAAK,CAAC;EACzC,IAAI,EAAEiB,QAAQ,YAAYC,KAAK,CAAC,EAAE;IAChC,OAAOD,QAAQ;EACjB;;EAEA;EACA,KAAK,MAAME,MAAM,IAAIf,QAAQ,EAAE;IAC7B,MAAMgB,kBAAkB,GAAGtB,WAAW,CAACY,IAAI,GAAGS,MAAM,EAAEnB,KAAK,CAAC;IAC5D,IAAIoB,kBAAkB,YAAYF,KAAK,EAAE;MACvC;MACA;IACF;IAEA,OAAOE,kBAAkB;EAC3B;EAEA,MAAMH,QAAQ;AAChB,CAAC;AAACI,OAAA,CAAAZ,WAAA,GAAAA,WAAA;AAEK,MAAMa,oBAAoB,GAAGA,CAClCZ,IAAY,EACZC,QAAgB,EAChBC,KAAe,KACK;EACpB,MAAMK,QAAQ,GAAGR,WAAW,CAACC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,CAAC;EACnD,OAAOW,OAAO,CAACtB,OAAO,CAACgB,QAAQ,CAAC;AAClC,CAAC;AAACI,OAAA,CAAAC,oBAAA,GAAAA,oBAAA"}
package/lib/babel.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=babel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.js","names":[],"sources":["../src/babel.ts"],"sourcesContent":["import type core from '@babel/core';\n\nexport type Core = typeof core;\n"],"mappings":""}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasEvalMeta = hasEvalMeta;
7
+ function hasEvalMeta(value) {
8
+ return typeof value === 'object' && value !== null && '__wyw_meta' in value;
9
+ }
10
+ //# sourceMappingURL=hasEvalMeta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasEvalMeta.js","names":["hasEvalMeta","value"],"sources":["../src/hasEvalMeta.ts"],"sourcesContent":["import type { WYWEvalMeta } from './types';\n\nexport function hasEvalMeta(value: unknown): value is WYWEvalMeta {\n return typeof value === 'object' && value !== null && '__wyw_meta' in value;\n}\n"],"mappings":";;;;;;AAEO,SAASA,WAAWA,CAACC,KAAc,EAAwB;EAChE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,IAAI,YAAY,IAAIA,KAAK;AAC7E"}
package/lib/index.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Debugger", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _debug.Debugger;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ValueType", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _types.ValueType;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "asyncResolveFallback", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _asyncResolveFallback.asyncResolveFallback;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "enableDebug", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _logger.enableDebug;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "hasEvalMeta", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _hasEvalMeta.hasEvalMeta;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "isBoxedPrimitive", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _isBoxedPrimitive.isBoxedPrimitive;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "isFeatureEnabled", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _isFeatureEnabled.isFeatureEnabled;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "logger", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _logger.logger;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "slugify", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _slugify.slugify;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "syncResolve", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _asyncResolveFallback.syncResolve;
64
+ }
65
+ });
66
+ var _debug = require("debug");
67
+ var _asyncResolveFallback = require("./asyncResolveFallback");
68
+ var _hasEvalMeta = require("./hasEvalMeta");
69
+ var _isBoxedPrimitive = require("./isBoxedPrimitive");
70
+ var _logger = require("./logger");
71
+ var _isFeatureEnabled = require("./options/isFeatureEnabled");
72
+ var _slugify = require("./slugify");
73
+ var _types = require("./types");
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_debug","require","_asyncResolveFallback","_hasEvalMeta","_isBoxedPrimitive","_logger","_isFeatureEnabled","_slugify","_types"],"sources":["../src/index.ts"],"sourcesContent":["export { Debugger } from 'debug';\n\nexport { asyncResolveFallback, syncResolve } from './asyncResolveFallback';\nexport { hasEvalMeta } from './hasEvalMeta';\nexport { isBoxedPrimitive } from './isBoxedPrimitive';\nexport { enableDebug, logger } from './logger';\nexport { isFeatureEnabled } from './options/isFeatureEnabled';\nexport { slugify } from './slugify';\nexport { ValueType } from './types';\n\nexport type {\n ClassNameSlugVars,\n ClassNameFn,\n StrictOptions,\n EvalRule,\n Evaluator,\n FeatureFlag,\n EvaluatorConfig,\n FeatureFlags,\n VariableNameFn,\n} from './options/types';\nexport type {\n Artifact,\n BuildCodeFrameErrorFn,\n ConstValue,\n ExpressionValue,\n FunctionValue,\n ICSSRule,\n LazyValue,\n Location,\n Replacement,\n Replacements,\n Rules,\n WYWEvalMeta,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBoxedPrimitive = isBoxedPrimitive;
7
+ // There is a problem with using boxed numbers and strings in TS,
8
+ // so we cannot just use `instanceof` here
9
+
10
+ const constructors = ['Number', 'String'];
11
+ function isBoxedPrimitive(o) {
12
+ if (typeof o !== 'object' || o === null) return false;
13
+ return constructors.includes(o.constructor.name) && typeof (o === null || o === void 0 ? void 0 : o.valueOf()) !== 'object';
14
+ }
15
+ //# sourceMappingURL=isBoxedPrimitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isBoxedPrimitive.js","names":["constructors","isBoxedPrimitive","o","includes","constructor","name","valueOf"],"sources":["../src/isBoxedPrimitive.ts"],"sourcesContent":["// There is a problem with using boxed numbers and strings in TS,\n// so we cannot just use `instanceof` here\n\nconst constructors = ['Number', 'String'];\nexport function isBoxedPrimitive(o: unknown): o is number | string {\n if (typeof o !== 'object' || o === null) return false;\n return (\n constructors.includes(o.constructor.name) &&\n typeof o?.valueOf() !== 'object'\n );\n}\n"],"mappings":";;;;;;AAAA;AACA;;AAEA,MAAMA,YAAY,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;AAClC,SAASC,gBAAgBA,CAACC,CAAU,EAAwB;EACjE,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,KAAK,IAAI,EAAE,OAAO,KAAK;EACrD,OACEF,YAAY,CAACG,QAAQ,CAACD,CAAC,CAACE,WAAW,CAACC,IAAI,CAAC,IACzC,QAAOH,CAAC,aAADA,CAAC,uBAADA,CAAC,CAAEI,OAAO,CAAC,CAAC,MAAK,QAAQ;AAEpC"}
package/lib/logger.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enableDebug = enableDebug;
7
+ exports.logger = void 0;
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const BASE_NAMESPACE = 'wyw-in-js';
11
+ const logger = exports.logger = (0, _debug.default)(BASE_NAMESPACE);
12
+ const loggers = new Map();
13
+ function gerOrCreate(namespace) {
14
+ if (!namespace) return logger;
15
+ const lastIndexOf = namespace.lastIndexOf(':');
16
+ if (!loggers.has(namespace)) {
17
+ loggers.set(namespace, gerOrCreate(namespace.substring(0, lastIndexOf)).extend(namespace.substring(lastIndexOf + 1)));
18
+ }
19
+ return loggers.get(namespace);
20
+ }
21
+ _debug.default.formatters.r = ref => {
22
+ var _ref$text;
23
+ const namespace = typeof ref === 'string' ? ref : ref.namespace;
24
+ const text = typeof ref === 'string' ? namespace : (_ref$text = ref.text) !== null && _ref$text !== void 0 ? _ref$text : namespace;
25
+ const color = parseInt(gerOrCreate(namespace).color, 10);
26
+ const colorCode = `\u001B[3${color < 8 ? color : `8;5;${color}`}`;
27
+ return `${colorCode};1m${text}\u001B[0m`;
28
+ };
29
+ _debug.default.formatters.f = function f(fn) {
30
+ return JSON.stringify(fn());
31
+ };
32
+ function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
33
+ _debug.default.enable(namespace);
34
+ }
35
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","names":["_debug","_interopRequireDefault","require","obj","__esModule","default","BASE_NAMESPACE","logger","exports","genericDebug","loggers","Map","gerOrCreate","namespace","lastIndexOf","has","set","substring","extend","get","formatters","r","ref","_ref$text","text","color","parseInt","colorCode","f","fn","JSON","stringify","enableDebug","enable"],"sources":["../src/logger.ts"],"sourcesContent":["import genericDebug from 'debug';\nimport type { Debugger } from 'debug';\n\nconst BASE_NAMESPACE = 'wyw-in-js';\n\nexport const logger = genericDebug(BASE_NAMESPACE);\n\nconst loggers = new Map<string, Debugger>();\n\nfunction gerOrCreate(namespace: string | null | undefined): Debugger {\n if (!namespace) return logger;\n const lastIndexOf = namespace.lastIndexOf(':');\n if (!loggers.has(namespace)) {\n loggers.set(\n namespace,\n gerOrCreate(namespace.substring(0, lastIndexOf)).extend(\n namespace.substring(lastIndexOf + 1)\n )\n );\n }\n\n return loggers.get(namespace)!;\n}\n\ngenericDebug.formatters.r = (\n ref: string | { namespace: string; text?: string }\n) => {\n const namespace = typeof ref === 'string' ? ref : ref.namespace;\n const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;\n const color = parseInt(gerOrCreate(namespace).color, 10);\n const colorCode = `\\u001B[3${color < 8 ? color : `8;5;${color}`}`;\n return `${colorCode};1m${text}\\u001B[0m`;\n};\n\ngenericDebug.formatters.f = function f(fn: () => unknown) {\n return JSON.stringify(fn());\n};\n\nexport function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {\n genericDebug.enable(namespace);\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAiC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGjC,MAAMG,cAAc,GAAG,WAAW;AAE3B,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAAE,cAAY,EAACH,cAAc,CAAC;AAElD,MAAMI,OAAO,GAAG,IAAIC,GAAG,CAAmB,CAAC;AAE3C,SAASC,WAAWA,CAACC,SAAoC,EAAY;EACnE,IAAI,CAACA,SAAS,EAAE,OAAON,MAAM;EAC7B,MAAMO,WAAW,GAAGD,SAAS,CAACC,WAAW,CAAC,GAAG,CAAC;EAC9C,IAAI,CAACJ,OAAO,CAACK,GAAG,CAACF,SAAS,CAAC,EAAE;IAC3BH,OAAO,CAACM,GAAG,CACTH,SAAS,EACTD,WAAW,CAACC,SAAS,CAACI,SAAS,CAAC,CAAC,EAAEH,WAAW,CAAC,CAAC,CAACI,MAAM,CACrDL,SAAS,CAACI,SAAS,CAACH,WAAW,GAAG,CAAC,CACrC,CACF,CAAC;EACH;EAEA,OAAOJ,OAAO,CAACS,GAAG,CAACN,SAAS,CAAC;AAC/B;AAEAJ,cAAY,CAACW,UAAU,CAACC,CAAC,GACvBC,GAAkD,IAC/C;EAAA,IAAAC,SAAA;EACH,MAAMV,SAAS,GAAG,OAAOS,GAAG,KAAK,QAAQ,GAAGA,GAAG,GAAGA,GAAG,CAACT,SAAS;EAC/D,MAAMW,IAAI,GAAG,OAAOF,GAAG,KAAK,QAAQ,GAAGT,SAAS,IAAAU,SAAA,GAAGD,GAAG,CAACE,IAAI,cAAAD,SAAA,cAAAA,SAAA,GAAIV,SAAS;EACxE,MAAMY,KAAK,GAAGC,QAAQ,CAACd,WAAW,CAACC,SAAS,CAAC,CAACY,KAAK,EAAE,EAAE,CAAC;EACxD,MAAME,SAAS,GAAI,WAAUF,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAI,OAAMA,KAAM,EAAE,EAAC;EACjE,OAAQ,GAAEE,SAAU,MAAKH,IAAK,WAAU;AAC1C,CAAC;AAEDf,cAAY,CAACW,UAAU,CAACQ,CAAC,GAAG,SAASA,CAACA,CAACC,EAAiB,EAAE;EACxD,OAAOC,IAAI,CAACC,SAAS,CAACF,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC;AAEM,SAASG,WAAWA,CAACnB,SAAS,GAAI,GAAEP,cAAe,IAAG,EAAE;EAC7DG,cAAY,CAACwB,MAAM,CAACpB,SAAS,CAAC;AAChC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isFeatureEnabled = void 0;
7
+ var _minimatch = require("minimatch");
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+
10
+ const cachedMatchers = new Map();
11
+ const isFeatureEnabled = (features, featureName, filename) => {
12
+ var _features$featureName;
13
+ const value = (_features$featureName = features === null || features === void 0 ? void 0 : features[featureName]) !== null && _features$featureName !== void 0 ? _features$featureName : false;
14
+ if (typeof value === 'boolean') {
15
+ return value;
16
+ }
17
+
18
+ // Fast check for glob patterns
19
+ if (value === '*' || value === '**/*') {
20
+ return true;
21
+ }
22
+ const array = Array.isArray(value) ? value : [value];
23
+
24
+ /**
25
+ * Check rule by rule like .gitignore
26
+ */
27
+ return array.map(pattern => {
28
+ let matcher = cachedMatchers.get(pattern);
29
+ if (!matcher) {
30
+ matcher = [pattern.startsWith('!'), new _minimatch.Minimatch(pattern)];
31
+ cachedMatchers.set(pattern, matcher);
32
+ }
33
+ return [matcher[0], matcher[1].match(filename)];
34
+ }).reduce((acc, [negated, match]) => negated ? acc && match : acc || match, false);
35
+ };
36
+ exports.isFeatureEnabled = isFeatureEnabled;
37
+ //# sourceMappingURL=isFeatureEnabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isFeatureEnabled.js","names":["_minimatch","require","cachedMatchers","Map","isFeatureEnabled","features","featureName","filename","_features$featureName","value","array","Array","isArray","map","pattern","matcher","get","startsWith","Minimatch","set","match","reduce","acc","negated","exports"],"sources":["../../src/options/isFeatureEnabled.ts"],"sourcesContent":["import { Minimatch } from 'minimatch';\n\nimport type { FeatureFlag } from './types';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype NoInfer<T> = [T][T extends any ? 0 : never];\n\nconst cachedMatchers = new Map<\n string,\n [nagated: boolean, matcher: Minimatch]\n>();\n\nexport const isFeatureEnabled = <T extends string>(\n features:\n | {\n [K in T]?: FeatureFlag;\n }\n | undefined,\n featureName: NoInfer<T>,\n filename: string\n) => {\n const value = features?.[featureName] ?? false;\n if (typeof value === 'boolean') {\n return value;\n }\n\n // Fast check for glob patterns\n if (value === '*' || value === '**/*') {\n return true;\n }\n\n const array: string[] = Array.isArray(value) ? value : [value];\n\n /**\n * Check rule by rule like .gitignore\n */\n return array\n .map((pattern) => {\n let matcher = cachedMatchers.get(pattern);\n if (!matcher) {\n matcher = [pattern.startsWith('!'), new Minimatch(pattern)];\n cachedMatchers.set(pattern, matcher);\n }\n\n return [matcher[0], matcher[1].match(filename)];\n })\n .reduce(\n (acc, [negated, match]) => (negated ? acc && match : acc || match),\n false\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAIA;;AAGA,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAG5B,CAAC;AAEI,MAAMC,gBAAgB,GAAGA,CAC9BC,QAIa,EACbC,WAAuB,EACvBC,QAAgB,KACb;EAAA,IAAAC,qBAAA;EACH,MAAMC,KAAK,IAAAD,qBAAA,GAAGH,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAGC,WAAW,CAAC,cAAAE,qBAAA,cAAAA,qBAAA,GAAI,KAAK;EAC9C,IAAI,OAAOC,KAAK,KAAK,SAAS,EAAE;IAC9B,OAAOA,KAAK;EACd;;EAEA;EACA,IAAIA,KAAK,KAAK,GAAG,IAAIA,KAAK,KAAK,MAAM,EAAE;IACrC,OAAO,IAAI;EACb;EAEA,MAAMC,KAAe,GAAGC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC;;EAE9D;AACF;AACA;EACE,OAAOC,KAAK,CACTG,GAAG,CAAEC,OAAO,IAAK;IAChB,IAAIC,OAAO,GAAGb,cAAc,CAACc,GAAG,CAACF,OAAO,CAAC;IACzC,IAAI,CAACC,OAAO,EAAE;MACZA,OAAO,GAAG,CAACD,OAAO,CAACG,UAAU,CAAC,GAAG,CAAC,EAAE,IAAIC,oBAAS,CAACJ,OAAO,CAAC,CAAC;MAC3DZ,cAAc,CAACiB,GAAG,CAACL,OAAO,EAAEC,OAAO,CAAC;IACtC;IAEA,OAAO,CAACA,OAAO,CAAC,CAAC,CAAC,EAAEA,OAAO,CAAC,CAAC,CAAC,CAACK,KAAK,CAACb,QAAQ,CAAC,CAAC;EACjD,CAAC,CAAC,CACDc,MAAM,CACL,CAACC,GAAG,EAAE,CAACC,OAAO,EAAEH,KAAK,CAAC,KAAMG,OAAO,GAAGD,GAAG,IAAIF,KAAK,GAAGE,GAAG,IAAIF,KAAM,EAClE,KACF,CAAC;AACL,CAAC;AAACI,OAAA,CAAApB,gBAAA,GAAAA,gBAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/options/types.ts"],"sourcesContent":["import type { Context as VmContext } from 'vm';\n\nimport type { TransformOptions } from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { IVariableContext } from '../IVariableContext';\nimport type { Core } from '../babel';\n\nexport type ClassNameSlugVars = {\n dir: string;\n ext: string;\n file: string;\n hash: string;\n name: string;\n title: string;\n};\n\nexport type ClassNameFn = (\n hash: string,\n title: string,\n args: ClassNameSlugVars\n) => string;\n\nexport type VariableNameFn = (context: IVariableContext) => string;\n\nexport type EvaluatorConfig = {\n features: StrictOptions['features'];\n highPriorityPlugins: string[];\n onlyExports: string[];\n};\n\nexport type Evaluator = (\n evalConfig: TransformOptions,\n ast: File,\n code: string,\n config: EvaluatorConfig,\n babel: Core\n) => [\n ast: File,\n code: string,\n imports: Map<string, string[]> | null,\n exports?: string[] | null,\n];\n\nexport type EvalRule = {\n action: Evaluator | 'ignore' | string;\n babelOptions?: TransformOptions;\n test?: RegExp | ((path: string, code: string) => boolean);\n};\n\nexport type FeatureFlag = boolean | string | string[];\n\ntype AllFeatureFlags = {\n dangerousCodeRemover: FeatureFlag;\n globalCache: FeatureFlag;\n happyDOM: FeatureFlag;\n softErrors: FeatureFlag;\n useBabelConfigs: FeatureFlag;\n};\n\nexport type FeatureFlags<\n TOnly extends keyof AllFeatureFlags = keyof AllFeatureFlags,\n> = Pick<AllFeatureFlags, TOnly>;\n\nexport type StrictOptions = {\n babelOptions: TransformOptions;\n classNameSlug?: string | ClassNameFn;\n displayName: boolean;\n evaluate: boolean;\n extensions: string[];\n features: FeatureFlags;\n highPriorityPlugins: string[];\n ignore?: RegExp;\n overrideContext?: (\n context: Partial<VmContext>,\n filename: string\n ) => Partial<VmContext>;\n rules: EvalRule[];\n tagResolver?: (source: string, tag: string) => string | null;\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n};\n"],"mappings":""}
package/lib/slugify.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.slugify = slugify;
7
+ /* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */
8
+ /**
9
+ * This file contains a utility to generate hashes to be used as generated class names
10
+ */
11
+
12
+ /**
13
+ * murmurhash2 via https://gist.github.com/raycmorgan/588423
14
+ */
15
+
16
+ function UInt32(str, pos) {
17
+ return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8) + (str.charCodeAt(pos++) << 16) + (str.charCodeAt(pos) << 24);
18
+ }
19
+ function UInt16(str, pos) {
20
+ return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);
21
+ }
22
+ function Umul32(n, m) {
23
+ n |= 0;
24
+ m |= 0;
25
+ const nlo = n & 0xffff;
26
+ const nhi = n >>> 16;
27
+ return nlo * m + ((nhi * m & 0xffff) << 16) | 0;
28
+ }
29
+ function doHash(str, seed = 0) {
30
+ const m = 0x5bd1e995;
31
+ const r = 24;
32
+ let h = seed ^ str.length;
33
+ let length = str.length;
34
+ let currentIndex = 0;
35
+ while (length >= 4) {
36
+ let k = UInt32(str, currentIndex);
37
+ k = Umul32(k, m);
38
+ k ^= k >>> r;
39
+ k = Umul32(k, m);
40
+ h = Umul32(h, m);
41
+ h ^= k;
42
+ currentIndex += 4;
43
+ length -= 4;
44
+ }
45
+ switch (length) {
46
+ case 3:
47
+ h ^= UInt16(str, currentIndex);
48
+ h ^= str.charCodeAt(currentIndex + 2) << 16;
49
+ h = Umul32(h, m);
50
+ break;
51
+ case 2:
52
+ h ^= UInt16(str, currentIndex);
53
+ h = Umul32(h, m);
54
+ break;
55
+ case 1:
56
+ h ^= str.charCodeAt(currentIndex);
57
+ h = Umul32(h, m);
58
+ break;
59
+ }
60
+ h ^= h >>> 13;
61
+ h = Umul32(h, m);
62
+ h ^= h >>> 15;
63
+ return h >>> 0;
64
+ }
65
+ function slugify(code) {
66
+ return doHash(code).toString(36);
67
+ }
68
+ //# sourceMappingURL=slugify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.js","names":["UInt32","str","pos","charCodeAt","UInt16","Umul32","n","m","nlo","nhi","doHash","seed","r","h","length","currentIndex","k","slugify","code","toString"],"sources":["../src/slugify.ts"],"sourcesContent":["/* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */\n/**\n * This file contains a utility to generate hashes to be used as generated class names\n */\n\n/**\n * murmurhash2 via https://gist.github.com/raycmorgan/588423\n */\n\nfunction UInt32(str: string, pos: number) {\n return (\n str.charCodeAt(pos++) +\n (str.charCodeAt(pos++) << 8) +\n (str.charCodeAt(pos++) << 16) +\n (str.charCodeAt(pos) << 24)\n );\n}\n\nfunction UInt16(str: string, pos: number) {\n return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);\n}\n\nfunction Umul32(n: number, m: number) {\n n |= 0;\n m |= 0;\n const nlo = n & 0xffff;\n const nhi = n >>> 16;\n return (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0;\n}\n\nfunction doHash(str: string, seed = 0) {\n const m = 0x5bd1e995;\n const r = 24;\n let h = seed ^ str.length;\n let length = str.length;\n let currentIndex = 0;\n\n while (length >= 4) {\n let k = UInt32(str, currentIndex);\n\n k = Umul32(k, m);\n k ^= k >>> r;\n k = Umul32(k, m);\n\n h = Umul32(h, m);\n h ^= k;\n\n currentIndex += 4;\n length -= 4;\n }\n\n switch (length) {\n case 3:\n h ^= UInt16(str, currentIndex);\n h ^= str.charCodeAt(currentIndex + 2) << 16;\n h = Umul32(h, m);\n break;\n\n case 2:\n h ^= UInt16(str, currentIndex);\n h = Umul32(h, m);\n break;\n\n case 1:\n h ^= str.charCodeAt(currentIndex);\n h = Umul32(h, m);\n break;\n }\n\n h ^= h >>> 13;\n h = Umul32(h, m);\n h ^= h >>> 15;\n\n return h >>> 0;\n}\n\nexport function slugify(code: string) {\n return doHash(code).toString(36);\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,SAASA,MAAMA,CAACC,GAAW,EAAEC,GAAW,EAAE;EACxC,OACED,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IACpBD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,IAC3BD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,IAC5BD,GAAG,CAACE,UAAU,CAACD,GAAG,CAAC,IAAI,EAAE,CAAC;AAE/B;AAEA,SAASE,MAAMA,CAACH,GAAW,EAAEC,GAAW,EAAE;EACxC,OAAOD,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAID,GAAG,CAACE,UAAU,CAACD,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAC7D;AAEA,SAASG,MAAMA,CAACC,CAAS,EAAEC,CAAS,EAAE;EACpCD,CAAC,IAAI,CAAC;EACNC,CAAC,IAAI,CAAC;EACN,MAAMC,GAAG,GAAGF,CAAC,GAAG,MAAM;EACtB,MAAMG,GAAG,GAAGH,CAAC,KAAK,EAAE;EACpB,OAAQE,GAAG,GAAGD,CAAC,IAAI,CAAEE,GAAG,GAAGF,CAAC,GAAI,MAAM,KAAK,EAAE,CAAC,GAAI,CAAC;AACrD;AAEA,SAASG,MAAMA,CAACT,GAAW,EAAEU,IAAI,GAAG,CAAC,EAAE;EACrC,MAAMJ,CAAC,GAAG,UAAU;EACpB,MAAMK,CAAC,GAAG,EAAE;EACZ,IAAIC,CAAC,GAAGF,IAAI,GAAGV,GAAG,CAACa,MAAM;EACzB,IAAIA,MAAM,GAAGb,GAAG,CAACa,MAAM;EACvB,IAAIC,YAAY,GAAG,CAAC;EAEpB,OAAOD,MAAM,IAAI,CAAC,EAAE;IAClB,IAAIE,CAAC,GAAGhB,MAAM,CAACC,GAAG,EAAEc,YAAY,CAAC;IAEjCC,CAAC,GAAGX,MAAM,CAACW,CAAC,EAAET,CAAC,CAAC;IAChBS,CAAC,IAAIA,CAAC,KAAKJ,CAAC;IACZI,CAAC,GAAGX,MAAM,CAACW,CAAC,EAAET,CAAC,CAAC;IAEhBM,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;IAChBM,CAAC,IAAIG,CAAC;IAEND,YAAY,IAAI,CAAC;IACjBD,MAAM,IAAI,CAAC;EACb;EAEA,QAAQA,MAAM;IACZ,KAAK,CAAC;MACJD,CAAC,IAAIT,MAAM,CAACH,GAAG,EAAEc,YAAY,CAAC;MAC9BF,CAAC,IAAIZ,GAAG,CAACE,UAAU,CAACY,YAAY,GAAG,CAAC,CAAC,IAAI,EAAE;MAC3CF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;IAEF,KAAK,CAAC;MACJM,CAAC,IAAIT,MAAM,CAACH,GAAG,EAAEc,YAAY,CAAC;MAC9BF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;IAEF,KAAK,CAAC;MACJM,CAAC,IAAIZ,GAAG,CAACE,UAAU,CAACY,YAAY,CAAC;MACjCF,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;MAChB;EACJ;EAEAM,CAAC,IAAIA,CAAC,KAAK,EAAE;EACbA,CAAC,GAAGR,MAAM,CAACQ,CAAC,EAAEN,CAAC,CAAC;EAChBM,CAAC,IAAIA,CAAC,KAAK,EAAE;EAEb,OAAOA,CAAC,KAAK,CAAC;AAChB;AAEO,SAASI,OAAOA,CAACC,IAAY,EAAE;EACpC,OAAOR,MAAM,CAACQ,IAAI,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC;AAClC"}
package/lib/types.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ValueType = void 0;
7
+ let ValueType = exports.ValueType = /*#__PURE__*/function (ValueType) {
8
+ ValueType[ValueType["LAZY"] = 0] = "LAZY";
9
+ ValueType[ValueType["FUNCTION"] = 1] = "FUNCTION";
10
+ ValueType[ValueType["CONST"] = 2] = "CONST";
11
+ return ValueType;
12
+ }({});
13
+ /**
14
+ * CSS-related types
15
+ */
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":["ValueType","exports"],"sources":["../src/types.ts"],"sourcesContent":["import type {\n BigIntLiteral,\n BooleanLiteral,\n DecimalLiteral,\n Identifier,\n NullLiteral,\n NumericLiteral,\n StringLiteral,\n} from '@babel/types';\n\nexport type Artifact = [name: string, data: unknown];\n\nexport type BuildCodeFrameErrorFn = <TError extends Error>(\n msg: string,\n Error?: new (innerMsg: string) => TError\n) => TError;\n\nexport enum ValueType {\n LAZY,\n FUNCTION,\n CONST,\n}\n\nexport type LazyValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.LAZY;\n source: string;\n};\n\nexport type FunctionValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.FUNCTION;\n source: string;\n};\n\nexport type ConstValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex:\n | StringLiteral\n | NumericLiteral\n | NullLiteral\n | BooleanLiteral\n | BigIntLiteral\n | DecimalLiteral;\n kind: ValueType.CONST;\n source: string;\n value: string | number | boolean | null;\n};\n\nexport type ExpressionValue = LazyValue | FunctionValue | ConstValue;\n\nexport type WYWEvalMeta = {\n __wyw_meta: {\n className: string;\n extends: WYWEvalMeta;\n };\n};\n\nexport type Location = {\n column: number;\n line: number;\n};\n\nexport type Replacement = {\n length: number;\n original: { end: Location; start: Location };\n};\n\nexport type Replacements = Array<Replacement>;\n\n/**\n * CSS-related types\n */\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n"],"mappings":";;;;;;IAiBYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAyDrB;AACA;AACA"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@wyw-in-js/shared",
3
+ "version": "0.1.0",
4
+ "dependencies": {
5
+ "debug": "^4.3.4",
6
+ "minimatch": "^9.0.3"
7
+ },
8
+ "devDependencies": {
9
+ "@babel/types": "^7.23.0",
10
+ "@types/babel__core": "^7.20.2",
11
+ "@types/debug": "^4.1.9",
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
+ "esm/",
23
+ "lib/",
24
+ "types/"
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,10 @@
1
+ export interface IVariableContext {
2
+ componentName: string;
3
+ componentSlug: string;
4
+ index: number;
5
+ precedingCss: string;
6
+ processor: string;
7
+ source: string;
8
+ unit: string;
9
+ valueSlug: string;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const syncResolve: (what: string, importer: string, stack: string[]) => string;
2
+ export declare const asyncResolveFallback: (what: string, importer: string, stack: string[]) => Promise<string>;
@@ -0,0 +1,45 @@
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.asyncResolveFallback = exports.syncResolve = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const safeResolve = (name, where) => {
9
+ try {
10
+ return require.resolve(name, {
11
+ paths: where,
12
+ });
13
+ }
14
+ catch (e) {
15
+ return e;
16
+ }
17
+ };
18
+ const suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc, ext) => {
19
+ acc.push(`/index${ext}`);
20
+ acc.push(ext);
21
+ return acc;
22
+ }, []);
23
+ const syncResolve = (what, importer, stack) => {
24
+ const where = [importer, ...stack].map((p) => path_1.default.dirname(p));
25
+ const resolved = safeResolve(what, where);
26
+ if (!(resolved instanceof Error)) {
27
+ return resolved;
28
+ }
29
+ // eslint-disable-next-line no-restricted-syntax
30
+ for (const suffix of suffixes) {
31
+ const resolvedWithSuffix = safeResolve(what + suffix, where);
32
+ if (resolvedWithSuffix instanceof Error) {
33
+ // eslint-disable-next-line no-continue
34
+ continue;
35
+ }
36
+ return resolvedWithSuffix;
37
+ }
38
+ throw resolved;
39
+ };
40
+ exports.syncResolve = syncResolve;
41
+ const asyncResolveFallback = (what, importer, stack) => {
42
+ const resolved = (0, exports.syncResolve)(what, importer, stack);
43
+ return Promise.resolve(resolved);
44
+ };
45
+ exports.asyncResolveFallback = asyncResolveFallback;
@@ -0,0 +1,2 @@
1
+ import type core from '@babel/core';
2
+ export type Core = typeof core;
package/types/babel.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import type { WYWEvalMeta } from './types';
2
+ export declare function hasEvalMeta(value: unknown): value is WYWEvalMeta;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasEvalMeta = void 0;
4
+ function hasEvalMeta(value) {
5
+ return typeof value === 'object' && value !== null && '__wyw_meta' in value;
6
+ }
7
+ exports.hasEvalMeta = hasEvalMeta;
@@ -0,0 +1,10 @@
1
+ export { Debugger } from 'debug';
2
+ export { asyncResolveFallback, syncResolve } from './asyncResolveFallback';
3
+ export { hasEvalMeta } from './hasEvalMeta';
4
+ export { isBoxedPrimitive } from './isBoxedPrimitive';
5
+ export { enableDebug, logger } from './logger';
6
+ export { isFeatureEnabled } from './options/isFeatureEnabled';
7
+ export { slugify } from './slugify';
8
+ export { ValueType } from './types';
9
+ export type { ClassNameSlugVars, ClassNameFn, StrictOptions, EvalRule, Evaluator, FeatureFlag, EvaluatorConfig, FeatureFlags, VariableNameFn, } from './options/types';
10
+ export type { Artifact, BuildCodeFrameErrorFn, ConstValue, ExpressionValue, FunctionValue, ICSSRule, LazyValue, Location, Replacement, Replacements, Rules, WYWEvalMeta, } from './types';
package/types/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueType = exports.slugify = exports.isFeatureEnabled = exports.logger = exports.enableDebug = exports.isBoxedPrimitive = exports.hasEvalMeta = exports.syncResolve = exports.asyncResolveFallback = void 0;
4
+ var asyncResolveFallback_1 = require("./asyncResolveFallback");
5
+ Object.defineProperty(exports, "asyncResolveFallback", { enumerable: true, get: function () { return asyncResolveFallback_1.asyncResolveFallback; } });
6
+ Object.defineProperty(exports, "syncResolve", { enumerable: true, get: function () { return asyncResolveFallback_1.syncResolve; } });
7
+ var hasEvalMeta_1 = require("./hasEvalMeta");
8
+ Object.defineProperty(exports, "hasEvalMeta", { enumerable: true, get: function () { return hasEvalMeta_1.hasEvalMeta; } });
9
+ var isBoxedPrimitive_1 = require("./isBoxedPrimitive");
10
+ Object.defineProperty(exports, "isBoxedPrimitive", { enumerable: true, get: function () { return isBoxedPrimitive_1.isBoxedPrimitive; } });
11
+ var logger_1 = require("./logger");
12
+ Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return logger_1.enableDebug; } });
13
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
14
+ var isFeatureEnabled_1 = require("./options/isFeatureEnabled");
15
+ Object.defineProperty(exports, "isFeatureEnabled", { enumerable: true, get: function () { return isFeatureEnabled_1.isFeatureEnabled; } });
16
+ var slugify_1 = require("./slugify");
17
+ Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return slugify_1.slugify; } });
18
+ var types_1 = require("./types");
19
+ Object.defineProperty(exports, "ValueType", { enumerable: true, get: function () { return types_1.ValueType; } });
@@ -0,0 +1 @@
1
+ export declare function isBoxedPrimitive(o: unknown): o is number | string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // There is a problem with using boxed numbers and strings in TS,
3
+ // so we cannot just use `instanceof` here
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.isBoxedPrimitive = void 0;
6
+ const constructors = ['Number', 'String'];
7
+ function isBoxedPrimitive(o) {
8
+ if (typeof o !== 'object' || o === null)
9
+ return false;
10
+ return (constructors.includes(o.constructor.name) &&
11
+ typeof o?.valueOf() !== 'object');
12
+ }
13
+ exports.isBoxedPrimitive = isBoxedPrimitive;
@@ -0,0 +1,3 @@
1
+ import genericDebug from 'debug';
2
+ export declare const logger: genericDebug.Debugger;
3
+ export declare function enableDebug(namespace?: string): void;
@@ -0,0 +1,33 @@
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.enableDebug = exports.logger = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const BASE_NAMESPACE = 'wyw-in-js';
9
+ exports.logger = (0, debug_1.default)(BASE_NAMESPACE);
10
+ const loggers = new Map();
11
+ function gerOrCreate(namespace) {
12
+ if (!namespace)
13
+ return exports.logger;
14
+ const lastIndexOf = namespace.lastIndexOf(':');
15
+ if (!loggers.has(namespace)) {
16
+ loggers.set(namespace, gerOrCreate(namespace.substring(0, lastIndexOf)).extend(namespace.substring(lastIndexOf + 1)));
17
+ }
18
+ return loggers.get(namespace);
19
+ }
20
+ debug_1.default.formatters.r = (ref) => {
21
+ const namespace = typeof ref === 'string' ? ref : ref.namespace;
22
+ const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;
23
+ const color = parseInt(gerOrCreate(namespace).color, 10);
24
+ const colorCode = `\u001B[3${color < 8 ? color : `8;5;${color}`}`;
25
+ return `${colorCode};1m${text}\u001B[0m`;
26
+ };
27
+ debug_1.default.formatters.f = function f(fn) {
28
+ return JSON.stringify(fn());
29
+ };
30
+ function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
31
+ debug_1.default.enable(namespace);
32
+ }
33
+ exports.enableDebug = enableDebug;
@@ -0,0 +1,4 @@
1
+ import type { FeatureFlag } from './types';
2
+ type NoInfer<T> = [T][T extends any ? 0 : never];
3
+ export declare const isFeatureEnabled: <T extends string>(features: { [K in T]?: FeatureFlag | undefined; } | undefined, featureName: NoInfer<T>, filename: string) => boolean;
4
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFeatureEnabled = void 0;
4
+ const minimatch_1 = require("minimatch");
5
+ const cachedMatchers = new Map();
6
+ const isFeatureEnabled = (features, featureName, filename) => {
7
+ const value = features?.[featureName] ?? false;
8
+ if (typeof value === 'boolean') {
9
+ return value;
10
+ }
11
+ // Fast check for glob patterns
12
+ if (value === '*' || value === '**/*') {
13
+ return true;
14
+ }
15
+ const array = Array.isArray(value) ? value : [value];
16
+ /**
17
+ * Check rule by rule like .gitignore
18
+ */
19
+ return array
20
+ .map((pattern) => {
21
+ let matcher = cachedMatchers.get(pattern);
22
+ if (!matcher) {
23
+ matcher = [pattern.startsWith('!'), new minimatch_1.Minimatch(pattern)];
24
+ cachedMatchers.set(pattern, matcher);
25
+ }
26
+ return [matcher[0], matcher[1].match(filename)];
27
+ })
28
+ .reduce((acc, [negated, match]) => (negated ? acc && match : acc || match), false);
29
+ };
30
+ exports.isFeatureEnabled = isFeatureEnabled;
@@ -0,0 +1,57 @@
1
+ /// <reference types="node" />
2
+ import type { Context as VmContext } from 'vm';
3
+ import type { TransformOptions } from '@babel/core';
4
+ import type { File } from '@babel/types';
5
+ import type { IVariableContext } from '../IVariableContext';
6
+ import type { Core } from '../babel';
7
+ export type ClassNameSlugVars = {
8
+ dir: string;
9
+ ext: string;
10
+ file: string;
11
+ hash: string;
12
+ name: string;
13
+ title: string;
14
+ };
15
+ export type ClassNameFn = (hash: string, title: string, args: ClassNameSlugVars) => string;
16
+ export type VariableNameFn = (context: IVariableContext) => string;
17
+ export type EvaluatorConfig = {
18
+ features: StrictOptions['features'];
19
+ highPriorityPlugins: string[];
20
+ onlyExports: string[];
21
+ };
22
+ export type Evaluator = (evalConfig: TransformOptions, ast: File, code: string, config: EvaluatorConfig, babel: Core) => [
23
+ ast: File,
24
+ code: string,
25
+ imports: Map<string, string[]> | null,
26
+ exports?: string[] | null
27
+ ];
28
+ export type EvalRule = {
29
+ action: Evaluator | 'ignore' | string;
30
+ babelOptions?: TransformOptions;
31
+ test?: RegExp | ((path: string, code: string) => boolean);
32
+ };
33
+ export type FeatureFlag = boolean | string | string[];
34
+ type AllFeatureFlags = {
35
+ dangerousCodeRemover: FeatureFlag;
36
+ globalCache: FeatureFlag;
37
+ happyDOM: FeatureFlag;
38
+ softErrors: FeatureFlag;
39
+ useBabelConfigs: FeatureFlag;
40
+ };
41
+ export type FeatureFlags<TOnly extends keyof AllFeatureFlags = keyof AllFeatureFlags> = Pick<AllFeatureFlags, TOnly>;
42
+ export type StrictOptions = {
43
+ babelOptions: TransformOptions;
44
+ classNameSlug?: string | ClassNameFn;
45
+ displayName: boolean;
46
+ evaluate: boolean;
47
+ extensions: string[];
48
+ features: FeatureFlags;
49
+ highPriorityPlugins: string[];
50
+ ignore?: RegExp;
51
+ overrideContext?: (context: Partial<VmContext>, filename: string) => Partial<VmContext>;
52
+ rules: EvalRule[];
53
+ tagResolver?: (source: string, tag: string) => string | null;
54
+ variableNameConfig?: 'var' | 'dashes' | 'raw';
55
+ variableNameSlug?: string | VariableNameFn;
56
+ };
57
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file contains a utility to generate hashes to be used as generated class names
3
+ */
4
+ export declare function slugify(code: string): string;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */
3
+ /**
4
+ * This file contains a utility to generate hashes to be used as generated class names
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.slugify = void 0;
8
+ /**
9
+ * murmurhash2 via https://gist.github.com/raycmorgan/588423
10
+ */
11
+ function UInt32(str, pos) {
12
+ return (str.charCodeAt(pos++) +
13
+ (str.charCodeAt(pos++) << 8) +
14
+ (str.charCodeAt(pos++) << 16) +
15
+ (str.charCodeAt(pos) << 24));
16
+ }
17
+ function UInt16(str, pos) {
18
+ return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);
19
+ }
20
+ function Umul32(n, m) {
21
+ n |= 0;
22
+ m |= 0;
23
+ const nlo = n & 0xffff;
24
+ const nhi = n >>> 16;
25
+ return (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0;
26
+ }
27
+ function doHash(str, seed = 0) {
28
+ const m = 0x5bd1e995;
29
+ const r = 24;
30
+ let h = seed ^ str.length;
31
+ let length = str.length;
32
+ let currentIndex = 0;
33
+ while (length >= 4) {
34
+ let k = UInt32(str, currentIndex);
35
+ k = Umul32(k, m);
36
+ k ^= k >>> r;
37
+ k = Umul32(k, m);
38
+ h = Umul32(h, m);
39
+ h ^= k;
40
+ currentIndex += 4;
41
+ length -= 4;
42
+ }
43
+ switch (length) {
44
+ case 3:
45
+ h ^= UInt16(str, currentIndex);
46
+ h ^= str.charCodeAt(currentIndex + 2) << 16;
47
+ h = Umul32(h, m);
48
+ break;
49
+ case 2:
50
+ h ^= UInt16(str, currentIndex);
51
+ h = Umul32(h, m);
52
+ break;
53
+ case 1:
54
+ h ^= str.charCodeAt(currentIndex);
55
+ h = Umul32(h, m);
56
+ break;
57
+ }
58
+ h ^= h >>> 13;
59
+ h = Umul32(h, m);
60
+ h ^= h >>> 15;
61
+ return h >>> 0;
62
+ }
63
+ function slugify(code) {
64
+ return doHash(code).toString(36);
65
+ }
66
+ exports.slugify = slugify;
@@ -0,0 +1,59 @@
1
+ import type { BigIntLiteral, BooleanLiteral, DecimalLiteral, Identifier, NullLiteral, NumericLiteral, StringLiteral } from '@babel/types';
2
+ export type Artifact = [name: string, data: unknown];
3
+ export type BuildCodeFrameErrorFn = <TError extends Error>(msg: string, Error?: new (innerMsg: string) => TError) => TError;
4
+ export declare enum ValueType {
5
+ LAZY = 0,
6
+ FUNCTION = 1,
7
+ CONST = 2
8
+ }
9
+ export type LazyValue = {
10
+ buildCodeFrameError: BuildCodeFrameErrorFn;
11
+ ex: Identifier;
12
+ importedFrom?: string[];
13
+ kind: ValueType.LAZY;
14
+ source: string;
15
+ };
16
+ export type FunctionValue = {
17
+ buildCodeFrameError: BuildCodeFrameErrorFn;
18
+ ex: Identifier;
19
+ importedFrom?: string[];
20
+ kind: ValueType.FUNCTION;
21
+ source: string;
22
+ };
23
+ export type ConstValue = {
24
+ buildCodeFrameError: BuildCodeFrameErrorFn;
25
+ ex: StringLiteral | NumericLiteral | NullLiteral | BooleanLiteral | BigIntLiteral | DecimalLiteral;
26
+ kind: ValueType.CONST;
27
+ source: string;
28
+ value: string | number | boolean | null;
29
+ };
30
+ export type ExpressionValue = LazyValue | FunctionValue | ConstValue;
31
+ export type WYWEvalMeta = {
32
+ __wyw_meta: {
33
+ className: string;
34
+ extends: WYWEvalMeta;
35
+ };
36
+ };
37
+ export type Location = {
38
+ column: number;
39
+ line: number;
40
+ };
41
+ export type Replacement = {
42
+ length: number;
43
+ original: {
44
+ end: Location;
45
+ start: Location;
46
+ };
47
+ };
48
+ export type Replacements = Array<Replacement>;
49
+ /**
50
+ * CSS-related types
51
+ */
52
+ export interface ICSSRule {
53
+ atom?: boolean;
54
+ className: string;
55
+ cssText: string;
56
+ displayName: string;
57
+ start: Location | null | undefined;
58
+ }
59
+ export type Rules = Record<string, ICSSRule>;
package/types/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueType = void 0;
4
+ var ValueType;
5
+ (function (ValueType) {
6
+ ValueType[ValueType["LAZY"] = 0] = "LAZY";
7
+ ValueType[ValueType["FUNCTION"] = 1] = "FUNCTION";
8
+ ValueType[ValueType["CONST"] = 2] = "CONST";
9
+ })(ValueType || (exports.ValueType = ValueType = {}));