@linaria/atomic 4.1.5 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/index.js +46 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/index.mjs +17 -0
  4. package/dist/index.mjs.map +1 -0
  5. package/dist/processors/css.js +372 -0
  6. package/dist/processors/css.js.map +1 -0
  7. package/dist/processors/css.mjs +344 -0
  8. package/dist/processors/css.mjs.map +1 -0
  9. package/dist/processors/styled.js +387 -0
  10. package/dist/processors/styled.js.map +1 -0
  11. package/dist/processors/styled.mjs +359 -0
  12. package/dist/processors/styled.mjs.map +1 -0
  13. package/package.json +33 -12
  14. package/processors/css.js +1 -1
  15. package/processors/styled.js +1 -1
  16. package/esm/CSSProperties.js +0 -2
  17. package/esm/CSSProperties.js.map +0 -1
  18. package/esm/css.js +0 -5
  19. package/esm/css.js.map +0 -1
  20. package/esm/index.js +0 -4
  21. package/esm/index.js.map +0 -1
  22. package/esm/processors/css.js +0 -39
  23. package/esm/processors/css.js.map +0 -1
  24. package/esm/processors/helpers/atomize.js +0 -100
  25. package/esm/processors/helpers/atomize.js.map +0 -1
  26. package/esm/processors/helpers/propertyPriority.js +0 -67
  27. package/esm/processors/helpers/propertyPriority.js.map +0 -1
  28. package/esm/processors/styled.js +0 -56
  29. package/esm/processors/styled.js.map +0 -1
  30. package/lib/CSSProperties.js +0 -2
  31. package/lib/CSSProperties.js.map +0 -1
  32. package/lib/css.js +0 -13
  33. package/lib/css.js.map +0 -1
  34. package/lib/index.js +0 -19
  35. package/lib/index.js.map +0 -1
  36. package/lib/processors/css.js +0 -55
  37. package/lib/processors/css.js.map +0 -1
  38. package/lib/processors/helpers/atomize.js +0 -116
  39. package/lib/processors/helpers/atomize.js.map +0 -1
  40. package/lib/processors/helpers/propertyPriority.js +0 -73
  41. package/lib/processors/helpers/propertyPriority.js.map +0 -1
  42. package/lib/processors/styled.js +0 -73
  43. package/lib/processors/styled.js.map +0 -1
@@ -0,0 +1,359 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+
20
+ // src/processors/styled.ts
21
+ import { debug } from "@linaria/logger";
22
+ import StyledProcessor from "@linaria/react/processors/styled";
23
+ import { hasMeta } from "@linaria/tags";
24
+
25
+ // src/processors/helpers/atomize.ts
26
+ import { all as knownProperties } from "known-css-properties";
27
+ import postcss from "postcss";
28
+ import stylis from "stylis";
29
+ import { slugify } from "@linaria/utils";
30
+
31
+ // src/processors/helpers/propertyPriority.ts
32
+ var shorthandProperties = {
33
+ animation: [
34
+ "animation-name",
35
+ "animation-duration",
36
+ "animation-timing-function",
37
+ "animation-delay",
38
+ "animation-iteration-count",
39
+ "animation-direction",
40
+ "animation-fill-mode",
41
+ "animation-play-state"
42
+ ],
43
+ background: [
44
+ "background-attachment",
45
+ "background-clip",
46
+ "background-color",
47
+ "background-image",
48
+ "background-origin",
49
+ "background-position",
50
+ "background-repeat",
51
+ "background-size"
52
+ ],
53
+ border: ["border-color", "border-style", "border-width"],
54
+ "border-block-end": [
55
+ "border-block-end-color",
56
+ "border-block-end-style",
57
+ "border-block-end-width"
58
+ ],
59
+ "border-block-start": [
60
+ "border-block-start-color",
61
+ "border-block-start-style",
62
+ "border-block-start-width"
63
+ ],
64
+ "border-bottom": [
65
+ "border-bottom-color",
66
+ "border-bottom-style",
67
+ "border-bottom-width"
68
+ ],
69
+ "border-color": [
70
+ "border-bottom-color",
71
+ "border-left-color",
72
+ "border-right-color",
73
+ "border-top-color"
74
+ ],
75
+ "border-image": [
76
+ "border-image-outset",
77
+ "border-image-repeat",
78
+ "border-image-slice",
79
+ "border-image-source",
80
+ "border-image-width"
81
+ ],
82
+ "border-inline-end": [
83
+ "border-inline-end-color",
84
+ "border-inline-end-style",
85
+ "border-inline-end-width"
86
+ ],
87
+ "border-inline-start": [
88
+ "border-inline-start-color",
89
+ "border-inline-start-style",
90
+ "border-inline-start-width"
91
+ ],
92
+ "border-left": [
93
+ "border-left-color",
94
+ "border-left-style",
95
+ "border-left-width"
96
+ ],
97
+ "border-radius": [
98
+ "border-top-left-radius",
99
+ "border-top-right-radius",
100
+ "border-bottom-right-radius",
101
+ "border-bottom-left-radius"
102
+ ],
103
+ "border-right": [
104
+ "border-right-color",
105
+ "border-right-style",
106
+ "border-right-width"
107
+ ],
108
+ "border-style": [
109
+ "border-bottom-style",
110
+ "border-left-style",
111
+ "border-right-style",
112
+ "border-top-style"
113
+ ],
114
+ "border-top": ["border-top-color", "border-top-style", "border-top-width"],
115
+ "border-width": [
116
+ "border-bottom-width",
117
+ "border-left-width",
118
+ "border-right-width",
119
+ "border-top-width"
120
+ ],
121
+ "column-rule": [
122
+ "column-rule-width",
123
+ "column-rule-style",
124
+ "column-rule-color"
125
+ ],
126
+ columns: ["column-count", "column-width"],
127
+ flex: ["flex-grow", "flex-shrink", "flex-basis"],
128
+ "flex-flow": ["flex-direction", "flex-wrap"],
129
+ font: [
130
+ "font-family",
131
+ "font-size",
132
+ "font-stretch",
133
+ "font-style",
134
+ "font-variant",
135
+ "font-weight",
136
+ "line-height"
137
+ ],
138
+ gap: ["row-gap", "column-gap"],
139
+ grid: [
140
+ "grid-auto-columns",
141
+ "grid-auto-flow",
142
+ "grid-auto-rows",
143
+ "grid-template-areas",
144
+ "grid-template-columns",
145
+ "grid-template-rows"
146
+ ],
147
+ "grid-area": [
148
+ "grid-row-start",
149
+ "grid-column-start",
150
+ "grid-row-end",
151
+ "grid-column-end"
152
+ ],
153
+ "grid-column": ["grid-column-end", "grid-column-start"],
154
+ "grid-row": ["grid-row-end", "grid-row-start"],
155
+ "grid-template": [
156
+ "grid-template-areas",
157
+ "grid-template-columns",
158
+ "grid-template-rows"
159
+ ],
160
+ "list-style": ["list-style-image", "list-style-position", "list-style-type"],
161
+ margin: ["margin-bottom", "margin-left", "margin-right", "margin-top"],
162
+ mask: [
163
+ "mask-clip",
164
+ "mask-composite",
165
+ "mask-image",
166
+ "mask-mode",
167
+ "mask-origin",
168
+ "mask-position",
169
+ "mask-repeat",
170
+ "mask-size"
171
+ ],
172
+ offset: [
173
+ "offset-anchor",
174
+ "offset-distance",
175
+ "offset-path",
176
+ "offset-position",
177
+ "offset-rotate"
178
+ ],
179
+ outline: ["outline-color", "outline-style", "outline-width"],
180
+ overflow: ["overflow-x", "overflow-y"],
181
+ padding: ["padding-bottom", "padding-left", "padding-right", "padding-top"],
182
+ "place-content": ["align-content", "justify-content"],
183
+ "place-items": ["align-items", "justify-items"],
184
+ "place-self": ["align-self", "justify-self"],
185
+ "scroll-margin": [
186
+ "scroll-margin-bottom",
187
+ "scroll-margin-left",
188
+ "scroll-margin-right",
189
+ "scroll-margin-top"
190
+ ],
191
+ "scroll-padding": [
192
+ "scroll-padding-bottom",
193
+ "scroll-padding-left",
194
+ "scroll-padding-right",
195
+ "scroll-padding-top"
196
+ ],
197
+ "text-decoration": [
198
+ "text-decoration-color",
199
+ "text-decoration-line",
200
+ "text-decoration-style",
201
+ "text-decoration-thickness"
202
+ ],
203
+ "text-emphasis": ["text-emphasis-color", "text-emphasis-style"],
204
+ transition: [
205
+ "transition-delay",
206
+ "transition-duration",
207
+ "transition-property",
208
+ "transition-timing-function"
209
+ ]
210
+ };
211
+ function getPropertyPriority(property) {
212
+ const longhands = Object.values(shorthandProperties).reduce(
213
+ (a, b) => [...a, ...b],
214
+ []
215
+ );
216
+ return longhands.includes(property) ? 2 : 1;
217
+ }
218
+
219
+ // src/processors/helpers/atomize.ts
220
+ var knownPropertiesMap = knownProperties.reduce(
221
+ (acc, property, i) => {
222
+ acc[property] = i;
223
+ return acc;
224
+ },
225
+ {}
226
+ );
227
+ function hashProperty(property) {
228
+ const index = knownPropertiesMap[property];
229
+ if (index !== void 0) {
230
+ return index.toString(36);
231
+ }
232
+ return slugify(property);
233
+ }
234
+ var parseCss = (cssText) => {
235
+ try {
236
+ return postcss.parse(cssText);
237
+ } catch (e) {
238
+ if (e instanceof Error) {
239
+ throw new Error(`Error parsing CSS: ${e.message}
240
+ CSS:
241
+ ${cssText}`);
242
+ }
243
+ throw new Error(`Unknown error parsing CSS.
244
+ CSS:
245
+ ${cssText}`);
246
+ }
247
+ };
248
+ function atomize(cssText, hasPriority = false) {
249
+ stylis.set({
250
+ prefix: false,
251
+ keyframe: false
252
+ });
253
+ const atomicRules = [];
254
+ const stylesheet = parseCss(cssText);
255
+ stylesheet.walkAtRules("keyframes", (atRule) => {
256
+ atRule.remove();
257
+ atomicRules.push({
258
+ property: atRule.name,
259
+ cssText: atRule.toString()
260
+ });
261
+ });
262
+ stylesheet.walkDecls((decl) => {
263
+ let thisParent = decl.parent;
264
+ const parents = [];
265
+ const atomicProperty = [decl.prop];
266
+ let hasAtRule = false;
267
+ while (thisParent && thisParent !== stylesheet) {
268
+ parents.unshift(thisParent);
269
+ if (thisParent.type === "atrule") {
270
+ hasAtRule = true;
271
+ atomicProperty.push(
272
+ thisParent.name,
273
+ thisParent.params
274
+ );
275
+ } else if (thisParent.type === "rule") {
276
+ atomicProperty.push(thisParent.selector);
277
+ }
278
+ thisParent = thisParent.parent;
279
+ }
280
+ const root = postcss.root();
281
+ let container = root;
282
+ parents.forEach((parent) => {
283
+ const newNode = parent.clone();
284
+ newNode.removeAll();
285
+ container.append(newNode);
286
+ container = newNode;
287
+ });
288
+ container.append(decl.clone());
289
+ const css = root.toString();
290
+ const propertySlug = hashProperty([...atomicProperty].join(";"));
291
+ const valueSlug = slugify(decl.value);
292
+ const className = `atm_${propertySlug}_${valueSlug}`;
293
+ const propertyPriority = getPropertyPriority(decl.prop) + (hasAtRule ? 1 : 0) + (hasPriority ? 1 : 0);
294
+ const processedCss = stylis(`.${className}`.repeat(propertyPriority), css);
295
+ atomicRules.push({
296
+ property: atomicProperty.join(" "),
297
+ className,
298
+ cssText: processedCss
299
+ });
300
+ });
301
+ return atomicRules;
302
+ }
303
+
304
+ // src/processors/styled.ts
305
+ var _classes;
306
+ var AtomicStyledProcessor = class extends StyledProcessor {
307
+ constructor() {
308
+ super(...arguments);
309
+ __privateAdd(this, _classes, void 0);
310
+ }
311
+ get classes() {
312
+ if (__privateGet(this, _classes)) {
313
+ return __privateGet(this, _classes);
314
+ }
315
+ throw new Error(
316
+ "Styles are not extracted yet. Please call `extractRules` first."
317
+ );
318
+ }
319
+ extractRules(valueCache, cssText, loc) {
320
+ const rules = {};
321
+ const wrappedValue = typeof this.component === "string" ? null : valueCache.get(this.component.node.name);
322
+ const atomicRules = atomize(cssText, hasMeta(wrappedValue));
323
+ atomicRules.forEach((rule) => {
324
+ rules[rule.cssText] = {
325
+ cssText: rule.cssText,
326
+ start: (loc == null ? void 0 : loc.start) ?? null,
327
+ className: this.className,
328
+ displayName: this.displayName,
329
+ atom: true
330
+ };
331
+ debug(
332
+ "evaluator:template-processor:extracted-atomic-rule",
333
+ `
334
+ ${rule.cssText}`
335
+ );
336
+ });
337
+ __privateSet(this, _classes, atomicRules.filter((rule) => !!rule.className).map((rule) => rule.className).join(" "));
338
+ return rules;
339
+ }
340
+ getProps() {
341
+ const props = super.getProps();
342
+ props.class = [this.classes, this.className].filter(Boolean).join(" ");
343
+ props.atomic = true;
344
+ return props;
345
+ }
346
+ getVariableId(source, unit, precedingCss) {
347
+ const id = this.getCustomVariableId(source, unit, precedingCss);
348
+ if (id) {
349
+ return id;
350
+ }
351
+ const context = this.getVariableContext(source, unit, precedingCss);
352
+ return context.valueSlug;
353
+ }
354
+ };
355
+ _classes = new WeakMap();
356
+ export {
357
+ AtomicStyledProcessor as default
358
+ };
359
+ //# sourceMappingURL=styled.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/processors/styled.ts","../../src/processors/helpers/atomize.ts","../../src/processors/helpers/propertyPriority.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport { debug } from '@linaria/logger';\nimport type { IProps } from '@linaria/react/processors/styled';\nimport StyledProcessor from '@linaria/react/processors/styled';\nimport { hasMeta } from '@linaria/tags';\nimport type { Rules, ValueCache } from '@linaria/tags';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicStyledProcessor extends StyledProcessor {\n #classes: string | undefined;\n\n private get classes(): string {\n if (this.#classes) {\n return this.#classes;\n }\n\n throw new Error(\n 'Styles are not extracted yet. Please call `extractRules` first.'\n );\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n const wrappedValue =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node.name);\n\n const atomicRules = atomize(cssText, hasMeta(wrappedValue));\n atomicRules.forEach((rule) => {\n // eslint-disable-next-line no-param-reassign\n rules[rule.cssText] = {\n cssText: rule.cssText,\n start: loc?.start ?? null,\n className: this.className,\n displayName: this.displayName,\n atom: true,\n };\n\n debug(\n 'evaluator:template-processor:extracted-atomic-rule',\n `\\n${rule.cssText}`\n );\n });\n\n this.#classes = atomicRules\n // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object\n .filter((rule) => !!rule.className)\n .map((rule) => rule.className!)\n .join(' ');\n\n return rules;\n }\n\n protected override getProps(): IProps {\n const props = super.getProps();\n props.class = [this.classes, this.className].filter(Boolean).join(' ');\n props.atomic = true;\n return props;\n }\n\n protected override getVariableId(\n source: string,\n unit: string,\n precedingCss: string\n ): string {\n const id = this.getCustomVariableId(source, unit, precedingCss);\n if (id) {\n return id;\n }\n\n const context = this.getVariableContext(source, unit, precedingCss);\n // id is based on the slugified value\n return context.valueSlug;\n }\n}\n","import { all as knownProperties } from 'known-css-properties';\nimport type { Document, AtRule, Container, Rule } from 'postcss';\nimport postcss from 'postcss';\nimport stylis from 'stylis';\n\nimport { slugify } from '@linaria/utils';\n\nimport { getPropertyPriority } from './propertyPriority';\n\nconst knownPropertiesMap = knownProperties.reduce(\n (acc: { [property: string]: number }, property, i) => {\n acc[property] = i;\n return acc;\n },\n {}\n);\n\nfunction hashProperty(property: string) {\n const index = knownPropertiesMap[property];\n // If it's a known property, let's use the index to cut down the length of the hash.\n // otherwise, slugify\n if (index !== undefined) {\n return index.toString(36); // base 36 so that we get a-z,0-9\n }\n return slugify(property);\n}\n\nconst parseCss = (cssText: string) => {\n try {\n return postcss.parse(cssText);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error parsing CSS: ${e.message}\\nCSS:\\n${cssText}`);\n }\n\n throw new Error(`Unknown error parsing CSS.\\nCSS:\\n${cssText}`);\n }\n};\n\nexport default function atomize(cssText: string, hasPriority = false) {\n stylis.set({\n prefix: false,\n keyframe: false,\n });\n const atomicRules: {\n className?: string;\n cssText: string;\n property: string;\n }[] = [];\n\n const stylesheet = parseCss(cssText);\n\n // We want to extract all keyframes and leave them as-is.\n // This isn't scoped locally yet\n stylesheet.walkAtRules('keyframes', (atRule) => {\n atRule.remove();\n atomicRules.push({\n property: atRule.name,\n cssText: atRule.toString(),\n });\n });\n\n stylesheet.walkDecls((decl) => {\n let thisParent: Document | Container | undefined = decl.parent;\n const parents: (Document | Container)[] = [];\n const atomicProperty = [decl.prop];\n let hasAtRule = false;\n\n // Traverse the declarations parents, and collect them all.\n while (thisParent && thisParent !== stylesheet) {\n parents.unshift(thisParent);\n if (thisParent.type === 'atrule') {\n hasAtRule = true;\n // @media queries, @supports etc.\n atomicProperty.push(\n (thisParent as AtRule).name,\n (thisParent as AtRule).params\n );\n } else if (thisParent.type === 'rule') {\n // pseudo classes etc.\n atomicProperty.push((thisParent as Rule).selector);\n }\n\n thisParent = thisParent.parent;\n }\n\n // Create a new stylesheet that contains *just* the extracted atomic rule and wrapping selectors, eg.\n // `@media (max-width: 400px) { background: red; }`, or\n // `&:hover { background: red; }`, or\n // `background: red;`\n // We do this so we can run it through stylis, to produce a full atom, eg.\n // `@media (max-width: 400px) { .atm_foo { background: red; } }`\n const root = postcss.root();\n let container: Document | Container = root;\n parents.forEach((parent) => {\n const newNode = parent.clone();\n newNode.removeAll();\n container.append(newNode);\n container = newNode;\n });\n container.append(decl.clone());\n\n const css = root.toString();\n const propertySlug = hashProperty([...atomicProperty].join(';'));\n const valueSlug = slugify(decl.value);\n const className = `atm_${propertySlug}_${valueSlug}`;\n\n const propertyPriority =\n getPropertyPriority(decl.prop) +\n (hasAtRule ? 1 : 0) +\n (hasPriority ? 1 : 0);\n const processedCss = stylis(`.${className}`.repeat(propertyPriority), css);\n\n atomicRules.push({\n property: atomicProperty.join(' '),\n className,\n cssText: processedCss,\n });\n });\n\n return atomicRules;\n}\n","const shorthandProperties = {\n // The `all` property resets everything, and should effectively have priority zero.\n // In practice, this can be achieved by using: div { all: ... } to have even less specificity, but to avoid duplicating all selectors, we just let it be\n // 'all': []\n animation: [\n 'animation-name',\n 'animation-duration',\n 'animation-timing-function',\n 'animation-delay',\n 'animation-iteration-count',\n 'animation-direction',\n 'animation-fill-mode',\n 'animation-play-state',\n ],\n background: [\n 'background-attachment',\n 'background-clip',\n 'background-color',\n 'background-image',\n 'background-origin',\n 'background-position',\n 'background-repeat',\n 'background-size',\n ],\n border: ['border-color', 'border-style', 'border-width'],\n 'border-block-end': [\n 'border-block-end-color',\n 'border-block-end-style',\n 'border-block-end-width',\n ],\n 'border-block-start': [\n 'border-block-start-color',\n 'border-block-start-style',\n 'border-block-start-width',\n ],\n 'border-bottom': [\n 'border-bottom-color',\n 'border-bottom-style',\n 'border-bottom-width',\n ],\n 'border-color': [\n 'border-bottom-color',\n 'border-left-color',\n 'border-right-color',\n 'border-top-color',\n ],\n 'border-image': [\n 'border-image-outset',\n 'border-image-repeat',\n 'border-image-slice',\n 'border-image-source',\n 'border-image-width',\n ],\n 'border-inline-end': [\n 'border-inline-end-color',\n 'border-inline-end-style',\n 'border-inline-end-width',\n ],\n 'border-inline-start': [\n 'border-inline-start-color',\n 'border-inline-start-style',\n 'border-inline-start-width',\n ],\n 'border-left': [\n 'border-left-color',\n 'border-left-style',\n 'border-left-width',\n ],\n 'border-radius': [\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-bottom-right-radius',\n 'border-bottom-left-radius',\n ],\n 'border-right': [\n 'border-right-color',\n 'border-right-style',\n 'border-right-width',\n ],\n 'border-style': [\n 'border-bottom-style',\n 'border-left-style',\n 'border-right-style',\n 'border-top-style',\n ],\n 'border-top': ['border-top-color', 'border-top-style', 'border-top-width'],\n 'border-width': [\n 'border-bottom-width',\n 'border-left-width',\n 'border-right-width',\n 'border-top-width',\n ],\n 'column-rule': [\n 'column-rule-width',\n 'column-rule-style',\n 'column-rule-color',\n ],\n columns: ['column-count', 'column-width'],\n flex: ['flex-grow', 'flex-shrink', 'flex-basis'],\n 'flex-flow': ['flex-direction', 'flex-wrap'],\n font: [\n 'font-family',\n 'font-size',\n 'font-stretch',\n 'font-style',\n 'font-variant',\n 'font-weight',\n 'line-height',\n ],\n gap: ['row-gap', 'column-gap'],\n grid: [\n 'grid-auto-columns',\n 'grid-auto-flow',\n 'grid-auto-rows',\n 'grid-template-areas',\n 'grid-template-columns',\n 'grid-template-rows',\n ],\n 'grid-area': [\n 'grid-row-start',\n 'grid-column-start',\n 'grid-row-end',\n 'grid-column-end',\n ],\n 'grid-column': ['grid-column-end', 'grid-column-start'],\n 'grid-row': ['grid-row-end', 'grid-row-start'],\n 'grid-template': [\n 'grid-template-areas',\n 'grid-template-columns',\n 'grid-template-rows',\n ],\n 'list-style': ['list-style-image', 'list-style-position', 'list-style-type'],\n margin: ['margin-bottom', 'margin-left', 'margin-right', 'margin-top'],\n mask: [\n 'mask-clip',\n 'mask-composite',\n 'mask-image',\n 'mask-mode',\n 'mask-origin',\n 'mask-position',\n 'mask-repeat',\n 'mask-size',\n ],\n offset: [\n 'offset-anchor',\n 'offset-distance',\n 'offset-path',\n 'offset-position',\n 'offset-rotate',\n ],\n outline: ['outline-color', 'outline-style', 'outline-width'],\n overflow: ['overflow-x', 'overflow-y'],\n padding: ['padding-bottom', 'padding-left', 'padding-right', 'padding-top'],\n 'place-content': ['align-content', 'justify-content'],\n 'place-items': ['align-items', 'justify-items'],\n 'place-self': ['align-self', 'justify-self'],\n 'scroll-margin': [\n 'scroll-margin-bottom',\n 'scroll-margin-left',\n 'scroll-margin-right',\n 'scroll-margin-top',\n ],\n 'scroll-padding': [\n 'scroll-padding-bottom',\n 'scroll-padding-left',\n 'scroll-padding-right',\n 'scroll-padding-top',\n ],\n 'text-decoration': [\n 'text-decoration-color',\n 'text-decoration-line',\n 'text-decoration-style',\n 'text-decoration-thickness',\n ],\n 'text-emphasis': ['text-emphasis-color', 'text-emphasis-style'],\n transition: [\n 'transition-delay',\n 'transition-duration',\n 'transition-property',\n 'transition-timing-function',\n ],\n};\n\n// Get the property priority: the higher the priority, the higher the resulting\n// specificity of the atom. For example, if we had:\n//\n// import { css } from '@linaria/atomic';\n// css`\n// background-color: blue;\n// background: red;\n// `;\n//\n// we would produce:\n//\n// .atm_a.atm_a { background-color: blue }\n// .atm_b { background: red }\n//\n// and so the more specific selector (.atm_a.atm_a) would win\nexport function getPropertyPriority(property: string) {\n const longhands = Object.values(shorthandProperties).reduce(\n (a, b) => [...a, ...b],\n []\n );\n\n return longhands.includes(property) ? 2 : 1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa;AAEtB,OAAO,qBAAqB;AAC5B,SAAS,eAAe;;;ACLxB,SAAS,OAAO,uBAAuB;AAEvC,OAAO,aAAa;AACpB,OAAO,YAAY;AAEnB,SAAS,eAAe;;;ACLxB,IAAM,sBAAsB;AAAA,EAI1B,WAAW;AAAA,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AY,UAAkB;AAC5B,QAAI,mBAAK,WAAU;AACjB,aAAO,mBAAK;AAAA,IACd;AAEA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEgB,aACd,YACA,SACA,KACO;AACP,UAAM,QAAe,CAAC;AAEtB,UAAM,eACJ,OAAO,KAAK,cAAc,WACtB,OACA,WAAW,IAAI,KAAK,UAAU,KAAK,IAAI;AAE7C,UAAM,cAAc,QAAQ,SAAS,QAAQ,YAAY,CAAC;AAC1D,gBAAY,QAAQ,CAAC,SAAS;AAE5B,YAAM,KAAK,WAAW;AAAA,QACpB,SAAS,KAAK;AAAA,QACd,QAAO,2BAAK,UAAS;AAAA,QACrB,WAAW,KAAK;AAAA,QAChB,aAAa,KAAK;AAAA,QAClB,MAAM;AAAA,MACR;AAEA;AAAA,QACE;AAAA,QACA;AAAA,EAAK,KAAK;AAAA,MACZ;AAAA,IACF,CAAC;AAED,uBAAK,UAAW,YAEb,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,SAAS,EACjC,IAAI,CAAC,SAAS,KAAK,SAAU,EAC7B,KAAK,GAAG;AAEX,WAAO;AAAA,EACT;AAAA,EAEmB,WAAmB;AACpC,UAAM,QAAQ,MAAM,SAAS;AAC7B,UAAM,QAAQ,CAAC,KAAK,SAAS,KAAK,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AACrE,UAAM,SAAS;AACf,WAAO;AAAA,EACT;AAAA,EAEmB,cACjB,QACA,MACA,cACQ;AACR,UAAM,KAAK,KAAK,oBAAoB,QAAQ,MAAM,YAAY;AAC9D,QAAI,IAAI;AACN,aAAO;AAAA,IACT;AAEA,UAAM,UAAU,KAAK,mBAAmB,QAAQ,MAAM,YAAY;AAElE,WAAO,QAAQ;AAAA,EACjB;AACF;AAvEE;","names":[]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@linaria/atomic",
3
3
  "description": "Blazing fast zero-runtime CSS in JS library",
4
- "version": "4.1.5",
4
+ "version": "4.2.0",
5
5
  "bugs": "https://github.com/callstack/linaria/issues",
6
6
  "dependencies": {
7
- "@linaria/core": "^4.1.4",
7
+ "@linaria/core": "^4.2.0",
8
8
  "@linaria/logger": "^4.0.0",
9
- "@linaria/react": "^4.1.5",
9
+ "@linaria/react": "^4.2.0",
10
10
  "@linaria/tags": "^4.1.4",
11
11
  "@linaria/utils": "^4.2.2",
12
12
  "known-css-properties": "^0.24.0",
@@ -20,9 +20,21 @@
20
20
  "engines": {
21
21
  "node": "^12.16.0 || >=13.7.0"
22
22
  },
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "types": "./types/index.d.ts",
27
+ "import": "./dist/index.mjs",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./*": {
31
+ "types": "./types/*.d.ts",
32
+ "import": "./dist/*.mjs",
33
+ "default": "./dist/*.js"
34
+ }
35
+ },
23
36
  "files": [
24
- "esm/",
25
- "lib/",
37
+ "dist/",
26
38
  "processors/",
27
39
  "types/"
28
40
  ],
@@ -37,23 +49,32 @@
37
49
  "license": "MIT",
38
50
  "linaria": {
39
51
  "tags": {
40
- "css": "./lib/processors/css.js",
41
- "styled": "./lib/processors/styled.js"
52
+ "css": "./dist/processors/css.js",
53
+ "styled": "./dist/processors/styled.js"
42
54
  }
43
55
  },
44
- "main": "lib/index.js",
45
- "module": "esm/index.js",
56
+ "main": "dist/index.js",
57
+ "module": "dist/index.mjs",
46
58
  "publishConfig": {
47
59
  "access": "public"
48
60
  },
49
61
  "repository": "git@github.com:callstack/linaria.git",
50
62
  "sideEffects": false,
63
+ "tsup": {
64
+ "entry": [
65
+ "src/index.ts",
66
+ "src/processors/css.ts",
67
+ "src/processors/styled.ts"
68
+ ],
69
+ "splitting": false,
70
+ "sourcemap": true,
71
+ "clean": true
72
+ },
51
73
  "types": "types/index.d.ts",
52
74
  "scripts": {
53
- "build": "npm run build:lib && npm run build:esm && npm run build:declarations",
75
+ "build": "npm run build:dist && npm run build:declarations",
54
76
  "build:declarations": "tsc --emitDeclarationOnly --outDir types",
55
- "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
56
- "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
77
+ "build:dist": "tsup --format cjs,esm",
57
78
  "typecheck": "tsc --noEmit --composite false",
58
79
  "watch": "npm run build --watch"
59
80
  }
package/processors/css.js CHANGED
@@ -2,4 +2,4 @@ Object.defineProperty(exports, '__esModule', {
2
2
  value: true,
3
3
  });
4
4
 
5
- exports.default = require('../lib/processors/css').default;
5
+ exports.default = require('../dist/processors/css').default;
@@ -2,4 +2,4 @@ Object.defineProperty(exports, '__esModule', {
2
2
  value: true,
3
3
  });
4
4
 
5
- exports.default = require('../lib/processors/styled').default;
5
+ exports.default = require('../dist/processors/styled').default;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=CSSProperties.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CSSProperties.js","names":[],"sources":["../src/CSSProperties.ts"],"sourcesContent":["export type CSSProperties = {\n [key: string]: string | number | CSSProperties;\n};\n"],"mappings":""}
package/esm/css.js DELETED
@@ -1,5 +0,0 @@
1
- export const css = () => {
2
- throw new Error('Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.');
3
- };
4
- export default css;
5
- //# sourceMappingURL=css.js.map
package/esm/css.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"css.js","names":["css","Error"],"sources":["../src/css.ts"],"sourcesContent":["import type { LinariaClassName } from '@linaria/core';\n\nimport type { CSSProperties } from './CSSProperties';\n\ntype CSS = (\n strings: TemplateStringsArray,\n ...exprs: Array<string | number | CSSProperties>\n) => LinariaClassName;\n\nexport const css: CSS = () => {\n throw new Error(\n 'Using the \"css\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.'\n );\n};\n\nexport default css;\n"],"mappings":"AASA,OAAO,MAAMA,GAAQ,GAAG,MAAM;EAC5B,MAAM,IAAIC,KAAJ,CACJ,wGADI,CAAN;AAGD,CAJM;AAMP,eAAeD,GAAf"}
package/esm/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { default as css } from './css';
2
- export { styled } from '@linaria/react';
3
- export { cx } from '@linaria/core';
4
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["default","css","styled","cx"],"sources":["../src/index.ts"],"sourcesContent":["export { default as css } from './css';\nexport { styled } from '@linaria/react';\nexport { cx } from '@linaria/core';\n\nexport type { CSSProperties } from './CSSProperties';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,GAApB,QAA+B,OAA/B;AACA,SAASC,MAAT,QAAuB,gBAAvB;AACA,SAASC,EAAT,QAAmB,eAAnB"}
@@ -1,39 +0,0 @@
1
- import CssProcessor from '@linaria/core/processors/css';
2
- import { debug } from '@linaria/logger';
3
- import atomize from './helpers/atomize';
4
- export default class AtomicCssProcessor extends CssProcessor {
5
- #classes;
6
-
7
- get classes() {
8
- if (this.#classes) {
9
- return this.#classes;
10
- }
11
-
12
- throw new Error('Styles are not extracted yet. Please call `build` first.');
13
- }
14
-
15
- doRuntimeReplacement() {
16
- this.replacer(this.astService.stringLiteral(this.classes), false);
17
- }
18
-
19
- extractRules(valueCache, cssText, loc) {
20
- const rules = {};
21
- const atomicRules = atomize(cssText, false);
22
- atomicRules.forEach(rule => {
23
- // eslint-disable-next-line no-param-reassign
24
- rules[rule.cssText] = {
25
- cssText: rule.cssText,
26
- start: loc?.start ?? null,
27
- className: this.className,
28
- displayName: this.displayName,
29
- atom: true
30
- };
31
- debug('evaluator:template-processor:extracted-atomic-rule', `\n${rule.cssText}`);
32
- });
33
- this.#classes = atomicRules // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object
34
- .filter(rule => !!rule.className).map(rule => rule.className).join(' ');
35
- return rules;
36
- }
37
-
38
- }
39
- //# sourceMappingURL=css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css.js","names":["CssProcessor","debug","atomize","AtomicCssProcessor","classes","Error","doRuntimeReplacement","replacer","astService","stringLiteral","extractRules","valueCache","cssText","loc","rules","atomicRules","forEach","rule","start","className","displayName","atom","filter","map","join"],"sources":["../../src/processors/css.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport CssProcessor from '@linaria/core/processors/css';\nimport { debug } from '@linaria/logger';\nimport type { Rules, ValueCache } from '@linaria/tags';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicCssProcessor extends CssProcessor {\n #classes: string | undefined;\n\n private get classes(): string {\n if (this.#classes) {\n return this.#classes;\n }\n\n throw new Error('Styles are not extracted yet. Please call `build` first.');\n }\n\n public override doRuntimeReplacement(): void {\n this.replacer(this.astService.stringLiteral(this.classes), false);\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n const atomicRules = atomize(cssText, false);\n atomicRules.forEach((rule) => {\n // eslint-disable-next-line no-param-reassign\n rules[rule.cssText] = {\n cssText: rule.cssText,\n start: loc?.start ?? null,\n className: this.className!,\n displayName: this.displayName!,\n atom: true,\n };\n\n debug(\n 'evaluator:template-processor:extracted-atomic-rule',\n `\\n${rule.cssText}`\n );\n });\n\n this.#classes = atomicRules\n // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object\n .filter((rule) => !!rule.className)\n .map((rule) => rule.className!)\n .join(' ');\n\n return rules;\n }\n}\n"],"mappings":"AAEA,OAAOA,YAAP,MAAyB,8BAAzB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAGA,OAAOC,OAAP,MAAoB,mBAApB;AAEA,eAAe,MAAMC,kBAAN,SAAiCH,YAAjC,CAA8C;EAC3D,CAACI,OAAD;;EAEmB,IAAPA,OAAO,GAAW;IAC5B,IAAI,KAAK,CAACA,OAAV,EAAmB;MACjB,OAAO,KAAK,CAACA,OAAb;IACD;;IAED,MAAM,IAAIC,KAAJ,CAAU,0DAAV,CAAN;EACD;;EAEeC,oBAAoB,GAAS;IAC3C,KAAKC,QAAL,CAAc,KAAKC,UAAL,CAAgBC,aAAhB,CAA8B,KAAKL,OAAnC,CAAd,EAA2D,KAA3D;EACD;;EAEeM,YAAY,CAC1BC,UAD0B,EAE1BC,OAF0B,EAG1BC,GAH0B,EAInB;IACP,MAAMC,KAAY,GAAG,EAArB;IAEA,MAAMC,WAAW,GAAGb,OAAO,CAACU,OAAD,EAAU,KAAV,CAA3B;IACAG,WAAW,CAACC,OAAZ,CAAqBC,IAAD,IAAU;MAC5B;MACAH,KAAK,CAACG,IAAI,CAACL,OAAN,CAAL,GAAsB;QACpBA,OAAO,EAAEK,IAAI,CAACL,OADM;QAEpBM,KAAK,EAAEL,GAAG,EAAEK,KAAL,IAAc,IAFD;QAGpBC,SAAS,EAAE,KAAKA,SAHI;QAIpBC,WAAW,EAAE,KAAKA,WAJE;QAKpBC,IAAI,EAAE;MALc,CAAtB;MAQApB,KAAK,CACH,oDADG,EAEF,KAAIgB,IAAI,CAACL,OAAQ,EAFf,CAAL;IAID,CAdD;IAgBA,KAAK,CAACR,OAAN,GAAgBW,WAAW,CACzB;IADyB,CAExBO,MAFa,CAELL,IAAD,IAAU,CAAC,CAACA,IAAI,CAACE,SAFX,EAGbI,GAHa,CAGRN,IAAD,IAAUA,IAAI,CAACE,SAHN,EAIbK,IAJa,CAIR,GAJQ,CAAhB;IAMA,OAAOV,KAAP;EACD;;AA9C0D"}
@@ -1,100 +0,0 @@
1
- import { all as knownProperties } from 'known-css-properties';
2
- import postcss from 'postcss';
3
- import stylis from 'stylis';
4
- import { slugify } from '@linaria/utils';
5
- import { getPropertyPriority } from './propertyPriority';
6
- const knownPropertiesMap = knownProperties.reduce((acc, property, i) => {
7
- acc[property] = i;
8
- return acc;
9
- }, {});
10
-
11
- function hashProperty(property) {
12
- const index = knownPropertiesMap[property]; // If it's a known property, let's use the index to cut down the length of the hash.
13
- // otherwise, slugify
14
-
15
- if (index !== undefined) {
16
- return index.toString(36); // base 36 so that we get a-z,0-9
17
- }
18
-
19
- return slugify(property);
20
- }
21
-
22
- const parseCss = cssText => {
23
- try {
24
- return postcss.parse(cssText);
25
- } catch (e) {
26
- if (e instanceof Error) {
27
- throw new Error(`Error parsing CSS: ${e.message}\nCSS:\n${cssText}`);
28
- }
29
-
30
- throw new Error(`Unknown error parsing CSS.\nCSS:\n${cssText}`);
31
- }
32
- };
33
-
34
- export default function atomize(cssText, hasPriority = false) {
35
- stylis.set({
36
- prefix: false,
37
- keyframe: false
38
- });
39
- const atomicRules = [];
40
- const stylesheet = parseCss(cssText); // We want to extract all keyframes and leave them as-is.
41
- // This isn't scoped locally yet
42
-
43
- stylesheet.walkAtRules('keyframes', atRule => {
44
- atRule.remove();
45
- atomicRules.push({
46
- property: atRule.name,
47
- cssText: atRule.toString()
48
- });
49
- });
50
- stylesheet.walkDecls(decl => {
51
- let thisParent = decl.parent;
52
- const parents = [];
53
- const atomicProperty = [decl.prop];
54
- let hasAtRule = false; // Traverse the declarations parents, and collect them all.
55
-
56
- while (thisParent && thisParent !== stylesheet) {
57
- parents.unshift(thisParent);
58
-
59
- if (thisParent.type === 'atrule') {
60
- hasAtRule = true; // @media queries, @supports etc.
61
-
62
- atomicProperty.push(thisParent.name, thisParent.params);
63
- } else if (thisParent.type === 'rule') {
64
- // pseudo classes etc.
65
- atomicProperty.push(thisParent.selector);
66
- }
67
-
68
- thisParent = thisParent.parent;
69
- } // Create a new stylesheet that contains *just* the extracted atomic rule and wrapping selectors, eg.
70
- // `@media (max-width: 400px) { background: red; }`, or
71
- // `&:hover { background: red; }`, or
72
- // `background: red;`
73
- // We do this so we can run it through stylis, to produce a full atom, eg.
74
- // `@media (max-width: 400px) { .atm_foo { background: red; } }`
75
-
76
-
77
- const root = postcss.root();
78
- let container = root;
79
- parents.forEach(parent => {
80
- const newNode = parent.clone();
81
- newNode.removeAll();
82
- container.append(newNode);
83
- container = newNode;
84
- });
85
- container.append(decl.clone());
86
- const css = root.toString();
87
- const propertySlug = hashProperty([...atomicProperty].join(';'));
88
- const valueSlug = slugify(decl.value);
89
- const className = `atm_${propertySlug}_${valueSlug}`;
90
- const propertyPriority = getPropertyPriority(decl.prop) + (hasAtRule ? 1 : 0) + (hasPriority ? 1 : 0);
91
- const processedCss = stylis(`.${className}`.repeat(propertyPriority), css);
92
- atomicRules.push({
93
- property: atomicProperty.join(' '),
94
- className,
95
- cssText: processedCss
96
- });
97
- });
98
- return atomicRules;
99
- }
100
- //# sourceMappingURL=atomize.js.map