@linaria/atomic 3.0.0-beta.15 → 3.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/CSSProperties.js.map +1 -1
- package/esm/css.js.map +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/processors/css.js +25 -0
- package/esm/processors/css.js.map +1 -0
- package/esm/processors/helpers/atomize.js +100 -0
- package/esm/processors/helpers/atomize.js.map +1 -0
- package/esm/processors/helpers/propertyPriority.js +67 -0
- package/esm/processors/helpers/propertyPriority.js.map +1 -0
- package/esm/processors/styled.js +40 -0
- package/esm/processors/styled.js.map +1 -0
- package/lib/CSSProperties.js.map +1 -1
- package/lib/css.js +1 -3
- package/lib/css.js.map +1 -1
- package/lib/index.js +10 -23
- package/lib/index.js.map +1 -1
- package/lib/processors/css.js +41 -0
- package/lib/processors/css.js.map +1 -0
- package/lib/processors/helpers/atomize.js +116 -0
- package/lib/processors/helpers/atomize.js.map +1 -0
- package/lib/processors/helpers/propertyPriority.js +73 -0
- package/lib/processors/helpers/propertyPriority.js.map +1 -0
- package/lib/processors/styled.js +61 -0
- package/lib/processors/styled.js.map +1 -0
- package/package.json +41 -27
- package/types/css.d.ts +2 -4
- package/types/index.d.ts +2 -3
- package/types/processors/css.d.ts +6 -0
- package/types/processors/helpers/atomize.d.ts +5 -0
- package/types/processors/helpers/propertyPriority.d.ts +1 -0
- package/types/processors/styled.d.ts +9 -0
- package/CHANGELOG.md +0 -11
- package/esm/atomize.js +0 -37
- package/esm/atomize.js.map +0 -1
- package/lib/atomize.js +0 -50
- package/lib/atomize.js.map +0 -1
- package/types/atomize.d.ts +0 -5
package/esm/CSSProperties.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
extractRules(valueCache, cssText, loc) {
|
|
6
|
+
const rules = {};
|
|
7
|
+
const atomicRules = atomize(cssText, false);
|
|
8
|
+
atomicRules.forEach(rule => {
|
|
9
|
+
// eslint-disable-next-line no-param-reassign
|
|
10
|
+
rules[rule.cssText] = {
|
|
11
|
+
cssText: rule.cssText,
|
|
12
|
+
start: loc?.start ?? null,
|
|
13
|
+
className: this.className,
|
|
14
|
+
displayName: this.displayName,
|
|
15
|
+
atom: true
|
|
16
|
+
};
|
|
17
|
+
debug('evaluator:template-processor:extracted-atomic-rule', `\n${rule.cssText}`);
|
|
18
|
+
});
|
|
19
|
+
const classes = atomicRules // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object
|
|
20
|
+
.filter(rule => !!rule.className).map(rule => rule.className).join(' ');
|
|
21
|
+
return [rules, classes];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","names":["CssProcessor","debug","atomize","AtomicCssProcessor","extractRules","valueCache","cssText","loc","rules","atomicRules","forEach","rule","start","className","displayName","atom","classes","filter","map","join"],"sources":["../../src/processors/css.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport CssProcessor from '@linaria/core/processors/css';\nimport type { Rules, ValueCache } from '@linaria/core/processors/types';\nimport { debug } from '@linaria/logger';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicCssProcessor extends CssProcessor {\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\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 const 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, classes];\n }\n}\n"],"mappings":"AAEA,OAAOA,YAAP,MAAyB,8BAAzB;AAEA,SAASC,KAAT,QAAsB,iBAAtB;AAEA,OAAOC,OAAP,MAAoB,mBAApB;AAEA,eAAe,MAAMC,kBAAN,SAAiCH,YAAjC,CAA8C;EAC3CI,YAAY,CAC1BC,UAD0B,EAE1BC,OAF0B,EAG1BC,GAH0B,EAIT;IACjB,MAAMC,KAAY,GAAG,EAArB;IAEA,MAAMC,WAAW,GAAGP,OAAO,CAACI,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;MAQAd,KAAK,CACH,oDADG,EAEF,KAAIU,IAAI,CAACL,OAAQ,EAFf,CAAL;IAID,CAdD;IAgBA,MAAMU,OAAO,GAAGP,WAAW,CACzB;IADyB,CAExBQ,MAFa,CAELN,IAAD,IAAU,CAAC,CAACA,IAAI,CAACE,SAFX,EAGbK,GAHa,CAGRP,IAAD,IAAUA,IAAI,CAACE,SAHN,EAIbM,IAJa,CAIR,GAJQ,CAAhB;IAMA,OAAO,CAACX,KAAD,EAAQQ,OAAR,CAAP;EACD;;AAhC0D"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomize.js","names":["all","knownProperties","postcss","stylis","slugify","getPropertyPriority","knownPropertiesMap","reduce","acc","property","i","hashProperty","index","undefined","toString","parseCss","cssText","parse","e","Error","message","atomize","hasPriority","set","prefix","keyframe","atomicRules","stylesheet","walkAtRules","atRule","remove","push","name","walkDecls","decl","thisParent","parent","parents","atomicProperty","prop","hasAtRule","unshift","type","params","selector","root","container","forEach","newNode","clone","removeAll","append","css","propertySlug","join","valueSlug","value","className","propertyPriority","processedCss","repeat"],"sources":["../../../src/processors/helpers/atomize.ts"],"sourcesContent":["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"],"mappings":"AAAA,SAASA,GAAG,IAAIC,eAAhB,QAAuC,sBAAvC;AAEA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAEA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,SAASC,mBAAT,QAAoC,oBAApC;AAEA,MAAMC,kBAAkB,GAAGL,eAAe,CAACM,MAAhB,CACzB,CAACC,GAAD,EAAsCC,QAAtC,EAAgDC,CAAhD,KAAsD;EACpDF,GAAG,CAACC,QAAD,CAAH,GAAgBC,CAAhB;E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AI,OAAMJ,YAAa,IAAGE,SAAU,EAAnD;IAEA,MAAMG,gBAAgB,GACpBrD,mBAAmB,CAAC6B,IAAI,CAACK,IAAN,CAAnB,IACCC,SAAS,GAAG,CAAH,GAAO,CADjB,KAEClB,WAAW,GAAG,CAAH,GAAO,CAFnB,CADF;IAIA,MAAMqC,YAAY,GAAGxD,MAAM,CAAE,IAAGsD,SAAU,EAAd,CAAgBG,MAAhB,CAAuBF,gBAAvB,CAAD,EAA2CN,GAA3C,CAA3B;IAEA1B,WAAW,CAACK,IAAZ,CAAiB;MACftB,QAAQ,EAAE6B,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;MAEfG,SAFe;MAGfzC,OAAO,EAAE2C;IAHM,CAAjB;EAKD,CAxDD;EA0DA,OAAOjC,WAAP;AACD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const shorthandProperties = {
|
|
2
|
+
// The `all` property resets everything, and should effectively have priority zero.
|
|
3
|
+
// 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
|
|
4
|
+
// 'all': []
|
|
5
|
+
animation: ['animation-name', 'animation-duration', 'animation-timing-function', 'animation-delay', 'animation-iteration-count', 'animation-direction', 'animation-fill-mode', 'animation-play-state'],
|
|
6
|
+
background: ['background-attachment', 'background-clip', 'background-color', 'background-image', 'background-origin', 'background-position', 'background-repeat', 'background-size'],
|
|
7
|
+
border: ['border-color', 'border-style', 'border-width'],
|
|
8
|
+
'border-block-end': ['border-block-end-color', 'border-block-end-style', 'border-block-end-width'],
|
|
9
|
+
'border-block-start': ['border-block-start-color', 'border-block-start-style', 'border-block-start-width'],
|
|
10
|
+
'border-bottom': ['border-bottom-color', 'border-bottom-style', 'border-bottom-width'],
|
|
11
|
+
'border-color': ['border-bottom-color', 'border-left-color', 'border-right-color', 'border-top-color'],
|
|
12
|
+
'border-image': ['border-image-outset', 'border-image-repeat', 'border-image-slice', 'border-image-source', 'border-image-width'],
|
|
13
|
+
'border-inline-end': ['border-inline-end-color', 'border-inline-end-style', 'border-inline-end-width'],
|
|
14
|
+
'border-inline-start': ['border-inline-start-color', 'border-inline-start-style', 'border-inline-start-width'],
|
|
15
|
+
'border-left': ['border-left-color', 'border-left-style', 'border-left-width'],
|
|
16
|
+
'border-radius': ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius'],
|
|
17
|
+
'border-right': ['border-right-color', 'border-right-style', 'border-right-width'],
|
|
18
|
+
'border-style': ['border-bottom-style', 'border-left-style', 'border-right-style', 'border-top-style'],
|
|
19
|
+
'border-top': ['border-top-color', 'border-top-style', 'border-top-width'],
|
|
20
|
+
'border-width': ['border-bottom-width', 'border-left-width', 'border-right-width', 'border-top-width'],
|
|
21
|
+
'column-rule': ['column-rule-width', 'column-rule-style', 'column-rule-color'],
|
|
22
|
+
columns: ['column-count', 'column-width'],
|
|
23
|
+
flex: ['flex-grow', 'flex-shrink', 'flex-basis'],
|
|
24
|
+
'flex-flow': ['flex-direction', 'flex-wrap'],
|
|
25
|
+
font: ['font-family', 'font-size', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'line-height'],
|
|
26
|
+
gap: ['row-gap', 'column-gap'],
|
|
27
|
+
grid: ['grid-auto-columns', 'grid-auto-flow', 'grid-auto-rows', 'grid-template-areas', 'grid-template-columns', 'grid-template-rows'],
|
|
28
|
+
'grid-area': ['grid-row-start', 'grid-column-start', 'grid-row-end', 'grid-column-end'],
|
|
29
|
+
'grid-column': ['grid-column-end', 'grid-column-start'],
|
|
30
|
+
'grid-row': ['grid-row-end', 'grid-row-start'],
|
|
31
|
+
'grid-template': ['grid-template-areas', 'grid-template-columns', 'grid-template-rows'],
|
|
32
|
+
'list-style': ['list-style-image', 'list-style-position', 'list-style-type'],
|
|
33
|
+
margin: ['margin-bottom', 'margin-left', 'margin-right', 'margin-top'],
|
|
34
|
+
mask: ['mask-clip', 'mask-composite', 'mask-image', 'mask-mode', 'mask-origin', 'mask-position', 'mask-repeat', 'mask-size'],
|
|
35
|
+
offset: ['offset-anchor', 'offset-distance', 'offset-path', 'offset-position', 'offset-rotate'],
|
|
36
|
+
outline: ['outline-color', 'outline-style', 'outline-width'],
|
|
37
|
+
overflow: ['overflow-x', 'overflow-y'],
|
|
38
|
+
padding: ['padding-bottom', 'padding-left', 'padding-right', 'padding-top'],
|
|
39
|
+
'place-content': ['align-content', 'justify-content'],
|
|
40
|
+
'place-items': ['align-items', 'justify-items'],
|
|
41
|
+
'place-self': ['align-self', 'justify-self'],
|
|
42
|
+
'scroll-margin': ['scroll-margin-bottom', 'scroll-margin-left', 'scroll-margin-right', 'scroll-margin-top'],
|
|
43
|
+
'scroll-padding': ['scroll-padding-bottom', 'scroll-padding-left', 'scroll-padding-right', 'scroll-padding-top'],
|
|
44
|
+
'text-decoration': ['text-decoration-color', 'text-decoration-line', 'text-decoration-style', 'text-decoration-thickness'],
|
|
45
|
+
'text-emphasis': ['text-emphasis-color', 'text-emphasis-style'],
|
|
46
|
+
transition: ['transition-delay', 'transition-duration', 'transition-property', 'transition-timing-function']
|
|
47
|
+
}; // Get the property priority: the higher the priority, the higher the resulting
|
|
48
|
+
// specificity of the atom. For example, if we had:
|
|
49
|
+
//
|
|
50
|
+
// import { css } from '@linaria/atomic';
|
|
51
|
+
// css`
|
|
52
|
+
// background-color: blue;
|
|
53
|
+
// background: red;
|
|
54
|
+
// `;
|
|
55
|
+
//
|
|
56
|
+
// we would produce:
|
|
57
|
+
//
|
|
58
|
+
// .atm_a.atm_a { background-color: blue }
|
|
59
|
+
// .atm_b { background: red }
|
|
60
|
+
//
|
|
61
|
+
// and so the more specific selector (.atm_a.atm_a) would win
|
|
62
|
+
|
|
63
|
+
export function getPropertyPriority(property) {
|
|
64
|
+
const longhands = Object.values(shorthandProperties).reduce((a, b) => [...a, ...b], []);
|
|
65
|
+
return longhands.includes(property) ? 2 : 1;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=propertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyPriority.js","names":["shorthandProperties","animation","background","border","columns","flex","font","gap","grid","margin","mask","offset","outline","overflow","padding","transition","getPropertyPriority","property","longhands","Object","values","reduce","a","b","includes"],"sources":["../../../src/processors/helpers/propertyPriority.ts"],"sourcesContent":["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":"AAAA,MAAMA,mBAAmB,GAAG;EAC1B;EACA;EACA;EACAC,SAAS,EAAE,CACT,gBADS,EAET,oBAFS,EAGT,2BAHS,EAIT,iBAJS,EAKT,2BALS,EAMT,qBANS,EAOT,qBAPS,EAQT,sBARS,CAJe;EAc1BC,UAAU,EAAE,CACV,uBADU,EAEV,iBAFU,EAGV,kBAHU,EAIV,kBAJU,EAKV,mBALU,EAMV,qBANU,EAOV,mBAPU,EAQV,iBARU,CAdc;EAwB1BC,MAAM,EAAE,CAAC,cAAD,EAAiB,cAAjB,EAAiC,cAAjC,CAxBkB;EAyB1B,oBAAoB,CAClB,wBADkB,EAElB,wBAFkB,EAGlB,wBAHkB,CAzBM;EA8B1B,sBAAsB,CACpB,0BADoB,EAEpB,0BAFoB,EAGpB,0BAHoB,CA9BI;EAmC1B,iBAAiB,CACf,qBADe,EAEf,qBAFe,EAGf,qBAHe,CAnCS;EAwC1B,gBAAgB,CACd,qBADc,EAEd,mBAFc,EAGd,oBAHc,EAId,kBAJc,CAxCU;EA8C1B,gBAAgB,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CAA5B,C,CAuLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,MAAMC,SAAS,GAAGC,MAAM,CAACC,MAAP,CAAcpB,mBAAd,EAAmCqB,MAAnC,CAChB,CAACC,CAAD,EAAIC,CAAJ,KAAU,CAAC,GAAGD,CAAJ,EAAO,GAAGC,CAAV,CADM,EAEhB,EAFgB,CAAlB;EAKA,OAAOL,SAAS,CAACM,QAAV,CAAmBP,QAAnB,IAA+B,CAA/B,GAAmC,CAA1C;AACD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { debug } from '@linaria/logger';
|
|
2
|
+
import StyledProcessor, { hasMeta } from '@linaria/react/processors/styled';
|
|
3
|
+
import { slugify } from '@linaria/utils';
|
|
4
|
+
import atomize from './helpers/atomize';
|
|
5
|
+
export default class AtomicStyledProcessor extends StyledProcessor {
|
|
6
|
+
extractRules(valueCache, cssText, loc) {
|
|
7
|
+
const rules = {};
|
|
8
|
+
const wrappedValue = typeof this.component === 'string' ? null : valueCache.get(this.component.node);
|
|
9
|
+
const atomicRules = atomize(cssText, hasMeta(wrappedValue));
|
|
10
|
+
atomicRules.forEach(rule => {
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
rules[rule.cssText] = {
|
|
13
|
+
cssText: rule.cssText,
|
|
14
|
+
start: loc?.start ?? null,
|
|
15
|
+
className: this.className,
|
|
16
|
+
displayName: this.displayName,
|
|
17
|
+
atom: true
|
|
18
|
+
};
|
|
19
|
+
debug('evaluator:template-processor:extracted-atomic-rule', `\n${rule.cssText}`);
|
|
20
|
+
});
|
|
21
|
+
const classes = atomicRules // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object
|
|
22
|
+
.filter(rule => !!rule.className).map(rule => rule.className).join(' ');
|
|
23
|
+
return [rules, classes];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getProps(classes, uniqInterpolations) {
|
|
27
|
+
const props = super.getProps(classes, uniqInterpolations);
|
|
28
|
+
props.class = [classes, this.className].filter(Boolean).join(' ');
|
|
29
|
+
props.atomic = true;
|
|
30
|
+
return props;
|
|
31
|
+
} // eslint-disable-next-line class-methods-use-this
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
getVariableId(value) {
|
|
35
|
+
// id is based on the slugified value
|
|
36
|
+
return slugify(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled.js","names":["debug","StyledProcessor","hasMeta","slugify","atomize","AtomicStyledProcessor","extractRules","valueCache","cssText","loc","rules","wrappedValue","component","get","node","atomicRules","forEach","rule","start","className","displayName","atom","classes","filter","map","join","getProps","uniqInterpolations","props","class","Boolean","atomic","getVariableId","value"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport type {\n IInterpolation,\n Rules,\n ValueCache,\n} from '@linaria/core/processors/types';\nimport { debug } from '@linaria/logger';\nimport type { IProps } from '@linaria/react/processors/styled';\nimport StyledProcessor, { hasMeta } from '@linaria/react/processors/styled';\nimport { slugify } from '@linaria/utils';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicStyledProcessor extends StyledProcessor {\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\n const rules: Rules = {};\n\n const wrappedValue =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node);\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 const 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, classes];\n }\n\n protected override getProps(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): IProps {\n const props = super.getProps(classes, uniqInterpolations);\n props.class = [classes, this.className].filter(Boolean).join(' ');\n props.atomic = true;\n return props;\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override getVariableId(value: string): string {\n // id is based on the slugified value\n return slugify(value);\n }\n}\n"],"mappings":"AAOA,SAASA,KAAT,QAAsB,iBAAtB;AAEA,OAAOC,eAAP,IAA0BC,OAA1B,QAAyC,kCAAzC;AACA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,OAAOC,OAAP,MAAoB,mBAApB;AAEA,eAAe,MAAMC,qBAAN,SAAoCJ,eAApC,CAAoD;EACjDK,YAAY,CAC1BC,UAD0B,EAE1BC,OAF0B,EAG1BC,GAH0B,EAIT;IACjB,MAAMC,KAAY,GAAG,EAArB;IAEA,MAAMC,YAAY,GAChB,OAAO,KAAKC,SAAZ,KAA0B,QAA1B,GACI,IADJ,GAEIL,UAAU,CAACM,GAAX,CAAe,KAAKD,SAAL,CAAeE,IAA9B,CAHN;IAKA,MAAMC,WAAW,GAAGX,OAAO,CAACI,OAAD,EAAUN,OAAO,CAACS,YAAD,CAAjB,CAA3B;IACAI,WAAW,CAACC,OAAZ,CAAqBC,IAAD,IAAU;MAC5B;MACAP,KAAK,CAACO,IAAI,CAACT,OAAN,CAAL,GAAsB;QACpBA,OAAO,EAAES,IAAI,CAACT,OADM;QAEpBU,KAAK,EAAET,GAAG,EAAES,KAAL,IAAc,IAFD;QAGpBC,SAAS,EAAE,KAAKA,SAHI;QAIpBC,WAAW,EAAE,KAAKA,WAJE;QAKpBC,IAAI,EAAE;MALc,CAAtB;MAQArB,KAAK,CACH,oDADG,EAEF,KAAIiB,IAAI,CAACT,OAAQ,EAFf,CAAL;IAID,CAdD;IAgBA,MAAMc,OAAO,GAAGP,WAAW,CACzB;IADyB,CAExBQ,MAFa,CAELN,IAAD,IAAU,CAAC,CAACA,IAAI,CAACE,SAFX,EAGbK,GAHa,CAGRP,IAAD,IAAUA,IAAI,CAACE,SAHN,EAIbM,IAJa,CAIR,GAJQ,CAAhB;IAMA,OAAO,CAACf,KAAD,EAAQY,OAAR,CAAP;EACD;;EAEkBI,QAAQ,CACzBJ,OADyB,EAEzBK,kBAFyB,EAGjB;IACR,MAAMC,KAAK,GAAG,MAAMF,QAAN,CAAeJ,OAAf,EAAwBK,kBAAxB,CAAd;IACAC,KAAK,CAACC,KAAN,GAAc,CAACP,OAAD,EAAU,KAAKH,SAAf,EAA0BI,MAA1B,CAAiCO,OAAjC,EAA0CL,IAA1C,CAA+C,GAA/C,CAAd;IACAG,KAAK,CAACG,MAAN,GAAe,IAAf;IACA,OAAOH,KAAP;EACD,CA/CgE,CAiDjE;;;EACmBI,aAAa,CAACC,KAAD,EAAwB;IACtD;IACA,OAAO9B,OAAO,CAAC8B,KAAD,CAAd;EACD;;AArDgE"}
|
package/lib/CSSProperties.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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/lib/css.js
CHANGED
package/lib/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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":";;;;;AASO,MAAMA,GAAQ,GAAG,MAAM;EAC5B,MAAM,IAAIC,KAAJ,CACJ,wGADI,CAAN;AAGD,CAJM;;;eAMQD,G"}
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "css", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _css.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "atomize", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _atomize.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "cx", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _utils.cx;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.styled = exports.cx = exports.css = void 0;
|
|
24
5
|
|
|
25
6
|
var _css = _interopRequireDefault(require("./css"));
|
|
26
7
|
|
|
27
|
-
|
|
8
|
+
exports.css = _css.default;
|
|
28
9
|
|
|
29
|
-
var
|
|
10
|
+
var _react = require("@linaria/react");
|
|
11
|
+
|
|
12
|
+
exports.styled = _react.styled;
|
|
13
|
+
|
|
14
|
+
var _core = require("@linaria/core");
|
|
15
|
+
|
|
16
|
+
exports.cx = _core.cx;
|
|
30
17
|
|
|
31
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"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;;;;AACA;;;;AACA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _css = _interopRequireDefault(require("@linaria/core/processors/css"));
|
|
9
|
+
|
|
10
|
+
var _logger = require("@linaria/logger");
|
|
11
|
+
|
|
12
|
+
var _atomize = _interopRequireDefault(require("./helpers/atomize"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
class AtomicCssProcessor extends _css.default {
|
|
17
|
+
extractRules(valueCache, cssText, loc) {
|
|
18
|
+
const rules = {};
|
|
19
|
+
const atomicRules = (0, _atomize.default)(cssText, false);
|
|
20
|
+
atomicRules.forEach(rule => {
|
|
21
|
+
var _loc$start;
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line no-param-reassign
|
|
24
|
+
rules[rule.cssText] = {
|
|
25
|
+
cssText: rule.cssText,
|
|
26
|
+
start: (_loc$start = loc === null || loc === void 0 ? void 0 : loc.start) !== null && _loc$start !== void 0 ? _loc$start : null,
|
|
27
|
+
className: this.className,
|
|
28
|
+
displayName: this.displayName,
|
|
29
|
+
atom: true
|
|
30
|
+
};
|
|
31
|
+
(0, _logger.debug)('evaluator:template-processor:extracted-atomic-rule', `\n${rule.cssText}`);
|
|
32
|
+
});
|
|
33
|
+
const 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, classes];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.default = AtomicCssProcessor;
|
|
41
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","names":["AtomicCssProcessor","CssProcessor","extractRules","valueCache","cssText","loc","rules","atomicRules","atomize","forEach","rule","start","className","displayName","atom","debug","classes","filter","map","join"],"sources":["../../src/processors/css.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport CssProcessor from '@linaria/core/processors/css';\nimport type { Rules, ValueCache } from '@linaria/core/processors/types';\nimport { debug } from '@linaria/logger';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicCssProcessor extends CssProcessor {\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\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 const 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, classes];\n }\n}\n"],"mappings":";;;;;;;AAEA;;AAEA;;AAEA;;;;AAEe,MAAMA,kBAAN,SAAiCC,YAAjC,CAA8C;EAC3CC,YAAY,CAC1BC,UAD0B,EAE1BC,OAF0B,EAG1BC,GAH0B,EAIT;IACjB,MAAMC,KAAY,GAAG,EAArB;IAEA,MAAMC,WAAW,GAAG,IAAAC,gBAAA,EAAQJ,OAAR,EAAiB,KAAjB,CAApB;IACAG,WAAW,CAACE,OAAZ,CAAqBC,IAAD,IAAU;MAAA;;MAC5B;MACAJ,KAAK,CAACI,IAAI,CAACN,OAAN,CAAL,GAAsB;QACpBA,OAAO,EAAEM,IAAI,CAACN,OADM;QAEpBO,KAAK,gBAAEN,GAAF,aAAEA,GAAF,uBAAEA,GAAG,CAAEM,KAAP,mDAAgB,IAFD;QAGpBC,SAAS,EAAE,KAAKA,SAHI;QAIpBC,WAAW,EAAE,KAAKA,WAJE;QAKpBC,IAAI,EAAE;MALc,CAAtB;MAQA,IAAAC,aAAA,EACE,oDADF,EAEG,KAAIL,IAAI,CAACN,OAAQ,EAFpB;IAID,CAdD;IAgBA,MAAMY,OAAO,GAAGT,WAAW,CACzB;IADyB,CAExBU,MAFa,CAELP,IAAD,IAAU,CAAC,CAACA,IAAI,CAACE,SAFX,EAGbM,GAHa,CAGRR,IAAD,IAAUA,IAAI,CAACE,SAHN,EAIbO,IAJa,CAIR,GAJQ,CAAhB;IAMA,OAAO,CAACb,KAAD,EAAQU,OAAR,CAAP;EACD;;AAhC0D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = atomize;
|
|
7
|
+
|
|
8
|
+
var _knownCssProperties = require("known-css-properties");
|
|
9
|
+
|
|
10
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
11
|
+
|
|
12
|
+
var _stylis = _interopRequireDefault(require("stylis"));
|
|
13
|
+
|
|
14
|
+
var _utils = require("@linaria/utils");
|
|
15
|
+
|
|
16
|
+
var _propertyPriority = require("./propertyPriority");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const knownPropertiesMap = _knownCssProperties.all.reduce((acc, property, i) => {
|
|
21
|
+
acc[property] = i;
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
|
|
25
|
+
function hashProperty(property) {
|
|
26
|
+
const index = knownPropertiesMap[property]; // If it's a known property, let's use the index to cut down the length of the hash.
|
|
27
|
+
// otherwise, slugify
|
|
28
|
+
|
|
29
|
+
if (index !== undefined) {
|
|
30
|
+
return index.toString(36); // base 36 so that we get a-z,0-9
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (0, _utils.slugify)(property);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const parseCss = cssText => {
|
|
37
|
+
try {
|
|
38
|
+
return _postcss.default.parse(cssText);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof Error) {
|
|
41
|
+
throw new Error(`Error parsing CSS: ${e.message}\nCSS:\n${cssText}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error(`Unknown error parsing CSS.\nCSS:\n${cssText}`);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function atomize(cssText, hasPriority = false) {
|
|
49
|
+
_stylis.default.set({
|
|
50
|
+
prefix: false,
|
|
51
|
+
keyframe: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const atomicRules = [];
|
|
55
|
+
const stylesheet = parseCss(cssText); // We want to extract all keyframes and leave them as-is.
|
|
56
|
+
// This isn't scoped locally yet
|
|
57
|
+
|
|
58
|
+
stylesheet.walkAtRules('keyframes', atRule => {
|
|
59
|
+
atRule.remove();
|
|
60
|
+
atomicRules.push({
|
|
61
|
+
property: atRule.name,
|
|
62
|
+
cssText: atRule.toString()
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
stylesheet.walkDecls(decl => {
|
|
66
|
+
let thisParent = decl.parent;
|
|
67
|
+
const parents = [];
|
|
68
|
+
const atomicProperty = [decl.prop];
|
|
69
|
+
let hasAtRule = false; // Traverse the declarations parents, and collect them all.
|
|
70
|
+
|
|
71
|
+
while (thisParent && thisParent !== stylesheet) {
|
|
72
|
+
parents.unshift(thisParent);
|
|
73
|
+
|
|
74
|
+
if (thisParent.type === 'atrule') {
|
|
75
|
+
hasAtRule = true; // @media queries, @supports etc.
|
|
76
|
+
|
|
77
|
+
atomicProperty.push(thisParent.name, thisParent.params);
|
|
78
|
+
} else if (thisParent.type === 'rule') {
|
|
79
|
+
// pseudo classes etc.
|
|
80
|
+
atomicProperty.push(thisParent.selector);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
thisParent = thisParent.parent;
|
|
84
|
+
} // Create a new stylesheet that contains *just* the extracted atomic rule and wrapping selectors, eg.
|
|
85
|
+
// `@media (max-width: 400px) { background: red; }`, or
|
|
86
|
+
// `&:hover { background: red; }`, or
|
|
87
|
+
// `background: red;`
|
|
88
|
+
// We do this so we can run it through stylis, to produce a full atom, eg.
|
|
89
|
+
// `@media (max-width: 400px) { .atm_foo { background: red; } }`
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const root = _postcss.default.root();
|
|
93
|
+
|
|
94
|
+
let container = root;
|
|
95
|
+
parents.forEach(parent => {
|
|
96
|
+
const newNode = parent.clone();
|
|
97
|
+
newNode.removeAll();
|
|
98
|
+
container.append(newNode);
|
|
99
|
+
container = newNode;
|
|
100
|
+
});
|
|
101
|
+
container.append(decl.clone());
|
|
102
|
+
const css = root.toString();
|
|
103
|
+
const propertySlug = hashProperty([...atomicProperty].join(';'));
|
|
104
|
+
const valueSlug = (0, _utils.slugify)(decl.value);
|
|
105
|
+
const className = `atm_${propertySlug}_${valueSlug}`;
|
|
106
|
+
const propertyPriority = (0, _propertyPriority.getPropertyPriority)(decl.prop) + (hasAtRule ? 1 : 0) + (hasPriority ? 1 : 0);
|
|
107
|
+
const processedCss = (0, _stylis.default)(`.${className}`.repeat(propertyPriority), css);
|
|
108
|
+
atomicRules.push({
|
|
109
|
+
property: atomicProperty.join(' '),
|
|
110
|
+
className,
|
|
111
|
+
cssText: processedCss
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return atomicRules;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=atomize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomize.js","names":["knownPropertiesMap","knownProperties","reduce","acc","property","i","hashProperty","index","undefined","toString","slugify","parseCss","cssText","postcss","parse","e","Error","message","atomize","hasPriority","stylis","set","prefix","keyframe","atomicRules","stylesheet","walkAtRules","atRule","remove","push","name","walkDecls","decl","thisParent","parent","parents","atomicProperty","prop","hasAtRule","unshift","type","params","selector","root","container","forEach","newNode","clone","removeAll","append","css","propertySlug","join","valueSlug","value","className","propertyPriority","getPropertyPriority","processedCss","repeat"],"sources":["../../../src/processors/helpers/atomize.ts"],"sourcesContent":["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"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;;AAEA;;;;AAEA,MAAMA,kBAAkB,GAAGC,uBAAA,CAAgBC,MAAhB,CACzB,CAACC,GAAD,EAAsCC,QAAtC,EAAgDC,CAAhD,KAAsD;EACpDF,GAAG,CAACC,QAAD,CAAH,GAAgBC,CAAhB;EACA,OAAOF,GAAP;AACD,CAJwB,EAKzB,EALyB,CAA3B;;AAQA,SAASG,YAAT,CAAsBF,QAAtB,EAAwC;EACtC,MAAMG,KAAK,GAAGP,kBAAkB,CAACI,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,GAAG,CAAH,GAAO,CADjB,KAECnB,WAAW,GAAG,CAAH,GAAO,CAFnB,CADF;IAIA,MAAMuC,YAAY,GAAG,IAAAtC,eAAA,EAAQ,IAAGmC,SAAU,EAAd,CAAgBI,MAAhB,CAAuBH,gBAAvB,CAAP,EAAiDN,GAAjD,CAArB;IAEA1B,WAAW,CAACK,IAAZ,CAAiB;MACfzB,QAAQ,EAAEgC,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;MAEfG,SAFe;MAGf3C,OAAO,EAAE8C;IAHM,CAAjB;EAKD,CAxDD;EA0DA,OAAOlC,WAAP;AACD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPropertyPriority = getPropertyPriority;
|
|
7
|
+
const shorthandProperties = {
|
|
8
|
+
// The `all` property resets everything, and should effectively have priority zero.
|
|
9
|
+
// 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
|
|
10
|
+
// 'all': []
|
|
11
|
+
animation: ['animation-name', 'animation-duration', 'animation-timing-function', 'animation-delay', 'animation-iteration-count', 'animation-direction', 'animation-fill-mode', 'animation-play-state'],
|
|
12
|
+
background: ['background-attachment', 'background-clip', 'background-color', 'background-image', 'background-origin', 'background-position', 'background-repeat', 'background-size'],
|
|
13
|
+
border: ['border-color', 'border-style', 'border-width'],
|
|
14
|
+
'border-block-end': ['border-block-end-color', 'border-block-end-style', 'border-block-end-width'],
|
|
15
|
+
'border-block-start': ['border-block-start-color', 'border-block-start-style', 'border-block-start-width'],
|
|
16
|
+
'border-bottom': ['border-bottom-color', 'border-bottom-style', 'border-bottom-width'],
|
|
17
|
+
'border-color': ['border-bottom-color', 'border-left-color', 'border-right-color', 'border-top-color'],
|
|
18
|
+
'border-image': ['border-image-outset', 'border-image-repeat', 'border-image-slice', 'border-image-source', 'border-image-width'],
|
|
19
|
+
'border-inline-end': ['border-inline-end-color', 'border-inline-end-style', 'border-inline-end-width'],
|
|
20
|
+
'border-inline-start': ['border-inline-start-color', 'border-inline-start-style', 'border-inline-start-width'],
|
|
21
|
+
'border-left': ['border-left-color', 'border-left-style', 'border-left-width'],
|
|
22
|
+
'border-radius': ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius'],
|
|
23
|
+
'border-right': ['border-right-color', 'border-right-style', 'border-right-width'],
|
|
24
|
+
'border-style': ['border-bottom-style', 'border-left-style', 'border-right-style', 'border-top-style'],
|
|
25
|
+
'border-top': ['border-top-color', 'border-top-style', 'border-top-width'],
|
|
26
|
+
'border-width': ['border-bottom-width', 'border-left-width', 'border-right-width', 'border-top-width'],
|
|
27
|
+
'column-rule': ['column-rule-width', 'column-rule-style', 'column-rule-color'],
|
|
28
|
+
columns: ['column-count', 'column-width'],
|
|
29
|
+
flex: ['flex-grow', 'flex-shrink', 'flex-basis'],
|
|
30
|
+
'flex-flow': ['flex-direction', 'flex-wrap'],
|
|
31
|
+
font: ['font-family', 'font-size', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'line-height'],
|
|
32
|
+
gap: ['row-gap', 'column-gap'],
|
|
33
|
+
grid: ['grid-auto-columns', 'grid-auto-flow', 'grid-auto-rows', 'grid-template-areas', 'grid-template-columns', 'grid-template-rows'],
|
|
34
|
+
'grid-area': ['grid-row-start', 'grid-column-start', 'grid-row-end', 'grid-column-end'],
|
|
35
|
+
'grid-column': ['grid-column-end', 'grid-column-start'],
|
|
36
|
+
'grid-row': ['grid-row-end', 'grid-row-start'],
|
|
37
|
+
'grid-template': ['grid-template-areas', 'grid-template-columns', 'grid-template-rows'],
|
|
38
|
+
'list-style': ['list-style-image', 'list-style-position', 'list-style-type'],
|
|
39
|
+
margin: ['margin-bottom', 'margin-left', 'margin-right', 'margin-top'],
|
|
40
|
+
mask: ['mask-clip', 'mask-composite', 'mask-image', 'mask-mode', 'mask-origin', 'mask-position', 'mask-repeat', 'mask-size'],
|
|
41
|
+
offset: ['offset-anchor', 'offset-distance', 'offset-path', 'offset-position', 'offset-rotate'],
|
|
42
|
+
outline: ['outline-color', 'outline-style', 'outline-width'],
|
|
43
|
+
overflow: ['overflow-x', 'overflow-y'],
|
|
44
|
+
padding: ['padding-bottom', 'padding-left', 'padding-right', 'padding-top'],
|
|
45
|
+
'place-content': ['align-content', 'justify-content'],
|
|
46
|
+
'place-items': ['align-items', 'justify-items'],
|
|
47
|
+
'place-self': ['align-self', 'justify-self'],
|
|
48
|
+
'scroll-margin': ['scroll-margin-bottom', 'scroll-margin-left', 'scroll-margin-right', 'scroll-margin-top'],
|
|
49
|
+
'scroll-padding': ['scroll-padding-bottom', 'scroll-padding-left', 'scroll-padding-right', 'scroll-padding-top'],
|
|
50
|
+
'text-decoration': ['text-decoration-color', 'text-decoration-line', 'text-decoration-style', 'text-decoration-thickness'],
|
|
51
|
+
'text-emphasis': ['text-emphasis-color', 'text-emphasis-style'],
|
|
52
|
+
transition: ['transition-delay', 'transition-duration', 'transition-property', 'transition-timing-function']
|
|
53
|
+
}; // Get the property priority: the higher the priority, the higher the resulting
|
|
54
|
+
// specificity of the atom. For example, if we had:
|
|
55
|
+
//
|
|
56
|
+
// import { css } from '@linaria/atomic';
|
|
57
|
+
// css`
|
|
58
|
+
// background-color: blue;
|
|
59
|
+
// background: red;
|
|
60
|
+
// `;
|
|
61
|
+
//
|
|
62
|
+
// we would produce:
|
|
63
|
+
//
|
|
64
|
+
// .atm_a.atm_a { background-color: blue }
|
|
65
|
+
// .atm_b { background: red }
|
|
66
|
+
//
|
|
67
|
+
// and so the more specific selector (.atm_a.atm_a) would win
|
|
68
|
+
|
|
69
|
+
function getPropertyPriority(property) {
|
|
70
|
+
const longhands = Object.values(shorthandProperties).reduce((a, b) => [...a, ...b], []);
|
|
71
|
+
return longhands.includes(property) ? 2 : 1;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=propertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyPriority.js","names":["shorthandProperties","animation","background","border","columns","flex","font","gap","grid","margin","mask","offset","outline","overflow","padding","transition","getPropertyPriority","property","longhands","Object","values","reduce","a","b","includes"],"sources":["../../../src/processors/helpers/propertyPriority.ts"],"sourcesContent":["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":";;;;;;AAAA,MAAMA,mBAAmB,GAAG;EAC1B;EACA;EACA;EACAC,SAAS,EAAE,CACT,gBADS,EAET,oBAFS,EAGT,2BAHS,EAIT,iBAJS,EAKT,2BALS,EAMT,qBANS,EAOT,qBAPS,EAQT,sBARS,CAJe;EAc1BC,UAAU,EAAE,CACV,uBADU,EAEV,iBAFU,EAGV,kBAHU,EAIV,kBAJU,EAKV,mBALU,EAMV,qBANU,EAOV,mBAPU,EAQV,iBARU,CAdc;EAwB1BC,MAAM,EAAE,CAAC,cAAD,EAAiB,cAAjB,EAAiC,cAAjC,CAxBkB;EAyB1B,oBAAoB,CAClB,wBADkB,EAElB,wBAFkB,EAGlB,wBAHkB,CAzBM;EA8B1B,sBAAsB,CACpB,0BADoB,EAEpB,0BAFoB,EAGpB,0BAHoB,CA9BI;EAmC1B,iBAAiB,CACf,qBADe,EAEf,qBAFe,EAGf,qBAHe,CAnCS;EAwC1B,gBAAgB,CACd,qBADc,EAEd,mBAFc,EAGd,oBAHc,EAId,kBA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BAHU,EAIV,4BAJU;AA/Kc,CAA5B,C,CAuLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,MAAMC,SAAS,GAAGC,MAAM,CAACC,MAAP,CAAcpB,mBAAd,EAAmCqB,MAAnC,CAChB,CAACC,CAAD,EAAIC,CAAJ,KAAU,CAAC,GAAGD,CAAJ,EAAO,GAAGC,CAAV,CADM,EAEhB,EAFgB,CAAlB;EAKA,OAAOL,SAAS,CAACM,QAAV,CAAmBP,QAAnB,IAA+B,CAA/B,GAAmC,CAA1C;AACD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _logger = require("@linaria/logger");
|
|
9
|
+
|
|
10
|
+
var _styled = _interopRequireWildcard(require("@linaria/react/processors/styled"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("@linaria/utils");
|
|
13
|
+
|
|
14
|
+
var _atomize = _interopRequireDefault(require("./helpers/atomize"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
class AtomicStyledProcessor extends _styled.default {
|
|
23
|
+
extractRules(valueCache, cssText, loc) {
|
|
24
|
+
const rules = {};
|
|
25
|
+
const wrappedValue = typeof this.component === 'string' ? null : valueCache.get(this.component.node);
|
|
26
|
+
const atomicRules = (0, _atomize.default)(cssText, (0, _styled.hasMeta)(wrappedValue));
|
|
27
|
+
atomicRules.forEach(rule => {
|
|
28
|
+
var _loc$start;
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line no-param-reassign
|
|
31
|
+
rules[rule.cssText] = {
|
|
32
|
+
cssText: rule.cssText,
|
|
33
|
+
start: (_loc$start = loc === null || loc === void 0 ? void 0 : loc.start) !== null && _loc$start !== void 0 ? _loc$start : null,
|
|
34
|
+
className: this.className,
|
|
35
|
+
displayName: this.displayName,
|
|
36
|
+
atom: true
|
|
37
|
+
};
|
|
38
|
+
(0, _logger.debug)('evaluator:template-processor:extracted-atomic-rule', `\n${rule.cssText}`);
|
|
39
|
+
});
|
|
40
|
+
const classes = atomicRules // Some atomic rules produced (eg. keyframes) don't have class names, and they also don't need to appear in the object
|
|
41
|
+
.filter(rule => !!rule.className).map(rule => rule.className).join(' ');
|
|
42
|
+
return [rules, classes];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getProps(classes, uniqInterpolations) {
|
|
46
|
+
const props = super.getProps(classes, uniqInterpolations);
|
|
47
|
+
props.class = [classes, this.className].filter(Boolean).join(' ');
|
|
48
|
+
props.atomic = true;
|
|
49
|
+
return props;
|
|
50
|
+
} // eslint-disable-next-line class-methods-use-this
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
getVariableId(value) {
|
|
54
|
+
// id is based on the slugified value
|
|
55
|
+
return (0, _utils.slugify)(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.default = AtomicStyledProcessor;
|
|
61
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled.js","names":["AtomicStyledProcessor","StyledProcessor","extractRules","valueCache","cssText","loc","rules","wrappedValue","component","get","node","atomicRules","atomize","hasMeta","forEach","rule","start","className","displayName","atom","debug","classes","filter","map","join","getProps","uniqInterpolations","props","class","Boolean","atomic","getVariableId","value","slugify"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type { SourceLocation } from '@babel/types';\n\nimport type {\n IInterpolation,\n Rules,\n ValueCache,\n} from '@linaria/core/processors/types';\nimport { debug } from '@linaria/logger';\nimport type { IProps } from '@linaria/react/processors/styled';\nimport StyledProcessor, { hasMeta } from '@linaria/react/processors/styled';\nimport { slugify } from '@linaria/utils';\n\nimport atomize from './helpers/atomize';\n\nexport default class AtomicStyledProcessor extends StyledProcessor {\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\n const rules: Rules = {};\n\n const wrappedValue =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node);\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 const 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, classes];\n }\n\n protected override getProps(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): IProps {\n const props = super.getProps(classes, uniqInterpolations);\n props.class = [classes, this.className].filter(Boolean).join(' ');\n props.atomic = true;\n return props;\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override getVariableId(value: string): string {\n // id is based on the slugified value\n return slugify(value);\n }\n}\n"],"mappings":";;;;;;;AAOA;;AAEA;;AACA;;AAEA;;;;;;;;AAEe,MAAMA,qBAAN,SAAoCC,eAApC,CAAoD;EACjDC,YAAY,CAC1BC,UAD0B,EAE1BC,OAF0B,EAG1BC,GAH0B,EAIT;IACjB,MAAMC,KAAY,GAAG,EAArB;IAEA,MAAMC,YAAY,GAChB,OAAO,KAAKC,SAAZ,KAA0B,QAA1B,GACI,IADJ,GAEIL,UAAU,CAACM,GAAX,CAAe,KAAKD,SAAL,CAAeE,IAA9B,CAHN;IAKA,MAAMC,WAAW,GAAG,IAAAC,gBAAA,EAAQR,OAAR,EAAiB,IAAAS,eAAA,EAAQN,YAAR,CAAjB,CAApB;IACAI,WAAW,CAACG,OAAZ,CAAqBC,IAAD,IAAU;MAAA;;MAC5B;MACAT,KAAK,CAACS,IAAI,CAACX,OAAN,CAAL,GAAsB;QACpBA,OAAO,EAAEW,IAAI,CAACX,OADM;QAEpBY,KAAK,gBAAEX,GAAF,aAAEA,GAAF,uBAAEA,GAAG,CAAEW,KAAP,mDAAgB,IAFD;QAGpBC,SAAS,EAAE,KAAKA,SAHI;QAIpBC,WAAW,EAAE,KAAKA,WAJE;QAKpBC,IAAI,EAAE;MALc,CAAtB;MAQA,IAAAC,aAAA,EACE,oDADF,EAEG,KAAIL,IAAI,CAACX,OAAQ,EAFpB;IAID,CAdD;IAgBA,MAAMiB,OAAO,GAAGV,WAAW,CACzB;IADyB,CAExBW,MAFa,CAELP,IAAD,IAAU,CAAC,CAACA,IAAI,CAACE,SAFX,EAGbM,GAHa,CAGRR,IAAD,IAAUA,IAAI,CAACE,SAHN,EAIbO,IAJa,CAIR,GAJQ,CAAhB;IAMA,OAAO,CAAClB,KAAD,EAAQe,OAAR,CAAP;EACD;;EAEkBI,QAAQ,CACzBJ,OADyB,EAEzBK,kBAFyB,EAGjB;IACR,MAAMC,KAAK,GAAG,MAAMF,QAAN,CAAeJ,OAAf,EAAwBK,kBAAxB,CAAd;IACAC,KAAK,CAACC,KAAN,GAAc,CAACP,OAAD,EAAU,KAAKJ,SAAf,EAA0BK,MAA1B,CAAiCO,OAAjC,EAA0CL,IAA1C,CAA+C,GAA/C,CAAd;IACAG,KAAK,CAACG,MAAN,GAAe,IAAf;IACA,OAAOH,KAAP;EACD,CA/CgE,CAiDjE;;;EACmBI,aAAa,CAACC,KAAD,EAAwB;IACtD;IACA,OAAO,IAAAC,cAAA,EAAQD,KAAR,CAAP;EACD;;AArDgE"}
|
package/package.json
CHANGED
|
@@ -1,44 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linaria/atomic",
|
|
3
|
-
"version": "3.0.0-beta.15",
|
|
4
|
-
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
6
|
-
},
|
|
7
3
|
"description": "Blazing fast zero-runtime CSS in JS library",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
4
|
+
"version": "3.0.0-beta.20",
|
|
5
|
+
"bugs": "https://github.com/callstack/linaria/issues",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@linaria/core": "^3.0.0-beta.20",
|
|
8
|
+
"@linaria/logger": "^3.0.0-beta.20",
|
|
9
|
+
"@linaria/react": "^3.0.0-beta.20",
|
|
10
|
+
"@linaria/utils": "^3.0.0-beta.20",
|
|
11
|
+
"known-css-properties": "^0.24.0",
|
|
12
|
+
"postcss": "^8.3.11",
|
|
13
|
+
"stylis": "^3.5.4",
|
|
14
|
+
"ts-invariant": "^0.10.3"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@babel/types": "^7.18.4"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": "^12.16.0 || >=13.7.0"
|
|
21
|
+
},
|
|
12
22
|
"files": [
|
|
13
23
|
"types/",
|
|
14
24
|
"lib/",
|
|
15
25
|
"esm/"
|
|
16
26
|
],
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"repository": "git@github.com:callstack/linaria.git",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/callstack/linaria/issues"
|
|
21
|
-
},
|
|
22
27
|
"homepage": "https://github.com/callstack/linaria#readme",
|
|
23
28
|
"keywords": [
|
|
24
|
-
"react",
|
|
25
|
-
"linaria",
|
|
26
29
|
"css",
|
|
27
30
|
"css-in-js",
|
|
31
|
+
"linaria",
|
|
32
|
+
"react",
|
|
28
33
|
"styled-components"
|
|
29
34
|
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"linaria": {
|
|
37
|
+
"tags": {
|
|
38
|
+
"css": "./lib/processors/css.js",
|
|
39
|
+
"styled": "./lib/processors/styled.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"main": "lib/index.js",
|
|
43
|
+
"module": "esm/index.js",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"repository": "git@github.com:callstack/linaria.git",
|
|
48
|
+
"sideEffects": false,
|
|
49
|
+
"types": "types/index.d.ts",
|
|
30
50
|
"scripts": {
|
|
31
|
-
"build
|
|
32
|
-
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
33
|
-
"build": "yarn build:lib && yarn build:esm",
|
|
51
|
+
"build": "npm run build:lib && npm run build:esm && npm run build:declarations",
|
|
34
52
|
"build:declarations": "tsc --emitDeclarationOnly --outDir types",
|
|
35
|
-
"
|
|
53
|
+
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
54
|
+
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
36
55
|
"typecheck": "tsc --noEmit --composite false",
|
|
37
|
-
"watch": "
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
"@linaria/utils": "^3.0.0-beta.15",
|
|
41
|
-
"postcss": "^8.3.11"
|
|
42
|
-
},
|
|
43
|
-
"gitHead": "a8ada3794c6e13231f70711d92b516d57677a5b1"
|
|
44
|
-
}
|
|
56
|
+
"watch": "npm run build --watch"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/types/css.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import type { LinariaClassName } from '@linaria/core';
|
|
1
2
|
import type { CSSProperties } from './CSSProperties';
|
|
2
|
-
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
}
|
|
5
|
-
declare type CSS = (strings: TemplateStringsArray, ...exprs: Array<string | number | CSSProperties>) => StyleCollectionObject;
|
|
3
|
+
declare type CSS = (strings: TemplateStringsArray, ...exprs: Array<string | number | CSSProperties>) => LinariaClassName;
|
|
6
4
|
export declare const css: CSS;
|
|
7
5
|
export default css;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { default as css } from './css';
|
|
2
|
-
export {
|
|
3
|
-
export { cx } from '@linaria/
|
|
2
|
+
export { styled } from '@linaria/react';
|
|
3
|
+
export { cx } from '@linaria/core';
|
|
4
4
|
export type { CSSProperties } from './CSSProperties';
|
|
5
|
-
export type { StyleCollectionObject } from './css';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceLocation } from '@babel/types';
|
|
2
|
+
import CssProcessor from '@linaria/core/processors/css';
|
|
3
|
+
import type { Rules, ValueCache } from '@linaria/core/processors/types';
|
|
4
|
+
export default class AtomicCssProcessor extends CssProcessor {
|
|
5
|
+
extractRules(valueCache: ValueCache, cssText: string, loc?: SourceLocation | null): [Rules, string];
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPropertyPriority(property: string): 1 | 2;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SourceLocation } from '@babel/types';
|
|
2
|
+
import type { IInterpolation, Rules, ValueCache } from '@linaria/core/processors/types';
|
|
3
|
+
import type { IProps } from '@linaria/react/processors/styled';
|
|
4
|
+
import StyledProcessor from '@linaria/react/processors/styled';
|
|
5
|
+
export default class AtomicStyledProcessor extends StyledProcessor {
|
|
6
|
+
extractRules(valueCache: ValueCache, cssText: string, loc?: SourceLocation | null): [Rules, string];
|
|
7
|
+
protected getProps(classes: string, uniqInterpolations: IInterpolation[]): IProps;
|
|
8
|
+
protected getVariableId(value: string): string;
|
|
9
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [3.0.0-beta.15](https://github.com/callstack/linaria/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2021-11-29)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
* **atomic:** create an atomic package for the css API ([#867](https://github.com/callstack/linaria/issues/867)) ([4773bcf](https://github.com/callstack/linaria/commit/4773bcf4b14f08cdc4d2b612654b962cdfc97eaa))
|
package/esm/atomize.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import postcss from 'postcss';
|
|
2
|
-
import { slugify } from '@linaria/utils';
|
|
3
|
-
export default function atomize(cssText) {
|
|
4
|
-
const atomicRules = [];
|
|
5
|
-
const stylesheet = postcss.parse(cssText);
|
|
6
|
-
stylesheet.walkDecls(decl => {
|
|
7
|
-
const parent = decl.parent;
|
|
8
|
-
|
|
9
|
-
if (parent === stylesheet) {
|
|
10
|
-
const line = `${decl.prop}: ${decl.value};`;
|
|
11
|
-
const className = `atm_${slugify(line)}`;
|
|
12
|
-
atomicRules.push({
|
|
13
|
-
property: decl.prop,
|
|
14
|
-
className,
|
|
15
|
-
cssText: line
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}); // Things like @media rules
|
|
19
|
-
|
|
20
|
-
stylesheet.walkAtRules(atRule => {
|
|
21
|
-
atRule.walkDecls(decl => {
|
|
22
|
-
const slug = slugify([atRule.name, atRule.params, decl.prop, decl.value].join(';'));
|
|
23
|
-
const className = `atm_${slug}`;
|
|
24
|
-
atomicRules.push({
|
|
25
|
-
// For @ rules we want the unique property we do merging on to contain
|
|
26
|
-
// the atrule params, eg. `media only screen and (max-width: 600px)`
|
|
27
|
-
// But not the value. That way, our hashes will match when the media rule +
|
|
28
|
-
// the declaration property match, and we can merge atomic media rules
|
|
29
|
-
property: [atRule.name, atRule.params, decl.prop].join(' '),
|
|
30
|
-
className,
|
|
31
|
-
cssText: `@${atRule.name} ${atRule.params} { .${className} { ${decl.prop}: ${decl.value}; } }`
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
return atomicRules;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=atomize.js.map
|
package/esm/atomize.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atomize.ts"],"names":["postcss","slugify","atomize","cssText","atomicRules","stylesheet","parse","walkDecls","decl","parent","line","prop","value","className","push","property","walkAtRules","atRule","slug","name","params","join"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,SAApB;AACA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,eAAe,SAASC,OAAT,CAAiBC,OAAjB,EAAkC;AAC/C,QAAMC,WAIH,GAAG,EAJN;AAMA,QAAMC,UAAU,GAAGL,OAAO,CAACM,KAAR,CAAcH,OAAd,CAAnB;AAEAE,EAAAA,UAAU,CAACE,SAAX,CAAsBC,IAAD,IAAU;AAC7B,UAAMC,MAAM,GAAGD,IAAI,CAACC,MAApB;;AACA,QAAIA,MAAM,KAAKJ,UAAf,EAA2B;AACzB,YAAMK,IAAI,GAAI,GAAEF,IAAI,CAACG,IAAK,KAAIH,IAAI,CAACI,KAAM,GAAzC;AACA,YAAMC,SAAS,GAAI,OAAMZ,OAAO,CAACS,IAAD,CAAO,EAAvC;AACAN,MAAAA,WAAW,CAACU,IAAZ,CAAiB;AACfC,QAAAA,QAAQ,EAAEP,IAAI,CAACG,IADA;AAEfE,QAAAA,SAFe;AAGfV,QAAAA,OAAO,EAAEO;AAHM,OAAjB;AAKD;AACF,GAXD,EAT+C,CAqB/C;;AACAL,EAAAA,UAAU,CAACW,WAAX,CAAwBC,MAAD,IAAY;AACjCA,IAAAA,MAAM,CAACV,SAAP,CAAkBC,IAAD,IAAU;AACzB,YAAMU,IAAI,GAAGjB,OAAO,CAClB,CAACgB,MAAM,CAACE,IAAR,EAAcF,MAAM,CAACG,MAArB,EAA6BZ,IAAI,CAACG,IAAlC,EAAwCH,IAAI,CAACI,KAA7C,EAAoDS,IAApD,CAAyD,GAAzD,CADkB,CAApB;AAGA,YAAMR,SAAS,GAAI,OAAMK,IAAK,EAA9B;AACAd,MAAAA,WAAW,CAACU,IAAZ,CAAiB;AACf;AACA;AACA;AACA;AACAC,QAAAA,QAAQ,EAAE,CAACE,MAAM,CAACE,IAAR,EAAcF,MAAM,CAACG,MAArB,EAA6BZ,IAAI,CAACG,IAAlC,EAAwCU,IAAxC,CAA6C,GAA7C,CALK;AAMfR,QAAAA,SANe;AAOfV,QAAAA,OAAO,EAAG,IAAGc,MAAM,CAACE,IAAK,IAAGF,MAAM,CAACG,MAAO,OAAMP,SAAU,MAAKL,IAAI,CAACG,IAAK,KAAIH,IAAI,CAACI,KAAM;AAPzE,OAAjB;AASD,KAdD;AAeD,GAhBD;AAkBA,SAAOR,WAAP;AACD","sourcesContent":["import postcss from 'postcss';\nimport { slugify } from '@linaria/utils';\n\nexport default function atomize(cssText: string) {\n const atomicRules: {\n className: string;\n cssText: string;\n property: string;\n }[] = [];\n\n const stylesheet = postcss.parse(cssText);\n\n stylesheet.walkDecls((decl) => {\n const parent = decl.parent;\n if (parent === stylesheet) {\n const line = `${decl.prop}: ${decl.value};`;\n const className = `atm_${slugify(line)}`;\n atomicRules.push({\n property: decl.prop,\n className,\n cssText: line,\n });\n }\n });\n // Things like @media rules\n stylesheet.walkAtRules((atRule) => {\n atRule.walkDecls((decl) => {\n const slug = slugify(\n [atRule.name, atRule.params, decl.prop, decl.value].join(';')\n );\n const className = `atm_${slug}`;\n atomicRules.push({\n // For @ rules we want the unique property we do merging on to contain\n // the atrule params, eg. `media only screen and (max-width: 600px)`\n // But not the value. That way, our hashes will match when the media rule +\n // the declaration property match, and we can merge atomic media rules\n property: [atRule.name, atRule.params, decl.prop].join(' '),\n className,\n cssText: `@${atRule.name} ${atRule.params} { .${className} { ${decl.prop}: ${decl.value}; } }`,\n });\n });\n });\n\n return atomicRules;\n}\n"],"file":"atomize.js"}
|
package/lib/atomize.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = atomize;
|
|
7
|
-
|
|
8
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
-
|
|
10
|
-
var _utils = require("@linaria/utils");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function atomize(cssText) {
|
|
15
|
-
const atomicRules = [];
|
|
16
|
-
|
|
17
|
-
const stylesheet = _postcss.default.parse(cssText);
|
|
18
|
-
|
|
19
|
-
stylesheet.walkDecls(decl => {
|
|
20
|
-
const parent = decl.parent;
|
|
21
|
-
|
|
22
|
-
if (parent === stylesheet) {
|
|
23
|
-
const line = `${decl.prop}: ${decl.value};`;
|
|
24
|
-
const className = `atm_${(0, _utils.slugify)(line)}`;
|
|
25
|
-
atomicRules.push({
|
|
26
|
-
property: decl.prop,
|
|
27
|
-
className,
|
|
28
|
-
cssText: line
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}); // Things like @media rules
|
|
32
|
-
|
|
33
|
-
stylesheet.walkAtRules(atRule => {
|
|
34
|
-
atRule.walkDecls(decl => {
|
|
35
|
-
const slug = (0, _utils.slugify)([atRule.name, atRule.params, decl.prop, decl.value].join(';'));
|
|
36
|
-
const className = `atm_${slug}`;
|
|
37
|
-
atomicRules.push({
|
|
38
|
-
// For @ rules we want the unique property we do merging on to contain
|
|
39
|
-
// the atrule params, eg. `media only screen and (max-width: 600px)`
|
|
40
|
-
// But not the value. That way, our hashes will match when the media rule +
|
|
41
|
-
// the declaration property match, and we can merge atomic media rules
|
|
42
|
-
property: [atRule.name, atRule.params, decl.prop].join(' '),
|
|
43
|
-
className,
|
|
44
|
-
cssText: `@${atRule.name} ${atRule.params} { .${className} { ${decl.prop}: ${decl.value}; } }`
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return atomicRules;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=atomize.js.map
|
package/lib/atomize.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atomize.ts"],"names":["atomize","cssText","atomicRules","stylesheet","postcss","parse","walkDecls","decl","parent","line","prop","value","className","push","property","walkAtRules","atRule","slug","name","params","join"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEe,SAASA,OAAT,CAAiBC,OAAjB,EAAkC;AAC/C,QAAMC,WAIH,GAAG,EAJN;;AAMA,QAAMC,UAAU,GAAGC,iBAAQC,KAAR,CAAcJ,OAAd,CAAnB;;AAEAE,EAAAA,UAAU,CAACG,SAAX,CAAsBC,IAAD,IAAU;AAC7B,UAAMC,MAAM,GAAGD,IAAI,CAACC,MAApB;;AACA,QAAIA,MAAM,KAAKL,UAAf,EAA2B;AACzB,YAAMM,IAAI,GAAI,GAAEF,IAAI,CAACG,IAAK,KAAIH,IAAI,CAACI,KAAM,GAAzC;AACA,YAAMC,SAAS,GAAI,OAAM,oBAAQH,IAAR,CAAc,EAAvC;AACAP,MAAAA,WAAW,CAACW,IAAZ,CAAiB;AACfC,QAAAA,QAAQ,EAAEP,IAAI,CAACG,IADA;AAEfE,QAAAA,SAFe;AAGfX,QAAAA,OAAO,EAAEQ;AAHM,OAAjB;AAKD;AACF,GAXD,EAT+C,CAqB/C;;AACAN,EAAAA,UAAU,CAACY,WAAX,CAAwBC,MAAD,IAAY;AACjCA,IAAAA,MAAM,CAACV,SAAP,CAAkBC,IAAD,IAAU;AACzB,YAAMU,IAAI,GAAG,oBACX,CAACD,MAAM,CAACE,IAAR,EAAcF,MAAM,CAACG,MAArB,EAA6BZ,IAAI,CAACG,IAAlC,EAAwCH,IAAI,CAACI,KAA7C,EAAoDS,IAApD,CAAyD,GAAzD,CADW,CAAb;AAGA,YAAMR,SAAS,GAAI,OAAMK,IAAK,EAA9B;AACAf,MAAAA,WAAW,CAACW,IAAZ,CAAiB;AACf;AACA;AACA;AACA;AACAC,QAAAA,QAAQ,EAAE,CAACE,MAAM,CAACE,IAAR,EAAcF,MAAM,CAACG,MAArB,EAA6BZ,IAAI,CAACG,IAAlC,EAAwCU,IAAxC,CAA6C,GAA7C,CALK;AAMfR,QAAAA,SANe;AAOfX,QAAAA,OAAO,EAAG,IAAGe,MAAM,CAACE,IAAK,IAAGF,MAAM,CAACG,MAAO,OAAMP,SAAU,MAAKL,IAAI,CAACG,IAAK,KAAIH,IAAI,CAACI,KAAM;AAPzE,OAAjB;AASD,KAdD;AAeD,GAhBD;AAkBA,SAAOT,WAAP;AACD","sourcesContent":["import postcss from 'postcss';\nimport { slugify } from '@linaria/utils';\n\nexport default function atomize(cssText: string) {\n const atomicRules: {\n className: string;\n cssText: string;\n property: string;\n }[] = [];\n\n const stylesheet = postcss.parse(cssText);\n\n stylesheet.walkDecls((decl) => {\n const parent = decl.parent;\n if (parent === stylesheet) {\n const line = `${decl.prop}: ${decl.value};`;\n const className = `atm_${slugify(line)}`;\n atomicRules.push({\n property: decl.prop,\n className,\n cssText: line,\n });\n }\n });\n // Things like @media rules\n stylesheet.walkAtRules((atRule) => {\n atRule.walkDecls((decl) => {\n const slug = slugify(\n [atRule.name, atRule.params, decl.prop, decl.value].join(';')\n );\n const className = `atm_${slug}`;\n atomicRules.push({\n // For @ rules we want the unique property we do merging on to contain\n // the atrule params, eg. `media only screen and (max-width: 600px)`\n // But not the value. That way, our hashes will match when the media rule +\n // the declaration property match, and we can merge atomic media rules\n property: [atRule.name, atRule.params, decl.prop].join(' '),\n className,\n cssText: `@${atRule.name} ${atRule.params} { .${className} { ${decl.prop}: ${decl.value}; } }`,\n });\n });\n });\n\n return atomicRules;\n}\n"],"file":"atomize.js"}
|