@cassida/compiler 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/config.schema.json +88 -0
- package/dist/canonicalizer.d.ts +42 -0
- package/dist/canonicalizer.d.ts.map +1 -0
- package/dist/canonicalizer.js +185 -0
- package/dist/canonicalizer.js.map +1 -0
- package/dist/compile.d.ts +46 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +84 -0
- package/dist/compile.js.map +1 -0
- package/dist/config.d.ts +182 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +150 -0
- package/dist/config.js.map +1 -0
- package/dist/emitter.d.ts +44 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +189 -0
- package/dist/emitter.js.map +1 -0
- package/dist/generated-property-specs.d.ts +3193 -0
- package/dist/generated-property-specs.d.ts.map +1 -0
- package/dist/generated-property-specs.js +472 -0
- package/dist/generated-property-specs.js.map +1 -0
- package/dist/hasher.d.ts +8 -0
- package/dist/hasher.d.ts.map +1 -0
- package/dist/hasher.js +10 -0
- package/dist/hasher.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/modifier-spec.d.ts +104 -0
- package/dist/modifier-spec.d.ts.map +1 -0
- package/dist/modifier-spec.js +52 -0
- package/dist/modifier-spec.js.map +1 -0
- package/dist/plugin.d.ts +66 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +65 -0
- package/dist/plugin.js.map +1 -0
- package/dist/property-spec.d.ts +321 -0
- package/dist/property-spec.d.ts.map +1 -0
- package/dist/property-spec.js +382 -0
- package/dist/property-spec.js.map +1 -0
- package/dist/registry.d.ts +71 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +123 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +6 -0
- package/dist/util.js.map +1 -0
- package/package.json +60 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Schema definitions live first so the user-facing `CassConfig` type
|
|
4
|
+
* can be derived from them via `z.infer`. Hand-writing the type and
|
|
5
|
+
* the validator separately is the kind of "type lies" we explicitly
|
|
6
|
+
* want to eliminate.
|
|
7
|
+
*/
|
|
8
|
+
declare const MediaSortSchema: z.ZodEnum<["mobile-first", "desktop-first"]>;
|
|
9
|
+
declare const CssModeSchema: z.ZodEnum<["rule-per-class", "shared-by-declaration"]>;
|
|
10
|
+
declare const ShorthandPolicySchema: z.ZodEnum<["strict", "shorthand-first", "lenient"]>;
|
|
11
|
+
/**
|
|
12
|
+
* Strict schema for `cassida.config.json` and inline plugin options.
|
|
13
|
+
* `.strict()` rejects unknown fields so config typos surface as
|
|
14
|
+
* build-time errors instead of silently ignored entries.
|
|
15
|
+
*/
|
|
16
|
+
export declare const CassConfigSchema: z.ZodObject<{
|
|
17
|
+
/** Editor convention; allowed but unused. */
|
|
18
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
19
|
+
layer: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
20
|
+
importSource: z.ZodOptional<z.ZodString>;
|
|
21
|
+
hash: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
23
|
+
length: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
}, "strict", z.ZodTypeAny, {
|
|
25
|
+
length?: number | undefined;
|
|
26
|
+
prefix?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
length?: number | undefined;
|
|
29
|
+
prefix?: string | undefined;
|
|
30
|
+
}>>;
|
|
31
|
+
media: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
sort: z.ZodOptional<z.ZodEnum<["mobile-first", "desktop-first"]>>;
|
|
33
|
+
}, "strict", z.ZodTypeAny, {
|
|
34
|
+
sort?: "mobile-first" | "desktop-first" | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
sort?: "mobile-first" | "desktop-first" | undefined;
|
|
37
|
+
}>>;
|
|
38
|
+
css: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
mode: z.ZodOptional<z.ZodEnum<["rule-per-class", "shared-by-declaration"]>>;
|
|
40
|
+
lightningcss: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
minify: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
targets: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, "strict", z.ZodTypeAny, {
|
|
45
|
+
enabled?: boolean | undefined;
|
|
46
|
+
minify?: boolean | undefined;
|
|
47
|
+
targets?: string | undefined;
|
|
48
|
+
}, {
|
|
49
|
+
enabled?: boolean | undefined;
|
|
50
|
+
minify?: boolean | undefined;
|
|
51
|
+
targets?: string | undefined;
|
|
52
|
+
}>>;
|
|
53
|
+
}, "strict", z.ZodTypeAny, {
|
|
54
|
+
mode?: "rule-per-class" | "shared-by-declaration" | undefined;
|
|
55
|
+
lightningcss?: {
|
|
56
|
+
enabled?: boolean | undefined;
|
|
57
|
+
minify?: boolean | undefined;
|
|
58
|
+
targets?: string | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
mode?: "rule-per-class" | "shared-by-declaration" | undefined;
|
|
62
|
+
lightningcss?: {
|
|
63
|
+
enabled?: boolean | undefined;
|
|
64
|
+
minify?: boolean | undefined;
|
|
65
|
+
targets?: string | undefined;
|
|
66
|
+
} | undefined;
|
|
67
|
+
}>>;
|
|
68
|
+
shorthand: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
policy: z.ZodOptional<z.ZodEnum<["strict", "shorthand-first", "lenient"]>>;
|
|
70
|
+
}, "strict", z.ZodTypeAny, {
|
|
71
|
+
policy?: "strict" | "shorthand-first" | "lenient" | undefined;
|
|
72
|
+
}, {
|
|
73
|
+
policy?: "strict" | "shorthand-first" | "lenient" | undefined;
|
|
74
|
+
}>>;
|
|
75
|
+
}, "strict", z.ZodTypeAny, {
|
|
76
|
+
media?: {
|
|
77
|
+
sort?: "mobile-first" | "desktop-first" | undefined;
|
|
78
|
+
} | undefined;
|
|
79
|
+
$schema?: string | undefined;
|
|
80
|
+
layer?: string | null | undefined;
|
|
81
|
+
importSource?: string | undefined;
|
|
82
|
+
hash?: {
|
|
83
|
+
length?: number | undefined;
|
|
84
|
+
prefix?: string | undefined;
|
|
85
|
+
} | undefined;
|
|
86
|
+
css?: {
|
|
87
|
+
mode?: "rule-per-class" | "shared-by-declaration" | undefined;
|
|
88
|
+
lightningcss?: {
|
|
89
|
+
enabled?: boolean | undefined;
|
|
90
|
+
minify?: boolean | undefined;
|
|
91
|
+
targets?: string | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
shorthand?: {
|
|
95
|
+
policy?: "strict" | "shorthand-first" | "lenient" | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}, {
|
|
98
|
+
media?: {
|
|
99
|
+
sort?: "mobile-first" | "desktop-first" | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
$schema?: string | undefined;
|
|
102
|
+
layer?: string | null | undefined;
|
|
103
|
+
importSource?: string | undefined;
|
|
104
|
+
hash?: {
|
|
105
|
+
length?: number | undefined;
|
|
106
|
+
prefix?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
css?: {
|
|
109
|
+
mode?: "rule-per-class" | "shared-by-declaration" | undefined;
|
|
110
|
+
lightningcss?: {
|
|
111
|
+
enabled?: boolean | undefined;
|
|
112
|
+
minify?: boolean | undefined;
|
|
113
|
+
targets?: string | undefined;
|
|
114
|
+
} | undefined;
|
|
115
|
+
} | undefined;
|
|
116
|
+
shorthand?: {
|
|
117
|
+
policy?: "strict" | "shorthand-first" | "lenient" | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
/** User-facing config: every field optional, derived from the schema. */
|
|
121
|
+
export type CassConfig = z.infer<typeof CassConfigSchema>;
|
|
122
|
+
export type MediaSort = z.infer<typeof MediaSortSchema>;
|
|
123
|
+
export type CssMode = z.infer<typeof CssModeSchema>;
|
|
124
|
+
export type ShorthandPolicy = z.infer<typeof ShorthandPolicySchema>;
|
|
125
|
+
/**
|
|
126
|
+
* Fully-populated config — the form consumed by the emitter, parser,
|
|
127
|
+
* and vite-plugin internals. Every field is required; partial
|
|
128
|
+
* `CassConfig` inputs are merged onto `defaultConfig` to produce one.
|
|
129
|
+
*/
|
|
130
|
+
export interface ResolvedCassConfig {
|
|
131
|
+
readonly layer: string | null;
|
|
132
|
+
readonly importSource: string;
|
|
133
|
+
readonly hash: {
|
|
134
|
+
readonly prefix: string;
|
|
135
|
+
readonly length: number;
|
|
136
|
+
};
|
|
137
|
+
readonly media: {
|
|
138
|
+
readonly sort: MediaSort;
|
|
139
|
+
};
|
|
140
|
+
readonly css: {
|
|
141
|
+
readonly mode: CssMode;
|
|
142
|
+
readonly lightningcss: {
|
|
143
|
+
readonly enabled: boolean;
|
|
144
|
+
readonly minify: boolean;
|
|
145
|
+
readonly targets: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
readonly shorthand: {
|
|
149
|
+
readonly policy: ShorthandPolicy;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export declare const defaultConfig: ResolvedCassConfig;
|
|
153
|
+
/**
|
|
154
|
+
* Deep-merge a sequence of partial configs over `defaultConfig`. Later
|
|
155
|
+
* layers win on field conflicts; `undefined` and missing fields are
|
|
156
|
+
* skipped (so a partial layer can leave earlier values intact).
|
|
157
|
+
*
|
|
158
|
+
* `layer: null` is preserved (it is an *explicit* "no @layer wrap"
|
|
159
|
+
* choice, distinct from "use the default layer name"). Only `undefined`
|
|
160
|
+
* is treated as "not set".
|
|
161
|
+
*/
|
|
162
|
+
export declare function mergeConfig(...layers: ReadonlyArray<CassConfig | undefined>): ResolvedCassConfig;
|
|
163
|
+
/**
|
|
164
|
+
* Validate raw input as a `CassConfig`. Use only at I/O boundaries
|
|
165
|
+
* (`cassida.config.json`, plugin options handed in from `vite.config.ts`);
|
|
166
|
+
* inside the compiler/parser/emitter, prefer `ResolvedCassConfig`.
|
|
167
|
+
*
|
|
168
|
+
* Errors surface as a single `Error` with a multi-line message that
|
|
169
|
+
* names every invalid field, suitable for Vite's overlay or terminal
|
|
170
|
+
* output. `sourcePath` (when supplied) is woven into the heading so
|
|
171
|
+
* monorepo users see which config produced the error.
|
|
172
|
+
*/
|
|
173
|
+
export declare function parseCassConfig(input: unknown, sourcePath?: string): CassConfig;
|
|
174
|
+
/**
|
|
175
|
+
* Schema for the values `path.evaluate()` is allowed to inline as
|
|
176
|
+
* concrete CSS. Confidently-evaluated objects, arrays, and functions
|
|
177
|
+
* fail validation and fall through to dynamic-CSS-variable handling
|
|
178
|
+
* (they can't be inlined into CSS anyway).
|
|
179
|
+
*/
|
|
180
|
+
export declare const EvaluatedPrimitiveSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AAEH,QAAA,MAAM,eAAe,8CAA4C,CAAC;AAClE,QAAA,MAAM,aAAa,wDAAsD,CAAC;AAC1E,QAAA,MAAM,qBAAqB,qDAAmD,CAAC;AAoC/E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;IAEzB,6CAA6C;;;;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AQG;AACH,wBAAgB,WAAW,CACzB,GAAG,MAAM,EAAE,aAAa,CAAC,UAAU,GAAG,SAAS,CAAC,GAC/C,kBAAkB,CA+BpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAQ/E;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,iEAKnC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Schema definitions live first so the user-facing `CassConfig` type
|
|
4
|
+
* can be derived from them via `z.infer`. Hand-writing the type and
|
|
5
|
+
* the validator separately is the kind of "type lies" we explicitly
|
|
6
|
+
* want to eliminate.
|
|
7
|
+
*/
|
|
8
|
+
const MediaSortSchema = z.enum(['mobile-first', 'desktop-first']);
|
|
9
|
+
const CssModeSchema = z.enum(['rule-per-class', 'shared-by-declaration']);
|
|
10
|
+
const ShorthandPolicySchema = z.enum(['strict', 'shorthand-first', 'lenient']);
|
|
11
|
+
const ShorthandSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
policy: ShorthandPolicySchema.optional(),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
const HashSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
prefix: z.string().optional(),
|
|
19
|
+
length: z.number().int().min(4).max(40).optional(),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const MediaSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
sort: MediaSortSchema.optional(),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
const LightningcssSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
enabled: z.boolean().optional(),
|
|
30
|
+
minify: z.boolean().optional(),
|
|
31
|
+
targets: z.string().optional(),
|
|
32
|
+
})
|
|
33
|
+
.strict();
|
|
34
|
+
const CssSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
mode: CssModeSchema.optional(),
|
|
37
|
+
lightningcss: LightningcssSchema.optional(),
|
|
38
|
+
})
|
|
39
|
+
.strict();
|
|
40
|
+
/**
|
|
41
|
+
* Strict schema for `cassida.config.json` and inline plugin options.
|
|
42
|
+
* `.strict()` rejects unknown fields so config typos surface as
|
|
43
|
+
* build-time errors instead of silently ignored entries.
|
|
44
|
+
*/
|
|
45
|
+
export const CassConfigSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
/** Editor convention; allowed but unused. */
|
|
48
|
+
$schema: z.string().optional(),
|
|
49
|
+
layer: z.union([z.string(), z.null()]).optional(),
|
|
50
|
+
importSource: z.string().optional(),
|
|
51
|
+
hash: HashSchema.optional(),
|
|
52
|
+
media: MediaSchema.optional(),
|
|
53
|
+
css: CssSchema.optional(),
|
|
54
|
+
shorthand: ShorthandSchema.optional(),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
export const defaultConfig = Object.freeze({
|
|
58
|
+
layer: 'cas',
|
|
59
|
+
importSource: '@cassida/core',
|
|
60
|
+
hash: Object.freeze({
|
|
61
|
+
prefix: 'cas-',
|
|
62
|
+
length: 8,
|
|
63
|
+
}),
|
|
64
|
+
media: Object.freeze({
|
|
65
|
+
sort: 'mobile-first',
|
|
66
|
+
}),
|
|
67
|
+
css: Object.freeze({
|
|
68
|
+
mode: 'rule-per-class',
|
|
69
|
+
lightningcss: Object.freeze({
|
|
70
|
+
enabled: false,
|
|
71
|
+
minify: true,
|
|
72
|
+
targets: 'defaults',
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
shorthand: Object.freeze({
|
|
76
|
+
policy: 'strict',
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Deep-merge a sequence of partial configs over `defaultConfig`. Later
|
|
81
|
+
* layers win on field conflicts; `undefined` and missing fields are
|
|
82
|
+
* skipped (so a partial layer can leave earlier values intact).
|
|
83
|
+
*
|
|
84
|
+
* `layer: null` is preserved (it is an *explicit* "no @layer wrap"
|
|
85
|
+
* choice, distinct from "use the default layer name"). Only `undefined`
|
|
86
|
+
* is treated as "not set".
|
|
87
|
+
*/
|
|
88
|
+
export function mergeConfig(...layers) {
|
|
89
|
+
let acc = defaultConfig;
|
|
90
|
+
for (const layer of layers) {
|
|
91
|
+
if (!layer)
|
|
92
|
+
continue;
|
|
93
|
+
acc = {
|
|
94
|
+
layer: layer.layer !== undefined ? layer.layer : acc.layer,
|
|
95
|
+
importSource: layer.importSource ?? acc.importSource,
|
|
96
|
+
hash: {
|
|
97
|
+
prefix: layer.hash?.prefix ?? acc.hash.prefix,
|
|
98
|
+
length: layer.hash?.length ?? acc.hash.length,
|
|
99
|
+
},
|
|
100
|
+
media: {
|
|
101
|
+
sort: layer.media?.sort ?? acc.media.sort,
|
|
102
|
+
},
|
|
103
|
+
css: {
|
|
104
|
+
mode: layer.css?.mode ?? acc.css.mode,
|
|
105
|
+
lightningcss: {
|
|
106
|
+
enabled: layer.css?.lightningcss?.enabled ?? acc.css.lightningcss.enabled,
|
|
107
|
+
minify: layer.css?.lightningcss?.minify ?? acc.css.lightningcss.minify,
|
|
108
|
+
targets: layer.css?.lightningcss?.targets ?? acc.css.lightningcss.targets,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
shorthand: {
|
|
112
|
+
policy: layer.shorthand?.policy ?? acc.shorthand.policy,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return acc;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Validate raw input as a `CassConfig`. Use only at I/O boundaries
|
|
120
|
+
* (`cassida.config.json`, plugin options handed in from `vite.config.ts`);
|
|
121
|
+
* inside the compiler/parser/emitter, prefer `ResolvedCassConfig`.
|
|
122
|
+
*
|
|
123
|
+
* Errors surface as a single `Error` with a multi-line message that
|
|
124
|
+
* names every invalid field, suitable for Vite's overlay or terminal
|
|
125
|
+
* output. `sourcePath` (when supplied) is woven into the heading so
|
|
126
|
+
* monorepo users see which config produced the error.
|
|
127
|
+
*/
|
|
128
|
+
export function parseCassConfig(input, sourcePath) {
|
|
129
|
+
const result = CassConfigSchema.safeParse(input);
|
|
130
|
+
if (result.success)
|
|
131
|
+
return result.data;
|
|
132
|
+
const issues = result.error.issues
|
|
133
|
+
.map((i) => ` - ${i.path.length === 0 ? '<root>' : i.path.join('.')}: ${i.message}`)
|
|
134
|
+
.join('\n');
|
|
135
|
+
const where = sourcePath ? ` in ${sourcePath}` : '';
|
|
136
|
+
throw new Error(`[cassida] invalid configuration${where}:\n${issues}`);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Schema for the values `path.evaluate()` is allowed to inline as
|
|
140
|
+
* concrete CSS. Confidently-evaluated objects, arrays, and functions
|
|
141
|
+
* fail validation and fall through to dynamic-CSS-variable handling
|
|
142
|
+
* (they can't be inlined into CSS anyway).
|
|
143
|
+
*/
|
|
144
|
+
export const EvaluatedPrimitiveSchema = z.union([
|
|
145
|
+
z.string(),
|
|
146
|
+
z.number(),
|
|
147
|
+
z.boolean(),
|
|
148
|
+
z.null(),
|
|
149
|
+
]);
|
|
150
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;AAClE,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,CAAC,CAAC;AAC1E,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC,CAAC;AAE/E,MAAM,eAAe,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AM;SAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;SACpF,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,MAAM,MAAM,EAAE,CAAC,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC;IAC9C,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,OAAO,EAAE;IACX,CAAC,CAAC,IAAI,EAAE;CACT,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { MediaSort } from './config.js';
|
|
2
|
+
import type { CompiledRule } from './types.js';
|
|
3
|
+
export interface CssEmitterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* `@layer` name for the wrapping cascade layer.
|
|
6
|
+
* - omitted / undefined → `'fss'`
|
|
7
|
+
* - explicit `null` → no `@layer` wrap (rules are emitted bare)
|
|
8
|
+
*/
|
|
9
|
+
readonly layer?: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Media-query ordering policy. See `MediaSort` for the cascade
|
|
12
|
+
* semantics each direction implies. Defaults to `'mobile-first'`.
|
|
13
|
+
*/
|
|
14
|
+
readonly mediaSort?: MediaSort;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stateful collector for compiled rules.
|
|
18
|
+
*
|
|
19
|
+
* Cross-call dedup: identical canonical bags produce the same className
|
|
20
|
+
* and the rule is stored once. A different canonical mapping to the
|
|
21
|
+
* same className surfaces as a hash collision error.
|
|
22
|
+
*
|
|
23
|
+
* Emission walks each stored `ScopeBag` tree, builds a nested CSS
|
|
24
|
+
* string with `&` for parent-relative selectors, then runs the whole
|
|
25
|
+
* thing through stylis to flatten — stylis natively handles nested
|
|
26
|
+
* `:hover` / `@media` and rule hoisting.
|
|
27
|
+
*
|
|
28
|
+
* `@property` rules accumulate alongside class rules (deduplicated by
|
|
29
|
+
* var name) and are emitted *outside* the `@layer` wrap, because
|
|
30
|
+
* `@property` is invalid inside a `@layer` block.
|
|
31
|
+
*/
|
|
32
|
+
export declare class CssEmitter {
|
|
33
|
+
private readonly rules;
|
|
34
|
+
private readonly seen;
|
|
35
|
+
private readonly properties;
|
|
36
|
+
private readonly options;
|
|
37
|
+
constructor(options?: CssEmitterOptions);
|
|
38
|
+
add(rule: CompiledRule): string;
|
|
39
|
+
emit(): string;
|
|
40
|
+
classNames(): readonly string[];
|
|
41
|
+
size(): number;
|
|
42
|
+
propertyCount(): number;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EACV,YAAY,EAKb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;gBAEhC,OAAO,GAAE,iBAAsB;IAI3C,GAAG,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM;IAqB/B,IAAI,IAAI,MAAM;IAwBd,UAAU,IAAI,SAAS,MAAM,EAAE;IAI/B,IAAI,IAAI,MAAM;IAId,aAAa,IAAI,MAAM;CAGxB"}
|
package/dist/emitter.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { compile, middleware, serialize, stringify } from 'stylis';
|
|
2
|
+
/**
|
|
3
|
+
* Stateful collector for compiled rules.
|
|
4
|
+
*
|
|
5
|
+
* Cross-call dedup: identical canonical bags produce the same className
|
|
6
|
+
* and the rule is stored once. A different canonical mapping to the
|
|
7
|
+
* same className surfaces as a hash collision error.
|
|
8
|
+
*
|
|
9
|
+
* Emission walks each stored `ScopeBag` tree, builds a nested CSS
|
|
10
|
+
* string with `&` for parent-relative selectors, then runs the whole
|
|
11
|
+
* thing through stylis to flatten — stylis natively handles nested
|
|
12
|
+
* `:hover` / `@media` and rule hoisting.
|
|
13
|
+
*
|
|
14
|
+
* `@property` rules accumulate alongside class rules (deduplicated by
|
|
15
|
+
* var name) and are emitted *outside* the `@layer` wrap, because
|
|
16
|
+
* `@property` is invalid inside a `@layer` block.
|
|
17
|
+
*/
|
|
18
|
+
export class CssEmitter {
|
|
19
|
+
rules = new Map();
|
|
20
|
+
seen = new Map();
|
|
21
|
+
properties = new Map();
|
|
22
|
+
options;
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
add(rule) {
|
|
27
|
+
const { className, canonical, tree, dynamics } = rule;
|
|
28
|
+
const previous = this.seen.get(className);
|
|
29
|
+
if (previous !== undefined && previous !== canonical) {
|
|
30
|
+
throw new Error(`[cassida] hash collision on "${className}":\n prev: ${previous}\n curr: ${canonical}`);
|
|
31
|
+
}
|
|
32
|
+
this.seen.set(className, canonical);
|
|
33
|
+
if (!this.rules.has(className)) {
|
|
34
|
+
this.rules.set(className, tree);
|
|
35
|
+
}
|
|
36
|
+
for (const slot of dynamics) {
|
|
37
|
+
const block = formatPropertyBlock(slot);
|
|
38
|
+
if (block !== null && !this.properties.has(slot.varName)) {
|
|
39
|
+
this.properties.set(slot.varName, block);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return className;
|
|
43
|
+
}
|
|
44
|
+
emit() {
|
|
45
|
+
if (this.rules.size === 0 && this.properties.size === 0)
|
|
46
|
+
return '';
|
|
47
|
+
const propertyBlocks = [...this.properties.values()].join('');
|
|
48
|
+
const sortMode = this.options.mediaSort ?? 'mobile-first';
|
|
49
|
+
const nestedRules = [];
|
|
50
|
+
for (const [className, tree] of this.rules.entries()) {
|
|
51
|
+
const nested = treeToNestedCss(className, tree, sortMode);
|
|
52
|
+
if (nested !== null)
|
|
53
|
+
nestedRules.push(nested);
|
|
54
|
+
}
|
|
55
|
+
if (nestedRules.length === 0)
|
|
56
|
+
return propertyBlocks;
|
|
57
|
+
const flat = serialize(compile(nestedRules.join('')), middleware([stringify]));
|
|
58
|
+
const layerBlock = this.options.layer === null
|
|
59
|
+
? flat
|
|
60
|
+
: `@layer ${this.options.layer ?? 'fss'}{${flat}}`;
|
|
61
|
+
return propertyBlocks + layerBlock;
|
|
62
|
+
}
|
|
63
|
+
classNames() {
|
|
64
|
+
return [...this.rules.keys()];
|
|
65
|
+
}
|
|
66
|
+
size() {
|
|
67
|
+
return this.rules.size;
|
|
68
|
+
}
|
|
69
|
+
propertyCount() {
|
|
70
|
+
return this.properties.size;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function treeToNestedCss(className, tree, sort) {
|
|
74
|
+
const decls = formatDeclarations(tree.bag);
|
|
75
|
+
const childRules = sortedChildren(tree.children, sort)
|
|
76
|
+
.map((c) => childToNestedCss(c, sort))
|
|
77
|
+
.filter((s) => s !== null);
|
|
78
|
+
if (decls === '' && childRules.length === 0)
|
|
79
|
+
return null;
|
|
80
|
+
const declsTerminated = decls === '' ? '' : decls + ';';
|
|
81
|
+
return `.${className}{${declsTerminated}${childRules.join('')}}`;
|
|
82
|
+
}
|
|
83
|
+
function childToNestedCss(node, sort) {
|
|
84
|
+
if (node.scope === null)
|
|
85
|
+
return null;
|
|
86
|
+
const decls = formatDeclarations(node.bag);
|
|
87
|
+
const grandchildren = sortedChildren(node.children, sort)
|
|
88
|
+
.map((c) => childToNestedCss(c, sort))
|
|
89
|
+
.filter((s) => s !== null);
|
|
90
|
+
if (decls === '' && grandchildren.length === 0)
|
|
91
|
+
return null;
|
|
92
|
+
const declsTerminated = decls === '' ? '' : decls + ';';
|
|
93
|
+
const inner = declsTerminated + grandchildren.join('');
|
|
94
|
+
if (node.scope.kind === 'pseudo' || node.scope.kind === 'raw') {
|
|
95
|
+
return `&${node.scope.selector}{${inner}}`;
|
|
96
|
+
}
|
|
97
|
+
return `@media ${node.scope.query}{${inner}}`;
|
|
98
|
+
}
|
|
99
|
+
function sortedChildren(children, sort) {
|
|
100
|
+
return [...children].sort((a, b) => compareScopes(a.scope, b.scope, sort));
|
|
101
|
+
}
|
|
102
|
+
const BUCKET_PSEUDO = 0;
|
|
103
|
+
const BUCKET_MEDIA_MIN_WIDTH = 1;
|
|
104
|
+
const BUCKET_MEDIA_MAX_WIDTH = 2;
|
|
105
|
+
const BUCKET_MEDIA_OTHER = 3;
|
|
106
|
+
const BUCKET_RAW = 4;
|
|
107
|
+
function scopeBucket(scope) {
|
|
108
|
+
if (scope.kind === 'pseudo')
|
|
109
|
+
return BUCKET_PSEUDO;
|
|
110
|
+
if (scope.kind === 'raw')
|
|
111
|
+
return BUCKET_RAW;
|
|
112
|
+
if (parseMinWidth(scope.query) !== null)
|
|
113
|
+
return BUCKET_MEDIA_MIN_WIDTH;
|
|
114
|
+
if (parseMaxWidth(scope.query) !== null)
|
|
115
|
+
return BUCKET_MEDIA_MAX_WIDTH;
|
|
116
|
+
return BUCKET_MEDIA_OTHER;
|
|
117
|
+
}
|
|
118
|
+
function compareScopes(a, b, sort) {
|
|
119
|
+
const ab = scopeBucket(a);
|
|
120
|
+
const bb = scopeBucket(b);
|
|
121
|
+
if (ab !== bb)
|
|
122
|
+
return ab - bb;
|
|
123
|
+
if (a.kind === 'pseudo' && b.kind === 'pseudo') {
|
|
124
|
+
return a.selector.localeCompare(b.selector);
|
|
125
|
+
}
|
|
126
|
+
if (a.kind === 'raw' && b.kind === 'raw') {
|
|
127
|
+
return a.selector.localeCompare(b.selector);
|
|
128
|
+
}
|
|
129
|
+
if (a.kind === 'media' && b.kind === 'media') {
|
|
130
|
+
if (ab === BUCKET_MEDIA_MIN_WIDTH) {
|
|
131
|
+
const an = parseMinWidth(a.query);
|
|
132
|
+
const bn = parseMinWidth(b.query);
|
|
133
|
+
return sort === 'mobile-first' ? an - bn : bn - an;
|
|
134
|
+
}
|
|
135
|
+
if (ab === BUCKET_MEDIA_MAX_WIDTH) {
|
|
136
|
+
const an = parseMaxWidth(a.query);
|
|
137
|
+
const bn = parseMaxWidth(b.query);
|
|
138
|
+
// mobile-first: larger max-width first (small overrides large via cascade)
|
|
139
|
+
return sort === 'mobile-first' ? bn - an : an - bn;
|
|
140
|
+
}
|
|
141
|
+
return a.query.localeCompare(b.query);
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Extracts the numeric value (in CSS px) for a `min-width` or `max-width`
|
|
147
|
+
* predicate. Supports `px`, `em`, `rem`. `em`/`rem` are normalized at
|
|
148
|
+
* 16 px so they sort sensibly relative to px values. Returns `null`
|
|
149
|
+
* when the predicate is absent or its value can't be parsed.
|
|
150
|
+
*/
|
|
151
|
+
function parseMinWidth(query) {
|
|
152
|
+
return parseWidth(query, /min-width:\s*([\d.]+)\s*(px|em|rem)?/i);
|
|
153
|
+
}
|
|
154
|
+
function parseMaxWidth(query) {
|
|
155
|
+
return parseWidth(query, /max-width:\s*([\d.]+)\s*(px|em|rem)?/i);
|
|
156
|
+
}
|
|
157
|
+
function parseWidth(query, re) {
|
|
158
|
+
const m = re.exec(query);
|
|
159
|
+
if (!m)
|
|
160
|
+
return null;
|
|
161
|
+
const v = parseFloat(m[1]);
|
|
162
|
+
if (!Number.isFinite(v))
|
|
163
|
+
return null;
|
|
164
|
+
const unit = m[2]?.toLowerCase() ?? 'px';
|
|
165
|
+
if (unit === 'em' || unit === 'rem')
|
|
166
|
+
return v * 16;
|
|
167
|
+
return v;
|
|
168
|
+
}
|
|
169
|
+
function formatDeclarations(bag) {
|
|
170
|
+
return Object.keys(bag)
|
|
171
|
+
.sort()
|
|
172
|
+
.map((k) => `${k}:${bag[k]}`)
|
|
173
|
+
.join(';');
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns the `@property` block string for a dynamic slot, or `null` if
|
|
177
|
+
* the slot is non-animatable, has no syntax descriptor, or has no
|
|
178
|
+
* initial-value (all three are required by the `@property` spec for
|
|
179
|
+
* the descriptor to be useful).
|
|
180
|
+
*/
|
|
181
|
+
function formatPropertyBlock(slot) {
|
|
182
|
+
if (!slot.animatable)
|
|
183
|
+
return null;
|
|
184
|
+
if (slot.syntax === undefined || slot.initialValue === undefined)
|
|
185
|
+
return null;
|
|
186
|
+
const inherits = 'false';
|
|
187
|
+
return `@property ${slot.varName}{syntax:"${slot.syntax}";inherits:${inherits};initial-value:${slot.initialValue};}`;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAwBnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAU;IACJ,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IACpC,IA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