pixel-data-js 0.15.1 → 0.16.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.dev.cjs +128 -187
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +121 -176
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +128 -187
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +85 -51
- package/dist/index.prod.js +121 -176
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/BlendModes/BlendModeRegistry.ts +78 -0
- package/src/BlendModes/blend-modes-fast.ts +31 -84
- package/src/BlendModes/blend-modes-perfect.ts +33 -82
- package/src/BlendModes/blend-modes.ts +25 -33
- package/src/PixelData/blendPixelData.ts +2 -3
- package/src/index.ts +2 -9
- package/src/BlendModes/blend-mode-getters.ts +0 -14
package/dist/index.dev.cjs
CHANGED
|
@@ -20,19 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
FAST_BLEND_MODE_BY_NAME: () => FAST_BLEND_MODE_BY_NAME,
|
|
27
|
-
FAST_BLEND_TO_INDEX: () => FAST_BLEND_TO_INDEX,
|
|
28
|
-
INDEX_TO_FAST_BLEND: () => INDEX_TO_FAST_BLEND,
|
|
29
|
-
INDEX_TO_PERFECT_BLEND: () => INDEX_TO_PERFECT_BLEND,
|
|
23
|
+
BASE_FAST_BLEND_MODE_FUNCTIONS: () => BASE_FAST_BLEND_MODE_FUNCTIONS,
|
|
24
|
+
BASE_PERFECT_BLEND_MODE_FUNCTIONS: () => BASE_PERFECT_BLEND_MODE_FUNCTIONS,
|
|
25
|
+
BaseBlendMode: () => BaseBlendMode,
|
|
30
26
|
IndexedImage: () => IndexedImage,
|
|
31
27
|
MaskType: () => MaskType,
|
|
32
|
-
PERFECT_BLENDER_REGISTRY: () => PERFECT_BLENDER_REGISTRY,
|
|
33
|
-
PERFECT_BLEND_MODES: () => PERFECT_BLEND_MODES,
|
|
34
|
-
PERFECT_BLEND_MODE_BY_NAME: () => PERFECT_BLEND_MODE_BY_NAME,
|
|
35
|
-
PERFECT_BLEND_TO_INDEX: () => PERFECT_BLEND_TO_INDEX,
|
|
36
28
|
PixelData: () => PixelData,
|
|
37
29
|
UnsupportedFormatError: () => UnsupportedFormatError,
|
|
38
30
|
applyMaskToPixelData: () => applyMaskToPixelData,
|
|
@@ -102,6 +94,9 @@ __export(src_exports, {
|
|
|
102
94
|
linearDodgePerfect: () => linearDodgePerfect,
|
|
103
95
|
linearLightFast: () => linearLightFast,
|
|
104
96
|
linearLightPerfect: () => linearLightPerfect,
|
|
97
|
+
makeBlendModeRegistry: () => makeBlendModeRegistry,
|
|
98
|
+
makeFastBlendModeRegistry: () => makeFastBlendModeRegistry,
|
|
99
|
+
makePerfectBlendModeRegistry: () => makePerfectBlendModeRegistry,
|
|
105
100
|
makePixelCanvas: () => makePixelCanvas,
|
|
106
101
|
makeReusableCanvas: () => makeReusableCanvas,
|
|
107
102
|
makeReusableImageData: () => makeReusableImageData,
|
|
@@ -110,6 +105,7 @@ __export(src_exports, {
|
|
|
110
105
|
multiplyPerfect: () => multiplyPerfect,
|
|
111
106
|
overlayFast: () => overlayFast,
|
|
112
107
|
overlayPerfect: () => overlayPerfect,
|
|
108
|
+
overwriteBase: () => overwriteBase,
|
|
113
109
|
overwriteFast: () => overwriteFast,
|
|
114
110
|
overwritePerfect: () => overwritePerfect,
|
|
115
111
|
packColor: () => packColor,
|
|
@@ -151,35 +147,68 @@ __export(src_exports, {
|
|
|
151
147
|
module.exports = __toCommonJS(src_exports);
|
|
152
148
|
|
|
153
149
|
// src/BlendModes/blend-modes.ts
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
})(BlendMode || {});
|
|
150
|
+
var BaseBlendMode = {
|
|
151
|
+
overwrite: 0,
|
|
152
|
+
sourceOver: 1,
|
|
153
|
+
darken: 2,
|
|
154
|
+
multiply: 3,
|
|
155
|
+
colorBurn: 4,
|
|
156
|
+
linearBurn: 5,
|
|
157
|
+
darkerColor: 6,
|
|
158
|
+
lighten: 7,
|
|
159
|
+
screen: 8,
|
|
160
|
+
colorDodge: 9,
|
|
161
|
+
linearDodge: 10,
|
|
162
|
+
lighterColor: 11,
|
|
163
|
+
overlay: 12,
|
|
164
|
+
softLight: 13,
|
|
165
|
+
hardLight: 14,
|
|
166
|
+
vividLight: 15,
|
|
167
|
+
linearLight: 16,
|
|
168
|
+
pinLight: 17,
|
|
169
|
+
hardMix: 18,
|
|
170
|
+
difference: 19,
|
|
171
|
+
exclusion: 20,
|
|
172
|
+
subtract: 21,
|
|
173
|
+
divide: 22
|
|
174
|
+
};
|
|
180
175
|
var overwriteBase = (src, _dst) => src;
|
|
181
176
|
overwriteBase.isOverwrite = true;
|
|
182
177
|
|
|
178
|
+
// src/BlendModes/BlendModeRegistry.ts
|
|
179
|
+
function makeBlendModeRegistry(blendModes, initialEntries) {
|
|
180
|
+
const modes = [];
|
|
181
|
+
const toIndex = /* @__PURE__ */ new Map();
|
|
182
|
+
const fromIndex = /* @__PURE__ */ new Map();
|
|
183
|
+
const byName = {};
|
|
184
|
+
const add = (name, index, blendFn) => {
|
|
185
|
+
if (modes[index]) {
|
|
186
|
+
throw new Error(`Blend Mode index: ${index} is already used`);
|
|
187
|
+
}
|
|
188
|
+
if (byName[name]) {
|
|
189
|
+
throw new Error(`Blend Mode name: "${name}" is already used`);
|
|
190
|
+
}
|
|
191
|
+
const idx = index;
|
|
192
|
+
modes[idx] = blendFn;
|
|
193
|
+
toIndex.set(blendFn, idx);
|
|
194
|
+
fromIndex.set(idx, blendFn);
|
|
195
|
+
byName[name] = blendFn;
|
|
196
|
+
};
|
|
197
|
+
for (const [name, index] of Object.entries(blendModes)) {
|
|
198
|
+
const blend = initialEntries[index];
|
|
199
|
+
add(name, index, blend);
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
modes,
|
|
203
|
+
byName,
|
|
204
|
+
toIndex,
|
|
205
|
+
fromIndex,
|
|
206
|
+
add,
|
|
207
|
+
indexType: null,
|
|
208
|
+
nameType: null
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
183
212
|
// src/BlendModes/blend-modes-fast.ts
|
|
184
213
|
var overwriteFast = overwriteBase;
|
|
185
214
|
var sourceOverFast = (src, dst) => {
|
|
@@ -565,76 +594,34 @@ var divideFast = (src, dst) => {
|
|
|
565
594
|
const a = 255 * sa + (dst >>> 24 & 255) * invA >> 8;
|
|
566
595
|
return (a << 24 | b << 16 | g << 8 | r) >>> 0;
|
|
567
596
|
};
|
|
568
|
-
var
|
|
569
|
-
[
|
|
570
|
-
[
|
|
571
|
-
[
|
|
572
|
-
[
|
|
573
|
-
[
|
|
574
|
-
[
|
|
575
|
-
[
|
|
576
|
-
[
|
|
577
|
-
[
|
|
578
|
-
[
|
|
579
|
-
[
|
|
580
|
-
[
|
|
581
|
-
[
|
|
582
|
-
[
|
|
583
|
-
[
|
|
584
|
-
[
|
|
585
|
-
[
|
|
586
|
-
[
|
|
587
|
-
[
|
|
588
|
-
[
|
|
589
|
-
[
|
|
590
|
-
[
|
|
591
|
-
[
|
|
592
|
-
];
|
|
593
|
-
var FAST_BLEND_MODES = [];
|
|
594
|
-
for (const [index, blend] of FAST_BLENDER_REGISTRY) {
|
|
595
|
-
FAST_BLEND_MODES[index] = blend;
|
|
596
|
-
}
|
|
597
|
-
var FAST_BLEND_TO_INDEX = new Map(
|
|
598
|
-
FAST_BLENDER_REGISTRY.map((entry, index) => {
|
|
599
|
-
return [
|
|
600
|
-
entry[1],
|
|
601
|
-
index
|
|
602
|
-
];
|
|
603
|
-
})
|
|
604
|
-
);
|
|
605
|
-
var INDEX_TO_FAST_BLEND = new Map(
|
|
606
|
-
FAST_BLENDER_REGISTRY.map((entry, index) => {
|
|
607
|
-
return [
|
|
608
|
-
index,
|
|
609
|
-
entry[1]
|
|
610
|
-
];
|
|
611
|
-
})
|
|
612
|
-
);
|
|
613
|
-
var FAST_BLEND_MODE_BY_NAME = {
|
|
614
|
-
overwrite: overwriteFast,
|
|
615
|
-
sourceOver: sourceOverFast,
|
|
616
|
-
darken: darkenFast,
|
|
617
|
-
multiply: multiplyFast,
|
|
618
|
-
colorBurn: colorBurnFast,
|
|
619
|
-
linearBurn: linearBurnFast,
|
|
620
|
-
darkerColor: darkerFast,
|
|
621
|
-
lighten: lightenFast,
|
|
622
|
-
screen: screenFast,
|
|
623
|
-
colorDodge: colorDodgeFast,
|
|
624
|
-
linearDodge: linearDodgeFast,
|
|
625
|
-
lighterColor: lighterFast,
|
|
626
|
-
overlay: overlayFast,
|
|
627
|
-
softLight: softLightFast,
|
|
628
|
-
hardLight: hardLightFast,
|
|
629
|
-
vividLight: vividLightFast,
|
|
630
|
-
linearLight: linearLightFast,
|
|
631
|
-
pinLight: pinLightFast,
|
|
632
|
-
hardMix: hardMixFast,
|
|
633
|
-
difference: differenceFast,
|
|
634
|
-
exclusion: exclusionFast,
|
|
635
|
-
subtract: subtractFast,
|
|
636
|
-
divide: divideFast
|
|
597
|
+
var BASE_FAST_BLEND_MODE_FUNCTIONS = {
|
|
598
|
+
[BaseBlendMode.overwrite]: overwriteFast,
|
|
599
|
+
[BaseBlendMode.sourceOver]: sourceOverFast,
|
|
600
|
+
[BaseBlendMode.darken]: darkenFast,
|
|
601
|
+
[BaseBlendMode.multiply]: multiplyFast,
|
|
602
|
+
[BaseBlendMode.colorBurn]: colorBurnFast,
|
|
603
|
+
[BaseBlendMode.linearBurn]: linearBurnFast,
|
|
604
|
+
[BaseBlendMode.darkerColor]: darkerFast,
|
|
605
|
+
[BaseBlendMode.lighten]: lightenFast,
|
|
606
|
+
[BaseBlendMode.screen]: screenFast,
|
|
607
|
+
[BaseBlendMode.colorDodge]: colorDodgeFast,
|
|
608
|
+
[BaseBlendMode.linearDodge]: linearDodgeFast,
|
|
609
|
+
[BaseBlendMode.lighterColor]: lighterFast,
|
|
610
|
+
[BaseBlendMode.overlay]: overlayFast,
|
|
611
|
+
[BaseBlendMode.softLight]: softLightFast,
|
|
612
|
+
[BaseBlendMode.hardLight]: hardLightFast,
|
|
613
|
+
[BaseBlendMode.vividLight]: vividLightFast,
|
|
614
|
+
[BaseBlendMode.linearLight]: linearLightFast,
|
|
615
|
+
[BaseBlendMode.pinLight]: pinLightFast,
|
|
616
|
+
[BaseBlendMode.hardMix]: hardMixFast,
|
|
617
|
+
[BaseBlendMode.difference]: differenceFast,
|
|
618
|
+
[BaseBlendMode.exclusion]: exclusionFast,
|
|
619
|
+
[BaseBlendMode.subtract]: subtractFast,
|
|
620
|
+
[BaseBlendMode.divide]: divideFast
|
|
637
621
|
};
|
|
622
|
+
function makeFastBlendModeRegistry() {
|
|
623
|
+
return makeBlendModeRegistry(BaseBlendMode, BASE_FAST_BLEND_MODE_FUNCTIONS);
|
|
624
|
+
}
|
|
638
625
|
|
|
639
626
|
// src/_types.ts
|
|
640
627
|
var MaskType = /* @__PURE__ */ ((MaskType2) => {
|
|
@@ -1395,76 +1382,34 @@ var dividePerfect = (src, dst) => {
|
|
|
1395
1382
|
const a = (255 * sa + (dst >>> 24 & 255) * invA) / 255 | 0;
|
|
1396
1383
|
return (a << 24 | b << 16 | g << 8 | r) >>> 0;
|
|
1397
1384
|
};
|
|
1398
|
-
var
|
|
1399
|
-
[
|
|
1400
|
-
[
|
|
1401
|
-
[
|
|
1402
|
-
[
|
|
1403
|
-
[
|
|
1404
|
-
[
|
|
1405
|
-
[
|
|
1406
|
-
[
|
|
1407
|
-
[
|
|
1408
|
-
[
|
|
1409
|
-
[
|
|
1410
|
-
[
|
|
1411
|
-
[
|
|
1412
|
-
[
|
|
1413
|
-
[
|
|
1414
|
-
[
|
|
1415
|
-
[
|
|
1416
|
-
[
|
|
1417
|
-
[
|
|
1418
|
-
[
|
|
1419
|
-
[
|
|
1420
|
-
[
|
|
1421
|
-
[
|
|
1422
|
-
];
|
|
1423
|
-
var PERFECT_BLEND_MODES = [];
|
|
1424
|
-
for (const [index, blend] of PERFECT_BLENDER_REGISTRY) {
|
|
1425
|
-
PERFECT_BLEND_MODES[index] = blend;
|
|
1426
|
-
}
|
|
1427
|
-
var PERFECT_BLEND_TO_INDEX = new Map(
|
|
1428
|
-
PERFECT_BLENDER_REGISTRY.map((entry, index) => {
|
|
1429
|
-
return [
|
|
1430
|
-
entry[1],
|
|
1431
|
-
index
|
|
1432
|
-
];
|
|
1433
|
-
})
|
|
1434
|
-
);
|
|
1435
|
-
var INDEX_TO_PERFECT_BLEND = new Map(
|
|
1436
|
-
PERFECT_BLENDER_REGISTRY.map((entry, index) => {
|
|
1437
|
-
return [
|
|
1438
|
-
index,
|
|
1439
|
-
entry[1]
|
|
1440
|
-
];
|
|
1441
|
-
})
|
|
1442
|
-
);
|
|
1443
|
-
var PERFECT_BLEND_MODE_BY_NAME = {
|
|
1444
|
-
overwrite: overwritePerfect,
|
|
1445
|
-
sourceOver: sourceOverPerfect,
|
|
1446
|
-
darken: darkenPerfect,
|
|
1447
|
-
multiply: multiplyPerfect,
|
|
1448
|
-
colorBurn: colorBurnPerfect,
|
|
1449
|
-
linearBurn: linearBurnPerfect,
|
|
1450
|
-
darkerColor: darkerPerfect,
|
|
1451
|
-
lighten: lightenPerfect,
|
|
1452
|
-
screen: screenPerfect,
|
|
1453
|
-
colorDodge: colorDodgePerfect,
|
|
1454
|
-
linearDodge: linearDodgePerfect,
|
|
1455
|
-
lighterColor: lighterPerfect,
|
|
1456
|
-
overlay: overlayPerfect,
|
|
1457
|
-
softLight: softLightPerfect,
|
|
1458
|
-
hardLight: hardLightPerfect,
|
|
1459
|
-
vividLight: vividLightPerfect,
|
|
1460
|
-
linearLight: linearLightPerfect,
|
|
1461
|
-
pinLight: pinLightPerfect,
|
|
1462
|
-
hardMix: hardMixPerfect,
|
|
1463
|
-
difference: differencePerfect,
|
|
1464
|
-
exclusion: exclusionPerfect,
|
|
1465
|
-
subtract: subtractPerfect,
|
|
1466
|
-
divide: dividePerfect
|
|
1385
|
+
var BASE_PERFECT_BLEND_MODE_FUNCTIONS = {
|
|
1386
|
+
[BaseBlendMode.overwrite]: overwritePerfect,
|
|
1387
|
+
[BaseBlendMode.sourceOver]: sourceOverPerfect,
|
|
1388
|
+
[BaseBlendMode.darken]: darkenPerfect,
|
|
1389
|
+
[BaseBlendMode.multiply]: multiplyPerfect,
|
|
1390
|
+
[BaseBlendMode.colorBurn]: colorBurnPerfect,
|
|
1391
|
+
[BaseBlendMode.linearBurn]: linearBurnPerfect,
|
|
1392
|
+
[BaseBlendMode.darkerColor]: darkerPerfect,
|
|
1393
|
+
[BaseBlendMode.lighten]: lightenPerfect,
|
|
1394
|
+
[BaseBlendMode.screen]: screenPerfect,
|
|
1395
|
+
[BaseBlendMode.colorDodge]: colorDodgePerfect,
|
|
1396
|
+
[BaseBlendMode.linearDodge]: linearDodgePerfect,
|
|
1397
|
+
[BaseBlendMode.lighterColor]: lighterPerfect,
|
|
1398
|
+
[BaseBlendMode.overlay]: overlayPerfect,
|
|
1399
|
+
[BaseBlendMode.softLight]: softLightPerfect,
|
|
1400
|
+
[BaseBlendMode.hardLight]: hardLightPerfect,
|
|
1401
|
+
[BaseBlendMode.vividLight]: vividLightPerfect,
|
|
1402
|
+
[BaseBlendMode.linearLight]: linearLightPerfect,
|
|
1403
|
+
[BaseBlendMode.pinLight]: pinLightPerfect,
|
|
1404
|
+
[BaseBlendMode.hardMix]: hardMixPerfect,
|
|
1405
|
+
[BaseBlendMode.difference]: differencePerfect,
|
|
1406
|
+
[BaseBlendMode.exclusion]: exclusionPerfect,
|
|
1407
|
+
[BaseBlendMode.subtract]: subtractPerfect,
|
|
1408
|
+
[BaseBlendMode.divide]: dividePerfect
|
|
1467
1409
|
};
|
|
1410
|
+
function makePerfectBlendModeRegistry() {
|
|
1411
|
+
return makeBlendModeRegistry(BaseBlendMode, BASE_PERFECT_BLEND_MODE_FUNCTIONS);
|
|
1412
|
+
}
|
|
1468
1413
|
|
|
1469
1414
|
// src/Canvas/_constants.ts
|
|
1470
1415
|
var OFFSCREEN_CANVAS_CTX_FAILED = "Failed to create OffscreenCanvas context";
|
|
@@ -2429,7 +2374,7 @@ function blendPixelData(dst, src, opts) {
|
|
|
2429
2374
|
w: width = src.width,
|
|
2430
2375
|
h: height = src.height,
|
|
2431
2376
|
alpha: globalAlpha = 255,
|
|
2432
|
-
blendFn =
|
|
2377
|
+
blendFn = sourceOverFast,
|
|
2433
2378
|
mask,
|
|
2434
2379
|
maskType = 0 /* ALPHA */,
|
|
2435
2380
|
mw,
|
|
@@ -2752,19 +2697,11 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2752
2697
|
}
|
|
2753
2698
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2754
2699
|
0 && (module.exports = {
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
FAST_BLEND_MODE_BY_NAME,
|
|
2759
|
-
FAST_BLEND_TO_INDEX,
|
|
2760
|
-
INDEX_TO_FAST_BLEND,
|
|
2761
|
-
INDEX_TO_PERFECT_BLEND,
|
|
2700
|
+
BASE_FAST_BLEND_MODE_FUNCTIONS,
|
|
2701
|
+
BASE_PERFECT_BLEND_MODE_FUNCTIONS,
|
|
2702
|
+
BaseBlendMode,
|
|
2762
2703
|
IndexedImage,
|
|
2763
2704
|
MaskType,
|
|
2764
|
-
PERFECT_BLENDER_REGISTRY,
|
|
2765
|
-
PERFECT_BLEND_MODES,
|
|
2766
|
-
PERFECT_BLEND_MODE_BY_NAME,
|
|
2767
|
-
PERFECT_BLEND_TO_INDEX,
|
|
2768
2705
|
PixelData,
|
|
2769
2706
|
UnsupportedFormatError,
|
|
2770
2707
|
applyMaskToPixelData,
|
|
@@ -2834,6 +2771,9 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2834
2771
|
linearDodgePerfect,
|
|
2835
2772
|
linearLightFast,
|
|
2836
2773
|
linearLightPerfect,
|
|
2774
|
+
makeBlendModeRegistry,
|
|
2775
|
+
makeFastBlendModeRegistry,
|
|
2776
|
+
makePerfectBlendModeRegistry,
|
|
2837
2777
|
makePixelCanvas,
|
|
2838
2778
|
makeReusableCanvas,
|
|
2839
2779
|
makeReusableImageData,
|
|
@@ -2842,6 +2782,7 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2842
2782
|
multiplyPerfect,
|
|
2843
2783
|
overlayFast,
|
|
2844
2784
|
overlayPerfect,
|
|
2785
|
+
overwriteBase,
|
|
2845
2786
|
overwriteFast,
|
|
2846
2787
|
overwritePerfect,
|
|
2847
2788
|
packColor,
|