1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const index = require('./index-a0a08b2a.js');
|
6 | const ionicGlobal = require('./ionic-global-06f21c1a.js');
|
7 |
|
8 | const imgCss = ":host{display:block;-o-object-fit:contain;object-fit:contain}img{display:block;width:100%;height:100%;-o-object-fit:inherit;object-fit:inherit;-o-object-position:inherit;object-position:inherit}";
|
9 |
|
10 | const Img = class {
|
11 | constructor(hostRef) {
|
12 | index.registerInstance(this, hostRef);
|
13 | this.ionImgWillLoad = index.createEvent(this, "ionImgWillLoad", 7);
|
14 | this.ionImgDidLoad = index.createEvent(this, "ionImgDidLoad", 7);
|
15 | this.ionError = index.createEvent(this, "ionError", 7);
|
16 | this.onLoad = () => {
|
17 | this.ionImgDidLoad.emit();
|
18 | };
|
19 | this.onError = () => {
|
20 | this.ionError.emit();
|
21 | };
|
22 | }
|
23 | srcChanged() {
|
24 | this.addIO();
|
25 | }
|
26 | componentDidLoad() {
|
27 | this.addIO();
|
28 | }
|
29 | addIO() {
|
30 | if (this.src === undefined) {
|
31 | return;
|
32 | }
|
33 | if (typeof window !== 'undefined' &&
|
34 | 'IntersectionObserver' in window &&
|
35 | 'IntersectionObserverEntry' in window &&
|
36 | 'isIntersecting' in window.IntersectionObserverEntry.prototype) {
|
37 | this.removeIO();
|
38 | this.io = new IntersectionObserver(data => {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | if (data[data.length - 1].isIntersecting) {
|
45 | this.load();
|
46 | this.removeIO();
|
47 | }
|
48 | });
|
49 | this.io.observe(this.el);
|
50 | }
|
51 | else {
|
52 |
|
53 | setTimeout(() => this.load(), 200);
|
54 | }
|
55 | }
|
56 | load() {
|
57 | this.loadError = this.onError;
|
58 | this.loadSrc = this.src;
|
59 | this.ionImgWillLoad.emit();
|
60 | }
|
61 | removeIO() {
|
62 | if (this.io) {
|
63 | this.io.disconnect();
|
64 | this.io = undefined;
|
65 | }
|
66 | }
|
67 | render() {
|
68 | return (index.h(index.Host, { class: ionicGlobal.getIonMode(this) }, index.h("img", { decoding: "async", src: this.loadSrc, alt: this.alt, onLoad: this.onLoad, onError: this.loadError, part: "image" })));
|
69 | }
|
70 | get el() { return index.getElement(this); }
|
71 | static get watchers() { return {
|
72 | "src": ["srcChanged"]
|
73 | }; }
|
74 | };
|
75 | Img.style = imgCss;
|
76 |
|
77 | exports.ion_img = Img;
|