react-native-unistyles 3.0.0-alpha.6 → 3.0.0-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. package/cxx/common/Helpers.h +24 -0
  2. package/cxx/core/HostStyle.cpp +4 -5
  3. package/cxx/core/HostStyle.h +4 -0
  4. package/cxx/core/StyleSheet.h +0 -1
  5. package/cxx/core/StyleSheetRegistry.cpp +9 -17
  6. package/cxx/core/StyleSheetRegistry.h +3 -4
  7. package/cxx/core/UnistyleData.h +22 -0
  8. package/cxx/core/UnistylesCommitHook.cpp +4 -1
  9. package/cxx/core/UnistylesRegistry.cpp +33 -49
  10. package/cxx/core/UnistylesRegistry.h +8 -8
  11. package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -3
  12. package/cxx/hybridObjects/HybridStyleSheet.cpp +8 -11
  13. package/cxx/parser/Parser.cpp +41 -57
  14. package/cxx/parser/Parser.h +8 -13
  15. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  16. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  17. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  18. package/lib/commonjs/specs/index.web.js +1 -1
  19. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  20. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  21. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  22. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  23. package/lib/commonjs/web/convert/index.js +76 -0
  24. package/lib/commonjs/web/convert/index.js.map +1 -0
  25. package/lib/commonjs/web/convert/module.d.js +2 -0
  26. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  27. package/lib/commonjs/web/convert/shadow.js +68 -0
  28. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  29. package/lib/commonjs/web/convert/style.js +89 -0
  30. package/lib/commonjs/web/convert/style.js.map +1 -0
  31. package/lib/commonjs/web/convert/textShadow.js +73 -0
  32. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  33. package/lib/commonjs/web/convert/transform.js +72 -0
  34. package/lib/commonjs/web/convert/transform.js.map +1 -0
  35. package/lib/commonjs/web/convert/types.js +9 -0
  36. package/lib/commonjs/web/convert/types.js.map +1 -0
  37. package/lib/commonjs/web/convert/utils.js +55 -0
  38. package/lib/commonjs/web/convert/utils.js.map +1 -0
  39. package/lib/commonjs/web/create.js +89 -0
  40. package/lib/commonjs/web/create.js.map +1 -0
  41. package/lib/commonjs/web/index.js +51 -0
  42. package/lib/commonjs/web/index.js.map +1 -0
  43. package/lib/commonjs/web/listener/index.js +13 -0
  44. package/lib/commonjs/web/listener/index.js.map +1 -0
  45. package/lib/commonjs/web/listener/listener.js +36 -0
  46. package/lib/commonjs/web/listener/listener.js.map +1 -0
  47. package/lib/commonjs/web/mock.js +37 -0
  48. package/lib/commonjs/web/mock.js.map +1 -0
  49. package/lib/commonjs/web/mq.js +23 -0
  50. package/lib/commonjs/web/mq.js.map +1 -0
  51. package/lib/commonjs/web/pseudo.js +11 -0
  52. package/lib/commonjs/web/pseudo.js.map +1 -0
  53. package/lib/commonjs/web/registry.js +37 -0
  54. package/lib/commonjs/web/registry.js.map +1 -0
  55. package/lib/commonjs/web/runtime.js +164 -0
  56. package/lib/commonjs/web/runtime.js.map +1 -0
  57. package/lib/commonjs/web/state.js +121 -0
  58. package/lib/commonjs/web/state.js.map +1 -0
  59. package/lib/commonjs/web/utils.js +78 -0
  60. package/lib/commonjs/web/utils.js.map +1 -0
  61. package/lib/commonjs/web/variants/getVariants.js +39 -0
  62. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  63. package/lib/commonjs/web/variants/index.js +28 -0
  64. package/lib/commonjs/web/variants/index.js.map +1 -0
  65. package/lib/commonjs/web/variants/useVariants.js +75 -0
  66. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  67. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  68. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  69. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  70. package/lib/module/specs/index.web.js +1 -1
  71. package/lib/module/specs/index.web.js.map +1 -1
  72. package/lib/module/web/convert/boxShadow.js +72 -0
  73. package/lib/module/web/convert/boxShadow.js.map +1 -0
  74. package/lib/module/web/convert/breakpoint.js +20 -0
  75. package/lib/module/web/convert/breakpoint.js.map +1 -0
  76. package/lib/module/web/convert/index.js +71 -0
  77. package/lib/module/web/convert/index.js.map +1 -0
  78. package/lib/module/web/convert/module.d.js +2 -0
  79. package/lib/module/web/convert/module.d.js.map +1 -0
  80. package/lib/module/web/convert/shadow.js +63 -0
  81. package/lib/module/web/convert/shadow.js.map +1 -0
  82. package/lib/module/web/convert/style.js +84 -0
  83. package/lib/module/web/convert/style.js.map +1 -0
  84. package/lib/module/web/convert/textShadow.js +68 -0
  85. package/lib/module/web/convert/textShadow.js.map +1 -0
  86. package/lib/module/web/convert/transform.js +67 -0
  87. package/lib/module/web/convert/transform.js.map +1 -0
  88. package/lib/module/web/convert/types.js +5 -0
  89. package/lib/module/web/convert/types.js.map +1 -0
  90. package/lib/module/web/convert/utils.js +43 -0
  91. package/lib/module/web/convert/utils.js.map +1 -0
  92. package/lib/module/web/create.js +84 -0
  93. package/lib/module/web/create.js.map +1 -0
  94. package/lib/module/web/index.js +24 -0
  95. package/lib/module/web/index.js.map +1 -0
  96. package/lib/module/web/listener/index.js +4 -0
  97. package/lib/module/web/listener/index.js.map +1 -0
  98. package/lib/module/web/listener/listener.js +31 -0
  99. package/lib/module/web/listener/listener.js.map +1 -0
  100. package/lib/module/web/mock.js +33 -0
  101. package/lib/module/web/mock.js.map +1 -0
  102. package/lib/module/web/mq.js +17 -0
  103. package/lib/module/web/mq.js.map +1 -0
  104. package/lib/module/web/pseudo.js +6 -0
  105. package/lib/module/web/pseudo.js.map +1 -0
  106. package/lib/module/web/registry.js +33 -0
  107. package/lib/module/web/registry.js.map +1 -0
  108. package/lib/module/web/runtime.js +160 -0
  109. package/lib/module/web/runtime.js.map +1 -0
  110. package/lib/module/web/state.js +117 -0
  111. package/lib/module/web/state.js.map +1 -0
  112. package/lib/module/web/utils.js +65 -0
  113. package/lib/module/web/utils.js.map +1 -0
  114. package/lib/module/web/variants/getVariants.js +34 -0
  115. package/lib/module/web/variants/getVariants.js.map +1 -0
  116. package/lib/module/web/variants/index.js +5 -0
  117. package/lib/module/web/variants/index.js.map +1 -0
  118. package/lib/module/web/variants/useVariants.js +70 -0
  119. package/lib/module/web/variants/useVariants.js.map +1 -0
  120. package/lib/typescript/example/App.d.ts.map +1 -1
  121. package/lib/typescript/example/Typography.d.ts +11 -0
  122. package/lib/typescript/example/Typography.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  124. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  125. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  126. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  127. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  128. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  129. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  130. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  131. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  132. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  133. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  134. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  135. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  136. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  137. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  138. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  139. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  140. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  141. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  142. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  143. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  144. package/lib/typescript/{web → src/web}/index.d.ts +12 -12
  145. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  146. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  147. package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
  148. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  149. package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
  150. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  151. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  152. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  153. package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
  154. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  155. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
  156. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  157. package/lib/typescript/{web → src/web}/state.d.ts +4 -4
  158. package/lib/typescript/src/web/state.d.ts.map +1 -0
  159. package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
  160. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  161. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  162. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  163. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  164. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  165. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  166. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  167. package/package.json +1 -1
  168. package/plugin/__tests__/dependencies.spec.js +181 -103
  169. package/plugin/__tests__/ref.spec.js +346 -156
  170. package/plugin/__tests__/stylesheet.spec.js +148 -55
  171. package/plugin/index.js +31 -21
  172. package/plugin/ref.js +67 -15
  173. package/plugin/style.js +13 -24
  174. package/plugin/stylesheet.js +44 -1
  175. package/plugin/variants.js +33 -0
  176. package/src/specs/ShadowRegistry/index.ts +4 -4
  177. package/src/specs/StyleSheet/index.ts +3 -1
  178. package/src/specs/index.web.ts +1 -1
  179. package/src/types/stylesheet.ts +1 -1
  180. package/{web → src/web}/convert/breakpoint.ts +1 -1
  181. package/{web → src/web}/convert/index.ts +1 -1
  182. package/{web → src/web}/convert/types.ts +1 -1
  183. package/{web → src/web}/create.ts +36 -33
  184. package/{web → src/web}/listener/listener.ts +1 -1
  185. package/{web → src/web}/mock.ts +2 -2
  186. package/{web → src/web}/registry.ts +1 -1
  187. package/{web → src/web}/runtime.ts +4 -4
  188. package/{web → src/web}/state.ts +5 -5
  189. package/{web → src/web}/utils.ts +5 -5
  190. package/src/web/variants/getVariants.ts +42 -0
  191. package/src/web/variants/index.ts +2 -0
  192. package/{web → src/web/variants}/useVariants.ts +24 -44
  193. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  194. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  195. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  196. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  197. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  198. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  199. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  200. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  201. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  202. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  203. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  204. package/lib/typescript/web/mock.d.ts.map +0 -1
  205. package/lib/typescript/web/mq.d.ts.map +0 -1
  206. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  207. package/lib/typescript/web/registry.d.ts.map +0 -1
  208. package/lib/typescript/web/runtime.d.ts.map +0 -1
  209. package/lib/typescript/web/state.d.ts.map +0 -1
  210. package/lib/typescript/web/useVariants.d.ts +0 -3
  211. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  212. package/lib/typescript/web/utils.d.ts.map +0 -1
  213. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  214. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  215. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  216. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  217. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  218. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  219. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  220. /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
  221. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  222. /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
  223. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  224. /package/{web → src/web}/convert/module.d.ts +0 -0
  225. /package/{web → src/web}/convert/shadow.ts +0 -0
  226. /package/{web → src/web}/convert/style.ts +0 -0
  227. /package/{web → src/web}/convert/textShadow.ts +0 -0
  228. /package/{web → src/web}/convert/transform.ts +0 -0
  229. /package/{web → src/web}/convert/utils.ts +0 -0
  230. /package/{web → src/web}/index.ts +0 -0
  231. /package/{web → src/web}/listener/index.ts +0 -0
  232. /package/{web → src/web}/mq.ts +0 -0
  233. /package/{web → src/web}/pseudo.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesRegistry","keyInObject","reduceObject","toReactNativeClassName","UnistylesRuntime","createUseVariants","getVariants","UnistylesListener","create","stylesheet","computedStylesheet","theme","miniRuntime","lastlySelectedVariants","listenToDependencies","key","className","unistyles","value","args","dependencies","length","addListeners","newComputedStylesheet","result","updateStyles","styles","webUnistyleByRef","Map","disposeByRef","ref","slice","variants","Object","fromEntries","resultWithVariants","HTMLElement","storedWebUnistyle","get","webUnistyle","createStyles","set","classList","add","newVariants"],"sourceRoot":"../../../src","sources":["web/create.ts"],"mappings":";;AAGA,SAASA,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,WAAW,EAAEC,YAAY,EAAEC,s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YAAY,CAACc,WAAW,CAACtB,SAAS,EAAEkB,kBAAkB,EAAEI,WAAW,CAACvB,SAAS,CAAC;UACpG;UAGA;QACJ;QAEA,OAAOb,sBAAsB,CAAC,IAAI,EAAEgC,kBAAkB,CAAC;MAC3D,CAAC;IACL;IAEA,MAAM;MAAEnB,SAAS;MAAEC;IAAU,CAAC,GAAGjB,iBAAiB,CAACwC,YAAY,CAACtB,KAAK,EAAEH,GAAG,CAAC;IAE3ED,oBAAoB,CAAC;MAAEC,GAAG;MAAEG,KAAK;MAAED,SAAS;MAAED;IAAU,CAAC,CAAC;IAE1D,OAAOb,sBAAsB,CAACa,SAAS,EAAEE,KAAK,CAAC;EACnD,CAAC,CAAsC;EAEvCb,iBAAiB,CAACqB,MAAM,EAAEkB,WAAW,IAAI;IACrC/B,sBAAsB,GAAG+B,WAAW;EACxC,CAAC,CAAC;EAEF,OAAOlB,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ import { create } from './create';
4
+ import { UnistylesRuntime } from './runtime';
5
+ import { UnistylesState } from './state';
6
+ import { deepMergeObjects } from './utils';
7
+ export const StyleSheet = {
8
+ configure: UnistylesState.init,
9
+ create,
10
+ absoluteFill: {
11
+ position: 'absolute',
12
+ left: 0,
13
+ top: 0,
14
+ right: 0,
15
+ bottom: 0
16
+ },
17
+ compose: (a, b) => deepMergeObjects(a, b),
18
+ flatten: (...styles) => deepMergeObjects(...styles),
19
+ hairlineWidth: 1
20
+ };
21
+ export { UnistylesRuntime } from './runtime';
22
+ export * from './mock';
23
+ export const getSSRUnistyles = () => UnistylesRuntime.getSSRUnistyles();
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["create","UnistylesRuntime","UnistylesState","deepMergeObjects","StyleSheet","configure","init","absoluteFill","position","left","top","right","bottom","compose","a","b","flatten","styles","hairlineWidth","getSSRUnistyles"],"sourceRoot":"../../../src","sources":["web/index.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,UAAU;AACjC,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,gBAAgB,QAAQ,SAAS;AAE1C,OAAO,MAAMC,UAAU,GAAG;EACtBC,SAAS,EAAEH,cAAc,CAACI,IAAI;EAC9BN,MAAM;EACNO,YAAY,EAAE;IACVC,QAAQ,EAAE,UAAU;IACpBC,IAAI,EAAE,CAAC;IACPC,GAAG,EAAE,CAAC;IACNC,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACZ,CAAC;EACDC,OAAO,EAAEA,CAACC,CAAS,EAAEC,CAAS,KAAKZ,gBAAgB,CAACW,CAAC,EAAEC,CAAC,CAAC;EACzDC,OAAO,EAAEA,CAAC,GAAGC,MAAqB,KAAKd,gBAAgB,CAAC,GAAGc,MAAM,CAAC;EAClEC,aAAa,EAAE;AACnB,CAAC;AAED,SAASjB,gBAAgB,QAAQ,WAAW;AAC5C,cAAc,QAAQ;AAEtB,OAAO,MAAMkB,eAAe,GAAGA,CAAA,KAAMlB,gBAAgB,CAACkB,eAAe,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { UnistylesListener } from './listener';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesListener"],"sourceRoot":"../../../../src","sources":["web/listener/index.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,YAAY","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ import { UnistyleDependency } from '../../specs/NativePlatform';
4
+ import { UnistylesRuntime } from '../runtime';
5
+ export class UnistylesListenerBuilder {
6
+ isInitialized = false;
7
+ listeners = Array.from({
8
+ length: Object.keys(UnistyleDependency).length / 2
9
+ }, () => new Set());
10
+ emitChange = dependency => {
11
+ this.listeners[dependency]?.forEach(listener => listener());
12
+ };
13
+ initListeners = () => {
14
+ if (this.isInitialized) {
15
+ return;
16
+ }
17
+ this.isInitialized = true;
18
+ UnistylesRuntime.darkMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme));
19
+ UnistylesRuntime.lightMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme));
20
+ window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation));
21
+ window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions));
22
+ };
23
+ addListeners = (dependencies, listener) => {
24
+ dependencies.forEach(dependency => this.listeners[dependency]?.add(listener));
25
+ return () => {
26
+ dependencies.forEach(dependency => this.listeners[dependency]?.delete(listener));
27
+ };
28
+ };
29
+ }
30
+ export const UnistylesListener = new UnistylesListenerBuilder();
31
+ //# sourceMappingURL=listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistyleDependency","UnistylesRuntime","UnistylesListenerBuilder","isInitialized","listeners","Array","from","length","Object","keys","Set","emitChange","dependency","forEach","listener","initListeners","darkMedia","addEventListener","ColorScheme","lightMedia","window","Orientation","Dimensions","addListeners","dependencies","add","delete","UnistylesListener"],"sourceRoot":"../../../../src","sources":["web/listener/listener.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,MAAMC,wBAAwB,CAAC;EAC1BC,aAAa,GAAG,KAAK;EACrBC,SAAS,GAAGC,KAAK,CAACC,IAAI,CAAC;IAAEC,MAAM,EAAEC,MAAM,CAACC,IAAI,CAACT,kBAAkB,CAAC,CAACO,MAAM,GAAG;EAAE,CAAC,EAAE,MAAM,IAAIG,GAAG,CAAe,CAAC,CAAC;EAErHC,UAAU,GAAIC,UAA8B,IAAK;IAC7C,IAAI,CAACR,SAAS,CAACQ,UAAU,CAAC,EAAEC,OAAO,CAACC,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC;EAC/D,CAAC;EAEDC,aAAa,GAAGA,CAAA,KAAM;IAClB,IAAI,IAAI,CAACZ,aAAa,EAAE;MACpB;IACJ;IAEA,IAAI,CAACA,aAAa,GAAG,IAAI;IACzBF,gBAAgB,CAACe,SAAS,EAAEC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,IAAI,CAACN,UAAU,CAACX,kBAAkB,CAACkB,WAAW,CAAC,CAAC;IAC7GjB,gBAAgB,CAACkB,UAAU,EAAEF,gBAAgB,CAAC,QAAQ,EAAE,MAAM,IAAI,CAACN,UAAU,CAACX,kBAAkB,CAACkB,WAAW,CAAC,CAAC;IAC9GE,MAAM,CAACH,gBAAgB,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAACN,UAAU,CAACX,kBAAkB,CAACqB,WAAW,CAAC,CAAC;IACnGD,MAAM,CAACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,IAAI,CAACN,UAAU,CAACX,kBAAkB,CAACsB,UAAU,CAAC,CAAC;EAC3F,CAAC;EAEDC,YAAY,GAAGA,CAACC,YAAuC,EAAEV,QAAsB,KAAK;IAChFU,YAAY,CAACX,OAAO,CAACD,UAAU,IAAI,IAAI,CAACR,SAAS,CAACQ,UAAU,CAAC,EAAEa,GAAG,CAACX,QAAQ,CAAC,CAAC;IAE7E,OAAO,MAAM;MACTU,YAAY,CAACX,OAAO,CAACD,UAAU,IAAI,IAAI,CAACR,SAAS,CAACQ,UAAU,CAAC,EAAEc,MAAM,CAACZ,QAAQ,CAAC,CAAC;IACpF,CAAC;EACL,CAAC;AACL;AAEA,OAAO,MAAMa,iBAAiB,GAAG,IAAIzB,wBAAwB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ export const StatusBar = {
4
+ width: 0,
5
+ height: 0,
6
+ setStyle: () => {},
7
+ setHidden: () => {},
8
+ setBackgroundColor: () => {},
9
+ equals: () => true,
10
+ toString: () => 'StatusBar',
11
+ __type: 'web',
12
+ name: 'StatusBar'
13
+ };
14
+ export const NavigationBar = {
15
+ width: 0,
16
+ height: 0,
17
+ setHidden: () => {},
18
+ setBackgroundColor: () => {},
19
+ equals: () => true,
20
+ toString: () => 'NavigationBar',
21
+ __type: 'web',
22
+ name: 'NavigationBar'
23
+ };
24
+ export const UnistylesShadowRegistry = {
25
+ name: 'UnistylesShadowRegistry',
26
+ __type: 'web',
27
+ equals: () => true,
28
+ toString: () => 'UnistylesShadowRegistry',
29
+ dispose: () => {},
30
+ add: () => {},
31
+ remove: () => {}
32
+ };
33
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StatusBar","width","height","setStyle","setHidden","setBackgroundColor","equals","toString","__type","name","NavigationBar","UnistylesShadowRegistry","dispose","add","remove"],"sourceRoot":"../../../src","sources":["web/mock.ts"],"mappings":";;AAGA,OAAO,MAAMA,SAAwB,GAAG;EACpCC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,CAAC;EACTC,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;EAClBC,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,kBAAkB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC5BC,MAAM,EAAEA,CAAA,KAAM,IAAI;EAClBC,QAAQ,EAAEA,CAAA,KAAM,WAAW;EAC3BC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE;AACV,CAAC;AAED,OAAO,MAAMC,aAAgC,GAAG;EAC5CT,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,CAAC;EACTE,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,kBAAkB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC5BC,MAAM,EAAEA,CAAA,KAAM,IAAI;EAClBC,QAAQ,EAAEA,CAAA,KAAM,eAAe;EAC/BC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE;AACV,CAAC;AAED,OAAO,MAAME,uBAAuB,GAAG;EACnCF,IAAI,EAAE,yBAAyB;EAC/BD,MAAM,EAAE,KAAK;EACbF,MAAM,EAAEA,CAAA,KAAM,IAAI;EAClBC,QAAQ,EAAEA,CAAA,KAAM,yBAAyB;EACzCK,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,GAAG,EAAEA,CAAA,KAAM,CAAC,CAAC;EACbC,MAAM,EAAEA,CAAA,KAAM,CAAC;AACnB,CAAC","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/;
4
+ const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
5
+ const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
6
+ export const parseMq = mq => {
7
+ const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || [];
8
+ const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || [];
9
+ return {
10
+ minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
11
+ maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
12
+ minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
13
+ maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH)
14
+ };
15
+ };
16
+ export const isUnistylesMq = mq => IS_UNISTYLES_REGEX.test(mq);
17
+ //# sourceMappingURL=mq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["IS_UNISTYLES_REGEX","UNISTYLES_WIDTH_REGEX","UNISTYLES_HEIGHT_REGEX","parseMq","mq","width","fromW","toW","exec","height","fromH","toH","minWidth","undefined","Number","maxWidth","minHeight","maxHeight","isUnistylesMq","test"],"sourceRoot":"../../../src","sources":["web/mq.ts"],"mappings":";;AAEA,MAAMA,kBAAkB,GAAG,wCAAwC;AACnE,MAAMC,qBAAqB,GAAG,qCAAqC;AACnE,MAAMC,sBAAsB,GAAG,qCAAqC;AAEpE,OAAO,MAAMC,OAAO,GAAIC,EAAU,IAAiB;EAC/C,MAAM,GAAGC,KAAK,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGN,qBAAqB,CAACO,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAClE,MAAM,GAAGK,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGT,sBAAsB,CAACM,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAEpE,OAAO;IACHQ,QAAQ,EAAE,CAACP,KAAK,IAAIC,KAAK,KAAK,UAAU,GAAGO,SAAS,GAAGC,MAAM,CAACR,KAAK,CAAC;IACpES,QAAQ,EAAE,CAACV,KAAK,IAAIE,GAAG,KAAK,UAAU,GAAGM,SAAS,GAAGC,MAAM,CAACP,GAAG,CAAC;IAChES,SAAS,EAAE,CAACP,MAAM,IAAIC,KAAK,KAAK,UAAU,GAAGG,SAAS,GAAGC,MAAM,CAACJ,KAAK,CAAC;IACtEO,SAAS,EAAE,CAACR,MAAM,IAAIE,GAAG,KAAK,UAAU,GAAGE,SAAS,GAAGC,MAAM,CAACH,GAAG;EACrE,CAAC;AACL,CAAC;AAED,OAAO,MAAMO,aAAa,GAAId,EAAU,IAAKJ,kBAAkB,CAACmB,IAAI,CAACf,EAAE,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ // TODO: Add complete list of pseudo selectors
4
+ export const pseudos = ['_hover', '_css', '_before', '_after'];
5
+ export const isPseudo = selector => pseudos.includes(selector);
6
+ //# sourceMappingURL=pseudo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["pseudos","isPseudo","selector","includes"],"sourceRoot":"../../../src","sources":["web/pseudo.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,CACnB,QAAQ,EACR,MAAM,EACN,SAAS,EACT,QAAQ,CACF;AAEV,OAAO,MAAMC,QAAQ,GAAIC,QAAgB,IAAKF,OAAO,CAACG,QAAQ,CAACD,QAAkB,CAAC","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ import { createTypeStyle } from 'typestyle';
4
+ import { convertToTypeStyle } from './convert';
5
+ import { UnistylesState } from './state';
6
+ class UnistylesRegistryBuilder {
7
+ createStyles = (stylesheet, key) => {
8
+ const stylesTag = UnistylesState.createTag();
9
+ const unistyles = createTypeStyle(stylesTag);
10
+ const typestyleStylesheet = convertToTypeStyle(stylesheet);
11
+ const className = unistyles.style({
12
+ $debugName: String(key)
13
+ }, typestyleStylesheet);
14
+ if (stylesheet._web?._css) {
15
+ const customClassName = Array.isArray(stylesheet._web._css) ? stylesheet._web._css.join(' ') : stylesheet._web._css;
16
+ return {
17
+ className: `${className} ${customClassName}`,
18
+ unistyles
19
+ };
20
+ }
21
+ return {
22
+ className,
23
+ unistyles
24
+ };
25
+ };
26
+ updateStyles = (unistyles, stylesheet, className) => {
27
+ const typestyleStylesheet = convertToTypeStyle(stylesheet);
28
+ unistyles.reinit();
29
+ unistyles.cssRule(`.${className}`, typestyleStylesheet);
30
+ };
31
+ }
32
+ export const UnistylesRegistry = new UnistylesRegistryBuilder();
33
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createTypeStyle","convertToTypeStyle","UnistylesState","UnistylesRegistryBuilder","createStyles","stylesheet","key","stylesTag","createTag","unistyles","typestyleStylesheet","className","style","$debugName","String","_web","_css","customClassName","Array","isArray","join","updateStyles","reinit","cssRule","UnistylesRegistry"],"sourceRoot":"../../../src","sources":["web/registry.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAmB,WAAW;AAEtD,SAASC,kBAAkB,QAAQ,WAAW;AAC9C,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,wBAAwB,CAAC;EAC3BC,YAAY,GAAGA,CAACC,UAA2B,EAAEC,GAAoB,KAAK;IAClE,MAAMC,SAAS,GAAGL,cAAc,CAACM,SAAS,CAAC,CAAC;IAC5C,MAAMC,SAAS,GAAGT,eAAe,CAACO,SAAS,CAAC;IAC5C,MAAMG,mBAAmB,GAAGT,kBAAkB,CAACI,UAAU,CAAC;IAE1D,MAAMM,SAAS,GAAGF,SAAS,CAACG,KAAK,CAAC;MAC9BC,UAAU,EAAEC,MAAM,CAACR,GAAG;IAC1B,CAAC,EAAEI,mBAAmB,CAAC;IAEvB,IAAIL,UAAU,CAACU,IAAI,EAAEC,IAAI,EAAE;MACvB,MAAMC,eAAe,GAAGC,KAAK,CAACC,OAAO,CAACd,UAAU,CAACU,IAAI,CAACC,IAAI,CAAC,GACrDX,UAAU,CAACU,IAAI,CAACC,IAAI,CAACI,IAAI,CAAC,GAAG,CAAC,GAC9Bf,UAAU,CAACU,IAAI,CAACC,IAAI;MAE1B,OAAO;QACHL,SAAS,EAAE,GAAGA,SAAS,IAAIM,eAAe,EAAE;QAC5CR;MACJ,CAAC;IACL;IAEA,OAAO;MACHE,SAAS;MACTF;IACJ,CAAC;EACL,CAAC;EAEDY,YAAY,GAAGA,CAACZ,SAAoB,EAAEJ,UAA2B,EAAEM,SAAiB,KAAK;IACrF,MAAMD,mBAAmB,GAAGT,kBAAkB,CAACI,UAAU,CAAC;IAE1DI,SAAS,CAACa,MAAM,CAAC,CAAC;IAClBb,SAAS,CAACc,OAAO,CAAC,IAAIZ,SAAS,EAAE,EAAED,mBAAmB,CAAC;EAC3D,CAAC;AACL;AAEA,OAAO,MAAMc,iBAAiB,GAAG,IAAIrB,wBAAwB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ import { UnistyleDependency } from '../specs/NativePlatform';
4
+ import { ColorScheme, Orientation } from '../specs/types';
5
+ import { WebContentSizeCategory } from '../types';
6
+ import { UnistylesListener } from './listener';
7
+ import { NavigationBar, StatusBar } from './mock';
8
+ import { UnistylesState } from './state';
9
+ import { hexToRGBA, isServer, schemeToTheme } from './utils';
10
+ class UnistylesRuntimeBuilder {
11
+ lightMedia = this.getLightMedia();
12
+ darkMedia = this.getDarkMedia();
13
+ getLightMedia() {
14
+ if (isServer()) {
15
+ return null;
16
+ }
17
+ if (!this.lightMedia) {
18
+ this.lightMedia = window.matchMedia('(prefers-color-scheme: light)');
19
+ }
20
+ return this.lightMedia;
21
+ }
22
+ getDarkMedia() {
23
+ if (isServer()) {
24
+ return null;
25
+ }
26
+ if (!this.darkMedia) {
27
+ this.darkMedia = window.matchMedia('(prefers-color-scheme: dark)');
28
+ }
29
+ return this.darkMedia;
30
+ }
31
+ get colorScheme() {
32
+ switch (true) {
33
+ case this.getLightMedia()?.matches:
34
+ return ColorScheme.Light;
35
+ case this.getDarkMedia()?.matches:
36
+ return ColorScheme.Dark;
37
+ default:
38
+ return ColorScheme.Unspecified;
39
+ }
40
+ }
41
+ get themeName() {
42
+ return UnistylesState.themeName;
43
+ }
44
+ get contentSizeCategory() {
45
+ return WebContentSizeCategory.Unspecified;
46
+ }
47
+ get breakpoint() {
48
+ return UnistylesState.breakpoint;
49
+ }
50
+ get orientation() {
51
+ if (isServer()) {
52
+ return Orientation.Portrait;
53
+ }
54
+ return screen.orientation.type.includes('portrait') ? Orientation.Portrait : Orientation.Landscape;
55
+ }
56
+ get theme() {
57
+ if (!this.themeName) {
58
+ throw new Error('🦄 No theme selected!');
59
+ }
60
+ const theme = UnistylesState.themes.get(this.themeName);
61
+ if (!theme) {
62
+ throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
63
+ }
64
+ return theme;
65
+ }
66
+ get pixelRatio() {
67
+ return isServer() ? 1 : window.devicePixelRatio;
68
+ }
69
+ get screen() {
70
+ if (isServer()) {
71
+ return {
72
+ width: 0,
73
+ height: 0
74
+ };
75
+ }
76
+ return {
77
+ width: window.innerWidth,
78
+ height: window.innerHeight
79
+ };
80
+ }
81
+ get fontScale() {
82
+ return 1;
83
+ }
84
+ get insets() {
85
+ return {
86
+ top: 0,
87
+ bottom: 0,
88
+ left: 0,
89
+ right: 0,
90
+ ime: 0
91
+ };
92
+ }
93
+ get statusBar() {
94
+ return StatusBar;
95
+ }
96
+ get rtl() {
97
+ return isServer() ? true : document.documentElement.dir === 'rtl';
98
+ }
99
+ get hasAdaptiveThemes() {
100
+ return UnistylesState.hasAdaptiveThemes;
101
+ }
102
+ get navigationBar() {
103
+ return NavigationBar;
104
+ }
105
+ get miniRuntime() {
106
+ return {
107
+ colorScheme: this.colorScheme,
108
+ themeName: this.themeName,
109
+ contentSizeCategory: this.contentSizeCategory,
110
+ breakpoint: this.breakpoint,
111
+ orientation: this.orientation,
112
+ pixelRatio: this.pixelRatio,
113
+ screen: this.screen,
114
+ fontScale: this.fontScale,
115
+ insets: this.insets,
116
+ statusBar: {
117
+ width: this.statusBar.width,
118
+ height: this.statusBar.height
119
+ },
120
+ navigationBar: {
121
+ width: this.navigationBar.width,
122
+ height: this.navigationBar.height
123
+ },
124
+ rtl: this.rtl,
125
+ hasAdaptiveThemes: this.hasAdaptiveThemes
126
+ };
127
+ }
128
+ setTheme = themeName => {
129
+ if (themeName === UnistylesRuntime.themeName) {
130
+ return;
131
+ }
132
+ UnistylesState.themeName = themeName;
133
+ UnistylesListener.emitChange(UnistyleDependency.Theme);
134
+ UnistylesListener.emitChange(UnistyleDependency.ThemeName);
135
+ };
136
+ setAdaptiveThemes = isEnabled => {
137
+ UnistylesState.hasAdaptiveThemes = isEnabled;
138
+ if (!isEnabled) {
139
+ return;
140
+ }
141
+ this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme));
142
+ };
143
+ setRootViewBackgroundColor = (hex, alpha) => {
144
+ if (isServer()) {
145
+ return;
146
+ }
147
+ document.documentElement.style.backgroundColor = alpha ? hexToRGBA(hex, alpha) : hex;
148
+ };
149
+ setImmersiveMode = () => {};
150
+ updateTheme = (themeName, updater) => {
151
+ const oldTheme = UnistylesState.themes.get(themeName);
152
+ if (!oldTheme) {
153
+ throw new Error(`🦄 Theme "${themeName}" is not registered!`);
154
+ }
155
+ UnistylesState.themes.set(themeName, updater(oldTheme));
156
+ };
157
+ getSSRUnistyles = () => UnistylesState.tags;
158
+ }
159
+ export const UnistylesRuntime = new UnistylesRuntimeBuilder();
160
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistyleDependency","ColorScheme","Orientation","WebContentSizeCategory","UnistylesListener","NavigationBar","StatusBar","UnistylesState","hexToRGBA","isServer","schemeToTheme","UnistylesRuntimeBuilder","lightMedia","getLightMedia","darkMedia","getDarkMedia","window","matchMedia","colorScheme","matches","Light","Dark","Unspecified","themeName","contentSizeCategory","breakpoint","orientation","Portrait","screen","type","includes","Landscape","theme","Error","themes","get","pixelRatio","devicePixelRatio","width","height","innerWidth","innerHeight","fontScale","insets","top","bottom","left","right","ime","statusBar","rtl","document","documentElement","dir","hasAdaptiveThemes","navigationBar","miniRuntime","setTheme","UnistylesRuntime","emitChange","Theme","ThemeName","setAdaptiveThemes","isEnabled","setRootViewBackgroundColor","hex","alpha","style","backgroundColor","setImmersiveMode","updateTheme","updater","oldTheme","set","getSSRUnistyles","tags"],"sourceRoot":"../../../src","sources":["web/runtime.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,WAAW,EAAEC,WAAW,QAA0C,gBAAgB;AAE3F,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,aAAa,EAAEC,SAAS,QAAQ,QAAQ;AACjD,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AAE5D,MAAMC,uBAAuB,CAAC;EAC1BC,UAAU,GAAG,IAAI,CAACC,aAAa,CAAC,CAAC;EACjCC,SAAS,GAAG,IAAI,CAACC,YAAY,CAAC,CAAC;EAEvBF,aAAaA,CAAA,EAA0B;IAC3C,IAAIJ,QAAQ,CAAC,CAAC,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,IAAI,CAAC,IAAI,CAACG,UAAU,EAAE;MAClB,IAAI,CAACA,UAAU,GAAGI,MAAM,CAACC,UAAU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CAACC,eAAe,CAACe,KAAK,CAACC,eAAe,GAAGF,KAAK,GAAG1D,SAAS,CAACyD,GAAG,EAAEC,KAAK,CAAC,GAAGD,GAAG;EACxF,CAAC;EAEDI,gBAAgB,GAAGA,CAAA,KAAM,CAAC,CAAC;EAE3BC,WAAW,GAAGA,CAAC/C,SAAuB,EAAEgD,OAA6C,KAAK;IACtF,MAAMC,QAAQ,GAAGjE,cAAc,CAAC2B,MAAM,CAACC,GAAG,CAACZ,SAAS,CAAC;IAErD,IAAI,CAACiD,QAAQ,EAAE;MACX,MAAM,IAAIvC,KAAK,CAAC,aAAaV,SAAS,sBAAsB,CAAC;IACjE;IAEAhB,cAAc,CAAC2B,MAAM,CAACuC,GAAG,CAAClD,SAAS,EAAEgD,OAAO,CAACC,QAAQ,CAAC,CAAC;EAC3D,CAAC;EAEDE,eAAe,GAAGA,CAAA,KAAMnE,cAAc,CAACoE,IAAI;AAC/C;AAEA,OAAO,MAAMjB,gBAAgB,GAAG,IAAI/C,uBAAuB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ import { createElement, createRef } from 'react';
4
+ import { UnistylesRuntime } from './runtime';
5
+ import { isServer, schemeToTheme } from './utils';
6
+ import { UnistylesListener } from './listener';
7
+ import { UnistyleDependency } from '../specs/NativePlatform';
8
+ class UnistylesStateBuilder {
9
+ isSSR = isServer();
10
+ tags = [];
11
+ themes = new Map();
12
+ hasAdaptiveThemes = false;
13
+ init = config => {
14
+ this.initThemes(config.themes);
15
+ this.initBreakpoints(config.breakpoints);
16
+ this.initSettings(config.settings);
17
+ if (this.isSSR) {
18
+ return;
19
+ }
20
+ UnistylesListener.initListeners();
21
+ };
22
+ initThemes = (themes = {}) => {
23
+ Object.entries(themes).forEach(([themeName, theme]) => {
24
+ this.themes.set(themeName, theme);
25
+ });
26
+ };
27
+ initSettings = settings => {
28
+ this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false;
29
+ const themeNames = Array.from(this.themes.keys());
30
+
31
+ // Single theme + no settings
32
+ if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
33
+ this.themeName = themeNames[0];
34
+ return;
35
+ }
36
+
37
+ // No settings
38
+ if (!settings?.adaptiveThemes && !settings?.initialTheme) {
39
+ throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config');
40
+ }
41
+
42
+ // Adaptive themes
43
+ if (settings.adaptiveThemes) {
44
+ this.themeName = schemeToTheme(UnistylesRuntime.colorScheme);
45
+ return;
46
+ }
47
+
48
+ // Initial theme
49
+ this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme;
50
+ };
51
+ initBreakpoints = (breakpoints = {}) => {
52
+ const breakpointsMap = new Map();
53
+ this.breakpoints = breakpoints;
54
+ Object.entries(breakpoints).sort(([, a], [, b]) => a - b).forEach(([breakpoint, value]) => {
55
+ if (isServer()) {
56
+ return;
57
+ }
58
+ const mediaQuery = window.matchMedia(`(min-width: ${value}px)`);
59
+ breakpointsMap.set(breakpoint, mediaQuery);
60
+ if (mediaQuery.matches) {
61
+ this.breakpoint = breakpoint;
62
+ }
63
+ mediaQuery.addEventListener('change', event => {
64
+ if (!event.matches) {
65
+ const [currentBreakpoint] = Array.from(breakpointsMap).find(([, mq]) => mq.matches) ?? [];
66
+ if (currentBreakpoint) {
67
+ this.breakpoint = currentBreakpoint;
68
+ UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
69
+ }
70
+ return;
71
+ }
72
+ this.breakpoint = breakpoint;
73
+ UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
74
+ });
75
+ });
76
+ };
77
+ createTag() {
78
+ if (!this.isSSR) {
79
+ const tag = document.createElement('style');
80
+ document.head.appendChild(tag);
81
+ return tag;
82
+ }
83
+ const tagRef = new Proxy(/*#__PURE__*/createRef(), {
84
+ set: (target, prop, value) => {
85
+ // When ref is assigned
86
+ if ('textContent' in value) {
87
+ value.textContent = tag.textContent;
88
+ }
89
+ return Reflect.set(target, prop, value);
90
+ }
91
+ });
92
+ const tagElement = /*#__PURE__*/createElement('style', {
93
+ ref: tagRef,
94
+ key: this.tags.length
95
+ }, '');
96
+ const tag = new Proxy({
97
+ textContent: ''
98
+ }, {
99
+ set: (target, prop, value) => {
100
+ if (prop !== 'textContent') {
101
+ return false;
102
+ }
103
+
104
+ // When css is updated
105
+ target.textContent = value;
106
+ if (tagRef.current) {
107
+ tagRef.current.textContent = value;
108
+ }
109
+ return true;
110
+ }
111
+ });
112
+ this.tags.push(tagElement);
113
+ return tag;
114
+ }
115
+ }
116
+ export const UnistylesState = new UnistylesStateBuilder();
117
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElement","createRef","UnistylesRuntime","isServer","schemeToTheme","UnistylesListener","UnistyleDependency","UnistylesStateBuilder","isSSR","tags","themes","Map","hasAdaptiveThemes","init","config","initThemes","initBreakpoints","breakpoints","initSettings","settings","initListeners","Object","entries","forEach","themeName","theme","set","adaptiveThemes","themeNames","Array","from","keys","initialTheme","length","Error","colorScheme","breakpointsMap","sort","a","b","breakpoint","value","mediaQuery","window","matchMedia","matches","addEventListener","event","currentBreakpoint","find","mq","emitChange","Breakpoints","createTag","tag","document","head","appendChild","tagRef","Proxy","target","prop","textContent","Reflect","tagElement","ref","key","current","push","UnistylesState"],"sourceRoot":"../../../src","sources":["web/state.ts"],"mappings":";;AAAA,SAA4BA,aAAa,EAAEC,SAAS,QAAQ,OAAO;AAKnE,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,kBAAkB,QAAQ,yBAAyB;AAE5D,MAAMC,qBAAqB,CAAC;EACPC,KAAK,GAAGL,QAAQ,CAAC,CAAC;EAC1BM,IAAI,GAAG,EAAE;EAElBC,MAAM,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAM1CC,iBAAiB,GAA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AI;MACf;IACJ,CAAC,CAAC;IAEF,IAAI,CAAChC,IAAI,CAAC2D,IAAI,CAACJ,UAAU,CAAC;IAE1B,OAAOV,GAAG;EACd;AACJ;AAEA,OAAO,MAAMe,cAAc,GAAG,IAAI9D,qBAAqB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ import { ColorScheme } from '../specs/types';
4
+ export const reduceObject = (obj, reducer) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value, key)]));
5
+ export const toReactNativeClassName = (className, values) => {
6
+ const returnValue = className ? {
7
+ $$css: true,
8
+ [className]: className
9
+ } : {};
10
+ Object.defineProperties(returnValue, reduceObject(values, value => ({
11
+ value,
12
+ enumerable: false,
13
+ configurable: true
14
+ })));
15
+ return returnValue;
16
+ };
17
+ export const keyInObject = (obj, key) => key in obj;
18
+ export const schemeToTheme = scheme => {
19
+ switch (scheme) {
20
+ case ColorScheme.Dark:
21
+ return 'dark';
22
+ case ColorScheme.Light:
23
+ default:
24
+ return 'light';
25
+ }
26
+ };
27
+ export const hexToRGBA = (hex, opacity) => hex.replace('#', '').split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num)).reduce((acc, color) => `${acc}${color},`, 'rgba(').concat(`${opacity})`);
28
+ export const isServer = () => typeof window === 'undefined';
29
+
30
+ /**
31
+ * Deeply merges properties of passed object
32
+ */
33
+ export const deepMergeObjects = (...sources) => {
34
+ const target = {};
35
+ sources.forEach(source => {
36
+ Object.keys(source).forEach(key => {
37
+ const sourceValue = source[key];
38
+ const targetValue = target[key];
39
+ if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
40
+ // @ts-expect-error - can't assign to generic
41
+ target[key] = deepMergeObjects(targetValue, sourceValue);
42
+ return;
43
+ }
44
+
45
+ // @ts-expect-error - can't assign to generic
46
+ target[key] = sourceValue;
47
+ });
48
+ });
49
+ return target;
50
+ };
51
+ export const warn = message => console.warn(`🦄 [react-native-unistyles] ${message}`);
52
+ export const equal = (a, b) => {
53
+ if (Object.is(a, b)) {
54
+ return true;
55
+ }
56
+ if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
57
+ return false;
58
+ }
59
+ const keysA = Object.keys(a);
60
+ if (keysA.length !== Object.keys(b).length) {
61
+ return false;
62
+ }
63
+ return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
64
+ };
65
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ColorScheme","reduceObject","obj","reducer","Object","fromEntries","entries","map","key","value","toReactNativeClassName","className","values","returnValue","$$css","defineProperties","enumerable","configurable","keyInObject","schemeToTheme","scheme","Dark","Light","hexToRGBA","hex","opacity","replace","split","x","parseInt","filter","num","isNaN","reduce","acc","color","concat","isServer","window","deepMergeObjects","sources","target","forEach","source","keys","sourceValue","targetValue","warn","message","console","equal","a","b","is","keysA","length","every","prototype","hasOwnProperty","call"],"sourceRoot":"../../../src","sources":["web/utils.ts"],"mappings":";;AAAA,SAASA,WAAW,QAA0B,gBAAgB;AAG9D,OAAO,MAAMC,YAAY,GAAGA,CACxBC,GAAS,EACTC,OAA+D,KAC9DC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACJ,GAAG,CAAC,CAACK,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK,CAACD,GAAG,EAAEL,OAAO,CAACM,KAAK,EAAsBD,GAAG,CAAC,CAAC,CAAC,CAAoC;AAErJ,OAAO,MAAME,sBAAsB,GAAGA,CAACC,SAAwB,EAAEC,MAAuB,KAAK;EACzF,MAAMC,WAAW,GAAGF,SAAS,GAAG;IAC5BG,KAAK,EAAE,IAAI;IACX,CAACH,SAAS,GAAGA;EACjB,CAAC,GAAG,CAAC,CAAC;EAENP,MAAM,CAACW,gBAAgB,CAACF,WAAW,EAAEZ,YAAY,CAACW,MAAM,EAAEH,KAAK,KAAK;IACh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+
3
+ import { deepMergeObjects } from '../utils';
4
+ const hasVariants = value => 'variants' in value[1];
5
+ export const getVariants = (styles, selectedVariants) => {
6
+ return Object.entries(styles).filter(hasVariants).filter(([_key, {
7
+ variants
8
+ }]) => Object.keys(variants).some(variant => variant in variants)).map(([key, {
9
+ variants,
10
+ compoundVariants = []
11
+ }]) => {
12
+ const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
13
+ const selectedVariant = selectedVariants[variant];
14
+ const selectedVariantStyles = styles[selectedVariant] ?? styles['default'];
15
+ if (!selectedVariantStyles) {
16
+ return [];
17
+ }
18
+ return selectedVariantStyles;
19
+ });
20
+ const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
21
+ const {
22
+ styles,
23
+ ...conditions
24
+ } = compoundVariant;
25
+ if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
26
+ return [];
27
+ }
28
+ return styles;
29
+ });
30
+ const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles);
31
+ return [key, mergedVariantStyles];
32
+ });
33
+ };
34
+ //# sourceMappingURL=getVariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["deepMergeObjects","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,UAAU;AAQ3C,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAE/H,OAAO,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAA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'./useVariants';
4
+ export * from './getVariants';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;AAAA,cAAc,eAAe;AAC7B,cAAc,eAAe","ignoreList":[]}