imagescript 1.3.1 → 3.0.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 (117) hide show
  1. package/LICENSE +4 -1
  2. package/README.md +64 -26
  3. package/THIRD_PARTY_NOTICES.md +74 -0
  4. package/dist/codecs/crc.d.ts +9 -0
  5. package/dist/codecs/crc.js +29 -0
  6. package/dist/codecs/exif.d.ts +11 -0
  7. package/dist/codecs/exif.js +27 -0
  8. package/dist/codecs/gif.d.ts +44 -0
  9. package/dist/codecs/gif.js +401 -0
  10. package/dist/codecs/jpeg.d.ts +35 -0
  11. package/dist/codecs/jpeg.js +980 -0
  12. package/dist/codecs/png.d.ts +44 -0
  13. package/dist/codecs/png.js +442 -0
  14. package/dist/codecs/quantize.d.ts +25 -0
  15. package/dist/codecs/quantize.js +302 -0
  16. package/dist/codecs/tiff.d.ts +6 -0
  17. package/dist/codecs/tiff.js +546 -0
  18. package/dist/codecs/zlib.d.ts +22 -0
  19. package/dist/codecs/zlib.js +607 -0
  20. package/dist/frame.d.ts +57 -0
  21. package/dist/frame.js +65 -0
  22. package/dist/gif.d.ts +44 -0
  23. package/dist/gif.js +93 -0
  24. package/dist/image-type.d.ts +20 -0
  25. package/dist/image-type.js +49 -0
  26. package/dist/image.d.ts +521 -0
  27. package/dist/image.js +1118 -0
  28. package/dist/index.d.ts +19 -0
  29. package/dist/index.js +13 -0
  30. package/dist/package.json +1 -0
  31. package/dist/render/font.d.ts +63 -0
  32. package/dist/render/font.js +857 -0
  33. package/dist/render/svg.d.ts +11 -0
  34. package/dist/render/svg.js +1717 -0
  35. package/dist/render/text.d.ts +61 -0
  36. package/dist/render/text.js +317 -0
  37. package/dist/text-layout.d.ts +46 -0
  38. package/dist/text-layout.js +35 -0
  39. package/dist/util/blur.d.ts +13 -0
  40. package/dist/util/blur.js +146 -0
  41. package/dist/util/mem.d.ts +10 -0
  42. package/dist/util/mem.js +23 -0
  43. package/dist/util/resample.d.ts +12 -0
  44. package/dist/util/resample.js +99 -0
  45. package/dist/util/utf8.d.ts +5 -0
  46. package/dist/util/utf8.js +55 -0
  47. package/dist/version.d.ts +1 -0
  48. package/dist/version.js +1 -0
  49. package/licenses/Apache-2.0.txt +202 -0
  50. package/licenses/README.ijg +260 -0
  51. package/package.json +31 -7
  52. package/ImageScript.d.ts +0 -954
  53. package/ImageScript.js +0 -1669
  54. package/bench/_.mjs +0 -166
  55. package/bench/all.mjs +0 -4
  56. package/bench/blur.mjs +0 -59
  57. package/bench/flip.mjs +0 -63
  58. package/bench/overlay.mjs +0 -35
  59. package/bench/package.json +0 -7
  60. package/bench/readme.md +0 -64
  61. package/bench/resize.mjs +0 -52
  62. package/codecs/LICENSE +0 -21
  63. package/codecs/lib.d.ts +0 -50
  64. package/codecs/lib.js +0 -6
  65. package/codecs/lib.mjs +0 -1
  66. package/codecs/node/bin/arm64-darwin.node +0 -0
  67. package/codecs/node/bin/arm64-linux.node +0 -0
  68. package/codecs/node/bin/x64-darwin.node +0 -0
  69. package/codecs/node/bin/x64-linux.node +0 -0
  70. package/codecs/node/bin/x64-win32.node +0 -0
  71. package/codecs/node/index.js +0 -3
  72. package/codecs/node/index.mjs +0 -6
  73. package/codecs/package.json +0 -14
  74. package/codecs/readme.md +0 -38
  75. package/codecs/wasm/bin/codecs.wasm +0 -0
  76. package/codecs/wasm/bin/simd.wasm +0 -0
  77. package/codecs/wasm/bundle/browser.js +0 -1
  78. package/codecs/wasm/index.js +0 -1
  79. package/codecs/wasm/index.mjs +0 -1
  80. package/png/README.md +0 -1
  81. package/png/node.js +0 -1137
  82. package/png/src/crc.mjs +0 -49
  83. package/png/src/mem.mjs +0 -24
  84. package/png/src/png.mjs +0 -254
  85. package/png/src/zlib.mjs +0 -618
  86. package/tsconfig.json +0 -21
  87. package/utils/mem.js +0 -26
  88. package/v2/codecs/magic.js +0 -25
  89. package/v2/framebuffer.d.ts +0 -67
  90. package/v2/framebuffer.js +0 -2352
  91. package/v2/framebuffer.mjs +0 -126
  92. package/v2/framebuffer.rs +0 -1264
  93. package/v2/index.d.ts +0 -84
  94. package/v2/index.js +0 -261
  95. package/v2/ops/blur.mjs +0 -303
  96. package/v2/ops/color.mjs +0 -277
  97. package/v2/ops/crop.mjs +0 -64
  98. package/v2/ops/fill.mjs +0 -33
  99. package/v2/ops/flip.mjs +0 -33
  100. package/v2/ops/index.mjs +0 -9
  101. package/v2/ops/iterator.mjs +0 -34
  102. package/v2/ops/overlay.mjs +0 -63
  103. package/v2/ops/resize.mjs +0 -166
  104. package/v2/ops/rotate.mjs +0 -117
  105. package/v2/util/mem.mjs +0 -24
  106. package/wasm/any/font.wasm +0 -0
  107. package/wasm/any/gif.wasm +0 -0
  108. package/wasm/any/jpeg.wasm +0 -0
  109. package/wasm/any/png.wasm +0 -0
  110. package/wasm/any/svg.wasm +0 -0
  111. package/wasm/any/tiff.wasm +0 -0
  112. package/wasm/node/font.js +0 -142
  113. package/wasm/node/gif.js +0 -76
  114. package/wasm/node/jpeg.js +0 -92
  115. package/wasm/node/png.js +0 -49
  116. package/wasm/node/svg.js +0 -56
  117. package/wasm/node/tiff.js +0 -47
@@ -1,126 +0,0 @@
1
- import Color from './ops/color.mjs';
2
- import { view } from './util/mem.mjs';
3
- import * as ops from './ops/index.mjs';
4
- import * as png from '../png/src/png.mjs';
5
-
6
- export { Color };
7
-
8
- // todo: tree shakable context
9
- // todo: make errors more verbose
10
-
11
- export default class framebuffer {
12
- constructor(width, height, buffer) {
13
- this.width = width | 0;
14
- this.height = height | 0;
15
- this.u8 = buffer ? view(buffer) : new Uint8Array(4 * this.width * this.height);
16
- this.view = new DataView(this.u8.buffer, this.u8.byteOffset, this.u8.byteLength);
17
- this.u32 = new Uint32Array(this.u8.buffer, this.u8.byteOffset, this.u8.byteLength / 4);
18
- if (this.u8.length !== 4 * this.width * this.height) throw new RangeError('invalid capacity of buffer');
19
- }
20
-
21
- [Symbol.iterator]() { return ops.iterator.cords(this); }
22
- toString() { return `framebuffer<${this.width}x${this.height}>`; }
23
- get(x, y) { return this.view.getUint32((x | 0) + (y | 0) * this.width, false); }
24
- clone() { return new this.constructor(this.width, this.height, this.u8.slice()); }
25
- set(x, y, color) { this.view.setUint32((x | 0) + (y | 0) * this.width, color, false); }
26
- toJSON() { return { width: this.width, height: this.height, buffer: Array.from(this.u8) } }
27
- scale(type, factor) { return this.resize(type, factor * this.width, factor * this.height); }
28
- overlay(frame, x = 0, y = 0) { return (ops.overlay.blend(this, frame, x | 0, y | 0), this); }
29
- replace(frame, x = 0, y = 0) { return (ops.overlay.replace(this, frame, x | 0, y | 0), this); }
30
- at(x, y) { const offset = 4 * ((x | 0) + (y | 0) * this.width); return this.u8.subarray(offset, 4 + offset); }
31
- static from(framebuffer) { return new this(framebuffer.width, framebuffer.height, framebuffer.u8 || framebuffer.buffer); }
32
- static decode(format, buffer) { if (format !== 'png') throw new RangeError('invalid image format'); else return framebuffer.from(png.decode(buffer)); }
33
-
34
- encode(format, options = {}) {
35
- if (format !== 'png') throw new RangeError('invalid image format');
36
- else return png.encode(this.u8, { channels: 4, width: this.width, height: this.height, level: ({ none: 0, fast: 3, default: 6, best: 9 })[options.compression] ?? 3 });
37
- }
38
-
39
- pixels(type) {
40
- if ('rgba' === type) return ops.iterator.rgba(this);
41
- if (!type || 'int' === type) return ops.iterator.u32(this);
42
-
43
- throw new RangeError('invalid iterator type');
44
- }
45
-
46
- flip(type) {
47
- if (type === 'vertical') ops.flip.vertical(this);
48
- else if (type === 'horizontal') ops.flip.horizontal(this);
49
-
50
- else throw new RangeError('invalid flip type');
51
-
52
- return this;
53
- }
54
-
55
- crop(type, arg0, arg1, arg2, arg3) {
56
- if (type === 'circle') ops.crop.circle(arg0 || 0, this);
57
- else if (type === 'box') ops.crop.crop(arg0 | 0, arg1 | 0, arg2 | 0, arg3 | 0, this);
58
-
59
- else throw new RangeError('invalid crop type');
60
-
61
- return this;
62
- }
63
-
64
- cut(type, arg0, arg1, arg2, arg3) {
65
- if (type === 'circle') return ops.crop.circle(arg0 || 0, this.clone());
66
- else if (type === 'box') return ops.crop.cut(arg0 | 0, arg1 | 0, arg2 | 0, arg3 | 0, this);
67
-
68
- else throw new RangeError('invalid cut type');
69
- }
70
-
71
- rotate(deg, resize = true) {
72
- if (0 === (deg %= 360)) return this;
73
- else if (90 === deg) ops.rotate.rotate90(this);
74
- else if (180 === deg) ops.rotate.rotate180(this);
75
- else if (270 === deg) ops.rotate.rotate270(this);
76
-
77
- else ops.rotate.rotate(deg, this, resize);
78
-
79
- return this;
80
- }
81
-
82
- blur(type, arg0) {
83
- if (type === 'cubic') ops.blur.cubic(this);
84
- else if (type === 'box') ops.blur.box(+arg0, this);
85
- else if (type === 'gaussian') ops.blur.gaussian(+arg0, this);
86
-
87
- else throw new RangeError('invalid blur type');
88
-
89
- return this;
90
- }
91
-
92
- fill(color) {
93
- const type = typeof color;
94
- if (type === 'function') ops.fill.fn(color, this);
95
- else if (type === 'number') ops.fill.color(color, this);
96
- else if (color instanceof Color) ops.fill.color(color.valueOf(), this);
97
- else if (Array.isArray(color)) ops.fill.color(ops.color.from_rgba(...color), this);
98
-
99
- else throw new TypeError('invalid fill color');
100
-
101
- return this;
102
- }
103
-
104
- swap(old, color) {
105
- const ot = typeof old;
106
- const nt = typeof color;
107
- if (ot === nt && ot === 'number') ops.fill.swap(old, color, this);
108
- else if (old instanceof Color && color instanceof Color) ops.fill.swap(old.valueOf(), color.valueOf(), this);
109
- else if (Array.isArray(old) && Array.isArray(color)) ops.fill.swap(ops.color.from_rgba(...old), ops.color.from_rgba(...color), this);
110
-
111
- else throw new RangeError('invalid swap color');
112
-
113
- return this;
114
- }
115
-
116
- resize(type, width, height) {
117
- if (width === this.width && height === this.height) return this;
118
- else if (type === 'cubic') ops.resize.cubic(width, height, this);
119
- else if (type === 'linear') ops.resize.linear(width, height, this);
120
- else if (type === 'nearest') ops.resize.nearest(width, height, this);
121
-
122
- else throw new RangeError('invalid resize type');
123
-
124
- return this;
125
- }
126
- }