@linaria/atomic 3.0.0-beta.15 → 3.0.0-beta.18
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/CHANGELOG.md +13 -0
- package/esm/atomize.js +78 -27
- package/esm/atomize.js.map +1 -1
- package/esm/css.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/propertyPriority.js +72 -0
- package/esm/propertyPriority.js.map +1 -0
- package/lib/atomize.js +83 -27
- package/lib/atomize.js.map +1 -1
- package/lib/css.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/propertyPriority.js +78 -0
- package/lib/propertyPriority.js.map +1 -0
- package/package.json +6 -4
- package/types/atomize.d.ts +1 -1
- package/types/css.d.ts +2 -4
- package/types/index.d.ts +0 -1
- package/types/propertyPriority.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-beta.18](https://github.com/callstack/linaria/compare/v3.0.0-beta.17...v3.0.0-beta.18) (2022-04-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **atomic:** add property priorities ([#950](https://github.com/callstack/linaria/issues/950)) ([c44becb](https://github.com/callstack/linaria/commit/c44becb11b2eec795b68c2b3d0715672ba4b3888))
|
|
12
|
+
* **atomic:** add support for at-rules, keyframes and pseudo classes ([#913](https://github.com/callstack/linaria/issues/913)) ([dee7fa1](https://github.com/callstack/linaria/commit/dee7fa14ea912224cac9f0673be7464e93571a73))
|
|
13
|
+
* **atomic:** string serialization of atoms ([#934](https://github.com/callstack/linaria/issues/934)) ([ef19ccb](https://github.com/callstack/linaria/commit/ef19ccb384cb7dbee561e789f637b0289d4d224c))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
# [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
20
|
|
|
8
21
|
|
package/esm/atomize.js
CHANGED
|
@@ -1,35 +1,86 @@
|
|
|
1
1
|
import postcss from 'postcss';
|
|
2
2
|
import { slugify } from '@linaria/utils';
|
|
3
|
+
import stylis from 'stylis';
|
|
4
|
+
import { all as knownProperties } from 'known-css-properties';
|
|
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
|
+
|
|
3
22
|
export default function atomize(cssText) {
|
|
23
|
+
stylis.set({
|
|
24
|
+
prefix: false,
|
|
25
|
+
keyframe: false
|
|
26
|
+
});
|
|
4
27
|
const atomicRules = [];
|
|
5
|
-
const stylesheet = postcss.parse(cssText);
|
|
28
|
+
const stylesheet = postcss.parse(cssText); // We want to extract all keyframes and leave them as-is.
|
|
29
|
+
// This isn't scoped locally yet
|
|
30
|
+
|
|
31
|
+
stylesheet.walkAtRules('keyframes', atRule => {
|
|
32
|
+
atRule.remove();
|
|
33
|
+
atomicRules.push({
|
|
34
|
+
property: atRule.name,
|
|
35
|
+
cssText: atRule.toString()
|
|
36
|
+
});
|
|
37
|
+
});
|
|
6
38
|
stylesheet.walkDecls(decl => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
let thisParent = decl.parent;
|
|
40
|
+
const parents = [];
|
|
41
|
+
const atomicProperty = [decl.prop];
|
|
42
|
+
let hasAtRule = false; // Traverse the declarations parents, and collect them all.
|
|
43
|
+
|
|
44
|
+
while (thisParent && thisParent !== stylesheet) {
|
|
45
|
+
parents.unshift(thisParent);
|
|
46
|
+
|
|
47
|
+
if (thisParent.type === 'atrule') {
|
|
48
|
+
hasAtRule = true; // @media queries, @supports etc.
|
|
49
|
+
|
|
50
|
+
atomicProperty.push(thisParent.name, thisParent.params);
|
|
51
|
+
} else if (thisParent.type === 'rule') {
|
|
52
|
+
// pseudo classes etc.
|
|
53
|
+
atomicProperty.push(thisParent.selector);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
thisParent = thisParent.parent;
|
|
57
|
+
} // Create a new stylesheet that contains *just* the extracted atomic rule and wrapping selectors, eg.
|
|
58
|
+
// `@media (max-width: 400px) { background: red; }`, or
|
|
59
|
+
// `&:hover { background: red; }`, or
|
|
60
|
+
// `background: red;`
|
|
61
|
+
// We do this so we can run it through stylis, to produce a full atom, eg.
|
|
62
|
+
// `@media (max-width: 400px) { .atm_foo { background: red; } }`
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const root = postcss.root();
|
|
66
|
+
let container = root;
|
|
67
|
+
parents.forEach(parent => {
|
|
68
|
+
const newNode = parent.clone();
|
|
69
|
+
newNode.removeAll();
|
|
70
|
+
container.append(newNode);
|
|
71
|
+
container = newNode;
|
|
72
|
+
});
|
|
73
|
+
container.append(decl.clone());
|
|
74
|
+
const css = root.toString();
|
|
75
|
+
const propertySlug = hashProperty([...atomicProperty].join(';'));
|
|
76
|
+
const valueSlug = slugify(decl.value);
|
|
77
|
+
const className = `atm_${propertySlug}_${valueSlug}`;
|
|
78
|
+
const propertyPriority = getPropertyPriority(decl.prop) + (hasAtRule ? 1 : 0);
|
|
79
|
+
const processedCss = stylis(`.${className}`.repeat(propertyPriority), css);
|
|
80
|
+
atomicRules.push({
|
|
81
|
+
property: atomicProperty.join(' '),
|
|
82
|
+
className,
|
|
83
|
+
cssText: processedCss
|
|
33
84
|
});
|
|
34
85
|
});
|
|
35
86
|
return atomicRules;
|
package/esm/atomize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atomize.ts"],"names":["postcss","slugify","atomize","cssText","atomicRules","stylesheet","parse","walkDecls","decl","parent","
|
|
1
|
+
{"version":3,"sources":["../src/atomize.ts"],"names":["postcss","slugify","stylis","all","knownProperties","getPropertyPriority","knownPropertiesMap","reduce","acc","property","i","hashProperty","index","undefined","toString","atomize","cssText","set","prefix","keyframe","atomicRules","stylesheet","parse","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"],"mappings":"AAAA,OAAOA,OAAP,MAA2D,SAA3D;AACA,SAASC,OAAT,QAAwB,gBAAxB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,GAAG,IAAIC,eAAhB,QAAuC,sBAAvC;AACA,SAASC,mBAAT,QAAoC,oBAApC;AAEA,MAAMC,kBAAkB,GAAGF,eAAe,CAACG,MAAhB,CACzB,CAACC,GAAD,EAAsCC,QAAtC,EAAgDC,CAAhD,KAAsD;AACpDF,EAAAA,GAAG,CAACC,QAAD,CAAH,GAAgBC,CAAhB;AACA,SAAOF,GAAP;AACD,CAJwB,EAKzB,EALyB,CAA3B;;AAQA,SAASG,YAA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W,CAACM,IAAZ,CAAiB;AACfjB,MAAAA,QAAQ,EAAEwB,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;AAEfG,MAAAA,SAFe;AAGfpC,MAAAA,OAAO,EAAEsC;AAHM,KAAjB;AAKD,GAtDD;AAwDA,SAAOlC,WAAP;AACD","sourcesContent":["import postcss, { Document, AtRule, Container, Rule } from 'postcss';\nimport { slugify } from '@linaria/utils';\nimport stylis from 'stylis';\nimport { all as knownProperties } from 'known-css-properties';\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\nexport default function atomize(cssText: string) {\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 = postcss.parse(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) + (hasAtRule ? 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"],"file":"atomize.js"}
|
package/esm/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css.ts"],"names":["css","Error"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/css.ts"],"names":["css","Error"],"mappings":"AAQA,OAAO,MAAMA,GAAQ,GAAG,MAAM;AAC5B,QAAM,IAAIC,KAAJ,CACJ,wGADI,CAAN;AAGD,CAJM;AAMP,eAAeD,GAAf","sourcesContent":["import type { LinariaClassName } from '@linaria/utils';\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"],"file":"css.js"}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["default","css","atomize","cx"],"mappings":"AAAA,SAASA,OAAO,IAAIC,GAApB,QAA+B,OAA/B;AACA,SAASD,OAAO,IAAIE,OAApB,QAAmC,WAAnC;AACA,SAASC,EAAT,QAAmB,gBAAnB","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { cx } from '@linaria/utils';\n\nexport type { CSSProperties } from './CSSProperties';\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["default","css","atomize","cx"],"mappings":"AAAA,SAASA,OAAO,IAAIC,GAApB,QAA+B,OAA/B;AACA,SAASD,OAAO,IAAIE,OAApB,QAAmC,WAAnC;AACA,SAASC,EAAT,QAAmB,gBAAnB","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { cx } from '@linaria/utils';\n\nexport type { CSSProperties } from './CSSProperties';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
|
|
66
|
+
if (longhands.includes(property)) {
|
|
67
|
+
return 2;
|
|
68
|
+
} else {
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=propertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/propertyPriority.ts"],"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"],"mappings":"AAAA,MAAMA,mBAAmB,GAAG;AAC1B;AACA;AACA;AACAC,EAAAA,SAAS,EAAE,CACT,gBADS,EAET,oBAFS,EAGT,2BAHS,EAIT,iBAJS,EAKT,2BALS,EAMT,qBANS,EAOT,qBAPS,EAQT,sBARS,CAJe;AAc1BC,EAAAA,UAAU,EAAE,CACV,uBADU,EAEV,iBAFU,EAGV,kBAHU,EAIV,kBAJU,EAKV,mBALU,EAMV,qBANU,EAOV,mBAPU,EAQV,iBARU,CAdc;AAwB1BC,EAAAA,MAAM,EAAE,CAAC,cAAD,EAAiB,cAAjB,EAAiC,cAAjC,CAxBkB;AAyB1B,sBAAoB,CAClB,wBADkB,EAElB,wBAFkB,EAGlB,wBAHkB,CAzBM;AA8B1B,wBAAsB,CACpB,0BADoB,EAEpB,0BAFoB,EAGpB,0BAHoB,CA9BI;AAmC1B,mBAAiB,CACf,qBADe,EAEf,qBAFe,EAGf,qBAHe,CAnCS;AAwC1B,kBAAgB,CACd,qBADc,EAEd,mBAFc,EAGd,oBAHc,EAId,kBAJc,CAxCU;AA8C1B,kBAAgB,CACd,qBADc,EAEd,qBAFc,EAGd,oBAHc,EAId,qBAJc,EAKd,oBALc,CA9CU;AAqD1B,uBAAqB,CACnB,yBADmB,EAEnB,yBAFmB,EAGnB,yBAHmB,CArDK;AA0D1B,yBAAuB,CACrB,2BADqB,EAErB,2BAFqB,EAGrB,2BAHqB,CA1DG;AA+D1B,iBAAe,CACb,mBADa,EAEb,mBAFa,EAGb,mBAHa,CA/DW;AAoE1B,mBAAiB,CACf,wBADe,EAEf,yBAFe,EAGf,4BAHe,EAIf,2BAJe,CApES;AA0E1B,kBAAgB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AGD,CAAJ,EAAO,GAAGC,CAAV,CADM,EAEhB,EAFgB,CAAlB;;AAKA,MAAIL,SAAS,CAACM,QAAV,CAAmBP,QAAnB,CAAJ,EAAkC;AAChC,WAAO,CAAP;AACD,GAFD,MAEO;AACL,WAAO,CAAP;AACD;AACF","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 if (longhands.includes(property)) {\n return 2;\n } else {\n return 1;\n }\n}\n"],"file":"propertyPriority.js"}
|
package/lib/atomize.js
CHANGED
|
@@ -9,40 +9,96 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@linaria/utils");
|
|
11
11
|
|
|
12
|
+
var _stylis = _interopRequireDefault(require("stylis"));
|
|
13
|
+
|
|
14
|
+
var _knownCssProperties = require("known-css-properties");
|
|
15
|
+
|
|
16
|
+
var _propertyPriority = require("./propertyPriority");
|
|
17
|
+
|
|
12
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
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
|
+
|
|
14
36
|
function atomize(cssText) {
|
|
37
|
+
_stylis.default.set({
|
|
38
|
+
prefix: false,
|
|
39
|
+
keyframe: false
|
|
40
|
+
});
|
|
41
|
+
|
|
15
42
|
const atomicRules = [];
|
|
16
43
|
|
|
17
|
-
const stylesheet = _postcss.default.parse(cssText);
|
|
44
|
+
const stylesheet = _postcss.default.parse(cssText); // We want to extract all keyframes and leave them as-is.
|
|
45
|
+
// This isn't scoped locally yet
|
|
46
|
+
|
|
18
47
|
|
|
48
|
+
stylesheet.walkAtRules('keyframes', atRule => {
|
|
49
|
+
atRule.remove();
|
|
50
|
+
atomicRules.push({
|
|
51
|
+
property: atRule.name,
|
|
52
|
+
cssText: atRule.toString()
|
|
53
|
+
});
|
|
54
|
+
});
|
|
19
55
|
stylesheet.walkDecls(decl => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
let thisParent = decl.parent;
|
|
57
|
+
const parents = [];
|
|
58
|
+
const atomicProperty = [decl.prop];
|
|
59
|
+
let hasAtRule = false; // Traverse the declarations parents, and collect them all.
|
|
60
|
+
|
|
61
|
+
while (thisParent && thisParent !== stylesheet) {
|
|
62
|
+
parents.unshift(thisParent);
|
|
63
|
+
|
|
64
|
+
if (thisParent.type === 'atrule') {
|
|
65
|
+
hasAtRule = true; // @media queries, @supports etc.
|
|
66
|
+
|
|
67
|
+
atomicProperty.push(thisParent.name, thisParent.params);
|
|
68
|
+
} else if (thisParent.type === 'rule') {
|
|
69
|
+
// pseudo classes etc.
|
|
70
|
+
atomicProperty.push(thisParent.selector);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
thisParent = thisParent.parent;
|
|
74
|
+
} // Create a new stylesheet that contains *just* the extracted atomic rule and wrapping selectors, eg.
|
|
75
|
+
// `@media (max-width: 400px) { background: red; }`, or
|
|
76
|
+
// `&:hover { background: red; }`, or
|
|
77
|
+
// `background: red;`
|
|
78
|
+
// We do this so we can run it through stylis, to produce a full atom, eg.
|
|
79
|
+
// `@media (max-width: 400px) { .atm_foo { background: red; } }`
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const root = _postcss.default.root();
|
|
83
|
+
|
|
84
|
+
let container = root;
|
|
85
|
+
parents.forEach(parent => {
|
|
86
|
+
const newNode = parent.clone();
|
|
87
|
+
newNode.removeAll();
|
|
88
|
+
container.append(newNode);
|
|
89
|
+
container = newNode;
|
|
90
|
+
});
|
|
91
|
+
container.append(decl.clone());
|
|
92
|
+
const css = root.toString();
|
|
93
|
+
const propertySlug = hashProperty([...atomicProperty].join(';'));
|
|
94
|
+
const valueSlug = (0, _utils.slugify)(decl.value);
|
|
95
|
+
const className = `atm_${propertySlug}_${valueSlug}`;
|
|
96
|
+
const propertyPriority = (0, _propertyPriority.getPropertyPriority)(decl.prop) + (hasAtRule ? 1 : 0);
|
|
97
|
+
const processedCss = (0, _stylis.default)(`.${className}`.repeat(propertyPriority), css);
|
|
98
|
+
atomicRules.push({
|
|
99
|
+
property: atomicProperty.join(' '),
|
|
100
|
+
className,
|
|
101
|
+
cssText: processedCss
|
|
46
102
|
});
|
|
47
103
|
});
|
|
48
104
|
return atomicRules;
|
package/lib/atomize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atomize.ts"],"names":["atomize","cssText","atomicRules","stylesheet","postcss","parse","walkDecls","decl","parent","
|
|
1
|
+
{"version":3,"sources":["../src/atomize.ts"],"names":["knownPropertiesMap","knownProperties","reduce","acc","property","i","hashProperty","index","undefined","toString","atomize","cssText","stylis","set","prefix","keyframe","atomicRules","stylesheet","postcss","parse","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"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA,MAAMA,kBAAkB,GAAGC,wBAAgBC,MAAhB,CACzB,CAACC,GAAD,EAAsCC,QAAtC,EAAgDC,CAAhD,KAAsD;AACpDF,EAAAA,GAAG,CAACC,QAAD,CAAH,GAAgBC,CAAhB;AACA,SAAOF,GAAP;AACD,CAJwB,EAKzB,EALyB,CAA3B;;AAQA,SAASG,YAAT,CAAsBF,QAAtB,EAAwC;AACtC,QAAMG,KAAK,GAAGP,kBAAkB,CAACI,QAAD,CAAhC,CADsC,CAEtC;AACA;;AACA,MAAIG,KAAK,KAAKC,SAAd,EAAyB;AACvB,WAAOD,KAAK,CAACE,QAAN,CAAe,EAAf,CAAP,CADuB,CACI;AAC5B;;AACD,SAAO,oBAAQL,QAAR,CAAP;AACD;;AAEc,SAASM,OAAT,CAAiBC,OAAjB,EAAkC;AAC/CC,kBAAOC,GAAP,CAAW;AACTC,IAAAA,MAAM,EAAE,KADC;AAETC,IAAAA,QAAQ,EAAE;AAFD,GAAX;;AAIA,QAAMC,WAIH,GAAG,EAJN;;AAMA,QAAMC,UAAU,GAAGC,iBAAQC,KAAR,CAAcR,OAAd,CAAnB,CAX+C,CAa/C;AACA;;;AACAM,EAAAA,UAAU,CAACG,WAAX,CAAuB,WAAvB,EAAqCC,MAAD,IAAY;AAC9CA,IAAAA,MAAM,CAACC,MAAP;AACAN,IAAAA,WAAW,CAACO,IAAZ,CAAiB;AACfnB,MAAAA,QA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AL,EAAjB;AAEA,UAAMG,GAAG,GAAGP,IAAI,CAAC5B,QAAL,EAAZ;AACA,UAAMoC,YAAY,GAAGvC,YAAY,CAAC,CAAC,GAAGwB,cAAJ,EAAoBgB,IAApB,CAAyB,GAAzB,CAAD,CAAjC;AACA,UAAMC,SAAS,GAAG,oBAAQrB,IAAI,CAACsB,KAAb,CAAlB;AACA,UAAMC,SAAS,GAAI,OAAMJ,YAAa,IAAGE,SAAU,EAAnD;AAEA,UAAMG,gBAAgB,GACpB,2CAAoBxB,IAAI,CAACK,IAAzB,KAAkCC,SAAS,GAAG,CAAH,GAAO,CAAlD,CADF;AAEA,UAAMmB,YAAY,GAAG,qBAAQ,IAAGF,SAAU,EAAd,CAAgBG,MAAhB,CAAuBF,gBAAvB,CAAP,EAAiDN,GAAjD,CAArB;AAEA5B,IAAAA,WAAW,CAACO,IAAZ,CAAiB;AACfnB,MAAAA,QAAQ,EAAE0B,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;AAEfG,MAAAA,SAFe;AAGftC,MAAAA,OAAO,EAAEwC;AAHM,KAAjB;AAKD,GAtDD;AAwDA,SAAOnC,WAAP;AACD","sourcesContent":["import postcss, { Document, AtRule, Container, Rule } from 'postcss';\nimport { slugify } from '@linaria/utils';\nimport stylis from 'stylis';\nimport { all as knownProperties } from 'known-css-properties';\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\nexport default function atomize(cssText: string) {\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 = postcss.parse(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) + (hasAtRule ? 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"],"file":"atomize.js"}
|
package/lib/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css.ts"],"names":["css","Error"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/css.ts"],"names":["css","Error"],"mappings":";;;;;;;AAQO,MAAMA,GAAQ,GAAG,MAAM;AAC5B,QAAM,IAAIC,KAAJ,CACJ,wGADI,CAAN;AAGD,CAJM;;;eAMQD,G","sourcesContent":["import type { LinariaClassName } from '@linaria/utils';\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"],"file":"css.js"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { cx } from '@linaria/utils';\n\nexport type { CSSProperties } from './CSSProperties';\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { cx } from '@linaria/utils';\n\nexport type { CSSProperties } from './CSSProperties';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
|
|
72
|
+
if (longhands.includes(property)) {
|
|
73
|
+
return 2;
|
|
74
|
+
} else {
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=propertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/propertyPriority.ts"],"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"],"mappings":";;;;;;AAAA,MAAMA,mBAAmB,GAAG;AAC1B;AACA;AACA;AACAC,EAAAA,SAAS,EAAE,CACT,gBADS,EAET,oBAFS,EAGT,2BAHS,EAIT,iBAJS,EAKT,2BALS,EAMT,qBANS,EAOT,qBAPS,EAQT,sBARS,CAJe;AAc1BC,EAAAA,UAAU,EAAE,CACV,uBADU,EAEV,iBAFU,EAGV,kBAHU,EAIV,kBAJU,EAKV,mBALU,EAMV,qBANU,EAOV,mBAPU,EAQV,iBARU,CAdc;AAwB1BC,EAAAA,MAAM,EAAE,CAAC,cAAD,EAAiB,cAAjB,EAAiC,cAAjC,CAxBkB;AAyB1B,sBAAoB,CAClB,wBADkB,EAElB,wBAFkB,EAGlB,wBAHkB,CAzBM;AA8B1B,wBAAsB,CACpB,0BADoB,EAEpB,0BAFoB,EAGpB,0BAHoB,CA9BI;AAmC1B,mBAAiB,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KQ;AAwK1B,qBAAmB,CACjB,uBADiB,EAEjB,sBAFiB,EAGjB,uBAHiB,EAIjB,2BAJiB,CAxKO;AA8K1B,mBAAiB,CAAC,qBAAD,EAAwB,qBAAxB,CA9KS;AA+K1BC,EAAAA,UAAU,EAAE,CACV,kBADU,EAEV,qBAFU,EAGV,qBAHU,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;AACpD,QAAMC,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;;AAKA,MAAIL,SAAS,CAACM,QAAV,CAAmBP,QAAnB,CAAJ,EAAkC;AAChC,WAAO,CAAP;AACD,GAFD,MAEO;AACL,WAAO,CAAP;AACD;AACF","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 if (longhands.includes(property)) {\n return 2;\n } else {\n return 1;\n }\n}\n"],"file":"propertyPriority.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linaria/atomic",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.18",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,8 +37,10 @@
|
|
|
37
37
|
"watch": "yarn build --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@linaria/utils": "^3.0.0-beta.
|
|
41
|
-
"
|
|
40
|
+
"@linaria/utils": "^3.0.0-beta.18",
|
|
41
|
+
"known-css-properties": "^0.24.0",
|
|
42
|
+
"postcss": "^8.3.11",
|
|
43
|
+
"stylis": "^3.5.4"
|
|
42
44
|
},
|
|
43
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c3f093a3a7fb4e7c82d23e44adb19a94438da68c"
|
|
44
46
|
}
|
package/types/atomize.d.ts
CHANGED
package/types/css.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import type { LinariaClassName } from '@linaria/utils';
|
|
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPropertyPriority(property: string): 2 | 1;
|