react-native-unistyles 2.0.0-rc.1 → 2.0.0-rc.3
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/cxx/cpp-adapter.cpp +26 -2
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +29 -3
- package/cxx/UnistylesRuntime.cpp +10 -0
- package/cxx/UnistylesRuntime.h +10 -2
- package/ios/UnistylesHelpers.h +1 -0
- package/ios/UnistylesHelpers.mm +32 -0
- package/ios/UnistylesModule.mm +39 -2
- package/lib/commonjs/common.js +21 -1
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +15 -25
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.js +190 -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 +8 -0
- package/lib/commonjs/core/UnistylesRuntime.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/hooks/useUnistyles.js +8 -1
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/index.js +12 -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 +2 -3
- 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 +12 -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/common.js +20 -0
- package/lib/module/common.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 +189 -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 +8 -0
- package/lib/module/core/UnistylesRuntime.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/hooks/useUnistyles.js +8 -1
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/index.js +2 -2
- 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 +2 -3
- 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 +12 -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/common.d.ts +19 -1
- package/lib/typescript/src/common.d.ts.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 +5 -0
- package/lib/typescript/src/core/UnistylesRuntime.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/hooks/useUnistyles.d.ts +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/unistyles.d.ts +9 -2
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/package.json +6 -8
- package/src/common.ts +21 -1
- package/src/core/UnistylesModule.native.ts +7 -0
- package/src/core/UnistylesModule.ts +227 -4
- package/src/core/UnistylesRuntime.ts +8 -0
- package/src/hooks/useCSS.native.ts +3 -0
- package/src/hooks/useCSS.ts +49 -1
- package/src/hooks/useUnistyles.ts +9 -2
- package/src/index.ts +3 -1
- package/src/types/unistyles.ts +10 -2
- package/src/useStyles.ts +1 -1
- 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,7 +1,230 @@
|
|
1
|
-
import { NativeModules } from 'react-native'
|
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'
|
2
6
|
|
3
|
-
|
4
|
-
|
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
|
+
#contentSizeCategory: string = 'unspecified'
|
22
|
+
|
23
|
+
constructor() {
|
24
|
+
if (!isServer) {
|
25
|
+
this.setupListeners()
|
26
|
+
this.#screenWidth = window.innerWidth
|
27
|
+
this.#screenHeight = window.innerHeight
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
public 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 'contentSizeCategory':
|
44
|
+
return this.#contentSizeCategory
|
45
|
+
case 'breakpoint':
|
46
|
+
return this.#breakpoint || undefined
|
47
|
+
case 'breakpoints':
|
48
|
+
return this.#breakpoints
|
49
|
+
case 'hasAdaptiveThemes':
|
50
|
+
return this.#hasAdaptiveThemes
|
51
|
+
case 'sortedBreakpointPairs':
|
52
|
+
return this.#sortedBreakpointPairs
|
53
|
+
case 'enabledPlugins':
|
54
|
+
return this.#enabledPlugins
|
55
|
+
case 'colorScheme':
|
56
|
+
return this.#colorScheme
|
57
|
+
case 'useTheme':
|
58
|
+
return (themeName: keyof UnistylesThemes) => this.useTheme(themeName)
|
59
|
+
case 'useBreakpoints':
|
60
|
+
return (breakpoints: UnistylesBreakpoints) => this.useBreakpoints(breakpoints)
|
61
|
+
case 'useAdaptiveThemes':
|
62
|
+
return (enable: boolean) => this.useAdaptiveThemes(enable)
|
63
|
+
case 'addPlugin':
|
64
|
+
return (pluginName: string, notify: boolean) => this.addPlugin(pluginName, notify)
|
65
|
+
case 'removePlugin':
|
66
|
+
return (pluginName: string) => this.removePlugin(pluginName)
|
67
|
+
default:
|
68
|
+
return Reflect.get(this, prop)
|
69
|
+
}
|
70
|
+
},
|
71
|
+
set: (target, prop, newValue, receiver) => {
|
72
|
+
switch (prop) {
|
73
|
+
case 'themes': {
|
74
|
+
this.#themes = newValue
|
75
|
+
this.#supportsAutomaticColorScheme = newValue.includes('light') && newValue.includes('dark')
|
76
|
+
|
77
|
+
return true
|
78
|
+
}
|
79
|
+
case 'themeName': {
|
80
|
+
this.#themeName = newValue as keyof UnistylesThemes
|
81
|
+
this.emitThemeChange()
|
82
|
+
|
83
|
+
return true
|
84
|
+
}
|
85
|
+
default:
|
86
|
+
return Reflect.set(target, prop, newValue, receiver)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
})
|
90
|
+
|
91
|
+
return true
|
92
|
+
}
|
93
|
+
|
94
|
+
private useTheme(themeName: keyof UnistylesThemes) {
|
95
|
+
this.#themeName = themeName
|
96
|
+
this.emitThemeChange()
|
97
|
+
}
|
98
|
+
|
99
|
+
private useBreakpoints(breakpoints: UnistylesBreakpoints) {
|
100
|
+
this.#breakpoints = breakpoints
|
101
|
+
this.#sortedBreakpointPairs = Object
|
102
|
+
.entries(breakpoints)
|
103
|
+
.sort(([, a], [, b]) => (a ?? 0) - (b ?? 0)) as Array<[keyof UnistylesBreakpoints, number]>
|
104
|
+
|
105
|
+
if (!isServer) {
|
106
|
+
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth as number)
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
private useAdaptiveThemes(enable: boolean) {
|
111
|
+
this.#hasAdaptiveThemes = enable
|
112
|
+
|
113
|
+
if (!this.#hasAdaptiveThemes || !this.#supportsAutomaticColorScheme) {
|
114
|
+
return
|
115
|
+
}
|
116
|
+
|
117
|
+
if (this.#themeName !== this.#colorScheme) {
|
118
|
+
this.#themeName = this.#colorScheme as keyof UnistylesThemes
|
119
|
+
this.emitThemeChange()
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
private addPlugin(pluginName: string, notify: boolean) {
|
124
|
+
this.#enabledPlugins = [pluginName].concat(this.#enabledPlugins)
|
125
|
+
|
126
|
+
if (notify) {
|
127
|
+
this.emitPluginChange()
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
private removePlugin(pluginName: string) {
|
132
|
+
this.#enabledPlugins = this.#enabledPlugins.filter(name => name !== pluginName)
|
133
|
+
this.emitPluginChange()
|
134
|
+
}
|
135
|
+
|
136
|
+
private getTheme(): keyof UnistylesThemes {
|
137
|
+
|
138
|
+
if (this.#themes.length === 1) {
|
139
|
+
return this.#themes.at(0) as keyof UnistylesThemes
|
140
|
+
}
|
141
|
+
|
142
|
+
return this.#themeName
|
143
|
+
}
|
144
|
+
|
145
|
+
private setupListeners() {
|
146
|
+
window.addEventListener('resize', () => {
|
147
|
+
clearTimeout(this.#timerRef)
|
148
|
+
|
149
|
+
this.#timerRef = setTimeout(() => {
|
150
|
+
this.#screenWidth = window.innerWidth
|
151
|
+
this.#screenHeight = window.innerHeight
|
152
|
+
this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth)
|
153
|
+
|
154
|
+
this.emitLayoutChange()
|
155
|
+
}, 100)
|
156
|
+
})
|
157
|
+
|
158
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
159
|
+
this.#colorScheme = event.matches
|
160
|
+
? 'dark'
|
161
|
+
: 'light'
|
162
|
+
|
163
|
+
if (!this.#supportsAutomaticColorScheme || !this.#hasAdaptiveThemes) {
|
164
|
+
return
|
165
|
+
}
|
166
|
+
|
167
|
+
if (this.#colorScheme !== this.#themeName) {
|
168
|
+
this.#themeName = this.#colorScheme as keyof UnistylesThemes
|
169
|
+
this.emitThemeChange()
|
170
|
+
}
|
171
|
+
})
|
172
|
+
}
|
173
|
+
|
174
|
+
private getBreakpointFromScreenWidth(width: number): keyof UnistylesBreakpoints {
|
175
|
+
const breakpoint = this.#sortedBreakpointPairs
|
176
|
+
.find(([, value], index, otherBreakpoints) => {
|
177
|
+
const minVal = value
|
178
|
+
const maxVal = otherBreakpoints[index + 1]?.[1]
|
179
|
+
|
180
|
+
if (!maxVal) {
|
181
|
+
return true
|
182
|
+
}
|
183
|
+
|
184
|
+
return width >= minVal && width < maxVal
|
185
|
+
})
|
186
|
+
|
187
|
+
return breakpoint?.at(0) as keyof UnistylesBreakpoints
|
188
|
+
}
|
189
|
+
|
190
|
+
private getPreferredColorScheme() {
|
191
|
+
if (!isServer && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
192
|
+
return 'dark'
|
193
|
+
}
|
194
|
+
|
195
|
+
return 'light'
|
196
|
+
}
|
197
|
+
|
198
|
+
private emitPluginChange() {
|
199
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
200
|
+
type: 'plugin'
|
201
|
+
})
|
202
|
+
}
|
203
|
+
|
204
|
+
private emitThemeChange() {
|
205
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
206
|
+
type: 'theme',
|
207
|
+
payload: {
|
208
|
+
themeName: this.#themeName
|
209
|
+
}
|
210
|
+
})
|
211
|
+
}
|
212
|
+
|
213
|
+
private emitLayoutChange() {
|
214
|
+
this.#unistylesEvents.emit('__unistylesOnChange', {
|
215
|
+
type: 'layout',
|
216
|
+
payload: {
|
217
|
+
breakpoint: this.#breakpoint,
|
218
|
+
orientation: (this.#screenWidth as number) > (this.#screenHeight as number)
|
219
|
+
? 'landscape'
|
220
|
+
: 'portrait',
|
221
|
+
screen: {
|
222
|
+
width: this.#screenWidth,
|
223
|
+
height: this.#screenHeight
|
224
|
+
}
|
225
|
+
}
|
226
|
+
})
|
227
|
+
}
|
5
228
|
}
|
6
229
|
|
7
|
-
export const UnistylesModule =
|
230
|
+
export const UnistylesModule = new UnistylesBridgeWeb()
|
@@ -33,6 +33,14 @@ export class UnistylesRuntime {
|
|
33
33
|
return this.unistylesBridge.themeName
|
34
34
|
}
|
35
35
|
|
36
|
+
/**
|
37
|
+
* Get the current content size category
|
38
|
+
* @returns - The current content size category
|
39
|
+
*/
|
40
|
+
public get contentSizeCategory() {
|
41
|
+
return this.unistylesBridge.contentSizeCategory
|
42
|
+
}
|
43
|
+
|
36
44
|
/**
|
37
45
|
* Get the current breakpoint based on device size
|
38
46
|
* @returns - The current breakpoint
|
package/src/hooks/useCSS.ts
CHANGED
@@ -1,3 +1,51 @@
|
|
1
|
+
import { useInsertionEffect, useRef } from 'react'
|
2
|
+
import { unistyles } from '../core'
|
1
3
|
import type { ReactNativeStyleSheet } from '../types'
|
4
|
+
import { generateReactNativeWebId } from '../utils'
|
2
5
|
|
3
|
-
export const useCSS = <T>(
|
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
|
+
}
|
@@ -2,13 +2,14 @@ import { NativeEventEmitter, NativeModules } from 'react-native'
|
|
2
2
|
import { useEffect, useState } from 'react'
|
3
3
|
import { unistyles } from '../core'
|
4
4
|
import { UnistylesEventType } from '../common'
|
5
|
-
import type { UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
|
5
|
+
import type { UnistylesDynamicTypeSizeEvent, UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
|
6
6
|
|
7
7
|
const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
|
8
8
|
|
9
9
|
export const useUnistyles = () => {
|
10
10
|
const [plugins, setPlugins] = useState(unistyles.runtime.enabledPlugins)
|
11
11
|
const [theme, setTheme] = useState(unistyles.registry.getTheme(unistyles.runtime.themeName))
|
12
|
+
const [contentSizeCategory, setContentSizeCategory] = useState(unistyles.runtime.contentSizeCategory)
|
12
13
|
const [layout, setLayout] = useState({
|
13
14
|
breakpoint: unistyles.runtime.breakpoint,
|
14
15
|
orientation: unistyles.runtime.orientation,
|
@@ -40,6 +41,11 @@ export const useUnistyles = () => {
|
|
40
41
|
case UnistylesEventType.Plugin: {
|
41
42
|
return setPlugins(unistyles.runtime.enabledPlugins)
|
42
43
|
}
|
44
|
+
case UnistylesEventType.DynamicTypeSize: {
|
45
|
+
const dynamicTypeSizeEvent = event as UnistylesDynamicTypeSizeEvent
|
46
|
+
|
47
|
+
return setContentSizeCategory(dynamicTypeSizeEvent.payload.contentSizeCategory)
|
48
|
+
}
|
43
49
|
default:
|
44
50
|
return
|
45
51
|
}
|
@@ -52,6 +58,7 @@ export const useUnistyles = () => {
|
|
52
58
|
return {
|
53
59
|
plugins,
|
54
60
|
theme,
|
55
|
-
layout
|
61
|
+
layout,
|
62
|
+
contentSizeCategory
|
56
63
|
}
|
57
64
|
}
|
package/src/index.ts
CHANGED
@@ -3,7 +3,7 @@ import { mq } from './utils'
|
|
3
3
|
import { useInitialTheme } from './hooks'
|
4
4
|
import type { UnistylesPlugin } from './types'
|
5
5
|
import type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
6
|
-
import { ScreenOrientation } from './common'
|
6
|
+
import { ScreenOrientation, AndroidContentSizeCategory, IOSContentSizeCategory } from './common'
|
7
7
|
import { useStyles } from './useStyles'
|
8
8
|
import { createStyleSheet } from './createStyleSheet'
|
9
9
|
|
@@ -37,6 +37,8 @@ export {
|
|
37
37
|
useInitialTheme,
|
38
38
|
createStyleSheet,
|
39
39
|
ScreenOrientation,
|
40
|
+
AndroidContentSizeCategory,
|
41
|
+
IOSContentSizeCategory,
|
40
42
|
UnistylesRegistry,
|
41
43
|
UnistylesRuntime
|
42
44
|
}
|
package/src/types/unistyles.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { UnistylesEventType, ScreenOrientation } from '../common'
|
1
|
+
import { UnistylesEventType, ScreenOrientation, IOSContentSizeCategory, AndroidContentSizeCategory } from '../common'
|
2
2
|
import type { UnistylesThemes, UnistylesBreakpoints } from '../global'
|
3
3
|
import type { ScreenSize } from './core'
|
4
4
|
import type { UnistylesPlugin } from './plugin'
|
@@ -21,6 +21,7 @@ export type UnistylesBridge = {
|
|
21
21
|
themeName: keyof UnistylesThemes,
|
22
22
|
breakpoint: keyof UnistylesBreakpoints,
|
23
23
|
colorScheme: ColorSchemeName,
|
24
|
+
contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory,
|
24
25
|
sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>,
|
25
26
|
|
26
27
|
// setters
|
@@ -52,4 +53,11 @@ export type UnistylesPluginEvent = {
|
|
52
53
|
type: UnistylesEventType.Plugin
|
53
54
|
}
|
54
55
|
|
55
|
-
export type
|
56
|
+
export type UnistylesDynamicTypeSizeEvent = {
|
57
|
+
type: UnistylesEventType.DynamicTypeSize,
|
58
|
+
payload: {
|
59
|
+
contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent | UnistylesDynamicTypeSizeEvent
|
package/src/useStyles.ts
CHANGED
@@ -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,GAAGJ,SAAS,GAAGK,MAAM,CAACC,UAAU;EACvD,CAACC,YAAY,GAAGH,gBAAQ,GAAGJ,SAAS,GAAGK,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,CAACC,iCAAwB,CAACC,IAAI,CAAC;EAChE,CAACC,eAAe,GAAG,IAAIC,+BAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC;EAClE,CAACC,qBAAqB,GAAgD,EAAE;EACxE,CAACC,UAAU,GAA+B,EAAE;EAE5CC,WAAWA,CAAA,EAAG;IACV,I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N;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,IAA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