@univerjs/drawing 1.0.3 → 1.1.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/cjs/index.js +33 -8
- package/lib/es/index.js +32 -8
- package/lib/index.js +32 -8
- package/lib/types/index.d.ts +1 -0
- package/lib/types/models/image-model-interface.d.ts +2 -0
- package/lib/types/services/drawing-manager-impl.service.d.ts +6 -1
- package/lib/types/utils/image-opacity.d.ts +16 -0
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/lib/cjs/index.js
CHANGED
|
@@ -56,7 +56,7 @@ const SetDrawingSelectedOperation = {
|
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region package.json
|
|
58
58
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.0
|
|
59
|
+
var version = "1.1.0";
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/config/config.ts
|
|
@@ -65,7 +65,7 @@ const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
|
|
|
65
65
|
const defaultPluginConfig = {};
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
|
-
//#region \0@oxc-project+runtime@0.
|
|
68
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
69
69
|
function _typeof(o) {
|
|
70
70
|
"@babel/helpers - typeof";
|
|
71
71
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -76,7 +76,7 @@ function _typeof(o) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
//#endregion
|
|
79
|
-
//#region \0@oxc-project+runtime@0.
|
|
79
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
80
80
|
function toPrimitive(t, r) {
|
|
81
81
|
if ("object" != _typeof(t) || !t) return t;
|
|
82
82
|
var e = t[Symbol.toPrimitive];
|
|
@@ -89,14 +89,14 @@ function toPrimitive(t, r) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
//#endregion
|
|
92
|
-
//#region \0@oxc-project+runtime@0.
|
|
92
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
93
93
|
function toPropertyKey(t) {
|
|
94
94
|
var i = toPrimitive(t, "string");
|
|
95
95
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
//#endregion
|
|
99
|
-
//#region \0@oxc-project+runtime@0.
|
|
99
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
100
100
|
function _defineProperty(e, r, t) {
|
|
101
101
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
102
102
|
value: t,
|
|
@@ -232,6 +232,8 @@ var UnitDrawingService = class {
|
|
|
232
232
|
const param = this._getCurrentBySearch(updateParam);
|
|
233
233
|
if (param == null) return;
|
|
234
234
|
param.transform = updateParam.transform;
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "sheetTransform")) param.sheetTransform = updateParam.sheetTransform;
|
|
236
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "axisAlignSheetTransform")) param.axisAlignSheetTransform = updateParam.axisAlignSheetTransform;
|
|
235
237
|
if (Object.prototype.hasOwnProperty.call(updateParam, "transforms")) param.transforms = updateParam.transforms;
|
|
236
238
|
if (Object.prototype.hasOwnProperty.call(updateParam, "isMultiTransform")) param.isMultiTransform = updateParam.isMultiTransform;
|
|
237
239
|
if ("behindText" in updateParam) param.behindText = updateParam.behindText;
|
|
@@ -1142,7 +1144,7 @@ var URLImageService = class extends _univerjs_core.Disposable {
|
|
|
1142
1144
|
};
|
|
1143
1145
|
|
|
1144
1146
|
//#endregion
|
|
1145
|
-
//#region \0@oxc-project+runtime@0.
|
|
1147
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
1146
1148
|
function __decorateParam(paramIndex, decorator) {
|
|
1147
1149
|
return function(target, key) {
|
|
1148
1150
|
decorator(target, key, paramIndex);
|
|
@@ -1150,7 +1152,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
1150
1152
|
}
|
|
1151
1153
|
|
|
1152
1154
|
//#endregion
|
|
1153
|
-
//#region \0@oxc-project+runtime@0.
|
|
1155
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
1154
1156
|
function __decorate(decorators, target, key, desc) {
|
|
1155
1157
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1156
1158
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1293,6 +1295,28 @@ const getImageSize = async (src) => {
|
|
|
1293
1295
|
});
|
|
1294
1296
|
};
|
|
1295
1297
|
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region src/utils/image-opacity.ts
|
|
1300
|
+
/**
|
|
1301
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1302
|
+
*
|
|
1303
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1304
|
+
* you may not use this file except in compliance with the License.
|
|
1305
|
+
* You may obtain a copy of the License at
|
|
1306
|
+
*
|
|
1307
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1308
|
+
*
|
|
1309
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1310
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1311
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1312
|
+
* See the License for the specific language governing permissions and
|
|
1313
|
+
* limitations under the License.
|
|
1314
|
+
*/
|
|
1315
|
+
function normalizeImageOpacity(opacity) {
|
|
1316
|
+
if (opacity === void 0 || !Number.isFinite(opacity)) return 1;
|
|
1317
|
+
return Math.min(Math.max(opacity, 0), 1);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1296
1320
|
//#endregion
|
|
1297
1321
|
//#region src/utils/rotate-enabled.ts
|
|
1298
1322
|
function getDrawingKey(drawing) {
|
|
@@ -1332,7 +1356,7 @@ exports.ImageIoService = ImageIoService;
|
|
|
1332
1356
|
exports.SetDrawingSelectedOperation = SetDrawingSelectedOperation;
|
|
1333
1357
|
exports.URLImageService = URLImageService;
|
|
1334
1358
|
exports.UnitDrawingService = UnitDrawingService;
|
|
1335
|
-
Object.defineProperty(exports,
|
|
1359
|
+
Object.defineProperty(exports, "UniverDrawingPlugin", {
|
|
1336
1360
|
enumerable: true,
|
|
1337
1361
|
get: function () {
|
|
1338
1362
|
return UniverDrawingPlugin;
|
|
@@ -1344,4 +1368,5 @@ exports.getDrawingShapeKeyByDrawingSearch = getDrawingShapeKeyByDrawingSearch;
|
|
|
1344
1368
|
exports.getImageSize = getImageSize;
|
|
1345
1369
|
exports.getOrCreateDrawingCopyPlan = getOrCreateDrawingCopyPlan;
|
|
1346
1370
|
exports.isGroupableDrawingType = isGroupableDrawingType;
|
|
1371
|
+
exports.normalizeImageOpacity = normalizeImageOpacity;
|
|
1347
1372
|
exports.resolveDrawingRotateEnabled = resolveDrawingRotateEnabled;
|
package/lib/es/index.js
CHANGED
|
@@ -55,7 +55,7 @@ const SetDrawingSelectedOperation = {
|
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region package.json
|
|
57
57
|
var name = "@univerjs/drawing";
|
|
58
|
-
var version = "1.0
|
|
58
|
+
var version = "1.1.0";
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/config/config.ts
|
|
@@ -64,7 +64,7 @@ const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
|
|
|
64
64
|
const defaultPluginConfig = {};
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
68
68
|
function _typeof(o) {
|
|
69
69
|
"@babel/helpers - typeof";
|
|
70
70
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -75,7 +75,7 @@ function _typeof(o) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
//#endregion
|
|
78
|
-
//#region \0@oxc-project+runtime@0.
|
|
78
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
79
79
|
function toPrimitive(t, r) {
|
|
80
80
|
if ("object" != _typeof(t) || !t) return t;
|
|
81
81
|
var e = t[Symbol.toPrimitive];
|
|
@@ -88,14 +88,14 @@ function toPrimitive(t, r) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
//#region \0@oxc-project+runtime@0.
|
|
91
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
92
92
|
function toPropertyKey(t) {
|
|
93
93
|
var i = toPrimitive(t, "string");
|
|
94
94
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region \0@oxc-project+runtime@0.
|
|
98
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
99
99
|
function _defineProperty(e, r, t) {
|
|
100
100
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
101
101
|
value: t,
|
|
@@ -231,6 +231,8 @@ var UnitDrawingService = class {
|
|
|
231
231
|
const param = this._getCurrentBySearch(updateParam);
|
|
232
232
|
if (param == null) return;
|
|
233
233
|
param.transform = updateParam.transform;
|
|
234
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "sheetTransform")) param.sheetTransform = updateParam.sheetTransform;
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "axisAlignSheetTransform")) param.axisAlignSheetTransform = updateParam.axisAlignSheetTransform;
|
|
234
236
|
if (Object.prototype.hasOwnProperty.call(updateParam, "transforms")) param.transforms = updateParam.transforms;
|
|
235
237
|
if (Object.prototype.hasOwnProperty.call(updateParam, "isMultiTransform")) param.isMultiTransform = updateParam.isMultiTransform;
|
|
236
238
|
if ("behindText" in updateParam) param.behindText = updateParam.behindText;
|
|
@@ -1141,7 +1143,7 @@ var URLImageService = class extends Disposable {
|
|
|
1141
1143
|
};
|
|
1142
1144
|
|
|
1143
1145
|
//#endregion
|
|
1144
|
-
//#region \0@oxc-project+runtime@0.
|
|
1146
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
1145
1147
|
function __decorateParam(paramIndex, decorator) {
|
|
1146
1148
|
return function(target, key) {
|
|
1147
1149
|
decorator(target, key, paramIndex);
|
|
@@ -1149,7 +1151,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
1149
1151
|
}
|
|
1150
1152
|
|
|
1151
1153
|
//#endregion
|
|
1152
|
-
//#region \0@oxc-project+runtime@0.
|
|
1154
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
1153
1155
|
function __decorate(decorators, target, key, desc) {
|
|
1154
1156
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1155
1157
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1292,6 +1294,28 @@ const getImageSize = async (src) => {
|
|
|
1292
1294
|
});
|
|
1293
1295
|
};
|
|
1294
1296
|
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/utils/image-opacity.ts
|
|
1299
|
+
/**
|
|
1300
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1301
|
+
*
|
|
1302
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1303
|
+
* you may not use this file except in compliance with the License.
|
|
1304
|
+
* You may obtain a copy of the License at
|
|
1305
|
+
*
|
|
1306
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1307
|
+
*
|
|
1308
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1309
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1310
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1311
|
+
* See the License for the specific language governing permissions and
|
|
1312
|
+
* limitations under the License.
|
|
1313
|
+
*/
|
|
1314
|
+
function normalizeImageOpacity(opacity) {
|
|
1315
|
+
if (opacity === void 0 || !Number.isFinite(opacity)) return 1;
|
|
1316
|
+
return Math.min(Math.max(opacity, 0), 1);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1295
1319
|
//#endregion
|
|
1296
1320
|
//#region src/utils/rotate-enabled.ts
|
|
1297
1321
|
function getDrawingKey(drawing) {
|
|
@@ -1319,4 +1343,4 @@ function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PUR
|
|
|
1319
1343
|
}
|
|
1320
1344
|
|
|
1321
1345
|
//#endregion
|
|
1322
|
-
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, resolveDrawingRotateEnabled };
|
|
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 };
|
package/lib/index.js
CHANGED
|
@@ -55,7 +55,7 @@ const SetDrawingSelectedOperation = {
|
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region package.json
|
|
57
57
|
var name = "@univerjs/drawing";
|
|
58
|
-
var version = "1.0
|
|
58
|
+
var version = "1.1.0";
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/config/config.ts
|
|
@@ -64,7 +64,7 @@ const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
|
|
|
64
64
|
const defaultPluginConfig = {};
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
68
68
|
function _typeof(o) {
|
|
69
69
|
"@babel/helpers - typeof";
|
|
70
70
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -75,7 +75,7 @@ function _typeof(o) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
//#endregion
|
|
78
|
-
//#region \0@oxc-project+runtime@0.
|
|
78
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
79
79
|
function toPrimitive(t, r) {
|
|
80
80
|
if ("object" != _typeof(t) || !t) return t;
|
|
81
81
|
var e = t[Symbol.toPrimitive];
|
|
@@ -88,14 +88,14 @@ function toPrimitive(t, r) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
//#region \0@oxc-project+runtime@0.
|
|
91
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
92
92
|
function toPropertyKey(t) {
|
|
93
93
|
var i = toPrimitive(t, "string");
|
|
94
94
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region \0@oxc-project+runtime@0.
|
|
98
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
99
99
|
function _defineProperty(e, r, t) {
|
|
100
100
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
101
101
|
value: t,
|
|
@@ -231,6 +231,8 @@ var UnitDrawingService = class {
|
|
|
231
231
|
const param = this._getCurrentBySearch(updateParam);
|
|
232
232
|
if (param == null) return;
|
|
233
233
|
param.transform = updateParam.transform;
|
|
234
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "sheetTransform")) param.sheetTransform = updateParam.sheetTransform;
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(updateParam, "axisAlignSheetTransform")) param.axisAlignSheetTransform = updateParam.axisAlignSheetTransform;
|
|
234
236
|
if (Object.prototype.hasOwnProperty.call(updateParam, "transforms")) param.transforms = updateParam.transforms;
|
|
235
237
|
if (Object.prototype.hasOwnProperty.call(updateParam, "isMultiTransform")) param.isMultiTransform = updateParam.isMultiTransform;
|
|
236
238
|
if ("behindText" in updateParam) param.behindText = updateParam.behindText;
|
|
@@ -1141,7 +1143,7 @@ var URLImageService = class extends Disposable {
|
|
|
1141
1143
|
};
|
|
1142
1144
|
|
|
1143
1145
|
//#endregion
|
|
1144
|
-
//#region \0@oxc-project+runtime@0.
|
|
1146
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
1145
1147
|
function __decorateParam(paramIndex, decorator) {
|
|
1146
1148
|
return function(target, key) {
|
|
1147
1149
|
decorator(target, key, paramIndex);
|
|
@@ -1149,7 +1151,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
1149
1151
|
}
|
|
1150
1152
|
|
|
1151
1153
|
//#endregion
|
|
1152
|
-
//#region \0@oxc-project+runtime@0.
|
|
1154
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
1153
1155
|
function __decorate(decorators, target, key, desc) {
|
|
1154
1156
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1155
1157
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1292,6 +1294,28 @@ const getImageSize = async (src) => {
|
|
|
1292
1294
|
});
|
|
1293
1295
|
};
|
|
1294
1296
|
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/utils/image-opacity.ts
|
|
1299
|
+
/**
|
|
1300
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1301
|
+
*
|
|
1302
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1303
|
+
* you may not use this file except in compliance with the License.
|
|
1304
|
+
* You may obtain a copy of the License at
|
|
1305
|
+
*
|
|
1306
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1307
|
+
*
|
|
1308
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1309
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1310
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1311
|
+
* See the License for the specific language governing permissions and
|
|
1312
|
+
* limitations under the License.
|
|
1313
|
+
*/
|
|
1314
|
+
function normalizeImageOpacity(opacity) {
|
|
1315
|
+
if (opacity === void 0 || !Number.isFinite(opacity)) return 1;
|
|
1316
|
+
return Math.min(Math.max(opacity, 0), 1);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1295
1319
|
//#endregion
|
|
1296
1320
|
//#region src/utils/rotate-enabled.ts
|
|
1297
1321
|
function getDrawingKey(drawing) {
|
|
@@ -1319,4 +1343,4 @@ function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PUR
|
|
|
1319
1343
|
}
|
|
1320
1344
|
|
|
1321
1345
|
//#endregion
|
|
1322
|
-
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, resolveDrawingRotateEnabled };
|
|
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 };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -29,5 +29,6 @@ export type { ICreateDrawingCopyPlanOptions, IDrawingCopyPlan } from './utils/dr
|
|
|
29
29
|
export { DRAWING_GROUPABLE_TYPES, isGroupableDrawingType } from './utils/drawing-group';
|
|
30
30
|
export { getDrawingShapeKeyByDrawingSearch } from './utils/get-image-shape-key';
|
|
31
31
|
export { getImageSize } from './utils/get-image-size';
|
|
32
|
+
export { normalizeImageOpacity } from './utils/image-opacity';
|
|
32
33
|
export { resolveDrawingRotateEnabled } from './utils/rotate-enabled';
|
|
33
34
|
export type { IDrawingRotateEnabledResolverOptions } from './utils/rotate-enabled';
|
|
@@ -17,6 +17,8 @@ import type { IDrawingParam, ImageSourceType, ISrcRect, Nullable, Serializable }
|
|
|
17
17
|
export interface IImageData extends IDrawingParam {
|
|
18
18
|
imageSourceType: ImageSourceType;
|
|
19
19
|
source: string;
|
|
20
|
+
/** Whole-image opacity from 0 (transparent) through 1 (opaque). Defaults to 1. */
|
|
21
|
+
opacity?: number;
|
|
20
22
|
/**
|
|
21
23
|
* 20.1.8.55 srcRect (Source Rectangle)
|
|
22
24
|
*/
|
|
@@ -32,10 +32,15 @@ export interface IDrawingJson1Type {
|
|
|
32
32
|
subUnitId: string;
|
|
33
33
|
objects: IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[];
|
|
34
34
|
}
|
|
35
|
+
interface IDrawingRefreshMetadata {
|
|
36
|
+
behindText?: unknown;
|
|
37
|
+
sheetTransform?: unknown;
|
|
38
|
+
axisAlignSheetTransform?: unknown;
|
|
39
|
+
}
|
|
35
40
|
/**
|
|
36
41
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
37
42
|
*/
|
|
38
|
-
export declare class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawingService<T> {
|
|
43
|
+
export declare class UnitDrawingService<T extends IDrawingParam & IDrawingRefreshMetadata> implements IUnitDrawingService<T> {
|
|
39
44
|
drawingManagerData: IDrawingMap<T>;
|
|
40
45
|
private _oldDrawingManagerData;
|
|
41
46
|
private _focusDrawings;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare function normalizeImageOpacity(opacity: number | undefined): number;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +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`});let r=5242880;function i(e){r=e}function a(){return r}let o=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],s=(0,t.createIdentifier)(`univer.drawing-manager.service`),c={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(s);return t!=null&&(n.focusDrawing(t),!0)}};var l=`@univerjs/drawing`,u=`1.0.3`;let d={};function f(e){"@babel/helpers - typeof";return f=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},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e){return Array.isArray(e)&&e.length>0}function _(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)=>_(e,t[n]));if(!v(e)||!v(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)&&_(e[n],t[n]))}function v(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function y(e){return Object.getOwnPropertyNames(e).every(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function b(e,n){return t.JSON1.type.writeCursor().writeAtPath(e,`r`,n).get()}function x(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=>x(e)??null);if(!v(e))return;let t={};return Object.entries(e).forEach(([e,n])=>{let r=x(n);r!==void 0&&(t[e]=r)}),t}function S(e,n,r,i,a){let o=x(i),s=x(r),c=a&&o!==void 0;if(c&&_(o,s))return;if(c&&v(i)&&v(r)&&y(i)&&y(r)){for(let t of new Set([...Object.keys(i),...Object.keys(r)]))S(e,[...n,t],r[t],i[t],Object.prototype.hasOwnProperty.call(i,t)&&i[t]!==void 0);return}let l=c?s===void 0?b(n,o):t.JSON1.replaceOp(n,o,s):s===void 0?null:t.JSON1.insertOp(n,s);l&&g(l)&&e.push(l)}function C(...e){for(let t of e)if(t===`__proto__`||t===`constructor`||t===`prototype`)throw Error(`Invalid drawing key`)}function w(e,t){return e!=null&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function T(e){for(let t of Object.keys(e)){C(t);let n=e[t];n!=null&&n.data&&Object.keys(n.data).forEach(e=>C(e)),n!=null&&n.order&&n.order.forEach(e=>C(e))}}var E=class{constructor(){h(this,`drawingManagerData`,{}),h(this,`_oldDrawingManagerData`,{}),h(this,`_focusDrawings`,[]),h(this,`_remove$`,new n.Subject),h(this,`remove$`,this._remove$.asObservable()),h(this,`_add$`,new n.Subject),h(this,`add$`,this._add$.asObservable()),h(this,`_update$`,new n.Subject),h(this,`update$`,this._update$.asObservable()),h(this,`_order$`,new n.Subject),h(this,`order$`,this._order$.asObservable()),h(this,`_group$`,new n.Subject),h(this,`group$`,this._group$.asObservable()),h(this,`_ungroup$`,new n.Subject),h(this,`ungroup$`,this._ungroup$.asObservable()),h(this,`_refreshTransform$`,new n.Subject),h(this,`refreshTransform$`,this._refreshTransform$.asObservable()),h(this,`_visible$`,new n.Subject),h(this,`visible$`,this._visible$.asObservable()),h(this,`_focus$`,new n.Subject),h(this,`focus$`,this._focus$.asObservable()),h(this,`_featurePluginUpdate$`,new n.Subject),h(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),h(this,`_featurePluginAdd$`,new n.Subject),h(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),h(this,`_featurePluginRemove$`,new n.Subject),h(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),h(this,`_featurePluginOrderUpdate$`,new n.Subject),h(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),h(this,`_featurePluginGroupUpdate$`,new n.Subject),h(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),h(this,`_featurePluginUngroupUpdate$`,new n.Subject),h(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),h(this,`_visible`,!0),h(this,`_editable`,!0)}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){e.forEach(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,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))}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return w(this.drawingManagerData,e)||{}}removeDrawingDataForUnit(e){let t=w(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){C(e),T(t),this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=w(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){C(e,t),Object.keys(n).forEach(e=>C(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=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=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=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);g(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=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){C(e,n),t.JSON1.type.checkValidOp(r);let i=w(this.drawingManagerData,e),a={...this.drawingManagerData,[e]:{...i,[n]:w(i,n)??{data:{},order:[]}}},o=t.JSON1.type.apply(a,r);for(let e of Object.keys(o))C(e),T(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){C(e,t),n.forEach(e=>C(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 w((t=w(w(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 w((t=w(w(this._oldDrawingManagerData,n),r))==null?void 0:t.data,i)}_establishDrawingMap(e,t,n){return C(e,t),n!=null&&C(n),w(this.drawingManagerData,e)||(this.drawingManagerData[e]={}),w(this.drawingManagerData[e],t)||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:w(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];S(a,[n,r,`data`,i,o],s,l,c)}),a}_getDrawingData(e,t){var n;return((n=w(w(this.drawingManagerData,e),t))==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=w(w(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}},D=class extends E{},O=class{constructor(){h(this,`_waitCount`,0),h(this,`_change$`,new n.Subject),h(this,`change$`,this._change$),h(this,`_imageSourceCache`,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(!o.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>a()){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;if(a==null){r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}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)}},k=class extends t.Disposable{constructor(...e){super(...e),h(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()}};function A(e,t){return function(n,r){t(n,r,e)}}function j(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 M=class extends t.Plugin{constructor(e=d,n,r,a){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=a;let{...o}=(0,t.merge)({},d,this._config);this._configService.setConfig(`drawing.config`,o),o.allowImageSize!==void 0&&i(o.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:O}],[t.IURLImageService,{useClass:k}],[s,{useClass:D}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[c].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};h(M,`pluginName`,`UNIVER_DRAWING_PLUGIN`),h(M,`packageName`,l),h(M,`version`,u),M=j([A(1,(0,t.Inject)(t.Injector)),A(2,t.IConfigService),A(3,t.ICommandService)],M);let N=`univer.drawing.copy-plan`;function P(e){return JSON.parse(JSON.stringify(e))}function F(e,t,n){let r=P(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 I(e,n){let{generateId:r=()=>(0,t.generateRandomId)(10)}=n,i=new Map;return e.forEach(e=>{i.has(e.drawingId)||i.set(e.drawingId,r())}),{idMap:i,drawings:e.map(e=>F(e,i,n))}}function L(e,n,r){if(e==null)return I(n,r);let i=e.get(N);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=>F(e,i.idMap,r)),...s],i}let a=I(n,r);return e.set(N,a),a}let R=[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 z(e){return R.includes(e)}function B({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let V=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 H(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function U(e,n={},r=new Set){var i,a,o;let s=H(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=>U(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=N,e.DRAWING_GROUPABLE_TYPES=R,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=o,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=D,e.IDrawingManagerService=s,e.ImageIoService=O,e.SetDrawingSelectedOperation=c,e.URLImageService=k,e.UnitDrawingService=E,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return M}}),e.createDrawingCopyPlan=I,e.getDrawingImageAllowSize=a,e.getDrawingShapeKeyByDrawingSearch=B,e.getImageSize=V,e.getOrCreateDrawingCopyPlan=L,e.isGroupableDrawingType=z,e.resolveDrawingRotateEnabled=U});
|
|
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`});let r=5242880;function i(e){r=e}function a(){return r}let o=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],s=(0,t.createIdentifier)(`univer.drawing-manager.service`),c={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(s);return t!=null&&(n.focusDrawing(t),!0)}};var l=`@univerjs/drawing`,u=`1.1.0`;let d={};function f(e){"@babel/helpers - typeof";return f=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},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e){return Array.isArray(e)&&e.length>0}function _(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)=>_(e,t[n]));if(!v(e)||!v(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)&&_(e[n],t[n]))}function v(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function y(e){return Object.getOwnPropertyNames(e).every(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function b(e,n){return t.JSON1.type.writeCursor().writeAtPath(e,`r`,n).get()}function x(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=>x(e)??null);if(!v(e))return;let t={};return Object.entries(e).forEach(([e,n])=>{let r=x(n);r!==void 0&&(t[e]=r)}),t}function S(e,n,r,i,a){let o=x(i),s=x(r),c=a&&o!==void 0;if(c&&_(o,s))return;if(c&&v(i)&&v(r)&&y(i)&&y(r)){for(let t of/* @__PURE__ */ new Set([...Object.keys(i),...Object.keys(r)]))S(e,[...n,t],r[t],i[t],Object.prototype.hasOwnProperty.call(i,t)&&i[t]!==void 0);return}let l=c?s===void 0?b(n,o):t.JSON1.replaceOp(n,o,s):s===void 0?null:t.JSON1.insertOp(n,s);l&&g(l)&&e.push(l)}function C(...e){for(let t of e)if(t===`__proto__`||t===`constructor`||t===`prototype`)throw Error(`Invalid drawing key`)}function w(e,t){return e!=null&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function T(e){for(let t of Object.keys(e)){C(t);let n=e[t];n!=null&&n.data&&Object.keys(n.data).forEach(e=>C(e)),n!=null&&n.order&&n.order.forEach(e=>C(e))}}var E=class{constructor(){h(this,`drawingManagerData`,{}),h(this,`_oldDrawingManagerData`,{}),h(this,`_focusDrawings`,[]),h(this,`_remove$`,new n.Subject),h(this,`remove$`,this._remove$.asObservable()),h(this,`_add$`,new n.Subject),h(this,`add$`,this._add$.asObservable()),h(this,`_update$`,new n.Subject),h(this,`update$`,this._update$.asObservable()),h(this,`_order$`,new n.Subject),h(this,`order$`,this._order$.asObservable()),h(this,`_group$`,new n.Subject),h(this,`group$`,this._group$.asObservable()),h(this,`_ungroup$`,new n.Subject),h(this,`ungroup$`,this._ungroup$.asObservable()),h(this,`_refreshTransform$`,new n.Subject),h(this,`refreshTransform$`,this._refreshTransform$.asObservable()),h(this,`_visible$`,new n.Subject),h(this,`visible$`,this._visible$.asObservable()),h(this,`_focus$`,new n.Subject),h(this,`focus$`,this._focus$.asObservable()),h(this,`_featurePluginUpdate$`,new n.Subject),h(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),h(this,`_featurePluginAdd$`,new n.Subject),h(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),h(this,`_featurePluginRemove$`,new n.Subject),h(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),h(this,`_featurePluginOrderUpdate$`,new n.Subject),h(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),h(this,`_featurePluginGroupUpdate$`,new n.Subject),h(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),h(this,`_featurePluginUngroupUpdate$`,new n.Subject),h(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),h(this,`_visible`,!0),h(this,`_editable`,!0)}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){e.forEach(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,Object.prototype.hasOwnProperty.call(e,`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))}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return w(this.drawingManagerData,e)||{}}removeDrawingDataForUnit(e){let t=w(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){C(e),T(t),this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=w(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){C(e,t),Object.keys(n).forEach(e=>C(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);g(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){C(e,n),t.JSON1.type.checkValidOp(r);let i=w(this.drawingManagerData,e),a={...this.drawingManagerData,[e]:{...i,[n]:w(i,n)??{data:{},order:[]}}},o=t.JSON1.type.apply(a,r);for(let e of Object.keys(o))C(e),T(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){C(e,t),n.forEach(e=>C(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 w((t=w(w(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 w((t=w(w(this._oldDrawingManagerData,n),r))==null?void 0:t.data,i)}_establishDrawingMap(e,t,n){return C(e,t),n!=null&&C(n),w(this.drawingManagerData,e)||(this.drawingManagerData[e]={}),w(this.drawingManagerData[e],t)||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:w(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];S(a,[n,r,`data`,i,o],s,l,c)}),a}_getDrawingData(e,t){var n;return((n=w(w(this.drawingManagerData,e),t))==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=w(w(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}},D=class extends E{},O=class{constructor(){h(this,`_waitCount`,0),h(this,`_change$`,new n.Subject),h(this,`change$`,this._change$),h(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(!o.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>a()){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)}},k=class extends t.Disposable{constructor(...e){super(...e),h(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()}};function A(e,t){return function(n,r){t(n,r,e)}}function j(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 M=class extends t.Plugin{constructor(e=d,n,r,a){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=a;let{...o}=(0,t.merge)({},d,this._config);this._configService.setConfig(`drawing.config`,o),o.allowImageSize!==void 0&&i(o.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:O}],[t.IURLImageService,{useClass:k}],[s,{useClass:D}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[c].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};h(M,`pluginName`,`UNIVER_DRAWING_PLUGIN`),h(M,`packageName`,l),h(M,`version`,u),M=j([A(1,(0,t.Inject)(t.Injector)),A(2,t.IConfigService),A(3,t.ICommandService)],M);let N=`univer.drawing.copy-plan`;function P(e){return JSON.parse(JSON.stringify(e))}function F(e,t,n){let r=P(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 I(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=>F(e,i,n))}}function L(e,n,r){if(e==null)return I(n,r);let i=e.get(N);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=>F(e,i.idMap,r)),...s],i}let a=I(n,r);return e.set(N,a),a}let R=[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 z(e){return R.includes(e)}function B({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let V=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 H(e){return e===void 0||!Number.isFinite(e)?1:Math.min(Math.max(e,0),1)}function U(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function W(e,n={},r=/* @__PURE__ */ new Set){var i,a,o;let s=U(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=>W(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=N,e.DRAWING_GROUPABLE_TYPES=R,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=o,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=D,e.IDrawingManagerService=s,e.ImageIoService=O,e.SetDrawingSelectedOperation=c,e.URLImageService=k,e.UnitDrawingService=E,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return M}}),e.createDrawingCopyPlan=I,e.getDrawingImageAllowSize=a,e.getDrawingShapeKeyByDrawingSearch=B,e.getImageSize=V,e.getOrCreateDrawingCopyPlan=L,e.isGroupableDrawingType=z,e.normalizeImageOpacity=H,e.resolveDrawingRotateEnabled=W});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared drawing models, commands, and services for Univer.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"rxjs": ">=7.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@univerjs/core": "1.0
|
|
55
|
+
"@univerjs/core": "1.1.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@univerjs-infra/shared": "1.0
|
|
58
|
+
"@univerjs-infra/shared": "1.1.0",
|
|
59
59
|
"rxjs": "^7.8.2",
|
|
60
60
|
"typescript": "^6.0.3",
|
|
61
|
-
"vitest": "^5.0.
|
|
61
|
+
"vitest": "^5.0.4"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"test": "vitest run",
|