wj-elements 0.7.7 → 0.8.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/dist/animations.js +28 -51
- package/dist/animations.js.map +1 -1
- package/dist/base-path.js +19 -31
- package/dist/base-path.js.map +1 -1
- package/dist/custom-elements.json +11504 -11499
- package/dist/dark.css +1 -302
- package/dist/date.js +16 -36
- package/dist/date.js.map +1 -1
- package/dist/element-utils.js +20 -81
- package/dist/element-utils.js.map +1 -1
- package/dist/event.js +49 -165
- package/dist/event.js.map +1 -1
- package/dist/form-associated-element-BjeJn7j8.js +101 -0
- package/dist/{form-associated-element-DEQ4y-jn.js.map → form-associated-element-BjeJn7j8.js.map} +1 -1
- package/dist/icon-DmsqtDpL.js +102 -0
- package/dist/{icon-CReYMzAK.js.map → icon-DmsqtDpL.js.map} +1 -1
- package/dist/light.css +1 -731
- package/dist/localize.js +36 -111
- package/dist/localize.js.map +1 -1
- package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -2
- package/dist/permissions.js +14 -41
- package/dist/permissions.js.map +1 -1
- package/dist/popup.element-CbkhthPP.js +806 -0
- package/dist/{popup.element-CwXvVFK7.js.map → popup.element-CbkhthPP.js.map} +1 -1
- package/dist/router-links-CNsJ-elb.js +105 -0
- package/dist/{router-links-wjqCnncc.js.map → router-links-CNsJ-elb.js.map} +1 -1
- package/dist/skeleton.css +1 -197
- package/dist/styles.css +1 -866
- package/dist/universal-service.js +48 -109
- package/dist/universal-service.js.map +1 -1
- package/dist/utils.js +11 -18
- package/dist/utils.js.map +1 -1
- package/dist/web-types.json +760 -760
- package/dist/wje-accordion-item.js +33 -106
- package/dist/wje-accordion-item.js.map +1 -1
- package/dist/wje-accordion.js +19 -84
- package/dist/wje-accordion.js.map +1 -1
- package/dist/wje-animation.js +37 -4258
- package/dist/wje-animation.js.map +1 -1
- package/dist/wje-aside.js +9 -34
- package/dist/wje-aside.js.map +1 -1
- package/dist/wje-avatar.js +36 -126
- package/dist/wje-avatar.js.map +1 -1
- package/dist/wje-badge.js +10 -52
- package/dist/wje-badge.js.map +1 -1
- package/dist/wje-breadcrumb.js +205 -672
- package/dist/wje-breadcrumb.js.map +1 -1
- package/dist/wje-breadcrumbs.js +177 -633
- package/dist/wje-breadcrumbs.js.map +1 -1
- package/dist/wje-button-group.js +48 -153
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +92 -413
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-card-content.js +7 -30
- package/dist/wje-card-content.js.map +1 -1
- package/dist/wje-card-controls.js +7 -30
- package/dist/wje-card-controls.js.map +1 -1
- package/dist/wje-card-header.js +7 -30
- package/dist/wje-card-header.js.map +1 -1
- package/dist/wje-card-subtitle.js +7 -34
- package/dist/wje-card-subtitle.js.map +1 -1
- package/dist/wje-card-title.js +7 -34
- package/dist/wje-card-title.js.map +1 -1
- package/dist/wje-card.js +15 -71
- package/dist/wje-card.js.map +1 -1
- package/dist/wje-carousel-item.js +12 -56
- package/dist/wje-carousel-item.js.map +1 -1
- package/dist/wje-carousel.js +154 -509
- package/dist/wje-carousel.js.map +1 -1
- package/dist/wje-checkbox.js +50 -227
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +43 -160
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-col.js +7 -20
- package/dist/wje-col.js.map +1 -1
- package/dist/wje-color-picker.js +445 -1464
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-container.js +9 -35
- package/dist/wje-container.js.map +1 -1
- package/dist/wje-copy-button.js +64 -204
- package/dist/wje-copy-button.js.map +1 -1
- package/dist/wje-dialog.js +85 -553
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-divider.js +7 -34
- package/dist/wje-divider.js.map +1 -1
- package/dist/wje-dropdown.js +78 -305
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +191 -700
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-file-upload-item.js +51 -156
- package/dist/wje-file-upload-item.js.map +1 -1
- package/dist/wje-file-upload.js +181 -619
- package/dist/wje-file-upload.js.map +1 -1
- package/dist/wje-footer.js +7 -31
- package/dist/wje-footer.js.map +1 -1
- package/dist/wje-form.js +7 -32
- package/dist/wje-form.js.map +1 -1
- package/dist/wje-format-digital.js +26 -118
- package/dist/wje-format-digital.js.map +1 -1
- package/dist/wje-grid.js +7 -33
- package/dist/wje-grid.js.map +1 -1
- package/dist/wje-header.js +9 -35
- package/dist/wje-header.js.map +1 -1
- package/dist/wje-icon-library.js +12 -18
- package/dist/wje-icon-library.js.map +1 -1
- package/dist/wje-icon-picker.js +65 -320
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-icon.js +1 -1
- package/dist/wje-img-comparer.js +37 -114
- package/dist/wje-img-comparer.js.map +1 -1
- package/dist/wje-img.js +50 -198
- package/dist/wje-img.js.map +1 -1
- package/dist/wje-infinite-scroll.js +94 -346
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input-file.js +23 -84
- package/dist/wje-input-file.js.map +1 -1
- package/dist/wje-input.js +78 -392
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-item.js +11 -64
- package/dist/wje-item.js.map +1 -1
- package/dist/wje-kanban.js +124 -401
- package/dist/wje-kanban.js.map +1 -1
- package/dist/wje-label.js +9 -32
- package/dist/wje-label.js.map +1 -1
- package/dist/wje-level-indicator.js +38 -157
- package/dist/wje-level-indicator.js.map +1 -1
- package/dist/wje-list.js +10 -40
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-main.js +7 -31
- package/dist/wje-main.js.map +1 -1
- package/dist/wje-masonry.js +66 -211
- package/dist/wje-masonry.js.map +1 -1
- package/dist/wje-master.js +45 -161
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-menu-button.js +10 -38
- package/dist/wje-menu-button.js.map +1 -1
- package/dist/wje-menu-item.js +127 -577
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-menu-label.js +9 -35
- package/dist/wje-menu-label.js.map +1 -1
- package/dist/wje-menu.js +14 -49
- package/dist/wje-menu.js.map +1 -1
- package/dist/wje-option.js +48 -279
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +130 -384
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-orgchart-group.js +16 -52
- package/dist/wje-orgchart-group.js.map +1 -1
- package/dist/wje-orgchart-item.js +24 -93
- package/dist/wje-orgchart-item.js.map +1 -1
- package/dist/wje-orgchart.js +18 -68
- package/dist/wje-orgchart.js.map +1 -1
- package/dist/wje-pagination.js +113 -397
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +3 -3
- package/dist/wje-popup.js.map +1 -1
- package/dist/wje-progress-bar.js +53 -205
- package/dist/wje-progress-bar.js.map +1 -1
- package/dist/wje-qr-code.js +398 -2980
- package/dist/wje-qr-code.js.map +1 -1
- package/dist/wje-radio-group.js +52 -190
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-radio.js +24 -118
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-rate.js +62 -266
- package/dist/wje-rate.js.map +1 -1
- package/dist/wje-relative-time.js +24 -99
- package/dist/wje-relative-time.js.map +1 -1
- package/dist/wje-reorder-dropzone.js +9 -31
- package/dist/wje-reorder-dropzone.js.map +1 -1
- package/dist/wje-reorder-handle.js +67 -204
- package/dist/wje-reorder-handle.js.map +1 -1
- package/dist/wje-reorder-item.js +14 -44
- package/dist/wje-reorder-item.js.map +1 -1
- package/dist/wje-reorder.js +61 -246
- package/dist/wje-reorder.js.map +1 -1
- package/dist/wje-route.js +6 -24
- package/dist/wje-route.js.map +1 -1
- package/dist/wje-router-link.js +11 -39
- package/dist/wje-router-link.js.map +1 -1
- package/dist/wje-router-outlet.js +76 -172
- package/dist/wje-router-outlet.js.map +1 -1
- package/dist/wje-routerx.js +537 -1331
- package/dist/wje-routerx.js.map +1 -1
- package/dist/wje-row.js +9 -31
- package/dist/wje-row.js.map +1 -1
- package/dist/wje-select.js +326 -1152
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-slider.js +44 -225
- package/dist/wje-slider.js.map +1 -1
- package/dist/wje-sliding-container.js +295 -1319
- package/dist/wje-sliding-container.js.map +1 -1
- package/dist/wje-split-view.js +35 -121
- package/dist/wje-split-view.js.map +1 -1
- package/dist/wje-status.js +14 -45
- package/dist/wje-status.js.map +1 -1
- package/dist/wje-step.js +9 -32
- package/dist/wje-step.js.map +1 -1
- package/dist/wje-stepper.js +109 -357
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-store.js +67 -360
- package/dist/wje-store.js.map +1 -1
- package/dist/wje-tab-group.js +85 -314
- package/dist/wje-tab-group.js.map +1 -1
- package/dist/wje-tab-panel.js +7 -28
- package/dist/wje-tab-panel.js.map +1 -1
- package/dist/wje-tab.js +21 -198
- package/dist/wje-tab.js.map +1 -1
- package/dist/wje-textarea.js +64 -264
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-thumbnail.js +10 -51
- package/dist/wje-thumbnail.js.map +1 -1
- package/dist/wje-toast.js +127 -632
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-toggle.js +52 -177
- package/dist/wje-toggle.js.map +1 -1
- package/dist/wje-toolbar-action.js +128 -456
- package/dist/wje-toolbar-action.js.map +1 -1
- package/dist/wje-toolbar.js +75 -270
- package/dist/wje-toolbar.js.map +1 -1
- package/dist/wje-tooltip.js +50 -161
- package/dist/wje-tooltip.js.map +1 -1
- package/dist/wje-tree-item.js +70 -301
- package/dist/wje-tree-item.js.map +1 -1
- package/dist/wje-tree.js +145 -489
- package/dist/wje-tree.js.map +1 -1
- package/dist/wje-visually-hidden.js +7 -34
- package/dist/wje-visually-hidden.js.map +1 -1
- package/package.json +3 -2
- package/dist/form-associated-element-DEQ4y-jn.js +0 -245
- package/dist/icon-CReYMzAK.js +0 -245
- package/dist/popup.element-CwXvVFK7.js +0 -2133
- package/dist/router-links-wjqCnncc.js +0 -156
package/dist/wje-img-comparer.js
CHANGED
|
@@ -1,135 +1,58 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import
|
|
5
|
-
import { I as
|
|
6
|
-
|
|
7
|
-
function move(pointerEvent) {
|
|
8
|
-
const dims = container.getBoundingClientRect();
|
|
9
|
-
const defaultView = container.ownerDocument.defaultView;
|
|
10
|
-
const offsetX = dims.left + defaultView.pageXOffset;
|
|
11
|
-
const offsetY = dims.top + defaultView.pageYOffset;
|
|
12
|
-
const x = pointerEvent.pageX - offsetX;
|
|
13
|
-
const y = pointerEvent.pageY - offsetY;
|
|
14
|
-
if (options == null ? void 0 : options.onMove) {
|
|
15
|
-
options.onMove(x, y);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function stop() {
|
|
19
|
-
document.removeEventListener("pointermove", move);
|
|
20
|
-
document.removeEventListener("pointerup", stop);
|
|
21
|
-
if (options == null ? void 0 : options.onStop) {
|
|
22
|
-
options.onStop();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
document.addEventListener("pointermove", move, { passive: true });
|
|
26
|
-
document.addEventListener("pointerup", stop);
|
|
27
|
-
if ((options == null ? void 0 : options.initialEvent) instanceof PointerEvent) {
|
|
28
|
-
move(options.initialEvent);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const styles = "/*\n[ WJ Image Compare ]\n*/\n\n:host {\n display: inline-block;\n position: relative;\n width: 100%;\n border-color: var(--wje-border-color);\n border-style: solid;\n border-width: 1px;\n}\n\n.wje-before,\n.wje-after {\n display: block;\n}\n\n.wje-after {\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n clip-path: var(--wje-img-compare-clip-path);\n}\n\n.native-split-view {\n max-width: 100%;\n max-height: 100%;\n overflow: hidden;\n}\n\n.wje-divider {\n display: flex;\n position: absolute;\n align-items: center;\n justify-content: center;\n z-index: 1;\n background-color: var(--wje-img-compare-divider-background);\n height: 100%;\n width: var(--wje-img-compare-divider-size);\n cursor: col-resize;\n top: 0;\n left: var(--wje-img-compare-divider-left);\n &:after {\n display: flex;\n content: '';\n position: absolute;\n height: 100%;\n left: calc(var(--wje-img-compare-divider-area) / -2 + var(--wje-img-compare-divider-size) / 2);\n width: var(---wje-img-compare-divider-area);\n }\n wje-icon {\n position: absolute;\n background-color: white;\n padding: 0.5rem;\n color: var(--wje-color-dark);\n border-radius: var(--wje-border-radius-circle);\n box-shadow: rgba(82, 63, 105, 0.2) 0 0 30px 10px;\n background: var(--wje-color-white) !important;\n }\n}\n";
|
|
32
|
-
class ImgComparer extends WJElement {
|
|
33
|
-
/**
|
|
34
|
-
* Creates an instance of ImgComparer.
|
|
35
|
-
* @class
|
|
36
|
-
*/
|
|
4
|
+
import e from "./wje-element.js";
|
|
5
|
+
import { I as t } from "./icon-DmsqtDpL.js";
|
|
6
|
+
class i extends e {
|
|
37
7
|
constructor() {
|
|
38
8
|
super();
|
|
39
|
-
|
|
40
|
-
* Dependencies of the ImgComparer component.
|
|
41
|
-
* @property {object} dependencies
|
|
42
|
-
*/
|
|
43
|
-
__publicField(this, "dependencies", {
|
|
44
|
-
"wje-icon": Icon
|
|
45
|
-
});
|
|
9
|
+
__publicField(this, "dependencies", { "wje-icon": t });
|
|
46
10
|
__publicField(this, "className", "ImgComparer");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
});
|
|
11
|
+
__publicField(this, "handleDrag", (e2) => {
|
|
12
|
+
const { width: t2 } = this.native.getBoundingClientRect();
|
|
13
|
+
!(function(e3, t3) {
|
|
14
|
+
function i2(i3) {
|
|
15
|
+
const o = e3.getBoundingClientRect(), r = e3.ownerDocument.defaultView, a = o.left + r.pageXOffset, n = o.top + r.pageYOffset, d = i3.pageX - a, s = i3.pageY - n;
|
|
16
|
+
(t3 == null ? void 0 : t3.onMove) && t3.onMove(d, s);
|
|
17
|
+
}
|
|
18
|
+
document.addEventListener("pointermove", i2, { passive: true }), document.addEventListener("pointerup", function e4() {
|
|
19
|
+
document.removeEventListener("pointermove", i2), document.removeEventListener("pointerup", e4), (t3 == null ? void 0 : t3.onStop) && t3.onStop();
|
|
20
|
+
}), (t3 == null ? void 0 : t3.initialEvent) instanceof PointerEvent && i2(t3.initialEvent);
|
|
21
|
+
})(this, { onMove: (e3) => {
|
|
22
|
+
let i2 = e3 / t2 * 100;
|
|
23
|
+
this.position = parseFloat(this.clamp(i2, 0, 100).toFixed(2)), this.native.style.setProperty("--wje-img-compare-divider-left", this.position + "%"), this.native.style.setProperty("--wje-img-compare-clip-path", `inset(0 ${100 - this.position}% 0 0)`);
|
|
24
|
+
}, initialEvent: e2 });
|
|
62
25
|
});
|
|
63
|
-
|
|
64
|
-
* Clamps a number between a minimum and maximum value.
|
|
65
|
-
* @param {number} num The number to clamp.
|
|
66
|
-
* @param {number} min The minimum value.
|
|
67
|
-
* @param {number} max The maximum value.
|
|
68
|
-
* @returns {number} The clamped number.
|
|
69
|
-
*/
|
|
70
|
-
__publicField(this, "clamp", (num, min, max) => Math.min(Math.max(num, min), max));
|
|
26
|
+
__publicField(this, "clamp", (e2, t2, i2) => Math.min(Math.max(e2, t2), i2));
|
|
71
27
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Returns the CSS styles for the component.
|
|
74
|
-
* @static
|
|
75
|
-
* @returns {CSSStyleSheet}
|
|
76
|
-
*/
|
|
77
28
|
static get cssStyleSheet() {
|
|
78
|
-
return
|
|
29
|
+
return ':host{display:inline-block;position:relative;width:100%;border-color:var(--wje-border-color);border-style:solid;border-width:1px}.wje-before,.wje-after{display:block}.wje-after{position:absolute;top:0;left:0;height:100%;width:100%;clip-path:var(--wje-img-compare-clip-path)}.native-split-view{max-width:100%;max-height:100%;overflow:hidden}.wje-divider{display:flex;position:absolute;align-items:center;justify-content:center;z-index:1;background-color:var(--wje-img-compare-divider-background);height:100%;width:var(--wje-img-compare-divider-size);cursor:col-resize;top:0;left:var(--wje-img-compare-divider-left)}.wje-divider:after{display:flex;content:"";position:absolute;height:100%;left:calc(var(--wje-img-compare-divider-area) / -2 + var(--wje-img-compare-divider-size) / 2);width:var(---wje-img-compare-divider-area)}.wje-divider wje-icon{position:absolute;background-color:#fff;padding:.5rem;color:var(--wje-color-dark);border-radius:var(--wje-border-radius-circle);box-shadow:#523f6933 0 0 30px 10px;background:var(--wje-color-white)!important}';
|
|
79
30
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Returns the list of attributes to observe for changes.
|
|
82
|
-
* @static
|
|
83
|
-
* @returns {Array<string>}
|
|
84
|
-
*/
|
|
85
31
|
static get observedAttributes() {
|
|
86
32
|
return [];
|
|
87
33
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Sets up the attributes for the component.
|
|
90
|
-
*/
|
|
91
34
|
setupAttributes() {
|
|
92
|
-
this.isShadowRoot = "open";
|
|
93
|
-
this.setAriaState({ role: "group" });
|
|
35
|
+
this.isShadowRoot = "open", this.setAriaState({ role: "group" });
|
|
94
36
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Draws the component.
|
|
97
|
-
* @returns {DocumentFragment}
|
|
98
|
-
*/
|
|
99
37
|
draw() {
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
dividerElement.classList.add("wje-divider");
|
|
115
|
-
dividerElement.setAttribute("part", "divider");
|
|
116
|
-
dividerElement.setAttribute("role", "separator");
|
|
117
|
-
dividerElement.setAttribute("tabindex", "0");
|
|
118
|
-
dividerElement.setAttribute("aria-orientation", "horizontal");
|
|
119
|
-
dividerElement.addEventListener("mousedown", this.handleDrag, false);
|
|
120
|
-
beforeElement.appendChild(before);
|
|
121
|
-
afterElement.appendChild(after);
|
|
122
|
-
dividerElement.appendChild(icon);
|
|
123
|
-
native.appendChild(beforeElement);
|
|
124
|
-
native.appendChild(afterElement);
|
|
125
|
-
native.appendChild(dividerElement);
|
|
126
|
-
fragment.appendChild(native);
|
|
127
|
-
this.native = native;
|
|
128
|
-
return fragment;
|
|
38
|
+
let e2 = document.createDocumentFragment(), t2 = document.createElement("div");
|
|
39
|
+
t2.classList.add("native-split-view");
|
|
40
|
+
let i2 = document.createElement("div");
|
|
41
|
+
i2.classList.add("wje-before");
|
|
42
|
+
let o = document.createElement("slot");
|
|
43
|
+
o.setAttribute("name", "before");
|
|
44
|
+
let r = document.createElement("div");
|
|
45
|
+
r.classList.add("wje-after");
|
|
46
|
+
let a = document.createElement("slot");
|
|
47
|
+
a.setAttribute("name", "after");
|
|
48
|
+
let n = document.createElement("wje-icon");
|
|
49
|
+
n.setAttribute("name", "arrow-bar-both");
|
|
50
|
+
let d = document.createElement("div");
|
|
51
|
+
return d.classList.add("wje-divider"), d.setAttribute("part", "divider"), d.setAttribute("role", "separator"), d.setAttribute("tabindex", "0"), d.setAttribute("aria-orientation", "horizontal"), d.addEventListener("mousedown", this.handleDrag, false), i2.appendChild(o), r.appendChild(a), d.appendChild(n), t2.appendChild(i2), t2.appendChild(r), t2.appendChild(d), e2.appendChild(t2), this.native = t2, e2;
|
|
129
52
|
}
|
|
130
53
|
}
|
|
131
|
-
|
|
54
|
+
i.define("wje-img-comparer", i);
|
|
132
55
|
export {
|
|
133
|
-
|
|
56
|
+
i as default
|
|
134
57
|
};
|
|
135
58
|
//# sourceMappingURL=wje-img-comparer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-img-comparer.js","sources":["../packages/wje-img-comparer/
|
|
1
|
+
{"version":3,"file":"wje-img-comparer.js","sources":["../packages/wje-img-comparer/img-comparer.element.js","../packages/wje-img-comparer/service/service.js","../packages/wje-img-comparer/img-comparer.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport Icon from '../wje-icon/icon.js';\nimport { drag } from './service/service.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element allows users to compare two images. `ImgComparer` is a custom web component that represents an image comparer.\n * It extends from `WJElement` and uses the `Icon` component.\n * @documentation https://elements.webjet.sk/components/img-comparer\n * @status stable\n * @augments {WJElement}\n * @slot before - The before image slot.\n * @slot after - The after image slot.\n * @csspart divider - The divider part.\n * @cssproperty [--wje-img-compare-divider-area=12px] - The area of the divider. This is the size of the divider. Accepts any valid CSS size.\n * @cssproperty [--wje-img-compare-divider-background=white] - Sets the background color of the divider in the image comparison component. Accepts any valid CSS color value (e.g., `red`, `#ff0000`, `rgba(255, 255, 255, 0.5)`). The default value is `white`, which ensures high contrast in most designs.\n * @cssproperty [--wje-img-compare-divider-size=2px] - The size of the divider. This is the thickness of the divider. Accepts any valid CSS size.\n * @cssproperty [--wje-img-compare-divider-left=50%] - The left position of the divider. This is the initial position of the divider.\n * @cssproperty [--wje-img-compare-position=50%] - The position of the divider. This is the position of the divider.\n * @cssproperty [--wje-img-compare-clip-path=inset(0 calc(100% - var(--wje-img-compare-position)) 0 0)] - The clip path of the divider. This is the clip path of the divider.\n * @tag wje-img-comparer\n */\nexport default class ImgComparer extends WJElement {\n /**\n * Creates an instance of ImgComparer.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Dependencies of the ImgComparer component.\n * @property {object} dependencies\n */\n dependencies = {\n 'wje-icon': Icon,\n };\n\n className = 'ImgComparer';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAriaState({ role: 'group' });\n }\n\n /**\n * Draws the component.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-split-view');\n\n let beforeElement = document.createElement('div');\n beforeElement.classList.add('wje-before');\n\n let before = document.createElement('slot');\n before.setAttribute('name', 'before');\n\n let afterElement = document.createElement('div');\n afterElement.classList.add('wje-after');\n\n let after = document.createElement('slot');\n after.setAttribute('name', 'after');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'arrow-bar-both');\n\n let dividerElement = document.createElement('div');\n dividerElement.classList.add('wje-divider');\n dividerElement.setAttribute('part', 'divider');\n dividerElement.setAttribute('role', 'separator');\n dividerElement.setAttribute('tabindex', '0');\n dividerElement.setAttribute('aria-orientation', 'horizontal');\n dividerElement.addEventListener('mousedown', this.handleDrag, false);\n\n beforeElement.appendChild(before);\n afterElement.appendChild(after);\n dividerElement.appendChild(icon);\n\n native.appendChild(beforeElement);\n native.appendChild(afterElement);\n native.appendChild(dividerElement);\n\n fragment.appendChild(native);\n\n this.native = native;\n\n return fragment;\n }\n\n /**\n * Handles the drag event.\n * @param {Event} e The event.\n */\n handleDrag = (e) => {\n const { width } = this.native.getBoundingClientRect();\n\n drag(this, {\n onMove: (x) => {\n let value = (x / width) * 100;\n this.position = parseFloat(this.clamp(value, 0, 100).toFixed(2));\n this.native.style.setProperty('--wje-img-compare-divider-left', this.position + '%');\n this.native.style.setProperty('--wje-img-compare-clip-path', `inset(0 ${100 - this.position}% 0 0)`);\n },\n initialEvent: e,\n });\n };\n\n /**\n * Clamps a number between a minimum and maximum value.\n * @param {number} num The number to clamp.\n * @param {number} min The minimum value.\n * @param {number} max The maximum value.\n * @returns {number} The clamped number.\n */\n clamp = (num, min, max) => Math.min(Math.max(num, min), max);\n}\n","export function drag(container, options) {\n function move(pointerEvent) {\n const dims = container.getBoundingClientRect();\n const defaultView = container.ownerDocument.defaultView;\n const offsetX = dims.left + defaultView.pageXOffset;\n const offsetY = dims.top + defaultView.pageYOffset;\n const x = pointerEvent.pageX - offsetX;\n const y = pointerEvent.pageY - offsetY;\n\n if (options?.onMove) {\n options.onMove(x, y);\n }\n }\n\n function stop() {\n document.removeEventListener('pointermove', move);\n document.removeEventListener('pointerup', stop);\n\n if (options?.onStop) {\n options.onStop();\n }\n }\n\n document.addEventListener('pointermove', move, { passive: true });\n document.addEventListener('pointerup', stop);\n\n if (options?.initialEvent instanceof PointerEvent) {\n move(options.initialEvent);\n }\n}\n","import ImgComparer from './img-comparer.element.js';\n\nexport default ImgComparer;\n\nImgComparer.define('wje-img-comparer', ImgComparer);\n"],"names":["ImgComparer","WJElement","constructor","super","dependencies","Icon","className","handleDrag","e","width","this","native","getBoundingClientRect","container","options","move","pointerEvent","dims","defaultView","ownerDocument","offsetX","left","pageXOffset","offsetY","top","pageYOffset","x","pageX","y","pageY","onMove","document","addEventListener","passive","stop","removeEventListener","onStop","initialEvent","PointerEvent","value","position","parseFloat","clamp","toFixed","style","setProperty","num","min","max","Math","cssStyleSheet","setupAttributes","isShadowRoot","setAriaState","role","draw","fragment","createDocumentFragment","createElement","classList","add","beforeElement","before","setAttribute","afterElement","after","icon","dividerElement","appendChild","define"],"mappings":";;;;;AAsBe,MAAMA,UAAoBC,EAAAA;AAAAA,EAKrC,cAAAC;AACIC,UAAAA;AAOJC,wCAAe,EACX,YAAYC;AAGhBC,qCAAY;AAgFZC,sCAAcC,CAAAA,OAAAA;AACV,YAAA,EAAMC,OAAEA,OAAUC,KAAKC,OAAOC,sBAAAA;AAAAA,QCxH/B,SAAcC,IAAWC,IAAAA;AAC5B,iBAASC,GAAKC;AACV,gBAAMC,IAAOJ,GAAUD,sBAAAA,GACjBM,IAAcL,GAAUM,cAAcD,aACtCE,IAAUH,EAAKI,OAAOH,EAAYI,aAClCC,IAAUN,E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AS0B,uBAAAA,GAEpB9C,KAASoB,SAAS2B,cAAc,KAAA;AACpC/C,IAAAA,GAAOgD,UAAUC,IAAI,mBAAA;AAErB,QAAIC,KAAgB9B,SAAS2B,cAAc,KAAA;AAC3CG,IAAAA,GAAcF,UAAUC,IAAI,YAAA;AAE5B,QAAIE,IAAS/B,SAAS2B,cAAc,MAAA;AACpCI,MAAOC,aAAa,QAAQ,QAAA;AAE5B,QAAIC,IAAejC,SAAS2B,cAAc,KAAA;AAC1CM,MAAaL,UAAUC,IAAI,WAAA;AAE3B,QAAIK,IAAQlC,SAAS2B,cAAc,MAAA;AACnCO,MAAMF,aAAa,QAAQ,OAAA;AAE3B,QAAIG,IAAOnC,SAAS2B,cAAc,UAAA;AAClCQ,MAAKH,aAAa,QAAQ,gBAAA;AAE1B,QAAII,IAAiBpC,SAAS2B,cAAc,KAAA;AAoB5C,WAnBAS,EAAeR,UAAUC,IAAI,aAAA,GAC7BO,EAAeJ,aAAa,QAAQ,SAAA,GACpCI,EAAeJ,aAAa,QAAQ,WAAA,GACpCI,EAAeJ,aAAa,YAAY,GAAA,GACxCI,EAAeJ,aAAa,oBAAoB,eAChDI,EAAenC,iBAAiB,aAAatB,KAAKH,YAAAA,KAAY,GAE9DsD,GAAcO,YAAYN,IAC1BE,EAAaI,YAAYH,CAAAA,GACzBE,EAAeC,YAAYF,CAAAA,GAE3BvD,GAAOyD,YAAYP,EAAAA,GACnBlD,GAAOyD,YAAYJ,CAAAA,GACnBrD,GAAOyD,YAAYD,CAAAA,GAEnBX,GAASY,YAAYzD,EAAAA,GAErBD,KAAKC,SAASA,IAEP6C;AAAAA,EACX;AA2BwDR;AExI5DhD,EAAYqE,OAAO,oBAAoBrE,CAAAA;"}
|
package/dist/wje-img.js
CHANGED
|
@@ -1,246 +1,98 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { getBasePath } from "./base-path.js";
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
class Img extends WJElement {
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of Img.
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
4
|
+
import { getBasePath as t } from "./base-path.js";
|
|
5
|
+
import e from "./wje-element.js";
|
|
6
|
+
class i extends e {
|
|
12
7
|
constructor() {
|
|
13
8
|
super();
|
|
14
|
-
/**
|
|
15
|
-
* The class name for the component.
|
|
16
|
-
* @type {string}
|
|
17
|
-
*/
|
|
18
9
|
__publicField(this, "className", "Img");
|
|
19
|
-
__publicField(this, "setAvatarInitials", (
|
|
20
|
-
let
|
|
21
|
-
|
|
10
|
+
__publicField(this, "setAvatarInitials", (t2 = false) => {
|
|
11
|
+
let e2 = this.parentElement;
|
|
12
|
+
"WJE-AVATAR" === (e2 == null ? void 0 : e2.tagName) && (e2.initials = t2);
|
|
22
13
|
});
|
|
23
|
-
/**
|
|
24
|
-
* Deletes the current image by calling the remove method.
|
|
25
|
-
* This function is typically used to trigger the removal of an image element
|
|
26
|
-
* or perform cleanup operations related to the image.
|
|
27
|
-
*/
|
|
28
14
|
__publicField(this, "deleteImage", () => {
|
|
29
15
|
this.remove();
|
|
30
16
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* corresponding actions. If `fallout` is not defined, the function terminates
|
|
34
|
-
* early. Logs the active actions and attempts to assign an error handler
|
|
35
|
-
* based on the `fallout` value. If the `fallout` value does not correspond to
|
|
36
|
-
* a recognized action, it logs an error message.
|
|
37
|
-
* @function onerrorFunc
|
|
38
|
-
* @memberof Img
|
|
39
|
-
*/
|
|
40
|
-
__publicField(this, "onerrorFunc", (img) => {
|
|
41
|
-
if (!this.fallout) return;
|
|
42
|
-
if (this.actions[this.fallout]) {
|
|
43
|
-
img.onerror = this.actions[this.fallout];
|
|
44
|
-
} else {
|
|
45
|
-
console.error("Unsupported value:", this.fallout);
|
|
46
|
-
}
|
|
17
|
+
__publicField(this, "onerrorFunc", (t2) => {
|
|
18
|
+
this.fallout && (this.actions[this.fallout] ? t2.onerror = this.actions[this.fallout] : console.error("Unsupported value:", this.fallout));
|
|
47
19
|
});
|
|
48
|
-
this._fallout = false;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the value of the `src` attribute for the element.
|
|
56
|
-
* @param {string} value The value to set for the `src` attribute.
|
|
57
|
-
*/
|
|
58
|
-
set src(value) {
|
|
59
|
-
this.setAttribute("src", value);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Retrieves the value of the 'src' attribute from the element.
|
|
63
|
-
* @returns {string} The value of the 'src' attribute.
|
|
64
|
-
*/
|
|
20
|
+
this._fallout = false, this.actions = { delete: () => this.deleteImage(), log: () => console.error("Error log pre obrázok:", this.src) };
|
|
21
|
+
}
|
|
22
|
+
set src(t2) {
|
|
23
|
+
this.setAttribute("src", t2);
|
|
24
|
+
}
|
|
65
25
|
get src() {
|
|
66
26
|
return this.getAttribute("src");
|
|
67
27
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*/
|
|
72
|
-
set alt(value) {
|
|
73
|
-
this.setAttribute("alt", value);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Retrieves the value of the 'alt' attribute for the current element.
|
|
77
|
-
* @returns {string|null} The value of the 'alt' attribute, or null if the attribute is not set.
|
|
78
|
-
*/
|
|
28
|
+
set alt(t2) {
|
|
29
|
+
this.setAttribute("alt", t2);
|
|
30
|
+
}
|
|
79
31
|
get alt() {
|
|
80
32
|
return this.getAttribute("alt");
|
|
81
33
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* otherwise, assigns the value to the `_fallout` property.
|
|
85
|
-
* @param {string|*} value The value to set for the fallout property. If a string, it will update the `fallout` attribute; for other types, it will assign it to the `_fallout` property.
|
|
86
|
-
*/
|
|
87
|
-
set fallout(value) {
|
|
88
|
-
if (typeof value === "string") {
|
|
89
|
-
this.setAttribute("fallout", value);
|
|
90
|
-
} else {
|
|
91
|
-
this._fallout = value;
|
|
92
|
-
}
|
|
34
|
+
set fallout(t2) {
|
|
35
|
+
"string" == typeof t2 ? this.setAttribute("fallout", t2) : this._fallout = t2;
|
|
93
36
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Retrieves the value of the 'fallout' attribute if it exists, otherwise returns the internal `_fallout` property.
|
|
96
|
-
* @returns {string|null} The value of the 'fallout' attribute or the `_fallout` property if the attribute is not present. Returns null if no value is found.
|
|
97
|
-
*/
|
|
98
37
|
get fallout() {
|
|
99
38
|
return this.hasAttribute("fallout") ? this.getAttribute("fallout") : this._fallout;
|
|
100
39
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* @param {string} value The value to set for the loader attribute.
|
|
104
|
-
*/
|
|
105
|
-
set loader(value) {
|
|
106
|
-
if (value) {
|
|
107
|
-
this.setAttribute("loader", value);
|
|
108
|
-
}
|
|
40
|
+
set loader(t2) {
|
|
41
|
+
t2 && this.setAttribute("loader", t2);
|
|
109
42
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Retrieves the configured loader URL or resolves the default loader from the base path.
|
|
112
|
-
* @returns {string} The loader URL.
|
|
113
|
-
*/
|
|
114
43
|
get loader() {
|
|
115
|
-
return this.getAttribute("loader") ||
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @param {boolean} value True to disable lazy loading, false to restore the default lazy behavior.
|
|
120
|
-
*/
|
|
121
|
-
set noLazy(value) {
|
|
122
|
-
if (value) {
|
|
123
|
-
this.setAttribute("no-lazy", "");
|
|
124
|
-
} else {
|
|
125
|
-
this.removeAttribute("no-lazy");
|
|
126
|
-
}
|
|
44
|
+
return this.getAttribute("loader") || t("assets/img/image-loader.gif");
|
|
45
|
+
}
|
|
46
|
+
set noLazy(t2) {
|
|
47
|
+
t2 ? this.setAttribute("no-lazy", "") : this.removeAttribute("no-lazy");
|
|
127
48
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Checks whether lazy loading is disabled.
|
|
130
|
-
* @returns {boolean} True when the `no-lazy` attribute is present.
|
|
131
|
-
*/
|
|
132
49
|
get noLazy() {
|
|
133
50
|
return this.hasAttribute("no-lazy");
|
|
134
51
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns the CSS styles for the component.
|
|
137
|
-
* @static
|
|
138
|
-
* @returns {CSSStyleSheet}
|
|
139
|
-
*/
|
|
140
52
|
static get cssStyleSheet() {
|
|
141
|
-
return
|
|
53
|
+
return "img{display:block;width:var(--wje-img-width, 100%);height:var(--wje-img-height, auto);max-width:100%;object-fit:inherit;border-radius:var(--wje-img-border-radius, 0)}";
|
|
142
54
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Returns the list of attributes to observe for changes.
|
|
145
|
-
* @static
|
|
146
|
-
* @returns {Array<string>}
|
|
147
|
-
*/
|
|
148
55
|
static get observedAttributes() {
|
|
149
56
|
return ["src", "alt", "no-lazy"];
|
|
150
57
|
}
|
|
151
|
-
attributeChangedCallback(
|
|
58
|
+
attributeChangedCallback(t2, e2, i2) {
|
|
152
59
|
var _a, _b;
|
|
153
|
-
(_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const label = (_b = this.alt) == null ? void 0 : _b.trim();
|
|
158
|
-
if (label) this.setAriaState({ label });
|
|
60
|
+
if ((_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this, t2, e2, i2), e2 !== i2 && "alt" === t2) {
|
|
61
|
+
this.native && this.native.setAttribute("alt", this.alt || "");
|
|
62
|
+
const t3 = (_b = this.alt) == null ? void 0 : _b.trim();
|
|
63
|
+
t3 && this.setAriaState({ label: t3 });
|
|
159
64
|
}
|
|
160
65
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Sets up the attributes for the component.
|
|
163
|
-
*/
|
|
164
66
|
setupAttributes() {
|
|
165
67
|
var _a;
|
|
166
|
-
this.isShadowRoot = "open";
|
|
167
|
-
|
|
168
|
-
if ((_a = this.alt) == null ? void 0 : _a.trim()) this.setAriaState({ label: this.alt.trim() });
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Creates and assembles a lazy-loaded image element within a document fragment.
|
|
172
|
-
* @returns {DocumentFragment} A document fragment containing the image element.
|
|
173
|
-
*/
|
|
68
|
+
this.isShadowRoot = "open", this.setAriaState({ role: "img" }), ((_a = this.alt) == null ? void 0 : _a.trim()) && this.setAriaState({ label: this.alt.trim() });
|
|
69
|
+
}
|
|
174
70
|
draw() {
|
|
175
71
|
var _a;
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
native.addEventListener("error", (e) => {
|
|
183
|
-
const absoluteLoaderUrl = new URL(this.loader, window.location.origin).href;
|
|
184
|
-
if (e.target.src === absoluteLoaderUrl) return;
|
|
185
|
-
this.setAvatarInitials(true);
|
|
186
|
-
});
|
|
187
|
-
this.onerrorFunc(native);
|
|
188
|
-
fragment.appendChild(native);
|
|
189
|
-
this.native = native;
|
|
190
|
-
if ((_a = this.alt) == null ? void 0 : _a.trim()) this.setAriaState({ label: this.alt.trim() });
|
|
191
|
-
return fragment;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Handles post-draw operations, such as setting up a lazy image loader using an IntersectionObserver.
|
|
195
|
-
* Observes when the target element becomes visible in the viewport and updates its source with the provided image source.
|
|
196
|
-
* Removes the `lazy` class once the image source is updated and unobserves the element.
|
|
197
|
-
* It also invokes the `onerrorFunc` method at the beginning to handle potential error scenarios.
|
|
198
|
-
* @returns {void} Does not return a value.
|
|
199
|
-
*/
|
|
72
|
+
let t2 = document.createDocumentFragment(), e2 = document.createElement("img");
|
|
73
|
+
return e2.setAttribute("part", "native"), e2.setAttribute("src", this.noLazy ? this.src : this.loader), e2.setAttribute("alt", this.alt || ""), e2.classList.add("lazy-loaded-image", "lazy"), e2.addEventListener("error", (t3) => {
|
|
74
|
+
const e3 = new URL(this.loader, window.location.origin).href;
|
|
75
|
+
t3.target.src !== e3 && this.setAvatarInitials(true);
|
|
76
|
+
}), this.onerrorFunc(e2), t2.appendChild(e2), this.native = e2, ((_a = this.alt) == null ? void 0 : _a.trim()) && this.setAriaState({ label: this.alt.trim() }), t2;
|
|
77
|
+
}
|
|
200
78
|
afterDraw() {
|
|
201
|
-
if (this.noLazy)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
let lazyImageObserver = new IntersectionObserver((entries, observer) => {
|
|
206
|
-
entries.forEach((entry) => {
|
|
207
|
-
if (entry.isIntersecting) {
|
|
208
|
-
entry.target.src = this.src;
|
|
209
|
-
this.classList.remove("lazy");
|
|
210
|
-
lazyImageObserver.unobserve(entry.target);
|
|
211
|
-
}
|
|
79
|
+
if (this.noLazy) return void this.native.classList.remove("lazy");
|
|
80
|
+
let t2 = new IntersectionObserver((e2, i2) => {
|
|
81
|
+
e2.forEach((e3) => {
|
|
82
|
+
e3.isIntersecting && (e3.target.src = this.src, this.classList.remove("lazy"), t2.unobserve(e3.target));
|
|
212
83
|
});
|
|
213
84
|
});
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Adds a new action to the internal actions object.
|
|
218
|
-
* @param {string} name The name of the action to be added.
|
|
219
|
-
* @param {Function} func The function representing the action logic.
|
|
220
|
-
* @returns {void} This method does not return a value.
|
|
221
|
-
*/
|
|
222
|
-
addAction(name, func) {
|
|
223
|
-
if (typeof func === "function") {
|
|
224
|
-
this.actions[name] = func;
|
|
225
|
-
} else {
|
|
226
|
-
console.error("The action must be a function.");
|
|
227
|
-
}
|
|
85
|
+
t2.observe(this.native);
|
|
228
86
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
removeAction(name) {
|
|
235
|
-
if (this.actions[name]) {
|
|
236
|
-
delete this.actions[name];
|
|
237
|
-
} else {
|
|
238
|
-
console.error(`Action "${name}" does not exist.`);
|
|
239
|
-
}
|
|
87
|
+
addAction(t2, e2) {
|
|
88
|
+
"function" == typeof e2 ? this.actions[t2] = e2 : console.error("The action must be a function.");
|
|
89
|
+
}
|
|
90
|
+
removeAction(t2) {
|
|
91
|
+
this.actions[t2] ? delete this.actions[t2] : console.error(`Action "${t2}" does not exist.`);
|
|
240
92
|
}
|
|
241
93
|
}
|
|
242
|
-
|
|
94
|
+
i.define("wje-img", i);
|
|
243
95
|
export {
|
|
244
|
-
|
|
96
|
+
i as default
|
|
245
97
|
};
|
|
246
98
|
//# sourceMappingURL=wje-img.js.map
|
package/dist/wje-img.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-img.js","sources":["../packages/wje-img/img.element.js","../packages/wje-img/img.js"],"sourcesContent":["import { getBasePath } from '../utils/base-path.js';\nimport { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element represents an image. `Img` is a custom web component that represents an image. It extends from `WJElement`.\n * @documentation https://elements.webjet.sk/components/img\n * @status stable\n * @augments {WJElement}\n * @cssproperty --img-width - The width of the image\n * @cssproperty --img-height - The height of the image\n * @property {string} src - The source URL of the image.\n * @property {string} alt - The alternative text for the image.\n * @property {string} fallout - The action to perform when an error occurs while loading the image. The value can be a function or a predefined action like 'delete'.\n * @property {string} loader - The URL of the image loader to display while the image is loading. Defaults to the loader asset resolved from the configured base path.\n * @property {boolean} noLazy - Disables lazy loading and renders the image source immediately.\n * @tag wje-img\n */\nexport default class Img extends WJElement {\n /**\n * Creates an instance of Img.\n * @class\n */\n constructor() {\n super();\n\n this._fallout = false;\n\n this.actions = {\n delete: () => this.deleteImage(),\n log: () => console.error('Error log pre obrázok:', this.src),\n };\n }\n\n /**\n * Sets the value of the `src` attribute for the element.\n * @param {string} value The value to set for the `src` attribute.\n */\n set src(value) {\n this.setAttribute('src', value);\n }\n\n /**\n * Retrieves the value of the 'src' attribute from the element.\n * @returns {string} The value of the 'src' attribute.\n */\n get src() {\n return this.getAttribute('src');\n }\n\n /**\n * Sets the value of the 'alt' attribute for the element.\n * @param {string} value The new value to set for the 'alt' attribute.\n */\n set alt(value) {\n this.setAttribute('alt', value);\n }\n\n /**\n * Retrieves the value of the 'alt' attribute for the current element.\n * @returns {string|null} The value of the 'alt' attribute, or null if the attribute is not set.\n */\n get alt() {\n return this.getAttribute('alt');\n }\n\n /**\n * Sets the fallout property. Updates the `fallout` attribute if the value is a string;\n * otherwise, assigns the value to the `_fallout` property.\n * @param {string|*} value The value to set for the fallout property. If a string, it will update the `fallout` attribute; for other types, it will assign it to the `_fallout` property.\n */\n set fallout(value) {\n if (typeof value === 'string') {\n this.setAttribute('fallout', value);\n } else {\n this._fallout = value;\n }\n }\n\n /**\n * Retrieves the value of the 'fallout' attribute if it exists, otherwise returns the internal `_fallout` property.\n * @returns {string|null} The value of the 'fallout' attribute or the `_fallout` property if the attribute is not present. Returns null if no value is found.\n */\n get fallout() {\n return this.hasAttribute('fallout') ? this.getAttribute('fallout') : this._fallout;\n }\n\n /**\n * Sets the value of the loader attribute.\n * @param {string} value The value to set for the loader attribute.\n */\n set loader(value) {\n if (value) {\n this.setAttribute('loader', value);\n }\n }\n\n /**\n * Retrieves the configured loader URL or resolves the default loader from the base path.\n * @returns {string} The loader URL.\n */\n get loader() {\n return this.getAttribute('loader') || getBasePath('assets/img/image-loader.gif');\n }\n\n /**\n * Enables or disables lazy loading for the image.\n * @param {boolean} value True to disable lazy loading, false to restore the default lazy behavior.\n */\n set noLazy(value) {\n if (value) {\n this.setAttribute('no-lazy', '');\n } else {\n this.removeAttribute('no-lazy');\n }\n }\n\n /**\n * Checks whether lazy loading is disabled.\n * @returns {boolean} True when the `no-lazy` attribute is present.\n */\n get noLazy() {\n return this.hasAttribute('no-lazy');\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'Img';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['src', 'alt', 'no-lazy'];\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n super.attributeChangedCallback?.(name, oldValue, newValue);\n if (oldValue === newValue) return;\n if (name === 'alt') {\n if (this.native) this.native.setAttribute('alt', this.alt || '');\n const label = this.alt?.trim();\n if (label) this.setAriaState({ label });\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAriaState({ role: 'img' });\n if (this.alt?.trim()) this.setAriaState({ label: this.alt.trim() });\n }\n\n /**\n * Creates and assembles a lazy-loaded image element within a document fragment.\n * @returns {DocumentFragment} A document fragment containing the image element.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('img');\n native.setAttribute('part', 'native');\n native.setAttribute('src', this.noLazy ? this.src : this.loader);\n native.setAttribute('alt', this.alt || '');\n native.classList.add('lazy-loaded-image', 'lazy');\n native.addEventListener('error', (e) => {\n const absoluteLoaderUrl = new URL(this.loader, window.location.origin).href;\n if (e.target.src === absoluteLoaderUrl) return;\n\n this.setAvatarInitials(true);\n });\n\n this.onerrorFunc(native);\n\n fragment.appendChild(native);\n\n this.native = native;\n\n if (this.alt?.trim()) this.setAriaState({ label: this.alt.trim() });\n\n return fragment;\n }\n\n /**\n * Handles post-draw operations, such as setting up a lazy image loader using an IntersectionObserver.\n * Observes when the target element becomes visible in the viewport and updates its source with the provided image source.\n * Removes the `lazy` class once the image source is updated and unobserves the element.\n * It also invokes the `onerrorFunc` method at the beginning to handle potential error scenarios.\n * @returns {void} Does not return a value.\n */\n afterDraw() {\n if (this.noLazy) {\n this.native.classList.remove('lazy');\n return;\n }\n\n let lazyImageObserver = new IntersectionObserver((entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n entry.target.src = this.src;\n this.classList.remove('lazy');\n\n lazyImageObserver.unobserve(entry.target);\n }\n });\n });\n\n lazyImageObserver.observe(this.native);\n }\n\n setAvatarInitials = (value = false) => {\n let parent = this.parentElement;\n if (parent?.tagName === 'WJE-AVATAR') parent.initials = value;\n };\n /**\n * Deletes the current image by calling the remove method.\n * This function is typically used to trigger the removal of an image element\n * or perform cleanup operations related to the image.\n */\n deleteImage = () => {\n this.remove();\n };\n\n /**\n * Adds a new action to the internal actions object.\n * @param {string} name The name of the action to be added.\n * @param {Function} func The function representing the action logic.\n * @returns {void} This method does not return a value.\n */\n addAction(name, func) {\n if (typeof func === 'function') {\n this.actions[name] = func;\n } else {\n console.error('The action must be a function.');\n }\n }\n\n /**\n * Removes an action from the actions list if it exists.\n * @param {string} name The name of the action to remove.\n * @returns {void} Does not return a value.\n */\n removeAction(name) {\n if (this.actions[name]) {\n delete this.actions[name];\n } else {\n console.error(`Action \"${name}\" does not exist.`);\n }\n }\n\n /**\n * Handles error scenarios by checking the `fallout` property and performing\n * corresponding actions. If `fallout` is not defined, the function terminates\n * early. Logs the active actions and attempts to assign an error handler\n * based on the `fallout` value. If the `fallout` value does not correspond to\n * a recognized action, it logs an error message.\n * @function onerrorFunc\n * @memberof Img\n */\n onerrorFunc = (img) => {\n if (!this.fallout) return;\n if (this.actions[this.fallout]) {\n img.onerror = this.actions[this.fallout];\n } else {\n console.error('Unsupported value:', this.fallout);\n }\n };\n}\n","import Img from './img.element.js';\n\nexport default Img;\n\nImg.define('wje-img', Img);\n"],"names":[],"mappings":";;;;;;AAkBe,MAAM,YAAY,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvC,cAAc;AACV,UAAK;AAyGT;AAAA;AAAA;AAAA;AAAA,qCAAY;AAgGZ,6CAAoB,CAAC,QA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I,IAAI;AAAA,IACzB,OAAO;AACH,cAAQ,MAAM,gCAAgC;AAAA,IAClD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,MAAM;AACf,QAAI,KAAK,QAAQ,IAAI,GAAG;AACpB,aAAO,KAAK,QAAQ,IAAI;AAAA,IAC5B,OAAO;AACH,cAAQ,MAAM,WAAW,IAAI,mBAAmB;AAAA,IACpD;AAAA,EACJ;AAmBJ;ACtRA,IAAI,OAAO,WAAW,GAAG;"}
|
|
1
|
+
{"version":3,"file":"wje-img.js","sources":["../packages/wje-img/img.element.js","../packages/wje-img/img.js"],"sourcesContent":["import { getBasePath } from '../utils/base-path.js';\nimport { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element represents an image. `Img` is a custom web component that represents an image. It extends from `WJElement`.\n * @documentation https://elements.webjet.sk/components/img\n * @status stable\n * @augments {WJElement}\n * @cssproperty --img-width - The width of the image\n * @cssproperty --img-height - The height of the image\n * @property {string} src - The source URL of the image.\n * @property {string} alt - The alternative text for the image.\n * @property {string} fallout - The action to perform when an error occurs while loading the image. The value can be a function or a predefined action like 'delete'.\n * @property {string} loader - The URL of the image loader to display while the image is loading. Defaults to the loader asset resolved from the configured base path.\n * @property {boolean} noLazy - Disables lazy loading and renders the image source immediately.\n * @tag wje-img\n */\nexport default class Img extends WJElement {\n /**\n * Creates an instance of Img.\n * @class\n */\n constructor() {\n super();\n\n this._fallout = false;\n\n this.actions = {\n delete: () => this.deleteImage(),\n log: () => console.error('Error log pre obrázok:', this.src),\n };\n }\n\n /**\n * Sets the value of the `src` attribute for the element.\n * @param {string} value The value to set for the `src` attribute.\n */\n set src(value) {\n this.setAttribute('src', value);\n }\n\n /**\n * Retrieves the value of the 'src' attribute from the element.\n * @returns {string} The value of the 'src' attribute.\n */\n get src() {\n return this.getAttribute('src');\n }\n\n /**\n * Sets the value of the 'alt' attribute for the element.\n * @param {string} value The new value to set for the 'alt' attribute.\n */\n set alt(value) {\n this.setAttribute('alt', value);\n }\n\n /**\n * Retrieves the value of the 'alt' attribute for the current element.\n * @returns {string|null} The value of the 'alt' attribute, or null if the attribute is not set.\n */\n get alt() {\n return this.getAttribute('alt');\n }\n\n /**\n * Sets the fallout property. Updates the `fallout` attribute if the value is a string;\n * otherwise, assigns the value to the `_fallout` property.\n * @param {string|*} value The value to set for the fallout property. If a string, it will update the `fallout` attribute; for other types, it will assign it to the `_fallout` property.\n */\n set fallout(value) {\n if (typeof value === 'string') {\n this.setAttribute('fallout', value);\n } else {\n this._fallout = value;\n }\n }\n\n /**\n * Retrieves the value of the 'fallout' attribute if it exists, otherwise returns the internal `_fallout` property.\n * @returns {string|null} The value of the 'fallout' attribute or the `_fallout` property if the attribute is not present. Returns null if no value is found.\n */\n get fallout() {\n return this.hasAttribute('fallout') ? this.getAttribute('fallout') : this._fallout;\n }\n\n /**\n * Sets the value of the loader attribute.\n * @param {string} value The value to set for the loader attribute.\n */\n set loader(value) {\n if (value) {\n this.setAttribute('loader', value);\n }\n }\n\n /**\n * Retrieves the configured loader URL or resolves the default loader from the base path.\n * @returns {string} The loader URL.\n */\n get loader() {\n return this.getAttribute('loader') || getBasePath('assets/img/image-loader.gif');\n }\n\n /**\n * Enables or disables lazy loading for the image.\n * @param {boolean} value True to disable lazy loading, false to restore the default lazy behavior.\n */\n set noLazy(value) {\n if (value) {\n this.setAttribute('no-lazy', '');\n } else {\n this.removeAttribute('no-lazy');\n }\n }\n\n /**\n * Checks whether lazy loading is disabled.\n * @returns {boolean} True when the `no-lazy` attribute is present.\n */\n get noLazy() {\n return this.hasAttribute('no-lazy');\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'Img';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['src', 'alt', 'no-lazy'];\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n super.attributeChangedCallback?.(name, oldValue, newValue);\n if (oldValue === newValue) return;\n if (name === 'alt') {\n if (this.native) this.native.setAttribute('alt', this.alt || '');\n const label = this.alt?.trim();\n if (label) this.setAriaState({ label });\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAriaState({ role: 'img' });\n if (this.alt?.trim()) this.setAriaState({ label: this.alt.trim() });\n }\n\n /**\n * Creates and assembles a lazy-loaded image element within a document fragment.\n * @returns {DocumentFragment} A document fragment containing the image element.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('img');\n native.setAttribute('part', 'native');\n native.setAttribute('src', this.noLazy ? this.src : this.loader);\n native.setAttribute('alt', this.alt || '');\n native.classList.add('lazy-loaded-image', 'lazy');\n native.addEventListener('error', (e) => {\n const absoluteLoaderUrl = new URL(this.loader, window.location.origin).href;\n if (e.target.src === absoluteLoaderUrl) return;\n\n this.setAvatarInitials(true);\n });\n\n this.onerrorFunc(native);\n\n fragment.appendChild(native);\n\n this.native = native;\n\n if (this.alt?.trim()) this.setAriaState({ label: this.alt.trim() });\n\n return fragment;\n }\n\n /**\n * Handles post-draw operations, such as setting up a lazy image loader using an IntersectionObserver.\n * Observes when the target element becomes visible in the viewport and updates its source with the provided image source.\n * Removes the `lazy` class once the image source is updated and unobserves the element.\n * It also invokes the `onerrorFunc` method at the beginning to handle potential error scenarios.\n * @returns {void} Does not return a value.\n */\n afterDraw() {\n if (this.noLazy) {\n this.native.classList.remove('lazy');\n return;\n }\n\n let lazyImageObserver = new IntersectionObserver((entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n entry.target.src = this.src;\n this.classList.remove('lazy');\n\n lazyImageObserver.unobserve(entry.target);\n }\n });\n });\n\n lazyImageObserver.observe(this.native);\n }\n\n setAvatarInitials = (value = false) => {\n let parent = this.parentElement;\n if (parent?.tagName === 'WJE-AVATAR') parent.initials = value;\n };\n /**\n * Deletes the current image by calling the remove method.\n * This function is typically used to trigger the removal of an image element\n * or perform cleanup operations related to the image.\n */\n deleteImage = () => {\n this.remove();\n };\n\n /**\n * Adds a new action to the internal actions object.\n * @param {string} name The name of the action to be added.\n * @param {Function} func The function representing the action logic.\n * @returns {void} This method does not return a value.\n */\n addAction(name, func) {\n if (typeof func === 'function') {\n this.actions[name] = func;\n } else {\n console.error('The action must be a function.');\n }\n }\n\n /**\n * Removes an action from the actions list if it exists.\n * @param {string} name The name of the action to remove.\n * @returns {void} Does not return a value.\n */\n removeAction(name) {\n if (this.actions[name]) {\n delete this.actions[name];\n } else {\n console.error(`Action \"${name}\" does not exist.`);\n }\n }\n\n /**\n * Handles error scenarios by checking the `fallout` property and performing\n * corresponding actions. If `fallout` is not defined, the function terminates\n * early. Logs the active actions and attempts to assign an error handler\n * based on the `fallout` value. If the `fallout` value does not correspond to\n * a recognized action, it logs an error message.\n * @function onerrorFunc\n * @memberof Img\n */\n onerrorFunc = (img) => {\n if (!this.fallout) return;\n if (this.actions[this.fallout]) {\n img.onerror = this.actions[this.fallout];\n } else {\n console.error('Unsupported value:', this.fallout);\n }\n };\n}\n","import Img from './img.element.js';\n\nexport default Img;\n\nImg.define('wje-img', Img);\n"],"names":["Img","WJElement","constructor","super","className","setAvatarInitials","value","parent","this","parentElement","tagName","initials","deleteImage","remove","onerrorFunc","img","fallout","actions","onerror","console","error","_fallout","delete","log","src","setAttribute","getAttribute","hasAttribute","loader","getBasePath","removeAttribute","noLazy","cssStyleSheet","observedAttributes","name","oldValue","newValue","attributeChangedCallback","native","alt","label","trim","setAriaState","setupAttributes","isShadowRoot","role","draw","fragment","document","createDocumentFragment","createElement","classList","add","addEventListener","e","absoluteLoaderUrl","URL","window","location","origin","href","target","appendChild","afterDraw","lazyImageObserver","IntersectionObserver","entries","observer","forEach","entry","isIntersecting","unobserve","observe","func","define"],"mappings":";;;;;AAkBe,MAAMA,UAAYC,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