@fileverse-dev/fortune-core 1.2.28 → 1.2.29
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/es/modules/text.js +13 -9
- package/es/modules/toolbar.js +40 -9
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +25 -0
- package/lib/modules/text.js +13 -9
- package/lib/modules/toolbar.js +39 -8
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +28 -1
- package/package.json +1 -1
package/es/modules/text.js
CHANGED
|
@@ -308,15 +308,19 @@ export function getCellTextInfo(cell, renderCtx, sheetCtx, option, ctx) {
|
|
|
308
308
|
});
|
|
309
309
|
similarIndex += 1;
|
|
310
310
|
} else {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
311
|
+
var newValueArray = newValue.split("");
|
|
312
|
+
for (var n = 0; n < newValueArray.length; n += 1) {
|
|
313
|
+
var nv = newValueArray[n];
|
|
314
|
+
inlineStringArr.push({
|
|
315
|
+
fontset: scfontset,
|
|
316
|
+
fc: !fc ? "#000" : fc,
|
|
317
|
+
cl: !cl ? 0 : cl,
|
|
318
|
+
un: !un ? 0 : un,
|
|
319
|
+
v: nv,
|
|
320
|
+
si: similarIndex,
|
|
321
|
+
fs: !fs ? 11 : fs
|
|
322
|
+
});
|
|
323
|
+
}
|
|
320
324
|
if (x !== splitArr.length - 1) {
|
|
321
325
|
inlineStringArr.push({
|
|
322
326
|
fontset: scfontset,
|
package/es/modules/toolbar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import { mergeCells } from "./merge";
|
|
3
3
|
import { getFlowdata } from "../context";
|
|
4
|
-
import { getSheetIndex, isAllowEdit } from "../utils";
|
|
4
|
+
import { getSheetIndex, isAllowEdit, getLineCount } from "../utils";
|
|
5
5
|
import { getRangetxt, isAllSelectedCellsInStatus, normalizedAttr, setCellValue } from "./cell";
|
|
6
6
|
import { colors } from "./color";
|
|
7
7
|
import { genarate, is_date, update } from "./format";
|
|
@@ -15,8 +15,8 @@ import { showLinkCard } from "./hyperlink";
|
|
|
15
15
|
import { cfSplitRange } from "./conditionalFormat";
|
|
16
16
|
import { clearMeasureTextCache, getCellTextInfo } from "./text";
|
|
17
17
|
export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
19
|
-
var
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
19
|
+
var _7;
|
|
20
20
|
if (_.isNil(d) || _.isNil(attr)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -122,23 +122,51 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
122
122
|
if (!_.isNil(ctx.config.rowhidden) && !_.isNil(ctx.config.rowhidden[r])) {
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
var _loop_1 = function _loop_1(c) {
|
|
126
126
|
var value = d[r][c];
|
|
127
127
|
if (value && _.isPlainObject(value)) {
|
|
128
128
|
updateInlineStringFormatOutside(value, attr, foucsStatus);
|
|
129
129
|
value[attr] = foucsStatus;
|
|
130
|
-
(
|
|
130
|
+
(_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
|
|
131
131
|
var cfg = ctx.luckysheetfile[sheetIndex].config;
|
|
132
132
|
var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
|
|
133
|
+
if (attr === "tb" && canvas && foucsStatus === "2") {
|
|
134
|
+
var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
|
|
135
|
+
var lineCount_1 = 1;
|
|
136
|
+
var fontString_1 = '10px Arial';
|
|
137
|
+
if (value.fs) {
|
|
138
|
+
fontString_1 = value.fs * 1.5 + "px Arial";
|
|
139
|
+
}
|
|
140
|
+
if (value === null || value === void 0 ? void 0 : value.bl) {
|
|
141
|
+
lineCount_1 = lineCount_1 + 1;
|
|
142
|
+
}
|
|
143
|
+
if (value.m) {
|
|
144
|
+
lineCount_1 = getLineCount(value.m, currentColWidth_1, fontString_1);
|
|
145
|
+
var hOffset = lineCount_1 < 4 ? 2 : 1.8;
|
|
146
|
+
lineCount_1 = lineCount_1 * hOffset + 1;
|
|
147
|
+
} else if ((_1 = (_0 = (_z = value === null || value === void 0 ? void 0 : value.ct) === null || _z === void 0 ? void 0 : _z.s) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.v) {
|
|
148
|
+
lineCount_1 = lineCount_1 - 1;
|
|
149
|
+
var line = (_4 = (_3 = (_2 = value === null || value === void 0 ? void 0 : value.ct) === null || _2 === void 0 ? void 0 : _2.s) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.v.split("\n");
|
|
150
|
+
line.forEach(function (item) {
|
|
151
|
+
var subLineCount = getLineCount(item, currentColWidth_1, fontString_1);
|
|
152
|
+
lineCount_1 = lineCount_1 + subLineCount;
|
|
153
|
+
});
|
|
154
|
+
var hOffset = lineCount_1 < 4 ? 2.2 : 1.9;
|
|
155
|
+
lineCount_1 = lineCount_1 * 1.9;
|
|
156
|
+
}
|
|
157
|
+
var fontSize = (value === null || value === void 0 ? void 0 : value.fs) || 10;
|
|
158
|
+
var rowHeight = fontSize * lineCount_1;
|
|
159
|
+
_.set(cfg, "rowlen.".concat(r), rowHeight);
|
|
160
|
+
}
|
|
133
161
|
if (attr === "fs" && canvas) {
|
|
134
162
|
var textInfo = getCellTextInfo(d[r][c], canvas, ctx, {
|
|
135
163
|
r: r,
|
|
136
164
|
c: c,
|
|
137
165
|
cellWidth: cellWidth
|
|
138
166
|
});
|
|
139
|
-
if (!textInfo) continue;
|
|
167
|
+
if (!textInfo) return "continue";
|
|
140
168
|
var rowHeight = _.round(textInfo.textHeightAll);
|
|
141
|
-
var currentRowHeight = ((
|
|
169
|
+
var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
|
|
142
170
|
if (!_.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
|
|
143
171
|
if (_.isUndefined(cfg.rowlen)) cfg.rowlen = {};
|
|
144
172
|
_.set(cfg, "rowlen.".concat(r), rowHeight);
|
|
@@ -151,9 +179,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
151
179
|
c: c,
|
|
152
180
|
cellWidth: cellWidth || 104
|
|
153
181
|
});
|
|
154
|
-
if (!textInfo) continue;
|
|
182
|
+
if (!textInfo) return "continue";
|
|
155
183
|
var newHeight = _.round(textInfo.textHeightAll);
|
|
156
|
-
var oldHeight = ((
|
|
184
|
+
var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
|
|
157
185
|
var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
|
|
158
186
|
if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
|
|
159
187
|
var padding = 12;
|
|
@@ -168,6 +196,9 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
168
196
|
};
|
|
169
197
|
d[r][c][attr] = foucsStatus;
|
|
170
198
|
}
|
|
199
|
+
};
|
|
200
|
+
for (var c = col_st; c <= col_ed; c += 1) {
|
|
201
|
+
_loop_1(c);
|
|
171
202
|
}
|
|
172
203
|
}
|
|
173
204
|
}
|
package/es/utils/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export declare function getContentInParentheses(str: string | null): string | nu
|
|
|
23
23
|
export declare function processArray(cellReferences: any, d: any, flowData: any): undefined;
|
|
24
24
|
export declare function getNumberFormat(strValue: any, commaPresent: boolean): string;
|
|
25
25
|
export declare function checkIsCol(str: string): boolean | null;
|
|
26
|
+
export declare function getLineCount(sentence: string, maxWidthPx: number, font?: string): number;
|
package/es/utils/index.js
CHANGED
|
@@ -331,4 +331,29 @@ export function checkIsCol(str) {
|
|
|
331
331
|
if (col1 === col2 && row1 !== row2) return false;
|
|
332
332
|
if (row1 === row2 && col1 !== col2) return true;
|
|
333
333
|
return null;
|
|
334
|
+
}
|
|
335
|
+
export function getLineCount(sentence, maxWidthPx, font) {
|
|
336
|
+
if (font === void 0) {
|
|
337
|
+
font = '12px Arial';
|
|
338
|
+
}
|
|
339
|
+
var canvas = document.createElement('canvas');
|
|
340
|
+
var context = canvas.getContext('2d');
|
|
341
|
+
if (context) {
|
|
342
|
+
context.font = font;
|
|
343
|
+
}
|
|
344
|
+
var words = sentence.split(' ');
|
|
345
|
+
var currentLine = '';
|
|
346
|
+
var lineCount = 0;
|
|
347
|
+
words.forEach(function (word) {
|
|
348
|
+
var testLine = currentLine ? currentLine + ' ' + word : word;
|
|
349
|
+
var testWidth = context === null || context === void 0 ? void 0 : context.measureText(testLine).width;
|
|
350
|
+
if (testWidth && testWidth > maxWidthPx && currentLine) {
|
|
351
|
+
lineCount++;
|
|
352
|
+
currentLine = word;
|
|
353
|
+
} else {
|
|
354
|
+
currentLine = testLine;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
if (currentLine) lineCount++;
|
|
358
|
+
return lineCount;
|
|
334
359
|
}
|
package/lib/modules/text.js
CHANGED
|
@@ -322,15 +322,19 @@ function getCellTextInfo(cell, renderCtx, sheetCtx, option, ctx) {
|
|
|
322
322
|
});
|
|
323
323
|
similarIndex += 1;
|
|
324
324
|
} else {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
325
|
+
var newValueArray = newValue.split("");
|
|
326
|
+
for (var n = 0; n < newValueArray.length; n += 1) {
|
|
327
|
+
var nv = newValueArray[n];
|
|
328
|
+
inlineStringArr.push({
|
|
329
|
+
fontset: scfontset,
|
|
330
|
+
fc: !fc ? "#000" : fc,
|
|
331
|
+
cl: !cl ? 0 : cl,
|
|
332
|
+
un: !un ? 0 : un,
|
|
333
|
+
v: nv,
|
|
334
|
+
si: similarIndex,
|
|
335
|
+
fs: !fs ? 11 : fs
|
|
336
|
+
});
|
|
337
|
+
}
|
|
334
338
|
if (x !== splitArr.length - 1) {
|
|
335
339
|
inlineStringArr.push({
|
|
336
340
|
fontset: scfontset,
|
package/lib/modules/toolbar.js
CHANGED
|
@@ -48,8 +48,8 @@ var _conditionalFormat = require("./conditionalFormat");
|
|
|
48
48
|
var _text = require("./text");
|
|
49
49
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
50
50
|
function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col_ed, canvas) {
|
|
51
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
52
|
-
var
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
52
|
+
var _7;
|
|
53
53
|
if (_lodash.default.isNil(d) || _lodash.default.isNil(attr)) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
@@ -155,23 +155,51 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
155
155
|
if (!_lodash.default.isNil(ctx.config.rowhidden) && !_lodash.default.isNil(ctx.config.rowhidden[r])) {
|
|
156
156
|
continue;
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
var _loop_1 = function _loop_1(c) {
|
|
159
159
|
var value = d[r][c];
|
|
160
160
|
if (value && _lodash.default.isPlainObject(value)) {
|
|
161
161
|
(0, _inlineString.updateInlineStringFormatOutside)(value, attr, foucsStatus);
|
|
162
162
|
value[attr] = foucsStatus;
|
|
163
|
-
(
|
|
163
|
+
(_7 = ctx.luckysheetfile[sheetIndex]).config || (_7.config = {});
|
|
164
164
|
var cfg = ctx.luckysheetfile[sheetIndex].config;
|
|
165
165
|
var cellWidth = ((_x = cfg.columnlen) === null || _x === void 0 ? void 0 : _x[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth;
|
|
166
|
+
if (attr === "tb" && canvas && foucsStatus === "2") {
|
|
167
|
+
var currentColWidth_1 = ((_y = cfg.columnlen) === null || _y === void 0 ? void 0 : _y[c]) || ctx.luckysheetfile[sheetIndex].defaultColWidth || 100;
|
|
168
|
+
var lineCount_1 = 1;
|
|
169
|
+
var fontString_1 = '10px Arial';
|
|
170
|
+
if (value.fs) {
|
|
171
|
+
fontString_1 = value.fs * 1.5 + "px Arial";
|
|
172
|
+
}
|
|
173
|
+
if (value === null || value === void 0 ? void 0 : value.bl) {
|
|
174
|
+
lineCount_1 = lineCount_1 + 1;
|
|
175
|
+
}
|
|
176
|
+
if (value.m) {
|
|
177
|
+
lineCount_1 = (0, _utils.getLineCount)(value.m, currentColWidth_1, fontString_1);
|
|
178
|
+
var hOffset = lineCount_1 < 4 ? 2 : 1.8;
|
|
179
|
+
lineCount_1 = lineCount_1 * hOffset + 1;
|
|
180
|
+
} else if ((_1 = (_0 = (_z = value === null || value === void 0 ? void 0 : value.ct) === null || _z === void 0 ? void 0 : _z.s) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.v) {
|
|
181
|
+
lineCount_1 = lineCount_1 - 1;
|
|
182
|
+
var line = (_4 = (_3 = (_2 = value === null || value === void 0 ? void 0 : value.ct) === null || _2 === void 0 ? void 0 : _2.s) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.v.split("\n");
|
|
183
|
+
line.forEach(function (item) {
|
|
184
|
+
var subLineCount = (0, _utils.getLineCount)(item, currentColWidth_1, fontString_1);
|
|
185
|
+
lineCount_1 = lineCount_1 + subLineCount;
|
|
186
|
+
});
|
|
187
|
+
var hOffset = lineCount_1 < 4 ? 2.2 : 1.9;
|
|
188
|
+
lineCount_1 = lineCount_1 * 1.9;
|
|
189
|
+
}
|
|
190
|
+
var fontSize = (value === null || value === void 0 ? void 0 : value.fs) || 10;
|
|
191
|
+
var rowHeight = fontSize * lineCount_1;
|
|
192
|
+
_lodash.default.set(cfg, "rowlen.".concat(r), rowHeight);
|
|
193
|
+
}
|
|
166
194
|
if (attr === "fs" && canvas) {
|
|
167
195
|
var textInfo = (0, _text.getCellTextInfo)(d[r][c], canvas, ctx, {
|
|
168
196
|
r: r,
|
|
169
197
|
c: c,
|
|
170
198
|
cellWidth: cellWidth
|
|
171
199
|
});
|
|
172
|
-
if (!textInfo) continue;
|
|
200
|
+
if (!textInfo) return "continue";
|
|
173
201
|
var rowHeight = _lodash.default.round(textInfo.textHeightAll);
|
|
174
|
-
var currentRowHeight = ((
|
|
202
|
+
var currentRowHeight = ((_5 = cfg.rowlen) === null || _5 === void 0 ? void 0 : _5[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
|
|
175
203
|
if (!_lodash.default.isUndefined(rowHeight) && rowHeight > currentRowHeight && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
|
|
176
204
|
if (_lodash.default.isUndefined(cfg.rowlen)) cfg.rowlen = {};
|
|
177
205
|
_lodash.default.set(cfg, "rowlen.".concat(r), rowHeight);
|
|
@@ -184,9 +212,9 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
184
212
|
c: c,
|
|
185
213
|
cellWidth: cellWidth || 104
|
|
186
214
|
});
|
|
187
|
-
if (!textInfo) continue;
|
|
215
|
+
if (!textInfo) return "continue";
|
|
188
216
|
var newHeight = _lodash.default.round(textInfo.textHeightAll);
|
|
189
|
-
var oldHeight = ((
|
|
217
|
+
var oldHeight = ((_6 = cfg.rowlen) === null || _6 === void 0 ? void 0 : _6[r]) || ctx.luckysheetfile[sheetIndex].defaultRowHeight || 19;
|
|
190
218
|
var shouldResize = foucsStatus === "2" ? newHeight > oldHeight : true;
|
|
191
219
|
if (shouldResize && (!cfg.customHeight || cfg.customHeight[r] !== 1)) {
|
|
192
220
|
var padding = 12;
|
|
@@ -201,6 +229,9 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
201
229
|
};
|
|
202
230
|
d[r][c][attr] = foucsStatus;
|
|
203
231
|
}
|
|
232
|
+
};
|
|
233
|
+
for (var c = col_st; c <= col_ed; c += 1) {
|
|
234
|
+
_loop_1(c);
|
|
204
235
|
}
|
|
205
236
|
}
|
|
206
237
|
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export declare function getContentInParentheses(str: string | null): string | nu
|
|
|
23
23
|
export declare function processArray(cellReferences: any, d: any, flowData: any): undefined;
|
|
24
24
|
export declare function getNumberFormat(strValue: any, commaPresent: boolean): string;
|
|
25
25
|
export declare function checkIsCol(str: string): boolean | null;
|
|
26
|
+
export declare function getLineCount(sentence: string, maxWidthPx: number, font?: string): number;
|
package/lib/utils/index.js
CHANGED
|
@@ -24,7 +24,8 @@ var _exportNames = {
|
|
|
24
24
|
getContentInParentheses: true,
|
|
25
25
|
processArray: true,
|
|
26
26
|
getNumberFormat: true,
|
|
27
|
-
checkIsCol: true
|
|
27
|
+
checkIsCol: true,
|
|
28
|
+
getLineCount: true
|
|
28
29
|
};
|
|
29
30
|
exports.chatatABC = chatatABC;
|
|
30
31
|
exports.checkIsCol = checkIsCol;
|
|
@@ -33,6 +34,7 @@ exports.escapeHTMLTag = escapeHTMLTag;
|
|
|
33
34
|
exports.escapeScriptTag = escapeScriptTag;
|
|
34
35
|
exports.generateRandomSheetName = generateRandomSheetName;
|
|
35
36
|
exports.getContentInParentheses = getContentInParentheses;
|
|
37
|
+
exports.getLineCount = getLineCount;
|
|
36
38
|
exports.getNowDateTime = getNowDateTime;
|
|
37
39
|
exports.getNumberFormat = getNumberFormat;
|
|
38
40
|
exports.getRegExpStr = getRegExpStr;
|
|
@@ -403,4 +405,29 @@ function checkIsCol(str) {
|
|
|
403
405
|
if (col1 === col2 && row1 !== row2) return false;
|
|
404
406
|
if (row1 === row2 && col1 !== col2) return true;
|
|
405
407
|
return null;
|
|
408
|
+
}
|
|
409
|
+
function getLineCount(sentence, maxWidthPx, font) {
|
|
410
|
+
if (font === void 0) {
|
|
411
|
+
font = '12px Arial';
|
|
412
|
+
}
|
|
413
|
+
var canvas = document.createElement('canvas');
|
|
414
|
+
var context = canvas.getContext('2d');
|
|
415
|
+
if (context) {
|
|
416
|
+
context.font = font;
|
|
417
|
+
}
|
|
418
|
+
var words = sentence.split(' ');
|
|
419
|
+
var currentLine = '';
|
|
420
|
+
var lineCount = 0;
|
|
421
|
+
words.forEach(function (word) {
|
|
422
|
+
var testLine = currentLine ? currentLine + ' ' + word : word;
|
|
423
|
+
var testWidth = context === null || context === void 0 ? void 0 : context.measureText(testLine).width;
|
|
424
|
+
if (testWidth && testWidth > maxWidthPx && currentLine) {
|
|
425
|
+
lineCount++;
|
|
426
|
+
currentLine = word;
|
|
427
|
+
} else {
|
|
428
|
+
currentLine = testLine;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
if (currentLine) lineCount++;
|
|
432
|
+
return lineCount;
|
|
406
433
|
}
|