pixel-data-js 0.30.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 +69 -7
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +63 -5
- package/dist/index.prod.js +67 -7
- 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/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++) {
|
|
@@ -2852,11 +2915,10 @@ var PixelWriter = class {
|
|
|
2852
2915
|
* throw immediately to prevent silent data loss from a nested extractPatch.
|
|
2853
2916
|
*
|
|
2854
2917
|
* @param transaction Callback to be executed inside the transaction.
|
|
2855
|
-
* @param
|
|
2856
|
-
* @param afterUndo Called after undo only — use for dimension or state changes specific to undo.
|
|
2918
|
+
* @param afterUndo Called after undo only.
|
|
2857
2919
|
* @param afterRedo Called after redo only.
|
|
2858
2920
|
*/
|
|
2859
|
-
withHistory(transaction,
|
|
2921
|
+
withHistory(transaction, afterUndo, afterRedo) {
|
|
2860
2922
|
if (this._inProgress) {
|
|
2861
2923
|
throw new Error("withHistory is not re-entrant \u2014 commit or rollback the current operation first");
|
|
2862
2924
|
}
|
|
@@ -2871,10 +2933,10 @@ var PixelWriter = class {
|
|
|
2871
2933
|
}
|
|
2872
2934
|
if (this.accumulator.beforeTiles.length === 0) return;
|
|
2873
2935
|
const patch = this.accumulator.extractPatch();
|
|
2874
|
-
const action = this.historyActionFactory(this.config, this.accumulator, patch,
|
|
2936
|
+
const action = this.historyActionFactory(this.config, this.accumulator, patch, afterUndo, afterRedo);
|
|
2875
2937
|
this.historyManager.commit(action);
|
|
2876
2938
|
}
|
|
2877
|
-
resize(newWidth, newHeight, offsetX = 0, offsetY = 0,
|
|
2939
|
+
resize(newWidth, newHeight, offsetX = 0, offsetY = 0, afterUndo, afterRedo, resizeImageDataFn = resizeImageData) {
|
|
2878
2940
|
if (this._inProgress) {
|
|
2879
2941
|
throw new Error("Cannot resize inside a withHistory callback");
|
|
2880
2942
|
}
|
|
@@ -2890,12 +2952,10 @@ var PixelWriter = class {
|
|
|
2890
2952
|
undo: () => {
|
|
2891
2953
|
setPixelData(target, beforeImageData);
|
|
2892
2954
|
afterUndo?.(beforeImageData);
|
|
2893
|
-
after?.(beforeImageData);
|
|
2894
2955
|
},
|
|
2895
2956
|
redo: () => {
|
|
2896
2957
|
setPixelData(target, afterImageData);
|
|
2897
2958
|
afterRedo?.(afterImageData);
|
|
2898
|
-
after?.(afterImageData);
|
|
2899
2959
|
}
|
|
2900
2960
|
});
|
|
2901
2961
|
}
|
|
@@ -6690,6 +6750,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6690
6750
|
makeAlphaMaskPaintBufferCommitter,
|
|
6691
6751
|
makeAlphaMaskPaintBufferManager,
|
|
6692
6752
|
makeAlphaMaskTile,
|
|
6753
|
+
makeBatchedQueue,
|
|
6693
6754
|
makeBinaryMask,
|
|
6694
6755
|
makeBinaryMaskFromAlphaMask,
|
|
6695
6756
|
makeBinaryMaskOutline,
|
|
@@ -6724,6 +6785,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6724
6785
|
makePixelTile,
|
|
6725
6786
|
makeRectBinaryMaskOutline,
|
|
6726
6787
|
makeRectFalloffPaintAlphaMask,
|
|
6788
|
+
makeRenderQueue,
|
|
6727
6789
|
makeReusableCanvas,
|
|
6728
6790
|
makeReusableImageData,
|
|
6729
6791
|
makeReusableOffscreenCanvas,
|