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.d.ts
CHANGED
|
@@ -680,6 +680,65 @@ declare function color32ToHex(color: Color32): string;
|
|
|
680
680
|
*/
|
|
681
681
|
declare function color32ToCssRGBA(color: Color32): string;
|
|
682
682
|
|
|
683
|
+
type BatchedQueueFn = (fn: () => void) => void;
|
|
684
|
+
type BatchedQueue = ReturnType<typeof makeBatchedQueue>;
|
|
685
|
+
/**
|
|
686
|
+
* Creates a high-performance, zero-allocation batching queue.
|
|
687
|
+
* This utility collects items marked as "dirty" and flushes them in a single batch.
|
|
688
|
+
* * **⚠️ CRITICAL: Synchronous Processing Required**
|
|
689
|
+
* Because the internal sets are reused, the `Set` passed to the `processor` is instantly
|
|
690
|
+
* cleared the moment the processor function returns. If you need to process the items
|
|
691
|
+
* asynchronously, you **must** manually clone the set inside your processor.
|
|
692
|
+
* @template T - The type of items being batched.
|
|
693
|
+
* @param processor - The callback executed when the batch flushes. Receives a `Set` of all batched items.
|
|
694
|
+
* @param queue - The scheduling function used to defer the flush. Defaults to `queueMicrotask`.
|
|
695
|
+
* @returns An object containing methods to mark items as dirty.
|
|
696
|
+
* @example
|
|
697
|
+
* * @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* import { nextTick } from 'vue'
|
|
700
|
+
* let bq = makeBatchedQueue<string>(
|
|
701
|
+
* (items) => drawSomething(items),
|
|
702
|
+
* nextTick,
|
|
703
|
+
* )
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
declare function makeBatchedQueue<T>(processor: (items: Set<T>) => void, queue: BatchedQueueFn): {
|
|
707
|
+
markDirty: (item: T) => void;
|
|
708
|
+
markMultipleDirty: (items: T[]) => void;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Creates a debounced render queue using `requestAnimationFrame`.
|
|
713
|
+
* This utility ensures that a callback is executed exactly once right before
|
|
714
|
+
* the next visual frame, regardless of how many times the trigger is called
|
|
715
|
+
* synchronously. It safely prevents layout thrashing and redundant computations.
|
|
716
|
+
* @param cb - The function to execute on the next animation frame.
|
|
717
|
+
* @returns A trigger function that schedules the callback. It includes a `.cancel()` method to abort the pending frame.
|
|
718
|
+
* * @example
|
|
719
|
+
* ```ts
|
|
720
|
+
* let renderQueue = makeRenderQueue(() => {
|
|
721
|
+
* console.log('DOM updated!')
|
|
722
|
+
* })
|
|
723
|
+
* * // Calling this multiple times synchronously...
|
|
724
|
+
* renderQueue()
|
|
725
|
+
* renderQueue()
|
|
726
|
+
* renderQueue()
|
|
727
|
+
* * // ...will only result in one 'DOM updated!' log on the next frame.
|
|
728
|
+
* ```
|
|
729
|
+
* * @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* // Canceling a scheduled render (e.g., when a component unmounts)
|
|
732
|
+
* let trigger = makeRenderQueue(updateLayout)
|
|
733
|
+
* trigger()
|
|
734
|
+
* trigger.cancel() // The callback will not execute
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
declare function makeRenderQueue(cb: () => void): {
|
|
738
|
+
(): void;
|
|
739
|
+
cancel(): void;
|
|
740
|
+
};
|
|
741
|
+
|
|
683
742
|
declare const enum TileType {
|
|
684
743
|
PIXEL = 0,
|
|
685
744
|
MASK = 1
|
|
@@ -759,7 +818,7 @@ interface HistoryAction {
|
|
|
759
818
|
dispose?: () => void;
|
|
760
819
|
}
|
|
761
820
|
type HistoryActionFactory = typeof makeHistoryAction;
|
|
762
|
-
declare function makeHistoryAction(config: PixelEngineConfig, accumulator: PixelAccumulator, patch: PixelPatchTiles,
|
|
821
|
+
declare function makeHistoryAction(config: PixelEngineConfig, accumulator: PixelAccumulator, patch: PixelPatchTiles, afterUndo?: (patch: PixelPatchTiles) => void, afterRedo?: (patch: PixelPatchTiles) => void, applyPatchTilesFn?: typeof applyPatchTiles): HistoryAction;
|
|
763
822
|
|
|
764
823
|
declare class HistoryManager {
|
|
765
824
|
maxSteps: number;
|
|
@@ -857,12 +916,11 @@ declare class PixelWriter<M> {
|
|
|
857
916
|
* throw immediately to prevent silent data loss from a nested extractPatch.
|
|
858
917
|
*
|
|
859
918
|
* @param transaction Callback to be executed inside the transaction.
|
|
860
|
-
* @param
|
|
861
|
-
* @param afterUndo Called after undo only — use for dimension or state changes specific to undo.
|
|
919
|
+
* @param afterUndo Called after undo only.
|
|
862
920
|
* @param afterRedo Called after redo only.
|
|
863
921
|
*/
|
|
864
|
-
withHistory(transaction: (mutator: M) => void,
|
|
865
|
-
resize(newWidth: number, newHeight: number, offsetX?: number, offsetY?: number,
|
|
922
|
+
withHistory(transaction: (mutator: M) => void, afterUndo?: (patch: PixelPatchTiles) => void, afterRedo?: (patch: PixelPatchTiles) => void): void;
|
|
923
|
+
resize(newWidth: number, newHeight: number, offsetX?: number, offsetY?: number, afterUndo?: (target: ImageData) => void, afterRedo?: (target: ImageData) => void, resizeImageDataFn?: typeof resizeImageData): void;
|
|
866
924
|
}
|
|
867
925
|
type HistoryMutator<T extends {}, D extends {}> = (writer: PixelWriter<any>, deps?: Partial<D>) => T;
|
|
868
926
|
|
|
@@ -1889,4 +1947,4 @@ declare const makeBinaryMaskTile: TileFactory<BinaryMaskTile>;
|
|
|
1889
1947
|
|
|
1890
1948
|
declare function makePixelTile(id: number, tx: number, ty: number, tileSize: number, tileArea: number): PixelTile;
|
|
1891
1949
|
|
|
1892
|
-
export { type AlphaMask, AlphaMaskPaintBuffer, type AlphaMaskPaintBufferCanvasRenderer, type AlphaMaskPaintBufferManager, type AlphaMaskRect, type AlphaMaskTile, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BinaryMask, BinaryMaskPaintBuffer, type BinaryMaskPaintBufferCanvasRenderer, type BinaryMaskPaintBufferManager, type BinaryMaskRect, type BinaryMaskTile, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type CanvasObjectFactory, type CanvasPixelDataRenderer, type ClippedBlit, type ClippedRect, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, ColorPaintBuffer, type ColorPaintBufferCanvasRenderer, type ColorPaintBufferManager, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, _errors as ERRORS, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type ImageDataLike, type IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type MutableAlphaMask, type MutableBinaryMask, type MutableMask, type MutablePixelData32, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, type PaintCursorRenderer, type PaintMask, PaintMaskOutline, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, type PixelData, type PixelData32, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, type PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableCanvasFactory, type ReusableImageData, type ReusablePixelData, type SerializedImageData, type Tile, type TileFactory, TilePool, TileType, UnsupportedFormatError, _macro_imageDataToUint32Array, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, commitColorPaintBuffer, commitMaskPaintBuffer, copyImageData, copyImageDataLike, copyMask, copyPixelData, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, destinationAtopFast, destinationAtopPerfect, destinationInFast, destinationInPerfect, destinationOutFast, destinationOutPerfect, destinationOverFast, destinationOverPerfect, differenceFast, differencePerfect, divideFast, dividePerfect, eachTileInBounds, exclusionFast, exclusionPerfect, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColor, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUint32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeAlphaMaskPaintBufferCanvasRenderer, makeAlphaMaskPaintBufferCommitter, makeAlphaMaskPaintBufferManager, makeAlphaMaskTile, makeBinaryMask, makeBinaryMaskFromAlphaMask, makeBinaryMaskOutline, makeBinaryMaskPaintBufferCanvasRenderer, makeBinaryMaskPaintBufferCommitter, makeBinaryMaskPaintBufferManager, makeBinaryMaskTile, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCanvasPixelDataRenderer, makeCircleBinaryMaskOutline, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeClippedBlit, makeClippedRect, makeColorPaintBufferCanvasRenderer, makeColorPaintBufferCommitter, makeColorPaintBufferManager, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makeIndexedImage, makeIndexedImageFromImageData, makeIndexedImageFromImageDataRaw, makePaintAlphaMask, makePaintBinaryMask, makePaintCursorRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makePixelData, makePixelTile, makeRectBinaryMaskOutline, makeRectFalloffPaintAlphaMask, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, makeReusablePixelData, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resamplePixelDataInPlace, resampleUint32Array, resizeImageData, resolveBlitClipping, resolveRectClipping, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, setPixelData, softLightFast, softLightPerfect, sourceAtopFast, sourceAtopPerfect, sourceInFast, sourceInPerfect, sourceOutFast, sourceOutPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, uInt32ArrayToPixelData, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer, xorFast, xorPerfect };
|
|
1950
|
+
export { type AlphaMask, AlphaMaskPaintBuffer, type AlphaMaskPaintBufferCanvasRenderer, type AlphaMaskPaintBufferManager, type AlphaMaskRect, type AlphaMaskTile, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BatchedQueue, type BatchedQueueFn, type BinaryMask, BinaryMaskPaintBuffer, type BinaryMaskPaintBufferCanvasRenderer, type BinaryMaskPaintBufferManager, type BinaryMaskRect, type BinaryMaskTile, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type CanvasObjectFactory, type CanvasPixelDataRenderer, type ClippedBlit, type ClippedRect, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, ColorPaintBuffer, type ColorPaintBufferCanvasRenderer, type ColorPaintBufferManager, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, _errors as ERRORS, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type ImageDataLike, type IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type MutableAlphaMask, type MutableBinaryMask, type MutableMask, type MutablePixelData32, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, type PaintCursorRenderer, type PaintMask, PaintMaskOutline, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, type PixelData, type PixelData32, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, type PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableCanvasFactory, type ReusableImageData, type ReusablePixelData, type SerializedImageData, type Tile, type TileFactory, TilePool, TileType, UnsupportedFormatError, _macro_imageDataToUint32Array, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, commitColorPaintBuffer, commitMaskPaintBuffer, copyImageData, copyImageDataLike, copyMask, copyPixelData, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, destinationAtopFast, destinationAtopPerfect, destinationInFast, destinationInPerfect, destinationOutFast, destinationOutPerfect, destinationOverFast, destinationOverPerfect, differenceFast, differencePerfect, divideFast, dividePerfect, eachTileInBounds, exclusionFast, exclusionPerfect, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColor, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUint32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeAlphaMaskPaintBufferCanvasRenderer, makeAlphaMaskPaintBufferCommitter, makeAlphaMaskPaintBufferManager, makeAlphaMaskTile, makeBatchedQueue, makeBinaryMask, makeBinaryMaskFromAlphaMask, makeBinaryMaskOutline, makeBinaryMaskPaintBufferCanvasRenderer, makeBinaryMaskPaintBufferCommitter, makeBinaryMaskPaintBufferManager, makeBinaryMaskTile, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCanvasPixelDataRenderer, makeCircleBinaryMaskOutline, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeClippedBlit, makeClippedRect, makeColorPaintBufferCanvasRenderer, makeColorPaintBufferCommitter, makeColorPaintBufferManager, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makeIndexedImage, makeIndexedImageFromImageData, makeIndexedImageFromImageDataRaw, makePaintAlphaMask, makePaintBinaryMask, makePaintCursorRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makePixelData, makePixelTile, makeRectBinaryMaskOutline, makeRectFalloffPaintAlphaMask, makeRenderQueue, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, makeReusablePixelData, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resamplePixelDataInPlace, resampleUint32Array, resizeImageData, resolveBlitClipping, resolveRectClipping, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, setPixelData, softLightFast, softLightPerfect, sourceAtopFast, sourceAtopPerfect, sourceInFast, sourceInPerfect, sourceOutFast, sourceOutPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, uInt32ArrayToPixelData, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer, xorFast, xorPerfect };
|
package/dist/index.prod.js
CHANGED
|
@@ -2025,6 +2025,67 @@ async function writeImageDataToClipboard(imageData) {
|
|
|
2025
2025
|
return writeImgBlobToClipboard(blob);
|
|
2026
2026
|
}
|
|
2027
2027
|
|
|
2028
|
+
// src/Control/BatchedQueue.ts
|
|
2029
|
+
function makeBatchedQueue(processor, queue) {
|
|
2030
|
+
let activeSet = /* @__PURE__ */ new Set();
|
|
2031
|
+
let processingSet = /* @__PURE__ */ new Set();
|
|
2032
|
+
let scheduled = false;
|
|
2033
|
+
const flush = () => {
|
|
2034
|
+
const current = activeSet;
|
|
2035
|
+
activeSet = processingSet;
|
|
2036
|
+
processingSet = current;
|
|
2037
|
+
scheduled = false;
|
|
2038
|
+
try {
|
|
2039
|
+
processor(processingSet);
|
|
2040
|
+
} finally {
|
|
2041
|
+
processingSet.clear();
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
function markDirty(item) {
|
|
2045
|
+
activeSet.add(item);
|
|
2046
|
+
if (!scheduled) {
|
|
2047
|
+
scheduled = true;
|
|
2048
|
+
queue(flush);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
function markMultipleDirty(items) {
|
|
2052
|
+
let len = items.length;
|
|
2053
|
+
if (len === 0) return;
|
|
2054
|
+
for (let i = 0; i < len; i++) {
|
|
2055
|
+
activeSet.add(items[i]);
|
|
2056
|
+
}
|
|
2057
|
+
if (!scheduled) {
|
|
2058
|
+
scheduled = true;
|
|
2059
|
+
queue(flush);
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
return {
|
|
2063
|
+
markDirty,
|
|
2064
|
+
markMultipleDirty
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
// src/Control/RenderQueue.ts
|
|
2069
|
+
function makeRenderQueue(cb) {
|
|
2070
|
+
let needsRender = false;
|
|
2071
|
+
let frameId = 0;
|
|
2072
|
+
const trigger = () => {
|
|
2073
|
+
if (needsRender) return;
|
|
2074
|
+
needsRender = true;
|
|
2075
|
+
frameId = requestAnimationFrame(() => {
|
|
2076
|
+
needsRender = false;
|
|
2077
|
+
cb();
|
|
2078
|
+
});
|
|
2079
|
+
};
|
|
2080
|
+
trigger.cancel = () => {
|
|
2081
|
+
if (needsRender) {
|
|
2082
|
+
cancelAnimationFrame(frameId);
|
|
2083
|
+
needsRender = false;
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
return trigger;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2028
2089
|
// src/History/PixelPatchTiles.ts
|
|
2029
2090
|
function applyPatchTiles(target, tiles, tileSize) {
|
|
2030
2091
|
for (let i = 0; i < tiles.length; i++) {
|
|
@@ -2050,19 +2111,17 @@ function applyPatchTiles(target, tiles, tileSize) {
|
|
|
2050
2111
|
}
|
|
2051
2112
|
|
|
2052
2113
|
// src/History/HistoryAction.ts
|
|
2053
|
-
function makeHistoryAction(config, accumulator, patch,
|
|
2114
|
+
function makeHistoryAction(config, accumulator, patch, afterUndo, afterRedo, applyPatchTilesFn = applyPatchTiles) {
|
|
2054
2115
|
const target = config.target;
|
|
2055
2116
|
const tileSize = config.tileSize;
|
|
2056
2117
|
return {
|
|
2057
2118
|
undo: () => {
|
|
2058
2119
|
applyPatchTilesFn(target, patch.beforeTiles, tileSize);
|
|
2059
|
-
afterUndo?.();
|
|
2060
|
-
after?.();
|
|
2120
|
+
afterUndo?.(patch);
|
|
2061
2121
|
},
|
|
2062
2122
|
redo: () => {
|
|
2063
2123
|
applyPatchTilesFn(target, patch.afterTiles, tileSize);
|
|
2064
|
-
afterRedo?.();
|
|
2065
|
-
after?.();
|
|
2124
|
+
afterRedo?.(patch);
|
|
2066
2125
|
},
|
|
2067
2126
|
dispose: () => accumulator.recyclePatch(patch)
|
|
2068
2127
|
};
|
|
@@ -2589,11 +2648,10 @@ var PixelWriter = class {
|
|
|
2589
2648
|
* throw immediately to prevent silent data loss from a nested extractPatch.
|
|
2590
2649
|
*
|
|
2591
2650
|
* @param transaction Callback to be executed inside the transaction.
|
|
2592
|
-
* @param
|
|
2593
|
-
* @param afterUndo Called after undo only — use for dimension or state changes specific to undo.
|
|
2651
|
+
* @param afterUndo Called after undo only.
|
|
2594
2652
|
* @param afterRedo Called after redo only.
|
|
2595
2653
|
*/
|
|
2596
|
-
withHistory(transaction,
|
|
2654
|
+
withHistory(transaction, afterUndo, afterRedo) {
|
|
2597
2655
|
if (this._inProgress) {
|
|
2598
2656
|
throw new Error("withHistory is not re-entrant \u2014 commit or rollback the current operation first");
|
|
2599
2657
|
}
|
|
@@ -2608,10 +2666,10 @@ var PixelWriter = class {
|
|
|
2608
2666
|
}
|
|
2609
2667
|
if (this.accumulator.beforeTiles.length === 0) return;
|
|
2610
2668
|
const patch = this.accumulator.extractPatch();
|
|
2611
|
-
const action = this.historyActionFactory(this.config, this.accumulator, patch,
|
|
2669
|
+
const action = this.historyActionFactory(this.config, this.accumulator, patch, afterUndo, afterRedo);
|
|
2612
2670
|
this.historyManager.commit(action);
|
|
2613
2671
|
}
|
|
2614
|
-
resize(newWidth, newHeight, offsetX = 0, offsetY = 0,
|
|
2672
|
+
resize(newWidth, newHeight, offsetX = 0, offsetY = 0, afterUndo, afterRedo, resizeImageDataFn = resizeImageData) {
|
|
2615
2673
|
if (this._inProgress) {
|
|
2616
2674
|
throw new Error("Cannot resize inside a withHistory callback");
|
|
2617
2675
|
}
|
|
@@ -2627,12 +2685,10 @@ var PixelWriter = class {
|
|
|
2627
2685
|
undo: () => {
|
|
2628
2686
|
setPixelData(target, beforeImageData);
|
|
2629
2687
|
afterUndo?.(beforeImageData);
|
|
2630
|
-
after?.(beforeImageData);
|
|
2631
2688
|
},
|
|
2632
2689
|
redo: () => {
|
|
2633
2690
|
setPixelData(target, afterImageData);
|
|
2634
2691
|
afterRedo?.(afterImageData);
|
|
2635
|
-
after?.(afterImageData);
|
|
2636
2692
|
}
|
|
2637
2693
|
});
|
|
2638
2694
|
}
|
|
@@ -6426,6 +6482,7 @@ export {
|
|
|
6426
6482
|
makeAlphaMaskPaintBufferCommitter,
|
|
6427
6483
|
makeAlphaMaskPaintBufferManager,
|
|
6428
6484
|
makeAlphaMaskTile,
|
|
6485
|
+
makeBatchedQueue,
|
|
6429
6486
|
makeBinaryMask,
|
|
6430
6487
|
makeBinaryMaskFromAlphaMask,
|
|
6431
6488
|
makeBinaryMaskOutline,
|
|
@@ -6460,6 +6517,7 @@ export {
|
|
|
6460
6517
|
makePixelTile,
|
|
6461
6518
|
makeRectBinaryMaskOutline,
|
|
6462
6519
|
makeRectFalloffPaintAlphaMask,
|
|
6520
|
+
makeRenderQueue,
|
|
6463
6521
|
makeReusableCanvas,
|
|
6464
6522
|
makeReusableImageData,
|
|
6465
6523
|
makeReusableOffscreenCanvas,
|