pixel-data-js 0.3.0 → 0.5.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.
Files changed (40) hide show
  1. package/dist/index.dev.cjs +1405 -70
  2. package/dist/index.dev.cjs.map +1 -1
  3. package/dist/index.dev.js +1355 -68
  4. package/dist/index.dev.js.map +1 -1
  5. package/dist/index.prod.cjs +1405 -70
  6. package/dist/index.prod.cjs.map +1 -1
  7. package/dist/index.prod.d.ts +581 -64
  8. package/dist/index.prod.js +1355 -68
  9. package/dist/index.prod.js.map +1 -1
  10. package/package.json +14 -3
  11. package/src/Algorithm/floodFillSelection.ts +229 -0
  12. package/src/Canvas/PixelCanvas.ts +31 -0
  13. package/src/Canvas/ReusableCanvas.ts +44 -0
  14. package/src/Canvas/_constants.ts +2 -0
  15. package/src/Clipboard/getImageDataFromClipboard.ts +42 -0
  16. package/src/Clipboard/writeImageDataToClipboard.ts +25 -0
  17. package/src/Clipboard/writeImgBlobToClipboard.ts +13 -0
  18. package/src/ImageData/{extractImageData.ts → extractImageDataPixels.ts} +21 -3
  19. package/src/ImageData/imageDataToAlphaMask.ts +35 -0
  20. package/src/ImageData/imageDataToDataUrl.ts +27 -0
  21. package/src/ImageData/imageDataToImgBlob.ts +31 -0
  22. package/src/ImageData/imgBlobToImageData.ts +52 -0
  23. package/src/ImageData/invertImageData.ts +10 -0
  24. package/src/ImageData/resizeImageData.ts +75 -0
  25. package/src/ImageData/{writeImageData.ts → writeImageDataPixels.ts} +22 -3
  26. package/src/Input/fileInputChangeToImageData.ts +37 -0
  27. package/src/Input/fileToImageData.ts +75 -0
  28. package/src/Input/getSupportedRasterFormats.ts +74 -0
  29. package/src/Mask/extractMask.ts +86 -0
  30. package/src/Mask/mergeMasks.ts +1 -6
  31. package/src/PixelData/blendColorPixelData.ts +9 -9
  32. package/src/PixelData/fillPixelData.ts +51 -12
  33. package/src/PixelData/invertPixelData.ts +16 -0
  34. package/src/PixelData/pixelDataToAlphaMask.ts +28 -0
  35. package/src/Rect/trimRectBounds.ts +118 -0
  36. package/src/_types.ts +37 -20
  37. package/src/blend-modes.ts +506 -66
  38. package/src/color.ts +6 -6
  39. package/src/globals.d.ts +2 -0
  40. package/src/index.ts +37 -1
package/src/_types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { sourceOverColor32 } from './blend-modes'
2
+
1
3
  /** ALL values are 0-255 (including alpha which in CSS is 0-1) */
2
4
  export type RGBA = { r: number, g: number, b: number, a: number }
3
5
 
@@ -15,7 +17,7 @@ export type BlendColor32 = (src: Color32, dst: Color32) => Color32
15
17
  export type ImageDataLike = {
16
18
  width: number
17
19
  height: number
18
- data: Uint8ClampedArray<ArrayBuffer>
20
+ data: Uint8ClampedArray<ArrayBufferLike>
19
21
  }
20
22
 
21
23
  export type SerializedImageData = {
@@ -64,23 +66,23 @@ export type AnyMask = BinaryMask | AlphaMask
64
66
  export interface PixelOptions {
65
67
  /**
66
68
  * The starting X coordinate in the destination buffer.
67
- * @Defaults 0.
68
- * */
69
+ * @default 0
70
+ */
69
71
  x?: number
70
72
  /**
71
73
  * The starting Y coordinate in the destination buffer.
72
- * @Default 0.
73
- * */
74
+ * @default 0
75
+ */
74
76
  y?: number
75
77
  /**
76
78
  * The width of the region to process.
77
- * @Default Source width.
78
- * */
79
+ * @default Source width.
80
+ */
79
81
  w?: number
80
82
  /**
81
83
  * The height of the region to process.
82
- * @Default Source height.
83
- * */
84
+ * @default Source height.
85
+ */
84
86
  h?: number
85
87
 
86
88
  /**
@@ -91,29 +93,34 @@ export interface PixelOptions {
91
93
 
92
94
  /**
93
95
  * Mask width.
94
- * @default w
95
- * */
96
+ * @default value of `w`
97
+ */
96
98
  mw?: number
97
99
 
98
100
  /**
99
101
  * X offset into the mask buffer.
100
102
  * @default 0
101
- * */
103
+ */
102
104
  mx?: number
103
105
 
104
106
  /**
105
107
  * Y offset into the mask buffer.
106
108
  * @default 0
107
- * */
109
+ */
108
110
  my?: number
109
111
 
110
112
  /** An optional mask to restrict where pixels are written. */
111
113
  mask?: AnyMask | null
112
114
 
113
- /** The interpretation logic for the provided mask. Defaults to MaskType.Binary. */
115
+ /** The interpretation logic for the provided mask.
116
+ * @default {@link MaskType.BINARY}
117
+ */
114
118
  maskType?: MaskType
115
119
 
116
- /** If true the inverse of the mask will be applied */
120
+ /**
121
+ * If true the inverse of the mask will be applied
122
+ * @default false
123
+ */
117
124
  invertMask?: boolean
118
125
  }
119
126
 
@@ -133,7 +140,10 @@ export interface PixelBlendOptions extends PixelOptions {
133
140
  */
134
141
  sy?: number
135
142
 
136
- /** The specific blending function/algorithm to use for pixel math. */
143
+ /**
144
+ * The blending algorithm to use for blending pixels.
145
+ * @default {@link sourceOverColor32}
146
+ */
137
147
  blendFn?: BlendColor32
138
148
  }
139
149
 
@@ -141,12 +151,19 @@ export interface PixelBlendOptions extends PixelOptions {
141
151
  * Configuration for operations that require color blending.
142
152
  */
143
153
  export interface ColorBlendOptions extends PixelOptions {
144
- /** The blending logic used to combine source and destination pixels. */
154
+ /**
155
+ * The blending algorithm to use for blending pixels.
156
+ * @default {@link sourceOverColor32}
157
+ */
145
158
  blendFn?: BlendColor32
146
159
  }
147
160
 
148
161
  export type ApplyMaskOptions = Omit<PixelOptions, 'mask'>
149
162
 
150
- // export function invertBinaryMask(dst: BinaryMask): void
151
- // export function invertAlphaMask(dst: AlphaMask): void
152
-
163
+ export type SelectionRect = Rect & ({
164
+ mask: Uint8Array,
165
+ maskType: MaskType,
166
+ } | {
167
+ mask?: null
168
+ maskType?: null,
169
+ })