@style-this/core 0.1.4 → 0.2.1

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.
@@ -1,37 +1,84 @@
1
1
  //#region native/pkg/style_this.d.ts
2
- /* tslint:disable */
3
- /* eslint-disable */
4
2
 
5
3
  declare class Transformer$1 {
6
4
  free(): void;
7
5
  [Symbol.dispose](): void;
6
+ /**
7
+ * Clear import registrations for a file
8
+ * Call this before re-transforming a file to clear its old import records
9
+ */
10
+ clear_file_imports(filepath: string): void;
11
+ /**
12
+ * Clear value cache for a specific file
13
+ */
14
+ clear_value_cache(filepath: string): void;
15
+ /**
16
+ * Get all collected atomic CSS
17
+ */
18
+ get_atomic_css(): string;
19
+ /**
20
+ * Get the current exports for a file from the value cache
21
+ * Returns a JS Array of export names
22
+ */
23
+ get_file_exports(filepath: string): Array<any>;
24
+ /**
25
+ * Get files that import changed exports from the given file
26
+ * Returns a JS Array of filepaths that need to be invalidated
27
+ *
28
+ * `changed_exports` should be a JS Array of export names that changed
29
+ */
30
+ get_importers_of_changed_exports(filepath: string, changed_exports: any): Array<any>;
31
+ /**
32
+ * Get all files that transitively depend on changed exports from the given file
33
+ *
34
+ * `changed_exports` should be a JS Array of export names that changed, empty means any
35
+ */
36
+ get_transitive_importers(filepath: string, changed_exports: any): Array<any>;
8
37
  constructor(opts: any);
9
- transform(code: string, filepath: string, skip_css_eval: boolean, import_source?: string | null): Promise<any | undefined>;
38
+ /**
39
+ * * `load_file` - Overrides the transformer's `loadFile` for this transform and all of its
40
+ * dependency evaluations, e.g. to resolve within the calling plugin context.
41
+ */
42
+ transform(code: string, filepath: string, skip_css_eval: boolean, load_file?: Function | null): Promise<any | undefined>;
10
43
  }
11
44
  //#endregion
12
45
  //#region src/compiler.d.ts
46
+ interface CacheRegistry {
47
+ css_cache_ref(): string;
48
+ atomic_cache_ref(): string;
49
+ value_cache_ref(): string;
50
+ invalidateModule(filepath: string): void;
51
+ }
13
52
  interface Transformer extends Omit<Transformer$1, "transform"> {
14
- transform(code: string, filepath: string, skipCssEval: boolean, importSource?: string): Promise<{
53
+ transform(code: string, filepath: string, skipCssEval: boolean, loadFile?: (id: string, importer: string) => Promise<[string, string]>): Promise<{
15
54
  code: string;
16
55
  sourcemap: string;
17
- temporaryPrograms: string[];
18
56
  } | undefined>;
19
57
  }
20
- type CssCachEntry = Promise<string> & {
21
- resolve: (value: string) => void;
22
- reject: (error: Error) => void;
58
+ type CssSourceMapData = Array<{
59
+ className: string;
60
+ start: number;
61
+ end: number;
62
+ }>;
63
+ type CssCachEntry = Promise<string | Error> & {
64
+ resolve: (value: string | Error, sourcemapData?: CssSourceMapData, filepath?: string) => void;
65
+ code: string;
23
66
  };
24
67
  declare const Transformer: new (opts: {
25
68
  cwd: string;
26
69
  ignoredImports: Record<string, string[]>;
27
70
  loadFile: (filepath: string, importer: string) => Promise<[string, string]>;
28
- cssCache: Map<string, CssCachEntry>;
29
- valueCache: Record<string, Record<string, any>>;
71
+ createRequire?: (filename: string) => NodeRequire;
72
+ cacheRegistry: CacheRegistry;
30
73
  wrapSelectorsWithGlobal?: boolean;
31
74
  cssExtension: string;
32
75
  useRequire?: boolean;
76
+ debug?: boolean;
77
+ atomic?: boolean;
78
+ onDebugVirtualModule?: (name: string, code: string) => void;
33
79
  }) => Transformer;
80
+ declare const CacheRegistry: new () => CacheRegistry;
34
81
  declare const initializeStyleThis: () => Promise<void>;
35
82
  //#endregion
36
- export { CssCachEntry, Transformer, initializeStyleThis };
83
+ export { CacheRegistry, CssCachEntry, CssSourceMapData, Transformer, initializeStyleThis };
37
84
  //# sourceMappingURL=compiler.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.cts","names":["Transformer","Symbol","dispose","Promise","initialize","InitInput","RequestInfo","URL","Response","BufferSource","WebAssembly","Module","InitOutput","Memory","Table","SyncInitInput","initSync","__wbg_init","default"],"sources":["../native/pkg/style_this.d.ts","../src/compiler.ts"],"sourcesContent":["/* tslint:disable */\n/* eslint-disable */\n\nexport class Transformer {\n free(): void;\n [Symbol.dispose](): void;\n constructor(opts: any);\n transform(code: string, filepath: string, skip_css_eval: boolean, import_source?: string | null): Promise<any | undefined>;\n}\n\nexport function initialize(): void;\n\nexport type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;\n\nexport interface InitOutput {\n readonly memory: WebAssembly.Memory;\n readonly __wbg_transformer_free: (a: number, b: number) => void;\n readonly transformer_new: (a: any) => number;\n readonly transformer_transform: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;\n readonly initialize: () => void;\n readonly wasm_bindgen__convert__closures_____invoke__h011f6951b77633db: (a: number, b: number, c: any) => void;\n readonly wasm_bindgen__closure__destroy__h4fe13f17b5a5dde9: (a: number, b: number) => void;\n readonly wasm_bindgen__convert__closures_____invoke__h8238ca605d8fd58c: (a: number, b: number, c: any, d: any) => void;\n readonly __wbindgen_malloc: (a: number, b: number) => number;\n readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;\n readonly __wbindgen_exn_store: (a: number) => void;\n readonly __externref_table_alloc: () => number;\n readonly __wbindgen_externrefs: WebAssembly.Table;\n readonly __wbindgen_free: (a: number, b: number, c: number) => void;\n readonly __wbindgen_start: () => void;\n}\n\nexport type SyncInitInput = BufferSource | WebAssembly.Module;\n\n/**\n* Instantiates the given `module`, which can either be bytes or\n* a precompiled `WebAssembly.Module`.\n*\n* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.\n*\n* @returns {InitOutput}\n*/\nexport function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;\n\n/**\n* If `module_or_path` is {RequestInfo} or {URL}, makes a request and\n* for everything else, calls `WebAssembly.instantiate` directly.\n*\n* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.\n*\n* @returns {Promise<InitOutput>}\n*/\nexport default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<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Array","Function","Promise","initialize","InitInput","RequestInfo","URL","Response","BufferSource","WebAssembly","Module","InitOutput","Memory","Table","SyncInitInput","initSync","__wbg_init","default"],"sources":["../native/pkg/style_this.d.ts","../src/compiler.ts"],"sourcesContent":["/* tslint:disable */\n/* eslint-disable */\n\n/**\n * Registry for all caches used during CSS transformation.\n * Holds Rust-side VALUE_CACHE, ATOMIC_CSS_CACHE, and owns JS-side caches.\n */\nexport class CacheRegistry {\n free(): void;\n [Symbol.dispose](): void;\n /**\n * Get the atomic cache reference (for internal Rust use with JS eval)\n */\n atomic_cache_ref(): string;\n /**\n * Get the CSS cache reference (for internal Rust use with JS eval)\n */\n css_cache_ref(): string;\n /**\n * Delete an atomic cache entry\n */\n delete_atomic_module(filepath: string): void;\n /**\n * Delete a CSS cache entry\n */\n delete_css_module(filepath: string): void;\n /**\n * Delete a value cache entry\n */\n delete_value_cache_entry(filepath: string): void;\n /**\n * Create a new CacheRegistry from an existing JS CacheRegistry\n * This creates global refs that point to the TS CacheRegistry's existing cache objects\n */\n static from_js_cache_registry(js_cache_registry: any, css_cache_ref: string, atomic_cache_ref: string, value_cache_ref: string): CacheRegistry;\n /**\n * Get atomic module from cache\n */\n get_atomic_module(filepath: string): any;\n /**\n * Get CSS module from cache\n */\n get_css_module(filepath: string): any;\n /**\n * Check if atomic module exists in cache\n */\n has_atomic_module(filepath: string): boolean;\n /**\n * Check if CSS module exists in cache\n */\n has_css_module(filepath: string): boolean;\n /**\n * Invalidate a module by removing it from both CSS and atomic caches\n */\n invalidate_module(filepath: string): void;\n /**\n * Create a new CacheRegistry with default JS caches\n */\n constructor();\n /**\n * Set atomic module in cache\n */\n set_atomic_module(filepath: string, value: any): void;\n /**\n * Set CSS module in cache\n */\n set_css_module(filepath: string, value: any): void;\n /**\n * Get the value cache reference (for internal Rust use with JS eval)\n */\n value_cache_ref(): string;\n}\n\nexport class Transformer {\n free(): void;\n [Symbol.dispose](): void;\n /**\n * Clear import registrations for a file\n * Call this before re-transforming a file to clear its old import records\n */\n clear_file_imports(filepath: string): void;\n /**\n * Clear value cache for a specific file\n */\n clear_value_cache(filepath: string): void;\n /**\n * Get all collected atomic CSS\n */\n get_atomic_css(): string;\n /**\n * Get the current exports for a file from the value cache\n * Returns a JS Array of export names\n */\n get_file_exports(filepath: string): Array<any>;\n /**\n * Get files that import changed exports from the given file\n * Returns a JS Array of filepaths that need to be invalidated\n *\n * `changed_exports` should be a JS Array of export names that changed\n */\n get_importers_of_changed_exports(filepath: string, changed_exports: any): Array<any>;\n /**\n * Get all files that transitively depend on changed exports from the given file\n *\n * `changed_exports` should be a JS Array of export names that changed, empty means any\n */\n get_transitive_importers(filepath: string, changed_exports: any): Array<any>;\n constructor(opts: any);\n /**\n * * `load_file` - Overrides the transformer's `loadFile` for this transform and all of its\n * dependency evaluations, e.g. to resolve within the calling plugin context.\n */\n transform(code: string, filepath: string, skip_css_eval: boolean, load_file?: Function | null): Promise<any | undefined>;\n}\n\nexport function initialize(): void;\n\nexport type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;\n\nexport interface InitOutput {\n readonly memory: WebAssembly.Memory;\n readonly __wbg_cacheregistry_free: (a: number, b: number) => void;\n readonly __wbg_transformer_free: (a: number, b: number) => void;\n readonly cacheregistry_atomic_cache_ref: (a: number) => [number, number];\n readonly cacheregistry_css_cache_ref: (a: number) => [number, number];\n readonly cacheregistry_delete_atomic_module: (a: number, b: number, c: number) => void;\n readonly cacheregistry_delete_css_module: (a: number, b: number, c: number) => void;\n readonly cacheregistry_delete_value_cache_entry: (a: number, b: number, c: number) => void;\n readonly cacheregistry_from_js_cache_registry: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => number;\n readonly cacheregistry_get_atomic_module: (a: number, b: number, c: number) => any;\n readonly cacheregistry_get_css_module: (a: number, b: number, c: number) => any;\n readonly cacheregistry_has_atomic_module: (a: number, b: number, c: number) => number;\n readonly cacheregistry_has_css_module: (a: number, b: number, c: number) => number;\n readonly cacheregistry_invalidate_module: (a: number, b: number, c: number) => void;\n readonly cacheregistry_new: () => number;\n readonly cacheregistry_set_atomic_module: (a: number, b: number, c: number, d: any) => void;\n readonly cacheregistry_set_css_module: (a: number, b: number, c: number, d: any) => void;\n readonly cacheregistry_value_cache_ref: (a: number) => [number, number];\n readonly initialize: () => void;\n readonly transformer_clear_file_imports: (a: number, b: number, c: number) => void;\n readonly transformer_clear_value_cache: (a: number, b: number, c: number) => void;\n readonly transformer_get_atomic_css: (a: number) => [number, number];\n readonly transformer_get_file_exports: (a: number, b: number, c: number) => any;\n readonly transformer_get_importers_of_changed_exports: (a: number, b: number, c: number, d: any) => any;\n readonly transformer_get_transitive_importers: (a: number, b: number, c: number, d: any) => any;\n readonly transformer_new: (a: any) => number;\n readonly transformer_transform: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;\n readonly wasm_bindgen_a26a977dcb4e9872___convert__closures_____invoke___js_sys_cd38c056b37ed74a___Function_fn_wasm_bindgen_a26a977dcb4e9872___JsValue_____wasm_bindgen_a26a977dcb4e9872___sys__Undefined___js_sys_cd38c056b37ed74a___Function_fn_wasm_bindgen_a26a977dcb4e9872___JsValue_____wasm_bindgen_a26a977dcb4e9872___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;\n readonly wasm_bindgen_a26a977dcb4e9872___convert__closures_____invoke___wasm_bindgen_a26a977dcb4e9872___JsValue__core_dde6c4b55a98adc4___result__Result_____wasm_bindgen_a26a977dcb4e9872___JsError___true_: (a: number, b: number, c: any) => [number, number];\n readonly __wbindgen_malloc: (a: number, b: number) => number;\n readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;\n readonly __wbindgen_free: (a: number, b: number, c: number) => void;\n readonly __wbindgen_exn_store: (a: number) => void;\n readonly __externref_table_alloc: () => number;\n readonly __wbindgen_externrefs: WebAssembly.Table;\n readonly __wbindgen_destroy_closure: (a: number, b: number) => void;\n readonly __externref_table_dealloc: (a: number) => void;\n readonly __wbindgen_start: () => void;\n}\n\nexport type SyncInitInput = BufferSource | WebAssembly.Module;\n\n/**\n * Instantiates the given `module`, which can either be bytes or\n * a precompiled `WebAssembly.Module`.\n *\n * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.\n *\n * @returns {InitOutput}\n */\nexport function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;\n\n/**\n * If `module_or_path` is {RequestInfo} or {URL}, makes a request and\n * for everything else, calls `WebAssembly.instantiate` directly.\n *\n * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.\n *\n * @returns {Promise<InitOutput>}\n */\nexport default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;\n"],"mappings":";;cAyEaG,aAAAA;;GAERF,MAAAA,CAAOC,OAAAA;;;;;;;;;;;;;;;;;;sCAkB4BE;;;;;;;4EAOsCA;;;;;;oEAMRA;;;;;;gFAMYC,kBAAkBC;;;;AAvCvFH,UCpEI,aAAA,CDoEO;EAEnBF,aAAOC,EAAAA,EAAAA,MAAAA;EAkB4BE,gBAAAA,EAAAA,EAAAA,MAAAA;EAOsCA,eAAAA,EAAAA,EAAAA,MAAAA;EAMRA,gBAAAA,CAAAA,QAAAA,EAAAA,MAAAA,CAAAA,EAAAA,IAAAA;;AAM8BE,UCpGnF,WAAA,SAAoB,IDoG+DA,CCpG1D,aDoG0DA,EAAAA,WAAAA,CAAAA,CAAAA;EAAO,SAAA,CAAA,IAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,WAAA,EAAA,OAAA,EAAA,QAAA,CAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,GC/F1D,OD+F0D,CAAA,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA,CAAA,EC9FtG,OD8FsG,CAAA;;;;AC3G3G;AAOiB,KAeL,gBAAA,GAAmB,KAfF,CAAA;EAAa,SAAA,EAAA,MAAA;EAKO,KAAA,EAAA,MAAA;EAC5C,GAAA,EAAA,MAAA;CANgC,CAAA;AAAI,KAqB7B,YAAA,GAAe,OArBc,CAAA,MAAA,GAqBG,KArBH,CAAA,GAAA;EAe7B,OAAA,EAAA,CAAA,KAAA,EAAA,MAAgB,GAQR,KARW,EAAA,aAAK,CAAA,EAShB,gBATgB,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAMxB,IAAA,EAAA,MAAA;CAAgC;AAAjB,cAUd,WAVc,EAAA,KAAA,IAAA,EAAA;EAEP,GAAA,EAAA,MAAA;EACA,cAAA,EASF,MATE,CAAA,MAAA,EAAA,MAAA,EAAA,CAAA;EAAgB,QAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,QAAA,EAAA,MAAA,EAAA,GAWgB,OAXhB,CAAA,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;EAOvB,aAAA,CAgBI,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAXuB,WAWvB;EAdC,aAAA,EAKD,aALC;EAEkC,uBAAA,CAAA,EAAA,OAAA;EACZ,YAAA,EAAA,MAAA;EAEvB,UAAA,CAAA,EAAA,OAAA;EASX,KAAA,CAAA,EAAA,OAAA;EAAW,MAAA,CAAA,EAAA,OAAA;EAEJ,oBAAoE,CAAA,EAAA,CAAA,IAAb,EAAA,MAAA,EAAA,IAAa,EAAA,MAAA,EAAA,GAAA,IAAA;AAEjF,CAAA,EAAA,GAJM,WAIO;cAFA,yBAAuD;cAEvD,2BAAmB"}
@@ -0,0 +1,31 @@
1
+ //#region src/compiler.d.ts
2
+
3
+ type CssSourceMapData = Array<{
4
+ className: string;
5
+ start: number;
6
+ end: number;
7
+ }>;
8
+ //#endregion
9
+ //#region src/cssSourceMap.d.ts
10
+ interface SourceMapSegment {
11
+ generatedLine: number;
12
+ generatedColumn: number;
13
+ originalLine: number;
14
+ originalColumn: number;
15
+ source: string;
16
+ }
17
+ interface SourceMap {
18
+ version: number;
19
+ file?: string;
20
+ sources: string[];
21
+ sourcesContent: string[];
22
+ names: string[];
23
+ mappings: string;
24
+ }
25
+ /**
26
+ * Generate a CSS source map that maps generated CSS classes back to original source locations
27
+ */
28
+ declare function generateCssSourceMap(cssContent: string, sourcemapData: CssSourceMapData, originalFilepath: string, originalSource: string, generatedFilepath?: string): SourceMap;
29
+ //#endregion
30
+ export { SourceMap, SourceMapSegment, generateCssSourceMap };
31
+ //# sourceMappingURL=cssSourceMap.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssSourceMap.d.mts","names":[],"sources":["../src/compiler.ts","../src/cssSourceMap.ts"],"sourcesContent":[],"mappings":";;KA2BY,gBAAA,GAAmB;;;;;;;AAAnB,UCzBK,gBAAA,CDyBW;;;;ECzBX,cAAA,EAAA,MAAgB;EAQhB,MAAA,EAAA,MAAS;AAY1B;UAZiB,SAAA;;;;;;;;;;;iBAYD,oBAAA,oCAEC,iGAId"}
@@ -0,0 +1,106 @@
1
+ //#region src/cssSourceMap.ts
2
+ /**
3
+ * Generate a CSS source map that maps generated CSS classes back to original source locations
4
+ */
5
+ function generateCssSourceMap(cssContent, sourcemapData, originalFilepath, originalSource, generatedFilepath) {
6
+ const segments = [];
7
+ for (const entry of sourcemapData) {
8
+ const position = findSelectorInCss(cssContent, `.${entry.className}`);
9
+ if (position) {
10
+ const originalPos = getLineAndColumn(originalSource, entry.start);
11
+ segments.push({
12
+ generatedLine: position.line,
13
+ generatedColumn: position.column,
14
+ originalLine: originalPos.line,
15
+ originalColumn: originalPos.column,
16
+ source: originalFilepath
17
+ });
18
+ }
19
+ }
20
+ const mappings = segmentsToVLQ(segments);
21
+ return {
22
+ version: 3,
23
+ file: generatedFilepath,
24
+ sources: [originalFilepath],
25
+ sourcesContent: [originalSource],
26
+ names: [],
27
+ mappings
28
+ };
29
+ }
30
+ function findSelectorInCss(css, selector) {
31
+ const index = css.indexOf(selector);
32
+ if (index === -1) return null;
33
+ const beforeSelector = css.substring(0, index);
34
+ return {
35
+ line: (beforeSelector.match(/\n/g) || []).length,
36
+ column: index - beforeSelector.lastIndexOf("\n") - 1
37
+ };
38
+ }
39
+ function getLineAndColumn(source, offset) {
40
+ const beforeOffset = source.substring(0, offset);
41
+ const line = (beforeOffset.match(/\n/g) || []).length;
42
+ const column = offset - beforeOffset.lastIndexOf("\n") - 1;
43
+ return {
44
+ line,
45
+ column: Math.max(0, column)
46
+ };
47
+ }
48
+ /**
49
+ * Convert segments to VLQ-encoded mappings string
50
+ * This is a simplified implementation - for production, consider using a library
51
+ */
52
+ function segmentsToVLQ(segments) {
53
+ if (segments.length === 0) return "";
54
+ segments.sort((a, b) => {
55
+ if (a.generatedLine !== b.generatedLine) return a.generatedLine - b.generatedLine;
56
+ return a.generatedColumn - b.generatedColumn;
57
+ });
58
+ const lines = [];
59
+ let currentLine = 0;
60
+ let previousGeneratedColumn = 0;
61
+ let previousOriginalLine = 0;
62
+ let previousOriginalColumn = 0;
63
+ let previousSourceIndex = 0;
64
+ for (const segment of segments) {
65
+ while (currentLine < segment.generatedLine) {
66
+ lines.push("");
67
+ currentLine++;
68
+ previousGeneratedColumn = 0;
69
+ }
70
+ const values = [
71
+ segment.generatedColumn - previousGeneratedColumn,
72
+ 0 - previousSourceIndex,
73
+ segment.originalLine - previousOriginalLine,
74
+ segment.originalColumn - previousOriginalColumn
75
+ ];
76
+ lines[currentLine] = (lines[currentLine] ? lines[currentLine] + "," : "") + values.map(encodeVLQ).join("");
77
+ previousGeneratedColumn = segment.generatedColumn;
78
+ previousOriginalLine = segment.originalLine;
79
+ previousOriginalColumn = segment.originalColumn;
80
+ previousSourceIndex = 0;
81
+ }
82
+ return lines.join(";");
83
+ }
84
+ /**
85
+ * Encode a value as VLQ (Variable Length Quantity)
86
+ */
87
+ function encodeVLQ(value) {
88
+ const VLQ_BASE_SHIFT = 5;
89
+ const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
90
+ const VLQ_BASE_MASK = VLQ_BASE - 1;
91
+ const VLQ_CONTINUATION_BIT = VLQ_BASE;
92
+ const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
93
+ let encoded = value < 0 ? -value << 1 | 1 : value << 1;
94
+ let result = "";
95
+ do {
96
+ let digit = encoded & VLQ_BASE_MASK;
97
+ encoded >>>= VLQ_BASE_SHIFT;
98
+ if (encoded > 0) digit |= VLQ_CONTINUATION_BIT;
99
+ result += BASE64_CHARS[digit];
100
+ } while (encoded > 0);
101
+ return result;
102
+ }
103
+
104
+ //#endregion
105
+ export { generateCssSourceMap };
106
+ //# sourceMappingURL=cssSourceMap.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssSourceMap.mjs","names":["segments: SourceMapSegment[]","lines: string[]"],"sources":["../src/cssSourceMap.ts"],"sourcesContent":["import type { CssSourceMapData } from \"./compiler.js\";\n\nexport interface SourceMapSegment {\n generatedLine: number;\n generatedColumn: number;\n originalLine: number;\n originalColumn: number;\n source: string;\n}\n\nexport interface SourceMap {\n version: number;\n file?: string;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n}\n\n/**\n * Generate a CSS source map that maps generated CSS classes back to original source locations\n */\nexport function generateCssSourceMap(\n cssContent: string,\n sourcemapData: CssSourceMapData,\n originalFilepath: string,\n originalSource: string,\n generatedFilepath?: string,\n): SourceMap {\n const segments: SourceMapSegment[] = [];\n\n // For each CSS class, find its position in the generated CSS and map it back\n for (const entry of sourcemapData) {\n const selector = `.${entry.className}`;\n const position = findSelectorInCss(cssContent, selector);\n\n if (position) {\n // Calculate line and column from byte offset in original source\n const originalPos = getLineAndColumn(originalSource, entry.start);\n\n segments.push({\n generatedLine: position.line,\n generatedColumn: position.column,\n originalLine: originalPos.line,\n originalColumn: originalPos.column,\n source: originalFilepath,\n });\n }\n }\n\n // Convert segments to VLQ mappings\n const mappings = segmentsToVLQ(segments);\n\n return {\n version: 3,\n file: generatedFilepath,\n sources: [originalFilepath],\n sourcesContent: [originalSource],\n names: [],\n mappings,\n };\n}\n\nfunction findSelectorInCss(\n css: string,\n selector: string,\n): { line: number; column: number } | null {\n const index = css.indexOf(selector);\n if (index === -1) return null;\n\n const beforeSelector = css.substring(0, index);\n const line = (beforeSelector.match(/\\n/g) || []).length;\n const lastNewline = beforeSelector.lastIndexOf(\"\\n\");\n const column = index - lastNewline - 1;\n\n return { line, column };\n}\n\nfunction getLineAndColumn(\n source: string,\n offset: number,\n): { line: number; column: number } {\n const beforeOffset = source.substring(0, offset);\n const line = (beforeOffset.match(/\\n/g) || []).length;\n const lastNewline = beforeOffset.lastIndexOf(\"\\n\");\n const column = offset - lastNewline - 1;\n\n return { line, column: Math.max(0, column) };\n}\n\n/**\n * Convert segments to VLQ-encoded mappings string\n * This is a simplified implementation - for production, consider using a library\n */\nfunction segmentsToVLQ(segments: SourceMapSegment[]): string {\n if (segments.length === 0) return \"\";\n\n // Sort segments by generated position\n segments.sort((a, b) => {\n if (a.generatedLine !== b.generatedLine) {\n return a.generatedLine - b.generatedLine;\n }\n return a.generatedColumn - b.generatedColumn;\n });\n\n const lines: string[] = [];\n let currentLine = 0;\n let previousGeneratedColumn = 0;\n let previousOriginalLine = 0;\n let previousOriginalColumn = 0;\n let previousSourceIndex = 0;\n\n for (const segment of segments) {\n // Add empty line segments for skipped lines\n while (currentLine < segment.generatedLine) {\n lines.push(\"\");\n currentLine++;\n previousGeneratedColumn = 0;\n }\n\n // Encode this segment\n const values = [\n segment.generatedColumn - previousGeneratedColumn,\n 0 - previousSourceIndex, // source index (always 0 for us)\n segment.originalLine - previousOriginalLine,\n segment.originalColumn - previousOriginalColumn,\n ];\n\n lines[currentLine] =\n (lines[currentLine] ? lines[currentLine] + \",\" : \"\") +\n values.map(encodeVLQ).join(\"\");\n\n previousGeneratedColumn = segment.generatedColumn;\n previousOriginalLine = segment.originalLine;\n previousOriginalColumn = segment.originalColumn;\n previousSourceIndex = 0;\n }\n\n return lines.join(\";\");\n}\n\n/**\n * Encode a value as VLQ (Variable Length Quantity)\n */\nfunction encodeVLQ(value: number): string {\n const VLQ_BASE_SHIFT = 5;\n const VLQ_BASE = 1 << VLQ_BASE_SHIFT;\n const VLQ_BASE_MASK = VLQ_BASE - 1;\n const VLQ_CONTINUATION_BIT = VLQ_BASE;\n\n const BASE64_CHARS =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n // Convert to sign-magnitude representation\n let encoded = value < 0 ? ((-value) << 1) | 1 : value << 1;\n\n let result = \"\";\n do {\n let digit = encoded & VLQ_BASE_MASK;\n encoded >>>= VLQ_BASE_SHIFT;\n\n if (encoded > 0) {\n digit |= VLQ_CONTINUATION_BIT;\n }\n\n result += BASE64_CHARS[digit];\n } while (encoded > 0);\n\n return result;\n}\n"],"mappings":";;;;AAsBA,SAAgB,qBACd,YACA,eACA,kBACA,gBACA,mBACW;CACX,MAAMA,WAA+B,EAAE;AAGvC,MAAK,MAAM,SAAS,eAAe;EAEjC,MAAM,WAAW,kBAAkB,YADlB,IAAI,MAAM,YAC6B;AAExD,MAAI,UAAU;GAEZ,MAAM,cAAc,iBAAiB,gBAAgB,MAAM,MAAM;AAEjE,YAAS,KAAK;IACZ,eAAe,SAAS;IACxB,iBAAiB,SAAS;IAC1B,cAAc,YAAY;IAC1B,gBAAgB,YAAY;IAC5B,QAAQ;IACT,CAAC;;;CAKN,MAAM,WAAW,cAAc,SAAS;AAExC,QAAO;EACL,SAAS;EACT,MAAM;EACN,SAAS,CAAC,iBAAiB;EAC3B,gBAAgB,CAAC,eAAe;EAChC,OAAO,EAAE;EACT;EACD;;AAGH,SAAS,kBACP,KACA,UACyC;CACzC,MAAM,QAAQ,IAAI,QAAQ,SAAS;AACnC,KAAI,UAAU,GAAI,QAAO;CAEzB,MAAM,iBAAiB,IAAI,UAAU,GAAG,MAAM;AAK9C,QAAO;EAAE,OAJK,eAAe,MAAM,MAAM,IAAI,EAAE,EAAE;EAIlC,QAFA,QADK,eAAe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AAS;AACb,IAAG;EACD,IAAI,QAAQ,UAAU;AACtB,eAAa;AAEb,MAAI,UAAU,EACZ,UAAS;AAGX,YAAU,aAAa;UAChB,UAAU;AAEnB,QAAO"}
package/dist/index.d.mts CHANGED
@@ -7,6 +7,16 @@ type CSS = string & {
7
7
  };
8
8
  declare const css: (..._raw: any) => CSS;
9
9
  declare const style: (s: TemplateStringsArray, ...expr: Array<string | number | CSSProperties>) => string;
10
+ declare const extraClass: (..._classes: string[]) => string;
11
+ type ClassValue = string | false | null | undefined;
12
+ /** Joins class lists, ignoring falsy values. */
13
+ declare const joinStyles: (...classes: Array<ClassValue>) => string;
14
+ /**
15
+ * Joins class lists, de-duping atomic classes of the same property (e.g. `m-xxxxx`), the last one wins.
16
+ * Other classes are only de-duped if identical. Falsy values are ignored.
17
+ * In non-atomic mode the transform replaces this with `joinStyles`.
18
+ */
19
+ declare const mergeStyles: (...classes: Array<ClassValue>) => string;
10
20
  //#endregion
11
- export { CSSProperties, css, style };
21
+ export { CSSProperties, css, extraClass, joinStyles, mergeStyles, style };
12
22
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";KAAY,aAAA;EAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,MAAa,GAAA,MACU,GAAA,aAAa;AAC9C,CAAA;AAMF,KAJK,GAAA,GAQJ,MAAA,GAAA;EAEY,GAAA,EAAA,MAUZ;CATI;AAC8B,cARtB,GAQsB,EAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GARA,GAQA;AAAxB,cAFE,KAEF,EAAA,CAAA,CAAA,EADN,oBACM,EAAA,GAAA,IAAA,EAAA,KAAA,CAAA,MAAA,GAAA,MAAA,GAAwB,aAAxB,CAAA,EAAA,GAAA,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";KAEY,aAAA;EAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,MAAa,GAAA,MACU,GAAA,aAAa;AAC9C,CAAA;AAMF,KAJK,GAAA,GAQJ,MAAA,GAAA;EAEY,GAAA,EAAA,MAUZ;CATI;AAC8B,cARtB,GAQsB,EAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GARA,GAQA;AAAxB,cAFE,KAEF,EAAA,CAAA,CAAA,EADN,oBACM,EAAA,GAAA,IAAA,EAAA,KAAA,CAAA,MAAA,GAAA,MAAA,GAAwB,aAAxB,CAAA,EAAA,GAAA,MAAA;AAAK,cAUH,UAVG,EAAA,CAAA,GAAA,QAAA,EAAA,MAAA,EAAA,EAAA,GAAA,MAAA;AAUhB,KAkBK,UAAA,GAdJ,MAAA,GAAA,KAAA,GAAA,IAAA,GAAA,SAAA;AAAC;AAiBW,cAAA,UAAgC,EAAA,CAAA,GAAA,OAAN,EAAA,KAAK,CAAC,UAAD,CAAA,EAAA,GAAA,MAAA;AAQ5C;;;;;cAAa,0BAA2B,MAAM"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,174 @@
1
+ //#region src/atomicPrefixes.json
2
+ var atomicPrefixes_default = {
3
+ margin: "m",
4
+ "margin-top": "mt",
5
+ "margin-right": "mr",
6
+ "margin-bottom": "mb",
7
+ "margin-left": "ml",
8
+ "margin-inline": "mx",
9
+ "margin-block": "my",
10
+ "margin-inline-start": "ms",
11
+ "margin-inline-end": "me",
12
+ "margin-block-start": "mbs",
13
+ "margin-block-end": "mbe",
14
+ padding: "p",
15
+ "padding-top": "pt",
16
+ "padding-right": "pr",
17
+ "padding-bottom": "pb",
18
+ "padding-left": "pl",
19
+ "padding-inline": "px",
20
+ "padding-block": "py",
21
+ "padding-inline-start": "ps",
22
+ "padding-inline-end": "pe",
23
+ "padding-block-start": "pbs",
24
+ "padding-block-end": "pbe",
25
+ width: "w",
26
+ "min-width": "min-w",
27
+ "max-width": "max-w",
28
+ height: "h",
29
+ "min-height": "min-h",
30
+ "max-height": "max-h",
31
+ "aspect-ratio": "aspect",
32
+ "box-sizing": "box",
33
+ display: "d",
34
+ position: "pos",
35
+ inset: "inset",
36
+ "inset-inline": "inset-x",
37
+ "inset-block": "inset-y",
38
+ top: "top",
39
+ right: "right",
40
+ bottom: "bottom",
41
+ left: "left",
42
+ "z-index": "z",
43
+ float: "float",
44
+ clear: "clear",
45
+ isolation: "isolate",
46
+ overflow: "overflow",
47
+ "overflow-x": "overflow-x",
48
+ "overflow-y": "overflow-y",
49
+ visibility: "visibility",
50
+ opacity: "opacity",
51
+ flex: "flex",
52
+ "flex-direction": "flex-d",
53
+ "flex-wrap": "flex-w",
54
+ "flex-flow": "flex-f",
55
+ "flex-grow": "grow",
56
+ "flex-shrink": "shrink",
57
+ "flex-basis": "basis",
58
+ order: "order",
59
+ gap: "gap",
60
+ "row-gap": "gap-y",
61
+ "column-gap": "gap-x",
62
+ "align-items": "items",
63
+ "align-content": "content",
64
+ "align-self": "self",
65
+ "justify-content": "justify",
66
+ "justify-items": "justify-items",
67
+ "justify-self": "justify-self",
68
+ "place-items": "place-items",
69
+ "place-content": "place-content",
70
+ "place-self": "place-self",
71
+ grid: "grid",
72
+ "grid-template": "grid-t",
73
+ "grid-template-columns": "grid-cols",
74
+ "grid-template-rows": "grid-rows",
75
+ "grid-template-areas": "grid-areas",
76
+ "grid-auto-flow": "grid-flow",
77
+ "grid-auto-columns": "auto-cols",
78
+ "grid-auto-rows": "auto-rows",
79
+ "grid-area": "area",
80
+ "grid-column": "col",
81
+ "grid-column-start": "col-start",
82
+ "grid-column-end": "col-end",
83
+ "grid-row": "row",
84
+ "grid-row-start": "row-start",
85
+ "grid-row-end": "row-end",
86
+ columns: "columns",
87
+ color: "c",
88
+ font: "f",
89
+ "font-family": "ff",
90
+ "font-size": "fs",
91
+ "font-weight": "fw",
92
+ "font-style": "fst",
93
+ "font-variant": "fv",
94
+ "line-height": "lh",
95
+ "letter-spacing": "ls",
96
+ "word-spacing": "wsp",
97
+ "text-align": "ta",
98
+ "text-decoration": "td",
99
+ "text-transform": "tt",
100
+ "text-overflow": "to",
101
+ "text-indent": "ti",
102
+ "text-shadow": "tsh",
103
+ "white-space": "ws",
104
+ "word-break": "wb",
105
+ "overflow-wrap": "ow",
106
+ "vertical-align": "va",
107
+ "list-style": "list",
108
+ "list-style-type": "list-t",
109
+ content: "cnt",
110
+ background: "bg",
111
+ "background-color": "bgc",
112
+ "background-image": "bgi",
113
+ "background-size": "bgs",
114
+ "background-position": "bgp",
115
+ "background-repeat": "bgr",
116
+ "background-clip": "bgcl",
117
+ "background-attachment": "bga",
118
+ "background-origin": "bgo",
119
+ "background-blend-mode": "bgbm",
120
+ border: "b",
121
+ "border-top": "bt",
122
+ "border-right": "br",
123
+ "border-bottom": "bb",
124
+ "border-left": "bl",
125
+ "border-inline": "bx",
126
+ "border-block": "by",
127
+ "border-width": "bw",
128
+ "border-style": "bs",
129
+ "border-color": "bc",
130
+ "border-radius": "r",
131
+ "border-top-left-radius": "rtl",
132
+ "border-top-right-radius": "rtr",
133
+ "border-bottom-right-radius": "rbr",
134
+ "border-bottom-left-radius": "rbl",
135
+ "border-collapse": "b-collapse",
136
+ "border-spacing": "b-spacing",
137
+ outline: "ol",
138
+ "outline-width": "olw",
139
+ "outline-style": "ols",
140
+ "outline-color": "olc",
141
+ "outline-offset": "olo",
142
+ "box-shadow": "shadow",
143
+ filter: "filter",
144
+ "backdrop-filter": "backdrop",
145
+ "mix-blend-mode": "blend",
146
+ "object-fit": "object",
147
+ "object-position": "object-p",
148
+ transform: "transform",
149
+ "transform-origin": "origin",
150
+ transition: "transition",
151
+ "transition-property": "transition-p",
152
+ "transition-duration": "duration",
153
+ "transition-timing-function": "ease",
154
+ "transition-delay": "delay",
155
+ animation: "animate",
156
+ "will-change": "will",
157
+ cursor: "cursor",
158
+ "pointer-events": "ptr",
159
+ "user-select": "select",
160
+ resize: "resize",
161
+ appearance: "appearance",
162
+ "scroll-behavior": "scroll",
163
+ "caret-color": "caret",
164
+ "accent-color": "accent",
165
+ "table-layout": "table",
166
+ fill: "fill",
167
+ stroke: "stroke",
168
+ "stroke-width": "stroke-w"
169
+ };
170
+
171
+ //#endregion
1
172
  //#region src/index.ts
2
173
  const css = (..._raw) => {
3
174
  throw new Error("@style-this: called 'css' at runtime. This indicates an error in the transform.");
@@ -10,7 +181,39 @@ const style = (s, ...expr) => {
10
181
  }
11
182
  return res;
12
183
  };
184
+ const extraClass = (..._classes) => {
185
+ throw new Error("@style-this: called 'extraClass' at runtime. This indicates an error in the transform.");
186
+ };
187
+ const ATOMIC_PREFIXES = new Set(Object.values(atomicPrefixes_default));
188
+ const ATOMIC_HASH_LENGTH = 5;
189
+ const getAtomicPrefix = (className) => {
190
+ const separatorIdx = className.length - ATOMIC_HASH_LENGTH - 1;
191
+ if (separatorIdx < 1 || className[separatorIdx] !== "-") return;
192
+ if (!/[a-zA-Z]/.test(className[separatorIdx + 1])) return;
193
+ const prefix = className.slice(0, separatorIdx);
194
+ return ATOMIC_PREFIXES.has(prefix) ? prefix : void 0;
195
+ };
196
+ /** Joins class lists, ignoring falsy values. */
197
+ const joinStyles = (...classes) => classes.filter(Boolean).join(" ");
198
+ /**
199
+ * Joins class lists, de-duping atomic classes of the same property (e.g. `m-xxxxx`), the last one wins.
200
+ * Other classes are only de-duped if identical. Falsy values are ignored.
201
+ * In non-atomic mode the transform replaces this with `joinStyles`.
202
+ */
203
+ const mergeStyles = (...classes) => {
204
+ const merged = /* @__PURE__ */ new Map();
205
+ for (const classList of classes) {
206
+ if (!classList) continue;
207
+ for (const className of classList.split(/\s+/)) {
208
+ if (!className) continue;
209
+ const key = getAtomicPrefix(className) ?? className;
210
+ merged.delete(key);
211
+ merged.set(key, className);
212
+ }
213
+ }
214
+ return [...merged.values()].join(" ");
215
+ };
13
216
 
14
217
  //#endregion
15
- export { css, style };
218
+ export { css, extraClass, joinStyles, mergeStyles, style };
16
219
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type CSSProperties = {\n [key: string]: string | number | CSSProperties;\n};\n\ntype CSS = string & {\n css: string;\n};\n\nexport const css = (..._raw: any): CSS => {\n throw new Error(\n \"@style-this: called 'css' at runtime. This indicates an error in the transform.\",\n );\n};\n\nexport const style = (\n s: TemplateStringsArray,\n ...expr: Array<string | number | CSSProperties>\n): string => {\n let res = \"\";\n for (let i = 0; i < Math.max(s.length, expr.length); ++i) {\n res += s[i] ?? \"\";\n res += expr[i] ?? \"\";\n }\n return res;\n};\n"],"mappings":";AAQA,MAAa,OAAO,GAAG,SAAmB;AACxC,OAAM,IAAI,MACR,kFACD;;AAGH,MAAa,SACX,GACA,GAAG,SACQ;CACX,IAAI,MAAM;AACV,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,QAAQ,KAAK,OAAO,EAAE,EAAE,GAAG;AACxD,SAAO,EAAE,MAAM;AACf,SAAO,KAAK,MAAM;;AAEpB,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":["atomicPrefixes"],"sources":["../src/atomicPrefixes.json","../src/index.ts"],"sourcesContent":["{\n \"margin\": \"m\",\n \"margin-top\": \"mt\",\n \"margin-right\": \"mr\",\n \"margin-bottom\": \"mb\",\n \"margin-left\": \"ml\",\n \"margin-inline\": \"mx\",\n \"margin-block\": \"my\",\n \"margin-inline-start\": \"ms\",\n \"margin-inline-end\": \"me\",\n \"margin-block-start\": \"mbs\",\n \"margin-block-end\": \"mbe\",\n \"padding\": \"p\",\n \"padding-top\": \"pt\",\n \"padding-right\": \"pr\",\n \"padding-bottom\": \"pb\",\n \"padding-left\": \"pl\",\n \"padding-inline\": \"px\",\n \"padding-block\": \"py\",\n \"padding-inline-start\": \"ps\",\n \"padding-inline-end\": \"pe\",\n \"padding-block-start\": \"pbs\",\n \"padding-block-end\": \"pbe\",\n \"width\": \"w\",\n \"min-width\": \"min-w\",\n \"max-width\": \"max-w\",\n \"height\": \"h\",\n \"min-height\": \"min-h\",\n \"max-height\": \"max-h\",\n \"aspect-ratio\": \"aspect\",\n \"box-sizing\": \"box\",\n \"display\": \"d\",\n \"position\": \"pos\",\n \"inset\": \"inset\",\n \"inset-inline\": \"inset-x\",\n \"inset-block\": \"inset-y\",\n \"top\": \"top\",\n \"right\": \"right\",\n \"bottom\": \"bottom\",\n \"left\": \"left\",\n \"z-index\": \"z\",\n \"float\": \"float\",\n \"clear\": \"clear\",\n \"isolation\": \"isolate\",\n \"overflow\": \"overflow\",\n \"overflow-x\": \"overflow-x\",\n \"overflow-y\": \"overflow-y\",\n \"visibility\": \"visibility\",\n \"opacity\": \"opacity\",\n \"flex\": \"flex\",\n \"flex-direction\": \"flex-d\",\n \"flex-wrap\": \"flex-w\",\n \"flex-flow\": \"flex-f\",\n \"flex-grow\": \"grow\",\n \"flex-shrink\": \"shrink\",\n \"flex-basis\": \"basis\",\n \"order\": \"order\",\n \"gap\": \"gap\",\n \"row-gap\": \"gap-y\",\n \"column-gap\": \"gap-x\",\n \"align-items\": \"items\",\n \"align-content\": \"content\",\n \"align-self\": \"self\",\n \"justify-content\": \"justify\",\n \"justify-items\": \"justify-items\",\n \"justify-self\": \"justify-self\",\n \"place-items\": \"place-items\",\n \"place-content\": \"place-content\",\n \"place-self\": \"place-self\",\n \"grid\": \"grid\",\n \"grid-template\": \"grid-t\",\n \"grid-template-columns\": \"grid-cols\",\n \"grid-template-rows\": \"grid-rows\",\n \"grid-template-areas\": \"grid-areas\",\n \"grid-auto-flow\": \"grid-flow\",\n \"grid-auto-columns\": \"auto-cols\",\n \"grid-auto-rows\": \"auto-rows\",\n \"grid-area\": \"area\",\n \"grid-column\": \"col\",\n \"grid-column-start\": \"col-start\",\n \"grid-column-end\": \"col-end\",\n \"grid-row\": \"row\",\n \"grid-row-start\": \"row-start\",\n \"grid-row-end\": \"row-end\",\n \"columns\": \"columns\",\n \"color\": \"c\",\n \"font\": \"f\",\n \"font-family\": \"ff\",\n \"font-size\": \"fs\",\n \"font-weight\": \"fw\",\n \"font-style\": \"fst\",\n \"font-variant\": \"fv\",\n \"line-height\": \"lh\",\n \"letter-spacing\": \"ls\",\n \"word-spacing\": \"wsp\",\n \"text-align\": \"ta\",\n \"text-decoration\": \"td\",\n \"text-transform\": \"tt\",\n \"text-overflow\": \"to\",\n \"text-indent\": \"ti\",\n \"text-shadow\": \"tsh\",\n \"white-space\": \"ws\",\n \"word-break\": \"wb\",\n \"overflow-wrap\": \"ow\",\n \"vertical-align\": \"va\",\n \"list-style\": \"list\",\n \"list-style-type\": \"list-t\",\n \"content\": \"cnt\",\n \"background\": \"bg\",\n \"background-color\": \"bgc\",\n \"background-image\": \"bgi\",\n \"background-size\": \"bgs\",\n \"background-position\": \"bgp\",\n \"background-repeat\": \"bgr\",\n \"background-clip\": \"bgcl\",\n \"background-attachment\": \"bga\",\n \"background-origin\": \"bgo\",\n \"background-blend-mode\": \"bgbm\",\n \"border\": \"b\",\n \"border-top\": \"bt\",\n \"border-right\": \"br\",\n \"border-bottom\": \"bb\",\n \"border-left\": \"bl\",\n \"border-inline\": \"bx\",\n \"border-block\": \"by\",\n \"border-width\": \"bw\",\n \"border-style\": \"bs\",\n \"border-color\": \"bc\",\n \"border-radius\": \"r\",\n \"border-top-left-radius\": \"rtl\",\n \"border-top-right-radius\": \"rtr\",\n \"border-bottom-right-radius\": \"rbr\",\n \"border-bottom-left-radius\": \"rbl\",\n \"border-collapse\": \"b-collapse\",\n \"border-spacing\": \"b-spacing\",\n \"outline\": \"ol\",\n \"outline-width\": \"olw\",\n \"outline-style\": \"ols\",\n \"outline-color\": \"olc\",\n \"outline-offset\": \"olo\",\n \"box-shadow\": \"shadow\",\n \"filter\": \"filter\",\n \"backdrop-filter\": \"backdrop\",\n \"mix-blend-mode\": \"blend\",\n \"object-fit\": \"object\",\n \"object-position\": \"object-p\",\n \"transform\": \"transform\",\n \"transform-origin\": \"origin\",\n \"transition\": \"transition\",\n \"transition-property\": \"transition-p\",\n \"transition-duration\": \"duration\",\n \"transition-timing-function\": \"ease\",\n \"transition-delay\": \"delay\",\n \"animation\": \"animate\",\n \"will-change\": \"will\",\n \"cursor\": \"cursor\",\n \"pointer-events\": \"ptr\",\n \"user-select\": \"select\",\n \"resize\": \"resize\",\n \"appearance\": \"appearance\",\n \"scroll-behavior\": \"scroll\",\n \"caret-color\": \"caret\",\n \"accent-color\": \"accent\",\n \"table-layout\": \"table\",\n \"fill\": \"fill\",\n \"stroke\": \"stroke\",\n \"stroke-width\": \"stroke-w\"\n}\n","import atomicPrefixes from \"./atomicPrefixes.json\";\n\nexport type CSSProperties = {\n [key: string]: string | number | CSSProperties;\n};\n\ntype CSS = string & {\n css: string;\n};\n\nexport const css = (..._raw: any): CSS => {\n throw new Error(\n \"@style-this: called 'css' at runtime. This indicates an error in the transform.\",\n );\n};\n\nexport const style = (\n s: TemplateStringsArray,\n ...expr: Array<string | number | CSSProperties>\n): string => {\n let res = \"\";\n for (let i = 0; i < Math.max(s.length, expr.length); ++i) {\n res += s[i] ?? \"\";\n res += expr[i] ?? \"\";\n }\n return res;\n};\n\nexport const extraClass = (..._classes: string[]): string => {\n throw new Error(\n \"@style-this: called 'extraClass' at runtime. This indicates an error in the transform.\",\n );\n};\n\nconst ATOMIC_PREFIXES = new Set<string>(Object.values(atomicPrefixes));\nconst ATOMIC_HASH_LENGTH = 5;\n\n// atomic classes are `<prefix>-<5 char hash>`, where the hash starts with a letter\nconst getAtomicPrefix = (className: string): string | undefined => {\n const separatorIdx = className.length - ATOMIC_HASH_LENGTH - 1;\n if (separatorIdx < 1 || className[separatorIdx] !== \"-\") return;\n if (!/[a-zA-Z]/.test(className[separatorIdx + 1])) return;\n const prefix = className.slice(0, separatorIdx);\n return ATOMIC_PREFIXES.has(prefix) ? prefix : undefined;\n};\n\ntype ClassValue = string | false | null | undefined;\n\n/** Joins class lists, ignoring falsy values. */\nexport const joinStyles = (...classes: Array<ClassValue>): string =>\n classes.filter(Boolean).join(\" \");\n\n/**\n * Joins class lists, de-duping atomic classes of the same property (e.g. `m-xxxxx`), the last one wins.\n * Other classes are only de-duped if identical. Falsy values are ignored.\n * In non-atomic mode the transform replaces this with `joinStyles`.\n */\nexport const mergeStyles = (...classes: Array<ClassValue>): string => {\n const merged = new Map<string, string>();\n for (const classList of classes) {\n if (!classList) continue;\n for (const className of classList.split(/\\s+/)) {\n if (!className) continue;\n const key = getAtomicPrefix(className) ?? className;\n merged.delete(key);\n merged.set(key, className);\n }\n }\n return [...merged.values()].join(\" \");\n};\n"],"mappings":";6BAAA;SACY;CACV,cAAc;CACd,gBAAgB;CAChB,iBAAiB;CACjB,eAAe;CACf,iBAAiB;CACjB,gBAAgB;CAChB,uBAAuB;CACvB,qBAAqB;CACrB,sBAAsB;CACtB,oBAAoB;UACT;CACX,eAAe;CACf,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,kBAAkB;CAClB,iBAAiB;CACjB,wBAAwB;CACxB,sBAAsB;CACtB,uBAAuB;CACvB,qBAAqB;QACZ;CACT,aAAa;CACb,aAAa;SACH;CACV,cAAc;CACd,cAAc;CACd,gBAAgB;CAChB,cAAc;UACH;WACC;QACH;CACT,gBAAgB;CAChB,eAAe;MACR;QACE;SACC;OACF;CACR,WAAW;QACF;QACA;YACI;WACD;CACZ,cAAc;CACd,cAAc;aACA;UACH;OACH;CACR,kBAAkB;CAClB,aAAa;CACb,aAAa;CACb,aAAa;CACb,eAAe;CACf,cAAc;QACL;MACF;CACP,WAAW;CACX,cAAc;CACd,eAAe;CACf,iBAAiB;CACjB,cAAc;CACd,mBAAmB;CACnB,iBAAiB;CACjB,gBAAgB;CAChB,eAAe;CACf,iBAAiB;CACjB,cAAc;OACN;CACR,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,uBAAuB;CACvB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,aAAa;CACb,eAAe;CACf,qBAAqB;CACrB,mBAAmB;CACnB,YAAY;CACZ,kBAAkB;CAClB,gBAAgB;UACL;QACF;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pB,QAAO;;AAGT,MAAa,cAAc,GAAG,aAA+B;AAC3D,OAAM,IAAI,MACR,yFACD;;AAGH,MAAM,kBAAkB,IAAI,IAAY,OAAO,OAAOA,uBAAe,CAAC;AACtE,MAAM,qBAAqB;AAG3B,MAAM,mBAAmB,cAA0C;CACjE,MAAM,eAAe,UAAU,SAAS,qBAAqB;AAC7D,KAAI,eAAe,KAAK,UAAU,kBAAkB,IAAK;AACzD,KAAI,CAAC,WAAW,KAAK,UAAU,eAAe,GAAG,CAAE;CACnD,MAAM,SAAS,UAAU,MAAM,GAAG,aAAa;AAC/C,QAAO,gBAAgB,IAAI,OAAO,GAAG,SAAS;;;AAMhD,MAAa,cAAc,GAAG,YAC5B,QAAQ,OAAO,QAAQ,CAAC,KAAK,IAAI;;;;;;AAOnC,MAAa,eAAe,GAAG,YAAuC;CACpE,MAAM,yBAAS,IAAI,KAAqB;AACxC,MAAK,MAAM,aAAa,SAAS;AAC/B,MAAI,CAAC,UAAW;AAChB,OAAK,MAAM,aAAa,UAAU,MAAM,MAAM,EAAE;AAC9C,OAAI,CAAC,UAAW;GAChB,MAAM,MAAM,gBAAgB,UAAU,IAAI;AAC1C,UAAO,OAAO,IAAI;AAClB,UAAO,IAAI,KAAK,UAAU;;;AAG9B,QAAO,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,KAAK,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@style-this/core",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "CSS-in-JS library for the modern web - core module",
5
5
  "type": "module",
6
6
  "files": [
@@ -10,13 +10,27 @@
10
10
  "module": "./dist/index.mjs",
11
11
  "types": "./dist/index.d.mts",
12
12
  "exports": {
13
- ".": "./dist/index.mjs",
13
+ ".": {
14
+ "types": "./dist/index.d.mts",
15
+ "import": "./dist/index.mjs",
16
+ "default": "./dist/index.mjs"
17
+ },
14
18
  "./compiler": {
15
19
  "require": "./dist/compiler.cjs",
16
20
  "types": "./dist/compiler.d.cts",
17
21
  "import": "./dist/compiler.cjs",
18
22
  "default": "./dist/compiler.cjs"
19
23
  },
24
+ "./cssSourceMap": {
25
+ "types": "./dist/cssSourceMap.d.mts",
26
+ "import": "./dist/cssSourceMap.mjs",
27
+ "default": "./dist/cssSourceMap.mjs"
28
+ },
29
+ "./atomic": {
30
+ "types": "./dist/atomic.d.mts",
31
+ "import": "./dist/atomic.mjs",
32
+ "default": "./dist/atomic.mjs"
33
+ },
20
34
  "./package.json": "./package.json"
21
35
  },
22
36
  "devDependencies": {