@univerjs/drawing 1.6.0 → 1.6.1
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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
package/lib/cjs/index.js
CHANGED
|
@@ -160,7 +160,7 @@ async function prepareOleSnapshot(snapshot, mode, targetUnitId, io) {
|
|
|
160
160
|
|
|
161
161
|
// package.json
|
|
162
162
|
var name = "@univerjs/drawing";
|
|
163
|
-
var version = "1.6.
|
|
163
|
+
var version = "1.6.1";
|
|
164
164
|
|
|
165
165
|
// src/config/config.ts
|
|
166
166
|
const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
|
package/lib/es/index.js
CHANGED
|
@@ -159,7 +159,7 @@ async function prepareOleSnapshot(snapshot, mode, targetUnitId, io) {
|
|
|
159
159
|
|
|
160
160
|
// package.json
|
|
161
161
|
var name = "@univerjs/drawing";
|
|
162
|
-
var version = "1.6.
|
|
162
|
+
var version = "1.6.1";
|
|
163
163
|
|
|
164
164
|
// src/config/config.ts
|
|
165
165
|
const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
|
package/lib/index.js
CHANGED
|
@@ -159,7 +159,7 @@ async function prepareOleSnapshot(snapshot, mode, targetUnitId, io) {
|
|
|
159
159
|
|
|
160
160
|
// package.json
|
|
161
161
|
var name = "@univerjs/drawing";
|
|
162
|
-
var version = "1.6.
|
|
162
|
+
var version = "1.6.1";
|
|
163
163
|
|
|
164
164
|
// src/config/config.ts
|
|
165
165
|
const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
|
package/lib/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawing={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.defineProperty,i=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},a=(e,t)=>{let n=Object.setPrototypeOf({},null);for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t&1||r(n,Symbol.toStringTag,{value:`Module`}),t&2?n:Object.preventExtensions(n)};let o=5242880;function s(e){o=e}function c(){return o}let l=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],u=(0,t.createIdentifier)(`univer.drawing-manager.service`),d={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(u);return t!=null&&(n.focusDrawing(t),!0)}};
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
function f(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function p(e,...t){if(!f(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function m(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function ee(e,t){p(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function h(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function g(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _(e,t){return e<<32-t|e>>>t}function te(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function v(e){return typeof e==`string`&&(e=te(e)),p(e),e}function ne(e){let t=t=>e().update(v(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var re,y=i((()=>{re=class{}}));function ie(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function ae(e,t,n){return e&t^~e&n}function oe(e,t,n){return e&t^e&n^t&n}var se,b,x,ce=i((()=>{y(),se=class extends re{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=g(this.buffer)}update(e){m(this),e=v(e),p(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=g(e);for(;r<=i-a;a+=r)this.process(t,a)}else n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){m(this),ee(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,h(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;ie(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=g(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},b=/* @__PURE__ */ Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),x=/* @__PURE__ */ Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])})),le,S,C,w,ue,T,de=i((()=>{ce(),y(),le=/* @__PURE__ */ Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),S=/* @__PURE__ */ new Uint32Array(64),C=class extends se{constructor(e=32){super(64,e,8,!1),this.A=b[0]|0,this.B=b[1]|0,this.C=b[2]|0,this.D=b[3]|0,this.E=b[4]|0,this.F=b[5]|0,this.G=b[6]|0,this.H=b[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)S[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=S[e-15],n=S[e-2],r=_(t,7)^_(t,18)^t>>>3,i=_(n,17)^_(n,19)^n>>>10;S[e]=i+S[e-7]+r+S[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=_(o,6)^_(o,11)^_(o,25),u=l+t+ae(o,s,c)+le[e]+S[e]|0,d=(_(n,2)^_(n,13)^_(n,22))+oe(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){h(S)}destroy(){this.set(0,0,0,0,0,0,0,0),h(this.buffer)}},w=class extends C{constructor(){super(28),this.A=x[0]|0,this.B=x[1]|0,this.C=x[2]|0,this.D=x[3]|0,this.E=x[4]|0,this.F=x[5]|0,this.G=x[6]|0,this.H=x[7]|0}},ue=/* @__PURE__ */ ne(()=>new C),T=/* @__PURE__ */ ne(()=>new w)})),fe=/* @__PURE__ */ a({SHA224:()=>O,SHA256:()=>E,sha224:()=>k,sha256:()=>D}),E,D,O,k,pe=i((()=>{de(),E=C,D=ue,O=w,k=T}));let A=`UNIVER_OLE_ATTACHMENT_PLUGIN`;function me(e){switch(e){case`application/vnd.ms-excel`:case`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`:return t.UniverInstanceType.UNIVER_SHEET;case`application/msword`:case`application/vnd.openxmlformats-officedocument.wordprocessingml.document`:return t.UniverInstanceType.UNIVER_DOC;case`application/vnd.ms-powerpoint`:case`application/vnd.openxmlformats-officedocument.presentationml.presentation`:return t.UniverInstanceType.UNIVER_SLIDE;default:return}}function j(e){if(new TextEncoder().encode(e).byteLength>52428800)throw Error(`OLE resource exceeds size limit`);let t=JSON.parse(e);if(!t.files||!t.objects||Array.isArray(t.files)||Array.isArray(t.objects))throw Error(`Invalid OLE resource`);let n=0;for(let[e,i]of Object.entries(t.files)){var r;if(!/^[a-f0-9]{64}$/.test(e)||e!==i.sha256||!Number.isSafeInteger(i.size)||i.size<0||typeof i.name!=`string`||typeof i.mimeType!=`string`)throw Error(`Invalid OLE file record`);if(n+=i.size,n>52428800||i.data!=null&&(typeof i.data!=`string`||i.data.length>Math.ceil(i.size/3)*4))throw Error(`OLE files exceed size limit`);if(i.data==null&&(!((r=i.attachment)!=null&&r.source)||i.attachment.sourceType!==`UUID`))throw Error(`Missing OLE attachment source`)}for(let[e,n]of Object.entries(t.objects)){if(n.id!==e||typeof n.drawingId!=`string`||typeof n.subUnitId!=`string`||n.fileName!=null&&typeof n.fileName!=`string`)throw Error(`Invalid OLE object identity`);for(let e of[n.fileId,n.rawFileId,...Object.values(n.parts)])if(e!=null&&!Object.prototype.hasOwnProperty.call(t.files,e))throw Error(`Missing OLE file record`)}return{files:t.files,objects:t.objects}}async function M(e,t,n){var r;if(n!=null&&n.aborted)throw Error(`OLE request aborted`);let i;if(e.data!=null){let t=atob(e.data);i=Uint8Array.from(t,e=>e.charCodeAt(0))}else if(e.attachment&&t)i=await t.read(e.attachment,n);else throw Error(`OLE attachment reader is unavailable`);if(n!=null&&n.aborted)throw Error(`OLE request aborted`);if(i.byteLength!==e.size||i.byteLength>52428800)throw Error(`OLE attachment size mismatch`);let a=(r=globalThis.crypto)!=null&&r.subtle?new Uint8Array(await globalThis.crypto.subtle.digest(`SHA-256`,i)):(await Promise.resolve().then(()=>(pe(),fe))).sha256(i);if(n!=null&&n.aborted)throw Error(`OLE request aborted`);if(Array.from(a,e=>e.toString(16).padStart(2,`0`)).join(``)!==e.sha256)throw Error(`OLE attachment integrity mismatch`);return i}async function he(e,t,n,r){let i=j(JSON.stringify(e));if(t===`unit`&&(!n||!r))throw Error(`OLE online import requires a target Unit and attachment IO`);for(let e of Object.values(i.files)){let i=await M(e,r);if(t===`unit`){let t=await r.upload(new File([i],e.name,{type:e.mimeType}),n);if(!t.source||t.sourceType!==`UUID`||t.size!==e.size)throw Error(`Invalid persisted OLE attachment response`);e.attachment=t,delete e.data}else{let t=``;for(let e=0;e<i.length;e+=8192)t+=String.fromCharCode(...i.subarray(e,e+8192));e.data=btoa(t),delete e.attachment}}return j(JSON.stringify(i))}async function ge(e,t,n,r){let i=e=>e instanceof Uint8Array?Uint8Array.from(e):Array.isArray(e)?e.map(i):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,i(t)])):e,a=i(e),o=a.snapshot??a,s=o.workbook??o.doc??o.slide??o,c=s,l=!1;if(o.slide&&s.originalMeta!=null){let e=typeof s.originalMeta==`string`?Uint8Array.from(atob(s.originalMeta),e=>e.charCodeAt(0)):s.originalMeta;c=JSON.parse(new TextDecoder().decode(e)),l=!0}for(let e of c.resources??[])if(e.name===`UNIVER_OLE_ATTACHMENT_PLUGIN`){let i=typeof e.data==`string`?e.data:new TextDecoder().decode(e.data),a=JSON.stringify(await he(j(i),t,n,r));e.data=typeof e.data==`string`?a:new TextEncoder().encode(a)}if(l){let e=new TextEncoder().encode(JSON.stringify(c)),t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));s.originalMeta=typeof s.originalMeta==`string`?btoa(t):e}return a}var _e=`@univerjs/drawing`,ve=`1.6.0`;let N={};function P(e){"@babel/helpers - typeof";return P=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},P(e)}function ye(e,t){if(P(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(P(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function be(e){var t=ye(e,`string`);return P(t)==`symbol`?t:t+``}function F(e,t,n){return(t=be(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function I(e){return Array.isArray(e)&&e.length>0}function L(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,n)=>L(e,t[n]));if(!R(e)||!R(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>Object.prototype.hasOwnProperty.call(t,n)&&L(e[n],t[n]))}function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function z(e){return Object.getOwnPropertyNames(e).every(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function xe(e,n){return t.JSON1.type.writeCursor().writeAtPath(e,`r`,n).get()}function B(e){if(e===void 0)return;if(e===null||typeof e==`boolean`||typeof e==`number`||typeof e==`string`)return e;if(Array.isArray(e))return e.map(e=>B(e)??null);if(!R(e))return;let t={};return Object.entries(e).forEach(([e,n])=>{let r=B(n);r!==void 0&&(t[e]=r)}),t}function V(e,n,r,i,a){let o=B(i),s=B(r),c=a&&o!==void 0;if(c&&L(o,s))return;if(c&&R(i)&&R(r)&&z(i)&&z(r)){for(let t of/* @__PURE__ */ new Set([...Object.keys(i),...Object.keys(r)]))V(e,[...n,t],r[t],i[t],Object.prototype.hasOwnProperty.call(i,t)&&i[t]!==void 0);return}let l=c?s===void 0?xe(n,o):t.JSON1.replaceOp(n,o,s):s===void 0?null:t.JSON1.insertOp(n,s);l&&I(l)&&e.push(l)}function H(...e){for(let t of e)if(t===`__proto__`||t===`constructor`||t===`prototype`)throw Error(`Invalid drawing key`)}function U(e,t){return e!=null&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function W(e){for(let t of Object.keys(e)){H(t);let n=e[t];n!=null&&n.data&&Object.keys(n.data).forEach(e=>H(e)),n!=null&&n.order&&n.order.forEach(e=>H(e))}}var G=class extends t.Disposable{constructor(...e){super(...e),F(this,`drawingManagerData`,{}),F(this,`_oldDrawingManagerData`,{}),F(this,`_focusDrawings`,[]),F(this,`_remove$`,new n.Subject),F(this,`remove$`,this._remove$.asObservable()),F(this,`_add$`,new n.Subject),F(this,`add$`,this._add$.asObservable()),F(this,`_update$`,new n.Subject),F(this,`update$`,this._update$.asObservable()),F(this,`_order$`,new n.Subject),F(this,`order$`,this._order$.asObservable()),F(this,`_group$`,new n.Subject),F(this,`group$`,this._group$.asObservable()),F(this,`_ungroup$`,new n.Subject),F(this,`ungroup$`,this._ungroup$.asObservable()),F(this,`_refreshTransform$`,new n.Subject),F(this,`refreshTransform$`,this._refreshTransform$.asObservable()),F(this,`_visible$`,new n.Subject),F(this,`visible$`,this._visible$.asObservable()),F(this,`_focus$`,new n.Subject),F(this,`focus$`,this._focus$.asObservable()),F(this,`_featurePluginUpdate$`,new n.Subject),F(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),F(this,`_featurePluginAdd$`,new n.Subject),F(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),F(this,`_featurePluginRemove$`,new n.Subject),F(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),F(this,`_featurePluginOrderUpdate$`,new n.Subject),F(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),F(this,`_featurePluginGroupUpdate$`,new n.Subject),F(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),F(this,`_featurePluginUngroupUpdate$`,new n.Subject),F(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),F(this,`_visible`,!0),F(this,`_editable`,!0)}dispose(){super.dispose(),this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e,t=!0){e.forEach(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,Object.prototype.hasOwnProperty.call(e,`sheetTransform`)&&(e.sheetTransform===void 0?delete t.sheetTransform:t.sheetTransform=e.sheetTransform),Object.prototype.hasOwnProperty.call(e,`axisAlignSheetTransform`)&&(t.axisAlignSheetTransform=e.axisAlignSheetTransform),Object.prototype.hasOwnProperty.call(e,`transforms`)&&(t.transforms=e.transforms),Object.prototype.hasOwnProperty.call(e,`isMultiTransform`)&&(t.isMultiTransform=e.isMultiTransform),`behindText`in e&&(t.behindText=e.behindText),`hidden`in e&&(t.hidden=e.hidden))}),t&&this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return U(this.drawingManagerData,e)||{}}removeDrawingDataForUnit(e){let t=U(this.drawingManagerData,e);if(t==null)return;delete this.drawingManagerData[e];let n=[];Object.keys(t).forEach(r=>{let i=t[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(t=>{n.push({unitId:e,subUnitId:r,drawingId:t})})}),n.length>0&&this.removeNotification(n)}registerDrawingData(e,t){H(e),W(t),this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=U(this.drawingManagerData,e);n!=null&&(Object.keys(n).forEach(r=>{this._establishDrawingMap(e,r);let i=n[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(n=>{let a=i.data[n];a.unitId=e,a.subUnitId=r,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,n){H(e,t),Object.keys(n).forEach(e=>H(e)),this._establishDrawingMap(e,t);let r=this.drawingManagerData[e],i=r[t];this._oldDrawingManagerData={...this.drawingManagerData,[e]:{...r,[t]:{...i}}},this.drawingManagerData[e][t].data=n}getBatchAddOp(e){let n=[],r=[],i=[];e.forEach(e=>{let{op:t,invertOp:a}=this._addByParam(e);n.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),r.push(t),i.push(a)});let a=r.reduce(t.JSON1.type.compose,null),o=i.reduce(t.JSON1.type.compose,null),{unitId:s,subUnitId:c}=e[0];return{undo:o,redo:a,unitId:s,subUnitId:c,objects:n}}getBatchRemoveOpInOder(e){if(e.length===0)return{undo:null,redo:null,unitId:``,subUnitId:``,objects:[]};let t=this.getDrawingOrder(e[0].unitId,e[0].subUnitId),n=/* @__PURE__ */ new Map;return t.forEach((e,t)=>{n.set(e,t)}),e.sort((e,t)=>(n.get(e.drawingId)??-1/0)-(n.get(t.drawingId)??-1/0)),this.getBatchRemoveOp(e)}_getExpandedBatchRemoveParams(e){let n=/* @__PURE__ */ new Set,r=[],i=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))},a=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push(e))};return e.forEach(e=>{let n=this.getDrawingByParam(e);if((n==null?void 0:n.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP){let t=this.getDrawingsByGroupNested(e);if(t){let{flatChildren:e,groups:n}=t;[...e??[],...n].forEach(e=>{i(e)})}else i(n)}else n?i(n):a(e)}),r}getBatchRemoveOp(e){let n=this._getExpandedBatchRemoveParams(e),{unitId:r,subUnitId:i}=n[0]??e[0]??{unitId:``,subUnitId:``};if(n.length===0)return{undo:null,redo:null,unitId:r,subUnitId:i,objects:[]};let a=this._getDrawingOrder(r,i),o=/* @__PURE__ */ new Map;a.forEach((e,t)=>o.set(e,t)),n.sort((e,t)=>(o.get(e.drawingId)??-1/0)-(o.get(t.drawingId)??-1/0));let s=[],c=[];n.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);s.unshift(t),c.push(n)});let l=s.reduce(t.JSON1.type.compose,null);return{undo:c.reduce(t.JSON1.type.compose,null),redo:l,unitId:r,subUnitId:i,objects:n}}getBatchUpdateOp(e){let n=[],r=[],i=[];if(e.forEach(e=>{let{op:t,invertOp:a}=this._updateByParam(e);I(t)&&(n.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),r.push(t),i.push(a))}),r.length===0){let{unitId:t,subUnitId:r}=e[0];return{undo:null,redo:null,unitId:t,subUnitId:r,objects:n}}let a=r.reduce(t.JSON1.type.compose,null),o=i.reduce(t.JSON1.type.compose,null),{unitId:s,subUnitId:c}=e[0];return{undo:o,redo:a,unitId:s,subUnitId:c,objects:n}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){let n=[],{unitId:r,subUnitId:i}=e[0].parent;e.forEach(e=>{n.push(this._getGroupDrawingOp(e))});let a=n.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(a,this.drawingManagerData),redo:a,unitId:r,subUnitId:i,objects:e}}getUngroupDrawingOp(e){let n=[],{unitId:r,subUnitId:i}=e[0].parent;e.forEach(e=>{n.push(this._getUngroupDrawingOp(e))});let a=n.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(a,this.drawingManagerData),redo:a,unitId:r,subUnitId:i,objects:e}}getDrawingsByGroup(e){let{unitId:t,subUnitId:n,drawingId:r}=e;if(this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})==null)return[];let i=this._getDrawingData(t,n),a=[];return Object.keys(i).forEach(e=>{let t=i[e];t.groupId===r&&a.push(t)}),a}getDrawingsByGroupNested(e){let{unitId:n,subUnitId:r}=e,i=this.getDrawingByParam(e);if(!i)return null;let a=this._getDrawingData(n,r),o=/* @__PURE__ */ new Map;Object.values(a).forEach(e=>{e.groupId!=null&&(o.has(e.groupId)||o.set(e.groupId,[]),o.get(e.groupId).push(e.drawingId))});let s=[],c=[],l={},u=e=>{let{drawingId:n}=e,r=o.get(n)??[];l[n]={drawingId:n,children:r},r.forEach(e=>{let n=a[e];n&&(n.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?(u(n),c.push(n)):s.push(n))})};return u(i),c.push(i),{nestedIdRecord:l,flatChildren:s,groups:c}}_getGroupDrawingOp(e){let{parent:n,children:r}=e,{unitId:i,subUnitId:a,drawingId:o}=n,s=[];s.push(t.JSON1.insertOp([i,a,`data`,o],n));let c=-1/0;return r.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:r});c=Math.max(c,i),s.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),c===-1/0&&(c=this._getDrawingOrder(i,a).length),s.push(t.JSON1.insertOp([i,a,`order`,c],o)),s.reduce(t.JSON1.type.compose,null)}_getUngroupDrawingOp(e){let{parent:n,children:r}=e,{unitId:i,subUnitId:a,drawingId:o}=n,s=[];return r.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e;s.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),s.push(t.JSON1.removeOp([i,a,`data`,o],!0)),s.push(t.JSON1.removeOp([i,a,`order`,this._getDrawingOrder(i,a).indexOf(o)],!0)),s.reduce(t.JSON1.type.compose,null)}applyJson1(e,n,r){H(e,n),t.JSON1.type.checkValidOp(r);let i=U(this.drawingManagerData,e),a={...this.drawingManagerData,[e]:{...i,[n]:U(i,n)??{data:{},order:[]}}},o=t.JSON1.type.apply(a,r);for(let e of Object.keys(o))H(e),W(o[e]);this._oldDrawingManagerData=this.drawingManagerData,this.drawingManagerData=o}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){let[t,n,r]=e.split(`#-#`);return this._getCurrentBySearch({unitId:t,subUnitId:n,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}let t=[];e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&t.push(o)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){let e=[];return this._focusDrawings.forEach(t=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=t,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&e.push(o)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,n){H(e,t),n.forEach(e=>H(e)),this._establishDrawingMap(e,t),this.drawingManagerData[e][t].order=n}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=[],o=this.getDrawingOrder(n,r),s=[...i];i.forEach(e=>{let i=this._hasDrawingOrder({unitId:n,subUnitId:r,drawingId:e});if(i===-1||i===o.length-1)return;let c=t.JSON1.moveOp([n,r,`order`,i],[n,r,`order`,i+1]);a.push(c),s.includes(o[i+1])||s.push(o[i+1])});let c=a.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:n,subUnitId:r,objects:{...e,drawingIds:s}}}getBackwardDrawingOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=[],o=this.getDrawingOrder(n,r),s=[...i];i.forEach(e=>{let i=this._hasDrawingOrder({unitId:n,subUnitId:r,drawingId:e});if(i===-1||i===0)return;let c=t.JSON1.moveOp([n,r,`order`,i],[n,r,`order`,i-1]);a.push(c),s.includes(o[i-1])||s.push(o[i-1])});let c=a.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:n,subUnitId:r,objects:{...e,drawingIds:s}}}getFrontDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getOrderFromSearchParams(n,r,i),o=[...i],s=this.getDrawingOrder(n,r),c=[];a.forEach(e=>{let{drawingId:i}=e,a=this._getDrawingCount(n,r)-1,l=t.JSON1.moveOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],[n,r,`order`,a]);c.push(l),o.includes(s[a])||o.push(s[a])});let l=c.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(l,this.drawingManagerData),redo:l,unitId:n,subUnitId:r,objects:{...e,drawingIds:o}}}getBackDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getOrderFromSearchParams(n,r,i,!0),o=[...i],s=this.getDrawingOrder(n,r),c=[];a.forEach(e=>{let{drawingId:i}=e,a=t.JSON1.moveOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],[n,r,`order`,0]);c.push(a),o.includes(s[0])||o.push(s[0])});let l=c.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(l,this.drawingManagerData),redo:l,unitId:n,subUnitId:r,objects:{...e,drawingIds:o}}}getDrawingOrderOp(e,n){let{unitId:r,subUnitId:i,drawingIds:a}=e;if(a.length!==1)return null;let o=this.getDrawingOrder(r,i),s=a[0],c=o.indexOf(s),l=(0,t.normalizeDrawingOrderIndex)(n,o.length);if(c<0||c===l)return null;let u=t.JSON1.moveOp([r,i,`order`,c],[r,i,`order`,l]),d=t.JSON1.type.invertWithDoc(u,this.drawingManagerData),f=o.slice(Math.min(c,l),Math.max(c,l)+1);return{undo:d,redo:u,unitId:r,subUnitId:i,objects:{...e,drawingIds:f}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,n,r,i=!1){return r.map(t=>({drawingId:t,zIndex:this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:t})})).sort(i===!1?t.sortRules:t.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;let{unitId:t,subUnitId:n,drawingId:r}=e;return this._establishDrawingMap(t,n),this._getDrawingOrder(t,n).indexOf(r)}_getCurrentBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return U((t=U(U(this.drawingManagerData,n),r))==null?void 0:t.data,i)}_getOldBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return U((t=U(U(this._oldDrawingManagerData,n),r))==null?void 0:t.data,i)}_establishDrawingMap(e,t,n){return H(e,t),n!=null&&H(n),U(this.drawingManagerData,e)||(this.drawingManagerData[e]={}),U(this.drawingManagerData[e],t)||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:U(this.drawingManagerData[e][t].data,n)}_addByParam(e){let{unitId:n,subUnitId:r,drawingId:i}=e;this._establishDrawingMap(n,r,i);let a=[t.JSON1.insertOp([n,r,`data`,i],e),t.JSON1.insertOp([n,r,`order`,this._getDrawingOrder(n,r).length],i)].reduce(t.JSON1.type.compose,null);return{op:a,invertOp:t.JSON1.type.invertWithDoc(a,this.drawingManagerData)}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};let{unitId:n,subUnitId:r,drawingId:i}=e;if(this._establishDrawingMap(n,r,i)==null)return{op:[],invertOp:[]};let a=[t.JSON1.removeOp([n,r,`data`,i],!0),t.JSON1.removeOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],!0)].reduce(t.JSON1.type.compose,null);return{op:a,invertOp:t.JSON1.type.invertWithDoc(a,this.drawingManagerData)}}_updateByParam(e){let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._establishDrawingMap(n,r,i);if(a==null)return{op:[],invertOp:[]};let o=this._getUpdateParamCompareOp(e,a);if(o.length===0)return{op:[],invertOp:[]};let s=o.reduce(t.JSON1.type.compose,null);return{op:s,invertOp:t.JSON1.type.invert(s)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=Object.prototype.hasOwnProperty.call(t,o),l=t[o];V(a,[n,r,`data`,i,o],s,l,c)}),a}_getDrawingData(e,t){var n;return((n=U(U(this.drawingManagerData,e),t))==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=U(U(this.drawingManagerData,e),t))==null?void 0:n.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}},K=class extends G{constructor(...e){super(...e),F(this,`_commandChecks`,[])}registerCommandCheck(e){return this._commandChecks.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._commandChecks,e)))}canExecuteCommand(e){return this._commandChecks.every(t=>t(e))}},q=class{constructor(){F(this,`_waitCount`,0),F(this,`_change$`,new n.Subject),F(this,`change$`,this._change$),F(this,`_imageSourceCache`,/* @__PURE__ */ new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){let r=this._imageSourceCache.get(e);if(r!=null)return r;if(n===t.ImageSourceType.BASE64){let t=new Image;return t.onload=()=>this._change$.next(this._waitCount),t.onerror=()=>this._change$.next(this._waitCount),t.src=e,this._imageSourceCache.set(e,t),t}}addImageSourceCache(e,n,r){n!==t.ImageSourceType.BASE64&&r!=null&&this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,r)=>{if(!l.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>c()){r(Error(t.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}let i=new FileReader;i.readAsDataURL(e),i.onload=e=>{var i;let a=(i=e.target)==null?void 0:i.result;a==null?(r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting()):(n({imageId:(0,t.generateRandomId)(6),imageSourceType:t.ImageSourceType.BASE64,source:a,base64Cache:a,status:t.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting())}})}_decreaseWaiting(){--this._waitCount,this._change$.next(this._waitCount)}};function J(e,t){return function(n,r){t(n,r,e)}}function Y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let X=class extends t.Disposable{constructor(e){super(),F(this,`_resources`,/* @__PURE__ */ new Map),this.disposeWithMe(e.registerPluginResource({pluginName:A,businesses:[t.UniverInstanceType.UNIVER_SHEET,t.UniverInstanceType.UNIVER_DOC,t.UniverInstanceType.UNIVER_SLIDE],onLoad:(e,t)=>this._resources.set(e,t),onUnLoad:e=>this._resources.delete(e),toJson:e=>JSON.stringify(this._resources.get(e)??{files:{},objects:{}}),parseJson:j}))}getResource(e){return this._resources.get(e)}dispose(){this._resources.clear(),super.dispose()}};X=Y([J(0,t.IResourceManagerService)],X);var Se=class extends t.Disposable{constructor(...e){super(...e),F(this,`_urlImageDownloader`,null)}registerURLImageDownloader(e){return this._urlImageDownloader=e,(0,t.toDisposable)(()=>{this._urlImageDownloader=null})}async getImage(e){if(this._urlImageDownloader)try{return await this._urlImageDownloader(e)}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default behavior:`,t)}return e}async downloadImage(e){if(this._urlImageDownloader)try{let t=await this._urlImageDownloader(e);return await(await fetch(t)).blob()}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default fetch:`,t)}return await(await fetch(e)).blob()}};let Z=class extends t.Plugin{constructor(e=N,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},N,this._config);this._configService.setConfig(`drawing.config`,a),a.allowImageSize!==void 0&&s(a.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies(),this._injector.get(X)}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:q}],[t.IURLImageService,{useClass:Se}],[u,{useClass:K}],[X]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[d].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};F(Z,`pluginName`,`UNIVER_DRAWING_PLUGIN`),F(Z,`packageName`,_e),F(Z,`version`,ve),Z=Y([J(1,(0,t.Inject)(t.Injector)),J(2,t.IConfigService),J(3,t.ICommandService)],Z);let Q=`univer.drawing.copy-plan`;function Ce(e){return JSON.parse(JSON.stringify(e))}function we(e,t,n){let r=Ce(e),i=t.get(e.drawingId);if(i==null)return r;if(r.unitId=n.unitId,r.subUnitId=n.targetSubUnitId,r.drawingId=i,r.groupId){let e=t.get(r.groupId);e?r.groupId=e:delete r.groupId}return r}function $(e,n){let{generateId:r=()=>(0,t.generateRandomId)(10)}=n,i=/* @__PURE__ */ new Map;return e.forEach(e=>{i.has(e.drawingId)||i.set(e.drawingId,r())}),{idMap:i,drawings:e.map(e=>we(e,i,n))}}function Te(e,n,r){if(e==null)return $(n,r);let i=e.get(Q);if(i){let{generateId:e=()=>(0,t.generateRandomId)(10)}=r;if(!n.some(e=>!i.idMap.has(e.drawingId)))return i;n.forEach(t=>{i.idMap.has(t.drawingId)||i.idMap.set(t.drawingId,e())});let a=new Set(n.map(e=>e.drawingId)),o=new Map(Array.from(i.idMap.entries()).map(([e,t])=>[t,e])),s=i.drawings.filter(e=>{let t=o.get(e.drawingId);return t==null||!a.has(t)});return i.drawings=[...n.map(e=>we(e,i.idMap,r)),...s],i}let a=$(n,r);return e.set(Q,a),a}let Ee=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_CHART,t.DrawingTypeEnum.DRAWING_SLICER,t.DrawingTypeEnum.DRAWING_TIMELINE,t.DrawingTypeEnum.DRAWING_GROUP];function De(e){return Ee.includes(e)}function Oe({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let ke=async e=>new Promise((t,n)=>{let r=new Image;r.src=e,r.onload=()=>{t({width:r.width,height:r.height,image:r})},r.onerror=e=>{n(e)}});function Ae(e){return e===void 0||!Number.isFinite(e)?1:Math.min(Math.max(e,0),1)}function je(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function Me(e,n={},r=/* @__PURE__ */ new Set){var i,a,o;if(e.drawingType===t.DrawingTypeEnum.DRAWING_OLE)return!1;let s=je(e);if(r.has(s))return!0;if(e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP){var c;r.add(s);let t=(c=n.getChildren)==null?void 0:c.call(n,e);if(t!=null){let e=t.every(e=>Me(e,n,r));return r.delete(s),e}r.delete(s)}return!(((i=e.transform)==null?void 0:i.rotateEnabled)===!1||((a=n.getRenderObject)==null||(a=a.call(n,e))==null||(a=a.transformerConfig)==null?void 0:a.rotateEnabled)===!1||(o=n.isKnownNonRotatableType)!=null&&o.call(n,e.drawingType))}e.DRAWING_COPY_CONTEXT_KEY=Q,e.DRAWING_GROUPABLE_TYPES=Ee,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=l,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=K,e.IDrawingManagerService=u,e.ImageIoService=q,e.OLE_RESOURCE_NAME=A,Object.defineProperty(e,"OleService",{enumerable:!0,get:function(){return X}}),e.SetDrawingSelectedOperation=d,e.URLImageService=Se,e.UnitDrawingService=G,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return Z}}),e.createDrawingCopyPlan=$,e.getDrawingImageAllowSize=c,e.getDrawingShapeKeyByDrawingSearch=Oe,e.getImageSize=ke,e.getOleOfficeType=me,e.getOrCreateDrawingCopyPlan=Te,e.isGroupableDrawingType=De,e.normalizeImageOpacity=Ae,e.prepareOleSnapshot=ge,e.readOleFile=M,e.resolveDrawingRotateEnabled=Me});
|
|
3
|
+
function f(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function p(e,...t){if(!f(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function m(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function ee(e,t){p(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function h(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function g(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _(e,t){return e<<32-t|e>>>t}function te(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function v(e){return typeof e==`string`&&(e=te(e)),p(e),e}function ne(e){let t=t=>e().update(v(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var re,y=i((()=>{re=class{}}));function ie(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function ae(e,t,n){return e&t^~e&n}function oe(e,t,n){return e&t^e&n^t&n}var se,b,x,ce=i((()=>{y(),se=class extends re{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=g(this.buffer)}update(e){m(this),e=v(e),p(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=g(e);for(;r<=i-a;a+=r)this.process(t,a)}else n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){m(this),ee(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,h(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;ie(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=g(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},b=/* @__PURE__ */ Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),x=/* @__PURE__ */ Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])})),le,S,C,w,ue,T,de=i((()=>{ce(),y(),le=/* @__PURE__ */ Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),S=/* @__PURE__ */ new Uint32Array(64),C=class extends se{constructor(e=32){super(64,e,8,!1),this.A=b[0]|0,this.B=b[1]|0,this.C=b[2]|0,this.D=b[3]|0,this.E=b[4]|0,this.F=b[5]|0,this.G=b[6]|0,this.H=b[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)S[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=S[e-15],n=S[e-2],r=_(t,7)^_(t,18)^t>>>3,i=_(n,17)^_(n,19)^n>>>10;S[e]=i+S[e-7]+r+S[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=_(o,6)^_(o,11)^_(o,25),u=l+t+ae(o,s,c)+le[e]+S[e]|0,d=(_(n,2)^_(n,13)^_(n,22))+oe(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){h(S)}destroy(){this.set(0,0,0,0,0,0,0,0),h(this.buffer)}},w=class extends C{constructor(){super(28),this.A=x[0]|0,this.B=x[1]|0,this.C=x[2]|0,this.D=x[3]|0,this.E=x[4]|0,this.F=x[5]|0,this.G=x[6]|0,this.H=x[7]|0}},ue=/* @__PURE__ */ ne(()=>new C),T=/* @__PURE__ */ ne(()=>new w)})),fe=/* @__PURE__ */ a({SHA224:()=>O,SHA256:()=>E,sha224:()=>k,sha256:()=>D}),E,D,O,k,pe=i((()=>{de(),E=C,D=ue,O=w,k=T}));let A=`UNIVER_OLE_ATTACHMENT_PLUGIN`;function me(e){switch(e){case`application/vnd.ms-excel`:case`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`:return t.UniverInstanceType.UNIVER_SHEET;case`application/msword`:case`application/vnd.openxmlformats-officedocument.wordprocessingml.document`:return t.UniverInstanceType.UNIVER_DOC;case`application/vnd.ms-powerpoint`:case`application/vnd.openxmlformats-officedocument.presentationml.presentation`:return t.UniverInstanceType.UNIVER_SLIDE;default:return}}function j(e){if(new TextEncoder().encode(e).byteLength>52428800)throw Error(`OLE resource exceeds size limit`);let t=JSON.parse(e);if(!t.files||!t.objects||Array.isArray(t.files)||Array.isArray(t.objects))throw Error(`Invalid OLE resource`);let n=0;for(let[e,i]of Object.entries(t.files)){var r;if(!/^[a-f0-9]{64}$/.test(e)||e!==i.sha256||!Number.isSafeInteger(i.size)||i.size<0||typeof i.name!=`string`||typeof i.mimeType!=`string`)throw Error(`Invalid OLE file record`);if(n+=i.size,n>52428800||i.data!=null&&(typeof i.data!=`string`||i.data.length>Math.ceil(i.size/3)*4))throw Error(`OLE files exceed size limit`);if(i.data==null&&(!((r=i.attachment)!=null&&r.source)||i.attachment.sourceType!==`UUID`))throw Error(`Missing OLE attachment source`)}for(let[e,n]of Object.entries(t.objects)){if(n.id!==e||typeof n.drawingId!=`string`||typeof n.subUnitId!=`string`||n.fileName!=null&&typeof n.fileName!=`string`)throw Error(`Invalid OLE object identity`);for(let e of[n.fileId,n.rawFileId,...Object.values(n.parts)])if(e!=null&&!Object.prototype.hasOwnProperty.call(t.files,e))throw Error(`Missing OLE file record`)}return{files:t.files,objects:t.objects}}async function M(e,t,n){var r;if(n!=null&&n.aborted)throw Error(`OLE request aborted`);let i;if(e.data!=null){let t=atob(e.data);i=Uint8Array.from(t,e=>e.charCodeAt(0))}else if(e.attachment&&t)i=await t.read(e.attachment,n);else throw Error(`OLE attachment reader is unavailable`);if(n!=null&&n.aborted)throw Error(`OLE request aborted`);if(i.byteLength!==e.size||i.byteLength>52428800)throw Error(`OLE attachment size mismatch`);let a=(r=globalThis.crypto)!=null&&r.subtle?new Uint8Array(await globalThis.crypto.subtle.digest(`SHA-256`,i)):(await Promise.resolve().then(()=>(pe(),fe))).sha256(i);if(n!=null&&n.aborted)throw Error(`OLE request aborted`);if(Array.from(a,e=>e.toString(16).padStart(2,`0`)).join(``)!==e.sha256)throw Error(`OLE attachment integrity mismatch`);return i}async function he(e,t,n,r){let i=j(JSON.stringify(e));if(t===`unit`&&(!n||!r))throw Error(`OLE online import requires a target Unit and attachment IO`);for(let e of Object.values(i.files)){let i=await M(e,r);if(t===`unit`){let t=await r.upload(new File([i],e.name,{type:e.mimeType}),n);if(!t.source||t.sourceType!==`UUID`||t.size!==e.size)throw Error(`Invalid persisted OLE attachment response`);e.attachment=t,delete e.data}else{let t=``;for(let e=0;e<i.length;e+=8192)t+=String.fromCharCode(...i.subarray(e,e+8192));e.data=btoa(t),delete e.attachment}}return j(JSON.stringify(i))}async function ge(e,t,n,r){let i=e=>e instanceof Uint8Array?Uint8Array.from(e):Array.isArray(e)?e.map(i):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,i(t)])):e,a=i(e),o=a.snapshot??a,s=o.workbook??o.doc??o.slide??o,c=s,l=!1;if(o.slide&&s.originalMeta!=null){let e=typeof s.originalMeta==`string`?Uint8Array.from(atob(s.originalMeta),e=>e.charCodeAt(0)):s.originalMeta;c=JSON.parse(new TextDecoder().decode(e)),l=!0}for(let e of c.resources??[])if(e.name===`UNIVER_OLE_ATTACHMENT_PLUGIN`){let i=typeof e.data==`string`?e.data:new TextDecoder().decode(e.data),a=JSON.stringify(await he(j(i),t,n,r));e.data=typeof e.data==`string`?a:new TextEncoder().encode(a)}if(l){let e=new TextEncoder().encode(JSON.stringify(c)),t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));s.originalMeta=typeof s.originalMeta==`string`?btoa(t):e}return a}var _e=`@univerjs/drawing`,ve=`1.6.1`;let N={};function P(e){"@babel/helpers - typeof";return P=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},P(e)}function ye(e,t){if(P(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(P(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function be(e){var t=ye(e,`string`);return P(t)==`symbol`?t:t+``}function F(e,t,n){return(t=be(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function I(e){return Array.isArray(e)&&e.length>0}function L(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,n)=>L(e,t[n]));if(!R(e)||!R(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>Object.prototype.hasOwnProperty.call(t,n)&&L(e[n],t[n]))}function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function z(e){return Object.getOwnPropertyNames(e).every(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function xe(e,n){return t.JSON1.type.writeCursor().writeAtPath(e,`r`,n).get()}function B(e){if(e===void 0)return;if(e===null||typeof e==`boolean`||typeof e==`number`||typeof e==`string`)return e;if(Array.isArray(e))return e.map(e=>B(e)??null);if(!R(e))return;let t={};return Object.entries(e).forEach(([e,n])=>{let r=B(n);r!==void 0&&(t[e]=r)}),t}function V(e,n,r,i,a){let o=B(i),s=B(r),c=a&&o!==void 0;if(c&&L(o,s))return;if(c&&R(i)&&R(r)&&z(i)&&z(r)){for(let t of/* @__PURE__ */ new Set([...Object.keys(i),...Object.keys(r)]))V(e,[...n,t],r[t],i[t],Object.prototype.hasOwnProperty.call(i,t)&&i[t]!==void 0);return}let l=c?s===void 0?xe(n,o):t.JSON1.replaceOp(n,o,s):s===void 0?null:t.JSON1.insertOp(n,s);l&&I(l)&&e.push(l)}function H(...e){for(let t of e)if(t===`__proto__`||t===`constructor`||t===`prototype`)throw Error(`Invalid drawing key`)}function U(e,t){return e!=null&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function W(e){for(let t of Object.keys(e)){H(t);let n=e[t];n!=null&&n.data&&Object.keys(n.data).forEach(e=>H(e)),n!=null&&n.order&&n.order.forEach(e=>H(e))}}var G=class extends t.Disposable{constructor(...e){super(...e),F(this,`drawingManagerData`,{}),F(this,`_oldDrawingManagerData`,{}),F(this,`_focusDrawings`,[]),F(this,`_remove$`,new n.Subject),F(this,`remove$`,this._remove$.asObservable()),F(this,`_add$`,new n.Subject),F(this,`add$`,this._add$.asObservable()),F(this,`_update$`,new n.Subject),F(this,`update$`,this._update$.asObservable()),F(this,`_order$`,new n.Subject),F(this,`order$`,this._order$.asObservable()),F(this,`_group$`,new n.Subject),F(this,`group$`,this._group$.asObservable()),F(this,`_ungroup$`,new n.Subject),F(this,`ungroup$`,this._ungroup$.asObservable()),F(this,`_refreshTransform$`,new n.Subject),F(this,`refreshTransform$`,this._refreshTransform$.asObservable()),F(this,`_visible$`,new n.Subject),F(this,`visible$`,this._visible$.asObservable()),F(this,`_focus$`,new n.Subject),F(this,`focus$`,this._focus$.asObservable()),F(this,`_featurePluginUpdate$`,new n.Subject),F(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),F(this,`_featurePluginAdd$`,new n.Subject),F(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),F(this,`_featurePluginRemove$`,new n.Subject),F(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),F(this,`_featurePluginOrderUpdate$`,new n.Subject),F(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),F(this,`_featurePluginGroupUpdate$`,new n.Subject),F(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),F(this,`_featurePluginUngroupUpdate$`,new n.Subject),F(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),F(this,`_visible`,!0),F(this,`_editable`,!0)}dispose(){super.dispose(),this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e,t=!0){e.forEach(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,Object.prototype.hasOwnProperty.call(e,`sheetTransform`)&&(e.sheetTransform===void 0?delete t.sheetTransform:t.sheetTransform=e.sheetTransform),Object.prototype.hasOwnProperty.call(e,`axisAlignSheetTransform`)&&(t.axisAlignSheetTransform=e.axisAlignSheetTransform),Object.prototype.hasOwnProperty.call(e,`transforms`)&&(t.transforms=e.transforms),Object.prototype.hasOwnProperty.call(e,`isMultiTransform`)&&(t.isMultiTransform=e.isMultiTransform),`behindText`in e&&(t.behindText=e.behindText),`hidden`in e&&(t.hidden=e.hidden))}),t&&this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return U(this.drawingManagerData,e)||{}}removeDrawingDataForUnit(e){let t=U(this.drawingManagerData,e);if(t==null)return;delete this.drawingManagerData[e];let n=[];Object.keys(t).forEach(r=>{let i=t[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(t=>{n.push({unitId:e,subUnitId:r,drawingId:t})})}),n.length>0&&this.removeNotification(n)}registerDrawingData(e,t){H(e),W(t),this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=U(this.drawingManagerData,e);n!=null&&(Object.keys(n).forEach(r=>{this._establishDrawingMap(e,r);let i=n[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(n=>{let a=i.data[n];a.unitId=e,a.subUnitId=r,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,n){H(e,t),Object.keys(n).forEach(e=>H(e)),this._establishDrawingMap(e,t);let r=this.drawingManagerData[e],i=r[t];this._oldDrawingManagerData={...this.drawingManagerData,[e]:{...r,[t]:{...i}}},this.drawingManagerData[e][t].data=n}getBatchAddOp(e){let n=[],r=[],i=[];e.forEach(e=>{let{op:t,invertOp:a}=this._addByParam(e);n.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),r.push(t),i.push(a)});let a=r.reduce(t.JSON1.type.compose,null),o=i.reduce(t.JSON1.type.compose,null),{unitId:s,subUnitId:c}=e[0];return{undo:o,redo:a,unitId:s,subUnitId:c,objects:n}}getBatchRemoveOpInOder(e){if(e.length===0)return{undo:null,redo:null,unitId:``,subUnitId:``,objects:[]};let t=this.getDrawingOrder(e[0].unitId,e[0].subUnitId),n=/* @__PURE__ */ new Map;return t.forEach((e,t)=>{n.set(e,t)}),e.sort((e,t)=>(n.get(e.drawingId)??-1/0)-(n.get(t.drawingId)??-1/0)),this.getBatchRemoveOp(e)}_getExpandedBatchRemoveParams(e){let n=/* @__PURE__ */ new Set,r=[],i=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))},a=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push(e))};return e.forEach(e=>{let n=this.getDrawingByParam(e);if((n==null?void 0:n.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP){let t=this.getDrawingsByGroupNested(e);if(t){let{flatChildren:e,groups:n}=t;[...e??[],...n].forEach(e=>{i(e)})}else i(n)}else n?i(n):a(e)}),r}getBatchRemoveOp(e){let n=this._getExpandedBatchRemoveParams(e),{unitId:r,subUnitId:i}=n[0]??e[0]??{unitId:``,subUnitId:``};if(n.length===0)return{undo:null,redo:null,unitId:r,subUnitId:i,objects:[]};let a=this._getDrawingOrder(r,i),o=/* @__PURE__ */ new Map;a.forEach((e,t)=>o.set(e,t)),n.sort((e,t)=>(o.get(e.drawingId)??-1/0)-(o.get(t.drawingId)??-1/0));let s=[],c=[];n.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);s.unshift(t),c.push(n)});let l=s.reduce(t.JSON1.type.compose,null);return{undo:c.reduce(t.JSON1.type.compose,null),redo:l,unitId:r,subUnitId:i,objects:n}}getBatchUpdateOp(e){let n=[],r=[],i=[];if(e.forEach(e=>{let{op:t,invertOp:a}=this._updateByParam(e);I(t)&&(n.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),r.push(t),i.push(a))}),r.length===0){let{unitId:t,subUnitId:r}=e[0];return{undo:null,redo:null,unitId:t,subUnitId:r,objects:n}}let a=r.reduce(t.JSON1.type.compose,null),o=i.reduce(t.JSON1.type.compose,null),{unitId:s,subUnitId:c}=e[0];return{undo:o,redo:a,unitId:s,subUnitId:c,objects:n}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){let n=[],{unitId:r,subUnitId:i}=e[0].parent;e.forEach(e=>{n.push(this._getGroupDrawingOp(e))});let a=n.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(a,this.drawingManagerData),redo:a,unitId:r,subUnitId:i,objects:e}}getUngroupDrawingOp(e){let n=[],{unitId:r,subUnitId:i}=e[0].parent;e.forEach(e=>{n.push(this._getUngroupDrawingOp(e))});let a=n.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(a,this.drawingManagerData),redo:a,unitId:r,subUnitId:i,objects:e}}getDrawingsByGroup(e){let{unitId:t,subUnitId:n,drawingId:r}=e;if(this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})==null)return[];let i=this._getDrawingData(t,n),a=[];return Object.keys(i).forEach(e=>{let t=i[e];t.groupId===r&&a.push(t)}),a}getDrawingsByGroupNested(e){let{unitId:n,subUnitId:r}=e,i=this.getDrawingByParam(e);if(!i)return null;let a=this._getDrawingData(n,r),o=/* @__PURE__ */ new Map;Object.values(a).forEach(e=>{e.groupId!=null&&(o.has(e.groupId)||o.set(e.groupId,[]),o.get(e.groupId).push(e.drawingId))});let s=[],c=[],l={},u=e=>{let{drawingId:n}=e,r=o.get(n)??[];l[n]={drawingId:n,children:r},r.forEach(e=>{let n=a[e];n&&(n.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?(u(n),c.push(n)):s.push(n))})};return u(i),c.push(i),{nestedIdRecord:l,flatChildren:s,groups:c}}_getGroupDrawingOp(e){let{parent:n,children:r}=e,{unitId:i,subUnitId:a,drawingId:o}=n,s=[];s.push(t.JSON1.insertOp([i,a,`data`,o],n));let c=-1/0;return r.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:r});c=Math.max(c,i),s.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),c===-1/0&&(c=this._getDrawingOrder(i,a).length),s.push(t.JSON1.insertOp([i,a,`order`,c],o)),s.reduce(t.JSON1.type.compose,null)}_getUngroupDrawingOp(e){let{parent:n,children:r}=e,{unitId:i,subUnitId:a,drawingId:o}=n,s=[];return r.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e;s.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),s.push(t.JSON1.removeOp([i,a,`data`,o],!0)),s.push(t.JSON1.removeOp([i,a,`order`,this._getDrawingOrder(i,a).indexOf(o)],!0)),s.reduce(t.JSON1.type.compose,null)}applyJson1(e,n,r){H(e,n),t.JSON1.type.checkValidOp(r);let i=U(this.drawingManagerData,e),a={...this.drawingManagerData,[e]:{...i,[n]:U(i,n)??{data:{},order:[]}}},o=t.JSON1.type.apply(a,r);for(let e of Object.keys(o))H(e),W(o[e]);this._oldDrawingManagerData=this.drawingManagerData,this.drawingManagerData=o}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){let[t,n,r]=e.split(`#-#`);return this._getCurrentBySearch({unitId:t,subUnitId:n,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}let t=[];e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&t.push(o)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){let e=[];return this._focusDrawings.forEach(t=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=t,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&e.push(o)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,n){H(e,t),n.forEach(e=>H(e)),this._establishDrawingMap(e,t),this.drawingManagerData[e][t].order=n}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=[],o=this.getDrawingOrder(n,r),s=[...i];i.forEach(e=>{let i=this._hasDrawingOrder({unitId:n,subUnitId:r,drawingId:e});if(i===-1||i===o.length-1)return;let c=t.JSON1.moveOp([n,r,`order`,i],[n,r,`order`,i+1]);a.push(c),s.includes(o[i+1])||s.push(o[i+1])});let c=a.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:n,subUnitId:r,objects:{...e,drawingIds:s}}}getBackwardDrawingOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=[],o=this.getDrawingOrder(n,r),s=[...i];i.forEach(e=>{let i=this._hasDrawingOrder({unitId:n,subUnitId:r,drawingId:e});if(i===-1||i===0)return;let c=t.JSON1.moveOp([n,r,`order`,i],[n,r,`order`,i-1]);a.push(c),s.includes(o[i-1])||s.push(o[i-1])});let c=a.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:n,subUnitId:r,objects:{...e,drawingIds:s}}}getFrontDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getOrderFromSearchParams(n,r,i),o=[...i],s=this.getDrawingOrder(n,r),c=[];a.forEach(e=>{let{drawingId:i}=e,a=this._getDrawingCount(n,r)-1,l=t.JSON1.moveOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],[n,r,`order`,a]);c.push(l),o.includes(s[a])||o.push(s[a])});let l=c.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(l,this.drawingManagerData),redo:l,unitId:n,subUnitId:r,objects:{...e,drawingIds:o}}}getBackDrawingsOp(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getOrderFromSearchParams(n,r,i,!0),o=[...i],s=this.getDrawingOrder(n,r),c=[];a.forEach(e=>{let{drawingId:i}=e,a=t.JSON1.moveOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],[n,r,`order`,0]);c.push(a),o.includes(s[0])||o.push(s[0])});let l=c.reduce(t.JSON1.type.compose,null);return{undo:t.JSON1.type.invertWithDoc(l,this.drawingManagerData),redo:l,unitId:n,subUnitId:r,objects:{...e,drawingIds:o}}}getDrawingOrderOp(e,n){let{unitId:r,subUnitId:i,drawingIds:a}=e;if(a.length!==1)return null;let o=this.getDrawingOrder(r,i),s=a[0],c=o.indexOf(s),l=(0,t.normalizeDrawingOrderIndex)(n,o.length);if(c<0||c===l)return null;let u=t.JSON1.moveOp([r,i,`order`,c],[r,i,`order`,l]),d=t.JSON1.type.invertWithDoc(u,this.drawingManagerData),f=o.slice(Math.min(c,l),Math.max(c,l)+1);return{undo:d,redo:u,unitId:r,subUnitId:i,objects:{...e,drawingIds:f}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,n,r,i=!1){return r.map(t=>({drawingId:t,zIndex:this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:t})})).sort(i===!1?t.sortRules:t.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;let{unitId:t,subUnitId:n,drawingId:r}=e;return this._establishDrawingMap(t,n),this._getDrawingOrder(t,n).indexOf(r)}_getCurrentBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return U((t=U(U(this.drawingManagerData,n),r))==null?void 0:t.data,i)}_getOldBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return U((t=U(U(this._oldDrawingManagerData,n),r))==null?void 0:t.data,i)}_establishDrawingMap(e,t,n){return H(e,t),n!=null&&H(n),U(this.drawingManagerData,e)||(this.drawingManagerData[e]={}),U(this.drawingManagerData[e],t)||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:U(this.drawingManagerData[e][t].data,n)}_addByParam(e){let{unitId:n,subUnitId:r,drawingId:i}=e;this._establishDrawingMap(n,r,i);let a=[t.JSON1.insertOp([n,r,`data`,i],e),t.JSON1.insertOp([n,r,`order`,this._getDrawingOrder(n,r).length],i)].reduce(t.JSON1.type.compose,null);return{op:a,invertOp:t.JSON1.type.invertWithDoc(a,this.drawingManagerData)}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};let{unitId:n,subUnitId:r,drawingId:i}=e;if(this._establishDrawingMap(n,r,i)==null)return{op:[],invertOp:[]};let a=[t.JSON1.removeOp([n,r,`data`,i],!0),t.JSON1.removeOp([n,r,`order`,this._getDrawingOrder(n,r).indexOf(i)],!0)].reduce(t.JSON1.type.compose,null);return{op:a,invertOp:t.JSON1.type.invertWithDoc(a,this.drawingManagerData)}}_updateByParam(e){let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._establishDrawingMap(n,r,i);if(a==null)return{op:[],invertOp:[]};let o=this._getUpdateParamCompareOp(e,a);if(o.length===0)return{op:[],invertOp:[]};let s=o.reduce(t.JSON1.type.compose,null);return{op:s,invertOp:t.JSON1.type.invert(s)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=Object.prototype.hasOwnProperty.call(t,o),l=t[o];V(a,[n,r,`data`,i,o],s,l,c)}),a}_getDrawingData(e,t){var n;return((n=U(U(this.drawingManagerData,e),t))==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=U(U(this.drawingManagerData,e),t))==null?void 0:n.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}},K=class extends G{constructor(...e){super(...e),F(this,`_commandChecks`,[])}registerCommandCheck(e){return this._commandChecks.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._commandChecks,e)))}canExecuteCommand(e){return this._commandChecks.every(t=>t(e))}},q=class{constructor(){F(this,`_waitCount`,0),F(this,`_change$`,new n.Subject),F(this,`change$`,this._change$),F(this,`_imageSourceCache`,/* @__PURE__ */ new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){let r=this._imageSourceCache.get(e);if(r!=null)return r;if(n===t.ImageSourceType.BASE64){let t=new Image;return t.onload=()=>this._change$.next(this._waitCount),t.onerror=()=>this._change$.next(this._waitCount),t.src=e,this._imageSourceCache.set(e,t),t}}addImageSourceCache(e,n,r){n!==t.ImageSourceType.BASE64&&r!=null&&this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,r)=>{if(!l.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>c()){r(Error(t.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}let i=new FileReader;i.readAsDataURL(e),i.onload=e=>{var i;let a=(i=e.target)==null?void 0:i.result;a==null?(r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting()):(n({imageId:(0,t.generateRandomId)(6),imageSourceType:t.ImageSourceType.BASE64,source:a,base64Cache:a,status:t.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting())}})}_decreaseWaiting(){--this._waitCount,this._change$.next(this._waitCount)}};function J(e,t){return function(n,r){t(n,r,e)}}function Y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let X=class extends t.Disposable{constructor(e){super(),F(this,`_resources`,/* @__PURE__ */ new Map),this.disposeWithMe(e.registerPluginResource({pluginName:A,businesses:[t.UniverInstanceType.UNIVER_SHEET,t.UniverInstanceType.UNIVER_DOC,t.UniverInstanceType.UNIVER_SLIDE],onLoad:(e,t)=>this._resources.set(e,t),onUnLoad:e=>this._resources.delete(e),toJson:e=>JSON.stringify(this._resources.get(e)??{files:{},objects:{}}),parseJson:j}))}getResource(e){return this._resources.get(e)}dispose(){this._resources.clear(),super.dispose()}};X=Y([J(0,t.IResourceManagerService)],X);var Se=class extends t.Disposable{constructor(...e){super(...e),F(this,`_urlImageDownloader`,null)}registerURLImageDownloader(e){return this._urlImageDownloader=e,(0,t.toDisposable)(()=>{this._urlImageDownloader=null})}async getImage(e){if(this._urlImageDownloader)try{return await this._urlImageDownloader(e)}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default behavior:`,t)}return e}async downloadImage(e){if(this._urlImageDownloader)try{let t=await this._urlImageDownloader(e);return await(await fetch(t)).blob()}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default fetch:`,t)}return await(await fetch(e)).blob()}};let Z=class extends t.Plugin{constructor(e=N,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},N,this._config);this._configService.setConfig(`drawing.config`,a),a.allowImageSize!==void 0&&s(a.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies(),this._injector.get(X)}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:q}],[t.IURLImageService,{useClass:Se}],[u,{useClass:K}],[X]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[d].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};F(Z,`pluginName`,`UNIVER_DRAWING_PLUGIN`),F(Z,`packageName`,_e),F(Z,`version`,ve),Z=Y([J(1,(0,t.Inject)(t.Injector)),J(2,t.IConfigService),J(3,t.ICommandService)],Z);let Q=`univer.drawing.copy-plan`;function Ce(e){return JSON.parse(JSON.stringify(e))}function we(e,t,n){let r=Ce(e),i=t.get(e.drawingId);if(i==null)return r;if(r.unitId=n.unitId,r.subUnitId=n.targetSubUnitId,r.drawingId=i,r.groupId){let e=t.get(r.groupId);e?r.groupId=e:delete r.groupId}return r}function $(e,n){let{generateId:r=()=>(0,t.generateRandomId)(10)}=n,i=/* @__PURE__ */ new Map;return e.forEach(e=>{i.has(e.drawingId)||i.set(e.drawingId,r())}),{idMap:i,drawings:e.map(e=>we(e,i,n))}}function Te(e,n,r){if(e==null)return $(n,r);let i=e.get(Q);if(i){let{generateId:e=()=>(0,t.generateRandomId)(10)}=r;if(!n.some(e=>!i.idMap.has(e.drawingId)))return i;n.forEach(t=>{i.idMap.has(t.drawingId)||i.idMap.set(t.drawingId,e())});let a=new Set(n.map(e=>e.drawingId)),o=new Map(Array.from(i.idMap.entries()).map(([e,t])=>[t,e])),s=i.drawings.filter(e=>{let t=o.get(e.drawingId);return t==null||!a.has(t)});return i.drawings=[...n.map(e=>we(e,i.idMap,r)),...s],i}let a=$(n,r);return e.set(Q,a),a}let Ee=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_CHART,t.DrawingTypeEnum.DRAWING_SLICER,t.DrawingTypeEnum.DRAWING_TIMELINE,t.DrawingTypeEnum.DRAWING_GROUP];function De(e){return Ee.includes(e)}function Oe({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let ke=async e=>new Promise((t,n)=>{let r=new Image;r.src=e,r.onload=()=>{t({width:r.width,height:r.height,image:r})},r.onerror=e=>{n(e)}});function Ae(e){return e===void 0||!Number.isFinite(e)?1:Math.min(Math.max(e,0),1)}function je(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function Me(e,n={},r=/* @__PURE__ */ new Set){var i,a,o;if(e.drawingType===t.DrawingTypeEnum.DRAWING_OLE)return!1;let s=je(e);if(r.has(s))return!0;if(e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP){var c;r.add(s);let t=(c=n.getChildren)==null?void 0:c.call(n,e);if(t!=null){let e=t.every(e=>Me(e,n,r));return r.delete(s),e}r.delete(s)}return!(((i=e.transform)==null?void 0:i.rotateEnabled)===!1||((a=n.getRenderObject)==null||(a=a.call(n,e))==null||(a=a.transformerConfig)==null?void 0:a.rotateEnabled)===!1||(o=n.isKnownNonRotatableType)!=null&&o.call(n,e.drawingType))}e.DRAWING_COPY_CONTEXT_KEY=Q,e.DRAWING_GROUPABLE_TYPES=Ee,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=l,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=K,e.IDrawingManagerService=u,e.ImageIoService=q,e.OLE_RESOURCE_NAME=A,Object.defineProperty(e,"OleService",{enumerable:!0,get:function(){return X}}),e.SetDrawingSelectedOperation=d,e.URLImageService=Se,e.UnitDrawingService=G,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return Z}}),e.createDrawingCopyPlan=$,e.getDrawingImageAllowSize=c,e.getDrawingShapeKeyByDrawingSearch=Oe,e.getImageSize=ke,e.getOleOfficeType=me,e.getOrCreateDrawingCopyPlan=Te,e.isGroupableDrawingType=De,e.normalizeImageOpacity=Ae,e.prepareOleSnapshot=ge,e.readOleFile=M,e.resolveDrawingRotateEnabled=Me});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared drawing models, commands, and services for Univer.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@noble/hashes": "1.8.0",
|
|
56
|
-
"@univerjs/core": "1.6.
|
|
56
|
+
"@univerjs/core": "1.6.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@univerjs-infra/shared": "1.6.
|
|
59
|
+
"@univerjs-infra/shared": "1.6.1",
|
|
60
60
|
"rxjs": "7.8.2",
|
|
61
61
|
"tsrs": "7.1.0-beta.tsrs2",
|
|
62
62
|
"vitest": "^5.1.1"
|