@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,321 @@
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 extractToClassNames_exports = {};
33
+ __export(extractToClassNames_exports, {
34
+ extractToClassNames: () => extractToClassNames
35
+ });
36
+ module.exports = __toCommonJS(extractToClassNames_exports);
37
+ var import_generator = __toESM(require("@babel/generator")),
38
+ t = __toESM(require("@babel/types")),
39
+ import_web = require("@hanzogui/web"),
40
+ path = __toESM(require("node:path")),
41
+ util = __toESM(require("node:util")),
42
+ import_requireGuiCore = require("../helpers/requireGuiCore.cjs"),
43
+ import_babelParse = require("./babelParse.cjs"),
44
+ import_createLogger = require("./createLogger.cjs"),
45
+ import_extractMediaStyle = require("./extractMediaStyle.cjs"),
46
+ import_normalizeTernaries = require("./normalizeTernaries.cjs"),
47
+ import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs"),
48
+ import_timer = require("./timer.cjs"),
49
+ import_errors = require("./errors.cjs"),
50
+ import_concatClassName = require("./concatClassName.cjs");
51
+ const remove = () => {},
52
+ spaceString = t.stringLiteral(" ");
53
+ async function extractToClassNames({
54
+ extractor,
55
+ source,
56
+ sourcePath = "",
57
+ options,
58
+ shouldPrintDebug
59
+ }) {
60
+ const tm = (0, import_timer.timer)(),
61
+ {
62
+ getCSSStylesAtomic,
63
+ createMediaStyle
64
+ } = (0, import_requireGuiCore.requireGuiCore)("web");
65
+ if (sourcePath.includes("node_modules")) return null;
66
+ if (shouldPrintDebug && console.warn(`--- ${sourcePath} ---
67
+
68
+ `), typeof source != "string") throw new Error("`source` must be a string of javascript");
69
+ if (!path.isAbsolute(sourcePath)) throw new Error("`sourcePath` must be an absolute path to a .js file, got: " + sourcePath);
70
+ /.[tj]sx?$/i.test(sourcePath || "") || console.warn(`${sourcePath.slice(0, 100)} - bad filename.`), !options.disableExtraction && !options._disableLoadGui && (await extractor.loadGui(options));
71
+ const printLog = (0, import_createLogger.createLogger)(sourcePath, options);
72
+ let ast;
73
+ try {
74
+ ast = (0, import_babelParse.babelParse)(source, sourcePath);
75
+ } catch (err) {
76
+ throw console.error("babel parse error:", sourcePath.slice(0, 100)), err;
77
+ }
78
+ tm.mark("babel-parse", shouldPrintDebug === "verbose");
79
+ const cssMap = /* @__PURE__ */new Map(),
80
+ guiConfig = extractor.getGui(),
81
+ res = await extractor.parse(ast, {
82
+ shouldPrintDebug,
83
+ ...options,
84
+ platform: "web",
85
+ sourcePath,
86
+ extractStyledDefinitions: !0,
87
+ onStyledDefinitionRule(identifier, rules) {
88
+ const css = rules.join(`
89
+ `);
90
+ shouldPrintDebug && console.info(`adding styled() rule: .${identifier} ${css}`), cssMap.set(`.${identifier}`, {
91
+ css,
92
+ commentTexts: []
93
+ });
94
+ },
95
+ getFlattenedNode: ({
96
+ tag
97
+ }) => tag,
98
+ onExtractTag: ({
99
+ parserProps,
100
+ attrs,
101
+ node,
102
+ attemptEval,
103
+ jsxPath,
104
+ originalNodeName,
105
+ filePath,
106
+ lineNumbers,
107
+ staticConfig
108
+ }) => {
109
+ if (staticConfig.acceptsClassName === !1) throw new import_errors.BailOptimizationError();
110
+ const finalAttrs = [];
111
+ let mergeForwardBaseStyle = null,
112
+ attrClassName = null,
113
+ baseFontFamily = "",
114
+ mediaStylesSeen = 1;
115
+ const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
116
+ function addStyle(style) {
117
+ const identifier = style[import_web.StyleObjectIdentifier],
118
+ rules = style[import_web.StyleObjectRules],
119
+ selector = `.${identifier}`;
120
+ return cssMap.has(selector) ? cssMap.get(selector).commentTexts.push(comment) : rules.length && cssMap.set(selector, {
121
+ css: rules.join(`
122
+ `),
123
+ commentTexts: [comment]
124
+ }), identifier;
125
+ }
126
+ function addStyles(style) {
127
+ const cssStyles = getCSSStylesAtomic(style),
128
+ classNames = [];
129
+ for (const style2 of cssStyles) {
130
+ const mediaName = style2[0].slice(1);
131
+ if (mediaName.startsWith("group-")) throw new import_errors.BailOptimizationError();
132
+ const mediaTypeMatch = mediaName.match(/^(theme|platform)-/);
133
+ if (mediaTypeMatch) {
134
+ const mediaType = mediaTypeMatch[1],
135
+ mediaStyle = createMediaStyle(style2, mediaName, extractor.getGui().media, mediaType, !1, mediaStylesSeen),
136
+ identifier2 = addStyle(mediaStyle);
137
+ classNames.push(identifier2);
138
+ continue;
139
+ }
140
+ if (mediaName in guiConfig.media) {
141
+ const mediaStyle = createMediaStyle(style2, mediaName, extractor.getGui().media, !0, !1, mediaStylesSeen),
142
+ identifier2 = addStyle(mediaStyle);
143
+ classNames.push(identifier2);
144
+ continue;
145
+ }
146
+ const identifier = addStyle(style2);
147
+ classNames.push(identifier);
148
+ }
149
+ return classNames;
150
+ }
151
+ const onlyTernaries = attrs.flatMap(attr => {
152
+ if (attr.type === "attr") {
153
+ const value = attr.value;
154
+ if (t.isJSXSpreadAttribute(value)) return console.error("Should never happen"), [];
155
+ if (value.name.name === "className") {
156
+ let inner = value.value;
157
+ t.isJSXExpressionContainer(inner) && (inner = inner.expression);
158
+ try {
159
+ const evaluatedValue = inner ? attemptEval(inner) : null;
160
+ typeof evaluatedValue == "string" && (attrClassName = t.stringLiteral(evaluatedValue));
161
+ } catch {
162
+ inner && (attrClassName ||= inner);
163
+ }
164
+ return [];
165
+ }
166
+ return finalAttrs.push(value), [];
167
+ }
168
+ if (attr.type === "style") return mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, attr.value), baseFontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(attr.value) || "", [];
169
+ let ternary = attr.value;
170
+ if (ternary.inlineMediaQuery) {
171
+ const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(parserProps, attr.value, jsxPath, extractor.getGui(), sourcePath || "", mediaStylesSeen++, shouldPrintDebug);
172
+ if (mediaExtraction) if (mediaExtraction.mediaStyles && (mergeForwardBaseStyle = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, {
173
+ [`$${ternary.inlineMediaQuery}`]: attr.value.consequent
174
+ })), mediaExtraction.ternaryWithoutMedia) ternary = mediaExtraction.ternaryWithoutMedia;else return [];
175
+ }
176
+ let mergedAlternate, mergedConsequent;
177
+ return ternary.alternate && Object.keys(ternary.alternate).length && (mergedAlternate = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.alternate || {}), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.alternate, mergedAlternate, baseFontFamily)), ternary.consequent && Object.keys(ternary.consequent).length && (mergedConsequent = (0, import_web.mergeProps)(mergeForwardBaseStyle || {}, ternary.consequent || {}), (0, import_propsToFontFamilyCache.forwardFontFamilyName)(ternary.consequent, mergedConsequent, baseFontFamily)), {
178
+ ...ternary,
179
+ alternate: mergedAlternate,
180
+ consequent: mergedConsequent
181
+ };
182
+ }),
183
+ hasTernaries = !!onlyTernaries.length,
184
+ baseClassNames = mergeForwardBaseStyle ? addStyles(mergeForwardBaseStyle) : null;
185
+ let baseClassNameStr = baseClassNames ? baseClassNames.join(" ") : "";
186
+ baseFontFamily && (baseClassNameStr = `font_${baseFontFamily}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`), baseClassNameStr = `${staticConfig.isText ? "is_Text" : "is_View"}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`;
187
+ const componentNameFinal = staticConfig.componentName;
188
+ let base = componentNameFinal && componentNameFinal !== "Text" ? t.stringLiteral(`is_${componentNameFinal}${baseClassNameStr ? ` ${baseClassNameStr}` : ""}`) : t.stringLiteral(baseClassNameStr || "");
189
+ attrClassName = attrClassName;
190
+ const baseClassNameExpression = attrClassName ? t.isStringLiteral(attrClassName) ? t.stringLiteral(base.value ? `${base.value} ${attrClassName.value}` : attrClassName.value) : t.binaryExpression("+", t.binaryExpression("+", attrClassName, spaceString), base) : base,
191
+ expandedTernaries = [];
192
+ if (onlyTernaries.length) {
193
+ const normalizedTernaries = (0, import_normalizeTernaries.normalizeTernaries)(onlyTernaries);
194
+ for (const ternary of normalizedTernaries) {
195
+ if (!expandedTernaries.length) {
196
+ expandTernary(ternary);
197
+ continue;
198
+ }
199
+ const prevTernaries = [...expandedTernaries];
200
+ for (const prev of prevTernaries) expandTernary(ternary, prev);
201
+ }
202
+ }
203
+ function expandTernary(ternary, prev) {
204
+ if (ternary.consequent && Object.keys(ternary.consequent).length) {
205
+ const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.consequent);
206
+ expandedTernaries.push({
207
+ fontFamily,
208
+ // prevTest && test: merge consequent
209
+ test: prev ? t.logicalExpression("&&", prev.test, ternary.test) : ternary.test,
210
+ consequent: prev ? (0, import_web.mergeProps)(prev.consequent, ternary.consequent) : ternary.consequent,
211
+ remove,
212
+ alternate: null
213
+ }), prev && expandedTernaries.push({
214
+ fontFamily,
215
+ // !prevTest && test: just consequent
216
+ test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
217
+ consequent: ternary.consequent,
218
+ alternate: null,
219
+ remove
220
+ });
221
+ }
222
+ if (ternary.alternate && Object.keys(ternary.alternate).length) {
223
+ const fontFamily = (0, import_propsToFontFamilyCache.getFontFamilyNameFromProps)(ternary.alternate),
224
+ negated = t.unaryExpression("!", ternary.test);
225
+ expandedTernaries.push({
226
+ fontFamily,
227
+ // prevTest && !test: merge alternate
228
+ test: prev ? t.logicalExpression("&&", prev.test, negated) : negated,
229
+ consequent: prev ? (0, import_web.mergeProps)(prev.alternate, ternary.alternate) : ternary.alternate,
230
+ remove,
231
+ alternate: null
232
+ }), prev && expandedTernaries.push({
233
+ fontFamily,
234
+ test: t.logicalExpression("&&", t.unaryExpression("!", prev.test), ternary.test),
235
+ consequent: ternary.alternate,
236
+ remove,
237
+ alternate: null
238
+ });
239
+ }
240
+ }
241
+ let ternaryClassNameExpr = null;
242
+ if (hasTernaries) for (const ternary of expandedTernaries) {
243
+ if (!ternary.consequent) continue;
244
+ const classNames = addStyles(ternary.consequent);
245
+ ternary.fontFamily && classNames.unshift(`font_${ternary.fontFamily}`);
246
+ const baseString = t.isStringLiteral(baseClassNameExpression) ? baseClassNameExpression.value : "",
247
+ fullClassNameWithDups = (baseString ? `${baseString} ` : "") + classNames.join(" "),
248
+ fullClassName = (0, import_concatClassName.concatClassName)(fullClassNameWithDups),
249
+ classNameLiteral = t.stringLiteral(fullClassName);
250
+ ternaryClassNameExpr ? ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, ternaryClassNameExpr) : ternaryClassNameExpr = t.conditionalExpression(ternary.test, classNameLiteral, baseClassNameExpression);
251
+ }
252
+ let finalExpression = ternaryClassNameExpr || baseClassNameExpression || null;
253
+ if (shouldPrintDebug && (console.info("attrs", JSON.stringify(attrs, null, 2)), console.info("expandedTernaries", JSON.stringify(expandedTernaries, null, 2)), console.info("finalExpression", JSON.stringify(finalExpression, null, 2)), console.info({
254
+ hasTernaries,
255
+ baseClassNameExpression
256
+ })), finalExpression) {
257
+ finalExpression = hoistClassNames(jsxPath, finalExpression);
258
+ const classNameProp = t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(finalExpression));
259
+ finalAttrs.unshift(classNameProp);
260
+ }
261
+ node.attributes = finalAttrs;
262
+ }
263
+ });
264
+ if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) return shouldPrintDebug && console.info("no res or none modified", res), null;
265
+ const styles = Array.from(cssMap.values()).map(x => x.css).join(`
266
+ `).trim(),
267
+ result = (0, import_generator.default)(ast, {
268
+ concise: !1,
269
+ filename: sourcePath,
270
+ // this makes the debug output terrible, and i think sourcemap works already
271
+ retainLines: !1,
272
+ sourceFileName: sourcePath,
273
+ sourceMaps: !0
274
+ }, source);
275
+ return shouldPrintDebug && (console.info(`
276
+ -------- output code -------
277
+
278
+ `, result.code.split(`
279
+ `).filter(x => !x.startsWith("//")).join(`
280
+ `)), console.info(`
281
+ -------- output style --------
282
+
283
+ `, styles)), printLog(res), {
284
+ ast,
285
+ styles,
286
+ js: result.code,
287
+ map: result.map,
288
+ stats: {
289
+ styled: res.styled,
290
+ flattened: res.flattened,
291
+ optimized: res.optimized,
292
+ found: res.found
293
+ }
294
+ };
295
+ }
296
+ function hoistClassNames(path2, expr) {
297
+ if (t.isStringLiteral(expr)) return hoistClassName(path2, expr.value);
298
+ if (t.isLogicalExpression(expr)) {
299
+ const left = t.isStringLiteral(expr.left) ? hoistClassName(path2, expr.left.value) : expr.left,
300
+ right = t.isStringLiteral(expr.right) ? hoistClassName(path2, expr.right.value) : hoistClassNames(path2, expr.right);
301
+ return t.logicalExpression(expr.operator, left, right);
302
+ }
303
+ if (t.isConditionalExpression(expr)) {
304
+ const cons = t.isStringLiteral(expr.consequent) ? hoistClassName(path2, expr.consequent.value) : hoistClassNames(path2, expr.consequent),
305
+ alt = t.isStringLiteral(expr.alternate) ? hoistClassName(path2, expr.alternate.value) : hoistClassNames(path2, expr.alternate);
306
+ return t.conditionalExpression(expr.test, cons, alt);
307
+ }
308
+ return expr;
309
+ }
310
+ function hoistClassName(path2, str) {
311
+ const uid = path2.scope.generateUidIdentifier("cn"),
312
+ parent = path2.findParent(path3 => path3.isProgram());
313
+ if (!parent) throw new Error("no program?");
314
+ const variable = t.variableDeclaration("const", [t.variableDeclarator(uid, t.stringLiteral(cleanupClassName(str)))]);
315
+ return parent.unshiftContainer("body", variable), uid;
316
+ }
317
+ function cleanupClassName(inStr) {
318
+ const out = /* @__PURE__ */new Set();
319
+ for (const part of inStr.split(" ")) !part || part === " " || part !== "font_" && out.add(part);
320
+ return [...out].join(" ");
321
+ }
@@ -0,0 +1,266 @@
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 extractToNative_exports = {};
33
+ __export(extractToNative_exports, {
34
+ extractToNative: () => extractToNative,
35
+ getBabelParseDefinition: () => getBabelParseDefinition,
36
+ getBabelPlugin: () => getBabelPlugin
37
+ });
38
+ module.exports = __toCommonJS(extractToNative_exports);
39
+ var import_core = require("@babel/core"),
40
+ import_generator = __toESM(require("@babel/generator")),
41
+ import_helper_plugin_utils = require("@babel/helper-plugin-utils"),
42
+ import_parser = require("@babel/parser"),
43
+ import_template = __toESM(require("@babel/template")),
44
+ t = __toESM(require("@babel/types")),
45
+ import_node_path = require("node:path"),
46
+ import_getPragmaOptions = require("../getPragmaOptions.cjs"),
47
+ import_createExtractor = require("./createExtractor.cjs"),
48
+ import_createLogger = require("./createLogger.cjs"),
49
+ import_extractHelpers = require("./extractHelpers.cjs"),
50
+ import_literalToAst = require("./literalToAst.cjs"),
51
+ import_loadGui = require("./loadGui.cjs");
52
+ const importNativeView = (0, import_template.default)(`
53
+ const __ReactNativeView = require('react-native').View;
54
+ const __ReactNativeText = require('react-native').Text;
55
+ `),
56
+ importStyleSheet = (0, import_template.default)(`
57
+ const __ReactNativeStyleSheet = require('react-native').StyleSheet;
58
+ `),
59
+ importWithStyle = import_template.default.ast("import { _withStableStyle } from '@hanzogui/core';"),
60
+ extractor = (0, import_createExtractor.createExtractor)({
61
+ platform: "native"
62
+ });
63
+ let guiBuildOptionsLoaded;
64
+ function extractToNative(sourceFileName, sourceCode, options) {
65
+ const ast = (0, import_parser.parse)(sourceCode, {
66
+ sourceType: "module",
67
+ plugins: ["jsx", "typescript"]
68
+ }),
69
+ babelPlugin = getBabelPlugin(),
70
+ out = (0, import_core.transformFromAstSync)(ast, sourceCode, {
71
+ plugins: [[babelPlugin, options]],
72
+ configFile: !1,
73
+ sourceFileName,
74
+ filename: sourceFileName
75
+ });
76
+ if (!out) throw new Error("No output returned");
77
+ return out;
78
+ }
79
+ function getBabelPlugin() {
80
+ return (0, import_helper_plugin_utils.declare)((api, options) => (api.assertVersion(7), getBabelParseDefinition(options)));
81
+ }
82
+ function getBabelParseDefinition(options) {
83
+ return {
84
+ name: "hanzo-gui",
85
+ visitor: {
86
+ Program: {
87
+ enter(root) {
88
+ let sourcePath = this.file.opts.filename;
89
+ if (sourcePath?.includes("node_modules") || !sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx")) return;
90
+ process.env.SOURCE_ROOT?.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
91
+ let hasImportedView = !1,
92
+ hasImportedViewWrapper = !1,
93
+ wrapperCount = 0;
94
+ const sheetStyles = {},
95
+ sheetIdentifier = root.scope.generateUidIdentifier("sheet"),
96
+ firstCommentContents =
97
+ // join because you can join together multiple pragmas
98
+ root.node.body[0]?.leadingComments?.map(comment => comment?.value || " ").join(" ") ?? "",
99
+ firstComment = firstCommentContents ? `//${firstCommentContents}` : "",
100
+ {
101
+ shouldPrintDebug,
102
+ shouldDisable
103
+ } = (0, import_getPragmaOptions.getPragmaOptions)({
104
+ source: firstComment,
105
+ path: sourcePath
106
+ });
107
+ if (shouldDisable) return;
108
+ !options.config && !options.components && (guiBuildOptionsLoaded ||= (0, import_loadGui.loadGuiBuildConfigSync)({}));
109
+ const finalOptions = {
110
+ // @ts-ignore just in case they leave it out
111
+ platform: "native",
112
+ ...guiBuildOptionsLoaded,
113
+ ...options
114
+ },
115
+ printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
116
+ function addSheetStyle(style, node) {
117
+ let key = `${`${Object.keys(sheetStyles).length}`}`;
118
+ if (process.env.NODE_ENV === "development") {
119
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
120
+ key += `:${(0, import_node_path.basename)(sourcePath)}:${lineNumbers}`;
121
+ }
122
+ return sheetStyles[key] = style, readStyleExpr(key);
123
+ }
124
+ function readStyleExpr(key) {
125
+ return (0, import_template.default)("SHEET['KEY']")({
126
+ SHEET: sheetIdentifier.name,
127
+ KEY: key
128
+ }).expression;
129
+ }
130
+ let res;
131
+ try {
132
+ res = extractor.parseSync(root, {
133
+ importsWhitelist: ["constants.js", "colors.js"],
134
+ excludeProps: /* @__PURE__ */new Set(["className", "userSelect", "whiteSpace", "textOverflow", "cursor", "contain"]),
135
+ // native props that should pass through without preventing extraction
136
+ inlineProps: /* @__PURE__ */new Set(["testID", "nativeID", "accessibilityLabel", "accessibilityHint", "accessibilityRole", "accessibilityState", "accessibilityValue", "accessibilityActions", "accessibilityLabelledBy", "accessibilityLiveRegion", "accessibilityElementsHidden", "accessibilityViewIsModal", "importantForAccessibility", "onAccessibilityAction", "onAccessibilityEscape", "onAccessibilityTap", "onMagicTap", "collapsable", "needsOffscreenAlphaCompositing", "removeClippedSubviews", "renderToHardwareTextureAndroid", "shouldRasterizeIOS", "hitSlop", "pointerEvents"]),
137
+ shouldPrintDebug,
138
+ ...finalOptions,
139
+ // disable extracting variables as no native concept of them (only theme values)
140
+ disableExtractVariables: !1,
141
+ sourcePath,
142
+ // disabling flattening for now
143
+ // it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
144
+ // thinking it's not really worth the effort to do much compilation on native
145
+ // for now just disable flatten as it can only run in narrow places on native
146
+ // disableFlattening: 'styled',
147
+ getFlattenedNode({
148
+ isTextView
149
+ }) {
150
+ return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
151
+ },
152
+ onExtractTag(props) {
153
+ assertValidTag(props.node);
154
+ const stylesExpr = t.arrayExpression([]),
155
+ hocStylesExpr = t.arrayExpression([]),
156
+ expressions = [],
157
+ finalAttrs = [],
158
+ themeKeysUsed = /* @__PURE__ */new Set();
159
+ function getStyleExpression(style) {
160
+ if (!style) return;
161
+ const {
162
+ plain,
163
+ themed
164
+ } = splitThemeStyles(style);
165
+ let themeExpr = null;
166
+ if (themed) {
167
+ for (const key in themed) themeKeysUsed.add(themed[key].split("$")[1]);
168
+ themeExpr = getThemedStyleExpression(themed);
169
+ }
170
+ const ident = addSheetStyle(plain, props.node);
171
+ return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
172
+ }
173
+ function addStyleExpression(expr, HOC = !1) {
174
+ Array.isArray(expr) ? (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr) : (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
175
+ }
176
+ function getThemedStyleExpression(styles) {
177
+ const themedStylesAst = (0, import_literalToAst.literalToAst)(styles);
178
+ return themedStylesAst.properties.forEach(_ => {
179
+ const prop = _;
180
+ if (prop.value.type === "StringLiteral") {
181
+ const propVal = prop.value.value.slice(1),
182
+ isComputed = !t.isValidIdentifier(propVal);
183
+ prop.value = t.callExpression(t.memberExpression(t.memberExpression(t.identifier("theme"), isComputed ? t.stringLiteral(propVal) : t.identifier(propVal), isComputed), t.identifier("get")), []);
184
+ }
185
+ }), themedStylesAst;
186
+ }
187
+ let hasDynamicStyle = !1;
188
+ for (const attr of props.attrs) switch (attr.type) {
189
+ case "style":
190
+ {
191
+ let styleExpr = getStyleExpression(attr.value);
192
+ addStyleExpression(styleExpr), addStyleExpression(styleExpr, !0);
193
+ break;
194
+ }
195
+ case "ternary":
196
+ {
197
+ const {
198
+ consequent,
199
+ alternate
200
+ } = attr.value,
201
+ consExpr = getStyleExpression(consequent),
202
+ altExpr = getStyleExpression(alternate);
203
+ expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0);
204
+ const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
205
+ addStyleExpression(styleExpr);
206
+ break;
207
+ }
208
+ case "attr":
209
+ {
210
+ t.isJSXSpreadAttribute(attr.value) && (0, import_extractHelpers.isSimpleSpread)(attr.value) && (stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style"))), hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")))), finalAttrs.push(attr.value);
211
+ break;
212
+ }
213
+ }
214
+ if (props.node.attributes = finalAttrs, themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
215
+ hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle), hasImportedViewWrapper = !0);
216
+ const name = props.flatNodeName || props.node.name.name,
217
+ wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`,
218
+ WrapperIdentifier = t.identifier(wrapperName),
219
+ WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
220
+ root.pushContainer("body", t.variableDeclaration("const", [t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("_withStableStyle"), [t.identifier(name), t.arrowFunctionExpression([t.identifier("theme"), t.identifier("_expressions")],
221
+ // return styles directly - no useMemo, theme changes must trigger style recalc
222
+ t.arrayExpression([...hocStylesExpr.elements]))]))])), props.node.name = WrapperJSXIdentifier, props.jsxPath.node.openingElement.name = WrapperJSXIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
223
+ } else props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
224
+ }
225
+ });
226
+ } catch (err) {
227
+ if (err instanceof Error) {
228
+ let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
229
+ message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Hanzo GUI parse, skipping", message, err.stack);
230
+ return;
231
+ }
232
+ }
233
+ if (!Object.keys(sheetStyles).length) {
234
+ shouldPrintDebug && console.info("END no styles"), res && printLog(res);
235
+ return;
236
+ }
237
+ const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles),
238
+ sheetOuter = (0, import_template.default)("const SHEET = __ReactNativeStyleSheet.create(null)")({
239
+ SHEET: sheetIdentifier.name
240
+ });
241
+ sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
242
+ -------- output code -------
243
+ `), console.info((0, import_generator.default)(root.parent).code.split(`
244
+ `).filter(x => !x.startsWith("//")).join(`
245
+ `))), res && printLog(res);
246
+ }
247
+ }
248
+ }
249
+ };
250
+ }
251
+ function assertValidTag(node) {
252
+ node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style") && process.env.DEBUG?.startsWith("@hanzo/gui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
253
+ }
254
+ function splitThemeStyles(style) {
255
+ const themed = {},
256
+ plain = {};
257
+ let noTheme = !0;
258
+ for (const key in style) {
259
+ const val = style[key];
260
+ val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
261
+ }
262
+ return {
263
+ themed: noTheme ? null : themed,
264
+ plain
265
+ };
266
+ }
@@ -0,0 +1,34 @@
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 findTopmostFunction_exports = {};
22
+ __export(findTopmostFunction_exports, {
23
+ findTopmostFunction: () => findTopmostFunction
24
+ });
25
+ module.exports = __toCommonJS(findTopmostFunction_exports);
26
+ function findTopmostFunction(jsxPath) {
27
+ const isFunction = path => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
28
+ let compFn = jsxPath.findParent(isFunction);
29
+ for (; compFn;) {
30
+ const parent = compFn.findParent(isFunction);
31
+ if (parent) compFn = parent;else break;
32
+ }
33
+ return compFn || null;
34
+ }
@@ -0,0 +1,47 @@
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 generatedUid_exports = {};
33
+ __export(generatedUid_exports, {
34
+ generateUid: () => generateUid
35
+ });
36
+ module.exports = __toCommonJS(generatedUid_exports);
37
+ var t = __toESM(require("@babel/types"));
38
+ function generateUid(scope, name) {
39
+ if (typeof scope != "object") throw "generateUid expects a scope object as its first parameter";
40
+ if (!(typeof name == "string" && name !== "")) throw "generateUid expects a valid name as its second parameter";
41
+ name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
42
+ let uid,
43
+ i = 0;
44
+ do i > 1 ? uid = name + i : uid = name, i++; while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
45
+ const program = scope.getProgramParent();
46
+ return program.references[uid] = !0, program.uids[uid] = !0, uid;
47
+ }