@hanzogui/static 4.4.0 → 7.0.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/check-dep-versions.cjs +1 -1
- package/dist/checkDeps.cjs +11 -11
- package/dist/constants.cjs +2 -2
- package/dist/exports.cjs +2 -2
- package/dist/extractor/bundle.cjs +20 -39
- package/dist/extractor/bundleConfig.cjs +46 -46
- package/dist/extractor/createExtractor.cjs +39 -39
- package/dist/extractor/createLogger.cjs +1 -1
- package/dist/extractor/extractHelpers.cjs +1 -1
- package/dist/extractor/extractMediaStyle.cjs +7 -7
- package/dist/extractor/extractToClassNames.cjs +9 -9
- package/dist/extractor/extractToNative.cjs +7 -7
- package/dist/extractor/{getGuiConfigPathFromOptionsConfig.cjs → getHanzoguiConfigPathFromOptionsConfig.cjs} +5 -5
- package/dist/extractor/getPrefixLogs.cjs +1 -1
- package/dist/extractor/getStaticBindingsForScope.cjs +2 -2
- package/dist/extractor/{loadGui.cjs → loadHanzogui.cjs} +97 -141
- package/dist/extractor/regenerateConfig.cjs +20 -20
- package/dist/extractor/{watchGuiConfig.cjs → watchHanzoguiConfig.cjs} +15 -15
- package/dist/getPragmaOptions.cjs +6 -6
- package/dist/helpers/{requireGuiCore.cjs → requireHanzoguiCore.cjs} +12 -12
- package/dist/registerRequire.cjs +21 -21
- package/dist/worker.cjs +3 -3
- package/package.json +22 -22
- package/src/check-dep-versions.ts +1 -5
- package/src/checkDeps.ts +28 -30
- package/src/constants.ts +2 -2
- package/src/exports.ts +2 -2
- package/src/extractor/bundle.ts +11 -13
- package/src/extractor/bundleConfig.ts +57 -57
- package/src/extractor/createEvaluator.ts +2 -2
- package/src/extractor/createExtractor.ts +62 -55
- package/src/extractor/createLogger.ts +5 -3
- package/src/extractor/esbuildTsconfigPaths.ts +1 -1
- package/src/extractor/extractHelpers.ts +15 -12
- package/src/extractor/extractMediaStyle.ts +19 -13
- package/src/extractor/extractToClassNames.ts +11 -11
- package/src/extractor/extractToNative.ts +13 -13
- package/src/extractor/{getGuiConfigPathFromOptionsConfig.ts → getHanzoguiConfigPathFromOptionsConfig.ts} +3 -3
- package/src/extractor/getPrefixLogs.ts +3 -3
- package/src/extractor/getStaticBindingsForScope.ts +2 -2
- package/src/extractor/{loadGui.ts → loadHanzogui.ts} +86 -83
- package/src/extractor/regenerateConfig.ts +34 -24
- package/src/extractor/{watchGuiConfig.ts → watchHanzoguiConfig.ts} +10 -10
- package/src/getPragmaOptions.ts +6 -6
- package/src/helpers/requireHanzoguiCore.ts +28 -0
- package/src/registerRequire.ts +34 -36
- package/src/server.ts +2 -2
- package/src/types.ts +13 -10
- package/src/worker.ts +7 -7
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/constants.d.ts.map +1 -1
- package/types/exports.d.ts +2 -2
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +2 -2
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +12 -12
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createEvaluator.d.ts +2 -2
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +5 -5
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/createLogger.d.ts +2 -2
- package/types/extractor/createLogger.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +8 -8
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +4 -4
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +2 -2
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts +3 -3
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts +3 -0
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +2 -2
- package/types/extractor/getPrefixLogs.d.ts.map +1 -1
- package/types/extractor/loadHanzogui.d.ts +22 -0
- package/types/extractor/loadHanzogui.d.ts.map +1 -0
- package/types/extractor/regenerateConfig.d.ts +4 -4
- package/types/extractor/regenerateConfig.d.ts.map +1 -1
- package/types/extractor/watchHanzoguiConfig.d.ts +5 -0
- package/types/extractor/watchHanzoguiConfig.d.ts.map +1 -0
- package/types/helpers/requireHanzoguiCore.d.ts +3 -0
- package/types/helpers/requireHanzoguiCore.d.ts.map +1 -0
- package/types/registerRequire.d.ts +3 -3
- package/types/registerRequire.d.ts.map +1 -1
- package/types/server.d.ts +2 -2
- package/types/server.d.ts.map +1 -1
- package/types/types.d.ts +10 -10
- package/types/types.d.ts.map +1 -1
- package/types/worker.d.ts +4 -4
- package/types/worker.d.ts.map +1 -1
- package/src/helpers/requireGuiCore.ts +0 -28
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +0 -3
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +0 -1
- package/types/extractor/loadGui.d.ts +0 -22
- package/types/extractor/loadGui.d.ts.map +0 -1
- package/types/extractor/watchGuiConfig.d.ts +0 -5
- package/types/extractor/watchGuiConfig.d.ts.map +0 -1
- package/types/helpers/requireGuiCore.d.ts +0 -3
- package/types/helpers/requireGuiCore.d.ts.map +0 -1
|
@@ -45,14 +45,14 @@ var import_node_fs = require("node:fs");
|
|
|
45
45
|
var import_node_path = require("node:path");
|
|
46
46
|
var import_typescript = require("typescript");
|
|
47
47
|
var import_constants = require("../constants.cjs");
|
|
48
|
-
var
|
|
48
|
+
var import_requireHanzoguiCore = require("../helpers/requireHanzoguiCore.cjs");
|
|
49
49
|
var import_createEvaluator = require("./createEvaluator.cjs");
|
|
50
50
|
var import_evaluateAstNode = require("./evaluateAstNode.cjs");
|
|
51
51
|
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
52
52
|
var import_findTopmostFunction = require("./findTopmostFunction.cjs");
|
|
53
53
|
var import_getStaticBindingsForScope = require("./getStaticBindingsForScope.cjs");
|
|
54
54
|
var import_literalToAst = require("./literalToAst.cjs");
|
|
55
|
-
var
|
|
55
|
+
var import_loadHanzogui = require("./loadHanzogui.cjs");
|
|
56
56
|
var import_logLines = require("./logLines.cjs");
|
|
57
57
|
var import_normalizeTernaries = require("./normalizeTernaries.cjs");
|
|
58
58
|
var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
|
|
@@ -189,23 +189,23 @@ function createExtractor({
|
|
|
189
189
|
if (isFullyDisabled(props)) {
|
|
190
190
|
return null;
|
|
191
191
|
}
|
|
192
|
-
return projectInfo ||= (0,
|
|
192
|
+
return projectInfo ||= (0, import_loadHanzogui.loadHanzoguiSync)(props);
|
|
193
193
|
}
|
|
194
194
|
async function load(props) {
|
|
195
195
|
if (isFullyDisabled(props)) {
|
|
196
196
|
return null;
|
|
197
197
|
}
|
|
198
|
-
return projectInfo ||= await (0,
|
|
198
|
+
return projectInfo ||= await (0, import_loadHanzogui.loadHanzogui)(props);
|
|
199
199
|
}
|
|
200
200
|
return {
|
|
201
201
|
options: {
|
|
202
202
|
logger
|
|
203
203
|
},
|
|
204
204
|
cleanupBeforeExit: import_getStaticBindingsForScope.cleanupBeforeExit,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return projectInfo?.
|
|
205
|
+
loadHanzogui: load,
|
|
206
|
+
loadHanzoguiSync: loadSync,
|
|
207
|
+
getHanzogui() {
|
|
208
|
+
return projectInfo?.hanzoguiConfig;
|
|
209
209
|
},
|
|
210
210
|
parseSync: (f, props) => {
|
|
211
211
|
globalThis.expo ||= {};
|
|
@@ -220,10 +220,10 @@ function createExtractor({
|
|
|
220
220
|
};
|
|
221
221
|
function parseWithConfig({
|
|
222
222
|
components,
|
|
223
|
-
|
|
223
|
+
hanzoguiConfig
|
|
224
224
|
}, fileOrPath, options) {
|
|
225
225
|
const {
|
|
226
|
-
config = "
|
|
226
|
+
config = "hanzogui.config.ts",
|
|
227
227
|
importsWhitelist = ["constants.js"],
|
|
228
228
|
evaluateVars = true,
|
|
229
229
|
sourcePath = "",
|
|
@@ -246,7 +246,7 @@ function createExtractor({
|
|
|
246
246
|
dynamicComponentCache.delete(sourcePath);
|
|
247
247
|
styledCheckCache.delete(sourcePath);
|
|
248
248
|
}
|
|
249
|
-
if (sourcePath.includes(".
|
|
249
|
+
if (sourcePath.includes(".hanzogui-dynamic-eval")) {
|
|
250
250
|
return null;
|
|
251
251
|
}
|
|
252
252
|
const {
|
|
@@ -257,7 +257,7 @@ function createExtractor({
|
|
|
257
257
|
proxyThemeVariables,
|
|
258
258
|
getDefaultProps,
|
|
259
259
|
pseudoDescriptors
|
|
260
|
-
} = (0,
|
|
260
|
+
} = (0, import_requireHanzoguiCore.requireHanzoguiCore)(platform2);
|
|
261
261
|
let shouldPrintDebug = options.shouldPrintDebug || false;
|
|
262
262
|
if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
|
|
263
263
|
return null;
|
|
@@ -275,7 +275,7 @@ function createExtractor({
|
|
|
275
275
|
}
|
|
276
276
|
function isValidStyleKey(name, staticConfig) {
|
|
277
277
|
if (!projectInfo) {
|
|
278
|
-
throw new Error(`
|
|
278
|
+
throw new Error(`Hanzogui extractor not loaded yet`);
|
|
279
279
|
}
|
|
280
280
|
if (platform2 === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
|
|
281
281
|
return false;
|
|
@@ -291,7 +291,7 @@ function createExtractor({
|
|
|
291
291
|
}
|
|
292
292
|
return !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
|
|
293
293
|
// don't disable variants or else you lose many things flattening
|
|
294
|
-
staticConfig.variants?.[name] || projectInfo?.
|
|
294
|
+
staticConfig.variants?.[name] || projectInfo?.hanzoguiConfig?.shorthands[name]);
|
|
295
295
|
}
|
|
296
296
|
const isTargetingHTML = platform2 === "web";
|
|
297
297
|
const ogDebug = shouldPrintDebug;
|
|
@@ -306,16 +306,16 @@ function createExtractor({
|
|
|
306
306
|
if (shouldPrintDebug) {
|
|
307
307
|
logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" "));
|
|
308
308
|
}
|
|
309
|
-
if (process.env.DEBUG?.startsWith("
|
|
309
|
+
if (process.env.DEBUG?.startsWith("hanzogui")) {
|
|
310
310
|
logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join("\n"));
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
tm.mark("load-
|
|
313
|
+
tm.mark("load-hanzogui", !!shouldPrintDebug);
|
|
314
314
|
if (!isFullyDisabled(options)) {
|
|
315
|
-
if (!
|
|
316
|
-
console.error(`\u26D4\uFE0F Error: Missing "themes" in your
|
|
315
|
+
if (!hanzoguiConfig?.themes) {
|
|
316
|
+
console.error(`\u26D4\uFE0F Error: Missing "themes" in your hanzogui.config file:
|
|
317
317
|
|
|
318
|
-
You may not need the compiler! Remember you can run
|
|
318
|
+
You may not need the compiler! Remember you can run Hanzogui with no configuration at all.
|
|
319
319
|
|
|
320
320
|
You may have not "export default" your config (you can also "export const config").
|
|
321
321
|
|
|
@@ -323,15 +323,15 @@ function createExtractor({
|
|
|
323
323
|
- try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
|
|
324
324
|
- or search your lockfile for mis-matches.
|
|
325
325
|
`);
|
|
326
|
-
console.info(` Got config:`,
|
|
326
|
+
console.info(` Got config:`, hanzoguiConfig);
|
|
327
327
|
process.exit(0);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
const firstThemeName = Object.keys(
|
|
331
|
-
const firstTheme =
|
|
330
|
+
const firstThemeName = Object.keys(hanzoguiConfig?.themes || {})[0];
|
|
331
|
+
const firstTheme = hanzoguiConfig?.themes[firstThemeName] || {};
|
|
332
332
|
if (!firstTheme || typeof firstTheme !== "object") {
|
|
333
333
|
const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
|
|
334
|
-
console.info(err, `Got config:`,
|
|
334
|
+
console.info(err, `Got config:`, hanzoguiConfig);
|
|
335
335
|
console.info(`Looking for theme:`, firstThemeName);
|
|
336
336
|
throw new Error(err);
|
|
337
337
|
}
|
|
@@ -348,8 +348,8 @@ function createExtractor({
|
|
|
348
348
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
349
349
|
if (!isFullyDisabled(options)) {
|
|
350
350
|
if (Object.keys(components || []).length === 0) {
|
|
351
|
-
console.warn(`Warning:
|
|
352
|
-
if (process.env.DEBUG === "
|
|
351
|
+
console.warn(`Warning: Hanzogui didn't find any valid components (DEBUG=hanzogui for more)`);
|
|
352
|
+
if (process.env.DEBUG === "hanzogui") {
|
|
353
353
|
console.info(`components`, Object.keys(components || []), components);
|
|
354
354
|
}
|
|
355
355
|
}
|
|
@@ -477,7 +477,7 @@ function createExtractor({
|
|
|
477
477
|
if (shouldPrintDebug) {
|
|
478
478
|
logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
|
|
479
479
|
}
|
|
480
|
-
const out2 = (0,
|
|
480
|
+
const out2 = (0, import_loadHanzogui.loadHanzoguiSync)({
|
|
481
481
|
forceExports: true,
|
|
482
482
|
components: [sourcePath],
|
|
483
483
|
cacheKey: version
|
|
@@ -493,12 +493,12 @@ function createExtractor({
|
|
|
493
493
|
if (!out2.cached) {
|
|
494
494
|
const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
|
|
495
495
|
if (foundNames) {
|
|
496
|
-
(0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` |
|
|
496
|
+
(0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Hanzogui found dynamic components: ${foundNames}`);
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
} catch (err) {
|
|
500
500
|
if (shouldPrintDebug) {
|
|
501
|
-
logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=
|
|
501
|
+
logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=hanzogui for more)`);
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
}
|
|
@@ -627,7 +627,7 @@ function createExtractor({
|
|
|
627
627
|
} else if (!dynamicLoadingInProgress.has(resolved) && mightHaveStyledComponents(resolved)) {
|
|
628
628
|
dynamicLoadingInProgress.add(resolved);
|
|
629
629
|
try {
|
|
630
|
-
const out = (0,
|
|
630
|
+
const out = (0, import_loadHanzogui.loadHanzoguiSync)({
|
|
631
631
|
forceExports: true,
|
|
632
632
|
components: [resolved]
|
|
633
633
|
});
|
|
@@ -676,7 +676,7 @@ function createExtractor({
|
|
|
676
676
|
if (!component || !component.staticConfig) {
|
|
677
677
|
if (shouldPrintDebug) {
|
|
678
678
|
logger.info(`
|
|
679
|
-
- No
|
|
679
|
+
- No Hanzogui conf for: ${node.name.name}
|
|
680
680
|
`);
|
|
681
681
|
}
|
|
682
682
|
return;
|
|
@@ -1206,7 +1206,7 @@ function createExtractor({
|
|
|
1206
1206
|
// always de-opt animation these
|
|
1207
1207
|
"animation", "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? ["pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
|
|
1208
1208
|
// when using a non-CSS driver, de-opt on enterStyle/exitStyle
|
|
1209
|
-
...(
|
|
1209
|
+
...(hanzoguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
|
|
1210
1210
|
const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || []);
|
|
1211
1211
|
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
1212
1212
|
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
@@ -1237,7 +1237,7 @@ function createExtractor({
|
|
|
1237
1237
|
style: {},
|
|
1238
1238
|
theme: defaultTheme,
|
|
1239
1239
|
viewProps: defaultProps,
|
|
1240
|
-
conf:
|
|
1240
|
+
conf: hanzoguiConfig,
|
|
1241
1241
|
props: defaultProps,
|
|
1242
1242
|
componentState,
|
|
1243
1243
|
styleProps: {
|
|
@@ -1344,7 +1344,7 @@ function createExtractor({
|
|
|
1344
1344
|
if (!isValidStyleKey(key, staticConfig)) {
|
|
1345
1345
|
return [];
|
|
1346
1346
|
}
|
|
1347
|
-
const name =
|
|
1347
|
+
const name = hanzoguiConfig?.shorthands[key] || key;
|
|
1348
1348
|
if (value === void 0) {
|
|
1349
1349
|
logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
|
|
1350
1350
|
shouldDeopt = true;
|
|
@@ -1420,9 +1420,9 @@ function createExtractor({
|
|
|
1420
1420
|
attrs = attrs.filter(x => !(x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme"));
|
|
1421
1421
|
if (!hasImportedTheme) {
|
|
1422
1422
|
hasImportedTheme = true;
|
|
1423
|
-
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("
|
|
1423
|
+
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_HanzoguiTheme"), t.identifier("Theme"))], t.stringLiteral("@hanzogui/web")));
|
|
1424
1424
|
}
|
|
1425
|
-
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("
|
|
1425
|
+
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_HanzoguiTheme"), [t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)]), t.jsxClosingElement(t.jsxIdentifier("_HanzoguiTheme")), [traversePath.node]));
|
|
1426
1426
|
}
|
|
1427
1427
|
}
|
|
1428
1428
|
if (shouldPrintDebug) {
|
|
@@ -1515,7 +1515,7 @@ function createExtractor({
|
|
|
1515
1515
|
}
|
|
1516
1516
|
let key = Object.keys(cur.value)[0];
|
|
1517
1517
|
const value = cur.value[key];
|
|
1518
|
-
const fullKey =
|
|
1518
|
+
const fullKey = hanzoguiConfig?.shorthands[key];
|
|
1519
1519
|
if (fullKey) {
|
|
1520
1520
|
cur.value = {
|
|
1521
1521
|
[fullKey]: value
|
|
@@ -1783,7 +1783,7 @@ function createExtractor({
|
|
|
1783
1783
|
node,
|
|
1784
1784
|
lineNumbers,
|
|
1785
1785
|
filePath,
|
|
1786
|
-
config:
|
|
1786
|
+
config: hanzoguiConfig,
|
|
1787
1787
|
flatNodeName,
|
|
1788
1788
|
attemptEval,
|
|
1789
1789
|
jsxPath: traversePath,
|
|
@@ -1808,8 +1808,8 @@ function createExtractor({
|
|
|
1808
1808
|
} catch (err) {
|
|
1809
1809
|
node.attributes = ogAttributes;
|
|
1810
1810
|
if (!(err instanceof import_errors.BailOptimizationError)) {
|
|
1811
|
-
console.error(`@hanzogui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment
|
|
1812
|
-
if (process.env.
|
|
1811
|
+
console.error(`@hanzogui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`);
|
|
1812
|
+
if (process.env.TAMAGUI_DEBUG === "1") {
|
|
1813
1813
|
console.error(err.stack);
|
|
1814
1814
|
}
|
|
1815
1815
|
}
|
|
@@ -30,7 +30,7 @@ var import_getPrefixLogs = require("./getPrefixLogs.cjs");
|
|
|
30
30
|
function createLogger(sourcePath, options) {
|
|
31
31
|
const shouldLogTiming = options.logTimings ?? true;
|
|
32
32
|
const start = Date.now();
|
|
33
|
-
const mem = process.env.
|
|
33
|
+
const mem = process.env.TAMAGUI_SHOW_MEMORY_USAGE && shouldLogTiming ? process.memoryUsage() : null;
|
|
34
34
|
return res => {
|
|
35
35
|
if (!shouldLogTiming) {
|
|
36
36
|
return;
|
|
@@ -171,7 +171,7 @@ const isValidImport = (props, moduleName, componentName) => {
|
|
|
171
171
|
return Boolean(getValidImport(props, moduleName, componentName));
|
|
172
172
|
};
|
|
173
173
|
const getValidComponentPackages = (0, import_memoize.memoize)(props => {
|
|
174
|
-
return [... /* @__PURE__ */new Set(["@hanzogui/core", "
|
|
174
|
+
return [... /* @__PURE__ */new Set(["@hanzogui/core", "hanzogui", ...(props.components || [])])];
|
|
175
175
|
});
|
|
176
176
|
const getValidComponentsPaths = (0, import_memoize.memoize)(props => {
|
|
177
177
|
return getValidComponentPackages(props).flatMap(pkg => {
|
|
@@ -39,12 +39,12 @@ __export(extractMediaStyle_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(extractMediaStyle_exports);
|
|
40
40
|
var t = __toESM(require("@babel/types"));
|
|
41
41
|
var core = __toESM(require("@hanzogui/core"));
|
|
42
|
-
var
|
|
42
|
+
var import_requireHanzoguiCore = require("../helpers/requireHanzoguiCore.cjs");
|
|
43
43
|
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
44
|
-
function extractMediaStyle(props, ternary, jsxPath,
|
|
44
|
+
function extractMediaStyle(props, ternary, jsxPath, hanzoguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
|
|
45
45
|
const {
|
|
46
46
|
getCSSStylesAtomic
|
|
47
|
-
} = (0,
|
|
47
|
+
} = (0, import_requireHanzoguiCore.requireHanzoguiCore)("web");
|
|
48
48
|
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath);
|
|
49
49
|
if (!mt) {
|
|
50
50
|
return null;
|
|
@@ -52,9 +52,9 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
|
|
|
52
52
|
const {
|
|
53
53
|
key
|
|
54
54
|
} = mt;
|
|
55
|
-
const mq =
|
|
55
|
+
const mq = hanzoguiConfig.media[key];
|
|
56
56
|
if (!mq) {
|
|
57
|
-
console.error(`Media query "${key}" not found: ${Object.keys(
|
|
57
|
+
console.error(`Media query "${key}" not found: ${Object.keys(hanzoguiConfig.media)}`);
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
const getStyleObj = (styleObj, negate = false) => {
|
|
@@ -68,7 +68,7 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
|
|
|
68
68
|
console.info(" media query, no styles?");
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
-
const mediaKeys = Object.keys(
|
|
71
|
+
const mediaKeys = Object.keys(hanzoguiConfig.media);
|
|
72
72
|
const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
|
|
73
73
|
acc[cur] = new Array(importance + 1).fill(":root").join("");
|
|
74
74
|
return acc;
|
|
@@ -80,7 +80,7 @@ function extractMediaStyle(props, ternary, jsxPath, guiConfig, sourcePath, impor
|
|
|
80
80
|
} of styleOpts) {
|
|
81
81
|
const styles = getCSSStylesAtomic(styleObj);
|
|
82
82
|
const singleMediaStyles = styles.map(style => {
|
|
83
|
-
const mediaStyle = core.createMediaStyle(style, key,
|
|
83
|
+
const mediaStyle = core.createMediaStyle(style, key, hanzoguiConfig.media, true, negate);
|
|
84
84
|
const className = `.${mediaStyle[core.StyleObjectIdentifier]}`;
|
|
85
85
|
return {
|
|
86
86
|
...mediaStyle,
|
|
@@ -41,7 +41,7 @@ var t = __toESM(require("@babel/types"));
|
|
|
41
41
|
var import_web = require("@hanzogui/web");
|
|
42
42
|
var path = __toESM(require("node:path"));
|
|
43
43
|
var util = __toESM(require("node:util"));
|
|
44
|
-
var
|
|
44
|
+
var import_requireHanzoguiCore = require("../helpers/requireHanzoguiCore.cjs");
|
|
45
45
|
var import_babelParse = require("./babelParse.cjs");
|
|
46
46
|
var import_createLogger = require("./createLogger.cjs");
|
|
47
47
|
var import_extractMediaStyle = require("./extractMediaStyle.cjs");
|
|
@@ -63,7 +63,7 @@ async function extractToClassNames({
|
|
|
63
63
|
const {
|
|
64
64
|
getCSSStylesAtomic,
|
|
65
65
|
createMediaStyle
|
|
66
|
-
} = (0,
|
|
66
|
+
} = (0, import_requireHanzoguiCore.requireHanzoguiCore)("web");
|
|
67
67
|
if (sourcePath.includes("node_modules")) {
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
@@ -81,8 +81,8 @@ async function extractToClassNames({
|
|
|
81
81
|
if (!/.[tj]sx?$/i.test(sourcePath || "")) {
|
|
82
82
|
console.warn(`${sourcePath.slice(0, 100)} - bad filename.`);
|
|
83
83
|
}
|
|
84
|
-
if (!options.disableExtraction && !options["
|
|
85
|
-
await extractor.
|
|
84
|
+
if (!options.disableExtraction && !options["_disableLoadHanzogui"]) {
|
|
85
|
+
await extractor.loadHanzogui(options);
|
|
86
86
|
}
|
|
87
87
|
const printLog = (0, import_createLogger.createLogger)(sourcePath, options);
|
|
88
88
|
let ast;
|
|
@@ -94,7 +94,7 @@ async function extractToClassNames({
|
|
|
94
94
|
}
|
|
95
95
|
tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
|
|
96
96
|
const cssMap = /* @__PURE__ */new Map();
|
|
97
|
-
const
|
|
97
|
+
const hanzoguiConfig = extractor.getHanzogui();
|
|
98
98
|
const res = await extractor.parse(ast, {
|
|
99
99
|
shouldPrintDebug,
|
|
100
100
|
...options,
|
|
@@ -163,13 +163,13 @@ async function extractToClassNames({
|
|
|
163
163
|
const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
|
|
164
164
|
if (mediaTypeMatch) {
|
|
165
165
|
const mediaType = mediaTypeMatch[1];
|
|
166
|
-
const mediaStyle = createMediaStyle(style2, mediaName, extractor.
|
|
166
|
+
const mediaStyle = createMediaStyle(style2, mediaName, extractor.getHanzogui().media, mediaType, false, mediaStylesSeen);
|
|
167
167
|
const identifier2 = addStyle(mediaStyle);
|
|
168
168
|
classNames.push(identifier2);
|
|
169
169
|
continue;
|
|
170
170
|
}
|
|
171
|
-
if (mediaName in
|
|
172
|
-
const mediaStyle = createMediaStyle(style2, mediaName, extractor.
|
|
171
|
+
if (mediaName in hanzoguiConfig.media) {
|
|
172
|
+
const mediaStyle = createMediaStyle(style2, mediaName, extractor.getHanzogui().media, true, false, mediaStylesSeen);
|
|
173
173
|
const identifier2 = addStyle(mediaStyle);
|
|
174
174
|
classNames.push(identifier2);
|
|
175
175
|
continue;
|
|
@@ -213,7 +213,7 @@ async function extractToClassNames({
|
|
|
213
213
|
}
|
|
214
214
|
let ternary = attr.value;
|
|
215
215
|
if (ternary.inlineMediaQuery) {
|
|
216
|
-
const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.
|
|
216
|
+
const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.getHanzogui(), sourcePath || "", mediaStylesSeen++, shouldPrintDebug);
|
|
217
217
|
if (mediaExtraction) {
|
|
218
218
|
if (mediaExtraction.mediaStyles) {
|
|
219
219
|
mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, {
|
|
@@ -50,7 +50,7 @@ var import_createExtractor = require("./createExtractor.cjs");
|
|
|
50
50
|
var import_createLogger = require("./createLogger.cjs");
|
|
51
51
|
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
52
52
|
var import_literalToAst = require("./literalToAst.cjs");
|
|
53
|
-
var
|
|
53
|
+
var import_loadHanzogui = require("./loadHanzogui.cjs");
|
|
54
54
|
const importNativeView = (0, import_template.default)(`
|
|
55
55
|
const __ReactNativeView = require('react-native').View;
|
|
56
56
|
const __ReactNativeText = require('react-native').Text;
|
|
@@ -62,7 +62,7 @@ const importWithStyle = import_template.default.ast(`import { _withStableStyle }
|
|
|
62
62
|
const extractor = (0, import_createExtractor.createExtractor)({
|
|
63
63
|
platform: "native"
|
|
64
64
|
});
|
|
65
|
-
let
|
|
65
|
+
let hanzoguiBuildOptionsLoaded;
|
|
66
66
|
function extractToNative(sourceFileName, sourceCode, options) {
|
|
67
67
|
const ast = (0, import_parser.parse)(sourceCode, {
|
|
68
68
|
sourceType: "module",
|
|
@@ -88,7 +88,7 @@ function getBabelPlugin() {
|
|
|
88
88
|
}
|
|
89
89
|
function getBabelParseDefinition(options) {
|
|
90
90
|
return {
|
|
91
|
-
name: "
|
|
91
|
+
name: "hanzogui",
|
|
92
92
|
visitor: {
|
|
93
93
|
Program: {
|
|
94
94
|
enter(root) {
|
|
@@ -122,12 +122,12 @@ function getBabelParseDefinition(options) {
|
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
if (!options.config && !options.components) {
|
|
125
|
-
|
|
125
|
+
hanzoguiBuildOptionsLoaded ||= (0, import_loadHanzogui.loadHanzoguiBuildConfigSync)({});
|
|
126
126
|
}
|
|
127
127
|
const finalOptions = {
|
|
128
128
|
// @ts-ignore just in case they leave it out
|
|
129
129
|
platform: "native",
|
|
130
|
-
...
|
|
130
|
+
...hanzoguiBuildOptionsLoaded,
|
|
131
131
|
...options
|
|
132
132
|
};
|
|
133
133
|
const printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
|
|
@@ -306,7 +306,7 @@ function getBabelParseDefinition(options) {
|
|
|
306
306
|
if (message.includes("Unexpected return value from visitor method")) {
|
|
307
307
|
message = "Unexpected return value from visitor method";
|
|
308
308
|
}
|
|
309
|
-
console.warn("Error in
|
|
309
|
+
console.warn("Error in Hanzogui parse, skipping", message, err.stack);
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
@@ -336,7 +336,7 @@ function getBabelParseDefinition(options) {
|
|
|
336
336
|
}
|
|
337
337
|
function assertValidTag(node) {
|
|
338
338
|
if (node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style")) {
|
|
339
|
-
if (process.env.DEBUG?.startsWith("
|
|
339
|
+
if (process.env.DEBUG?.startsWith("hanzogui")) {
|
|
340
340
|
console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -20,14 +20,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
21
|
value: true
|
|
22
22
|
}), mod);
|
|
23
|
-
var
|
|
24
|
-
__export(
|
|
25
|
-
|
|
23
|
+
var getHanzoguiConfigPathFromOptionsConfig_exports = {};
|
|
24
|
+
__export(getHanzoguiConfigPathFromOptionsConfig_exports, {
|
|
25
|
+
getHanzoguiConfigPathFromOptionsConfig: () => getHanzoguiConfigPathFromOptionsConfig
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(getHanzoguiConfigPathFromOptionsConfig_exports);
|
|
28
28
|
var import_node_path = require("node:path");
|
|
29
29
|
var import_node_fs = require("node:fs");
|
|
30
|
-
function
|
|
30
|
+
function getHanzoguiConfigPathFromOptionsConfig(config) {
|
|
31
31
|
if ((0, import_node_path.isAbsolute)(config)) {
|
|
32
32
|
return config;
|
|
33
33
|
}
|
|
@@ -27,5 +27,5 @@ __export(getPrefixLogs_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(getPrefixLogs_exports);
|
|
28
28
|
var import_cli_color = require("@hanzogui/cli-color");
|
|
29
29
|
function getPrefixLogs(options) {
|
|
30
|
-
return options?.prefixLogs ?? ` \u{1F425} [
|
|
30
|
+
return options?.prefixLogs ?? ` \u{1F425} [hanzogui] ${(0, import_cli_color.colorString)(import_cli_color.Color.FgYellow, options?.platform || "web")}`;
|
|
31
31
|
}
|
|
@@ -141,8 +141,8 @@ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bind
|
|
|
141
141
|
}
|
|
142
142
|
} catch (err) {
|
|
143
143
|
if (shouldPrintDebug) {
|
|
144
|
-
console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=
|
|
145
|
-
} else if (process.env.DEBUG?.startsWith("
|
|
144
|
+
console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=hanzogui for more)`);
|
|
145
|
+
} else if (process.env.DEBUG?.startsWith("hanzogui")) {
|
|
146
146
|
console.info(`Error in partial evaluation`, err.message, err.stack);
|
|
147
147
|
}
|
|
148
148
|
}
|