@melt-js/libs-core 2026.11.14 → 2026.11.15-1
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.
- package/README.md +49 -3
- package/dist/browser.d.mts +2 -0
- package/dist/browser.mjs +60 -0
- package/dist/demo/docs.d.mts +28 -0
- package/dist/demo/docs.mjs +58 -0
- package/dist/demo/download.d.mts +35 -0
- package/dist/demo/download.mjs +4 -0
- package/dist/demo/fullscreen.d.mts +8 -0
- package/dist/demo/fullscreen.mjs +1 -0
- package/dist/demo/index.d.mts +7 -0
- package/dist/demo/index.mjs +1 -0
- package/dist/demo/model.d.mts +12 -0
- package/dist/demo/model.mjs +1 -0
- package/dist/demo/remote-debug.d.mts +11 -0
- package/dist/demo/remote-debug.mjs +1 -0
- package/dist/demo/runtime.mjs +92 -0
- package/dist/demo/split-pane.d.mts +8 -0
- package/dist/demo/split-pane.mjs +1 -0
- package/dist/demo/tabs.d.mts +15 -0
- package/dist/demo/tabs.mjs +1 -0
- package/dist/hel-deployment.json +8 -0
- package/{src/index.ts → dist/index.d.ts} +1 -1
- package/dist/loading.mjs +11 -0
- package/dist/remote-address.cjs +2 -0
- package/{src → dist}/remote.d.mts +16 -2
- package/dist/remote.mjs +1 -0
- package/package.json +26 -16
- package/scripts/build-browser.mjs +31 -0
- package/scripts/check-tdz.mjs +5 -2
- package/scripts/component-events.mjs +57 -0
- package/scripts/hel-build-paths.cjs +48 -0
- package/scripts/package-artifacts.mjs +180 -0
- package/scripts/package-env.cjs +193 -180
- package/scripts/publish-stage.mjs +18 -10
- package/src/remote.mjs +0 -249
- package/tsconfig.json +0 -13
- /package/{src → scripts}/remote-address.cjs +0 -0
package/src/remote.mjs
DELETED
|
@@ -1,249 +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
|
-
function fetchOptions(spec) {
|
|
108
|
-
return {
|
|
109
|
-
...(spec.platform ? { platform: spec.platform } : {}),
|
|
110
|
-
custom: {
|
|
111
|
-
skipFetchHelMeta: !isHelMetaHost(spec.host), enable: true, trust: true,
|
|
112
|
-
...(spec.custom || {}),
|
|
113
|
-
host: spec.host,
|
|
114
|
-
appGroupName: spec.appGroupName || (spec.custom && spec.custom.appGroupName) || spec.name,
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function identityOf(spec) {
|
|
120
|
-
const options = fetchOptions(spec)
|
|
121
|
-
return JSON.stringify([spec.platform || '', options.custom.appGroupName || spec.name])
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function canonical(value) {
|
|
125
|
-
if (Array.isArray(value)) return value.map(canonical)
|
|
126
|
-
if (value && typeof value === 'object') {
|
|
127
|
-
return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]))
|
|
128
|
-
}
|
|
129
|
-
return value
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function requestKey(spec) {
|
|
133
|
-
return JSON.stringify(canonical([spec.name, fetchOptions(spec)]))
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Shared by preload and on-demand calls, including independently started plans. */
|
|
137
|
-
export function createHelLoader(fetchLib = preFetchLib) {
|
|
138
|
-
const requests = new Map()
|
|
139
|
-
let queue = Promise.resolve()
|
|
140
|
-
|
|
141
|
-
function loadHelLib(dep, options = {}) {
|
|
142
|
-
let spec
|
|
143
|
-
let identity
|
|
144
|
-
let key
|
|
145
|
-
try {
|
|
146
|
-
spec = resolveHelDep(dep, options)
|
|
147
|
-
identity = identityOf(spec)
|
|
148
|
-
key = requestKey(spec)
|
|
149
|
-
} catch (error) { return Promise.reject(error) }
|
|
150
|
-
const existing = requests.get(identity)
|
|
151
|
-
if (existing && existing.key !== key) {
|
|
152
|
-
return Promise.reject(configError('模块已使用另一地址或版本加载:' + spec.name, spec.name, spec.host))
|
|
153
|
-
}
|
|
154
|
-
let pending = existing && existing.promise
|
|
155
|
-
if (!pending) {
|
|
156
|
-
pending = queue.then(async () => {
|
|
157
|
-
try {
|
|
158
|
-
const lib = await fetchLib(spec.name, fetchOptions(spec))
|
|
159
|
-
assertHelExports(spec.name, spec.host, lib)
|
|
160
|
-
return lib
|
|
161
|
-
} catch (cause) {
|
|
162
|
-
if (cause instanceof HelLoadError) throw cause
|
|
163
|
-
throw new HelLoadError({ moduleName: spec.name, host: spec.host, phase: 'assets', cause,
|
|
164
|
-
message: '[hel-loader] ' + spec.name + ' 加载失败:' + (cause instanceof Error ? cause.message : String(cause)) })
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
requests.set(identity, { key, promise: pending })
|
|
168
|
-
// Release failed requests for an explicit retry; never poison the serial queue.
|
|
169
|
-
queue = pending.then(() => undefined, () => { requests.delete(identity) })
|
|
170
|
-
}
|
|
171
|
-
// Export requirements belong to each caller, not to the shared network request.
|
|
172
|
-
return pending.then(lib => {
|
|
173
|
-
assertHelExports(spec.name, spec.host, lib, spec.requiredExports)
|
|
174
|
-
return lib
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async function loadHelLibsSerial(specs) {
|
|
179
|
-
const loaded = []
|
|
180
|
-
for (const spec of specs) loaded.push(await loadHelLib(spec))
|
|
181
|
-
return loaded
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async function preloadHelLibs(options) {
|
|
185
|
-
const loaded = Object.create(null)
|
|
186
|
-
for (const spec of resolveHelDeps(options)) loaded[spec.name] = await loadHelLib(spec)
|
|
187
|
-
return loaded
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return { loadHelLib, loadHelLibsSerial, preloadHelLibs }
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const defaultLoader = createHelLoader()
|
|
194
|
-
export const { loadHelLib, loadHelLibsSerial, preloadHelLibs } = defaultLoader
|
|
195
|
-
|
|
196
|
-
/** Select an export using the same loader and cache as startup preloading. */
|
|
197
|
-
export async function loadHelComponent(options) {
|
|
198
|
-
const spec = options.dep ? resolveHelDep(options.dep, options) : null
|
|
199
|
-
const name = spec ? spec.name : 'remote'
|
|
200
|
-
const host = spec ? spec.host : ''
|
|
201
|
-
if (!options.exportName || typeof options.exportName !== 'string') throw configError('组件需要 exportName')
|
|
202
|
-
if (!spec && typeof options.loader !== 'function') throw configError('组件需要 dep 或 loader')
|
|
203
|
-
const lib = options.loader ? await options.loader() : await loadHelLib(spec)
|
|
204
|
-
assertHelExports(name, host, lib, [options.exportName])
|
|
205
|
-
const component = lib[options.exportName]
|
|
206
|
-
if (typeof component !== 'object' && typeof component !== 'function') {
|
|
207
|
-
throw new HelLoadError({ moduleName: name, host, phase: 'exports', missingExports: [options.exportName],
|
|
208
|
-
message: '[hel-loader] ' + options.exportName + ' 不是可用的组件导出' })
|
|
209
|
-
}
|
|
210
|
-
return component
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** Per-view state; network deduplication remains in loadHelLib, never in UI adapters. */
|
|
214
|
-
export function createHelComponentResource(options, onChange = () => {}) {
|
|
215
|
-
let generation = 0
|
|
216
|
-
let disposed = false
|
|
217
|
-
let state = { status: 'loading', component: null, error: null }
|
|
218
|
-
const update = next => { state = next; onChange(next) }
|
|
219
|
-
function fail(error) {
|
|
220
|
-
if (disposed) return
|
|
221
|
-
generation++
|
|
222
|
-
update({ status: 'error', component: null, error })
|
|
223
|
-
if (options.onError) options.onError(error)
|
|
224
|
-
}
|
|
225
|
-
async function load() {
|
|
226
|
-
if (disposed) return
|
|
227
|
-
const current = ++generation
|
|
228
|
-
update({ status: 'loading', component: null, error: null })
|
|
229
|
-
try {
|
|
230
|
-
const component = await loadHelComponent(options)
|
|
231
|
-
if (!disposed && current === generation) update({ status: 'ready', component, error: null })
|
|
232
|
-
} catch (error) {
|
|
233
|
-
if (!disposed && current === generation) fail(error)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return { getState: () => state, load, retry: load, fail, dispose: () => { disposed = true; generation++ } }
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** Existing deployment target helper; SFTP/GitHub use unversioned project folders. */
|
|
240
|
-
export function resolveHelHost({ packageName, target, version = '', projectName, baseUrl = '' }) {
|
|
241
|
-
const parsed = packageRef(packageName)
|
|
242
|
-
parsed.version = version
|
|
243
|
-
const url = remoteAddress.packageUrl(parsed, {
|
|
244
|
-
type: target === 'sftp' ? 'custom' : target, base: baseUrl,
|
|
245
|
-
projectName: target === 'unpkg' ? undefined : projectName, versioned: target === 'unpkg',
|
|
246
|
-
})
|
|
247
|
-
url.pathname += '/hel_dist/hel-meta.json'
|
|
248
|
-
return url.href
|
|
249
|
-
}
|
package/tsconfig.json
DELETED
|
File without changes
|