vis-core 0.23.2 → 0.23.4

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.
@@ -90,7 +90,7 @@ const publicKeyPEM = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRz
90
90
  ).toString(CryptoJS.enc.Utf8), qe = JSON.parse($e), st = Date.now();
91
91
  return !qe.s || qe.s > st ? (this.token = void 0, "") : qe.e && qe.e < st ? (this.token = void 0, "") : (qe.isValid = Qe, qe);
92
92
  }
93
- }, version = "0.23.2";
93
+ }, version = "0.23.4";
94
94
  /**
95
95
  * @license
96
96
  * Copyright 2010-2024 Three.js Authors
@@ -48558,7 +48558,7 @@ class Command {
48558
48558
  return e.type = this.type, e.id = this.id, e.name = this.name, e.updatable = this.updatable, e;
48559
48559
  }
48560
48560
  fromJSON(e) {
48561
- if (this.type = e.type, this.id = e.id, this.name = e.name, this.updatable = e.updatable, !this.editor.jsonVersion && e.objectUuid) {
48561
+ if (this.type = e.type, this.id = e.id, this.name = e.name, this.updatable = e.updatable, !this.editor.config.meta.jsonVersion && e.objectUuid) {
48562
48562
  const s = this.editor.objectByUuid(e.objectUuid);
48563
48563
  s && (e.objectUuid = this.editor.uuidByObject(s));
48564
48564
  const r = this.editor.baseObjectByUuid(e.objectUuid);
@@ -49367,8 +49367,8 @@ class History {
49367
49367
  r("dispose");
49368
49368
  return;
49369
49369
  }
49370
- const Qe = T.shift(), _e = this.editor.scripts.events.beforeExecuteUndo.length ? this.editor.scripts.dispatch("beforeExecuteUndo", Qe) : Qe;
49371
- _e && (yield this.executeUndo(_e)), this.editor.scripts.events.afterExecuteUndo.length && this.editor.scripts.dispatch("afterExecuteUndo", Qe), Xe += 1;
49370
+ const Qe = T.shift(), _e = this.editor.hooks.events.beforeExecuteUndo.length ? this.editor.hooks.dispatch("beforeExecuteUndo", Qe) : Qe;
49371
+ _e && (yield this.executeUndo(_e)), this.editor.hooks.events.afterExecuteUndo.length && this.editor.hooks.dispatch("afterExecuteUndo", Qe), Xe += 1;
49372
49372
  }
49373
49373
  this.editor.emit("progress", {
49374
49374
  type: "还原场景",
@@ -49433,7 +49433,7 @@ class Viewport {
49433
49433
  }
49434
49434
  if (this.vis = this.options.visFactories, this.vis.visName !== e)
49435
49435
  throw new Error(`visName is not match, import {${e}}`);
49436
- const T = this.editor.scripts.events.beforeSetVisOptions.length ? this.editor.scripts.dispatch("beforeSetVisOptions", s) : s;
49436
+ const T = this.editor.hooks.events.beforeSetVisOptions.length ? this.editor.hooks.dispatch("beforeSetVisOptions", s) : s;
49437
49437
  this.vis.setOptions(ai(ai({}, T), this.extendsOptions)), this.delLoadObj && (this.vis.delLoadArr = this.delLoadObj), this.vis.playing = this.editor.playing, this.vis._baseObjectByUuid = this.editor.baseObjectByUuid.bind(this.editor), this.vis.on("loaderProgress", (Ke, Je) => {
49438
49438
  this.editor.emit("progress", {
49439
49439
  type: "下载资源",
@@ -49619,7 +49619,7 @@ const compareVersion = (c, e) => {
49619
49619
  }
49620
49620
  }), compareVersion(c.c.version, "0.21.24") === -1 && c.h.u[0] && c.h.u[0].visType === "map" && (T = (r = c.v) == null ? void 0 : r.eo) != null && T.parentBgCurvatureResolution && (delete c.v.eo.parentBgCurvatureResolution, c.v.eo.parentBgTopSegments = 400), compareVersion(c.c.version, "0.23.1") === -1 && c.h.u[0] && c.h.u[0].visType === "map2" && !c.h.u[0].visOptions.cityOnMap && (c.h.u[0].visOptions.clickHandleDrillDown = !0), c;
49621
49621
  };
49622
- class Scripts {
49622
+ class Hooks {
49623
49623
  constructor(e) {
49624
49624
  H0(this, "editor");
49625
49625
  H0(this, "events", {
@@ -49627,10 +49627,23 @@ class Scripts {
49627
49627
  beforeExecuteUndo: [],
49628
49628
  afterExecuteUndo: [],
49629
49629
  beforeShow: [],
49630
- afterShow: []
49630
+ afterShow: [],
49631
+ beforeFromJSON: [],
49632
+ afterFromJSON: [],
49633
+ errorFromJSON: []
49631
49634
  });
49632
49635
  H0(this, "source", "");
49633
- this.editor = e;
49636
+ this.editor = e, this.addEvents({
49637
+ beforeFromJSON: () => {
49638
+ window.postMessage({ type: "vis-core.fromJSON.start" }), console.time("vis-core:time.fromJSON");
49639
+ },
49640
+ afterFromJSON: () => {
49641
+ window.postMessage({ type: "vis-core.fromJSON.end" }), console.timeEnd("vis-core:time.fromJSON");
49642
+ },
49643
+ errorFromJSON: () => {
49644
+ window.postMessage({ type: "vis-core.fromJSON.error" }), console.timeEnd("vis-core:time.fromJSON");
49645
+ }
49646
+ });
49634
49647
  }
49635
49648
  addEvents(e) {
49636
49649
  for (const s in e) {
@@ -49644,12 +49657,13 @@ class Scripts {
49644
49657
  this.source !== s && (this.source = s, this.editor.emit("scriptsChanged"));
49645
49658
  }
49646
49659
  fromJSON(e) {
49647
- try {
49648
- const s = new Function(`return ${e}()`)();
49649
- this.addEvents(s), this.source = e;
49650
- } catch (s) {
49651
- console.error(s);
49652
- }
49660
+ if (e)
49661
+ try {
49662
+ const s = new Function(`return ${e}()`)();
49663
+ this.addEvents(s), this.source = e;
49664
+ } catch (s) {
49665
+ console.error(s);
49666
+ }
49653
49667
  }
49654
49668
  toJSON() {
49655
49669
  return this.source;
@@ -49667,6 +49681,40 @@ class Scripts {
49667
49681
  return r;
49668
49682
  }
49669
49683
  }
49684
+ class Config {
49685
+ constructor(e) {
49686
+ H0(this, "editor");
49687
+ H0(this, "meta", {
49688
+ name: "",
49689
+ key: "",
49690
+ open: !1,
49691
+ jsonVersion: "0.0.0",
49692
+ sdkVersion: "0.0.0"
49693
+ });
49694
+ this.editor = e;
49695
+ }
49696
+ setConfig(e, s) {
49697
+ this.meta[e] = s, this.editor.emit("configChanged", ai({}, this.meta));
49698
+ }
49699
+ fromJSON(e) {
49700
+ Object.keys(e).forEach((s) => {
49701
+ const r = s === "version" ? "jsonVersion" : s;
49702
+ r in this.meta && this.setConfig(r, e[s]);
49703
+ });
49704
+ }
49705
+ compareVersion() {
49706
+ compareVersion(this.meta.jsonVersion, this.meta.sdkVersion) === 1 && console.warn(
49707
+ "vis-core 版本过低,可能会出现问题",
49708
+ "json:" + this.meta.jsonVersion,
49709
+ "sdk:" + this.meta.sdkVersion
49710
+ );
49711
+ }
49712
+ toJSON() {
49713
+ return {
49714
+ version: this.meta.sdkVersion
49715
+ };
49716
+ }
49717
+ }
49670
49718
  const jsonFetch = (c, e, s = !1) => {
49671
49719
  const r = makePromiseCreator(!0), T = c.endsWith("gzip") || s;
49672
49720
  return window.fetch(c).then((de) => {
@@ -49691,15 +49739,11 @@ class Editor {
49691
49739
  H0(this, "events", new EventEmitter());
49692
49740
  H0(this, "history");
49693
49741
  H0(this, "viewport");
49694
- H0(this, "scripts");
49742
+ H0(this, "hooks");
49743
+ H0(this, "config");
49695
49744
  H0(this, "pencil");
49696
49745
  H0(this, "on", this.events.on.bind(this.events));
49697
49746
  H0(this, "emit", this.events.emit.bind(this.events));
49698
- H0(this, "sdkVersion", version);
49699
- H0(this, "jsonVersion");
49700
- H0(this, "key");
49701
- H0(this, "name");
49702
- H0(this, "open", !1);
49703
49747
  H0(this, "options");
49704
49748
  H0(this, "selectOption", []);
49705
49749
  H0(this, "selectOption2", []);
@@ -49719,7 +49763,7 @@ class Editor {
49719
49763
  processUndosMaxFrameTime: Number.MAX_VALUE
49720
49764
  }, e), this.events.setMaxListeners(9999999), this.viewport = new Viewport(this, {
49721
49765
  visFactories: e.visFactories
49722
- }), this.history = new History(this), this.scripts = new Scripts(this);
49766
+ }), this.history = new History(this), this.hooks = new Hooks(this), this.config = new Config(this), this.config.setConfig("sdkVersion", version);
49723
49767
  }
49724
49768
  getObjectMaterial(e, s) {
49725
49769
  if (!e)
@@ -49814,7 +49858,7 @@ class Editor {
49814
49858
  object: s.camera,
49815
49859
  uuid: "camera"
49816
49860
  }
49817
- ), !this.jsonVersion) {
49861
+ ), !this.config.meta.jsonVersion) {
49818
49862
  const Xe = new window.Map();
49819
49863
  de.forEach((Ke, Je) => {
49820
49864
  Xe.has(Ke.name) ? Ke.fixUuid = Ke.name + "_" + Je : (Ke.fixUuid = Ke.name, Xe.set(Ke.name, !0));
@@ -49844,34 +49888,34 @@ class Editor {
49844
49888
  try {
49845
49889
  s && !n$1(s) ? console.warn(
49846
49890
  "fromJSON 第二个参数已修改,{beforeSetVisOptions:(r)=>r} 替代"
49847
- ) : s && this.scripts.addEvents(s), window.postMessage({ type: "vis-core.fromJSON.start" }), console.time("vis-core:time.fromJSON");
49891
+ ) : s && this.hooks.addEvents(s);
49848
49892
  let Ke;
49849
49893
  if (typeof e == "string") {
49850
- const Je = this.options.assetsPrefix + e, { res: Qe } = yield jsonFetch(Je);
49894
+ const Je = this.options.assetsPrefix + e;
49895
+ console.time("vis-core:time.json-fetch");
49896
+ const { res: Qe, err: _e } = yield jsonFetch(Je);
49897
+ if (console.timeEnd("vis-core:time.json-fetch"), _e)
49898
+ throw new Error("fromJSON error:" + _e);
49851
49899
  Ke = Qe;
49852
49900
  } else
49853
49901
  Ke = e;
49854
- if (Ke = fixJSON(Ke), Ke.at && (accessToken.token = Ke.at), !this.storage) {
49902
+ if (this.hooks.dispatch("beforeFromJSON"), Ke = fixJSON(Ke), Ke.at && (accessToken.token = Ke.at), !this.storage) {
49855
49903
  if (!accessToken.token)
49856
49904
  throw new Error("设置 token 或平台重新下载 JSON 文件");
49857
49905
  const Je = accessToken.getInfo();
49858
49906
  if (!Je || !Je.isValid)
49859
49907
  throw new Error("need accessToken");
49860
49908
  }
49861
- if (compareVersion(Ke.c.version, this.sdkVersion) === 1 && console.warn(
49862
- "vis-core 版本过低,可能会出现问题",
49863
- "json:" + Ke.c.version,
49864
- "sdk:" + this.sdkVersion
49865
- ), this.setConfig(Ke.c), this.history.fromJSON(Ke.h), this.viewport.fromJSON(Ke.v), Ke.s && this.scripts.fromJSON(Ke.s), yield this.history.processUndos(this.options.processUndosMaxFrameTime), (r = Ke.v.bg) != null && r.texture && this.viewport.vis) {
49909
+ if (this.config.fromJSON(Ke.c), this.history.fromJSON(Ke.h), this.viewport.fromJSON(Ke.v), this.hooks.fromJSON(Ke.s), this.config.compareVersion(), yield this.history.processUndos(this.options.processUndosMaxFrameTime), (r = Ke.v.bg) != null && r.texture && this.viewport.vis) {
49866
49910
  const Je = parseTexture(Ke.v.bg.texture);
49867
49911
  Je.colorSpace = SRGBColorSpace, this.viewport.vis.pencil.scene.background = Je;
49868
49912
  }
49869
- return this.scripts.dispatch("beforeShow"), (T = this.viewport.vis) == null || T.show(), this.scripts.dispatch("afterShow"), (de = this.pencil.controls) == null || de.saveState(), this.select(null), console.timeEnd("vis-core:time.fromJSON"), window.postMessage({ type: "vis-core.fromJSON.end" }), (Xe = this.viewport.vis) != null && Xe.workerOnce && this.playing && window.requestIdleCallback(() => {
49913
+ return this.hooks.dispatch("beforeShow"), (T = this.viewport.vis) == null || T.show(), this.hooks.dispatch("afterShow"), (de = this.pencil.controls) == null || de.saveState(), this.select(null), (Xe = this.viewport.vis) != null && Xe.workerOnce && this.playing && window.requestIdleCallback(() => {
49870
49914
  var Je;
49871
49915
  (Je = this.viewport.vis) == null || Je.worker.dispose();
49872
- }), Ke;
49916
+ }), this.hooks.dispatch("afterFromJSON"), Ke;
49873
49917
  } catch (Ke) {
49874
- throw window.postMessage({ type: "vis-core.fromJSON.error" }), new Error("fromJSON error:" + Ke);
49918
+ throw this.hooks.dispatch("errorFromJSON"), new Error("fromJSON error:" + Ke);
49875
49919
  }
49876
49920
  });
49877
49921
  }
@@ -49884,29 +49928,11 @@ class Editor {
49884
49928
  }
49885
49929
  setViewportVis(...e) {
49886
49930
  }
49887
- setConfig(e) {
49888
- const s = {
49889
- name: this.name,
49890
- key: this.key,
49891
- version: this.jsonVersion,
49892
- open: this.open
49893
- };
49894
- e.name && typeof e.name == "string" && (this.name = e.name), e.key !== void 0 && (this.key = e.key), e.version !== void 0 && (this.jsonVersion = e.version), e.open !== void 0 && (this.open = e.open), this.emit(
49895
- "configChanged",
49896
- {
49897
- name: this.name,
49898
- key: this.key,
49899
- version: this.jsonVersion,
49900
- open: this.open
49901
- },
49902
- s
49903
- );
49904
- }
49905
49931
  getDataURL() {
49906
49932
  return this.pencil ? (this.pencil.render(), this.pencil.renderer.domElement.toDataURL()) : "";
49907
49933
  }
49908
49934
  dispose() {
49909
- this.events.removeAllListeners(), this.viewport.dispose(), this.history.clear(), this.scripts.clear(), this._dispose = !0;
49935
+ this.events.removeAllListeners(), this.viewport.dispose(), this.history.clear(), this.hooks.clear(), this._dispose = !0;
49910
49936
  }
49911
49937
  }
49912
49938
  const BLOCKLISTED_GPUS = [
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "0.23.2";
1
+ declare const _default: "0.23.4";
2
2
  export default _default;
@@ -75,7 +75,7 @@ export default class Base extends Event {
75
75
  constructor(options: BaseOptions);
76
76
  setOptions(options: Record<string, any>): void;
77
77
  _baseObjectByUuid: Editor['baseObjectByUuid'];
78
- get fromJSON(): (jsonOrUrl: Record<string, any> | string, scripts?: Record<string, any>) => Promise<Record<string, any>>;
78
+ get fromJSON(): (jsonOrUrl: Record<string, any> | string, hooks?: Record<string, any>) => Promise<Record<string, any>>;
79
79
  get baseObjectByUuid(): {
80
80
  (uuid: `arc${string}`, flag?: boolean): Arc;
81
81
  (uuid: `sprite${string}`, flag?: boolean): import("../all/objects/Sprite").default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vis-core",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
4
4
  "scripts": {
5
5
  "start": "npm run version && PORT=5173 bundler-dev",
6
6
  "build:site": "npm run version && bundler",