@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.
Files changed (52) hide show
  1. package/dist/.buildinfo +1 -0
  2. package/dist/concatClassName.js +43 -55
  3. package/dist/concatClassName.js.map +2 -2
  4. package/dist/getStylesAtomic.js +17 -12
  5. package/dist/getStylesAtomic.js.map +2 -2
  6. package/dist/index.cjs +226 -90
  7. package/dist/index.cjs.map +3 -3
  8. package/dist/index.js +3 -1
  9. package/dist/index.js.map +2 -2
  10. package/dist/validStyleProps.js +11 -23
  11. package/dist/validStyleProps.js.map +2 -2
  12. package/package.json +3 -3
  13. package/dist/allRules.js +0 -9
  14. package/dist/allRules.js.map +0 -7
  15. package/dist/cjs/allRules.js +0 -15
  16. package/dist/cjs/allRules.js.map +0 -7
  17. package/dist/cjs/concatClassName.js +0 -78
  18. package/dist/cjs/concatClassName.js.map +0 -7
  19. package/dist/cjs/index.js +0 -24
  20. package/dist/cjs/index.js.map +0 -7
  21. package/dist/cjs/simpleHash.js +0 -21
  22. package/dist/cjs/simpleHash.js.map +0 -7
  23. package/dist/cjs/types.js +0 -4
  24. package/dist/cjs/types.js.map +0 -7
  25. package/dist/cjs/validStyleProps.js +0 -163
  26. package/dist/cjs/validStyleProps.js.map +0 -7
  27. package/dist/esm/allRules.js +0 -9
  28. package/dist/esm/allRules.js.map +0 -7
  29. package/dist/esm/concatClassName.js +0 -72
  30. package/dist/esm/concatClassName.js.map +0 -7
  31. package/dist/esm/index.js +0 -5
  32. package/dist/esm/index.js.map +0 -7
  33. package/dist/esm/simpleHash.js +0 -15
  34. package/dist/esm/simpleHash.js.map +0 -7
  35. package/dist/esm/types.js +0 -1
  36. package/dist/esm/types.js.map +0 -7
  37. package/dist/esm/validStyleProps.js +0 -150
  38. package/dist/esm/validStyleProps.js.map +0 -7
  39. package/dist/getStylesAtomic.native.js +0 -11
  40. package/dist/getStylesAtomic.native.js.map +0 -7
  41. package/dist/jsx/allRules.js +0 -8
  42. package/dist/jsx/concatClassName.js +0 -71
  43. package/dist/jsx/index.js +0 -4
  44. package/dist/jsx/simpleHash.js +0 -14
  45. package/dist/jsx/types.js +0 -0
  46. package/dist/jsx/validStyleProps.js +0 -149
  47. package/types/allRules.d.ts.map +0 -1
  48. package/types/concatClassName.d.ts.map +0 -1
  49. package/types/index.d.ts.map +0 -1
  50. package/types/simpleHash.d.ts.map +0 -1
  51. package/types/types.d.ts.map +0 -1
  52. package/types/validStyleProps.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"at":1636517189907}
@@ -1,71 +1,59 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- function concatClassName(_cn) {
4
- const classNamesOrPropObjects = arguments;
5
- const usedPrefixes = [];
6
- let final = "";
7
- const len = classNamesOrPropObjects.length;
8
- let propObjects = null;
9
- for (let x = len; x >= 0; x--) {
10
- const cns = classNamesOrPropObjects[x];
11
- if (!cns)
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 (!Array.isArray(cns) && typeof cns !== "string") {
14
- propObjects = propObjects || [];
15
- propObjects.push(cns);
18
+ if (name[0] !== "_") {
19
+ final.push(name);
16
20
  continue;
17
21
  }
18
- const names = Array.isArray(cns) ? cns : cns.split(" ");
19
- const numNames = names.length;
20
- for (let i = numNames - 1; i >= 0; i--) {
21
- const name = names[i];
22
- if (!name || name === " ")
23
- continue;
24
- if (name[0] !== "_") {
25
- final = name + " " + final;
26
- continue;
27
- }
28
- const splitIndex = name.indexOf("-");
29
- if (splitIndex < 1) {
30
- final = name + " " + final;
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
- const nextChar = name[splitIndex + 1];
34
- const isMediaQuery = nextChar === "_";
35
- const isPsuedoQuery = nextChar === "-";
36
- const styleKey = name.slice(1, splitIndex);
37
- const mediaKey = isMediaQuery || isPsuedoQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null;
38
- const uid = mediaKey ? styleKey + mediaKey : styleKey;
39
- if (!isMediaQuery && !isPsuedoQuery) {
40
- if (usedPrefixes.indexOf(uid) > -1) {
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": ["// perf sensitive so doing some weird stuff\n\n// testing caching\n// because we can hit these recent ones a ton of times in common cases\n// we're caching the simple case, this shouldn't be bad on memory either\n// const recently = new Map()\n// setInterval(() => {\n// recently.clear()\n// }, 1000)\n\nexport function concatClassName(_cn: any) {\n // if (arguments.length === 1) {\n // if (recently.has(arguments[0])) {\n // return recently.get(arguments[0])\n // }\n // }\n\n const classNamesOrPropObjects = arguments\n const usedPrefixes: string[] = []\n let final = ''\n\n const len = classNamesOrPropObjects.length\n let propObjects: any = null\n for (let x = len; x >= 0; x--) {\n const cns = classNamesOrPropObjects[x]\n if (!cns) continue\n if (!Array.isArray(cns) && typeof cns !== 'string') {\n // is prop object\n propObjects = propObjects || []\n propObjects.push(cns)\n continue\n }\n const names = Array.isArray(cns) ? cns : cns.split(' ')\n\n const numNames = names.length\n for (let i = numNames - 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 = name + ' ' + final\n continue\n }\n const splitIndex = name.indexOf('-')\n\n if (splitIndex < 1) {\n final = name + ' ' + final\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\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\n if (!isMediaQuery && !isPsuedoQuery) {\n if (usedPrefixes.indexOf(uid) > -1) {\n continue\n }\n usedPrefixes.push(uid)\n }\n\n // overrides for full safety\n const propName = styleKey\n if (propName && propObjects) {\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 return res\n })\n ) {\n continue\n }\n }\n\n final = name + ' ' + final\n }\n }\n\n // if (arguments.length === 1) {\n // recently.set(arguments[0], final)\n // }\n\n return final\n}\n\nconst pseudoInvert = {\n hover: 'hoverStyle',\n focus: 'focusStyle',\n press: 'pressStyle',\n}\n"],
5
- "mappings": ";;AAUO,yBAAyB,KAAU;AAOxC,QAAM,0BAA0B;AAChC,QAAM,eAAyB;AAC/B,MAAI,QAAQ;AAEZ,QAAM,MAAM,wBAAwB;AACpC,MAAI,cAAmB;AACvB,WAAS,IAAI,KAAK,KAAK,GAAG,KAAK;AAC7B,UAAM,MAAM,wBAAwB;AACpC,QAAI,CAAC;AAAK;AACV,QAAI,CAAC,MAAM,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAElD,oBAAc,eAAe;AAC7B,kBAAY,KAAK;AACjB;AAAA;AAEF,UAAM,QAAQ,MAAM,QAAQ,OAAO,MAAM,IAAI,MAAM;AAEnD,UAAM,WAAW,MAAM;AACvB,aAAS,IAAI,WAAW,GAAG,KAAK,GAAG,KAAK;AACtC,YAAM,OAAO,MAAM;AACnB,UAAI,CAAC,QAAQ,SAAS;AAAK;AAC3B,UAAI,KAAK,OAAO,KAAK;AAEnB,gBAAQ,OAAO,MAAM;AACrB;AAAA;AAEF,YAAM,aAAa,KAAK,QAAQ;AAEhC,UAAI,aAAa,GAAG;AAClB,gBAAQ,OAAO,MAAM;AACrB;AAAA;AAEF,YAAM,WAAW,KAAK,aAAa;AAGnC,YAAM,eAAe,aAAa;AAElC,YAAM,gBAAgB,aAAa;AAEnC,YAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,YAAM,WACJ,gBAAgB,gBAAgB,KAAK,MAAM,aAAa,GAAG,aAAa,KAAK;AAC/E,YAAM,MAAM,WAAW,WAAW,WAAW;AAE7C,UAAI,CAAC,gBAAgB,CAAC,eAAe;AACnC,YAAI,aAAa,QAAQ,OAAO,IAAI;AAClC;AAAA;AAEF,qBAAa,KAAK;AAAA;AAIpB,YAAM,WAAW;AACjB,UAAI,YAAY,aAAa;AAC3B,YACE,YAAY,KAAK,CAAC,OAAO;AACvB,cAAI,UAAU;AACZ,kBAAM,UAAU,aAAa;AAC7B,mBAAO,MAAM,GAAG,YAAY,YAAY,GAAG,YAAY,GAAG,aAAa;AAAA;AAEzE,gBAAM,MAAM,MAAM,YAAY,MAAM,GAAG,cAAc;AACrD,iBAAO;AAAA,YAET;AACA;AAAA;AAAA;AAIJ,cAAQ,OAAO,MAAM;AAAA;AAAA;AAQzB,SAAO;AAAA;AAnFO;AAsFhB,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA;",
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
  }
@@ -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 { AllRules } from "./AllRules";
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, avoidCollection = false) {
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], avoidCollection);
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, avoidCollection) {
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 hash = val.identifier.slice(`${val.identifier}`.lastIndexOf("-") + 1);
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 = `_${val.property}-${psuedoPrefix}${hash}`;
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 { AllRules } from './AllRules'\nimport { StyleObject } from './types'\n\nexport const pseudos = {\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, avoidCollection = false) {\n const styles: { [key: string]: ViewStyle } = {\n base: {},\n }\n // split pseudos\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], avoidCollection)\n })\n .flat()\n}\n\nconst importantRegex = /\\!important*/g\n\nfunction getAtomicStyle(\n style: ViewStyle,\n pseudo?: { name: string; priority: number },\n avoidCollection?: boolean\n): 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 // TODO man, rnw has a ton of function calls etc here\n ...atomic(createCompileableStyle(createReactDOMStyle(i18Style(style)))),\n }\n\n return Object.keys(all).map((key) => {\n const val = all[key]\n const hash = val.identifier.slice(`${val.identifier}`.lastIndexOf('-') + 1)\n // pseudos have a `--` to be easier to find with concatClassNames\n const psuedoPrefix = pseudo ? `-${pseudo.name}-` : ''\n const identifier = `_${val.property}-${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\n if (!avoidCollection) {\n if (rules.length > 1) {\n console.warn('have never seen more than one, verifying')\n }\n AllRules.add(rules[0])\n }\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;AAGO,MAAM,UAAU;AAAA,EACrB,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,kBAAkB,OAAO;AACnE,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,MAAM;AAAA,KAElD;AAAA;AAhBW;AAmBhB,MAAM,iBAAiB;AAEvB,wBACE,OACA,QACA,iBACe;AACf,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,OAEP,OAAO,uBAAuB,oBAAoB,SAAS;AAAA;AAGhE,SAAO,OAAO,KAAK,KAAK,IAAI,CAAC,QAAQ;AACnC,UAAM,MAAM,IAAI;AAChB,UAAM,OAAO,IAAI,WAAW,MAAM,GAAG,IAAI,aAAa,YAAY,OAAO;AAEzE,UAAM,eAAe,SAAS,IAAI,OAAO,UAAU;AACnD,UAAM,aAAa,IAAI,IAAI,YAAY,eAAe;AACtD,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;AAG/E,QAAI,CAAC,iBAAiB;AACpB,UAAI,MAAM,SAAS,GAAG;AACpB,gBAAQ,KAAK;AAAA;AAEf,eAAS,IAAI,MAAM;AAAA;AAGrB,UAAM,SAAsB;AAAA,MAC1B,UAAU,IAAI;AAAA,MACd,OAAO,IAAI;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA;AAEF,WAAO;AAAA;AAAA;AA9DF;",
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
- getStyleRules: () => getStyleRules,
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
- validStyles: () => validStyles,
36
- validStylesPseudo: () => validStylesPseudo
52
+ uniqueKeyToStyleName: () => uniqueKeyToStyleName,
53
+ uniqueStyleKeys: () => uniqueStyleKeys,
54
+ validStyles: () => validStyles
37
55
  });
38
56
 
39
- // src/concatClassName.ts
40
- function concatClassName(_cn) {
41
- const classNamesOrPropObjects = arguments;
42
- const usedPrefixes = [];
43
- let final = "";
44
- const len = classNamesOrPropObjects.length;
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 final;
65
+ return key;
99
66
  }
100
- __name(concatClassName, "concatClassName");
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(__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
- }, stylePropsTransform), process.env.TAMAGUI_TARGET === "web" && {
203
- userSelect: true,
204
- cursor: true,
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
- }, process.env.TAMAGUI_TARGET === "web" && {
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 validStylesPseudo = {
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
- var validStyles = __spreadValues(__spreadValues({}, validStylesPseudo), stylePropsView);
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/allRules.ts
241
- var AllRules = new Set();
242
- var getStyleRules = /* @__PURE__ */ __name(() => AllRules, "getStyleRules");
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