react-native-unistyles 3.0.0-alpha.7 → 3.0.0-alpha.9
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/common/Helpers.h +58 -0
- package/cxx/core/Unistyle.h +0 -6
- package/cxx/core/UnistyleData.h +3 -2
- package/cxx/core/UnistyleWrapper.h +6 -6
- package/cxx/core/UnistylesRegistry.cpp +11 -10
- package/cxx/core/UnistylesRegistry.h +4 -3
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -2
- package/cxx/parser/Parser.cpp +24 -78
- package/cxx/parser/Parser.h +1 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +33 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +70 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/package.json +1 -1
- package/plugin/__tests__/dependencies.spec.js +5 -5
- package/plugin/__tests__/ref.spec.js +132 -17
- package/plugin/__tests__/stylesheet.spec.js +9 -9
- package/plugin/index.js +12 -13
- package/plugin/ref.js +18 -14
- package/plugin/style.js +13 -7
- package/src/specs/ShadowRegistry/index.ts +4 -4
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /package/{web → src/web}/pseudo.ts +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["media","deepMergeObjects","keyInObject","normalizeNumericValue","convertBreakpoint","normalizeTransform","key","value","includes","createTransformValue","transforms","map","transform","Object","keys","undefined","join","filter","Boolean","getTransformStyle","breakpoints","Set","normalTransforms","forEach","property","Array","isArray","breakpoint","add","push","breakpointTransforms","from","flatMap","transformsPerBreakpoint"],"sourceRoot":"../../../../src","sources":["web/convert/transform.ts"],"mapp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pD,CAAC,EAAE,GAAGQ,oBAAoB,CAAC;AAC/B,CAAC","ignoreList":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["TEXT_SHADOW_STYLES","BOX_SHADOW_STYLES"],"sourceRoot":"../../../../src","sources":["web/convert/types.ts"],"mappings":";;AAKA,OAAO,MAAMA,kBAAkB,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,CAAU;AAItG,OAAO,MAAMC,iBAAiB,GAAG,CAAC,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,CAAU","ignoreList":[]}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// based on react-native-web normalizer
|
4
|
+
// https://github.com/necolas/react-native-web
|
5
|
+
import normalizeColors from '@react-native/normalize-colors';
|
6
|
+
import { BOX_SHADOW_STYLES, TEXT_SHADOW_STYLES } from './types';
|
7
|
+
export const isTransform = (key, value) => key === 'transform' && Array.isArray(value);
|
8
|
+
export const isTextShadow = key => TEXT_SHADOW_STYLES.includes(key);
|
9
|
+
export const isBoxShadow = key => BOX_SHADOW_STYLES.includes(key);
|
10
|
+
export const normalizeNumericValue = value => value ? `${value}px` : value;
|
11
|
+
export const normalizeColor = (color, opacity = 1) => {
|
12
|
+
// If the opacity is 1 there's no need to normalize the color
|
13
|
+
if (opacity === 1) {
|
14
|
+
return color;
|
15
|
+
}
|
16
|
+
const integer = normalizeColors(color);
|
17
|
+
|
18
|
+
// If the color is an unknown format, the return value is null
|
19
|
+
if (integer === null) {
|
20
|
+
return color;
|
21
|
+
}
|
22
|
+
const hex = integer.toString(16).padStart(8, '0');
|
23
|
+
if (hex.length === 8) {
|
24
|
+
const [r = 0, g = 0, b = 0, a = 1] = hex.split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num));
|
25
|
+
return `rgba(${r},${g},${b},${a / 255 * opacity})`;
|
26
|
+
}
|
27
|
+
return color;
|
28
|
+
};
|
29
|
+
export const extractShadowValue = (key, breakpoint, styles) => {
|
30
|
+
const value = styles[key];
|
31
|
+
if (key === 'textShadowOffset' || key === 'shadowOffset') {
|
32
|
+
const {
|
33
|
+
width,
|
34
|
+
height
|
35
|
+
} = value;
|
36
|
+
return {
|
37
|
+
width: typeof width === 'object' ? width[breakpoint] : width,
|
38
|
+
height: typeof height === 'object' ? height[breakpoint] : height
|
39
|
+
};
|
40
|
+
}
|
41
|
+
return typeof value === 'object' ? value[breakpoint] : value;
|
42
|
+
};
|
43
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["normalizeColors","BOX_SHADOW_STYLES","TEXT_SHADOW_STYLES","isTransform","key","value","Array","isArray","isTextShadow","includes","isBoxShadow","normalizeNumericValue","normalizeColor","color","opacity","integer","hex","toString","padStart","length","r","g","b","a","split","map","x","parseInt","filter","num","isNaN","extractShadowValue","breakpoint","styles","width","height"],"sourceRoot":"../../../../src","sources":["web/convert/utils.ts"],"mappings":";;AAAA;AACA;AACA,OAAOA,eAAe,MAAM,gCAAgC;AAC5D,SAASC,iBAAiB,EAAEC,kBAAkB,QAA4C,SAAS;AAEnG,OAAO,MAAMC,WAAW,GAAGA,CAACC,GAAW,EAAEC,KAAU,KAA0CD,GAAG,KAAK,WAAW,IAAIE,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC;AAExI,OAAO,MAAMG,YAAY,GAAIJ,GAAW,IAAKF,kBAAkB,CAACO,QAAQ,CAACL,GAAwC,CAAC;AAElH,OAAO,MAAMM,WAAW,GAAIN,GAAW,IAAKH,iBAAiB,CAACQ,QAAQ,CAACL,GAAuC,CAAC;AAE/G,OAAO,MAAMO,qBAAqB,GAAIN,KAAa,IAAKA,KAAK,GAAG,GAAGA,KAAK,IAAI,GAAGA,KAAK;AAEpF,OAAO,MAAMO,cAAc,GAAGA,CAACC,KAAa,EAAEC,OAAe,GAAG,CAAC,KAAK;EAClE;EACA,IAAIA,OAAO,KAA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;EAEA,OAAO,OAAO9B,KAAK,KAAK,QAAQ,GAAGA,KAAK,CAAC2B,UAAU,CAAC,GAAG3B,KAAK;AAChE,CAAC","ignoreList":[]}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { UnistylesRegistry } from './registry';
|
4
|
+
import { keyInObject, reduceObject, toReactNativeClassName } from './utils';
|
5
|
+
import { UnistylesRuntime } from './runtime';
|
6
|
+
import { createUseVariants, getVariants } from './variants';
|
7
|
+
import { UnistylesListener } from './listener';
|
8
|
+
export const create = stylesheet => {
|
9
|
+
const computedStylesheet = typeof stylesheet === 'function' ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime) : stylesheet;
|
10
|
+
let lastlySelectedVariants = {};
|
11
|
+
const listenToDependencies = ({
|
12
|
+
key,
|
13
|
+
className,
|
14
|
+
unistyles,
|
15
|
+
value,
|
16
|
+
args = []
|
17
|
+
}) => {
|
18
|
+
const dependencies = 'uni__dependencies' in value ? value['uni__dependencies'] : [];
|
19
|
+
if (dependencies.length === 0) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
return UnistylesListener.addListeners(dependencies, () => {
|
23
|
+
const newComputedStylesheet = typeof stylesheet === 'function' ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime) : stylesheet;
|
24
|
+
if (!keyInObject(newComputedStylesheet, key)) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
const value = newComputedStylesheet[key];
|
28
|
+
const result = typeof value === 'function' ? value(...args) : value;
|
29
|
+
UnistylesRegistry.updateStyles(unistyles, result, className);
|
30
|
+
});
|
31
|
+
};
|
32
|
+
const styles = reduceObject(computedStylesheet, (value, key) => {
|
33
|
+
if (typeof value === 'function') {
|
34
|
+
const webUnistyleByRef = new Map();
|
35
|
+
const disposeByRef = new Map();
|
36
|
+
return (...args) => {
|
37
|
+
const [ref] = args.slice(-1);
|
38
|
+
const result = value(...args);
|
39
|
+
const variants = Object.fromEntries(getVariants({
|
40
|
+
[key]: result
|
41
|
+
}, lastlySelectedVariants));
|
42
|
+
const resultWithVariants = {
|
43
|
+
...result,
|
44
|
+
...variants[key]
|
45
|
+
};
|
46
|
+
if (ref instanceof HTMLElement) {
|
47
|
+
const storedWebUnistyle = webUnistyleByRef.get(ref);
|
48
|
+
const webUnistyle = storedWebUnistyle ?? UnistylesRegistry.createStyles(resultWithVariants, key);
|
49
|
+
webUnistyleByRef.set(ref, webUnistyle);
|
50
|
+
disposeByRef.get(ref)?.();
|
51
|
+
disposeByRef.set(ref, listenToDependencies({
|
52
|
+
key,
|
53
|
+
value,
|
54
|
+
unistyles: webUnistyle.unistyles,
|
55
|
+
className: webUnistyle.className,
|
56
|
+
args
|
57
|
+
}));
|
58
|
+
ref.classList.add(webUnistyle.className);
|
59
|
+
if (storedWebUnistyle) {
|
60
|
+
UnistylesRegistry.updateStyles(webUnistyle.unistyles, resultWithVariants, webUnistyle.className);
|
61
|
+
}
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
return toReactNativeClassName(null, resultWithVariants);
|
65
|
+
};
|
66
|
+
}
|
67
|
+
const {
|
68
|
+
className,
|
69
|
+
unistyles
|
70
|
+
} = UnistylesRegistry.createStyles(value, key);
|
71
|
+
listenToDependencies({
|
72
|
+
key,
|
73
|
+
value,
|
74
|
+
unistyles,
|
75
|
+
className
|
76
|
+
});
|
77
|
+
return toReactNativeClassName(className, value);
|
78
|
+
});
|
79
|
+
createUseVariants(styles, newVariants => {
|
80
|
+
lastlySelectedVariants = newVariants;
|
81
|
+
});
|
82
|
+
return styles;
|
83
|
+
};
|
84
|
+
//# sourceMappingURL=create.js.map
|
@@ -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,sBAAsB,QAAQ,SAAS;AAC3E,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,iBAAiB,EAAEC,WAAW,QAAQ,YAAY;AAC3D,SAASC,iBAAiB,QAAQ,YAAY;AAa9C,OAAO,MAAMC,MAAM,GAAIC,UAAiD,IAAK;EACzE,MAAMC,kBAAkB,GAAG,OAAOD,UAAU,KAAK,UAAU,GACrDA,UAAU,CAACL,gBAAgB,CAACO,KAAK,EAAEP,gBAAgB,CAACQ,WAAW,CAAC,GAChEH,UAAU;EAChB,IAAII,sBAA2C,GAAG,CAAC,CAAC;EAEpD,MAAMC,oBAAoB,GAAGA,CAAC;IAAEC,GAAG;IAAEC,SAAS;IAAEC,SAAS;IAAEC,KAAK;IAAEC,IAAI,GAAG;EAA+B,CAAC,KAAK;IAC1G,MAAMC,YAAY,GAAI,mBAAmB,IAAIF,KAAK,GAAGA,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAgC;IAElH,IAAIE,YAAY,CAACC,MAAM,KAAK,CAAC,EAAE;MAC3B;IACJ;IAEA,OAAOd,iBAAiB,CAACe,YAAY,CAACF,YAAY,EAAE,MAAM;MACtD,MAAMG,qBAAqB,GAAG,OAAOd,UAAU,KAAK,UAAU,GACxDA,UAAU,CAACL,gBAAgB,CAACO,KAAK,EAAEP,gBAAgB,CAACQ,WAAW,CAAC,GAChEH,UAAU;MAEhB,IAAI,CAACR,WAAW,CAACsB,qBAAqB,EAAER,GAAG,CAAC,EAAE;QAC1C;MACJ;MAEA,MAAMG,KAAK,GAAGK,qBAAqB,CAACR,GAAG,CAAE;MACzC,MAAMS,M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AAK;YACLD,SAAS,EAAEsB,WAAW,CAACtB,SAAS;YAChCD,SAAS,EAAEuB,WAAW,CAACvB,SAAS;YAChCG;UACJ,CAAC,CAAC,CAAC;UACHW,GAAG,CAACY,SAAS,CAACC,GAAG,CAACJ,WAAW,CAACvB,SAAS,CAAC;UAExC,IAAIqB,iBAAiB,EAAE;YACnBrC,iBAAiB,CAACyB,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 @@
|
|
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,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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 @@
|
|
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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D,cAAc,CAAC+C,iBAAiB,GAAGS,SAAS;IAE5C,IAAI,CAACA,SAAS,EAAE;MACZ;IACJ;IAEA,IAAI,CAACN,QAAQ,CAAC/C,aAAa,CAACgD,gBAAgB,CAACxC,WAAW,CAAC,CAAC;EAC9D,CAAC;EAED8C,0BAA0B,GAAGA,CAACC,GAAW,EAAEC,KAAc,KAAK;IAC1D,IAAIzD,QAAQ,CAAC,CAAC,EAAE;MACZ;IACJ;IAEA0C,QAAQ,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
|