@canvas-components/utils 0.2.7 → 0.2.9

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/dist/index.cjs CHANGED
@@ -1215,6 +1215,25 @@ function resolveThousandsSeparator(separator) {
1215
1215
  return ",";
1216
1216
  }
1217
1217
 
1218
+ // src/async/index.ts
1219
+ async function mapInBatches(length, create, options = {}) {
1220
+ const result = new Array(length);
1221
+ let index = 0;
1222
+ options.signal?.throwIfAborted();
1223
+ while (index < length) {
1224
+ await new Promise((resolve) => setTimeout(resolve, 0));
1225
+ options.signal?.throwIfAborted();
1226
+ const deadline = performance.now() + 8;
1227
+ do {
1228
+ result[index] = create(index);
1229
+ index++;
1230
+ } while (index < length && performance.now() < deadline);
1231
+ options.onProgress?.(index, length);
1232
+ }
1233
+ options.signal?.throwIfAborted();
1234
+ return result;
1235
+ }
1236
+
1218
1237
  exports.addPreciseNumbers = addPreciseNumbers;
1219
1238
  exports.buildCsvContent = buildCsvContent;
1220
1239
  exports.buildTxtContent = buildTxtContent;
@@ -1241,6 +1260,7 @@ exports.getValueByDataIndex = getValueByDataIndex;
1241
1260
  exports.isDateTimeFormatPattern = isDateTimeFormatPattern;
1242
1261
  exports.isPointInRect = isPointInRect;
1243
1262
  exports.isSameDataIndex = isSameDataIndex;
1263
+ exports.mapInBatches = mapInBatches;
1244
1264
  exports.mapRowsToExportRecords = mapRowsToExportRecords;
1245
1265
  exports.normalizeDecimalPlaces = normalizeDecimalPlaces;
1246
1266
  exports.parseChineseNumber = parseChineseNumber;
package/dist/index.d.cts CHANGED
@@ -98,4 +98,12 @@ declare function resolveCanvasScrollbarAxis(options: CanvasScrollbarOptions | un
98
98
  /** 长按按钮时逐渐加速,2.5 秒达到配置上限。 */
99
99
  declare function resolveCanvasScrollbarHoldSpeed(elapsedMs: number, maxScrollSpeed: number): number;
100
100
 
101
- export { type CanvasScrollbarAxisOptions, type CanvasScrollbarOptions, type TableExportColumnChoice, type TableExportNameRequest, type TableExportSettings, type TableExportSummarySettings, type TableExportSummaryType, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed };
101
+ /** 分批任务的取消信号与进度通知。 */
102
+ interface BatchTaskOptions {
103
+ signal?: AbortSignal;
104
+ onProgress?: (completed: number, total: number) => void;
105
+ }
106
+ /** 按约 8ms 的时间片构造数组,在批次之间让出主线程。 */
107
+ declare function mapInBatches<T>(length: number, create: (index: number) => T, options?: BatchTaskOptions): Promise<T[]>;
108
+
109
+ export { type BatchTaskOptions, type CanvasScrollbarAxisOptions, type CanvasScrollbarOptions, type TableExportColumnChoice, type TableExportNameRequest, type TableExportSettings, type TableExportSummarySettings, type TableExportSummaryType, mapInBatches, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed };
package/dist/index.d.ts CHANGED
@@ -98,4 +98,12 @@ declare function resolveCanvasScrollbarAxis(options: CanvasScrollbarOptions | un
98
98
  /** 长按按钮时逐渐加速,2.5 秒达到配置上限。 */
99
99
  declare function resolveCanvasScrollbarHoldSpeed(elapsedMs: number, maxScrollSpeed: number): number;
100
100
 
101
- export { type CanvasScrollbarAxisOptions, type CanvasScrollbarOptions, type TableExportColumnChoice, type TableExportNameRequest, type TableExportSettings, type TableExportSummarySettings, type TableExportSummaryType, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed };
101
+ /** 分批任务的取消信号与进度通知。 */
102
+ interface BatchTaskOptions {
103
+ signal?: AbortSignal;
104
+ onProgress?: (completed: number, total: number) => void;
105
+ }
106
+ /** 按约 8ms 的时间片构造数组,在批次之间让出主线程。 */
107
+ declare function mapInBatches<T>(length: number, create: (index: number) => T, options?: BatchTaskOptions): Promise<T[]>;
108
+
109
+ export { type BatchTaskOptions, type CanvasScrollbarAxisOptions, type CanvasScrollbarOptions, type TableExportColumnChoice, type TableExportNameRequest, type TableExportSettings, type TableExportSummarySettings, type TableExportSummaryType, mapInBatches, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed };
package/dist/index.js CHANGED
@@ -1193,4 +1193,23 @@ function resolveThousandsSeparator(separator) {
1193
1193
  return ",";
1194
1194
  }
1195
1195
 
1196
- export { addPreciseNumbers, buildCsvContent, buildTxtContent, clamp, comparePreciseNumbers, copyJson, copyRows, copyText, copyTextSync, dividePreciseNumber, downloadJsonFile, exportTableToCsv, exportTableToTxt, exportTableToXlsx, formatChineseNumber, formatCustomNumberPattern, formatDateTimeValue, formatNumberValue, formatPercentValue, formatPreciseNumber, formatRowsForClipboard, formatScientificValue, getValueByDataIndex, isDateTimeFormatPattern, isPointInRect, isSameDataIndex, mapRowsToExportRecords, normalizeDecimalPlaces, parseChineseNumber, parseNumberValue, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed, resolveDateValue, roundPreciseNumber, serializeCsvRows, stringifyDataIndex, sumPreciseNumbers };
1196
+ // src/async/index.ts
1197
+ async function mapInBatches(length, create, options = {}) {
1198
+ const result = new Array(length);
1199
+ let index = 0;
1200
+ options.signal?.throwIfAborted();
1201
+ while (index < length) {
1202
+ await new Promise((resolve) => setTimeout(resolve, 0));
1203
+ options.signal?.throwIfAborted();
1204
+ const deadline = performance.now() + 8;
1205
+ do {
1206
+ result[index] = create(index);
1207
+ index++;
1208
+ } while (index < length && performance.now() < deadline);
1209
+ options.onProgress?.(index, length);
1210
+ }
1211
+ options.signal?.throwIfAborted();
1212
+ return result;
1213
+ }
1214
+
1215
+ export { addPreciseNumbers, buildCsvContent, buildTxtContent, clamp, comparePreciseNumbers, copyJson, copyRows, copyText, copyTextSync, dividePreciseNumber, downloadJsonFile, exportTableToCsv, exportTableToTxt, exportTableToXlsx, formatChineseNumber, formatCustomNumberPattern, formatDateTimeValue, formatNumberValue, formatPercentValue, formatPreciseNumber, formatRowsForClipboard, formatScientificValue, getValueByDataIndex, isDateTimeFormatPattern, isPointInRect, isSameDataIndex, mapInBatches, mapRowsToExportRecords, normalizeDecimalPlaces, parseChineseNumber, parseNumberValue, resolveCanvasScrollbarAxis, resolveCanvasScrollbarHoldSpeed, resolveDateValue, roundPreciseNumber, serializeCsvRows, stringifyDataIndex, sumPreciseNumbers };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas-components/utils",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Clipboard and export utilities for canvas-components.",
5
5
  "license": "MIT",
6
6
  "type": "module",