react-native-unistyles 2.0.0-beta.7 → 2.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -35
- package/lib/commonjs/core/UnistyleRegistry.js +15 -25
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.js +187 -2
- package/lib/commonjs/core/UnistylesModule.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.native.js +9 -0
- package/lib/commonjs/core/UnistylesModule.native.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +64 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/createStyleSheet.js +5 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.js +36 -1
- package/lib/commonjs/hooks/useCSS.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.native.js +9 -0
- package/lib/commonjs/hooks/useCSS.native.js.map +1 -0
- package/lib/commonjs/index.js +16 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/normalizer/normalizer.js +1 -2
- package/lib/commonjs/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/useStyles.js +7 -2
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +2 -11
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/cssMediaQuery.js +3 -9
- package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
- package/lib/commonjs/utils/mq.js +17 -36
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js +1 -2
- package/lib/commonjs/utils/mqParser.js.map +1 -1
- package/lib/commonjs/utils/styles.js +34 -39
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +15 -25
- package/lib/module/core/UnistyleRegistry.js.map +1 -1
- package/lib/module/core/UnistylesModule.js +186 -2
- package/lib/module/core/UnistylesModule.js.map +1 -1
- package/lib/module/core/UnistylesModule.native.js +3 -0
- package/lib/module/core/UnistylesModule.native.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +64 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/createStyleSheet.js +5 -0
- package/lib/module/createStyleSheet.js.map +1 -1
- package/lib/module/hooks/useCSS.js +36 -1
- package/lib/module/hooks/useCSS.js.map +1 -1
- package/lib/module/hooks/useCSS.native.js +2 -0
- package/lib/module/hooks/useCSS.native.js.map +1 -0
- package/lib/module/index.js +17 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/normalizer/normalizer.js +1 -2
- package/lib/module/normalizer/normalizer.js.map +1 -1
- package/lib/module/useStyles.js +7 -2
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +2 -11
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/cssMediaQuery.js +3 -9
- package/lib/module/utils/cssMediaQuery.js.map +1 -1
- package/lib/module/utils/mq.js +17 -36
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/mqParser.js +1 -2
- package/lib/module/utils/mqParser.js.map +1 -1
- package/lib/module/utils/styles.js +34 -39
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.d.ts +17 -4
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.native.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +52 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/createStyleSheet.d.ts +5 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.native.d.ts +3 -0
- package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts +6 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +4 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -1
- package/package.json +14 -16
- package/src/core/UnistylesModule.native.ts +7 -0
- package/src/core/UnistylesModule.ts +224 -4
- package/src/core/UnistylesRuntime.ts +52 -0
- package/src/createStyleSheet.ts +5 -0
- package/src/hooks/useCSS.native.ts +3 -0
- package/src/hooks/useCSS.ts +49 -1
- package/src/index.ts +16 -0
- package/src/useStyles.ts +6 -0
- package/src/utils/mq.ts +4 -0
- package/lib/commonjs/core/UnistylesModule.web.js +0 -199
- package/lib/commonjs/core/UnistylesModule.web.js.map +0 -1
- package/lib/commonjs/hooks/useCSS.web.js +0 -46
- package/lib/commonjs/hooks/useCSS.web.js.map +0 -1
- package/lib/module/core/UnistylesModule.web.js +0 -192
- package/lib/module/core/UnistylesModule.web.js.map +0 -1
- package/lib/module/hooks/useCSS.web.js +0 -39
- package/lib/module/hooks/useCSS.web.js.map +0 -1
- package/lib/typescript/src/core/UnistylesModule.web.d.ts +0 -19
- package/lib/typescript/src/core/UnistylesModule.web.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useCSS.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useCSS.web.d.ts.map +0 -1
- package/src/core/UnistylesModule.web.ts +0 -227
- package/src/hooks/useCSS.web.ts +0 -51
@@ -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,C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,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":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAGhE,SAASC,wBAAwB,QAAQ,YAAY;AACrD,SAASC,QAAQ,QAAQ,WAAW;AAEpC,OAAO,MAAMC,kBAAkB,CAAC;EAC5B,CAACC,QAAQ,GAAmCC,SAAS;EACrD,CAACC,iBAAiB,GAAY,KAAK;EACnC,CAACC,4BAA4B,GAAG,KAAK;EACrC,CAACC,WAAW,GAAGN,QAAQ,GAAGG,SAAS,GAAGI,MAAM,CAACC,UAAU;EACvD,CAACC,YAAY,GAAGT,QAAQ,GAAGG,SAAS,GAAGI,MAAM,CAACG,WAAW;EACzD,CAACC,MAAM,GAAiC,EAAE;EAC1C,CAACC,WAAW,GAAyB,CAAC,CAAC;EACvC,CAACC,WAAW,GAAoB,IAAI,CAACC,uBAAuB,CAAC,CAAC;EAC9D,CAACC,SAAS,GAA0B,EAAE;EACtC,CAACC,cAAc,GAAkB,CAACjB,wBAAwB,CAACkB,IAAI,CAAC;EAChE,CAACC,eAAe,GAAG,IAAIrB,kBAAkB,CAACC,aAAa,CAACqB,SAAS,CAAC;EAClE,CAACC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C7D,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 +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"}
|
@@ -1,227 +0,0 @@
|
|
1
|
-
import { NativeEventEmitter, NativeModules } from 'react-native'
|
2
|
-
import type { UnistylesThemes, UnistylesBreakpoints } from 'react-native-unistyles'
|
3
|
-
import type { ColorSchemeName } from '../types'
|
4
|
-
import { normalizeWebStylesPlugin } from '../plugins'
|
5
|
-
import { isServer } from '../common'
|
6
|
-
|
7
|
-
export class UnistylesBridgeWeb {
|
8
|
-
#timerRef?: ReturnType<typeof setTimeout> = undefined
|
9
|
-
#hasAdaptiveThemes: boolean = false
|
10
|
-
#supportsAutomaticColorScheme = false
|
11
|
-
#screenWidth = isServer ? undefined : window.innerWidth
|
12
|
-
#screenHeight = isServer ? undefined : window.innerHeight
|
13
|
-
#themes: Array<keyof UnistylesThemes> = []
|
14
|
-
#breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
|
15
|
-
#colorScheme: ColorSchemeName = this.getPreferredColorScheme()
|
16
|
-
#themeName: keyof UnistylesThemes = '' as keyof UnistylesThemes
|
17
|
-
#enabledPlugins: Array<string> = [normalizeWebStylesPlugin.name]
|
18
|
-
#unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
|
19
|
-
#sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, number]> = []
|
20
|
-
#breakpoint: keyof UnistylesBreakpoints = '' as keyof UnistylesBreakpoints
|
21
|
-
|
22
|
-
constructor() {
|
23
|
-
if (!isServer) {
|
24
|
-
this.setupListeners()
|
25
|
-
this.#screenWidth = window.innerWidth
|
26
|
-
this.#screenHeight = window.innerHeight
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
public install() {
|
31
|
-
// @ts-ignore
|
32
|
-
// eslint-disable-next-line no-undef
|
33
|
-
globalThis.__UNISTYLES__ = new Proxy({}, {
|
34
|
-
get: (_target, prop) => {
|
35
|
-
switch (prop) {
|
36
|
-
case 'themeName':
|
37
|
-
return this.getTheme()
|
38
|
-
case 'screenWidth':
|
39
|
-
return this.#screenWidth
|
40
|
-
case 'screenHeight':
|
41
|
-
return this.#screenHeight
|
42
|
-
case 'breakpoint':
|
43
|
-
return this.#breakpoint || undefined
|
44
|
-
case 'breakpoints':
|
45
|
-
return this.#breakpoints
|
46
|
-
case 'hasAdaptiveThemes':
|
47
|
-
return this.#hasAdaptiveThemes
|
48
|
-
case 'sortedBreakpointPairs':
|
49
|
-
return this.#sortedBreakpointPairs
|
50
|
-
case 'enabledPlugins':
|
51
|
-
return this.#enabledPlugins
|
52
|
-
case 'colorScheme':
|
53
|
-
return this.#colorScheme
|
54
|
-
case 'useTheme':
|
55
|
-
return (themeName: keyof UnistylesThemes) => this.useTheme(themeName)
|
56
|
-
case 'useBreakpoints':
|
57
|
-
return (breakpoints: UnistylesBreakpoints) => this.useBreakpoints(breakpoints)
|
58
|
-
case 'useAdaptiveThemes':
|
59
|
-
return (enable: boolean) => this.useAdaptiveThemes(enable)
|
60
|
-
case 'addPlugin':
|
61
|
-
return (pluginName: string, notify: boolean) => this.addPlugin(pluginName, notify)
|
62
|
-
case 'removePlugin':
|
63
|
-
return (pluginName: string) => this.removePlugin(pluginName)
|
64
|
-
default:
|
65
|
-
return Reflect.get(this, prop)
|
66
|
-
}
|
67
|
-
},
|
68
|
-
set: (target, prop, newValue, receiver) => {
|
69
|
-
switch (prop) {
|
70
|
-
case 'themes': {
|
71
|
-
this.#themes = newValue
|
72
|
-
this.#supportsAutomaticColorScheme = newValue.includes('light') && newValue.includes('dark')
|
73
|
-
|
74
|
-
return true
|
75
|
-
}
|
76
|
-
case 'themeName': {
|
77
|
-
this.#themeName = newValue as keyof UnistylesThemes
|
78
|
-
this.emitThemeChange()
|
79
|
-
|
80
|
-
return true
|
81
|
-
}
|
82
|
-
default:
|
83
|
-
return Reflect.set(target, prop, newValue, receiver)
|
84
|
-
}
|
85
|
-
}
|
86
|
-
})
|
87
|
-
|
88
|
-
return true
|
89
|
-
}
|
90
|
-
|
91
|
-
private useTheme(themeName: keyof UnistylesThemes) {
|
92
|
-
this.#themeName = themeName
|
93
|
-
this.emitThemeChange()
|
94
|
-
}
|
95
|
-
|
96
|
-
private useBreakpoints(breakpoints: UnistylesBreakpoints) {
|
97
|
-
this.#breakpoints = breakpoints
|
98
|
-
this.#sortedBreakpointPairs = Object
|
99
|
-
.entries(breakpoints)
|
100
|
-
.sort(([, a], [, b]) => (a ?? 0) - (b ?? 0)) as Array<[keyof UnistylesBreakpoints, number]>
|
101
|
-
|
102
|
-
if (!isServer) {
|
103
|
-
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth as number)
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
private useAdaptiveThemes(enable: boolean) {
|
108
|
-
this.#hasAdaptiveThemes = enable
|
109
|
-
|
110
|
-
if (!this.#hasAdaptiveThemes || !this.#supportsAutomaticColorScheme) {
|
111
|
-
return
|
112
|
-
}
|
113
|
-
|
114
|
-
if (this.#themeName !== this.#colorScheme) {
|
115
|
-
this.#themeName = this.#colorScheme as keyof UnistylesThemes
|
116
|
-
this.emitThemeChange()
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
private addPlugin(pluginName: string, notify: boolean) {
|
121
|
-
this.#enabledPlugins = [pluginName].concat(this.#enabledPlugins)
|
122
|
-
|
123
|
-
if (notify) {
|
124
|
-
this.emitPluginChange()
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
|
-
private removePlugin(pluginName: string) {
|
129
|
-
this.#enabledPlugins = this.#enabledPlugins.filter(name => name !== pluginName)
|
130
|
-
this.emitPluginChange()
|
131
|
-
}
|
132
|
-
|
133
|
-
private getTheme(): keyof UnistylesThemes {
|
134
|
-
|
135
|
-
if (this.#themes.length === 1) {
|
136
|
-
return this.#themes.at(0) as keyof UnistylesThemes
|
137
|
-
}
|
138
|
-
|
139
|
-
return this.#themeName
|
140
|
-
}
|
141
|
-
|
142
|
-
private setupListeners() {
|
143
|
-
window.addEventListener('resize', () => {
|
144
|
-
clearTimeout(this.#timerRef)
|
145
|
-
|
146
|
-
this.#timerRef = setTimeout(() => {
|
147
|
-
this.#screenWidth = window.innerWidth
|
148
|
-
this.#screenHeight = window.innerHeight
|
149
|
-
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth)
|
150
|
-
|
151
|
-
this.emitLayoutChange()
|
152
|
-
}, 100)
|
153
|
-
})
|
154
|
-
|
155
|
-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
156
|
-
this.#colorScheme = event.matches
|
157
|
-
? 'dark'
|
158
|
-
: 'light'
|
159
|
-
|
160
|
-
if (!this.#supportsAutomaticColorScheme || !this.#hasAdaptiveThemes) {
|
161
|
-
return
|
162
|
-
}
|
163
|
-
|
164
|
-
if (this.#colorScheme !== this.#themeName) {
|
165
|
-
this.#themeName = this.#colorScheme as keyof UnistylesThemes
|
166
|
-
this.emitThemeChange()
|
167
|
-
}
|
168
|
-
})
|
169
|
-
}
|
170
|
-
|
171
|
-
private getBreakpointFromScreenWidth(width: number): keyof UnistylesBreakpoints {
|
172
|
-
const breakpoint = this.#sortedBreakpointPairs
|
173
|
-
.find(([, value], index, otherBreakpoints) => {
|
174
|
-
const minVal = value
|
175
|
-
const maxVal = otherBreakpoints[index + 1]?.[1]
|
176
|
-
|
177
|
-
if (!maxVal) {
|
178
|
-
return true
|
179
|
-
}
|
180
|
-
|
181
|
-
return width >= minVal && width < maxVal
|
182
|
-
})
|
183
|
-
|
184
|
-
return breakpoint?.at(0) as keyof UnistylesBreakpoints
|
185
|
-
}
|
186
|
-
|
187
|
-
private getPreferredColorScheme() {
|
188
|
-
if (!isServer && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
189
|
-
return 'dark'
|
190
|
-
}
|
191
|
-
|
192
|
-
return 'light'
|
193
|
-
}
|
194
|
-
|
195
|
-
private emitPluginChange() {
|
196
|
-
this.#unistylesEvents.emit('__unistylesOnChange', {
|
197
|
-
type: 'plugin'
|
198
|
-
})
|
199
|
-
}
|
200
|
-
|
201
|
-
private emitThemeChange() {
|
202
|
-
this.#unistylesEvents.emit('__unistylesOnChange', {
|
203
|
-
type: 'theme',
|
204
|
-
payload: {
|
205
|
-
themeName: this.#themeName
|
206
|
-
}
|
207
|
-
})
|
208
|
-
}
|
209
|
-
|
210
|
-
private emitLayoutChange() {
|
211
|
-
this.#unistylesEvents.emit('__unistylesOnChange', {
|
212
|
-
type: 'layout',
|
213
|
-
payload: {
|
214
|
-
breakpoint: this.#breakpoint,
|
215
|
-
orientation: (this.#screenWidth as number) > (this.#screenHeight as number)
|
216
|
-
? 'landscape'
|
217
|
-
: 'portrait',
|
218
|
-
screen: {
|
219
|
-
width: this.#screenWidth,
|
220
|
-
height: this.#screenHeight
|
221
|
-
}
|
222
|
-
}
|
223
|
-
})
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
|
-
export const UnistylesModule = new UnistylesBridgeWeb()
|
package/src/hooks/useCSS.web.ts
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
import { useInsertionEffect, useRef } from 'react'
|
2
|
-
import { unistyles } from '../core'
|
3
|
-
import type { ReactNativeStyleSheet } from '../types'
|
4
|
-
import { generateReactNativeWebId } from '../utils'
|
5
|
-
|
6
|
-
export const useCSS = <T>(stylesheet: ReactNativeStyleSheet<T>) => {
|
7
|
-
const insertedIds = useRef<Array<string>>([])
|
8
|
-
|
9
|
-
useInsertionEffect(() => {
|
10
|
-
if (!unistyles.registry.config.experimentalCSSMediaQueries) {
|
11
|
-
return
|
12
|
-
}
|
13
|
-
|
14
|
-
Object
|
15
|
-
.entries(stylesheet)
|
16
|
-
.forEach(([_key, value]) => {
|
17
|
-
Object.entries(value!)
|
18
|
-
.forEach(([prop, val]) => {
|
19
|
-
if (!val.toString().includes('@media')) {
|
20
|
-
return
|
21
|
-
}
|
22
|
-
|
23
|
-
const id = generateReactNativeWebId(prop, '""')
|
24
|
-
|
25
|
-
if (insertedIds.current.includes(id)) {
|
26
|
-
return
|
27
|
-
}
|
28
|
-
|
29
|
-
const style = document.createElement('style')
|
30
|
-
|
31
|
-
style.id = id
|
32
|
-
style.innerHTML = val
|
33
|
-
|
34
|
-
document.head.appendChild(style)
|
35
|
-
insertedIds.current = [...insertedIds.current, id]
|
36
|
-
})
|
37
|
-
})
|
38
|
-
|
39
|
-
return () => {
|
40
|
-
insertedIds.current.forEach(id => {
|
41
|
-
const style = document.getElementById(id)
|
42
|
-
|
43
|
-
if (style) {
|
44
|
-
style.remove()
|
45
|
-
}
|
46
|
-
})
|
47
|
-
|
48
|
-
insertedIds.current = []
|
49
|
-
}
|
50
|
-
}, [stylesheet])
|
51
|
-
}
|