@metagl/smartearth-base 0.0.0-stage → 0.2.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/CHANGELOG.md +35 -0
- package/README.md +196 -3
- package/dist/chunk-O7CP7PJG.js +1862 -0
- package/dist/errors-CtkYU3iT.d.ts +267 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +1 -0
- package/dist/vite.d.ts +20 -0
- package/dist/vite.js +89 -0
- package/dist/vue.d.ts +32 -0
- package/dist/vue.js +54 -0
- package/package.json +67 -3
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,32 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
import { d as CreateEarthOptions, E as Earth, r as SmartEarthError } from './errors-CtkYU3iT.js';
|
|
4
|
+
import 'cesium';
|
|
5
|
+
import '@metagl/sdk-render';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* <SmartEarthView :options="..." @ready="(earth) => ..." @error="(err) => ..." />
|
|
9
|
+
*
|
|
10
|
+
* 挂载时 createEarth,卸载时 destroy。options 只在挂载时读一次;要换授权或底图请用 :key 重建组件。
|
|
11
|
+
*/
|
|
12
|
+
declare const SmartEarthView: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
13
|
+
options: {
|
|
14
|
+
type: PropType<CreateEarthOptions>;
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
|
|
20
|
+
ready: (earth: Earth) => boolean;
|
|
21
|
+
error: (error: SmartEarthError) => boolean;
|
|
22
|
+
}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
23
|
+
options: {
|
|
24
|
+
type: PropType<CreateEarthOptions>;
|
|
25
|
+
required: true;
|
|
26
|
+
};
|
|
27
|
+
}>> & Readonly<{
|
|
28
|
+
onReady?: ((earth: Earth) => any) | undefined;
|
|
29
|
+
onError?: ((error: SmartEarthError) => any) | undefined;
|
|
30
|
+
}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
31
|
+
|
|
32
|
+
export { SmartEarthView, SmartEarthView as default };
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createEarth, SmartEarthError, describeCause } from './chunk-O7CP7PJG.js';
|
|
2
|
+
import { defineComponent, ref, shallowRef, onMounted, onBeforeUnmount, h } from 'vue';
|
|
3
|
+
|
|
4
|
+
var SmartEarthView = defineComponent({
|
|
5
|
+
name: "SmartEarthView",
|
|
6
|
+
props: {
|
|
7
|
+
options: {
|
|
8
|
+
type: Object,
|
|
9
|
+
required: true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
emits: {
|
|
13
|
+
ready: (earth) => Boolean(earth),
|
|
14
|
+
error: (error) => error instanceof SmartEarthError
|
|
15
|
+
},
|
|
16
|
+
setup(props, { emit, expose }) {
|
|
17
|
+
const container = ref(null);
|
|
18
|
+
const earth = shallowRef(null);
|
|
19
|
+
let unmounted = false;
|
|
20
|
+
onMounted(async () => {
|
|
21
|
+
const element = container.value;
|
|
22
|
+
if (!element) return;
|
|
23
|
+
try {
|
|
24
|
+
const created = await createEarth(element, props.options);
|
|
25
|
+
if (unmounted) {
|
|
26
|
+
created.destroy();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
earth.value = created;
|
|
30
|
+
emit("ready", created);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (unmounted) return;
|
|
33
|
+
emit(
|
|
34
|
+
"error",
|
|
35
|
+
error instanceof SmartEarthError ? error : new SmartEarthError("RENDER_INIT_FAILED", describeCause(error), error)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
onBeforeUnmount(() => {
|
|
40
|
+
unmounted = true;
|
|
41
|
+
earth.value?.destroy();
|
|
42
|
+
earth.value = null;
|
|
43
|
+
});
|
|
44
|
+
expose({ earth });
|
|
45
|
+
return () => h("div", {
|
|
46
|
+
ref: container,
|
|
47
|
+
class: "smartearth-view",
|
|
48
|
+
style: { position: "relative", width: "100%", height: "100%", overflow: "hidden" }
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
var vue_default = SmartEarthView;
|
|
53
|
+
|
|
54
|
+
export { SmartEarthView, vue_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metagl/smartearth-base",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "集群业务地图底层包:基于 @metagl/sdk-render 的三维地球(替代已废弃的 @agent-earth/smart-earth)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.0.0"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./vite": {
|
|
25
|
+
"types": "./dist/vite.d.ts",
|
|
26
|
+
"import": "./dist/vite.js"
|
|
27
|
+
},
|
|
28
|
+
"./vue": {
|
|
29
|
+
"types": "./dist/vue.d.ts",
|
|
30
|
+
"import": "./dist/vue.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@metagl/sdk-render": "^3.0.0 || ^4.0.1",
|
|
36
|
+
"cesium": ">=1.132.0 <1.137.0",
|
|
37
|
+
"vite": ">=5.0.0",
|
|
38
|
+
"vue": "^3.5.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"vite": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"vue": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@metagl/sdk-render": "4.0.2",
|
|
50
|
+
"@types/node": "^22.0.0",
|
|
51
|
+
"cesium": "1.136.0",
|
|
52
|
+
"jsdom": "^26.0.0",
|
|
53
|
+
"tsup": "^8.5.0",
|
|
54
|
+
"typescript": "^5.8.0",
|
|
55
|
+
"vite": "^6.0.0",
|
|
56
|
+
"vitest": "^3.2.0",
|
|
57
|
+
"vue": "^3.5.0"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"registry": "https://registry.npmjs.org/",
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsup",
|
|
65
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"check": "pnpm typecheck && pnpm test && pnpm build",
|
|
68
|
+
"example:dev": "pnpm build && pnpm --filter smartearth-base-example-vue dev"
|
|
69
|
+
}
|
|
6
70
|
}
|