@huh-david/bmp-js 0.5.0 → 0.6.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/README.md +43 -1
- package/dist/chunk-YH5DJH4H.js +832 -0
- package/dist/chunk-YH5DJH4H.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -47
- package/dist/index.d.ts +3 -47
- package/dist/index.js +6 -824
- package/dist/index.js.map +1 -1
- package/dist/sharp/index.cjs +1025 -0
- package/dist/sharp/index.cjs.map +1 -0
- package/dist/sharp/index.d.cts +58 -0
- package/dist/sharp/index.d.ts +58 -0
- package/dist/sharp/index.js +172 -0
- package/dist/sharp/index.js.map +1 -0
- package/dist/types-CzYgOtEn.d.cts +48 -0
- package/dist/types-CzYgOtEn.d.ts +48 -0
- package/package.json +25 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sharp/index.ts","../../src/binary.ts","../../src/decoder.ts","../../src/encoder.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: DecodeForSharpInput | BmpSharpInput): Uint8Array {\n if (input instanceof Uint8Array) {\n return input;\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nexport function isBmp(input: BmpSharpInput): boolean {\n try {\n const bytes = toUint8Array(input);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance {\n const decoded = decodeForSharp(input);\n const sharp = loadSharpModule(sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options: EncodeBmpOptions = {}): Uint8Array {\n const data = toUint8Array(input.data);\n const width = input.info.width;\n const height = input.info.height;\n const channels = input.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (options.palette) {\n encodeOptions.palette = options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","import type { BmpBinaryInput } from \"./types\";\n\nexport function toUint8Array(input: BmpBinaryInput): Uint8Array {\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input);\n }\n\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n\nexport function assertInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n}\n","import { toUint8Array } from \"./binary\";\nimport type { BmpBinaryInput, BmpPaletteColor, DecodeOptions, DecodedBmp } from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_MIN = 40;\nconst CORE_HEADER_SIZE = 12;\n\nfunction rowStride(width: number, bitPP: number): number {\n return Math.floor((bitPP * width + 31) / 32) * 4;\n}\n\nclass BmpDecoder implements DecodedBmp {\n private pos = 0;\n private readonly bytes: Uint8Array;\n private readonly view: DataView;\n private readonly options: Required<DecodeOptions>;\n private bottomUp = true;\n private dibStart = FILE_HEADER_SIZE;\n private paletteEntrySize = 4;\n private externalMaskOffset = 0;\n\n private maskRed = 0;\n private maskGreen = 0;\n private maskBlue = 0;\n private maskAlpha = 0;\n\n fileSize!: number;\n reserved!: number;\n offset!: number;\n headerSize!: number;\n width!: number;\n height!: number;\n planes!: number;\n bitPP!: number;\n compress!: number;\n rawSize!: number;\n hr!: number;\n vr!: number;\n colors!: number;\n importantColors!: number;\n palette?: BmpPaletteColor[];\n data!: Uint8Array;\n\n constructor(input: BmpBinaryInput, options: DecodeOptions = {}) {\n this.bytes = toUint8Array(input);\n this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);\n this.options = {\n treat16BitAs15BitAlpha: options.treat16BitAs15BitAlpha ?? false,\n toRGBA: options.toRGBA ?? false,\n };\n\n this.parseFileHeader();\n this.parseDibHeader();\n this.parsePalette();\n this.pos = this.offset;\n this.parseRGBA();\n this.transformToRgbaIfNeeded();\n }\n\n private ensureReadable(offset: number, size: number, context: string): void {\n if (offset < 0 || size < 0 || offset + size > this.bytes.length) {\n throw new Error(`BMP decode out-of-range while reading ${context}`);\n }\n }\n\n private readUInt8(offset = this.pos): number {\n this.ensureReadable(offset, 1, \"uint8\");\n if (offset === this.pos) this.pos += 1;\n return this.view.getUint8(offset);\n }\n\n private readUInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"uint16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getUint16(offset, true);\n }\n\n private readInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"int16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getInt16(offset, true);\n }\n\n private readUInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"uint32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getUint32(offset, true);\n }\n\n private readInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"int32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getInt32(offset, true);\n }\n\n private parseFileHeader(): void {\n this.ensureReadable(0, FILE_HEADER_SIZE, \"file header\");\n if (this.bytes[0] !== 0x42 || this.bytes[1] !== 0x4d) {\n throw new Error(\"Invalid BMP file signature\");\n }\n\n this.pos = 2;\n this.fileSize = this.readUInt32LE();\n this.reserved = this.readUInt32LE();\n this.offset = this.readUInt32LE();\n\n if (this.offset < FILE_HEADER_SIZE || this.offset > this.bytes.length) {\n throw new Error(`Invalid pixel data offset: ${this.offset}`);\n }\n }\n\n private parseDibHeader(): void {\n this.pos = this.dibStart;\n this.headerSize = this.readUInt32LE();\n if (this.headerSize < CORE_HEADER_SIZE) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n this.ensureReadable(this.dibStart, this.headerSize, \"DIB header\");\n\n if (this.headerSize === CORE_HEADER_SIZE) {\n this.parseCoreHeader();\n return;\n }\n\n if (this.headerSize < INFO_HEADER_MIN) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n\n this.parseInfoHeader();\n }\n\n private parseCoreHeader(): void {\n const width = this.readUInt16LE(this.dibStart + 4);\n const height = this.readUInt16LE(this.dibStart + 6);\n\n this.width = width;\n this.height = height;\n this.planes = this.readUInt16LE(this.dibStart + 8);\n this.bitPP = this.readUInt16LE(this.dibStart + 10);\n this.compress = 0;\n this.rawSize = 0;\n this.hr = 0;\n this.vr = 0;\n this.colors = 0;\n this.importantColors = 0;\n this.bottomUp = true;\n this.paletteEntrySize = 3;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n this.validateDimensions();\n }\n\n private parseInfoHeader(): void {\n const rawWidth = this.readInt32LE(this.dibStart + 4);\n const rawHeight = this.readInt32LE(this.dibStart + 8);\n\n this.width = rawWidth;\n this.height = rawHeight;\n this.planes = this.readUInt16LE(this.dibStart + 12);\n this.bitPP = this.readUInt16LE(this.dibStart + 14);\n this.compress = this.readUInt32LE(this.dibStart + 16);\n this.rawSize = this.readUInt32LE(this.dibStart + 20);\n this.hr = this.readUInt32LE(this.dibStart + 24);\n this.vr = this.readUInt32LE(this.dibStart + 28);\n this.colors = this.readUInt32LE(this.dibStart + 32);\n this.importantColors = this.readUInt32LE(this.dibStart + 36);\n this.paletteEntrySize = 4;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n if (this.height < 0) {\n this.height *= -1;\n this.bottomUp = false;\n }\n\n if (this.width < 0) {\n this.width *= -1;\n }\n\n if (this.bitPP === 16 && this.options.treat16BitAs15BitAlpha) {\n this.bitPP = 15;\n }\n\n this.validateDimensions();\n this.parseBitMasks();\n }\n\n private validateDimensions(): void {\n if (\n !Number.isInteger(this.width) ||\n !Number.isInteger(this.height) ||\n this.width <= 0 ||\n this.height <= 0\n ) {\n throw new Error(`Invalid BMP dimensions: ${this.width}x${this.height}`);\n }\n }\n\n private parseBitMasks(): void {\n if (\n !(this.bitPP === 16 || this.bitPP === 32) ||\n !(this.compress === 3 || this.compress === 6)\n ) {\n return;\n }\n\n const inHeaderMaskStart = this.dibStart + 40;\n const hasMasksInHeader = this.headerSize >= 52;\n const maskStart = hasMasksInHeader ? inHeaderMaskStart : this.externalMaskOffset;\n const maskCount = this.compress === 6 || this.headerSize >= 56 ? 4 : 3;\n this.ensureReadable(maskStart, maskCount * 4, \"bit masks\");\n\n this.maskRed = this.readUInt32LE(maskStart);\n this.maskGreen = this.readUInt32LE(maskStart + 4);\n this.maskBlue = this.readUInt32LE(maskStart + 8);\n this.maskAlpha = maskCount >= 4 ? this.readUInt32LE(maskStart + 12) : 0;\n\n if (!hasMasksInHeader) {\n this.externalMaskOffset += maskCount * 4;\n }\n }\n\n private parsePalette(): void {\n if (this.bitPP >= 16) {\n return;\n }\n\n const colorCount = this.colors === 0 ? 1 << this.bitPP : this.colors;\n if (colorCount <= 0) {\n return;\n }\n\n const paletteStart = this.externalMaskOffset;\n const paletteSize = colorCount * this.paletteEntrySize;\n if (paletteStart + paletteSize > this.offset) {\n throw new Error(\"Palette data overlaps or exceeds pixel data offset\");\n }\n\n this.palette = new Array(colorCount);\n for (let i = 0; i < colorCount; i += 1) {\n const base = paletteStart + i * this.paletteEntrySize;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const quad = this.paletteEntrySize === 4 ? this.readUInt8(base + 3) : 0;\n this.palette[i] = { red, green, blue, quad };\n }\n }\n\n private parseRGBA(): void {\n const pixelCount = this.width * this.height;\n const len = pixelCount * 4;\n this.data = new Uint8Array(len);\n\n switch (this.bitPP) {\n case 1:\n this.bit1();\n return;\n case 4:\n this.bit4();\n return;\n case 8:\n this.bit8();\n return;\n case 15:\n this.bit15();\n return;\n case 16:\n this.bit16();\n return;\n case 24:\n this.bit24();\n return;\n case 32:\n this.bit32();\n return;\n default:\n throw new Error(`Unsupported BMP bit depth: ${this.bitPP}`);\n }\n }\n\n private transformToRgbaIfNeeded(): void {\n if (!this.options.toRGBA) {\n return;\n }\n\n for (let i = 0; i < this.data.length; i += 4) {\n const alpha = this.data[i] ?? 0;\n const blue = this.data[i + 1] ?? 0;\n const green = this.data[i + 2] ?? 0;\n const red = this.data[i + 3] ?? 0;\n\n this.data[i] = red;\n this.data[i + 1] = green;\n this.data[i + 2] = blue;\n this.data[i + 3] = alpha;\n }\n }\n\n private getPaletteColor(index: number): BmpPaletteColor {\n const color = this.palette?.[index];\n if (color) {\n return color;\n }\n\n return { red: 0xff, green: 0xff, blue: 0xff, quad: 0x00 };\n }\n\n private setPixel(\n destY: number,\n x: number,\n alpha: number,\n blue: number,\n green: number,\n red: number,\n ): void {\n const base = (destY * this.width + x) * 4;\n this.data[base] = alpha;\n this.data[base + 1] = blue;\n this.data[base + 2] = green;\n this.data[base + 3] = red;\n }\n\n private bit1(): void {\n const stride = rowStride(this.width, 1);\n const bytesPerRow = Math.ceil(this.width / 8);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"1-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 8));\n const bit = (packed >> (7 - (x % 8))) & 0x01;\n const rgb = this.getPaletteColor(bit);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit4(): void {\n if (this.compress === 2) {\n this.bit4Rle();\n return;\n }\n\n const stride = rowStride(this.width, 4);\n const bytesPerRow = Math.ceil(this.width / 2);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"4-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 2));\n const idx = x % 2 === 0 ? (packed & 0xf0) >> 4 : packed & 0x0f;\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit8(): void {\n if (this.compress === 1) {\n this.bit8Rle();\n return;\n }\n\n const stride = rowStride(this.width, 8);\n const bytesPerRow = this.width;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"8-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const idx = this.readUInt8(rowStart + x);\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit15(): void {\n const stride = rowStride(this.width, 16);\n const max = 0b11111;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"15-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = (((value >> 0) & max) / max) * 255;\n const green = (((value >> 5) & max) / max) * 255;\n const red = (((value >> 10) & max) / max) * 255;\n const alpha = (value & 0x8000) !== 0 ? 0xff : 0x00;\n\n this.setPixel(destY, x, alpha, blue | 0, green | 0, red | 0);\n }\n }\n }\n\n private scaleMasked(value: number, mask: number): number {\n if (mask === 0) return 0;\n let shift = 0;\n let bits = 0;\n let m = mask;\n while ((m & 1) === 0) {\n shift += 1;\n m >>>= 1;\n }\n while ((m & 1) === 1) {\n bits += 1;\n m >>>= 1;\n }\n\n const component = (value & mask) >>> shift;\n if (bits >= 8) {\n return component >>> (bits - 8);\n }\n\n return (component << (8 - bits)) & 0xff;\n }\n\n private bit16(): void {\n if (this.maskRed === 0 && this.maskGreen === 0 && this.maskBlue === 0) {\n this.maskRed = 0x7c00;\n this.maskGreen = 0x03e0;\n this.maskBlue = 0x001f;\n }\n\n const stride = rowStride(this.width, 16);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"16-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = this.scaleMasked(value, this.maskBlue);\n const green = this.scaleMasked(value, this.maskGreen);\n const red = this.scaleMasked(value, this.maskRed);\n const alpha = this.maskAlpha !== 0 ? this.scaleMasked(value, this.maskAlpha) : 0xff;\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n\n private bit24(): void {\n const stride = rowStride(this.width, 24);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 3, \"24-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 3;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n this.setPixel(destY, x, 0xff, blue, green, red);\n }\n }\n }\n\n private bit32(): void {\n const stride = rowStride(this.width, 32);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 4, \"32-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 4;\n if (this.compress === 3 || this.compress === 6) {\n const pixel = this.readUInt32LE(base);\n const red = this.scaleMasked(pixel, this.maskRed || 0x00ff0000);\n const green = this.scaleMasked(pixel, this.maskGreen || 0x0000ff00);\n const blue = this.scaleMasked(pixel, this.maskBlue || 0x000000ff);\n const alpha = this.maskAlpha === 0 ? 0xff : this.scaleMasked(pixel, this.maskAlpha);\n this.setPixel(destY, x, alpha, blue, green, red);\n } else {\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const alpha = this.readUInt8(base + 3);\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n }\n\n private bit8Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n for (let i = 0; i < value; i += 1) {\n const idx = this.readUInt8();\n const rgb = this.getPaletteColor(idx);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n if ((value & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n const rgb = this.getPaletteColor(value);\n for (let i = 0; i < count; i += 1) {\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n private bit4Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n let current = this.readUInt8();\n for (let i = 0; i < value; i += 1) {\n const nibble = i % 2 === 0 ? (current & 0xf0) >> 4 : current & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n if (i % 2 === 1 && i + 1 < value) {\n current = this.readUInt8();\n }\n }\n if ((((value + 1) >> 1) & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n for (let i = 0; i < count; i += 1) {\n const nibble = i % 2 === 0 ? (value & 0xf0) >> 4 : value & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n getData(): Uint8Array {\n return this.data;\n }\n}\n\nexport function decode(bmpData: BmpBinaryInput, options?: DecodeOptions): DecodedBmp {\n return new BmpDecoder(bmpData, options);\n}\n\nexport { BmpDecoder };\n","import { assertInteger } from \"./binary\";\nimport type {\n BmpImageData,\n BmpPaletteColor,\n EncodeBitDepth,\n EncodeOptions,\n EncodedBmp,\n} from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_SIZE = 40;\nconst BYTES_PER_PIXEL_ABGR = 4;\nconst SUPPORTED_BIT_DEPTHS = [1, 4, 8, 16, 24, 32] as const;\n\ntype SupportedBitDepth = (typeof SUPPORTED_BIT_DEPTHS)[number];\ntype ResolvedEncodeOptions = Required<Pick<EncodeOptions, \"orientation\" | \"bitPP\">> & {\n palette: BmpPaletteColor[];\n};\n\nfunction isSupportedBitDepth(value: number): value is SupportedBitDepth {\n return (SUPPORTED_BIT_DEPTHS as readonly number[]).includes(value);\n}\n\nfunction normalizeEncodeOptions(qualityOrOptions?: number | EncodeOptions): ResolvedEncodeOptions {\n if (typeof qualityOrOptions === \"number\" || typeof qualityOrOptions === \"undefined\") {\n return {\n orientation: \"top-down\",\n bitPP: 24,\n palette: [],\n };\n }\n\n return {\n orientation: qualityOrOptions.orientation ?? \"top-down\",\n bitPP: qualityOrOptions.bitPP ?? 24,\n palette: qualityOrOptions.palette ?? [],\n };\n}\n\nclass BmpEncoder {\n private readonly pixelData: Uint8Array;\n private readonly width: number;\n private readonly height: number;\n private readonly options: ResolvedEncodeOptions;\n private readonly palette: BmpPaletteColor[];\n private readonly exactPaletteIndex = new Map<number, number>();\n\n constructor(imgData: BmpImageData, options: ResolvedEncodeOptions) {\n this.pixelData = imgData.data;\n this.width = imgData.width;\n this.height = imgData.height;\n this.options = options;\n this.palette = this.normalizePalette(options);\n\n assertInteger(\"width\", this.width);\n assertInteger(\"height\", this.height);\n\n if (!isSupportedBitDepth(this.options.bitPP)) {\n throw new Error(\n `Unsupported encode bit depth: ${this.options.bitPP}. Supported: 1, 4, 8, 16, 24, 32.`,\n );\n }\n\n const minLength = this.width * this.height * BYTES_PER_PIXEL_ABGR;\n if (this.pixelData.length < minLength) {\n throw new Error(\n `Image data is too short: expected at least ${minLength} bytes for ${this.width}x${this.height} ABGR data.`,\n );\n }\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const key = this.paletteKey(color.quad, color.blue, color.green, color.red);\n if (!this.exactPaletteIndex.has(key)) {\n this.exactPaletteIndex.set(key, i);\n }\n }\n }\n\n private normalizePalette(options: ResolvedEncodeOptions): BmpPaletteColor[] {\n if (options.bitPP === 1) {\n const palette = options.palette.length\n ? options.palette\n : [\n { red: 255, green: 255, blue: 255, quad: 0 },\n { red: 0, green: 0, blue: 0, quad: 0 },\n ];\n this.validatePalette(options.bitPP, palette);\n return palette;\n }\n\n if (options.bitPP === 4 || options.bitPP === 8) {\n if (options.palette.length === 0) {\n throw new Error(`Encoding ${options.bitPP}-bit BMP requires a non-empty palette.`);\n }\n this.validatePalette(options.bitPP, options.palette);\n return options.palette;\n }\n\n return [];\n }\n\n private validatePalette(bitPP: 1 | 4 | 8, palette: BmpPaletteColor[]): void {\n const maxSize = 1 << bitPP;\n if (palette.length === 0 || palette.length > maxSize) {\n throw new Error(\n `Palette size ${palette.length} is invalid for ${bitPP}-bit BMP. Expected 1..${maxSize}.`,\n );\n }\n\n for (const color of palette) {\n this.validateChannel(\"palette.red\", color.red);\n this.validateChannel(\"palette.green\", color.green);\n this.validateChannel(\"palette.blue\", color.blue);\n this.validateChannel(\"palette.quad\", color.quad);\n }\n }\n\n private validateChannel(name: string, value: number): void {\n if (!Number.isInteger(value) || value < 0 || value > 255) {\n throw new Error(`${name} must be an integer between 0 and 255.`);\n }\n }\n\n private rowStride(): number {\n return Math.floor((this.options.bitPP * this.width + 31) / 32) * 4;\n }\n\n private sourceY(fileRow: number): number {\n return this.options.orientation === \"top-down\" ? fileRow : this.height - 1 - fileRow;\n }\n\n private sourceOffset(x: number, y: number): number {\n return (y * this.width + x) * BYTES_PER_PIXEL_ABGR;\n }\n\n private paletteKey(alpha: number, blue: number, green: number, red: number): number {\n return (\n (((alpha & 0xff) << 24) | ((blue & 0xff) << 16) | ((green & 0xff) << 8) | (red & 0xff)) >>> 0\n );\n }\n\n private findPaletteIndex(a: number, b: number, g: number, r: number): number {\n const exact = this.exactPaletteIndex.get(this.paletteKey(a, b, g, r));\n if (exact !== undefined) {\n return exact;\n }\n\n let bestIndex = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const dr = color.red - r;\n const dg = color.green - g;\n const db = color.blue - b;\n const da = color.quad - a;\n const distance = dr * dr + dg * dg + db * db + da * da;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestIndex = i;\n }\n }\n\n return bestIndex;\n }\n\n private writePalette(output: Uint8Array, paletteOffset: number): void {\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const base = paletteOffset + i * 4;\n output[base] = color.blue;\n output[base + 1] = color.green;\n output[base + 2] = color.red;\n output[base + 3] = color.quad;\n }\n }\n\n private encode1Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 8) {\n let packed = 0;\n for (let bit = 0; bit < 8; bit += 1) {\n const px = x + bit;\n if (px >= this.width) {\n break;\n }\n const source = this.sourceOffset(px, srcY);\n const a = this.pixelData[source] ?? 0xff;\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n const idx = this.findPaletteIndex(a, b, g, r) & 0x01;\n packed |= idx << (7 - bit);\n }\n output[rowStart + Math.floor(x / 8)] = packed;\n }\n }\n }\n\n private encode4Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 2) {\n const sourceA = this.sourceOffset(x, srcY);\n const idxA = this.findPaletteIndex(\n this.pixelData[sourceA] ?? 0xff,\n this.pixelData[sourceA + 1] ?? 0,\n this.pixelData[sourceA + 2] ?? 0,\n this.pixelData[sourceA + 3] ?? 0,\n );\n\n let idxB = 0;\n if (x + 1 < this.width) {\n const sourceB = this.sourceOffset(x + 1, srcY);\n idxB = this.findPaletteIndex(\n this.pixelData[sourceB] ?? 0xff,\n this.pixelData[sourceB + 1] ?? 0,\n this.pixelData[sourceB + 2] ?? 0,\n this.pixelData[sourceB + 3] ?? 0,\n );\n }\n\n output[rowStart + Math.floor(x / 2)] = ((idxA & 0x0f) << 4) | (idxB & 0x0f);\n }\n }\n }\n\n private encode8Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n output[rowStart + x] = this.findPaletteIndex(\n this.pixelData[source] ?? 0xff,\n this.pixelData[source + 1] ?? 0,\n this.pixelData[source + 2] ?? 0,\n this.pixelData[source + 3] ?? 0,\n );\n }\n }\n }\n\n private encode16Bit(\n output: Uint8Array,\n view: DataView,\n pixelOffset: number,\n stride: number,\n ): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n\n const value = (((r >> 3) & 0x1f) << 10) | (((g >> 3) & 0x1f) << 5) | ((b >> 3) & 0x1f);\n view.setUint16(rowStart + x * 2, value, true);\n }\n }\n }\n\n private encode24Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 3;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n }\n }\n }\n\n private encode32Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 4;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n output[target + 3] = this.pixelData[source] ?? 0xff;\n }\n }\n }\n\n encode(): Uint8Array {\n const stride = this.rowStride();\n const imageSize = stride * this.height;\n const paletteSize = this.palette.length * 4;\n const offset = FILE_HEADER_SIZE + INFO_HEADER_SIZE + paletteSize;\n const totalSize = offset + imageSize;\n const output = new Uint8Array(totalSize);\n const view = new DataView(output.buffer, output.byteOffset, output.byteLength);\n\n // BITMAPFILEHEADER\n output[0] = 0x42; // B\n output[1] = 0x4d; // M\n view.setUint32(2, totalSize, true);\n view.setUint32(6, 0, true);\n view.setUint32(10, offset, true);\n\n // BITMAPINFOHEADER\n view.setUint32(14, INFO_HEADER_SIZE, true);\n view.setInt32(18, this.width, true);\n const signedHeight = this.options.orientation === \"top-down\" ? -this.height : this.height;\n view.setInt32(22, signedHeight, true);\n view.setUint16(26, 1, true);\n view.setUint16(28, this.options.bitPP, true);\n view.setUint32(30, 0, true);\n view.setUint32(34, imageSize, true);\n view.setUint32(38, 0, true);\n view.setUint32(42, 0, true);\n view.setUint32(46, this.palette.length, true);\n view.setUint32(50, 0, true);\n\n if (this.palette.length > 0) {\n this.writePalette(output, FILE_HEADER_SIZE + INFO_HEADER_SIZE);\n }\n\n switch (this.options.bitPP as EncodeBitDepth) {\n case 1:\n this.encode1Bit(output, offset, stride);\n break;\n case 4:\n this.encode4Bit(output, offset, stride);\n break;\n case 8:\n this.encode8Bit(output, offset, stride);\n break;\n case 16:\n this.encode16Bit(output, view, offset, stride);\n break;\n case 24:\n this.encode24Bit(output, offset, stride);\n break;\n case 32:\n this.encode32Bit(output, offset, stride);\n break;\n }\n\n return output;\n }\n}\n\nexport function encode(\n imgData: BmpImageData,\n qualityOrOptions?: number | EncodeOptions,\n): EncodedBmp {\n const options = normalizeEncodeOptions(qualityOrOptions);\n const encoder = new BmpEncoder(imgData, options);\n const data = encoder.encode();\n\n return {\n data,\n width: imgData.width,\n height: imgData.height,\n };\n}\n\nexport { BmpEncoder };\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AU,QAAQ;AAAA,EAClC;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM,WAAW,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF,EAAE;AACJ;","names":["rgb","FILE_HEADER_SIZE","require","toUint8Array"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as sharp from 'sharp';
|
|
2
|
+
import { e as EncodeBitDepth, B as BmpPaletteColor } from '../types-CzYgOtEn.cjs';
|
|
3
|
+
|
|
4
|
+
interface SharpRawDescriptor {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
channels: 3 | 4;
|
|
8
|
+
premultiplied?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface DecodedSharpInput {
|
|
11
|
+
data: Uint8Array;
|
|
12
|
+
raw: SharpRawDescriptor & {
|
|
13
|
+
channels: 4;
|
|
14
|
+
};
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
channels: 4;
|
|
18
|
+
}
|
|
19
|
+
interface SharpRawInfo {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
channels: number;
|
|
23
|
+
premultiplied?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface SharpRawLike {
|
|
26
|
+
data: Uint8Array;
|
|
27
|
+
info: SharpRawInfo;
|
|
28
|
+
}
|
|
29
|
+
interface EncodeBmpOptions {
|
|
30
|
+
bitDepth?: EncodeBitDepth;
|
|
31
|
+
topDown?: boolean;
|
|
32
|
+
palette?: BmpPaletteColor[];
|
|
33
|
+
}
|
|
34
|
+
type BmpSharpInput = Uint8Array | ArrayBufferLike;
|
|
35
|
+
type DecodeForSharpInput = Uint8Array | ArrayBufferLike;
|
|
36
|
+
type SharpModule = typeof sharp;
|
|
37
|
+
type SharpInstance = sharp.Sharp;
|
|
38
|
+
|
|
39
|
+
declare class SharpAdapterError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
declare class NotBmpInputError extends SharpAdapterError {
|
|
43
|
+
constructor();
|
|
44
|
+
}
|
|
45
|
+
declare class SharpModuleLoadError extends SharpAdapterError {
|
|
46
|
+
constructor(message?: string);
|
|
47
|
+
}
|
|
48
|
+
declare class InvalidSharpRawInputError extends SharpAdapterError {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare function isBmp(input: BmpSharpInput): boolean;
|
|
53
|
+
declare function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput;
|
|
54
|
+
declare function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput;
|
|
55
|
+
declare function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;
|
|
56
|
+
declare function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;
|
|
57
|
+
|
|
58
|
+
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, SharpAdapterError, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as sharp from 'sharp';
|
|
2
|
+
import { e as EncodeBitDepth, B as BmpPaletteColor } from '../types-CzYgOtEn.js';
|
|
3
|
+
|
|
4
|
+
interface SharpRawDescriptor {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
channels: 3 | 4;
|
|
8
|
+
premultiplied?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface DecodedSharpInput {
|
|
11
|
+
data: Uint8Array;
|
|
12
|
+
raw: SharpRawDescriptor & {
|
|
13
|
+
channels: 4;
|
|
14
|
+
};
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
channels: 4;
|
|
18
|
+
}
|
|
19
|
+
interface SharpRawInfo {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
channels: number;
|
|
23
|
+
premultiplied?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface SharpRawLike {
|
|
26
|
+
data: Uint8Array;
|
|
27
|
+
info: SharpRawInfo;
|
|
28
|
+
}
|
|
29
|
+
interface EncodeBmpOptions {
|
|
30
|
+
bitDepth?: EncodeBitDepth;
|
|
31
|
+
topDown?: boolean;
|
|
32
|
+
palette?: BmpPaletteColor[];
|
|
33
|
+
}
|
|
34
|
+
type BmpSharpInput = Uint8Array | ArrayBufferLike;
|
|
35
|
+
type DecodeForSharpInput = Uint8Array | ArrayBufferLike;
|
|
36
|
+
type SharpModule = typeof sharp;
|
|
37
|
+
type SharpInstance = sharp.Sharp;
|
|
38
|
+
|
|
39
|
+
declare class SharpAdapterError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
declare class NotBmpInputError extends SharpAdapterError {
|
|
43
|
+
constructor();
|
|
44
|
+
}
|
|
45
|
+
declare class SharpModuleLoadError extends SharpAdapterError {
|
|
46
|
+
constructor(message?: string);
|
|
47
|
+
}
|
|
48
|
+
declare class InvalidSharpRawInputError extends SharpAdapterError {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare function isBmp(input: BmpSharpInput): boolean;
|
|
53
|
+
declare function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput;
|
|
54
|
+
declare function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput;
|
|
55
|
+
declare function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;
|
|
56
|
+
declare function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;
|
|
57
|
+
|
|
58
|
+
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, SharpAdapterError, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decode,
|
|
3
|
+
encode
|
|
4
|
+
} from "../chunk-YH5DJH4H.js";
|
|
5
|
+
|
|
6
|
+
// src/sharp/index.ts
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
|
|
9
|
+
// src/sharp/errors.ts
|
|
10
|
+
var SharpAdapterError = class extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "SharpAdapterError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var NotBmpInputError = class extends SharpAdapterError {
|
|
17
|
+
constructor() {
|
|
18
|
+
super("Input is not a BMP file.");
|
|
19
|
+
this.name = "NotBmpInputError";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var SharpModuleLoadError = class extends SharpAdapterError {
|
|
23
|
+
constructor(message = "Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.") {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "SharpModuleLoadError";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var InvalidSharpRawInputError = class extends SharpAdapterError {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "InvalidSharpRawInputError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/sharp/index.ts
|
|
36
|
+
var require2 = createRequire(
|
|
37
|
+
typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`
|
|
38
|
+
);
|
|
39
|
+
function toUint8Array(input) {
|
|
40
|
+
if (input instanceof Uint8Array) {
|
|
41
|
+
return input;
|
|
42
|
+
}
|
|
43
|
+
return new Uint8Array(input);
|
|
44
|
+
}
|
|
45
|
+
function toAbgrData(input, channels) {
|
|
46
|
+
const pixelCount = Math.floor(input.length / channels);
|
|
47
|
+
const output = new Uint8Array(pixelCount * 4);
|
|
48
|
+
for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {
|
|
49
|
+
const red = input[src] ?? 0;
|
|
50
|
+
const green = input[src + 1] ?? 0;
|
|
51
|
+
const blue = input[src + 2] ?? 0;
|
|
52
|
+
const alpha = channels === 4 ? input[src + 3] ?? 255 : 255;
|
|
53
|
+
output[dst] = alpha;
|
|
54
|
+
output[dst + 1] = blue;
|
|
55
|
+
output[dst + 2] = green;
|
|
56
|
+
output[dst + 3] = red;
|
|
57
|
+
}
|
|
58
|
+
return output;
|
|
59
|
+
}
|
|
60
|
+
function loadSharpModule(sharpModule) {
|
|
61
|
+
if (sharpModule) {
|
|
62
|
+
return sharpModule;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const loaded = require2("sharp");
|
|
66
|
+
if (typeof loaded === "function") {
|
|
67
|
+
return loaded;
|
|
68
|
+
}
|
|
69
|
+
if (loaded.default && typeof loaded.default === "function") {
|
|
70
|
+
return loaded.default;
|
|
71
|
+
}
|
|
72
|
+
throw new SharpModuleLoadError("Loaded 'sharp' module has an unexpected shape.");
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error instanceof SharpModuleLoadError) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
throw new SharpModuleLoadError();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function assertPositiveInteger(name, value) {
|
|
81
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
82
|
+
throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function normalizeBitDepth(channels, bitDepth) {
|
|
86
|
+
if (bitDepth !== void 0) {
|
|
87
|
+
return bitDepth;
|
|
88
|
+
}
|
|
89
|
+
return channels === 4 ? 32 : 24;
|
|
90
|
+
}
|
|
91
|
+
function isBmp(input) {
|
|
92
|
+
try {
|
|
93
|
+
const bytes = toUint8Array(input);
|
|
94
|
+
return bytes.length >= 2 && bytes[0] === 66 && bytes[1] === 77;
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function decodeForSharp(input) {
|
|
100
|
+
const bytes = toUint8Array(input);
|
|
101
|
+
if (!isBmp(bytes)) {
|
|
102
|
+
throw new NotBmpInputError();
|
|
103
|
+
}
|
|
104
|
+
const decoded = decode(bytes, { toRGBA: true });
|
|
105
|
+
const raw = {
|
|
106
|
+
width: decoded.width,
|
|
107
|
+
height: decoded.height,
|
|
108
|
+
channels: 4
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
data: decoded.data,
|
|
112
|
+
raw,
|
|
113
|
+
width: decoded.width,
|
|
114
|
+
height: decoded.height,
|
|
115
|
+
channels: 4
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function toSharpInput(input) {
|
|
119
|
+
return decodeForSharp(input);
|
|
120
|
+
}
|
|
121
|
+
function sharpFromBmp(input, sharpModule) {
|
|
122
|
+
const decoded = decodeForSharp(input);
|
|
123
|
+
const sharp = loadSharpModule(sharpModule);
|
|
124
|
+
return sharp(decoded.data, { raw: decoded.raw });
|
|
125
|
+
}
|
|
126
|
+
function encodeFromSharp(input, options = {}) {
|
|
127
|
+
const data = toUint8Array(input.data);
|
|
128
|
+
const width = input.info.width;
|
|
129
|
+
const height = input.info.height;
|
|
130
|
+
const channels = input.info.channels;
|
|
131
|
+
assertPositiveInteger("info.width", width);
|
|
132
|
+
assertPositiveInteger("info.height", height);
|
|
133
|
+
if (channels !== 3 && channels !== 4) {
|
|
134
|
+
throw new InvalidSharpRawInputError(
|
|
135
|
+
`Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const expectedLength = width * height * channels;
|
|
139
|
+
if (data.length !== expectedLength) {
|
|
140
|
+
throw new InvalidSharpRawInputError(
|
|
141
|
+
`Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const bitDepth = normalizeBitDepth(channels, options.bitDepth);
|
|
145
|
+
const encodeOptions = {
|
|
146
|
+
bitPP: bitDepth,
|
|
147
|
+
orientation: options.topDown ? "top-down" : "bottom-up"
|
|
148
|
+
};
|
|
149
|
+
if (options.palette) {
|
|
150
|
+
encodeOptions.palette = options.palette;
|
|
151
|
+
}
|
|
152
|
+
return encode(
|
|
153
|
+
{
|
|
154
|
+
data: toAbgrData(data, channels),
|
|
155
|
+
width,
|
|
156
|
+
height
|
|
157
|
+
},
|
|
158
|
+
encodeOptions
|
|
159
|
+
).data;
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
InvalidSharpRawInputError,
|
|
163
|
+
NotBmpInputError,
|
|
164
|
+
SharpAdapterError,
|
|
165
|
+
SharpModuleLoadError,
|
|
166
|
+
decodeForSharp,
|
|
167
|
+
encodeFromSharp,
|
|
168
|
+
isBmp,
|
|
169
|
+
sharpFromBmp,
|
|
170
|
+
toSharpInput
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sharp/index.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: DecodeForSharpInput | BmpSharpInput): Uint8Array {\n if (input instanceof Uint8Array) {\n return input;\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nexport function isBmp(input: BmpSharpInput): boolean {\n try {\n const bytes = toUint8Array(input);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance {\n const decoded = decodeForSharp(input);\n const sharp = loadSharpModule(sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options: EncodeBmpOptions = {}): Uint8Array {\n const data = toUint8Array(input.data);\n const width = input.info.width;\n const height = input.info.height;\n const channels = input.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (options.palette) {\n encodeOptions.palette = options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,qBAAqB;;;ACAvB,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,kBAAkB;AAAA,EACtD,cAAc;AACZ,UAAM,0BAA0B;AAChC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,uBAAN,cAAmC,kBAAkB;AAAA,EAC1D,YACE,UAAU,0FACV;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,4BAAN,cAAwC,kBAAkB;AAAA,EAC/D,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADVA,IAAMA,WAAU;AAAA,EACd,OAAO,eAAe,WAAW,aAAa,GAAG,QAAQ,IAAI,CAAC;AAChE;AAEA,SAAS,aAAa,OAAwD;AAC5E,MAAI,iBAAiB,YAAY;AAC/B,WAAO;AAAA,EACT;AAEA,SAAO,IAAI,WAAW,KAAK;AAC7B;AAEA,SAAS,WAAW,OAAmB,UAA6B;AAClE,QAAM,aAAa,KAAK,MAAM,MAAM,SAAS,QAAQ;AACrD,QAAM,SAAS,IAAI,WAAW,aAAa,CAAC;AAE5C,WAAS,MAAM,GAAG,MAAM,GAAG,MAAM,MAAM,QAAQ,OAA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,EAC9C;AAEA,MAAI,QAAQ,SAAS;AACnB,kBAAc,UAAU,QAAQ;AAAA,EAClC;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM,WAAW,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF,EAAE;AACJ;","names":["require"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface BmpPaletteColor {
|
|
2
|
+
red: number;
|
|
3
|
+
green: number;
|
|
4
|
+
blue: number;
|
|
5
|
+
quad: number;
|
|
6
|
+
}
|
|
7
|
+
type BmpBinaryInput = ArrayBuffer | ArrayBufferView;
|
|
8
|
+
type EncodeBitDepth = 1 | 4 | 8 | 16 | 24 | 32;
|
|
9
|
+
interface BmpImageData {
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
interface EncodeOptions {
|
|
15
|
+
orientation?: "top-down" | "bottom-up";
|
|
16
|
+
bitPP?: EncodeBitDepth;
|
|
17
|
+
palette?: BmpPaletteColor[];
|
|
18
|
+
}
|
|
19
|
+
interface DecodeOptions {
|
|
20
|
+
treat16BitAs15BitAlpha?: boolean;
|
|
21
|
+
toRGBA?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface EncodedBmp {
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
interface DecodedBmp {
|
|
29
|
+
fileSize: number;
|
|
30
|
+
reserved: number;
|
|
31
|
+
offset: number;
|
|
32
|
+
headerSize: number;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
planes: number;
|
|
36
|
+
bitPP: number;
|
|
37
|
+
compress: number;
|
|
38
|
+
rawSize: number;
|
|
39
|
+
hr: number;
|
|
40
|
+
vr: number;
|
|
41
|
+
colors: number;
|
|
42
|
+
importantColors: number;
|
|
43
|
+
palette?: BmpPaletteColor[];
|
|
44
|
+
data: Uint8Array;
|
|
45
|
+
getData(): Uint8Array;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type { BmpPaletteColor as B, DecodedBmp as D, EncodeOptions as E, BmpBinaryInput as a, DecodeOptions as b, BmpImageData as c, EncodedBmp as d, EncodeBitDepth as e };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface BmpPaletteColor {
|
|
2
|
+
red: number;
|
|
3
|
+
green: number;
|
|
4
|
+
blue: number;
|
|
5
|
+
quad: number;
|
|
6
|
+
}
|
|
7
|
+
type BmpBinaryInput = ArrayBuffer | ArrayBufferView;
|
|
8
|
+
type EncodeBitDepth = 1 | 4 | 8 | 16 | 24 | 32;
|
|
9
|
+
interface BmpImageData {
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
interface EncodeOptions {
|
|
15
|
+
orientation?: "top-down" | "bottom-up";
|
|
16
|
+
bitPP?: EncodeBitDepth;
|
|
17
|
+
palette?: BmpPaletteColor[];
|
|
18
|
+
}
|
|
19
|
+
interface DecodeOptions {
|
|
20
|
+
treat16BitAs15BitAlpha?: boolean;
|
|
21
|
+
toRGBA?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface EncodedBmp {
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
interface DecodedBmp {
|
|
29
|
+
fileSize: number;
|
|
30
|
+
reserved: number;
|
|
31
|
+
offset: number;
|
|
32
|
+
headerSize: number;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
planes: number;
|
|
36
|
+
bitPP: number;
|
|
37
|
+
compress: number;
|
|
38
|
+
rawSize: number;
|
|
39
|
+
hr: number;
|
|
40
|
+
vr: number;
|
|
41
|
+
colors: number;
|
|
42
|
+
importantColors: number;
|
|
43
|
+
palette?: BmpPaletteColor[];
|
|
44
|
+
data: Uint8Array;
|
|
45
|
+
getData(): Uint8Array;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type { BmpPaletteColor as B, DecodedBmp as D, EncodeOptions as E, BmpBinaryInput as a, DecodeOptions as b, BmpImageData as c, EncodedBmp as d, EncodeBitDepth as e };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huh-david/bmp-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A pure TypeScript BMP encoder and decoder for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bmp",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"image",
|
|
12
12
|
"typescript"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://github.
|
|
14
|
+
"homepage": "https://huh-david.github.io/bmp-js/",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/Huh-David/bmp-js/issues"
|
|
17
17
|
},
|
|
@@ -41,6 +41,12 @@
|
|
|
41
41
|
"require": "./dist/index.cjs",
|
|
42
42
|
"default": "./dist/index.js"
|
|
43
43
|
},
|
|
44
|
+
"./sharp": {
|
|
45
|
+
"types": "./dist/sharp/index.d.ts",
|
|
46
|
+
"import": "./dist/sharp/index.js",
|
|
47
|
+
"require": "./dist/sharp/index.cjs",
|
|
48
|
+
"default": "./dist/sharp/index.js"
|
|
49
|
+
},
|
|
44
50
|
"./package.json": "./package.json"
|
|
45
51
|
},
|
|
46
52
|
"publishConfig": {
|
|
@@ -53,10 +59,22 @@
|
|
|
53
59
|
"oxfmt": "^0.42.0",
|
|
54
60
|
"oxlint": "^1.57.0",
|
|
55
61
|
"rimraf": "^6.0.1",
|
|
62
|
+
"sharp": "^0.33.5",
|
|
56
63
|
"tsup": "^8.5.1",
|
|
64
|
+
"typedoc": "^0.28.14",
|
|
65
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
57
66
|
"typescript": "^5.9.3",
|
|
67
|
+
"vitepress": "^1.6.3",
|
|
58
68
|
"vitest": "^3.2.4"
|
|
59
69
|
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"sharp": "^0.33.5"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"sharp": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
60
78
|
"engines": {
|
|
61
79
|
"node": ">=22"
|
|
62
80
|
},
|
|
@@ -71,6 +89,11 @@
|
|
|
71
89
|
"typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.test.json --noEmit",
|
|
72
90
|
"fixtures:generate": "node scripts/generate-bmp-fixtures.mjs",
|
|
73
91
|
"fixtures:validate": "node scripts/validate-fixture-provenance.mjs",
|
|
92
|
+
"docs:api": "rimraf site/api/reference && typedoc --options typedoc.json",
|
|
93
|
+
"docs:dev": "pnpm docs:api && vitepress dev site",
|
|
94
|
+
"docs:build": "pnpm docs:api && vitepress build site",
|
|
95
|
+
"docs:preview": "vitepress preview site",
|
|
96
|
+
"docs:check": "pnpm docs:build",
|
|
74
97
|
"pack:check": "npm pack --dry-run > /dev/null",
|
|
75
98
|
"check": "pnpm format:check && pnpm lint && pnpm fixtures:validate && pnpm typecheck && pnpm test && pnpm pack:check",
|
|
76
99
|
"changeset": "changeset",
|