@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/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, JSON1, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
1
+ import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IResourceManagerService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, JSON1, Plugin, UniverInstanceType, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, remove, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
2
2
  import { Subject } from "rxjs";
3
3
 
4
- //#region src/basics/config.ts
4
+ // src/basics/config.ts
5
5
  /**
6
6
  * Copyright 2023-present DreamNum Co., Ltd.
7
7
  *
@@ -35,12 +35,10 @@ const DRAWING_IMAGE_ALLOW_IMAGE_LIST = [
35
35
  "image/bmp"
36
36
  ];
37
37
 
38
- //#endregion
39
- //#region src/services/drawing-manager.service.ts
38
+ // src/services/drawing-manager.service.ts
40
39
  const IDrawingManagerService = createIdentifier("univer.drawing-manager.service");
41
40
 
42
- //#endregion
43
- //#region src/commands/operations/set-drawing-selected.operation.ts
41
+ // src/commands/operations/set-drawing-selected.operation.ts
44
42
  const SetDrawingSelectedOperation = {
45
43
  id: "drawing.operation.set-drawing-selected",
46
44
  type: CommandType.OPERATION,
@@ -52,19 +50,123 @@ const SetDrawingSelectedOperation = {
52
50
  }
53
51
  };
54
52
 
55
- //#endregion
56
- //#region package.json
53
+ // src/models/ole-model.ts
54
+ const OLE_RESOURCE_NAME = "UNIVER_OLE_ATTACHMENT_PLUGIN";
55
+ const OLE_MAX_RESOURCE_BYTES = 52428800;
56
+ function getOleOfficeType(mimeType) {
57
+ switch (mimeType) {
58
+ case "application/vnd.ms-excel":
59
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return UniverInstanceType.UNIVER_SHEET;
60
+ case "application/msword":
61
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return UniverInstanceType.UNIVER_DOC;
62
+ case "application/vnd.ms-powerpoint":
63
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation": return UniverInstanceType.UNIVER_SLIDE;
64
+ default: return;
65
+ }
66
+ }
67
+ function parseOleResource(json) {
68
+ if (new TextEncoder().encode(json).byteLength > 52428800) throw new Error("OLE resource exceeds size limit");
69
+ const value = JSON.parse(json);
70
+ if (!value.files || !value.objects || Array.isArray(value.files) || Array.isArray(value.objects)) throw new Error("Invalid OLE resource");
71
+ let total = 0;
72
+ for (const [id, file] of Object.entries(value.files)) {
73
+ var _file$attachment;
74
+ 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");
75
+ total += file.size;
76
+ 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");
77
+ 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");
78
+ }
79
+ for (const [id, object] of Object.entries(value.objects)) {
80
+ 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");
81
+ for (const fileId of [
82
+ object.fileId,
83
+ object.rawFileId,
84
+ ...Object.values(object.parts)
85
+ ]) if (fileId != null && !Object.prototype.hasOwnProperty.call(value.files, fileId)) throw new Error("Missing OLE file record");
86
+ }
87
+ return {
88
+ files: value.files,
89
+ objects: value.objects
90
+ };
91
+ }
92
+ async function readOleFile(file, io, signal) {
93
+ var _globalThis$crypto;
94
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
95
+ let bytes;
96
+ if (file.data != null) {
97
+ const binary = atob(file.data);
98
+ bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
99
+ } else if (file.attachment && io) bytes = await io.read(file.attachment, signal);
100
+ else throw new Error("OLE attachment reader is unavailable");
101
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
102
+ if (bytes.byteLength !== file.size || bytes.byteLength > 52428800) throw new Error("OLE attachment size mismatch");
103
+ 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);
104
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) throw new Error("OLE request aborted");
105
+ if (Array.from(hash, (byte) => byte.toString(16).padStart(2, "0")).join("") !== file.sha256) throw new Error("OLE attachment integrity mismatch");
106
+ return bytes;
107
+ }
108
+ /** Atomic model conversion: failures leave the caller's resource unchanged. */
109
+ async function prepareOleResource(resource, mode, targetUnitId, io) {
110
+ const candidate = parseOleResource(JSON.stringify(resource));
111
+ if (mode === "unit" && (!targetUnitId || !io)) throw new Error("OLE online import requires a target Unit and attachment IO");
112
+ for (const file of Object.values(candidate.files)) {
113
+ const bytes = await readOleFile(file, io);
114
+ if (mode === "unit") {
115
+ const attachment = await io.upload(new File([bytes], file.name, { type: file.mimeType }), targetUnitId);
116
+ if (!attachment.source || attachment.sourceType !== "UUID" || attachment.size !== file.size) throw new Error("Invalid persisted OLE attachment response");
117
+ file.attachment = attachment;
118
+ delete file.data;
119
+ } else {
120
+ let binary = "";
121
+ for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
122
+ file.data = btoa(binary);
123
+ delete file.attachment;
124
+ }
125
+ }
126
+ return parseOleResource(JSON.stringify(candidate));
127
+ }
128
+ /** Prepare a UnitData model or a native exchange JSON envelope without changing the caller's model. */
129
+ async function prepareOleSnapshot(snapshot, mode, targetUnitId, io) {
130
+ const clone = (value) => {
131
+ if (value instanceof Uint8Array) return Uint8Array.from(value);
132
+ if (Array.isArray(value)) return value.map(clone);
133
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clone(item)]));
134
+ return value;
135
+ };
136
+ const candidate = clone(snapshot);
137
+ const envelope = candidate.snapshot ?? candidate;
138
+ const host = envelope.workbook ?? envelope.doc ?? envelope.slide ?? envelope;
139
+ let model = host;
140
+ let encoded = false;
141
+ if (envelope.slide && host.originalMeta != null) {
142
+ const bytes = typeof host.originalMeta === "string" ? Uint8Array.from(atob(host.originalMeta), (character) => character.charCodeAt(0)) : host.originalMeta;
143
+ model = JSON.parse(new TextDecoder().decode(bytes));
144
+ encoded = true;
145
+ }
146
+ for (const entry of model.resources ?? []) if (entry.name === "UNIVER_OLE_ATTACHMENT_PLUGIN") {
147
+ const text = typeof entry.data === "string" ? entry.data : new TextDecoder().decode(entry.data);
148
+ const prepared = JSON.stringify(await prepareOleResource(parseOleResource(text), mode, targetUnitId, io));
149
+ entry.data = typeof entry.data === "string" ? prepared : new TextEncoder().encode(prepared);
150
+ }
151
+ if (encoded) {
152
+ const bytes = new TextEncoder().encode(JSON.stringify(model));
153
+ let binary = "";
154
+ for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
155
+ host.originalMeta = typeof host.originalMeta === "string" ? btoa(binary) : bytes;
156
+ }
157
+ return candidate;
158
+ }
159
+
160
+ // package.json
57
161
  var name = "@univerjs/drawing";
58
- var version = "1.3.1";
162
+ var version = "1.5.0";
59
163
 
60
- //#endregion
61
- //#region src/config/config.ts
164
+ // src/config/config.ts
62
165
  const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
63
166
  const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
64
167
  const defaultPluginConfig = {};
65
168
 
66
- //#endregion
67
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
169
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
68
170
  function _typeof(o) {
69
171
  "@babel/helpers - typeof";
70
172
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -74,28 +176,25 @@ function _typeof(o) {
74
176
  }, _typeof(o);
75
177
  }
76
178
 
77
- //#endregion
78
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
79
- function toPrimitive(t, r) {
179
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
180
+ function toPrimitive(t, e) {
80
181
  if ("object" != _typeof(t) || !t) return t;
81
- var e = t[Symbol.toPrimitive];
82
- if (void 0 !== e) {
83
- var i = e.call(t, r || "default");
182
+ var r;
183
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
184
+ var i = r.call(t, e || "default");
84
185
  if ("object" != _typeof(i)) return i;
85
186
  throw new TypeError("@@toPrimitive must return a primitive value.");
86
187
  }
87
- return ("string" === r ? String : Number)(t);
188
+ return ("string" === e ? String : Number)(t);
88
189
  }
89
190
 
90
- //#endregion
91
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
191
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
92
192
  function toPropertyKey(t) {
93
193
  var i = toPrimitive(t, "string");
94
194
  return "symbol" == _typeof(i) ? i : i + "";
95
195
  }
96
196
 
97
- //#endregion
98
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
197
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
99
198
  function _defineProperty(e, r, t) {
100
199
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
101
200
  value: t,
@@ -105,8 +204,7 @@ function _defineProperty(e, r, t) {
105
204
  }) : e[r] = t, e;
106
205
  }
107
206
 
108
- //#endregion
109
- //#region src/services/drawing-manager-impl.service.ts
207
+ // src/services/drawing-manager-impl.service.ts
110
208
  function isNonEmptyOp(op) {
111
209
  return Array.isArray(op) && op.length > 0;
112
210
  }
@@ -172,8 +270,9 @@ function validateDrawingData(data) {
172
270
  /**
173
271
  * unitId -> subUnitId -> drawingId -> drawingParam
174
272
  */
175
- var UnitDrawingService = class {
176
- constructor() {
273
+ var UnitDrawingService = class extends Disposable {
274
+ constructor(..._args) {
275
+ super(..._args);
177
276
  _defineProperty(this, "drawingManagerData", {});
178
277
  _defineProperty(this, "_oldDrawingManagerData", {});
179
278
  _defineProperty(this, "_focusDrawings", []);
@@ -211,6 +310,7 @@ var UnitDrawingService = class {
211
310
  _defineProperty(this, "_editable", true);
212
311
  }
213
312
  dispose() {
313
+ super.dispose();
214
314
  this._remove$.complete();
215
315
  this._add$.complete();
216
316
  this._update$.complete();
@@ -1037,10 +1137,21 @@ var UnitDrawingService = class {
1037
1137
  this._editable = editable;
1038
1138
  }
1039
1139
  };
1040
- var DrawingManagerService = class extends UnitDrawingService {};
1140
+ var DrawingManagerService = class extends UnitDrawingService {
1141
+ constructor(..._args2) {
1142
+ super(..._args2);
1143
+ _defineProperty(this, "_commandChecks", []);
1144
+ }
1145
+ registerCommandCheck(check) {
1146
+ this._commandChecks.push(check);
1147
+ return this.disposeWithMe(toDisposable(() => remove(this._commandChecks, check)));
1148
+ }
1149
+ canExecuteCommand(command) {
1150
+ return this._commandChecks.every((check) => check(command));
1151
+ }
1152
+ };
1041
1153
 
1042
- //#endregion
1043
- //#region src/services/image-io-impl.service.ts
1154
+ // src/services/image-io-impl.service.ts
1044
1155
  var ImageIoService = class {
1045
1156
  constructor() {
1046
1157
  _defineProperty(this, "_waitCount", 0);
@@ -1110,8 +1221,68 @@ var ImageIoService = class {
1110
1221
  }
1111
1222
  };
1112
1223
 
1113
- //#endregion
1114
- //#region src/services/url-image.service.ts
1224
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
1225
+ function __decorateParam(paramIndex, decorator) {
1226
+ return function(target, key) {
1227
+ decorator(target, key, paramIndex);
1228
+ };
1229
+ }
1230
+
1231
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
1232
+ function __decorate(decorators, target, key, desc) {
1233
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1234
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1235
+ 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;
1236
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1237
+ }
1238
+
1239
+ // src/services/ole.service.ts
1240
+ /**
1241
+ * Copyright 2023-present DreamNum Co., Ltd.
1242
+ *
1243
+ * Licensed under the Apache License, Version 2.0 (the "License");
1244
+ * you may not use this file except in compliance with the License.
1245
+ * You may obtain a copy of the License at
1246
+ *
1247
+ * http://www.apache.org/licenses/LICENSE-2.0
1248
+ *
1249
+ * Unless required by applicable law or agreed to in writing, software
1250
+ * distributed under the License is distributed on an "AS IS" BASIS,
1251
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1252
+ * See the License for the specific language governing permissions and
1253
+ * limitations under the License.
1254
+ */
1255
+ let OleService = class OleService extends Disposable {
1256
+ constructor(resourceManager) {
1257
+ super();
1258
+ _defineProperty(this, "_resources", /* @__PURE__ */ new Map());
1259
+ this.disposeWithMe(resourceManager.registerPluginResource({
1260
+ pluginName: OLE_RESOURCE_NAME,
1261
+ businesses: [
1262
+ UniverInstanceType.UNIVER_SHEET,
1263
+ UniverInstanceType.UNIVER_DOC,
1264
+ UniverInstanceType.UNIVER_SLIDE
1265
+ ],
1266
+ onLoad: (unitId, resource) => this._resources.set(unitId, resource),
1267
+ onUnLoad: (unitId) => this._resources.delete(unitId),
1268
+ toJson: (unitId) => JSON.stringify(this._resources.get(unitId) ?? {
1269
+ files: {},
1270
+ objects: {}
1271
+ }),
1272
+ parseJson: parseOleResource
1273
+ }));
1274
+ }
1275
+ getResource(unitId) {
1276
+ return this._resources.get(unitId);
1277
+ }
1278
+ dispose() {
1279
+ this._resources.clear();
1280
+ super.dispose();
1281
+ }
1282
+ };
1283
+ OleService = __decorate([__decorateParam(0, IResourceManagerService)], OleService);
1284
+
1285
+ // src/services/url-image.service.ts
1115
1286
  var URLImageService = class extends Disposable {
1116
1287
  constructor(..._args) {
1117
1288
  super(..._args);
@@ -1142,25 +1313,7 @@ var URLImageService = class extends Disposable {
1142
1313
  }
1143
1314
  };
1144
1315
 
1145
- //#endregion
1146
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
1147
- function __decorateParam(paramIndex, decorator) {
1148
- return function(target, key) {
1149
- decorator(target, key, paramIndex);
1150
- };
1151
- }
1152
-
1153
- //#endregion
1154
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
1155
- function __decorate(decorators, target, key, desc) {
1156
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1157
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1158
- 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;
1159
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1160
- }
1161
-
1162
- //#endregion
1163
- //#region src/plugin.ts
1316
+ // src/plugin.ts
1164
1317
  let UniverDrawingPlugin = class UniverDrawingPlugin extends Plugin {
1165
1318
  constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
1166
1319
  super();
@@ -1175,13 +1328,15 @@ let UniverDrawingPlugin = class UniverDrawingPlugin extends Plugin {
1175
1328
  onStarting() {
1176
1329
  this._initCommands();
1177
1330
  this._initDependencies();
1331
+ this._injector.get(OleService);
1178
1332
  }
1179
1333
  _initDependencies() {
1180
1334
  var _this$_config;
1181
1335
  mergeOverrideWithDependencies([
1182
1336
  [IImageIoService, { useClass: ImageIoService }],
1183
1337
  [IURLImageService, { useClass: URLImageService }],
1184
- [IDrawingManagerService, { useClass: DrawingManagerService }]
1338
+ [IDrawingManagerService, { useClass: DrawingManagerService }],
1339
+ [OleService]
1185
1340
  ], (_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.override).forEach((d) => this._injector.add(d));
1186
1341
  }
1187
1342
  _initCommands() {
@@ -1197,8 +1352,7 @@ UniverDrawingPlugin = __decorate([
1197
1352
  __decorateParam(3, ICommandService)
1198
1353
  ], UniverDrawingPlugin);
1199
1354
 
1200
- //#endregion
1201
- //#region src/utils/drawing-copy-plan.ts
1355
+ // src/utils/drawing-copy-plan.ts
1202
1356
  /**
1203
1357
  * A command-scoped cache key shared by sheet-copy interceptors so every drawing model
1204
1358
  * resolves against the same copied drawing IDs.
@@ -1255,8 +1409,7 @@ function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
1255
1409
  return plan;
1256
1410
  }
1257
1411
 
1258
- //#endregion
1259
- //#region src/utils/drawing-group.ts
1412
+ // src/utils/drawing-group.ts
1260
1413
  const DRAWING_GROUPABLE_TYPES = [
1261
1414
  DrawingTypeEnum.DRAWING_IMAGE,
1262
1415
  DrawingTypeEnum.DRAWING_SHAPE,
@@ -1269,14 +1422,12 @@ function isGroupableDrawingType(type) {
1269
1422
  return DRAWING_GROUPABLE_TYPES.includes(type);
1270
1423
  }
1271
1424
 
1272
- //#endregion
1273
- //#region src/utils/get-image-shape-key.ts
1425
+ // src/utils/get-image-shape-key.ts
1274
1426
  function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
1275
1427
  return typeof index === "number" ? `${unitId}#-#${subUnitId}#-#${drawingId}#-#${index}` : `${unitId}#-#${subUnitId}#-#${drawingId}`;
1276
1428
  }
1277
1429
 
1278
- //#endregion
1279
- //#region src/utils/get-image-size.ts
1430
+ // src/utils/get-image-size.ts
1280
1431
  const getImageSize = async (src) => {
1281
1432
  return new Promise((resolve, reject) => {
1282
1433
  const image = new Image();
@@ -1294,8 +1445,7 @@ const getImageSize = async (src) => {
1294
1445
  });
1295
1446
  };
1296
1447
 
1297
- //#endregion
1298
- //#region src/utils/image-opacity.ts
1448
+ // src/utils/image-opacity.ts
1299
1449
  /**
1300
1450
  * Copyright 2023-present DreamNum Co., Ltd.
1301
1451
  *
@@ -1316,13 +1466,13 @@ function normalizeImageOpacity(opacity) {
1316
1466
  return Math.min(Math.max(opacity, 0), 1);
1317
1467
  }
1318
1468
 
1319
- //#endregion
1320
- //#region src/utils/rotate-enabled.ts
1469
+ // src/utils/rotate-enabled.ts
1321
1470
  function getDrawingKey(drawing) {
1322
1471
  return `${drawing.unitId}\u0000${drawing.subUnitId}\u0000${drawing.drawingId}`;
1323
1472
  }
1324
1473
  function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PURE__ */ new Set()) {
1325
1474
  var _drawing$transform, _options$getRenderObj, _options$isKnownNonRo;
1475
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_OLE) return false;
1326
1476
  const drawingKey = getDrawingKey(drawing);
1327
1477
  if (visiting.has(drawingKey)) return true;
1328
1478
  if (drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP) {
@@ -1342,5 +1492,4 @@ function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PUR
1342
1492
  return true;
1343
1493
  }
1344
1494
 
1345
- //#endregion
1346
- export { DRAWING_COPY_CONTEXT_KEY, DRAWING_GROUPABLE_TYPES, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingManagerService, IDrawingManagerService, ImageIoService, SetDrawingSelectedOperation, URLImageService, UnitDrawingService, UniverDrawingPlugin, createDrawingCopyPlan, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize, getOrCreateDrawingCopyPlan, isGroupableDrawingType, normalizeImageOpacity, resolveDrawingRotateEnabled };
1495
+ export { DRAWING_COPY_CONTEXT_KEY, DRAWING_GROUPABLE_TYPES, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingManagerService, IDrawingManagerService, ImageIoService, OLE_RESOURCE_NAME, OleService, SetDrawingSelectedOperation, URLImageService, UnitDrawingService, UniverDrawingPlugin, createDrawingCopyPlan, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize, getOleOfficeType, getOrCreateDrawingCopyPlan, isGroupableDrawingType, normalizeImageOpacity, prepareOleSnapshot, readOleFile, resolveDrawingRotateEnabled };
@@ -14,9 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { DependencyOverride } from '@univerjs/core';
17
+ import type { IOleConfig } from '../models/ole-model';
17
18
  export declare const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
18
19
  export declare const configSymbol: unique symbol;
19
20
  export interface IUniverDrawingConfig {
21
+ ole?: IOleConfig;
20
22
  override?: DependencyOverride;
21
23
  /**
22
24
  * The maximum allowed size of uploaded images in bytes.
@@ -17,12 +17,15 @@ export { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAG
17
17
  export { SetDrawingSelectedOperation } from './commands/operations/set-drawing-selected.operation';
18
18
  export type { IUniverDrawingConfig } from './config/config';
19
19
  export type { IDocFloatDomData, IDocFloatDomDataBase, IImageData } from './models/image-model-interface';
20
+ export type { IOleAttachmentIo, IOleConfig, IOleDrawing, IOleOnlineConversionRequest, IOleOnlineUnit, IOlePreviewRequest, IOleResource, OleConversionStage } from './models/ole-model';
21
+ export { getOleOfficeType, OLE_RESOURCE_NAME, prepareOleSnapshot, readOleFile } from './models/ole-model';
20
22
  export { UniverDrawingPlugin } from './plugin';
21
23
  export { DrawingManagerService, UnitDrawingService } from './services/drawing-manager-impl.service';
22
24
  export type { IDrawingJson1Type, IDrawingJsonUndo1 } from './services/drawing-manager-impl.service';
23
25
  export type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItem, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService, } from './services/drawing-manager.service';
24
26
  export { IDrawingManagerService } from './services/drawing-manager.service';
25
27
  export { ImageIoService } from './services/image-io-impl.service';
28
+ export { OleService } from './services/ole.service';
26
29
  export { URLImageService } from './services/url-image.service';
27
30
  export { createDrawingCopyPlan, DRAWING_COPY_CONTEXT_KEY, getOrCreateDrawingCopyPlan } from './utils/drawing-copy-plan';
28
31
  export type { ICreateDrawingCopyPlanOptions, IDrawingCopyPlan } from './utils/drawing-copy-plan';
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IBaseAttachment, IDisposable } from '@univerjs/core';
17
+ import { UniverInstanceType } from '@univerjs/core';
18
+ import type { IImageData } from './image-model-interface';
19
+ export declare const OLE_RESOURCE_NAME = "UNIVER_OLE_ATTACHMENT_PLUGIN";
20
+ export declare const OLE_MAX_RESOURCE_BYTES: number;
21
+ export interface IOleDrawing extends IImageData {
22
+ oleAttachmentId: string;
23
+ /** Per-occurrence display and download name; original attachment metadata stays intact. */
24
+ oleFileName?: string;
25
+ oleOnlineUnit?: IOleOnlineUnit;
26
+ }
27
+ export interface IOleOnlineUnit {
28
+ unitId: string;
29
+ type: UniverInstanceType;
30
+ }
31
+ export declare function getOleOfficeType(mimeType: string): UniverInstanceType | undefined;
32
+ export interface IOleFile {
33
+ name: string;
34
+ mimeType: string;
35
+ size: number;
36
+ sha256: string;
37
+ data?: string;
38
+ attachment?: IBaseAttachment;
39
+ }
40
+ export interface IOleRelationship {
41
+ id: string;
42
+ relationshipType: string;
43
+ target: string;
44
+ external: boolean;
45
+ }
46
+ export interface IOleObject {
47
+ id: string;
48
+ hostPart: string;
49
+ fileName?: string;
50
+ subUnitId: string;
51
+ drawingId: string;
52
+ initialGeometry?: object;
53
+ shapeId: string;
54
+ progId: string;
55
+ relationshipId: string;
56
+ external: boolean;
57
+ status: 'ready' | 'opaque' | 'missing' | 'external-unavailable';
58
+ rawFileId: string | null;
59
+ fileId: string | null;
60
+ xml: string;
61
+ relationships: IOleRelationship[];
62
+ parts: Record<string, string>;
63
+ legacy?: {
64
+ hostPart: string;
65
+ xml: string;
66
+ shapeTypes: string[];
67
+ relationships: IOleRelationship[];
68
+ };
69
+ }
70
+ export interface IOleResource {
71
+ files: Record<string, IOleFile>;
72
+ objects: Record<string, IOleObject>;
73
+ }
74
+ /** The online adapter follows the application's existing attachment upload/read contract. */
75
+ export interface IOleAttachmentIo {
76
+ upload: (file: File, targetUnitId: string) => Promise<IBaseAttachment>;
77
+ read: (attachment: IBaseAttachment, signal?: AbortSignal) => Promise<Uint8Array>;
78
+ }
79
+ export interface IOlePreviewRequest {
80
+ unitId: string;
81
+ attachmentId: string;
82
+ name: string;
83
+ mimeType: string;
84
+ bytes: Uint8Array;
85
+ signal: AbortSignal;
86
+ }
87
+ export type OleConversionStage = 'reading' | 'uploading' | 'converting' | 'creating' | 'saving';
88
+ /** Existing Unit attachments are converted by reference. JSON attachments upload their bytes once. */
89
+ export type IOleOnlineConversionRequest = Omit<IOlePreviewRequest, 'bytes'> & {
90
+ onProgress?: (stage: OleConversionStage) => void;
91
+ } & ({
92
+ fileId: string;
93
+ bytes?: never;
94
+ } | {
95
+ bytes: Uint8Array;
96
+ fileId?: never;
97
+ });
98
+ export interface IOleConfig {
99
+ /** Whether this exact host Unit is backed by the collaboration server. */
100
+ isCollaborative?: (unitId: string) => boolean;
101
+ /** Resolve the current application URL on each Open action; URLs are never persisted. */
102
+ getLink?: (unitId: string, type: UniverInstanceType) => string;
103
+ /** Explicitly create an independent online Unit and return its durable identity. */
104
+ convertToOnline?: (request: IOleOnlineConversionRequest) => Promise<IOleOnlineUnit>;
105
+ attachmentIo?: IOleAttachmentIo;
106
+ /** Open a temporary read-only Office preview. The handler must not create a persisted child Unit. */
107
+ previewOffice?: (request: IOlePreviewRequest) => Promise<void>;
108
+ /** Convert on demand to UnitData, using JSON output without persisting a child Unit. */
109
+ createOfficePreview?: (container: HTMLElement, view: {
110
+ type: UniverInstanceType;
111
+ data: object;
112
+ }) => Promise<IDisposable>;
113
+ convertOffice?: (request: IOlePreviewRequest) => Promise<{
114
+ type: UniverInstanceType;
115
+ data: object;
116
+ }>;
117
+ }
118
+ export declare function parseOleResource(json: string): IOleResource;
119
+ export declare function readOleFile(file: IOleFile, io?: IOleAttachmentIo, signal?: AbortSignal): Promise<Uint8Array>;
120
+ /** Atomic model conversion: failures leave the caller's resource unchanged. */
121
+ export declare function prepareOleResource(resource: IOleResource, mode: 'json' | 'unit', targetUnitId?: string, io?: IOleAttachmentIo): Promise<IOleResource>;
122
+ /** Prepare a UnitData model or a native exchange JSON envelope without changing the caller's model. */
123
+ export declare function prepareOleSnapshot<T extends object>(snapshot: T, mode: 'json' | 'unit', targetUnitId?: string, io?: IOleAttachmentIo): Promise<T>;
@@ -13,10 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
16
+ import type { ICommandInfo, IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
17
17
  import type { Observable } from 'rxjs';
18
+ import { Disposable, JSON1 } from '@univerjs/core';
18
19
  import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
19
- import { JSON1 } from '@univerjs/core';
20
20
  type JSONOp = JSON1.JSONOp;
21
21
  type JSONOpList = JSON1.JSONOpList;
22
22
  export interface IDrawingJsonUndo1<TObjects = IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[]> {
@@ -40,7 +40,7 @@ interface IDrawingRefreshMetadata {
40
40
  /**
41
41
  * unitId -> subUnitId -> drawingId -> drawingParam
42
42
  */
43
- export declare class UnitDrawingService<T extends IDrawingParam & IDrawingRefreshMetadata> implements IUnitDrawingService<T> {
43
+ export declare class UnitDrawingService<T extends IDrawingParam & IDrawingRefreshMetadata> extends Disposable implements IUnitDrawingService<T> {
44
44
  drawingManagerData: IDrawingMap<T>;
45
45
  private _oldDrawingManagerData;
46
46
  private _focusDrawings;
@@ -141,5 +141,8 @@ export declare class UnitDrawingService<T extends IDrawingParam & IDrawingRefres
141
141
  setDrawingEditable(editable: boolean): void;
142
142
  }
143
143
  export declare class DrawingManagerService extends UnitDrawingService<IDrawingParam> {
144
+ private readonly _commandChecks;
145
+ registerCommandCheck(check: (command: ICommandInfo) => boolean): import("@univerjs/core").IDisposable;
146
+ canExecuteCommand(command: ICommandInfo): boolean;
144
147
  }
145
148
  export {};
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { ArrangeTypeEnum, IDisposable, IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
16
+ import type { ArrangeTypeEnum, ICommandInfo, IDisposable, IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
17
17
  import type { Observable } from 'rxjs';
18
18
  export interface IDrawingMap<T extends IDrawingParam> {
19
19
  [unitId: string]: IDrawingSubunitMap<T>;
@@ -126,5 +126,7 @@ export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNorma
126
126
  setDrawingEditable(editable: boolean): void;
127
127
  }
128
128
  export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {
129
+ registerCommandCheck(check: (command: ICommandInfo) => boolean): IDisposable;
130
+ canExecuteCommand(command: ICommandInfo): boolean;
129
131
  }
130
- export declare const IDrawingManagerService: import("@wendellhu/redi").IdentifierDecorator<IUnitDrawingService<IDrawingParam>>;
132
+ export declare const IDrawingManagerService: import("@univerjs/core").IdentifierDecorator<IDrawingManagerService>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable, IResourceManagerService } from '@univerjs/core';
17
+ import type { IOleResource } from '../models/ole-model';
18
+ /** Registered by the model plugin so headless save/export preserves original files too. */
19
+ export declare class OleService extends Disposable {
20
+ private readonly _resources;
21
+ constructor(resourceManager: IResourceManagerService);
22
+ getResource(unitId: string): IOleResource | undefined;
23
+ dispose(): void;
24
+ }