@niibase/uniwind 1.7.0 → 1.8.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/CHANGELOG.md +35 -0
- package/dist/cli/index.cjs +91 -0
- package/dist/cli/index.mjs +84 -0
- package/dist/common/bundler/artifacts/css/themes.js +3 -0
- package/dist/common/bundler/cli/index.js +76 -0
- package/dist/common/bundler/config.js +6 -0
- package/dist/common/bundler/css-compiler/compileNativeCSS.js +3 -3
- package/dist/common/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
- package/dist/common/bundler/css-processor/color.js +1 -1
- package/dist/common/bundler/css-processor/css.js +2 -2
- package/dist/common/bundler/css-processor/processor.js +7 -7
- package/dist/common/bundler/css-processor/units.js +1 -1
- package/dist/common/bundler/css-processor/utils.js +3 -5
- package/dist/common/bundler/css-processor/var.js +1 -1
- package/dist/common/bundler/css-visitor/rule-visitor.js +2 -2
- package/dist/common/bundler/logger.js +3 -0
- package/dist/common/core/config/config.native.js +1 -5
- package/dist/common/core/native/native-utils.js +1 -8
- package/dist/common/core/native/parsers/textShadow.js +6 -18
- package/dist/common/core/native/parsers/transforms.js +1 -5
- package/dist/common/core/native/store.js +19 -65
- package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/metro/index.cjs +29 -13
- package/dist/metro/index.mjs +22 -6
- package/dist/metro/transformer.cjs +61 -65
- package/dist/metro/transformer.mjs +23 -27
- package/dist/module/bundler/artifacts/css/themes.js +3 -0
- package/dist/module/bundler/cli/index.d.ts +2 -0
- package/dist/module/bundler/cli/index.js +81 -0
- package/dist/module/bundler/config.d.ts +1 -0
- package/dist/module/bundler/config.js +8 -0
- package/dist/module/bundler/css-compiler/compileNativeCSS.js +3 -3
- package/dist/module/bundler/css-compiler/compileTailwind.d.ts +1 -1
- package/dist/module/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
- package/dist/module/bundler/css-processor/color.js +1 -1
- package/dist/module/bundler/css-processor/css.js +2 -2
- package/dist/module/bundler/css-processor/processor.js +7 -7
- package/dist/module/bundler/css-processor/units.js +1 -1
- package/dist/module/bundler/css-processor/utils.d.ts +0 -1
- package/dist/module/bundler/css-processor/utils.js +2 -4
- package/dist/module/bundler/css-processor/var.js +1 -1
- package/dist/module/bundler/css-visitor/rule-visitor.js +2 -2
- package/dist/module/bundler/logger.d.ts +1 -0
- package/dist/module/bundler/logger.js +3 -0
- package/dist/module/components/native/useStyle.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/Text.d.ts +4 -1
- package/dist/module/core/config/config.native.js +1 -5
- package/dist/module/core/native/native-utils.d.ts +0 -1
- package/dist/module/core/native/native-utils.js +0 -6
- package/dist/module/core/native/parsers/textShadow.js +6 -18
- package/dist/module/core/native/parsers/transforms.js +1 -5
- package/dist/module/core/native/store.d.ts +2 -2
- package/dist/module/core/native/store.js +21 -63
- package/dist/module/core/types.d.ts +6 -4
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/shared/{uniwind.CFiAZ3D-.cjs → uniwind.BEqYiPBB.cjs} +17 -5
- package/dist/shared/uniwind.CFAAUZ2t.mjs +3 -0
- package/dist/shared/uniwind.DJ5M1Q4q.cjs +5 -0
- package/dist/shared/{uniwind.u-s1XVU8.mjs → uniwind.DgC4MT51.mjs} +18 -5
- package/dist/vite/index.cjs +75 -42
- package/dist/vite/index.mjs +72 -40
- package/package.json +37 -21
- package/src/bundler/adapters/metro/metro.ts +24 -3
- package/src/bundler/adapters/metro/patches.ts +1 -1
- package/src/bundler/adapters/vite/vite.ts +104 -51
- package/src/bundler/artifacts/css/themes.ts +6 -1
- package/src/bundler/cli/index.ts +105 -0
- package/src/bundler/config.ts +10 -0
- package/src/bundler/css-compiler/compileNativeCSS.ts +3 -3
- package/src/bundler/css-processor/addMetaToStylesTemplate.ts +3 -3
- package/src/bundler/css-processor/color.ts +1 -1
- package/src/bundler/css-processor/css.ts +2 -2
- package/src/bundler/css-processor/processor.ts +7 -7
- package/src/bundler/css-processor/units.ts +1 -1
- package/src/bundler/css-processor/utils.ts +2 -5
- package/src/bundler/css-processor/var.ts +1 -1
- package/src/bundler/css-visitor/rule-visitor.ts +2 -2
- package/src/bundler/logger.ts +4 -0
- package/src/core/config/config.native.ts +1 -5
- package/src/core/native/native-utils.ts +0 -9
- package/src/core/native/parsers/textShadow.ts +6 -18
- package/src/core/native/parsers/transforms.ts +1 -5
- package/src/core/native/runtime.ts +1 -1
- package/src/core/native/store.ts +24 -66
- package/src/core/types.ts +7 -4
- package/src/hooks/useCSSVariable/getVariableValue.native.ts +5 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const config = require('../shared/uniwind.BEqYiPBB.cjs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const _package = require('../shared/uniwind.DJ5M1Q4q.cjs');
|
|
5
6
|
const lightningcss = require('lightningcss');
|
|
6
7
|
const culori = require('culori');
|
|
7
8
|
const node = require('@tailwindcss/node');
|
|
@@ -35,10 +36,9 @@ const smartSplit = (str, separator = " ") => {
|
|
|
35
36
|
};
|
|
36
37
|
const addMissingSpaces = (str) => pipe(str)(
|
|
37
38
|
(x) => x.trim(),
|
|
38
|
-
(x) => x.replace(/([^ {])this/g, "$1 this"),
|
|
39
39
|
(x) => x.replace(/\](?=\d)/g, "] "),
|
|
40
40
|
(x) => x.replace(/\](?=")/g, "] "),
|
|
41
|
-
(x) => x.replace(/\)(
|
|
41
|
+
(x) => x.replace(/\)(?=[^\s,])/g, ") "),
|
|
42
42
|
(x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
|
|
43
43
|
);
|
|
44
44
|
const isValidJSValue = (jsValueString) => {
|
|
@@ -55,7 +55,7 @@ const shouldBeSerialized = (value) => {
|
|
|
55
55
|
}
|
|
56
56
|
return [
|
|
57
57
|
isNumber(value),
|
|
58
|
-
value.startsWith("
|
|
58
|
+
value.startsWith("vars["),
|
|
59
59
|
value.startsWith("rt."),
|
|
60
60
|
/[*/+-]/.test(value),
|
|
61
61
|
value.includes('"'),
|
|
@@ -166,7 +166,7 @@ const serializeJSObject = (obj, serializer) => {
|
|
|
166
166
|
new Function(`function validateJS() { const obj = ({ ${serializedValue} }) }`);
|
|
167
167
|
return true;
|
|
168
168
|
} catch {
|
|
169
|
-
|
|
169
|
+
config.Logger.error(`Failed to serialize ${serializedValue} as a valid JS object entry. Skipping.`);
|
|
170
170
|
return false;
|
|
171
171
|
}
|
|
172
172
|
}),
|
|
@@ -182,8 +182,8 @@ const serializeJSObject = (obj, serializer) => {
|
|
|
182
182
|
};
|
|
183
183
|
|
|
184
184
|
const extractVarsFromString = (value) => {
|
|
185
|
-
const
|
|
186
|
-
return
|
|
185
|
+
const varsIndexes = [...value.matchAll(/vars\[/g)].map((m) => m.index);
|
|
186
|
+
return varsIndexes.map((index) => {
|
|
187
187
|
const afterIndex = value.slice(index + 5);
|
|
188
188
|
const closingIndex = afterIndex.indexOf("]");
|
|
189
189
|
const varName = afterIndex.slice(0, closingIndex);
|
|
@@ -235,10 +235,10 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
235
235
|
dataAttributes,
|
|
236
236
|
...rest
|
|
237
237
|
} = style;
|
|
238
|
-
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`]);
|
|
238
|
+
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function(vars) { return ${serialize(value)} }`]);
|
|
239
239
|
if (platform) {
|
|
240
|
-
const isTV = currentPlatform ===
|
|
241
|
-
const commonPlatform = isTV ?
|
|
240
|
+
const isTV = currentPlatform === config.Platform.AndroidTV || currentPlatform === config.Platform.AppleTV;
|
|
241
|
+
const commonPlatform = isTV ? config.Platform.TV : config.Platform.Native;
|
|
242
242
|
if (platform !== commonPlatform && platform !== currentPlatform) {
|
|
243
243
|
return null;
|
|
244
244
|
}
|
|
@@ -251,25 +251,25 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
251
251
|
const usedVars = extractVarsFromString(stringifiedEntries);
|
|
252
252
|
const isUsingThemedVar = usedVars.some((usedVarName) => hasThemedVarDependency(usedVarName, Processor));
|
|
253
253
|
if (usedVars.length > 0) {
|
|
254
|
-
dependencies.push(
|
|
254
|
+
dependencies.push(config.StyleDependency.Variables);
|
|
255
255
|
}
|
|
256
256
|
if (theme !== null || isUsingThemedVar || stringifiedEntries.includes("rt.lightDark")) {
|
|
257
|
-
dependencies.push(
|
|
257
|
+
dependencies.push(config.StyleDependency.Theme);
|
|
258
258
|
}
|
|
259
259
|
if (orientation !== null) {
|
|
260
|
-
dependencies.push(
|
|
260
|
+
dependencies.push(config.StyleDependency.Orientation);
|
|
261
261
|
}
|
|
262
262
|
if (rtl !== null) {
|
|
263
|
-
dependencies.push(
|
|
263
|
+
dependencies.push(config.StyleDependency.Rtl);
|
|
264
264
|
}
|
|
265
265
|
if (Number(minWidth) !== 0 || Number(maxWidth) !== Number.MAX_VALUE || stringifiedEntries.includes("rt.makeResponsive") || stringifiedEntries.includes("rt.screen")) {
|
|
266
|
-
dependencies.push(
|
|
266
|
+
dependencies.push(config.StyleDependency.Dimensions);
|
|
267
267
|
}
|
|
268
268
|
if (stringifiedEntries.includes("rt.insets")) {
|
|
269
|
-
dependencies.push(
|
|
269
|
+
dependencies.push(config.StyleDependency.Insets);
|
|
270
270
|
}
|
|
271
271
|
if (stringifiedEntries.includes("rt.fontScale")) {
|
|
272
|
-
dependencies.push(
|
|
272
|
+
dependencies.push(config.StyleDependency.FontScale);
|
|
273
273
|
}
|
|
274
274
|
return {
|
|
275
275
|
entries,
|
|
@@ -301,7 +301,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
301
301
|
].filter(Boolean).length
|
|
302
302
|
};
|
|
303
303
|
});
|
|
304
|
-
const filteredStyles = styles.filter(
|
|
304
|
+
const filteredStyles = styles.filter(config.isDefined);
|
|
305
305
|
if (filteredStyles.length === 0) {
|
|
306
306
|
return null;
|
|
307
307
|
}
|
|
@@ -309,7 +309,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
309
309
|
className,
|
|
310
310
|
filteredStyles
|
|
311
311
|
];
|
|
312
|
-
}).filter(
|
|
312
|
+
}).filter(config.isDefined);
|
|
313
313
|
const stylesheets = Object.fromEntries(stylesheetsEntries);
|
|
314
314
|
return stylesheets;
|
|
315
315
|
};
|
|
@@ -358,11 +358,7 @@ const parseTransformsMutation = (styles, preserve = false) => {
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
if (transformsResult.length > 0) {
|
|
361
|
-
|
|
362
|
-
configurable: true,
|
|
363
|
-
enumerable: true,
|
|
364
|
-
value: transformsResult
|
|
365
|
-
});
|
|
361
|
+
styles.transform = transformsResult;
|
|
366
362
|
}
|
|
367
363
|
};
|
|
368
364
|
|
|
@@ -372,7 +368,7 @@ class Color {
|
|
|
372
368
|
}
|
|
373
369
|
toRgb = culori.converter("rgb");
|
|
374
370
|
black = "#000000";
|
|
375
|
-
logger = new
|
|
371
|
+
logger = new config.Logger("Color");
|
|
376
372
|
processColor(color) {
|
|
377
373
|
if (typeof color === "string") {
|
|
378
374
|
const parsed = culori.parse(color);
|
|
@@ -389,7 +385,7 @@ class Color {
|
|
|
389
385
|
}
|
|
390
386
|
try {
|
|
391
387
|
if (color.type === "currentcolor") {
|
|
392
|
-
return '
|
|
388
|
+
return 'vars["currentColor"]?.(vars)';
|
|
393
389
|
}
|
|
394
390
|
if (color.type === "rgb" || color.type === "srgb") {
|
|
395
391
|
const alpha = typeof color.alpha === "number" ? color.alpha : pipe(color.alpha)(
|
|
@@ -543,7 +539,7 @@ class CSS {
|
|
|
543
539
|
constructor(Processor) {
|
|
544
540
|
this.Processor = Processor;
|
|
545
541
|
}
|
|
546
|
-
logger = new
|
|
542
|
+
logger = new config.Logger("CSS");
|
|
547
543
|
processValue(declarationValue, declarationProperty) {
|
|
548
544
|
const processedValue = this.getProcessedValue(declarationValue, declarationProperty);
|
|
549
545
|
if (typeof processedValue === "string") {
|
|
@@ -608,7 +604,7 @@ class CSS {
|
|
|
608
604
|
this.processValue(filter.value.yOffset),
|
|
609
605
|
this.processValue(filter.value.blur),
|
|
610
606
|
this.processValue(filter.value.color)
|
|
611
|
-
].filter(
|
|
607
|
+
].filter(config.isDefined);
|
|
612
608
|
return `drop-shadow(${parts.join(" ")})`;
|
|
613
609
|
}
|
|
614
610
|
const value = this.processValue(filter.value);
|
|
@@ -771,7 +767,7 @@ class CSS {
|
|
|
771
767
|
return this.Processor.Color.processColor(declarationValue.value);
|
|
772
768
|
}
|
|
773
769
|
if (declarationValue.value === "currentcolor") {
|
|
774
|
-
return '
|
|
770
|
+
return 'vars["currentColor"]?.(vars)';
|
|
775
771
|
}
|
|
776
772
|
return declarationValue.value;
|
|
777
773
|
case "env":
|
|
@@ -808,7 +804,7 @@ class CSS {
|
|
|
808
804
|
case "pair":
|
|
809
805
|
return declarationValue.inside.type;
|
|
810
806
|
case "currentcolor":
|
|
811
|
-
return '
|
|
807
|
+
return 'vars["currentColor"]?.(vars)';
|
|
812
808
|
case "calc":
|
|
813
809
|
return this.Processor.Functions.processCalc(declarationValue.value);
|
|
814
810
|
case "min":
|
|
@@ -841,7 +837,7 @@ class CSS {
|
|
|
841
837
|
return [
|
|
842
838
|
this.Processor.Color.processColor(declarationValue.color),
|
|
843
839
|
declarationValue.position ? this.processValue(declarationValue.position) : null
|
|
844
|
-
].filter(
|
|
840
|
+
].filter(config.isDefined).join(" ");
|
|
845
841
|
case "side":
|
|
846
842
|
return declarationValue.side;
|
|
847
843
|
case "absolute":
|
|
@@ -982,7 +978,7 @@ class CSS {
|
|
|
982
978
|
this.processValue(declarationValue.blur),
|
|
983
979
|
this.processValue(declarationValue.spread),
|
|
984
980
|
this.processValue(declarationValue.color)
|
|
985
|
-
].filter(
|
|
981
|
+
].filter(config.isDefined).join(" ");
|
|
986
982
|
}
|
|
987
983
|
if ("blockStart" in declarationValue) {
|
|
988
984
|
const startValue = this.processValue(declarationValue.blockStart);
|
|
@@ -1106,7 +1102,7 @@ class Functions {
|
|
|
1106
1102
|
constructor(Processor) {
|
|
1107
1103
|
this.Processor = Processor;
|
|
1108
1104
|
}
|
|
1109
|
-
logger = new
|
|
1105
|
+
logger = new config.Logger("Functions");
|
|
1110
1106
|
processCalc(calc) {
|
|
1111
1107
|
switch (calc.type) {
|
|
1112
1108
|
case "sum": {
|
|
@@ -1300,12 +1296,12 @@ class MQ {
|
|
|
1300
1296
|
for (const mediaQuery of mediaQueries) {
|
|
1301
1297
|
const { condition, mediaType } = mediaQuery;
|
|
1302
1298
|
if ([
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1299
|
+
config.Platform.Android,
|
|
1300
|
+
config.Platform.iOS,
|
|
1301
|
+
config.Platform.Native,
|
|
1302
|
+
config.Platform.AndroidTV,
|
|
1303
|
+
config.Platform.AppleTV,
|
|
1304
|
+
config.Platform.TV
|
|
1309
1305
|
].includes(mediaType)) {
|
|
1310
1306
|
mq.platform = mediaType;
|
|
1311
1307
|
continue;
|
|
@@ -1630,7 +1626,7 @@ class RN {
|
|
|
1630
1626
|
typeof value === "string" ? addMissingSpaces(value) : value
|
|
1631
1627
|
);
|
|
1632
1628
|
const joinedStyles = this.joinStyles(rn);
|
|
1633
|
-
return Object.entries(joinedStyles).filter(([, value2]) =>
|
|
1629
|
+
return Object.entries(joinedStyles).filter(([, value2]) => config.isDefined(value2)).map(([prop, val]) => [prop, this.makeResponsive(prop, val)]);
|
|
1634
1630
|
}
|
|
1635
1631
|
makeResponsive(property, value) {
|
|
1636
1632
|
const mode = this.Processor.bundlerConfig.polyfills?.responsive;
|
|
@@ -1652,10 +1648,10 @@ class RN {
|
|
|
1652
1648
|
const isTextMode = mode === true || mode === "text";
|
|
1653
1649
|
const isComponentMode = mode === true || mode === "components";
|
|
1654
1650
|
if (isTextMode && (property === "fontSize" || property === "--uniwind-em")) {
|
|
1655
|
-
return `rt.makeResponsive(${value}, ${
|
|
1651
|
+
return `rt.makeResponsive(${value}, ${config.DEFAULT_SCREEN_HEIGHT}, true)`;
|
|
1656
1652
|
}
|
|
1657
1653
|
if (isComponentMode && COMPONENT_RESPONSIVE_PROPS.has(property)) {
|
|
1658
|
-
return `rt.makeResponsive(${value}, ${
|
|
1654
|
+
return `rt.makeResponsive(${value}, ${config.DEFAULT_SCREEN_WIDTH})`;
|
|
1659
1655
|
}
|
|
1660
1656
|
return value;
|
|
1661
1657
|
}
|
|
@@ -1769,7 +1765,7 @@ class Units {
|
|
|
1769
1765
|
constructor(Processor) {
|
|
1770
1766
|
this.Processor = Processor;
|
|
1771
1767
|
}
|
|
1772
|
-
logger = new
|
|
1768
|
+
logger = new config.Logger("Units");
|
|
1773
1769
|
processLength(length) {
|
|
1774
1770
|
if (typeof length === "number") {
|
|
1775
1771
|
return length;
|
|
@@ -1785,7 +1781,7 @@ class Units {
|
|
|
1785
1781
|
case "rem":
|
|
1786
1782
|
return length.value * this.Processor.vars["--uniwind-em"];
|
|
1787
1783
|
case "em":
|
|
1788
|
-
return `
|
|
1784
|
+
return `vars["--uniwind-em"]?.(vars) * ${length.value}`;
|
|
1789
1785
|
default:
|
|
1790
1786
|
this.logger.warn(`Unsupported unit - ${length.unit}`);
|
|
1791
1787
|
return length.value;
|
|
@@ -1818,7 +1814,7 @@ class Var {
|
|
|
1818
1814
|
this.Processor = Processor;
|
|
1819
1815
|
}
|
|
1820
1816
|
processVar(variable) {
|
|
1821
|
-
const value = `
|
|
1817
|
+
const value = `vars[${JSON.stringify(variable.name.ident)}]?.(vars)`;
|
|
1822
1818
|
if (!variable.fallback || variable.fallback.length === 0) {
|
|
1823
1819
|
return value;
|
|
1824
1820
|
}
|
|
@@ -1906,7 +1902,7 @@ class ProcessorBuilder {
|
|
|
1906
1902
|
return this.stylesheets[this.declarationConfig.className]?.at(-1);
|
|
1907
1903
|
}
|
|
1908
1904
|
if (mq.platform !== null) {
|
|
1909
|
-
const platformKey = `${
|
|
1905
|
+
const platformKey = `${config.UNIWIND_PLATFORM_VARIABLES}${mq.platform}`;
|
|
1910
1906
|
this.scopedVars[platformKey] ??= {};
|
|
1911
1907
|
return this.scopedVars[platformKey];
|
|
1912
1908
|
}
|
|
@@ -1918,7 +1914,7 @@ class ProcessorBuilder {
|
|
|
1918
1914
|
if (this.declarationConfig.theme === null) {
|
|
1919
1915
|
return this.vars;
|
|
1920
1916
|
}
|
|
1921
|
-
const themeKey = `${
|
|
1917
|
+
const themeKey = `${config.UNIWIND_THEME_VARIABLES}${this.declarationConfig.theme}`;
|
|
1922
1918
|
this.scopedVars[themeKey] ??= {};
|
|
1923
1919
|
return this.scopedVars[themeKey];
|
|
1924
1920
|
})();
|
|
@@ -1940,7 +1936,7 @@ class ProcessorBuilder {
|
|
|
1940
1936
|
if (!isVar && important) {
|
|
1941
1937
|
style.importantProperties.push(property);
|
|
1942
1938
|
}
|
|
1943
|
-
const match = typeof value === "string" ? value.match(/
|
|
1939
|
+
const match = typeof value === "string" ? value.match(/vars\["(.*?)"\]/) : null;
|
|
1944
1940
|
if (match && !isVar) {
|
|
1945
1941
|
const className = this.declarationConfig.className;
|
|
1946
1942
|
if (className === null) {
|
|
@@ -2070,12 +2066,12 @@ class ProcessorBuilder {
|
|
|
2070
2066
|
}
|
|
2071
2067
|
});
|
|
2072
2068
|
if ([rtl, theme, active, focus, disabled, dataAttributes].some(Boolean)) {
|
|
2073
|
-
this.declarationConfig.rtl
|
|
2074
|
-
this.declarationConfig.theme
|
|
2075
|
-
this.declarationConfig.active
|
|
2076
|
-
this.declarationConfig.focus
|
|
2077
|
-
this.declarationConfig.disabled
|
|
2078
|
-
this.declarationConfig.dataAttributes
|
|
2069
|
+
this.declarationConfig.rtl ??= rtl;
|
|
2070
|
+
this.declarationConfig.theme ??= theme;
|
|
2071
|
+
this.declarationConfig.active ??= active;
|
|
2072
|
+
this.declarationConfig.focus ??= focus;
|
|
2073
|
+
this.declarationConfig.disabled ??= disabled;
|
|
2074
|
+
this.declarationConfig.dataAttributes ??= dataAttributes;
|
|
2079
2075
|
rule.value.declarations?.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
2080
2076
|
rule.value.declarations?.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
2081
2077
|
rule.value.rules?.forEach((rule2) => this.parseRuleRec(rule2));
|
|
@@ -2163,7 +2159,7 @@ const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
|
|
|
2163
2159
|
);
|
|
2164
2160
|
const vars = serializeJSObject(
|
|
2165
2161
|
Processor.vars,
|
|
2166
|
-
(key, value) => `
|
|
2162
|
+
(key, value) => `"${key}": vars => ${value}`
|
|
2167
2163
|
);
|
|
2168
2164
|
const keyframes = serializeJSObject(
|
|
2169
2165
|
Processor.keyframes,
|
|
@@ -2172,11 +2168,11 @@ const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
|
|
|
2172
2168
|
const scopedVars = Object.fromEntries(
|
|
2173
2169
|
Object.entries(Processor.scopedVars).map(([scopedVarsName, scopedVars2]) => [
|
|
2174
2170
|
scopedVarsName,
|
|
2175
|
-
serializeJSObject(scopedVars2, (key, value) => `
|
|
2171
|
+
serializeJSObject(scopedVars2, (key, value) => `"${key}": vars => ${value}`)
|
|
2176
2172
|
])
|
|
2177
2173
|
);
|
|
2178
2174
|
const serializedScopedVars = Object.entries(scopedVars).map(([scopedVarsName, scopedVars2]) => `"${scopedVarsName}": ({ ${scopedVars2} }),`).join("");
|
|
2179
|
-
const currentColorVar = `
|
|
2175
|
+
const currentColorVar = `currentColor: () => rt.colorScheme === 'dark' ? '#ffffff' : '#000000',`;
|
|
2180
2176
|
return [
|
|
2181
2177
|
"({",
|
|
2182
2178
|
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
@@ -2216,7 +2212,7 @@ const compileWebCSS = (bundlerConfig, tailwindCSS) => {
|
|
|
2216
2212
|
|
|
2217
2213
|
const compileCSS = async (bundlerConfig) => {
|
|
2218
2214
|
const tailwindCSS = await compileTailwind(bundlerConfig);
|
|
2219
|
-
if (bundlerConfig.platform ===
|
|
2215
|
+
if (bundlerConfig.platform === config.Platform.Web) {
|
|
2220
2216
|
return compileWebCSS(bundlerConfig, tailwindCSS);
|
|
2221
2217
|
}
|
|
2222
2218
|
return compileNativeCSS(bundlerConfig, tailwindCSS);
|
|
@@ -2234,10 +2230,10 @@ try {
|
|
|
2234
2230
|
} catch {
|
|
2235
2231
|
worker = require("metro-transform-worker");
|
|
2236
2232
|
}
|
|
2237
|
-
const transform = async (config, projectRoot, filePath, data, options) => {
|
|
2238
|
-
const isCss = options.type !== "asset" && path__default.join(process.cwd(), config.uniwind.cssEntryFile) === path__default.join(projectRoot, filePath);
|
|
2233
|
+
const transform = async (config$1, projectRoot, filePath, data, options) => {
|
|
2234
|
+
const isCss = options.type !== "asset" && path__default.join(process.cwd(), config$1.uniwind.cssEntryFile) === path__default.join(projectRoot, filePath);
|
|
2239
2235
|
if (filePath.endsWith("/components/web/metro-injected.js")) {
|
|
2240
|
-
const bundlerConfig2 =
|
|
2236
|
+
const bundlerConfig2 = config.UniwindBundlerConfig.fromMetroConfig(config$1.uniwind, config.Platform.Web);
|
|
2241
2237
|
data = Buffer.from(
|
|
2242
2238
|
[
|
|
2243
2239
|
`import { Uniwind } from '${_package.name}';`,
|
|
@@ -2247,12 +2243,12 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2247
2243
|
);
|
|
2248
2244
|
}
|
|
2249
2245
|
if (!isCss) {
|
|
2250
|
-
return worker.transform(config, projectRoot, filePath, data, options);
|
|
2246
|
+
return worker.transform(config$1, projectRoot, filePath, data, options);
|
|
2251
2247
|
}
|
|
2252
|
-
const bundlerConfig =
|
|
2248
|
+
const bundlerConfig = config.UniwindBundlerConfig.fromMetroConfig(config$1.uniwind, options.platform);
|
|
2253
2249
|
await bundlerConfig.generateArtifacts(cssArtifactPath);
|
|
2254
2250
|
const virtualCode = await compileCSS(bundlerConfig);
|
|
2255
|
-
const isWeb = bundlerConfig.platform ===
|
|
2251
|
+
const isWeb = bundlerConfig.platform === config.Platform.Web;
|
|
2256
2252
|
data = Buffer.from(
|
|
2257
2253
|
isWeb ? virtualCode : [
|
|
2258
2254
|
`const { Uniwind } = require('${_package.name}');`,
|
|
@@ -2261,7 +2257,7 @@ const transform = async (config, projectRoot, filePath, data, options) => {
|
|
|
2261
2257
|
"utf-8"
|
|
2262
2258
|
);
|
|
2263
2259
|
const transform2 = await worker.transform(
|
|
2264
|
-
config,
|
|
2260
|
+
config$1,
|
|
2265
2261
|
projectRoot,
|
|
2266
2262
|
`${filePath}${isWeb ? "" : ".js"}`,
|
|
2267
2263
|
data,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { L as Logger, P as Platform, S as StyleDependency, i as isDefined, D as DEFAULT_SCREEN_HEIGHT, a as DEFAULT_SCREEN_WIDTH, b as UNIWIND_PLATFORM_VARIABLES, c as UNIWIND_THEME_VARIABLES, U as UniwindBundlerConfig
|
|
1
|
+
import { L as Logger, P as Platform, S as StyleDependency, i as isDefined, D as DEFAULT_SCREEN_HEIGHT, a as DEFAULT_SCREEN_WIDTH, b as UNIWIND_PLATFORM_VARIABLES, c as UNIWIND_THEME_VARIABLES, U as UniwindBundlerConfig } from '../shared/uniwind.DgC4MT51.mjs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { n as name } from '../shared/uniwind.CFAAUZ2t.mjs';
|
|
3
4
|
import { transform as transform$1 } from 'lightningcss';
|
|
4
5
|
import { converter, parse, formatHex, formatHex8 } from 'culori';
|
|
5
6
|
import { compile } from '@tailwindcss/node';
|
|
@@ -28,10 +29,9 @@ const smartSplit = (str, separator = " ") => {
|
|
|
28
29
|
};
|
|
29
30
|
const addMissingSpaces = (str) => pipe(str)(
|
|
30
31
|
(x) => x.trim(),
|
|
31
|
-
(x) => x.replace(/([^ {])this/g, "$1 this"),
|
|
32
32
|
(x) => x.replace(/\](?=\d)/g, "] "),
|
|
33
33
|
(x) => x.replace(/\](?=")/g, "] "),
|
|
34
|
-
(x) => x.replace(/\)(
|
|
34
|
+
(x) => x.replace(/\)(?=[^\s,])/g, ") "),
|
|
35
35
|
(x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
|
|
36
36
|
);
|
|
37
37
|
const isValidJSValue = (jsValueString) => {
|
|
@@ -48,7 +48,7 @@ const shouldBeSerialized = (value) => {
|
|
|
48
48
|
}
|
|
49
49
|
return [
|
|
50
50
|
isNumber(value),
|
|
51
|
-
value.startsWith("
|
|
51
|
+
value.startsWith("vars["),
|
|
52
52
|
value.startsWith("rt."),
|
|
53
53
|
/[*/+-]/.test(value),
|
|
54
54
|
value.includes('"'),
|
|
@@ -175,8 +175,8 @@ const serializeJSObject = (obj, serializer) => {
|
|
|
175
175
|
};
|
|
176
176
|
|
|
177
177
|
const extractVarsFromString = (value) => {
|
|
178
|
-
const
|
|
179
|
-
return
|
|
178
|
+
const varsIndexes = [...value.matchAll(/vars\[/g)].map((m) => m.index);
|
|
179
|
+
return varsIndexes.map((index) => {
|
|
180
180
|
const afterIndex = value.slice(index + 5);
|
|
181
181
|
const closingIndex = afterIndex.indexOf("]");
|
|
182
182
|
const varName = afterIndex.slice(0, closingIndex);
|
|
@@ -228,7 +228,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
|
228
228
|
dataAttributes,
|
|
229
229
|
...rest
|
|
230
230
|
} = style;
|
|
231
|
-
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`]);
|
|
231
|
+
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function(vars) { return ${serialize(value)} }`]);
|
|
232
232
|
if (platform) {
|
|
233
233
|
const isTV = currentPlatform === Platform.AndroidTV || currentPlatform === Platform.AppleTV;
|
|
234
234
|
const commonPlatform = isTV ? Platform.TV : Platform.Native;
|
|
@@ -351,11 +351,7 @@ const parseTransformsMutation = (styles, preserve = false) => {
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
if (transformsResult.length > 0) {
|
|
354
|
-
|
|
355
|
-
configurable: true,
|
|
356
|
-
enumerable: true,
|
|
357
|
-
value: transformsResult
|
|
358
|
-
});
|
|
354
|
+
styles.transform = transformsResult;
|
|
359
355
|
}
|
|
360
356
|
};
|
|
361
357
|
|
|
@@ -382,7 +378,7 @@ class Color {
|
|
|
382
378
|
}
|
|
383
379
|
try {
|
|
384
380
|
if (color.type === "currentcolor") {
|
|
385
|
-
return '
|
|
381
|
+
return 'vars["currentColor"]?.(vars)';
|
|
386
382
|
}
|
|
387
383
|
if (color.type === "rgb" || color.type === "srgb") {
|
|
388
384
|
const alpha = typeof color.alpha === "number" ? color.alpha : pipe(color.alpha)(
|
|
@@ -764,7 +760,7 @@ class CSS {
|
|
|
764
760
|
return this.Processor.Color.processColor(declarationValue.value);
|
|
765
761
|
}
|
|
766
762
|
if (declarationValue.value === "currentcolor") {
|
|
767
|
-
return '
|
|
763
|
+
return 'vars["currentColor"]?.(vars)';
|
|
768
764
|
}
|
|
769
765
|
return declarationValue.value;
|
|
770
766
|
case "env":
|
|
@@ -801,7 +797,7 @@ class CSS {
|
|
|
801
797
|
case "pair":
|
|
802
798
|
return declarationValue.inside.type;
|
|
803
799
|
case "currentcolor":
|
|
804
|
-
return '
|
|
800
|
+
return 'vars["currentColor"]?.(vars)';
|
|
805
801
|
case "calc":
|
|
806
802
|
return this.Processor.Functions.processCalc(declarationValue.value);
|
|
807
803
|
case "min":
|
|
@@ -1778,7 +1774,7 @@ class Units {
|
|
|
1778
1774
|
case "rem":
|
|
1779
1775
|
return length.value * this.Processor.vars["--uniwind-em"];
|
|
1780
1776
|
case "em":
|
|
1781
|
-
return `
|
|
1777
|
+
return `vars["--uniwind-em"]?.(vars) * ${length.value}`;
|
|
1782
1778
|
default:
|
|
1783
1779
|
this.logger.warn(`Unsupported unit - ${length.unit}`);
|
|
1784
1780
|
return length.value;
|
|
@@ -1811,7 +1807,7 @@ class Var {
|
|
|
1811
1807
|
this.Processor = Processor;
|
|
1812
1808
|
}
|
|
1813
1809
|
processVar(variable) {
|
|
1814
|
-
const value = `
|
|
1810
|
+
const value = `vars[${JSON.stringify(variable.name.ident)}]?.(vars)`;
|
|
1815
1811
|
if (!variable.fallback || variable.fallback.length === 0) {
|
|
1816
1812
|
return value;
|
|
1817
1813
|
}
|
|
@@ -1933,7 +1929,7 @@ class ProcessorBuilder {
|
|
|
1933
1929
|
if (!isVar && important) {
|
|
1934
1930
|
style.importantProperties.push(property);
|
|
1935
1931
|
}
|
|
1936
|
-
const match = typeof value === "string" ? value.match(/
|
|
1932
|
+
const match = typeof value === "string" ? value.match(/vars\["(.*?)"\]/) : null;
|
|
1937
1933
|
if (match && !isVar) {
|
|
1938
1934
|
const className = this.declarationConfig.className;
|
|
1939
1935
|
if (className === null) {
|
|
@@ -2063,12 +2059,12 @@ class ProcessorBuilder {
|
|
|
2063
2059
|
}
|
|
2064
2060
|
});
|
|
2065
2061
|
if ([rtl, theme, active, focus, disabled, dataAttributes].some(Boolean)) {
|
|
2066
|
-
this.declarationConfig.rtl
|
|
2067
|
-
this.declarationConfig.theme
|
|
2068
|
-
this.declarationConfig.active
|
|
2069
|
-
this.declarationConfig.focus
|
|
2070
|
-
this.declarationConfig.disabled
|
|
2071
|
-
this.declarationConfig.dataAttributes
|
|
2062
|
+
this.declarationConfig.rtl ??= rtl;
|
|
2063
|
+
this.declarationConfig.theme ??= theme;
|
|
2064
|
+
this.declarationConfig.active ??= active;
|
|
2065
|
+
this.declarationConfig.focus ??= focus;
|
|
2066
|
+
this.declarationConfig.disabled ??= disabled;
|
|
2067
|
+
this.declarationConfig.dataAttributes ??= dataAttributes;
|
|
2072
2068
|
rule.value.declarations?.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
2073
2069
|
rule.value.declarations?.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
2074
2070
|
rule.value.rules?.forEach((rule2) => this.parseRuleRec(rule2));
|
|
@@ -2156,7 +2152,7 @@ const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
|
|
|
2156
2152
|
);
|
|
2157
2153
|
const vars = serializeJSObject(
|
|
2158
2154
|
Processor.vars,
|
|
2159
|
-
(key, value) => `
|
|
2155
|
+
(key, value) => `"${key}": vars => ${value}`
|
|
2160
2156
|
);
|
|
2161
2157
|
const keyframes = serializeJSObject(
|
|
2162
2158
|
Processor.keyframes,
|
|
@@ -2165,11 +2161,11 @@ const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
|
|
|
2165
2161
|
const scopedVars = Object.fromEntries(
|
|
2166
2162
|
Object.entries(Processor.scopedVars).map(([scopedVarsName, scopedVars2]) => [
|
|
2167
2163
|
scopedVarsName,
|
|
2168
|
-
serializeJSObject(scopedVars2, (key, value) => `
|
|
2164
|
+
serializeJSObject(scopedVars2, (key, value) => `"${key}": vars => ${value}`)
|
|
2169
2165
|
])
|
|
2170
2166
|
);
|
|
2171
2167
|
const serializedScopedVars = Object.entries(scopedVars).map(([scopedVarsName, scopedVars2]) => `"${scopedVarsName}": ({ ${scopedVars2} }),`).join("");
|
|
2172
|
-
const currentColorVar = `
|
|
2168
|
+
const currentColorVar = `currentColor: () => rt.colorScheme === 'dark' ? '#ffffff' : '#000000',`;
|
|
2173
2169
|
return [
|
|
2174
2170
|
"({",
|
|
2175
2171
|
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
@@ -49,6 +49,9 @@ export const generateCSSForThemes = async (themes, input) => {
|
|
|
49
49
|
}
|
|
50
50
|
const importUrls = /* @__PURE__ */ new Set();
|
|
51
51
|
const importsCSS = dependencies.filter((dependency) => {
|
|
52
|
+
if (dependency.type !== "import") {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
52
55
|
if (dependency.url.startsWith(".")) {
|
|
53
56
|
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url));
|
|
54
57
|
return false;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { UniwindBundlerConfig } from "@/bundler/config";
|
|
3
|
+
import { Logger } from "@/bundler/logger";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import path from "path";
|
|
6
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const cssArtifactPath = path.resolve(dirname, "../../uniwind.css");
|
|
8
|
+
const printHelp = () => {
|
|
9
|
+
console.log([
|
|
10
|
+
"Usage: uniwind generate-artifacts --css <file> [--theme <name>...] [--dts <file>]",
|
|
11
|
+
"",
|
|
12
|
+
"Options:",
|
|
13
|
+
" --css <file> CSS entry file path, e.g. ./global.css",
|
|
14
|
+
" --theme <name> Extra theme name. Can be passed multiple times",
|
|
15
|
+
" --dts <file> Generated TypeScript declarations path",
|
|
16
|
+
" --help Show help"
|
|
17
|
+
].join("\n"));
|
|
18
|
+
};
|
|
19
|
+
const readValue = (args, index, flag) => {
|
|
20
|
+
const value = args[index + 1];
|
|
21
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
22
|
+
throw new Error(`Uniwind: ${flag} requires a value`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const parseGenerateArtifactsArgs = (args) => {
|
|
27
|
+
const parsed = {
|
|
28
|
+
extraThemes: []
|
|
29
|
+
};
|
|
30
|
+
for (let index = 0; index < args.length; index++) {
|
|
31
|
+
const arg = args[index];
|
|
32
|
+
switch (arg) {
|
|
33
|
+
case "--css":
|
|
34
|
+
parsed.cssEntryFile = readValue(args, index, arg);
|
|
35
|
+
index++;
|
|
36
|
+
break;
|
|
37
|
+
case "--theme":
|
|
38
|
+
parsed.extraThemes.push(readValue(args, index, arg));
|
|
39
|
+
index++;
|
|
40
|
+
break;
|
|
41
|
+
case "--dts":
|
|
42
|
+
parsed.dtsFile = readValue(args, index, arg);
|
|
43
|
+
index++;
|
|
44
|
+
break;
|
|
45
|
+
case "--help":
|
|
46
|
+
printHelp();
|
|
47
|
+
process.exit(0);
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Uniwind: Unknown option ${arg}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
};
|
|
54
|
+
const generateArtifacts = async (args) => {
|
|
55
|
+
const parsed = parseGenerateArtifactsArgs(args);
|
|
56
|
+
const bundlerConfig = UniwindBundlerConfig.fromCliConfig({
|
|
57
|
+
cssEntryFile: parsed.cssEntryFile,
|
|
58
|
+
dtsFile: parsed.dtsFile,
|
|
59
|
+
extraThemes: parsed.extraThemes
|
|
60
|
+
});
|
|
61
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath);
|
|
62
|
+
Logger.info("Artifacts generated");
|
|
63
|
+
};
|
|
64
|
+
const main = async () => {
|
|
65
|
+
const [command, ...args] = process.argv.slice(2);
|
|
66
|
+
if (command === "--help" || command === void 0) {
|
|
67
|
+
printHelp();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
switch (command) {
|
|
71
|
+
case "generate-artifacts":
|
|
72
|
+
await generateArtifacts(args);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Uniwind: Unknown command ${command}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
main().catch((error) => {
|
|
79
|
+
console.error(error instanceof Error ? error.message : error);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
@@ -5,6 +5,7 @@ export declare class UniwindBundlerConfig {
|
|
|
5
5
|
readonly platform: Platform;
|
|
6
6
|
static fromMetroConfig(config: UniwindMetroConfig, platform?: string | null): UniwindBundlerConfig;
|
|
7
7
|
static fromViteConfig(config: UniwindConfig): UniwindBundlerConfig;
|
|
8
|
+
static fromCliConfig(config: UniwindConfig): UniwindBundlerConfig;
|
|
8
9
|
constructor(config: UniwindMetroConfig, platform: Platform);
|
|
9
10
|
get cssPath(): any;
|
|
10
11
|
get themes(): any[];
|
|
@@ -38,6 +38,14 @@ export class UniwindBundlerConfig {
|
|
|
38
38
|
static fromViteConfig(config) {
|
|
39
39
|
return new UniwindBundlerConfig(config, Platform.Web);
|
|
40
40
|
}
|
|
41
|
+
static fromCliConfig(config) {
|
|
42
|
+
if (typeof config.cssEntryFile === "undefined") {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Uniwind: You need to pass css entry file, e.g. uniwind generate-artifacts --css ./global.css. Run uniwind generate-artifacts --help for usage."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return new UniwindBundlerConfig(config, Platform.Web);
|
|
48
|
+
}
|
|
41
49
|
get cssPath() {
|
|
42
50
|
return path.join(process.cwd(), this.config.cssEntryFile);
|
|
43
51
|
}
|