@univerjs/sheets-conditional-formatting 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/lib/cjs/facade.js +9 -9
- package/lib/cjs/index.js +237 -49
- package/lib/es/facade.js +9 -9
- package/lib/es/index.js +238 -50
- package/lib/facade.js +9 -9
- package/lib/index.js +238 -50
- package/lib/types/render/conditional-formatting-raster-cache.d.ts +24 -0
- package/lib/types/render/data-bar.render.d.ts +4 -1
- package/lib/types/render/icon.render.d.ts +5 -1
- package/lib/types/render/resolve-render-ranges.d.ts +18 -0
- package/lib/types/services/conditional-formatting-range-transform.service.d.ts +7 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
## Package Overview
|
|
10
10
|
|
|
11
|
-
| Package | UMD global | CSS | Locales | Facade entry |
|
|
12
|
-
| --- | --- | :---: | :---: | :---: |
|
|
13
|
-
| `@univerjs/sheets-conditional-formatting` | `UniverSheetsConditionalFormatting` | No | Yes | Yes |
|
|
11
|
+
| Package | UMD global | CSS | Locales | Facade entry | Worker entry |
|
|
12
|
+
| --- | --- | :---: | :---: | :---: | :---: |
|
|
13
|
+
| `@univerjs/sheets-conditional-formatting` | `UniverSheetsConditionalFormatting` | No | Yes | Yes | No |
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -20,10 +20,10 @@ pnpm add @univerjs/sheets-conditional-formatting
|
|
|
20
20
|
npm install @univerjs/sheets-conditional-formatting
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Keep all `@univerjs/*` packages on the same version.
|
|
24
|
-
|
|
25
23
|
## Usage
|
|
26
24
|
|
|
25
|
+
Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
|
|
26
|
+
|
|
27
27
|
```ts
|
|
28
28
|
import { LocaleType, mergeLocales, Univer } from '@univerjs/core';
|
|
29
29
|
import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
|
|
@@ -42,6 +42,7 @@ univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);
|
|
|
42
42
|
## Integration Notes
|
|
43
43
|
|
|
44
44
|
Use this package with `@univerjs/sheets-conditional-formatting-ui` when users need menus and rule-management panels.
|
|
45
|
+
- Import `@univerjs/sheets-conditional-formatting/facade` when using this package through Univer Facade APIs.
|
|
45
46
|
|
|
46
47
|
## Resources
|
|
47
48
|
|
package/lib/cjs/facade.js
CHANGED
|
@@ -4,7 +4,7 @@ let _univerjs_sheets_conditional_formatting = require("@univerjs/sheets-conditio
|
|
|
4
4
|
let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
|
|
5
5
|
let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
6
6
|
|
|
7
|
-
// \0@oxc-project+runtime@0.
|
|
7
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
8
8
|
function _typeof(o) {
|
|
9
9
|
"@babel/helpers - typeof";
|
|
10
10
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -14,25 +14,25 @@ function _typeof(o) {
|
|
|
14
14
|
}, _typeof(o);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// \0@oxc-project+runtime@0.
|
|
18
|
-
function toPrimitive(t,
|
|
17
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
18
|
+
function toPrimitive(t, e) {
|
|
19
19
|
if ("object" != _typeof(t) || !t) return t;
|
|
20
|
-
var
|
|
21
|
-
if (void 0 !==
|
|
22
|
-
var i =
|
|
20
|
+
var r;
|
|
21
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
22
|
+
var i = r.call(t, e || "default");
|
|
23
23
|
if ("object" != _typeof(i)) return i;
|
|
24
24
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
25
25
|
}
|
|
26
|
-
return ("string" ===
|
|
26
|
+
return ("string" === e ? String : Number)(t);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// \0@oxc-project+runtime@0.
|
|
29
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
30
30
|
function toPropertyKey(t) {
|
|
31
31
|
var i = toPrimitive(t, "string");
|
|
32
32
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
// \0@oxc-project+runtime@0.
|
|
35
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
36
36
|
function _defineProperty(e, r, t) {
|
|
37
37
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
38
|
value: t,
|
package/lib/cjs/index.js
CHANGED
|
@@ -216,7 +216,7 @@ const isAnchorEqual = (anchor1, anchor2) => {
|
|
|
216
216
|
*/
|
|
217
217
|
const createCfId = () => `${(0, _univerjs_core.generateRandomId)(8)}`;
|
|
218
218
|
|
|
219
|
-
// \0@oxc-project+runtime@0.
|
|
219
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
220
220
|
function _typeof(o) {
|
|
221
221
|
"@babel/helpers - typeof";
|
|
222
222
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -226,25 +226,25 @@ function _typeof(o) {
|
|
|
226
226
|
}, _typeof(o);
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
// \0@oxc-project+runtime@0.
|
|
230
|
-
function toPrimitive(t,
|
|
229
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
230
|
+
function toPrimitive(t, e) {
|
|
231
231
|
if ("object" != _typeof(t) || !t) return t;
|
|
232
|
-
var
|
|
233
|
-
if (void 0 !==
|
|
234
|
-
var i =
|
|
232
|
+
var r;
|
|
233
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
234
|
+
var i = r.call(t, e || "default");
|
|
235
235
|
if ("object" != _typeof(i)) return i;
|
|
236
236
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
237
237
|
}
|
|
238
|
-
return ("string" ===
|
|
238
|
+
return ("string" === e ? String : Number)(t);
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
// \0@oxc-project+runtime@0.
|
|
241
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
242
242
|
function toPropertyKey(t) {
|
|
243
243
|
var i = toPrimitive(t, "string");
|
|
244
244
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
// \0@oxc-project+runtime@0.
|
|
247
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
248
248
|
function _defineProperty(e, r, t) {
|
|
249
249
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
250
250
|
value: t,
|
|
@@ -500,14 +500,14 @@ const AddCfCommand = {
|
|
|
500
500
|
}
|
|
501
501
|
};
|
|
502
502
|
|
|
503
|
-
// \0@oxc-project+runtime@0.
|
|
503
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
504
504
|
function __decorateParam(paramIndex, decorator) {
|
|
505
505
|
return function(target, key) {
|
|
506
506
|
decorator(target, key, paramIndex);
|
|
507
507
|
};
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
// \0@oxc-project+runtime@0.
|
|
510
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
511
511
|
function __decorate(decorators, target, key, desc) {
|
|
512
512
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
513
513
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -604,14 +604,15 @@ ConditionalFormattingRangeIndexModel = __decorate([__decorateParam(0, (0, _unive
|
|
|
604
604
|
// src/services/conditional-formatting-range-transform.service.ts
|
|
605
605
|
var ConditionalFormattingRangeTransformService = class {
|
|
606
606
|
subtractRanges(sourceRanges, rangesToSubtract) {
|
|
607
|
-
return _univerjs_core.Rectangle.mergeRanges(_univerjs_core.Rectangle.subtractMulti(sourceRanges, rangesToSubtract));
|
|
607
|
+
return this._keepCoveredRangeType(_univerjs_core.Rectangle.mergeRanges(_univerjs_core.Rectangle.subtractMulti(sourceRanges, rangesToSubtract)), sourceRanges);
|
|
608
608
|
}
|
|
609
609
|
addRanges(sourceRanges, rangesToAdd) {
|
|
610
|
-
return _univerjs_core.Rectangle.mergeRanges([...sourceRanges, ...rangesToAdd]);
|
|
610
|
+
return this._keepCoveredRangeType(_univerjs_core.Rectangle.mergeRanges([...sourceRanges, ...rangesToAdd]), sourceRanges);
|
|
611
611
|
}
|
|
612
612
|
applyRangeDelta(sourceRanges, rangesToSubtract, rangesToAdd) {
|
|
613
|
-
const ranges = rangesToSubtract.length ?
|
|
614
|
-
|
|
613
|
+
const ranges = rangesToSubtract.length ? _univerjs_core.Rectangle.mergeRanges(_univerjs_core.Rectangle.subtractMulti(sourceRanges, rangesToSubtract)) : sourceRanges;
|
|
614
|
+
const merged = rangesToAdd.length ? _univerjs_core.Rectangle.mergeRanges([...ranges, ...rangesToAdd]) : ranges;
|
|
615
|
+
return this._keepCoveredRangeType(merged, sourceRanges);
|
|
615
616
|
}
|
|
616
617
|
copyIntersectingRanges(sourceRanges, sourceRange, targetAnchor) {
|
|
617
618
|
const fragments = [];
|
|
@@ -633,6 +634,21 @@ var ConditionalFormattingRangeTransformService = class {
|
|
|
633
634
|
endColumn: range.endColumn + offset.col
|
|
634
635
|
};
|
|
635
636
|
}
|
|
637
|
+
/**
|
|
638
|
+
* Rebuilding ranges from coordinates drops `rangeType`. A result range that still covers exactly
|
|
639
|
+
* the same cells as a whole column/row source has to keep that type, otherwise a rule that was
|
|
640
|
+
* not actually changed (for example adding an already covered range) degrades to concrete rows.
|
|
641
|
+
* Results that no longer match a source range are genuine partial coverage and stay concrete.
|
|
642
|
+
*/
|
|
643
|
+
_keepCoveredRangeType(ranges, sourceRanges) {
|
|
644
|
+
return ranges.map((range) => {
|
|
645
|
+
const source = sourceRanges.find((item) => item.rangeType && item.startRow === range.startRow && item.endRow === range.endRow && item.startColumn === range.startColumn && item.endColumn === range.endColumn);
|
|
646
|
+
return source ? {
|
|
647
|
+
...range,
|
|
648
|
+
rangeType: source.rangeType
|
|
649
|
+
} : range;
|
|
650
|
+
});
|
|
651
|
+
}
|
|
636
652
|
};
|
|
637
653
|
|
|
638
654
|
// src/commands/mutations/set-conditional-rule.mutation.ts
|
|
@@ -1200,6 +1216,154 @@ var ColorScaleCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1200
1216
|
}
|
|
1201
1217
|
};
|
|
1202
1218
|
|
|
1219
|
+
// src/render/conditional-formatting-raster-cache.ts
|
|
1220
|
+
/**
|
|
1221
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1222
|
+
*
|
|
1223
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1224
|
+
* you may not use this file except in compliance with the License.
|
|
1225
|
+
* You may obtain a copy of the License at
|
|
1226
|
+
*
|
|
1227
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1228
|
+
*
|
|
1229
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1230
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1231
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1232
|
+
* See the License for the specific language governing permissions and
|
|
1233
|
+
* limitations under the License.
|
|
1234
|
+
*/
|
|
1235
|
+
const MAX_ENTRIES = 128;
|
|
1236
|
+
const MAX_PIXELS = 524288;
|
|
1237
|
+
const MAX_BITMAP_PIXELS = 131072;
|
|
1238
|
+
/** Retain physical pixels without mutating image sources already submitted to the destination. */
|
|
1239
|
+
var ConditionalFormattingRasterCache = class extends _univerjs_core.Disposable {
|
|
1240
|
+
constructor(..._args) {
|
|
1241
|
+
super(..._args);
|
|
1242
|
+
_defineProperty(this, "_bitmaps", /* @__PURE__ */ new Map());
|
|
1243
|
+
_defineProperty(this, "_pixels", 0);
|
|
1244
|
+
}
|
|
1245
|
+
draw(ctx, x, y, width, height, variant, draw, strokeWidth = 0) {
|
|
1246
|
+
var _native$getContextAtt;
|
|
1247
|
+
this.ensureNotDisposed();
|
|
1248
|
+
const native = ctx._context;
|
|
1249
|
+
const m = native === null || native === void 0 ? void 0 : native.getTransform();
|
|
1250
|
+
const colorSpace = native === null || native === void 0 || (_native$getContextAtt = native.getContextAttributes) === null || _native$getContextAtt === void 0 || (_native$getContextAtt = _native$getContextAtt.call(native)) === null || _native$getContextAtt === void 0 ? void 0 : _native$getContextAtt.colorSpace;
|
|
1251
|
+
if (!m || ctx.__mode === "printing" || typeof document === "undefined" || m.a !== m.d || m.a <= 0 || m.b || m.c || native.globalAlpha !== 1 || native.globalCompositeOperation !== "source-over" || colorSpace && colorSpace !== "srgb" || native.shadowBlur || native.shadowOffsetX || native.shadowOffsetY || ![
|
|
1252
|
+
"rgba(0, 0, 0, 0)",
|
|
1253
|
+
"transparent",
|
|
1254
|
+
"#00000000"
|
|
1255
|
+
].includes(native.shadowColor) || native.filter && native.filter !== "none" || width <= 0 || height <= 0 || typeof native.fillStyle !== "string" || typeof native.strokeStyle !== "string") {
|
|
1256
|
+
draw(ctx, x, y);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
const px = x * m.a + m.e;
|
|
1260
|
+
const py = y * m.d + m.f;
|
|
1261
|
+
const padding = Math.max(2, Math.ceil(strokeWidth * m.a / 2) + 1);
|
|
1262
|
+
const left = Math.floor(px) - padding;
|
|
1263
|
+
const top = Math.floor(py) - padding;
|
|
1264
|
+
const pixelWidth = Math.ceil(px + width * m.a) - left + padding;
|
|
1265
|
+
const pixelHeight = Math.ceil(py + height * m.d) - top + padding;
|
|
1266
|
+
const pixels = pixelWidth * pixelHeight;
|
|
1267
|
+
if (!Number.isFinite(pixels) || pixels > MAX_BITMAP_PIXELS) {
|
|
1268
|
+
draw(ctx, x, y);
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
const localX = px - left;
|
|
1272
|
+
const localY = py - top;
|
|
1273
|
+
const dash = native.getLineDash();
|
|
1274
|
+
const key = JSON.stringify([
|
|
1275
|
+
variant,
|
|
1276
|
+
width,
|
|
1277
|
+
height,
|
|
1278
|
+
m.a,
|
|
1279
|
+
localX,
|
|
1280
|
+
localY,
|
|
1281
|
+
strokeWidth,
|
|
1282
|
+
native.fillStyle,
|
|
1283
|
+
native.strokeStyle,
|
|
1284
|
+
dash,
|
|
1285
|
+
native.lineDashOffset,
|
|
1286
|
+
native.lineCap,
|
|
1287
|
+
native.lineJoin,
|
|
1288
|
+
native.miterLimit,
|
|
1289
|
+
native.imageSmoothingEnabled,
|
|
1290
|
+
native.imageSmoothingQuality
|
|
1291
|
+
]);
|
|
1292
|
+
let bitmap = this._bitmaps.get(key);
|
|
1293
|
+
if (!bitmap) {
|
|
1294
|
+
const canvas = document.createElement("canvas");
|
|
1295
|
+
canvas.width = pixelWidth;
|
|
1296
|
+
canvas.height = pixelHeight;
|
|
1297
|
+
const context = canvas.getContext("2d");
|
|
1298
|
+
if (!context) {
|
|
1299
|
+
draw(ctx, x, y);
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
const paint = new _univerjs_engine_render.UniverRenderingContext(context);
|
|
1303
|
+
paint.setTransform(m.a, 0, 0, m.d, localX, localY);
|
|
1304
|
+
paint.setLineDash(dash);
|
|
1305
|
+
paint.lineDashOffset = native.lineDashOffset;
|
|
1306
|
+
paint.lineCap = native.lineCap;
|
|
1307
|
+
paint.lineJoin = native.lineJoin;
|
|
1308
|
+
paint.miterLimit = native.miterLimit;
|
|
1309
|
+
paint.imageSmoothingEnabled = native.imageSmoothingEnabled;
|
|
1310
|
+
paint.imageSmoothingQuality = native.imageSmoothingQuality;
|
|
1311
|
+
draw(paint, 0, 0);
|
|
1312
|
+
while (this._bitmaps.size >= MAX_ENTRIES || this._pixels + pixels > MAX_PIXELS) {
|
|
1313
|
+
const oldestKey = this._bitmaps.keys().next().value;
|
|
1314
|
+
if (oldestKey === void 0) break;
|
|
1315
|
+
this._pixels -= this._bitmaps.get(oldestKey).pixels;
|
|
1316
|
+
this._bitmaps.delete(oldestKey);
|
|
1317
|
+
}
|
|
1318
|
+
bitmap = {
|
|
1319
|
+
canvas,
|
|
1320
|
+
pixels
|
|
1321
|
+
};
|
|
1322
|
+
this._bitmaps.set(key, bitmap);
|
|
1323
|
+
this._pixels += pixels;
|
|
1324
|
+
}
|
|
1325
|
+
ctx.save();
|
|
1326
|
+
try {
|
|
1327
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1328
|
+
ctx.imageSmoothingEnabled = false;
|
|
1329
|
+
ctx.drawImage(bitmap.canvas, left, top);
|
|
1330
|
+
} finally {
|
|
1331
|
+
ctx.restore();
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
dispose() {
|
|
1335
|
+
for (const { canvas } of this._bitmaps.values()) {
|
|
1336
|
+
canvas.width = 0;
|
|
1337
|
+
canvas.height = 0;
|
|
1338
|
+
}
|
|
1339
|
+
this._bitmaps.clear();
|
|
1340
|
+
this._pixels = 0;
|
|
1341
|
+
super.dispose();
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
// src/render/resolve-render-ranges.ts
|
|
1346
|
+
function resolveRenderRanges(worksheet, sourceRanges, resolver) {
|
|
1347
|
+
if (!resolver) return sourceRanges;
|
|
1348
|
+
const mergedRanges = worksheet.getMergeData().length ? sourceRanges.flatMap((range) => worksheet.getMergedCellRange(range.startRow, range.startColumn, range.endRow, range.endColumn)) : [];
|
|
1349
|
+
const queryRanges = mergedRanges.length ? [...sourceRanges, ...mergedRanges.map((range) => ({
|
|
1350
|
+
startRow: range.startRow,
|
|
1351
|
+
endRow: range.startRow,
|
|
1352
|
+
startColumn: range.startColumn,
|
|
1353
|
+
endColumn: range.startColumn
|
|
1354
|
+
}))] : sourceRanges;
|
|
1355
|
+
const resolved = resolver(worksheet.getUnitId(), worksheet.getSheetId(), queryRanges);
|
|
1356
|
+
if (!resolved) return sourceRanges;
|
|
1357
|
+
if (!mergedRanges.length || !resolved.length) return resolved;
|
|
1358
|
+
const formattedMerges = mergedRanges.filter((merge) => resolved.some((range) => _univerjs_core.Rectangle.intersects(merge, range)));
|
|
1359
|
+
const clipped = [];
|
|
1360
|
+
for (const source of sourceRanges) for (const range of [...resolved, ...formattedMerges]) {
|
|
1361
|
+
const intersection = (0, _univerjs_core.getIntersectRange)(source, range);
|
|
1362
|
+
if (intersection) clipped.push(intersection);
|
|
1363
|
+
}
|
|
1364
|
+
return clipped.length > 1 ? _univerjs_core.Rectangle.mergeRanges(clipped) : clipped;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1203
1367
|
// src/render/data-bar.render.ts
|
|
1204
1368
|
const dataBarUKey = "sheet-conditional-rule-data-bar";
|
|
1205
1369
|
const defaultDataBarPositiveColor = "#ffbe38";
|
|
@@ -1210,11 +1374,13 @@ const stringifyRange$1 = (range) => {
|
|
|
1210
1374
|
const { startRow, endRow, startColumn, endColumn } = range;
|
|
1211
1375
|
return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
|
|
1212
1376
|
};
|
|
1213
|
-
var DataBar = class extends _univerjs_engine_render.SheetExtension {
|
|
1377
|
+
var DataBar = class DataBar extends _univerjs_engine_render.SheetExtension {
|
|
1214
1378
|
constructor(..._args) {
|
|
1215
1379
|
super(..._args);
|
|
1380
|
+
_defineProperty(this, "viewportCacheReusable", this.constructor === DataBar);
|
|
1216
1381
|
_defineProperty(this, "_paddingRightAndLeft", 2);
|
|
1217
1382
|
_defineProperty(this, "_paddingTopAndBottom", 2);
|
|
1383
|
+
_defineProperty(this, "_rasterCache", new ConditionalFormattingRasterCache());
|
|
1218
1384
|
_defineProperty(this, "_renderRangeResolver", null);
|
|
1219
1385
|
_defineProperty(this, "uKey", dataBarUKey);
|
|
1220
1386
|
_defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
|
|
@@ -1228,7 +1394,7 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
|
|
|
1228
1394
|
if (!worksheet) return false;
|
|
1229
1395
|
const mergeCellRendered = /* @__PURE__ */ new Set();
|
|
1230
1396
|
const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
|
|
1231
|
-
const renderRanges =
|
|
1397
|
+
const renderRanges = resolveRenderRanges(worksheet, sourceRanges, this._renderRangeResolver);
|
|
1232
1398
|
if (!renderRanges.length) return;
|
|
1233
1399
|
ctx.save();
|
|
1234
1400
|
renderRanges.forEach((range) => {
|
|
@@ -1251,43 +1417,42 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
|
|
|
1251
1417
|
const borderHeight = endY + _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET - startY;
|
|
1252
1418
|
const width = borderWidth - this._paddingRightAndLeft * 2;
|
|
1253
1419
|
const height = borderHeight - this._paddingTopAndBottom * 2;
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1420
|
+
const positive = value > 0;
|
|
1421
|
+
const dataBarWidth = Math.max(positive ? width * (1 - startPoint / 100) * value / 100 : width * startPoint / 100 * Math.abs(value) / 100, 1);
|
|
1422
|
+
const x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width - (positive ? 0 : dataBarWidth);
|
|
1423
|
+
const y0 = startY + this._paddingTopAndBottom;
|
|
1424
|
+
ctx.fillStyle = color;
|
|
1425
|
+
ctx.strokeStyle = color;
|
|
1426
|
+
const fillColor = ctx.fillStyle;
|
|
1427
|
+
const strokeColor = ctx.strokeStyle;
|
|
1428
|
+
this._drawAtLocalOrigin(ctx, x0, y0, dataBarWidth, height, (paint, x, y) => {
|
|
1258
1429
|
if (isGradient) {
|
|
1259
|
-
const gradient =
|
|
1260
|
-
gradient.addColorStop(0, color);
|
|
1261
|
-
gradient.addColorStop(1, "rgb(255 255 255)");
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
} else
|
|
1266
|
-
this._drawRectWithRoundedCorner(
|
|
1267
|
-
if (isGradient)
|
|
1268
|
-
}
|
|
1269
|
-
const dataBarWidth = Math.max(width * startPoint / 100 * Math.abs(value) / 100, 1);
|
|
1270
|
-
const x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width - dataBarWidth;
|
|
1271
|
-
const y0 = startY + this._paddingTopAndBottom;
|
|
1272
|
-
if (isGradient) {
|
|
1273
|
-
const gradient = ctx.createLinearGradient(x0, y0, x0 + dataBarWidth, y0);
|
|
1274
|
-
gradient.addColorStop(0, "rgb(255 255 255)");
|
|
1275
|
-
gradient.addColorStop(1, color);
|
|
1276
|
-
ctx.fillStyle = gradient;
|
|
1277
|
-
ctx.strokeStyle = color;
|
|
1278
|
-
ctx.lineWidth = 1;
|
|
1279
|
-
} else ctx.fillStyle = color;
|
|
1280
|
-
this._drawRectWithRoundedCorner(ctx, x0, y0, dataBarWidth, height, true, false, false, true);
|
|
1281
|
-
if (isGradient) ctx.stroke();
|
|
1282
|
-
}
|
|
1430
|
+
const gradient = paint.createLinearGradient(x, y, x + dataBarWidth, y);
|
|
1431
|
+
gradient.addColorStop(0, positive ? color : "rgb(255 255 255)");
|
|
1432
|
+
gradient.addColorStop(1, positive ? "rgb(255 255 255)" : color);
|
|
1433
|
+
paint.fillStyle = gradient;
|
|
1434
|
+
paint.strokeStyle = paint === ctx ? color : strokeColor;
|
|
1435
|
+
paint.lineWidth = 1;
|
|
1436
|
+
} else paint.fillStyle = paint === ctx ? color : fillColor;
|
|
1437
|
+
this._drawRectWithRoundedCorner(paint, x, y, dataBarWidth, height, !positive, positive, positive, !positive);
|
|
1438
|
+
if (isGradient) paint.stroke();
|
|
1439
|
+
}, `${positive}:${isGradient}:${this._radius}:${color}`, isGradient ? 1 : 0);
|
|
1283
1440
|
});
|
|
1284
1441
|
});
|
|
1285
1442
|
ctx.restore();
|
|
1286
1443
|
}
|
|
1287
1444
|
dispose() {
|
|
1445
|
+
this._rasterCache.dispose();
|
|
1288
1446
|
this._renderRangeResolver = null;
|
|
1289
1447
|
super.dispose();
|
|
1290
1448
|
}
|
|
1449
|
+
_drawAtLocalOrigin(ctx, x, y, width, height, draw, variant = "", strokeWidth = 0) {
|
|
1450
|
+
if (typeof navigator !== "undefined" && (ctx.getBrowserType() === "Safari" || _univerjs_core.Tools.isIPhone())) {
|
|
1451
|
+
draw(ctx, x, y);
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
this._rasterCache.draw(ctx, x, y, width, height, variant, draw, strokeWidth);
|
|
1455
|
+
}
|
|
1291
1456
|
_drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
|
|
1292
1457
|
const radius = this._radius;
|
|
1293
1458
|
if (!height || !width) return;
|
|
@@ -2544,7 +2709,7 @@ for (const key in iconMap) {
|
|
|
2544
2709
|
|
|
2545
2710
|
// package.json
|
|
2546
2711
|
var name = "@univerjs/sheets-conditional-formatting";
|
|
2547
|
-
var version = "1.
|
|
2712
|
+
var version = "1.5.0";
|
|
2548
2713
|
|
|
2549
2714
|
// src/config/config.ts
|
|
2550
2715
|
/**
|
|
@@ -2806,7 +2971,9 @@ let ConditionalFormattingService = class ConditionalFormattingService extends _u
|
|
|
2806
2971
|
};
|
|
2807
2972
|
switch (commandInfo.id) {
|
|
2808
2973
|
case _univerjs_sheets.SetRangeValuesMutation.id: {
|
|
2974
|
+
var _this$_conditionalFor;
|
|
2809
2975
|
const { subUnitId, unitId, cellValue } = commandInfo.params;
|
|
2976
|
+
if (!((_this$_conditionalFor = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId)) === null || _this$_conditionalFor === void 0 ? void 0 : _this$_conditionalFor.length)) break;
|
|
2810
2977
|
const ranges = [];
|
|
2811
2978
|
new _univerjs_core.ObjectMatrix(cellValue).forValue((row, col, value) => {
|
|
2812
2979
|
if (value && Object.keys(value).some((key) => ["p", "v"].includes(key))) ranges.push({
|
|
@@ -2976,12 +3143,15 @@ const stringifyRange = (range) => {
|
|
|
2976
3143
|
const { startRow, endRow, startColumn, endColumn } = range;
|
|
2977
3144
|
return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
|
|
2978
3145
|
};
|
|
2979
|
-
var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExtension {
|
|
3146
|
+
var ConditionalFormattingIcon = class ConditionalFormattingIcon extends _univerjs_engine_render.SheetExtension {
|
|
2980
3147
|
constructor() {
|
|
2981
3148
|
super();
|
|
3149
|
+
_defineProperty(this, "viewportCacheReusable", this.constructor === ConditionalFormattingIcon);
|
|
2982
3150
|
_defineProperty(this, "_paddingRightAndLeft", 2);
|
|
2983
3151
|
_defineProperty(this, "_width", 15);
|
|
2984
3152
|
_defineProperty(this, "_imageMap", /* @__PURE__ */ new Map());
|
|
3153
|
+
_defineProperty(this, "_rasterCache", new ConditionalFormattingRasterCache());
|
|
3154
|
+
_defineProperty(this, "_pendingImages", /* @__PURE__ */ new Set());
|
|
2985
3155
|
_defineProperty(this, "_renderRangeResolver", null);
|
|
2986
3156
|
_defineProperty(this, "uKey", IconUKey);
|
|
2987
3157
|
_defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX);
|
|
@@ -2996,7 +3166,7 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
|
|
|
2996
3166
|
if (!worksheet) return false;
|
|
2997
3167
|
const mergeCellRendered = /* @__PURE__ */ new Set();
|
|
2998
3168
|
const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
|
|
2999
|
-
const renderRanges =
|
|
3169
|
+
const renderRanges = resolveRenderRanges(worksheet, sourceRanges, this._renderRangeResolver);
|
|
3000
3170
|
if (!renderRanges.length) return;
|
|
3001
3171
|
ctx.save();
|
|
3002
3172
|
renderRanges.forEach((range) => {
|
|
@@ -3022,22 +3192,40 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
|
|
|
3022
3192
|
const borderHeight = endY - startY;
|
|
3023
3193
|
if (this._width > borderHeight || this._width > borderWidth + this._paddingRightAndLeft * 2) return;
|
|
3024
3194
|
const y = (borderHeight - this._width) / 2 + startY;
|
|
3025
|
-
|
|
3195
|
+
this._drawIcon(ctx, icon, startX + this._paddingRightAndLeft, y);
|
|
3026
3196
|
});
|
|
3027
3197
|
});
|
|
3028
3198
|
ctx.restore();
|
|
3029
3199
|
}
|
|
3030
3200
|
dispose() {
|
|
3201
|
+
this._rasterCache.dispose();
|
|
3202
|
+
for (const image of this._pendingImages) image.onload = null;
|
|
3203
|
+
this._pendingImages.clear();
|
|
3204
|
+
this._imageMap.clear();
|
|
3031
3205
|
this._renderRangeResolver = null;
|
|
3032
3206
|
super.dispose();
|
|
3033
3207
|
}
|
|
3208
|
+
_drawIcon(ctx, image, x, y) {
|
|
3209
|
+
if (!ctx._context || ctx.__mode === "printing" || ctx.getSystemType() !== "Linux") {
|
|
3210
|
+
ctx.drawImage(image, x, y, this._width, this._width);
|
|
3211
|
+
return;
|
|
3212
|
+
}
|
|
3213
|
+
this._rasterCache.draw(ctx, x, y, this._width, this._width, image.src, (paint, left, top) => {
|
|
3214
|
+
paint.drawImage(image, left, top, this._width, this._width);
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3034
3217
|
_init() {
|
|
3035
3218
|
for (const type in iconMap) iconMap[type].forEach((base64, index) => {
|
|
3036
3219
|
const key = this._createKey(type, String(index));
|
|
3037
3220
|
const image = new Image();
|
|
3038
3221
|
image.onload = () => {
|
|
3222
|
+
var _this$parent;
|
|
3223
|
+
image.onload = null;
|
|
3224
|
+
this._pendingImages.delete(image);
|
|
3039
3225
|
this._imageMap.set(key, image);
|
|
3226
|
+
(_this$parent = this.parent) === null || _this$parent === void 0 || _this$parent.makeDirty(true);
|
|
3040
3227
|
};
|
|
3228
|
+
this._pendingImages.add(image);
|
|
3041
3229
|
image.src = base64;
|
|
3042
3230
|
});
|
|
3043
3231
|
}
|
package/lib/es/facade.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AddCfCommand, CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperat
|
|
|
3
3
|
import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
4
4
|
import { FEnum } from "@univerjs/core/facade";
|
|
5
5
|
|
|
6
|
-
// \0@oxc-project+runtime@0.
|
|
6
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
7
7
|
function _typeof(o) {
|
|
8
8
|
"@babel/helpers - typeof";
|
|
9
9
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -13,25 +13,25 @@ function _typeof(o) {
|
|
|
13
13
|
}, _typeof(o);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// \0@oxc-project+runtime@0.
|
|
17
|
-
function toPrimitive(t,
|
|
16
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
17
|
+
function toPrimitive(t, e) {
|
|
18
18
|
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
-
var
|
|
20
|
-
if (void 0 !==
|
|
21
|
-
var i =
|
|
19
|
+
var r;
|
|
20
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
21
|
+
var i = r.call(t, e || "default");
|
|
22
22
|
if ("object" != _typeof(i)) return i;
|
|
23
23
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
24
|
}
|
|
25
|
-
return ("string" ===
|
|
25
|
+
return ("string" === e ? String : Number)(t);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// \0@oxc-project+runtime@0.
|
|
28
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
29
29
|
function toPropertyKey(t) {
|
|
30
30
|
var i = toPrimitive(t, "string");
|
|
31
31
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// \0@oxc-project+runtime@0.
|
|
34
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
35
35
|
function _defineProperty(e, r, t) {
|
|
36
36
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
37
37
|
value: t,
|