@everymatrix/casino-engagement-suite-container 1.77.0 → 1.77.2

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.
@@ -6,59 +6,140 @@ const UiImageStyle0 = uiImageCss;
6
6
  const UiImage = class {
7
7
  constructor(hostRef) {
8
8
  registerInstance(this, hostRef);
9
+ this.hasStarted = false;
9
10
  this.src = undefined;
10
11
  this.width = undefined;
11
12
  this.height = undefined;
12
13
  this.alt = undefined;
13
14
  this.styles = undefined;
14
15
  this.detectDistance = '200px';
16
+ this.loading = 'lazy';
15
17
  this.imgLoaded = false;
16
- this.shouldLoad = false;
17
18
  }
18
- handleSrc() {
19
- if (!this.shouldLoad) {
19
+ onSrcChange() {
20
+ if (this.loading === 'eager')
20
21
  return;
22
+ this.imgLoaded = false;
23
+ this.hasStarted = false;
24
+ if (typeof window === 'undefined' || !('IntersectionObserver' in window)) {
25
+ this.beginLoad();
21
26
  }
22
- const preloadedImage = new Image();
23
- preloadedImage.onload = () => {
24
- if (this.image) {
25
- this.image.src = this.src;
26
- this.imgLoaded = true;
27
- preloadedImage.onload = null;
27
+ }
28
+ onLoadingChange(newVal, oldVal) {
29
+ if (newVal === oldVal)
30
+ return;
31
+ this.cleanupObserver();
32
+ this.detachImgHandlers();
33
+ if (newVal === 'eager') {
34
+ if (this.imgEl && this.src) {
35
+ this.imgEl.src = this.src;
28
36
  }
29
- };
30
- preloadedImage.src = this.src;
37
+ this.hasStarted = true;
38
+ }
39
+ else {
40
+ this.imgLoaded = false;
41
+ this.hasStarted = false;
42
+ this.setupObserver();
43
+ }
31
44
  }
32
45
  componentDidLoad() {
33
- if ('IntersectionObserver' in window) {
34
- this.el.__uxComponent = this;
35
- if (!window.EMUxObserver) {
36
- window.EMUxObserver = new IntersectionObserver((entries) => {
37
- entries.forEach(entry => {
38
- if (entry.isIntersecting) {
39
- const comp = entry.target.__uxComponent;
40
- if (comp) {
41
- comp.shouldLoad = true;
42
- comp.handleSrc();
43
- }
44
- window.EMUxObserver.unobserve(entry.target);
45
- }
46
- });
47
- }, { rootMargin: this.detectDistance });
46
+ if (this.loading === 'eager')
47
+ return;
48
+ this.setupObserver();
49
+ }
50
+ disconnectedCallback() {
51
+ this.cleanupObserver();
52
+ this.detachImgHandlers();
53
+ }
54
+ canUseIO() {
55
+ return typeof window !== 'undefined' && 'IntersectionObserver' in window;
56
+ }
57
+ setupObserver() {
58
+ if (this.loading === 'eager')
59
+ return;
60
+ if (!this.canUseIO()) {
61
+ this.beginLoad();
62
+ return;
63
+ }
64
+ this.io = new IntersectionObserver((entries) => {
65
+ var _a;
66
+ for (const entry of entries) {
67
+ if (entry.isIntersecting) {
68
+ this.beginLoad();
69
+ (_a = this.io) === null || _a === void 0 ? void 0 : _a.unobserve(entry.target);
70
+ this.cleanupObserver();
71
+ break;
72
+ }
48
73
  }
49
- window.EMUxObserver.observe(this.el);
74
+ }, { root: null, rootMargin: this.detectDistance, threshold: 0 });
75
+ this.io.observe(this.el);
76
+ }
77
+ cleanupObserver() {
78
+ var _a;
79
+ (_a = this.io) === null || _a === void 0 ? void 0 : _a.disconnect();
80
+ this.io = undefined;
81
+ }
82
+ wireOnceHandlers() {
83
+ if (!this.imgEl)
84
+ return;
85
+ this.detachImgHandlers();
86
+ this._onLoad = () => {
87
+ var _a;
88
+ if (this.currentSrc && ((_a = this.imgEl) === null || _a === void 0 ? void 0 : _a.currentSrc) && !this.imgEl.currentSrc.includes(this.currentSrc))
89
+ return;
90
+ this.imgLoaded = true;
91
+ };
92
+ this._onError = () => {
93
+ console.error('Load image failed:', this.src);
94
+ };
95
+ this.imgEl.addEventListener('load', this._onLoad, { once: true });
96
+ this.imgEl.addEventListener('error', this._onError, { once: true });
97
+ }
98
+ detachImgHandlers() {
99
+ if (!this.imgEl)
100
+ return;
101
+ if (this._onLoad)
102
+ this.imgEl.removeEventListener('load', this._onLoad);
103
+ if (this._onError)
104
+ this.imgEl.removeEventListener('error', this._onError);
105
+ this._onLoad = undefined;
106
+ this._onError = undefined;
107
+ }
108
+ beginLoad() {
109
+ if (this.hasStarted)
110
+ return;
111
+ if (!this.imgEl)
112
+ return;
113
+ if (!this.src)
114
+ return;
115
+ this.hasStarted = true;
116
+ this.wireOnceHandlers();
117
+ if (this.imgEl.complete && this.imgEl.naturalWidth > 0) {
118
+ this.imgLoaded = true;
119
+ return;
50
120
  }
51
- else {
52
- this.shouldLoad = true;
53
- this.handleSrc();
121
+ this.currentSrc = this.src;
122
+ this.imgEl.src = this.src;
123
+ if (this.imgEl.complete && this.imgEl.naturalWidth > 0) {
124
+ this.imgLoaded = true;
54
125
  }
55
126
  }
127
+ get showSkeleton() {
128
+ return this.loading !== 'eager' && !this.imgLoaded;
129
+ }
130
+ renderEager() {
131
+ return (h(Host, { class: "HostContainer" }, h("img", { src: this.src, decoding: "async", style: this.styles, class: "UiContainer Visible", alt: this.alt, width: this.width, height: this.height, loading: "eager" })));
132
+ }
133
+ renderLazy() {
134
+ return (h(Host, { class: "HostContainer", "aria-busy": !this.imgLoaded ? 'true' : 'false' }, this.showSkeleton && (h("ui-skeleton", { class: "UiContainer", structure: "image", width: "100%", height: "100%" })), h("img", { ref: (el) => (this.imgEl = el), src: undefined, decoding: "async", style: this.styles, class: `UiContainer ${this.imgLoaded ? 'Visible' : 'Hidden'}`, alt: this.alt, width: this.width, height: this.height, loading: "lazy" })));
135
+ }
56
136
  render() {
57
- return (h(Host, { key: 'f506ba73852f257ad80bf59ca177d2065a5f365e', class: "HostContainer" }, !this.imgLoaded && (h("ui-skeleton", { key: '564ebfab701f827ddc2debccb7615926dbc9e876', class: "UiContainer", structure: "image", width: "100%", height: "100%" })), h("img", { key: '2188ca4494c10587f064acc5459ffc468948f497', ref: (el) => (this.image = el), src: this.shouldLoad ? this.src : undefined, onLoad: () => (this.imgLoaded = true), style: this.styles, class: `UiContainer ${this.imgLoaded ? 'Visible' : 'Hidden'}`, alt: this.alt, width: this.width, height: this.height, loading: "lazy" })));
137
+ return this.loading === 'eager' ? this.renderEager() : this.renderLazy();
58
138
  }
59
139
  get el() { return getElement(this); }
60
140
  static get watchers() { return {
61
- "src": ["handleSrc"]
141
+ "src": ["onSrcChange"],
142
+ "loading": ["onLoadingChange"]
62
143
  }; }
63
144
  };
64
145
  UiImage.style = UiImageStyle0;
@@ -1,3 +1,4 @@
1
1
  export * from "./vite-chunk-plugin";
2
2
  export * from "./stencil-clean-deps-plugin";
3
3
  export * from "./vite-clean-deps-plugin";
4
+ export * from "./lazy-load-chunk-plugin";
@@ -0,0 +1,12 @@
1
+ export declare const lazyLoadChunkPlugin: () => {
2
+ name: string;
3
+ config(config: any): {
4
+ build: {
5
+ rollupOptions: {
6
+ output: {
7
+ manualChunks(id: any): any;
8
+ };
9
+ };
10
+ };
11
+ };
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-engagement-suite-container",
3
- "version": "1.77.0",
3
+ "version": "1.77.2",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "module": "./dist/index.js",
6
6
  "es2015": "./dist/esm/index.mjs",