pixel-data-js 0.22.2 → 0.23.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pixel-data-js",
3
3
  "type": "module",
4
- "version": "0.22.2",
4
+ "version": "0.23.1",
5
5
  "packageManager": "pnpm@10.30.0",
6
6
  "description": "JS Pixel and ImageData operations",
7
7
  "author": {
@@ -16,7 +16,7 @@ export const mutatorBlendPixelData = ((writer: PixelWriter<any>, deps: Partial<D
16
16
  return {
17
17
  blendPixelData(
18
18
  src: IPixelData,
19
- opts: PixelBlendOptions,
19
+ opts: PixelBlendOptions = {},
20
20
  ) {
21
21
  const {
22
22
  x = 0,
@@ -0,0 +1,33 @@
1
+ import type { AlphaMask, HistoryMutator, IPixelData, PixelBlendMaskOptions } from '../../_types'
2
+ import { blendPixelDataAlphaMask } from '../../PixelData/blendPixelDataAlphaMask'
3
+ import { PixelWriter } from '../PixelWriter'
4
+
5
+ const defaults = { blendPixelDataAlphaMask }
6
+ type Deps = Partial<typeof defaults>
7
+
8
+ /**
9
+ * @param deps - @hidden
10
+ */
11
+ export const mutatorBlendPixelDataAlphaMask = ((writer: PixelWriter<any>, deps: Partial<Deps> = defaults) => {
12
+ const {
13
+ blendPixelDataAlphaMask = defaults.blendPixelDataAlphaMask,
14
+ } = deps
15
+
16
+ return {
17
+ blendPixelDataAlphaMask(
18
+ src: IPixelData,
19
+ mask: AlphaMask,
20
+ opts: PixelBlendMaskOptions = {},
21
+ ) {
22
+ const x = opts.x ?? 0
23
+ const y = opts.y ?? 0
24
+ const w = opts.w ?? src.width
25
+ const h = opts.h ?? src.height
26
+
27
+ writer.accumulator.storeRegionBeforeState(x, y, w, h)
28
+
29
+ blendPixelDataAlphaMask(writer.target, src, mask, opts)
30
+ },
31
+ }
32
+ }) satisfies HistoryMutator<any, Deps>
33
+
@@ -0,0 +1,33 @@
1
+ import type { BinaryMask, HistoryMutator, IPixelData, PixelBlendMaskOptions } from '../../_types'
2
+ import { blendPixelDataBinaryMask } from '../../PixelData/blendPixelDataBinaryMask'
3
+ import { PixelWriter } from '../PixelWriter'
4
+
5
+ const defaults = { blendPixelDataBinaryMask }
6
+ type Deps = Partial<typeof defaults>
7
+
8
+ /**
9
+ * @param deps - @hidden
10
+ */
11
+ export const mutatorBlendPixelDataBinaryMask = ((writer: PixelWriter<any>, deps: Partial<Deps> = defaults) => {
12
+ const {
13
+ blendPixelDataBinaryMask = defaults.blendPixelDataBinaryMask,
14
+ } = deps
15
+
16
+ return {
17
+ blendPixelDataBinaryMask(
18
+ src: IPixelData,
19
+ mask: BinaryMask,
20
+ opts: PixelBlendMaskOptions = {},
21
+ ) {
22
+ const x = opts.x ?? 0
23
+ const y = opts.y ?? 0
24
+ const w = opts.w ?? src.width
25
+ const h = opts.h ?? src.height
26
+
27
+ writer.accumulator.storeRegionBeforeState(x, y, w, h)
28
+
29
+ blendPixelDataBinaryMask(writer.target, src, mask, opts)
30
+ },
31
+ }
32
+ }) satisfies HistoryMutator<any, Deps>
33
+
@@ -1,4 +1,4 @@
1
- import type { BinaryMaskRect, Color32, HistoryMutator } from '../../_types'
1
+ import type { Color32, HistoryMutator, Rect } from '../../_types'
2
2
  import { fillPixelData } from '../../PixelData/fillPixelData'
3
3
  import { PixelWriter } from '../PixelWriter'
4
4
 
@@ -16,7 +16,7 @@ export const mutatorClear = ((writer: PixelWriter<any>, deps: Deps = defaults) =
16
16
 
17
17
  return {
18
18
  clear(
19
- rect: Partial<BinaryMaskRect> = {},
19
+ rect: Partial<Rect> = {},
20
20
  ) {
21
21
  const x = rect.x ?? 0
22
22
  const y = rect.y ?? 0
@@ -2,6 +2,7 @@ import { mutatorApplyAlphaMask } from './PixelMutator/mutatorApplyAlphaMask'
2
2
  import { mutatorApplyBinaryMask } from './PixelMutator/mutatorApplyBinaryMask'
3
3
  import { mutatorApplyCircleBrush } from './PixelMutator/mutatorApplyCircleBrush'
4
4
  import { mutatorApplyCircleBrushStroke } from './PixelMutator/mutatorApplyCircleBrushStroke'
5
+ import { mutatorApplyCirclePencil } from './PixelMutator/mutatorApplyCirclePencil'
5
6
  import { mutatorApplyCirclePencilStroke } from './PixelMutator/mutatorApplyCirclePencilStroke'
6
7
  import { mutatorApplyRectBrush } from './PixelMutator/mutatorApplyRectBrush'
7
8
  import { mutatorApplyRectBrushStroke } from './PixelMutator/mutatorApplyRectBrushStroke'
@@ -10,33 +11,35 @@ import { mutatorApplyRectPencilStroke } from './PixelMutator/mutatorApplyRectPen
10
11
  import { mutatorBlendColor } from './PixelMutator/mutatorBlendColor'
11
12
  import { mutatorBlendPixel } from './PixelMutator/mutatorBlendPixel'
12
13
  import { mutatorBlendPixelData } from './PixelMutator/mutatorBlendPixelData'
14
+ import { mutatorBlendPixelDataAlphaMask } from './PixelMutator/mutatorBlendPixelDataAlphaMask'
15
+ import { mutatorBlendPixelDataBinaryMask } from './PixelMutator/mutatorBlendPixelDataBinaryMask'
13
16
  import { mutatorClear } from './PixelMutator/mutatorClear'
14
17
  import { mutatorFill } from './PixelMutator/mutatorFill'
18
+ import { mutatorFillBinaryMask } from './PixelMutator/mutatorFillBinaryMask'
15
19
  import { mutatorInvert } from './PixelMutator/mutatorInvert'
16
20
  import type { PixelWriter } from './PixelWriter'
17
21
 
18
22
  export function makeFullPixelMutator(writer: PixelWriter<any>) {
19
23
  return {
24
+ // @sort
20
25
  ...mutatorApplyAlphaMask(writer),
21
26
  ...mutatorApplyBinaryMask(writer),
22
-
23
- ...mutatorBlendPixelData(writer),
24
- ...mutatorBlendColor(writer),
25
- ...mutatorBlendPixel(writer),
26
- ...mutatorFill(writer),
27
- ...mutatorInvert(writer),
28
-
29
27
  ...mutatorApplyCircleBrush(writer),
30
28
  ...mutatorApplyCircleBrushStroke(writer),
31
-
29
+ ...mutatorApplyCirclePencil(writer),
32
30
  ...mutatorApplyCirclePencilStroke(writer),
33
-
34
31
  ...mutatorApplyRectBrush(writer),
35
32
  ...mutatorApplyRectBrushStroke(writer),
36
-
37
33
  ...mutatorApplyRectPencil(writer),
38
34
  ...mutatorApplyRectPencilStroke(writer),
39
-
35
+ ...mutatorBlendColor(writer),
36
+ ...mutatorBlendPixel(writer),
37
+ ...mutatorBlendPixelData(writer),
38
+ ...mutatorBlendPixelDataAlphaMask(writer),
39
+ ...mutatorBlendPixelDataBinaryMask(writer),
40
40
  ...mutatorClear(writer),
41
+ ...mutatorFill(writer),
42
+ ...mutatorFillBinaryMask(writer),
43
+ ...mutatorInvert(writer),
41
44
  }
42
45
  }
@@ -18,7 +18,7 @@ import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
18
18
  export function blendPixelData(
19
19
  dst: IPixelData,
20
20
  src: IPixelData,
21
- opts: PixelBlendOptions,
21
+ opts: PixelBlendOptions = {},
22
22
  ) {
23
23
  const {
24
24
  x: targetX = 0,
@@ -5,7 +5,7 @@ export function blendPixelDataBinaryMask(
5
5
  dst: IPixelData,
6
6
  src: IPixelData,
7
7
  binaryMask: BinaryMask,
8
- opts: PixelBlendMaskOptions,
8
+ opts: PixelBlendMaskOptions = {},
9
9
  ) {
10
10
  const {
11
11
  x: targetX = 0,
package/src/index.ts CHANGED
@@ -43,6 +43,8 @@ export * from './History/PixelMutator/mutatorApplyRectBrushStroke'
43
43
  export * from './History/PixelMutator/mutatorBlendColor'
44
44
  export * from './History/PixelMutator/mutatorBlendPixel'
45
45
  export * from './History/PixelMutator/mutatorBlendPixelData'
46
+ export * from './History/PixelMutator/mutatorBlendPixelDataAlphaMask'
47
+ export * from './History/PixelMutator/mutatorBlendPixelDataBinaryMask'
46
48
  export * from './History/PixelMutator/mutatorClear'
47
49
  export * from './History/PixelMutator/mutatorFill'
48
50
  export * from './History/PixelMutator/mutatorFillBinaryMask'