@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.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/check-dep-versions.cjs +267 -0
  4. package/dist/checkDeps.cjs +200 -0
  5. package/dist/constants.cjs +49 -0
  6. package/dist/exports.cjs +44 -0
  7. package/dist/extractor/accessSafe.cjs +46 -0
  8. package/dist/extractor/babelParse.cjs +54 -0
  9. package/dist/extractor/buildClassName.cjs +62 -0
  10. package/dist/extractor/bundle.cjs +185 -0
  11. package/dist/extractor/bundleConfig.cjs +513 -0
  12. package/dist/extractor/concatClassName.cjs +80 -0
  13. package/dist/extractor/createEvaluator.cjs +75 -0
  14. package/dist/extractor/createExtractor.cjs +1150 -0
  15. package/dist/extractor/createLogger.cjs +45 -0
  16. package/dist/extractor/detectModuleFormat.cjs +49 -0
  17. package/dist/extractor/ensureImportingConcat.cjs +48 -0
  18. package/dist/extractor/errors.cjs +26 -0
  19. package/dist/extractor/esbuildAliasPlugin.cjs +44 -0
  20. package/dist/extractor/esbuildTsconfigPaths.cjs +86 -0
  21. package/dist/extractor/evaluateAstNode.cjs +83 -0
  22. package/dist/extractor/extractHelpers.cjs +119 -0
  23. package/dist/extractor/extractMediaStyle.cjs +128 -0
  24. package/dist/extractor/extractToClassNames.cjs +321 -0
  25. package/dist/extractor/extractToNative.cjs +266 -0
  26. package/dist/extractor/findTopmostFunction.cjs +34 -0
  27. package/dist/extractor/generatedUid.cjs +47 -0
  28. package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +35 -0
  29. package/dist/extractor/getPrefixLogs.cjs +29 -0
  30. package/dist/extractor/getPropValueFromAttributes.cjs +67 -0
  31. package/dist/extractor/getSourceModule.cjs +64 -0
  32. package/dist/extractor/getStaticBindingsForScope.cjs +150 -0
  33. package/dist/extractor/hoistClassNames.cjs +62 -0
  34. package/dist/extractor/literalToAst.cjs +84 -0
  35. package/dist/extractor/loadFile.cjs +11 -0
  36. package/dist/extractor/loadGui.cjs +322 -0
  37. package/dist/extractor/logLines.cjs +35 -0
  38. package/dist/extractor/normalizeTernaries.cjs +73 -0
  39. package/dist/extractor/propsToFontFamilyCache.cjs +38 -0
  40. package/dist/extractor/regenerateConfig.cjs +150 -0
  41. package/dist/extractor/removeUnusedHooks.cjs +76 -0
  42. package/dist/extractor/timer.cjs +43 -0
  43. package/dist/extractor/validHTMLAttributes.cjs +77 -0
  44. package/dist/extractor/watchGuiConfig.cjs +58 -0
  45. package/dist/getPragmaOptions.cjs +58 -0
  46. package/dist/helpers/memoize.cjs +37 -0
  47. package/dist/helpers/requireGuiCore.cjs +33 -0
  48. package/dist/index.cjs +40 -0
  49. package/dist/registerRequire.cjs +115 -0
  50. package/dist/server.cjs +75 -0
  51. package/dist/setup.cjs +0 -0
  52. package/dist/types.cjs +16 -0
  53. package/dist/worker.cjs +89 -0
  54. package/package.json +101 -0
  55. package/src/check-dep-versions.ts +738 -0
  56. package/src/checkDeps.ts +371 -0
  57. package/src/constants.ts +14 -0
  58. package/src/exports.ts +15 -0
  59. package/src/extractor/accessSafe.ts +22 -0
  60. package/src/extractor/babelParse.ts +37 -0
  61. package/src/extractor/buildClassName.ts +76 -0
  62. package/src/extractor/bundle.ts +277 -0
  63. package/src/extractor/bundleConfig.ts +958 -0
  64. package/src/extractor/concatClassName.ts +105 -0
  65. package/src/extractor/createEvaluator.ts +82 -0
  66. package/src/extractor/createExtractor.ts +2665 -0
  67. package/src/extractor/createLogger.ts +41 -0
  68. package/src/extractor/detectModuleFormat.ts +42 -0
  69. package/src/extractor/ensureImportingConcat.ts +36 -0
  70. package/src/extractor/errors.ts +1 -0
  71. package/src/extractor/esbuildAliasPlugin.ts +40 -0
  72. package/src/extractor/esbuildTsconfigPaths.ts +103 -0
  73. package/src/extractor/evaluateAstNode.ts +136 -0
  74. package/src/extractor/extractHelpers.ts +211 -0
  75. package/src/extractor/extractMediaStyle.ts +194 -0
  76. package/src/extractor/extractToClassNames.ts +631 -0
  77. package/src/extractor/extractToNative.ts +463 -0
  78. package/src/extractor/findTopmostFunction.ts +24 -0
  79. package/src/extractor/generatedUid.ts +41 -0
  80. package/src/extractor/getGuiConfigPathFromOptionsConfig.ts +24 -0
  81. package/src/extractor/getPrefixLogs.ts +9 -0
  82. package/src/extractor/getPropValueFromAttributes.ts +95 -0
  83. package/src/extractor/getSourceModule.ts +96 -0
  84. package/src/extractor/getStaticBindingsForScope.ts +237 -0
  85. package/src/extractor/hoistClassNames.ts +52 -0
  86. package/src/extractor/literalToAst.ts +85 -0
  87. package/src/extractor/loadFile.ts +17 -0
  88. package/src/extractor/loadGui.ts +487 -0
  89. package/src/extractor/logLines.ts +16 -0
  90. package/src/extractor/normalizeTernaries.ts +75 -0
  91. package/src/extractor/propsToFontFamilyCache.ts +18 -0
  92. package/src/extractor/regenerateConfig.ts +186 -0
  93. package/src/extractor/removeUnusedHooks.ts +83 -0
  94. package/src/extractor/timer.ts +25 -0
  95. package/src/extractor/validHTMLAttributes.ts +52 -0
  96. package/src/extractor/watchGuiConfig.ts +57 -0
  97. package/src/getPragmaOptions.ts +57 -0
  98. package/src/helpers/memoize.ts +24 -0
  99. package/src/helpers/requireGuiCore.ts +28 -0
  100. package/src/index.ts +4 -0
  101. package/src/registerRequire.ts +236 -0
  102. package/src/server.ts +43 -0
  103. package/src/setup.ts +0 -0
  104. package/src/types.ts +109 -0
  105. package/src/worker.ts +142 -0
  106. package/types/check-dep-versions.d.ts +37 -0
  107. package/types/check-dep-versions.d.ts.map +1 -0
  108. package/types/checkDeps.d.ts +19 -0
  109. package/types/checkDeps.d.ts.map +1 -0
  110. package/types/constants.d.ts +6 -0
  111. package/types/constants.d.ts.map +1 -0
  112. package/types/exports.d.ts +16 -0
  113. package/types/exports.d.ts.map +1 -0
  114. package/types/extractor/accessSafe.d.ts +3 -0
  115. package/types/extractor/accessSafe.d.ts.map +1 -0
  116. package/types/extractor/babelParse.d.ts +5 -0
  117. package/types/extractor/babelParse.d.ts.map +1 -0
  118. package/types/extractor/buildClassName.d.ts +7 -0
  119. package/types/extractor/buildClassName.d.ts.map +1 -0
  120. package/types/extractor/bundle.d.ts +121 -0
  121. package/types/extractor/bundle.d.ts.map +1 -0
  122. package/types/extractor/bundleConfig.d.ts +49 -0
  123. package/types/extractor/bundleConfig.d.ts.map +1 -0
  124. package/types/extractor/concatClassName.d.ts +8 -0
  125. package/types/extractor/concatClassName.d.ts.map +1 -0
  126. package/types/extractor/createEvaluator.d.ts +12 -0
  127. package/types/extractor/createEvaluator.d.ts.map +1 -0
  128. package/types/extractor/createExtractor.d.ts +32 -0
  129. package/types/extractor/createExtractor.d.ts.map +1 -0
  130. package/types/extractor/createLogger.d.ts +3 -0
  131. package/types/extractor/createLogger.d.ts.map +1 -0
  132. package/types/extractor/detectModuleFormat.d.ts +5 -0
  133. package/types/extractor/detectModuleFormat.d.ts.map +1 -0
  134. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  135. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  136. package/types/extractor/errors.d.ts +3 -0
  137. package/types/extractor/errors.d.ts.map +1 -0
  138. package/types/extractor/esbuildAliasPlugin.d.ts +18 -0
  139. package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -0
  140. package/types/extractor/esbuildTsconfigPaths.d.ts +11 -0
  141. package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -0
  142. package/types/extractor/evaluateAstNode.d.ts +3 -0
  143. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  144. package/types/extractor/extractHelpers.d.ts +28 -0
  145. package/types/extractor/extractHelpers.d.ts.map +1 -0
  146. package/types/extractor/extractMediaStyle.d.ts +11 -0
  147. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  148. package/types/extractor/extractToClassNames.d.ts +25 -0
  149. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  150. package/types/extractor/extractToNative.d.ts +13 -0
  151. package/types/extractor/extractToNative.d.ts.map +1 -0
  152. package/types/extractor/findTopmostFunction.d.ts +4 -0
  153. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  154. package/types/extractor/generatedUid.d.ts +5 -0
  155. package/types/extractor/generatedUid.d.ts.map +1 -0
  156. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +3 -0
  157. package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -0
  158. package/types/extractor/getPrefixLogs.d.ts +3 -0
  159. package/types/extractor/getPrefixLogs.d.ts.map +1 -0
  160. package/types/extractor/getPropValueFromAttributes.d.ts +19 -0
  161. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  162. package/types/extractor/getSourceModule.d.ts +16 -0
  163. package/types/extractor/getSourceModule.d.ts.map +1 -0
  164. package/types/extractor/getStaticBindingsForScope.d.ts +5 -0
  165. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  166. package/types/extractor/hoistClassNames.d.ts +6 -0
  167. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  168. package/types/extractor/literalToAst.d.ts +4 -0
  169. package/types/extractor/literalToAst.d.ts.map +1 -0
  170. package/types/extractor/loadFile.d.ts +1 -0
  171. package/types/extractor/loadFile.d.ts.map +1 -0
  172. package/types/extractor/loadGui.d.ts +22 -0
  173. package/types/extractor/loadGui.d.ts.map +1 -0
  174. package/types/extractor/logLines.d.ts +2 -0
  175. package/types/extractor/logLines.d.ts.map +1 -0
  176. package/types/extractor/normalizeTernaries.d.ts +3 -0
  177. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  178. package/types/extractor/propsToFontFamilyCache.d.ts +4 -0
  179. package/types/extractor/propsToFontFamilyCache.d.ts.map +1 -0
  180. package/types/extractor/regenerateConfig.d.ts +9 -0
  181. package/types/extractor/regenerateConfig.d.ts.map +1 -0
  182. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  183. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  184. package/types/extractor/timer.d.ts +5 -0
  185. package/types/extractor/timer.d.ts.map +1 -0
  186. package/types/extractor/validHTMLAttributes.d.ts +52 -0
  187. package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
  188. package/types/extractor/watchGuiConfig.d.ts +5 -0
  189. package/types/extractor/watchGuiConfig.d.ts.map +1 -0
  190. package/types/getPragmaOptions.d.ts +8 -0
  191. package/types/getPragmaOptions.d.ts.map +1 -0
  192. package/types/helpers/memoize.d.ts +8 -0
  193. package/types/helpers/memoize.d.ts.map +1 -0
  194. package/types/helpers/requireGuiCore.d.ts +3 -0
  195. package/types/helpers/requireGuiCore.d.ts.map +1 -0
  196. package/types/index.d.ts +4 -0
  197. package/types/index.d.ts.map +1 -0
  198. package/types/registerRequire.d.ts +10 -0
  199. package/types/registerRequire.d.ts.map +1 -0
  200. package/types/server.d.ts +3 -0
  201. package/types/server.d.ts.map +1 -0
  202. package/types/setup.d.ts +1 -0
  203. package/types/setup.d.ts.map +1 -0
  204. package/types/types.d.ts +92 -0
  205. package/types/types.d.ts.map +1 -0
  206. package/types/worker.d.ts +46 -0
  207. package/types/worker.d.ts.map +1 -0
@@ -0,0 +1,35 @@
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 getGuiConfigPathFromOptionsConfig_exports = {};
22
+ __export(getGuiConfigPathFromOptionsConfig_exports, {
23
+ getGuiConfigPathFromOptionsConfig: () => getGuiConfigPathFromOptionsConfig
24
+ });
25
+ module.exports = __toCommonJS(getGuiConfigPathFromOptionsConfig_exports);
26
+ var import_node_path = require("node:path"),
27
+ import_node_fs = require("node:fs");
28
+ function getGuiConfigPathFromOptionsConfig(config) {
29
+ if ((0, import_node_path.isAbsolute)(config)) return config;
30
+ const fullPath = (0, import_node_path.join)(process.cwd(), config);
31
+ try {
32
+ if ((0, import_node_fs.statSync)(fullPath).isFile()) return fullPath;
33
+ } catch {}
34
+ return config;
35
+ }
@@ -0,0 +1,29 @@
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 getPrefixLogs_exports = {};
22
+ __export(getPrefixLogs_exports, {
23
+ getPrefixLogs: () => getPrefixLogs
24
+ });
25
+ module.exports = __toCommonJS(getPrefixLogs_exports);
26
+ var import_cli_color = require("@hanzogui/cli-color");
27
+ function getPrefixLogs(options) {
28
+ return options?.prefixLogs ?? ` \u{1F425} [hanzo-gui] ${(0, import_cli_color.colorString)(import_cli_color.Color.FgYellow, options?.platform || "web")}`;
29
+ }
@@ -0,0 +1,67 @@
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 getPropValueFromAttributes_exports = {};
33
+ __export(getPropValueFromAttributes_exports, {
34
+ getPropValueFromAttributes: () => getPropValueFromAttributes
35
+ });
36
+ module.exports = __toCommonJS(getPropValueFromAttributes_exports);
37
+ var import_generator = __toESM(require("@babel/generator")),
38
+ t = __toESM(require("@babel/types")),
39
+ import_accessSafe = require("./accessSafe.cjs");
40
+ function getPropValueFromAttributes(propName, attrs) {
41
+ let propIndex = -1,
42
+ jsxAttr = null;
43
+ for (let idx = -1, len = attrs.length; ++idx < len;) {
44
+ const attr = attrs[idx];
45
+ if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
46
+ propIndex = idx, jsxAttr = attr;
47
+ break;
48
+ }
49
+ }
50
+ if (!jsxAttr || jsxAttr.value == null) return null;
51
+ let propValue = jsxAttr.value;
52
+ if (t.isJSXExpressionContainer(propValue) && (propValue = propValue.expression), t.isJSXEmptyExpression(propValue)) return console.error("encountered JSXEmptyExpression"), null;
53
+ const applicableSpreads = attrs.filter(
54
+ // 1. idx is greater than propValue prop index
55
+ // 2. attr is a spread operator
56
+ (attr, idx) => {
57
+ if (t.isJSXSpreadAttribute(attr)) {
58
+ if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) return idx > propIndex;
59
+ if (t.isLogicalExpression(attr.argument)) return !1;
60
+ throw new Error(`unsupported spread of type "${attr.argument.type}": ${
61
+ // @ts-ignore
62
+ (0, import_generator.default)(attr).code}`);
63
+ }
64
+ return !1;
65
+ }).map(attr => attr.argument);
66
+ return applicableSpreads.length > 0 && (propValue = applicableSpreads.reduce((acc, val) => t.logicalExpression("||", (0, import_accessSafe.accessSafe)(val, propName), acc), propValue)), propValue;
67
+ }
@@ -0,0 +1,64 @@
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 getSourceModule_exports = {};
33
+ __export(getSourceModule_exports, {
34
+ getSourceModule: () => getSourceModule
35
+ });
36
+ module.exports = __toCommonJS(getSourceModule_exports);
37
+ var t = __toESM(require("@babel/types"));
38
+ function getSourceModule(itemName, itemBinding) {
39
+ if (!itemBinding.constant) return null;
40
+ let sourceModule,
41
+ imported,
42
+ local,
43
+ destructured,
44
+ usesImportSyntax = !1;
45
+ const itemNode = itemBinding.path.node;
46
+ if (t.isImportDefaultSpecifier(itemNode) || t.isImportSpecifier(itemNode)) t.isImportDeclaration(itemBinding.path.parent) && (sourceModule = itemBinding.path.parent.source.value, local = itemNode.local.name, usesImportSyntax = !0, t.isImportSpecifier(itemNode) ? (imported = itemNode.imported.name, destructured = !0) : (imported = itemNode.local.name, destructured = !1));else if (t.isVariableDeclarator(itemNode) && itemNode.init != null && t.isCallExpression(itemNode.init) && t.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
47
+ const firstArg = itemNode.init.arguments[0];
48
+ if (!t.isStringLiteral(firstArg)) return null;
49
+ if (sourceModule = firstArg.value, t.isIdentifier(itemNode.id)) local = itemNode.id.name, imported = itemNode.id.name, destructured = !1;else if (t.isObjectPattern(itemNode.id)) {
50
+ for (const objProp of itemNode.id.properties) if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
51
+ local = objProp.value.name, imported = objProp.key.name, destructured = !0;
52
+ break;
53
+ }
54
+ if (!local || !imported) return console.error("could not find prop with value `%s`", itemName), null;
55
+ } else return console.error("Unhandled id type: %s", itemNode.id.type), null;
56
+ } else return null;
57
+ return {
58
+ destructured,
59
+ imported,
60
+ local,
61
+ sourceModule,
62
+ usesImportSyntax
63
+ };
64
+ }
@@ -0,0 +1,150 @@
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 getStaticBindingsForScope_exports = {};
33
+ __export(getStaticBindingsForScope_exports, {
34
+ cleanupBeforeExit: () => cleanupBeforeExit,
35
+ getStaticBindingsForScope: () => getStaticBindingsForScope
36
+ });
37
+ module.exports = __toCommonJS(getStaticBindingsForScope_exports);
38
+ var import_node_child_process = require("node:child_process"),
39
+ import_node_path = require("node:path"),
40
+ t = __toESM(require("@babel/types")),
41
+ import_evaluateAstNode = require("./evaluateAstNode.cjs"),
42
+ import_getSourceModule = require("./getSourceModule.cjs");
43
+ const isLocalImport = path => path.startsWith(".") || path.startsWith("/");
44
+ function resolveImportPath(sourcePath, path) {
45
+ const sourceDir = (0, import_node_path.dirname)(sourcePath);
46
+ return isLocalImport(path) ? ((0, import_node_path.extname)(path) === "" && (path += ""), (0, import_node_path.resolve)(sourceDir, path)) : path;
47
+ }
48
+ const cache = /* @__PURE__ */new Map(),
49
+ pending = /* @__PURE__ */new Map(),
50
+ loadCmd = `${(0, import_node_path.join)(__dirname, "loadFile.js")}`;
51
+ let exited = !1,
52
+ child = null;
53
+ function forkChild() {
54
+ child = (0, import_node_child_process.fork)(loadCmd, [], {
55
+ execArgv: ["-r", "esbuild-register"],
56
+ detached: !1,
57
+ stdio: "ignore"
58
+ });
59
+ }
60
+ function cleanupBeforeExit() {
61
+ exited || child && (child.removeAllListeners(), child.unref(), child.disconnect(), child.kill(), exited = !0);
62
+ }
63
+ process.once("SIGTERM", cleanupBeforeExit);
64
+ process.once("SIGINT", cleanupBeforeExit);
65
+ process.once("beforeExit", cleanupBeforeExit);
66
+ function importModule(path) {
67
+ if (child || forkChild(), pending.has(path)) return pending.get(path);
68
+ const promise = new Promise((res, rej) => {
69
+ if (!child) return;
70
+ if (cache.size > 2e3 && cache.clear(), cache.has(path)) return cache.get(path);
71
+ const listener = msg => {
72
+ if (!child || !msg || typeof msg != "string") return;
73
+ if (msg[0] === "-") {
74
+ rej(new Error(msg.slice(1)));
75
+ return;
76
+ }
77
+ child.removeListener("message", listener);
78
+ const val = JSON.parse(msg);
79
+ cache.set(path, val), res(val);
80
+ };
81
+ child.once("message", listener), child.send(`${path.replace(".js", "")}`);
82
+ }).finally(() => {
83
+ pending.delete(path);
84
+ });
85
+ return pending.set(path, promise), promise;
86
+ }
87
+ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
88
+ const bindings = scope.getAllBindings(),
89
+ ret = {},
90
+ program = scope.getProgramParent().block;
91
+ for (const node of program.body) if (t.isImportDeclaration(node)) {
92
+ const importPath = node.source.value;
93
+ if (!node.specifiers.length || !isLocalImport(importPath)) continue;
94
+ const moduleName = resolveImportPath(sourcePath, importPath);
95
+ if (!whitelist.some(test => moduleName.endsWith(test))) continue;
96
+ try {
97
+ const src = await importModule(moduleName);
98
+ if (!src) continue;
99
+ for (const specifier of node.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && typeof src[specifier.imported.name] < "u") {
100
+ const val = src[specifier.local.name];
101
+ ret[specifier.local.name] = val;
102
+ }
103
+ } catch (err) {
104
+ shouldPrintDebug ? console.warn(` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=hanzo-gui for more)`) : process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Error in partial evaluation", err.message, err.stack);
105
+ }
106
+ }
107
+ if (!bindingCache) throw new Error("BindingCache is a required param");
108
+ for (const k in bindings) {
109
+ const binding = bindings[k],
110
+ sourceModule = (0, import_getSourceModule.getSourceModule)(k, binding);
111
+ if (sourceModule) {
112
+ if (!sourceModule.sourceModule) continue;
113
+ const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
114
+ if (whitelist.some(test => moduleName.endsWith(test))) {
115
+ const src = importModule(moduleName);
116
+ if (!src) return console.info(` | \u26A0\uFE0F Missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`), {};
117
+ sourceModule.destructured ? sourceModule.imported && (ret[k] = src[sourceModule.imported]) : ret[k] = src;
118
+ }
119
+ continue;
120
+ }
121
+ const {
122
+ parent
123
+ } = binding.path;
124
+ if (!t.isVariableDeclaration(parent) || parent.kind !== "const") continue;
125
+ const dec = parent.declarations.find(d => t.isIdentifier(d.id) && d.id.name === k);
126
+ if (!dec || !dec.init) continue;
127
+ if (typeof dec.id.start != "number" || typeof dec.id.end != "number") {
128
+ console.error("dec.id.start/end is not a number");
129
+ continue;
130
+ }
131
+ if (!t.isIdentifier(dec.id)) {
132
+ console.error("dec is not an identifier");
133
+ continue;
134
+ }
135
+ const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
136
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
137
+ ret[k] = bindingCache[cacheKey];
138
+ continue;
139
+ }
140
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
141
+ ret[k] = bindingCache[cacheKey];
142
+ continue;
143
+ }
144
+ try {
145
+ ret[k] = (0, import_evaluateAstNode.evaluateAstNode)(dec.init, void 0, shouldPrintDebug), bindingCache[cacheKey] = ret[k];
146
+ continue;
147
+ } catch {}
148
+ }
149
+ return ret;
150
+ }
@@ -0,0 +1,62 @@
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 hoistClassNames_exports = {};
33
+ __export(hoistClassNames_exports, {
34
+ hoistClassNames: () => hoistClassNames
35
+ });
36
+ module.exports = __toCommonJS(hoistClassNames_exports);
37
+ var t = __toESM(require("@babel/types"));
38
+ function hoistClassNames(path, existing, expr) {
39
+ const hoist = hoistClassNames.bind(null, path, existing);
40
+ if (t.isStringLiteral(expr)) {
41
+ if (expr.value.trim() === "") return expr;
42
+ if (existing[expr.value]) return existing[expr.value];
43
+ const identifier = replaceStringWithVariable(expr);
44
+ return existing[expr.value] = identifier, identifier;
45
+ }
46
+ if (t.isBinaryExpression(expr)) {
47
+ if (t.isPrivateName(expr.left)) throw new Error("no private name");
48
+ return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
49
+ }
50
+ if (t.isLogicalExpression(expr)) return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
51
+ if (t.isConditionalExpression(expr)) return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
52
+ return expr;
53
+ function replaceStringWithVariable(str) {
54
+ const uid = path.scope.generateUidIdentifier("cn"),
55
+ parent = path.findParent(path2 => path2.isProgram());
56
+ if (!parent) throw new Error("no program?");
57
+ const variable = t.variableDeclaration("const", [
58
+ // adding a space for extra safety
59
+ t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))]);
60
+ return parent.unshiftContainer("body", variable), uid;
61
+ }
62
+ }
@@ -0,0 +1,84 @@
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 literalToAst_exports = {};
33
+ __export(literalToAst_exports, {
34
+ astToLiteral: () => astToLiteral,
35
+ literalToAst: () => literalToAst
36
+ });
37
+ module.exports = __toCommonJS(literalToAst_exports);
38
+ var t = __toESM(require("@babel/types"));
39
+ function literalToAst(literal) {
40
+ if (literal === null) return t.nullLiteral();
41
+ switch (typeof literal) {
42
+ case "function":
43
+ throw new Error("Unsupported");
44
+ case "number":
45
+ return t.numericLiteral(literal);
46
+ case "string":
47
+ return t.stringLiteral(literal);
48
+ case "boolean":
49
+ return t.booleanLiteral(literal);
50
+ case "undefined":
51
+ return t.unaryExpression("void", t.numericLiteral(0), !0);
52
+ default:
53
+ return Array.isArray(literal) ? t.arrayExpression(literal.map(literalToAst)) : t.objectExpression(Object.keys(literal).filter(k => typeof literal[k] < "u").map(k => t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))));
54
+ }
55
+ }
56
+ const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
57
+ function astToLiteral(node) {
58
+ if (node) {
59
+ if (easyPeasies.includes(node.type)) return node.value;
60
+ if (!(node.name === "undefined" && !node.value)) {
61
+ if (t.isNullLiteral(node)) return null;
62
+ if (t.isObjectExpression(node)) return computeProps(node.properties);
63
+ if (t.isArrayExpression(node)) return node.elements.reduce(
64
+ // @ts-ignore
65
+ (acc, element) => [...acc, ...(element?.type === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)])], []);
66
+ }
67
+ }
68
+ }
69
+ function computeProps(props) {
70
+ return props.reduce((acc, prop) => {
71
+ if (prop.type === "SpreadElement") return {
72
+ ...acc,
73
+ ...astToLiteral(prop.argument)
74
+ };
75
+ if (prop.type !== "ObjectMethod") {
76
+ const val = astToLiteral(prop.value);
77
+ if (val !== void 0) return {
78
+ ...acc,
79
+ [prop.key.name]: val
80
+ };
81
+ }
82
+ return acc;
83
+ }, {});
84
+ }
@@ -0,0 +1,11 @@
1
+ process.on("message", path => {
2
+ if (typeof path != "string") throw new Error(`Not a string: ${path}`);
3
+ try {
4
+ const out = require(path);
5
+ process.send?.(JSON.stringify(out));
6
+ } catch (err) {
7
+ err instanceof Error ? process.send?.(`-${err.message}
8
+ ${err.stack}`) : process.send?.(`-${err}`);
9
+ }
10
+ });
11
+ setInterval(() => {}, 1e3);