@niibase/uniwind 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/common/consts.js +18 -0
- package/dist/common/components/native/Pressable.js +13 -2
- package/dist/common/components/native/TouchableHighlight.js +11 -1
- package/dist/common/components/native/TouchableOpacity.js +11 -1
- package/dist/common/core/native/store.js +19 -2
- package/dist/common/css/variants.js +1 -1
- package/dist/metro/index.cjs +2 -2
- package/dist/metro/index.d.ts +1 -0
- package/dist/metro/index.mjs +1 -1
- package/dist/metro/metro-transformer.cjs +44 -11
- package/dist/metro/metro-transformer.mjs +42 -9
- package/dist/module/common/consts.d.ts +11 -0
- package/dist/module/common/consts.js +12 -0
- package/dist/module/components/native/Pressable.d.ts +5 -0
- package/dist/module/components/native/Pressable.js +12 -2
- package/dist/module/components/native/TouchableHighlight.js +11 -1
- package/dist/module/components/native/TouchableOpacity.js +11 -1
- package/dist/module/core/native/parsers/gradient.d.ts +1 -1
- package/dist/module/core/native/store.d.ts +1 -0
- package/dist/module/core/native/store.js +19 -2
- package/dist/module/css/variants.js +1 -1
- package/dist/shared/uniwind.B5q8hBGv.cjs +18 -0
- package/dist/shared/{uniwind.B_j3NcHy.mjs → uniwind.BWb5KNML.mjs} +1 -1
- package/dist/shared/{uniwind.D7C2Zt-r.cjs → uniwind.DTMo4epG.cjs} +1 -1
- package/dist/shared/uniwind.JSWK3vHl.mjs +14 -0
- package/dist/vite/index.cjs +1 -1
- package/dist/vite/index.mjs +1 -1
- package/package.json +17 -12
- package/readme.md +1 -1
- package/src/common/consts.ts +12 -0
- package/src/components/native/Pressable.tsx +17 -1
- package/src/components/native/TouchableHighlight.tsx +10 -0
- package/src/components/native/TouchableOpacity.tsx +10 -0
- package/src/core/config/config.common.ts +1 -2
- package/src/core/native/parsers/gradient.ts +1 -1
- package/src/core/native/store.ts +24 -2
- package/src/css/variants.ts +1 -1
- package/src/metro/addMetaToStylesTemplate.ts +9 -3
- package/src/metro/compileVirtual.ts +2 -1
- package/src/metro/index.d.ts +1 -0
- package/src/metro/metro-transformer.ts +19 -2
- package/src/metro/processor/mq.ts +12 -2
- package/src/metro/processor/processor.ts +3 -2
- package/src/metro/processor/rn.ts +10 -0
- package/src/metro/types.ts +2 -7
- package/src/metro/withUniwindConfig.ts +2 -1
- package/uniwind.css +5 -2
- package/dist/shared/uniwind.BZIuaszw.cjs +0 -11
- package/dist/shared/uniwind.CyoRUwOj.mjs +0 -9
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UNIWIND_THEME_VARIABLES = exports.UNIWIND_PLATFORM_VARIABLES = exports.Platform = void 0;
|
|
7
|
+
var Platform = exports.Platform = /* @__PURE__ */(Platform2 => {
|
|
8
|
+
Platform2["Android"] = "android";
|
|
9
|
+
Platform2["iOS"] = "ios";
|
|
10
|
+
Platform2["Web"] = "web";
|
|
11
|
+
Platform2["Native"] = "native";
|
|
12
|
+
Platform2["TV"] = "tv";
|
|
13
|
+
Platform2["AndroidTV"] = "android-tv";
|
|
14
|
+
Platform2["AppleTV"] = "apple-tv";
|
|
15
|
+
return Platform2;
|
|
16
|
+
})(Platform || {});
|
|
17
|
+
const UNIWIND_PLATFORM_VARIABLES = exports.UNIWIND_PLATFORM_VARIABLES = "__uniwind-platform-";
|
|
18
|
+
const UNIWIND_THEME_VARIABLES = exports.UNIWIND_THEME_VARIABLES = "__uniwind-theme-";
|
|
@@ -11,17 +11,20 @@ var _utils = require("../utils");
|
|
|
11
11
|
var _useStyle = require("./useStyle");
|
|
12
12
|
const Pressable = exports.Pressable = (0, _utils.copyComponentProperties)(_reactNative.Pressable, props => {
|
|
13
13
|
const [isPressed, setIsPressed] = (0, _react.useState)(false);
|
|
14
|
+
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
14
15
|
const {
|
|
15
16
|
Component,
|
|
16
17
|
style
|
|
17
18
|
} = (0, _useStyle.useStyle)(_reactNative.Pressable, props.className, props, {
|
|
18
19
|
isDisabled: Boolean(props.disabled),
|
|
19
|
-
isPressed
|
|
20
|
+
isPressed,
|
|
21
|
+
isFocused
|
|
20
22
|
});
|
|
21
23
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Component, {
|
|
22
24
|
...props,
|
|
23
25
|
style: [style, typeof props.style === "function" ? props.style({
|
|
24
|
-
pressed: isPressed
|
|
26
|
+
pressed: isPressed,
|
|
27
|
+
focused: isFocused
|
|
25
28
|
}) : props.style],
|
|
26
29
|
onPressIn: event => {
|
|
27
30
|
setIsPressed(true);
|
|
@@ -30,6 +33,14 @@ const Pressable = exports.Pressable = (0, _utils.copyComponentProperties)(_react
|
|
|
30
33
|
onPressOut: event => {
|
|
31
34
|
setIsPressed(false);
|
|
32
35
|
props.onPressOut?.(event);
|
|
36
|
+
},
|
|
37
|
+
onFocus: event => {
|
|
38
|
+
setIsFocused(true);
|
|
39
|
+
props.onFocus?.(event);
|
|
40
|
+
},
|
|
41
|
+
onBlur: event => {
|
|
42
|
+
setIsFocused(false);
|
|
43
|
+
props.onBlur?.(event);
|
|
33
44
|
}
|
|
34
45
|
});
|
|
35
46
|
});
|
|
@@ -11,9 +11,11 @@ var _utils = require("../utils");
|
|
|
11
11
|
var _useStyle = require("./useStyle");
|
|
12
12
|
const TouchableHighlight = exports.TouchableHighlight = (0, _utils.copyComponentProperties)(_reactNative.TouchableHighlight, props => {
|
|
13
13
|
const [isPressed, setIsPressed] = (0, _react.useState)(false);
|
|
14
|
+
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
14
15
|
const state = {
|
|
15
16
|
isDisabled: Boolean(props.disabled),
|
|
16
|
-
isPressed
|
|
17
|
+
isPressed,
|
|
18
|
+
isFocused
|
|
17
19
|
};
|
|
18
20
|
const {
|
|
19
21
|
Component,
|
|
@@ -31,6 +33,14 @@ const TouchableHighlight = exports.TouchableHighlight = (0, _utils.copyComponent
|
|
|
31
33
|
onPressOut: event => {
|
|
32
34
|
setIsPressed(false);
|
|
33
35
|
props.onPressOut?.(event);
|
|
36
|
+
},
|
|
37
|
+
onFocus: event => {
|
|
38
|
+
setIsFocused(true);
|
|
39
|
+
props.onFocus?.(event);
|
|
40
|
+
},
|
|
41
|
+
onBlur: event => {
|
|
42
|
+
setIsFocused(false);
|
|
43
|
+
props.onBlur?.(event);
|
|
34
44
|
}
|
|
35
45
|
});
|
|
36
46
|
});
|
|
@@ -11,9 +11,11 @@ var _utils = require("../utils");
|
|
|
11
11
|
var _useStyle = require("./useStyle");
|
|
12
12
|
const TouchableOpacity = exports.TouchableOpacity = (0, _utils.copyComponentProperties)(_reactNative.TouchableOpacity, props => {
|
|
13
13
|
const [isPressed, setIsPressed] = (0, _react.useState)(false);
|
|
14
|
+
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
14
15
|
const state = {
|
|
15
16
|
isDisabled: Boolean(props.disabled),
|
|
16
|
-
isPressed
|
|
17
|
+
isPressed,
|
|
18
|
+
isFocused
|
|
17
19
|
};
|
|
18
20
|
const {
|
|
19
21
|
Component,
|
|
@@ -29,6 +31,14 @@ const TouchableOpacity = exports.TouchableOpacity = (0, _utils.copyComponentProp
|
|
|
29
31
|
onPressOut: event => {
|
|
30
32
|
setIsPressed(false);
|
|
31
33
|
props.onPressOut?.(event);
|
|
34
|
+
},
|
|
35
|
+
onFocus: event => {
|
|
36
|
+
setIsFocused(true);
|
|
37
|
+
props.onFocus?.(event);
|
|
38
|
+
},
|
|
39
|
+
onBlur: event => {
|
|
40
|
+
setIsFocused(false);
|
|
41
|
+
props.onBlur?.(event);
|
|
32
42
|
}
|
|
33
43
|
});
|
|
34
44
|
});
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.UniwindStore = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
+
var _consts = require("../../common/consts");
|
|
8
9
|
var _types = require("../../types");
|
|
9
10
|
var _listener = require("../listener");
|
|
10
11
|
var _nativeUtils = require("./native-utils");
|
|
@@ -46,7 +47,13 @@ class UniwindStoreBuilder {
|
|
|
46
47
|
vars,
|
|
47
48
|
keyframes
|
|
48
49
|
} = generateStyleSheetCallback(this.runtime);
|
|
49
|
-
const
|
|
50
|
+
const platform = this.getCurrentPlatform();
|
|
51
|
+
const commonPlatform = platform.includes("tv") ? _consts.Platform.TV : _consts.Platform.Native;
|
|
52
|
+
const commonPlatformVars = scopedVars[`${_consts.UNIWIND_PLATFORM_VARIABLES}${commonPlatform}`];
|
|
53
|
+
const platformVars = scopedVars[`${_consts.UNIWIND_PLATFORM_VARIABLES}${platform}`];
|
|
54
|
+
if (commonPlatformVars) {
|
|
55
|
+
Object.defineProperties(vars, Object.getOwnPropertyDescriptors(commonPlatformVars));
|
|
56
|
+
}
|
|
50
57
|
if (platformVars) {
|
|
51
58
|
Object.defineProperties(vars, Object.getOwnPropertyDescriptors(platformVars));
|
|
52
59
|
}
|
|
@@ -54,7 +61,7 @@ class UniwindStoreBuilder {
|
|
|
54
61
|
this.stylesheet = stylesheet;
|
|
55
62
|
this.vars = Object.fromEntries(themes.map(theme => {
|
|
56
63
|
const clonedVars = (0, _nativeUtils.cloneWithAccessors)(vars);
|
|
57
|
-
const themeVars = scopedVars[
|
|
64
|
+
const themeVars = scopedVars[`${_consts.UNIWIND_THEME_VARIABLES}${theme}`];
|
|
58
65
|
if (themeVars) {
|
|
59
66
|
Object.defineProperties(clonedVars, Object.getOwnPropertyDescriptors(themeVars));
|
|
60
67
|
}
|
|
@@ -217,6 +224,16 @@ class UniwindStoreBuilder {
|
|
|
217
224
|
}
|
|
218
225
|
return true;
|
|
219
226
|
}
|
|
227
|
+
getCurrentPlatform() {
|
|
228
|
+
const platform = _reactNative.Platform.OS;
|
|
229
|
+
if (platform === "android") {
|
|
230
|
+
return _reactNative.Platform.isTV ? _consts.Platform.AndroidTV : _consts.Platform.Android;
|
|
231
|
+
}
|
|
232
|
+
if (platform === "ios") {
|
|
233
|
+
return _reactNative.Platform.isTV ? _consts.Platform.AppleTV : _consts.Platform.iOS;
|
|
234
|
+
}
|
|
235
|
+
return platform;
|
|
236
|
+
}
|
|
220
237
|
}
|
|
221
238
|
const UniwindStore = exports.UniwindStore = new UniwindStoreBuilder();
|
|
222
239
|
_reactNative.Dimensions.addEventListener("change", ({
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateCSSForVariants = void 0;
|
|
7
|
-
const variants = ["ios", "android", "web", "native"];
|
|
7
|
+
const variants = ["ios", "android", "web", "native", "tv", "android-tv", "apple-tv"];
|
|
8
8
|
const generateCSSForVariants = () => {
|
|
9
9
|
let css = "";
|
|
10
10
|
variants.forEach(variant => {
|
package/dist/metro/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const consts = require('../shared/uniwind.B5q8hBGv.cjs');
|
|
3
4
|
const FileStoreBase = require('metro-cache/private/stores/FileStore');
|
|
4
5
|
const os = require('os');
|
|
5
6
|
const path = require('path');
|
|
6
7
|
const node_path = require('node:path');
|
|
7
8
|
const common = require('../shared/uniwind.nl8746mK.cjs');
|
|
8
|
-
const types = require('../shared/uniwind.BZIuaszw.cjs');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
11
|
|
|
@@ -172,7 +172,7 @@ const withUniwindConfig = (config, uniwindConfig) => {
|
|
|
172
172
|
),
|
|
173
173
|
resolveRequest: (context, moduleName, platform) => {
|
|
174
174
|
const resolver = config.resolver?.resolveRequest ?? context.resolveRequest;
|
|
175
|
-
const platformResolver = (platform ===
|
|
175
|
+
const platformResolver = (platform === consts.Platform.Web ? webResolver : nativeResolver)(uniwindConfig.extraComponents ?? {});
|
|
176
176
|
const resolved = platformResolver({
|
|
177
177
|
context,
|
|
178
178
|
moduleName,
|
package/dist/metro/index.d.ts
CHANGED
package/dist/metro/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { P as Platform } from '../shared/uniwind.JSWK3vHl.mjs';
|
|
1
2
|
import FileStoreBase from 'metro-cache/private/stores/FileStore';
|
|
2
3
|
import os from 'os';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { join, dirname, sep, basename } from 'node:path';
|
|
5
6
|
import { n as name, u as uniq } from '../shared/uniwind.F-0-Rr--.mjs';
|
|
6
|
-
import { P as Platform } from '../shared/uniwind.CyoRUwOj.mjs';
|
|
7
7
|
|
|
8
8
|
class FileStore extends FileStoreBase {
|
|
9
9
|
async set(key, value) {
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const common = require('../shared/uniwind.nl8746mK.cjs');
|
|
6
|
+
const consts = require('../shared/uniwind.B5q8hBGv.cjs');
|
|
6
7
|
const node = require('@tailwindcss/node');
|
|
7
8
|
const oxide = require('@tailwindcss/oxide');
|
|
8
9
|
const lightningcss = require('lightningcss');
|
|
9
|
-
const
|
|
10
|
-
const stringifyThemes = require('../shared/uniwind.D7C2Zt-r.cjs');
|
|
10
|
+
const stringifyThemes = require('../shared/uniwind.DTMo4epG.cjs');
|
|
11
11
|
const culori = require('culori');
|
|
12
12
|
|
|
13
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -163,8 +163,12 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
163
163
|
...rest
|
|
164
164
|
} = style;
|
|
165
165
|
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`]);
|
|
166
|
-
if (platform
|
|
167
|
-
|
|
166
|
+
if (platform) {
|
|
167
|
+
const isTV = currentPlatform === consts.Platform.AndroidTV || currentPlatform === consts.Platform.AppleTV;
|
|
168
|
+
const commonPlatform = isTV ? consts.Platform.TV : consts.Platform.Native;
|
|
169
|
+
if (platform !== commonPlatform && platform !== currentPlatform) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
168
172
|
}
|
|
169
173
|
if (entries.length === 0) {
|
|
170
174
|
return null;
|
|
@@ -1190,7 +1194,14 @@ class MQ {
|
|
|
1190
1194
|
const mq = this.getInitialMediaQueryResolver();
|
|
1191
1195
|
for (const mediaQuery of mediaQueries) {
|
|
1192
1196
|
const { condition, mediaType } = mediaQuery;
|
|
1193
|
-
if ([
|
|
1197
|
+
if ([
|
|
1198
|
+
consts.Platform.Android,
|
|
1199
|
+
consts.Platform.iOS,
|
|
1200
|
+
consts.Platform.Native,
|
|
1201
|
+
consts.Platform.AndroidTV,
|
|
1202
|
+
consts.Platform.AppleTV,
|
|
1203
|
+
consts.Platform.TV
|
|
1204
|
+
].includes(mediaType)) {
|
|
1194
1205
|
mq.platform = mediaType;
|
|
1195
1206
|
continue;
|
|
1196
1207
|
}
|
|
@@ -1425,7 +1436,17 @@ const cssToRNMap = {
|
|
|
1425
1436
|
},
|
|
1426
1437
|
fontVariantNumeric: (value) => ({
|
|
1427
1438
|
fontVariant: value
|
|
1428
|
-
})
|
|
1439
|
+
}),
|
|
1440
|
+
display: (value) => {
|
|
1441
|
+
if (value === '"box"') {
|
|
1442
|
+
return {
|
|
1443
|
+
display: '"flex"'
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return {
|
|
1447
|
+
display: value
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1429
1450
|
};
|
|
1430
1451
|
const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
|
|
1431
1452
|
const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
|
|
@@ -1689,7 +1710,7 @@ class ProcessorBuilder {
|
|
|
1689
1710
|
return this.stylesheets[this.declarationConfig.className]?.at(-1);
|
|
1690
1711
|
}
|
|
1691
1712
|
if (mq.platform !== null) {
|
|
1692
|
-
const platformKey =
|
|
1713
|
+
const platformKey = `${consts.UNIWIND_PLATFORM_VARIABLES}${mq.platform}`;
|
|
1693
1714
|
this.scopedVars[platformKey] ??= {};
|
|
1694
1715
|
return this.scopedVars[platformKey];
|
|
1695
1716
|
}
|
|
@@ -1701,7 +1722,7 @@ class ProcessorBuilder {
|
|
|
1701
1722
|
if (this.declarationConfig.theme === null) {
|
|
1702
1723
|
return this.vars;
|
|
1703
1724
|
}
|
|
1704
|
-
const themeKey =
|
|
1725
|
+
const themeKey = `${consts.UNIWIND_THEME_VARIABLES}${this.declarationConfig.theme}`;
|
|
1705
1726
|
this.scopedVars[themeKey] ??= {};
|
|
1706
1727
|
return this.scopedVars[themeKey];
|
|
1707
1728
|
})();
|
|
@@ -1953,7 +1974,7 @@ const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug
|
|
|
1953
1974
|
]
|
|
1954
1975
|
});
|
|
1955
1976
|
const tailwindCSS = compiler.build(candidates ?? scanner.scan());
|
|
1956
|
-
if (platform ===
|
|
1977
|
+
if (platform === consts.Platform.Web) {
|
|
1957
1978
|
return lightningcss.transform({
|
|
1958
1979
|
code: Buffer.from(tailwindCSS),
|
|
1959
1980
|
filename: "uniwind.css",
|
|
@@ -2035,6 +2056,18 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2035
2056
|
if (!isCss) {
|
|
2036
2057
|
return worker.transform(config, projectRoot, filePath, data, options);
|
|
2037
2058
|
}
|
|
2059
|
+
const getPlatform = () => {
|
|
2060
|
+
if (!config.uniwind.isTV) {
|
|
2061
|
+
return options.platform;
|
|
2062
|
+
}
|
|
2063
|
+
if (options.platform === consts.Platform.Android) {
|
|
2064
|
+
return consts.Platform.AndroidTV;
|
|
2065
|
+
}
|
|
2066
|
+
if (options.platform === consts.Platform.iOS) {
|
|
2067
|
+
return consts.Platform.AppleTV;
|
|
2068
|
+
}
|
|
2069
|
+
throw new Error(`Platform ${options.platform} not supported`);
|
|
2070
|
+
};
|
|
2038
2071
|
const cssPath = path__default.join(process.cwd(), config.uniwind.cssEntryFile);
|
|
2039
2072
|
const injectedThemesCode = await injectThemes({
|
|
2040
2073
|
input: cssPath,
|
|
@@ -2042,7 +2075,7 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2042
2075
|
dtsPath: config.uniwind.dtsFile
|
|
2043
2076
|
});
|
|
2044
2077
|
const css = fs__default.readFileSync(filePath, "utf-8");
|
|
2045
|
-
const platform =
|
|
2078
|
+
const platform = getPlatform();
|
|
2046
2079
|
const virtualCode = await compileVirtual({
|
|
2047
2080
|
css,
|
|
2048
2081
|
platform,
|
|
@@ -2051,7 +2084,7 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2051
2084
|
cssPath,
|
|
2052
2085
|
debug: config.uniwind.debug
|
|
2053
2086
|
});
|
|
2054
|
-
const isWeb = platform ===
|
|
2087
|
+
const isWeb = platform === consts.Platform.Web;
|
|
2055
2088
|
data = Buffer.from(
|
|
2056
2089
|
isWeb ? virtualCode : [
|
|
2057
2090
|
`import { Uniwind } from '${common.name}';`,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { p as pipe, r as roundToPrecision, i as isNumber, a as isValidJSValue, s as smartSplit, b as addMissingSpaces, t as toCamelCase, c as isDefined, d as deepEqual, e as shouldBeSerialized, f as removeKeys, n as name } from '../shared/uniwind.F-0-Rr--.mjs';
|
|
4
|
+
import { P as Platform, U as UNIWIND_PLATFORM_VARIABLES, a as UNIWIND_THEME_VARIABLES } from '../shared/uniwind.JSWK3vHl.mjs';
|
|
4
5
|
import { compile } from '@tailwindcss/node';
|
|
5
6
|
import { Scanner } from '@tailwindcss/oxide';
|
|
6
7
|
import { transform as transform$1 } from 'lightningcss';
|
|
7
|
-
import {
|
|
8
|
-
import { L as Logger, U as UniwindCSSVisitor, s as stringifyThemes, b as buildDtsFile, a as buildCSS } from '../shared/uniwind.B_j3NcHy.mjs';
|
|
8
|
+
import { L as Logger, U as UniwindCSSVisitor, s as stringifyThemes, b as buildDtsFile, a as buildCSS } from '../shared/uniwind.BWb5KNML.mjs';
|
|
9
9
|
import { converter, parse, formatHex, formatHex8 } from 'culori';
|
|
10
10
|
|
|
11
11
|
const parseStringValue = (value) => {
|
|
@@ -156,8 +156,12 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
156
156
|
...rest
|
|
157
157
|
} = style;
|
|
158
158
|
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`]);
|
|
159
|
-
if (platform
|
|
160
|
-
|
|
159
|
+
if (platform) {
|
|
160
|
+
const isTV = currentPlatform === Platform.AndroidTV || currentPlatform === Platform.AppleTV;
|
|
161
|
+
const commonPlatform = isTV ? Platform.TV : Platform.Native;
|
|
162
|
+
if (platform !== commonPlatform && platform !== currentPlatform) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
161
165
|
}
|
|
162
166
|
if (entries.length === 0) {
|
|
163
167
|
return null;
|
|
@@ -1183,7 +1187,14 @@ class MQ {
|
|
|
1183
1187
|
const mq = this.getInitialMediaQueryResolver();
|
|
1184
1188
|
for (const mediaQuery of mediaQueries) {
|
|
1185
1189
|
const { condition, mediaType } = mediaQuery;
|
|
1186
|
-
if ([
|
|
1190
|
+
if ([
|
|
1191
|
+
Platform.Android,
|
|
1192
|
+
Platform.iOS,
|
|
1193
|
+
Platform.Native,
|
|
1194
|
+
Platform.AndroidTV,
|
|
1195
|
+
Platform.AppleTV,
|
|
1196
|
+
Platform.TV
|
|
1197
|
+
].includes(mediaType)) {
|
|
1187
1198
|
mq.platform = mediaType;
|
|
1188
1199
|
continue;
|
|
1189
1200
|
}
|
|
@@ -1418,7 +1429,17 @@ const cssToRNMap = {
|
|
|
1418
1429
|
},
|
|
1419
1430
|
fontVariantNumeric: (value) => ({
|
|
1420
1431
|
fontVariant: value
|
|
1421
|
-
})
|
|
1432
|
+
}),
|
|
1433
|
+
display: (value) => {
|
|
1434
|
+
if (value === '"box"') {
|
|
1435
|
+
return {
|
|
1436
|
+
display: '"flex"'
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
return {
|
|
1440
|
+
display: value
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1422
1443
|
};
|
|
1423
1444
|
const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
|
|
1424
1445
|
const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
|
|
@@ -1682,7 +1703,7 @@ class ProcessorBuilder {
|
|
|
1682
1703
|
return this.stylesheets[this.declarationConfig.className]?.at(-1);
|
|
1683
1704
|
}
|
|
1684
1705
|
if (mq.platform !== null) {
|
|
1685
|
-
const platformKey =
|
|
1706
|
+
const platformKey = `${UNIWIND_PLATFORM_VARIABLES}${mq.platform}`;
|
|
1686
1707
|
this.scopedVars[platformKey] ??= {};
|
|
1687
1708
|
return this.scopedVars[platformKey];
|
|
1688
1709
|
}
|
|
@@ -1694,7 +1715,7 @@ class ProcessorBuilder {
|
|
|
1694
1715
|
if (this.declarationConfig.theme === null) {
|
|
1695
1716
|
return this.vars;
|
|
1696
1717
|
}
|
|
1697
|
-
const themeKey =
|
|
1718
|
+
const themeKey = `${UNIWIND_THEME_VARIABLES}${this.declarationConfig.theme}`;
|
|
1698
1719
|
this.scopedVars[themeKey] ??= {};
|
|
1699
1720
|
return this.scopedVars[themeKey];
|
|
1700
1721
|
})();
|
|
@@ -2028,6 +2049,18 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2028
2049
|
if (!isCss) {
|
|
2029
2050
|
return worker.transform(config, projectRoot, filePath, data, options);
|
|
2030
2051
|
}
|
|
2052
|
+
const getPlatform = () => {
|
|
2053
|
+
if (!config.uniwind.isTV) {
|
|
2054
|
+
return options.platform;
|
|
2055
|
+
}
|
|
2056
|
+
if (options.platform === Platform.Android) {
|
|
2057
|
+
return Platform.AndroidTV;
|
|
2058
|
+
}
|
|
2059
|
+
if (options.platform === Platform.iOS) {
|
|
2060
|
+
return Platform.AppleTV;
|
|
2061
|
+
}
|
|
2062
|
+
throw new Error(`Platform ${options.platform} not supported`);
|
|
2063
|
+
};
|
|
2031
2064
|
const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile);
|
|
2032
2065
|
const injectedThemesCode = await injectThemes({
|
|
2033
2066
|
input: cssPath,
|
|
@@ -2035,7 +2068,7 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2035
2068
|
dtsPath: config.uniwind.dtsFile
|
|
2036
2069
|
});
|
|
2037
2070
|
const css = fs.readFileSync(filePath, "utf-8");
|
|
2038
|
-
const platform =
|
|
2071
|
+
const platform = getPlatform();
|
|
2039
2072
|
const virtualCode = await compileVirtual({
|
|
2040
2073
|
css,
|
|
2041
2074
|
platform,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const enum Platform {
|
|
2
|
+
Android = "android",
|
|
3
|
+
iOS = "ios",
|
|
4
|
+
Web = "web",
|
|
5
|
+
Native = "native",
|
|
6
|
+
TV = "tv",
|
|
7
|
+
AndroidTV = "android-tv",
|
|
8
|
+
AppleTV = "apple-tv"
|
|
9
|
+
}
|
|
10
|
+
export declare const UNIWIND_PLATFORM_VARIABLES = "__uniwind-platform-";
|
|
11
|
+
export declare const UNIWIND_THEME_VARIABLES = "__uniwind-theme-";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var Platform = /* @__PURE__ */ ((Platform2) => {
|
|
2
|
+
Platform2["Android"] = "android";
|
|
3
|
+
Platform2["iOS"] = "ios";
|
|
4
|
+
Platform2["Web"] = "web";
|
|
5
|
+
Platform2["Native"] = "native";
|
|
6
|
+
Platform2["TV"] = "tv";
|
|
7
|
+
Platform2["AndroidTV"] = "android-tv";
|
|
8
|
+
Platform2["AppleTV"] = "apple-tv";
|
|
9
|
+
return Platform2;
|
|
10
|
+
})(Platform || {});
|
|
11
|
+
export const UNIWIND_PLATFORM_VARIABLES = "__uniwind-platform-";
|
|
12
|
+
export const UNIWIND_THEME_VARIABLES = "__uniwind-theme-";
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { PressableProps } from 'react-native';
|
|
2
|
+
declare module 'react-native' {
|
|
3
|
+
interface PressableStateCallbackType {
|
|
4
|
+
focused?: boolean;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
2
7
|
export declare const Pressable: import("react").ForwardRefExoticComponent<PressableProps & import("react").RefAttributes<import("react-native").View>>;
|
|
3
8
|
export default Pressable;
|
|
@@ -5,9 +5,11 @@ import { copyComponentProperties } from "../utils.js";
|
|
|
5
5
|
import { useStyle } from "./useStyle.js";
|
|
6
6
|
export const Pressable = copyComponentProperties(RNPressable, (props) => {
|
|
7
7
|
const [isPressed, setIsPressed] = useState(false);
|
|
8
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
8
9
|
const { Component, style } = useStyle(RNPressable, props.className, props, {
|
|
9
10
|
isDisabled: Boolean(props.disabled),
|
|
10
|
-
isPressed
|
|
11
|
+
isPressed,
|
|
12
|
+
isFocused
|
|
11
13
|
});
|
|
12
14
|
return /* @__PURE__ */ jsx(
|
|
13
15
|
Component,
|
|
@@ -15,7 +17,7 @@ export const Pressable = copyComponentProperties(RNPressable, (props) => {
|
|
|
15
17
|
...props,
|
|
16
18
|
style: [
|
|
17
19
|
style,
|
|
18
|
-
typeof props.style === "function" ? props.style({ pressed: isPressed }) : props.style
|
|
20
|
+
typeof props.style === "function" ? props.style({ pressed: isPressed, focused: isFocused }) : props.style
|
|
19
21
|
],
|
|
20
22
|
onPressIn: (event) => {
|
|
21
23
|
setIsPressed(true);
|
|
@@ -24,6 +26,14 @@ export const Pressable = copyComponentProperties(RNPressable, (props) => {
|
|
|
24
26
|
onPressOut: (event) => {
|
|
25
27
|
setIsPressed(false);
|
|
26
28
|
props.onPressOut?.(event);
|
|
29
|
+
},
|
|
30
|
+
onFocus: (event) => {
|
|
31
|
+
setIsFocused(true);
|
|
32
|
+
props.onFocus?.(event);
|
|
33
|
+
},
|
|
34
|
+
onBlur: (event) => {
|
|
35
|
+
setIsFocused(false);
|
|
36
|
+
props.onBlur?.(event);
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
39
|
);
|
|
@@ -5,9 +5,11 @@ import { copyComponentProperties } from "../utils.js";
|
|
|
5
5
|
import { useStyle } from "./useStyle.js";
|
|
6
6
|
export const TouchableHighlight = copyComponentProperties(RNTouchableHighlight, (props) => {
|
|
7
7
|
const [isPressed, setIsPressed] = useState(false);
|
|
8
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
8
9
|
const state = {
|
|
9
10
|
isDisabled: Boolean(props.disabled),
|
|
10
|
-
isPressed
|
|
11
|
+
isPressed,
|
|
12
|
+
isFocused
|
|
11
13
|
};
|
|
12
14
|
const { Component, style } = useStyle(RNTouchableHighlight, props.className, props, state);
|
|
13
15
|
const underlayColor = useStyle(props.underlayColorClassName, props, state).accentColor;
|
|
@@ -24,6 +26,14 @@ export const TouchableHighlight = copyComponentProperties(RNTouchableHighlight,
|
|
|
24
26
|
onPressOut: (event) => {
|
|
25
27
|
setIsPressed(false);
|
|
26
28
|
props.onPressOut?.(event);
|
|
29
|
+
},
|
|
30
|
+
onFocus: (event) => {
|
|
31
|
+
setIsFocused(true);
|
|
32
|
+
props.onFocus?.(event);
|
|
33
|
+
},
|
|
34
|
+
onBlur: (event) => {
|
|
35
|
+
setIsFocused(false);
|
|
36
|
+
props.onBlur?.(event);
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
39
|
);
|
|
@@ -5,9 +5,11 @@ import { copyComponentProperties } from "../utils.js";
|
|
|
5
5
|
import { useStyle } from "./useStyle.js";
|
|
6
6
|
export const TouchableOpacity = copyComponentProperties(RNTouchableOpacity, (props) => {
|
|
7
7
|
const [isPressed, setIsPressed] = useState(false);
|
|
8
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
8
9
|
const state = {
|
|
9
10
|
isDisabled: Boolean(props.disabled),
|
|
10
|
-
isPressed
|
|
11
|
+
isPressed,
|
|
12
|
+
isFocused
|
|
11
13
|
};
|
|
12
14
|
const { Component, style } = useStyle(RNTouchableOpacity, props.className, props, state);
|
|
13
15
|
return /* @__PURE__ */ jsx(
|
|
@@ -22,6 +24,14 @@ export const TouchableOpacity = copyComponentProperties(RNTouchableOpacity, (pro
|
|
|
22
24
|
onPressOut: (event) => {
|
|
23
25
|
setIsPressed(false);
|
|
24
26
|
props.onPressOut?.(event);
|
|
27
|
+
},
|
|
28
|
+
onFocus: (event) => {
|
|
29
|
+
setIsFocused(true);
|
|
30
|
+
props.onFocus?.(event);
|
|
31
|
+
},
|
|
32
|
+
onBlur: (event) => {
|
|
33
|
+
setIsFocused(false);
|
|
34
|
+
props.onBlur?.(event);
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
);
|
|
@@ -15,6 +15,7 @@ declare class UniwindStoreBuilder {
|
|
|
15
15
|
reinit: (generateStyleSheetCallback: GenerateStyleSheetsCallback, themes: Array<string>) => void;
|
|
16
16
|
private resolveStyles;
|
|
17
17
|
private validateDataAttributes;
|
|
18
|
+
private getCurrentPlatform;
|
|
18
19
|
}
|
|
19
20
|
export declare const UniwindStore: UniwindStoreBuilder;
|
|
20
21
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dimensions, Platform } from "react-native";
|
|
2
|
+
import { Platform as UniwindPlatform, UNIWIND_PLATFORM_VARIABLES, UNIWIND_THEME_VARIABLES } from "../../common/consts.js";
|
|
2
3
|
import { Orientation, StyleDependency } from "../../types.js";
|
|
3
4
|
import { UniwindListener } from "../listener.js";
|
|
4
5
|
import { cloneWithAccessors } from "./native-utils.js";
|
|
@@ -40,7 +41,13 @@ class UniwindStoreBuilder {
|
|
|
40
41
|
}
|
|
41
42
|
reinit = (generateStyleSheetCallback, themes) => {
|
|
42
43
|
const { scopedVars, stylesheet, vars, keyframes } = generateStyleSheetCallback(this.runtime);
|
|
43
|
-
const
|
|
44
|
+
const platform = this.getCurrentPlatform();
|
|
45
|
+
const commonPlatform = platform.includes("tv") ? UniwindPlatform.TV : UniwindPlatform.Native;
|
|
46
|
+
const commonPlatformVars = scopedVars[`${UNIWIND_PLATFORM_VARIABLES}${commonPlatform}`];
|
|
47
|
+
const platformVars = scopedVars[`${UNIWIND_PLATFORM_VARIABLES}${platform}`];
|
|
48
|
+
if (commonPlatformVars) {
|
|
49
|
+
Object.defineProperties(vars, Object.getOwnPropertyDescriptors(commonPlatformVars));
|
|
50
|
+
}
|
|
44
51
|
if (platformVars) {
|
|
45
52
|
Object.defineProperties(vars, Object.getOwnPropertyDescriptors(platformVars));
|
|
46
53
|
}
|
|
@@ -48,7 +55,7 @@ class UniwindStoreBuilder {
|
|
|
48
55
|
this.stylesheet = stylesheet;
|
|
49
56
|
this.vars = Object.fromEntries(themes.map((theme) => {
|
|
50
57
|
const clonedVars = cloneWithAccessors(vars);
|
|
51
|
-
const themeVars = scopedVars[
|
|
58
|
+
const themeVars = scopedVars[`${UNIWIND_THEME_VARIABLES}${theme}`];
|
|
52
59
|
if (themeVars) {
|
|
53
60
|
Object.defineProperties(clonedVars, Object.getOwnPropertyDescriptors(themeVars));
|
|
54
61
|
}
|
|
@@ -209,6 +216,16 @@ class UniwindStoreBuilder {
|
|
|
209
216
|
}
|
|
210
217
|
return true;
|
|
211
218
|
}
|
|
219
|
+
getCurrentPlatform() {
|
|
220
|
+
const platform = Platform.OS;
|
|
221
|
+
if (platform === "android") {
|
|
222
|
+
return Platform.isTV ? UniwindPlatform.AndroidTV : UniwindPlatform.Android;
|
|
223
|
+
}
|
|
224
|
+
if (platform === "ios") {
|
|
225
|
+
return Platform.isTV ? UniwindPlatform.AppleTV : UniwindPlatform.iOS;
|
|
226
|
+
}
|
|
227
|
+
return platform;
|
|
228
|
+
}
|
|
212
229
|
}
|
|
213
230
|
export const UniwindStore = new UniwindStoreBuilder();
|
|
214
231
|
Dimensions.addEventListener("change", ({ window }) => {
|