@univerjs/drawing 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/lib/cjs/index.js +224 -65
- package/lib/es/index.js +216 -67
- package/lib/index.js +216 -67
- package/lib/types/config/config.d.ts +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/models/ole-model.d.ts +123 -0
- package/lib/types/services/drawing-manager-impl.service.d.ts +6 -3
- package/lib/types/services/drawing-manager.service.d.ts +4 -2
- package/lib/types/services/ole.service.d.ts +24 -0
- package/lib/umd/index.js +3 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
## Package Overview
|
|
10
10
|
|
|
11
|
-
| Package | UMD global | CSS | Locales | Facade entry |
|
|
12
|
-
| --- | --- | :---: | :---: | :---: |
|
|
13
|
-
| `@univerjs/drawing` | `UniverDrawing` | No | No | No |
|
|
11
|
+
| Package | UMD global | CSS | Locales | Facade entry | Worker entry |
|
|
12
|
+
| --- | --- | :---: | :---: | :---: | :---: |
|
|
13
|
+
| `@univerjs/drawing` | `UniverDrawing` | No | No | No | No |
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -20,10 +20,10 @@ pnpm add @univerjs/drawing
|
|
|
20
20
|
npm install @univerjs/drawing
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Keep all `@univerjs/*` packages on the same version.
|
|
24
|
-
|
|
25
23
|
## Usage
|
|
26
24
|
|
|
25
|
+
Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
|
|
26
|
+
|
|
27
27
|
```ts
|
|
28
28
|
import { UniverDrawingPlugin } from '@univerjs/drawing';
|
|
29
29
|
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
let _univerjs_core = require("@univerjs/core");
|
|
3
3
|
let rxjs = require("rxjs");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/basics/config.ts
|
|
6
6
|
/**
|
|
7
7
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
8
8
|
*
|
|
@@ -36,12 +36,10 @@ const DRAWING_IMAGE_ALLOW_IMAGE_LIST = [
|
|
|
36
36
|
"image/bmp"
|
|
37
37
|
];
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
//#region src/services/drawing-manager.service.ts
|
|
39
|
+
// src/services/drawing-manager.service.ts
|
|
41
40
|
const IDrawingManagerService = (0, _univerjs_core.createIdentifier)("univer.drawing-manager.service");
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
//#region src/commands/operations/set-drawing-selected.operation.ts
|
|
42
|
+
// src/commands/operations/set-drawing-selected.operation.ts
|
|
45
43
|
const SetDrawingSelectedOperation = {
|
|
46
44
|
id: "drawing.operation.set-drawing-selected",
|
|
47
45
|
type: _univerjs_core.CommandType.OPERATION,
|
|
@@ -53,19 +51,123 @@ const SetDrawingSelectedOperation = {
|
|
|
53
51
|
}
|
|
54
52
|
};
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
// src/models/ole-model.ts
|
|
55
|
+
const OLE_RESOURCE_NAME = "UNIVER_OLE_ATTACHMENT_PLUGIN";
|
|
56
|
+
const OLE_MAX_RESOURCE_BYTES = 52428800;
|
|
57
|
+
function getOleOfficeType(mimeType) {
|
|
58
|
+
switch (mimeType) {
|
|
59
|
+
case "application/vnd.ms-excel":
|
|
60
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return _univerjs_core.UniverInstanceType.UNIVER_SHEET;
|
|
61
|
+
case "application/msword":
|
|
62
|
+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return _univerjs_core.UniverInstanceType.UNIVER_DOC;
|
|
63
|
+
case "application/vnd.ms-powerpoint":
|
|
64
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.presentation": return _univerjs_core.UniverInstanceType.UNIVER_SLIDE;
|
|
65
|
+
default: return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function parseOleResource(json) {
|
|
69
|
+
if (new TextEncoder().encode(json).byteLength > 52428800) throw new Error("OLE resource exceeds size limit");
|
|
70
|
+
const value = JSON.parse(json);
|
|
71
|
+
if (!value.files || !value.objects || Array.isArray(value.files) || Array.isArray(value.objects)) throw new Error("Invalid OLE resource");
|
|
72
|
+
let total = 0;
|
|
73
|
+
for (const [id, file] of Object.entries(value.files)) {
|
|
74
|
+
var _file$attachment;
|
|
75
|
+
if (!/^[a-f0-9]{64}$/.test(id) || id !== file.sha256 || !Number.isSafeInteger(file.size) || file.size < 0 || typeof file.name !== "string" || typeof file.mimeType !== "string") throw new Error("Invalid OLE file record");
|
|
76
|
+
total += file.size;
|
|
77
|
+
if (total > 52428800 || file.data != null && (typeof file.data !== "string" || file.data.length > Math.ceil(file.size / 3) * 4)) throw new Error("OLE files exceed size limit");
|
|
78
|
+
if (file.data == null && (!((_file$attachment = file.attachment) === null || _file$attachment === void 0 ? void 0 : _file$attachment.source) || file.attachment.sourceType !== "UUID")) throw new Error("Missing OLE attachment source");
|
|
79
|
+
}
|
|
80
|
+
for (const [id, object] of Object.entries(value.objects)) {
|
|
81
|
+
if (object.id !== id || typeof object.drawingId !== "string" || typeof object.subUnitId !== "string" || object.fileName != null && typeof object.fileName !== "string") throw new Error("Invalid OLE object identity");
|
|
82
|
+
for (const fileId of [
|
|
83
|
+
object.fileId,
|
|
84
|
+
object.rawFileId,
|
|
85
|
+
...Object.values(object.parts)
|
|
86
|
+
]) if (fileId != null && !Object.prototype.hasOwnProperty.call(value.files, fileId)) throw new Error("Missing OLE file record");
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
files: value.files,
|
|
90
|
+
objects: value.objects
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function readOleFile(file, io, signal) {
|
|
94
|
+
var _globalThis$crypto;
|
|
95
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
|
|
96
|
+
let bytes;
|
|
97
|
+
if (file.data != null) {
|
|
98
|
+
const binary = atob(file.data);
|
|
99
|
+
bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
100
|
+
} else if (file.attachment && io) bytes = await io.read(file.attachment, signal);
|
|
101
|
+
else throw new Error("OLE attachment reader is unavailable");
|
|
102
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
|
|
103
|
+
if (bytes.byteLength !== file.size || bytes.byteLength > 52428800) throw new Error("OLE attachment size mismatch");
|
|
104
|
+
const hash = ((_globalThis$crypto = globalThis.crypto) === null || _globalThis$crypto === void 0 ? void 0 : _globalThis$crypto.subtle) ? new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes)) : (await import("@noble/hashes/sha256")).sha256(bytes);
|
|
105
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
|
|
106
|
+
if (Array.from(hash, (byte) => byte.toString(16).padStart(2, "0")).join("") !== file.sha256) throw new Error("OLE attachment integrity mismatch");
|
|
107
|
+
return bytes;
|
|
108
|
+
}
|
|
109
|
+
/** Atomic model conversion: failures leave the caller's resource unchanged. */
|
|
110
|
+
async function prepareOleResource(resource, mode, targetUnitId, io) {
|
|
111
|
+
const candidate = parseOleResource(JSON.stringify(resource));
|
|
112
|
+
if (mode === "unit" && (!targetUnitId || !io)) throw new Error("OLE online import requires a target Unit and attachment IO");
|
|
113
|
+
for (const file of Object.values(candidate.files)) {
|
|
114
|
+
const bytes = await readOleFile(file, io);
|
|
115
|
+
if (mode === "unit") {
|
|
116
|
+
const attachment = await io.upload(new File([bytes], file.name, { type: file.mimeType }), targetUnitId);
|
|
117
|
+
if (!attachment.source || attachment.sourceType !== "UUID" || attachment.size !== file.size) throw new Error("Invalid persisted OLE attachment response");
|
|
118
|
+
file.attachment = attachment;
|
|
119
|
+
delete file.data;
|
|
120
|
+
} else {
|
|
121
|
+
let binary = "";
|
|
122
|
+
for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
|
|
123
|
+
file.data = btoa(binary);
|
|
124
|
+
delete file.attachment;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return parseOleResource(JSON.stringify(candidate));
|
|
128
|
+
}
|
|
129
|
+
/** Prepare a UnitData model or a native exchange JSON envelope without changing the caller's model. */
|
|
130
|
+
async function prepareOleSnapshot(snapshot, mode, targetUnitId, io) {
|
|
131
|
+
const clone = (value) => {
|
|
132
|
+
if (value instanceof Uint8Array) return Uint8Array.from(value);
|
|
133
|
+
if (Array.isArray(value)) return value.map(clone);
|
|
134
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clone(item)]));
|
|
135
|
+
return value;
|
|
136
|
+
};
|
|
137
|
+
const candidate = clone(snapshot);
|
|
138
|
+
const envelope = candidate.snapshot ?? candidate;
|
|
139
|
+
const host = envelope.workbook ?? envelope.doc ?? envelope.slide ?? envelope;
|
|
140
|
+
let model = host;
|
|
141
|
+
let encoded = false;
|
|
142
|
+
if (envelope.slide && host.originalMeta != null) {
|
|
143
|
+
const bytes = typeof host.originalMeta === "string" ? Uint8Array.from(atob(host.originalMeta), (character) => character.charCodeAt(0)) : host.originalMeta;
|
|
144
|
+
model = JSON.parse(new TextDecoder().decode(bytes));
|
|
145
|
+
encoded = true;
|
|
146
|
+
}
|
|
147
|
+
for (const entry of model.resources ?? []) if (entry.name === "UNIVER_OLE_ATTACHMENT_PLUGIN") {
|
|
148
|
+
const text = typeof entry.data === "string" ? entry.data : new TextDecoder().decode(entry.data);
|
|
149
|
+
const prepared = JSON.stringify(await prepareOleResource(parseOleResource(text), mode, targetUnitId, io));
|
|
150
|
+
entry.data = typeof entry.data === "string" ? prepared : new TextEncoder().encode(prepared);
|
|
151
|
+
}
|
|
152
|
+
if (encoded) {
|
|
153
|
+
const bytes = new TextEncoder().encode(JSON.stringify(model));
|
|
154
|
+
let binary = "";
|
|
155
|
+
for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
|
|
156
|
+
host.originalMeta = typeof host.originalMeta === "string" ? btoa(binary) : bytes;
|
|
157
|
+
}
|
|
158
|
+
return candidate;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// package.json
|
|
58
162
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.
|
|
163
|
+
var version = "1.5.0";
|
|
60
164
|
|
|
61
|
-
|
|
62
|
-
//#region src/config/config.ts
|
|
165
|
+
// src/config/config.ts
|
|
63
166
|
const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
|
|
64
167
|
const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
|
|
65
168
|
const defaultPluginConfig = {};
|
|
66
169
|
|
|
67
|
-
|
|
68
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
170
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
69
171
|
function _typeof(o) {
|
|
70
172
|
"@babel/helpers - typeof";
|
|
71
173
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -75,28 +177,25 @@ function _typeof(o) {
|
|
|
75
177
|
}, _typeof(o);
|
|
76
178
|
}
|
|
77
179
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
function toPrimitive(t, r) {
|
|
180
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
181
|
+
function toPrimitive(t, e) {
|
|
81
182
|
if ("object" != _typeof(t) || !t) return t;
|
|
82
|
-
var
|
|
83
|
-
if (void 0 !==
|
|
84
|
-
var i =
|
|
183
|
+
var r;
|
|
184
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
185
|
+
var i = r.call(t, e || "default");
|
|
85
186
|
if ("object" != _typeof(i)) return i;
|
|
86
187
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
87
188
|
}
|
|
88
|
-
return ("string" ===
|
|
189
|
+
return ("string" === e ? String : Number)(t);
|
|
89
190
|
}
|
|
90
191
|
|
|
91
|
-
|
|
92
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
192
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
93
193
|
function toPropertyKey(t) {
|
|
94
194
|
var i = toPrimitive(t, "string");
|
|
95
195
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
96
196
|
}
|
|
97
197
|
|
|
98
|
-
|
|
99
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
198
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
100
199
|
function _defineProperty(e, r, t) {
|
|
101
200
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
102
201
|
value: t,
|
|
@@ -106,8 +205,7 @@ function _defineProperty(e, r, t) {
|
|
|
106
205
|
}) : e[r] = t, e;
|
|
107
206
|
}
|
|
108
207
|
|
|
109
|
-
|
|
110
|
-
//#region src/services/drawing-manager-impl.service.ts
|
|
208
|
+
// src/services/drawing-manager-impl.service.ts
|
|
111
209
|
function isNonEmptyOp(op) {
|
|
112
210
|
return Array.isArray(op) && op.length > 0;
|
|
113
211
|
}
|
|
@@ -173,8 +271,9 @@ function validateDrawingData(data) {
|
|
|
173
271
|
/**
|
|
174
272
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
175
273
|
*/
|
|
176
|
-
var UnitDrawingService = class {
|
|
177
|
-
constructor() {
|
|
274
|
+
var UnitDrawingService = class extends _univerjs_core.Disposable {
|
|
275
|
+
constructor(..._args) {
|
|
276
|
+
super(..._args);
|
|
178
277
|
_defineProperty(this, "drawingManagerData", {});
|
|
179
278
|
_defineProperty(this, "_oldDrawingManagerData", {});
|
|
180
279
|
_defineProperty(this, "_focusDrawings", []);
|
|
@@ -212,6 +311,7 @@ var UnitDrawingService = class {
|
|
|
212
311
|
_defineProperty(this, "_editable", true);
|
|
213
312
|
}
|
|
214
313
|
dispose() {
|
|
314
|
+
super.dispose();
|
|
215
315
|
this._remove$.complete();
|
|
216
316
|
this._add$.complete();
|
|
217
317
|
this._update$.complete();
|
|
@@ -1038,10 +1138,21 @@ var UnitDrawingService = class {
|
|
|
1038
1138
|
this._editable = editable;
|
|
1039
1139
|
}
|
|
1040
1140
|
};
|
|
1041
|
-
var DrawingManagerService = class extends UnitDrawingService {
|
|
1141
|
+
var DrawingManagerService = class extends UnitDrawingService {
|
|
1142
|
+
constructor(..._args2) {
|
|
1143
|
+
super(..._args2);
|
|
1144
|
+
_defineProperty(this, "_commandChecks", []);
|
|
1145
|
+
}
|
|
1146
|
+
registerCommandCheck(check) {
|
|
1147
|
+
this._commandChecks.push(check);
|
|
1148
|
+
return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._commandChecks, check)));
|
|
1149
|
+
}
|
|
1150
|
+
canExecuteCommand(command) {
|
|
1151
|
+
return this._commandChecks.every((check) => check(command));
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1042
1154
|
|
|
1043
|
-
|
|
1044
|
-
//#region src/services/image-io-impl.service.ts
|
|
1155
|
+
// src/services/image-io-impl.service.ts
|
|
1045
1156
|
var ImageIoService = class {
|
|
1046
1157
|
constructor() {
|
|
1047
1158
|
_defineProperty(this, "_waitCount", 0);
|
|
@@ -1111,8 +1222,68 @@ var ImageIoService = class {
|
|
|
1111
1222
|
}
|
|
1112
1223
|
};
|
|
1113
1224
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1225
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
1226
|
+
function __decorateParam(paramIndex, decorator) {
|
|
1227
|
+
return function(target, key) {
|
|
1228
|
+
decorator(target, key, paramIndex);
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
1233
|
+
function __decorate(decorators, target, key, desc) {
|
|
1234
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1235
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1236
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1237
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// src/services/ole.service.ts
|
|
1241
|
+
/**
|
|
1242
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1243
|
+
*
|
|
1244
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1245
|
+
* you may not use this file except in compliance with the License.
|
|
1246
|
+
* You may obtain a copy of the License at
|
|
1247
|
+
*
|
|
1248
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1249
|
+
*
|
|
1250
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1251
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1252
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1253
|
+
* See the License for the specific language governing permissions and
|
|
1254
|
+
* limitations under the License.
|
|
1255
|
+
*/
|
|
1256
|
+
let OleService = class OleService extends _univerjs_core.Disposable {
|
|
1257
|
+
constructor(resourceManager) {
|
|
1258
|
+
super();
|
|
1259
|
+
_defineProperty(this, "_resources", /* @__PURE__ */ new Map());
|
|
1260
|
+
this.disposeWithMe(resourceManager.registerPluginResource({
|
|
1261
|
+
pluginName: OLE_RESOURCE_NAME,
|
|
1262
|
+
businesses: [
|
|
1263
|
+
_univerjs_core.UniverInstanceType.UNIVER_SHEET,
|
|
1264
|
+
_univerjs_core.UniverInstanceType.UNIVER_DOC,
|
|
1265
|
+
_univerjs_core.UniverInstanceType.UNIVER_SLIDE
|
|
1266
|
+
],
|
|
1267
|
+
onLoad: (unitId, resource) => this._resources.set(unitId, resource),
|
|
1268
|
+
onUnLoad: (unitId) => this._resources.delete(unitId),
|
|
1269
|
+
toJson: (unitId) => JSON.stringify(this._resources.get(unitId) ?? {
|
|
1270
|
+
files: {},
|
|
1271
|
+
objects: {}
|
|
1272
|
+
}),
|
|
1273
|
+
parseJson: parseOleResource
|
|
1274
|
+
}));
|
|
1275
|
+
}
|
|
1276
|
+
getResource(unitId) {
|
|
1277
|
+
return this._resources.get(unitId);
|
|
1278
|
+
}
|
|
1279
|
+
dispose() {
|
|
1280
|
+
this._resources.clear();
|
|
1281
|
+
super.dispose();
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
OleService = __decorate([__decorateParam(0, _univerjs_core.IResourceManagerService)], OleService);
|
|
1285
|
+
|
|
1286
|
+
// src/services/url-image.service.ts
|
|
1116
1287
|
var URLImageService = class extends _univerjs_core.Disposable {
|
|
1117
1288
|
constructor(..._args) {
|
|
1118
1289
|
super(..._args);
|
|
@@ -1143,25 +1314,7 @@ var URLImageService = class extends _univerjs_core.Disposable {
|
|
|
1143
1314
|
}
|
|
1144
1315
|
};
|
|
1145
1316
|
|
|
1146
|
-
|
|
1147
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
1148
|
-
function __decorateParam(paramIndex, decorator) {
|
|
1149
|
-
return function(target, key) {
|
|
1150
|
-
decorator(target, key, paramIndex);
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
//#endregion
|
|
1155
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
1156
|
-
function __decorate(decorators, target, key, desc) {
|
|
1157
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1158
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1159
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1160
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
//#endregion
|
|
1164
|
-
//#region src/plugin.ts
|
|
1317
|
+
// src/plugin.ts
|
|
1165
1318
|
let UniverDrawingPlugin = class UniverDrawingPlugin extends _univerjs_core.Plugin {
|
|
1166
1319
|
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
1167
1320
|
super();
|
|
@@ -1176,13 +1329,15 @@ let UniverDrawingPlugin = class UniverDrawingPlugin extends _univerjs_core.Plugi
|
|
|
1176
1329
|
onStarting() {
|
|
1177
1330
|
this._initCommands();
|
|
1178
1331
|
this._initDependencies();
|
|
1332
|
+
this._injector.get(OleService);
|
|
1179
1333
|
}
|
|
1180
1334
|
_initDependencies() {
|
|
1181
1335
|
var _this$_config;
|
|
1182
1336
|
(0, _univerjs_core.mergeOverrideWithDependencies)([
|
|
1183
1337
|
[_univerjs_core.IImageIoService, { useClass: ImageIoService }],
|
|
1184
1338
|
[_univerjs_core.IURLImageService, { useClass: URLImageService }],
|
|
1185
|
-
[IDrawingManagerService, { useClass: DrawingManagerService }]
|
|
1339
|
+
[IDrawingManagerService, { useClass: DrawingManagerService }],
|
|
1340
|
+
[OleService]
|
|
1186
1341
|
], (_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.override).forEach((d) => this._injector.add(d));
|
|
1187
1342
|
}
|
|
1188
1343
|
_initCommands() {
|
|
@@ -1198,8 +1353,7 @@ UniverDrawingPlugin = __decorate([
|
|
|
1198
1353
|
__decorateParam(3, _univerjs_core.ICommandService)
|
|
1199
1354
|
], UniverDrawingPlugin);
|
|
1200
1355
|
|
|
1201
|
-
|
|
1202
|
-
//#region src/utils/drawing-copy-plan.ts
|
|
1356
|
+
// src/utils/drawing-copy-plan.ts
|
|
1203
1357
|
/**
|
|
1204
1358
|
* A command-scoped cache key shared by sheet-copy interceptors so every drawing model
|
|
1205
1359
|
* resolves against the same copied drawing IDs.
|
|
@@ -1256,8 +1410,7 @@ function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
|
1256
1410
|
return plan;
|
|
1257
1411
|
}
|
|
1258
1412
|
|
|
1259
|
-
|
|
1260
|
-
//#region src/utils/drawing-group.ts
|
|
1413
|
+
// src/utils/drawing-group.ts
|
|
1261
1414
|
const DRAWING_GROUPABLE_TYPES = [
|
|
1262
1415
|
_univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
1263
1416
|
_univerjs_core.DrawingTypeEnum.DRAWING_SHAPE,
|
|
@@ -1270,14 +1423,12 @@ function isGroupableDrawingType(type) {
|
|
|
1270
1423
|
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1271
1424
|
}
|
|
1272
1425
|
|
|
1273
|
-
|
|
1274
|
-
//#region src/utils/get-image-shape-key.ts
|
|
1426
|
+
// src/utils/get-image-shape-key.ts
|
|
1275
1427
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
|
1276
1428
|
return typeof index === "number" ? `${unitId}#-#${subUnitId}#-#${drawingId}#-#${index}` : `${unitId}#-#${subUnitId}#-#${drawingId}`;
|
|
1277
1429
|
}
|
|
1278
1430
|
|
|
1279
|
-
|
|
1280
|
-
//#region src/utils/get-image-size.ts
|
|
1431
|
+
// src/utils/get-image-size.ts
|
|
1281
1432
|
const getImageSize = async (src) => {
|
|
1282
1433
|
return new Promise((resolve, reject) => {
|
|
1283
1434
|
const image = new Image();
|
|
@@ -1295,8 +1446,7 @@ const getImageSize = async (src) => {
|
|
|
1295
1446
|
});
|
|
1296
1447
|
};
|
|
1297
1448
|
|
|
1298
|
-
|
|
1299
|
-
//#region src/utils/image-opacity.ts
|
|
1449
|
+
// src/utils/image-opacity.ts
|
|
1300
1450
|
/**
|
|
1301
1451
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1302
1452
|
*
|
|
@@ -1317,13 +1467,13 @@ function normalizeImageOpacity(opacity) {
|
|
|
1317
1467
|
return Math.min(Math.max(opacity, 0), 1);
|
|
1318
1468
|
}
|
|
1319
1469
|
|
|
1320
|
-
|
|
1321
|
-
//#region src/utils/rotate-enabled.ts
|
|
1470
|
+
// src/utils/rotate-enabled.ts
|
|
1322
1471
|
function getDrawingKey(drawing) {
|
|
1323
1472
|
return `${drawing.unitId}\u0000${drawing.subUnitId}\u0000${drawing.drawingId}`;
|
|
1324
1473
|
}
|
|
1325
1474
|
function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PURE__ */ new Set()) {
|
|
1326
1475
|
var _drawing$transform, _options$getRenderObj, _options$isKnownNonRo;
|
|
1476
|
+
if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_OLE) return false;
|
|
1327
1477
|
const drawingKey = getDrawingKey(drawing);
|
|
1328
1478
|
if (visiting.has(drawingKey)) return true;
|
|
1329
1479
|
if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP) {
|
|
@@ -1343,7 +1493,6 @@ function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PUR
|
|
|
1343
1493
|
return true;
|
|
1344
1494
|
}
|
|
1345
1495
|
|
|
1346
|
-
//#endregion
|
|
1347
1496
|
exports.DRAWING_COPY_CONTEXT_KEY = DRAWING_COPY_CONTEXT_KEY;
|
|
1348
1497
|
exports.DRAWING_GROUPABLE_TYPES = DRAWING_GROUPABLE_TYPES;
|
|
1349
1498
|
exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST = DRAWING_IMAGE_ALLOW_IMAGE_LIST;
|
|
@@ -1353,6 +1502,13 @@ exports.DRAWING_IMAGE_WIDTH_LIMIT = DRAWING_IMAGE_WIDTH_LIMIT;
|
|
|
1353
1502
|
exports.DrawingManagerService = DrawingManagerService;
|
|
1354
1503
|
exports.IDrawingManagerService = IDrawingManagerService;
|
|
1355
1504
|
exports.ImageIoService = ImageIoService;
|
|
1505
|
+
exports.OLE_RESOURCE_NAME = OLE_RESOURCE_NAME;
|
|
1506
|
+
Object.defineProperty(exports, "OleService", {
|
|
1507
|
+
enumerable: true,
|
|
1508
|
+
get: function () {
|
|
1509
|
+
return OleService;
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1356
1512
|
exports.SetDrawingSelectedOperation = SetDrawingSelectedOperation;
|
|
1357
1513
|
exports.URLImageService = URLImageService;
|
|
1358
1514
|
exports.UnitDrawingService = UnitDrawingService;
|
|
@@ -1366,7 +1522,10 @@ exports.createDrawingCopyPlan = createDrawingCopyPlan;
|
|
|
1366
1522
|
exports.getDrawingImageAllowSize = getDrawingImageAllowSize;
|
|
1367
1523
|
exports.getDrawingShapeKeyByDrawingSearch = getDrawingShapeKeyByDrawingSearch;
|
|
1368
1524
|
exports.getImageSize = getImageSize;
|
|
1525
|
+
exports.getOleOfficeType = getOleOfficeType;
|
|
1369
1526
|
exports.getOrCreateDrawingCopyPlan = getOrCreateDrawingCopyPlan;
|
|
1370
1527
|
exports.isGroupableDrawingType = isGroupableDrawingType;
|
|
1371
1528
|
exports.normalizeImageOpacity = normalizeImageOpacity;
|
|
1529
|
+
exports.prepareOleSnapshot = prepareOleSnapshot;
|
|
1530
|
+
exports.readOleFile = readOleFile;
|
|
1372
1531
|
exports.resolveDrawingRotateEnabled = resolveDrawingRotateEnabled;
|