@tamagui/helpers 1.0.0-alpha.31 → 1.0.0-alpha.38
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/dist/.buildinfo +1 -0
- package/dist/concatClassName.js +43 -55
- package/dist/concatClassName.js.map +2 -2
- package/dist/getStylesAtomic.js +17 -12
- package/dist/getStylesAtomic.js.map +2 -2
- package/dist/index.cjs +226 -90
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +3 -1
- package/dist/index.js.map +2 -2
- package/dist/validStyleProps.js +11 -23
- package/dist/validStyleProps.js.map +2 -2
- package/package.json +3 -3
- package/dist/allRules.js +0 -9
- package/dist/allRules.js.map +0 -7
- package/dist/cjs/allRules.js +0 -15
- package/dist/cjs/allRules.js.map +0 -7
- package/dist/cjs/concatClassName.js +0 -78
- package/dist/cjs/concatClassName.js.map +0 -7
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/simpleHash.js +0 -21
- package/dist/cjs/simpleHash.js.map +0 -7
- package/dist/cjs/types.js +0 -4
- package/dist/cjs/types.js.map +0 -7
- package/dist/cjs/validStyleProps.js +0 -163
- package/dist/cjs/validStyleProps.js.map +0 -7
- package/dist/esm/allRules.js +0 -9
- package/dist/esm/allRules.js.map +0 -7
- package/dist/esm/concatClassName.js +0 -72
- package/dist/esm/concatClassName.js.map +0 -7
- package/dist/esm/index.js +0 -5
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/simpleHash.js +0 -15
- package/dist/esm/simpleHash.js.map +0 -7
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/esm/validStyleProps.js +0 -150
- package/dist/esm/validStyleProps.js.map +0 -7
- package/dist/getStylesAtomic.native.js +0 -11
- package/dist/getStylesAtomic.native.js.map +0 -7
- package/dist/jsx/allRules.js +0 -8
- package/dist/jsx/concatClassName.js +0 -71
- package/dist/jsx/index.js +0 -4
- package/dist/jsx/simpleHash.js +0 -14
- package/dist/jsx/types.js +0 -0
- package/dist/jsx/validStyleProps.js +0 -149
- package/types/allRules.d.ts.map +0 -1
- package/types/concatClassName.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/simpleHash.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
- package/types/validStyleProps.d.ts.map +0 -1
package/dist/.buildinfo
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"at":1636517189907}
|
package/dist/concatClassName.js
CHANGED
|
@@ -1,71 +1,59 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { uniqueKeyToStyleName } from "./uniqueStyleKeys";
|
|
4
|
+
const pseudoInvert = {
|
|
5
|
+
hover: "hoverStyle",
|
|
6
|
+
focus: "focusStyle",
|
|
7
|
+
press: "pressStyle"
|
|
8
|
+
};
|
|
9
|
+
function concatClassName(className, ...propObjects) {
|
|
10
|
+
const usedPrefixes = new Set();
|
|
11
|
+
const final = [];
|
|
12
|
+
const names = className.split(" ");
|
|
13
|
+
const hasPropObjects = propObjects.length;
|
|
14
|
+
for (let i = names.length - 1; i >= 0; i--) {
|
|
15
|
+
const name = names[i];
|
|
16
|
+
if (!name || name === " ")
|
|
12
17
|
continue;
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
propObjects.push(cns);
|
|
18
|
+
if (name[0] !== "_") {
|
|
19
|
+
final.push(name);
|
|
16
20
|
continue;
|
|
17
21
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
const splitIndex = name.indexOf("-");
|
|
23
|
+
if (splitIndex < 1) {
|
|
24
|
+
final.push(name);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const nextChar = name[splitIndex + 1];
|
|
28
|
+
const isMediaQuery = nextChar === "_";
|
|
29
|
+
const isPsuedoQuery = nextChar === "-";
|
|
30
|
+
const styleKey = name.slice(1, splitIndex);
|
|
31
|
+
const mediaKey = isMediaQuery || isPsuedoQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null;
|
|
32
|
+
const uid = mediaKey ? styleKey + mediaKey : styleKey;
|
|
33
|
+
if (!isMediaQuery && !isPsuedoQuery) {
|
|
34
|
+
if (usedPrefixes.has(uid)) {
|
|
31
35
|
continue;
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
usedPrefixes.push(uid);
|
|
44
|
-
}
|
|
45
|
-
const propName = styleKey;
|
|
46
|
-
if (propName && propObjects) {
|
|
47
|
-
if (propObjects.some((po) => {
|
|
48
|
-
if (mediaKey) {
|
|
49
|
-
const propKey = pseudoInvert[mediaKey];
|
|
50
|
-
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null;
|
|
51
|
-
}
|
|
52
|
-
const res = po && propName in po && po[propName] !== null;
|
|
53
|
-
return res;
|
|
54
|
-
})) {
|
|
55
|
-
continue;
|
|
37
|
+
usedPrefixes.add(uid);
|
|
38
|
+
}
|
|
39
|
+
const propName = uniqueKeyToStyleName[styleKey];
|
|
40
|
+
if (propName && hasPropObjects) {
|
|
41
|
+
if (propObjects.some((po) => {
|
|
42
|
+
if (mediaKey) {
|
|
43
|
+
const propKey = pseudoInvert[mediaKey];
|
|
44
|
+
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null;
|
|
56
45
|
}
|
|
46
|
+
const res = po && propName in po && po[propName] !== null;
|
|
47
|
+
return res;
|
|
48
|
+
})) {
|
|
49
|
+
continue;
|
|
57
50
|
}
|
|
58
|
-
final = name + " " + final;
|
|
59
51
|
}
|
|
52
|
+
final.push(name);
|
|
60
53
|
}
|
|
61
|
-
return final;
|
|
54
|
+
return final.join(" ");
|
|
62
55
|
}
|
|
63
56
|
__name(concatClassName, "concatClassName");
|
|
64
|
-
const pseudoInvert = {
|
|
65
|
-
hover: "hoverStyle",
|
|
66
|
-
focus: "focusStyle",
|
|
67
|
-
press: "pressStyle"
|
|
68
|
-
};
|
|
69
57
|
export {
|
|
70
58
|
concatClassName
|
|
71
59
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/concatClassName.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;
|
|
4
|
+
"sourcesContent": ["import { uniqueKeyToStyleName } from './uniqueStyleKeys'\n\nconst pseudoInvert = {\n hover: 'hoverStyle',\n focus: 'focusStyle',\n press: 'pressStyle',\n}\n\nexport function concatClassName(className: string, ...propObjects: any[]) {\n const usedPrefixes = new Set<string>()\n const final: string[] = []\n const names = className.split(' ')\n const hasPropObjects = propObjects.length\n // const shouldLog = className.includes('_col-varzzzcolor3z')\n // shouldLog && console.log('>>>>>>>>>>', className)\n\n for (let i = names.length - 1; i >= 0; i--) {\n const name = names[i]\n if (!name || name === ' ') continue\n if (name[0] !== '_') {\n // not snack style (todo slightly stronger heuristic)\n final.push(name)\n continue\n }\n const splitIndex = name.indexOf('-')\n if (splitIndex < 1) {\n final.push(name)\n continue\n }\n const nextChar = name[splitIndex + 1]\n // synced to static-ui constants\n // MEDIA_SEP\n const isMediaQuery = nextChar === '_'\n // PSEUDO_SEP\n const isPsuedoQuery = nextChar === '-'\n const styleKey = name.slice(1, splitIndex)\n const mediaKey =\n isMediaQuery || isPsuedoQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null\n const uid = mediaKey ? styleKey + mediaKey : styleKey\n // shouldLog && console.log('uid', uid)\n if (!isMediaQuery && !isPsuedoQuery) {\n if (usedPrefixes.has(uid)) {\n // shouldLog && console.log('used', uid)\n continue\n }\n usedPrefixes.add(uid)\n }\n const propName = uniqueKeyToStyleName[styleKey]\n // shouldLog && console.log('propName', propName)\n if (propName && hasPropObjects) {\n if (\n propObjects.some((po) => {\n if (mediaKey) {\n const propKey = pseudoInvert[mediaKey]\n return po && po[propKey] && propName in po[propKey] && po[propKey] !== null\n }\n const res = po && propName in po && po[propName] !== null\n // shouldLog && res && console.log('SKIP BECAUSE', propName, po)\n return res\n })\n ) {\n // shouldLog && console.log('SKIP PROP')\n continue\n }\n }\n // shouldLog && console.log('push', name)\n final.push(name)\n }\n\n // shouldLog && console.log(' in:', className, 'out:', final)\n\n return final.join(' ')\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA;AAGF,yBAAyB,cAAsB,aAAoB;AACxE,QAAM,eAAe,IAAI;AACzB,QAAM,QAAkB;AACxB,QAAM,QAAQ,UAAU,MAAM;AAC9B,QAAM,iBAAiB,YAAY;AAInC,WAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC1C,UAAM,OAAO,MAAM;AACnB,QAAI,CAAC,QAAQ,SAAS;AAAK;AAC3B,QAAI,KAAK,OAAO,KAAK;AAEnB,YAAM,KAAK;AACX;AAAA;AAEF,UAAM,aAAa,KAAK,QAAQ;AAChC,QAAI,aAAa,GAAG;AAClB,YAAM,KAAK;AACX;AAAA;AAEF,UAAM,WAAW,KAAK,aAAa;AAGnC,UAAM,eAAe,aAAa;AAElC,UAAM,gBAAgB,aAAa;AACnC,UAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,UAAM,WACJ,gBAAgB,gBAAgB,KAAK,MAAM,aAAa,GAAG,aAAa,KAAK;AAC/E,UAAM,MAAM,WAAW,WAAW,WAAW;AAE7C,QAAI,CAAC,gBAAgB,CAAC,eAAe;AACnC,UAAI,aAAa,IAAI,MAAM;AAEzB;AAAA;AAEF,mBAAa,IAAI;AAAA;AAEnB,UAAM,WAAW,qBAAqB;AAEtC,QAAI,YAAY,gBAAgB;AAC9B,UACE,YAAY,KAAK,CAAC,OAAO;AACvB,YAAI,UAAU;AACZ,gBAAM,UAAU,aAAa;AAC7B,iBAAO,MAAM,GAAG,YAAY,YAAY,GAAG,YAAY,GAAG,aAAa;AAAA;AAEzE,cAAM,MAAM,MAAM,YAAY,MAAM,GAAG,cAAc;AAErD,eAAO;AAAA,UAET;AAEA;AAAA;AAAA;AAIJ,UAAM,KAAK;AAAA;AAKb,SAAO,MAAM,KAAK;AAAA;AA/DJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/getStylesAtomic.js
CHANGED
|
@@ -4,8 +4,13 @@ import { atomic } from "react-native-web/dist/cjs/exports/StyleSheet/compile";
|
|
|
4
4
|
import createCompileableStyle from "react-native-web/dist/cjs/exports/StyleSheet/createCompileableStyle";
|
|
5
5
|
import createReactDOMStyle from "react-native-web/dist/cjs/exports/StyleSheet/createReactDOMStyle";
|
|
6
6
|
import i18Style from "react-native-web/dist/cjs/exports/StyleSheet/i18nStyle";
|
|
7
|
-
import {
|
|
7
|
+
import { simpleHash } from "./simpleHash";
|
|
8
|
+
import { getOrCreateStylePrefix } from "./uniqueStyleKeys";
|
|
8
9
|
const pseudos = {
|
|
10
|
+
focusWithinStyle: {
|
|
11
|
+
name: "focus-within",
|
|
12
|
+
priority: 4
|
|
13
|
+
},
|
|
9
14
|
focusStyle: {
|
|
10
15
|
name: "focus",
|
|
11
16
|
priority: 3
|
|
@@ -26,7 +31,7 @@ const borderDefaults = {
|
|
|
26
31
|
borderLeftWidth: "borderLeftStyle",
|
|
27
32
|
borderRightWidth: "borderRightStyle"
|
|
28
33
|
};
|
|
29
|
-
function getStylesAtomic(style
|
|
34
|
+
function getStylesAtomic(style) {
|
|
30
35
|
const styles = {
|
|
31
36
|
base: {}
|
|
32
37
|
};
|
|
@@ -38,12 +43,12 @@ function getStylesAtomic(style, avoidCollection = false) {
|
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
return Object.keys(styles).map((key) => {
|
|
41
|
-
return getAtomicStyle(styles[key], pseudos[key]
|
|
46
|
+
return getAtomicStyle(styles[key], pseudos[key]);
|
|
42
47
|
}).flat();
|
|
43
48
|
}
|
|
44
49
|
__name(getStylesAtomic, "getStylesAtomic");
|
|
45
50
|
const importantRegex = /\!important*/g;
|
|
46
|
-
function getAtomicStyle(style, pseudo
|
|
51
|
+
function getAtomicStyle(style, pseudo) {
|
|
47
52
|
if (style == null || typeof style !== "object") {
|
|
48
53
|
throw new Error(`Wrong style type: "${typeof style}": ${style}`);
|
|
49
54
|
}
|
|
@@ -57,9 +62,15 @@ function getAtomicStyle(style, pseudo, avoidCollection) {
|
|
|
57
62
|
};
|
|
58
63
|
return Object.keys(all).map((key) => {
|
|
59
64
|
const val = all[key];
|
|
60
|
-
const
|
|
65
|
+
const prefix = `_${getOrCreateStylePrefix(val.property)}`;
|
|
66
|
+
const hash = (() => {
|
|
67
|
+
let s = `${val.value}`.replace(/[%]/g, "pct").replace(/[^a-z0-9]/gi, "z").replace(/\s/, "-");
|
|
68
|
+
if (s.length < 16)
|
|
69
|
+
return s;
|
|
70
|
+
return simpleHash(val.identifier);
|
|
71
|
+
})();
|
|
61
72
|
const psuedoPrefix = pseudo ? `-${pseudo.name}-` : "";
|
|
62
|
-
const identifier =
|
|
73
|
+
const identifier = `${prefix}-${psuedoPrefix}${hash}`;
|
|
63
74
|
const className = `.${identifier}`;
|
|
64
75
|
const rules = val.rules.map((rule) => {
|
|
65
76
|
if (pseudo) {
|
|
@@ -72,12 +83,6 @@ function getAtomicStyle(style, pseudo, avoidCollection) {
|
|
|
72
83
|
}
|
|
73
84
|
return rule.replace(`.${val.identifier}`, className).replace(importantRegex, "");
|
|
74
85
|
});
|
|
75
|
-
if (!avoidCollection) {
|
|
76
|
-
if (rules.length > 1) {
|
|
77
|
-
console.warn("have never seen more than one, verifying");
|
|
78
|
-
}
|
|
79
|
-
AllRules.add(rules[0]);
|
|
80
|
-
}
|
|
81
86
|
const result = {
|
|
82
87
|
property: val.property,
|
|
83
88
|
value: val.value,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/getStylesAtomic.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ViewStyle } from 'react-native'\nimport { atomic } from 'react-native-web/dist/cjs/exports/StyleSheet/compile'\nimport createCompileableStyle from 'react-native-web/dist/cjs/exports/StyleSheet/createCompileableStyle'\nimport createReactDOMStyle from 'react-native-web/dist/cjs/exports/StyleSheet/createReactDOMStyle'\nimport i18Style from 'react-native-web/dist/cjs/exports/StyleSheet/i18nStyle'\n\nimport {
|
|
5
|
-
"mappings": ";;AACA;AACA;AACA;AACA;AAEA;
|
|
4
|
+
"sourcesContent": ["import type { ViewStyle } from 'react-native'\nimport { atomic } from 'react-native-web/dist/cjs/exports/StyleSheet/compile'\nimport createCompileableStyle from 'react-native-web/dist/cjs/exports/StyleSheet/createCompileableStyle'\nimport createReactDOMStyle from 'react-native-web/dist/cjs/exports/StyleSheet/createReactDOMStyle'\nimport i18Style from 'react-native-web/dist/cjs/exports/StyleSheet/i18nStyle'\n\nimport { simpleHash } from './simpleHash'\nimport { StyleObject } from './types'\nimport { getOrCreateStylePrefix } from './uniqueStyleKeys'\n\nexport const pseudos = {\n focusWithinStyle: {\n name: 'focus-within',\n priority: 4,\n },\n focusStyle: {\n name: 'focus',\n priority: 3,\n },\n pressStyle: {\n name: 'active',\n priority: 2,\n },\n hoverStyle: {\n name: 'hover',\n priority: 1,\n },\n}\n\nconst borderDefaults = {\n borderWidth: 'borderStyle',\n borderBottomWidth: 'borderBottomStyle',\n borderTopWidth: 'borderTopStyle',\n borderLeftWidth: 'borderLeftStyle',\n borderRightWidth: 'borderRightStyle',\n}\n\nexport function getStylesAtomic(style: any) {\n const styles: { [key: string]: ViewStyle } = {\n base: {},\n }\n // split psuedos\n for (const key in style) {\n if (!!pseudos[key]) {\n styles[key] = style[key]\n } else {\n styles.base[key] = style[key]\n }\n }\n return Object.keys(styles)\n .map((key) => {\n return getAtomicStyle(styles[key], pseudos[key])\n })\n .flat()\n}\n\nconst importantRegex = /\\!important*/g\n\nfunction getAtomicStyle(style: ViewStyle, pseudo?: { name: string; priority: number }): StyleObject[] {\n if (style == null || typeof style !== 'object') {\n throw new Error(`Wrong style type: \"${typeof style}\": ${style}`)\n }\n\n // why is this diff from react-native-web!? need to figure out\n for (const key in borderDefaults) {\n if (key in style) {\n style[borderDefaults[key]] = style[borderDefaults[key]] ?? 'solid'\n }\n }\n\n const all = {\n ...atomic(createCompileableStyle(createReactDOMStyle(i18Style(style)))),\n }\n\n return Object.keys(all).map((key) => {\n const val = all[key]\n const prefix = `_${getOrCreateStylePrefix(val.property)}`\n const hash = (() => {\n let s = `${val.value}`\n .replace(/[%]/g, 'pct')\n .replace(/[^a-z0-9]/gi, 'z')\n .replace(/\\s/, '-')\n if (s.length < 16) return s\n return simpleHash(val.identifier)\n })()\n\n // pseudos have a `--` to be easier to find with concatClassNames\n const psuedoPrefix = pseudo ? `-${pseudo.name}-` : ''\n const identifier = `${prefix}-${psuedoPrefix}${hash}`\n const className = `.${identifier}`\n const rules = val.rules.map((rule) => {\n if (pseudo) {\n const psuedoPrefixSelect = [...Array(pseudo.priority)].map(() => ':root').join('') + ' '\n let res = rule\n .replace(`.${val.identifier}`, `${psuedoPrefixSelect} ${className}`)\n .replace('{', `:${pseudo.name}{`)\n\n if (pseudo.name === 'hover') {\n // hover styles need to be conditional\n // perhaps this can be generalized but for now lets just shortcut\n // and hardcode for hover styles, if we need to later we can\n // WEIRD SYNTAX, SEE:\n // https://stackoverflow.com/questions/40532204/media-query-for-devices-supporting-hover\n res = `@media not all and (hover: none) { ${res} }`\n }\n return res\n }\n return rule.replace(`.${val.identifier}`, className).replace(importantRegex, '')\n })\n const result: StyleObject = {\n property: val.property,\n value: val.value,\n identifier,\n className,\n rules,\n }\n return result\n })\n}\n"],
|
|
5
|
+
"mappings": ";;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEO,MAAM,UAAU;AAAA,EACrB,kBAAkB;AAAA,IAChB,MAAM;AAAA,IACN,UAAU;AAAA;AAAA,EAEZ,YAAY;AAAA,IACV,MAAM;AAAA,IACN,UAAU;AAAA;AAAA,EAEZ,YAAY;AAAA,IACV,MAAM;AAAA,IACN,UAAU;AAAA;AAAA,EAEZ,YAAY;AAAA,IACV,MAAM;AAAA,IACN,UAAU;AAAA;AAAA;AAId,MAAM,iBAAiB;AAAA,EACrB,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA;AAGb,yBAAyB,OAAY;AAC1C,QAAM,SAAuC;AAAA,IAC3C,MAAM;AAAA;AAGR,aAAW,OAAO,OAAO;AACvB,QAAI,CAAC,CAAC,QAAQ,MAAM;AAClB,aAAO,OAAO,MAAM;AAAA,WACf;AACL,aAAO,KAAK,OAAO,MAAM;AAAA;AAAA;AAG7B,SAAO,OAAO,KAAK,QAChB,IAAI,CAAC,QAAQ;AACZ,WAAO,eAAe,OAAO,MAAM,QAAQ;AAAA,KAE5C;AAAA;AAhBW;AAmBhB,MAAM,iBAAiB;AAEvB,wBAAwB,OAAkB,QAA4D;AACpG,MAAI,SAAS,QAAQ,OAAO,UAAU,UAAU;AAC9C,UAAM,IAAI,MAAM,sBAAsB,OAAO,WAAW;AAAA;AAI1D,aAAW,OAAO,gBAAgB;AAChC,QAAI,OAAO,OAAO;AAChB,YAAM,eAAe,QAAQ,MAAM,eAAe,SAAS;AAAA;AAAA;AAI/D,QAAM,MAAM;AAAA,OACP,OAAO,uBAAuB,oBAAoB,SAAS;AAAA;AAGhE,SAAO,OAAO,KAAK,KAAK,IAAI,CAAC,QAAQ;AACnC,UAAM,MAAM,IAAI;AAChB,UAAM,SAAS,IAAI,uBAAuB,IAAI;AAC9C,UAAM,OAAQ,OAAM;AAClB,UAAI,IAAI,GAAG,IAAI,QACZ,QAAQ,QAAQ,OAChB,QAAQ,eAAe,KACvB,QAAQ,MAAM;AACjB,UAAI,EAAE,SAAS;AAAI,eAAO;AAC1B,aAAO,WAAW,IAAI;AAAA;AAIxB,UAAM,eAAe,SAAS,IAAI,OAAO,UAAU;AACnD,UAAM,aAAa,GAAG,UAAU,eAAe;AAC/C,UAAM,YAAY,IAAI;AACtB,UAAM,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AACpC,UAAI,QAAQ;AACV,cAAM,qBAAqB,CAAC,GAAG,MAAM,OAAO,WAAW,IAAI,MAAM,SAAS,KAAK,MAAM;AACrF,YAAI,MAAM,KACP,QAAQ,IAAI,IAAI,cAAc,GAAG,sBAAsB,aACvD,QAAQ,KAAK,IAAI,OAAO;AAE3B,YAAI,OAAO,SAAS,SAAS;AAM3B,gBAAM,sCAAsC;AAAA;AAE9C,eAAO;AAAA;AAET,aAAO,KAAK,QAAQ,IAAI,IAAI,cAAc,WAAW,QAAQ,gBAAgB;AAAA;AAE/E,UAAM,SAAsB;AAAA,MAC1B,UAAU,IAAI;AAAA,MACd,OAAO,IAAI;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA;AAEF,WAAO;AAAA;AAAA;AA1DF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -21,95 +25,53 @@ var __export = (target, all) => {
|
|
|
21
25
|
for (var name in all)
|
|
22
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
27
|
};
|
|
28
|
+
var __reExport = (target, module2, desc) => {
|
|
29
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(module2))
|
|
31
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
32
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __toModule = (module2) => {
|
|
37
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
38
|
+
};
|
|
24
39
|
|
|
25
40
|
// src/index.ts
|
|
26
41
|
__export(exports, {
|
|
27
|
-
AllRules: () => AllRules,
|
|
28
42
|
concatClassName: () => concatClassName,
|
|
29
|
-
|
|
43
|
+
getNiceKey: () => getNiceKey,
|
|
44
|
+
getOrCreateStylePrefix: () => getOrCreateStylePrefix,
|
|
45
|
+
getStylesAtomic: () => getStylesAtomic,
|
|
46
|
+
pseudos: () => pseudos,
|
|
30
47
|
stylePropsAll: () => stylePropsAll,
|
|
31
48
|
stylePropsText: () => stylePropsText,
|
|
32
49
|
stylePropsTextOnly: () => stylePropsTextOnly,
|
|
33
50
|
stylePropsTransform: () => stylePropsTransform,
|
|
34
51
|
stylePropsView: () => stylePropsView,
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
uniqueKeyToStyleName: () => uniqueKeyToStyleName,
|
|
53
|
+
uniqueStyleKeys: () => uniqueStyleKeys,
|
|
54
|
+
validStyles: () => validStyles
|
|
37
55
|
});
|
|
38
56
|
|
|
39
|
-
// src/
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let propObjects = null;
|
|
46
|
-
for (let x = len; x >= 0; x--) {
|
|
47
|
-
const cns = classNamesOrPropObjects[x];
|
|
48
|
-
if (!cns)
|
|
49
|
-
continue;
|
|
50
|
-
if (!Array.isArray(cns) && typeof cns !== "string") {
|
|
51
|
-
propObjects = propObjects || [];
|
|
52
|
-
propObjects.push(cns);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const names = Array.isArray(cns) ? cns : cns.split(" ");
|
|
56
|
-
const numNames = names.length;
|
|
57
|
-
for (let i = numNames - 1; i >= 0; i--) {
|
|
58
|
-
const name = names[i];
|
|
59
|
-
if (!name || name === " ")
|
|
60
|
-
continue;
|
|
61
|
-
if (name[0] !== "_") {
|
|
62
|
-
final = name + " " + final;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const splitIndex = name.indexOf("-");
|
|
66
|
-
if (splitIndex < 1) {
|
|
67
|
-
final = name + " " + final;
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const nextChar = name[splitIndex + 1];
|
|
71
|
-
const isMediaQuery = nextChar === "_";
|
|
72
|
-
const isPsuedoQuery = nextChar === "-";
|
|
73
|
-
const styleKey = name.slice(1, splitIndex);
|
|
74
|
-
const mediaKey = isMediaQuery || isPsuedoQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null;
|
|
75
|
-
const uid = mediaKey ? styleKey + mediaKey : styleKey;
|
|
76
|
-
if (!isMediaQuery && !isPsuedoQuery) {
|
|
77
|
-
if (usedPrefixes.indexOf(uid) > -1) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
usedPrefixes.push(uid);
|
|
81
|
-
}
|
|
82
|
-
const propName = styleKey;
|
|
83
|
-
if (propName && propObjects) {
|
|
84
|
-
if (propObjects.some((po) => {
|
|
85
|
-
if (mediaKey) {
|
|
86
|
-
const propKey = pseudoInvert[mediaKey];
|
|
87
|
-
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null;
|
|
88
|
-
}
|
|
89
|
-
const res = po && propName in po && po[propName] !== null;
|
|
90
|
-
return res;
|
|
91
|
-
})) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
final = name + " " + final;
|
|
57
|
+
// src/getNiceKey.ts
|
|
58
|
+
function getNiceKey(name, len = 2) {
|
|
59
|
+
let key = "";
|
|
60
|
+
for (const [index, char] of name.split("").entries()) {
|
|
61
|
+
if (index === 0 || char.toUpperCase() === char) {
|
|
62
|
+
key += name.slice(index, index + len);
|
|
96
63
|
}
|
|
97
64
|
}
|
|
98
|
-
return
|
|
65
|
+
return key;
|
|
99
66
|
}
|
|
100
|
-
__name(
|
|
101
|
-
var pseudoInvert = {
|
|
102
|
-
hover: "hoverStyle",
|
|
103
|
-
focus: "focusStyle",
|
|
104
|
-
press: "pressStyle"
|
|
105
|
-
};
|
|
67
|
+
__name(getNiceKey, "getNiceKey");
|
|
106
68
|
|
|
107
69
|
// src/validStyleProps.ts
|
|
108
70
|
var stylePropsTransform = {
|
|
109
71
|
x: true,
|
|
110
72
|
y: true,
|
|
111
|
-
scale: true,
|
|
112
73
|
perspective: true,
|
|
74
|
+
scale: true,
|
|
113
75
|
scaleX: true,
|
|
114
76
|
scaleY: true,
|
|
115
77
|
skewX: true,
|
|
@@ -120,9 +82,13 @@ var stylePropsTransform = {
|
|
|
120
82
|
rotateX: true,
|
|
121
83
|
rotateZ: true
|
|
122
84
|
};
|
|
123
|
-
var stylePropsView = Object.freeze(__spreadValues(
|
|
85
|
+
var stylePropsView = Object.freeze(__spreadValues({
|
|
86
|
+
pointerEvents: true,
|
|
87
|
+
userSelect: true,
|
|
88
|
+
cursor: true,
|
|
124
89
|
backfaceVisibility: true,
|
|
125
90
|
backgroundColor: true,
|
|
91
|
+
boxSizing: true,
|
|
126
92
|
borderBottomColor: true,
|
|
127
93
|
borderBottomEndRadius: true,
|
|
128
94
|
borderBottomLeftRadius: true,
|
|
@@ -198,15 +164,10 @@ var stylePropsView = Object.freeze(__spreadValues(__spreadValues({
|
|
|
198
164
|
shadowColor: true,
|
|
199
165
|
shadowOffset: true,
|
|
200
166
|
shadowOpacity: true,
|
|
201
|
-
shadowRadius: true
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
contain: true,
|
|
206
|
-
pointerEvents: true,
|
|
207
|
-
boxSizing: true
|
|
208
|
-
}));
|
|
209
|
-
var stylePropsTextOnly = Object.freeze(__spreadValues({
|
|
167
|
+
shadowRadius: true,
|
|
168
|
+
contain: true
|
|
169
|
+
}, stylePropsTransform));
|
|
170
|
+
var stylePropsTextOnly = Object.freeze({
|
|
210
171
|
color: true,
|
|
211
172
|
fontFamily: true,
|
|
212
173
|
fontSize: true,
|
|
@@ -222,22 +183,197 @@ var stylePropsTextOnly = Object.freeze(__spreadValues({
|
|
|
222
183
|
textShadowOffset: true,
|
|
223
184
|
textShadowRadius: true,
|
|
224
185
|
textTransform: true
|
|
225
|
-
}
|
|
226
|
-
whiteSpace: true,
|
|
227
|
-
wordWrap: true,
|
|
228
|
-
textOverflow: true,
|
|
229
|
-
textDecorationDistance: true
|
|
230
|
-
}));
|
|
186
|
+
});
|
|
231
187
|
var stylePropsText = Object.freeze(__spreadValues(__spreadValues({}, stylePropsView), stylePropsTextOnly));
|
|
232
188
|
var stylePropsAll = stylePropsText;
|
|
233
|
-
var
|
|
189
|
+
var validStyles = __spreadValues({
|
|
234
190
|
hoverStyle: true,
|
|
235
191
|
pressStyle: true,
|
|
236
192
|
focusStyle: true
|
|
193
|
+
}, stylePropsView);
|
|
194
|
+
|
|
195
|
+
// src/uniqueStyleKeys.ts
|
|
196
|
+
var existing = new Set();
|
|
197
|
+
var uniqueStyleKeys = {};
|
|
198
|
+
var uniqueKeyToStyleName = {};
|
|
199
|
+
for (const name in stylePropsAll) {
|
|
200
|
+
addStylePrefix(name);
|
|
201
|
+
}
|
|
202
|
+
function getOrCreateStylePrefix(name) {
|
|
203
|
+
return uniqueStyleKeys[name] ?? addStylePrefix(name);
|
|
204
|
+
}
|
|
205
|
+
__name(getOrCreateStylePrefix, "getOrCreateStylePrefix");
|
|
206
|
+
function addStylePrefix(name) {
|
|
207
|
+
let len = 1;
|
|
208
|
+
let key = getNiceKey(name);
|
|
209
|
+
while (existing.has(key)) {
|
|
210
|
+
len++;
|
|
211
|
+
key = getNiceKey(name, len);
|
|
212
|
+
}
|
|
213
|
+
existing.add(key);
|
|
214
|
+
uniqueStyleKeys[name] = key;
|
|
215
|
+
uniqueKeyToStyleName[key] = name;
|
|
216
|
+
return key;
|
|
217
|
+
}
|
|
218
|
+
__name(addStylePrefix, "addStylePrefix");
|
|
219
|
+
|
|
220
|
+
// src/concatClassName.ts
|
|
221
|
+
var pseudoInvert = {
|
|
222
|
+
hover: "hoverStyle",
|
|
223
|
+
focus: "focusStyle",
|
|
224
|
+
press: "pressStyle"
|
|
237
225
|
};
|
|
238
|
-
|
|
226
|
+
function concatClassName(className, ...propObjects) {
|
|
227
|
+
const usedPrefixes = new Set();
|
|
228
|
+
const final = [];
|
|
229
|
+
const names = className.split(" ");
|
|
230
|
+
const hasPropObjects = propObjects.length;
|
|
231
|
+
for (let i = names.length - 1; i >= 0; i--) {
|
|
232
|
+
const name = names[i];
|
|
233
|
+
if (!name || name === " ")
|
|
234
|
+
continue;
|
|
235
|
+
if (name[0] !== "_") {
|
|
236
|
+
final.push(name);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const splitIndex = name.indexOf("-");
|
|
240
|
+
if (splitIndex < 1) {
|
|
241
|
+
final.push(name);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const nextChar = name[splitIndex + 1];
|
|
245
|
+
const isMediaQuery = nextChar === "_";
|
|
246
|
+
const isPsuedoQuery = nextChar === "-";
|
|
247
|
+
const styleKey = name.slice(1, splitIndex);
|
|
248
|
+
const mediaKey = isMediaQuery || isPsuedoQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null;
|
|
249
|
+
const uid = mediaKey ? styleKey + mediaKey : styleKey;
|
|
250
|
+
if (!isMediaQuery && !isPsuedoQuery) {
|
|
251
|
+
if (usedPrefixes.has(uid)) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
usedPrefixes.add(uid);
|
|
255
|
+
}
|
|
256
|
+
const propName = uniqueKeyToStyleName[styleKey];
|
|
257
|
+
if (propName && hasPropObjects) {
|
|
258
|
+
if (propObjects.some((po) => {
|
|
259
|
+
if (mediaKey) {
|
|
260
|
+
const propKey = pseudoInvert[mediaKey];
|
|
261
|
+
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null;
|
|
262
|
+
}
|
|
263
|
+
const res = po && propName in po && po[propName] !== null;
|
|
264
|
+
return res;
|
|
265
|
+
})) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
final.push(name);
|
|
270
|
+
}
|
|
271
|
+
return final.join(" ");
|
|
272
|
+
}
|
|
273
|
+
__name(concatClassName, "concatClassName");
|
|
239
274
|
|
|
240
|
-
// src/
|
|
241
|
-
var
|
|
242
|
-
var
|
|
275
|
+
// src/getStylesAtomic.ts
|
|
276
|
+
var import_compile = __toModule(require("react-native-web/dist/cjs/exports/StyleSheet/compile"));
|
|
277
|
+
var import_createCompileableStyle = __toModule(require("react-native-web/dist/cjs/exports/StyleSheet/createCompileableStyle"));
|
|
278
|
+
var import_createReactDOMStyle = __toModule(require("react-native-web/dist/cjs/exports/StyleSheet/createReactDOMStyle"));
|
|
279
|
+
var import_i18nStyle = __toModule(require("react-native-web/dist/cjs/exports/StyleSheet/i18nStyle"));
|
|
280
|
+
|
|
281
|
+
// src/simpleHash.ts
|
|
282
|
+
var simpleHash = /* @__PURE__ */ __name((str) => {
|
|
283
|
+
let hash = 0;
|
|
284
|
+
for (let i = 0; i < str.length; i++) {
|
|
285
|
+
const char = str.charCodeAt(i);
|
|
286
|
+
hash = (hash << 5) - hash + char;
|
|
287
|
+
hash &= hash;
|
|
288
|
+
}
|
|
289
|
+
return new Uint32Array([hash])[0].toString(36);
|
|
290
|
+
}, "simpleHash");
|
|
291
|
+
|
|
292
|
+
// src/getStylesAtomic.ts
|
|
293
|
+
var pseudos = {
|
|
294
|
+
focusWithinStyle: {
|
|
295
|
+
name: "focus-within",
|
|
296
|
+
priority: 4
|
|
297
|
+
},
|
|
298
|
+
focusStyle: {
|
|
299
|
+
name: "focus",
|
|
300
|
+
priority: 3
|
|
301
|
+
},
|
|
302
|
+
pressStyle: {
|
|
303
|
+
name: "active",
|
|
304
|
+
priority: 2
|
|
305
|
+
},
|
|
306
|
+
hoverStyle: {
|
|
307
|
+
name: "hover",
|
|
308
|
+
priority: 1
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var borderDefaults = {
|
|
312
|
+
borderWidth: "borderStyle",
|
|
313
|
+
borderBottomWidth: "borderBottomStyle",
|
|
314
|
+
borderTopWidth: "borderTopStyle",
|
|
315
|
+
borderLeftWidth: "borderLeftStyle",
|
|
316
|
+
borderRightWidth: "borderRightStyle"
|
|
317
|
+
};
|
|
318
|
+
function getStylesAtomic(style) {
|
|
319
|
+
const styles = {
|
|
320
|
+
base: {}
|
|
321
|
+
};
|
|
322
|
+
for (const key in style) {
|
|
323
|
+
if (!!pseudos[key]) {
|
|
324
|
+
styles[key] = style[key];
|
|
325
|
+
} else {
|
|
326
|
+
styles.base[key] = style[key];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return Object.keys(styles).map((key) => {
|
|
330
|
+
return getAtomicStyle(styles[key], pseudos[key]);
|
|
331
|
+
}).flat();
|
|
332
|
+
}
|
|
333
|
+
__name(getStylesAtomic, "getStylesAtomic");
|
|
334
|
+
var importantRegex = /\!important*/g;
|
|
335
|
+
function getAtomicStyle(style, pseudo) {
|
|
336
|
+
if (style == null || typeof style !== "object") {
|
|
337
|
+
throw new Error(`Wrong style type: "${typeof style}": ${style}`);
|
|
338
|
+
}
|
|
339
|
+
for (const key in borderDefaults) {
|
|
340
|
+
if (key in style) {
|
|
341
|
+
style[borderDefaults[key]] = style[borderDefaults[key]] ?? "solid";
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const all = __spreadValues({}, (0, import_compile.atomic)((0, import_createCompileableStyle.default)((0, import_createReactDOMStyle.default)((0, import_i18nStyle.default)(style)))));
|
|
345
|
+
return Object.keys(all).map((key) => {
|
|
346
|
+
const val = all[key];
|
|
347
|
+
const prefix = `_${getOrCreateStylePrefix(val.property)}`;
|
|
348
|
+
const hash = (() => {
|
|
349
|
+
let s = `${val.value}`.replace(/[%]/g, "pct").replace(/[^a-z0-9]/gi, "z").replace(/\s/, "-");
|
|
350
|
+
if (s.length < 16)
|
|
351
|
+
return s;
|
|
352
|
+
return simpleHash(val.identifier);
|
|
353
|
+
})();
|
|
354
|
+
const psuedoPrefix = pseudo ? `-${pseudo.name}-` : "";
|
|
355
|
+
const identifier = `${prefix}-${psuedoPrefix}${hash}`;
|
|
356
|
+
const className = `.${identifier}`;
|
|
357
|
+
const rules = val.rules.map((rule) => {
|
|
358
|
+
if (pseudo) {
|
|
359
|
+
const psuedoPrefixSelect = [...Array(pseudo.priority)].map(() => ":root").join("") + " ";
|
|
360
|
+
let res = rule.replace(`.${val.identifier}`, `${psuedoPrefixSelect} ${className}`).replace("{", `:${pseudo.name}{`);
|
|
361
|
+
if (pseudo.name === "hover") {
|
|
362
|
+
res = `@media not all and (hover: none) { ${res} }`;
|
|
363
|
+
}
|
|
364
|
+
return res;
|
|
365
|
+
}
|
|
366
|
+
return rule.replace(`.${val.identifier}`, className).replace(importantRegex, "");
|
|
367
|
+
});
|
|
368
|
+
const result = {
|
|
369
|
+
property: val.property,
|
|
370
|
+
value: val.value,
|
|
371
|
+
identifier,
|
|
372
|
+
className,
|
|
373
|
+
rules
|
|
374
|
+
};
|
|
375
|
+
return result;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
__name(getAtomicStyle, "getAtomicStyle");
|
|
243
379
|
//# sourceMappingURL=index.cjs.map
|