@linaria/atomic 3.0.0-airbnb.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
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.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
+
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)
20
+
21
+
22
+ ### Features
23
+
24
+ * **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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Callstack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <p align="center">
2
+ <img alt="Linaria" src="https://raw.githubusercontent.com/callstack/linaria/HEAD/website/assets/linaria-logo@2x.png" width="496">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Zero-runtime CSS in JS library.
7
+ </p>
8
+
9
+ ---
10
+
11
+ ### 📖 Please refer to the [GitHub](https://github.com/callstack/linaria#readme) for full documentation.
12
+
13
+ ## Features
14
+
15
+ - Write CSS in JS, but with **zero runtime**, CSS is extracted to CSS files during build
16
+ - Familiar **CSS syntax** with Sass like nesting
17
+ - Use **dynamic prop based styles** with the React bindings, uses CSS variables behind the scenes
18
+ - Easily find where the style was defined with **CSS sourcemaps**
19
+ - **Lint your CSS** in JS with [stylelint](https://github.com/stylelint/stylelint)
20
+ - Use **JavaScript for logic**, no CSS preprocessor needed
21
+ - Optionally use any **CSS preprocessor** such as Sass or PostCSS
22
+
23
+ **[Why use Linaria](../../docs/BENEFITS.md)**
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ npm install @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
29
+ ```
30
+
31
+ or
32
+
33
+ ```sh
34
+ yarn add @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
35
+ ```
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CSSProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"CSSProperties.js"}
package/esm/atomize.js ADDED
@@ -0,0 +1,88 @@
1
+ import postcss from 'postcss';
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
+
22
+ export default function atomize(cssText, hasPriority = false) {
23
+ stylis.set({
24
+ prefix: false,
25
+ keyframe: false
26
+ });
27
+ const atomicRules = [];
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
+ });
38
+ stylesheet.walkDecls(decl => {
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) + (hasPriority ? 1 : 0);
79
+ const processedCss = stylis(`.${className}`.repeat(propertyPriority), css);
80
+ atomicRules.push({
81
+ property: atomicProperty.join(' '),
82
+ className,
83
+ cssText: processedCss
84
+ });
85
+ });
86
+ return atomicRules;
87
+ }
88
+ //# sourceMappingURL=atomize.js.map
@@ -0,0 +1 @@
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","hasPriority","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,M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gBAAgB,GACpBjD,mBAAmB,CAACyB,IAAI,CAACK,IAAN,CAAnB,IACCC,SAAS,GAAG,CAAH,GAAO,CADjB,KAECnB,WAAW,GAAG,CAAH,GAAO,CAFnB,CADF;AAIA,UAAMsC,YAAY,GAAGrD,MAAM,CAAE,IAAGmD,SAAU,EAAd,CAAgBG,MAAhB,CAAuBF,gBAAvB,CAAD,EAA2CN,GAA3C,CAA3B;AAEA3B,IAAAA,WAAW,CAACM,IAAZ,CAAiB;AACflB,MAAAA,QAAQ,EAAEyB,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;AAEfG,MAAAA,SAFe;AAGfrC,MAAAA,OAAO,EAAEuC;AAHM,KAAjB;AAKD,GAxDD;AA0DA,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, 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 = 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) +\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"],"file":"atomize.js"}
package/esm/css.js ADDED
@@ -0,0 +1,5 @@
1
+ export const css = () => {
2
+ throw new Error('Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.');
3
+ };
4
+ export default css;
5
+ //# sourceMappingURL=css.js.map
package/esm/css.js.map ADDED
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,5 @@
1
+ export { default as css } from './css';
2
+ export { default as atomize } from './atomize';
3
+ export { styled } from '@linaria/react';
4
+ export { cx } from '@linaria/utils';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["default","css","atomize","styled","cx"],"mappings":"AAAA,SAASA,OAAO,IAAIC,GAApB,QAA+B,OAA/B;AACA,SAASD,OAAO,IAAIE,OAApB,QAAmC,WAAnC;AACA,SAASC,MAAT,QAAuB,gBAAvB;AACA,SAASC,EAAT,QAAmB,gBAAnB","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { styled } from '@linaria/react';\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,mBAAm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O,EAAE,CAAC,eAAD,EAAkB,eAAlB,EAAmC,eAAnC,CAtJiB;AAuJ1BC,EAAAA,QAAQ,EAAE,CAAC,YAAD,EAAe,YAAf,CAvJgB;AAwJ1BC,EAAAA,OAAO,EAAE,CAAC,gBAAD,EAAmB,cAAnB,EAAmC,eAAnC,EAAoD,aAApD,CAxJiB;AAyJ1B,mBAAiB,CAAC,eAAD,EAAkB,iBAAlB,CAzJS;AA0J1B,iBAAe,CAAC,aAAD,EAAgB,eAAhB,CA1JW;AA2J1B,gBAAc,CAAC,YAAD,EAAe,cAAf,CA3JY;AA4J1B,mBAAiB,CACf,sBADe,EAEf,oBAFe,EAGf,qBAHe,EAIf,mBAJe,CA5JS;AAkK1B,oBAAkB,CAChB,uBADgB,EAEhB,qBAFgB,EAGhB,sBAHgB,EAIhB,oBAJgB,CAlKQ;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;;AACA,OAAO,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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=CSSProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"CSSProperties.js"}
package/lib/atomize.js ADDED
@@ -0,0 +1,106 @@
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
+ var _stylis = _interopRequireDefault(require("stylis"));
13
+
14
+ var _knownCssProperties = require("known-css-properties");
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
+ function atomize(cssText, hasPriority = false) {
37
+ _stylis.default.set({
38
+ prefix: false,
39
+ keyframe: false
40
+ });
41
+
42
+ const atomicRules = [];
43
+
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
+
47
+
48
+ stylesheet.walkAtRules('keyframes', atRule => {
49
+ atRule.remove();
50
+ atomicRules.push({
51
+ property: atRule.name,
52
+ cssText: atRule.toString()
53
+ });
54
+ });
55
+ stylesheet.walkDecls(decl => {
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) + (hasPriority ? 1 : 0);
97
+ const processedCss = (0, _stylis.default)(`.${className}`.repeat(propertyPriority), css);
98
+ atomicRules.push({
99
+ property: atomicProperty.join(' '),
100
+ className,
101
+ cssText: processedCss
102
+ });
103
+ });
104
+ return atomicRules;
105
+ }
106
+ //# sourceMappingURL=atomize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/atomize.ts"],"names":["knownPropertiesMap","knownProperties","reduce","acc","property","i","hashProperty","index","undefined","toString","atomize","cssText","hasPriority","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,EAAkCC,WAAW,GAAG,KAAhD,EAAuD;AACpEC,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,CAAcT,OAAd,CAAnB,CAXoE,CAapE;AACA;;;AACA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R;AACAJ,MAAAA,SAAS,CAACK,MAAV,CAAiBH,OAAjB;AACAF,MAAAA,SAAS,GAAGE,OAAZ;AACD,KALD;AAMAF,IAAAA,SAAS,CAACK,MAAV,CAAiBjB,IAAI,CAACe,KAAL,EAAjB;AAEA,UAAMG,GAAG,GAAGP,IAAI,CAAC7B,QAAL,EAAZ;AACA,UAAMqC,YAAY,GAAGxC,YAAY,CAAC,CAAC,GAAGyB,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,KACCC,SAAS,GAAG,CAAH,GAAO,CADjB,KAECrB,WAAW,GAAG,CAAH,GAAO,CAFnB,CADF;AAIA,UAAMwC,YAAY,GAAG,qBAAQ,IAAGF,SAAU,EAAd,CAAgBG,MAAhB,CAAuBF,gBAAvB,CAAP,EAAiDN,GAAjD,CAArB;AAEA5B,IAAAA,WAAW,CAACO,IAAZ,CAAiB;AACfpB,MAAAA,QAAQ,EAAE2B,cAAc,CAACgB,IAAf,CAAoB,GAApB,CADK;AAEfG,MAAAA,SAFe;AAGfvC,MAAAA,OAAO,EAAEyC;AAHM,KAAjB;AAKD,GAxDD;AA0DA,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, 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 = 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) +\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"],"file":"atomize.js"}
package/lib/css.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.css = void 0;
7
+
8
+ const css = () => {
9
+ throw new Error('Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.');
10
+ };
11
+
12
+ exports.css = css;
13
+ var _default = css;
14
+ exports.default = _default;
15
+ //# sourceMappingURL=css.js.map
package/lib/css.js.map ADDED
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
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, "styled", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _react.styled;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "cx", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.cx;
28
+ }
29
+ });
30
+
31
+ var _css = _interopRequireDefault(require("./css"));
32
+
33
+ var _atomize = _interopRequireDefault(require("./atomize"));
34
+
35
+ var _react = require("@linaria/react");
36
+
37
+ var _utils = require("@linaria/utils");
38
+
39
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA","sourcesContent":["export { default as css } from './css';\nexport { default as atomize } from './atomize';\nexport { styled } from '@linaria/react';\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,iBA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ApD,CAxJiB;AAyJ1B,mBAAiB,CAAC,eAAD,EAAkB,iBAAlB,CAzJS;AA0J1B,iBAAe,CAAC,aAAD,EAAgB,eAAhB,CA1JW;AA2J1B,gBAAc,CAAC,YAAD,EAAe,cAAf,CA3JY;AA4J1B,mBAAiB,CACf,sBADe,EAEf,oBAFe,EAGf,qBAHe,EAIf,mBAJe,CA5JS;AAkK1B,oBAAkB,CAChB,uBADgB,EAEhB,qBAFgB,EAGhB,sBAHgB,EAIhB,oBAJgB,CAlKQ;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 ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@linaria/atomic",
3
+ "version": "3.0.0-airbnb.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Blazing fast zero-runtime CSS in JS library",
8
+ "sideEffects": false,
9
+ "main": "lib/index.js",
10
+ "module": "esm/index.js",
11
+ "types": "types/index.d.ts",
12
+ "files": [
13
+ "types/",
14
+ "lib/",
15
+ "esm/"
16
+ ],
17
+ "license": "MIT",
18
+ "repository": "git@github.com:callstack/linaria.git",
19
+ "bugs": {
20
+ "url": "https://github.com/callstack/linaria/issues"
21
+ },
22
+ "homepage": "https://github.com/callstack/linaria#readme",
23
+ "keywords": [
24
+ "react",
25
+ "linaria",
26
+ "css",
27
+ "css-in-js",
28
+ "styled-components"
29
+ ],
30
+ "scripts": {
31
+ "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
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",
34
+ "build:declarations": "tsc --emitDeclarationOnly --outDir types",
35
+ "prepare": "yarn build && yarn build:declarations",
36
+ "typecheck": "tsc --noEmit --composite false",
37
+ "watch": "yarn build --watch"
38
+ },
39
+ "dependencies": {
40
+ "@linaria/react": "^3.0.0-airbnb.0",
41
+ "@linaria/utils": "^3.0.0-airbnb.0",
42
+ "known-css-properties": "^0.24.0",
43
+ "postcss": "^8.3.11",
44
+ "stylis": "^3.5.4"
45
+ },
46
+ "gitHead": "1c8bd4331b152498dd76e3f137940f43bd30e7b0"
47
+ }
@@ -0,0 +1,3 @@
1
+ export declare type CSSProperties = {
2
+ [key: string]: string | number | CSSProperties;
3
+ };
@@ -0,0 +1,5 @@
1
+ export default function atomize(cssText: string, hasPriority?: boolean): {
2
+ className?: string | undefined;
3
+ cssText: string;
4
+ property: string;
5
+ }[];
package/types/css.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { LinariaClassName } from '@linaria/utils';
2
+ import type { CSSProperties } from './CSSProperties';
3
+ declare type CSS = (strings: TemplateStringsArray, ...exprs: Array<string | number | CSSProperties>) => LinariaClassName;
4
+ export declare const css: CSS;
5
+ export default css;
@@ -0,0 +1,5 @@
1
+ export { default as css } from './css';
2
+ export { default as atomize } from './atomize';
3
+ export { styled } from '@linaria/react';
4
+ export { cx } from '@linaria/utils';
5
+ export type { CSSProperties } from './CSSProperties';
@@ -0,0 +1 @@
1
+ export declare function getPropertyPriority(property: string): 2 | 1;