@metagl/smartearth-base 0.0.0-stage → 0.3.0

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/dist/vite.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface SmartEarthAssetsOptions {
4
+ /**
5
+ * 资源拷到哪个目录,默认 Vite 的 publicDir(通常是 <root>/public)。
6
+ * 拷出来的 cesium/、assets/、resources/ 应加进 .gitignore。
7
+ */
8
+ readonly outDir?: string;
9
+ /** Cesium 资源在站点上的子路径,默认 'cesium'(即 `${base}cesium`)。 */
10
+ readonly cesiumPath?: string;
11
+ }
12
+ /**
13
+ * SmartEarth 运行所需的 Vite 配置:
14
+ * - 把 Cesium(Assets/ThirdParty/Widgets/Workers)与 sdk-render(assets/resources)资源拷到 publicDir;
15
+ * - define CESIUM_BASE_URL,并在页面里写 window.CESIUM_BASE_URL;
16
+ * - cesium 别名到源码入口、dedupe,sdk-render 不预构建。
17
+ */
18
+ declare function smartEarthAssets(options?: SmartEarthAssetsOptions): Plugin;
19
+
20
+ export { type SmartEarthAssetsOptions, smartEarthAssets as default, smartEarthAssets };
package/dist/vite.js ADDED
@@ -0,0 +1,89 @@
1
+ import { mkdir, cp, writeFile, readFile } from 'fs/promises';
2
+ import { existsSync } from 'fs';
3
+ import { createRequire } from 'module';
4
+ import { resolve, join, dirname } from 'path';
5
+
6
+ // src/vite/index.ts
7
+ var STAMP_FILE = ".smartearth-assets.json";
8
+ function packageRoot(requireFrom, name) {
9
+ return dirname(requireFrom.resolve(`${name}/package.json`));
10
+ }
11
+ function readVersion(root) {
12
+ const pkg = createRequire(join(root, "package.json"))(join(root, "package.json"));
13
+ return pkg.version ?? "unknown";
14
+ }
15
+ function copyJobs(cesiumRoot, sdkRenderRoot, cesiumPath) {
16
+ return [
17
+ { source: resolve(cesiumRoot, "Build/Cesium/Assets"), target: `${cesiumPath}/Assets` },
18
+ { source: resolve(cesiumRoot, "Build/Cesium/ThirdParty"), target: `${cesiumPath}/ThirdParty` },
19
+ { source: resolve(cesiumRoot, "Build/Cesium/Widgets"), target: `${cesiumPath}/Widgets` },
20
+ { source: resolve(cesiumRoot, "Build/Cesium/Workers"), target: `${cesiumPath}/Workers` },
21
+ { source: resolve(sdkRenderRoot, "assets"), target: "assets" },
22
+ { source: resolve(sdkRenderRoot, "resources"), target: "resources" }
23
+ ];
24
+ }
25
+ async function isUpToDate(stampPath, stamp, targets) {
26
+ if (!existsSync(stampPath) || targets.some((target) => !existsSync(target))) return false;
27
+ return await readFile(stampPath, "utf8") === stamp;
28
+ }
29
+ function smartEarthAssets(options = {}) {
30
+ const cesiumPath = (options.cesiumPath ?? "cesium").replace(/^\/+|\/+$/g, "");
31
+ let cesiumRoot = "";
32
+ let sdkRenderRoot = "";
33
+ let cesiumBaseUrl = `/${cesiumPath}`;
34
+ return {
35
+ name: "smartearth-assets",
36
+ enforce: "pre",
37
+ config(userConfig) {
38
+ const root = resolve(userConfig.root ?? process.cwd());
39
+ const requireFromRoot = createRequire(join(root, "package.json"));
40
+ cesiumRoot = packageRoot(requireFromRoot, "cesium");
41
+ sdkRenderRoot = packageRoot(requireFromRoot, "@metagl/sdk-render");
42
+ const base = userConfig.base ?? "/";
43
+ cesiumBaseUrl = `${base.endsWith("/") ? base : `${base}/`}${cesiumPath}`;
44
+ return {
45
+ define: { CESIUM_BASE_URL: JSON.stringify(cesiumBaseUrl) },
46
+ resolve: {
47
+ alias: [{ find: /^cesium$/, replacement: resolve(cesiumRoot, "Source/Cesium.js") }],
48
+ dedupe: ["cesium"]
49
+ },
50
+ optimizeDeps: {
51
+ include: ["cesium"],
52
+ exclude: ["@metagl/sdk-render"]
53
+ }
54
+ };
55
+ },
56
+ async configResolved(config) {
57
+ const outDir = options.outDir ? resolve(config.root, options.outDir) : config.publicDir;
58
+ if (!outDir) {
59
+ throw new Error("[smartearth-assets] \u6CA1\u6709 publicDir\uFF0C\u8BF7\u4F20 outDir \u6307\u5B9A\u8D44\u6E90\u62F7\u8D1D\u76EE\u5F55\u3002");
60
+ }
61
+ const stamp = JSON.stringify({
62
+ cesium: readVersion(cesiumRoot),
63
+ sdkRender: readVersion(sdkRenderRoot),
64
+ cesiumPath
65
+ });
66
+ const stampPath = join(outDir, STAMP_FILE);
67
+ const jobs = copyJobs(cesiumRoot, sdkRenderRoot, cesiumPath);
68
+ if (await isUpToDate(stampPath, stamp, jobs.map((job) => join(outDir, job.target)))) return;
69
+ for (const job of jobs) {
70
+ const destination = join(outDir, job.target);
71
+ await mkdir(dirname(destination), { recursive: true });
72
+ await cp(job.source, destination, { recursive: true, force: true });
73
+ }
74
+ await writeFile(stampPath, stamp, "utf8");
75
+ },
76
+ transformIndexHtml() {
77
+ return [
78
+ {
79
+ tag: "script",
80
+ children: `window.CESIUM_BASE_URL = ${JSON.stringify(cesiumBaseUrl)};`,
81
+ injectTo: "head-prepend"
82
+ }
83
+ ];
84
+ }
85
+ };
86
+ }
87
+ var vite_default = smartEarthAssets;
88
+
89
+ export { vite_default as default, smartEarthAssets };
package/dist/vue.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, VNode } from 'vue';
3
+ import { l as Earth, j as CreateEarthOptions } from './createEarth-BY0dtgQQ.js';
4
+ import { S as SmartEarthError } from './errors-cB7IQlHy.js';
5
+ import { PresetLibrary, PresetSource, PresetSummary } from './presets.js';
6
+ import 'cesium';
7
+ import '@metagl/sdk-render';
8
+
9
+ /**
10
+ * 预设库面板(同 sdk-render 样板间的配置库):大区 / 城市浏览与搜索、SDK 内置 / 业务集群 / 样板间预设卡、
11
+ * 预览 → 确认 / 取消、存到业务集群、下载、生成样板间上传包。逻辑在 createPresetLibrary 上,这里只是界面。
12
+ *
13
+ * <SmartEarthPresetLibrary :earth="earth" :store="store" adcode="110000" @applied="..." @close="..." />
14
+ * 要自己配数据源就传 :library="createPresetLibrary(earth, {...})",此时 store 不再起作用。
15
+ */
16
+ declare const SmartEarthPresetLibrary: vue.DefineComponent<vue.ExtractPropTypes<{
17
+ earth: {
18
+ type: PropType<Earth>;
19
+ required: true;
20
+ };
21
+ /** 现成的预设库;不传就按 store 建一个。只在挂载时读一次。 */
22
+ library: {
23
+ type: PropType<PresetLibrary>;
24
+ default: undefined;
25
+ };
26
+ /** 存预设的地方,上层建好传进来(如 httpPresetStore({ baseUrl, getToken, clusterId }));不传就只能浏览、不能存。只在挂载时读一次。 */
27
+ store: {
28
+ type: PropType<PresetSource>;
29
+ default: undefined;
30
+ };
31
+ /** 打开时默认选中的城市(6 位 adcode)。 */
32
+ adcode: {
33
+ type: StringConstructor;
34
+ default: undefined;
35
+ };
36
+ /** 显示右上角关闭按钮(点了发 close 事件)。 */
37
+ closable: {
38
+ type: BooleanConstructor;
39
+ default: boolean;
40
+ };
41
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
42
+ [key: string]: any;
43
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
44
+ applied: (entry: PresetSummary) => boolean;
45
+ saved: (entry: PresetSummary) => boolean;
46
+ close: () => true;
47
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
48
+ earth: {
49
+ type: PropType<Earth>;
50
+ required: true;
51
+ };
52
+ /** 现成的预设库;不传就按 store 建一个。只在挂载时读一次。 */
53
+ library: {
54
+ type: PropType<PresetLibrary>;
55
+ default: undefined;
56
+ };
57
+ /** 存预设的地方,上层建好传进来(如 httpPresetStore({ baseUrl, getToken, clusterId }));不传就只能浏览、不能存。只在挂载时读一次。 */
58
+ store: {
59
+ type: PropType<PresetSource>;
60
+ default: undefined;
61
+ };
62
+ /** 打开时默认选中的城市(6 位 adcode)。 */
63
+ adcode: {
64
+ type: StringConstructor;
65
+ default: undefined;
66
+ };
67
+ /** 显示右上角关闭按钮(点了发 close 事件)。 */
68
+ closable: {
69
+ type: BooleanConstructor;
70
+ default: boolean;
71
+ };
72
+ }>> & Readonly<{
73
+ onClose?: (() => any) | undefined;
74
+ onApplied?: ((entry: PresetSummary) => any) | undefined;
75
+ onSaved?: ((entry: PresetSummary) => any) | undefined;
76
+ }>, {
77
+ adcode: string;
78
+ library: PresetLibrary;
79
+ store: PresetSource;
80
+ closable: boolean;
81
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
82
+
83
+ /**
84
+ * <SmartEarthView :options="..." @ready="(earth) => ..." @error="(err) => ..." />
85
+ *
86
+ * 挂载时 createEarth,卸载时 destroy。options 只在挂载时读一次;要换授权或底图请用 :key 重建组件。
87
+ */
88
+ declare const SmartEarthView: vue.DefineComponent<vue.ExtractPropTypes<{
89
+ options: {
90
+ type: PropType<CreateEarthOptions>;
91
+ required: true;
92
+ };
93
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
94
+ [key: string]: any;
95
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
96
+ ready: (earth: Earth) => boolean;
97
+ error: (error: SmartEarthError) => boolean;
98
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
99
+ options: {
100
+ type: PropType<CreateEarthOptions>;
101
+ required: true;
102
+ };
103
+ }>> & Readonly<{
104
+ onReady?: ((earth: Earth) => any) | undefined;
105
+ onError?: ((error: SmartEarthError) => any) | undefined;
106
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
107
+
108
+ export { SmartEarthPresetLibrary, SmartEarthView, SmartEarthView as default };
package/dist/vue.js ADDED
@@ -0,0 +1,291 @@
1
+ import { createEarth } from './chunk-24R3PPPA.js';
2
+ import { createPresetLibrary } from './chunk-POH7K3F4.js';
3
+ import { SmartEarthError, describeCause } from './chunk-UENQT22J.js';
4
+ import { defineComponent, h, ref, shallowRef, onMounted, onBeforeUnmount, computed } from 'vue';
5
+
6
+ // src/vue/presetLibraryStyle.ts
7
+ var STYLE_ID = "smartearth-preset-library-style";
8
+ var CSS = `
9
+ .se-pl{display:flex;flex-direction:column;gap:8px;width:100%;max-height:100%;overflow-y:auto;box-sizing:border-box;padding:10px 14px;border-radius:8px;background:var(--se-pl-bg,#0b1020);color:var(--se-pl-fg,#e5e7eb);font:13px/1.5 system-ui,'Microsoft YaHei',sans-serif}
10
+ .se-pl h2,.se-pl h3{margin:0;font-size:13px;font-weight:600}
11
+ .se-pl-head{display:flex;justify-content:space-between;align-items:center}
12
+ .se-pl-row,.se-pl-chips{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
13
+ .se-pl-cities{display:flex;flex-wrap:wrap;gap:4px;max-height:120px;overflow-y:auto}
14
+ .se-pl-cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
15
+ .se-pl-card{display:flex;flex-direction:column;gap:4px;padding:6px;border:1px solid #334155;border-radius:6px;background:var(--se-pl-card-bg,#0f172a)}
16
+ .se-pl-card[data-active="true"]{border-color:var(--se-pl-accent,#2563eb)}
17
+ .se-pl .se-pl-thumb{height:80px;padding:4px;border:0;border-radius:4px;background:linear-gradient(135deg,#1e3a8a,#0f766e) center/cover;text-align:left;cursor:pointer}
18
+ .se-pl-thumb span{font-size:11px;padding:1px 4px;border-radius:3px;background:rgb(0 0 0 / 50%);color:#fff}
19
+ .se-pl small,.se-pl-hint{color:#94a3b8}
20
+ .se-pl-banner{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:6px;border-radius:6px;background:rgb(37 99 235 / 25%)}
21
+ .se-pl-save{display:flex;flex-direction:column;gap:4px;padding-top:8px;border-top:1px solid #334155}
22
+ .se-pl input{flex:1;min-width:0;padding:3px 6px;border:1px solid #475569;border-radius:6px;background:transparent;color:inherit;font:inherit}
23
+ .se-pl button{padding:3px 8px;border:1px solid #475569;border-radius:6px;background:transparent;color:inherit;font:inherit;cursor:pointer}
24
+ .se-pl button[aria-pressed="true"]{background:var(--se-pl-accent,#2563eb);border-color:var(--se-pl-accent,#2563eb)}
25
+ .se-pl button:disabled{opacity:.4;cursor:not-allowed}
26
+ .se-pl-message{margin:0;color:#fcd34d}
27
+ `;
28
+ function injectPresetLibraryStyle() {
29
+ if (typeof document === "undefined" || document.getElementById(STYLE_ID)) return;
30
+ const style = document.createElement("style");
31
+ style.id = STYLE_ID;
32
+ style.textContent = CSS;
33
+ document.head.appendChild(style);
34
+ }
35
+
36
+ // src/vue/PresetLibrary.ts
37
+ function download(filename, content, type) {
38
+ const isDataUrl = content.startsWith("data:");
39
+ const link = document.createElement("a");
40
+ link.href = isDataUrl ? content : URL.createObjectURL(new Blob([content], { type }));
41
+ link.download = filename;
42
+ link.click();
43
+ if (!isDataUrl) setTimeout(() => URL.revokeObjectURL(link.href), 1e3);
44
+ }
45
+ function useLibraryState(library, initialAdcode) {
46
+ const state = {
47
+ cities: ref([]),
48
+ region: ref("all"),
49
+ query: ref(""),
50
+ hits: ref(null),
51
+ city: ref(null),
52
+ cards: ref([]),
53
+ loading: ref(false),
54
+ previewing: ref(null),
55
+ note: ref(null),
56
+ message: ref(""),
57
+ name: ref(""),
58
+ desc: ref("")
59
+ };
60
+ const guard = async (action) => {
61
+ try {
62
+ await action();
63
+ state.message.value = "";
64
+ return true;
65
+ } catch (error) {
66
+ state.message.value = error.message;
67
+ return false;
68
+ }
69
+ };
70
+ const refreshCards = async () => {
71
+ if (state.city.value) state.cards.value = await library.list(state.city.value.adcode);
72
+ };
73
+ const selectCity = async (next) => {
74
+ state.city.value = next;
75
+ state.loading.value = true;
76
+ await guard(refreshCards);
77
+ state.loading.value = false;
78
+ };
79
+ onMounted(
80
+ () => guard(async () => {
81
+ state.cities.value = await library.listCities();
82
+ const initial = state.cities.value.find((item) => item.adcode === initialAdcode);
83
+ if (initial) await selectCity(initial);
84
+ })
85
+ );
86
+ const visibleCities = computed(
87
+ () => state.cities.value.filter(
88
+ (item) => (state.region.value === "all" || item.regionId === state.region.value) && (state.hits.value === null || state.hits.value.has(item.adcode))
89
+ )
90
+ );
91
+ return { library, state, guard, refreshCards, selectCity, visibleCities };
92
+ }
93
+ var SmartEarthPresetLibrary = defineComponent({
94
+ name: "SmartEarthPresetLibrary",
95
+ props: {
96
+ earth: { type: Object, required: true },
97
+ /** 现成的预设库;不传就按 store 建一个。只在挂载时读一次。 */
98
+ library: { type: Object, default: void 0 },
99
+ /** 存预设的地方,上层建好传进来(如 httpPresetStore({ baseUrl, getToken, clusterId }));不传就只能浏览、不能存。只在挂载时读一次。 */
100
+ store: { type: Object, default: void 0 },
101
+ /** 打开时默认选中的城市(6 位 adcode)。 */
102
+ adcode: { type: String, default: void 0 },
103
+ /** 显示右上角关闭按钮(点了发 close 事件)。 */
104
+ closable: { type: Boolean, default: true }
105
+ },
106
+ emits: {
107
+ applied: (entry) => Boolean(entry),
108
+ saved: (entry) => Boolean(entry),
109
+ close: () => true
110
+ },
111
+ setup(props, { emit }) {
112
+ injectPresetLibraryStyle();
113
+ const library = props.library ?? createPresetLibrary(props.earth, props.store ? { store: props.store } : {});
114
+ const sourceLabel = (card2) => library.sources.find((item) => item.id === card2.source)?.label ?? card2.source;
115
+ const { state, guard, refreshCards, selectCity, visibleCities } = useLibraryState(library, props.adcode);
116
+ const search = () => guard(async () => {
117
+ const text = state.query.value.trim();
118
+ state.hits.value = text ? new Set((await library.searchCities(text)).map((item) => item.adcode)) : null;
119
+ });
120
+ const preview = (entry) => guard(async () => {
121
+ await library.preview(entry);
122
+ state.previewing.value = entry;
123
+ state.note.value = library.compatibility(entry);
124
+ });
125
+ const confirm = () => {
126
+ const entry = state.previewing.value;
127
+ library.confirmPreview();
128
+ state.previewing.value = null;
129
+ state.note.value = null;
130
+ if (entry) emit("applied", entry);
131
+ };
132
+ const cancel = () => guard(async () => {
133
+ await library.cancelPreview();
134
+ state.previewing.value = null;
135
+ state.note.value = null;
136
+ });
137
+ const downloadCard = (entry) => guard(async () => {
138
+ const document2 = await library.getDocument(entry);
139
+ download(`${entry.name}.json`, JSON.stringify(document2, null, 2), "application/json");
140
+ });
141
+ const removeEntry = (entry) => guard(async () => {
142
+ await library.remove(entry);
143
+ await refreshCards();
144
+ });
145
+ const save = () => guard(async () => {
146
+ if (!state.city.value) throw new Error("\u5148\u9009\u4E00\u4E2A\u57CE\u5E02\uFF0C\u9884\u8BBE\u6309\u57CE\u5E02\u4FDD\u5B58");
147
+ const entry = await library.save({
148
+ name: state.name.value,
149
+ desc: state.desc.value,
150
+ ...state.city.value ? { adcode: state.city.value.adcode } : {}
151
+ });
152
+ state.name.value = "";
153
+ state.desc.value = "";
154
+ await refreshCards();
155
+ emit("saved", entry);
156
+ });
157
+ const makeCityPackage = async () => {
158
+ let uploadDir = "";
159
+ await guard(async () => {
160
+ if (!state.city.value) throw new Error("\u5148\u9009\u4E00\u4E2A\u57CE\u5E02");
161
+ const pack = await library.bucketUploadPackage(state.city.value.adcode, { name: state.name.value, desc: state.desc.value });
162
+ download(pack.filename, JSON.stringify(pack.config, null, 2), "application/json");
163
+ if (pack.thumb) download(pack.thumb.filename, pack.thumb.dataUrl, "image/jpeg");
164
+ download("index.json", JSON.stringify(pack.index, null, 2), "application/json");
165
+ uploadDir = pack.uploadDir;
166
+ });
167
+ if (uploadDir) state.message.value = `\u5DF2\u4E0B\u8F7D\u914D\u7F6E\u3001\u622A\u56FE\u4E0E index.json\uFF0C\u4EA4\u7ED9\u6709 CDN \u5199\u6743\u9650\u7684\u4EBA\u4E0A\u4F20\u5230 ${uploadDir}`;
168
+ };
169
+ const button = (label, onClick, extra = {}) => h("button", { type: "button", onClick, ...extra }, label);
170
+ const input = (model, placeholder, onEnter) => h("input", {
171
+ value: model.value,
172
+ placeholder,
173
+ onInput: (event) => model.value = event.target.value,
174
+ ...onEnter ? { onKeydown: (event) => event.key === "Enter" && onEnter() } : {}
175
+ });
176
+ const card = (entry) => h("article", { class: "se-pl-card", "data-active": String(state.previewing.value?.id === entry.id), key: entry.id }, [
177
+ h(
178
+ "button",
179
+ {
180
+ type: "button",
181
+ class: "se-pl-thumb",
182
+ style: entry.thumb ? { backgroundImage: `url(${entry.thumb})` } : {},
183
+ title: "\u9884\u89C8",
184
+ onClick: () => preview(entry)
185
+ },
186
+ [h("span", sourceLabel(entry))]
187
+ ),
188
+ h("strong", entry.name),
189
+ entry.desc ? h("small", entry.desc) : null,
190
+ h("div", { class: "se-pl-chips" }, [
191
+ entry.source === "builtin" ? null : button("\u4E0B\u8F7D", () => downloadCard(entry)),
192
+ entry.writable ? button("\u5220\u9664", () => removeEntry(entry)) : null
193
+ ])
194
+ ]);
195
+ return () => {
196
+ const city = state.city.value;
197
+ return h("section", { class: "se-pl", "aria-label": "\u9884\u8BBE\u5E93" }, [
198
+ h("div", { class: "se-pl-head" }, [
199
+ h("h2", "\u9884\u8BBE\u5E93"),
200
+ props.closable ? button("\xD7", () => emit("close"), { "aria-label": "\u5173\u95ED" }) : null
201
+ ]),
202
+ h("div", { class: "se-pl-row" }, [input(state.query, "\u641C\u57CE\u5E02 / \u7701\u4EFD / \u5927\u533A / \u9884\u8BBE\u540D", search), button("\u641C\u7D22", search)]),
203
+ h("div", { class: "se-pl-chips" }, [
204
+ button("\u5168\u90E8", () => state.region.value = "all", { "aria-pressed": state.region.value === "all" }),
205
+ ...library.regions.map(
206
+ (item) => button(item.name, () => state.region.value = item.id, { key: item.id, "aria-pressed": state.region.value === item.id })
207
+ )
208
+ ]),
209
+ h(
210
+ "div",
211
+ { class: "se-pl-cities" },
212
+ visibleCities.value.map(
213
+ (item) => button(item.name, () => selectCity(item), { key: item.adcode, "aria-pressed": city?.adcode === item.adcode })
214
+ )
215
+ ),
216
+ city ? h("h3", `${city.name} \xB7 ${city.adcode}`) : null,
217
+ city && state.loading.value ? h("p", { class: "se-pl-hint" }, "\u8BFB\u53D6\u4E2D\u2026") : null,
218
+ city && !state.loading.value && state.cards.value.length === 0 ? h("p", { class: "se-pl-hint" }, "\u8FD9\u4E2A\u57CE\u5E02\u8FD8\u6CA1\u6709\u9884\u8BBE\uFF0C\u53EF\u4EE5\u5728\u4E0B\u9762\u4FDD\u5B58\u4E00\u4E2A\u3002") : null,
219
+ city ? h("div", { class: "se-pl-cards" }, state.cards.value.map(card)) : null,
220
+ state.previewing.value ? h("div", { class: "se-pl-banner" }, [
221
+ `\u6B63\u5728\u9884\u89C8\u300C${state.previewing.value.name}\u300D`,
222
+ button("\u786E\u8BA4", confirm),
223
+ button("\u53D6\u6D88\uFF08\u6062\u590D\u539F\u6837\uFF09", cancel),
224
+ state.note.value ? h("small", state.note.value) : null
225
+ ]) : null,
226
+ h("div", { class: "se-pl-save" }, [
227
+ input(state.name, "\u540D\u79F0"),
228
+ input(state.desc, "\u63CF\u8FF0\uFF08\u53EF\u9009\uFF09"),
229
+ h("div", { class: "se-pl-chips" }, [
230
+ button(library.canSave ? "\u4FDD\u5B58\u4E3A\u9884\u8BBE" : "\u4FDD\u5B58\uFF08\u672A\u914D\u7F6E\u9884\u8BBE\u5B58\u50A8\uFF09", save, { disabled: !library.canSave || !city }),
231
+ library.sources.some((item) => item.id === "bucket") ? button("\u751F\u6210\u6837\u677F\u95F4\u4E0A\u4F20\u5305", makeCityPackage, { disabled: !city }) : null
232
+ ])
233
+ ]),
234
+ state.message.value ? h("p", { class: "se-pl-message" }, state.message.value) : null
235
+ ]);
236
+ };
237
+ }
238
+ });
239
+
240
+ // src/vue/index.ts
241
+ var SmartEarthView = defineComponent({
242
+ name: "SmartEarthView",
243
+ props: {
244
+ options: {
245
+ type: Object,
246
+ required: true
247
+ }
248
+ },
249
+ emits: {
250
+ ready: (earth) => Boolean(earth),
251
+ error: (error) => error instanceof SmartEarthError
252
+ },
253
+ setup(props, { emit, expose }) {
254
+ const container = ref(null);
255
+ const earth = shallowRef(null);
256
+ let unmounted = false;
257
+ onMounted(async () => {
258
+ const element = container.value;
259
+ if (!element) return;
260
+ try {
261
+ const created = await createEarth(element, props.options);
262
+ if (unmounted) {
263
+ created.destroy();
264
+ return;
265
+ }
266
+ earth.value = created;
267
+ emit("ready", created);
268
+ } catch (error) {
269
+ if (unmounted) return;
270
+ emit(
271
+ "error",
272
+ error instanceof SmartEarthError ? error : new SmartEarthError("RENDER_INIT_FAILED", describeCause(error), error)
273
+ );
274
+ }
275
+ });
276
+ onBeforeUnmount(() => {
277
+ unmounted = true;
278
+ earth.value?.destroy();
279
+ earth.value = null;
280
+ });
281
+ expose({ earth });
282
+ return () => h("div", {
283
+ ref: container,
284
+ class: "smartearth-view",
285
+ style: { position: "relative", width: "100%", height: "100%", overflow: "hidden" }
286
+ });
287
+ }
288
+ });
289
+ var vue_default = SmartEarthView;
290
+
291
+ export { SmartEarthPresetLibrary, SmartEarthView, vue_default as default };
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
- {
2
- "name": "@metagl/smartearth-base",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@metagl/smartearth-base",
3
+ "version": "0.3.0",
4
+ "description": "集群业务地图底层包:基于 @metagl/sdk-render 的三维地球(替代已废弃的 @agent-earth/smart-earth)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "packageManager": "pnpm@10.26.0",
8
+ "engines": {
9
+ "node": ">=20.0.0"
10
+ },
11
+ "sideEffects": false,
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "CHANGELOG.md"
16
+ ],
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./vite": {
26
+ "types": "./dist/vite.d.ts",
27
+ "import": "./dist/vite.js"
28
+ },
29
+ "./presets": {
30
+ "types": "./dist/presets.d.ts",
31
+ "import": "./dist/presets.js"
32
+ },
33
+ "./vue": {
34
+ "types": "./dist/vue.d.ts",
35
+ "import": "./dist/vue.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "typecheck": "tsc --noEmit -p tsconfig.json",
42
+ "test": "vitest run",
43
+ "check": "pnpm typecheck && pnpm test && pnpm build",
44
+ "example:dev": "pnpm build && pnpm --filter smartearth-base-example-vue dev"
45
+ },
46
+ "peerDependencies": {
47
+ "@metagl/sdk-render": "^3.0.0 || ^4.0.1",
48
+ "cesium": ">=1.132.0 <1.137.0",
49
+ "vite": ">=5.0.0",
50
+ "vue": "^3.5.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "vite": {
54
+ "optional": true
55
+ },
56
+ "vue": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@metagl/sdk-render": "4.0.3",
62
+ "@types/node": "^22.0.0",
63
+ "cesium": "1.136.0",
64
+ "jsdom": "^26.0.0",
65
+ "tsup": "^8.5.0",
66
+ "typescript": "^5.8.0",
67
+ "vite": "^6.0.0",
68
+ "vitest": "^3.2.0",
69
+ "vue": "^3.5.0"
70
+ },
71
+ "publishConfig": {
72
+ "registry": "https://registry.npmjs.org/",
73
+ "access": "public"
74
+ }
75
+ }