@melt-js/libs-core 2026.11.15 → 2026.11.16

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 (76) hide show
  1. package/README.md +35 -2
  2. package/dist/browser.d.mts +3 -0
  3. package/dist/browser.mjs +1 -50
  4. package/dist/browser.mjs.gz +0 -0
  5. package/dist/cdn/browser.umd.cjs +2 -0
  6. package/dist/cdn/browser.umd.cjs.gz +0 -0
  7. package/dist/cdn/demo-browser.umd.cjs +2 -0
  8. package/dist/cdn/demo-browser.umd.cjs.gz +0 -0
  9. package/dist/cdn/demo.umd.cjs +2 -0
  10. package/dist/cdn/demo.umd.cjs.gz +0 -0
  11. package/dist/cdn/example-esm.html +1 -0
  12. package/dist/cdn/example-umd.html +1 -0
  13. package/dist/cdn/index.umd.cjs +2 -0
  14. package/dist/cdn/index.umd.cjs.gz +0 -0
  15. package/dist/cdn/manifest.json +129 -0
  16. package/dist/cdn/vendor.umd.cjs +50 -0
  17. package/dist/cdn/vendor.umd.cjs.gz +0 -0
  18. package/dist/cdn.d.mts +3 -0
  19. package/dist/cdn.mjs +1 -0
  20. package/dist/demo/browser.mjs +1 -0
  21. package/dist/demo/browser.mjs.gz +0 -0
  22. package/dist/demo/clipboard.d.mts +6 -0
  23. package/dist/demo/clipboard.mjs +1 -0
  24. package/{src → dist}/demo/docs.d.mts +3 -0
  25. package/dist/demo/docs.mjs +1 -0
  26. package/dist/demo/docs.mjs.gz +0 -0
  27. package/{src → dist}/demo/download.d.mts +38 -33
  28. package/dist/demo/download.mjs +1 -0
  29. package/dist/demo/download.mjs.gz +0 -0
  30. package/dist/demo/fullscreen.mjs +1 -0
  31. package/dist/demo/index.d.mts +9 -0
  32. package/dist/demo/index.mjs +1 -0
  33. package/dist/demo/model.mjs +1 -0
  34. package/dist/demo/remote-debug.d.mts +11 -0
  35. package/dist/demo/remote-debug.mjs +1 -0
  36. package/{src → dist}/demo/runtime.mjs +92 -104
  37. package/dist/demo/split-pane.d.mts +8 -0
  38. package/dist/demo/split-pane.mjs +1 -0
  39. package/dist/demo/standalone.d.mts +9 -0
  40. package/dist/demo/standalone.mjs +1 -0
  41. package/dist/demo/tabs.d.mts +15 -0
  42. package/dist/demo/tabs.mjs +1 -0
  43. package/{src/index.ts → dist/index.d.ts} +1 -1
  44. package/dist/loading.mjs +1 -0
  45. package/dist/remote-address.cjs +2 -0
  46. package/{src → dist}/remote.d.mts +16 -2
  47. package/dist/remote.mjs +1 -0
  48. package/dist/remote.mjs.gz +0 -0
  49. package/dist/vendor/hel-runtime.mjs +50 -0
  50. package/dist/vendor/hel-runtime.mjs.gz +0 -0
  51. package/package.json +41 -25
  52. package/scripts/browser-formats.mjs +355 -0
  53. package/scripts/build-browser.mjs +59 -13
  54. package/scripts/build-protected-esm.mjs +51 -0
  55. package/scripts/cdn-runtime.cjs +30 -0
  56. package/scripts/check-tdz.mjs +327 -324
  57. package/scripts/comps-bundle-obfuscation.cjs +2 -1
  58. package/scripts/package-artifacts.mjs +199 -0
  59. package/scripts/package-env.cjs +193 -193
  60. package/scripts/publish-stage.mjs +50 -42
  61. package/scripts/webpack-bundle-obfuscation.cjs +13 -0
  62. package/demo/index.js +0 -1
  63. package/dist/hel-deployment.json +0 -8
  64. package/src/browser.d.mts +0 -2
  65. package/src/browser.mjs +0 -3
  66. package/src/demo/docs.mjs +0 -75
  67. package/src/demo/download.mjs +0 -118
  68. package/src/demo/fullscreen.mjs +0 -80
  69. package/src/demo/index.d.mts +0 -4
  70. package/src/demo/index.mjs +0 -4
  71. package/src/demo/model.mjs +0 -203
  72. package/src/remote.mjs +0 -286
  73. package/tsconfig.json +0 -13
  74. /package/{src → dist}/demo/fullscreen.d.mts +0 -0
  75. /package/{src → dist}/demo/model.d.mts +0 -0
  76. /package/{src → scripts}/remote-address.cjs +0 -0
package/src/remote.mjs DELETED
@@ -1,286 +0,0 @@
1
- import helMicro from 'hel-micro'
2
- import remoteAddress from './remote-address.cjs'
3
-
4
- // Default interop also works with Vue CLI 4 / webpack 4 consuming this ESM file.
5
- const { preFetchLib } = helMicro
6
-
7
- export const { HEL_BASES } = remoteAddress
8
-
9
- function packageRef(ref) {
10
- try { return remoteAddress.packageRef(ref) } catch (error) { throw configError(error.message) }
11
- }
12
-
13
- export class HelLoadError extends Error {
14
- constructor({ moduleName, host, phase, message, missingExports = [], cause }) {
15
- super(message, { cause })
16
- this.name = 'HelLoadError'
17
- this.moduleName = moduleName
18
- this.host = host
19
- this.phase = phase
20
- this.missingExports = missingExports
21
- this.cause = cause
22
- }
23
- }
24
-
25
- function configError(message, moduleName = '', host = '') {
26
- return new HelLoadError({ moduleName, host, phase: 'config', message: '[hel-loader] ' + message })
27
- }
28
-
29
- function httpUrl(value) {
30
- let url
31
- try { url = new URL(value) } catch { throw configError('需要绝对 HTTP(S) 地址:' + value) }
32
- if (!/^https?:$/.test(url.protocol)) throw configError('不支持的地址协议:' + value)
33
- return url
34
- }
35
-
36
- export function isHelMetaHost(host) {
37
- return /\/hel-meta\.json$/i.test(httpUrl(host.trim()).pathname)
38
- }
39
-
40
- /** A leading slash is relative to base's directory, not the origin root. */
41
- export function resolveHelDep(dep, options = {}) {
42
- if (dep && typeof dep === 'object') {
43
- if (typeof dep.name !== 'string' || !dep.name.trim() || typeof dep.host !== 'string') {
44
- throw configError('显式依赖需要 name 和 host')
45
- }
46
- httpUrl(dep.host)
47
- return { ...dep, name: dep.name.trim() }
48
- }
49
- if (typeof dep !== 'string' || !dep.trim()) throw configError('依赖必须是包引用、URL 或显式依赖对象')
50
- const ref = dep.trim()
51
- const type = options.type || 'unpkg'
52
- if (!['custom', 'unpkg', 'github'].includes(type)) throw configError('未知加载类型:' + type)
53
- let url
54
- let parsed
55
- if (/^https?:\/\//i.test(ref)) {
56
- url = httpUrl(ref)
57
- const path = url.pathname.replace(/\/+$/, '').replace(/\/(?:(?:hel_dist|dist)(?:\/(?:hel-meta\.json|index\.html))?|hel-meta\.json|index\.html)$/i, '')
58
- parsed = packageRef(decodeURIComponent(path.split('/').pop() || ''))
59
- } else {
60
- parsed = packageRef(ref.replace(/^\//, ''))
61
- try { url = remoteAddress.packageUrl(parsed, { ...options, type }) }
62
- catch (error) { throw configError(error.message) }
63
- }
64
- const path = url.pathname.replace(/\/+$/, '')
65
- url.pathname = path
66
- if (!/\/(?:hel-meta\.json|index\.html)$/i.test(path)) {
67
- const output = /\/(hel_dist|dist)$/i.exec(path)
68
- const directory = output ? output[1].toLowerCase() : /^(?:tpl|demo)-/.test(parsed.name) ? 'dist' : 'hel_dist'
69
- url.pathname = path + (output ? '' : '/' + directory) + (directory === 'dist' ? '/index.html' : '/hel-meta.json')
70
- }
71
- return { name: parsed.name, host: url.href }
72
- }
73
-
74
- function batch(spec) {
75
- const name = spec.name.split('/').pop()
76
- return name.startsWith('libs-') ? 0 : name.startsWith('comps-') ? 1 : 2
77
- }
78
-
79
- export function resolveHelDeps(options) {
80
- if (!options || !Array.isArray(options.deps)) throw configError('预加载需要 deps 数组')
81
- // Validate the whole plan before starting any network work.
82
- const specs = options.deps.map(dep => resolveHelDep(dep, options))
83
- const identities = new Map()
84
- for (const spec of specs) {
85
- const identity = identityOf(spec)
86
- const key = requestKey(spec)
87
- if (identities.has(identity) && identities.get(identity) !== key) {
88
- throw configError('同一模块不能配置多个地址或版本:' + spec.name, spec.name, spec.host)
89
- }
90
- identities.set(identity, key)
91
- }
92
- // Keep declaration order inside each batch; custom registration must stay serial.
93
- return specs.sort((a, b) => batch(a) - batch(b))
94
- }
95
-
96
- export function assertHelExports(moduleName, host, lib, requiredExports = []) {
97
- if (!lib || (typeof lib !== 'object' && typeof lib !== 'function')) {
98
- throw new HelLoadError({ moduleName, host, phase: 'ready', message: '[hel-loader] ' + moduleName + ' 未返回远程模块对象' })
99
- }
100
- const missingExports = requiredExports.filter(name => !(name in lib) || lib[name] == null)
101
- if (missingExports.length) {
102
- throw new HelLoadError({ moduleName, host, phase: 'exports', missingExports,
103
- message: '[hel-loader] ' + moduleName + ' 缺少导出:' + missingExports.join(', ') })
104
- }
105
- }
106
-
107
- /** Relative builds must resolve against the remote package, including file:// hosts. */
108
- function resolveMetaAssets(meta, host) {
109
- const srcMap = meta && meta.version && meta.version.src_map
110
- if (!srcMap || !isHelMetaHost(host)) return
111
- const base = new URL('.', host).href
112
- const webDir = String(srcMap.webDirPath || '').replace(/\/+$/, '')
113
- const absolute = value => {
114
- if (typeof value !== 'string' || !value || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(value)) return value
115
- const resolved = webDir && value.startsWith(webDir + '/')
116
- ? new URL(value.slice(webDir.length + 1), base).href
117
- : new URL(!webDir ? value.replace(/^\/+/, '') : value, base).href
118
- // Webpack chunks retain their original publicPath inside the runtime. Use
119
- // HEL's existing append hook for those dynamic requests as well as metadata.
120
- if (typeof document !== 'undefined' && document.baseURI) {
121
- const core = helMicro.core
122
- const browserUrl = new URL(value, document.baseURI).href
123
- core.setCommonData(core.helConsts.KEY_ASSET_CTX, browserUrl, {
124
- marked: true,
125
- beforeAppend: ({ setAssetUrl }) => { setAssetUrl(resolved) },
126
- })
127
- }
128
- return resolved
129
- }
130
- for (const [key, value] of Object.entries(srcMap)) {
131
- if (key === 'headAssetList' || key === 'bodyAssetList') {
132
- for (const asset of value || []) {
133
- for (const attr of ['src', 'href']) {
134
- if (asset.attrs && asset.attrs[attr]) asset.attrs[attr] = absolute(asset.attrs[attr])
135
- }
136
- }
137
- } else if (key.endsWith('List') && Array.isArray(value)) srcMap[key] = value.map(absolute)
138
- else if (key !== 'webDirPath' && /(?:Path|Src|Index)$/.test(key)) srcMap[key] = absolute(value)
139
- }
140
- if (!/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(webDir)) srcMap.webDirPath = base.replace(/\/$/, '')
141
- }
142
-
143
- function fetchOptions(spec) {
144
- return {
145
- ...(spec.platform ? { platform: spec.platform } : {}),
146
- hook: { onFetchMetaSuccess: meta => resolveMetaAssets(meta, spec.host) },
147
- custom: {
148
- skipFetchHelMeta: !isHelMetaHost(spec.host), enable: true, trust: true,
149
- ...(spec.custom || {}),
150
- host: spec.host,
151
- appGroupName: spec.appGroupName || (spec.custom && spec.custom.appGroupName) || spec.name,
152
- },
153
- }
154
- }
155
-
156
- function identityOf(spec) {
157
- const options = fetchOptions(spec)
158
- return JSON.stringify([spec.platform || '', options.custom.appGroupName || spec.name])
159
- }
160
-
161
- function canonical(value) {
162
- if (Array.isArray(value)) return value.map(canonical)
163
- if (value && typeof value === 'object') {
164
- return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]))
165
- }
166
- return value
167
- }
168
-
169
- function requestKey(spec) {
170
- return JSON.stringify(canonical([spec.name, fetchOptions(spec)]))
171
- }
172
-
173
- /** Shared by preload and on-demand calls, including independently started plans. */
174
- export function createHelLoader(fetchLib = preFetchLib) {
175
- const requests = new Map()
176
- let queue = Promise.resolve()
177
-
178
- function loadHelLib(dep, options = {}) {
179
- let spec
180
- let identity
181
- let key
182
- try {
183
- spec = resolveHelDep(dep, options)
184
- identity = identityOf(spec)
185
- key = requestKey(spec)
186
- } catch (error) { return Promise.reject(error) }
187
- const existing = requests.get(identity)
188
- if (existing && existing.key !== key) {
189
- return Promise.reject(configError('模块已使用另一地址或版本加载:' + spec.name, spec.name, spec.host))
190
- }
191
- let pending = existing && existing.promise
192
- if (!pending) {
193
- pending = queue.then(async () => {
194
- try {
195
- const lib = await fetchLib(spec.name, fetchOptions(spec))
196
- assertHelExports(spec.name, spec.host, lib)
197
- return lib
198
- } catch (cause) {
199
- if (cause instanceof HelLoadError) throw cause
200
- throw new HelLoadError({ moduleName: spec.name, host: spec.host, phase: 'assets', cause,
201
- message: '[hel-loader] ' + spec.name + ' 加载失败:' + (cause instanceof Error ? cause.message : String(cause)) })
202
- }
203
- })
204
- requests.set(identity, { key, promise: pending })
205
- // Release failed requests for an explicit retry; never poison the serial queue.
206
- queue = pending.then(() => undefined, () => { requests.delete(identity) })
207
- }
208
- // Export requirements belong to each caller, not to the shared network request.
209
- return pending.then(lib => {
210
- assertHelExports(spec.name, spec.host, lib, spec.requiredExports)
211
- return lib
212
- })
213
- }
214
-
215
- async function loadHelLibsSerial(specs) {
216
- const loaded = []
217
- for (const spec of specs) loaded.push(await loadHelLib(spec))
218
- return loaded
219
- }
220
-
221
- async function preloadHelLibs(options) {
222
- const loaded = Object.create(null)
223
- for (const spec of resolveHelDeps(options)) loaded[spec.name] = await loadHelLib(spec)
224
- return loaded
225
- }
226
-
227
- return { loadHelLib, loadHelLibsSerial, preloadHelLibs }
228
- }
229
-
230
- const defaultLoader = createHelLoader()
231
- export const { loadHelLib, loadHelLibsSerial, preloadHelLibs } = defaultLoader
232
-
233
- /** Select an export using the same loader and cache as startup preloading. */
234
- export async function loadHelComponent(options) {
235
- const spec = options.dep ? resolveHelDep(options.dep, options) : null
236
- const name = spec ? spec.name : 'remote'
237
- const host = spec ? spec.host : ''
238
- if (!options.exportName || typeof options.exportName !== 'string') throw configError('组件需要 exportName')
239
- if (!spec && typeof options.loader !== 'function') throw configError('组件需要 dep 或 loader')
240
- const lib = options.loader ? await options.loader() : await loadHelLib(spec)
241
- assertHelExports(name, host, lib, [options.exportName])
242
- const component = lib[options.exportName]
243
- if (typeof component !== 'object' && typeof component !== 'function') {
244
- throw new HelLoadError({ moduleName: name, host, phase: 'exports', missingExports: [options.exportName],
245
- message: '[hel-loader] ' + options.exportName + ' 不是可用的组件导出' })
246
- }
247
- return component
248
- }
249
-
250
- /** Per-view state; network deduplication remains in loadHelLib, never in UI adapters. */
251
- export function createHelComponentResource(options, onChange = () => {}) {
252
- let generation = 0
253
- let disposed = false
254
- let state = { status: 'loading', component: null, error: null }
255
- const update = next => { state = next; onChange(next) }
256
- function fail(error) {
257
- if (disposed) return
258
- generation++
259
- update({ status: 'error', component: null, error })
260
- if (options.onError) options.onError(error)
261
- }
262
- async function load() {
263
- if (disposed) return
264
- const current = ++generation
265
- update({ status: 'loading', component: null, error: null })
266
- try {
267
- const component = await loadHelComponent(options)
268
- if (!disposed && current === generation) update({ status: 'ready', component, error: null })
269
- } catch (error) {
270
- if (!disposed && current === generation) fail(error)
271
- }
272
- }
273
- return { getState: () => state, load, retry: load, fail, dispose: () => { disposed = true; generation++ } }
274
- }
275
-
276
- /** Existing deployment target helper; SFTP/GitHub use unversioned project folders. */
277
- export function resolveHelHost({ packageName, target, version = '', projectName, baseUrl = '' }) {
278
- const parsed = packageRef(packageName)
279
- parsed.version = version
280
- const url = remoteAddress.packageUrl(parsed, {
281
- type: target === 'sftp' ? 'custom' : target, base: baseUrl,
282
- projectName: target === 'unpkg' ? undefined : projectName, versioned: target === 'unpkg',
283
- })
284
- url.pathname += '/hel_dist/hel-meta.json'
285
- return url.href
286
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "lib": ["ESNext", "DOM"],
7
- "strict": true,
8
- "declaration": true,
9
- "skipLibCheck": true,
10
- "noEmit": true
11
- },
12
- "include": ["src/**/*.ts"]
13
- }
File without changes
File without changes
File without changes