@fastkit/plugboy-vanilla-extract-plugin 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/css.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/css/layer.ts","../src/css/theme.ts","../src/css/utils.ts"],"names":["globalStyle","layerStyle","rule","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA,eAAAA;AAAA,OAGK;;;ACPP,SAAS,qBAAqB,mBAAmB;;;ACO1C,SAAS,IAAI,KAAU,MAAqB;AACjD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,QAAI,EAAE,OAAO,SAAS;AACpB,YAAM,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,4BAA4B;AAAA,IACtE;AACA,aAAS,OAAO,GAAG;AAAA,EACrB;AAEA,SAAO;AACT;AACO,SAAS,WACd,KACA,IACA,OAAsB,CAAC,GACC;AACxB,QAAM,QAAQ,IAAI,YAAY;AAE9B,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAG;AACrB,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAEjC,QACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,SAAS,MACT;AACA,YAAM,GAAG,IAAI,GAAG,OAAoB,WAAW;AAAA,IACjD,WAAW,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GAAG;AAC7D,YAAM,GAAG,IAAI,WAAW,OAAmB,IAAI,WAAW;AAAA,IAC5D,OAAO;AACL,cAAQ;AAAA,QACN,yBAAyB,YAAY;AAAA,UACnC;AAAA,QACF,8DACE,MAAM,QAAQ,KAAK,IAAI,UAAU,OAAO;AAAA,MAE5C;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,WACd,aACA,QACgC;AAChC,QAAM,aAA+C,C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AAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAEA,SAAO;AACT","sourcesContent":["import {\n style,\n layer,\n globalLayer,\n StyleRule,\n globalStyle,\n GlobalStyleRule,\n createGlobalTheme as _createGlobalTheme,\n} from '@vanilla-extract/css';\nimport { createGlobalTheme } from './theme';\n\ntype CustomStyleRules = Record<string, any>;\n\ntype _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];\n\ntype LayerStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;\n\ntype ClassNames = string | ClassNames[];\n\ntype ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> =\n LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];\n\ntype _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];\n\ntype LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null\n ? _LayerGlobalStyleRules\n : _LayerGlobalStyleRules & CustomRules;\n\ntype AnyStyleRule<CustomRules extends CustomStyleRules | null = null> =\n | LayerStyleRules<CustomRules>\n | LayerGlobalStyleRules<CustomRules>;\n\ntype LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {\n style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;\n global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;\n anyStyle?: (style: AnyStyleRule<CustomRules>) => void;\n};\n\nexport interface LayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n> {\n layerName: string;\n parentLayerName: string | null;\n /**\n * @see {@link style}\n */\n (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link style}\n */\n style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link globalStyle}\n */\n global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;\n\n /**\n * @see {@link _createGlobalTheme}\n */\n globalTheme: typeof _createGlobalTheme;\n\n defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ): LayerStyle<CustomRules>;\n\n /**\n * Add global CSS variable with layer\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n *\n * @param selector - selector\n * @param vars - variables\n */\n pushGlobalVars(selector: string, vars: Record<string, string>): void;\n\n /**\n * Output variables accumulated by `pushGlobalVars`.\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n */\n dumpGlobalVars(): void;\n hooks: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerParentOptions {\n parent?: string;\n}\n\nexport interface DefineLayerBaseOptions<\n CustomRules extends CustomStyleRules | null = null,\n> {\n hooks?: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerScopedOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n /** Debug ID */\n debugId?: string;\n globalName?: never;\n}\n\nexport interface DefineLayerGlobalOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n debugId?: never;\n /** Parent layer name */\n globalName: string;\n}\n\nexport type DefineLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> =\n | DefineLayerScopedOptions<CustomRules>\n | DefineLayerGlobalOptions<CustomRules>;\n\nexport type DefineNestableLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;\n\nfunction isGlobalOptions(\n options: DefineLayerOptions<any>,\n): options is DefineLayerGlobalOptions {\n return 'globalName' in options;\n}\n\nfunction normalizeToObject<T extends DefineLayerOptions<any>>(\n source?: string | T,\n): T {\n if (!source) return {} as T;\n if (typeof source === 'string') return { globalName: source } as unknown as T;\n return source;\n}\n\nexport function defineLayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n>(\n globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>,\n): LayerStyle<CustomRules> {\n const options = normalizeToObject(globalNameOrOptions);\n const { parent, hooks = {} } = options;\n\n const layerName = isGlobalOptions(options)\n ? globalLayer({ parent }, options.globalName)\n : layer({ parent }, options.debugId);\n\n const layerStyle = function layerStyle(rule, debugId) {\n const rules = Array.isArray(rule) ? rule : [rule];\n const layerAppliedRules = rules.map((rule) => {\n if (typeof rule === 'string' || Array.isArray(rule)) return rule;\n return {\n '@layer': {\n [layerName]: rule,\n },\n };\n });\n if (hooks.anyStyle) {\n for (const rule of rules) {\n if (typeof rule === 'string' || Array.isArray(rule)) continue;\n hooks.anyStyle(rule);\n }\n }\n hooks.style && hooks.style(rule, debugId);\n return style(layerAppliedRules, debugId);\n } as LayerStyle<CustomRules>;\n\n layerStyle.layerName = layerName;\n layerStyle.parentLayerName = parent || null;\n layerStyle.style = layerStyle;\n layerStyle.hooks = hooks;\n\n layerStyle.global = function layerGlobalStyle(\n selector: string,\n rule: LayerGlobalStyleRules<CustomRules>,\n ) {\n hooks.anyStyle && hooks.anyStyle(rule);\n hooks.global && hooks.global(selector, rule);\n\n return globalStyle(selector, {\n '@layer': {\n [layerName]: rule,\n },\n });\n };\n\n layerStyle.globalTheme = (...args: any) =>\n (createGlobalTheme as any)(layerName, ...args);\n\n let _varQueues: [string, Record<string, string>][] = [];\n\n layerStyle.pushGlobalVars = function pushGlobalVars(\n selector: string,\n vars: Record<string, string>,\n ) {\n let queue = _varQueues.find((q) => q[0] === selector);\n if (!queue) {\n queue = [selector, {}];\n _varQueues.push(queue);\n }\n Object.assign(queue[1], vars);\n };\n\n layerStyle.dumpGlobalVars = function dumpGlobalVars() {\n for (const [selector, vars] of _varQueues) {\n layerStyle.global(selector, {\n vars,\n } as any);\n }\n _varQueues = [];\n };\n\n layerStyle.defineNestedLayer = function defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ) {\n const options = normalizeToObject(globalNameOrNestedOptions);\n const nestedHooks = options.hooks;\n\n return defineLayerStyle({\n ...options,\n hooks: {\n ...hooks,\n ...nestedHooks,\n },\n parent: layerName,\n });\n };\n\n return layerStyle;\n}\n","import { Tokens, ThemeVars, Contract, MapLeafNodes } from './types';\nimport { createThemeContract, globalStyle } from '@vanilla-extract/css';\nimport { assignVars } from './utils';\n\nexport function createGlobalTheme<ThemeTokens extends Tokens>(\n layerName: string,\n selector: string,\n tokens: ThemeTokens,\n): ThemeVars<ThemeTokens>;\nexport function createGlobalTheme<ThemeContract extends Contract>(\n layerName: string,\n selector: string,\n themeContract: ThemeContract,\n tokens: MapLeafNodes<ThemeContract, string>,\n): void;\nexport function createGlobalTheme(\n layerName: string,\n selector: string,\n arg2: any,\n arg3?: any,\n): any {\n const shouldCreateVars = Boolean(!arg3);\n\n const themeVars = shouldCreateVars\n ? createThemeContract(arg2)\n : (arg2 as ThemeVars<any>);\n\n const tokens = shouldCreateVars ? arg2 : arg3;\n\n globalStyle(selector, {\n '@layer': {\n [layerName]: {\n vars: assignVars(themeVars, tokens),\n },\n },\n });\n\n // appendCss(\n // {\n // type: 'global',\n // selector: selector,\n // rule: { vars: assignVars(themeVars, tokens) },\n // },\n // getFileScope(),\n // );\n\n if (shouldCreateVars) {\n return themeVars;\n }\n}\n","import { Contract, MapLeafNodes, CSSVarFunction } from './types';\n\ntype Primitive = string | number | null | undefined;\n\ntype Walkable = {\n [Key in string | number]: Primitive | Walkable;\n};\n\nexport function get(obj: any, path: Array<string>) {\n let result = obj;\n\n for (const key of path) {\n if (!(key in result)) {\n throw new Error(`Path ${path.join(' -> ')} does not exist in object`);\n }\n result = result[key];\n }\n\n return result;\n}\nexport function walkObject<T extends Walkable, MapTo>(\n obj: T,\n fn: (value: Primitive, path: Array<string>) => MapTo,\n path: Array<string> = [],\n): MapLeafNodes<T, MapTo> {\n const clone = obj.constructor();\n\n for (const key in obj) {\n const value = obj[key];\n const currentPath = [...path, key];\n\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n value == null\n ) {\n clone[key] = fn(value as Primitive, currentPath);\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n clone[key] = walkObject(value as Walkable, fn, currentPath);\n } else {\n console.warn(\n `Skipping invalid key \"${currentPath.join(\n '.',\n )}\". Should be a string, number, null or object. Received: \"${\n Array.isArray(value) ? 'Array' : typeof value\n }\"`,\n );\n }\n }\n\n return clone;\n}\n\nexport function assignVars<VarContract extends Contract>(\n varContract: VarContract,\n tokens: MapLeafNodes<VarContract, string>,\n): Record<CSSVarFunction, string> {\n const varSetters: { [cssVarName: string]: string } = {};\n // const { valid, diffString } = validateContract(varContract, tokens);\n\n // if (!valid) {\n // throw new Error(`Tokens don't match contract.\\n${diffString}`);\n // }\n\n walkObject(tokens, (value, path) => {\n varSetters[get(varContract, path)] = String(value);\n });\n\n return varSetters;\n}\n"]}
1
+ {"version":3,"sources":["../src/css/layer.ts","../src/css/theme.ts","../src/css/utils.ts"],"names":["globalStyle","layerStyle","rule","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA,eAAAA;AAAA,OAGK;;;ACPP,SAAS,qBAAqB,mBAAmB;;;ACQ1C,SAAS,IAAI,KAAU,MAAqB;AACjD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,QAAI,EAAE,OAAO,SAAS;AACpB,YAAM,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,4BAA4B;AAAA,IACtE;AACA,aAAS,OAAO,GAAG;AAAA,EACrB;AAEA,SAAO;AACT;AACO,SAAS,WACd,KACA,IACA,OAAsB,CAAC,GACC;AACxB,QAAM,QAAQ,IAAI,YAAY;AAE9B,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAG;AACrB,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAEjC,QACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,SAAS,MACT;AACA,YAAM,GAAG,IAAI,GAAG,OAAoB,WAAW;AAAA,IACjD,WAAW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AAiB;AACpD,eAAW,CAAC,UAAU,IAAI,KAAK,YAAY;AACzC,iBAAW,OAAO,UAAU;AAAA,QAC1B;AAAA,MACF,CAAQ;AAAA,IACV;AACA,iBAAa,CAAC;AAAA,EAChB;AAEA,aAAW,oBAAoB,SAAS,kBACtC,2BACA;AACA,UAAMG,WAAU,kBAAkB,yBAAyB;AAC3D,UAAM,cAAcA,SAAQ;AAE5B,WAAO,iBAAiB;AAAA,MACtB,GAAGA;AAAA,MACH,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAEA,SAAO;AACT","sourcesContent":["import {\n style,\n layer,\n globalLayer,\n StyleRule,\n globalStyle,\n GlobalStyleRule,\n createGlobalTheme as _createGlobalTheme,\n} from '@vanilla-extract/css';\nimport { createGlobalTheme } from './theme';\n\ntype CustomStyleRules = Record<string, any>;\n\ntype _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];\n\ntype LayerStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;\n\ntype ClassNames = string | ClassNames[];\n\ntype ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> =\n LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];\n\ntype _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];\n\ntype LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null\n ? _LayerGlobalStyleRules\n : _LayerGlobalStyleRules & CustomRules;\n\ntype AnyStyleRule<CustomRules extends CustomStyleRules | null = null> =\n | LayerStyleRules<CustomRules>\n | LayerGlobalStyleRules<CustomRules>;\n\ntype LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {\n style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;\n global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;\n anyStyle?: (style: AnyStyleRule<CustomRules>) => void;\n};\n\nexport interface LayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n> {\n layerName: string;\n parentLayerName: string | null;\n /**\n * @see {@link style}\n */\n (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link style}\n */\n style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link globalStyle}\n */\n global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;\n\n /**\n * @see {@link _createGlobalTheme}\n */\n globalTheme: typeof _createGlobalTheme;\n\n defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ): LayerStyle<CustomRules>;\n\n /**\n * Add global CSS variable with layer\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n *\n * @param selector - selector\n * @param vars - variables\n */\n pushGlobalVars(selector: string, vars: Record<string, string>): void;\n\n /**\n * Output variables accumulated by `pushGlobalVars`.\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n */\n dumpGlobalVars(): void;\n hooks: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerParentOptions {\n parent?: string;\n}\n\nexport interface DefineLayerBaseOptions<\n CustomRules extends CustomStyleRules | null = null,\n> {\n hooks?: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerScopedOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n /** Debug ID */\n debugId?: string;\n globalName?: never;\n}\n\nexport interface DefineLayerGlobalOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n debugId?: never;\n /** Parent layer name */\n globalName: string;\n}\n\nexport type DefineLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> =\n | DefineLayerScopedOptions<CustomRules>\n | DefineLayerGlobalOptions<CustomRules>;\n\nexport type DefineNestableLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;\n\nfunction isGlobalOptions(\n options: DefineLayerOptions<any>,\n): options is DefineLayerGlobalOptions {\n return 'globalName' in options;\n}\n\nfunction normalizeToObject<T extends DefineLayerOptions<any>>(\n source?: string | T,\n): T {\n if (!source) return {} as T;\n if (typeof source === 'string') return { globalName: source } as unknown as T;\n return source;\n}\n\nexport function defineLayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n>(\n globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>,\n): LayerStyle<CustomRules> {\n const options = normalizeToObject(globalNameOrOptions);\n const { parent, hooks = {} } = options;\n\n const layerName = isGlobalOptions(options)\n ? globalLayer({ parent }, options.globalName)\n : layer({ parent }, options.debugId);\n\n const layerStyle = function layerStyle(rule, debugId) {\n const rules = Array.isArray(rule) ? rule : [rule];\n const layerAppliedRules = rules.map((rule) => {\n if (typeof rule === 'string' || Array.isArray(rule)) return rule;\n return {\n '@layer': {\n [layerName]: rule,\n },\n };\n });\n if (hooks.anyStyle) {\n for (const rule of rules) {\n if (typeof rule === 'string' || Array.isArray(rule)) continue;\n hooks.anyStyle(rule);\n }\n }\n hooks.style && hooks.style(rule, debugId);\n return style(layerAppliedRules, debugId);\n } as LayerStyle<CustomRules>;\n\n layerStyle.layerName = layerName;\n layerStyle.parentLayerName = parent || null;\n layerStyle.style = layerStyle;\n layerStyle.hooks = hooks;\n\n layerStyle.global = function layerGlobalStyle(\n selector: string,\n rule: LayerGlobalStyleRules<CustomRules>,\n ) {\n hooks.anyStyle && hooks.anyStyle(rule);\n hooks.global && hooks.global(selector, rule);\n\n return globalStyle(selector, {\n '@layer': {\n [layerName]: rule,\n },\n });\n };\n\n layerStyle.globalTheme = (...args: any) =>\n (createGlobalTheme as any)(layerName, ...args);\n\n let _varQueues: [string, Record<string, string>][] = [];\n\n layerStyle.pushGlobalVars = function pushGlobalVars(\n selector: string,\n vars: Record<string, string>,\n ) {\n let queue = _varQueues.find((q) => q[0] === selector);\n if (!queue) {\n queue = [selector, {}];\n _varQueues.push(queue);\n }\n Object.assign(queue[1], vars);\n };\n\n layerStyle.dumpGlobalVars = function dumpGlobalVars() {\n for (const [selector, vars] of _varQueues) {\n layerStyle.global(selector, {\n vars,\n } as any);\n }\n _varQueues = [];\n };\n\n layerStyle.defineNestedLayer = function defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ) {\n const options = normalizeToObject(globalNameOrNestedOptions);\n const nestedHooks = options.hooks;\n\n return defineLayerStyle({\n ...options,\n hooks: {\n ...hooks,\n ...nestedHooks,\n },\n parent: layerName,\n });\n };\n\n return layerStyle;\n}\n","import { Tokens, ThemeVars, Contract, MapLeafNodes } from './types';\nimport { createThemeContract, globalStyle } from '@vanilla-extract/css';\nimport { assignVars } from './utils';\n\nexport function createGlobalTheme<ThemeTokens extends Tokens>(\n layerName: string,\n selector: string,\n tokens: ThemeTokens,\n): ThemeVars<ThemeTokens>;\nexport function createGlobalTheme<ThemeContract extends Contract>(\n layerName: string,\n selector: string,\n themeContract: ThemeContract,\n tokens: MapLeafNodes<ThemeContract, string>,\n): void;\nexport function createGlobalTheme(\n layerName: string,\n selector: string,\n arg2: any,\n arg3?: any,\n): any {\n const shouldCreateVars = Boolean(!arg3);\n\n const themeVars = shouldCreateVars\n ? createThemeContract(arg2)\n : (arg2 as ThemeVars<any>);\n\n const tokens = shouldCreateVars ? arg2 : arg3;\n\n globalStyle(selector, {\n '@layer': {\n [layerName]: {\n vars: assignVars(themeVars, tokens),\n },\n },\n });\n\n // appendCss(\n // {\n // type: 'global',\n // selector: selector,\n // rule: { vars: assignVars(themeVars, tokens) },\n // },\n // getFileScope(),\n // );\n\n if (shouldCreateVars) {\n return themeVars;\n }\n}\n","/* eslint-disable no-console */\nimport { Contract, MapLeafNodes, CSSVarFunction } from './types';\n\ntype Primitive = string | number | null | undefined;\n\ntype Walkable = {\n [Key in string | number]: Primitive | Walkable;\n};\n\nexport function get(obj: any, path: Array<string>) {\n let result = obj;\n\n for (const key of path) {\n if (!(key in result)) {\n throw new Error(`Path ${path.join(' -> ')} does not exist in object`);\n }\n result = result[key];\n }\n\n return result;\n}\nexport function walkObject<T extends Walkable, MapTo>(\n obj: T,\n fn: (value: Primitive, path: Array<string>) => MapTo,\n path: Array<string> = [],\n): MapLeafNodes<T, MapTo> {\n const clone = obj.constructor();\n\n for (const key in obj) {\n const value = obj[key];\n const currentPath = [...path, key];\n\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n value == null\n ) {\n clone[key] = fn(value as Primitive, currentPath);\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n clone[key] = walkObject(value as Walkable, fn, currentPath);\n } else {\n console.warn(\n `Skipping invalid key \"${currentPath.join(\n '.',\n )}\". Should be a string, number, null or object. Received: \"${\n Array.isArray(value) ? 'Array' : typeof value\n }\"`,\n );\n }\n }\n\n return clone;\n}\n\nexport function assignVars<VarContract extends Contract>(\n varContract: VarContract,\n tokens: MapLeafNodes<VarContract, string>,\n): Record<CSSVarFunction, string> {\n const varSetters: { [cssVarName: string]: string } = {};\n // const { valid, diffString } = validateContract(varContract, tokens);\n\n // if (!valid) {\n // throw new Error(`Tokens don't match contract.\\n${diffString}`);\n // }\n\n walkObject(tokens, (value, path) => {\n varSetters[get(varContract, path)] = String(value);\n });\n\n return varSetters;\n}\n"]}
@@ -42,7 +42,7 @@ async function createVanillaExtractPlugin(options = {}) {
42
42
  hooks: {
43
43
  async setupWorkspace(ctx) {
44
44
  const { external = [] } = ctx.config;
45
- ctx.config.external = [...external, /@vanilla\-extract/];
45
+ ctx.config.external = [...external, /@vanilla-extract/];
46
46
  ctx.meta.hasVanillaExtract = await !!findFile(
47
47
  ctx.dirs.src.value,
48
48
  /\.css\.ts$/
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/plugin.ts","../src/esbuild.ts","../src/utils.ts","../src/vite.ts"],"names":["vanillaExtractPlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO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AS,MAAM;AACtC,kBAAM,MAAM,WAAW,QAAQ;AAC/B,gBAAI,CAAC;AAAK;AAEV,kBAAM,OAAO,MAAM,GAAG,SAAS,UAAU,OAAO;AAChD,kBAAM,UAAU,QAAQ,QAAQ,UAAU;AAC1C,gBAAI,CAAC;AAAS;AACd,kBAAM,WAAW,QAAQ,IAAI;AAC7B,gBAAI,SAAS;AAAU;AAEvB,kBAAM,GAAG,UAAU,UAAU,SAAS,UAAU,GAAG,OAAO;AAAA,UAC5D,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,CAAC,cAAc;AACb,YAAI,CAAC,UAAU,KAAK;AAAmB;AACvC,eAAO,sBAAsB,OAAO;AAAA,MACtC;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AG9DA,SAAS,yBAAyB;AAElC,SAAS,wBAAAA,6BAA4B;AAWrC,eAAsB,yBACpB,UAA2C,CAAC,GACvB;AACrB,QAAM,SAAS,MAAM,kBAAwC,WAAW;AACxE,QAAM;AAAA,IACJ,aAAa;AAAA,IACb,gBAAgB,qBAAqB,CAAC;AAAA,EACxC,IAAI,QAAQ,WAAW,CAAC;AAExB,QAAM,EAAE,iBAAiB,CAAC,EAAE,IAAI;AAEhC,SAAOA,sBAAqB;AAAA,IAC1B,aAAa;AAAA,IACb,GAAG;AAAA,IACH,gBAAgB;AAAA,MACd,GAAG;AAAA,MACH,GAAG;AAAA,MACH,UAAU;AAAA,QACR,mBAAmB;AAAA,QACnB,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF,CAAC;AACH","sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as esbuildPlugin } from '@vanilla-extract/esbuild-plugin';\n\ntype VanillaExtractPluginOptions = NonNullable<\n Parameters<typeof esbuildPlugin>[0]\n>;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface VanillaExtractEsbuildOptions\n extends NonNullable<VanillaExtractPluginOptions['esbuildOptions']> {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PluginOptions\n extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {}\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n options: PluginOptions;\n}\n","import { definePlugin, findFile } from '@fastkit/plugboy';\nimport { ESBuildVanillaExtract } from './esbuild';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\nimport fs from 'node:fs/promises';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nconst extMatchRe = /\\.(mjs|css)$/;\n\nfunction extractExt(filePath: string) {\n return filePath.match(extMatchRe)?.[1] as 'mjs' | 'css' | undefined;\n}\n\nconst emptyVanillaImportRe = /(^|\\n)import '@vanilla-extract\\/css';?/g;\n\nfunction cleanJS(code: string) {\n return code.replace(emptyVanillaImportRe, '');\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n options,\n hooks: {\n async setupWorkspace(ctx) {\n const { external = [] } = ctx.config;\n\n ctx.config.external = [...external, /@vanilla\\-extract/];\n\n ctx.meta.hasVanillaExtract = await !!findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n );\n },\n async onSuccess(builder, files) {\n if (!builder.workspace.meta.hasVanillaExtract) return;\n await Promise.all(\n files.map(async ({ path: filePath }) => {\n const ext = extractExt(filePath);\n if (!ext) return;\n\n const code = await fs.readFile(filePath, 'utf-8');\n const cleaner = ext === 'mjs' ? cleanJS : undefined;\n if (!cleaner) return;\n const replaced = cleaner(code);\n if (code === replaced) return;\n\n await fs.writeFile(filePath, replaced.trimStart(), 'utf-8');\n }),\n );\n },\n },\n esbuildPlugins: [\n (workspace) => {\n if (!workspace.meta.hasVanillaExtract) return;\n return ESBuildVanillaExtract(options);\n },\n ],\n });\n}\n","import { ESBuildPlugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';\nimport { PluginOptions } from './types';\nimport { mergeExternal } from './utils';\n\nexport function ESBuildVanillaExtract(\n options: PluginOptions = {},\n): ESBuildPlugin {\n const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n ...options,\n esbuildOptions: {\n ...esbuildOptions,\n external: mergeExternal(esbuildOptions.external),\n },\n }) as any;\n}\n","const EXTERNAL_DEFAULTS = ['node:*'];\n\nexport function mergeExternal(...chunks: (string[] | undefined)[]): string[] {\n const result: string[] = [...EXTERNAL_DEFAULTS];\n for (const chunk of chunks) {\n chunk && result.push(...chunk);\n }\n return Array.from(new Set(result));\n}\n","import { PLUGIN_NAME, VanillaExtractPlugin } from './types';\nimport { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { mergeExternal } from './utils';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface ViteVanillaExtractPluginOptions\n extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const {\n identifiers: baseIdentifiers,\n esbuildOptions: baseEsbuildOptions = {},\n } = plugin?.options || {};\n\n const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n esbuildOptions: {\n ...baseEsbuildOptions,\n ...esbuildOptions,\n external: mergeExternal(\n baseEsbuildOptions.external,\n esbuildOptions.external,\n ),\n },\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/plugin.ts","../src/esbuild.ts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AQ,UAAU,KAAK;AAAmB;AAC/C,cAAM,QAAQ;AAAA,UACZ,MAAM,IAAI,OAAO,EAAE,MAAM,SAAS,MAAM;AACtC,kBAAM,MAAM,WAAW,QAAQ;AAC/B,gBAAI,CAAC;AAAK;AAEV,kBAAM,OAAO,MAAM,GAAG,SAAS,UAAU,OAAO;AAChD,kBAAM,UAAU,QAAQ,QAAQ,UAAU;AAC1C,gBAAI,CAAC;AAAS;AACd,kBAAM,WAAW,QAAQ,IAAI;AAC7B,gBAAI,SAAS;AAAU;AAEvB,kBAAM,GAAG,UAAU,UAAU,SAAS,UAAU,GAAG,OAAO;AAAA,UAC5D,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,CAAC,cAAc;AACb,YAAI,CAAC,UAAU,KAAK;AAAmB;AACvC,eAAO,sBAAsB,OAAO;AAAA,MACtC;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AG9DA,SAAS,yBAAyB;AAElC,SAAS,wBAAAA,6BAA4B;AAWrC,eAAsB,yBACpB,UAA2C,CAAC,GACvB;AACrB,QAAM,SAAS,MAAM,kBAAwC,WAAW;AACxE,QAAM;AAAA,IACJ,aAAa;AAAA,IACb,gBAAgB,qBAAqB,CAAC;AAAA,EACxC,IAAI,QAAQ,WAAW,CAAC;AAExB,QAAM,EAAE,iBAAiB,CAAC,EAAE,IAAI;AAEhC,SAAOA,sBAAqB;AAAA,IAC1B,aAAa;AAAA,IACb,GAAG;AAAA,IACH,gBAAgB;AAAA,MACd,GAAG;AAAA,MACH,GAAG;AAAA,MACH,UAAU;AAAA,QACR,mBAAmB;AAAA,QACnB,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF,CAAC;AACH","sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as esbuildPlugin } from '@vanilla-extract/esbuild-plugin';\n\ntype VanillaExtractPluginOptions = NonNullable<\n Parameters<typeof esbuildPlugin>[0]\n>;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface VanillaExtractEsbuildOptions\n extends NonNullable<VanillaExtractPluginOptions['esbuildOptions']> {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PluginOptions\n extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {}\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n options: PluginOptions;\n}\n","import { definePlugin, findFile } from '@fastkit/plugboy';\nimport { ESBuildVanillaExtract } from './esbuild';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\nimport fs from 'node:fs/promises';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nconst extMatchRe = /\\.(mjs|css)$/;\n\nfunction extractExt(filePath: string) {\n return filePath.match(extMatchRe)?.[1] as 'mjs' | 'css' | undefined;\n}\n\nconst emptyVanillaImportRe = /(^|\\n)import '@vanilla-extract\\/css';?/g;\n\nfunction cleanJS(code: string) {\n return code.replace(emptyVanillaImportRe, '');\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n options,\n hooks: {\n async setupWorkspace(ctx) {\n const { external = [] } = ctx.config;\n\n ctx.config.external = [...external, /@vanilla-extract/];\n\n ctx.meta.hasVanillaExtract = await !!findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n );\n },\n async onSuccess(builder, files) {\n if (!builder.workspace.meta.hasVanillaExtract) return;\n await Promise.all(\n files.map(async ({ path: filePath }) => {\n const ext = extractExt(filePath);\n if (!ext) return;\n\n const code = await fs.readFile(filePath, 'utf-8');\n const cleaner = ext === 'mjs' ? cleanJS : undefined;\n if (!cleaner) return;\n const replaced = cleaner(code);\n if (code === replaced) return;\n\n await fs.writeFile(filePath, replaced.trimStart(), 'utf-8');\n }),\n );\n },\n },\n esbuildPlugins: [\n (workspace) => {\n if (!workspace.meta.hasVanillaExtract) return;\n return ESBuildVanillaExtract(options);\n },\n ],\n });\n}\n","import { ESBuildPlugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';\nimport { PluginOptions } from './types';\nimport { mergeExternal } from './utils';\n\nexport function ESBuildVanillaExtract(\n options: PluginOptions = {},\n): ESBuildPlugin {\n const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n ...options,\n esbuildOptions: {\n ...esbuildOptions,\n external: mergeExternal(esbuildOptions.external),\n },\n }) as any;\n}\n","const EXTERNAL_DEFAULTS = ['node:*'];\n\nexport function mergeExternal(...chunks: (string[] | undefined)[]): string[] {\n const result: string[] = [...EXTERNAL_DEFAULTS];\n for (const chunk of chunks) {\n chunk && result.push(...chunk);\n }\n return Array.from(new Set(result));\n}\n","import { PLUGIN_NAME, VanillaExtractPlugin } from './types';\nimport { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { mergeExternal } from './utils';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface ViteVanillaExtractPluginOptions\n extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const {\n identifiers: baseIdentifiers,\n esbuildOptions: baseEsbuildOptions = {},\n } = plugin?.options || {};\n\n const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n esbuildOptions: {\n ...baseEsbuildOptions,\n ...esbuildOptions,\n external: mergeExternal(\n baseEsbuildOptions.external,\n esbuildOptions.external,\n ),\n },\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastkit/plugboy-vanilla-extract-plugin",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -48,11 +48,11 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "vite": "^4.3.5",
51
- "@fastkit/plugboy": "0.1.6"
51
+ "@fastkit/plugboy": "0.1.8"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "vite": "^4.3.0",
55
- "@fastkit/plugboy": "0.1.6"
55
+ "@fastkit/plugboy": "0.1.8"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "@vanilla-extract/vite-plugin": {