wj-elements 0.1.180 → 0.1.182
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/{wje-fetchAndParseCSS.js → animations.js} +1 -1
- package/dist/animations.js.map +1 -0
- package/dist/date.js +43 -0
- package/dist/date.js.map +1 -0
- package/dist/element-utils.js +95 -0
- package/dist/element-utils.js.map +1 -0
- package/dist/event.js +191 -0
- package/dist/event.js.map +1 -0
- package/dist/icon-DY5AZ6xM.js +211 -0
- package/dist/icon-DY5AZ6xM.js.map +1 -0
- package/dist/light.css +9 -1
- package/dist/packages/index.d.ts +5 -4
- package/dist/packages/utils/date.d.ts +1 -0
- package/dist/packages/utils/icon-library.d.ts +3 -0
- package/dist/packages/wje-button-group/button-group.element.d.ts +57 -0
- package/dist/packages/wje-element/element.d.ts +1 -1
- package/dist/packages/wje-options/options.element.d.ts +2 -2
- package/dist/packages/wje-select/select.element.d.ts +2 -0
- package/dist/permissions.js +56 -0
- package/dist/permissions.js.map +1 -0
- package/dist/{popup.element-AaduHP2r.js → popup.element-Di4nHYij.js} +3 -2
- package/dist/{popup.element-AaduHP2r.js.map → popup.element-Di4nHYij.js.map} +1 -1
- package/dist/universal-service.js +117 -0
- package/dist/universal-service.js.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/utils.js.map +1 -0
- package/dist/wje-accordion-item.js +2 -1
- package/dist/wje-accordion-item.js.map +1 -1
- package/dist/wje-animation.js +1 -1
- package/dist/wje-breadcrumb.js +3 -1
- package/dist/wje-breadcrumb.js.map +1 -1
- package/dist/wje-button-group.js +105 -8
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +7 -7
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-carousel-item.js +2 -1
- package/dist/wje-carousel-item.js.map +1 -1
- package/dist/wje-checkbox.js +2 -1
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +3 -1
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-color-picker.js +2 -1
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-copy-button.js +3 -1
- package/dist/wje-copy-button.js.map +1 -1
- package/dist/wje-dialog.js +2 -1
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-dropdown.js +3 -2
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +5 -431
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-file-upload-item.js +1 -1
- package/dist/wje-icon-picker.js +5 -5
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-icon.js +2 -189
- package/dist/wje-icon.js.map +1 -1
- package/dist/wje-img-comparer.js +1 -1
- package/dist/wje-infinite-scroll.js +380 -1
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input-file.js +2 -1
- package/dist/wje-input-file.js.map +1 -1
- package/dist/wje-input.js +2 -1
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-list.js +46 -1
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-master.js +119 -142
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-menu-button.js +2 -1
- package/dist/wje-menu-button.js.map +1 -1
- package/dist/wje-menu-item.js +3 -1
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-menu-label.js +2 -1
- package/dist/wje-menu-label.js.map +1 -1
- package/dist/wje-option.js +4 -2
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +4 -3
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-orgchart-group.js +2 -1
- package/dist/wje-orgchart-group.js.map +1 -1
- package/dist/wje-pagination.js +3 -2
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +1 -1
- package/dist/wje-radio.js +2 -1
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-reorder-item.js +2 -1
- package/dist/wje-reorder-item.js.map +1 -1
- package/dist/wje-select.js +12 -4
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-slider.js +2 -1
- package/dist/wje-slider.js.map +1 -1
- package/dist/wje-stepper.js +2 -1
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-tab.js +2 -1
- package/dist/wje-tab.js.map +1 -1
- package/dist/wje-textarea.js +2 -1
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-toast.js +3 -1
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-toggle.js +2 -1
- package/dist/wje-toggle.js.map +1 -1
- package/dist/wje-tooltip.js +3 -2
- package/dist/wje-tooltip.js.map +1 -1
- package/package.json +1 -1
- package/dist/infinite-scroll.element-CasKXuGZ.js +0 -382
- package/dist/infinite-scroll.element-CasKXuGZ.js.map +0 -1
- package/dist/list.element-D4-wlFN_.js +0 -50
- package/dist/list.element-D4-wlFN_.js.map +0 -1
- package/dist/wje-fetchAndParseCSS.js.map +0 -1
- /package/dist/packages/{wje-element/service → utils}/universal-service.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animations.js","sources":["../packages/utils/animations.js"],"sourcesContent":["let animations = [];\n\nfunction parseCSS(css) {\n const keyframesRegex = /@keyframes\\s+([\\w-]+)\\s*{([\\s\\S]+?})\\s*}/g;\n let match;\n let localAnimations = [];\n\n while ((match = keyframesRegex.exec(css)) !== null) {\n let name = match[1];\n let frames = match[2].trim();\n let keyframes = parseKeyframes(frames);\n\n localAnimations.push({ name, keyframes });\n }\n\n return localAnimations;\n}\n\nfunction parseKeyframes(frames) {\n const frameRegex = /([\\d%]+)\\s*{([\\s\\S]+?)}/g;\n let match;\n let keyframes = [];\n\n while ((match = frameRegex.exec(frames)) !== null) {\n let offset = parseFloat(match[1]) / 100; // Prevedenie percent na desatinné číslo\n let properties = parseProperties(match[2]);\n\n // Preformátovanie vlastností na požadovaný formát\n let keyframeObject = {\n offset: offset,\n ...properties,\n };\n\n keyframes.push(keyframeObject);\n }\n\n // Zoradenie keyframes podľa offsetu\n keyframes.sort((a, b) => a.offset - b.offset);\n\n return keyframes;\n}\n\nfunction parseProperties(propertiesString) {\n const properties = {};\n propertiesString.split(';').forEach((property) => {\n const [key, value] = property.split(':').map((part) => part.trim());\n if (key && value) {\n // Mapovanie názvov vlastností na požadované kľúčové slová\n if (key === 'animation-timing-function') {\n properties['easing'] = value;\n } else {\n properties[key] = value;\n }\n }\n });\n return properties;\n}\n\nexport async function fetchAndParseCSS(css) {\n try {\n if (animations.length > 0) {\n return animations;\n }\n animations = parseCSS(css);\n\n return await animations;\n } catch (error) {\n console.error('Error:', error);\n return null;\n }\n}\n\nexport { animations };\n"],"names":[],"mappings":"AAAG,IAAC,aAAa,CAAA;AAEjB,SAAS,SAAS,KAAK;AACnB,QAAM,iBAAiB;AACvB,MAAI;AACJ,MAAI,kBAAkB,CAAE;AAExB,UAAQ,QAAQ,eAAe,KAAK,GAAG,OAAO,MAAM;AAChD,QAAI,OAAO,MAAM,CAAC;AAClB,QAAI,SAAS,MAAM,CAAC,EAAE,KAAM;AAC5B,QAAI,YAAY,eAAe,MAAM;AAErC,oBAAgB,KAAK,EAAE,MAAM,UAAS,CAAE;AAAA,EAChD;AAEI,SAAO;AACX;AAEA,SAAS,eAAe,QAAQ;AAC5B,QAAM,aAAa;AACnB,MAAI;AACJ,MAAI,YAAY,CAAE;AAElB,UAAQ,QAAQ,WAAW,KAAK,MAAM,OAAO,MAAM;AAC/C,QAAI,SAAS,WAAW,MAAM,CAAC,CAAC,IAAI;AACpC,QAAI,aAAa,gBAAgB,MAAM,CAAC,CAAC;AAGzC,QAAI,iBAAiB;AAAA,MACjB;AAAA,MACA,GAAG;AAAA,IACN;AAED,cAAU,KAAK,cAAc;AAAA,EACrC;AAGI,YAAU,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM;AAE5C,SAAO;AACX;AAEA,SAAS,gBAAgB,kBAAkB;AACvC,QAAM,aAAa,CAAE;AACrB,mBAAiB,MAAM,GAAG,EAAE,QAAQ,CAAC,aAAa;AAC9C,UAAM,CAAC,KAAK,KAAK,IAAI,SAAS,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAI,CAAE;AAClE,QAAI,OAAO,OAAO;AAEd,UAAI,QAAQ,6BAA6B;AACrC,mBAAW,QAAQ,IAAI;AAAA,MACvC,OAAmB;AACH,mBAAW,GAAG,IAAI;AAAA,MAClC;AAAA,IACA;AAAA,EACA,CAAK;AACD,SAAO;AACX;AAEO,eAAe,iBAAiB,KAAK;AACxC,MAAI;AACA,QAAI,WAAW,SAAS,GAAG;AACvB,aAAO;AAAA,IACnB;AACQ,iBAAa,SAAS,GAAG;AAEzB,WAAO,MAAM;AAAA,EAChB,SAAQ,OAAO;AACZ,YAAQ,MAAM,UAAU,KAAK;AAC7B,WAAO;AAAA,EACf;AACA;"}
|
package/dist/date.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function formatDate(input, format) {
|
|
2
|
+
let date;
|
|
3
|
+
if (typeof input === "string") {
|
|
4
|
+
date = new Date(input);
|
|
5
|
+
} else if (typeof input === "number") {
|
|
6
|
+
date = new Date(input);
|
|
7
|
+
} else if (input instanceof Date) {
|
|
8
|
+
date = input;
|
|
9
|
+
} else {
|
|
10
|
+
throw new Error("Invalid date input");
|
|
11
|
+
}
|
|
12
|
+
const map = {
|
|
13
|
+
yyyy: date.getFullYear(),
|
|
14
|
+
MM: String(date.getMonth() + 1).padStart(2, "0"),
|
|
15
|
+
// Mesiace sú indexované od 0
|
|
16
|
+
dd: String(date.getDate()).padStart(2, "0"),
|
|
17
|
+
HH: String(date.getHours()).padStart(2, "0"),
|
|
18
|
+
mm: String(date.getMinutes()).padStart(2, "0"),
|
|
19
|
+
ss: String(date.getSeconds()).padStart(2, "0"),
|
|
20
|
+
MMMM: date.toLocaleString("en-US", { month: "long" }),
|
|
21
|
+
// Full month name
|
|
22
|
+
MMM: date.toLocaleString("en-US", { month: "short" })
|
|
23
|
+
// Short month name
|
|
24
|
+
};
|
|
25
|
+
return format.replace(/yyyy|MM|dd|HH|mm|ss|MMMM|MMM/g, (matched) => map[matched]);
|
|
26
|
+
}
|
|
27
|
+
function toSafeDate(iso) {
|
|
28
|
+
const timeOnlyRegex = /^\d{2}:\d{2}(?::\d{2}(?:\.\d{3})?)?(Z)?$/;
|
|
29
|
+
if (timeOnlyRegex.test(iso)) {
|
|
30
|
+
let cleanTime = iso.replace(/Z$/, "");
|
|
31
|
+
let [h, m, s = "00.000"] = cleanTime.split(":");
|
|
32
|
+
if (!s.includes(".")) {
|
|
33
|
+
s = `${s}.000`;
|
|
34
|
+
}
|
|
35
|
+
return `1970-01-01T${h}:${m}:${s}Z`;
|
|
36
|
+
}
|
|
37
|
+
return iso;
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
formatDate,
|
|
41
|
+
toSafeDate
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=date.js.map
|
package/dist/date.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sources":["../packages/utils/date.js"],"sourcesContent":["export function formatDate(input, format) {\n let date;\n\n // Rozpoznanie typu vstupu a jeho konverzia na objekt Date\n if (typeof input === 'string') {\n date = new Date(input); // Predpokladáme, že je to ISO reťazec\n } else if (typeof input === 'number') {\n date = new Date(input); // Predpokladáme, že je to timestamp\n } else if (input instanceof Date) {\n date = input; // Je to objekt Date\n } else {\n throw new Error('Invalid date input');\n }\n\n const map = {\n yyyy: date.getFullYear(),\n MM: String(date.getMonth() + 1).padStart(2, '0'), // Mesiace sú indexované od 0\n dd: String(date.getDate()).padStart(2, '0'),\n HH: String(date.getHours()).padStart(2, '0'),\n mm: String(date.getMinutes()).padStart(2, '0'),\n ss: String(date.getSeconds()).padStart(2, '0'),\n MMMM: date.toLocaleString('en-US', { month: 'long' }), // Full month name\n MMM: date.toLocaleString('en-US', { month: 'short' }), // Short month name\n };\n\n return format.replace(/yyyy|MM|dd|HH|mm|ss|MMMM|MMM/g, (matched) => map[matched]);\n}\n\nexport function toSafeDate(iso) {\n // Match 07:00, 07:00:00, 07:00:00.000, 07:00:00.000Z\n const timeOnlyRegex = /^\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{3})?)?(Z)?$/;\n\n if (timeOnlyRegex.test(iso)) {\n let cleanTime = iso.replace(/Z$/, ''); // Remove Z if present\n let [h, m, s = '00.000'] = cleanTime.split(':');\n\n // Ensure seconds and milliseconds\n if (!s.includes('.')) {\n s = `${s}.000`;\n }\n\n return `1970-01-01T${h}:${m}:${s}Z`;\n }\n\n return iso;\n}\n"],"names":[],"mappings":"AAAO,SAAS,WAAW,OAAO,QAAQ;AACtC,MAAI;AAGJ,MAAI,OAAO,UAAU,UAAU;AAC3B,WAAO,IAAI,KAAK,KAAK;AAAA,EAC7B,WAAe,OAAO,UAAU,UAAU;AAClC,WAAO,IAAI,KAAK,KAAK;AAAA,EAC7B,WAAe,iBAAiB,MAAM;AAC9B,WAAO;AAAA,EACf,OAAW;AACH,UAAM,IAAI,MAAM,oBAAoB;AAAA,EAC5C;AAEI,QAAM,MAAM;AAAA,IACR,MAAM,KAAK,YAAa;AAAA,IACxB,IAAI,OAAO,KAAK,SAAQ,IAAK,CAAC,EAAE,SAAS,GAAG,GAAG;AAAA;AAAA,IAC/C,IAAI,OAAO,KAAK,QAAS,CAAA,EAAE,SAAS,GAAG,GAAG;AAAA,IAC1C,IAAI,OAAO,KAAK,SAAU,CAAA,EAAE,SAAS,GAAG,GAAG;AAAA,IAC3C,IAAI,OAAO,KAAK,WAAY,CAAA,EAAE,SAAS,GAAG,GAAG;AAAA,IAC7C,IAAI,OAAO,KAAK,WAAY,CAAA,EAAE,SAAS,GAAG,GAAG;AAAA,IAC7C,MAAM,KAAK,eAAe,SAAS,EAAE,OAAO,QAAQ;AAAA;AAAA,IACpD,KAAK,KAAK,eAAe,SAAS,EAAE,OAAO,SAAS;AAAA;AAAA,EACvD;AAED,SAAO,OAAO,QAAQ,iCAAiC,CAAC,YAAY,IAAI,OAAO,CAAC;AACpF;AAEO,SAAS,WAAW,KAAK;AAE5B,QAAM,gBAAgB;AAEtB,MAAI,cAAc,KAAK,GAAG,GAAG;AACzB,QAAI,YAAY,IAAI,QAAQ,MAAM,EAAE;AACpC,QAAI,CAAC,GAAG,GAAG,IAAI,QAAQ,IAAI,UAAU,MAAM,GAAG;AAG9C,QAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AAClB,UAAI,GAAG,CAAC;AAAA,IACpB;AAEQ,WAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;AAAA,EACxC;AAEI,SAAO;AACX;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
class WjElementUtils {
|
|
2
|
+
/**
|
|
3
|
+
* This function creates an element.
|
|
4
|
+
* @param element : HTMLElement - The element value.
|
|
5
|
+
* @param object : Object - The object value.
|
|
6
|
+
*/
|
|
7
|
+
static setAttributesToElement(element, object) {
|
|
8
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
9
|
+
element.setAttribute(key, value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This function gets the attributes from an element.
|
|
14
|
+
* @param {string|HTMLElement} el The element or selector to retrieve attributes from.
|
|
15
|
+
* @returns {object} - An object containing the element's attributes as key-value pairs.
|
|
16
|
+
*/
|
|
17
|
+
static getAttributes(el) {
|
|
18
|
+
if (typeof el === "string") el = document.querySelector(el);
|
|
19
|
+
return Array.from(el.attributes).filter((a) => !a.name.startsWith("@")).map((a) => [
|
|
20
|
+
a.name.split("-").map((s, i) => {
|
|
21
|
+
if (i !== 0) {
|
|
22
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
23
|
+
} else {
|
|
24
|
+
return s;
|
|
25
|
+
}
|
|
26
|
+
}).join(""),
|
|
27
|
+
a.value
|
|
28
|
+
]).reduce((acc, attr) => {
|
|
29
|
+
acc[attr[0]] = attr[1];
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* This function gets the events from an element.
|
|
35
|
+
* @param {string|HTMLElement} el The element or selector to retrieve events from.
|
|
36
|
+
* @returns {Map<any, any>} - The map value.
|
|
37
|
+
*/
|
|
38
|
+
static getEvents(el) {
|
|
39
|
+
if (typeof el === "string") el = document.querySelector(el);
|
|
40
|
+
return Array.from(el.attributes).filter((a) => a.name.startsWith("@wje")).map((a) => [a.name.substring(3).split("-").join(""), a.value]).reduce((acc, attr) => {
|
|
41
|
+
acc.set(attr[0], attr[1]);
|
|
42
|
+
return acc;
|
|
43
|
+
}, /* @__PURE__ */ new Map());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* This function converts an object to a string.
|
|
47
|
+
* @param {object} object The object to convert.
|
|
48
|
+
* @returns {string} - The string value.
|
|
49
|
+
*/
|
|
50
|
+
static attributesToString(object) {
|
|
51
|
+
return Object.entries(object).map(([key, value]) => {
|
|
52
|
+
return `${key}="${value}"`;
|
|
53
|
+
}).join(" ");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* This function checks if the slot exists.
|
|
57
|
+
* @param {string|HTMLElement} el The element or selector to check for slots.
|
|
58
|
+
* @param slotName The slot name to check for.
|
|
59
|
+
* @returns {boolean} - The boolean value.
|
|
60
|
+
*/
|
|
61
|
+
static hasSlot(el, slotName = null) {
|
|
62
|
+
let selector = slotName ? `[slot="${slotName}"]` : "[slot]";
|
|
63
|
+
return el.querySelectorAll(selector).length > 0 ? true : false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* This function checks if the slot has content.
|
|
67
|
+
* @param {string|HTMLElement} el The element or selector to check for slot content
|
|
68
|
+
* @param slotName The slot name to check for.
|
|
69
|
+
* @returns {boolean} - The boolean value.
|
|
70
|
+
*/
|
|
71
|
+
static hasSlotContent(el, slotName = null) {
|
|
72
|
+
let slotElement = el.querySelector(`slot`);
|
|
73
|
+
if (slotName) {
|
|
74
|
+
slotElement = el.querySelector(`slot[name="${slotName}"]`);
|
|
75
|
+
}
|
|
76
|
+
if (slotElement) {
|
|
77
|
+
const assignedElements = slotElement.assignedElements();
|
|
78
|
+
return assignedElements.length > 0;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* This function converts a string to a boolean.
|
|
84
|
+
* @param {string | object} value The value to convert to a boolean. If the value is a boolean, it will be returned as is.
|
|
85
|
+
* @returns {boolean} - The boolean value.
|
|
86
|
+
*/
|
|
87
|
+
static stringToBoolean(value) {
|
|
88
|
+
if (typeof value === "boolean") return value;
|
|
89
|
+
return !["false", "0", 0].includes(value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
WjElementUtils
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=element-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-utils.js","sources":["../packages/utils/element-utils.js"],"sourcesContent":["export class WjElementUtils {\n /**\n * This function creates an element.\n * @param element : HTMLElement - The element value.\n * @param object : Object - The object value.\n */\n static setAttributesToElement(element, object) {\n Object.entries(object).forEach(([key, value]) => {\n element.setAttribute(key, value);\n });\n }\n\n /**\n * This function gets the attributes from an element.\n * @param {string|HTMLElement} el The element or selector to retrieve attributes from.\n * @returns {object} - An object containing the element's attributes as key-value pairs.\n */\n static getAttributes(el) {\n if (typeof el === 'string') el = document.querySelector(el);\n\n return Array.from(el.attributes)\n .filter((a) => !a.name.startsWith('@'))\n .map((a) => [\n a.name\n .split('-')\n .map((s, i) => {\n if (i !== 0) {\n return s.charAt(0).toUpperCase() + s.slice(1);\n } else {\n return s;\n }\n })\n .join(''),\n a.value,\n ])\n .reduce((acc, attr) => {\n acc[attr[0]] = attr[1];\n return acc;\n }, {});\n }\n\n /**\n * This function gets the events from an element.\n * @param {string|HTMLElement} el The element or selector to retrieve events from.\n * @returns {Map<any, any>} - The map value.\n */\n static getEvents(el) {\n if (typeof el === 'string') el = document.querySelector(el);\n\n return Array.from(el.attributes)\n .filter((a) => a.name.startsWith('@wje'))\n .map((a) => [a.name.substring(3).split('-').join(''), a.value])\n .reduce((acc, attr) => {\n acc.set(attr[0], attr[1]);\n return acc;\n }, new Map());\n }\n\n /**\n * This function converts an object to a string.\n * @param {object} object The object to convert.\n * @returns {string} - The string value.\n */\n static attributesToString(object) {\n return Object.entries(object)\n .map(([key, value]) => {\n return `${key}=\"${value}\"`;\n })\n .join(' ');\n }\n\n /**\n * This function checks if the slot exists.\n * @param {string|HTMLElement} el The element or selector to check for slots.\n * @param slotName The slot name to check for.\n * @returns {boolean} - The boolean value.\n */\n static hasSlot(el, slotName = null) {\n let selector = slotName ? `[slot=\"${slotName}\"]` : '[slot]';\n\n return el.querySelectorAll(selector).length > 0 ? true : false;\n }\n\n /**\n * This function checks if the slot has content.\n * @param {string|HTMLElement} el The element or selector to check for slot content\n * @param slotName The slot name to check for.\n * @returns {boolean} - The boolean value.\n */\n static hasSlotContent(el, slotName = null) {\n let slotElement = el.querySelector(`slot`);\n if (slotName) {\n slotElement = el.querySelector(`slot[name=\"${slotName}\"]`);\n }\n\n if (slotElement) {\n const assignedElements = slotElement.assignedElements();\n return assignedElements.length > 0;\n }\n\n return false;\n }\n\n /**\n * This function converts a string to a boolean.\n * @param {string | object} value The value to convert to a boolean. If the value is a boolean, it will be returned as is.\n * @returns {boolean} - The boolean value.\n */\n static stringToBoolean(value) {\n if (typeof value === 'boolean') return value;\n\n return !['false', '0', 0].includes(value);\n }\n}\n"],"names":[],"mappings":"AAAO,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,OAAO,uBAAuB,SAAS,QAAQ;AAC3C,WAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC7C,cAAQ,aAAa,KAAK,KAAK;AAAA,IAC3C,CAAS;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,OAAO,cAAc,IAAI;AACrB,QAAI,OAAO,OAAO,SAAU,MAAK,SAAS,cAAc,EAAE;A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AAA;AAAA,EAQI,OAAO,QAAQ,IAAI,WAAW,MAAM;AAChC,QAAI,WAAW,WAAW,UAAU,QAAQ,OAAO;AAEnD,WAAO,GAAG,iBAAiB,QAAQ,EAAE,SAAS,IAAI,OAAO;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,OAAO,eAAe,IAAI,WAAW,MAAM;AACvC,QAAI,cAAc,GAAG,cAAc,MAAM;AACzC,QAAI,UAAU;AACV,oBAAc,GAAG,cAAc,cAAc,QAAQ,IAAI;AAAA,IACrE;AAEQ,QAAI,aAAa;AACb,YAAM,mBAAmB,YAAY,iBAAkB;AACvD,aAAO,iBAAiB,SAAS;AAAA,IAC7C;AAEQ,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,OAAO,gBAAgB,OAAO;AAC1B,QAAI,OAAO,UAAU,UAAW,QAAO;AAEvC,WAAO,CAAC,CAAC,SAAS,KAAK,CAAC,EAAE,SAAS,KAAK;AAAA,EAChD;AACA;"}
|
package/dist/event.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
6
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
7
|
+
var _Event_instances, dispatch_fn;
|
|
8
|
+
var self;
|
|
9
|
+
class Event {
|
|
10
|
+
constructor() {
|
|
11
|
+
__privateAdd(this, _Event_instances);
|
|
12
|
+
this.customEventWeakMap = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
self = this;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Dispatch custom event to the element with the specified event name and detail.
|
|
17
|
+
* @param element
|
|
18
|
+
* @param event
|
|
19
|
+
* @param detail
|
|
20
|
+
*/
|
|
21
|
+
dispatchCustomEvent(element, event2, detail) {
|
|
22
|
+
element.dispatchEvent(
|
|
23
|
+
new CustomEvent(event2, {
|
|
24
|
+
detail: detail || {
|
|
25
|
+
context: element,
|
|
26
|
+
event: self
|
|
27
|
+
},
|
|
28
|
+
bubbles: true,
|
|
29
|
+
composed: true,
|
|
30
|
+
cancelable: true
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Find record by element in the storage.
|
|
36
|
+
* @param element
|
|
37
|
+
* @returns {*}
|
|
38
|
+
*/
|
|
39
|
+
findRecordByElement(element) {
|
|
40
|
+
return this.customEventWeakMap.get(element);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Add listener to the element. If the element is an array, the listener will be added to all elements in the array.
|
|
44
|
+
* @param element
|
|
45
|
+
* @param originalEvent
|
|
46
|
+
* @param event
|
|
47
|
+
* @param listener
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
50
|
+
addListener(element, originalEvent, event2, listener, options) {
|
|
51
|
+
if (!element) return;
|
|
52
|
+
if (!Array.isArray(element)) element = [element];
|
|
53
|
+
element.forEach((el) => {
|
|
54
|
+
this.writeRecord(el, originalEvent, event2, listener, options);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Write record to the storage.
|
|
59
|
+
* @param element
|
|
60
|
+
* @param originalEvent
|
|
61
|
+
* @param event
|
|
62
|
+
* @param listener
|
|
63
|
+
* @param options
|
|
64
|
+
*/
|
|
65
|
+
writeRecord(element, originalEvent, event2, listener, options) {
|
|
66
|
+
let recordListeners = this.findRecordByElement(element);
|
|
67
|
+
if (!recordListeners) {
|
|
68
|
+
this.customEventWeakMap.set(element, {
|
|
69
|
+
[originalEvent]: []
|
|
70
|
+
});
|
|
71
|
+
recordListeners = this.findRecordByElement(element);
|
|
72
|
+
} else {
|
|
73
|
+
recordListeners[originalEvent] = recordListeners[originalEvent] || [];
|
|
74
|
+
}
|
|
75
|
+
listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
|
|
76
|
+
let obj = {
|
|
77
|
+
listener,
|
|
78
|
+
options,
|
|
79
|
+
event: event2
|
|
80
|
+
};
|
|
81
|
+
if (!this.isRecordExists(recordListeners[originalEvent], obj)) {
|
|
82
|
+
if (!this.listenerExists(recordListeners[originalEvent], obj)) {
|
|
83
|
+
element.addEventListener(originalEvent, listener, options);
|
|
84
|
+
obj.unbind = () => {
|
|
85
|
+
element.removeEventListener(originalEvent, listener, options);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
recordListeners[originalEvent].push(obj);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Performs a deep equality check between two objects.
|
|
93
|
+
* @param x The first object to compare.
|
|
94
|
+
* @param y The second object to compare.
|
|
95
|
+
* @returns - Returns `true` if the objects are deeply equal, `false` otherwise.
|
|
96
|
+
*/
|
|
97
|
+
deepEqual(x, y) {
|
|
98
|
+
return x && y && typeof x === "object" && typeof x === typeof y ? Object.keys(x).length === Object.keys(y).length && Object.keys(x).every((key) => this.deepEqual(x[key], y[key])) : x === y;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if the listener already exists on the element.
|
|
102
|
+
* @param records
|
|
103
|
+
* @param eventObj
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
listenerExists(records, eventObj) {
|
|
107
|
+
return records.some((e) => e.listener === eventObj.listener);
|
|
108
|
+
}
|
|
109
|
+
isRecordExists(records, eventObj) {
|
|
110
|
+
return records.some((e) => this.deepEqual(e, eventObj));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Remove listener from the element and delete the listener from the custom event storage.
|
|
114
|
+
* @param element
|
|
115
|
+
* @param originalEvent
|
|
116
|
+
* @param event
|
|
117
|
+
* @param listener
|
|
118
|
+
* @param options
|
|
119
|
+
*/
|
|
120
|
+
removeListener(element, originalEvent, event2, listener, options) {
|
|
121
|
+
let records = this.findRecordByElement(element);
|
|
122
|
+
let listeners = records == null ? void 0 : records[originalEvent];
|
|
123
|
+
listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
|
|
124
|
+
if (listeners) {
|
|
125
|
+
let listenerOfWeakMap = listeners.find((e) => e.listener === listener);
|
|
126
|
+
if (listenerOfWeakMap) {
|
|
127
|
+
listeners.splice(listeners.indexOf(listenerOfWeakMap), 1);
|
|
128
|
+
}
|
|
129
|
+
if (!listeners.length) {
|
|
130
|
+
delete records[originalEvent];
|
|
131
|
+
element == null ? void 0 : element.removeEventListener(originalEvent, listener, options);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Remove all event listeners from the specified element and delete the element from the custom event storage.
|
|
137
|
+
* @param {HTMLElement} element The element from which all listeners will be removed.
|
|
138
|
+
*/
|
|
139
|
+
removeElement(element) {
|
|
140
|
+
let listeners = this.customEventWeakMap.get(element);
|
|
141
|
+
if (listeners) {
|
|
142
|
+
queueMicrotask(() => {
|
|
143
|
+
for (let event2 in listeners) {
|
|
144
|
+
listeners[event2].forEach((e) => {
|
|
145
|
+
element.removeEventListener(event2, e.listener, e.options);
|
|
146
|
+
e.unbind();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
this.customEventWeakMap.delete(element);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// TODO
|
|
154
|
+
createPromiseFromEvent(element, event2) {
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
let success = () => {
|
|
157
|
+
element.removeEventListener(event2, success);
|
|
158
|
+
resolve();
|
|
159
|
+
};
|
|
160
|
+
element.addEventListener(event2, success);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_Event_instances = new WeakSet();
|
|
165
|
+
/**
|
|
166
|
+
* Dispatch event to the element and trigger the listener.
|
|
167
|
+
* @param e
|
|
168
|
+
*/
|
|
169
|
+
dispatch_fn = function(e) {
|
|
170
|
+
let element = this;
|
|
171
|
+
let record = self.customEventWeakMap.get(this);
|
|
172
|
+
if (!record) return;
|
|
173
|
+
let listeners = record[e.type];
|
|
174
|
+
listeners.forEach((listener) => {
|
|
175
|
+
self.dispatchCustomEvent(element, listener.event, {
|
|
176
|
+
originalEvent: (e == null ? void 0 : e.type) || null,
|
|
177
|
+
context: element,
|
|
178
|
+
event: self
|
|
179
|
+
});
|
|
180
|
+
if (listener.options && listener.options.stopPropagation === true) {
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
e.stopImmediatePropagation();
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
let event = new Event();
|
|
188
|
+
export {
|
|
189
|
+
event
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sources":["../packages/utils/event.js"],"sourcesContent":["var self; // eslint-disable-line no-var\n\nclass Event {\n constructor() {\n this.customEventWeakMap = new WeakMap();\n self = this;\n }\n\n /**\n * Dispatch event to the element and trigger the listener.\n * @param e\n */\n #dispatch(e) {\n let element = this;\n // let record = self.findRecordByElement(element);\n let record = self.customEventWeakMap.get(this);\n\n if (!record) return;\n\n let listeners = record[e.type];\n\n listeners.forEach((listener) => {\n self.dispatchCustomEvent(element, listener.event, {\n originalEvent: e?.type || null,\n context: element,\n event: self,\n });\n\n if (listener.options && listener.options.stopPropagation === true) {\n e.stopPropagation();\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n });\n }\n\n /**\n * Dispatch custom event to the element with the specified event name and detail.\n * @param element\n * @param event\n * @param detail\n */\n dispatchCustomEvent(element, event, detail) {\n element.dispatchEvent(\n new CustomEvent(event, {\n detail: detail || {\n context: element,\n event: self,\n },\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n /**\n * Find record by element in the storage.\n * @param element\n * @returns {*}\n */\n\n findRecordByElement(element) {\n return this.customEventWeakMap.get(element);\n }\n\n /**\n * Add listener to the element. If the element is an array, the listener will be added to all elements in the array.\n * @param element\n * @param originalEvent\n * @param event\n * @param listener\n * @param options\n */\n addListener(element, originalEvent, event, listener, options) {\n if (!element) return;\n\n if (!Array.isArray(element)) element = [element];\n\n element.forEach((el) => {\n this.writeRecord(el, originalEvent, event, listener, options);\n });\n }\n\n /**\n * Write record to the storage.\n * @param element\n * @param originalEvent\n * @param event\n * @param listener\n * @param options\n */\n writeRecord(element, originalEvent, event, listener, options) {\n let recordListeners = this.findRecordByElement(element);\n\n if (!recordListeners) {\n this.customEventWeakMap.set(element, {\n [originalEvent]: [],\n });\n\n recordListeners = this.findRecordByElement(element);\n } else {\n recordListeners[originalEvent] = recordListeners[originalEvent] || [];\n }\n\n listener = listener || this.#dispatch;\n let obj = {\n listener: listener,\n options: options,\n event: event,\n };\n\n // skontrolujeme ci uz tento listener neexistuje\n if (!this.isRecordExists(recordListeners[originalEvent], obj)) {\n if (!this.listenerExists(recordListeners[originalEvent], obj)) {\n element.addEventListener(originalEvent, listener, options);\n obj.unbind = () => {\n element.removeEventListener(originalEvent, listener, options);\n };\n }\n\n recordListeners[originalEvent].push(obj);\n\n } else {\n // in case we want to add the same listener multiple times trigger a warning for a better debugging\n //console.info(\"Listener already exists\", element, originalEvent);\n }\n }\n\n /**\n * Performs a deep equality check between two objects.\n * @param x The first object to compare.\n * @param y The second object to compare.\n * @returns - Returns `true` if the objects are deeply equal, `false` otherwise.\n */\n deepEqual(x, y) {\n return x && y && typeof x === 'object' && typeof x === typeof y\n ? Object.keys(x).length === Object.keys(y).length &&\n Object.keys(x).every((key) => this.deepEqual(x[key], y[key]))\n : x === y;\n }\n\n /**\n * Check if the listener already exists on the element.\n * @param records\n * @param eventObj\n * @returns\n */\n listenerExists(records, eventObj) {\n return records.some((e) => e.listener === eventObj.listener);\n }\n\n isRecordExists(records, eventObj) {\n return records.some((e) => this.deepEqual(e, eventObj))\n }\n\n /**\n * Remove listener from the element and delete the listener from the custom event storage.\n * @param element\n * @param originalEvent\n * @param event\n * @param listener\n * @param options\n */\n removeListener(element, originalEvent, event, listener, options) {\n let records = this.findRecordByElement(element);\n let listeners = records?.[originalEvent];\n listener = listener || this.#dispatch;\n\n if (listeners) {\n let listenerOfWeakMap = listeners.find((e) => e.listener === listener);\n\n if (listenerOfWeakMap) {\n listeners.splice(listeners.indexOf(listenerOfWeakMap), 1);\n }\n\n if (!listeners.length) {\n delete records[originalEvent];\n element?.removeEventListener(originalEvent, listener, options);\n }\n }\n }\n\n /**\n * Remove all event listeners from the specified element and delete the element from the custom event storage.\n * @param {HTMLElement} element The element from which all listeners will be removed.\n */\n removeElement(element) {\n // remove all listeners from the element\n let listeners = this.customEventWeakMap.get(element);\n if (listeners) {\n queueMicrotask(() => {\n for (let event in listeners) {\n listeners[event].forEach((e) => {\n element.removeEventListener(event, e.listener, e.options);\n e.unbind();\n });\n }\n\n this.customEventWeakMap.delete(element);\n });\n }\n }\n\n // TODO\n createPromiseFromEvent(element, event) {\n return new Promise((resolve) => {\n let success = () => {\n element.removeEventListener(event, success);\n resolve();\n };\n\n element.addEventListener(event, success);\n });\n }\n}\n\nlet event = new Event();\nexport { event };\n"],"names":["event"],"mappings":";;;;;;AAAA;AAAA,IAAI;AAEJ,MAAM,MAAM;AAAA,EACR,cAAc;AADlB;AAEQ,SAAK,qBAAqB,oBAAI,QAAS;AACvC,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCI,oBAAoB,SAASA,QAAO,QAAQ;AACxC,YAAQ;AAAA,MACJ,IAAI,YAAYA,QAAO;AAAA,QACnB,QAAQ,UAAU;AAAA,UACd,SAAS;AAAA,UACT,OAAO;AAAA,QACV;AAAA,QACD,SAAS;AAAA,QACT,UAAU;AA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AUA,MAAK,EAAE,QAAQ,CAAC,MAAM;AAC5B,oBAAQ,oBAAoBA,QAAO,EAAE,UAAU,EAAE,OAAO;AACxD,cAAE,OAAQ;AAAA,UAClC,CAAqB;AAAA,QACrB;AAEgB,aAAK,mBAAmB,OAAO,OAAO;AAAA,MACtD,CAAa;AAAA,IACb;AAAA,EACA;AAAA;AAAA,EAGI,uBAAuB,SAASA,QAAO;AACnC,WAAO,IAAI,QAAQ,CAAC,YAAY;AAC5B,UAAI,UAAU,MAAM;AAChB,gBAAQ,oBAAoBA,QAAO,OAAO;AAC1C,gBAAS;AAAA,MACZ;AAED,cAAQ,iBAAiBA,QAAO,OAAO;AAAA,IACnD,CAAS;AAAA,EACT;AACA;AArNA;AAAA;AAAA;AAAA;AAAA;AAUI,cAAS,SAAC,GAAG;AACT,MAAI,UAAU;AAEd,MAAI,SAAS,KAAK,mBAAmB,IAAI,IAAI;AAE7C,MAAI,CAAC,OAAQ;AAEb,MAAI,YAAY,OAAO,EAAE,IAAI;AAE7B,YAAU,QAAQ,CAAC,aAAa;AAC5B,SAAK,oBAAoB,SAAS,SAAS,OAAO;AAAA,MAC9C,gBAAe,uBAAG,SAAQ;AAAA,MAC1B,SAAS;AAAA,MACT,OAAO;AAAA,IACvB,CAAa;AAED,QAAI,SAAS,WAAW,SAAS,QAAQ,oBAAoB,MAAM;AAC/D,QAAE,gBAAiB;AACnB,QAAE,yBAA0B;AAC5B,QAAE,eAAgB;AAAA,IAClC;AAAA,EACA,CAAS;AACT;AAuLG,IAAC,QAAQ,IAAI,MAAK;"}
|
|
@@ -0,0 +1,211 @@
|
|
|
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import WJElement from "./wje-element.js";
|
|
5
|
+
import { getBasePath } from "./base-path.js";
|
|
6
|
+
let registry = [];
|
|
7
|
+
registerIconLibrary("default", {
|
|
8
|
+
resolver: (name, style) => getBasePath(`assets/img/icons/${style}/${name}.svg`)
|
|
9
|
+
});
|
|
10
|
+
function getIconLibrary(name) {
|
|
11
|
+
return registry.find((lib) => lib.name === name);
|
|
12
|
+
}
|
|
13
|
+
function registerIconLibrary(name, options) {
|
|
14
|
+
unregisterIconLibrary(name);
|
|
15
|
+
registry.push({
|
|
16
|
+
name,
|
|
17
|
+
resolver: options.resolver
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function unregisterIconLibrary(name) {
|
|
21
|
+
registry = registry.filter((lib) => lib.name !== name);
|
|
22
|
+
}
|
|
23
|
+
const iconContent = /* @__PURE__ */ new Map();
|
|
24
|
+
const requests = /* @__PURE__ */ new Map();
|
|
25
|
+
let parser;
|
|
26
|
+
const getSrc = (src) => {
|
|
27
|
+
if (isStr(src)) {
|
|
28
|
+
src = src.trim();
|
|
29
|
+
if (isSrc(src)) {
|
|
30
|
+
return src;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str);
|
|
36
|
+
const isSvgDataUrl = (url) => url.startsWith("data:image/svg+xml");
|
|
37
|
+
const isEncodedDataUrl = (url) => url.indexOf(";utf8,") !== -1;
|
|
38
|
+
const isStr = (val) => typeof val === "string";
|
|
39
|
+
const validateContent = (svgContent) => {
|
|
40
|
+
const div = document.createElement("div");
|
|
41
|
+
div.innerHTML = svgContent;
|
|
42
|
+
const svgElm = div.firstElementChild;
|
|
43
|
+
if (svgElm && svgElm.nodeName.toLowerCase() === "svg") {
|
|
44
|
+
svgElm.getAttribute("class") || "";
|
|
45
|
+
if (isValid(svgElm)) {
|
|
46
|
+
return div.innerHTML;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "";
|
|
50
|
+
};
|
|
51
|
+
const isValid = (elm) => {
|
|
52
|
+
if (elm.nodeType === 1) {
|
|
53
|
+
if (elm.nodeName.toLowerCase() === "script") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
for (let i = 0; i < elm.attributes.length; i++) {
|
|
57
|
+
const name = elm.attributes[i].name;
|
|
58
|
+
if (isStr(name) && name.toLowerCase().indexOf("on") === 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (let i = 0; i < elm.childNodes.length; i++) {
|
|
63
|
+
if (!isValid(elm.childNodes[i])) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
70
|
+
const getSvgContent = (url, sanitize) => {
|
|
71
|
+
let req = requests.get(url);
|
|
72
|
+
if (!req) {
|
|
73
|
+
if (typeof fetch !== "undefined" && typeof document !== "undefined") {
|
|
74
|
+
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
|
|
75
|
+
if (!parser) {
|
|
76
|
+
parser = new DOMParser();
|
|
77
|
+
}
|
|
78
|
+
const doc = parser.parseFromString(url, "text/html");
|
|
79
|
+
const svg = doc.querySelector("svg");
|
|
80
|
+
if (svg) {
|
|
81
|
+
iconContent.set(url, svg.outerHTML);
|
|
82
|
+
}
|
|
83
|
+
return Promise.resolve();
|
|
84
|
+
} else {
|
|
85
|
+
req = fetch(url).then((rsp) => {
|
|
86
|
+
if (rsp.ok) {
|
|
87
|
+
return rsp.text().then((svgContent) => {
|
|
88
|
+
if (svgContent && sanitize !== false) {
|
|
89
|
+
svgContent = validateContent(svgContent);
|
|
90
|
+
}
|
|
91
|
+
iconContent.set(url, svgContent || "");
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return iconContent.set(url, "");
|
|
95
|
+
});
|
|
96
|
+
requests.set(url, req);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
iconContent.set(url, "");
|
|
100
|
+
return Promise.resolve();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return req;
|
|
104
|
+
};
|
|
105
|
+
const getUrl = (i) => {
|
|
106
|
+
let url = getSrc(i.src);
|
|
107
|
+
if (url) {
|
|
108
|
+
return url;
|
|
109
|
+
}
|
|
110
|
+
url = getName(i.name);
|
|
111
|
+
if (url) {
|
|
112
|
+
return getNamedUrl(url, i.library, i.hasAttribute("filled"));
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
};
|
|
116
|
+
const getName = (iconName) => {
|
|
117
|
+
if (!isStr(iconName) || iconName.trim() === "") {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const invalidChars = iconName.replace(/[a-z]|-|\d/gi, "");
|
|
121
|
+
if (invalidChars !== "") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return iconName;
|
|
125
|
+
};
|
|
126
|
+
const getNamedUrl = (iconName, libraryName = "default", filled = false) => {
|
|
127
|
+
let library = getIconLibrary(libraryName);
|
|
128
|
+
let url = library.resolver(iconName, filled ? "filled" : "outline");
|
|
129
|
+
return url;
|
|
130
|
+
};
|
|
131
|
+
const styles = "/*\n[ WJ Icon ]\n*/\n\n:host {\n width: var(--wje-icon-size);\n height: var(--wje-icon-size);\n display: block;\n}\n\n.native-icon {\n display: flex;\n align-items: center;\n}\n\nsvg {\n width: 100%;\n height: 100%;\n stroke-width: var(--wje-icon-stroke);\n color: var(--wje-icon-color);\n}\n\n/*STROKE*/\n:host([stroke='1']) {\n --wje-icon-stroke: 1;\n}\n\n:host([stroke='1.25']) {\n --wje-icon-stroke: 1.25;\n}\n\n:host([stroke='1.5']) {\n --wje-icon-stroke: 1.5;\n}\n\n:host([stroke='1.75']) {\n --wje-icon-stroke: 1.75;\n}\n\n:host([stroke='2']) {\n --wje-icon-stroke: 2;\n}\n\n/*SIZE*/\n:host([size='2x-small']) {\n --wje-icon-size: var(--wje-size-2x-small);\n}\n\n:host([size='x-small']) {\n --wje-icon-size: var(--wje-size-x-small);\n}\n\n:host([size='small']) {\n --wje-icon-size: var(--wje-size-small);\n}\n\n:host([size='medium']) {\n --wje-icon-size: var(--wje-size-medium);\n}\n\n:host([size='large']) {\n --wje-icon-size: var(--wje-size-large);\n}\n\n:host([size='x-large']) {\n --wje-icon-size: var(--wje-size-x-large);\n}\n\n:host([size='2x-large']) {\n --wje-icon-size: var(--wje-size-2x-large);\n}\n\n:host([size='3x-large']) {\n --wje-icon-size: var(--wje-size-3x-large);\n}\n\n:host([size='4x-large']) {\n --wje-icon-size: var(--wje-size-4x-large);\n}\n\n/*COLOR*/\n:host([color='primary']) .native-icon {\n color: var(--wje-color-primary-9);\n}\n\n:host([color='complete']) .native-icon {\n color: var(--wje-color-complete-9);\n}\n\n:host([color='success']) .native-icon {\n color: var(--wje-color-success-9);\n}\n\n:host([color='warning']) .native-icon {\n color: var(--wje-color-warning-9);\n}\n\n:host([color='danger']) .native-icon {\n color: var(--wje-color-danger-9);\n}\n\n:host([color='info']) .native-icon {\n color: var(--wje-color-info-9);\n}\n\n:host([color='menu']) .native-icon {\n color: var(--wje-color-contrast-9);\n}\n";
|
|
132
|
+
class Icon extends WJElement {
|
|
133
|
+
/**
|
|
134
|
+
* Creates an instance of IconElement.
|
|
135
|
+
* @class
|
|
136
|
+
*/
|
|
137
|
+
constructor() {
|
|
138
|
+
super();
|
|
139
|
+
/**
|
|
140
|
+
* Sets the name of the icon.
|
|
141
|
+
* @type {string}
|
|
142
|
+
*/
|
|
143
|
+
__publicField(this, "className", "Icon");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns the CSS styles for the component.
|
|
147
|
+
* @static
|
|
148
|
+
* @returns {CSSStyleSheet}
|
|
149
|
+
*/
|
|
150
|
+
static get cssStyleSheet() {
|
|
151
|
+
return styles;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the list of attributes to observe for changes.
|
|
155
|
+
* @static
|
|
156
|
+
* @returns {Array<string>}
|
|
157
|
+
*/
|
|
158
|
+
static get observedAttributes() {
|
|
159
|
+
return ["name", "filled"];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets up the attributes for the component.
|
|
163
|
+
*/
|
|
164
|
+
setupAttributes() {
|
|
165
|
+
this.isShadowRoot = "open";
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Draws the component.
|
|
169
|
+
* @param {object} context The context for drawing.
|
|
170
|
+
* @param {object} store The store for drawing.
|
|
171
|
+
* @param {object} params The parameters for drawing.
|
|
172
|
+
* @returns {DocumentFragment}
|
|
173
|
+
*/
|
|
174
|
+
draw(context, store, params) {
|
|
175
|
+
let fragment = document.createDocumentFragment();
|
|
176
|
+
this.classList.add("lazy-loaded-image", "lazy");
|
|
177
|
+
let native = document.createElement("div");
|
|
178
|
+
native.setAttribute("part", "native");
|
|
179
|
+
native.classList.add("native-icon");
|
|
180
|
+
this.url = getUrl(this);
|
|
181
|
+
fragment.appendChild(native);
|
|
182
|
+
this.native = native;
|
|
183
|
+
return fragment;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Called after the component has been drawn.
|
|
187
|
+
*/
|
|
188
|
+
afterDraw() {
|
|
189
|
+
let lazyImageObserver = new IntersectionObserver((entries, observer) => {
|
|
190
|
+
entries.forEach((entry) => {
|
|
191
|
+
if (entry.isIntersecting) {
|
|
192
|
+
getSvgContent(this.url).then((svgContent) => {
|
|
193
|
+
var _a;
|
|
194
|
+
this.native.innerHTML = iconContent == null ? void 0 : iconContent.get(this.url);
|
|
195
|
+
(_a = this.native.querySelector("svg")) == null ? void 0 : _a.setAttribute("part", "svg");
|
|
196
|
+
});
|
|
197
|
+
this.classList.remove("lazy");
|
|
198
|
+
lazyImageObserver.unobserve(entry.target);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
lazyImageObserver.observe(this.native);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
Icon.define("wje-icon", Icon);
|
|
206
|
+
export {
|
|
207
|
+
Icon as I,
|
|
208
|
+
registerIconLibrary as r,
|
|
209
|
+
unregisterIconLibrary as u
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=icon-DY5AZ6xM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-DY5AZ6xM.js","sources":["../packages/utils/icon-library.js","../packages/wje-icon/service/service.js","../packages/wje-icon/icon.element.js","../packages/wje-icon/icon.js"],"sourcesContent":["import { getBasePath } from \"./base-path.js\";\n\nlet registry = [];\n\nregisterIconLibrary(\"default\", {\n resolver: (name, style) => getBasePath(`assets/img/icons/${style}/${name}.svg`)\n});\n\nexport function getIconLibrary(name) {\n return registry.find(lib => lib.name === name);\n}\n\nexport function registerIconLibrary(name, options) {\n unregisterIconLibrary(name);\n registry.push({\n name,\n resolver: options.resolver,\n });\n}\n\nexport function unregisterIconLibrary(name) {\n registry = registry.filter(lib => lib.name !== name);\n}","import { getIconLibrary } from \"../../utils/icon-library.js\";\n\nexport const iconContent = new Map();\nconst requests = new Map();\n\nlet parser;\n\n/**\n * Validates and returns a trimmed source string if it meets the required criteria.\n * @param {string} src The source string to validate and trim.\n * @returns {string|null} The validated and trimmed source string, or `null` if invalid.\n * @example\n * getSrc(' https://example.com/image.jpg '); // Returns 'https://example.com/image.jpg'\n * getSrc('invalid-src'); // Returns null\n */\nexport const getSrc = (src) => {\n if (isStr(src)) {\n src = src.trim();\n if (isSrc(src)) {\n return src;\n }\n }\n return null;\n};\n\n/**\n * Checks if a given string is a valid source based on specific criteria.\n * @param {string} str The string to validate as a source.\n * @returns {boolean} `true` if the string is considered a valid source, `false` otherwise.\n * @example\n * isSrc('https://example.com/image.jpg'); // Returns true\n * isSrc('image.jpg'); // Returns true\n * isSrc('invalid-src'); // Returns false\n */\nexport const isSrc = (str) => str.length > 0 && /(\\/|\\.)/.test(str);\n\n/**\n * Checks if the provided URL is an SVG data URL.\n * @param {string} url The URL to check.\n * @returns {boolean} - Returns `true` if the URL starts with 'data:image/svg+xml', otherwise `false`.\n * @example\n * isSvgDataUrl('data:image/svg+xml;base64,...'); // Returns true\n * isSvgDataUrl('https://example.com/image.svg'); // Returns false\n */\nexport const isSvgDataUrl = (url) => url.startsWith('data:image/svg+xml');\n\n/**\n * Checks if the provided URL is an encoded data URL.\n * @param {string} url The URL to check.\n * @returns {boolean} - Returns `true` if the URL contains ';utf8,', otherwise `false`.\n * @example\n * isEncodedDataUrl('data:text/plain;charset=utf8,...'); // Returns true\n * isEncodedDataUrl('https://example.com/file.txt'); // Returns false\n */\nexport const isEncodedDataUrl = (url) => url.indexOf(';utf8,') !== -1;\n\n/**\n * Checks if the provided value is of string type.\n * @param {*} val The value to check.\n * @returns {boolean} - Returns `true` if the value is a string, otherwise `false`.\n * @example\n * isStr('Hello, World!'); // Returns true\n * isStr(12345); // Returns false\n */\nexport const isStr = (val) => typeof val === 'string';\n\n/**\n * Validates the provided SVG content and ensures it contains a valid SVG element.\n * @param {string} svgContent The SVG content to validate.\n * @returns {string} Returns the validated SVG content as a string if valid, otherwise an empty string.\n * @example\n * const validSvg = '<svg class=\"icon\" xmlns=\"http://www.w3.org/2000/svg\"></svg>';\n * validateContent(validSvg); // Returns '<svg class=\"icon\" xmlns=\"http://www.w3.org/2000/svg\"></svg>'\n * const invalidSvg = '<div></div>';\n * validateContent(invalidSvg); // Returns ''\n */\nexport const validateContent = (svgContent) => {\n const div = document.createElement('div');\n div.innerHTML = svgContent;\n\n const svgElm = div.firstElementChild;\n if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {\n const svgClass = svgElm.getAttribute('class') || '';\n\n if (isValid(svgElm)) {\n return div.innerHTML;\n }\n }\n return '';\n};\n\n/**\n * Validates an element to ensure it does not contain potentially unsafe content.\n * @param {Element|Node} elm The element or node to validate.\n * @returns {boolean} - Returns `true` if the element is valid, otherwise `false`.\n * @description\n * This function checks the following:\n * 1. The element is an element node (nodeType 1).\n * 2. The element is not a `<script>` tag.\n * 3. The element does not contain any `on*` event handler attributes (e.g., `onclick`).\n * 4. All child nodes recursively pass the same validation.\n * @example\n * const validElement = document.createElement('div');\n * isValid(validElement); // Returns true\n *\n * const scriptElement = document.createElement('script');\n * isValid(scriptElement); // Returns false\n *\n * const divWithOnClick = document.createElement('div');\n * divWithOnClick.setAttribute('onclick', 'alert(\"hi\")');\n * isValid(divWithOnClick); // Returns false\n */\nexport const isValid = (elm) => {\n // Only element nodes\n if (elm.nodeType === 1) {\n // Check for script elements\n if (elm.nodeName.toLowerCase() === 'script') {\n return false;\n }\n\n // Check for on* attributes\n for (let i = 0; i < elm.attributes.length; i++) {\n const name = elm.attributes[i].name;\n if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {\n return false;\n }\n }\n\n // Check for child nodes\n for (let i = 0; i < elm.childNodes.length; i++) {\n if (!isValid(elm.childNodes[i])) {\n return false;\n }\n }\n }\n return true;\n};\n\n/**\n * Fetches and optionally sanitizes SVG content from a given URL.\n * @param {string} url The URL of the SVG resource or data URL.\n * @param {boolean} [sanitize] Whether to sanitize the SVG content. Defaults to `true`.\n * @returns {Promise<void>} A promise that resolves when the SVG content is fetched and stored.\n * @description\n * This function performs the following:\n * - If the URL is an SVG data URL and encoded, it parses the content to extract the SVG.\n * - If the URL is a standard HTTP/HTTPS URL, it fetches the content.\n * - Optionally sanitizes the fetched SVG content.\n * - Caches the content for future use.\n * @example\n * getSvgContent('https://example.com/icon.svg').then(() => {\n * console.log('SVG content fetched and stored.');\n * });\n * @example\n * getSvgContent('data:image/svg+xml;base64,...', false).then(() => {\n * console.log('SVG data URL processed without sanitization.');\n * });\n */\nexport const getSvgContent = (url, sanitize) => {\n let req = requests.get(url);\n if (!req) {\n if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {\n if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {\n if (!parser) {\n parser = new DOMParser();\n }\n const doc = parser.parseFromString(url, 'text/html');\n const svg = doc.querySelector('svg');\n if (svg) {\n iconContent.set(url, svg.outerHTML);\n }\n return Promise.resolve();\n } else {\n req = fetch(url).then((rsp) => {\n if (rsp.ok) {\n return rsp.text().then((svgContent) => {\n if (svgContent && sanitize !== false) {\n svgContent = validateContent(svgContent);\n }\n iconContent.set(url, svgContent || '');\n });\n }\n return iconContent.set(url, '');\n });\n requests.set(url, req);\n }\n } else {\n iconContent.set(url, '');\n return Promise.resolve();\n }\n }\n return req;\n};\n\n/**\n * Retrieves the URL for an icon based on its `src` or `name` attributes.\n * @param {HTMLElement} i The icon element from which to extract the URL.\n * @returns {string|null} The URL of the icon if found, or `null` if no valid URL can be determined.\n * @description\n * This function performs the following:\n * 1. Attempts to retrieve the URL from the `src` attribute using `getSrc`.\n * 2. If no `src` is provided, it falls back to the `name` attribute using `getName`.\n * 3. If a name is found, it uses `getNamedUrl` to construct the URL, considering the `filled` attribute.\n * @example\n * const iconElement = document.querySelector('wje-icon');\n * const url = getUrl(iconElement);\n * console.log(url); // Outputs the resolved URL or `null`.\n */\nexport const getUrl = (i) => {\n let url = getSrc(i.src);\n if (url) {\n return url;\n }\n\n url = getName(i.name);\n\n if (url) {\n return getNamedUrl(url, i.library, i.hasAttribute('filled'));\n }\n\n return null;\n};\n\n/**\n * Validates and returns a sanitized icon name.\n * @param {string} iconName The icon name to validate.\n * @returns {string|null} The sanitized icon name, or `null` if the input is invalid.\n * @description\n * This function checks if the provided `iconName` is a valid string:\n * - It must not be empty or contain invalid characters.\n * - Only alphanumeric characters, hyphens, and digits are allowed.\n * @example\n * const validName = getName('user-icon');\n * console.log(validName); // 'user-icon'\n * const invalidName = getName('user@icon!');\n * console.log(invalidName); // null\n */\nexport const getName = (iconName) => {\n if (!isStr(iconName) || iconName.trim() === '') {\n return null;\n }\n\n const invalidChars = iconName.replace(/[a-z]|-|\\d/gi, '');\n if (invalidChars !== '') {\n return null;\n }\n\n return iconName;\n};\n\n/**\n * Constructs the URL for a named SVG icon.\n * @param {string} iconName The name of the icon to retrieve.\n * @param {string} [libraryName] The name of the icon library to use. Defaults to \"default\".\n * @param {boolean} [filled] Whether to use the \"filled\" variant of the icon. Defaults to \"outline\" if `false`.\n * @returns {string} - The complete URL to the SVG icon.\n * @description\n * This function generates a URL for an icon based on its name and style (filled or outline).\n * It uses the base URL from the environment variable `VITE_ICON_ASSETS_URL`.\n * @example\n * const url = getNamedUrl('user-icon', 'default', true);\n * console.log(url); // 'https://example.com/filled/user-icon.svg'\n *\n * const outlineUrl = getNamedUrl('settings', 'default');\n * console.log(outlineUrl); // 'https://example.com/outline/settings.svg'\n */\nconst getNamedUrl = (iconName, libraryName = 'default', filled = false) => {\n let library = getIconLibrary(libraryName);\n let url = library.resolver(iconName, filled ? 'filled' : 'outline');\n\n return url;\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport { getSvgContent, getUrl, iconContent } from './service/service.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element represents an icon. `IconElement` is a custom web component that represents an icon.\n * @documentation https://elements.webjet.sk/components/icon\n * @status stable\n * @augments WJElement\n * @csspart svg - The SVG part of the icon\n * @cssproperty [--wje-icon-size=1rem] - The size of the icon element\n * @cssproperty [--wje-icon-width=var(--wje-icon-size, 100%)] - The width of the icon element\n * @cssproperty [--wje-icon-height=var(--wje-icon-size, 100%)] - The height of the icon element\n * @tag wje-icon\n */\nexport default class Icon extends WJElement {\n /**\n * Creates an instance of IconElement.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the name of the icon.\n * @type {string}\n */\n className = 'Icon';\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 ['name', 'filled'];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('lazy-loaded-image', 'lazy');\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-icon');\n\n this.url = getUrl(this);\n\n fragment.appendChild(native);\n\n this.native = native;\n\n return fragment;\n }\n\n /**\n * Called after the component has been drawn.\n */\n afterDraw() {\n let lazyImageObserver = new IntersectionObserver((entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n getSvgContent(this.url).then((svgContent) => {\n this.native.innerHTML = iconContent?.get(this.url);\n this.native.querySelector('svg')?.setAttribute('part', 'svg');\n });\n\n this.classList.remove('lazy');\n lazyImageObserver.unobserve(entry.target);\n }\n });\n });\n\n lazyImageObserver.observe(this.native);\n }\n}\n","import Icon from './icon.element.js';\n\nexport default Icon;\n\nIcon.define('wje-icon', Icon);\n"],"names":[],"mappings":";;;;;AAEA,IAAI,WAAW,CAAE;AAEjB,oBAAoB,WAAW;AAAA,EAC7B,UAAU,CAAC,MAAM,UAAU,YAAY,oBAAoB,KAAK,IAAI,IAAI,MAAM;AAChF,CAAC;AAEM,SAAS,eAAe,MAAM;AACnC,SAAO,SAAS,KAAK,SAAO,IAAI,SAAS,IAAI;AAC/C;AAEO,SAAS,oBAAoB,MAAM,SAAS;AACjD,wBAAsB,IAAI;AAC1B,WAAS,KAAK;AAAA,IACZ;AAAA,IACA,UAAU,QAAQ;AAAA,EACtB,CAAG;AACH;AAEO,SAAS,sBAAsB,MAAM;AAC1C,aAAW,SAAS,OAAO,SAAO,IAAI,SAAS,IAAI;AACrD;ACpBO,MAAM,cAAc,oBAAI,IAAK;AACpC,MAAM,WAAW,oBAAI,IAAK;AAE1B,IAAI;AAUG,MAAM,SAAS,CAAC,QAAQ;AAC3B,MAAI,MAAM,GAAG,GAAG;AACZ,UAAM,IAAI,KAAM;AAChB,QAAI,MAAM,GAAG,GAAG;AACZ,aAAO;AAAA,IACnB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