react-native-unistyles 2.0.0-rc.1 → 2.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/lib/commonjs/core/UnistyleRegistry.js +15 -25
  2. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  3. package/lib/commonjs/core/UnistylesModule.js +187 -2
  4. package/lib/commonjs/core/UnistylesModule.js.map +1 -1
  5. package/lib/commonjs/core/UnistylesModule.native.js +9 -0
  6. package/lib/commonjs/core/UnistylesModule.native.js.map +1 -0
  7. package/lib/commonjs/hooks/useCSS.js +36 -1
  8. package/lib/commonjs/hooks/useCSS.js.map +1 -1
  9. package/lib/commonjs/hooks/useCSS.native.js +9 -0
  10. package/lib/commonjs/hooks/useCSS.native.js.map +1 -0
  11. package/lib/commonjs/normalizer/normalizer.js +1 -2
  12. package/lib/commonjs/normalizer/normalizer.js.map +1 -1
  13. package/lib/commonjs/useStyles.js +1 -2
  14. package/lib/commonjs/useStyles.js.map +1 -1
  15. package/lib/commonjs/utils/breakpoints.js +2 -11
  16. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  17. package/lib/commonjs/utils/cssMediaQuery.js +3 -9
  18. package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
  19. package/lib/commonjs/utils/mq.js +12 -36
  20. package/lib/commonjs/utils/mq.js.map +1 -1
  21. package/lib/commonjs/utils/mqParser.js +1 -2
  22. package/lib/commonjs/utils/mqParser.js.map +1 -1
  23. package/lib/commonjs/utils/styles.js +34 -39
  24. package/lib/commonjs/utils/styles.js.map +1 -1
  25. package/lib/module/core/UnistyleRegistry.js +15 -25
  26. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  27. package/lib/module/core/UnistylesModule.js +186 -2
  28. package/lib/module/core/UnistylesModule.js.map +1 -1
  29. package/lib/module/core/UnistylesModule.native.js +3 -0
  30. package/lib/module/core/UnistylesModule.native.js.map +1 -0
  31. package/lib/module/hooks/useCSS.js +36 -1
  32. package/lib/module/hooks/useCSS.js.map +1 -1
  33. package/lib/module/hooks/useCSS.native.js +2 -0
  34. package/lib/module/hooks/useCSS.native.js.map +1 -0
  35. package/lib/module/normalizer/normalizer.js +1 -2
  36. package/lib/module/normalizer/normalizer.js.map +1 -1
  37. package/lib/module/useStyles.js +1 -2
  38. package/lib/module/useStyles.js.map +1 -1
  39. package/lib/module/utils/breakpoints.js +2 -11
  40. package/lib/module/utils/breakpoints.js.map +1 -1
  41. package/lib/module/utils/cssMediaQuery.js +3 -9
  42. package/lib/module/utils/cssMediaQuery.js.map +1 -1
  43. package/lib/module/utils/mq.js +12 -36
  44. package/lib/module/utils/mq.js.map +1 -1
  45. package/lib/module/utils/mqParser.js +1 -2
  46. package/lib/module/utils/mqParser.js.map +1 -1
  47. package/lib/module/utils/styles.js +34 -39
  48. package/lib/module/utils/styles.js.map +1 -1
  49. package/lib/typescript/src/core/UnistylesModule.d.ts +17 -4
  50. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
  51. package/lib/typescript/src/core/UnistylesModule.native.d.ts +6 -0
  52. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -0
  53. package/lib/typescript/src/hooks/useCSS.d.ts +1 -1
  54. package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
  55. package/lib/typescript/src/hooks/useCSS.native.d.ts +3 -0
  56. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -0
  57. package/package.json +6 -8
  58. package/src/core/UnistylesModule.native.ts +7 -0
  59. package/src/core/UnistylesModule.ts +224 -4
  60. package/src/hooks/useCSS.native.ts +3 -0
  61. package/src/hooks/useCSS.ts +49 -1
  62. package/lib/commonjs/core/UnistylesModule.web.js +0 -199
  63. package/lib/commonjs/core/UnistylesModule.web.js.map +0 -1
  64. package/lib/commonjs/hooks/useCSS.web.js +0 -46
  65. package/lib/commonjs/hooks/useCSS.web.js.map +0 -1
  66. package/lib/module/core/UnistylesModule.web.js +0 -192
  67. package/lib/module/core/UnistylesModule.web.js.map +0 -1
  68. package/lib/module/hooks/useCSS.web.js +0 -39
  69. package/lib/module/hooks/useCSS.web.js.map +0 -1
  70. package/lib/typescript/src/core/UnistylesModule.web.d.ts +0 -19
  71. package/lib/typescript/src/core/UnistylesModule.web.d.ts.map +0 -1
  72. package/lib/typescript/src/hooks/useCSS.web.d.ts +0 -3
  73. package/lib/typescript/src/hooks/useCSS.web.d.ts.map +0 -1
  74. package/src/core/UnistylesModule.web.ts +0 -227
  75. package/src/hooks/useCSS.web.ts +0 -51
@@ -1,199 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UnistylesModule = exports.UnistylesBridgeWeb = void 0;
7
- var _reactNative = require("react-native");
8
- var _plugins = require("../plugins");
9
- var _common = require("../common");
10
- class UnistylesBridgeWeb {
11
- #timerRef = undefined;
12
- #hasAdaptiveThemes = false;
13
- #supportsAutomaticColorScheme = false;
14
- #screenWidth = _common.isServer ? undefined : window.innerWidth;
15
- #screenHeight = _common.isServer ? undefined : window.innerHeight;
16
- #themes = [];
17
- #breakpoints = {};
18
- #colorScheme = this.getPreferredColorScheme();
19
- #themeName = '';
20
- #enabledPlugins = [_plugins.normalizeWebStylesPlugin.name];
21
- #unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
22
- #sortedBreakpointPairs = [];
23
- #breakpoint = '';
24
- constructor() {
25
- if (!_common.isServer) {
26
- this.setupListeners();
27
- this.#screenWidth = window.innerWidth;
28
- this.#screenHeight = window.innerHeight;
29
- }
30
- }
31
- install() {
32
- // @ts-ignore
33
- // eslint-disable-next-line no-undef
34
- globalThis.__UNISTYLES__ = new Proxy({}, {
35
- get: (_target, prop) => {
36
- switch (prop) {
37
- case 'themeName':
38
- return this.getTheme();
39
- case 'screenWidth':
40
- return this.#screenWidth;
41
- case 'screenHeight':
42
- return this.#screenHeight;
43
- case 'breakpoint':
44
- return this.#breakpoint || undefined;
45
- case 'breakpoints':
46
- return this.#breakpoints;
47
- case 'hasAdaptiveThemes':
48
- return this.#hasAdaptiveThemes;
49
- case 'sortedBreakpointPairs':
50
- return this.#sortedBreakpointPairs;
51
- case 'enabledPlugins':
52
- return this.#enabledPlugins;
53
- case 'colorScheme':
54
- return this.#colorScheme;
55
- case 'useTheme':
56
- return themeName => this.useTheme(themeName);
57
- case 'useBreakpoints':
58
- return breakpoints => this.useBreakpoints(breakpoints);
59
- case 'useAdaptiveThemes':
60
- return enable => this.useAdaptiveThemes(enable);
61
- case 'addPlugin':
62
- return (pluginName, notify) => this.addPlugin(pluginName, notify);
63
- case 'removePlugin':
64
- return pluginName => this.removePlugin(pluginName);
65
- default:
66
- return Reflect.get(this, prop);
67
- }
68
- },
69
- set: (target, prop, newValue, receiver) => {
70
- switch (prop) {
71
- case 'themes':
72
- {
73
- this.#themes = newValue;
74
- this.#supportsAutomaticColorScheme = newValue.includes('light') && newValue.includes('dark');
75
- return true;
76
- }
77
- case 'themeName':
78
- {
79
- this.#themeName = newValue;
80
- this.emitThemeChange();
81
- return true;
82
- }
83
- default:
84
- return Reflect.set(target, prop, newValue, receiver);
85
- }
86
- }
87
- });
88
- return true;
89
- }
90
- useTheme(themeName) {
91
- this.#themeName = themeName;
92
- this.emitThemeChange();
93
- }
94
- useBreakpoints(breakpoints) {
95
- this.#breakpoints = breakpoints;
96
- this.#sortedBreakpointPairs = Object.entries(breakpoints).sort((_ref, _ref2) => {
97
- let [, a] = _ref;
98
- let [, b] = _ref2;
99
- return (a ?? 0) - (b ?? 0);
100
- });
101
- if (!_common.isServer) {
102
- this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
103
- }
104
- }
105
- useAdaptiveThemes(enable) {
106
- this.#hasAdaptiveThemes = enable;
107
- if (!this.#hasAdaptiveThemes || !this.#supportsAutomaticColorScheme) {
108
- return;
109
- }
110
- if (this.#themeName !== this.#colorScheme) {
111
- this.#themeName = this.#colorScheme;
112
- this.emitThemeChange();
113
- }
114
- }
115
- addPlugin(pluginName, notify) {
116
- this.#enabledPlugins = [pluginName].concat(this.#enabledPlugins);
117
- if (notify) {
118
- this.emitPluginChange();
119
- }
120
- }
121
- removePlugin(pluginName) {
122
- this.#enabledPlugins = this.#enabledPlugins.filter(name => name !== pluginName);
123
- this.emitPluginChange();
124
- }
125
- getTheme() {
126
- if (this.#themes.length === 1) {
127
- return this.#themes.at(0);
128
- }
129
- return this.#themeName;
130
- }
131
- setupListeners() {
132
- window.addEventListener('resize', () => {
133
- clearTimeout(this.#timerRef);
134
- this.#timerRef = setTimeout(() => {
135
- this.#screenWidth = window.innerWidth;
136
- this.#screenHeight = window.innerHeight;
137
- this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
138
- this.emitLayoutChange();
139
- }, 100);
140
- });
141
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
142
- this.#colorScheme = event.matches ? 'dark' : 'light';
143
- if (!this.#supportsAutomaticColorScheme || !this.#hasAdaptiveThemes) {
144
- return;
145
- }
146
- if (this.#colorScheme !== this.#themeName) {
147
- this.#themeName = this.#colorScheme;
148
- this.emitThemeChange();
149
- }
150
- });
151
- }
152
- getBreakpointFromScreenWidth(width) {
153
- const breakpoint = this.#sortedBreakpointPairs.find((_ref3, index, otherBreakpoints) => {
154
- let [, value] = _ref3;
155
- const minVal = value;
156
- const maxVal = otherBreakpoints[index + 1]?.[1];
157
- if (!maxVal) {
158
- return true;
159
- }
160
- return width >= minVal && width < maxVal;
161
- });
162
- return breakpoint?.at(0);
163
- }
164
- getPreferredColorScheme() {
165
- if (!_common.isServer && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
166
- return 'dark';
167
- }
168
- return 'light';
169
- }
170
- emitPluginChange() {
171
- this.#unistylesEvents.emit('__unistylesOnChange', {
172
- type: 'plugin'
173
- });
174
- }
175
- emitThemeChange() {
176
- this.#unistylesEvents.emit('__unistylesOnChange', {
177
- type: 'theme',
178
- payload: {
179
- themeName: this.#themeName
180
- }
181
- });
182
- }
183
- emitLayoutChange() {
184
- this.#unistylesEvents.emit('__unistylesOnChange', {
185
- type: 'layout',
186
- payload: {
187
- breakpoint: this.#breakpoint,
188
- orientation: this.#screenWidth > this.#screenHeight ? 'landscape' : 'portrait',
189
- screen: {
190
- width: this.#screenWidth,
191
- height: this.#screenHeight
192
- }
193
- }
194
- });
195
- }
196
- }
197
- exports.UnistylesBridgeWeb = UnistylesBridgeWeb;
198
- const UnistylesModule = exports.UnistylesModule = new UnistylesBridgeWeb();
199
- //# sourceMappingURL=UnistylesModule.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_plugins","_common","UnistylesBridgeWeb","timerRef","undefined","hasAdaptiveThemes","supportsAutomaticColorScheme","screenWidth","isServer","window","innerWidth","screenHeight","innerHeight","themes","breakpoints","colorScheme","getPreferredColorScheme","themeName","enabledPlugins","normalizeWebStylesPlugin","name","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","sortedBreakpointPairs","breakpoint","constructor","setupListeners","install","globalThis","__UNISTYLES__","Proxy","get","_target","prop","getTheme","useTheme","useBreakpoints","enable","useAdaptiveThemes","pluginName","notify","addPlugin","removePlugin","Reflect","set","target","newValue","receiver","includes","emitThemeChange","Object","entries","sort","_ref","_ref2","a","b","getBreakpointFromScreenWidth","concat","emitPluginChange","filter","length","at","addEventListener","clearTimeout","setTimeout","emitLayoutChange","matchMedia","event","matches","width","find","_ref3","index","otherBreakpoints","value","minVal","maxVal","emit","type","payload","orientation","screen","height","exports","UnistylesModule"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.web.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEO,MAAMG,kBAAkB,CAAC;EAC5B,CAACC,QAAQ,GAAmCC,SAAS;EACrD,CAACC,iBAAiB,GAAY,KAAK;EACnC,CAACC,4BAA4B,GAAG,KAAK;EACrC,CAACC,WAAW,GAAGC,gBAAQ,G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,EAAE;QACLjE,SAAS,EAAE,IAAI,CAAC,CAACA;MACrB;IACJ,CAAC,CAAC;EACN;EAEQmD,gBAAgBA,CAAA,EAAG;IACvB,IAAI,CAAC,CAAC/C,eAAe,CAAC2D,IAAI,CAAC,qBAAqB,EAAE;MAC9CC,IAAI,EAAE,QAAQ;MACdC,OAAO,EAAE;QACLxD,UAAU,EAAE,IAAI,CAAC,CAACA,UAAU;QAC5ByD,WAAW,EAAG,IAAI,CAAC,CAAC5E,WAAW,GAAe,IAAI,CAAC,CAACI,YAAuB,GACrE,WAAW,GACX,UAAU;QAChByE,MAAM,EAAE;UACJZ,KAAK,EAAE,IAAI,CAAC,CAACjE,WAAW;UACxB8E,MAAM,EAAE,IAAI,CAAC,CAAC1E;QAClB;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;AAAC2E,OAAA,CAAApF,kBAAA,GAAAA,kBAAA;AAEM,MAAMqF,eAAe,GAAAD,OAAA,CAAAC,eAAA,GAAG,IAAIrF,kBAAkB,CAAC,CAAC"}
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useCSS = void 0;
7
- var _react = require("react");
8
- var _core = require("../core");
9
- var _utils = require("../utils");
10
- const useCSS = stylesheet => {
11
- const insertedIds = (0, _react.useRef)([]);
12
- (0, _react.useInsertionEffect)(() => {
13
- if (!_core.unistyles.registry.config.experimentalCSSMediaQueries) {
14
- return;
15
- }
16
- Object.entries(stylesheet).forEach(_ref => {
17
- let [_key, value] = _ref;
18
- Object.entries(value).forEach(_ref2 => {
19
- let [prop, val] = _ref2;
20
- if (!val.toString().includes('@media')) {
21
- return;
22
- }
23
- const id = (0, _utils.generateReactNativeWebId)(prop, '""');
24
- if (insertedIds.current.includes(id)) {
25
- return;
26
- }
27
- const style = document.createElement('style');
28
- style.id = id;
29
- style.innerHTML = val;
30
- document.head.appendChild(style);
31
- insertedIds.current = [...insertedIds.current, id];
32
- });
33
- });
34
- return () => {
35
- insertedIds.current.forEach(id => {
36
- const style = document.getElementById(id);
37
- if (style) {
38
- style.remove();
39
- }
40
- });
41
- insertedIds.current = [];
42
- };
43
- }, [stylesheet]);
44
- };
45
- exports.useCSS = useCSS;
46
- //# sourceMappingURL=useCSS.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_core","_utils","useCSS","stylesheet","insertedIds","useRef","useInsertionEffect","unistyles","registry","config","experimentalCSSMediaQueries","Object","entries","forEach","_ref","_key","value","_ref2","prop","val","toString","includes","id","generateReactNativeWebId","current","style","document","createElement","innerHTML","head","appendChild","getElementById","remove","exports"],"sourceRoot":"../../../src","sources":["hooks/useCSS.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEO,MAAMG,MAAM,GAAOC,UAAoC,IAAK;EAC/D,MAAMC,WAAW,GAAG,IAAAC,aAAM,EAAgB,EAAE,CAAC;EAE7C,IAAAC,yBAAkB,EAAC,MAAM;IACrB,IAAI,CAACC,eAAS,CAACC,QAAQ,CAACC,MAAM,CAACC,2BAA2B,EAAE;MACxD;IACJ;IAEAC,MAAM,CACDC,OAAO,CAACT,UAAU,CAAC,CACnBU,OAAO,CAACC,IAAA,IAAmB;MAAA,IAAlB,CAACC,IAAI,EAAEC,KAAK,CAAC,GAAAF,IAAA;MACnBH,MAAM,CAACC,OAAO,CAACI,KAAM,CAAC,CACjBH,OAAO,CAACI,KAAA,IAAiB;QAAA,IAAhB,CAACC,IAAI,EAAEC,GAAG,CAAC,GAAAF,KAAA;QACjB,IAAI,CAACE,GAAG,CAACC,QAAQ,CAAC,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC,EAAE;UACpC;QACJ;QAEA,MAAMC,EAAE,GAAG,IAAAC,+BAAwB,EAACL,IAAI,EAAE,IAAI,CAAC;QAE/C,IAAId,WAAW,CAACoB,OAAO,CAACH,QAAQ,CAACC,EAAE,CAAC,EAAE;UAClC;QACJ;QAEA,MAAMG,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;QAE7CF,KAAK,CAACH,EAAE,GAAGA,EAAE;QACbG,KAAK,CAACG,SAAS,GAAGT,GAAG;QAErBO,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,KAAK,CAAC;QAChCrB,WAAW,CAACoB,OAAO,GAAG,CAAC,GAAGpB,WAAW,CAACoB,OAAO,EAAEF,EAAE,CAAC;MACtD,CAAC,CAAC;IACV,CAAC,CAAC;IAEN,OAAO,MAAM;MACTlB,WAAW,CAACoB,OAAO,CAACX,OAAO,CAACS,EAAE,IAAI;QAC9B,MAAMG,KAAK,GAAGC,QAAQ,CAACK,cAAc,CAACT,EAAE,CAAC;QAEzC,IAAIG,KAAK,EAAE;UACPA,KAAK,CAACO,MAAM,CAAC,CAAC;QAClB;MACJ,CAAC,CAAC;MAEF5B,WAAW,CAACoB,OAAO,GAAG,EAAE;IAC5B,CAAC;EACL,CAAC,EAAE,CAACrB,UAAU,CAAC,CAAC;AACpB,CAAC;AAAA8B,OAAA,CAAA/B,MAAA,GAAAA,MAAA"}
@@ -1,192 +0,0 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native';
2
- import { normalizeWebStylesPlugin } from '../plugins';
3
- import { isServer } from '../common';
4
- export class UnistylesBridgeWeb {
5
- #timerRef = undefined;
6
- #hasAdaptiveThemes = false;
7
- #supportsAutomaticColorScheme = false;
8
- #screenWidth = isServer ? undefined : window.innerWidth;
9
- #screenHeight = isServer ? undefined : window.innerHeight;
10
- #themes = [];
11
- #breakpoints = {};
12
- #colorScheme = this.getPreferredColorScheme();
13
- #themeName = '';
14
- #enabledPlugins = [normalizeWebStylesPlugin.name];
15
- #unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
16
- #sortedBreakpointPairs = [];
17
- #breakpoint = '';
18
- constructor() {
19
- if (!isServer) {
20
- this.setupListeners();
21
- this.#screenWidth = window.innerWidth;
22
- this.#screenHeight = window.innerHeight;
23
- }
24
- }
25
- install() {
26
- // @ts-ignore
27
- // eslint-disable-next-line no-undef
28
- globalThis.__UNISTYLES__ = new Proxy({}, {
29
- get: (_target, prop) => {
30
- switch (prop) {
31
- case 'themeName':
32
- return this.getTheme();
33
- case 'screenWidth':
34
- return this.#screenWidth;
35
- case 'screenHeight':
36
- return this.#screenHeight;
37
- case 'breakpoint':
38
- return this.#breakpoint || undefined;
39
- case 'breakpoints':
40
- return this.#breakpoints;
41
- case 'hasAdaptiveThemes':
42
- return this.#hasAdaptiveThemes;
43
- case 'sortedBreakpointPairs':
44
- return this.#sortedBreakpointPairs;
45
- case 'enabledPlugins':
46
- return this.#enabledPlugins;
47
- case 'colorScheme':
48
- return this.#colorScheme;
49
- case 'useTheme':
50
- return themeName => this.useTheme(themeName);
51
- case 'useBreakpoints':
52
- return breakpoints => this.useBreakpoints(breakpoints);
53
- case 'useAdaptiveThemes':
54
- return enable => this.useAdaptiveThemes(enable);
55
- case 'addPlugin':
56
- return (pluginName, notify) => this.addPlugin(pluginName, notify);
57
- case 'removePlugin':
58
- return pluginName => this.removePlugin(pluginName);
59
- default:
60
- return Reflect.get(this, prop);
61
- }
62
- },
63
- set: (target, prop, newValue, receiver) => {
64
- switch (prop) {
65
- case 'themes':
66
- {
67
- this.#themes = newValue;
68
- this.#supportsAutomaticColorScheme = newValue.includes('light') && newValue.includes('dark');
69
- return true;
70
- }
71
- case 'themeName':
72
- {
73
- this.#themeName = newValue;
74
- this.emitThemeChange();
75
- return true;
76
- }
77
- default:
78
- return Reflect.set(target, prop, newValue, receiver);
79
- }
80
- }
81
- });
82
- return true;
83
- }
84
- useTheme(themeName) {
85
- this.#themeName = themeName;
86
- this.emitThemeChange();
87
- }
88
- useBreakpoints(breakpoints) {
89
- this.#breakpoints = breakpoints;
90
- this.#sortedBreakpointPairs = Object.entries(breakpoints).sort((_ref, _ref2) => {
91
- let [, a] = _ref;
92
- let [, b] = _ref2;
93
- return (a ?? 0) - (b ?? 0);
94
- });
95
- if (!isServer) {
96
- this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
97
- }
98
- }
99
- useAdaptiveThemes(enable) {
100
- this.#hasAdaptiveThemes = enable;
101
- if (!this.#hasAdaptiveThemes || !this.#supportsAutomaticColorScheme) {
102
- return;
103
- }
104
- if (this.#themeName !== this.#colorScheme) {
105
- this.#themeName = this.#colorScheme;
106
- this.emitThemeChange();
107
- }
108
- }
109
- addPlugin(pluginName, notify) {
110
- this.#enabledPlugins = [pluginName].concat(this.#enabledPlugins);
111
- if (notify) {
112
- this.emitPluginChange();
113
- }
114
- }
115
- removePlugin(pluginName) {
116
- this.#enabledPlugins = this.#enabledPlugins.filter(name => name !== pluginName);
117
- this.emitPluginChange();
118
- }
119
- getTheme() {
120
- if (this.#themes.length === 1) {
121
- return this.#themes.at(0);
122
- }
123
- return this.#themeName;
124
- }
125
- setupListeners() {
126
- window.addEventListener('resize', () => {
127
- clearTimeout(this.#timerRef);
128
- this.#timerRef = setTimeout(() => {
129
- this.#screenWidth = window.innerWidth;
130
- this.#screenHeight = window.innerHeight;
131
- this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth);
132
- this.emitLayoutChange();
133
- }, 100);
134
- });
135
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
136
- this.#colorScheme = event.matches ? 'dark' : 'light';
137
- if (!this.#supportsAutomaticColorScheme || !this.#hasAdaptiveThemes) {
138
- return;
139
- }
140
- if (this.#colorScheme !== this.#themeName) {
141
- this.#themeName = this.#colorScheme;
142
- this.emitThemeChange();
143
- }
144
- });
145
- }
146
- getBreakpointFromScreenWidth(width) {
147
- const breakpoint = this.#sortedBreakpointPairs.find((_ref3, index, otherBreakpoints) => {
148
- let [, value] = _ref3;
149
- const minVal = value;
150
- const maxVal = otherBreakpoints[index + 1]?.[1];
151
- if (!maxVal) {
152
- return true;
153
- }
154
- return width >= minVal && width < maxVal;
155
- });
156
- return breakpoint?.at(0);
157
- }
158
- getPreferredColorScheme() {
159
- if (!isServer && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
160
- return 'dark';
161
- }
162
- return 'light';
163
- }
164
- emitPluginChange() {
165
- this.#unistylesEvents.emit('__unistylesOnChange', {
166
- type: 'plugin'
167
- });
168
- }
169
- emitThemeChange() {
170
- this.#unistylesEvents.emit('__unistylesOnChange', {
171
- type: 'theme',
172
- payload: {
173
- themeName: this.#themeName
174
- }
175
- });
176
- }
177
- emitLayoutChange() {
178
- this.#unistylesEvents.emit('__unistylesOnChange', {
179
- type: 'layout',
180
- payload: {
181
- breakpoint: this.#breakpoint,
182
- orientation: this.#screenWidth > this.#screenHeight ? 'landscape' : 'portrait',
183
- screen: {
184
- width: this.#screenWidth,
185
- height: this.#screenHeight
186
- }
187
- }
188
- });
189
- }
190
- }
191
- export const UnistylesModule = new UnistylesBridgeWeb();
192
- //# sourceMappingURL=UnistylesModule.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","normalizeWebStylesPlugin","isServer","UnistylesBridgeWeb","timerRef","undefined","hasAdaptiveThemes","supportsAutomaticColorScheme","screenWidth","window","innerWidth","screenHeight","innerHeight","themes","breakpoints","colorScheme","getPreferredColorScheme","themeName","enabledPlugins","name","unistylesEvents","Unistyles","sortedBreakpointPairs","breakpoint","constructor","setupListeners","install","globalThis","__UNISTYLES__","Proxy","get","_target","prop","getTheme","useTheme","useBreakpoints","enable","useAdaptiveThemes","pluginName","notify","addPlugin","removePlugin","Reflect","set","target","newValue","receiver","includes","emitThemeChange","Object","entries","sort","_ref","_ref2","a","b","getBreakpointFromScreenWidth","concat","emitPluginChange","filter","length","at","addEventListener","clearTimeout","setTimeout","emitLayoutChange","matchMedia","event","matches","width","find","_ref3","index","otherBreakpoints","value","minVal","maxVal","emit","type","payload","orientation","screen","height","UnistylesModule"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.web.ts"],"mappings":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OAAO;EAClB;EAEQV,gBAAgBA,CAAA,EAAG;IACvB,IAAI,CAAC,CAACtC,eAAe,CAACyD,IAAI,CAAC,qBAAqB,EAAE;MAC9CC,IAAI,EAAE;IACV,CAAC,CAAC;EACN;EAEQ9B,eAAeA,CAAA,EAAG;IACtB,IAAI,CAAC,CAAC5B,eAAe,CAACyD,IAAI,CAAC,qBAAqB,EAAE;MAC9CC,IAAI,EAAE,OAAO;MACbC,OAAO,EAAE;QACL9D,SAAS,EAAE,IAAI,CAAC,CAACA;MACrB;IACJ,CAAC,CAAC;EACN;EAEQgD,gBAAgBA,CAAA,EAAG;IACvB,IAAI,CAAC,CAAC7C,eAAe,CAACyD,IAAI,CAAC,qBAAqB,EAAE;MAC9CC,IAAI,EAAE,QAAQ;MACdC,OAAO,EAAE;QACLxD,UAAU,EAAE,IAAI,CAAC,CAACA,UAAU;QAC5ByD,WAAW,EAAG,IAAI,CAAC,CAACxE,WAAW,GAAe,IAAI,CAAC,CAACG,YAAuB,GACrE,WAAW,GACX,UAAU;QAChBsE,MAAM,EAAE;UACJZ,KAAK,EAAE,IAAI,CAAC,CAAC7D,WAAW;UACxB0E,MAAM,EAAE,IAAI,CAAC,CAACvE;QAClB;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMwE,eAAe,GAAG,IAAIhF,kBAAkB,CAAC,CAAC"}
@@ -1,39 +0,0 @@
1
- import { useInsertionEffect, useRef } from 'react';
2
- import { unistyles } from '../core';
3
- import { generateReactNativeWebId } from '../utils';
4
- export const useCSS = stylesheet => {
5
- const insertedIds = useRef([]);
6
- useInsertionEffect(() => {
7
- if (!unistyles.registry.config.experimentalCSSMediaQueries) {
8
- return;
9
- }
10
- Object.entries(stylesheet).forEach(_ref => {
11
- let [_key, value] = _ref;
12
- Object.entries(value).forEach(_ref2 => {
13
- let [prop, val] = _ref2;
14
- if (!val.toString().includes('@media')) {
15
- return;
16
- }
17
- const id = generateReactNativeWebId(prop, '""');
18
- if (insertedIds.current.includes(id)) {
19
- return;
20
- }
21
- const style = document.createElement('style');
22
- style.id = id;
23
- style.innerHTML = val;
24
- document.head.appendChild(style);
25
- insertedIds.current = [...insertedIds.current, id];
26
- });
27
- });
28
- return () => {
29
- insertedIds.current.forEach(id => {
30
- const style = document.getElementById(id);
31
- if (style) {
32
- style.remove();
33
- }
34
- });
35
- insertedIds.current = [];
36
- };
37
- }, [stylesheet]);
38
- };
39
- //# sourceMappingURL=useCSS.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useInsertionEffect","useRef","unistyles","generateReactNativeWebId","useCSS","stylesheet","insertedIds","registry","config","experimentalCSSMediaQueries","Object","entries","forEach","_ref","_key","value","_ref2","prop","val","toString","includes","id","current","style","document","createElement","innerHTML","head","appendChild","getElementById","remove"],"sourceRoot":"../../../src","sources":["hooks/useCSS.web.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,MAAM,QAAQ,OAAO;AAClD,SAASC,SAAS,QAAQ,SAAS;AAEnC,SAASC,wBAAwB,QAAQ,UAAU;AAEnD,OAAO,MAAMC,MAAM,GAAOC,UAAoC,IAAK;EAC/D,MAAMC,WAAW,GAAGL,MAAM,CAAgB,EAAE,CAAC;EAE7CD,kBAAkB,CAAC,MAAM;IACrB,IAAI,CAACE,SAAS,CAACK,QAAQ,CAACC,MAAM,CAACC,2BAA2B,EAAE;MACxD;IACJ;IAEAC,MAAM,CACDC,OAAO,CAACN,UAAU,CAAC,CACnBO,OAAO,CAACC,IAAA,IAAmB;MAAA,IAAlB,CAACC,IAAI,EAAEC,KAAK,CAAC,GAAAF,IAAA;MACnBH,MAAM,CAACC,OAAO,CAACI,KAAM,CAAC,CACjBH,OAAO,CAACI,KAAA,IAAiB;QAAA,IAAhB,CAACC,IAAI,EAAEC,GAAG,CAAC,GAAAF,KAAA;QACjB,IAAI,CAACE,GAAG,CAACC,QAAQ,CAAC,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC,EAAE;UACpC;QACJ;QAEA,MAAMC,EAAE,GAAGlB,wBAAwB,CAACc,IAAI,EAAE,IAAI,CAAC;QAE/C,IAAIX,WAAW,CAACgB,OAAO,CAACF,QAAQ,CAACC,EAAE,CAAC,EAAE;UAClC;QACJ;QAEA,MAAME,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;QAE7CF,KAAK,CAACF,EAAE,GAAGA,EAAE;QACbE,KAAK,CAACG,SAAS,GAAGR,GAAG;QAErBM,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,KAAK,CAAC;QAChCjB,WAAW,CAACgB,OAAO,GAAG,CAAC,GAAGhB,WAAW,CAACgB,OAAO,EAAED,EAAE,CAAC;MACtD,CAAC,CAAC;IACV,CAAC,CAAC;IAEN,OAAO,MAAM;MACTf,WAAW,CAACgB,OAAO,CAACV,OAAO,CAACS,EAAE,IAAI;QAC9B,MAAME,KAAK,GAAGC,QAAQ,CAACK,cAAc,CAACR,EAAE,CAAC;QAEzC,IAAIE,KAAK,EAAE;UACPA,KAAK,CAACO,MAAM,CAAC,CAAC;QAClB;MACJ,CAAC,CAAC;MAEFxB,WAAW,CAACgB,OAAO,GAAG,EAAE;IAC5B,CAAC;EACL,CAAC,EAAE,CAACjB,UAAU,CAAC,CAAC;AACpB,CAAC"}
@@ -1,19 +0,0 @@
1
- export declare class UnistylesBridgeWeb {
2
- #private;
3
- constructor();
4
- install(): boolean;
5
- private useTheme;
6
- private useBreakpoints;
7
- private useAdaptiveThemes;
8
- private addPlugin;
9
- private removePlugin;
10
- private getTheme;
11
- private setupListeners;
12
- private getBreakpointFromScreenWidth;
13
- private getPreferredColorScheme;
14
- private emitPluginChange;
15
- private emitThemeChange;
16
- private emitLayoutChange;
17
- }
18
- export declare const UnistylesModule: UnistylesBridgeWeb;
19
- //# sourceMappingURL=UnistylesModule.web.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnistylesModule.web.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesModule.web.ts"],"names":[],"mappings":"AAMA,qBAAa,kBAAkB;;;IAuBpB,OAAO;IA6Dd,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,cAAc;IA6BtB,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,uBAAuB;IAQ/B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,gBAAgB;CAe3B;AAED,eAAO,MAAM,eAAe,oBAA2B,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { ReactNativeStyleSheet } from '../types';
2
- export declare const useCSS: <T>(stylesheet: ReactNativeStyleSheet<T>) => void;
3
- //# sourceMappingURL=useCSS.web.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCSS.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCSS.web.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAGrD,eAAO,MAAM,MAAM,mDA6ClB,CAAA"}