@fileverse-dev/fortune-core 1.1.11 → 1.1.14

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) {
@@ -879,10 +879,10 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
879
879
  }
880
880
  var funcV = execfunction(ctx, func, h, c, undefined, undefined, true);
881
881
  var afterUpdateCell = ctx.hooks.afterUpdateCell;
882
- if (afterUpdateCell && arr.length === 1) {
882
+ if (afterUpdateCell) {
883
883
  afterUpdateCell(h, c, null, __assign(__assign({}, value), {
884
- v: funcV[1],
885
- m: "[object Promise]"
884
+ v: arr.length === 1 ? funcV[1] : value.v,
885
+ m: funcV[1] instanceof Promise ? "[object Promise]" : funcV[1]
886
886
  }));
887
887
  }
888
888
  if (!_.isNil(value.spl)) {}
package/es/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./locale";
8
8
  export * from "./modules";
9
9
  export * from "./utils";
10
10
  export * from "./types";
11
+ export * from "./animate";
package/es/index.js CHANGED
@@ -7,4 +7,5 @@ export * from "./events";
7
7
  export * from "./locale";
8
8
  export * from "./modules";
9
9
  export * from "./utils";
10
- export * from "./types";
10
+ export * from "./types";
11
+ export * from "./animate";
package/es/types.d.ts CHANGED
@@ -144,6 +144,18 @@ export type ConditionRulesProps = {
144
144
  repeatValue: string;
145
145
  projectValue: string;
146
146
  };
147
+ export type LiveQueryData = {
148
+ data: {
149
+ row: number;
150
+ column: number;
151
+ function: string;
152
+ value: any;
153
+ id: string;
154
+ name: string;
155
+ subSheetId: string;
156
+ };
157
+ cellData: Cell;
158
+ };
147
159
  export type Sheet = {
148
160
  name: string;
149
161
  config?: SheetConfig;
@@ -205,6 +217,7 @@ export type Sheet = {
205
217
  column_focus: number;
206
218
  };
207
219
  };
220
+ liveQueryList?: Record<string, LiveQueryData>;
208
221
  };
209
222
  export type CommentBox = {
210
223
  r: number;
@@ -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/lib/animate.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cellFadeAnimator = void 0;
7
+ exports.markCellChanged = markCellChanged;
8
+ var CellFadeAnimator = function () {
9
+ function CellFadeAnimator(durationMs) {
10
+ if (durationMs === void 0) {
11
+ durationMs = 350;
12
+ }
13
+ this.durationMs = durationMs;
14
+ this.active = new Map();
15
+ this.animationFrameId = null;
16
+ this.onTick = null;
17
+ this.durationMs = durationMs;
18
+ }
19
+ CellFadeAnimator.prototype.markChanged = function (sheetId, r, c) {
20
+ this.active.set("".concat(sheetId, ":").concat(r, ":").concat(c), {
21
+ start: performance.now(),
22
+ dur: this.durationMs
23
+ });
24
+ this.ensureTicking();
25
+ };
26
+ CellFadeAnimator.prototype.getOpacity = function (sheetId, r, c) {
27
+ var activeCellAnimationData = this.active.get("".concat(sheetId, ":").concat(r, ":").concat(c));
28
+ if (!activeCellAnimationData) return 1;
29
+ var animationProgress = Math.min(1, (performance.now() - activeCellAnimationData.start) / activeCellAnimationData.dur);
30
+ if (animationProgress >= 1) {
31
+ this.active.delete("".concat(sheetId, ":").concat(r, ":").concat(c));
32
+ return 1;
33
+ }
34
+ return Math.max(0.05, 1 - Math.pow(1 - animationProgress, 3));
35
+ };
36
+ CellFadeAnimator.prototype.setOnTick = function (repaintFn) {
37
+ this.onTick = repaintFn;
38
+ this.ensureTicking();
39
+ };
40
+ CellFadeAnimator.prototype.ensureTicking = function () {
41
+ var _this = this;
42
+ if (this.animationFrameId !== null) return;
43
+ if (this.active.size === 0) return;
44
+ var _loop = function loop() {
45
+ var _a;
46
+ _this.animationFrameId = null;
47
+ if (_this.active.size === 0) {
48
+ return;
49
+ }
50
+ (_a = _this.onTick) === null || _a === void 0 ? void 0 : _a.call(_this);
51
+ _this.animationFrameId = requestAnimationFrame(_loop);
52
+ };
53
+ this.animationFrameId = requestAnimationFrame(_loop);
54
+ };
55
+ return CellFadeAnimator;
56
+ }();
57
+ var cellFadeAnimator = exports.cellFadeAnimator = new CellFadeAnimator(4000);
58
+ function markCellChanged(sheetId, r, c) {
59
+ cellFadeAnimator.markChanged(sheetId, r, c);
60
+ }
@@ -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/lib/canvas.js CHANGED
@@ -12,6 +12,7 @@ var _inlineString = require("./modules/inline-string");
12
12
  var _utils = require("./utils");
13
13
  var _border = require("./modules/border");
14
14
  var _modules = require("./modules");
15
+ var _animate = require("./animate");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  var defaultStyle = exports.defaultStyle = {
17
18
  fillStyle: "#000000",
@@ -767,7 +768,16 @@ var Canvas = exports.Canvas = function () {
767
768
  var horizonAlignPos = startX + 4 + offsetLeft;
768
769
  var verticalAlignPos = endY + offsetTop - 2;
769
770
  renderCtx.textBaseline = "bottom";
770
- renderCtx.fillText(_lodash.default.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
771
+ var sheetId = this.sheetCtx.currentSheetId;
772
+ var opacity = _animate.cellFadeAnimator.getOpacity(sheetId, r, c);
773
+ if (opacity < 0.999) {
774
+ renderCtx.save();
775
+ renderCtx.globalAlpha = opacity;
776
+ renderCtx.fillText(_lodash.default.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
777
+ renderCtx.restore();
778
+ } else {
779
+ renderCtx.fillText(_lodash.default.isNil(value) ? "" : value, horizonAlignPos, verticalAlignPos);
780
+ }
771
781
  }
772
782
  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) {
773
783
  var ps_w = 12 * this.sheetCtx.zoomRatio;
@@ -1072,10 +1082,22 @@ var Canvas = exports.Canvas = function () {
1072
1082
  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) {
1073
1083
  renderCtx.fillStyle = "#ff0000";
1074
1084
  }
1075
- this.cellTextRender(textInfo, renderCtx, {
1076
- pos_x: pos_x,
1077
- pos_y: pos_y
1078
- });
1085
+ var sheetId = this.sheetCtx.currentSheetId;
1086
+ var opacity = _animate.cellFadeAnimator.getOpacity(sheetId, r, c);
1087
+ if (opacity < 0.999) {
1088
+ renderCtx.save();
1089
+ renderCtx.globalAlpha = opacity;
1090
+ this.cellTextRender(textInfo, renderCtx, {
1091
+ pos_x: pos_x,
1092
+ pos_y: pos_y
1093
+ });
1094
+ renderCtx.restore();
1095
+ } else {
1096
+ this.cellTextRender(textInfo, renderCtx, {
1097
+ pos_x: pos_x,
1098
+ pos_y: pos_y
1099
+ });
1100
+ }
1079
1101
  renderCtx.restore();
1080
1102
  }
1081
1103
  if (cellOverflow_bd_r_render) {
@@ -1157,10 +1179,22 @@ var Canvas = exports.Canvas = function () {
1157
1179
  if (checksCF === null || checksCF === void 0 ? void 0 : checksCF.textColor) {
1158
1180
  renderCtx.fillStyle = checksCF.textColor;
1159
1181
  }
1160
- this.cellTextRender(textInfo, renderCtx, {
1161
- pos_x: pos_x,
1162
- pos_y: pos_y
1163
- });
1182
+ var sheetId = this.sheetCtx.currentSheetId;
1183
+ var opacity = _animate.cellFadeAnimator.getOpacity(sheetId, r, c);
1184
+ if (opacity < 0.999) {
1185
+ renderCtx.save();
1186
+ renderCtx.globalAlpha = opacity;
1187
+ this.cellTextRender(textInfo, renderCtx, {
1188
+ pos_x: pos_x,
1189
+ pos_y: pos_y
1190
+ });
1191
+ renderCtx.restore();
1192
+ } else {
1193
+ this.cellTextRender(textInfo, renderCtx, {
1194
+ pos_x: pos_x,
1195
+ pos_y: pos_y
1196
+ });
1197
+ }
1164
1198
  renderCtx.restore();
1165
1199
  };
1166
1200
  Canvas.prototype.cellOverflow_trace = function (r, curC, traceC, traceDir, horizonAlign, textMetrics) {
@@ -888,10 +888,10 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
888
888
  }
889
889
  var funcV = (0, _formula.execfunction)(ctx, func, h, c, undefined, undefined, true);
890
890
  var afterUpdateCell = ctx.hooks.afterUpdateCell;
891
- if (afterUpdateCell && arr.length === 1) {
891
+ if (afterUpdateCell) {
892
892
  afterUpdateCell(h, c, null, __assign(__assign({}, value), {
893
- v: funcV[1],
894
- m: "[object Promise]"
893
+ v: arr.length === 1 ? funcV[1] : value.v,
894
+ m: funcV[1] instanceof Promise ? "[object Promise]" : funcV[1]
895
895
  }));
896
896
  }
897
897
  if (!_lodash.default.isNil(value.spl)) {}
package/lib/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./locale";
8
8
  export * from "./modules";
9
9
  export * from "./utils";
10
10
  export * from "./types";
11
+ export * from "./animate";
package/lib/index.js CHANGED
@@ -106,4 +106,16 @@ Object.keys(_types).forEach(function (key) {
106
106
  }
107
107
  });
108
108
  });
109
+ var _animate = require("./animate");
110
+ Object.keys(_animate).forEach(function (key) {
111
+ if (key === "default" || key === "__esModule") return;
112
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
113
+ if (key in exports && exports[key] === _animate[key]) return;
114
+ Object.defineProperty(exports, key, {
115
+ enumerable: true,
116
+ get: function get() {
117
+ return _animate[key];
118
+ }
119
+ });
120
+ });
109
121
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
package/lib/types.d.ts CHANGED
@@ -144,6 +144,18 @@ export type ConditionRulesProps = {
144
144
  repeatValue: string;
145
145
  projectValue: string;
146
146
  };
147
+ export type LiveQueryData = {
148
+ data: {
149
+ row: number;
150
+ column: number;
151
+ function: string;
152
+ value: any;
153
+ id: string;
154
+ name: string;
155
+ subSheetId: string;
156
+ };
157
+ cellData: Cell;
158
+ };
147
159
  export type Sheet = {
148
160
  name: string;
149
161
  config?: SheetConfig;
@@ -205,6 +217,7 @@ export type Sheet = {
205
217
  column_focus: number;
206
218
  };
207
219
  };
220
+ liveQueryList?: Record<string, LiveQueryData>;
208
221
  };
209
222
  export type CommentBox = {
210
223
  r: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.11",
3
+ "version": "1.1.14",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "dev": "father-build --watch"
16
16
  },
17
17
  "dependencies": {
18
- "@fileverse-dev/formula-parser": "0.2.62",
18
+ "@fileverse-dev/formula-parser": "0.2.63",
19
19
  "dayjs": "^1.11.0",
20
20
  "immer": "^9.0.12",
21
21
  "lodash": "^4.17.21",