@melt-js/libs-core 2026.11.15 → 2026.11.16-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 (85) hide show
  1. package/README.md +73 -16
  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 +141 -0
  16. package/dist/cdn/vendor.umd.cjs +16 -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.d.mts +1 -0
  21. package/dist/demo/browser.mjs +1 -0
  22. package/dist/demo/browser.mjs.gz +0 -0
  23. package/dist/demo/clipboard.d.mts +6 -0
  24. package/dist/demo/clipboard.mjs +1 -0
  25. package/{src → dist}/demo/docs.d.mts +3 -0
  26. package/dist/demo/docs.mjs +1 -0
  27. package/dist/demo/docs.mjs.gz +0 -0
  28. package/{src → dist}/demo/download.d.mts +10 -2
  29. package/dist/demo/download.mjs +1 -0
  30. package/dist/demo/download.mjs.gz +0 -0
  31. package/dist/demo/fullscreen.mjs +1 -0
  32. package/dist/demo/highlight.d.mts +2 -0
  33. package/dist/demo/highlight.mjs +1 -0
  34. package/dist/demo/index.d.mts +10 -0
  35. package/dist/demo/index.mjs +1 -0
  36. package/dist/demo/model.mjs +1 -0
  37. package/dist/demo/remote-debug.d.mts +9 -0
  38. package/dist/demo/remote-debug.mjs +1 -0
  39. package/{src → dist}/demo/runtime.mjs +92 -104
  40. package/dist/demo/split-pane.d.mts +8 -0
  41. package/dist/demo/split-pane.mjs +1 -0
  42. package/dist/demo/standalone.d.mts +12 -0
  43. package/dist/demo/standalone.mjs +1 -0
  44. package/dist/demo/standalone.mjs.gz +0 -0
  45. package/dist/demo/tabs.d.mts +15 -0
  46. package/dist/demo/tabs.mjs +1 -0
  47. package/{src/index.ts → dist/index.d.ts} +1 -1
  48. package/dist/loading.mjs +1 -0
  49. package/dist/loading.mjs.gz +0 -0
  50. package/dist/remote-address.cjs +2 -0
  51. package/{src → dist}/remote.d.mts +20 -2
  52. package/dist/remote.mjs +1 -0
  53. package/dist/remote.mjs.gz +0 -0
  54. package/dist/vendor/hel-runtime.mjs +16 -0
  55. package/dist/vendor/hel-runtime.mjs.gz +0 -0
  56. package/package.json +41 -25
  57. package/scripts/browser-formats.mjs +357 -0
  58. package/scripts/build-browser.mjs +59 -13
  59. package/scripts/build-protected-esm.mjs +54 -0
  60. package/scripts/cdn-runtime.cjs +30 -0
  61. package/scripts/check-tdz.mjs +327 -324
  62. package/scripts/client-build-security.cjs +48 -0
  63. package/scripts/comps-bundle-obfuscation.cjs +269 -262
  64. package/scripts/comps-obfuscator-options.cjs +7 -1
  65. package/scripts/hel-build-paths.cjs +49 -48
  66. package/scripts/obfuscator-split-strings.cjs +22 -0
  67. package/scripts/package-artifacts.mjs +206 -0
  68. package/scripts/package-env.cjs +156 -193
  69. package/scripts/publish-stage.mjs +50 -42
  70. package/scripts/webpack-bundle-obfuscation.cjs +125 -121
  71. package/demo/index.js +0 -1
  72. package/dist/hel-deployment.json +0 -8
  73. package/src/browser.d.mts +0 -2
  74. package/src/browser.mjs +0 -3
  75. package/src/demo/docs.mjs +0 -75
  76. package/src/demo/download.mjs +0 -118
  77. package/src/demo/fullscreen.mjs +0 -80
  78. package/src/demo/index.d.mts +0 -4
  79. package/src/demo/index.mjs +0 -4
  80. package/src/demo/model.mjs +0 -203
  81. package/src/remote.mjs +0 -286
  82. package/tsconfig.json +0 -13
  83. /package/{src → dist}/demo/fullscreen.d.mts +0 -0
  84. /package/{src → dist}/demo/model.d.mts +0 -0
  85. /package/{src → scripts}/remote-address.cjs +0 -0
@@ -1,203 +0,0 @@
1
- /*
2
- |--------------------------------------------------------------------------
3
- |
4
- | v-model / value 双向绑定的契约解析(与 Vue 版本无关)
5
- |
6
- | 面板和预览组件共用同一份 values:
7
- | - 面板改值 -> v-bind 到组件
8
- | - 组件内部交互 -> 组件 emit 模型事件 -> 写回 values -> 面板 refresh
9
- |
10
- | 模型 prop / event 的来源优先级:
11
- | 1. PropsPlayground 的 models prop(显式覆盖,最可靠)
12
- | 2. 组件自身的 model 选项 / Vue 3 emits 里的 update:xxx(运行时最真实)
13
- | 3. schema 里 prop.model / prop.modelEvent(老组件、拿不到组件定义时)
14
- | 4. schema 里存在 value / modelValue 时按默认约定兜底
15
- |
16
- | 注意:这里只解析“契约”,不碰 Vue 实例;PropsPlayground 负责绑定与回写。
17
- |
18
- |--------------------------------------------------------------------------
19
- */
20
- const isBindable = prop => Boolean(prop && prop.bindable);
21
-
22
- const UPDATE_PREFIX = 'update:';
23
-
24
- /** 按 prop 名猜默认事件:modelValue -> update:modelValue,其余 -> input */
25
- export function defaultModelEvent(prop) {
26
- return prop === 'modelValue' ? `${UPDATE_PREFIX}modelValue` : 'input';
27
- }
28
-
29
- /**
30
- * 把各种写法归一成 { prop, event, getValue? }
31
- *
32
- * 支持:
33
- * - 'value'
34
- * - { prop: 'selectValue', event: 'change' }
35
- * - { name: 'checked', event: 'change', getValue: (...args) => ... }
36
- */
37
- export function normalizeModel(input) {
38
- if (!input) return null;
39
- if (typeof input === 'string') {
40
- return { prop: input, event: defaultModelEvent(input) };
41
- }
42
- const prop = input.prop || input.name;
43
- if (!prop) return null;
44
- return {
45
- prop,
46
- event: input.event || input.modelEvent || defaultModelEvent(prop),
47
- getValue: typeof input.getValue === 'function' ? input.getValue : null,
48
- };
49
- }
50
-
51
- /** 单个 model 或 model 数组 -> 数组 */
52
- export function normalizeModels(models) {
53
- if (!models) return [];
54
- const list = Array.isArray(models) ? models : [models];
55
- return list.map(normalizeModel).filter(Boolean);
56
- }
57
-
58
- /**
59
- * 从 schema 读取模型标记:
60
- * { name: 'selectValue', model: true, modelEvent: 'change' }
61
- * { name: 'value', model: { event: 'change' } }
62
- */
63
- export function schemaModels(schema) {
64
- return (schema || []).reduce((models, prop) => {
65
- if (!prop || !prop.model) return models;
66
- const config = typeof prop.model === 'object' ? prop.model : {};
67
- const model = normalizeModel({
68
- prop: config.prop || prop.name,
69
- event: config.event || prop.modelEvent,
70
- getValue: config.getValue,
71
- });
72
- if (model) models.push(model);
73
- return models;
74
- }, []);
75
- }
76
-
77
- /** 组件定义:Vue 2 的构造函数是 { options },普通对象/Vue 3 直接就是 options */
78
- export function componentOptions(component) {
79
- if (!component) return null;
80
- if (component.options) return component.options;
81
- if (typeof component === 'function') return component.options || null;
82
- return component;
83
- }
84
-
85
- /** 组件显式声明的 props 名;拿不到时返回 [](比如远程代理壳) */
86
- export function componentPropNames(component) {
87
- const options = componentOptions(component);
88
- const props = options && options.props;
89
- if (!props) return [];
90
- return Array.isArray(props) ? props.slice() : Object.keys(props);
91
- }
92
-
93
- /** 组件显式声明的 emits 名(Vue 3) */
94
- export function componentEmitNames(component) {
95
- const options = componentOptions(component);
96
- const emits = options && options.emits;
97
- if (!emits) return [];
98
- return Array.isArray(emits) ? emits.slice() : Object.keys(emits);
99
- }
100
-
101
- /**
102
- * 从组件定义里读取“显式”的模型契约。
103
- *
104
- * Vue 2:只认 model 选项;没有时交给 schema 标记 / 默认约定兜底,
105
- * 这样 schema 里的 modelEvent 才能覆盖 value + input 的默认推断。
106
- * Vue 3:emits 里声明的 update:xxx(对应 v-model:xxx,可以一次同步多个模型)。
107
- */
108
- export function componentModels(component, options = {}) {
109
- const { isVue2 = true } = options;
110
- const resolved = componentOptions(component);
111
- if (!resolved) return [];
112
-
113
- if (isVue2) {
114
- const model = normalizeModel(resolved.model);
115
- return model ? [model] : [];
116
- }
117
-
118
- const props = componentPropNames(component);
119
- const emits = componentEmitNames(component);
120
- const models = [];
121
- const seen = new Set();
122
-
123
- emits.forEach((event) => {
124
- if (!event.startsWith(UPDATE_PREFIX)) return;
125
- const prop = event.slice(UPDATE_PREFIX.length);
126
- if (!prop || seen.has(prop)) return;
127
- if (props.length && !props.includes(prop)) return;
128
- seen.add(prop);
129
- models.push({ prop, event });
130
- });
131
-
132
- return models;
133
- }
134
-
135
- /** schema 里有 value / modelValue 时按框架默认约定兜底 */
136
- export function fallbackModels(schema, options = {}) {
137
- const { isVue2 = true } = options;
138
- const names = new Set((schema || []).map((prop) => prop && prop.name).filter(Boolean));
139
- const models = [];
140
-
141
- const add = (prop, event) => {
142
- if (names.has(prop)) models.push({ prop, event });
143
- };
144
-
145
- if (isVue2) {
146
- add('value', 'input');
147
- add('modelValue', `${UPDATE_PREFIX}modelValue`);
148
- } else {
149
- add('modelValue', `${UPDATE_PREFIX}modelValue`);
150
- add('value', 'input');
151
- }
152
- return models;
153
- }
154
-
155
- /**
156
- * 解析当前组件要同步的模型列表。
157
- *
158
- * @param {object} options
159
- * @param {object|Function} options.component 预览组件
160
- * @param {Array} options.schema 组件的 propsSchema
161
- * @param {object|Array} [options.models] 宿主显式配置,优先级最高
162
- * @param {boolean} [options.isVue2=true] 当前运行时
163
- * @returns {Array<{prop:string,event:string,getValue?:Function}>}
164
- */
165
- export function resolveModels(options = {}) {
166
- const { component, schema, models, isVue2 = true } = options;
167
- const explicit = normalizeModels(models);
168
- const candidates = (
169
- explicit.length
170
- ? explicit
171
- : [
172
- ...componentModels(component, { isVue2 }),
173
- ...schemaModels(schema),
174
- ...fallbackModels(schema, { isVue2 }),
175
- ]
176
- )
177
- .map(normalizeModel)
178
- .filter(Boolean);
179
-
180
- // 面板上只有 bindable 的 prop 有控件;没有控件就没必要回写。
181
- // 显式 models 允许指向非 bindable(宿主可能自己接住 values)。
182
- const bindable = new Set((schema || []).filter(isBindable).map((prop) => prop.name));
183
- const seen = new Set();
184
-
185
- return candidates.filter((model) => {
186
- if (!model || !model.prop || !model.event) return false;
187
- // 同一个 prop 只同步一次;候选顺序已经保证了显式 > 组件 > schema > 兜底
188
- const key = model.prop;
189
- if (seen.has(key)) return false;
190
- seen.add(key);
191
- if (explicit.length) return true;
192
- return !bindable.size || bindable.has(model.prop);
193
- });
194
- }
195
-
196
- /** 判断两个面板值是否等价(数组按元素比较,对象仍用引用比较) */
197
- export function isSameValue(a, b) {
198
- if (Object.is(a, b)) return true;
199
- if (Array.isArray(a) && Array.isArray(b)) {
200
- return a.length === b.length && a.every((item, index) => Object.is(item, b[index]));
201
- }
202
- return false;
203
- }
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