pixel-data-js 0.28.0 → 0.30.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 +297 -245
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +43 -34
- package/dist/index.prod.js +289 -245
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/Canvas/CanvasFrameRenderer.ts +2 -2
- package/src/History/HistoryAction.ts +4 -7
- package/src/Internal/_constants.ts +3 -0
- package/src/Paint/AlphaMaskPaintBuffer.ts +0 -56
- package/src/Paint/BinaryMaskPaintBuffer.ts +0 -56
- package/src/Paint/ColorPaintBuffer.ts +0 -53
- package/src/Paint/Commit/AlphaMaskPaintBufferCommitter.ts +26 -0
- package/src/Paint/Commit/AlphaMaskPaintBufferManager.ts +34 -0
- package/src/Paint/Commit/BinaryMaskPaintBufferCommitter.ts +26 -0
- package/src/Paint/Commit/BinaryMaskPaintBufferManager.ts +31 -0
- package/src/Paint/Commit/ColorPaintBufferCommitter.ts +23 -0
- package/src/Paint/Commit/ColorPaintBufferManager.ts +34 -0
- package/src/Paint/Commit/commitColorPaintBuffer.ts +55 -0
- package/src/Paint/Commit/commitMaskPaintBuffer.ts +78 -0
- package/src/Paint/{AlphaMaskPaintBufferCanvasRenderer.ts → Render/AlphaMaskPaintBufferCanvasRenderer.ts} +9 -9
- package/src/Paint/{BinaryMaskPaintBufferCanvasRenderer.ts → Render/BinaryMaskPaintBufferCanvasRenderer.ts} +9 -9
- package/src/Paint/{ColorPaintBufferCanvasRenderer.ts → Render/ColorPaintBufferCanvasRenderer.ts} +8 -10
- package/src/Paint/{PaintCursorRenderer.ts → Render/PaintCursorRenderer.ts} +23 -22
- package/src/index.ts +15 -4
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type { Color32 } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import type { Color32 } from '../../_types'
|
|
2
|
+
import type { CanvasObjectFactory } from '../../Canvas/_canvas-types'
|
|
3
|
+
import { DEFAULT_CANVAS_FACTORY } from '../../Internal/_constants'
|
|
4
|
+
import { CANVAS_CTX_FAILED } from '../../Internal/_errors'
|
|
5
|
+
import { makePixelData } from '../../PixelData/PixelData'
|
|
6
|
+
import type { BinaryMaskPaintBuffer } from '../BinaryMaskPaintBuffer'
|
|
5
7
|
|
|
6
8
|
export type BinaryMaskPaintBufferCanvasRenderer = ReturnType<typeof makeBinaryMaskPaintBufferCanvasRenderer>
|
|
7
9
|
|
|
8
10
|
export function makeBinaryMaskPaintBufferCanvasRenderer(
|
|
9
11
|
paintBuffer: BinaryMaskPaintBuffer,
|
|
10
|
-
|
|
12
|
+
canvasFactory: CanvasObjectFactory<any> = DEFAULT_CANVAS_FACTORY,
|
|
11
13
|
) {
|
|
12
14
|
const config = paintBuffer.config
|
|
13
15
|
const tileSize = config.tileSize
|
|
@@ -15,18 +17,16 @@ export function makeBinaryMaskPaintBufferCanvasRenderer(
|
|
|
15
17
|
const tileArea = config.tileArea
|
|
16
18
|
const lookup = paintBuffer.lookup
|
|
17
19
|
|
|
18
|
-
const canvas =
|
|
20
|
+
const canvas = canvasFactory(tileSize, tileSize)
|
|
19
21
|
const ctx = canvas.getContext('2d')
|
|
20
|
-
|
|
21
22
|
if (!ctx) throw new Error(CANVAS_CTX_FAILED)
|
|
22
|
-
|
|
23
23
|
ctx.imageSmoothingEnabled = false
|
|
24
24
|
|
|
25
25
|
const bridge = makePixelData(new ImageData(tileSize, tileSize))
|
|
26
26
|
const view32 = bridge.data
|
|
27
27
|
|
|
28
28
|
return function drawPaintBuffer(
|
|
29
|
-
targetCtx: CanvasRenderingContext2D,
|
|
29
|
+
targetCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,
|
|
30
30
|
color: Color32,
|
|
31
31
|
alpha = 255,
|
|
32
32
|
compOperation: GlobalCompositeOperation = 'source-over',
|
package/src/Paint/{ColorPaintBufferCanvasRenderer.ts → Render/ColorPaintBufferCanvasRenderer.ts}
RENAMED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { CanvasObjectFactory } from '../../Canvas/_canvas-types'
|
|
2
|
+
import { DEFAULT_CANVAS_FACTORY } from '../../Internal/_constants'
|
|
3
|
+
import { CANVAS_CTX_FAILED } from '../../Internal/_errors'
|
|
4
|
+
import type { ColorPaintBuffer } from '../ColorPaintBuffer'
|
|
3
5
|
|
|
4
6
|
export type ColorPaintBufferCanvasRenderer = ReturnType<typeof makeColorPaintBufferCanvasRenderer>
|
|
5
7
|
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param paintBuffer
|
|
9
|
-
* @param offscreenCanvasClass - @internal
|
|
10
|
-
*/
|
|
11
8
|
export function makeColorPaintBufferCanvasRenderer(
|
|
12
9
|
paintBuffer: ColorPaintBuffer,
|
|
13
|
-
|
|
10
|
+
canvasFactory: CanvasObjectFactory<any> = DEFAULT_CANVAS_FACTORY,
|
|
14
11
|
) {
|
|
15
12
|
const config = paintBuffer.config
|
|
16
13
|
const tileSize = config.tileSize
|
|
17
14
|
const tileShift = config.tileShift
|
|
18
15
|
const lookup = paintBuffer.lookup
|
|
19
|
-
|
|
16
|
+
|
|
17
|
+
const canvas = canvasFactory(tileSize, tileSize)
|
|
20
18
|
const ctx = canvas.getContext('2d')
|
|
21
19
|
if (!ctx) throw new Error(CANVAS_CTX_FAILED)
|
|
22
20
|
ctx.imageSmoothingEnabled = false
|
|
23
21
|
|
|
24
22
|
return function drawPaintBuffer(
|
|
25
|
-
targetCtx: CanvasRenderingContext2D,
|
|
23
|
+
targetCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,
|
|
26
24
|
alpha = 255,
|
|
27
25
|
compOperation: GlobalCompositeOperation = 'source-over',
|
|
28
26
|
): void {
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { type Color32 } from '
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { _macro_paintRectCenterOffset } from '
|
|
6
|
-
import { type BinaryMask, MaskType } from '
|
|
7
|
-
import { makeBinaryMaskFromAlphaMask } from '
|
|
8
|
-
import { makeBinaryMaskOutline } from '
|
|
9
|
-
import { makeCircleBinaryMaskOutline } from '
|
|
10
|
-
import { makeRectBinaryMaskOutline } from '
|
|
11
|
-
import { fillPixelDataBinaryMask } from '
|
|
12
|
-
import { makeReusablePixelData } from '
|
|
13
|
-
import type { Rect } from '
|
|
14
|
-
import { type PaintMask, PaintMaskOutline } from '
|
|
1
|
+
import { type Color32 } from '../../_types'
|
|
2
|
+
import type { ReusableCanvasFactory } from '../../Canvas/_canvas-types'
|
|
3
|
+
import { makeReusableOffscreenCanvas } from '../../Canvas/ReusableCanvas'
|
|
4
|
+
import { packColor } from '../../color'
|
|
5
|
+
import { _macro_paintRectCenterOffset } from '../../Internal/macros'
|
|
6
|
+
import { type BinaryMask, MaskType } from '../../Mask/_mask-types'
|
|
7
|
+
import { makeBinaryMaskFromAlphaMask } from '../../Mask/BinaryMask/makeBinaryMaskFromAlphaMask'
|
|
8
|
+
import { makeBinaryMaskOutline } from '../../Mask/BinaryMask/makeBinaryMaskOutline'
|
|
9
|
+
import { makeCircleBinaryMaskOutline } from '../../Mask/BinaryMask/makeCircleBinaryMaskOutline'
|
|
10
|
+
import { makeRectBinaryMaskOutline } from '../../Mask/BinaryMask/makeRectBinaryMaskOutline'
|
|
11
|
+
import { fillPixelDataBinaryMask } from '../../PixelData/fillPixelDataBinaryMask'
|
|
12
|
+
import { makeReusablePixelData } from '../../PixelData/ReusablePixelData'
|
|
13
|
+
import type { Rect } from '../../Rect/_rect-types'
|
|
14
|
+
import { type PaintMask, PaintMaskOutline } from '../_paint-types'
|
|
15
15
|
|
|
16
16
|
export type PaintCursorRenderer = ReturnType<typeof makePaintCursorRenderer>
|
|
17
17
|
|
|
18
|
-
export function makePaintCursorRenderer<T extends HTMLCanvasElement | OffscreenCanvas>(
|
|
19
|
-
|
|
18
|
+
export function makePaintCursorRenderer<T extends HTMLCanvasElement | OffscreenCanvas = OffscreenCanvas>(
|
|
19
|
+
reusableCanvasFactory?: () => ReusableCanvasFactory<T>,
|
|
20
20
|
) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
ctx.imageSmoothingEnabled = false
|
|
21
|
+
const factory = (reusableCanvasFactory ?? makeReusableOffscreenCanvas) as unknown as () => ReusableCanvasFactory<T>
|
|
22
|
+
const updateBuffer = factory()
|
|
23
|
+
const { canvas, ctx } = updateBuffer(1, 1)
|
|
25
24
|
|
|
26
25
|
const getPixelData = makeReusablePixelData()
|
|
27
26
|
|
|
@@ -45,8 +44,10 @@ export function makePaintCursorRenderer<T extends HTMLCanvasElement | OffscreenC
|
|
|
45
44
|
_scale = scale ?? _scale
|
|
46
45
|
_color = color ?? _color
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
updateBuffer(
|
|
48
|
+
currentMask.w * _scale + 2 * _scale,
|
|
49
|
+
currentMask.h * _scale + 2 * _scale,
|
|
50
|
+
)
|
|
50
51
|
|
|
51
52
|
if (currentMask.type === MaskType.BINARY) {
|
|
52
53
|
if (currentMask.outlineType === PaintMaskOutline.CIRCLE) {
|
package/src/index.ts
CHANGED
|
@@ -106,16 +106,27 @@ export * from './MaskRect/subtractBinaryMaskRects'
|
|
|
106
106
|
|
|
107
107
|
export * from './Paint/_paint-types'
|
|
108
108
|
export * from './Paint/AlphaMaskPaintBuffer'
|
|
109
|
-
export * from './Paint/AlphaMaskPaintBufferCanvasRenderer'
|
|
110
109
|
export * from './Paint/BinaryMaskPaintBuffer'
|
|
111
|
-
export * from './Paint/BinaryMaskPaintBufferCanvasRenderer'
|
|
112
110
|
export * from './Paint/ColorPaintBuffer'
|
|
113
|
-
|
|
111
|
+
|
|
112
|
+
export * from './Paint/Commit/AlphaMaskPaintBufferCommitter'
|
|
113
|
+
export * from './Paint/Commit/AlphaMaskPaintBufferManager'
|
|
114
|
+
export * from './Paint/Commit/BinaryMaskPaintBufferCommitter'
|
|
115
|
+
export * from './Paint/Commit/BinaryMaskPaintBufferManager'
|
|
116
|
+
export * from './Paint/Commit/ColorPaintBufferCommitter'
|
|
117
|
+
export * from './Paint/Commit/ColorPaintBufferManager'
|
|
118
|
+
export * from './Paint/Commit/commitColorPaintBuffer'
|
|
119
|
+
export * from './Paint/Commit/commitMaskPaintBuffer'
|
|
120
|
+
|
|
114
121
|
export * from './Paint/eachTileInBounds'
|
|
115
122
|
export * from './Paint/makeCirclePaintMask'
|
|
116
123
|
export * from './Paint/makePaintMask'
|
|
117
124
|
export * from './Paint/makeRectFalloffPaintAlphaMask'
|
|
118
|
-
|
|
125
|
+
|
|
126
|
+
export * from './Paint/Render/AlphaMaskPaintBufferCanvasRenderer'
|
|
127
|
+
export * from './Paint/Render/BinaryMaskPaintBufferCanvasRenderer'
|
|
128
|
+
export * from './Paint/Render/ColorPaintBufferCanvasRenderer'
|
|
129
|
+
export * from './Paint/Render/PaintCursorRenderer'
|
|
119
130
|
|
|
120
131
|
export * from './PixelData/_pixelData-types'
|
|
121
132
|
export * from './PixelData/applyAlphaMaskToPixelData'
|