wj-elements 0.0.11 → 0.0.13

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.
Files changed (79) hide show
  1. package/dist/localize-20081fd1.js +55 -0
  2. package/dist/router-links-26e4a166.js +204 -0
  3. package/dist/style.css +2243 -2
  4. package/dist/wj-animation.js +35 -23
  5. package/dist/wj-aside.js +22 -16
  6. package/dist/wj-avatar.js +49 -30
  7. package/dist/wj-badge.js +22 -18
  8. package/dist/wj-breadcrumb.js +102 -50
  9. package/dist/wj-breadcrumbs.js +36 -19
  10. package/dist/wj-button-group.js +36 -22
  11. package/dist/wj-button.js +104 -39
  12. package/dist/wj-card-content.js +18 -14
  13. package/dist/wj-card-controls.js +18 -14
  14. package/dist/wj-card-header.js +20 -14
  15. package/dist/wj-card-subtitle.js +19 -15
  16. package/dist/wj-card-title.js +18 -14
  17. package/dist/wj-card.js +20 -14
  18. package/dist/wj-carousel-item.js +22 -16
  19. package/dist/wj-carousel.js +169 -92
  20. package/dist/wj-checkbox.js +46 -24
  21. package/dist/wj-chip.js +39 -21
  22. package/dist/wj-col.js +31 -17
  23. package/dist/wj-color-picker.js +877 -509
  24. package/dist/wj-container.js +20 -16
  25. package/dist/wj-copy-button.js +112 -64
  26. package/dist/wj-dialog.js +68 -42
  27. package/dist/wj-divider.js +20 -14
  28. package/dist/wj-dropdown.js +29 -17
  29. package/dist/wj-element.js +415 -241
  30. package/dist/wj-fetchAndParseCSS.js +49 -32
  31. package/dist/wj-file-upload-item.js +64 -38
  32. package/dist/wj-file-upload.js +237 -137
  33. package/dist/wj-footer.js +18 -14
  34. package/dist/wj-form.js +18 -14
  35. package/dist/wj-format-digital.js +40 -25
  36. package/dist/wj-grid.js +20 -16
  37. package/dist/wj-header.js +22 -16
  38. package/dist/wj-icon-picker.js +122 -68
  39. package/dist/wj-icon.js +144 -64
  40. package/dist/wj-img-comparer.js +72 -41
  41. package/dist/wj-img.js +31 -19
  42. package/dist/wj-infinite-scroll.js +90 -52
  43. package/dist/wj-input-file.js +50 -27
  44. package/dist/wj-input.js +169 -70
  45. package/dist/wj-item.js +34 -17
  46. package/dist/wj-label.js +21 -19
  47. package/dist/wj-list.js +20 -15
  48. package/dist/wj-main.js +18 -14
  49. package/dist/wj-masonry.js +140 -83
  50. package/dist/wj-master.js +492 -350
  51. package/dist/wj-menu-button.js +19 -15
  52. package/dist/wj-menu-item.js +150 -64
  53. package/dist/wj-menu-label.js +21 -17
  54. package/dist/wj-menu.js +24 -18
  55. package/dist/wj-popup.js +1140 -712
  56. package/dist/wj-progress-bar.js +100 -40
  57. package/dist/wj-radio-group.js +38 -25
  58. package/dist/wj-radio.js +46 -22
  59. package/dist/wj-rate.js +121 -71
  60. package/dist/wj-relative-time.js +48 -24
  61. package/dist/wj-route.js +11 -8
  62. package/dist/wj-router-link.js +22 -17
  63. package/dist/wj-router-outlet.js +135 -71
  64. package/dist/wj-routerx.js +1124 -641
  65. package/dist/wj-row.js +21 -19
  66. package/dist/wj-slider.js +97 -55
  67. package/dist/wj-split-view.js +81 -43
  68. package/dist/wj-store.js +195 -110
  69. package/dist/wj-textarea.js +86 -37
  70. package/dist/wj-thumbnail.js +19 -15
  71. package/dist/wj-toast.js +87 -34
  72. package/dist/wj-toggle.js +42 -24
  73. package/dist/wj-toolbar-action.js +27 -16
  74. package/dist/wj-toolbar.js +26 -19
  75. package/dist/wj-tooltip.js +40 -24
  76. package/dist/wj-visually-hidden.js +18 -14
  77. package/package.json +1 -1
  78. package/dist/localize-762a9f0f.js +0 -43
  79. package/dist/router-links-e0087f84.js +0 -146
package/dist/wj-icon.js CHANGED
@@ -1,64 +1,129 @@
1
- var w = Object.defineProperty;
2
- var f = (e, t, o) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var l = (e, t, o) => (f(e, typeof t != "symbol" ? t + "" : t, o), o);
4
- import m from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const n = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
7
- let c;
8
- const u = (e) => a(e) && (e = e.trim(), g(e)) ? e : null, g = (e) => e.length > 0 && /(\/|\.)/.test(e), j = (e) => e.startsWith("data:image/svg+xml"), v = (e) => e.indexOf(";utf8,") !== -1, a = (e) => typeof e == "string", p = (e) => {
9
- const t = document.createElement("div");
10
- t.innerHTML = e;
11
- const o = t.firstElementChild;
12
- return o && o.nodeName.toLowerCase() === "svg" && (o.getAttribute("class"), d(o)) ? t.innerHTML : "";
13
- }, d = (e) => {
14
- if (e.nodeType === 1) {
15
- if (e.nodeName.toLowerCase() === "script")
16
- return !1;
17
- for (let t = 0; t < e.attributes.length; t++) {
18
- const o = e.attributes[t].name;
19
- if (a(o) && o.toLowerCase().indexOf("on") === 0)
20
- return !1;
9
+ const iconContent = /* @__PURE__ */ new Map();
10
+ const requests = /* @__PURE__ */ new Map();
11
+ let parser;
12
+ const getSrc = (src) => {
13
+ if (isStr(src)) {
14
+ src = src.trim();
15
+ if (isSrc(src)) {
16
+ return src;
17
+ }
18
+ }
19
+ return null;
20
+ };
21
+ const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str);
22
+ const isSvgDataUrl = (url) => url.startsWith("data:image/svg+xml");
23
+ const isEncodedDataUrl = (url) => url.indexOf(";utf8,") !== -1;
24
+ const isStr = (val) => typeof val === "string";
25
+ const validateContent = (svgContent) => {
26
+ const div = document.createElement("div");
27
+ div.innerHTML = svgContent;
28
+ const svgElm = div.firstElementChild;
29
+ if (svgElm && svgElm.nodeName.toLowerCase() === "svg") {
30
+ svgElm.getAttribute("class") || "";
31
+ if (isValid(svgElm)) {
32
+ return div.innerHTML;
33
+ }
34
+ }
35
+ return "";
36
+ };
37
+ const isValid = (elm) => {
38
+ if (elm.nodeType === 1) {
39
+ if (elm.nodeName.toLowerCase() === "script") {
40
+ return false;
41
+ }
42
+ for (let i = 0; i < elm.attributes.length; i++) {
43
+ const name = elm.attributes[i].name;
44
+ if (isStr(name) && name.toLowerCase().indexOf("on") === 0) {
45
+ return false;
46
+ }
47
+ }
48
+ for (let i = 0; i < elm.childNodes.length; i++) {
49
+ if (!isValid(elm.childNodes[i])) {
50
+ return false;
51
+ }
21
52
  }
22
- for (let t = 0; t < e.childNodes.length; t++)
23
- if (!d(e.childNodes[t]))
24
- return !1;
25
53
  }
26
- return !0;
27
- }, z = (e, t) => {
28
- let o = h.get(e);
29
- if (!o)
30
- if (typeof fetch < "u" && typeof document < "u")
31
- if (j(e) && v(e)) {
32
- c || (c = new DOMParser());
33
- const s = c.parseFromString(e, "text/html").querySelector("svg");
34
- return s && n.set(e, s.outerHTML), Promise.resolve();
35
- } else
36
- o = fetch(e).then((r) => {
37
- if (r.ok)
38
- return r.text().then((s) => {
39
- s && t !== !1 && (s = p(s)), n.set(e, s || "");
54
+ return true;
55
+ };
56
+ const getSvgContent = (url, sanitize) => {
57
+ let req = requests.get(url);
58
+ if (!req) {
59
+ if (typeof fetch !== "undefined" && typeof document !== "undefined") {
60
+ if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
61
+ if (!parser) {
62
+ parser = new DOMParser();
63
+ }
64
+ const doc = parser.parseFromString(url, "text/html");
65
+ const svg = doc.querySelector("svg");
66
+ if (svg) {
67
+ iconContent.set(url, svg.outerHTML);
68
+ }
69
+ return Promise.resolve();
70
+ } else {
71
+ req = fetch(url).then((rsp) => {
72
+ if (rsp.ok) {
73
+ return rsp.text().then((svgContent) => {
74
+ if (svgContent && sanitize !== false) {
75
+ svgContent = validateContent(svgContent);
76
+ }
77
+ iconContent.set(url, svgContent || "");
40
78
  });
41
- n.set(e, "");
42
- }), h.set(e, o);
43
- else
44
- return n.set(e, ""), Promise.resolve();
45
- return o;
46
- }, b = (e) => {
47
- let t = u(e.src);
48
- return t || (t = y(e.name), t ? L(t) : null);
49
- }, y = (e) => !a(e) || e.trim() === "" || e.replace(/[a-z]|-|\d/gi, "") !== "" ? null : e, L = (e) => {
50
- const t = `/assets/img/icons/svg/${e}.svg`;
51
- let o = new URL(import.meta.url), r = o.pathname, s = r.substring(0, r.lastIndexOf("/"));
52
- return new URL(o.origin + s + t).href;
53
- }, x = `:host(.wj-color-primary){--wj-icon-color: var(--wj-color-primary)}:host(.wj-color-complete){--wj-icon-color: var(--wj-color-complete)}:host(.wj-color-success){--wj-icon-color: var(--wj-color-success)}:host(.wj-color-warning){--wj-icon-color: var(--wj-color-warning)}:host(.wj-color-danger){--wj-icon-color: var(--wj-color-danger)}:host(.wj-color-info){--wj-icon-color: var(--wj-color-info)}:host{--wj-icon-size: 1rem;--wj-icon-width: var(--wj-icon-size, 100%);--wj-icon-height: var(--wj-icon-size, 100%);display:inline-block;width:var(--wj-icon-width);height:var(--wj-icon-height);contain:strict;fill:currentColor;box-sizing:content-box!important}.icon-inner,svg{display:block;width:var(--wj-icon-width);height:var(--wj-icon-height)}:host(.wj-size-small){--wj-icon-size: 18px}:host(.wj-size-large){--wj-icon-size: 32px}:host(.wj-size){font-size:var(--wj-icon-size)}:host(.wj-color){color:var(--wj-icon-color)!important}
54
- `;
55
- class S extends m {
79
+ }
80
+ iconContent.set(url, "");
81
+ });
82
+ requests.set(url, req);
83
+ }
84
+ } else {
85
+ iconContent.set(url, "");
86
+ return Promise.resolve();
87
+ }
88
+ }
89
+ return req;
90
+ };
91
+ const getUrl = (i) => {
92
+ let url = getSrc(i.src);
93
+ if (url) {
94
+ return url;
95
+ }
96
+ url = getName(i.name);
97
+ if (url) {
98
+ return getNamedUrl(url);
99
+ }
100
+ return null;
101
+ };
102
+ const getName = (iconName) => {
103
+ if (!isStr(iconName) || iconName.trim() === "") {
104
+ return null;
105
+ }
106
+ const invalidChars = iconName.replace(/[a-z]|-|\d/gi, "");
107
+ if (invalidChars !== "") {
108
+ return null;
109
+ }
110
+ return iconName;
111
+ };
112
+ const getNamedUrl = (iconName) => {
113
+ const path = `/assets/img/icons/svg/${iconName}.svg`;
114
+ let parsedUrl = new URL(import.meta.url);
115
+ let pathName = parsedUrl.pathname;
116
+ let folderPath = pathName.substring(0, pathName.lastIndexOf("/"));
117
+ return new URL(parsedUrl.origin + folderPath + path).href;
118
+ };
119
+ const styles = "/*\n[ WJ Icon ]\n*/\n:host(.wj-color-primary) {\n --wj-icon-color: var(--wj-color-primary);\n}\n\n:host(.wj-color-complete) {\n --wj-icon-color: var(--wj-color-complete);\n}\n\n:host(.wj-color-success) {\n --wj-icon-color: var(--wj-color-success);\n}\n\n:host(.wj-color-warning) {\n --wj-icon-color: var(--wj-color-warning);\n}\n\n:host(.wj-color-danger) {\n --wj-icon-color: var(--wj-color-danger);\n}\n\n:host(.wj-color-info) {\n --wj-icon-color: var(--wj-color-info);\n}\n\n:host {\n --wj-icon-size: 1rem;\n --wj-icon-width: var(--wj-icon-size, 100%);\n --wj-icon-height: var(--wj-icon-size, 100%);\n display: inline-block;\n width: var(--wj-icon-width);\n height: var(--wj-icon-height);\n contain: strict;\n fill: currentColor;\n box-sizing: content-box !important;\n}\n\n.icon-inner, svg {\n display: block;\n width: var(--wj-icon-width);\n height: var(--wj-icon-height);\n}\n\n:host(.wj-size-small) {\n --wj-icon-size: 18px;\n}\n\n:host(.wj-size-large) {\n --wj-icon-size: 32px;\n}\n\n:host(.wj-size) {\n font-size: var(--wj-icon-size);\n}\n\n:host(.wj-color) {\n color: var(--wj-icon-color) !important;\n}";
120
+ class Icon extends WJElement {
56
121
  constructor() {
57
122
  super();
58
- l(this, "className", "Icon");
123
+ __publicField(this, "className", "Icon");
59
124
  }
60
125
  static get cssStyleSheet() {
61
- return x;
126
+ return styles;
62
127
  }
63
128
  static get observedAttributes() {
64
129
  return ["name"];
@@ -66,22 +131,37 @@ class S extends m {
66
131
  setupAttributes() {
67
132
  this.isShadowRoot = "open";
68
133
  }
69
- draw(o, r, s) {
70
- let i = document.createDocumentFragment();
71
- return this.classList.add("lazy-loaded-image", "lazy"), this.element = document.createElement("div"), this.element.classList.add("icon-inner"), this.url = b(this), this.classList.add("wj-size"), this.color && this.classList.add("wj-color-" + this.color, "wj-color"), this.size && this.classList.add("wj-size-" + this.size), i.appendChild(this.element), i;
134
+ draw(context, store, params) {
135
+ let fragment = document.createDocumentFragment();
136
+ this.classList.add("lazy-loaded-image", "lazy");
137
+ this.element = document.createElement("div");
138
+ this.element.classList.add("icon-inner");
139
+ this.url = getUrl(this);
140
+ this.classList.add("wj-size");
141
+ if (this.color)
142
+ this.classList.add("wj-color-" + this.color, "wj-color");
143
+ if (this.size)
144
+ this.classList.add("wj-size-" + this.size);
145
+ fragment.appendChild(this.element);
146
+ return fragment;
72
147
  }
73
148
  afterDraw() {
74
- let o = new IntersectionObserver((r, s) => {
75
- r.forEach((i) => {
76
- i.isIntersecting && (z(this.url).then((C) => {
77
- this.element.innerHTML = n.get(this.url), this.element.querySelector("svg").setAttribute("part", "svg");
78
- }), this.classList.remove("lazy"), o.unobserve(i.target));
149
+ let lazyImageObserver = new IntersectionObserver((entries, observer) => {
150
+ entries.forEach((entry) => {
151
+ if (entry.isIntersecting) {
152
+ getSvgContent(this.url).then((svgContent) => {
153
+ this.element.innerHTML = iconContent.get(this.url);
154
+ this.element.querySelector("svg").setAttribute("part", "svg");
155
+ });
156
+ this.classList.remove("lazy");
157
+ lazyImageObserver.unobserve(entry.target);
158
+ }
79
159
  });
80
160
  });
81
- o.observe(this.element);
161
+ lazyImageObserver.observe(this.element);
82
162
  }
83
163
  }
84
- customElements.get("wj-icon") || window.customElements.define("wj-icon", S);
164
+ customElements.get("wj-icon") || window.customElements.define("wj-icon", Icon);
85
165
  export {
86
- S as Icon
166
+ Icon
87
167
  };
@@ -1,38 +1,57 @@
1
- var w = Object.defineProperty;
2
- var u = (i, e, t) => e in i ? w(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var p = (i, e, t) => (u(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- import h from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- function f(i, e) {
7
- function t(o) {
8
- const d = i.getBoundingClientRect(), r = i.ownerDocument.defaultView, n = d.left + r.pageXOffset, l = d.top + r.pageYOffset, c = o.pageX - n, m = o.pageY - l;
9
- e != null && e.onMove && e.onMove(c, m);
9
+ function drag(container, options) {
10
+ function move(pointerEvent) {
11
+ const dims = container.getBoundingClientRect();
12
+ const defaultView = container.ownerDocument.defaultView;
13
+ const offsetX = dims.left + defaultView.pageXOffset;
14
+ const offsetY = dims.top + defaultView.pageYOffset;
15
+ const x = pointerEvent.pageX - offsetX;
16
+ const y = pointerEvent.pageY - offsetY;
17
+ if (options == null ? void 0 : options.onMove) {
18
+ options.onMove(x, y);
19
+ }
20
+ }
21
+ function stop() {
22
+ document.removeEventListener("pointermove", move);
23
+ document.removeEventListener("pointerup", stop);
24
+ if (options == null ? void 0 : options.onStop) {
25
+ options.onStop();
26
+ }
10
27
  }
11
- function a() {
12
- document.removeEventListener("pointermove", t), document.removeEventListener("pointerup", a), e != null && e.onStop && e.onStop();
28
+ document.addEventListener("pointermove", move, { passive: true });
29
+ document.addEventListener("pointerup", stop);
30
+ if ((options == null ? void 0 : options.initialEvent) instanceof PointerEvent) {
31
+ move(options.initialEvent);
13
32
  }
14
- document.addEventListener("pointermove", t, { passive: !0 }), document.addEventListener("pointerup", a), (e == null ? void 0 : e.initialEvent) instanceof PointerEvent && t(e.initialEvent);
15
33
  }
16
- const g = `:host{--wj-img-compare-divider-area: 12px;--wj-img-compare-divider-background: white;--wj-img-compare-divider-size: 2px;--wj-img-compare-divider-left: 50%;--wj-img-compare-position: 50%;--wj-img-compare-clip-path: inset(0 calc(100% - var(--wj-img-compare-position)) 0 0);display:inline-block;position:relative;width:100%;border-color:var(--wj-border-color);border-style:solid;border-width:1px}.wj-before,.wj-after{display:block}.wj-after{position:absolute;top:0;left:0;height:100%;width:100%;clip-path:var(--wj-img-compare-clip-path)}.native-split-view{max-width:100%;max-height:100%;overflow:hidden}.wj-divider{display:flex;position:absolute;align-items:center;justify-content:center;z-index:1;background-color:var(--wj-img-compare-divider-background);height:100%;width:var(--wj-img-compare-divider-size);cursor:col-resize;top:0;left:var(--wj-img-compare-divider-left)}.wj-divider:after{display:flex;content:"";position:absolute;height:100%;left:calc(var(--wj-img-compare-divider-area) / -2 + var(--wj-img-compare-divider-size) / 2);width:var(---wj-img-compare-divider-area)}.wj-divider wj-icon{position:absolute;background-color:#fff;padding:.5rem;color:var(--wj-color-dark);border-radius:var(--wj-border-radius-circle);box-shadow:#523f6933 0 0 30px 10px;background:var(--wj-color-white)!important}
17
- `;
18
- class j extends h {
34
+ const styles = '/*\n[ WJ Image Compare ]\n*/\n:host {\n --wj-img-compare-divider-area: 12px;\n --wj-img-compare-divider-background: white;\n --wj-img-compare-divider-size: 2px;\n --wj-img-compare-divider-left: 50%;\n --wj-img-compare-position: 50%;\n --wj-img-compare-clip-path: inset(0 calc(100% - var(--wj-img-compare-position)) 0 0);\n display: inline-block;\n position: relative;\n width: 100%;\n border-color: var(--wj-border-color);\n border-style: solid;\n border-width: 1px;\n}\n\n.wj-before, .wj-after {\n display: block;\n}\n\n.wj-after {\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n clip-path: var(--wj-img-compare-clip-path);\n}\n\n.native-split-view {\n max-width: 100%;\n max-height: 100%;\n overflow: hidden;\n}\n\n.wj-divider {\n display: flex;\n position: absolute;\n align-items: center;\n justify-content: center;\n z-index: 1;\n background-color: var(--wj-img-compare-divider-background);\n height: 100%;\n width: var(--wj-img-compare-divider-size);\n cursor: col-resize;\n top: 0;\n left: var(--wj-img-compare-divider-left);\n}\n.wj-divider:after {\n display: flex;\n content: "";\n position: absolute;\n height: 100%;\n left: calc(var(--wj-img-compare-divider-area) / -2 + var(--wj-img-compare-divider-size) / 2);\n width: var(---wj-img-compare-divider-area);\n}\n.wj-divider wj-icon {\n position: absolute;\n background-color: white;\n padding: 0.5rem;\n color: var(--wj-color-dark);\n border-radius: var(--wj-border-radius-circle);\n box-shadow: rgba(82, 63, 105, 0.2) 0 0 30px 10px;\n background: var(--wj-color-white) !important;\n}';
35
+ class ImgComparer extends WJElement {
19
36
  constructor() {
20
37
  super();
21
- p(this, "className", "ImgComparer");
22
- p(this, "handleDrag", (t) => {
23
- const { width: a } = this.native.getBoundingClientRect();
24
- f(this, {
25
- onMove: (o) => {
26
- let d = o / a * 100;
27
- this.position = parseFloat(this.clamp(d, 0, 100).toFixed(2)), this.native.style.setProperty("--wj-img-compare-divider-left", this.position + "%"), this.native.style.setProperty("--wj-img-compare-clip-path", `inset(0 ${100 - this.position}% 0 0)`);
38
+ __publicField(this, "className", "ImgComparer");
39
+ __publicField(this, "handleDrag", (e) => {
40
+ const { width } = this.native.getBoundingClientRect();
41
+ drag(this, {
42
+ onMove: (x) => {
43
+ let value = x / width * 100;
44
+ this.position = parseFloat(this.clamp(value, 0, 100).toFixed(2));
45
+ this.native.style.setProperty("--wj-img-compare-divider-left", this.position + "%");
46
+ this.native.style.setProperty("--wj-img-compare-clip-path", `inset(0 ${100 - this.position}% 0 0)`);
28
47
  },
29
- initialEvent: t
48
+ initialEvent: e
30
49
  });
31
50
  });
32
- p(this, "clamp", (t, a, o) => Math.min(Math.max(t, a), o));
51
+ __publicField(this, "clamp", (num, min, max) => Math.min(Math.max(num, min), max));
33
52
  }
34
53
  static get cssStyleSheet() {
35
- return g;
54
+ return styles;
36
55
  }
37
56
  static get observedAttributes() {
38
57
  return [];
@@ -40,24 +59,36 @@ class j extends h {
40
59
  setupAttributes() {
41
60
  this.isShadowRoot = "open";
42
61
  }
43
- draw(t, a, o) {
44
- let d = document.createDocumentFragment(), r = document.createElement("div");
45
- r.classList.add("native-split-view");
46
- let n = document.createElement("div");
47
- n.classList.add("wj-before");
48
- let l = document.createElement("slot");
49
- l.setAttribute("name", "before");
50
- let c = document.createElement("div");
51
- c.classList.add("wj-after");
52
- let m = document.createElement("slot");
53
- m.setAttribute("name", "after");
54
- let v = document.createElement("wj-icon");
55
- v.setAttribute("name", "arrow-bar-both");
56
- let s = document.createElement("div");
57
- return s.classList.add("wj-divider"), s.setAttribute("part", "divider"), s.addEventListener("mousedown", this.handleDrag, !1), n.appendChild(l), c.appendChild(m), s.appendChild(v), r.appendChild(n), r.appendChild(c), r.appendChild(s), d.appendChild(r), this.native = r, d;
62
+ draw(context, store, params) {
63
+ let fragment = document.createDocumentFragment();
64
+ let native = document.createElement("div");
65
+ native.classList.add("native-split-view");
66
+ let beforeElement = document.createElement("div");
67
+ beforeElement.classList.add("wj-before");
68
+ let before = document.createElement("slot");
69
+ before.setAttribute("name", "before");
70
+ let afterElement = document.createElement("div");
71
+ afterElement.classList.add("wj-after");
72
+ let after = document.createElement("slot");
73
+ after.setAttribute("name", "after");
74
+ let icon = document.createElement("wj-icon");
75
+ icon.setAttribute("name", "arrow-bar-both");
76
+ let dividerElement = document.createElement("div");
77
+ dividerElement.classList.add("wj-divider");
78
+ dividerElement.setAttribute("part", "divider");
79
+ dividerElement.addEventListener("mousedown", this.handleDrag, false);
80
+ beforeElement.appendChild(before);
81
+ afterElement.appendChild(after);
82
+ dividerElement.appendChild(icon);
83
+ native.appendChild(beforeElement);
84
+ native.appendChild(afterElement);
85
+ native.appendChild(dividerElement);
86
+ fragment.appendChild(native);
87
+ this.native = native;
88
+ return fragment;
58
89
  }
59
90
  }
60
- customElements.get("wj-img-comparer") || window.customElements.define("wj-img-comparer", j);
91
+ customElements.get("wj-img-comparer") || window.customElements.define("wj-img-comparer", ImgComparer);
61
92
  export {
62
- j as ImgComparer
93
+ ImgComparer
63
94
  };
package/dist/wj-img.js CHANGED
@@ -1,35 +1,47 @@
1
- var g = Object.defineProperty;
2
- var n = (r, e, t) => e in r ? g(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var m = (r, e, t) => (n(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- import l from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const d = `img{display:block;width:var(--wj-img-width, 100%);height:var(--wj-img-height, auto);max-width:100%;object-fit:inherit;border-radius:var(--wj-img-border-radius, 0)}
7
- `;
8
- class h extends l {
9
+ const styles = "/*\n[ WJ Img ]\n*/\nimg {\n display: block;\n width: var(--wj-img-width, 100%);\n height: var(--wj-img-height, auto);\n max-width: 100%;\n object-fit: inherit;\n border-radius: var(--wj-img-border-radius, 0);\n}";
10
+ class Img extends WJElement {
9
11
  constructor() {
10
12
  super();
11
- m(this, "className", "Img");
13
+ __publicField(this, "className", "Img");
12
14
  }
13
15
  static get cssStyleSheet() {
14
- return d;
16
+ return styles;
15
17
  }
16
18
  setupAttributes() {
17
19
  this.isShadowRoot = "open";
18
20
  }
19
- draw(t, o, c) {
20
- let i = document.createDocumentFragment(), s = document.createElement("img");
21
- return s.setAttribute("src", "./demo/assets/img/image-loader.gif"), s.classList.add("lazy-loaded-image", "lazy"), s.setAttribute("alt", this.alt || ""), this.img = s, i.appendChild(s), i;
21
+ draw(context, store, params) {
22
+ let fragment = document.createDocumentFragment();
23
+ let img = document.createElement("img");
24
+ img.setAttribute("src", "./demo/assets/img/image-loader.gif");
25
+ img.classList.add("lazy-loaded-image", "lazy");
26
+ img.setAttribute("alt", this.alt || "");
27
+ this.img = img;
28
+ fragment.appendChild(img);
29
+ return fragment;
22
30
  }
23
- afterDraw(t, o, c) {
24
- let i = new IntersectionObserver((s, u) => {
25
- s.forEach((a) => {
26
- a.isIntersecting && (a.target.src = this.src, this.classList.remove("lazy"), i.unobserve(a.target));
31
+ afterDraw(context, store, params) {
32
+ let lazyImageObserver = new IntersectionObserver((entries, observer) => {
33
+ entries.forEach((entry) => {
34
+ if (entry.isIntersecting) {
35
+ entry.target.src = this.src;
36
+ this.classList.remove("lazy");
37
+ lazyImageObserver.unobserve(entry.target);
38
+ }
27
39
  });
28
40
  });
29
- i.observe(this.img);
41
+ lazyImageObserver.observe(this.img);
30
42
  }
31
43
  }
32
- customElements.get("wj-img") || window.customElements.define("wj-img", h);
44
+ customElements.get("wj-img") || window.customElements.define("wj-img", Img);
33
45
  export {
34
- h as Img
46
+ Img
35
47
  };
@@ -1,38 +1,49 @@
1
- var u = Object.defineProperty;
2
- var m = (l, r, t) => r in l ? u(l, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[r] = t;
3
- var h = (l, r, t) => (m(l, typeof r != "symbol" ? r + "" : r, t), t);
4
- import g, { event as p } from "./wj-element.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement, { event } from "./wj-element.js";
5
8
  import "./wj-store.js";
6
- const f = `:host{--wj-infinite-scroll-width: 100%;--wj-infinite-scroll-height: 300px;overflow-x:auto;width:var(--wj-infinite-scroll-width);height:var(--wj-infinite-scroll-height);display:block}
7
- `;
8
- class w extends g {
9
- constructor(t = {}) {
9
+ const styles = "/*\n[ Wj nfinite Scroll ]\n*/\n:host {\n --wj-infinite-scroll-width: 100%;\n --wj-infinite-scroll-height: 300px;\n overflow-x: auto;\n width: var(--wj-infinite-scroll-width);\n height: var(--wj-infinite-scroll-height);\n display: block;\n}";
10
+ class InfiniteScroll extends WJElement {
11
+ constructor(options = {}) {
10
12
  super();
11
- h(this, "className", "InfiniteScroll");
12
- h(this, "scrollEvent", () => {
13
+ __publicField(this, "className", "InfiniteScroll");
14
+ __publicField(this, "scrollEvent", () => {
13
15
  this.addEventListener("scroll", this.onScroll);
14
16
  });
15
- h(this, "unScrollEvent", () => {
17
+ __publicField(this, "unScrollEvent", () => {
16
18
  this.removeEventListener("scroll", this.onScroll);
17
19
  });
18
- h(this, "onScroll", (t) => {
19
- const { scrollTop: s, scrollHeight: e, clientHeight: i } = t.target;
20
- s + i >= e - 300 && this.currentPage <= this.totalPages && this.isLoading.includes(this.currentPage) && (this.currentPage++, this.loadPages(this.currentPage));
20
+ __publicField(this, "onScroll", (e) => {
21
+ const { scrollTop, scrollHeight, clientHeight } = e.target;
22
+ if (scrollTop + clientHeight >= scrollHeight - 300 && this.currentPage <= this.totalPages && this.isLoading.includes(this.currentPage)) {
23
+ this.currentPage++;
24
+ this.loadPages(this.currentPage);
25
+ }
21
26
  });
22
- this.totalPages = 0, this.isLoading = [], String.prototype.interpolate = function(s) {
23
- let e = this, i = e.match(/\{{.*?\}}/g);
24
- if (i)
25
- for (let a of i) {
26
- let o = a.replace("{{", "").replace("}}", ""), n = "";
27
- o.split(".").forEach((c) => {
28
- n = n == "" ? s[c] : n[c];
29
- }), e = e.replace(a, n);
27
+ this.totalPages = 0;
28
+ this.isLoading = [];
29
+ String.prototype.interpolate = function(params) {
30
+ let template = this;
31
+ let keys = template.match(/\{{.*?\}}/g);
32
+ if (keys) {
33
+ for (let key of keys) {
34
+ let cleanKey = key.replace("{{", "").replace("}}", "");
35
+ let val = "";
36
+ cleanKey.split(".").forEach((k) => {
37
+ val = val == "" ? params[k] : val[k];
38
+ });
39
+ template = template.replace(key, val);
30
40
  }
31
- return e;
41
+ }
42
+ return template;
32
43
  };
33
44
  }
34
45
  static get cssStyleSheet() {
35
- return f;
46
+ return styles;
36
47
  }
37
48
  static get observedAttributes() {
38
49
  return [];
@@ -40,26 +51,40 @@ class w extends g {
40
51
  setupAttributes() {
41
52
  this.isShadowRoot = "open";
42
53
  }
43
- beforeDraw(t, s, e) {
44
- this.iterate = this.querySelector("[iterate]"), this.infiniteScrollTemplate = this.iterate.outerHTML, this.iterate.remove(), this.setAttribute("style", "height: " + this.height);
54
+ beforeDraw(context, store, params) {
55
+ this.iterate = this.querySelector("[iterate]");
56
+ this.infiniteScrollTemplate = this.iterate.outerHTML;
57
+ this.iterate.remove();
58
+ this.setAttribute("style", "height: " + this.height);
45
59
  }
46
- draw(t, s, e) {
47
- let i = document.createDocumentFragment(), a = document.createElement("slot"), o = document.createElement("div");
48
- return o.classList.add("loader"), i.appendChild(o), i.appendChild(a), this.loaderEl = o, i;
60
+ draw(context, store, params) {
61
+ let fragment = document.createDocumentFragment();
62
+ let slot = document.createElement("slot");
63
+ let loader = document.createElement("div");
64
+ loader.classList.add("loader");
65
+ fragment.appendChild(loader);
66
+ fragment.appendChild(slot);
67
+ this.loaderEl = loader;
68
+ return fragment;
49
69
  }
50
70
  async afterDraw() {
51
- this.queryParams = this.queryParams || "", this.size = +this.size || 10, this.currentPage = 0, this.scrollEvent(), await this.loadPages(this.currentPage);
71
+ this.queryParams = this.queryParams || "";
72
+ this.size = +this.size || 10;
73
+ this.currentPage = 0;
74
+ this.scrollEvent();
75
+ await this.loadPages(this.currentPage);
52
76
  }
53
77
  /** @function getPages
54
78
  * @description nacitanie dalsej stranky
55
79
  * @return response json
56
80
  */
57
- async getPages(t) {
58
- let s = this.url.includes("?");
59
- const e = await fetch(`${this.url}${s ? "&" : "?"}page=${t}&size=${this.size}${this == null ? void 0 : this.queryParams}`);
60
- if (!e.ok)
61
- throw new Error(`An error occurred: ${e.status}`);
62
- return await e.json();
81
+ async getPages(page) {
82
+ let hasParams = this.url.includes("?");
83
+ const response = await fetch(`${this.url}${hasParams ? "&" : "?"}page=${page}&size=${this.size}${this == null ? void 0 : this.queryParams}`);
84
+ if (!response.ok) {
85
+ throw new Error(`An error occurred: ${response.status}`);
86
+ }
87
+ return await response.json();
63
88
  }
64
89
  hideLoader() {
65
90
  this.loaderEl.classList.remove("show");
@@ -67,34 +92,47 @@ class w extends g {
67
92
  showLoader() {
68
93
  this.loaderEl.classList.add("show");
69
94
  }
70
- hasMorePages(t) {
71
- return this.totalPages === 0 || t <= this.totalPages;
95
+ hasMorePages(page) {
96
+ return this.totalPages === 0 || page <= this.totalPages;
72
97
  }
73
98
  /** @function getPages
74
99
  * @description methoda zavola getPages a nasledne sa vykona callback funkcia draw. Ako a kde sa nieco vykresli sa deje v inicializacii lib-ky
75
100
  * @return response json
76
101
  */
77
- async loadPages(t) {
102
+ async loadPages(page) {
78
103
  this.showLoader();
79
104
  try {
80
- if (this.hasMorePages(t) || typeof this.setCustomData == "function") {
81
- let s, e;
82
- typeof this.setCustomData == "function" ? e = await this.setCustomData(t) : e = await this.getPages(t), this.totalPages = e.totalPages, this.currentPage = t;
83
- const i = new DOMParser();
84
- let a = this;
85
- this.hasAttribute("placement") && (a = this.querySelector(this.placement)), e.data.forEach((o) => {
86
- const n = this.infiniteScrollTemplate.interpolate(o), d = i.parseFromString(n, "text/html").querySelector(this.iterate.tagName.toLowerCase());
87
- p.addListener(d, "click", "wj-infinite-scroll:click-item", null, { stopPropagation: !0 }), a.insertAdjacentElement("beforeend", d);
88
- }), this.isLoading.push(t);
105
+ if (this.hasMorePages(page) || typeof this.setCustomData === "function") {
106
+ let result;
107
+ let response;
108
+ if (typeof this.setCustomData === "function") {
109
+ response = await this.setCustomData(page);
110
+ } else {
111
+ response = await this.getPages(page);
112
+ }
113
+ this.totalPages = response.totalPages;
114
+ this.currentPage = page;
115
+ const parser = new DOMParser();
116
+ let placement = this;
117
+ if (this.hasAttribute("placement"))
118
+ placement = this.querySelector(this.placement);
119
+ response.data.forEach((item) => {
120
+ const interpolateItem = this.infiniteScrollTemplate.interpolate(item);
121
+ const doc = parser.parseFromString(interpolateItem, "text/html");
122
+ const element = doc.querySelector(this.iterate.tagName.toLowerCase());
123
+ event.addListener(element, "click", "wj-infinite-scroll:click-item", null, { stopPropagation: true });
124
+ placement.insertAdjacentElement("beforeend", element);
125
+ });
126
+ this.isLoading.push(page);
89
127
  }
90
- } catch (s) {
91
- console.log(s.message);
128
+ } catch (error) {
129
+ console.log(error.message);
92
130
  } finally {
93
131
  this.hideLoader();
94
132
  }
95
133
  }
96
134
  }
97
- customElements.get("wj-infinite-scroll") || window.customElements.define("wj-infinite-scroll", w);
135
+ customElements.get("wj-infinite-scroll") || window.customElements.define("wj-infinite-scroll", InfiniteScroll);
98
136
  export {
99
- w as InfiniteScroll
137
+ InfiniteScroll
100
138
  };