@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.2

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 (210) hide show
  1. package/CHANGELOG.md +597 -0
  2. package/LICENSE +21 -0
  3. package/README.md +292 -2
  4. package/README.zh-CN.md +307 -0
  5. package/SKILL.md +261 -0
  6. package/cordis.patch.yml +9 -0
  7. package/demo-prompts.md +118 -0
  8. package/lib/assets/echarts-core.js +43 -0
  9. package/lib/assets/echarts-full.js +72 -0
  10. package/lib/assets/mermaid.js +3591 -0
  11. package/lib/assets/standalone-runtime.js +1506 -0
  12. package/lib/assets/three.js +3844 -0
  13. package/lib/client.js +405 -0
  14. package/lib/index.js +5187 -0
  15. package/lib/invariant.js +19 -0
  16. package/lib/types/client/EChartNode.d.ts +13 -0
  17. package/lib/types/client/ErrorBoundary.d.ts +30 -0
  18. package/lib/types/client/GenuiBlock.d.ts +9 -0
  19. package/lib/types/client/PlotBlock.d.ts +44 -0
  20. package/lib/types/client/TemplateDrawer.d.ts +7 -0
  21. package/lib/types/client/achievement-store.d.ts +35 -0
  22. package/lib/types/client/achievement-toast.d.ts +2 -0
  23. package/lib/types/client/achievements.d.ts +63 -0
  24. package/lib/types/client/action-context.d.ts +7 -0
  25. package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
  26. package/lib/types/client/artifact/create.d.ts +5 -0
  27. package/lib/types/client/artifact/download.d.ts +9 -0
  28. package/lib/types/client/artifact/html.d.ts +5 -0
  29. package/lib/types/client/artifact/index.d.ts +8 -0
  30. package/lib/types/client/artifact/json.d.ts +3 -0
  31. package/lib/types/client/artifact/parse.d.ts +3 -0
  32. package/lib/types/client/artifact/portability.d.ts +4 -0
  33. package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
  34. package/lib/types/client/artifact/types.d.ts +33 -0
  35. package/lib/types/client/asset-echarts-core.d.ts +1 -0
  36. package/lib/types/client/asset-echarts.d.ts +17 -0
  37. package/lib/types/client/asset-loader.d.ts +33 -0
  38. package/lib/types/client/asset-mermaid.d.ts +1 -0
  39. package/lib/types/client/asset-three.d.ts +1 -0
  40. package/lib/types/client/blocks/advanced.d.ts +101 -0
  41. package/lib/types/client/blocks/basic.d.ts +22 -0
  42. package/lib/types/client/blocks/charts.d.ts +53 -0
  43. package/lib/types/client/blocks/checkbox.d.ts +17 -0
  44. package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
  45. package/lib/types/client/blocks/diagram/index.d.ts +5 -0
  46. package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
  47. package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
  48. package/lib/types/client/blocks/forms.d.ts +77 -0
  49. package/lib/types/client/blocks/image.d.ts +6 -0
  50. package/lib/types/client/blocks/render-node.d.ts +10 -0
  51. package/lib/types/client/blocks/state.d.ts +63 -0
  52. package/lib/types/client/blocks/svg.d.ts +4 -0
  53. package/lib/types/client/dom-fence.d.ts +30 -0
  54. package/lib/types/client/echarts-engine.d.ts +4 -0
  55. package/lib/types/client/echarts-lazy.d.ts +18 -0
  56. package/lib/types/client/embed.d.ts +10 -0
  57. package/lib/types/client/fence-render.d.ts +106 -0
  58. package/lib/types/client/gallery.d.ts +7 -0
  59. package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
  60. package/lib/types/client/genui-runtime/index.d.ts +1 -0
  61. package/lib/types/client/genui-runtime/limits.d.ts +54 -0
  62. package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
  63. package/lib/types/client/genui-runtime/schema.d.ts +87 -0
  64. package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
  65. package/lib/types/client/guard.d.ts +144 -0
  66. package/lib/types/client/i18n/en.d.ts +307 -0
  67. package/lib/types/client/i18n/index.d.ts +44 -0
  68. package/lib/types/client/i18n/runtime.d.ts +64 -0
  69. package/lib/types/client/i18n/zh.d.ts +8 -0
  70. package/lib/types/client/index.d.ts +36 -0
  71. package/lib/types/client/inline.d.ts +5 -0
  72. package/lib/types/client/interaction-store.d.ts +48 -0
  73. package/lib/types/client/mermaid-core.d.ts +8 -0
  74. package/lib/types/client/mermaid-lazy.d.ts +9 -0
  75. package/lib/types/client/mermaid-safe.d.ts +52 -0
  76. package/lib/types/client/panel-command.d.ts +34 -0
  77. package/lib/types/client/panel-store.d.ts +94 -0
  78. package/lib/types/client/panel.d.ts +18 -0
  79. package/lib/types/client/parse-partial.d.ts +63 -0
  80. package/lib/types/client/primitive-adapter.d.ts +4 -0
  81. package/lib/types/client/primitive-labels.d.ts +18 -0
  82. package/lib/types/client/safe-math.d.ts +43 -0
  83. package/lib/types/client/scene3d-core.d.ts +21 -0
  84. package/lib/types/client/scene3d-lazy.d.ts +8 -0
  85. package/lib/types/client/session-resolver.d.ts +8 -0
  86. package/lib/types/client/source-fence.d.ts +29 -0
  87. package/lib/types/client/spec.d.ts +709 -0
  88. package/lib/types/client/standalone/asset-loader.d.ts +2 -0
  89. package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
  90. package/lib/types/client/standalone/katex-style.d.ts +1 -0
  91. package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
  92. package/lib/types/client/standalone/runtime.d.ts +2 -0
  93. package/lib/types/client/submission-registry.d.ts +51 -0
  94. package/lib/types/client/svg-fence.d.ts +2 -0
  95. package/lib/types/client/table-details.d.ts +20 -0
  96. package/lib/types/client/templates.d.ts +41 -0
  97. package/lib/types/client/toolview.d.ts +7 -0
  98. package/lib/types/client/walk-spec.d.ts +3 -0
  99. package/lib/types/index.d.ts +1 -0
  100. package/lib/types/plugin/chart-contract.d.ts +9 -0
  101. package/lib/types/plugin/fence-feedback.d.ts +151 -0
  102. package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
  103. package/lib/types/plugin/index.d.ts +35 -0
  104. package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
  105. package/lib/types/plugin/invariant.d.ts +15 -0
  106. package/lib/types/plugin/tool.d.ts +27 -0
  107. package/lib/types/shared/fence-repair.d.ts +78 -0
  108. package/lib/types/shared/fence-resolve.d.ts +39 -0
  109. package/package.json +249 -4
  110. package/src/client/EChartNode.tsx +466 -0
  111. package/src/client/ErrorBoundary.tsx +67 -0
  112. package/src/client/GenuiBlock.module.css +2221 -0
  113. package/src/client/GenuiBlock.tsx +235 -0
  114. package/src/client/PlotBlock.module.css +171 -0
  115. package/src/client/PlotBlock.tsx +492 -0
  116. package/src/client/TemplateDrawer.module.css +152 -0
  117. package/src/client/TemplateDrawer.tsx +147 -0
  118. package/src/client/achievement-store.ts +151 -0
  119. package/src/client/achievement-toast.tsx +71 -0
  120. package/src/client/achievements.ts +160 -0
  121. package/src/client/action-context.ts +32 -0
  122. package/src/client/artifact/ArtifactExport.module.css +64 -0
  123. package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
  124. package/src/client/artifact/create.ts +69 -0
  125. package/src/client/artifact/download.ts +42 -0
  126. package/src/client/artifact/html.ts +157 -0
  127. package/src/client/artifact/index.ts +15 -0
  128. package/src/client/artifact/json.ts +6 -0
  129. package/src/client/artifact/parse.ts +32 -0
  130. package/src/client/artifact/portability.ts +47 -0
  131. package/src/client/artifact/standalone-theme.ts +94 -0
  132. package/src/client/artifact/types.ts +44 -0
  133. package/src/client/asset-echarts-core.ts +39 -0
  134. package/src/client/asset-echarts.ts +27 -0
  135. package/src/client/asset-loader.ts +96 -0
  136. package/src/client/asset-mermaid.ts +13 -0
  137. package/src/client/asset-three.ts +12 -0
  138. package/src/client/blocks/advanced.tsx +537 -0
  139. package/src/client/blocks/basic.tsx +121 -0
  140. package/src/client/blocks/charts.tsx +999 -0
  141. package/src/client/blocks/checkbox.tsx +61 -0
  142. package/src/client/blocks/diagram/geometry.ts +151 -0
  143. package/src/client/blocks/diagram/index.tsx +293 -0
  144. package/src/client/blocks/diagram/layout.ts +202 -0
  145. package/src/client/blocks/diagram/theme.ts +127 -0
  146. package/src/client/blocks/forms.tsx +531 -0
  147. package/src/client/blocks/image.tsx +28 -0
  148. package/src/client/blocks/render-node.tsx +494 -0
  149. package/src/client/blocks/state.ts +65 -0
  150. package/src/client/blocks/svg.tsx +66 -0
  151. package/src/client/dom-fence.tsx +1123 -0
  152. package/src/client/echarts-engine.ts +9 -0
  153. package/src/client/echarts-lazy.ts +41 -0
  154. package/src/client/embed.ts +19 -0
  155. package/src/client/fence-render.tsx +266 -0
  156. package/src/client/gallery.ts +215 -0
  157. package/src/client/genui-runtime/diagnostics.ts +165 -0
  158. package/src/client/genui-runtime/index.ts +1 -0
  159. package/src/client/genui-runtime/limits.ts +54 -0
  160. package/src/client/genui-runtime/normalize.ts +329 -0
  161. package/src/client/genui-runtime/schema.ts +352 -0
  162. package/src/client/genui-runtime/value-utils.ts +67 -0
  163. package/src/client/guard.ts +1965 -0
  164. package/src/client/i18n/en.ts +335 -0
  165. package/src/client/i18n/index.ts +125 -0
  166. package/src/client/i18n/runtime.ts +130 -0
  167. package/src/client/i18n/zh.ts +330 -0
  168. package/src/client/index.tsx +228 -0
  169. package/src/client/inline.ts +106 -0
  170. package/src/client/interaction-store.ts +127 -0
  171. package/src/client/mermaid-core.ts +158 -0
  172. package/src/client/mermaid-lazy.ts +31 -0
  173. package/src/client/mermaid-safe.ts +122 -0
  174. package/src/client/panel-command.ts +138 -0
  175. package/src/client/panel-store.ts +471 -0
  176. package/src/client/panel.tsx +287 -0
  177. package/src/client/parse-partial.ts +170 -0
  178. package/src/client/primitive-adapter.ts +13 -0
  179. package/src/client/primitive-labels.ts +55 -0
  180. package/src/client/safe-math.ts +298 -0
  181. package/src/client/scene3d-core.ts +195 -0
  182. package/src/client/scene3d-lazy.ts +26 -0
  183. package/src/client/session-resolver.ts +33 -0
  184. package/src/client/source-fence.ts +70 -0
  185. package/src/client/spec.ts +896 -0
  186. package/src/client/standalone/asset-loader.ts +9 -0
  187. package/src/client/standalone/bootstrap-types.ts +11 -0
  188. package/src/client/standalone/katex-style.ts +1 -0
  189. package/src/client/standalone/primitive-adapter.tsx +94 -0
  190. package/src/client/standalone/runtime.tsx +27 -0
  191. package/src/client/submission-registry.ts +150 -0
  192. package/src/client/svg-fence.tsx +39 -0
  193. package/src/client/table-details.ts +151 -0
  194. package/src/client/templates.ts +322 -0
  195. package/src/client/toolview.tsx +67 -0
  196. package/src/client/walk-spec.ts +43 -0
  197. package/src/css-modules.d.ts +5 -0
  198. package/src/index.ts +9 -0
  199. package/src/plugin/chart-contract.ts +13 -0
  200. package/src/plugin/fence-feedback.ts +655 -0
  201. package/src/plugin/genui-diagnostic.ts +112 -0
  202. package/src/plugin/index.ts +224 -0
  203. package/src/plugin/inline-content-diagnostic.ts +178 -0
  204. package/src/plugin/invariant.ts +30 -0
  205. package/src/plugin/node-shims.d.ts +31 -0
  206. package/src/plugin/tool.ts +424 -0
  207. package/src/shared/fence-repair.ts +536 -0
  208. package/src/shared/fence-resolve.ts +80 -0
  209. package/tsconfig.json +35 -0
  210. package/tsdown.config.ts +275 -0
@@ -0,0 +1,275 @@
1
+ /**
2
+ * dsh-genui build: node-half lib (host plugin, prompt injection) + browser
3
+ * client bundle (the dsh-ui renderer) speaking the dsh module-loader
4
+ * protocol (`window.__ModuleLoader__.load`). Mirrors the dsh repo's
5
+ * packages/client/tsdown.client.ts preset, simplified for one package.
6
+ *
7
+ * Deterministic output: the CSS Modules class map is emitted in fixed
8
+ * UTF-16 local-name order (never localeCompare — system-locale drift), and
9
+ * the production browser bundle carries no sourcemap, so the same source
10
+ * builds byte-identical client.js every time.
11
+ */
12
+ import { readFile } from 'node:fs/promises'
13
+ import { basename, dirname, extname, relative, resolve as resolvePath } from 'node:path'
14
+ import { fileURLToPath } from 'node:url'
15
+ import type { UserConfig } from 'tsdown'
16
+ import { transform } from 'lightningcss'
17
+
18
+ const ID = '@sparkelf/dsh-genui'
19
+ const PROJECT_ROOT = dirname(fileURLToPath(import.meta.url))
20
+
21
+ /** Module-table entries this bundle may leave external: platform seed rows
22
+ * (react family, cordis, ui-primitives) answered by the loader's require.
23
+ * `react-dom/client` joins the list for the DOM render channel (pure-plugin
24
+ * fence rendering on pristine hosts mounts its own React roots). */
25
+ const EXTERNALS = [
26
+ 'react', 'react/jsx-runtime', 'react-dom/client', '@deepseek-ai/cordis', '@deepseek-ai/dsh-client-ui-primitives',
27
+ ]
28
+
29
+ const CSS_VIRTUAL_PREFIX = '\0dsh-css:'
30
+ const CSS_VIRTUAL_SUFFIX = '.mjs'
31
+
32
+
33
+ function cssModulesPlugin(): NonNullable<UserConfig['plugins']>[number] {
34
+ return {
35
+ name: 'dsh-css-modules-inline',
36
+ resolveId(source: string, importer: string | undefined) {
37
+ if (!source.endsWith('.module.css')) return null
38
+ // The bundle builds straight from src, so the importer's directory is
39
+ // always the source tree — no lib/types backtracking needed.
40
+ const abs = importer !== undefined ? resolvePath(dirname(importer), source) : source
41
+ const stableId = relative(PROJECT_ROOT, abs).replaceAll('\\', '/')
42
+ return CSS_VIRTUAL_PREFIX + stableId + CSS_VIRTUAL_SUFFIX
43
+ },
44
+ async load(virtualId: string) {
45
+ if (!virtualId.startsWith(CSS_VIRTUAL_PREFIX)) return null
46
+ const stableId = virtualId.slice(CSS_VIRTUAL_PREFIX.length, -CSS_VIRTUAL_SUFFIX.length)
47
+ const fileId = resolvePath(PROJECT_ROOT, stableId)
48
+ this.addWatchFile(fileId)
49
+ const source = await readFile(fileId)
50
+ const { code, exports: cssExports } = transform({
51
+ filename: stableId,
52
+ code: source,
53
+ cssModules: { pattern: '[hash]_[local]' },
54
+ minify: true,
55
+ })
56
+ // Deterministic key order: fixed UTF-16 comparison on the LOCAL class
57
+ // names (localeCompare depends on the system locale). Values unchanged.
58
+ const entries = Object.entries(cssExports ?? {})
59
+ .map(([local, exp]) => [local, exp.name] as const)
60
+ .sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
61
+ const classMap = Object.fromEntries(entries)
62
+ const tagId = `${ID}/${basename(fileId)}`
63
+ return [
64
+ `const css = ${JSON.stringify(code.toString())};`,
65
+ `const tagId = ${JSON.stringify(tagId)};`,
66
+ `if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css=' + JSON.stringify(tagId) + ']') === null) {`,
67
+ ` const tag = document.createElement('style');`,
68
+ ` tag.dataset.plugin = ${JSON.stringify(ID)};`,
69
+ ' tag.dataset.pluginCss = tagId;',
70
+ ' tag.textContent = css;',
71
+ ' document.head.appendChild(tag);',
72
+ '}',
73
+ `export default ${JSON.stringify(classMap)};`,
74
+ ].join('\n')
75
+ },
76
+ }
77
+ }
78
+
79
+ function purityGate(): NonNullable<UserConfig['plugins']>[number] {
80
+ return {
81
+ name: 'dsh-client-bundle-purity',
82
+ resolveId(source: string) {
83
+ if (!source.startsWith('@deepseek-ai/')) return null
84
+ if (EXTERNALS.includes(source)) return null
85
+ throw new Error(
86
+ `client bundle purity: "${source}" is not in the module table (EXTERNALS) — `
87
+ + 'cross-plugin value imports are forbidden; collaborate through cordis services',
88
+ )
89
+ },
90
+ }
91
+ }
92
+
93
+ function standaloneAliasPlugin(): NonNullable<UserConfig['plugins']>[number] {
94
+ const adapterPath = resolvePath(PROJECT_ROOT, 'src/client/primitive-adapter.ts')
95
+ const standaloneAdapterPath = resolvePath(PROJECT_ROOT, 'src/client/standalone/primitive-adapter.tsx')
96
+ const assetLoaderPath = resolvePath(PROJECT_ROOT, 'src/client/asset-loader.ts')
97
+ const standaloneAssetLoaderPath = resolvePath(PROJECT_ROOT, 'src/client/standalone/asset-loader.ts')
98
+ return {
99
+ name: 'dsh-genui-standalone-primitives',
100
+ resolveId(source: string, importer: string | undefined) {
101
+ if (importer === undefined) return null
102
+ const resolved = resolvePath(dirname(importer), source)
103
+ if (resolved === adapterPath) return standaloneAdapterPath
104
+ return resolved === assetLoaderPath ? standaloneAssetLoaderPath : null
105
+ },
106
+ }
107
+ }
108
+
109
+ function standaloneKatexCssPlugin(): NonNullable<UserConfig['plugins']>[number] {
110
+ const sourcePath = resolvePath(PROJECT_ROOT, 'src/client/standalone/katex-style.ts')
111
+ const virtualId = '\0dsh-genui-standalone-katex'
112
+ const cssPath = resolvePath(PROJECT_ROOT, 'node_modules/katex/dist/katex.min.css')
113
+ return {
114
+ name: 'dsh-genui-standalone-katex',
115
+ resolveId(source: string, importer: string | undefined) {
116
+ if (importer !== undefined && resolvePath(dirname(importer), source) === sourcePath) return virtualId
117
+ return null
118
+ },
119
+ async load(id: string) {
120
+ if (id !== virtualId) return null
121
+ const transformed = transform({
122
+ filename: cssPath,
123
+ code: await readFile(cssPath),
124
+ analyzeDependencies: true,
125
+ visitor: {
126
+ Rule: {
127
+ /** 独立 HTML 面向支持 WOFF2 的浏览器,每种字体只需内嵌一份。 */
128
+ 'font-face'(rule) {
129
+ const source = rule.value.properties.find(property => property.type === 'source')
130
+ if (source === undefined) throw new Error('KaTeX font face has no source')
131
+ const woff2 = source.value.filter(entry => entry.type === 'url' && entry.value.format?.type === 'woff2')
132
+ if (woff2.length !== 1) throw new Error('KaTeX font face must have exactly one WOFF2 source')
133
+ source.value = woff2
134
+ return rule
135
+ },
136
+ },
137
+ },
138
+ })
139
+ let css = transformed.code.toString()
140
+ for (const dependency of transformed.dependencies ?? []) {
141
+ if (dependency.type !== 'url' || dependency.url.startsWith('data:') || dependency.url.startsWith('#')) continue
142
+ const fontPath = resolvePath(dirname(cssPath), dependency.url)
143
+ const extension = extname(new URL(dependency.url, 'https://genui.invalid/').pathname)
144
+ if (extension !== '.woff2') throw new Error(`unsupported KaTeX asset: ${dependency.url}`)
145
+ const font = await readFile(fontPath)
146
+ css = css.replaceAll(dependency.placeholder, `data:font/woff2;base64,${font.toString('base64')}`)
147
+ }
148
+ return `const style = document.createElement('style'); style.dataset.genuiStandaloneKatex = ''; style.textContent = ${JSON.stringify(css)}; document.head.appendChild(style);`
149
+ },
150
+ }
151
+ }
152
+
153
+ const clientConfig: UserConfig = {
154
+ name: `${ID}/client`,
155
+ entry: { client: 'src/client/index.tsx' },
156
+ outDir: 'lib',
157
+ format: 'cjs',
158
+ platform: 'browser',
159
+ dts: false,
160
+ // Minified production bundles: the host serves plugin bytes uncompressed,
161
+ // so every byte counts at first-load time.
162
+ minify: true,
163
+ // No sourcemap in the production bundle: nothing ships the map, nothing
164
+ // rewrites paths, builds are byte-identical.
165
+ sourcemap: false,
166
+ clean: false,
167
+ deps: {
168
+ neverBundle: [...EXTERNALS],
169
+ alwaysBundle: (id: string) => !EXTERNALS.includes(id),
170
+ },
171
+ define: {
172
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
173
+ 'import.meta.env.MODE': JSON.stringify(process.env.NODE_ENV ?? 'production'),
174
+ 'import.meta.env': JSON.stringify({ MODE: process.env.NODE_ENV ?? 'production' }),
175
+ },
176
+ plugins: [purityGate(), cssModulesPlugin()],
177
+ outputOptions: {
178
+ entryFileNames: 'client.js',
179
+ // The loader fetches one script per plugin; the lazy mermaid/three
180
+ // engines are NOT part of this bundle anymore — they ship as standalone
181
+ // IIFE assets under lib/assets/, fetched on demand by the runtime loaders
182
+ // (see asset-loader.ts). Nothing heavy may re-enter this bundle.
183
+ codeSplitting: false,
184
+ banner: `window.__ModuleLoader__.load({ id: ${JSON.stringify(ID)}, factory: (require) => {`,
185
+ footer: 'return module.exports; } });',
186
+ intro: 'var module = { exports: {} }; var exports = module.exports;',
187
+ },
188
+ }
189
+
190
+ const standaloneConfig: UserConfig = {
191
+ name: `${ID}/standalone`,
192
+ entry: { 'assets/standalone-runtime': 'src/client/standalone/runtime.tsx' },
193
+ outDir: 'lib',
194
+ format: 'iife',
195
+ platform: 'browser',
196
+ dts: false,
197
+ minify: true,
198
+ sourcemap: false,
199
+ clean: false,
200
+ deps: { alwaysBundle: () => true },
201
+ define: {
202
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
203
+ 'import.meta.env.MODE': JSON.stringify(process.env.NODE_ENV ?? 'production'),
204
+ 'import.meta.env': JSON.stringify({ MODE: process.env.NODE_ENV ?? 'production' }),
205
+ },
206
+ plugins: [standaloneAliasPlugin(), cssModulesPlugin(), standaloneKatexCssPlugin()],
207
+ outputOptions: { entryFileNames: '[name].js', codeSplitting: false },
208
+ }
209
+
210
+ /**
211
+ * Lazy engine assets: mermaid and three ship as standalone single-entry
212
+ * IIFEs that register themselves on `window.__GenuiAssets__` (no
213
+ * module-loader protocol — the loaders read the global directly after script
214
+ * injection). Two configs because rolldown refuses IIFE with multiple
215
+ * entries; each bundle is fully independent (no cross-entry chunks). The
216
+ * main client bundle never contains either engine, so the eager download
217
+ * drops from ~9 MB to the small renderer core.
218
+ */
219
+ function assetConfig(name: 'mermaid' | 'three' | 'echarts', entry: string): UserConfig {
220
+ return {
221
+ name: `${ID}/assets/${name}`,
222
+ entry: { [`assets/${name}`]: entry },
223
+ outDir: 'lib',
224
+ format: 'iife',
225
+ platform: 'browser',
226
+ dts: false,
227
+ // Minified: these engines are huge unminified (6.7 MB / 1.8 MB) and the
228
+ // host serves uncompressed bytes; on-demand loads still want them small.
229
+ minify: true,
230
+ sourcemap: false,
231
+ clean: false,
232
+ deps: {
233
+ neverBundle: [...EXTERNALS],
234
+ alwaysBundle: (id: string) => !EXTERNALS.includes(id),
235
+ },
236
+ define: {
237
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
238
+ },
239
+ plugins: [purityGate()],
240
+ outputOptions: {
241
+ entryFileNames: '[name].js',
242
+ },
243
+ }
244
+ }
245
+
246
+ const libConfig: UserConfig = {
247
+ name: ID,
248
+ // Named entries keep the published layout stable (lib/index.js +
249
+ // lib/invariant.js) while src/index.ts becomes the canonical bundle
250
+ // source entry that plugin_check's tool-bundle contract expects.
251
+ entry: { index: 'src/index.ts', invariant: 'src/plugin/invariant.ts' },
252
+ outDir: 'lib',
253
+ format: ['esm'],
254
+ platform: 'node',
255
+ target: 'es2024',
256
+ fixedExtension: false,
257
+ dts: false,
258
+ // Flatten entry outputs to lib/<basename>.js so package exports keep the
259
+ // stable paths lib/index.js + lib/invariant.js (a directory-mirroring
260
+ // default would emit lib/plugin/invariant.js).
261
+ outputOptions: { entryFileNames: '[name].js' },
262
+ // Cleanup happens in the build script (`rm -rf lib` before tsc): tsdown
263
+ // must never wipe lib/types (tsc's declaration output) mid-pipeline.
264
+ clean: false,
265
+ }
266
+
267
+ export default [
268
+ libConfig,
269
+ clientConfig,
270
+ standaloneConfig,
271
+ assetConfig('mermaid', 'src/client/asset-mermaid.ts'),
272
+ assetConfig('three', 'src/client/asset-three.ts'),
273
+ assetConfig('echarts-core', 'src/client/asset-echarts-core.ts'),
274
+ assetConfig('echarts-full', 'src/client/asset-echarts.ts'),
275
+ ]