@fileverse-dev/fortune-core 1.1.10 → 1.1.11-patch-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ declare class CellFadeAnimator {
2
+ private durationMs;
3
+ private active;
4
+ private animationFrameId;
5
+ private onTick;
6
+ constructor(durationMs?: number);
7
+ markChanged(sheetId: string, r: number, c: number): void;
8
+ getOpacity(sheetId: string, r: number, c: number): number;
9
+ setOnTick(repaintFn: (() => void) | null): void;
10
+ private ensureTicking;
11
+ }
12
+ export declare const cellFadeAnimator: CellFadeAnimator;
13
+ export declare function markCellChanged(sheetId: string, r: number, c: number): void;
14
+ export {};
package/es/animate.js ADDED
@@ -0,0 +1,53 @@
1
+ var CellFadeAnimator = function () {
2
+ function CellFadeAnimator(durationMs) {
3
+ if (durationMs === void 0) {
4
+ durationMs = 350;
5
+ }
6
+ this.durationMs = durationMs;
7
+ this.active = new Map();
8
+ this.animationFrameId = null;
9
+ this.onTick = null;
10
+ this.durationMs = durationMs;
11
+ }
12
+ CellFadeAnimator.prototype.markChanged = function (sheetId, r, c) {
13
+ this.active.set("".concat(sheetId, ":").concat(r, ":").concat(c), {
14
+ start: performance.now(),
15
+ dur: this.durationMs
16
+ });
17
+ this.ensureTicking();
18
+ };
19
+ CellFadeAnimator.prototype.getOpacity = function (sheetId, r, c) {
20
+ var activeCellAnimationData = this.active.get("".concat(sheetId, ":").concat(r, ":").concat(c));
21
+ if (!activeCellAnimationData) return 1;
22
+ var animationProgress = Math.min(1, (performance.now() - activeCellAnimationData.start) / activeCellAnimationData.dur);
23
+ if (animationProgress >= 1) {
24
+ this.active.delete("".concat(sheetId, ":").concat(r, ":").concat(c));
25
+ return 1;
26
+ }
27
+ return Math.max(0.05, 1 - Math.pow(1 - animationProgress, 3));
28
+ };
29
+ CellFadeAnimator.prototype.setOnTick = function (repaintFn) {
30
+ this.onTick = repaintFn;
31
+ this.ensureTicking();
32
+ };
33
+ CellFadeAnimator.prototype.ensureTicking = function () {
34
+ var _this = this;
35
+ if (this.animationFrameId !== null) return;
36
+ if (this.active.size === 0) return;
37
+ var _loop = function loop() {
38
+ var _a;
39
+ _this.animationFrameId = null;
40
+ if (_this.active.size === 0) {
41
+ return;
42
+ }
43
+ (_a = _this.onTick) === null || _a === void 0 ? void 0 : _a.call(_this);
44
+ _this.animationFrameId = requestAnimationFrame(_loop);
45
+ };
46
+ this.animationFrameId = requestAnimationFrame(_loop);
47
+ };
48
+ return CellFadeAnimator;
49
+ }();
50
+ export var cellFadeAnimator = new CellFadeAnimator(4000);
51
+ export function markCellChanged(sheetId, r, c) {
52
+ cellFadeAnimator.markChanged(sheetId, r, c);
53
+ }
@@ -68,4 +68,5 @@ export declare function getSheetWithLatestCelldata(ctx: Context, options?: Commo
68
68
  column_focus: number;
69
69
  } | undefined;
70
70
  } | undefined;
71
+ liveQueryList?: Record<string, import("../types").LiveQueryData> | undefined;
71
72
  };
package/es/canvas.js CHANGED
@@ -6,6 +6,7 @@ import { isInlineStringCell } from "./modules/inline-string";
6
6
  import { getSheetIndex, indexToColumnChar } from "./utils";
7
7
  import { getBorderInfoComputeRange } from "./modules/border";
8
8
  import { checkCF, getComputeMap, validateCellData } from "./modules";
9
+ import { cellFadeAnimator } from "./animate";
9
10
  export var defaultStyle = {
10
11
  fillStyle: "#000000",
11
12
  textBaseline: "middle",
@@ -760,7 +761,16 @@ var Canvas = function () {
760
761
  var horizonAlignPos = startX + 4 + offsetLeft;
761
762
  var verticalAlignPos = endY + offsetTop - 2;
762
763
  renderCtx.textBaseline = "bottom";
763
- renderCtx.fillText(_.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
764
+ var sheetId = this.sheetCtx.currentSheetId;
765
+ var opacity = cellFadeAnimator.getOpacity(sheetId, r, c);
766
+ if (opacity < 0.999) {
767
+ renderCtx.save();
768
+ renderCtx.globalAlpha = opacity;
769
+ renderCtx.fillText(_.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
770
+ renderCtx.restore();
771
+ } else {
772
+ renderCtx.fillText(_.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
773
+ }
764
774
  }
765
775
  if ((_d = (_c = flowdata === null || flowdata === void 0 ? void 0 : flowdata[r]) === null || _c === void 0 ? void 0 : _c[c]) === null || _d === void 0 ? void 0 : _d.ps) {
766
776
  var ps_w = 12 * this.sheetCtx.zoomRatio;
@@ -1065,10 +1075,22 @@ var Canvas = function () {
1065
1075
  if (((_j = (_h = (_g = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _g === void 0 ? void 0 : _g.fa) === null || _h === void 0 ? void 0 : _h.indexOf("[Red]")) !== null && _j !== void 0 ? _j : -1) > -1 && ((_k = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _k === void 0 ? void 0 : _k.t) === "n" && (cell === null || cell === void 0 ? void 0 : cell.v) < 0) {
1066
1076
  renderCtx.fillStyle = "#ff0000";
1067
1077
  }
1068
- this.cellTextRender(textInfo, renderCtx, {
1069
- pos_x: pos_x,
1070
- pos_y: pos_y
1071
- });
1078
+ var sheetId = this.sheetCtx.currentSheetId;
1079
+ var opacity = cellFadeAnimator.getOpacity(sheetId, r, c);
1080
+ if (opacity < 0.999) {
1081
+ renderCtx.save();
1082
+ renderCtx.globalAlpha = opacity;
1083
+ this.cellTextRender(textInfo, renderCtx, {
1084
+ pos_x: pos_x,
1085
+ pos_y: pos_y
1086
+ });
1087
+ renderCtx.restore();
1088
+ } else {
1089
+ this.cellTextRender(textInfo, renderCtx, {
1090
+ pos_x: pos_x,
1091
+ pos_y: pos_y
1092
+ });
1093
+ }
1072
1094
  renderCtx.restore();
1073
1095
  }
1074
1096
  if (cellOverflow_bd_r_render) {
@@ -1150,10 +1172,22 @@ var Canvas = function () {
1150
1172
  if (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor) {
1151
1173
  renderCtx.fillStyle = checksCF.textColor;
1152
1174
  }
1153
- this.cellTextRender(textInfo, renderCtx, {
1154
- pos_x: pos_x,
1155
- pos_y: pos_y
1156
- });
1175
+ var sheetId = this.sheetCtx.currentSheetId;
1176
+ var opacity = cellFadeAnimator.getOpacity(sheetId, r, c);
1177
+ if (opacity < 0.999) {
1178
+ renderCtx.save();
1179
+ renderCtx.globalAlpha = opacity;
1180
+ this.cellTextRender(textInfo, renderCtx, {
1181
+ pos_x: pos_x,
1182
+ pos_y: pos_y
1183
+ });
1184
+ renderCtx.restore();
1185
+ } else {
1186
+ this.cellTextRender(textInfo, renderCtx, {
1187
+ pos_x: pos_x,
1188
+ pos_y: pos_y
1189
+ });
1190
+ }
1157
1191
  renderCtx.restore();
1158
1192
  };
1159
1193
  Canvas.prototype.cellOverflow_trace = function (r, curC, traceC, traceDir, horizonAlign, textMetrics) {