@lumal/cockpit 0.0.1-beta
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/cockpit.css +2 -0
- package/dist/createCockpitRegistry-D5F4d5By.js +30 -0
- package/dist/createCockpitRegistry-DHr9nXJY.cjs +1 -0
- package/dist/designer.cjs +1 -0
- package/dist/designer.js +2282 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +30 -0
- package/dist/registry.cjs +1 -0
- package/dist/registry.js +2 -0
- package/dist/resolveComponent-BF1aCxAk.cjs +1 -0
- package/dist/resolveComponent-QbJRsdxR.js +308 -0
- package/dist/runtime-CXiih7DE.js +627 -0
- package/dist/runtime-wzWMTWrS.cjs +1 -0
- package/dist/runtime.cjs +1 -0
- package/dist/runtime.js +3 -0
- package/dist/src/composables/index.d.ts +9 -0
- package/dist/src/composables/index.d.ts.map +1 -0
- package/dist/src/composables/useCanvasScale.d.ts +30 -0
- package/dist/src/composables/useCanvasScale.d.ts.map +1 -0
- package/dist/src/composables/useCockpit.d.ts +14 -0
- package/dist/src/composables/useCockpit.d.ts.map +1 -0
- package/dist/src/composables/useCockpitAutoRefresh.d.ts +27 -0
- package/dist/src/composables/useCockpitAutoRefresh.d.ts.map +1 -0
- package/dist/src/composables/useCockpitContext.d.ts +16 -0
- package/dist/src/composables/useCockpitContext.d.ts.map +1 -0
- package/dist/src/composables/useCockpitRefresh.d.ts +9 -0
- package/dist/src/composables/useCockpitRefresh.d.ts.map +1 -0
- package/dist/src/config/defaults.d.ts +19 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/index.d.ts +13 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/migrate.d.ts +6 -0
- package/dist/src/config/migrate.d.ts.map +1 -0
- package/dist/src/config/normalize.d.ts +3 -0
- package/dist/src/config/normalize.d.ts.map +1 -0
- package/dist/src/config/validate.d.ts +8 -0
- package/dist/src/config/validate.d.ts.map +1 -0
- package/dist/src/designer/CockpitComponentLibrary.vue.d.ts +16 -0
- package/dist/src/designer/CockpitComponentLibrary.vue.d.ts.map +1 -0
- package/dist/src/designer/CockpitLayoutEditor.vue.d.ts +34 -0
- package/dist/src/designer/CockpitLayoutEditor.vue.d.ts.map +1 -0
- package/dist/src/designer/CockpitWidgetDropZone.vue.d.ts +45 -0
- package/dist/src/designer/CockpitWidgetDropZone.vue.d.ts.map +1 -0
- package/dist/src/designer/CockpitWidgetPreview.vue.d.ts +19 -0
- package/dist/src/designer/CockpitWidgetPreview.vue.d.ts.map +1 -0
- package/dist/src/designer/LumalCockpitDesigner.vue.d.ts +41 -0
- package/dist/src/designer/LumalCockpitDesigner.vue.d.ts.map +1 -0
- package/dist/src/designer/confirmWidgetReplacement.d.ts +3 -0
- package/dist/src/designer/confirmWidgetReplacement.d.ts.map +1 -0
- package/dist/src/designer/index.d.ts +13 -0
- package/dist/src/designer/index.d.ts.map +1 -0
- package/dist/src/designer/types.d.ts +13 -0
- package/dist/src/designer/types.d.ts.map +1 -0
- package/dist/src/designer/useCockpitDraft.d.ts +50 -0
- package/dist/src/designer/useCockpitDraft.d.ts.map +1 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/messaging/createCockpitMessageBus.d.ts +16 -0
- package/dist/src/messaging/createCockpitMessageBus.d.ts.map +1 -0
- package/dist/src/messaging/index.d.ts +5 -0
- package/dist/src/messaging/index.d.ts.map +1 -0
- package/dist/src/messaging/topics.d.ts +10 -0
- package/dist/src/messaging/topics.d.ts.map +1 -0
- package/dist/src/messaging/types.d.ts +24 -0
- package/dist/src/messaging/types.d.ts.map +1 -0
- package/dist/src/registry/createCockpitRegistry.d.ts +4 -0
- package/dist/src/registry/createCockpitRegistry.d.ts.map +1 -0
- package/dist/src/registry/index.d.ts +3 -0
- package/dist/src/registry/index.d.ts.map +1 -0
- package/dist/src/registry/types.d.ts +20 -0
- package/dist/src/registry/types.d.ts.map +1 -0
- package/dist/src/runtime/CockpitErrorBoundary.vue.d.ts +26 -0
- package/dist/src/runtime/CockpitErrorBoundary.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpit.vue.d.ts +105 -0
- package/dist/src/runtime/LumalCockpit.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpitCanvas.vue.d.ts +47 -0
- package/dist/src/runtime/LumalCockpitCanvas.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpitCard.vue.d.ts +31 -0
- package/dist/src/runtime/LumalCockpitCard.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpitContainer.vue.d.ts +12 -0
- package/dist/src/runtime/LumalCockpitContainer.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpitRegion.vue.d.ts +11 -0
- package/dist/src/runtime/LumalCockpitRegion.vue.d.ts.map +1 -0
- package/dist/src/runtime/LumalCockpitWidgetHost.vue.d.ts +12 -0
- package/dist/src/runtime/LumalCockpitWidgetHost.vue.d.ts.map +1 -0
- package/dist/src/runtime/card.d.ts +16 -0
- package/dist/src/runtime/card.d.ts.map +1 -0
- package/dist/src/runtime/context.d.ts +25 -0
- package/dist/src/runtime/context.d.ts.map +1 -0
- package/dist/src/runtime/index.d.ts +19 -0
- package/dist/src/runtime/index.d.ts.map +1 -0
- package/dist/src/runtime/resolveComponent.d.ts +13 -0
- package/dist/src/runtime/resolveComponent.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +83 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/validate-DkC_IHrC.js +94 -0
- package/dist/validate-KSzm5SZW.cjs +1 -0
- package/package.json +73 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./resolveComponent-BF1aCxAk.cjs"),t=require("./runtime-wzWMTWrS.cjs"),n=require("./validate-KSzm5SZW.cjs"),r=require("./createCockpitRegistry-DHr9nXJY.cjs");let i=require("vue");function a(n){let r=e.y();(0,i.onBeforeUnmount)(r.messages.subscribe(t.f,n,{targetId:r.instanceId}))}function o(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function s(e){if(!o(e))throw Error(`驾驶舱配置必须是对象。`);if(e.schemaVersion!==3)throw Error(`仅支持 v3 驾驶舱配置,请重新创建布局。`);return{...e}}function c(e){return e.schemaVersion!==3}function l(t){return e.i(s(t))}exports.COCKPIT_REFRESH_TOPIC=t.f,exports.COCKPIT_SCHEMA_VERSION=e.a,exports.DEFAULT_COCKPIT_AUTO_REFRESH_INTERVAL_MS=t.u,exports.DEFAULT_COLUMN_WIDTH=e.o,exports.DEFAULT_REGION_WIDTH=e.s,exports.DEFAULT_ROW_HEIGHT=e.c,exports.LumalCockpit=t.t,exports.LumalCockpitCard=t.n,exports.computeCanvasScale=e.b,exports.createCockpitId=e.l,exports.createCockpitMessageBus=e.r,exports.createCockpitRegistry=r.t,exports.createDefaultCockpitConfig=e.u,exports.createGridCell=e.d,exports.createGridColumn=e.f,exports.createGridRow=e.p,exports.createLayout=e.m,exports.createRegion=e.h,exports.createWidgetInstance=e.g,exports.equalizeRegionColumns=e._,exports.migrateCockpitConfig=s,exports.needsMigration=c,exports.normalizeCockpitConfig=e.i,exports.prepareCockpitConfig=l,exports.useCanvasScale=e.x,exports.useCockpit=t.l,exports.useCockpitAutoRefresh=t.d,exports.useCockpitContext=e.y,exports.useCockpitRefresh=a,exports.useCockpitRuntimeEnv=t.c,exports.validateCockpitConfig=n.t;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, o as d, p as f, r as p, s as m, u as h, x as g, y as _ } from "./resolveComponent-QbJRsdxR.js";
|
|
2
|
+
import { c as v, d as y, f as b, l as x, n as S, t as C, u as w } from "./runtime-CXiih7DE.js";
|
|
3
|
+
import { t as T } from "./validate-DkC_IHrC.js";
|
|
4
|
+
import { t as E } from "./createCockpitRegistry-D5F4d5By.js";
|
|
5
|
+
import { onBeforeUnmount as D } from "vue";
|
|
6
|
+
//#region src/composables/useCockpitRefresh.ts
|
|
7
|
+
function O(e) {
|
|
8
|
+
let t = _();
|
|
9
|
+
D(t.messages.subscribe(b, e, { targetId: t.instanceId }));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/config/migrate.ts
|
|
13
|
+
function k(e) {
|
|
14
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
15
|
+
}
|
|
16
|
+
function A(e) {
|
|
17
|
+
if (!k(e)) throw Error("驾驶舱配置必须是对象。");
|
|
18
|
+
if (e.schemaVersion !== 3) throw Error("仅支持 v3 驾驶舱配置,请重新创建布局。");
|
|
19
|
+
return { ...e };
|
|
20
|
+
}
|
|
21
|
+
function j(e) {
|
|
22
|
+
return e.schemaVersion !== 3;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/config/index.ts
|
|
26
|
+
function M(e) {
|
|
27
|
+
return c(A(e));
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { b as COCKPIT_REFRESH_TOPIC, t as COCKPIT_SCHEMA_VERSION, w as DEFAULT_COCKPIT_AUTO_REFRESH_INTERVAL_MS, d as DEFAULT_COLUMN_WIDTH, m as DEFAULT_REGION_WIDTH, r as DEFAULT_ROW_HEIGHT, C as LumalCockpit, S as LumalCockpitCard, n as computeCanvasScale, l as createCockpitId, p as createCockpitMessageBus, E as createCockpitRegistry, h as createDefaultCockpitConfig, i as createGridCell, a as createGridColumn, f as createGridRow, u as createLayout, s as createRegion, o as createWidgetInstance, e as equalizeRegionColumns, A as migrateCockpitConfig, j as needsMigration, c as normalizeCockpitConfig, M as prepareCockpitConfig, g as useCanvasScale, x as useCockpit, y as useCockpitAutoRefresh, _ as useCockpitContext, O as useCockpitRefresh, v as useCockpitRuntimeEnv, T as validateCockpitConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./createCockpitRegistry-DHr9nXJY.cjs");exports.createCockpitRegistry=e.t;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("vue"),t=require("element-plus"),n=require("@lumal/icons-vue");function r(e,t,n,r){if(n<=0||r<=0||e<=0||t<=0)return{scale:1,scaledWidth:n,scaledHeight:r,offsetX:0,offsetY:0};let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{scale:i,scaledWidth:a,scaledHeight:o,offsetX:(e-a)/2,offsetY:(t-o)/2}}function i(t,n){let i=(0,e.shallowRef)({scale:1,scaledWidth:n.baseWidth(),scaledHeight:n.baseHeight(),offsetX:0,offsetY:0}),a=(0,e.ref)(!1),o=null,s=0;function c(){let e=t.value;e&&(i.value=r(e.clientWidth,e.clientHeight,n.baseWidth(),n.baseHeight()),a.value=!0)}function l(){if(typeof requestAnimationFrame>`u`){c();return}s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{s=0,c()})}return(0,e.onMounted)(()=>{c(),typeof ResizeObserver<`u`&&t.value&&(o=new ResizeObserver(l),o.observe(t.value))}),(0,e.onBeforeUnmount)(()=>{s&&typeof cancelAnimationFrame<`u`&&cancelAnimationFrame(s),o?.disconnect(),o=null}),{result:i,ready:a,measure:c}}var a=Symbol(`lumal-cockpit-context`);function o(t){(0,e.provide)(a,t)}function s(t=!1){let n=(0,e.inject)(a,null);if(!n&&!t)throw Error(`[cockpit] 未找到驾驶舱渲染上下文,请确认组件在 LumalCockpit 内渲染。`);return n}var c=3,l=320,u=420,d=100,f=0;function p(e=`ck`){f+=1;let t=Date.now().toString(36),n=Math.random().toString(36).slice(2,8);return`${e}-${t}-${f.toString(36)}-${n}`}function m(e,t){return{id:p(`widget`),type:e,title:t}}function h(e=320){return{id:p(`column`),width:e}}function g(e){let t=Math.max(1,e.columns.length),n=Math.max(t,Math.round(e.width)||420);e.width=n;let r=Math.floor(n/t),i=n-r*t;e.columns.forEach(e=>{e.width=r+ +(i>0),i>0&&--i})}function _(){return{id:p(`cell`)}}function v(e,t=`grid`,n=100){return{id:p(`row`),height:n,mode:t,cells:t===`grid`?Array.from({length:Math.max(1,e)},_):[],widgets:[]}}function y(e=1,t=1,n=420){let r=Array.from({length:Math.max(1,e)},()=>h()),i={width:n,columns:r,rows:Array.from({length:Math.max(1,t)},()=>v(r.length,`grid`,100/Math.max(1,t)))};return g(i),i}function b(e=`新布局`){return{id:p(`layout`),title:e,left:y(),right:y()}}function x(e=p(`cockpit`)){let t=b(`布局 1`);return{schemaVersion:3,id:e,title:`驾驶舱`,activeLayoutId:t.id,layouts:[t]}}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(e){return Array.isArray(e)?e:[]}function w(e,t){return typeof e==`string`&&e.trim()?e:t}function T(e,t){let n=typeof e==`number`?e:Number(e);return Number.isFinite(n)&&n>0?n:t}function E(e){if(!(!S(e)||typeof e.type!=`string`||!e.type.trim()))return{id:w(e.id,p(`widget`)),type:e.type,title:typeof e.title==`string`&&e.title.trim()?e.title:void 0}}function D(e){let t=S(e)?e:{};return{id:w(t.id,p(`cell`)),widget:E(t.widget)}}function O(e){let t=C(e).map(e=>{let t=S(e)?e:{};return{id:w(t.id,p(`column`)),width:Math.round(T(t.width,320))}});return t.length?t:[h()]}function k(e,t){let n=S(e)?e:{},r=n.mode===`tabs`?`tabs`:`grid`,i={id:w(n.id,p(`row`)),height:T(n.height,100),mode:r,cells:[],widgets:[]};if(r===`tabs`){i.widgets=C(n.widgets).map(E).filter(e=>!!e);let e=typeof n.activeWidgetId==`string`?n.activeWidgetId:void 0;i.activeWidgetId=i.widgets.some(t=>t.id===e)?e:i.widgets[0]?.id}else{let e=C(n.cells).map(D).slice(0,t);for(;e.length<t;)e.push(_());i.cells=e}return i}function A(e){let t=e.reduce((e,t)=>e+t.height,0);if(t<=0){let t=100/e.length;e.forEach(e=>{e.height=t});return}e.forEach(e=>{e.height=Number((e.height/t*100).toFixed(3))});let n=Number((100-e.reduce((e,t)=>e+t.height,0)).toFixed(3));e[e.length-1]&&(e[e.length-1].height=Number((e[e.length-1].height+n).toFixed(3)))}function j(e){let t=S(e)?e:{},n=O(t.columns),r=n.reduce((e,t)=>e+t.width,0),i=Math.round(T(t.width,r>0?r:420)),a=C(t.rows).map(e=>k(e,n.length));a.length||a.push(v(n.length)),A(a);let o={width:i,columns:n,rows:a};return g(o),o}function M(e){let t=S(e)?e:{},n=b(w(t.title,`未命名布局`));return n.id=w(t.id,n.id),n.left=j(t.left),n.right=j(t.right),n}function N(e){let t=S(e)?e:{},n=C(t.layouts).map(M),r={schemaVersion:3,id:w(t.id,p(`cockpit`)),title:w(t.title,`驾驶舱`),layouts:n.length?n:[b(`布局 1`)]},i=typeof t.activeLayoutId==`string`?t.activeLayoutId:void 0;return r.activeLayoutId=r.layouts.some(e=>e.id===i)?i:r.layouts[0].id,r}function P(){let e=new Map;function t(t){let n=e.get(t.topic);if(!n||n.size===0)return;let r=[...n];for(let e of r){let n=t.targetId===void 0,r=e.targetId!==void 0&&e.targetId===t.targetId;if(!(!n&&!r))try{e.handler(t)}catch(e){console.error(`[cockpit] 消息订阅处理器异常(topic: ${t.topic})`,e)}}}function n(t,n,r){let i=e.get(t);i||(i=new Set,e.set(t,i));let a={handler:n,targetId:r?.targetId};return i.add(a),function(){let n=e.get(t);n&&(n.delete(a),n.size===0&&e.delete(t))}}function r(t){for(let[n,r]of e){for(let e of[...r])e.targetId===t&&r.delete(e);r.size===0&&e.delete(n)}}return{publish:t,subscribe:n,clearInstance:r}}var F={class:`lumal-cockpit-error-boundary`},I={class:`lumal-cockpit-error-boundary__fallback`,role:`alert`},L=(0,e.defineComponent)({__name:`CockpitErrorBoundary`,emits:[`error`],setup(r,{emit:i}){let a=i,o=(0,e.ref)(!1),s=(0,e.ref)(null),c=(0,e.ref)(0);(0,e.onErrorCaptured)(e=>(o.value=!0,s.value=e,a(`error`,e),!1));async function l(){o.value=!1,s.value=null,await(0,e.nextTick)(),c.value+=1}return(r,i)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,F,[o.value?(0,e.renderSlot)(r.$slots,`error`,{key:0,error:s.value,retry:l},()=>[(0,e.createElementVNode)(`div`,I,[i[1]||=(0,e.createElementVNode)(`p`,{class:`lumal-cockpit-error-boundary__message`},` 组件渲染失败 `,-1),(0,e.createVNode)((0,e.unref)(t.ElButton),{class:`lumal-cockpit-error-boundary__retry`,onClick:l},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(n.LumalIcon),{name:`lumal:refresh`,size:15}),i[0]||=(0,e.createTextVNode)(` 重试 `,-1)]),_:1})])]):(0,e.renderSlot)(r.$slots,`default`,{key:c.value})]))}}),R=new WeakMap;function z(t){if(typeof t==`function`){let n=t,r=R.get(n);if(r)return r;let i=(0,e.defineAsyncComponent)(t);return R.set(n,i),i}return t}Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return s}});
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createElementBlock as e, createElementVNode as t, createTextVNode as n, createVNode as r, defineAsyncComponent as i, defineComponent as a, inject as o, nextTick as s, onBeforeUnmount as c, onErrorCaptured as l, onMounted as u, openBlock as d, provide as f, ref as p, renderSlot as m, shallowRef as h, unref as g, withCtx as _ } from "vue";
|
|
2
|
+
import { ElButton as v } from "element-plus";
|
|
3
|
+
import { LumalIcon as ee } from "@lumal/icons-vue";
|
|
4
|
+
//#region src/composables/useCanvasScale.ts
|
|
5
|
+
function y(e, t, n, r) {
|
|
6
|
+
if (n <= 0 || r <= 0 || e <= 0 || t <= 0) return {
|
|
7
|
+
scale: 1,
|
|
8
|
+
scaledWidth: n,
|
|
9
|
+
scaledHeight: r,
|
|
10
|
+
offsetX: 0,
|
|
11
|
+
offsetY: 0
|
|
12
|
+
};
|
|
13
|
+
let i = Math.min(e / n, t / r), a = n * i, o = r * i;
|
|
14
|
+
return {
|
|
15
|
+
scale: i,
|
|
16
|
+
scaledWidth: a,
|
|
17
|
+
scaledHeight: o,
|
|
18
|
+
offsetX: (e - a) / 2,
|
|
19
|
+
offsetY: (t - o) / 2
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function b(e, t) {
|
|
23
|
+
let n = h({
|
|
24
|
+
scale: 1,
|
|
25
|
+
scaledWidth: t.baseWidth(),
|
|
26
|
+
scaledHeight: t.baseHeight(),
|
|
27
|
+
offsetX: 0,
|
|
28
|
+
offsetY: 0
|
|
29
|
+
}), r = p(!1), i = null, a = 0;
|
|
30
|
+
function o() {
|
|
31
|
+
let i = e.value;
|
|
32
|
+
i && (n.value = y(i.clientWidth, i.clientHeight, t.baseWidth(), t.baseHeight()), r.value = !0);
|
|
33
|
+
}
|
|
34
|
+
function s() {
|
|
35
|
+
if (typeof requestAnimationFrame > "u") {
|
|
36
|
+
o();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
a && cancelAnimationFrame(a), a = requestAnimationFrame(() => {
|
|
40
|
+
a = 0, o();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return u(() => {
|
|
44
|
+
o(), typeof ResizeObserver < "u" && e.value && (i = new ResizeObserver(s), i.observe(e.value));
|
|
45
|
+
}), c(() => {
|
|
46
|
+
a && typeof cancelAnimationFrame < "u" && cancelAnimationFrame(a), i?.disconnect(), i = null;
|
|
47
|
+
}), {
|
|
48
|
+
result: n,
|
|
49
|
+
ready: r,
|
|
50
|
+
measure: o
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/composables/useCockpitContext.ts
|
|
55
|
+
var x = Symbol("lumal-cockpit-context");
|
|
56
|
+
function S(e) {
|
|
57
|
+
f(x, e);
|
|
58
|
+
}
|
|
59
|
+
function C(e = !1) {
|
|
60
|
+
let t = o(x, null);
|
|
61
|
+
if (!t && !e) throw Error("[cockpit] 未找到驾驶舱渲染上下文,请确认组件在 LumalCockpit 内渲染。");
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/config/defaults.ts
|
|
66
|
+
var w = 3, T = 320, E = 420, D = 100, O = 0;
|
|
67
|
+
function k(e = "ck") {
|
|
68
|
+
O += 1;
|
|
69
|
+
let t = Date.now().toString(36), n = Math.random().toString(36).slice(2, 8);
|
|
70
|
+
return `${e}-${t}-${O.toString(36)}-${n}`;
|
|
71
|
+
}
|
|
72
|
+
function A(e, t) {
|
|
73
|
+
return {
|
|
74
|
+
id: k("widget"),
|
|
75
|
+
type: e,
|
|
76
|
+
title: t
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function j(e = 320) {
|
|
80
|
+
return {
|
|
81
|
+
id: k("column"),
|
|
82
|
+
width: e
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function M(e) {
|
|
86
|
+
let t = Math.max(1, e.columns.length), n = Math.max(t, Math.round(e.width) || 420);
|
|
87
|
+
e.width = n;
|
|
88
|
+
let r = Math.floor(n / t), i = n - r * t;
|
|
89
|
+
e.columns.forEach((e) => {
|
|
90
|
+
e.width = r + +(i > 0), i > 0 && --i;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function N() {
|
|
94
|
+
return { id: k("cell") };
|
|
95
|
+
}
|
|
96
|
+
function P(e, t = "grid", n = 100) {
|
|
97
|
+
return {
|
|
98
|
+
id: k("row"),
|
|
99
|
+
height: n,
|
|
100
|
+
mode: t,
|
|
101
|
+
cells: t === "grid" ? Array.from({ length: Math.max(1, e) }, N) : [],
|
|
102
|
+
widgets: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function F(e = 1, t = 1, n = 420) {
|
|
106
|
+
let r = Array.from({ length: Math.max(1, e) }, () => j()), i = {
|
|
107
|
+
width: n,
|
|
108
|
+
columns: r,
|
|
109
|
+
rows: Array.from({ length: Math.max(1, t) }, () => P(r.length, "grid", 100 / Math.max(1, t)))
|
|
110
|
+
};
|
|
111
|
+
return M(i), i;
|
|
112
|
+
}
|
|
113
|
+
function I(e = "新布局") {
|
|
114
|
+
return {
|
|
115
|
+
id: k("layout"),
|
|
116
|
+
title: e,
|
|
117
|
+
left: F(),
|
|
118
|
+
right: F()
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function L(e = k("cockpit")) {
|
|
122
|
+
let t = I("布局 1");
|
|
123
|
+
return {
|
|
124
|
+
schemaVersion: 3,
|
|
125
|
+
id: e,
|
|
126
|
+
title: "驾驶舱",
|
|
127
|
+
activeLayoutId: t.id,
|
|
128
|
+
layouts: [t]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/config/normalize.ts
|
|
133
|
+
function R(e) {
|
|
134
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
135
|
+
}
|
|
136
|
+
function z(e) {
|
|
137
|
+
return Array.isArray(e) ? e : [];
|
|
138
|
+
}
|
|
139
|
+
function B(e, t) {
|
|
140
|
+
return typeof e == "string" && e.trim() ? e : t;
|
|
141
|
+
}
|
|
142
|
+
function V(e, t) {
|
|
143
|
+
let n = typeof e == "number" ? e : Number(e);
|
|
144
|
+
return Number.isFinite(n) && n > 0 ? n : t;
|
|
145
|
+
}
|
|
146
|
+
function H(e) {
|
|
147
|
+
if (!(!R(e) || typeof e.type != "string" || !e.type.trim())) return {
|
|
148
|
+
id: B(e.id, k("widget")),
|
|
149
|
+
type: e.type,
|
|
150
|
+
title: typeof e.title == "string" && e.title.trim() ? e.title : void 0
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function U(e) {
|
|
154
|
+
let t = R(e) ? e : {};
|
|
155
|
+
return {
|
|
156
|
+
id: B(t.id, k("cell")),
|
|
157
|
+
widget: H(t.widget)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function W(e) {
|
|
161
|
+
let t = z(e).map((e) => {
|
|
162
|
+
let t = R(e) ? e : {};
|
|
163
|
+
return {
|
|
164
|
+
id: B(t.id, k("column")),
|
|
165
|
+
width: Math.round(V(t.width, 320))
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
return t.length ? t : [j()];
|
|
169
|
+
}
|
|
170
|
+
function G(e, t) {
|
|
171
|
+
let n = R(e) ? e : {}, r = n.mode === "tabs" ? "tabs" : "grid", i = {
|
|
172
|
+
id: B(n.id, k("row")),
|
|
173
|
+
height: V(n.height, 100),
|
|
174
|
+
mode: r,
|
|
175
|
+
cells: [],
|
|
176
|
+
widgets: []
|
|
177
|
+
};
|
|
178
|
+
if (r === "tabs") {
|
|
179
|
+
i.widgets = z(n.widgets).map(H).filter((e) => !!e);
|
|
180
|
+
let e = typeof n.activeWidgetId == "string" ? n.activeWidgetId : void 0;
|
|
181
|
+
i.activeWidgetId = i.widgets.some((t) => t.id === e) ? e : i.widgets[0]?.id;
|
|
182
|
+
} else {
|
|
183
|
+
let e = z(n.cells).map(U).slice(0, t);
|
|
184
|
+
for (; e.length < t;) e.push(N());
|
|
185
|
+
i.cells = e;
|
|
186
|
+
}
|
|
187
|
+
return i;
|
|
188
|
+
}
|
|
189
|
+
function K(e) {
|
|
190
|
+
let t = e.reduce((e, t) => e + t.height, 0);
|
|
191
|
+
if (t <= 0) {
|
|
192
|
+
let t = 100 / e.length;
|
|
193
|
+
e.forEach((e) => {
|
|
194
|
+
e.height = t;
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
e.forEach((e) => {
|
|
199
|
+
e.height = Number((e.height / t * 100).toFixed(3));
|
|
200
|
+
});
|
|
201
|
+
let n = Number((100 - e.reduce((e, t) => e + t.height, 0)).toFixed(3));
|
|
202
|
+
e[e.length - 1] && (e[e.length - 1].height = Number((e[e.length - 1].height + n).toFixed(3)));
|
|
203
|
+
}
|
|
204
|
+
function q(e) {
|
|
205
|
+
let t = R(e) ? e : {}, n = W(t.columns), r = n.reduce((e, t) => e + t.width, 0), i = Math.round(V(t.width, r > 0 ? r : 420)), a = z(t.rows).map((e) => G(e, n.length));
|
|
206
|
+
a.length || a.push(P(n.length)), K(a);
|
|
207
|
+
let o = {
|
|
208
|
+
width: i,
|
|
209
|
+
columns: n,
|
|
210
|
+
rows: a
|
|
211
|
+
};
|
|
212
|
+
return M(o), o;
|
|
213
|
+
}
|
|
214
|
+
function J(e) {
|
|
215
|
+
let t = R(e) ? e : {}, n = I(B(t.title, "未命名布局"));
|
|
216
|
+
return n.id = B(t.id, n.id), n.left = q(t.left), n.right = q(t.right), n;
|
|
217
|
+
}
|
|
218
|
+
function Y(e) {
|
|
219
|
+
let t = R(e) ? e : {}, n = z(t.layouts).map(J), r = {
|
|
220
|
+
schemaVersion: 3,
|
|
221
|
+
id: B(t.id, k("cockpit")),
|
|
222
|
+
title: B(t.title, "驾驶舱"),
|
|
223
|
+
layouts: n.length ? n : [I("布局 1")]
|
|
224
|
+
}, i = typeof t.activeLayoutId == "string" ? t.activeLayoutId : void 0;
|
|
225
|
+
return r.activeLayoutId = r.layouts.some((e) => e.id === i) ? i : r.layouts[0].id, r;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/messaging/createCockpitMessageBus.ts
|
|
229
|
+
function X() {
|
|
230
|
+
let e = /* @__PURE__ */ new Map();
|
|
231
|
+
function t(t) {
|
|
232
|
+
let n = e.get(t.topic);
|
|
233
|
+
if (!n || n.size === 0) return;
|
|
234
|
+
let r = [...n];
|
|
235
|
+
for (let e of r) {
|
|
236
|
+
let n = t.targetId === void 0, r = e.targetId !== void 0 && e.targetId === t.targetId;
|
|
237
|
+
if (!(!n && !r)) try {
|
|
238
|
+
e.handler(t);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.error(`[cockpit] 消息订阅处理器异常(topic: ${t.topic})`, e);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function n(t, n, r) {
|
|
245
|
+
let i = e.get(t);
|
|
246
|
+
i || (i = /* @__PURE__ */ new Set(), e.set(t, i));
|
|
247
|
+
let a = {
|
|
248
|
+
handler: n,
|
|
249
|
+
targetId: r?.targetId
|
|
250
|
+
};
|
|
251
|
+
return i.add(a), function() {
|
|
252
|
+
let n = e.get(t);
|
|
253
|
+
n && (n.delete(a), n.size === 0 && e.delete(t));
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function r(t) {
|
|
257
|
+
for (let [n, r] of e) {
|
|
258
|
+
for (let e of [...r]) e.targetId === t && r.delete(e);
|
|
259
|
+
r.size === 0 && e.delete(n);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
publish: t,
|
|
264
|
+
subscribe: n,
|
|
265
|
+
clearInstance: r
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/runtime/CockpitErrorBoundary.vue?vue&type=script&setup=true&lang.ts
|
|
270
|
+
var Z = { class: "lumal-cockpit-error-boundary" }, Q = {
|
|
271
|
+
class: "lumal-cockpit-error-boundary__fallback",
|
|
272
|
+
role: "alert"
|
|
273
|
+
}, te = /* @__PURE__ */ a({
|
|
274
|
+
__name: "CockpitErrorBoundary",
|
|
275
|
+
emits: ["error"],
|
|
276
|
+
setup(i, { emit: a }) {
|
|
277
|
+
let o = a, c = p(!1), u = p(null), f = p(0);
|
|
278
|
+
l((e) => (c.value = !0, u.value = e, o("error", e), !1));
|
|
279
|
+
async function h() {
|
|
280
|
+
c.value = !1, u.value = null, await s(), f.value += 1;
|
|
281
|
+
}
|
|
282
|
+
return (i, a) => (d(), e("div", Z, [c.value ? m(i.$slots, "error", {
|
|
283
|
+
key: 0,
|
|
284
|
+
error: u.value,
|
|
285
|
+
retry: h
|
|
286
|
+
}, () => [t("div", Q, [a[1] ||= t("p", { class: "lumal-cockpit-error-boundary__message" }, " 组件渲染失败 ", -1), r(g(v), {
|
|
287
|
+
class: "lumal-cockpit-error-boundary__retry",
|
|
288
|
+
onClick: h
|
|
289
|
+
}, {
|
|
290
|
+
default: _(() => [r(g(ee), {
|
|
291
|
+
name: "lumal:refresh",
|
|
292
|
+
size: 15
|
|
293
|
+
}), a[0] ||= n(" 重试 ", -1)]),
|
|
294
|
+
_: 1
|
|
295
|
+
})])]) : m(i.$slots, "default", { key: f.value })]));
|
|
296
|
+
}
|
|
297
|
+
}), $ = /* @__PURE__ */ new WeakMap();
|
|
298
|
+
function ne(e) {
|
|
299
|
+
if (typeof e == "function") {
|
|
300
|
+
let t = e, n = $.get(t);
|
|
301
|
+
if (n) return n;
|
|
302
|
+
let r = i(e);
|
|
303
|
+
return $.set(t, r), r;
|
|
304
|
+
}
|
|
305
|
+
return e;
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
export { M as _, w as a, y as b, D as c, N as d, j as f, A as g, F as h, Y as i, k as l, I as m, te as n, T as o, P as p, X as r, E as s, ne as t, L as u, S as v, b as x, C as y };
|