pixel-data-js 0.29.0 → 0.31.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/dist/index.prod.cjs +72 -12
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +64 -6
- package/dist/index.prod.js +70 -12
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/Control/BatchedQueue.ts +76 -0
- package/src/Control/RenderQueue.ts +49 -0
- package/src/History/HistoryAction.ts +4 -7
- package/src/History/PixelWriter.ts +5 -9
- package/src/index.ts +3 -0
package/dist/index.prod.cjs
CHANGED
|
@@ -142,6 +142,7 @@ __export(src_exports, {
|
|
|
142
142
|
makeAlphaMaskPaintBufferCommitter: () => makeAlphaMaskPaintBufferCommitter,
|
|
143
143
|
makeAlphaMaskPaintBufferManager: () => makeAlphaMaskPaintBufferManager,
|
|
144
144
|
makeAlphaMaskTile: () => makeAlphaMaskTile,
|
|
145
|
+
makeBatchedQueue: () => makeBatchedQueue,
|
|
145
146
|
makeBinaryMask: () => makeBinaryMask,
|
|
146
147
|
makeBinaryMaskFromAlphaMask: () => makeBinaryMaskFromAlphaMask,
|
|
147
148
|
makeBinaryMaskOutline: () => makeBinaryMaskOutline,
|
|
@@ -176,6 +177,7 @@ __export(src_exports, {
|
|
|
176
177
|
makePixelTile: () => makePixelTile,
|
|
177
178
|
makeRectBinaryMaskOutline: () => makeRectBinaryMaskOutline,
|
|
178
179
|
makeRectFalloffPaintAlphaMask: () => makeRectFalloffPaintAlphaMask,
|
|
180
|
+
makeRenderQueue: () => makeRenderQueue,
|
|
179
181
|
makeReusableCanvas: () => makeReusableCanvas,
|
|
180
182
|
makeReusableImageData: () => makeReusableImageData,
|
|
181
183
|
makeReusableOffscreenCanvas: () => makeReusableOffscreenCanvas,
|
|
@@ -2290,6 +2292,67 @@ async function writeImageDataToClipboard(imageData) {
|
|
|
2290
2292
|
return writeImgBlobToClipboard(blob);
|
|
2291
2293
|
}
|
|
2292
2294
|
|
|
2295
|
+
// src/Control/BatchedQueue.ts
|
|
2296
|
+
function makeBatchedQueue(processor, queue) {
|
|
2297
|
+
let activeSet = /* @__PURE__ */ new Set();
|
|
2298
|
+
let processingSet = /* @__PURE__ */ new Set();
|
|
2299
|
+
let scheduled = false;
|
|
2300
|
+
const flush = () => {
|
|
2301
|
+
const current = activeSet;
|
|
2302
|
+
activeSet = processingSet;
|
|
2303
|
+
processingSet = current;
|
|
2304
|
+
scheduled = false;
|
|
2305
|
+
try {
|
|
2306
|
+
processor(processingSet);
|
|
2307
|
+
} finally {
|
|
2308
|
+
processingSet.clear();
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
function markDirty(item) {
|
|
2312
|
+
activeSet.add(item);
|
|
2313
|
+
if (!scheduled) {
|
|
2314
|
+
scheduled = true;
|
|
2315
|
+
queue(flush);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
function markMultipleDirty(items) {
|
|
2319
|
+
let len = items.length;
|
|
2320
|
+
if (len === 0) return;
|
|
2321
|
+
for (let i = 0; i < len; i++) {
|
|
2322
|
+
activeSet.add(items[i]);
|
|
2323
|
+
}
|
|
2324
|
+
if (!scheduled) {
|
|
2325
|
+
scheduled = true;
|
|
2326
|
+
queue(flush);
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
return {
|
|
2330
|
+
markDirty,
|
|
2331
|
+
markMultipleDirty
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
// src/Control/RenderQueue.ts
|
|
2336
|
+
function makeRenderQueue(cb) {
|
|
2337
|
+
let needsRender = false;
|
|
2338
|
+
let frameId = 0;
|
|
2339
|
+
const trigger = () => {
|
|
2340
|
+
if (needsRender) return;
|
|
2341
|
+
needsRender = true;
|
|
2342
|
+
frameId = requestAnimationFrame(() => {
|
|
2343
|
+
needsRender = false;
|
|
2344
|
+
cb();
|
|
2345
|
+
});
|
|
2346
|
+
};
|
|
2347
|
+
trigger.cancel = () => {
|
|
2348
|
+
if (needsRender) {
|
|
2349
|
+
cancelAnimationFrame(frameId);
|
|
2350
|
+
needsRender = false;
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
return trigger;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2293
2356
|
// src/History/PixelPatchTiles.ts
|
|
2294
2357
|
function applyPatchTiles(target, tiles, tileSize) {
|
|
2295
2358
|
for (let i = 0; i < tiles.length; i++) {
|
|
@@ -2315,19 +2378,17 @@ function applyPatchTiles(target, tiles, tileSize) {
|
|
|
2315
2378
|
}
|
|
2316
2379
|
|
|
2317
2380
|
// src/History/HistoryAction.ts
|
|
2318
|
-
function makeHistoryAction(config, accumulator, patch,
|
|
2381
|
+
function makeHistoryAction(config, accumulator, patch, afterUndo, afterRedo, applyPatchTilesFn = applyPatchTiles) {
|
|
2319
2382
|
const target = config.target;
|
|
2320
2383
|
const tileSize = config.tileSize;
|
|
2321
2384
|
return {
|
|
2322
2385
|
undo: () => {
|
|
2323
2386
|
applyPatchTilesFn(target, patch.beforeTiles, tileSize);
|
|
2324
|
-
afterUndo?.();
|
|
2325
|
-
after?.();
|
|
2387
|
+
afterUndo?.(patch);
|
|
2326
2388
|
},
|
|
2327
2389
|
redo: () => {
|
|
2328
2390
|
applyPatchTilesFn(target, patch.afterTiles, tileSize);
|
|
2329
|
-
afterRedo?.();
|
|
2330
|
-
after?.();
|
|
2391
|
+
afterRedo?.(patch);
|
|
2331
2392
|
},
|
|
2332
2393
|
dispose: () => accumulator.recyclePatch(patch)
|
|
2333
2394
|
};
|
|
@@ -2854,11 +2915,10 @@ var PixelWriter = class {
|
|
|
2854
2915
|
* throw immediately to prevent silent data loss from a nested extractPatch.
|
|
2855
2916
|
*
|
|
2856
2917
|
* @param transaction Callback to be executed inside the transaction.
|
|
2857
|
-
* @param
|
|
2858
|
-
* @param afterUndo Called after undo only — use for dimension or state changes specific to undo.
|
|
2918
|
+
* @param afterUndo Called after undo only.
|
|
2859
2919
|
* @param afterRedo Called after redo only.
|
|
2860
2920
|
*/
|
|
2861
|
-
withHistory(transaction,
|
|
2921
|
+
withHistory(transaction, afterUndo, afterRedo) {
|
|
2862
2922
|
if (this._inProgress) {
|
|
2863
2923
|
throw new Error("withHistory is not re-entrant \u2014 commit or rollback the current operation first");
|
|
2864
2924
|
}
|
|
@@ -2873,10 +2933,10 @@ var PixelWriter = class {
|
|
|
2873
2933
|
}
|
|
2874
2934
|
if (this.accumulator.beforeTiles.length === 0) return;
|
|
2875
2935
|
const patch = this.accumulator.extractPatch();
|
|
2876
|
-
const action = this.historyActionFactory(this.config, this.accumulator, patch,
|
|
2936
|
+
const action = this.historyActionFactory(this.config, this.accumulator, patch, afterUndo, afterRedo);
|
|
2877
2937
|
this.historyManager.commit(action);
|
|
2878
2938
|
}
|
|
2879
|
-
resize(newWidth, newHeight, offsetX = 0, offsetY = 0,
|
|
2939
|
+
resize(newWidth, newHeight, offsetX = 0, offsetY = 0, afterUndo, afterRedo, resizeImageDataFn = resizeImageData) {
|
|
2880
2940
|
if (this._inProgress) {
|
|
2881
2941
|
throw new Error("Cannot resize inside a withHistory callback");
|
|
2882
2942
|
}
|
|
@@ -2892,12 +2952,10 @@ var PixelWriter = class {
|
|
|
2892
2952
|
undo: () => {
|
|
2893
2953
|
setPixelData(target, beforeImageData);
|
|
2894
2954
|
afterUndo?.(beforeImageData);
|
|
2895
|
-
after?.(beforeImageData);
|
|
2896
2955
|
},
|
|
2897
2956
|
redo: () => {
|
|
2898
2957
|
setPixelData(target, afterImageData);
|
|
2899
2958
|
afterRedo?.(afterImageData);
|
|
2900
|
-
after?.(afterImageData);
|
|
2901
2959
|
}
|
|
2902
2960
|
});
|
|
2903
2961
|
}
|
|
@@ -6692,6 +6750,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6692
6750
|
makeAlphaMaskPaintBufferCommitter,
|
|
6693
6751
|
makeAlphaMaskPaintBufferManager,
|
|
6694
6752
|
makeAlphaMaskTile,
|
|
6753
|
+
makeBatchedQueue,
|
|
6695
6754
|
makeBinaryMask,
|
|
6696
6755
|
makeBinaryMaskFromAlphaMask,
|
|
6697
6756
|
makeBinaryMaskOutline,
|
|
@@ -6726,6 +6785,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6726
6785
|
makePixelTile,
|
|
6727
6786
|
makeRectBinaryMaskOutline,
|
|
6728
6787
|
makeRectFalloffPaintAlphaMask,
|
|
6788
|
+
makeRenderQueue,
|
|
6729
6789
|
makeReusableCanvas,
|
|
6730
6790
|
makeReusableImageData,
|
|
6731
6791
|
makeReusableOffscreenCanvas,
|