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.
@@ -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
- BlendMode: () => BlendMode,
24
- FAST_BLENDER_REGISTRY: () => FAST_BLENDER_REGISTRY,
25
- FAST_BLEND_MODES: () => FAST_BLEND_MODES,
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 BlendMode = /* @__PURE__ */ ((BlendMode2) => {
155
- BlendMode2[BlendMode2["overwrite"] = 0] = "overwrite";
156
- BlendMode2[BlendMode2["sourceOver"] = 1] = "sourceOver";
157
- BlendMode2[BlendMode2["darken"] = 2] = "darken";
158
- BlendMode2[BlendMode2["multiply"] = 3] = "multiply";
159
- BlendMode2[BlendMode2["colorBurn"] = 4] = "colorBurn";
160
- BlendMode2[BlendMode2["linearBurn"] = 5] = "linearBurn";
161
- BlendMode2[BlendMode2["darkerColor"] = 6] = "darkerColor";
162
- BlendMode2[BlendMode2["lighten"] = 7] = "lighten";
163
- BlendMode2[BlendMode2["screen"] = 8] = "screen";
164
- BlendMode2[BlendMode2["colorDodge"] = 9] = "colorDodge";
165
- BlendMode2[BlendMode2["linearDodge"] = 10] = "linearDodge";
166
- BlendMode2[BlendMode2["lighterColor"] = 11] = "lighterColor";
167
- BlendMode2[BlendMode2["overlay"] = 12] = "overlay";
168
- BlendMode2[BlendMode2["softLight"] = 13] = "softLight";
169
- BlendMode2[BlendMode2["hardLight"] = 14] = "hardLight";
170
- BlendMode2[BlendMode2["vividLight"] = 15] = "vividLight";
171
- BlendMode2[BlendMode2["linearLight"] = 16] = "linearLight";
172
- BlendMode2[BlendMode2["pinLight"] = 17] = "pinLight";
173
- BlendMode2[BlendMode2["hardMix"] = 18] = "hardMix";
174
- BlendMode2[BlendMode2["difference"] = 19] = "difference";
175
- BlendMode2[BlendMode2["exclusion"] = 20] = "exclusion";
176
- BlendMode2[BlendMode2["subtract"] = 21] = "subtract";
177
- BlendMode2[BlendMode2["divide"] = 22] = "divide";
178
- return BlendMode2;
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 FAST_BLENDER_REGISTRY = [
569
- [0 /* overwrite */, overwriteFast],
570
- [1 /* sourceOver */, sourceOverFast],
571
- [2 /* darken */, darkenFast],
572
- [3 /* multiply */, multiplyFast],
573
- [4 /* colorBurn */, colorBurnFast],
574
- [5 /* linearBurn */, linearBurnFast],
575
- [6 /* darkerColor */, darkerFast],
576
- [7 /* lighten */, lightenFast],
577
- [8 /* screen */, screenFast],
578
- [9 /* colorDodge */, colorDodgeFast],
579
- [10 /* linearDodge */, linearDodgeFast],
580
- [11 /* lighterColor */, lighterFast],
581
- [12 /* overlay */, overlayFast],
582
- [13 /* softLight */, softLightFast],
583
- [14 /* hardLight */, hardLightFast],
584
- [15 /* vividLight */, vividLightFast],
585
- [16 /* linearLight */, linearLightFast],
586
- [17 /* pinLight */, pinLightFast],
587
- [18 /* hardMix */, hardMixFast],
588
- [19 /* difference */, differenceFast],
589
- [20 /* exclusion */, exclusionFast],
590
- [21 /* subtract */, subtractFast],
591
- [22 /* divide */, divideFast]
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 PERFECT_BLENDER_REGISTRY = [
1399
- [0 /* overwrite */, overwritePerfect],
1400
- [1 /* sourceOver */, sourceOverPerfect],
1401
- [2 /* darken */, darkenPerfect],
1402
- [3 /* multiply */, multiplyPerfect],
1403
- [4 /* colorBurn */, colorBurnPerfect],
1404
- [5 /* linearBurn */, linearBurnPerfect],
1405
- [6 /* darkerColor */, darkerPerfect],
1406
- [7 /* lighten */, lightenPerfect],
1407
- [8 /* screen */, screenPerfect],
1408
- [9 /* colorDodge */, colorDodgePerfect],
1409
- [10 /* linearDodge */, linearDodgePerfect],
1410
- [11 /* lighterColor */, lighterPerfect],
1411
- [12 /* overlay */, overlayPerfect],
1412
- [13 /* softLight */, softLightPerfect],
1413
- [14 /* hardLight */, hardLightPerfect],
1414
- [15 /* vividLight */, vividLightPerfect],
1415
- [16 /* linearLight */, linearLightPerfect],
1416
- [17 /* pinLight */, pinLightPerfect],
1417
- [18 /* hardMix */, hardMixPerfect],
1418
- [19 /* difference */, differencePerfect],
1419
- [20 /* exclusion */, exclusionPerfect],
1420
- [21 /* subtract */, subtractPerfect],
1421
- [22 /* divide */, dividePerfect]
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 = FAST_BLEND_MODES[1 /* sourceOver */],
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
- BlendMode,
2756
- FAST_BLENDER_REGISTRY,
2757
- FAST_BLEND_MODES,
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,