mxcad 1.0.34 → 1.0.35

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/mxcad.d.ts CHANGED
@@ -9,9 +9,24 @@ import { McGePoint3d } from 'mxdraw';
9
9
  export declare function fetchAndInstantiate(url: string, importObject: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
10
10
  export declare function b64Encode(str: string): string;
11
11
  export declare function b64Decode(str: string): string;
12
+ export type FileTypes = {
13
+ description?: string;
14
+ accept: {
15
+ [type: string]: string[];
16
+ };
17
+ }[];
18
+ /** 文件下载保存(另存为只支持 Chrome86 或 Edge 86 以及 Opera 72)兼容 iE10等较低版本的浏览器 */
19
+ export declare function saveAsFileDialog({ blob, filename, types }: {
20
+ blob: Blob;
21
+ filename?: string;
22
+ types?: FileTypes;
23
+ }): Promise<void>;
24
+ export declare function downloadFile(blob: any, filename: string): void;
12
25
  export declare const MxTools: {
13
26
  b64Encode: typeof b64Encode;
14
27
  b64Decode: typeof b64Decode;
28
+ saveAsFileDialog: typeof saveAsFileDialog;
29
+ downloadFile: typeof downloadFile;
15
30
  };
16
31
  /** 绘制文字 */
17
32
  export declare function drawText(): Promise<void>;
@@ -111,18 +126,16 @@ export declare class MdDbDatabase extends MdRxObject {
111
126
  }
112
127
  export declare class McObject {
113
128
  private imp;
114
- static _currentOpenWebFileName: string;
129
+ static currentFileName: string;
115
130
  constructor(imp: any);
116
131
  getImp(): any;
117
132
  getMxCppImp(): any;
118
133
  updateDisplay(modelViewMatrix: number[], projectionMatrix: number[]): void;
119
134
  test(): void;
120
135
  openWebFile(sFileUrl: string): boolean;
121
- getCurrentOpenWebFileUrl(): string;
136
+ getCurrentFileName(): string;
122
137
  saveFileToUrl(sSaveProgramUrl: string): boolean;
123
- /** 文件下载保存(另存为只支持 Chrome86 Edge 86 以及 Opera 72)兼容 iE10等较低版本的浏览器 */
124
- private downloadFile;
125
- saveFile(pszFilePath?: string, call?: (data: any) => void, isDownland?: boolean): boolean;
138
+ saveFile(pszFilePath?: string, call?: (data: any) => void, isDownland?: boolean, isShowSaveFileDialog?: boolean): boolean;
126
139
  GetDatabase(): MdDbDatabase;
127
140
  GetSysVarString(varName: string): string;
128
141
  SetSysVarString(varName: string, val: string): any;
package/dist/mxcad.es.js CHANGED
@@ -9,9 +9,56 @@ function b64Encode(e) {
9
9
  function b64Decode(e) {
10
10
  return decodeURIComponent(escape(atob(e)));
11
11
  }
12
+ async function saveAsFileDialog({
13
+ blob: e,
14
+ filename: t = "",
15
+ types: n = [
16
+ {
17
+ description: "mxweb File",
18
+ accept: {
19
+ "application/octet-stream": [".mxweb"]
20
+ }
21
+ }
22
+ ]
23
+ }) {
24
+ try {
25
+ if (window.showSaveFilePicker)
26
+ if (window.navigator?.userActivation?.isActive)
27
+ try {
28
+ if (!window.showSaveFilePicker)
29
+ return;
30
+ const _ = await (await window.showSaveFilePicker({
31
+ suggestedName: t,
32
+ types: n
33
+ })).createWritable();
34
+ await _.write(e), await _.close();
35
+ return;
36
+ } catch (o) {
37
+ if (o?.name === "AbortError")
38
+ return;
39
+ console.error(o);
40
+ }
41
+ else
42
+ console.warn("\u975E\u7528\u6237\u4EA4\u4E92 \u65E0\u6CD5\u8C03\u7528showSaveFilePicker \u5DF2\u9009\u62E9\u517C\u5BB9\u65B9\u6848");
43
+ if (window.navigator?.msSaveOrOpenBlob) {
44
+ window.navigator.msSaveOrOpenBlob(e, t);
45
+ return;
46
+ }
47
+ const i = document.createElement("a");
48
+ i.href = window.URL.createObjectURL(e), i.download = t, i.style.display = "none", document.body.appendChild(i), i.click(), document.body.removeChild(i), typeof window.URL.revokeObjectURL == "function" ? window.URL.revokeObjectURL(i.href) : typeof window.webkitURL < "u" && typeof window.webkitURL.revokeObjectURL == "function" ? window.webkitURL.revokeObjectURL(i.href) : window.URL.revokeObjectURL(i.href);
49
+ } catch (i) {
50
+ console.error(i.name, i.message);
51
+ }
52
+ }
53
+ function downloadFile(e, t) {
54
+ const n = document.createElement("a");
55
+ n.href = window.URL.createObjectURL(e), n.download = t, n.click();
56
+ }
12
57
  const MxTools = {
13
58
  b64Encode,
14
- b64Decode
59
+ b64Decode,
60
+ saveAsFileDialog,
61
+ downloadFile
15
62
  };
16
63
  async function drawText() {
17
64
  const e = new MrxDbgUiPrPoint();
@@ -337,7 +384,7 @@ class MdDbDatabase extends MdRxObject {
337
384
  }
338
385
  class McObject {
339
386
  imp;
340
- static _currentOpenWebFileName;
387
+ static currentFileName;
341
388
  constructor(t) {
342
389
  this.imp = t;
343
390
  }
@@ -354,63 +401,34 @@ class McObject {
354
401
  this.imp.test();
355
402
  }
356
403
  openWebFile(t) {
357
- return McObject._currentOpenWebFileName = t, this.imp.openWebFile(t);
404
+ return McObject.currentFileName = t, this.imp.openWebFile(t);
358
405
  }
359
- getCurrentOpenWebFileUrl() {
360
- return McObject._currentOpenWebFileName;
406
+ getCurrentFileName() {
407
+ return McObject.currentFileName;
361
408
  }
362
409
  saveFileToUrl(t) {
363
410
  return this.imp.saveFileToUrl(t);
364
411
  }
365
- async downloadFile({
366
- blob: t,
367
- filename: n = "",
368
- types: i = [
369
- {
370
- description: "mxweb File",
371
- accept: {
372
- "application/octet-stream": [".mxweb"]
412
+ saveFile(t, n, i = !0, o = !0) {
413
+ t || (t = this.getCurrentFileName());
414
+ const _ = window;
415
+ return _.mx_saveFile_call = (s) => {
416
+ if (n && n(s), !!s) {
417
+ if (i) {
418
+ let u;
419
+ /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ? u = new Blob([s.buffer], { type: "application/octet-stream" }) : u = new Blob([s.buffer], { type: "application/octet-binary" }), o ? MxTools.saveAsFileDialog({
420
+ blob: u,
421
+ filename: t,
422
+ types: [{
423
+ description: "mxweb File",
424
+ accept: {
425
+ "application/octet-stream": [".mxweb"]
426
+ }
427
+ }]
428
+ }) : MxTools.downloadFile(u, t);
373
429
  }
430
+ _.mx_saveFile_call = null;
374
431
  }
375
- ]
376
- }) {
377
- try {
378
- if (window.showSaveFilePicker)
379
- if (window.navigator?.userActivation?.isActive)
380
- try {
381
- if (!window.showSaveFilePicker)
382
- return;
383
- const s = await (await window.showSaveFilePicker({
384
- suggestedName: n,
385
- types: i
386
- })).createWritable();
387
- await s.write(t), await s.close();
388
- return;
389
- } catch (_) {
390
- if (_?.name === "AbortError")
391
- return;
392
- console.error(_);
393
- }
394
- else
395
- console.warn("\u975E\u7528\u6237\u4EA4\u4E92 \u65E0\u6CD5\u8C03\u7528showSaveFilePicker \u5DF2\u9009\u62E9\u517C\u5BB9\u65B9\u6848");
396
- if (window.navigator?.msSaveOrOpenBlob) {
397
- window.navigator.msSaveOrOpenBlob(t, n);
398
- return;
399
- }
400
- const o = document.createElement("a");
401
- o.href = window.URL.createObjectURL(t), o.download = n, o.style.display = "none", document.body.appendChild(o), o.click(), document.body.removeChild(o), typeof window.URL.revokeObjectURL == "function" ? window.URL.revokeObjectURL(o.href) : typeof window.webkitURL < "u" && typeof window.webkitURL.revokeObjectURL == "function" ? window.webkitURL.revokeObjectURL(o.href) : window.URL.revokeObjectURL(o.href);
402
- } catch (o) {
403
- console.error(o.name, o.message);
404
- }
405
- }
406
- saveFile(t = this.getCurrentOpenWebFileUrl(), n, i = !0) {
407
- const o = window;
408
- return o.mx_saveFile_call = (_) => {
409
- if (n && n(_), i && _) {
410
- let s;
411
- /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ? s = new Blob([_.buffer], { type: "application/octet-stream" }) : s = new Blob([_.buffer], { type: "application/octet-binary" }), this.downloadFile({ blob: s, filename: t });
412
- }
413
- o.mx_saveFile_call = null;
414
432
  }, this.imp.saveFile(t);
415
433
  }
416
434
  GetDatabase() {
@@ -5749,6 +5767,8 @@ const _export = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
5749
5767
  fetchAndInstantiate,
5750
5768
  b64Encode,
5751
5769
  b64Decode,
5770
+ saveAsFileDialog,
5771
+ downloadFile,
5752
5772
  MxTools,
5753
5773
  drawText,
5754
5774
  drawCircle,
@@ -5796,6 +5816,7 @@ export {
5796
5816
  b64Decode,
5797
5817
  b64Encode,
5798
5818
  _export as default,
5819
+ downloadFile,
5799
5820
  drawArc,
5800
5821
  drawCircle,
5801
5822
  drawEllipticalArc,
@@ -5806,5 +5827,6 @@ export {
5806
5827
  drawText,
5807
5828
  fetchAndInstantiate,
5808
5829
  loadMxCADassembly,
5809
- mxErase
5830
+ mxErase,
5831
+ saveAsFileDialog
5810
5832
  };