@wyw-in-js/processor-utils 0.8.1 → 1.0.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.
- package/esm/BaseProcessor.js.map +1 -1
- package/esm/TaggedTemplateProcessor.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/buildSlug.js.map +1 -1
- package/esm/utils/getClassNameAndSlug.js.map +1 -1
- package/esm/utils/getVariableName.js.map +1 -1
- package/esm/utils/stripLines.js.map +1 -1
- package/esm/utils/templateProcessor.js.map +1 -1
- package/esm/utils/throwIfInvalid.js.map +1 -1
- package/esm/utils/toCSS.js.map +1 -1
- package/esm/utils/toValidCSSIdentifier.js.map +1 -1
- package/esm/utils/types.js.map +1 -1
- package/esm/utils/units.js.map +1 -1
- package/esm/utils/validateParams.js.map +1 -1
- package/lib/BaseProcessor.js +1 -1
- package/lib/BaseProcessor.js.map +1 -1
- package/lib/TaggedTemplateProcessor.js +1 -1
- package/lib/TaggedTemplateProcessor.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/buildSlug.js.map +1 -1
- package/lib/utils/getClassNameAndSlug.js.map +1 -1
- package/lib/utils/getVariableName.js.map +1 -1
- package/lib/utils/stripLines.js.map +1 -1
- package/lib/utils/templateProcessor.js +2 -3
- package/lib/utils/templateProcessor.js.map +1 -1
- package/lib/utils/throwIfInvalid.js.map +1 -1
- package/lib/utils/toCSS.js.map +1 -1
- package/lib/utils/toValidCSSIdentifier.js.map +1 -1
- package/lib/utils/types.js.map +1 -1
- package/lib/utils/units.js.map +1 -1
- package/lib/utils/validateParams.js.map +1 -1
- package/package.json +10 -11
- package/types/utils/buildSlug.js +1 -2
- package/types/utils/getClassNameAndSlug.js +1 -1
- package/types/utils/getVariableName.js +1 -2
- package/types/utils/stripLines.js +1 -1
- package/types/utils/templateProcessor.js +18 -8
- package/types/utils/toCSS.d.ts +2 -2
- package/types/utils/toCSS.js +1 -1
- package/types/utils/toValidCSSIdentifier.js +1 -2
- package/types/utils/validateParams.js +2 -3
- package/LICENSE +0 -21
package/esm/BaseProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProcessor.js","names":["generator","hasEvalMeta","getClassNameAndSlug","isCSSable","validateParams","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","className","slug","callee","isValidValue","value","toString","tagSourceCode","type","name","code"],"sources":["../src/BaseProcessor.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport type { NodePath, types as t } from '@babel/core';\nimport generator from '@babel/generator';\nimport type {\n Expression,\n Identifier,\n SourceLocation,\n MemberExpression,\n} from '@babel/types';\n\nimport type { Artifact, ExpressionValue } from '@wyw-in-js/shared';\nimport { hasEvalMeta } from '@wyw-in-js/shared';\n\nimport type { IInterpolation, Params, Value, ValueCache } from './types';\nimport getClassNameAndSlug from './utils/getClassNameAndSlug';\nimport { isCSSable } from './utils/toCSS';\nimport type { IFileContext, IOptions } from './utils/types';\nimport { validateParams } from './utils/validateParams';\n\nexport { Expression };\n\nexport type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;\nexport type TailProcessorParams = ProcessorParams extends [Params, ...infer T]\n ? T\n : never;\n\nexport type TagSource = {\n imported: string;\n source: string;\n};\n\nexport abstract class BaseProcessor {\n public static SKIP = Symbol('skip');\n\n public readonly artifacts: Artifact[] = [];\n\n public readonly className: string;\n\n public readonly dependencies: ExpressionValue[] = [];\n\n public interpolations: IInterpolation[] = [];\n\n public readonly slug: string;\n\n protected callee: Identifier | MemberExpression;\n\n protected evaluated:\n | Record<'dependencies' | 'expression', Value[]>\n | undefined;\n\n public constructor(\n params: Params,\n public tagSource: TagSource,\n protected readonly astService: typeof t & {\n addDefaultImport: (source: string, nameHint?: string) => Identifier;\n addNamedImport: (\n name: string,\n source: string,\n nameHint?: string\n ) => Identifier;\n },\n public readonly location: SourceLocation | null,\n protected readonly replacer: (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => void,\n public readonly displayName: string,\n public readonly isReferenced: boolean,\n protected readonly idx: number,\n protected readonly options: IOptions,\n protected readonly context: IFileContext\n ) {\n validateParams(\n params,\n ['callee'],\n 'Unknown error: a callee param is not specified'\n );\n\n const { className, slug } = getClassNameAndSlug(\n this.displayName,\n this.idx,\n this.options,\n this.context\n );\n\n this.className = className;\n this.slug = slug;\n\n [[, this.callee]] = params;\n }\n\n /**\n * A replacement for tag referenced in a template literal.\n */\n public abstract get asSelector(): string;\n\n /**\n * A replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract get value(): Expression;\n\n public isValidValue(value: unknown): value is Value {\n return (\n typeof value === 'function' || isCSSable(value) || hasEvalMeta(value)\n );\n }\n\n public toString(): string {\n return this.tagSourceCode();\n }\n\n protected tagSourceCode(): string {\n if (this.callee.type === 'Identifier') {\n return this.callee.name;\n }\n\n return generator(this.callee).code;\n }\n\n public abstract build(values: ValueCache): void;\n\n /**\n * Perform a replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract doEvaltimeReplacement(): void;\n\n /**\n * Perform a replacement for the tag with its runtime version.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with a component.\n * If some parts require evaluated data for render,\n * they will be replaced with placeholders.\n */\n public abstract doRuntimeReplacement(): void;\n}\n"],"mappings":"AAAA;;AAEA,OAAOA,SAAS,MAAM,kBAAkB;AASxC,SAASC,WAAW,QAAQ,mBAAmB;AAG/C,OAAOC,mBAAmB,MAAM,6BAA6B;AAC7D,SAASC,SAAS,QAAQ,eAAe;AAEzC,SAASC,cAAc,QAAQ,wBAAwB;AAcvD,OAAO,MAAeC,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,M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A,EAAW;IAChC,IAAI,IAAI,CAACJ,MAAM,CAACK,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACL,MAAM,CAACM,IAAI;IACzB;IAEA,OAAO9B,SAAS,CAAC,IAAI,CAACwB,MAAM,CAAC,CAACO,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA"}
|
|
1
|
+
{"version":3,"file":"BaseProcessor.js","names":["generator","hasEvalMeta","getClassNameAndSlug","isCSSable","validateParams","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","className","slug","callee","isValidValue","value","toString","tagSourceCode","type","name","code"],"sources":["../src/BaseProcessor.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport type { NodePath, types as t } from '@babel/core';\nimport generator from '@babel/generator';\nimport type {\n Expression,\n Identifier,\n SourceLocation,\n MemberExpression,\n} from '@babel/types';\n\nimport type { Artifact, ExpressionValue } from '@wyw-in-js/shared';\nimport { hasEvalMeta } from '@wyw-in-js/shared';\n\nimport type { IInterpolation, Params, Value, ValueCache } from './types';\nimport getClassNameAndSlug from './utils/getClassNameAndSlug';\nimport { isCSSable } from './utils/toCSS';\nimport type { IFileContext, IOptions } from './utils/types';\nimport { validateParams } from './utils/validateParams';\n\nexport { Expression };\n\nexport type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;\nexport type TailProcessorParams = ProcessorParams extends [Params, ...infer T]\n ? T\n : never;\n\nexport type TagSource = {\n imported: string;\n source: string;\n};\n\nexport abstract class BaseProcessor {\n public static SKIP = Symbol('skip');\n\n public readonly artifacts: Artifact[] = [];\n\n public readonly className: string;\n\n public readonly dependencies: ExpressionValue[] = [];\n\n public interpolations: IInterpolation[] = [];\n\n public readonly slug: string;\n\n protected callee: Identifier | MemberExpression;\n\n protected evaluated:\n | Record<'dependencies' | 'expression', Value[]>\n | undefined;\n\n public constructor(\n params: Params,\n public tagSource: TagSource,\n protected readonly astService: typeof t & {\n addDefaultImport: (source: string, nameHint?: string) => Identifier;\n addNamedImport: (\n name: string,\n source: string,\n nameHint?: string\n ) => Identifier;\n },\n public readonly location: SourceLocation | null,\n protected readonly replacer: (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => void,\n public readonly displayName: string,\n public readonly isReferenced: boolean,\n protected readonly idx: number,\n protected readonly options: IOptions,\n protected readonly context: IFileContext\n ) {\n validateParams(\n params,\n ['callee'],\n 'Unknown error: a callee param is not specified'\n );\n\n const { className, slug } = getClassNameAndSlug(\n this.displayName,\n this.idx,\n this.options,\n this.context\n );\n\n this.className = className;\n this.slug = slug;\n\n [[, this.callee]] = params;\n }\n\n /**\n * A replacement for tag referenced in a template literal.\n */\n public abstract get asSelector(): string;\n\n /**\n * A replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract get value(): Expression;\n\n public isValidValue(value: unknown): value is Value {\n return (\n typeof value === 'function' || isCSSable(value) || hasEvalMeta(value)\n );\n }\n\n public toString(): string {\n return this.tagSourceCode();\n }\n\n protected tagSourceCode(): string {\n if (this.callee.type === 'Identifier') {\n return this.callee.name;\n }\n\n return generator(this.callee).code;\n }\n\n public abstract build(values: ValueCache): void;\n\n /**\n * Perform a replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract doEvaltimeReplacement(): void;\n\n /**\n * Perform a replacement for the tag with its runtime version.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with a component.\n * If some parts require evaluated data for render,\n * they will be replaced with placeholders.\n */\n public abstract doRuntimeReplacement(): void;\n}\n"],"mappings":"AAAA;;AAEA,OAAOA,SAAS,MAAM,kBAAkB;AASxC,SAASC,WAAW,QAAQ,mBAAmB;AAG/C,OAAOC,mBAAmB,MAAM,6BAA6B;AAC7D,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CAACyB,KAAK,CAAC;EAEzE;EAEOC,QAAQA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,aAAa,CAAC,CAAC;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACJ,MAAM,CAACK,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACL,MAAM,CAACM,IAAI;IACzB;IAEA,OAAO9B,SAAS,CAAC,IAAI,CAACwB,MAAM,CAAC,CAACO,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaggedTemplateProcessor.js","names":["ValueType","BaseProcessor","templateProcessor","validateParams","TaggedTemplateProcessor","template","constructor","params","args","SKIP","tag","forEach","element","kind","FUNCTION","dependencies","push","build","values","artifacts","length","Error","artifact","options","variableNameConfig","toString"],"sources":["../src/TaggedTemplateProcessor.ts"],"sourcesContent":["import type { TemplateElement, Expression, SourceLocation } from '@babel/types';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\n\nimport type { TailProcessorParams } from './BaseProcessor';\nimport { BaseProcessor } from './BaseProcessor';\nimport type { ValueCache, Rules, Params } from './types';\nimport templateProcessor from './utils/templateProcessor';\nimport { validateParams } from './utils/validateParams';\n\nexport abstract class TaggedTemplateProcessor extends BaseProcessor {\n readonly #template: (TemplateElement | ExpressionValue)[];\n\n protected constructor(params: Params, ...args: TailProcessorParams) {\n // Should have at least two params and the first one should be a callee.\n validateParams(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);\n\n validateParams(\n params,\n ['callee', 'template'],\n 'Invalid usage of template tag'\n );\n const [tag, [, template]] = params;\n\n super([tag], ...args);\n\n template.forEach((element) => {\n if ('kind' in element && element.kind !== ValueType.FUNCTION) {\n this.dependencies.push(element);\n }\n });\n\n this.#template = template;\n }\n\n public override build(values: ValueCache) {\n if (this.artifacts.length > 0) {\n // FIXME: why it was called twice?\n throw new Error('Tag is already built');\n }\n\n const artifact = templateProcessor(\n this,\n this.#template,\n values,\n this.options.variableNameConfig\n );\n if (artifact) {\n this.artifacts.push(['css', artifact]);\n }\n }\n\n public override toString(): string {\n return `${super.toString()}\\`…\\``;\n }\n\n /**\n * It is called for each resolved expression in a template literal.\n * @param node\n * @param precedingCss\n * @param source\n * @param unit\n * @return chunk of CSS that should be added to extracted CSS\n */\n public abstract addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit?: string\n ): string;\n\n public abstract extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules;\n}\n"],"mappings":"AAGA,SAASA,SAAS,QAAQ,mBAAmB;AAG7C,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,OAAOC,iBAAiB,MAAM,2BAA2B;AACzD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,OAAO,MAAeC,uBAAuB,SAASH,aAAa,CAAC;EACzD,CAACI,QAAQ;EAERC,WAAWA,CAACC,MAAc,EAAE,GAAGC,IAAyB,EAAE;IAClE;IACAL,cAAc,CAACI,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAEH,uBAAuB,CAACK,IAAI,CAAC;IAEvEN,cAAc,CACZI,MAAM,EACN,CAAC,QAAQ,EAAE,UAAU,CAAC,EACtB,+BACF,CAAC;IACD,MAAM,CAACG,GAAG,EAAE,GAAGL,QAAQ,CAAC,CAAC,GAAGE,MAAM;IAElC,KAAK,CAAC,CAACG,GAAG,CAAC,EAAE,GAAGF,IAAI,CAAC;IAErBH,QAAQ,CAACM,OAAO,CAAEC,OAAO,IAAK;MAC5B,IAAI,MAAM,IAAIA,OAAO,IAAIA,OAAO,CAACC,IAAI,KAAKb,SAAS,CAACc,QAAQ,EAAE;QAC5D,IAAI,CAACC,YAAY,CAACC,IAAI,CAACJ,OAAO,CAAC;MACjC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,CAACP,QAAQ,GAAGA,QAAQ;EAC3B;EAEgBY,KAAKA,CAACC,MAAkB,EAAE;IACxC,IAAI,IAAI,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IAEA,MAAMC,QAAQ,GAAGpB,iBAAiB,CAChC,IAAI,EACJ,IAAI,CAAC,CAACG,QAAQ,EACda,MAAM,EACN,IAAI,CAACK,OAAO,CAACC,kBACf,CAAC;IACD,IAAIF,QAAQ,EAAE;MACZ,IAAI,CAACH,SAAS,CAACH,IAAI,CAAC,CAAC,KAAK,EAAEM,QAAQ,CAAC,CAAC;IACxC;EACF;EAEgBG,QAAQA,CAAA,EAAW;IACjC,
|
|
1
|
+
{"version":3,"file":"TaggedTemplateProcessor.js","names":["ValueType","BaseProcessor","templateProcessor","validateParams","TaggedTemplateProcessor","template","constructor","params","args","SKIP","tag","forEach","element","kind","FUNCTION","dependencies","push","build","values","artifacts","length","Error","artifact","options","variableNameConfig","toString"],"sources":["../src/TaggedTemplateProcessor.ts"],"sourcesContent":["import type { TemplateElement, Expression, SourceLocation } from '@babel/types';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\n\nimport type { TailProcessorParams } from './BaseProcessor';\nimport { BaseProcessor } from './BaseProcessor';\nimport type { ValueCache, Rules, Params } from './types';\nimport templateProcessor from './utils/templateProcessor';\nimport { validateParams } from './utils/validateParams';\n\nexport abstract class TaggedTemplateProcessor extends BaseProcessor {\n readonly #template: (TemplateElement | ExpressionValue)[];\n\n protected constructor(params: Params, ...args: TailProcessorParams) {\n // Should have at least two params and the first one should be a callee.\n validateParams(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);\n\n validateParams(\n params,\n ['callee', 'template'],\n 'Invalid usage of template tag'\n );\n const [tag, [, template]] = params;\n\n super([tag], ...args);\n\n template.forEach((element) => {\n if ('kind' in element && element.kind !== ValueType.FUNCTION) {\n this.dependencies.push(element);\n }\n });\n\n this.#template = template;\n }\n\n public override build(values: ValueCache) {\n if (this.artifacts.length > 0) {\n // FIXME: why it was called twice?\n throw new Error('Tag is already built');\n }\n\n const artifact = templateProcessor(\n this,\n this.#template,\n values,\n this.options.variableNameConfig\n );\n if (artifact) {\n this.artifacts.push(['css', artifact]);\n }\n }\n\n public override toString(): string {\n return `${super.toString()}\\`…\\``;\n }\n\n /**\n * It is called for each resolved expression in a template literal.\n * @param node\n * @param precedingCss\n * @param source\n * @param unit\n * @return chunk of CSS that should be added to extracted CSS\n */\n public abstract addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit?: string\n ): string;\n\n public abstract extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules;\n}\n"],"mappings":"AAGA,SAASA,SAAS,QAAQ,mBAAmB;AAG7C,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,OAAOC,iBAAiB,MAAM,2BAA2B;AACzD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,OAAO,MAAeC,uBAAuB,SAASH,aAAa,CAAC;EACzD,CAACI,QAAQ;EAERC,WAAWA,CAACC,MAAc,EAAE,GAAGC,IAAyB,EAAE;IAClE;IACAL,cAAc,CAACI,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAEH,uBAAuB,CAACK,IAAI,CAAC;IAEvEN,cAAc,CACZI,MAAM,EACN,CAAC,QAAQ,EAAE,UAAU,CAAC,EACtB,+BACF,CAAC;IACD,MAAM,CAACG,GAAG,EAAE,GAAGL,QAAQ,CAAC,CAAC,GAAGE,MAAM;IAElC,KAAK,CAAC,CAACG,GAAG,CAAC,EAAE,GAAGF,IAAI,CAAC;IAErBH,QAAQ,CAACM,OAAO,CAAEC,OAAO,IAAK;MAC5B,IAAI,MAAM,IAAIA,OAAO,IAAIA,OAAO,CAACC,IAAI,KAAKb,SAAS,CAACc,QAAQ,EAAE;QAC5D,IAAI,CAACC,YAAY,CAACC,IAAI,CAACJ,OAAO,CAAC;MACjC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,CAACP,QAAQ,GAAGA,QAAQ;EAC3B;EAEgBY,KAAKA,CAACC,MAAkB,EAAE;IACxC,IAAI,IAAI,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IAEA,MAAMC,QAAQ,GAAGpB,iBAAiB,CAChC,IAAI,EACJ,IAAI,CAAC,CAACG,QAAQ,EACda,MAAM,EACN,IAAI,CAACK,OAAO,CAACC,kBACf,CAAC;IACD,IAAIF,QAAQ,EAAE;MACZ,IAAI,CAACH,SAAS,CAACH,IAAI,CAAC,CAAC,KAAK,EAAEM,QAAQ,CAAC,CAAC;IACxC;EACF;EAEgBG,QAAQA,CAAA,EAAW;IACjC,OAAO,GAAG,KAAK,CAACA,QAAQ,CAAC,CAAC,OAAO;EACnC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAaA","ignoreList":[]}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["BaseProcessor","buildSlug","isValidParams","validateParams","TaggedTemplateProcessor","toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iBAAiB;AAO/C,cAAc,SAAS;AACvB,SAASC,SAAS,QAAQ,mBAAmB;AAE7C,SAASC,aAAa,EAAEC,cAAc,QAAQ,wBAAwB;AAEtE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,8BAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["BaseProcessor","buildSlug","isValidParams","validateParams","TaggedTemplateProcessor","toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iBAAiB;AAO/C,cAAc,SAAS;AACvB,SAASC,SAAS,QAAQ,mBAAmB;AAE7C,SAASC,aAAa,EAAEC,cAAc,QAAQ,wBAAwB;AAEtE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,8BAA8B","ignoreList":[]}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":"AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAEpC,OAAO,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":"AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAEpC,OAAO,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClassNameAndSlug.js","names":["basename","dirname","extname","relative","sep","posix","logger","slugify","buildSlug","toValidCSSIdentifier","getClassNameAndSlug","displayName","idx","options","context","relativeFilename","root","filename","replace","slug","charAt","toLowerCase","ext","slugVars","hash","title","index","file","name","dir","split","pop","className","classNameSlug","Error","extend"],"sources":["../../src/utils/getClassNameAndSlug.ts"],"sourcesContent":["import { basename, dirname, extname, relative, sep, posix } from 'path';\n\nimport type { ClassNameSlugVars } from '@wyw-in-js/shared';\nimport { logger, slugify } from '@wyw-in-js/shared';\n\nimport { buildSlug } from './buildSlug';\nimport { toValidCSSIdentifier } from './toValidCSSIdentifier';\nimport type { IFileContext, IOptions } from './types';\n\nexport default function getClassNameAndSlug(\n displayName: string,\n idx: number,\n options: IOptions,\n context: IFileContext\n): { className: string; slug: string } {\n const relativeFilename = (\n context.root && context.filename\n ? relative(context.root, context.filename)\n : context.filename ?? 'unknown'\n ).replace(/\\\\/g, posix.sep);\n\n // Custom properties need to start with a letter, so we prefix the slug\n // Also use append the index of the class to the filename for uniqueness in the file\n const slug = toValidCSSIdentifier(\n `${displayName.charAt(0).toLowerCase()}${slugify(\n `${relativeFilename}:${idx}`\n )}`\n );\n\n // Collect some useful replacement patterns from the filename\n // Available variables for the square brackets used in `classNameSlug` options\n const ext = extname(relativeFilename);\n const slugVars: ClassNameSlugVars = {\n hash: slug,\n title: displayName,\n index: idx,\n file: relativeFilename,\n ext,\n name: basename(relativeFilename, ext),\n dir: dirname(relativeFilename).split(sep).pop() as string,\n };\n\n let className = options.displayName\n ? `${toValidCSSIdentifier(displayName!)}_${slug!}`\n : slug!;\n\n // The className can be defined by the user either as fn or a string\n if (typeof options.classNameSlug === 'function') {\n try {\n className = toValidCSSIdentifier(\n options.classNameSlug(slug, displayName, slugVars)\n );\n } catch {\n throw new Error('classNameSlug option must return a string');\n }\n }\n\n if (typeof options.classNameSlug === 'string') {\n className = toValidCSSIdentifier(\n buildSlug(options.classNameSlug, slugVars)\n );\n }\n\n logger.extend('template-parse:generated-meta')(\n `slug: ${slug}, displayName: ${displayName}, className: ${className}`\n );\n\n return { className, slug };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,QAAQ,MAAM;AAGvE,SAASC,MAAM,EAAEC,OAAO,QAAQ,mBAAmB;AAEnD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,oBAAoB,QAAQ,wBAAwB;AAG7D,eAAe,SAASC,mBAAmBA,CACzCC,WAAmB,EACnBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACgB;EACrC,MAAMC,gBAAgB,GAAG,CACvBD,OAAO,CAACE,IAAI,IAAIF,OAAO,CAACG,QAAQ,GAC5Bd,QAAQ,CAACW,OAAO,CAACE,IAAI,EAAEF,OAAO,CAACG,QAAQ,CAAC,GACxCH,OAAO,CAACG,QAAQ,IAAI,SAAS,EACjCC,OAAO,CAAC,KAAK,EAAEb,KAAK,CAACD,GAAG,CAAC;;EAE3B;EACA;EACA,MAAMe,IAAI,GAAGV,oBAAoB,
|
|
1
|
+
{"version":3,"file":"getClassNameAndSlug.js","names":["basename","dirname","extname","relative","sep","posix","logger","slugify","buildSlug","toValidCSSIdentifier","getClassNameAndSlug","displayName","idx","options","context","relativeFilename","root","filename","replace","slug","charAt","toLowerCase","ext","slugVars","hash","title","index","file","name","dir","split","pop","className","classNameSlug","Error","extend"],"sources":["../../src/utils/getClassNameAndSlug.ts"],"sourcesContent":["import { basename, dirname, extname, relative, sep, posix } from 'path';\n\nimport type { ClassNameSlugVars } from '@wyw-in-js/shared';\nimport { logger, slugify } from '@wyw-in-js/shared';\n\nimport { buildSlug } from './buildSlug';\nimport { toValidCSSIdentifier } from './toValidCSSIdentifier';\nimport type { IFileContext, IOptions } from './types';\n\nexport default function getClassNameAndSlug(\n displayName: string,\n idx: number,\n options: IOptions,\n context: IFileContext\n): { className: string; slug: string } {\n const relativeFilename = (\n context.root && context.filename\n ? relative(context.root, context.filename)\n : context.filename ?? 'unknown'\n ).replace(/\\\\/g, posix.sep);\n\n // Custom properties need to start with a letter, so we prefix the slug\n // Also use append the index of the class to the filename for uniqueness in the file\n const slug = toValidCSSIdentifier(\n `${displayName.charAt(0).toLowerCase()}${slugify(\n `${relativeFilename}:${idx}`\n )}`\n );\n\n // Collect some useful replacement patterns from the filename\n // Available variables for the square brackets used in `classNameSlug` options\n const ext = extname(relativeFilename);\n const slugVars: ClassNameSlugVars = {\n hash: slug,\n title: displayName,\n index: idx,\n file: relativeFilename,\n ext,\n name: basename(relativeFilename, ext),\n dir: dirname(relativeFilename).split(sep).pop() as string,\n };\n\n let className = options.displayName\n ? `${toValidCSSIdentifier(displayName!)}_${slug!}`\n : slug!;\n\n // The className can be defined by the user either as fn or a string\n if (typeof options.classNameSlug === 'function') {\n try {\n className = toValidCSSIdentifier(\n options.classNameSlug(slug, displayName, slugVars)\n );\n } catch {\n throw new Error('classNameSlug option must return a string');\n }\n }\n\n if (typeof options.classNameSlug === 'string') {\n className = toValidCSSIdentifier(\n buildSlug(options.classNameSlug, slugVars)\n );\n }\n\n logger.extend('template-parse:generated-meta')(\n `slug: ${slug}, displayName: ${displayName}, className: ${className}`\n );\n\n return { className, slug };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,QAAQ,MAAM;AAGvE,SAASC,MAAM,EAAEC,OAAO,QAAQ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O,CAACoB,aAAa,CAACd,IAAI,EAAER,WAAW,EAAEY,QAAQ,CACnD,CAAC;IACH,CAAC,CAAC,MAAM;MACN,MAAM,IAAIW,KAAK,CAAC,2CAA2C,CAAC;IAC9D;EACF;EAEA,IAAI,OAAOrB,OAAO,CAACoB,aAAa,KAAK,QAAQ,EAAE;IAC7CD,SAAS,GAAGvB,oBAAoB,CAC9BD,SAAS,CAACK,OAAO,CAACoB,aAAa,EAAEV,QAAQ,CAC3C,CAAC;EACH;EAEAjB,MAAM,CAAC6B,MAAM,CAAC,+BAA+B,CAAC,CAC5C,SAAShB,IAAI,kBAAkBR,WAAW,gBAAgBqB,SAAS,EACrE,CAAC;EAED,OAAO;IAAEA,SAAS;IAAEb;EAAK,CAAC;AAC5B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVariableName.js","names":["getVariableName","varId","rawVariableName"],"sources":["../../src/utils/getVariableName.ts"],"sourcesContent":["import type { IOptions } from './types';\n\nexport function getVariableName(\n varId: string,\n rawVariableName: IOptions['variableNameConfig'] | undefined\n) {\n switch (rawVariableName) {\n case 'raw':\n return varId;\n case 'dashes':\n return `--${varId}`;\n case 'var':\n default:\n return `var(--${varId})`;\n }\n}\n"],"mappings":"AAEA,OAAO,SAASA,eAAeA,CAC7BC,KAAa,EACbC,eAA2D,EAC3D;EACA,QAAQA,eAAe;IACrB,KAAK,KAAK;MACR,OAAOD,KAAK;IACd,KAAK,QAAQ;MACX,
|
|
1
|
+
{"version":3,"file":"getVariableName.js","names":["getVariableName","varId","rawVariableName"],"sources":["../../src/utils/getVariableName.ts"],"sourcesContent":["import type { IOptions } from './types';\n\nexport function getVariableName(\n varId: string,\n rawVariableName: IOptions['variableNameConfig'] | undefined\n) {\n switch (rawVariableName) {\n case 'raw':\n return varId;\n case 'dashes':\n return `--${varId}`;\n case 'var':\n default:\n return `var(--${varId})`;\n }\n}\n"],"mappings":"AAEA,OAAO,SAASA,eAAeA,CAC7BC,KAAa,EACbC,eAA2D,EAC3D;EACA,QAAQA,eAAe;IACrB,KAAK,KAAK;MACR,OAAOD,KAAK;IACd,KAAK,QAAQ;MACX,OAAO,KAAKA,KAAK,EAAE;IACrB,KAAK,KAAK;IACV;MACE,OAAO,SAASA,KAAK,GAAG;EAC5B;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripLines.js","names":["stripLines","loc","text","result","String","replace","trim","start","line","end","repeat","column"],"sources":["../../src/utils/stripLines.ts"],"sourcesContent":["import type { Location } from '@wyw-in-js/shared';\n\n// Stripping away the new lines ensures that we preserve line numbers\n// This is useful in case of tools such as the stylelint pre-processor\n// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings\nexport default function stripLines(\n loc: { end: Location; start: Location },\n text: string | number\n) {\n let result = String(text)\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n\n // If the start and end line numbers aren't same, add new lines to span the text across multiple lines\n if (loc.start.line !== loc.end.line) {\n result += '\\n'.repeat(loc.end.line - loc.start.line);\n\n // Add extra spaces to offset the column\n result += ' '.repeat(loc.end.column);\n }\n\n return result;\n}\n"],"mappings":"AAEA;AACA;AACA;AACA,eAAe,SAASA,UAAUA,CAChCC,GAAuC,EACvCC,IAAqB,EACrB;EACA,IAAIC,MAAM,GAAGC,MAAM,CAACF,IAAI,CAAC,CACtBG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CACxBC,IAAI,CAAC,CAAC;;EAET;EACA,IAAIL,GAAG,CAACM,KAAK,CAACC,IAAI,KAAKP,GAAG,CAACQ,GAAG,CAACD,IAAI,EAAE;IACnCL,MAAM,IAAI,IAAI,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACD,IAAI,GAAGP,GAAG,CAACM,KAAK,CAACC,IAAI,CAAC;;IAEpD;IACAL,MAAM,IAAI,GAAG,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACE,MAAM,CAAC;EACtC;EAEA,OAAOR,MAAM;AACf"}
|
|
1
|
+
{"version":3,"file":"stripLines.js","names":["stripLines","loc","text","result","String","replace","trim","start","line","end","repeat","column"],"sources":["../../src/utils/stripLines.ts"],"sourcesContent":["import type { Location } from '@wyw-in-js/shared';\n\n// Stripping away the new lines ensures that we preserve line numbers\n// This is useful in case of tools such as the stylelint pre-processor\n// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings\nexport default function stripLines(\n loc: { end: Location; start: Location },\n text: string | number\n) {\n let result = String(text)\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n\n // If the start and end line numbers aren't same, add new lines to span the text across multiple lines\n if (loc.start.line !== loc.end.line) {\n result += '\\n'.repeat(loc.end.line - loc.start.line);\n\n // Add extra spaces to offset the column\n result += ' '.repeat(loc.end.column);\n }\n\n return result;\n}\n"],"mappings":"AAEA;AACA;AACA;AACA,eAAe,SAASA,UAAUA,CAChCC,GAAuC,EACvCC,IAAqB,EACrB;EACA,IAAIC,MAAM,GAAGC,MAAM,CAACF,IAAI,CAAC,CACtBG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CACxBC,IAAI,CAAC,CAAC;;EAET;EACA,IAAIL,GAAG,CAACM,KAAK,CAACC,IAAI,KAAKP,GAAG,CAACQ,GAAG,CAACD,IAAI,EAAE;IACnCL,MAAM,IAAI,IAAI,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACD,IAAI,GAAGP,GAAG,CAACM,KAAK,CAACC,IAAI,CAAC;;IAEpD;IACAL,MAAM,IAAI,GAAG,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACE,MAAM,CAAC;EACtC;EAEA,OAAOR,MAAM;AACf","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateProcessor.js","names":["hasEvalMeta","ValueType","getVariableName","stripLines","throwIfInvalid","toCSS","isCSSable","units","unitRegex","RegExp","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","get","name","kind","FUNCTION","matches","match","unit","varId","addInterpolation","source","substring","e","Error","buildCodeFrameError","message","isValidValue","bind","undefined","__wyw_meta","className","push","original","rules","extractRules","location","includes"],"sources":["../../src/utils/templateProcessor.ts"],"sourcesContent":["/* eslint-disable no-continue */\n/**\n * This file handles transforming template literals to class names or styled components and generates CSS content.\n * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.\n */\n\nimport type { TemplateElement } from '@babel/types';\n\nimport type { ExpressionValue, Replacements } from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType } from '@wyw-in-js/shared';\n\nimport type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';\nimport type { ValueCache, Rules } from '../types';\n\nimport { getVariableName } from './getVariableName';\nimport stripLines from './stripLines';\nimport throwIfInvalid from './throwIfInvalid';\nimport toCSS, { isCSSable } from './toCSS';\nimport type { IOptions } from './types';\nimport { units } from './units';\n\n// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);\n\nexport default function templateProcessor(\n tagProcessor: TaggedTemplateProcessor,\n [...template]: (TemplateElement | ExpressionValue)[],\n valueCache: ValueCache,\n variableNameConfig: IOptions['variableNameConfig'] | undefined\n): [rules: Rules, sourceMapReplacements: Replacements] | null {\n const sourceMapReplacements: Replacements = [];\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n const { isReferenced } = tagProcessor;\n\n // Serialize the tagged template literal to a string\n let cssText = '';\n\n let item: TemplateElement | ExpressionValue | undefined;\n // eslint-disable-next-line no-cond-assign\n while ((item = template.shift())) {\n if ('type' in item) {\n // It's a template element\n cssText += item.value.cooked;\n continue;\n }\n\n // It's an expression\n const { ex } = item;\n\n const { end, start } = ex.loc!;\n const beforeLength = cssText.length;\n\n // The location will be end of the current string to start of next string\n const next = template[0] as TemplateElement; // template[0] is the next template element\n const loc = {\n start,\n end: next\n ? { line: next.loc!.start.line, column: next.loc!.start.column }\n : { line: end.line, column: end.column + 1 },\n };\n\n const value = 'value' in item ? item.value : valueCache.get(item.ex.name);\n\n // Is it props based interpolation?\n if (item.kind === ValueType.FUNCTION || typeof value === 'function') {\n // Check if previous expression was a CSS variable that we replaced\n // If it has a unit after it, we need to move the unit into the interpolation\n // e.g. `var(--size)px` should actually be `var(--size)`\n // So we check if the current text starts with a unit, and add the unit to the previous interpolation\n // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units\n // https://bugzilla.mozilla.org/show_bug.cgi?id=956573\n const matches = next.value.cooked?.match(unitRegex);\n\n try {\n if (matches) {\n template.shift();\n const [unit] = matches;\n\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source,\n unit\n );\n cssText += getVariableName(varId, variableNameConfig);\n\n cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';\n } else {\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source\n );\n cssText += getVariableName(varId, variableNameConfig);\n }\n } catch (e) {\n if (e instanceof Error) {\n throw item.buildCodeFrameError(e.message);\n }\n\n throw e;\n }\n } else {\n throwIfInvalid(\n tagProcessor.isValidValue.bind(tagProcessor),\n value,\n item,\n item.source\n );\n\n if (value !== undefined && typeof value !== 'function') {\n // Skip the blank string instead of throw ing an error\n if (value === '') {\n continue;\n }\n\n if (hasEvalMeta(value)) {\n // If it's a React component wrapped in styled, get the class name\n // Useful for interpolating components\n cssText += `.${value.__wyw_meta.className}`;\n } else if (isCSSable(value)) {\n // If it's a plain object or an array, convert it to a CSS string\n cssText += stripLines(loc, toCSS(value));\n } else {\n // For anything else, assume it'll be stringified\n cssText += stripLines(loc, value);\n }\n\n sourceMapReplacements.push({\n original: loc,\n length: cssText.length - beforeLength,\n });\n }\n }\n }\n\n const rules = tagProcessor.extractRules(\n valueCache,\n cssText,\n tagProcessor.location\n );\n\n // tagProcessor.doRuntimeReplacement(classes);\n if (!isReferenced && !cssText.includes(':global')) {\n return null;\n }\n\n // eslint-disable-next-line no-param-reassign\n return [rules, sourceMapReplacements];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAKA,SAASA,WAAW,EAAEC,SAAS,QAAQ,mBAAmB;AAK1D,SAASC,eAAe,QAAQ,mBAAmB;AACnD,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,KAAK,IAAIC,SAAS,QAAQ,SAAS;AAE1C,SAASC,KAAK,QAAQ,SAAS;;AAE/B;AACA,MAAMC,SAAS,GAAG,IAAIC,MAAM,
|
|
1
|
+
{"version":3,"file":"templateProcessor.js","names":["hasEvalMeta","ValueType","getVariableName","stripLines","throwIfInvalid","toCSS","isCSSable","units","unitRegex","RegExp","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","get","name","kind","FUNCTION","matches","match","unit","varId","addInterpolation","source","substring","e","Error","buildCodeFrameError","message","isValidValue","bind","undefined","__wyw_meta","className","push","original","rules","extractRules","location","includes"],"sources":["../../src/utils/templateProcessor.ts"],"sourcesContent":["/* eslint-disable no-continue */\n/**\n * This file handles transforming template literals to class names or styled components and generates CSS content.\n * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.\n */\n\nimport type { TemplateElement } from '@babel/types';\n\nimport type { ExpressionValue, Replacements } from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType } from '@wyw-in-js/shared';\n\nimport type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';\nimport type { ValueCache, Rules } from '../types';\n\nimport { getVariableName } from './getVariableName';\nimport stripLines from './stripLines';\nimport throwIfInvalid from './throwIfInvalid';\nimport toCSS, { isCSSable } from './toCSS';\nimport type { IOptions } from './types';\nimport { units } from './units';\n\n// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);\n\nexport default function templateProcessor(\n tagProcessor: TaggedTemplateProcessor,\n [...template]: (TemplateElement | ExpressionValue)[],\n valueCache: ValueCache,\n variableNameConfig: IOptions['variableNameConfig'] | undefined\n): [rules: Rules, sourceMapReplacements: Replacements] | null {\n const sourceMapReplacements: Replacements = [];\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n const { isReferenced } = tagProcessor;\n\n // Serialize the tagged template literal to a string\n let cssText = '';\n\n let item: TemplateElement | ExpressionValue | undefined;\n // eslint-disable-next-line no-cond-assign\n while ((item = template.shift())) {\n if ('type' in item) {\n // It's a template element\n cssText += item.value.cooked;\n continue;\n }\n\n // It's an expression\n const { ex } = item;\n\n const { end, start } = ex.loc!;\n const beforeLength = cssText.length;\n\n // The location will be end of the current string to start of next string\n const next = template[0] as TemplateElement; // template[0] is the next template element\n const loc = {\n start,\n end: next\n ? { line: next.loc!.start.line, column: next.loc!.start.column }\n : { line: end.line, column: end.column + 1 },\n };\n\n const value = 'value' in item ? item.value : valueCache.get(item.ex.name);\n\n // Is it props based interpolation?\n if (item.kind === ValueType.FUNCTION || typeof value === 'function') {\n // Check if previous expression was a CSS variable that we replaced\n // If it has a unit after it, we need to move the unit into the interpolation\n // e.g. `var(--size)px` should actually be `var(--size)`\n // So we check if the current text starts with a unit, and add the unit to the previous interpolation\n // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units\n // https://bugzilla.mozilla.org/show_bug.cgi?id=956573\n const matches = next.value.cooked?.match(unitRegex);\n\n try {\n if (matches) {\n template.shift();\n const [unit] = matches;\n\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source,\n unit\n );\n cssText += getVariableName(varId, variableNameConfig);\n\n cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';\n } else {\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source\n );\n cssText += getVariableName(varId, variableNameConfig);\n }\n } catch (e) {\n if (e instanceof Error) {\n throw item.buildCodeFrameError(e.message);\n }\n\n throw e;\n }\n } else {\n throwIfInvalid(\n tagProcessor.isValidValue.bind(tagProcessor),\n value,\n item,\n item.source\n );\n\n if (value !== undefined && typeof value !== 'function') {\n // Skip the blank string instead of throw ing an error\n if (value === '') {\n continue;\n }\n\n if (hasEvalMeta(value)) {\n // If it's a React component wrapped in styled, get the class name\n // Useful for interpolating components\n cssText += `.${value.__wyw_meta.className}`;\n } else if (isCSSable(value)) {\n // If it's a plain object or an array, convert it to a CSS string\n cssText += stripLines(loc, toCSS(value));\n } else {\n // For anything else, assume it'll be stringified\n cssText += stripLines(loc, value);\n }\n\n sourceMapReplacements.push({\n original: loc,\n length: cssText.length - beforeLength,\n });\n }\n }\n }\n\n const rules = tagProcessor.extractRules(\n valueCache,\n cssText,\n tagProcessor.location\n );\n\n // tagProcessor.doRuntimeReplacement(classes);\n if (!isReferenced && !cssText.includes(':global')) {\n return null;\n }\n\n // eslint-disable-next-line no-param-reassign\n return [rules, sourceMapReplacements];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAKA,SAASA,WAAW,EAAEC,SAAS,QAAQ,mBAAmB;AAK1D,SAASC,eAAe,QAAQ,mBAAmB;AACnD,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,KAAK,IAAIC,SAAS,QAAQ,SAAS;AAE1C,SAASC,KAAK,QAAQ,SAAS;;AAE/B;AACA,MAAMC,SAAS,GAAG,IAAIC,MAAM,CAAC,OAAOF,KAAK,CAACG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC;AAEvE,eAAe,SAASC,iBAAiBA,CACvCC,YAAqC,EACrC,CAAC,GAAGC,QAAQ,CAAwC,EACpDC,UAAsB,EACtBC,kBAA8D,EACF;EAC5D,MAAMC,qBAAmC,GAAG,EAAE;EAC9C;EACA;EACA,MAAM;IAAEC;EAAa,CAAC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AAErB,KAAK,CAACgB,KAAK,CAAC,CAAC;QAC1C,CAAC,MAAM;UACL;UACAH,OAAO,IAAIf,UAAU,CAACuB,GAAG,EAAEL,KAAK,CAAC;QACnC;QAEAL,qBAAqB,CAACoC,IAAI,CAAC;UACzBC,QAAQ,EAAE3B,GAAG;UACbE,MAAM,EAAEV,OAAO,CAACU,MAAM,GAAGD;QAC3B,CAAC,CAAC;MACJ;IACF;EACF;EAEA,MAAM2B,KAAK,GAAG1C,YAAY,CAAC2C,YAAY,CACrCzC,UAAU,EACVI,OAAO,EACPN,YAAY,CAAC4C,QACf,CAAC;;EAED;EACA,IAAI,CAACvC,YAAY,IAAI,CAACC,OAAO,CAACuC,QAAQ,CAAC,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAEtC,qBAAqB,CAAC;AACvC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throwIfInvalid.js","names":["isLikeError","value","throwIfInvalid","checker","ex","source","stack","message","buildCodeFrameError","stringified","JSON","stringify","String"],"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,
|
|
1
|
+
{"version":3,"file":"throwIfInvalid.js","names":["isLikeError","value","throwIfInvalid","checker","ex","source","stack","message","buildCodeFrameError","stringified","JSON","stringify","String"],"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,CAC1B;AACN;AACA,MAAMP,KAAK,CAACM,OAAO;AACnB;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,CAC1B,gCAAgCC,WAAW,8IAA8IJ,MAAM,KACjM,CAAC;AACH;AAEA,eAAeH,cAAc","ignoreList":[]}
|
package/esm/utils/toCSS.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCSS.js","names":["isBoxedPrimitive","unitless","isCSSPropertyValue","o","Number","isFinite","isCSSable","Array","isArray","every","Object","values","hyphenate","s","startsWith","replace","match","p1","toLowerCase","toCSS","map","join","valueOf","toString","entries","filter","value","key","p2","p3"],"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,SAASA,gBAAgB,QAAQ,mBAAmB;AAIpD,SAASC,QAAQ,QAAQ,SAAS;AAElC,MAAMC,kBAAkB,GAAIC,CAAU,IAA4B;EAChE,OACEH,gBAAgB,CAACG,CAAC,CAAC,IACnB,OAAOA,CAAC,KAAK,QAAQ,IACpB,OAAOA,CAAC,KAAK,QAAQ,IAAIC,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAE;AAEjD,CAAC;AAED,OAAO,MAAMG,SAAS,GAAIH,CAAU,IAAmB;EACrD,IAAID,kBAAkB,CAACC,CAAC,CAAC,EAAE;IACzB,OAAO,IAAI;EACb;EAEA,IAAII,KAAK,CAACC,OAAO,CAACL,CAAC,CAAC,EAAE;IACpB,OAAOA,CAAC,CAACM,KAAK,CAACH,SAAS,CAAC;EAC3B;EAEA,IAAI,OAAOH,CAAC,KAAK,QAAQ,EAAE;IACzB,OAAOA,CAAC,KAAK,IAAI,IAAIO,MAAM,CAACC,MAAM,CAACR,CAAC,CAAC,CAACM,KAAK,CAACH,SAAS,CAAC;EACxD;EAEA,OAAO,KAAK;AACd,CAAC;AAED,MAAMM,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,
|
|
1
|
+
{"version":3,"file":"toCSS.js","names":["isBoxedPrimitive","unitless","isCSSPropertyValue","o","Number","isFinite","isCSSable","Array","isArray","every","Object","values","hyphenate","s","startsWith","replace","match","p1","toLowerCase","toCSS","map","join","valueOf","toString","entries","filter","value","key","p2","p3"],"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,SAASA,gBAAgB,QAAQ,mBAAmB;AAIpD,SAASC,QAAQ,QAAQ,SAAS;AAElC,MAAMC,kBAAkB,GAAIC,CAAU,IAA4B;EAChE,OACEH,gBAAgB,CAACG,CAAC,CAAC,IACnB,OAAOA,CAAC,KAAK,QAAQ,IACpB,OAAOA,CAAC,KAAK,QAAQ,IAAIC,MAAM,CAACC,QAAQ,CAACF,CAAC,C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C,CAACO,GAAG,EAAED,KAAK,CAAC,KAAK;IACrB,IAAI,CAACxB,kBAAkB,CAACwB,KAAK,CAAC,EAAE;MAC9B,OAAO,GAAGC,GAAG,MAAMR,KAAK,CAACO,KAAK,CAAC,IAAI;IACrC;IAEA,OAAO,GAAGd,SAAS,CAACe,GAAG,CAAC,KACtB,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,KAAK,GAAGD,EAAE,CAACV,WAAW,CAAC,CAAC,GAAGW,EAAE,EACjD,CAAC,IAAI5B,QAAQ,CACd,GACG,GAAGyB,KAAK,IAAI,GACZA,KAAK,GACR;EACL,CAAC,CAAC,CACDL,IAAI,CAAC,GAAG,CAAC;AACd","ignoreList":[]}
|
|
@@ -1 +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":"AAAA,OAAO,SAASA,oBAAoBA,CAACC,CAAS,EAAE;EAC9C,OAAOA,CAAC,CAACC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACzE"}
|
|
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":"AAAA,OAAO,SAASA,oBAAoBA,CAACC,CAAS,EAAE;EAC9C,OAAOA,CAAC,CAACC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACzE","ignoreList":[]}
|
package/esm/utils/types.js.map
CHANGED
|
@@ -1 +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 extensions?: string[];\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":""}
|
|
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 extensions?: string[];\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":"","ignoreList":[]}
|
package/esm/utils/units.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","names":["units","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;AACA,OAAO,MAAMA,KAAK,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,MA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AAE,IAAI;EACjBC,eAAe,EAAE,IAAI;EACrBC,gBAAgB,EAAE,IAAI;EACtBC,gBAAgB,EAAE,IAAI;EACtBC,aAAa,EAAE,IAAI;EACnBC,WAAW,EAAE;AACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"units.js","names":["units","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;AACA,OAAO,MAAMA,KAAK,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;AAED,OAAO,MAAMC,QAAQ,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","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateParams.js","names":["isValidParams","params","constraints","length","Math","max","i","undefined","constraint","Array","isArray","every","c","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;;AAEV,OAAO,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;IAC/B,IAAIL,MAAM,CAACK,CAAC,CAAC,KAAKC,SAAS,IAAIL,WAAW,CAACI,CAAC,CAAC,KAAKC,SAAS,EAAE;MAC3D,OAAO,KAAK;IACd;IAEA,MAAMC,UAAU,GAAGN,WAAW,CAACI,CAAC,CAAC;IACjC,IAAIE,UAAU,KAAK,KAAK,EAAE;MACxB,OAAO,IAAI;IACb;IAEA,IAAIA,UAAU,KAAK,GAAG,EAAE;MACtB,IAAIP,MAAM,CAACK,CAAC,CAAC,KAAKC,SAAS,EAAE;QAC3B,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,EAAE;MACpC,IAAIA,UAAU,CAACG,KAAK,CAAEC,CAAC,IAAKA,CAAC,KAAKX,MAAM,CAACK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACjD,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIE,UAAU,KAAKP,MAAM,CAACK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE;MACxC,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAI;AACb;AAEA,OAAO,SAASO,cAAcA,CAC5BZ,MAAc,EACdC,WAAc,EACdY,cAAuB,EACS;EAChC,IAAI,CAACd,aAAa,CAACC,MAAM,EAAEC,WAAW,CAAC,EAAE;IACvC,IAAI,OAAOY,cAAc,KAAK,QAAQ,EAAE;MACtC,MAAM,IAAIC,KAAK,CAACD,cAAc,CAAC;IACjC;IAEA,MAAMA,cAAc;EACtB;AACF"}
|
|
1
|
+
{"version":3,"file":"validateParams.js","names":["isValidParams","params","constraints","length","Math","max","i","undefined","constraint","Array","isArray","every","c","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;;AAEV,OAAO,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;IAC/B,IAAIL,MAAM,CAACK,CAAC,CAAC,KAAKC,SAAS,IAAIL,WAAW,CAACI,CAAC,CAAC,KAAKC,SAAS,EAAE;MAC3D,OAAO,KAAK;IACd;IAEA,MAAMC,UAAU,GAAGN,WAAW,CAACI,CAAC,CAAC;IACjC,IAAIE,UAAU,KAAK,KAAK,EAAE;MACxB,OAAO,IAAI;IACb;IAEA,IAAIA,UAAU,KAAK,GAAG,EAAE;MACtB,IAAIP,MAAM,CAACK,CAAC,CAAC,KAAKC,SAAS,EAAE;QAC3B,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,EAAE;MACpC,IAAIA,UAAU,CAACG,KAAK,CAAEC,CAAC,IAAKA,CAAC,KAAKX,MAAM,CAACK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACjD,OAAO,KAAK;MACd;IACF,CAAC,MAAM,IAAIE,UAAU,KAAKP,MAAM,CAACK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE;MACxC,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAI;AACb;AAEA,OAAO,SAASO,cAAcA,CAC5BZ,MAAc,EACdC,WAAc,EACdY,cAAuB,EACS;EAChC,IAAI,CAACd,aAAa,CAACC,MAAM,EAAEC,WAAW,CAAC,EAAE;IACvC,IAAI,OAAOY,cAAc,KAAK,QAAQ,EAAE;MACtC,MAAM,IAAIC,KAAK,CAACD,cAAc,CAAC;IACjC;IAEA,MAAMA,cAAc;EACtB;AACF","ignoreList":[]}
|
package/lib/BaseProcessor.js
CHANGED
|
@@ -9,7 +9,7 @@ var _shared = require("@wyw-in-js/shared");
|
|
|
9
9
|
var _getClassNameAndSlug = _interopRequireDefault(require("./utils/getClassNameAndSlug"));
|
|
10
10
|
var _toCSS = require("./utils/toCSS");
|
|
11
11
|
var _validateParams = require("./utils/validateParams");
|
|
12
|
-
function _interopRequireDefault(
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
/* eslint-disable class-methods-use-this */
|
|
14
14
|
|
|
15
15
|
class BaseProcessor {
|
package/lib/BaseProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_getClassNameAndSlug","_toCSS","_validateParams","
|
|
1
|
+
{"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_getClassNameAndSlug","_toCSS","_validateParams","e","__esModule","default","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","validateParams","className","slug","getClassNameAndSlug","callee","isValidValue","value","isCSSable","hasEvalMeta","toString","tagSourceCode","type","name","generator","code","exports"],"sources":["../src/BaseProcessor.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport type { NodePath, types as t } from '@babel/core';\nimport generator from '@babel/generator';\nimport type {\n Expression,\n Identifier,\n SourceLocation,\n MemberExpression,\n} from '@babel/types';\n\nimport type { Artifact, ExpressionValue } from '@wyw-in-js/shared';\nimport { hasEvalMeta } from '@wyw-in-js/shared';\n\nimport type { IInterpolation, Params, Value, ValueCache } from './types';\nimport getClassNameAndSlug from './utils/getClassNameAndSlug';\nimport { isCSSable } from './utils/toCSS';\nimport type { IFileContext, IOptions } from './utils/types';\nimport { validateParams } from './utils/validateParams';\n\nexport { Expression };\n\nexport type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;\nexport type TailProcessorParams = ProcessorParams extends [Params, ...infer T]\n ? T\n : never;\n\nexport type TagSource = {\n imported: string;\n source: string;\n};\n\nexport abstract class BaseProcessor {\n public static SKIP = Symbol('skip');\n\n public readonly artifacts: Artifact[] = [];\n\n public readonly className: string;\n\n public readonly dependencies: ExpressionValue[] = [];\n\n public interpolations: IInterpolation[] = [];\n\n public readonly slug: string;\n\n protected callee: Identifier | MemberExpression;\n\n protected evaluated:\n | Record<'dependencies' | 'expression', Value[]>\n | undefined;\n\n public constructor(\n params: Params,\n public tagSource: TagSource,\n protected readonly astService: typeof t & {\n addDefaultImport: (source: string, nameHint?: string) => Identifier;\n addNamedImport: (\n name: string,\n source: string,\n nameHint?: string\n ) => Identifier;\n },\n public readonly location: SourceLocation | null,\n protected readonly replacer: (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => void,\n public readonly displayName: string,\n public readonly isReferenced: boolean,\n protected readonly idx: number,\n protected readonly options: IOptions,\n protected readonly context: IFileContext\n ) {\n validateParams(\n params,\n ['callee'],\n 'Unknown error: a callee param is not specified'\n );\n\n const { className, slug } = getClassNameAndSlug(\n this.displayName,\n this.idx,\n this.options,\n this.context\n );\n\n this.className = className;\n this.slug = slug;\n\n [[, this.callee]] = params;\n }\n\n /**\n * A replacement for tag referenced in a template literal.\n */\n public abstract get asSelector(): string;\n\n /**\n * A replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract get value(): Expression;\n\n public isValidValue(value: unknown): value is Value {\n return (\n typeof value === 'function' || isCSSable(value) || hasEvalMeta(value)\n );\n }\n\n public toString(): string {\n return this.tagSourceCode();\n }\n\n protected tagSourceCode(): string {\n if (this.callee.type === 'Identifier') {\n return this.callee.name;\n }\n\n return generator(this.callee).code;\n }\n\n public abstract build(values: ValueCache): void;\n\n /**\n * Perform a replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract doEvaltimeReplacement(): void;\n\n /**\n * Perform a replacement for the tag with its runtime version.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with a component.\n * If some parts require evaluated data for render,\n * they will be replaced with placeholders.\n */\n public abstract doRuntimeReplacement(): void;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AASA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,oBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,eAAA,GAAAJ,OAAA;AAAwD,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAjBxD;;AA+BO,MAAeG,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACxC;IAAA,KAnBOR,SAAoB,GAApBA,SAAoB;IAAA,KACRC,UAOlB,GAPkBA,UAOlB;IAAA,KACeC,QAA+B,GAA/BA,QAA+B;IAAA,KAC5BC,QAGV,GAHUA,QAGV;IAAA,KACOC,WAAmB,GAAnBA,WAAmB;IAAA,KACnBC,YAAqB,GAArBA,YAAqB;IAAA,KAClBC,GAAW,GAAXA,GAAW;IAAA,KACXC,OAAiB,GAAjBA,OAAiB;IAAA,KACjBC,OAAqB,GAArBA,OAAqB;IAExC,IAAAC,8BAAc,EACZV,MAAM,EACN,CAAC,QAAQ,CAAC,EACV,gDACF,CAAC;IAED,MAAM;MAAEW,SAAS;MAAEC;IAAK,CAAC,GAAG,IAAAC,4BAAmB,EAC7C,IAAI,CAACR,WAAW,EAChB,IAAI,CAACE,GAAG,EACR,IAAI,CAACC,OAAO,EACZ,IAAI,CAACC,OACP,CAAC;IAED,IAAI,CAACE,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,CAAC,GAAG,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGd,MAAM;EAC5B;;EAEA;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;;EAGSe,YAAYA,CAACC,KAAc,EAAkB;IAClD,OACE,OAAOA,KAAK,KAAK,UAAU,IAAI,IAAAC,gBAAS,EAACD,KAAK,CAAC,IAAI,IAAAE,mBAAW,EAACF,KAAK,CAAC;EAEzE;EAEOG,QAAQA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,aAAa,CAAC,CAAC;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACN,MAAM,CAACO,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACP,MAAM,CAACQ,IAAI;IACzB;IAEA,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAACT,MAAM,CAAC,CAACU,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA;AAACC,OAAA,CAAAhC,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -8,7 +8,7 @@ var _shared = require("@wyw-in-js/shared");
|
|
|
8
8
|
var _BaseProcessor = require("./BaseProcessor");
|
|
9
9
|
var _templateProcessor = _interopRequireDefault(require("./utils/templateProcessor"));
|
|
10
10
|
var _validateParams = require("./utils/validateParams");
|
|
11
|
-
function _interopRequireDefault(
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
class TaggedTemplateProcessor extends _BaseProcessor.BaseProcessor {
|
|
13
13
|
#template;
|
|
14
14
|
constructor(params, ...args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaggedTemplateProcessor.js","names":["_shared","require","_BaseProcessor","_templateProcessor","_interopRequireDefault","_validateParams","
|
|
1
|
+
{"version":3,"file":"TaggedTemplateProcessor.js","names":["_shared","require","_BaseProcessor","_templateProcessor","_interopRequireDefault","_validateParams","e","__esModule","default","TaggedTemplateProcessor","BaseProcessor","template","constructor","params","args","validateParams","SKIP","tag","forEach","element","kind","ValueType","FUNCTION","dependencies","push","build","values","artifacts","length","Error","artifact","templateProcessor","options","variableNameConfig","toString","exports"],"sources":["../src/TaggedTemplateProcessor.ts"],"sourcesContent":["import type { TemplateElement, Expression, SourceLocation } from '@babel/types';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\n\nimport type { TailProcessorParams } from './BaseProcessor';\nimport { BaseProcessor } from './BaseProcessor';\nimport type { ValueCache, Rules, Params } from './types';\nimport templateProcessor from './utils/templateProcessor';\nimport { validateParams } from './utils/validateParams';\n\nexport abstract class TaggedTemplateProcessor extends BaseProcessor {\n readonly #template: (TemplateElement | ExpressionValue)[];\n\n protected constructor(params: Params, ...args: TailProcessorParams) {\n // Should have at least two params and the first one should be a callee.\n validateParams(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);\n\n validateParams(\n params,\n ['callee', 'template'],\n 'Invalid usage of template tag'\n );\n const [tag, [, template]] = params;\n\n super([tag], ...args);\n\n template.forEach((element) => {\n if ('kind' in element && element.kind !== ValueType.FUNCTION) {\n this.dependencies.push(element);\n }\n });\n\n this.#template = template;\n }\n\n public override build(values: ValueCache) {\n if (this.artifacts.length > 0) {\n // FIXME: why it was called twice?\n throw new Error('Tag is already built');\n }\n\n const artifact = templateProcessor(\n this,\n this.#template,\n values,\n this.options.variableNameConfig\n );\n if (artifact) {\n this.artifacts.push(['css', artifact]);\n }\n }\n\n public override toString(): string {\n return `${super.toString()}\\`…\\``;\n }\n\n /**\n * It is called for each resolved expression in a template literal.\n * @param node\n * @param precedingCss\n * @param source\n * @param unit\n * @return chunk of CSS that should be added to extracted CSS\n */\n public abstract addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit?: string\n ): string;\n\n public abstract extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAAwD,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEjD,MAAeG,uBAAuB,SAASC,4BAAa,CAAC;EACzD,CAACC,QAAQ;EAERC,WAAWA,CAACC,MAAc,EAAE,GAAGC,IAAyB,EAAE;IAClE;IACA,IAAAC,8BAAc,EAACF,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAEJ,uBAAuB,CAACO,IAAI,CAAC;IAEvE,IAAAD,8BAAc,EACZF,MAAM,EACN,CAAC,QAAQ,EAAE,UAAU,CAAC,EACtB,+BACF,CAAC;IACD,MAAM,CAACI,GAAG,EAAE,GAAGN,QAAQ,CAAC,CAAC,GAAGE,MAAM;IAElC,KAAK,CAAC,CAACI,GAAG,CAAC,EAAE,GAAGH,IAAI,CAAC;IAErBH,QAAQ,CAACO,OAAO,CAAEC,OAAO,IAAK;MAC5B,IAAI,MAAM,IAAIA,OAAO,IAAIA,OAAO,CAACC,IAAI,KAAKC,iBAAS,CAACC,QAAQ,EAAE;QAC5D,IAAI,CAACC,YAAY,CAACC,IAAI,CAACL,OAAO,CAAC;MACjC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,CAACR,QAAQ,GAAGA,QAAQ;EAC3B;EAEgBc,KAAKA,CAACC,MAAkB,EAAE;IACxC,IAAI,IAAI,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IAEA,MAAMC,QAAQ,GAAG,IAAAC,0BAAiB,EAChC,IAAI,EACJ,IAAI,CAAC,CAACpB,QAAQ,EACde,MAAM,EACN,IAAI,CAACM,OAAO,CAACC,kBACf,CAAC;IACD,IAAIH,QAAQ,EAAE;MACZ,IAAI,CAACH,SAAS,CAACH,IAAI,CAAC,CAAC,KAAK,EAAEM,QAAQ,CAAC,CAAC;IACxC;EACF;EAEgBI,QAAQA,CAAA,EAAW;IACjC,OAAO,GAAG,KAAK,CAACA,QAAQ,CAAC,CAAC,OAAO;EACnC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAaA;AAACC,OAAA,CAAA1B,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_BaseProcessor","require","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_buildSlug","_validateParams","_TaggedTemplateProcessor","_toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAEA,IAAAe,eAAA,GAAAf,OAAA;AAEA,IAAAgB,wBAAA,GAAAhB,OAAA;AACA,IAAAiB,qBAAA,GAAAjB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_BaseProcessor","require","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_buildSlug","_validateParams","_TaggedTemplateProcessor","_toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAEA,IAAAe,eAAA,GAAAf,OAAA;AAEA,IAAAgB,wBAAA,GAAAhB,OAAA;AACA,IAAAiB,qBAAA,GAAAjB,OAAA","ignoreList":[]}
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":";;;;;;AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAE7B,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":";;;;;;AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAE7B,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClassNameAndSlug.js","names":["_path","require","_shared","_buildSlug","_toValidCSSIdentifier","getClassNameAndSlug","displayName","idx","options","context","_context$filename","relativeFilename","root","filename","relative","replace","posix","sep","slug","toValidCSSIdentifier","charAt","toLowerCase","slugify","ext","extname","slugVars","hash","title","index","file","name","basename","dir","dirname","split","pop","className","classNameSlug","Error","buildSlug","logger","extend"],"sources":["../../src/utils/getClassNameAndSlug.ts"],"sourcesContent":["import { basename, dirname, extname, relative, sep, posix } from 'path';\n\nimport type { ClassNameSlugVars } from '@wyw-in-js/shared';\nimport { logger, slugify } from '@wyw-in-js/shared';\n\nimport { buildSlug } from './buildSlug';\nimport { toValidCSSIdentifier } from './toValidCSSIdentifier';\nimport type { IFileContext, IOptions } from './types';\n\nexport default function getClassNameAndSlug(\n displayName: string,\n idx: number,\n options: IOptions,\n context: IFileContext\n): { className: string; slug: string } {\n const relativeFilename = (\n context.root && context.filename\n ? relative(context.root, context.filename)\n : context.filename ?? 'unknown'\n ).replace(/\\\\/g, posix.sep);\n\n // Custom properties need to start with a letter, so we prefix the slug\n // Also use append the index of the class to the filename for uniqueness in the file\n const slug = toValidCSSIdentifier(\n `${displayName.charAt(0).toLowerCase()}${slugify(\n `${relativeFilename}:${idx}`\n )}`\n );\n\n // Collect some useful replacement patterns from the filename\n // Available variables for the square brackets used in `classNameSlug` options\n const ext = extname(relativeFilename);\n const slugVars: ClassNameSlugVars = {\n hash: slug,\n title: displayName,\n index: idx,\n file: relativeFilename,\n ext,\n name: basename(relativeFilename, ext),\n dir: dirname(relativeFilename).split(sep).pop() as string,\n };\n\n let className = options.displayName\n ? `${toValidCSSIdentifier(displayName!)}_${slug!}`\n : slug!;\n\n // The className can be defined by the user either as fn or a string\n if (typeof options.classNameSlug === 'function') {\n try {\n className = toValidCSSIdentifier(\n options.classNameSlug(slug, displayName, slugVars)\n );\n } catch {\n throw new Error('classNameSlug option must return a string');\n }\n }\n\n if (typeof options.classNameSlug === 'string') {\n className = toValidCSSIdentifier(\n buildSlug(options.classNameSlug, slugVars)\n );\n }\n\n logger.extend('template-parse:generated-meta')(\n `slug: ${slug}, displayName: ${displayName}, className: ${className}`\n );\n\n return { className, slug };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAGe,SAASI,mBAAmBA,CACzCC,WAAmB,EACnBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACgB;EAAA,IAAAC,iBAAA;EACrC,MAAMC,gBAAgB,GAAG,CACvBF,OAAO,CAACG,IAAI,IAAIH,OAAO,CAACI,QAAQ,GAC5B,IAAAC,cAAQ,EAACL,OAAO,CAACG,IAAI,EAAEH,OAAO,CAACI,QAAQ,CAAC,IAAAH,iBAAA,GACxCD,OAAO,CAACI,QAAQ,cAAAH,iBAAA,cAAAA,iBAAA,GAAI,SAAS,EACjCK,OAAO,CAAC,KAAK,EAAEC,WAAK,CAACC,GAAG,CAAC;;EAE3B;EACA;EACA,MAAMC,IAAI,GAAG,IAAAC,0CAAoB,
|
|
1
|
+
{"version":3,"file":"getClassNameAndSlug.js","names":["_path","require","_shared","_buildSlug","_toValidCSSIdentifier","getClassNameAndSlug","displayName","idx","options","context","_context$filename","relativeFilename","root","filename","relative","replace","posix","sep","slug","toValidCSSIdentifier","charAt","toLowerCase","slugify","ext","extname","slugVars","hash","title","index","file","name","basename","dir","dirname","split","pop","className","classNameSlug","Error","buildSlug","logger","extend"],"sources":["../../src/utils/getClassNameAndSlug.ts"],"sourcesContent":["import { basename, dirname, extname, relative, sep, posix } from 'path';\n\nimport type { ClassNameSlugVars } from '@wyw-in-js/shared';\nimport { logger, slugify } from '@wyw-in-js/shared';\n\nimport { buildSlug } from './buildSlug';\nimport { toValidCSSIdentifier } from './toValidCSSIdentifier';\nimport type { IFileContext, IOptions } from './types';\n\nexport default function getClassNameAndSlug(\n displayName: string,\n idx: number,\n options: IOptions,\n context: IFileContext\n): { className: string; slug: string } {\n const relativeFilename = (\n context.root && context.filename\n ? relative(context.root, context.filename)\n : context.filename ?? 'unknown'\n ).replace(/\\\\/g, posix.sep);\n\n // Custom properties need to start with a letter, so we prefix the slug\n // Also use append the index of the class to the filename for uniqueness in the file\n const slug = toValidCSSIdentifier(\n `${displayName.charAt(0).toLowerCase()}${slugify(\n `${relativeFilename}:${idx}`\n )}`\n );\n\n // Collect some useful replacement patterns from the filename\n // Available variables for the square brackets used in `classNameSlug` options\n const ext = extname(relativeFilename);\n const slugVars: ClassNameSlugVars = {\n hash: slug,\n title: displayName,\n index: idx,\n file: relativeFilename,\n ext,\n name: basename(relativeFilename, ext),\n dir: dirname(relativeFilename).split(sep).pop() as string,\n };\n\n let className = options.displayName\n ? `${toValidCSSIdentifier(displayName!)}_${slug!}`\n : slug!;\n\n // The className can be defined by the user either as fn or a string\n if (typeof options.classNameSlug === 'function') {\n try {\n className = toValidCSSIdentifier(\n options.classNameSlug(slug, displayName, slugVars)\n );\n } catch {\n throw new Error('classNameSlug option must return a string');\n }\n }\n\n if (typeof options.classNameSlug === 'string') {\n className = toValidCSSIdentifier(\n buildSlug(options.classNameSlug, slugVars)\n );\n }\n\n logger.extend('template-parse:generated-meta')(\n `slug: ${slug}, displayName: ${displayName}, className: ${className}`\n );\n\n return { className, slug };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAGe,SAASI,mBAAm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X,OAAO,CAAC6B,aAAa,CAACnB,IAAI,EAAEZ,WAAW,EAAEmB,QAAQ,CACnD,CAAC;IACH,CAAC,CAAC,MAAM;MACN,MAAM,IAAIa,KAAK,CAAC,2CAA2C,CAAC;IAC9D;EACF;EAEA,IAAI,OAAO9B,OAAO,CAAC6B,aAAa,KAAK,QAAQ,EAAE;IAC7CD,SAAS,GAAG,IAAAjB,0CAAoB,EAC9B,IAAAoB,oBAAS,EAAC/B,OAAO,CAAC6B,aAAa,EAAEZ,QAAQ,CAC3C,CAAC;EACH;EAEAe,cAAM,CAACC,MAAM,CAAC,+BAA+B,CAAC,CAC5C,SAASvB,IAAI,kBAAkBZ,WAAW,gBAAgB8B,SAAS,EACrE,CAAC;EAED,OAAO;IAAEA,SAAS;IAAElB;EAAK,CAAC;AAC5B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVariableName.js","names":["getVariableName","varId","rawVariableName"],"sources":["../../src/utils/getVariableName.ts"],"sourcesContent":["import type { IOptions } from './types';\n\nexport function getVariableName(\n varId: string,\n rawVariableName: IOptions['variableNameConfig'] | undefined\n) {\n switch (rawVariableName) {\n case 'raw':\n return varId;\n case 'dashes':\n return `--${varId}`;\n case 'var':\n default:\n return `var(--${varId})`;\n }\n}\n"],"mappings":";;;;;;AAEO,SAASA,eAAeA,CAC7BC,KAAa,EACbC,eAA2D,EAC3D;EACA,QAAQA,eAAe;IACrB,KAAK,KAAK;MACR,OAAOD,KAAK;IACd,KAAK,QAAQ;MACX,
|
|
1
|
+
{"version":3,"file":"getVariableName.js","names":["getVariableName","varId","rawVariableName"],"sources":["../../src/utils/getVariableName.ts"],"sourcesContent":["import type { IOptions } from './types';\n\nexport function getVariableName(\n varId: string,\n rawVariableName: IOptions['variableNameConfig'] | undefined\n) {\n switch (rawVariableName) {\n case 'raw':\n return varId;\n case 'dashes':\n return `--${varId}`;\n case 'var':\n default:\n return `var(--${varId})`;\n }\n}\n"],"mappings":";;;;;;AAEO,SAASA,eAAeA,CAC7BC,KAAa,EACbC,eAA2D,EAC3D;EACA,QAAQA,eAAe;IACrB,KAAK,KAAK;MACR,OAAOD,KAAK;IACd,KAAK,QAAQ;MACX,OAAO,KAAKA,KAAK,EAAE;IACrB,KAAK,KAAK;IACV;MACE,OAAO,SAASA,KAAK,GAAG;EAC5B;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripLines.js","names":["stripLines","loc","text","result","String","replace","trim","start","line","end","repeat","column"],"sources":["../../src/utils/stripLines.ts"],"sourcesContent":["import type { Location } from '@wyw-in-js/shared';\n\n// Stripping away the new lines ensures that we preserve line numbers\n// This is useful in case of tools such as the stylelint pre-processor\n// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings\nexport default function stripLines(\n loc: { end: Location; start: Location },\n text: string | number\n) {\n let result = String(text)\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n\n // If the start and end line numbers aren't same, add new lines to span the text across multiple lines\n if (loc.start.line !== loc.end.line) {\n result += '\\n'.repeat(loc.end.line - loc.start.line);\n\n // Add extra spaces to offset the column\n result += ' '.repeat(loc.end.column);\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACe,SAASA,UAAUA,CAChCC,GAAuC,EACvCC,IAAqB,EACrB;EACA,IAAIC,MAAM,GAAGC,MAAM,CAACF,IAAI,CAAC,CACtBG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CACxBC,IAAI,CAAC,CAAC;;EAET;EACA,IAAIL,GAAG,CAACM,KAAK,CAACC,IAAI,KAAKP,GAAG,CAACQ,GAAG,CAACD,IAAI,EAAE;IACnCL,MAAM,IAAI,IAAI,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACD,IAAI,GAAGP,GAAG,CAACM,KAAK,CAACC,IAAI,CAAC;;IAEpD;IACAL,MAAM,IAAI,GAAG,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACE,MAAM,CAAC;EACtC;EAEA,OAAOR,MAAM;AACf"}
|
|
1
|
+
{"version":3,"file":"stripLines.js","names":["stripLines","loc","text","result","String","replace","trim","start","line","end","repeat","column"],"sources":["../../src/utils/stripLines.ts"],"sourcesContent":["import type { Location } from '@wyw-in-js/shared';\n\n// Stripping away the new lines ensures that we preserve line numbers\n// This is useful in case of tools such as the stylelint pre-processor\n// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings\nexport default function stripLines(\n loc: { end: Location; start: Location },\n text: string | number\n) {\n let result = String(text)\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n\n // If the start and end line numbers aren't same, add new lines to span the text across multiple lines\n if (loc.start.line !== loc.end.line) {\n result += '\\n'.repeat(loc.end.line - loc.start.line);\n\n // Add extra spaces to offset the column\n result += ' '.repeat(loc.end.column);\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACe,SAASA,UAAUA,CAChCC,GAAuC,EACvCC,IAAqB,EACrB;EACA,IAAIC,MAAM,GAAGC,MAAM,CAACF,IAAI,CAAC,CACtBG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CACxBC,IAAI,CAAC,CAAC;;EAET;EACA,IAAIL,GAAG,CAACM,KAAK,CAACC,IAAI,KAAKP,GAAG,CAACQ,GAAG,CAACD,IAAI,EAAE;IACnCL,MAAM,IAAI,IAAI,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACD,IAAI,GAAGP,GAAG,CAACM,KAAK,CAACC,IAAI,CAAC;;IAEpD;IACAL,MAAM,IAAI,GAAG,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACE,MAAM,CAAC;EACtC;EAEA,OAAOR,MAAM;AACf","ignoreList":[]}
|
|
@@ -10,9 +10,8 @@ var _stripLines = _interopRequireDefault(require("./stripLines"));
|
|
|
10
10
|
var _throwIfInvalid = _interopRequireDefault(require("./throwIfInvalid"));
|
|
11
11
|
var _toCSS = _interopRequireWildcard(require("./toCSS"));
|
|
12
12
|
var _units = require("./units");
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
15
|
/* eslint-disable no-continue */
|
|
17
16
|
/**
|
|
18
17
|
* This file handles transforming template literals to class names or styled components and generates CSS content.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateProcessor.js","names":["_shared","require","_getVariableName","_stripLines","_interopRequireDefault","_throwIfInvalid","_toCSS","_interopRequireWildcard","_units","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","unitRegex","RegExp","units","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","name","kind","ValueType","FUNCTION","_next$value$cooked","matches","match","_next$value$cooked$su","_next$value$cooked2","_unit$length","unit","varId","addInterpolation","source","getVariableName","substring","Error","buildCodeFrameError","message","throwIfInvalid","isValidValue","bind","undefined","hasEvalMeta","__wyw_meta","className","isCSSable","stripLines","toCSS","push","original","rules","extractRules","location","includes"],"sources":["../../src/utils/templateProcessor.ts"],"sourcesContent":["/* eslint-disable no-continue */\n/**\n * This file handles transforming template literals to class names or styled components and generates CSS content.\n * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.\n */\n\nimport type { TemplateElement } from '@babel/types';\n\nimport type { ExpressionValue, Replacements } from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType } from '@wyw-in-js/shared';\n\nimport type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';\nimport type { ValueCache, Rules } from '../types';\n\nimport { getVariableName } from './getVariableName';\nimport stripLines from './stripLines';\nimport throwIfInvalid from './throwIfInvalid';\nimport toCSS, { isCSSable } from './toCSS';\nimport type { IOptions } from './types';\nimport { units } from './units';\n\n// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);\n\nexport default function templateProcessor(\n tagProcessor: TaggedTemplateProcessor,\n [...template]: (TemplateElement | ExpressionValue)[],\n valueCache: ValueCache,\n variableNameConfig: IOptions['variableNameConfig'] | undefined\n): [rules: Rules, sourceMapReplacements: Replacements] | null {\n const sourceMapReplacements: Replacements = [];\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n const { isReferenced } = tagProcessor;\n\n // Serialize the tagged template literal to a string\n let cssText = '';\n\n let item: TemplateElement | ExpressionValue | undefined;\n // eslint-disable-next-line no-cond-assign\n while ((item = template.shift())) {\n if ('type' in item) {\n // It's a template element\n cssText += item.value.cooked;\n continue;\n }\n\n // It's an expression\n const { ex } = item;\n\n const { end, start } = ex.loc!;\n const beforeLength = cssText.length;\n\n // The location will be end of the current string to start of next string\n const next = template[0] as TemplateElement; // template[0] is the next template element\n const loc = {\n start,\n end: next\n ? { line: next.loc!.start.line, column: next.loc!.start.column }\n : { line: end.line, column: end.column + 1 },\n };\n\n const value = 'value' in item ? item.value : valueCache.get(item.ex.name);\n\n // Is it props based interpolation?\n if (item.kind === ValueType.FUNCTION || typeof value === 'function') {\n // Check if previous expression was a CSS variable that we replaced\n // If it has a unit after it, we need to move the unit into the interpolation\n // e.g. `var(--size)px` should actually be `var(--size)`\n // So we check if the current text starts with a unit, and add the unit to the previous interpolation\n // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units\n // https://bugzilla.mozilla.org/show_bug.cgi?id=956573\n const matches = next.value.cooked?.match(unitRegex);\n\n try {\n if (matches) {\n template.shift();\n const [unit] = matches;\n\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source,\n unit\n );\n cssText += getVariableName(varId, variableNameConfig);\n\n cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';\n } else {\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source\n );\n cssText += getVariableName(varId, variableNameConfig);\n }\n } catch (e) {\n if (e instanceof Error) {\n throw item.buildCodeFrameError(e.message);\n }\n\n throw e;\n }\n } else {\n throwIfInvalid(\n tagProcessor.isValidValue.bind(tagProcessor),\n value,\n item,\n item.source\n );\n\n if (value !== undefined && typeof value !== 'function') {\n // Skip the blank string instead of throw ing an error\n if (value === '') {\n continue;\n }\n\n if (hasEvalMeta(value)) {\n // If it's a React component wrapped in styled, get the class name\n // Useful for interpolating components\n cssText += `.${value.__wyw_meta.className}`;\n } else if (isCSSable(value)) {\n // If it's a plain object or an array, convert it to a CSS string\n cssText += stripLines(loc, toCSS(value));\n } else {\n // For anything else, assume it'll be stringified\n cssText += stripLines(loc, value);\n }\n\n sourceMapReplacements.push({\n original: loc,\n length: cssText.length - beforeLength,\n });\n }\n }\n }\n\n const rules = tagProcessor.extractRules(\n valueCache,\n cssText,\n tagProcessor.location\n );\n\n // tagProcessor.doRuntimeReplacement(classes);\n if (!isReferenced && !cssText.includes(':global')) {\n return null;\n }\n\n // eslint-disable-next-line no-param-reassign\n return [rules, sourceMapReplacements];\n}\n"],"mappings":";;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,G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C,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAE/C,qBAAqB,CAAC;AACvC"}
|
|
1
|
+
{"version":3,"file":"templateProcessor.js","names":["_shared","require","_getVariableName","_stripLines","_interopRequireDefault","_throwIfInvalid","_toCSS","_interopRequireWildcard","_units","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","unitRegex","RegExp","units","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","name","kind","ValueType","FUNCTION","_next$value$cooked","matches","match","_next$value$cooked$su","_next$value$cooked2","_unit$length","unit","varId","addInterpolation","source","getVariableName","substring","Error","buildCodeFrameError","message","throwIfInvalid","isValidValue","bind","undefined","hasEvalMeta","__wyw_meta","className","isCSSable","stripLines","toCSS","push","original","rules","extractRules","location","includes"],"sources":["../../src/utils/templateProcessor.ts"],"sourcesContent":["/* eslint-disable no-continue */\n/**\n * This file handles transforming template literals to class names or styled components and generates CSS content.\n * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.\n */\n\nimport type { TemplateElement } from '@babel/types';\n\nimport type { ExpressionValue, Replacements } from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType } from '@wyw-in-js/shared';\n\nimport type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';\nimport type { ValueCache, Rules } from '../types';\n\nimport { getVariableName } from './getVariableName';\nimport stripLines from './stripLines';\nimport throwIfInvalid from './throwIfInvalid';\nimport toCSS, { isCSSable } from './toCSS';\nimport type { IOptions } from './types';\nimport { units } from './units';\n\n// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);\n\nexport default function templateProcessor(\n tagProcessor: TaggedTemplateProcessor,\n [...template]: (TemplateElement | ExpressionValue)[],\n valueCache: ValueCache,\n variableNameConfig: IOptions['variableNameConfig'] | undefined\n): [rules: Rules, sourceMapReplacements: Replacements] | null {\n const sourceMapReplacements: Replacements = [];\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n const { isReferenced } = tagProcessor;\n\n // Serialize the tagged template literal to a string\n let cssText = '';\n\n let item: TemplateElement | ExpressionValue | undefined;\n // eslint-disable-next-line no-cond-assign\n while ((item = template.shift())) {\n if ('type' in item) {\n // It's a template element\n cssText += item.value.cooked;\n continue;\n }\n\n // It's an expression\n const { ex } = item;\n\n const { end, start } = ex.loc!;\n const beforeLength = cssText.length;\n\n // The location will be end of the current string to start of next string\n const next = template[0] as TemplateElement; // template[0] is the next template element\n const loc = {\n start,\n end: next\n ? { line: next.loc!.start.line, column: next.loc!.start.column }\n : { line: end.line, column: end.column + 1 },\n };\n\n const value = 'value' in item ? item.value : valueCache.get(item.ex.name);\n\n // Is it props based interpolation?\n if (item.kind === ValueType.FUNCTION || typeof value === 'function') {\n // Check if previous expression was a CSS variable that we replaced\n // If it has a unit after it, we need to move the unit into the interpolation\n // e.g. `var(--size)px` should actually be `var(--size)`\n // So we check if the current text starts with a unit, and add the unit to the previous interpolation\n // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units\n // https://bugzilla.mozilla.org/show_bug.cgi?id=956573\n const matches = next.value.cooked?.match(unitRegex);\n\n try {\n if (matches) {\n template.shift();\n const [unit] = matches;\n\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source,\n unit\n );\n cssText += getVariableName(varId, variableNameConfig);\n\n cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';\n } else {\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source\n );\n cssText += getVariableName(varId, variableNameConfig);\n }\n } catch (e) {\n if (e instanceof Error) {\n throw item.buildCodeFrameError(e.message);\n }\n\n throw e;\n }\n } else {\n throwIfInvalid(\n tagProcessor.isValidValue.bind(tagProcessor),\n value,\n item,\n item.source\n );\n\n if (value !== undefined && typeof value !== 'function') {\n // Skip the blank string instead of throw ing an error\n if (value === '') {\n continue;\n }\n\n if (hasEvalMeta(value)) {\n // If it's a React component wrapped in styled, get the class name\n // Useful for interpolating components\n cssText += `.${value.__wyw_meta.className}`;\n } else if (isCSSable(value)) {\n // If it's a plain object or an array, convert it to a CSS string\n cssText += stripLines(loc, toCSS(value));\n } else {\n // For anything else, assume it'll be stringified\n cssText += stripLines(loc, value);\n }\n\n sourceMapReplacements.push({\n original: loc,\n length: cssText.length - beforeLength,\n });\n }\n }\n }\n\n const rules = tagProcessor.extractRules(\n valueCache,\n cssText,\n tagProcessor.location\n );\n\n // tagProcessor.doRuntimeReplacement(classes);\n if (!isReferenced && !cssText.includes(':global')) {\n return null;\n }\n\n // eslint-disable-next-line no-param-reassign\n return [rules, sourceMapReplacements];\n}\n"],"mappings":";;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,MAAA,GAAAC,uBAAA,CAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAAgC,SAAAM,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA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,OAAO,IAAI,IAAAyC,mBAAU,EAACjC,GAAG,EAAE,IAAAkC,cAAK,EAACvC,KAAK,CAAC,CAAC;QAC1C,CAAC,MAAM;UACL;UACAH,OAAO,IAAI,IAAAyC,mBAAU,EAACjC,GAAG,EAAEL,KAAK,CAAC;QACnC;QAEAL,qBAAqB,CAAC6C,IAAI,CAAC;UACzBC,QAAQ,EAAEpC,GAAG;UACbE,MAAM,EAAEV,OAAO,CAACU,MAAM,GAAGD;QAC3B,CAAC,CAAC;MACJ;IACF;EACF;EAEA,MAAMoC,KAAK,GAAGnD,YAAY,CAACoD,YAAY,CACrClD,UAAU,EACVI,OAAO,EACPN,YAAY,CAACqD,QACf,CAAC;;EAED;EACA,IAAI,CAAChD,YAAY,IAAI,CAACC,OAAO,CAACgD,QAAQ,CAAC,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAE/C,qBAAqB,CAAC;AACvC","ignoreList":[]}
|
|
@@ -1 +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,
|
|
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,CAC1B;AACN;AACA,MAAMP,KAAK,CAACM,OAAO;AACnB;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,CAC1B,gCAAgCC,WAAW,8IAA8IJ,MAAM,KACjM,CAAC;AACH;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcb,cAAc","ignoreList":[]}
|
package/lib/utils/toCSS.js.map
CHANGED
|
@@ -1 +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,
|
|
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,IAAA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ACzB,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,OAAO,GAAGC,GAAG,MAAMR,KAAK,CAACO,KAAK,CAAC,IAAI;IACrC;IAEA,OAAO,GAAGd,SAAS,CAACe,GAAG,CAAC,KACtB,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,KAAK,GAAGD,EAAE,CAACV,WAAW,CAAC,CAAC,GAAGW,EAAE,EACjD,CAAC,IAAIC,eAAQ,CACd,GACG,GAAGJ,KAAK,IAAI,GACZA,KAAK,GACR;EACL,CAAC,CAAC,CACDL,IAAI,CAAC,GAAG,CAAC;AACd","ignoreList":[]}
|
|
@@ -1 +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"}
|
|
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","ignoreList":[]}
|
package/lib/utils/types.js.map
CHANGED
|
@@ -1 +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 extensions?: string[];\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":""}
|
|
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 extensions?: string[];\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":"","ignoreList":[]}
|
package/lib/utils/units.js.map
CHANGED
|
@@ -1 +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 str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AAE,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"}
|
|
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","ignoreList":[]}
|
|
@@ -1 +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"}
|
|
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","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/processor-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@babel/generator": "^7.23.5",
|
|
6
|
-
"@wyw-in-js/shared": "
|
|
6
|
+
"@wyw-in-js/shared": "workspace:*"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@babel/types": "^7.23.5",
|
|
10
10
|
"@types/babel__core": "^7.20.5",
|
|
11
11
|
"@types/babel__generator": "^7.6.7",
|
|
12
12
|
"@types/node": "^16.18.55",
|
|
13
|
-
"
|
|
14
|
-
"@wyw-in-js/
|
|
15
|
-
"@wyw-in-js/
|
|
16
|
-
"
|
|
17
|
-
"@wyw-in-js/ts-config": "0.8.1"
|
|
13
|
+
"@wyw-in-js/babel-config": "workspace:*",
|
|
14
|
+
"@wyw-in-js/eslint-config": "workspace:*",
|
|
15
|
+
"@wyw-in-js/ts-config": "workspace:*",
|
|
16
|
+
"typescript": "^5.2.2"
|
|
18
17
|
},
|
|
19
18
|
"engines": {
|
|
20
19
|
"node": ">=16.0.0"
|
|
@@ -30,12 +29,12 @@
|
|
|
30
29
|
"publishConfig": {
|
|
31
30
|
"access": "public"
|
|
32
31
|
},
|
|
33
|
-
"types": "types/index.d.ts",
|
|
34
32
|
"scripts": {
|
|
35
33
|
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
36
34
|
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
37
35
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
38
36
|
"lint": "eslint --ext .js,.ts .",
|
|
39
|
-
"test": "
|
|
40
|
-
}
|
|
41
|
-
|
|
37
|
+
"test": "bun test src"
|
|
38
|
+
},
|
|
39
|
+
"types": "types/index.d.ts"
|
|
40
|
+
}
|
package/types/utils/buildSlug.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSlug =
|
|
3
|
+
exports.buildSlug = buildSlug;
|
|
4
4
|
const PLACEHOLDER = /\[(.*?)]/g;
|
|
5
5
|
const isValidArgName = (key, args) => key in args;
|
|
6
6
|
function buildSlug(pattern, args) {
|
|
7
7
|
return pattern.replace(PLACEHOLDER, (_, name) => isValidArgName(name, args) ? args[name].toString() : '');
|
|
8
8
|
}
|
|
9
|
-
exports.buildSlug = buildSlug;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getClassNameAndSlug;
|
|
3
4
|
const path_1 = require("path");
|
|
4
5
|
const shared_1 = require("@wyw-in-js/shared");
|
|
5
6
|
const buildSlug_1 = require("./buildSlug");
|
|
@@ -41,4 +42,3 @@ function getClassNameAndSlug(displayName, idx, options, context) {
|
|
|
41
42
|
shared_1.logger.extend('template-parse:generated-meta')(`slug: ${slug}, displayName: ${displayName}, className: ${className}`);
|
|
42
43
|
return { className, slug };
|
|
43
44
|
}
|
|
44
|
-
exports.default = getClassNameAndSlug;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariableName =
|
|
3
|
+
exports.getVariableName = getVariableName;
|
|
4
4
|
function getVariableName(varId, rawVariableName) {
|
|
5
5
|
switch (rawVariableName) {
|
|
6
6
|
case 'raw':
|
|
@@ -12,4 +12,3 @@ function getVariableName(varId, rawVariableName) {
|
|
|
12
12
|
return `var(--${varId})`;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
exports.getVariableName = getVariableName;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = stripLines;
|
|
3
4
|
// Stripping away the new lines ensures that we preserve line numbers
|
|
4
5
|
// This is useful in case of tools such as the stylelint pre-processor
|
|
5
6
|
// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings
|
|
@@ -15,4 +16,3 @@ function stripLines(loc, text) {
|
|
|
15
16
|
}
|
|
16
17
|
return result;
|
|
17
18
|
}
|
|
18
|
-
exports.default = stripLines;
|
|
@@ -20,17 +20,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
20
20
|
}) : function(o, v) {
|
|
21
21
|
o["default"] = v;
|
|
22
22
|
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
30
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
42
|
};
|
|
33
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.default = templateProcessor;
|
|
34
45
|
const shared_1 = require("@wyw-in-js/shared");
|
|
35
46
|
const getVariableName_1 = require("./getVariableName");
|
|
36
47
|
const stripLines_1 = __importDefault(require("./stripLines"));
|
|
@@ -131,4 +142,3 @@ function templateProcessor(tagProcessor, [...template], valueCache, variableName
|
|
|
131
142
|
// eslint-disable-next-line no-param-reassign
|
|
132
143
|
return [rules, sourceMapReplacements];
|
|
133
144
|
}
|
|
134
|
-
exports.default = templateProcessor;
|
package/types/utils/toCSS.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const isCSSable: (o: unknown) => o is
|
|
1
|
+
import type { CSSable } from '../types';
|
|
2
|
+
export declare const isCSSable: (o: unknown) => o is CSSable;
|
|
3
3
|
export default function toCSS(o: CSSable): string;
|
package/types/utils/toCSS.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCSSable = void 0;
|
|
4
|
+
exports.default = toCSS;
|
|
4
5
|
const shared_1 = require("@wyw-in-js/shared");
|
|
5
6
|
const units_1 = require("./units");
|
|
6
7
|
const isCSSPropertyValue = (o) => {
|
|
@@ -58,4 +59,3 @@ function toCSS(o) {
|
|
|
58
59
|
})
|
|
59
60
|
.join(' ');
|
|
60
61
|
}
|
|
61
|
-
exports.default = toCSS;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toValidCSSIdentifier =
|
|
3
|
+
exports.toValidCSSIdentifier = toValidCSSIdentifier;
|
|
4
4
|
function toValidCSSIdentifier(s) {
|
|
5
5
|
return s.replace(/[^-_a-z0-9\u00A0-\uFFFF]/gi, '_').replace(/^\d/, '_');
|
|
6
6
|
}
|
|
7
|
-
exports.toValidCSSIdentifier = toValidCSSIdentifier;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValidParams = isValidParams;
|
|
4
|
+
exports.validateParams = validateParams;
|
|
4
5
|
function isValidParams(params, constraints) {
|
|
5
6
|
const length = Math.max(params.length, constraints.length);
|
|
6
7
|
for (let i = 0; i < length; i++) {
|
|
@@ -27,7 +28,6 @@ function isValidParams(params, constraints) {
|
|
|
27
28
|
}
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
|
-
exports.isValidParams = isValidParams;
|
|
31
31
|
function validateParams(params, constraints, messageOrError) {
|
|
32
32
|
if (!isValidParams(params, constraints)) {
|
|
33
33
|
if (typeof messageOrError === 'string') {
|
|
@@ -36,4 +36,3 @@ function validateParams(params, constraints, messageOrError) {
|
|
|
36
36
|
throw messageOrError;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
exports.validateParams = validateParams;
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|