UNPKG

@ynmstudio/utils

Version:
1 lines 3.96 kB
{"version":3,"file":"ynmstudio-utils-blurhash.mjs","sources":["../../../projects/ynm-utils/blurhash/src/lib/draw-blurhash.directive.ts","../../../projects/ynm-utils/blurhash/src/public_api.ts","../../../projects/ynm-utils/blurhash/src/ynmstudio-utils-blurhash.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n AfterViewInit,\n Directive,\n ElementRef,\n HostBinding,\n Inject,\n Input,\n PLATFORM_ID,\n} from '@angular/core';\n\n@Directive({\n selector: '[drawBlurhash]',\n standalone: true\n})\nexport class DrawBlurhash implements AfterViewInit {\n @Input() blurhash?: string | null;\n\n @HostBinding('attr.width') get width(): number {\n return this.WIDTH;\n }\n @HostBinding('attr.height') get height(): number {\n return this.HEIGHT;\n }\n\n constructor(@Inject(PLATFORM_ID) private platformId: Object, private readonly canvas: ElementRef<HTMLCanvasElement>) { }\n\n ngAfterViewInit(): void {\n this.drawCanvas();\n }\n WIDTH = 32;\n HEIGHT = 32;\n\n private decode?: (\n blur_hash: string,\n width: number,\n height: number\n ) => Uint8Array | undefined;\n\n private async drawCanvas(): Promise<void> {\n if (!isPlatformBrowser(this.platformId)) return;\n try {\n if (!this.blurhash || !this.canvas) return;\n if (!this.decode) {\n const { decode } = await import('blurhash-wasm');\n this.decode = decode;\n }\n const pixels = this.decode(this.blurhash, this.WIDTH, this.HEIGHT);\n if (!pixels) return;\n const asClamped = new Uint8ClampedArray(pixels);\n const imageData = new ImageData(asClamped, this.WIDTH, this.HEIGHT);\n const ctx = this.canvas?.nativeElement.getContext('2d');\n if (imageData) ctx?.putImageData(imageData, 0, 0);\n } catch (error) {\n console.error(error);\n }\n }\n}\n","/*\n * Public API Surface of draw-blurhash\n */\n\nexport * from './lib/draw-blurhash.directive';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;MAea,YAAY,CAAA;AAGvB,IAAA,IAA+B,KAAK,GAAA;QAClC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