1 | import {
|
2 | watch
|
3 | } from "./chunk.W6MGCO4G.js";
|
4 | import {
|
5 | emit
|
6 | } from "./chunk.UY5AQKHP.js";
|
7 | import {
|
8 | e,
|
9 | i,
|
10 | n,
|
11 | t
|
12 | } from "./chunk.VKNZYXSO.js";
|
13 | import {
|
14 | animated_image_styles_default
|
15 | } from "./chunk.H6ATIIQQ.js";
|
16 | import {
|
17 | $,
|
18 | s
|
19 | } from "./chunk.WWAD5WF4.js";
|
20 | import {
|
21 | __decorateClass
|
22 | } from "./chunk.K2NRSETB.js";
|
23 |
|
24 |
|
25 | var SlAnimatedImage = class extends s {
|
26 | constructor() {
|
27 | super(...arguments);
|
28 | this.isLoaded = false;
|
29 | }
|
30 | handleClick() {
|
31 | this.play = !this.play;
|
32 | }
|
33 | handleLoad() {
|
34 | const canvas = document.createElement("canvas");
|
35 | const { width, height } = this.animatedImage;
|
36 | canvas.width = width;
|
37 | canvas.height = height;
|
38 | canvas.getContext("2d").drawImage(this.animatedImage, 0, 0, width, height);
|
39 | this.frozenFrame = canvas.toDataURL("image/gif");
|
40 | if (!this.isLoaded) {
|
41 | emit(this, "sl-load");
|
42 | this.isLoaded = true;
|
43 | }
|
44 | }
|
45 | handleError() {
|
46 | emit(this, "sl-error");
|
47 | }
|
48 | handlePlayChange() {
|
49 | if (this.play) {
|
50 | this.animatedImage.src = "";
|
51 | this.animatedImage.src = this.src;
|
52 | }
|
53 | }
|
54 | handleSrcChange() {
|
55 | this.isLoaded = false;
|
56 | }
|
57 | render() {
|
58 | return $`
|
59 | <div class="animated-image">
|
60 | <img
|
61 | class="animated-image__animated"
|
62 | src=${this.src}
|
63 | alt=${this.alt}
|
64 | crossorigin="anonymous"
|
65 | aria-hidden=${this.play ? "false" : "true"}
|
66 | @click=${this.handleClick}
|
67 | @load=${this.handleLoad}
|
68 | @error=${this.handleError}
|
69 | />
|
70 |
|
71 | ${this.isLoaded ? $`
|
72 | <img
|
73 | class="animated-image__frozen"
|
74 | src=${this.frozenFrame}
|
75 | alt=${this.alt}
|
76 | aria-hidden=${this.play ? "true" : "false"}
|
77 | @click=${this.handleClick}
|
78 | />
|
79 |
|
80 | <div part="control-box" class="animated-image__control-box">
|
81 | ${this.play ? $`<sl-icon part="pause-icon" name="pause-fill" library="system"></sl-icon>` : $`<sl-icon part="play-icon" name="play-fill" library="system"></sl-icon>`}
|
82 | </div>
|
83 | ` : ""}
|
84 | </div>
|
85 | `;
|
86 | }
|
87 | };
|
88 | SlAnimatedImage.styles = animated_image_styles_default;
|
89 | __decorateClass([
|
90 | t()
|
91 | ], SlAnimatedImage.prototype, "frozenFrame", 2);
|
92 | __decorateClass([
|
93 | t()
|
94 | ], SlAnimatedImage.prototype, "isLoaded", 2);
|
95 | __decorateClass([
|
96 | i(".animated-image__animated")
|
97 | ], SlAnimatedImage.prototype, "animatedImage", 2);
|
98 | __decorateClass([
|
99 | e()
|
100 | ], SlAnimatedImage.prototype, "src", 2);
|
101 | __decorateClass([
|
102 | e()
|
103 | ], SlAnimatedImage.prototype, "alt", 2);
|
104 | __decorateClass([
|
105 | e({ type: Boolean, reflect: true })
|
106 | ], SlAnimatedImage.prototype, "play", 2);
|
107 | __decorateClass([
|
108 | watch("play", { waitUntilFirstUpdate: true })
|
109 | ], SlAnimatedImage.prototype, "handlePlayChange", 1);
|
110 | __decorateClass([
|
111 | watch("src")
|
112 | ], SlAnimatedImage.prototype, "handleSrcChange", 1);
|
113 | SlAnimatedImage = __decorateClass([
|
114 | n("sl-animated-image")
|
115 | ], SlAnimatedImage);
|
116 |
|
117 | export {
|
118 | SlAnimatedImage
|
119 | };
|