@hanzogui/static 2.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/check-dep-versions.cjs +267 -0
- package/dist/checkDeps.cjs +200 -0
- package/dist/constants.cjs +49 -0
- package/dist/exports.cjs +44 -0
- package/dist/extractor/accessSafe.cjs +46 -0
- package/dist/extractor/babelParse.cjs +54 -0
- package/dist/extractor/buildClassName.cjs +62 -0
- package/dist/extractor/bundle.cjs +185 -0
- package/dist/extractor/bundleConfig.cjs +513 -0
- package/dist/extractor/concatClassName.cjs +80 -0
- package/dist/extractor/createEvaluator.cjs +75 -0
- package/dist/extractor/createExtractor.cjs +1150 -0
- package/dist/extractor/createLogger.cjs +45 -0
- package/dist/extractor/detectModuleFormat.cjs +49 -0
- package/dist/extractor/ensureImportingConcat.cjs +48 -0
- package/dist/extractor/errors.cjs +26 -0
- package/dist/extractor/esbuildAliasPlugin.cjs +44 -0
- package/dist/extractor/esbuildTsconfigPaths.cjs +86 -0
- package/dist/extractor/evaluateAstNode.cjs +83 -0
- package/dist/extractor/extractHelpers.cjs +119 -0
- package/dist/extractor/extractMediaStyle.cjs +128 -0
- package/dist/extractor/extractToClassNames.cjs +321 -0
- package/dist/extractor/extractToNative.cjs +266 -0
- package/dist/extractor/findTopmostFunction.cjs +34 -0
- package/dist/extractor/generatedUid.cjs +47 -0
- package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +35 -0
- package/dist/extractor/getPrefixLogs.cjs +29 -0
- package/dist/extractor/getPropValueFromAttributes.cjs +67 -0
- package/dist/extractor/getSourceModule.cjs +64 -0
- package/dist/extractor/getStaticBindingsForScope.cjs +150 -0
- package/dist/extractor/hoistClassNames.cjs +62 -0
- package/dist/extractor/literalToAst.cjs +84 -0
- package/dist/extractor/loadFile.cjs +11 -0
- package/dist/extractor/loadGui.cjs +322 -0
- package/dist/extractor/logLines.cjs +35 -0
- package/dist/extractor/normalizeTernaries.cjs +73 -0
- package/dist/extractor/propsToFontFamilyCache.cjs +38 -0
- package/dist/extractor/regenerateConfig.cjs +150 -0
- package/dist/extractor/removeUnusedHooks.cjs +76 -0
- package/dist/extractor/timer.cjs +43 -0
- package/dist/extractor/validHTMLAttributes.cjs +77 -0
- package/dist/extractor/watchGuiConfig.cjs +58 -0
- package/dist/getPragmaOptions.cjs +58 -0
- package/dist/helpers/memoize.cjs +37 -0
- package/dist/helpers/requireGuiCore.cjs +33 -0
- package/dist/index.cjs +40 -0
- package/dist/registerRequire.cjs +115 -0
- package/dist/server.cjs +75 -0
- package/dist/setup.cjs +0 -0
- package/dist/types.cjs +16 -0
- package/dist/worker.cjs +89 -0
- package/package.json +101 -0
- package/src/check-dep-versions.ts +738 -0
- package/src/checkDeps.ts +371 -0
- package/src/constants.ts +14 -0
- package/src/exports.ts +15 -0
- package/src/extractor/accessSafe.ts +22 -0
- package/src/extractor/babelParse.ts +37 -0
- package/src/extractor/buildClassName.ts +76 -0
- package/src/extractor/bundle.ts +277 -0
- package/src/extractor/bundleConfig.ts +958 -0
- package/src/extractor/concatClassName.ts +105 -0
- package/src/extractor/createEvaluator.ts +82 -0
- package/src/extractor/createExtractor.ts +2665 -0
- package/src/extractor/createLogger.ts +41 -0
- package/src/extractor/detectModuleFormat.ts +42 -0
- package/src/extractor/ensureImportingConcat.ts +36 -0
- package/src/extractor/errors.ts +1 -0
- package/src/extractor/esbuildAliasPlugin.ts +40 -0
- package/src/extractor/esbuildTsconfigPaths.ts +103 -0
- package/src/extractor/evaluateAstNode.ts +136 -0
- package/src/extractor/extractHelpers.ts +211 -0
- package/src/extractor/extractMediaStyle.ts +194 -0
- package/src/extractor/extractToClassNames.ts +631 -0
- package/src/extractor/extractToNative.ts +463 -0
- package/src/extractor/findTopmostFunction.ts +24 -0
- package/src/extractor/generatedUid.ts +41 -0
- package/src/extractor/getGuiConfigPathFromOptionsConfig.ts +24 -0
- package/src/extractor/getPrefixLogs.ts +9 -0
- package/src/extractor/getPropValueFromAttributes.ts +95 -0
- package/src/extractor/getSourceModule.ts +96 -0
- package/src/extractor/getStaticBindingsForScope.ts +237 -0
- package/src/extractor/hoistClassNames.ts +52 -0
- package/src/extractor/literalToAst.ts +85 -0
- package/src/extractor/loadFile.ts +17 -0
- package/src/extractor/loadGui.ts +487 -0
- package/src/extractor/logLines.ts +16 -0
- package/src/extractor/normalizeTernaries.ts +75 -0
- package/src/extractor/propsToFontFamilyCache.ts +18 -0
- package/src/extractor/regenerateConfig.ts +186 -0
- package/src/extractor/removeUnusedHooks.ts +83 -0
- package/src/extractor/timer.ts +25 -0
- package/src/extractor/validHTMLAttributes.ts +52 -0
- package/src/extractor/watchGuiConfig.ts +57 -0
- package/src/getPragmaOptions.ts +57 -0
- package/src/helpers/memoize.ts +24 -0
- package/src/helpers/requireGuiCore.ts +28 -0
- package/src/index.ts +4 -0
- package/src/registerRequire.ts +236 -0
- package/src/server.ts +43 -0
- package/src/setup.ts +0 -0
- package/src/types.ts +109 -0
- package/src/worker.ts +142 -0
- package/types/check-dep-versions.d.ts +37 -0
- package/types/check-dep-versions.d.ts.map +1 -0
- package/types/checkDeps.d.ts +19 -0
- package/types/checkDeps.d.ts.map +1 -0
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/exports.d.ts +16 -0
- package/types/exports.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +7 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/bundle.d.ts +121 -0
- package/types/extractor/bundle.d.ts.map +1 -0
- package/types/extractor/bundleConfig.d.ts +49 -0
- package/types/extractor/bundleConfig.d.ts.map +1 -0
- package/types/extractor/concatClassName.d.ts +8 -0
- package/types/extractor/concatClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +32 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/createLogger.d.ts +3 -0
- package/types/extractor/createLogger.d.ts.map +1 -0
- package/types/extractor/detectModuleFormat.d.ts +5 -0
- package/types/extractor/detectModuleFormat.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/errors.d.ts +3 -0
- package/types/extractor/errors.d.ts.map +1 -0
- package/types/extractor/esbuildAliasPlugin.d.ts +18 -0
- package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts +11 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +28 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +11 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +25 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/extractToNative.d.ts +13 -0
- package/types/extractor/extractToNative.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +3 -0
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +3 -0
- package/types/extractor/getPrefixLogs.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +19 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +5 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +4 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadFile.d.ts +1 -0
- package/types/extractor/loadFile.d.ts.map +1 -0
- package/types/extractor/loadGui.d.ts +22 -0
- package/types/extractor/loadGui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/propsToFontFamilyCache.d.ts +4 -0
- package/types/extractor/propsToFontFamilyCache.d.ts.map +1 -0
- package/types/extractor/regenerateConfig.d.ts +9 -0
- package/types/extractor/regenerateConfig.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/extractor/timer.d.ts +5 -0
- package/types/extractor/timer.d.ts.map +1 -0
- package/types/extractor/validHTMLAttributes.d.ts +52 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
- package/types/extractor/watchGuiConfig.d.ts +5 -0
- package/types/extractor/watchGuiConfig.d.ts.map +1 -0
- package/types/getPragmaOptions.d.ts +8 -0
- package/types/getPragmaOptions.d.ts.map +1 -0
- package/types/helpers/memoize.d.ts +8 -0
- package/types/helpers/memoize.d.ts.map +1 -0
- package/types/helpers/requireGuiCore.d.ts +3 -0
- package/types/helpers/requireGuiCore.d.ts.map +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/registerRequire.d.ts +10 -0
- package/types/registerRequire.d.ts.map +1 -0
- package/types/server.d.ts +3 -0
- package/types/server.d.ts.map +1 -0
- package/types/setup.d.ts +1 -0
- package/types/setup.d.ts.map +1 -0
- package/types/types.d.ts +92 -0
- package/types/types.d.ts.map +1 -0
- package/types/worker.d.ts +46 -0
- package/types/worker.d.ts.map +1 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var bundleConfig_exports = {};
|
|
33
|
+
__export(bundleConfig_exports, {
|
|
34
|
+
bundleConfig: () => bundleConfig,
|
|
35
|
+
esbuildOptions: () => esbuildOptions,
|
|
36
|
+
esbuildOptionsWithPlugins: () => esbuildOptionsWithPlugins,
|
|
37
|
+
getBundledConfig: () => getBundledConfig,
|
|
38
|
+
getLoadedConfig: () => getLoadedConfig,
|
|
39
|
+
hasBundledConfigChanged: () => hasBundledConfigChanged,
|
|
40
|
+
loadComponents: () => loadComponents,
|
|
41
|
+
loadComponentsInner: () => loadComponentsInner,
|
|
42
|
+
loadComponentsInnerSync: () => loadComponentsInnerSync,
|
|
43
|
+
loadComponentsSync: () => loadComponentsSync,
|
|
44
|
+
writeGuiCSS: () => writeGuiCSS
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(bundleConfig_exports);
|
|
47
|
+
var import_generator = __toESM(require("@babel/generator")),
|
|
48
|
+
import_traverse = __toESM(require("@babel/traverse")),
|
|
49
|
+
t = __toESM(require("@babel/types")),
|
|
50
|
+
import_node_crypto = require("node:crypto"),
|
|
51
|
+
import_node_fs = require("node:fs"),
|
|
52
|
+
import_node_path = require("node:path"),
|
|
53
|
+
import_node_url = require("node:url"),
|
|
54
|
+
import_cli_color = require("@hanzogui/cli-color"),
|
|
55
|
+
import_esbuild = __toESM(require("esbuild")),
|
|
56
|
+
FS = __toESM(require("fs-extra")),
|
|
57
|
+
import_promises = require("node:fs/promises"),
|
|
58
|
+
import_registerRequire = require("../registerRequire.cjs"),
|
|
59
|
+
import_babelParse = require("./babelParse.cjs"),
|
|
60
|
+
import_bundle = require("./bundle.cjs"),
|
|
61
|
+
import_getGuiConfigPathFromOptionsConfig = require("./getGuiConfigPathFromOptionsConfig.cjs"),
|
|
62
|
+
import_requireGuiCore = require("../helpers/requireGuiCore.cjs"),
|
|
63
|
+
import_detectModuleFormat = require("./detectModuleFormat.cjs");
|
|
64
|
+
const activeTempFiles = /* @__PURE__ */new Set();
|
|
65
|
+
function getDynamicEvalOutfile(name, format, contents) {
|
|
66
|
+
const ext = format === "esm" ? "mjs" : "cjs",
|
|
67
|
+
hash = (0, import_node_crypto.createHash)("sha1").update(name).update("\0").update(format).update("\0").update(contents).digest("hex").slice(0, 10);
|
|
68
|
+
return (0, import_node_path.join)(process.cwd(), ".gui", `dynamic-eval-${hash}-${(0, import_node_path.basename)(name)}.${ext}`);
|
|
69
|
+
}
|
|
70
|
+
function getEsbuildStdinLoader(filePath) {
|
|
71
|
+
return filePath.endsWith(".tsx") ? "tsx" : filePath.endsWith(".ts") ? "ts" : filePath.endsWith(".jsx") ? "jsx" : "js";
|
|
72
|
+
}
|
|
73
|
+
function resolvePackageEntry(packageName, format) {
|
|
74
|
+
if (format === "cjs") return require.resolve(packageName);
|
|
75
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`),
|
|
76
|
+
packageJson = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf-8")),
|
|
77
|
+
packageRoot = (0, import_node_path.dirname)(packageJsonPath),
|
|
78
|
+
exportEntry = packageJson.exports?.["."],
|
|
79
|
+
esmEntry = exportEntry?.import || exportEntry?.module || exportEntry?.browser || packageJson.module;
|
|
80
|
+
return typeof esmEntry == "string" ? (0, import_node_path.join)(packageRoot, esmEntry) : require.resolve(packageName);
|
|
81
|
+
}
|
|
82
|
+
function cleanupTempFiles() {
|
|
83
|
+
for (const f of activeTempFiles) try {
|
|
84
|
+
(0, import_node_fs.unlinkSync)(f);
|
|
85
|
+
} catch {}
|
|
86
|
+
activeTempFiles.clear();
|
|
87
|
+
}
|
|
88
|
+
process.on("exit", cleanupTempFiles);
|
|
89
|
+
process.on("SIGINT", () => {
|
|
90
|
+
cleanupTempFiles(), process.exit();
|
|
91
|
+
});
|
|
92
|
+
process.on("SIGTERM", () => {
|
|
93
|
+
cleanupTempFiles(), process.exit();
|
|
94
|
+
});
|
|
95
|
+
const external = ["@hanzogui/core", "@hanzogui/web", "react", "react-dom", "react-native-svg"],
|
|
96
|
+
esbuildExtraOptions = {
|
|
97
|
+
define: {
|
|
98
|
+
__DEV__: `${process.env.NODE_ENV === "development"}`
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
handleEsmFeaturesPlugin = {
|
|
102
|
+
name: "handle-esm-features",
|
|
103
|
+
setup(build) {
|
|
104
|
+
const isCjs = build.initialOptions.format === "cjs" || !build.initialOptions.format;
|
|
105
|
+
build.onLoad({
|
|
106
|
+
filter: /\.(ts|tsx|js|jsx|mjs)$/
|
|
107
|
+
}, args => {
|
|
108
|
+
if (!isCjs || args.path.includes("node_modules") && !args.path.includes("@gui")) return null;
|
|
109
|
+
let contents = (0, import_node_fs.readFileSync)(args.path, "utf8"),
|
|
110
|
+
modified = !1;
|
|
111
|
+
return contents.includes("import.meta.env") && (contents = contents.replace(/import\.meta\.env/g, "process.env"), modified = !0), contents.includes("import.meta.url") && (contents = contents.replace(/import\.meta\.url/g, '""'), modified = !0), contents.includes("import.meta.main") && (contents = contents.replace(/import\.meta\.main/g, "false"), modified = !0), /^\s*(?:const|let|var|export)\s+[^=]*=\s*await\b/m.test(contents) || /^await\s/m.test(contents) ? (process.env.DEBUG?.startsWith("@hanzo/gui") && console.info(`[hanzo-gui] stubbing file with top-level await: ${args.path}`), {
|
|
112
|
+
contents: `// stubbed - contains top-level await
|
|
113
|
+
module.exports = {}`,
|
|
114
|
+
loader: "js"
|
|
115
|
+
}) : modified ? {
|
|
116
|
+
contents,
|
|
117
|
+
loader: args.path.endsWith(".tsx") ? "tsx" : args.path.endsWith(".ts") ? "ts" : args.path.endsWith(".jsx") ? "jsx" : "js"
|
|
118
|
+
} : null;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
esbuildTransformOptions = {
|
|
123
|
+
target: "es2022",
|
|
124
|
+
format: "cjs",
|
|
125
|
+
jsx: "automatic",
|
|
126
|
+
platform: "node",
|
|
127
|
+
...esbuildExtraOptions
|
|
128
|
+
},
|
|
129
|
+
esbuildOptions = {
|
|
130
|
+
...esbuildTransformOptions
|
|
131
|
+
},
|
|
132
|
+
esbuildOptionsWithPlugins = {
|
|
133
|
+
...esbuildTransformOptions,
|
|
134
|
+
plugins: [handleEsmFeaturesPlugin]
|
|
135
|
+
};
|
|
136
|
+
let currentBundle = null,
|
|
137
|
+
isBundling = !1,
|
|
138
|
+
lastBundle = null;
|
|
139
|
+
const waitForBundle = /* @__PURE__ */new Set();
|
|
140
|
+
function hasBundledConfigChanged() {
|
|
141
|
+
return lastBundle === currentBundle ? !1 : (lastBundle = currentBundle, !0);
|
|
142
|
+
}
|
|
143
|
+
let loadedConfig = null;
|
|
144
|
+
const getLoadedConfig = () => loadedConfig;
|
|
145
|
+
async function getBundledConfig(props, rebuild = !1) {
|
|
146
|
+
if (isBundling) await new Promise(res => {
|
|
147
|
+
waitForBundle.add(res);
|
|
148
|
+
});else if (!currentBundle || rebuild) return await bundleConfig(props);
|
|
149
|
+
return currentBundle;
|
|
150
|
+
}
|
|
151
|
+
global.guiLastLoaded ||= 0;
|
|
152
|
+
function updateLastLoaded(config) {
|
|
153
|
+
global.guiLastLoaded = Date.now(), global.guiLastBundledConfig = config;
|
|
154
|
+
}
|
|
155
|
+
let hasBundledOnce = !1,
|
|
156
|
+
hasLoggedBuild = !1;
|
|
157
|
+
async function bundleConfig(props) {
|
|
158
|
+
if (global.guiLastBundledConfig && Date.now() - global.guiLastLoaded < 3e3) return global.guiLastBundledConfig;
|
|
159
|
+
try {
|
|
160
|
+
isBundling = !0;
|
|
161
|
+
const configEntry = props.config ? (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(props.config) : "",
|
|
162
|
+
tmpDir = (0, import_node_path.join)(process.cwd(), ".gui"),
|
|
163
|
+
configFormat = configEntry ? (0, import_detectModuleFormat.detectModuleFormat)(configEntry) : "cjs",
|
|
164
|
+
configOutPath = (0, import_node_path.join)(tmpDir, `gui.config${configFormat === "esm" ? ".mjs" : ".cjs"}`),
|
|
165
|
+
baseComponents = (props.components || []).filter(x => x !== "@hanzogui/core"),
|
|
166
|
+
componentFormats = baseComponents.map(mod => {
|
|
167
|
+
try {
|
|
168
|
+
const pkgJson = require.resolve(mod + "/package.json");
|
|
169
|
+
return JSON.parse((0, import_node_fs.readFileSync)(pkgJson, "utf-8")).type === "module" ? "esm" : "cjs";
|
|
170
|
+
} catch {
|
|
171
|
+
return "cjs";
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
componentOutPaths = baseComponents.map((componentModule, i) => {
|
|
175
|
+
const ext = componentFormats[i] === "esm" ? ".mjs" : ".cjs";
|
|
176
|
+
return (0, import_node_path.join)(tmpDir, `${componentModule.split(import_node_path.sep).join("-").replace(/[^a-z0-9]+/gi, "")}-components.config${ext}`);
|
|
177
|
+
});
|
|
178
|
+
process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Building config entry", configEntry);
|
|
179
|
+
let shouldBuild = !props.disableInitialBuild;
|
|
180
|
+
if (shouldBuild && props.config) {
|
|
181
|
+
const allOutFiles = [configOutPath, ...componentOutPaths];
|
|
182
|
+
try {
|
|
183
|
+
(await Promise.all(allOutFiles.map(f => FS.stat(f).catch(() => null)))).every(s => s !== null && Date.now() - s.mtimeMs < 3e3) && (shouldBuild = !1);
|
|
184
|
+
} catch {}
|
|
185
|
+
}
|
|
186
|
+
if (shouldBuild) {
|
|
187
|
+
try {
|
|
188
|
+
await FS.ensureDir(tmpDir);
|
|
189
|
+
} catch {}
|
|
190
|
+
const start = Date.now();
|
|
191
|
+
await Promise.all([props.config ? (0, import_bundle.esbundleGuiConfig)({
|
|
192
|
+
entryPoints: [configEntry],
|
|
193
|
+
external,
|
|
194
|
+
outfile: configOutPath,
|
|
195
|
+
target: "node24",
|
|
196
|
+
format: configFormat,
|
|
197
|
+
...esbuildExtraOptions
|
|
198
|
+
}, props.platform || "web") : null, ...baseComponents.map((componentModule, i) => (0, import_bundle.esbundleGuiConfig)({
|
|
199
|
+
entryPoints: [componentModule],
|
|
200
|
+
resolvePlatformSpecificEntries: !0,
|
|
201
|
+
external,
|
|
202
|
+
outfile: componentOutPaths[i],
|
|
203
|
+
target: "node24",
|
|
204
|
+
format: componentFormats[i],
|
|
205
|
+
...esbuildExtraOptions
|
|
206
|
+
}, props.platform || "web"))]), !hasLoggedBuild && !props._skipBuildLog && (hasLoggedBuild = !0, (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, `
|
|
207
|
+
\u27A1 [hanzo-gui] built config, components, prompt (${Date.now() - start}ms)`), process.env.DEBUG?.startsWith("@hanzo/gui") && (0, import_cli_color.colorLog)(import_cli_color.Color.Dim, `
|
|
208
|
+
Config .${import_node_path.sep}${(0, import_node_path.relative)(process.cwd(), configOutPath)}
|
|
209
|
+
Components ${componentOutPaths.map(p => `.${import_node_path.sep}${(0, import_node_path.relative)(process.cwd(), p)}`).join(`
|
|
210
|
+
`)}
|
|
211
|
+
`));
|
|
212
|
+
}
|
|
213
|
+
if (hasBundledOnce) {
|
|
214
|
+
try {
|
|
215
|
+
delete require.cache[require.resolve(configOutPath)];
|
|
216
|
+
} catch {}
|
|
217
|
+
for (const p of componentOutPaths) try {
|
|
218
|
+
delete require.cache[require.resolve(p)];
|
|
219
|
+
} catch {}
|
|
220
|
+
} else hasBundledOnce = !0;
|
|
221
|
+
let out;
|
|
222
|
+
configFormat === "esm" ? out = await import((0, import_node_url.pathToFileURL)(configOutPath).href) : out = require(configOutPath);
|
|
223
|
+
let config = out.default || out || out.config;
|
|
224
|
+
if (config && config.config && !config.tokens && (config = config.config), !config) throw new Error(`No config: ${config}`);
|
|
225
|
+
if (config._isProxyWorm) throw new Error("Got a proxied config - likely a module loading error. Set DEBUG=hanzo-gui for details.");
|
|
226
|
+
if (loadedConfig = config, !config.parsed) {
|
|
227
|
+
const {
|
|
228
|
+
createGui
|
|
229
|
+
} = (0, import_requireGuiCore.requireGuiCore)(props.platform || "web");
|
|
230
|
+
config = createGui(config);
|
|
231
|
+
}
|
|
232
|
+
props.outputCSS && (await writeGuiCSS(props.outputCSS, config));
|
|
233
|
+
let components = await loadComponents({
|
|
234
|
+
...props,
|
|
235
|
+
components: componentOutPaths
|
|
236
|
+
});
|
|
237
|
+
if (!components) throw new Error(`No components found: ${componentOutPaths.join(", ")}`);
|
|
238
|
+
for (const component of components) component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)] || component.moduleName, component.moduleName || (process.env.DEBUG?.includes("@hanzo/gui") || process.env.IS_HANZO_GUI_DEV) && console.warn(`\u26A0\uFE0F no module name found: ${component.moduleName} ${JSON.stringify(baseComponents)} in ${JSON.stringify(componentOutPaths)}`);
|
|
239
|
+
process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Loaded components", components);
|
|
240
|
+
const res = {
|
|
241
|
+
components,
|
|
242
|
+
nameToPaths: {},
|
|
243
|
+
guiConfig: config
|
|
244
|
+
};
|
|
245
|
+
return currentBundle = res, updateLastLoaded(res), res;
|
|
246
|
+
} catch (err) {
|
|
247
|
+
console.error(`Error bundling gui config: ${err?.message} (run with DEBUG=hanzo-gui to see stack)`), process.env.DEBUG?.includes("@hanzo/gui") && console.error(err.stack);
|
|
248
|
+
} finally {
|
|
249
|
+
isBundling = !1, waitForBundle.forEach(cb => cb()), waitForBundle.clear();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async function writeGuiCSS(outputCSS, config) {
|
|
253
|
+
const flush = async () => {
|
|
254
|
+
(0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` \u27A1 [hanzo-gui] output css: ${outputCSS}`), await FS.writeFile(outputCSS, css);
|
|
255
|
+
},
|
|
256
|
+
css = config.getCSS();
|
|
257
|
+
if (typeof css != "string") throw new Error(`Invalid CSS: ${typeof css} ${css}`);
|
|
258
|
+
try {
|
|
259
|
+
(0, import_node_fs.existsSync)(outputCSS) && (await (0, import_promises.readFile)(outputCSS, "utf8")) === css || (await flush());
|
|
260
|
+
} catch (err) {
|
|
261
|
+
console.info("Error writing themes", err);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function loadComponents(props, forceExports = !1) {
|
|
265
|
+
const coreComponents = getCoreComponentsSync(props),
|
|
266
|
+
otherComponents = await loadComponentsInner(props, forceExports);
|
|
267
|
+
return [...coreComponents, ...(otherComponents || [])];
|
|
268
|
+
}
|
|
269
|
+
function loadComponentsSync(props, forceExports = !1) {
|
|
270
|
+
const coreComponents = getCoreComponentsSync(props),
|
|
271
|
+
otherComponents = loadComponentsInnerSync(props, forceExports);
|
|
272
|
+
return [...coreComponents, ...(otherComponents || [])];
|
|
273
|
+
}
|
|
274
|
+
function getCoreComponentsSync(props) {
|
|
275
|
+
const loaded = loadComponentsInnerSync({
|
|
276
|
+
...props,
|
|
277
|
+
components: ["@hanzogui/core"]
|
|
278
|
+
});
|
|
279
|
+
if (!loaded) throw new Error("Core should always load");
|
|
280
|
+
return [{
|
|
281
|
+
...loaded[0],
|
|
282
|
+
moduleName: "@hanzogui/core"
|
|
283
|
+
}];
|
|
284
|
+
}
|
|
285
|
+
async function loadComponentsInner(props, forceExports = !1) {
|
|
286
|
+
const componentsModules = props.components || [],
|
|
287
|
+
key = componentsModules.join("\0");
|
|
288
|
+
if (!forceExports && cacheComponents[key]) return cacheComponents[key];
|
|
289
|
+
const {
|
|
290
|
+
unregister
|
|
291
|
+
} = (0, import_registerRequire.registerRequire)(props.platform || "web", {
|
|
292
|
+
proxyWormImports: forceExports
|
|
293
|
+
});
|
|
294
|
+
try {
|
|
295
|
+
const results = [];
|
|
296
|
+
for (const name of componentsModules) {
|
|
297
|
+
const isLocal = !!(0, import_node_path.extname)(name),
|
|
298
|
+
isDynamic = isLocal && forceExports,
|
|
299
|
+
format = isLocal ? (0, import_detectModuleFormat.detectModuleFormat)(name) : "cjs",
|
|
300
|
+
fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
|
|
301
|
+
let loadModule = name,
|
|
302
|
+
writtenContents = fileContents,
|
|
303
|
+
didBabel = !1;
|
|
304
|
+
const attemptLoad = async ({
|
|
305
|
+
forceExports: forceExports2 = !1
|
|
306
|
+
} = {}) => {
|
|
307
|
+
isDynamic && (writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents, loadModule = getDynamicEvalOutfile(name, format, writtenContents), FS.ensureDirSync((0, import_node_path.dirname)(loadModule)), activeTempFiles.add(loadModule), await import_esbuild.default.build({
|
|
308
|
+
...esbuildOptionsWithPlugins,
|
|
309
|
+
format,
|
|
310
|
+
outfile: loadModule,
|
|
311
|
+
stdin: {
|
|
312
|
+
contents: writtenContents,
|
|
313
|
+
resolveDir: (0, import_node_path.dirname)(name),
|
|
314
|
+
sourcefile: name,
|
|
315
|
+
loader: getEsbuildStdinLoader(name)
|
|
316
|
+
},
|
|
317
|
+
alias: {
|
|
318
|
+
"react-native": resolvePackageEntry("@hanzogui/react-native-web-lite", format),
|
|
319
|
+
"@hanzogui/react-native-web-lite": resolvePackageEntry("@hanzogui/react-native-web-lite", format),
|
|
320
|
+
"@hanzogui/react-native-web-internals": resolvePackageEntry("@hanzogui/react-native-web-internals", format)
|
|
321
|
+
},
|
|
322
|
+
bundle: !0,
|
|
323
|
+
packages: "external",
|
|
324
|
+
allowOverwrite: !0,
|
|
325
|
+
sourcemap: !1,
|
|
326
|
+
loader: import_bundle.esbuildLoaderConfig
|
|
327
|
+
})), process.env.DEBUG === "@hanzo/gui" && console.info("loadModule", loadModule, format);
|
|
328
|
+
let moduleResult;
|
|
329
|
+
format === "esm" ? moduleResult = await import((0, import_node_url.pathToFileURL)(loadModule).href) : moduleResult = require(loadModule), forceExports2 || (0, import_registerRequire.setRequireResult)(name, moduleResult);
|
|
330
|
+
const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
|
|
331
|
+
return {
|
|
332
|
+
moduleName: name,
|
|
333
|
+
nameToInfo
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
dispose = () => {
|
|
337
|
+
isDynamic && (FS.removeSync(loadModule), activeTempFiles.delete(loadModule));
|
|
338
|
+
};
|
|
339
|
+
let loaded;
|
|
340
|
+
try {
|
|
341
|
+
loaded = await attemptLoad({
|
|
342
|
+
forceExports: !0
|
|
343
|
+
}), didBabel = !0;
|
|
344
|
+
} catch (err) {
|
|
345
|
+
console.info("babel err", err, writtenContents), writtenContents = fileContents, process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Error parsing babel likely", err);
|
|
346
|
+
try {
|
|
347
|
+
loaded = await attemptLoad({
|
|
348
|
+
forceExports: !1
|
|
349
|
+
});
|
|
350
|
+
} catch (err2) {
|
|
351
|
+
process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.info(`
|
|
352
|
+
Gui attempted but failed to dynamically optimize components in:
|
|
353
|
+
${name}
|
|
354
|
+
`), console.info(err2), console.info(`At: ${loadModule}`, `
|
|
355
|
+
didBabel: ${didBabel}`, `
|
|
356
|
+
In:`, writtenContents, `
|
|
357
|
+
isDynamic: `, isDynamic)), loaded = [];
|
|
358
|
+
}
|
|
359
|
+
} finally {
|
|
360
|
+
dispose();
|
|
361
|
+
}
|
|
362
|
+
Array.isArray(loaded) ? results.push(...loaded) : loaded && results.push(loaded);
|
|
363
|
+
}
|
|
364
|
+
return cacheComponents[key] = results, results;
|
|
365
|
+
} catch (err) {
|
|
366
|
+
return console.info("Gui error bundling components", err.message, err.stack), null;
|
|
367
|
+
} finally {
|
|
368
|
+
unregister();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function loadComponentsInnerSync(props, forceExports = !1) {
|
|
372
|
+
const componentsModules = props.components || [],
|
|
373
|
+
key = componentsModules.join("\0");
|
|
374
|
+
if (!forceExports && cacheComponents[key]) return cacheComponents[key];
|
|
375
|
+
const {
|
|
376
|
+
unregister
|
|
377
|
+
} = (0, import_registerRequire.registerRequire)(props.platform || "web", {
|
|
378
|
+
proxyWormImports: forceExports
|
|
379
|
+
});
|
|
380
|
+
try {
|
|
381
|
+
const info = componentsModules.flatMap(name => {
|
|
382
|
+
const isDynamic = !!(0, import_node_path.extname)(name) && forceExports,
|
|
383
|
+
fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
|
|
384
|
+
let loadModule = name,
|
|
385
|
+
writtenContents = fileContents,
|
|
386
|
+
didBabel = !1;
|
|
387
|
+
function attemptLoad({
|
|
388
|
+
forceExports: forceExports2 = !1
|
|
389
|
+
} = {}) {
|
|
390
|
+
isDynamic && (writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents, loadModule = getDynamicEvalOutfile(name, "cjs", writtenContents), FS.ensureDirSync((0, import_node_path.dirname)(loadModule)), activeTempFiles.add(loadModule), import_esbuild.default.buildSync({
|
|
391
|
+
...esbuildOptions,
|
|
392
|
+
outfile: loadModule,
|
|
393
|
+
stdin: {
|
|
394
|
+
contents: writtenContents,
|
|
395
|
+
resolveDir: (0, import_node_path.dirname)(name),
|
|
396
|
+
sourcefile: name,
|
|
397
|
+
loader: getEsbuildStdinLoader(name)
|
|
398
|
+
},
|
|
399
|
+
alias: {
|
|
400
|
+
"react-native": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
|
|
401
|
+
"@hanzogui/react-native-web-lite": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
|
|
402
|
+
"@hanzogui/react-native-web-internals": resolvePackageEntry("@hanzogui/react-native-web-internals", "esm")
|
|
403
|
+
},
|
|
404
|
+
bundle: !0,
|
|
405
|
+
packages: "external",
|
|
406
|
+
allowOverwrite: !0,
|
|
407
|
+
sourcemap: !1,
|
|
408
|
+
loader: import_bundle.esbuildLoaderConfig
|
|
409
|
+
})), process.env.DEBUG === "@hanzo/gui" && console.info("loadModule", loadModule, require.resolve(loadModule));
|
|
410
|
+
const moduleResult = require(loadModule);
|
|
411
|
+
forceExports2 || (0, import_registerRequire.setRequireResult)(name, moduleResult);
|
|
412
|
+
const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
|
|
413
|
+
return {
|
|
414
|
+
moduleName: name,
|
|
415
|
+
nameToInfo
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const dispose = () => {
|
|
419
|
+
isDynamic && (FS.removeSync(loadModule), activeTempFiles.delete(loadModule));
|
|
420
|
+
};
|
|
421
|
+
try {
|
|
422
|
+
const res = attemptLoad({
|
|
423
|
+
forceExports: !0
|
|
424
|
+
});
|
|
425
|
+
return didBabel = !0, res;
|
|
426
|
+
} catch (err) {
|
|
427
|
+
console.info("babel err", err, writtenContents), writtenContents = fileContents, process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Error parsing babel likely", err);
|
|
428
|
+
} finally {
|
|
429
|
+
dispose();
|
|
430
|
+
}
|
|
431
|
+
try {
|
|
432
|
+
return attemptLoad({
|
|
433
|
+
forceExports: !1
|
|
434
|
+
});
|
|
435
|
+
} catch (err) {
|
|
436
|
+
return process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.info(`
|
|
437
|
+
Gui attempted but failed to dynamically optimize components in:
|
|
438
|
+
${name}
|
|
439
|
+
`), console.info(err), console.info(`At: ${loadModule}`, `
|
|
440
|
+
didBabel: ${didBabel}`, `
|
|
441
|
+
In:`, writtenContents, `
|
|
442
|
+
isDynamic: `, isDynamic)), [];
|
|
443
|
+
} finally {
|
|
444
|
+
dispose();
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
return cacheComponents[key] = info, info;
|
|
448
|
+
} catch (err) {
|
|
449
|
+
return console.info("Gui error bundling components", err.message, err.stack), null;
|
|
450
|
+
} finally {
|
|
451
|
+
unregister();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const esbuildit = (src, target) => import_esbuild.default.transformSync(src, {
|
|
455
|
+
...esbuildTransformOptions,
|
|
456
|
+
...(target === "modern" && {
|
|
457
|
+
target: "es2022",
|
|
458
|
+
jsx: "automatic",
|
|
459
|
+
loader: "tsx",
|
|
460
|
+
platform: "neutral",
|
|
461
|
+
format: "esm"
|
|
462
|
+
})
|
|
463
|
+
}).code;
|
|
464
|
+
function getComponentStaticConfigByName(name, exported) {
|
|
465
|
+
const components = {};
|
|
466
|
+
try {
|
|
467
|
+
if (!exported || typeof exported != "object" || Array.isArray(exported)) throw new Error(`Invalid export from package ${name}: ${typeof exported}`);
|
|
468
|
+
for (const key in exported) {
|
|
469
|
+
const found = getGuiComponent(key, exported[key]);
|
|
470
|
+
if (found) {
|
|
471
|
+
const {
|
|
472
|
+
Component,
|
|
473
|
+
...sc
|
|
474
|
+
} = found.staticConfig;
|
|
475
|
+
components[key] = {
|
|
476
|
+
staticConfig: sc
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
} catch (err) {
|
|
481
|
+
process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.error(`Gui failed getting components from ${name} (Disable error by setting environment variable HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD=1)`), console.error(err));
|
|
482
|
+
}
|
|
483
|
+
return components;
|
|
484
|
+
}
|
|
485
|
+
function getGuiComponent(name, Component) {
|
|
486
|
+
if (name[0].toUpperCase() !== name[0]) return;
|
|
487
|
+
if (Component?.staticConfig) return Component;
|
|
488
|
+
}
|
|
489
|
+
function interopDefaultExport(mod) {
|
|
490
|
+
return mod?.default ?? mod;
|
|
491
|
+
}
|
|
492
|
+
const cacheComponents = {};
|
|
493
|
+
function transformAddExports(ast) {
|
|
494
|
+
const usedNames = /* @__PURE__ */new Set();
|
|
495
|
+
return (0, import_traverse.default)(ast, {
|
|
496
|
+
ExportNamedDeclaration(nodePath) {
|
|
497
|
+
if (nodePath.node.specifiers) for (const spec of nodePath.node.specifiers) usedNames.add(t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value);
|
|
498
|
+
}
|
|
499
|
+
}), (0, import_traverse.default)(ast, {
|
|
500
|
+
VariableDeclaration(nodePath) {
|
|
501
|
+
if (!t.isProgram(nodePath.parent)) return;
|
|
502
|
+
const decs = nodePath.node.declarations;
|
|
503
|
+
if (decs.length > 1) return;
|
|
504
|
+
const [dec] = decs;
|
|
505
|
+
t.isIdentifier(dec.id) && dec.init && (usedNames.has(dec.id.name) || (usedNames.add(dec.id.name), nodePath.replaceWith(t.exportNamedDeclaration(t.variableDeclaration("let", [dec]), [t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name))]))));
|
|
506
|
+
}
|
|
507
|
+
}), (0, import_generator.default)(ast, {
|
|
508
|
+
concise: !1,
|
|
509
|
+
filename: "test.tsx",
|
|
510
|
+
retainLines: !1,
|
|
511
|
+
sourceMaps: !1
|
|
512
|
+
}).code;
|
|
513
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var concatClassName_exports = {};
|
|
22
|
+
__export(concatClassName_exports, {
|
|
23
|
+
concatClassName: () => concatClassName
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(concatClassName_exports);
|
|
26
|
+
function concatClassName(_cn) {
|
|
27
|
+
const args = arguments,
|
|
28
|
+
usedPrefixes = /* @__PURE__ */new Set();
|
|
29
|
+
let final = "";
|
|
30
|
+
const len = args.length;
|
|
31
|
+
let propObjects = null;
|
|
32
|
+
for (let x = len; x >= 0; x--) {
|
|
33
|
+
const cns = args[x];
|
|
34
|
+
if (!cns) continue;
|
|
35
|
+
if (!Array.isArray(cns) && typeof cns != "string") {
|
|
36
|
+
propObjects = propObjects || [], propObjects.push(cns);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const names = Array.isArray(cns) ? cns : cns.split(" "),
|
|
40
|
+
numNames = names.length;
|
|
41
|
+
for (let i = numNames - 1; i >= 0; i--) {
|
|
42
|
+
const name = names[i];
|
|
43
|
+
if (!name || name === " ") continue;
|
|
44
|
+
if (name[0] !== "_") {
|
|
45
|
+
final = name + " " + final;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const splitIndex = name.indexOf("-");
|
|
49
|
+
if (splitIndex < 1) {
|
|
50
|
+
final = name + " " + final;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const isMediaQuery = name[splitIndex + 1] === "_",
|
|
54
|
+
styleKey = name.slice(1, name.indexOf("-")),
|
|
55
|
+
mediaStart = splitIndex + 2,
|
|
56
|
+
mediaEnd = name.indexOf("_", mediaStart),
|
|
57
|
+
mediaKey = isMediaQuery && mediaEnd > mediaStart ? name.slice(mediaStart, mediaEnd) : null,
|
|
58
|
+
uid = mediaKey ? styleKey + mediaKey : styleKey;
|
|
59
|
+
if (usedPrefixes.has(uid)) continue;
|
|
60
|
+
usedPrefixes.add(uid);
|
|
61
|
+
const propName = styleKey;
|
|
62
|
+
propName && propObjects && propObjects.some(po => {
|
|
63
|
+
if (mediaKey) {
|
|
64
|
+
const propKey = pseudoInvert[mediaKey];
|
|
65
|
+
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null;
|
|
66
|
+
}
|
|
67
|
+
return po && propName in po && po[propName] !== null;
|
|
68
|
+
}) || (final = name + " " + final);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return final.trim();
|
|
72
|
+
}
|
|
73
|
+
const pseudoInvert = {
|
|
74
|
+
hover: "hoverStyle",
|
|
75
|
+
focus: "focusStyle",
|
|
76
|
+
press: "pressStyle",
|
|
77
|
+
focusVisible: "focusVisibleStyle",
|
|
78
|
+
focusWithin: "focusWithinStyle",
|
|
79
|
+
disabled: "disabledStyle"
|
|
80
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var createEvaluator_exports = {};
|
|
33
|
+
__export(createEvaluator_exports, {
|
|
34
|
+
createEvaluator: () => createEvaluator,
|
|
35
|
+
createSafeEvaluator: () => createSafeEvaluator
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(createEvaluator_exports);
|
|
38
|
+
var import_node_vm = __toESM(require("node:vm")),
|
|
39
|
+
import_generator = __toESM(require("@babel/generator")),
|
|
40
|
+
t = __toESM(require("@babel/types")),
|
|
41
|
+
import_esbuild = __toESM(require("esbuild")),
|
|
42
|
+
import_constants = require("../constants.cjs"),
|
|
43
|
+
import_evaluateAstNode = require("./evaluateAstNode.cjs");
|
|
44
|
+
function createEvaluator({
|
|
45
|
+
props,
|
|
46
|
+
staticNamespace,
|
|
47
|
+
sourcePath,
|
|
48
|
+
traversePath,
|
|
49
|
+
shouldPrintDebug
|
|
50
|
+
}) {
|
|
51
|
+
const evalFn = n => {
|
|
52
|
+
if (t.isIdentifier(n) && typeof staticNamespace[n.name] < "u") return staticNamespace[n.name];
|
|
53
|
+
const evalContext = import_node_vm.default.createContext(staticNamespace),
|
|
54
|
+
codeWithTypescriptAnnotations = `(${(0, import_generator.default)(n).code})`,
|
|
55
|
+
code = import_esbuild.default.transformSync(codeWithTypescriptAnnotations, {
|
|
56
|
+
loader: "tsx"
|
|
57
|
+
}).code.replace(/;\n$/, "");
|
|
58
|
+
shouldPrintDebug && console.info("evaluating", code);
|
|
59
|
+
const result1 = import_node_vm.default.runInContext(code, evalContext),
|
|
60
|
+
result2 = import_node_vm.default.runInContext(code, evalContext);
|
|
61
|
+
if (!(Object.is(result1, result2) || typeof result1 == "object" && typeof result2 == "object" && JSON.stringify(result1) === JSON.stringify(result2))) throw shouldPrintDebug && console.info("Bailing on non-deterministic expression:", code, `
|
|
62
|
+
First result:`, result1, "Second result:", result2), new Error("Non-deterministic value, bailing");
|
|
63
|
+
return result1;
|
|
64
|
+
};
|
|
65
|
+
return n => (0, import_evaluateAstNode.evaluateAstNode)(n, evalFn);
|
|
66
|
+
}
|
|
67
|
+
function createSafeEvaluator(attemptEval) {
|
|
68
|
+
return n => {
|
|
69
|
+
try {
|
|
70
|
+
return attemptEval(n);
|
|
71
|
+
} catch {
|
|
72
|
+
return import_constants.FAILED_EVAL;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|