@melt-js/libs-core 2026.11.14 → 2026.11.15-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.
- 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/{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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ModelBinding { prop: string; event: string; getValue?: ((...args: unknown[]) => unknown) | null }
|
|
2
|
+
export function defaultModelEvent(prop: string): string
|
|
3
|
+
export function normalizeModel(input: unknown): ModelBinding | null
|
|
4
|
+
export function normalizeModels(models: unknown): ModelBinding[]
|
|
5
|
+
export function schemaModels(schema?: unknown[]): ModelBinding[]
|
|
6
|
+
export function componentOptions(component: unknown): unknown
|
|
7
|
+
export function componentPropNames(component: unknown): string[]
|
|
8
|
+
export function componentEmitNames(component: unknown): string[]
|
|
9
|
+
export function componentModels(component: unknown, options?: { isVue2?: boolean }): ModelBinding[]
|
|
10
|
+
export function fallbackModels(schema?: unknown[], options?: { isVue2?: boolean }): ModelBinding[]
|
|
11
|
+
export function resolveModels(options?: { component?: unknown; schema?: unknown[]; models?: unknown; isVue2?: boolean }): ModelBinding[]
|
|
12
|
+
export function isSameValue(a: unknown, b: unknown): boolean
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const y=e=>!!(e&&e.bindable),c="update:";function m(e){return e==="modelValue"?`${c}modelValue`:"input"}function f(e){if(!e)return null;if(typeof e=="string")return{prop:e,event:m(e)};const n=e.prop||e.name;return n?{prop:n,event:e.event||e.modelEvent||m(n),getValue:typeof e.getValue=="function"?e.getValue:null}:null}function h(e){return e?(Array.isArray(e)?e:[e]).map(f).filter(Boolean):[]}function V(e){return(e||[]).reduce((n,t)=>{if(!t||!t.model)return n;const o=typeof t.model=="object"?t.model:{},s=f({prop:o.prop||t.name,event:o.event||t.modelEvent,getValue:o.getValue});return s&&n.push(s),n},[])}function d(e){return e?e.options?e.options:typeof e=="function"?e.options||null:e:null}function g(e){const n=d(e),t=n&&n.props;return t?Array.isArray(t)?t.slice():Object.keys(t):[]}function v(e){const n=d(e),t=n&&n.emits;return t?Array.isArray(t)?t.slice():Object.keys(t):[]}function x(e,n={}){const{isVue2:t=!0}=n,o=d(e);if(!o)return[];if(t){const u=f(o.model);return u?[u]:[]}const s=g(e),i=v(e),l=[],a=new Set;return i.forEach(u=>{if(!u.startsWith(c))return;const r=u.slice(c.length);!r||a.has(r)||s.length&&!s.includes(r)||(a.add(r),l.push({prop:r,event:u}))}),l}function A(e,n={}){const{isVue2:t=!0}=n,o=new Set((e||[]).map(l=>l&&l.name).filter(Boolean)),s=[],i=(l,a)=>{o.has(l)&&s.push({prop:l,event:a})};return t?(i("value","input"),i("modelValue",`${c}modelValue`)):(i("modelValue",`${c}modelValue`),i("value","input")),s}function b(e={}){const{component:n,schema:t,models:o,isVue2:s=!0}=e,i=h(o),l=(i.length?i:[...x(n,{isVue2:s}),...V(t),...A(t,{isVue2:s})]).map(f).filter(Boolean),a=new Set((t||[]).filter(y).map(r=>r.name)),u=new Set;return l.filter(r=>{if(!r||!r.prop||!r.event)return!1;const p=r.prop;return u.has(p)?!1:(u.add(p),i.length?!0:!a.size||a.has(r.prop))})}function E(e,n){return Object.is(e,n)?!0:Array.isArray(e)&&Array.isArray(n)?e.length===n.length&&e.every((t,o)=>Object.is(t,n[o])):!1}export{v as componentEmitNames,x as componentModels,d as componentOptions,g as componentPropNames,m as defaultModelEvent,A as fallbackModels,E as isSameValue,f as normalizeModel,h as normalizeModels,b as resolveModels,V as schemaModels};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HelLoadSpec } from '../remote.mjs'
|
|
2
|
+
|
|
3
|
+
export function setupDemoRemoteDebug(options: {
|
|
4
|
+
deps: (HelLoadSpec & { localHost: string })[]
|
|
5
|
+
window?: Window
|
|
6
|
+
}): {
|
|
7
|
+
deps: HelLoadSpec[]
|
|
8
|
+
local: boolean
|
|
9
|
+
dispose(): void
|
|
10
|
+
renderError(root: HTMLElement | null, error: unknown): void
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function g({deps:f,window:t=globalThis.window}){const l=()=>/^#\/local\/?(?:\?|$)/i.test(t.location.hash),n=l(),i=f.map(({localHost:o,...r})=>{const e=n?o:r.host;if(!e)throw new Error("\u7F3A\u5C11\u8FDC\u7A0B\u5730\u5740\uFF1A"+r.name);return{...r,host:e}});let d=!1;const s=()=>{!d&&l()!==n&&(d=!0,t.location.reload())};return t.addEventListener("hashchange",s),t.addEventListener("popstate",s),{deps:i,local:n,dispose(){t.removeEventListener("hashchange",s),t.removeEventListener("popstate",s)},renderError(o,r){if(!o)return;const e=o.ownerDocument,m=e.createElement("p");m.textContent=n?"\u672C\u5730\u670D\u52A1\u8FDE\u63A5\u5931\u8D25\u3002\u8BF7\u542F\u52A8\u4EE5\u4E0B\u7EC4\u4EF6\u4E0E\u5C5E\u6027\u9762\u677F\u670D\u52A1\uFF0C\u7136\u540E\u91CD\u8BD5\u3002":"\u8FDC\u7A0B\u4F9D\u8D56\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002";const h=e.createElement("ul");for(const E of i){const u=e.createElement("li");u.textContent=E.name+"\uFF1A"+E.host,h.append(u)}const p=e.createElement("p");p.textContent=String(r);const a=e.createElement("button");a.type="button",a.textContent="\u91CD\u8BD5\u8FDE\u63A5",a.addEventListener("click",()=>t.location.reload());const c=e.createElement("a");c.href=n?"#/remote":"#/local",c.textContent=n?"\u8FD4\u56DE\u9ED8\u8BA4\u793A\u4F8B":"\u8FDE\u63A5\u672C\u5730\u670D\u52A1",c.style.marginLeft="16px",o.setAttribute("role","alert"),o.replaceChildren(m,h,p,a,c)}}}export{g as setupDemoRemoteDebug};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const e=String.raw`
|
|
2
|
+
const slotMap = typeof example.slotHtml === 'string' ? { default: example.slotHtml } : example.slotHtml || {}
|
|
3
|
+
const RemoteComponent = defineHelComponent({ dep: example.remoteDep || example.packageName, exportName: example.component })
|
|
4
|
+
const props = Vue.reactive({ ...example.props })
|
|
5
|
+
if (example.openProp) props[example.openProp] = false
|
|
6
|
+
Vue.createApp({
|
|
7
|
+
mounted() { if (example.openProp) props[example.openProp] = true },
|
|
8
|
+
render() {
|
|
9
|
+
return Vue.h(RemoteComponent, props, Object.fromEntries(Object.entries(slotMap).map(([name, html]) => [name, () => Vue.h('div', { innerHTML: html })])))
|
|
10
|
+
},
|
|
11
|
+
}).mount('#demo-root')
|
|
12
|
+
`,t=String.raw`
|
|
13
|
+
const slotMap = typeof example.slotHtml === 'string' ? { default: example.slotHtml } : example.slotHtml || {}
|
|
14
|
+
const RemoteComponent = defineHelComponent({ dep: example.remoteDep || example.packageName, exportName: example.component })
|
|
15
|
+
new Vue({
|
|
16
|
+
data: () => ({ values: { ...example.props, ...(example.openProp ? { [example.openProp]: false } : {}) } }),
|
|
17
|
+
mounted() { if (example.openProp) this.$set(this.values, example.openProp, true) },
|
|
18
|
+
render(h) {
|
|
19
|
+
return h(RemoteComponent, { attrs: this.values, scopedSlots: Object.fromEntries(Object.entries(slotMap).map(([name, html]) => [name, () => h('div', { domProps: { innerHTML: html } })])) })
|
|
20
|
+
},
|
|
21
|
+
}).$mount('#demo-root')
|
|
22
|
+
`,o=String.raw`
|
|
23
|
+
const slotMap = typeof example.slotHtml === 'string' ? { default: example.slotHtml } : example.slotHtml || {}
|
|
24
|
+
const RemotePreview = defineHelComponent({
|
|
25
|
+
exportName: 'Preview',
|
|
26
|
+
loader: async () => {
|
|
27
|
+
const Component = await loadHelComponent({ dep: example.remoteDep || example.packageName, exportName: example.component })
|
|
28
|
+
return { Preview: {
|
|
29
|
+
data: () => ({ values: { ...example.props, [example.openProp]: false } }),
|
|
30
|
+
mounted() { this.$nextTick(() => this.$set(this.values, example.openProp, true)) },
|
|
31
|
+
render(h) {
|
|
32
|
+
return h(Component, { props: this.values, scopedSlots: Object.fromEntries(Object.entries(slotMap).map(([name, html]) => [name, () => h('div', { domProps: { innerHTML: html } })])) })
|
|
33
|
+
},
|
|
34
|
+
} }
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
new Vue({ render: h => h(RemotePreview) }).$mount('#demo-root')
|
|
38
|
+
`,a=String.raw`
|
|
39
|
+
const slotMap = typeof example.slotHtml === 'string' ? { default: example.slotHtml } : example.slotHtml || {}
|
|
40
|
+
const RemotePreview = defineHelComponent({
|
|
41
|
+
exportName: 'Preview',
|
|
42
|
+
loader: async () => {
|
|
43
|
+
const Component = await loadHelComponent({ dep: example.remoteDep || example.packageName, exportName: example.component })
|
|
44
|
+
return { Preview: {
|
|
45
|
+
setup() {
|
|
46
|
+
const props = Vue.reactive({ ...example.props, [example.openProp]: false })
|
|
47
|
+
Vue.onMounted(() => Vue.nextTick(() => { props[example.openProp] = true }))
|
|
48
|
+
return () => Vue.h(Component, props, Object.fromEntries(Object.entries(slotMap).map(([name, html]) => [name, () => Vue.h('div', { innerHTML: html })])))
|
|
49
|
+
},
|
|
50
|
+
} }
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
Vue.createApp({ render: () => Vue.h(RemotePreview) }).mount('#demo-root')
|
|
54
|
+
`,n=String.raw`
|
|
55
|
+
bindReactRuntime({ React, ReactDOM, ReactIs })
|
|
56
|
+
// 面板包先于组件包准备;加载请求由 core 复用,错误和重试由适配层处理。
|
|
57
|
+
const panelDep = '@melt-js/libs-react-leva'
|
|
58
|
+
const loader = async () => {
|
|
59
|
+
if (example.panelSchema) await loadHelLib(panelDep)
|
|
60
|
+
return loadHelLib(example.remoteDep || example.packageName)
|
|
61
|
+
}
|
|
62
|
+
const items = example.items.map(item => ({ ...item,
|
|
63
|
+
Component: defineHelComponent({ loader, exportName: item.name }),
|
|
64
|
+
}))
|
|
65
|
+
let content
|
|
66
|
+
if (example.propsPanel) {
|
|
67
|
+
const item = items[0]
|
|
68
|
+
const Panel = defineHelComponent({ dep: panelDep, exportName: 'PropsPanel' })
|
|
69
|
+
function Preview() {
|
|
70
|
+
const [values, setValues] = React.useState(item.props)
|
|
71
|
+
const onChange = React.useCallback(next => setValues({ ...item.props, ...next }), [])
|
|
72
|
+
return React.createElement('div', null,
|
|
73
|
+
React.createElement(item.Component, values),
|
|
74
|
+
React.createElement(Panel, { compName: item.name, schema: example.panelSchema, value: values, onChange }))
|
|
75
|
+
}
|
|
76
|
+
content = React.createElement(Preview)
|
|
77
|
+
} else if (example.panelSchema) {
|
|
78
|
+
const item = items[0]
|
|
79
|
+
const Playground = defineHelComponent({ dep: panelDep, exportName: 'PropsPlayground' })
|
|
80
|
+
content = React.createElement(Playground, {
|
|
81
|
+
components: { [item.name]: item.Component },
|
|
82
|
+
schemas: { [item.name]: example.panelSchema },
|
|
83
|
+
presets: { [item.name]: item.props },
|
|
84
|
+
stageStyles: { [item.name]: { height: '320px', background: '#f6f7f9' } },
|
|
85
|
+
})
|
|
86
|
+
} else {
|
|
87
|
+
content = React.createElement('div', { className: items.length > 1 ? 'example-grid' : '' },
|
|
88
|
+
...items.map(item => React.createElement('section', { key: item.name, className: 'example-item' },
|
|
89
|
+
React.createElement('h2', null, item.label), React.createElement(item.Component, item.props, item.slotHtml?.default ? React.createElement('span', { dangerouslySetInnerHTML: { __html: item.slotHtml.default } }) : item.props.children))))
|
|
90
|
+
}
|
|
91
|
+
ReactDOM.createRoot(document.getElementById('demo-root')).render(content)
|
|
92
|
+
`;export{n as react,t as vue2,o as vue2Modal,e as vue3,a as vue3Modal};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function createSplitPaneController(options: {
|
|
2
|
+
root: HTMLElement
|
|
3
|
+
onChange?: (state: { width: number; min: number; max: number }) => void
|
|
4
|
+
initialWidth?: number; minPanel?: number; maxPanel?: number; minPreview?: number
|
|
5
|
+
}): {
|
|
6
|
+
start(event: PointerEvent, target?: HTMLElement): void; move(event: PointerEvent): void; stop(event?: PointerEvent): void
|
|
7
|
+
reset(): void; key(event: KeyboardEvent): void; dispose(): void
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function A({root:s,onChange:w=()=>{},initialWidth:f=320,minPanel:y=240,maxPanel:m=800,minPreview:x=240}){let n=f,i=null,r=null,a=null,c=!1,p=s.getBoundingClientRect().width;const b=typeof requestAnimationFrame=="function"?requestAnimationFrame:e=>setTimeout(e,16),C=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:clearTimeout,h=()=>{const e=Math.max(0,s.getBoundingClientRect().width-x-2),t=Math.min(m,e||m);return{min:Math.min(y,t),max:t}},l=e=>{const{min:t,max:o}=h();n=Math.round(Math.min(o,Math.max(t,e))),(!r||r.width!==n)&&s.style.setProperty("--leva-panel-width",n+"px"),(!r||r.width!==n||r.min!==t||r.max!==o)&&(r={width:n,min:t,max:o},w(r))},d=e=>{if(!i||e&&e.pointerId!==i.id)return;const t=i;i=null,s.classList.remove("is-resizing"),t.target.hasPointerCapture&&t.target.hasPointerCapture(t.id)&&t.target.releasePointerCapture(t.id)},u=typeof ResizeObserver!="undefined"?new ResizeObserver(()=>{if(c||i)return;const e=s.getBoundingClientRect().width;e!==p&&(p=e,a===null&&(a=b(()=>{a=null,!c&&!i&&l(n)})))}):null;return u&&u.observe(s),l(n),{start(e,t=e.currentTarget){i||e.button!==0||(e.preventDefault(),i={id:e.pointerId,x:e.clientX,width:n,target:t},s.classList.add("is-resizing"),t.setPointerCapture(e.pointerId))},move(e){i&&i.id===e.pointerId&&l(i.width+i.x-e.clientX)},stop:d,reset(){d(),l(f)},key(e){const{min:t,max:o}=h(),g={ArrowLeft:n+(e.shiftKey?50:16),ArrowRight:n-(e.shiftKey?50:16),Home:t,End:o};Object.prototype.hasOwnProperty.call(g,e.key)&&(e.preventDefault(),l(g[e.key]))},dispose(){c=!0,d(),u&&u.disconnect(),a!==null&&(C(a),a=null)}}}export{A as createSplitPaneController};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface DemoTabsScrollState {
|
|
2
|
+
overflowing: boolean
|
|
3
|
+
canScrollLeft: boolean
|
|
4
|
+
canScrollRight: boolean
|
|
5
|
+
}
|
|
6
|
+
export function createDemoTabsController(options: {
|
|
7
|
+
root: HTMLElement
|
|
8
|
+
viewport: HTMLElement
|
|
9
|
+
list: HTMLElement
|
|
10
|
+
onChange?: (state: DemoTabsScrollState) => void
|
|
11
|
+
}): {
|
|
12
|
+
refresh(revealActive?: boolean): void
|
|
13
|
+
scroll(direction: -1 | 1): void
|
|
14
|
+
dispose(): void
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function S({root:W,viewport:t,list:d,onChange:y=()=>{}}){let c=!1,r=null,u=!1,m,g=t.clientWidth;const E=typeof requestAnimationFrame=="function"?requestAnimationFrame:e=>setTimeout(e,16),F=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:clearTimeout,i=()=>W.classList.contains("is-expanded"),h=()=>Math.max(0,t.scrollWidth-t.clientWidth),L=e=>{if(!e||i()||!t.clientWidth)return;const s=t.getBoundingClientRect(),l=e.getBoundingClientRect(),n=4;let f=0;l.width>s.width-n*2?(l.right<s.left+n||l.left>s.right-n)&&(f=l.left-s.left-n):l.left<s.left+n?f=l.left-s.left-n:l.right>s.right-n&&(f=l.right-s.right+n),f&&(t.scrollLeft=Math.min(h(),Math.max(0,t.scrollLeft+f)))},A=()=>{if(c)return;const e=h(),s=Math.max(0,Math.min(t.scrollLeft,e)),l={overflowing:e>1,canScrollLeft:!i()&&s>1,canScrollRight:!i()&&s<e-1};(!m||Object.keys(l).some(n=>l[n]!==m[n]))&&(m=l,y(l))},a=(e=!1)=>{c||(u=u||e,r===null&&(r=E(()=>{r=null,!c&&(u&&L(d.querySelector(".is-active")),u=!1,A())})))},b=e=>{if(i()||e.ctrlKey||!h())return;const l=(Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.deltaY)*(e.deltaMode===1?16:e.deltaMode===2?t.clientWidth:1),n=Math.min(h(),Math.max(0,t.scrollLeft+l));n!==t.scrollLeft&&(e.preventDefault(),t.scrollLeft=n,a())},M=()=>a(),x=e=>{L(e.target.closest(".leva-demo-tabs__item")),a()},R=()=>{const e=g!==t.clientWidth;g=t.clientWidth,a(e)},o=typeof ResizeObserver!="undefined"?new ResizeObserver(R):null;return o&&(o.observe(t),o.observe(d)),t.addEventListener("wheel",b,{passive:!1}),t.addEventListener("scroll",M,{passive:!0}),d.addEventListener("focusin",x),a(!0),{refresh:a,scroll(e){c||i()||t.scrollBy({left:e*Math.max(120,t.clientWidth*.7),behavior:"smooth"})},dispose(){c=!0,o&&o.disconnect(),r!==null&&F(r),t.removeEventListener("wheel",b),t.removeEventListener("scroll",M),d.removeEventListener("focusin",x)}}}export{S as createDemoTabsController};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './remote.mjs'
|
|
1
|
+
export * from './remote.mjs'
|
package/dist/loading.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const s=`
|
|
2
|
+
[data-hel-loading] { position:fixed; inset:0; z-index:2147483647; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:22px; margin:0; background:var(--hel-loading-background,#f8fafc); color:var(--hel-loading-color,#2563eb); font:15px/1.6 system-ui,sans-serif; }
|
|
3
|
+
[data-hel-loading] .hel-loading-shapes { display:grid; grid-template-columns:repeat(2,18px); gap:7px; }
|
|
4
|
+
[data-hel-loading] .hel-loading-square { box-sizing:border-box; width:18px; height:18px; border:3px solid currentColor; border-radius:3px; animation:hel-loading-morph 1.8s ease-in-out infinite; }
|
|
5
|
+
[data-hel-loading] .hel-loading-square:nth-child(2) { animation-delay:.15s; }
|
|
6
|
+
[data-hel-loading] .hel-loading-square:nth-child(3) { animation-delay:.3s; }
|
|
7
|
+
[data-hel-loading] .hel-loading-square:nth-child(4) { animation-delay:.45s; }
|
|
8
|
+
[data-hel-loading] .hel-loading-text { max-width:80vw; text-align:center; white-space:pre-wrap; overflow-wrap:anywhere; }
|
|
9
|
+
@keyframes hel-loading-morph { 50% { transform:rotate(180deg) scale(.55); border-radius:50%; } 100% { transform:rotate(360deg); } }
|
|
10
|
+
@media (prefers-reduced-motion:reduce) { [data-hel-loading] .hel-loading-square { animation:none; } }
|
|
11
|
+
`;function c(n={}){if(n===!1||typeof document=="undefined")return()=>{};const t=n===!0?{}:n,l=document.body||document.documentElement;if(!l)return()=>{};const e=document.createElement("div");e.setAttribute("data-hel-loading",""),e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-busy","true"),t.background&&e.style.setProperty("--hel-loading-background",t.background),t.color&&e.style.setProperty("--hel-loading-color",t.color);const i=document.createElement("style");i.textContent=s;const a=document.createElement("div");a.className="hel-loading-shapes",a.setAttribute("aria-hidden","true");for(let d=0;d<4;d++){const r=document.createElement("span");r.className="hel-loading-square",a.appendChild(r)}const o=document.createElement("div");return o.className="hel-loading-text",o.textContent=t.text!=null?t.text:"\u6B63\u5728\u52A0\u8F7D\u5E94\u7528\u2026",e.appendChild(i),e.appendChild(a),e.appendChild(o),l.appendChild(e),()=>e.remove()}export{c as showHelLoading};
|
|
@@ -20,7 +20,20 @@ export type HelAddressOptions = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export type HelDep = string | HelLoadSpec
|
|
23
|
-
export type
|
|
23
|
+
export type HelLoadingOptions = {
|
|
24
|
+
text?: string
|
|
25
|
+
background?: string
|
|
26
|
+
color?: string
|
|
27
|
+
}
|
|
28
|
+
/** Full-screen startup overlay. No-op outside the browser; cleanup is idempotent. */
|
|
29
|
+
export function showHelLoading(options?: boolean | HelLoadingOptions): () => void
|
|
30
|
+
export type HelPreloadOptions = HelAddressOptions & {
|
|
31
|
+
deps: readonly HelDep[]
|
|
32
|
+
/** Disabled by default. true or an options object enables the startup overlay. */
|
|
33
|
+
loading?: boolean | HelLoadingOptions
|
|
34
|
+
/** Dynamically import/mount the app after preload, before dismissing loading. */
|
|
35
|
+
loadApp?: () => unknown | Promise<unknown>
|
|
36
|
+
}
|
|
24
37
|
export type HelLoadPhase = 'config' | 'meta' | 'assets' | 'ready' | 'exports'
|
|
25
38
|
|
|
26
39
|
export class HelLoadError extends Error {
|
|
@@ -52,12 +65,13 @@ export interface HelLoader {
|
|
|
52
65
|
loadHelLib<T extends object = HelLibRecord>(dep: string | HelLoadSpec<T>, options?: HelAddressOptions): Promise<T>
|
|
53
66
|
/** Explicit caller order, retained for callers with a dependency chain. */
|
|
54
67
|
loadHelLibsSerial(specs: readonly HelLoadSpec[]): Promise<HelLibRecord[]>
|
|
55
|
-
/** Resolves
|
|
68
|
+
/** Resolves after all batches and optional loadApp. Always cleans up startup loading. */
|
|
56
69
|
preloadHelLibs(options: HelPreloadOptions): Promise<Record<string, HelLibRecord>>
|
|
57
70
|
}
|
|
58
71
|
|
|
59
72
|
export type HelFetchLib = (name: string, options: {
|
|
60
73
|
platform?: string
|
|
74
|
+
hook: { onFetchMetaSuccess: (meta: unknown) => void }
|
|
61
75
|
custom: Record<string, unknown>
|
|
62
76
|
}) => Promise<HelLibRecord>
|
|
63
77
|
|
package/dist/remote.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import A from"hel-micro";import y from"./remote-address.cjs";import{showHelLoading as S}from"./loading.mjs";import{showHelLoading as K}from"./loading.mjs";const{preFetchLib:U}=A,{HEL_BASES:z}=y;function g(e){try{return y.packageRef(e)}catch(t){throw p(t.message)}}class m extends Error{constructor({moduleName:t,host:n,phase:s,message:a,missingExports:i=[],cause:r}){super(a,{cause:r}),this.name="HelLoadError",this.moduleName=t,this.host=n,this.phase=s,this.missingExports=i,this.cause=r}}function p(e,t="",n=""){return new m({moduleName:t,host:n,phase:"config",message:"[hel-loader] "+e})}function w(e){let t;try{t=new URL(e)}catch{throw p("\u9700\u8981\u7EDD\u5BF9 HTTP(S) \u5730\u5740\uFF1A"+e)}if(!/^https?:$/.test(t.protocol))throw p("\u4E0D\u652F\u6301\u7684\u5730\u5740\u534F\u8BAE\uFF1A"+e);return t}function j(e){return/\/hel-meta\.json$/i.test(w(e.trim()).pathname)}function x(e,t={}){if(e&&typeof e=="object"){if(typeof e.name!="string"||!e.name.trim()||typeof e.host!="string")throw p("\u663E\u5F0F\u4F9D\u8D56\u9700\u8981 name \u548C host");return w(e.host),{...e,name:e.name.trim()}}if(typeof e!="string"||!e.trim())throw p("\u4F9D\u8D56\u5FC5\u987B\u662F\u5305\u5F15\u7528\u3001URL \u6216\u663E\u5F0F\u4F9D\u8D56\u5BF9\u8C61");const n=e.trim(),s=t.type||"unpkg";if(!["custom","unpkg","github"].includes(s))throw p("\u672A\u77E5\u52A0\u8F7D\u7C7B\u578B\uFF1A"+s);let a,i;if(/^https?:\/\//i.test(n)){a=w(n);const c=a.pathname.replace(/\/+$/,"").replace(/\/(?:(?:hel_dist|dist)(?:\/(?:hel-meta\.json|index\.html))?|hel-meta\.json|index\.html)$/i,"");i=g(decodeURIComponent(c.split("/").pop()||""))}else{i=g(n.replace(/^\//,""));try{a=y.packageUrl(i,{...t,type:s})}catch(c){throw p(c.message)}}const r=a.pathname.replace(/\/+$/,"");if(a.pathname=r,!/\/(?:hel-meta\.json|index\.html)$/i.test(r)){const c=/\/(hel_dist|dist)$/i.exec(r),o=c?c[1].toLowerCase():/^(?:tpl|demo)-/.test(i.name)?"dist":"hel_dist";a.pathname=r+(c?"":"/"+o)+(o==="dist"?"/index.html":"/hel-meta.json")}return{name:i.name,host:a.href}}function E(e){const t=e.name.split("/").pop();return t.startsWith("libs-")?0:t.startsWith("comps-")?1:2}function R(e){if(!e||!Array.isArray(e.deps))throw p("\u9884\u52A0\u8F7D\u9700\u8981 deps \u6570\u7EC4");const t=e.deps.map(s=>x(s,e)),n=new Map;for(const s of t){const a=k(s),i=N(s);if(n.has(a)&&n.get(a)!==i)throw p("\u540C\u4E00\u6A21\u5757\u4E0D\u80FD\u914D\u7F6E\u591A\u4E2A\u5730\u5740\u6216\u7248\u672C\uFF1A"+s.name,s.name,s.host);n.set(a,i)}return t.sort((s,a)=>E(s)-E(a))}function b(e,t,n,s=[]){if(!n||typeof n!="object"&&typeof n!="function")throw new m({moduleName:e,host:t,phase:"ready",message:"[hel-loader] "+e+" \u672A\u8FD4\u56DE\u8FDC\u7A0B\u6A21\u5757\u5BF9\u8C61"});const a=s.filter(i=>!(i in n)||n[i]==null);if(a.length)throw new m({moduleName:e,host:t,phase:"exports",missingExports:a,message:"[hel-loader] "+e+" \u7F3A\u5C11\u5BFC\u51FA\uFF1A"+a.join(", ")})}function $(e,t){const n=e&&e.version&&e.version.src_map;if(!n||!j(t))return;const s=new URL(".",t).href,a=String(n.webDirPath||"").replace(/\/+$/,""),i=r=>{if(typeof r!="string"||!r||/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(r))return r;const c=a&&r.startsWith(a+"/")?new URL(r.slice(a.length+1),s).href:new URL(a?r:r.replace(/^\/+/,""),s).href;if(typeof document!="undefined"&&document.baseURI){const o=A.core,l=new URL(r,document.baseURI).href;o.setCommonData(o.helConsts.KEY_ASSET_CTX,l,{marked:!0,beforeAppend:({setAssetUrl:h})=>{h(c)}})}return c};for(const[r,c]of Object.entries(n))if(r==="headAssetList"||r==="bodyAssetList")for(const o of c||[])for(const l of["src","href"])o.attrs&&o.attrs[l]&&(o.attrs[l]=i(o.attrs[l]));else r.endsWith("List")&&Array.isArray(c)?n[r]=c.map(i):r!=="webDirPath"&&/(?:Path|Src|Index)$/.test(r)&&(n[r]=i(c));/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(a)||(n.webDirPath=s.replace(/\/$/,""))}function L(e){return{...e.platform?{platform:e.platform}:{},hook:{onFetchMetaSuccess:t=>$(t,e.host)},custom:{skipFetchHelMeta:!j(e.host),enable:!0,trust:!0,...e.custom||{},host:e.host,appGroupName:e.appGroupName||e.custom&&e.custom.appGroupName||e.name}}}function k(e){const t=L(e);return JSON.stringify([e.platform||"",t.custom.appGroupName||e.name])}function H(e){return Array.isArray(e)?e.map(H):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(t=>[t,H(e[t])])):e}function N(e){return JSON.stringify(H([e.name,L(e)]))}function M(e=U){const t=new Map;let n=Promise.resolve();function s(r,c={}){let o,l,h;try{o=x(r,c),l=k(o),h=N(o)}catch(f){return Promise.reject(f)}const d=t.get(l);if(d&&d.key!==h)return Promise.reject(p("\u6A21\u5757\u5DF2\u4F7F\u7528\u53E6\u4E00\u5730\u5740\u6216\u7248\u672C\u52A0\u8F7D\uFF1A"+o.name,o.name,o.host));let u=d&&d.promise;return u||(u=n.then(async()=>{try{const f=await e(o.name,L(o));return b(o.name,o.host,f),f}catch(f){throw f instanceof m?f:new m({moduleName:o.name,host:o.host,phase:"assets",cause:f,message:"[hel-loader] "+o.name+" \u52A0\u8F7D\u5931\u8D25\uFF1A"+(f instanceof Error?f.message:String(f))})}}),t.set(l,{key:h,promise:u}),n=u.then(()=>{},()=>{t.delete(l)})),u.then(f=>(b(o.name,o.host,f,o.requiredExports),f))}async function a(r){const c=[];for(const o of r)c.push(await s(o));return c}async function i(r){const c=R(r),o=Object.create(null);if(r.loadApp!==void 0&&typeof r.loadApp!="function")throw p("loadApp \u5FC5\u987B\u662F\u51FD\u6570");const l=r.loading&&(c.length||r.loadApp)?S(r.loading):()=>{};try{for(const h of c)o[h.name]=await s(h);return r.loadApp&&await r.loadApp(),o}finally{l()}}return{loadHelLib:s,loadHelLibsSerial:a,preloadHelLibs:i}}const O=M(),{loadHelLib:P,loadHelLibsSerial:G,preloadHelLibs:I}=O;async function _(e){const t=e.dep?x(e.dep,e):null,n=t?t.name:"remote",s=t?t.host:"";if(!e.exportName||typeof e.exportName!="string")throw p("\u7EC4\u4EF6\u9700\u8981 exportName");if(!t&&typeof e.loader!="function")throw p("\u7EC4\u4EF6\u9700\u8981 dep \u6216 loader");const a=e.loader?await e.loader():await P(t);b(n,s,a,[e.exportName]);const i=a[e.exportName];if(typeof i!="object"&&typeof i!="function")throw new m({moduleName:n,host:s,phase:"exports",missingExports:[e.exportName],message:"[hel-loader] "+e.exportName+" \u4E0D\u662F\u53EF\u7528\u7684\u7EC4\u4EF6\u5BFC\u51FA"});return i}function T(e,t=()=>{}){let n=0,s=!1,a={status:"loading",component:null,error:null};const i=o=>{a=o,t(o)};function r(o){s||(n++,i({status:"error",component:null,error:o}),e.onError&&e.onError(o))}async function c(){if(s)return;const o=++n;i({status:"loading",component:null,error:null});try{const l=await _(e);!s&&o===n&&i({status:"ready",component:l,error:null})}catch(l){!s&&o===n&&r(l)}}return{getState:()=>a,load:c,retry:c,fail:r,dispose:()=>{s=!0,n++}}}function W({packageName:e,target:t,version:n="",projectName:s,baseUrl:a=""}){const i=g(e);i.version=n;const r=y.packageUrl(i,{type:t==="sftp"?"custom":t,base:a,projectName:t==="unpkg"?void 0:s,versioned:t==="unpkg"});return r.pathname+="/hel_dist/hel-meta.json",r.href}export{z as HEL_BASES,m as HelLoadError,b as assertHelExports,T as createHelComponentResource,M as createHelLoader,j as isHelMetaHost,_ as loadHelComponent,P as loadHelLib,G as loadHelLibsSerial,I as preloadHelLibs,x as resolveHelDep,R as resolveHelDeps,W as resolveHelHost,K as showHelLoading};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melt-js/libs-core",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.15-2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "
|
|
7
|
-
"types": "
|
|
5
|
+
"main": "dist/remote.mjs",
|
|
6
|
+
"module": "dist/remote.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public",
|
|
10
10
|
"registry": "https://registry.npmjs.org",
|
|
@@ -20,34 +20,44 @@
|
|
|
20
20
|
"@babel/parser": "7.29.13",
|
|
21
21
|
"@babel/types": "7.29.11",
|
|
22
22
|
"@vue/compiler-sfc": "2.7.14",
|
|
23
|
-
"doctrine": "3.0.0"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
23
|
+
"doctrine": "3.0.0",
|
|
24
|
+
"esbuild": "0.25.12",
|
|
25
|
+
"typescript": "5.9.3",
|
|
26
|
+
"vue-tsc": "3.3.11"
|
|
27
27
|
},
|
|
28
|
+
"devDependencies": {},
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|
|
30
|
-
"types": "./
|
|
31
|
-
"default": "./
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/remote.mjs"
|
|
32
33
|
},
|
|
33
|
-
"./src/*": "./src/*",
|
|
34
34
|
"./scripts/*": "./scripts/*",
|
|
35
35
|
"./package.json": "./package.json",
|
|
36
|
-
"./vdoc-parser": "./scripts/vdoc-parser/index.mjs"
|
|
36
|
+
"./vdoc-parser": "./scripts/vdoc-parser/index.mjs",
|
|
37
|
+
"./browser": {
|
|
38
|
+
"types": "./dist/browser.d.mts",
|
|
39
|
+
"default": "./dist/browser.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./demo": {
|
|
42
|
+
"types": "./dist/demo/index.d.mts",
|
|
43
|
+
"default": "./dist/demo/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./src/*": "./dist/*"
|
|
37
46
|
},
|
|
38
47
|
"files": [
|
|
39
|
-
"
|
|
48
|
+
"dist",
|
|
40
49
|
"scripts",
|
|
41
|
-
"tsconfig.json",
|
|
42
50
|
"README.md"
|
|
43
51
|
],
|
|
44
52
|
"bin": {
|
|
45
53
|
"hel-publish-stage": "./scripts/publish-stage.mjs",
|
|
46
|
-
"hel-check-tdz": "./scripts/check-tdz.mjs"
|
|
54
|
+
"hel-check-tdz": "./scripts/check-tdz.mjs",
|
|
55
|
+
"hel-package-artifacts": "./scripts/package-artifacts.mjs"
|
|
47
56
|
},
|
|
48
57
|
"scripts": {
|
|
49
58
|
"typecheck": "tsc --noEmit",
|
|
50
59
|
"test": "node --test tests/*.test.mjs",
|
|
51
|
-
"publish:stage": "node scripts/publish-stage.mjs"
|
|
60
|
+
"publish:stage": "node scripts/publish-stage.mjs",
|
|
61
|
+
"build": "node scripts/build-browser.mjs"
|
|
52
62
|
}
|
|
53
63
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
const src = fileURLToPath(new URL('../src/', import.meta.url))
|
|
7
|
+
const dist = fileURLToPath(new URL('../dist/', import.meta.url))
|
|
8
|
+
// Keep the ESM module layout for declarations and legacy public subpaths.
|
|
9
|
+
for (const file of fs.readdirSync(src, { recursive: true })) {
|
|
10
|
+
const source = path.join(src, file)
|
|
11
|
+
if (!fs.statSync(source).isFile()) continue
|
|
12
|
+
const target = path.join(dist, file)
|
|
13
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
14
|
+
if (/\.mjs$/.test(file)) {
|
|
15
|
+
await build({ entryPoints: [source], outfile: target, format: 'esm', target: 'es2019', minify: true, sourcemap: false })
|
|
16
|
+
} else if (/\.d\.(mts|ts)$|\.cjs$/.test(file)) {
|
|
17
|
+
fs.copyFileSync(source, target)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
fs.writeFileSync(path.join(dist, 'index.d.ts'), "export * from './remote.mjs'\n")
|
|
21
|
+
|
|
22
|
+
await build({
|
|
23
|
+
entryPoints: [fileURLToPath(new URL('../src/browser.mjs', import.meta.url))],
|
|
24
|
+
outfile: fileURLToPath(new URL('../dist/browser.mjs', import.meta.url)),
|
|
25
|
+
bundle: true,
|
|
26
|
+
format: 'esm',
|
|
27
|
+
platform: 'browser',
|
|
28
|
+
target: 'es2020',
|
|
29
|
+
minify: true,
|
|
30
|
+
legalComments: 'eof',
|
|
31
|
+
})
|
package/scripts/check-tdz.mjs
CHANGED
|
@@ -228,9 +228,12 @@ function analyzeCode(code, filename) {
|
|
|
228
228
|
for (const key of Object.keys(node)) {
|
|
229
229
|
if (SKIP_KEYS.has(key)) continue
|
|
230
230
|
const value = node[key]
|
|
231
|
+
// The discriminant runs before the case block's lexical environment exists.
|
|
232
|
+
// `switch (x) { case 0: let x }` reads the outer x here.
|
|
233
|
+
const childScope = node.type === 'SwitchStatement' && key === 'discriminant' ? scope : current
|
|
231
234
|
if (Array.isArray(value)) {
|
|
232
|
-
for (const item of value) if (isNode(item)) build(item,
|
|
233
|
-
} else if (isNode(value)) build(value,
|
|
235
|
+
for (const item of value) if (isNode(item)) build(item, childScope)
|
|
236
|
+
} else if (isNode(value)) build(value, childScope)
|
|
234
237
|
}
|
|
235
238
|
}
|
|
236
239
|
build(ast, root)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import { parse } from '@babel/parser'
|
|
3
|
+
|
|
4
|
+
/** Supplement props schemas with Vue event declarations; no component evaluation. */
|
|
5
|
+
export function parseComponentEvents(file) {
|
|
6
|
+
const source = fs.readFileSync(file, 'utf8')
|
|
7
|
+
const events = new Map()
|
|
8
|
+
const add = (name, type = '', description = '') => {
|
|
9
|
+
if (!name || typeof name !== 'string') return
|
|
10
|
+
const previous = events.get(name)
|
|
11
|
+
events.set(name, { name, type: type || previous?.type || '', description: description || previous?.description || '', default: '', required: false, version: '', isEvent: true, bindable: false })
|
|
12
|
+
}
|
|
13
|
+
for (const match of source.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
14
|
+
const code = match[1]
|
|
15
|
+
const ast = parse(code, { sourceType: 'module', plugins: ['typescript', 'jsx', 'decorators-legacy'] })
|
|
16
|
+
const text = node => node ? code.slice(node.start, node.end) : ''
|
|
17
|
+
const nameOf = node => node?.name || node?.value
|
|
18
|
+
const description = node => (node.leadingComments || []).map(comment => comment.value.replace(/\*/g, '').trim()).join(' ').replace(/^@description\s*/, '')
|
|
19
|
+
function walk(node) {
|
|
20
|
+
if (!node || typeof node !== 'object') return
|
|
21
|
+
if (node.type === 'CallExpression') {
|
|
22
|
+
const callee = node.callee
|
|
23
|
+
if (callee.type === 'Identifier' && callee.name === 'defineEmits') {
|
|
24
|
+
const declaration = node.typeParameters?.params?.[0] || node.typeArguments?.params?.[0]
|
|
25
|
+
if (declaration?.type === 'TSTypeLiteral') {
|
|
26
|
+
for (const member of declaration.members) {
|
|
27
|
+
if (member.type === 'TSPropertySignature') add(nameOf(member.key), text(member.typeAnnotation?.typeAnnotation), description(member))
|
|
28
|
+
if (member.type === 'TSCallSignatureDeclaration') {
|
|
29
|
+
const parameters = member.parameters || []
|
|
30
|
+
const eventType = parameters[0]?.typeAnnotation?.typeAnnotation
|
|
31
|
+
const names = eventType?.type === 'TSUnionType' ? eventType.types : [eventType]
|
|
32
|
+
for (const item of names) if (item?.type === 'TSLiteralType') add(item.literal.value, parameters.slice(1).map(text).join(', ') || '无参数', description(member))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const runtime = node.arguments[0]
|
|
37
|
+
if (runtime?.type === 'ArrayExpression') for (const item of runtime.elements) add(item?.value)
|
|
38
|
+
if (runtime?.type === 'ObjectExpression') for (const item of runtime.properties) add(nameOf(item.key), '', description(item))
|
|
39
|
+
}
|
|
40
|
+
if ((callee.type === 'Identifier' && callee.name === 'emit') || (callee.type === 'MemberExpression' && nameOf(callee.property) === '$emit')) {
|
|
41
|
+
if (node.arguments[0]?.type === 'StringLiteral') add(node.arguments[0].value)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (node.type === 'ObjectProperty' && nameOf(node.key) === 'emits') {
|
|
45
|
+
if (node.value.type === 'ArrayExpression') for (const item of node.value.elements) add(item?.value)
|
|
46
|
+
if (node.value.type === 'ObjectExpression') for (const item of node.value.properties) add(nameOf(item.key), '', description(item))
|
|
47
|
+
}
|
|
48
|
+
for (const [key, child] of Object.entries(node)) {
|
|
49
|
+
if (['loc', 'comments', 'tokens', 'leadingComments', 'trailingComments'].includes(key)) continue
|
|
50
|
+
if (Array.isArray(child)) child.forEach(walk)
|
|
51
|
+
else if (child && typeof child === 'object') walk(child)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
walk(ast.program)
|
|
55
|
+
}
|
|
56
|
+
return [...events.values()]
|
|
57
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
|
|
4
|
+
function normalizeAssetUrl(value) {
|
|
5
|
+
if (typeof value !== 'string') return value
|
|
6
|
+
const origin = value.match(/^(?:https?:)?\/\/[^/\\]+/i)?.[0] || ''
|
|
7
|
+
return origin + value.slice(origin.length).replace(/\\/g, '/').replace(/\/{2,}/g, '/')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function normalizeSrcMap(srcMap) {
|
|
11
|
+
for (const [key, value] of Object.entries(srcMap)) {
|
|
12
|
+
if (key.endsWith('List') && Array.isArray(value)) {
|
|
13
|
+
if (key === 'headAssetList' || key === 'bodyAssetList') {
|
|
14
|
+
for (const asset of value) {
|
|
15
|
+
for (const attr of ['src', 'href']) {
|
|
16
|
+
if (asset.attrs?.[attr]) asset.attrs[attr] = normalizeAssetUrl(asset.attrs[attr])
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else srcMap[key] = [...new Set(value.map(normalizeAssetUrl))]
|
|
20
|
+
} else if (typeof value === 'string' && /(?:Path|Src|Index)$/.test(key)) srcMap[key] = normalizeAssetUrl(value)
|
|
21
|
+
}
|
|
22
|
+
// hel-dev-utils trims the trailing slash, turning the root homePage into an empty string.
|
|
23
|
+
if (!srcMap.webDirPath && srcMap.htmlIndexSrc === '/index.html') srcMap.webDirPath = '/'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Accept the caller's directly declared hel-dev-utils dependency; no cross-package lookup.
|
|
27
|
+
module.exports = function withHelBuildPaths(helDevUtils) {
|
|
28
|
+
const adapted = { ...helDevUtils }
|
|
29
|
+
for (const factory of ['createVueSubApp', 'createReactSubApp', 'createLibSubApp']) {
|
|
30
|
+
adapted[factory] = (...args) => {
|
|
31
|
+
const appInfo = helDevUtils[factory](...args)
|
|
32
|
+
if (process.env.HEL_RELATIVE_PATH === '1' && process.env.HEL_APP_HOME_PAGE === '/' && appInfo.homePage === '/') {
|
|
33
|
+
appInfo.getPublicPathOrUrl = () => '/'
|
|
34
|
+
}
|
|
35
|
+
return appInfo
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
adapted.extractHelMetaJson = async options => {
|
|
39
|
+
if (process.env.HEL_RELATIVE_PATH !== '1') return helDevUtils.extractHelMetaJson(options)
|
|
40
|
+
const meta = await helDevUtils.extractHelMetaJson({ ...options, writeMetaJsonToDist: false })
|
|
41
|
+
normalizeSrcMap(meta.version.src_map)
|
|
42
|
+
if (options.writeMetaJsonToDist !== false) {
|
|
43
|
+
fs.writeFileSync(path.join(options.buildDirFullPath, 'hel-meta.json'), JSON.stringify(meta, null, 2))
|
|
44
|
+
}
|
|
45
|
+
return meta
|
|
46
|
+
}
|
|
47
|
+
return adapted
|
|
48
|
+
}
|