@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,186 @@
1
+ import { dirname, join } from 'node:path'
2
+
3
+ import { generateThemes, writeGeneratedThemes } from '@hanzogui/generate-themes'
4
+ import type { GuiOptions } from '@hanzogui/types'
5
+ import * as FS from 'fs-extra'
6
+
7
+ import { requireGuiCore } from '../helpers/requireGuiCore'
8
+ import type { GuiPlatform } from '../types'
9
+ import type { BundledConfig } from './bundleConfig'
10
+ import { getBundledConfig } from './bundleConfig'
11
+
12
+ const guiDir = join(process.cwd(), '.gui')
13
+ const confFile = join(guiDir, 'gui.config.json')
14
+
15
+ /**
16
+ * Sort of a super-set of bundleConfig(), this code needs some refactoring ideally
17
+ */
18
+
19
+ export async function regenerateConfig(
20
+ guiOptions: GuiOptions,
21
+ configIn?: BundledConfig | null,
22
+ rebuild = false
23
+ ) {
24
+ try {
25
+ // this has a side effect of rebuilding config and css!
26
+ // need to improve code here:
27
+ const config = configIn ?? (await getBundledConfig(guiOptions, rebuild))
28
+ if (!config) return
29
+ const out = transformConfig(config, guiOptions.platform || 'web')
30
+
31
+ await FS.ensureDir(dirname(confFile))
32
+ await FS.writeJSON(confFile, out, {
33
+ spaces: 2,
34
+ })
35
+ } catch (err) {
36
+ if (process.env.DEBUG?.includes('@hanzo/gui') || process.env.IS_HANZO_GUI_DEV) {
37
+ console.warn('regenerateConfig error', err)
38
+ }
39
+ // ignore for now
40
+ }
41
+ }
42
+
43
+ export function regenerateConfigSync(
44
+ _guiOptions: GuiOptions,
45
+ config: BundledConfig
46
+ ) {
47
+ try {
48
+ FS.ensureDirSync(dirname(confFile))
49
+ FS.writeJSONSync(
50
+ confFile,
51
+ transformConfig(config, _guiOptions.platform || 'web'),
52
+ {
53
+ spaces: 2,
54
+ }
55
+ )
56
+ } catch (err) {
57
+ if (process.env.DEBUG?.includes('@hanzo/gui') || process.env.IS_HANZO_GUI_DEV) {
58
+ console.warn('regenerateConfig error', err)
59
+ }
60
+ // ignore for now
61
+ }
62
+ }
63
+
64
+ export async function generateGuiThemes(
65
+ guiOptions: GuiOptions,
66
+ force = false
67
+ ) {
68
+ if (!guiOptions.themeBuilder) {
69
+ return
70
+ }
71
+
72
+ const { input, output } = guiOptions.themeBuilder
73
+ const inPath = resolveRelativePath(input)
74
+ const outPath = resolveRelativePath(output)
75
+ const generatedOutput = await generateThemes(inPath)
76
+
77
+ // because this runs in parallel (its cheap) lets avoid logging a bunch, so check to see if changed:
78
+ const hasChanged =
79
+ force ||
80
+ (await (async () => {
81
+ try {
82
+ if (!generatedOutput) return false
83
+ const next = generatedOutput.generated
84
+ const current = await FS.readFile(outPath, 'utf-8')
85
+ return next !== current
86
+ } catch (err) {
87
+ // ok
88
+ }
89
+ return true
90
+ })())
91
+
92
+ if (hasChanged) {
93
+ await writeGeneratedThemes(guiDir, outPath, generatedOutput)
94
+ }
95
+
96
+ return hasChanged
97
+ }
98
+
99
+ const resolveRelativePath = (inputPath: string) =>
100
+ inputPath.startsWith('.') ? join(process.cwd(), inputPath) : require.resolve(inputPath)
101
+
102
+ function cloneDeepSafe(x: any, excludeKeys = {}) {
103
+ if (!x) return x
104
+ if (Array.isArray(x)) return x.map((_) => cloneDeepSafe(_))
105
+ if (typeof x === 'function') return `Function`
106
+ if (typeof x !== 'object') return x
107
+ if ('$$typeof' in x) return 'Component'
108
+ return Object.fromEntries(
109
+ Object.entries(x).flatMap(([k, v]) => (excludeKeys[k] ? [] : [[k, cloneDeepSafe(v)]]))
110
+ )
111
+ }
112
+
113
+ function transformConfig(config: BundledConfig, platform: GuiPlatform) {
114
+ if (!config) {
115
+ return null
116
+ }
117
+
118
+ const { getVariableValue } = requireGuiCore(platform)
119
+
120
+ // ensure we don't mangle anything in the original
121
+ const next = cloneDeepSafe(config, {
122
+ validStyles: true,
123
+ }) as BundledConfig
124
+
125
+ const { components, nameToPaths, guiConfig } = next
126
+ const { themes, tokens } = guiConfig
127
+
128
+ // reduce down to usable, smaller json
129
+
130
+ // slim themes, add name
131
+ for (const key in themes) {
132
+ const theme = themes[key]
133
+ // @ts-ignore
134
+ theme.id = key
135
+ for (const tkey in theme) {
136
+ theme[tkey] = getVariableValue(theme[tkey])
137
+ }
138
+ }
139
+
140
+ // flatten variables
141
+ for (const key in tokens) {
142
+ const token = { ...tokens[key] }
143
+ for (const tkey in token) {
144
+ token[tkey] = getVariableValue(token[tkey])
145
+ }
146
+ }
147
+
148
+ // remove bulky stuff in components
149
+ for (const component of components) {
150
+ for (const _ in component.nameToInfo) {
151
+ // avoid mutating
152
+ const compDefinition = { ...component.nameToInfo[_] }
153
+ component.nameToInfo[_] = compDefinition
154
+
155
+ const { parentStaticConfig, ...rest } = compDefinition.staticConfig
156
+ compDefinition.staticConfig = rest
157
+ }
158
+ }
159
+
160
+ // set to array
161
+ next.nameToPaths = {}
162
+ for (const key in nameToPaths) {
163
+ next.nameToPaths[key] = [...nameToPaths[key]]
164
+ }
165
+
166
+ // remove stuff we dont need to send
167
+ const {
168
+ fontsParsed,
169
+ getCSS,
170
+ tokensParsed,
171
+ themeConfig,
172
+ shorthands: _shorthands,
173
+ userShorthands,
174
+ ...cleanedConfig
175
+ } = next.guiConfig
176
+
177
+ return {
178
+ components,
179
+ nameToPaths,
180
+ guiConfig: {
181
+ ...cleanedConfig,
182
+ // Output userShorthands as shorthands (excludes built-ins)
183
+ shorthands: userShorthands,
184
+ },
185
+ }
186
+ }
@@ -0,0 +1,83 @@
1
+ import type { NodePath } from '@babel/traverse'
2
+ import * as t from '@babel/types'
3
+
4
+ const hooks = {
5
+ useMedia: true,
6
+ useTheme: true,
7
+ }
8
+
9
+ export function removeUnusedHooks(
10
+ compFn: NodePath<any>,
11
+ shouldPrintDebug: boolean | 'verbose'
12
+ ) {
13
+ compFn.scope.crawl()
14
+ // check the top level statements
15
+ let bodyStatements = compFn?.get('body')
16
+ if (!bodyStatements) {
17
+ console.info('no body statemnts?', compFn)
18
+ return
19
+ }
20
+ if (!Array.isArray(bodyStatements)) {
21
+ if (bodyStatements.isFunctionExpression()) {
22
+ bodyStatements = bodyStatements.scope.path.get('body')
23
+ } else {
24
+ bodyStatements = bodyStatements.get('body')
25
+ }
26
+ }
27
+ if (!bodyStatements || !Array.isArray(bodyStatements)) {
28
+ return
29
+ }
30
+ const statements = bodyStatements as NodePath<any>[]
31
+ for (const statement of statements) {
32
+ if (!statement.isVariableDeclaration()) {
33
+ continue
34
+ }
35
+ const declarations = statement.get('declarations')
36
+ if (!Array.isArray(declarations)) {
37
+ continue
38
+ }
39
+ const isBindingReferenced = (name: string) => {
40
+ return !!statement.scope.getBinding(name)?.referenced
41
+ }
42
+ for (const declarator of declarations) {
43
+ const id = declarator.get('id')
44
+ const init = declarator.node.init
45
+ if (Array.isArray(id) || Array.isArray(init)) {
46
+ continue
47
+ }
48
+ const shouldRemove = (() => {
49
+ const isHook =
50
+ init &&
51
+ t.isCallExpression(init) &&
52
+ t.isIdentifier(init.callee) &&
53
+ hooks[init.callee.name]
54
+ if (!isHook) {
55
+ return false
56
+ }
57
+ if (t.isIdentifier(id.node)) {
58
+ // remove "const media = useMedia()"
59
+ const name = id.node.name
60
+ return !isBindingReferenced(name)
61
+ }
62
+ if (t.isObjectPattern(id.node)) {
63
+ // remove "const { sm } = useMedia()"
64
+ const propPaths = id.get('properties') as NodePath<any>[]
65
+ return propPaths.every((prop) => {
66
+ if (!prop.isObjectProperty()) return false
67
+ const value = prop.get('value')
68
+ if (Array.isArray(value) || !value.isIdentifier()) return false
69
+ const name = value.node.name
70
+ return !isBindingReferenced(name)
71
+ })
72
+ }
73
+ return false
74
+ })()
75
+ if (shouldRemove) {
76
+ declarator.remove()
77
+ if (shouldPrintDebug) {
78
+ console.info(` [🪝] removed ${id.node['name'] ?? ''}`)
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,25 @@
1
+ export const timer = () => {
2
+ const start = Date.now()
3
+ let last = start
4
+ return {
5
+ mark: (name: string, print = false) => {
6
+ if (print) {
7
+ const took = Date.now() - last
8
+ last = Date.now()
9
+ console.info(`Time ${name}: ${took}ms`)
10
+ if (took > 10) {
11
+ console.info(' long timer')
12
+ }
13
+ }
14
+ },
15
+ done: (print = false) => {
16
+ if (print) {
17
+ const total = Date.now() - start
18
+ console.info(`Total time: ${total}ms`)
19
+ if (total > 50) {
20
+ console.info(' long timer')
21
+ }
22
+ }
23
+ },
24
+ }
25
+ }
@@ -0,0 +1,52 @@
1
+ export const validHTMLAttributes = {
2
+ // SVG attributes that should pass through untouched
3
+ fill: true,
4
+ stroke: true,
5
+ autocomplete: true,
6
+ style: true,
7
+ tabIndex: true,
8
+ contenteditable: true,
9
+ crossorigin: true,
10
+ dir: true,
11
+ draggable: true,
12
+ enctype: true,
13
+ formenctype: true,
14
+ formmethod: true,
15
+ formtarget: true,
16
+ inputmode: true,
17
+ kind: true,
18
+ link: true,
19
+ method: true,
20
+ preload: true,
21
+ referrerpolicy: true,
22
+ rel: true,
23
+ rev: true,
24
+ role: true,
25
+ sandbox: true,
26
+ shape: true,
27
+ spellcheck: true,
28
+ target: true,
29
+ translate: true,
30
+ type: true,
31
+ wrap: true,
32
+ 'aria-autocomplete': true,
33
+ 'aria-busy': true,
34
+ 'aria-checked': true,
35
+ 'aria-current': true,
36
+ 'aria-disabled': true,
37
+ 'aria-expanded': true,
38
+ 'aria-haspopup': true,
39
+ 'aria-hidden': true,
40
+ 'aria-invalid': true,
41
+ 'aria-polite': true,
42
+ 'aria-modal': true,
43
+ 'aria-multiline': true,
44
+ 'aria-multiselectable': true,
45
+ 'aria-orientation': true,
46
+ 'aria-pressed': true,
47
+ 'aria-readonly': true,
48
+ 'aria-relevant': true,
49
+ 'aria-required': true,
50
+ 'aria-selected': true,
51
+ 'aria-sort': true,
52
+ }
@@ -0,0 +1,57 @@
1
+ import type { GuiOptions } from '@hanzogui/types'
2
+ import { esbuildWatchFiles, generateThemesAndLog, getOptions } from './loadGui'
3
+ import { regenerateConfig } from './regenerateConfig'
4
+
5
+ let isWatching = false
6
+
7
+ export async function watchGuiConfig(guiOptions: GuiOptions) {
8
+ if (process.env.NODE_ENV === 'production') {
9
+ return {
10
+ dispose() {},
11
+ }
12
+ }
13
+
14
+ if (isWatching) {
15
+ return
16
+ }
17
+
18
+ isWatching = true
19
+
20
+ const options = await getOptions({ guiOptions })
21
+
22
+ if (!options.guiOptions.config) {
23
+ isWatching = false
24
+ throw new Error(`No config`)
25
+ }
26
+
27
+ const disposeConfigWatcher = await esbuildWatchFiles(
28
+ options.guiOptions.config,
29
+ async () => {
30
+ await generateThemesAndLog(options.guiOptions)
31
+ await regenerateConfig(options.guiOptions, null, true)
32
+ }
33
+ )
34
+
35
+ const themeBuilderInput = options.guiOptions.themeBuilder?.input
36
+ let disposeThemesWatcher: Function | undefined
37
+
38
+ if (themeBuilderInput) {
39
+ let inputPath = themeBuilderInput
40
+ try {
41
+ inputPath = require.resolve(themeBuilderInput)
42
+ } catch {
43
+ // ok
44
+ }
45
+ disposeThemesWatcher = await esbuildWatchFiles(inputPath, async () => {
46
+ await generateThemesAndLog(options.guiOptions)
47
+ })
48
+ }
49
+
50
+ return {
51
+ dispose() {
52
+ isWatching = false
53
+ disposeConfigWatcher()
54
+ disposeThemesWatcher?.()
55
+ },
56
+ }
57
+ }
@@ -0,0 +1,57 @@
1
+ export function getPragmaOptions({ source, path }: { source: string; path: string }) {
2
+ let shouldPrintDebug: boolean | 'verbose' = false
3
+ let shouldDisable = false
4
+
5
+ // try and avoid too much parsing but sometimes esbuild adds helpers above..
6
+ const firstLines = source.slice(0, 800)
7
+
8
+ let pragma = ''
9
+ for (const line of firstLines.split('\n')) {
10
+ const trimmed = line.trim()
11
+ // only look at leading comments/empty lines, stop at first real code
12
+ if (trimmed && !trimmed.startsWith('//') && !trimmed.startsWith('/*')) {
13
+ break
14
+ }
15
+ pragma =
16
+ trimmed
17
+ .match(/(\/\/|\/\*)\s?!?\s?(gui-ignore|debug|debug-verbose)(\n|\s|$).*/)?.[2]
18
+ .trim() || ''
19
+ if (pragma) {
20
+ pragma = pragma.replace('!', '').trim()
21
+ break
22
+ }
23
+ }
24
+
25
+ switch (pragma) {
26
+ case 'gui-ignore':
27
+ shouldDisable = true
28
+ break
29
+
30
+ case 'debug':
31
+ shouldPrintDebug = true
32
+ break
33
+
34
+ case 'debug-verbose':
35
+ shouldPrintDebug = 'verbose'
36
+ break
37
+ }
38
+
39
+ if (process.env.HANZO_GUI_DEBUG_FILE) {
40
+ if (path.includes(process.env.HANZO_GUI_DEBUG_FILE)) {
41
+ shouldPrintDebug = 'verbose'
42
+ }
43
+ }
44
+
45
+ if (process.env.DEBUG?.includes('@hanzo/gui')) {
46
+ shouldPrintDebug ||= true
47
+ }
48
+
49
+ if (process.env.DEBUG?.includes('gui-verbose')) {
50
+ shouldPrintDebug = 'verbose'
51
+ }
52
+
53
+ return {
54
+ shouldPrintDebug,
55
+ shouldDisable,
56
+ }
57
+ }
@@ -0,0 +1,24 @@
1
+ // @ts-nocheck
2
+ export function memoize(func?: Function, resolver?: any) {
3
+ if (
4
+ typeof func !== 'function' ||
5
+ (resolver != null && typeof resolver !== 'function')
6
+ ) {
7
+ throw new TypeError('Expected a function')
8
+ }
9
+ const memoized = function (...args) {
10
+ const key = resolver ? resolver.apply(this, args) : args[0]
11
+ const cache = memoized.cache
12
+
13
+ if (cache.has(key)) {
14
+ return cache.get(key)
15
+ }
16
+ const result = func.apply(this, args)
17
+ memoized.cache = cache.set(key, result) || cache
18
+ return result
19
+ }
20
+ memoized.cache = new (memoize.Cache || Map)()
21
+ return memoized
22
+ }
23
+
24
+ memoize.Cache = Map
@@ -0,0 +1,28 @@
1
+ // this allows us to swap between core native and web in the same process:
2
+
3
+ import type { GuiPlatform } from '../types'
4
+
5
+ export function requireGuiCore(
6
+ platform: GuiPlatform,
7
+ ogRequire: Function = require
8
+ ): typeof import('@hanzogui/core') {
9
+ if (!platform) {
10
+ throw new Error(`No platform given to requireGuiCore`)
11
+ }
12
+
13
+ // avoid tree shaking out themes
14
+ const og1 = process.env.HANZO_GUI_IS_SERVER
15
+ const og2 = process.env.HANZO_GUI_KEEP_THEMES
16
+ process.env.HANZO_GUI_IS_SERVER ||= '1'
17
+ process.env.HANZO_GUI_KEEP_THEMES ||= '1'
18
+
19
+ const exported = ogRequire(
20
+ platform === 'native' ? '@hanzogui/core/native' : '@hanzogui/core'
21
+ )
22
+
23
+ // restore back
24
+ process.env.HANZO_GUI_IS_SERVER = og1
25
+ process.env.HANZO_GUI_KEEP_THEMES = og2
26
+
27
+ return exported
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ // cjs/esm interop
2
+ import * as Static1 from './exports'
3
+ export * from './exports'
4
+ export default Static1