mypgs 1.5.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/AGENTS.md +8 -5
  2. package/README.md +1 -1
  3. package/assets/javascript/_imports.js +4 -0
  4. package/assets/javascript/_pgs.js +58 -0
  5. package/assets/javascript/base/_darkmode.js +27 -105
  6. package/assets/javascript/base/_svg.js +103 -0
  7. package/assets/javascript/components/_accordion.js +2 -2
  8. package/assets/javascript/components/_menu.js +1 -3
  9. package/assets/javascript/components/_modals.js +159 -136
  10. package/assets/javascript/components/_notifications.js +19 -9
  11. package/assets/javascript/components/_search.js +391 -0
  12. package/assets/javascript/components/_slides.js +66 -32
  13. package/assets/javascript/components/_stepTabs.js +4 -4
  14. package/assets/javascript/components/_steps.js +2 -2
  15. package/assets/javascript/components/_summary.js +2 -2
  16. package/assets/javascript/functions/_formValidate.js +97 -53
  17. package/assets/javascript/functions/_scrollY.js +10 -10
  18. package/assets/javascript/index.js +2 -0
  19. package/assets/javascript/layout/_header.js +29 -7
  20. package/assets/scss/base/_color.scss +5 -5
  21. package/assets/scss/base/_html.scss +2 -2
  22. package/assets/scss/base/_variables.scss +4 -2
  23. package/assets/scss/components/_dropdown.scss +2 -1
  24. package/assets/scss/components/_form.scss +2 -2
  25. package/assets/scss/components/_logo.scss +2 -2
  26. package/assets/scss/components/_menu.scss +20 -27
  27. package/assets/scss/components/_modals.scss +11 -1
  28. package/assets/scss/components/_notification.scss +23 -30
  29. package/assets/scss/components/_search.scss +140 -0
  30. package/assets/scss/index.scss +2 -2
  31. package/assets/scss/layout/_header.scss +1 -1
  32. package/assets/scss/layout/_pageShell.scss +19 -15
  33. package/assets/scss/mixin/_mx-form.scss +7 -7
  34. package/{templates/html → demo}/demo.html +1 -1
  35. package/demo/demo.js +240 -0
  36. package/dist/css/index.css +188 -125
  37. package/dist/css/index.css.map +1 -1
  38. package/dist/css/index.min.css +1 -1
  39. package/dist/index.d.ts +70 -0
  40. package/dist/javascript/index.js +1038 -405
  41. package/dist/javascript/index.js.map +1 -1
  42. package/dist/javascript/index.min.js +1 -1
  43. package/docs/componenti-e-markup.md +62 -27
  44. package/docs/components/accordion.md +61 -0
  45. package/docs/components/badges.md +67 -0
  46. package/docs/components/breadcumbs.md +43 -0
  47. package/docs/components/button.md +59 -0
  48. package/docs/components/card.md +50 -0
  49. package/docs/components/dropdown.md +135 -0
  50. package/docs/components/form.md +113 -0
  51. package/docs/components/logo.md +36 -0
  52. package/docs/components/menu.md +90 -0
  53. package/docs/components/modal.md +131 -0
  54. package/docs/components/notification.md +81 -0
  55. package/docs/components/search.md +117 -0
  56. package/docs/components/slides.md +85 -0
  57. package/docs/components/stepTabs.md +93 -0
  58. package/docs/components/steps.md +56 -0
  59. package/docs/components/summary.md +49 -0
  60. package/docs/components/table.md +42 -0
  61. package/docs/components/tooltip.md +53 -0
  62. package/docs/helper-javascript.md +71 -3
  63. package/docs/layout/body.md +41 -0
  64. package/docs/layout/flex.md +116 -0
  65. package/docs/layout/footer.md +71 -0
  66. package/docs/layout/grid.md +116 -0
  67. package/docs/layout/header.md +116 -0
  68. package/docs/layout/pageShell.md +94 -0
  69. package/docs/layout/section.md +69 -0
  70. package/docs/patterns/cookieConsent.md +89 -0
  71. package/package.json +2 -1
  72. package/scripts/generate-component-docs.js +557 -0
  73. package/templates/html/components/accordion.html +33 -4
  74. package/templates/html/components/badges.html +23 -0
  75. package/templates/html/components/breadcumbs.html +14 -0
  76. package/templates/html/components/button.html +22 -0
  77. package/templates/html/components/card.html +20 -0
  78. package/templates/html/components/dropdown.html +34 -0
  79. package/templates/html/components/form.html +82 -4
  80. package/templates/html/components/logo.html +22 -1
  81. package/templates/html/components/menu.html +40 -1
  82. package/templates/html/components/modal.html +44 -0
  83. package/templates/html/components/notification.html +68 -32
  84. package/templates/html/components/search.html +107 -0
  85. package/templates/html/components/slides.html +43 -0
  86. package/templates/html/components/stepTabs.html +47 -0
  87. package/templates/html/components/steps.html +24 -0
  88. package/templates/html/components/summary.html +27 -0
  89. package/templates/html/components/table.html +12 -0
  90. package/templates/html/components/tooltip.html +35 -0
  91. package/templates/html/layout/body.html +20 -5
  92. package/templates/html/layout/flex.html +20 -0
  93. package/templates/html/layout/footer.html +29 -1
  94. package/templates/html/layout/grid.html +20 -0
  95. package/templates/html/layout/header.html +52 -5
  96. package/templates/html/layout/pageShell.html +19 -0
  97. package/templates/html/layout/section.html +32 -10
  98. package/templates/html/patterns/cookieConsent.html +31 -0
  99. package/templates/react/components/form.jsx +3 -3
  100. package/templates/react/components/logo.jsx +1 -1
  101. package/templates/react/components/notification.jsx +4 -4
  102. package/templates/react/components/{searchbar.jsx → search.jsx} +9 -7
  103. package/templates/react/patterns/footer.jsx +1 -1
  104. package/templates/react/patterns/header.jsx +16 -10
  105. package/assets/scss/components/_searchbar.scss +0 -70
  106. package/templates/html/components/searchbar.html +0 -29
  107. package/templates/html/demo.js +0 -137
  108. /package/{templates/html → demo}/demo.css +0 -0
package/AGENTS.md CHANGED
@@ -8,7 +8,7 @@ This guide is for any AI/Codex agent that initializes or modifies a project base
8
8
 
9
9
  - HTML `pgs` attributes as the contract between markup, SCSS, and JavaScript;
10
10
  - SCSS sources with base styles, layouts, components, patterns, CSS variables, and mixins;
11
- - JavaScript modules for recurring behaviors such as accordions, dropdowns, menus, modals, slides, steps, step tabs, notifications, header, cookie consent, and dark mode;
11
+ - JavaScript modules for recurring behaviors such as accordions, dropdowns, menus, modals, search suggestions, slides, steps, step tabs, notifications, header, cookie consent, and dark mode;
12
12
  - example HTML templates in `templates/`;
13
13
  - compiled assets in `dist/`.
14
14
 
@@ -26,7 +26,7 @@ Write custom code only when the pattern does not exist, or when you are adding a
26
26
  ## 2. General Usage Rules
27
27
 
28
28
  - Use `mypgs` as the first choice for layouts, components, helpers, variables, utilities, and available patterns.
29
- - Do not recreate existing components from scratch: buttons, forms, dropdowns, modals, menus, slides, accordions, steps, stepTabs, notifications, tooltips, tables, searchbars, logos, headers, footers, and cookie consent.
29
+ - Do not recreate existing components from scratch: buttons, forms, dropdowns, modals, menus, slides, accordions, steps, stepTabs, notifications, tooltips, tables, search, logos, headers, footers, and cookie consent.
30
30
  - Do not duplicate logic already handled by the `mypgs` JS modules, such as modal open/close, accordion state, Popover API dropdowns, step tabs, notifications, or form validation.
31
31
  - Keep `pgs` tokens in markup, SCSS selectors, and JS queries consistent.
32
32
  - Prefer composing `pgs` tokens over adding new CSS classes.
@@ -52,6 +52,7 @@ Files analyzed:
52
52
  - `assets/javascript/components/_steps.js`
53
53
  - `assets/javascript/components/_stepTabs.js`
54
54
  - `assets/javascript/components/_notifications.js`
55
+ - `assets/javascript/components/_search.js`
55
56
  - `assets/javascript/functions/_formValidate.js`
56
57
  - `assets/javascript/functions/_scrollY.js`
57
58
  - `assets/javascript/patterns/_header.js`
@@ -70,10 +71,11 @@ Patterns found:
70
71
 
71
72
  - `pgs` is the main attribute: tokens are separated by spaces, for example `pgs="button modal-button"`.
72
73
  - `assets/scss/index.scss` imports base, layout, components, and patterns; layouts/components/patterns are almost all scoped under `[pgs~=initP]`.
73
- - The main markup must enable the library with `htmlBase initP`, and the body with base body tokens. Use `templates/demo.html` and `templates/html/layout/body.html` as the canonical references.
74
+ - The main markup must enable the library with `htmlBase initP`, and the body with base body tokens. Use `demo/demo.html` and `templates/html/layout/body.html` as the canonical references.
74
75
  - Components use a root token and child tokens with a consistent prefix. Use `templates/html/components/` as the canonical markup source.
75
76
 
76
77
  - Runtime states use `pgs-state`, for example `open`, `is-active`, `is-completed`, `is-locked`, `success`, `error`, `warning`, and `info`.
78
+ - La ricerca componibile usa esclusivamente `pgs="search"` come root grafico e comportamentale e il figlio opzionale `pgs="search-suggestions"`. La sorgente dati si configura tramite `pgs.search.api(element)?.configure({ source })` e deve restare indipendente dal backend.
77
79
  - Configurable options use `pgs-option`, with simple tokens or values inside square brackets. Prefer copying the current option syntax from the relevant template rather than duplicating examples in this guide.
78
80
 
79
81
  - Naming is mostly camelCase for compound tokens (`menuHorizontal`, `buttonStrong`, `flexColumnElements`) and kebab-like for component sub-elements (`accordion-button`, `modal-dialog-content`, `cookieConsent-actionAccept`).
@@ -186,6 +188,7 @@ Recommended direct access:
186
188
  ```js
187
189
  pgs.notification.toast.success("Saved");
188
190
  pgs.modal.api(modalEl)?.open();
191
+ pgs.search.api(searchEl)?.setSource(async ({ query, signal }) => []);
189
192
  ```
190
193
 
191
194
  `assets/javascript/_imports.js` registers modules with `pgs.registerModules`:
@@ -224,9 +227,9 @@ Use the templates as the single source of truth for component and layout markup.
224
227
  Canonical template references:
225
228
 
226
229
  - Layouts: `templates/html/layout/body.html`, `templates/html/layout/flex.html`, `templates/html/layout/grid.html`, `templates/html/layout/pageShell.html`, `templates/html/layout/section.html`
227
- - Components: `templates/html/components/accordion.html`, `templates/html/components/breadcumbs.html`, `templates/html/components/button.html`, `templates/html/components/card.html`, `templates/html/components/dropdown.html`, `templates/html/components/form.html`, `templates/html/components/logo.html`, `templates/html/components/menu.html`, `templates/html/components/modal.html`, `templates/html/components/notification.html`, `templates/html/components/searchbar.html`, `templates/html/components/slides.html`, `templates/html/components/stepTabs.html`, `templates/html/components/steps.html`, `templates/html/components/table.html`, `templates/html/components/tooltip.html`
230
+ - Components: `templates/html/components/accordion.html`, `templates/html/components/breadcumbs.html`, `templates/html/components/button.html`, `templates/html/components/card.html`, `templates/html/components/dropdown.html`, `templates/html/components/form.html`, `templates/html/components/logo.html`, `templates/html/components/menu.html`, `templates/html/components/modal.html`, `templates/html/components/notification.html`, `templates/html/components/search.html`, `templates/html/components/slides.html`, `templates/html/components/stepTabs.html`, `templates/html/components/steps.html`, `templates/html/components/table.html`, `templates/html/components/tooltip.html`
228
231
  - Patterns: `templates/html/patterns/cookieConsent.html`, `templates/html/patterns/footer.html`, `templates/html/patterns/header.html`
229
- - Complete demo assembly. DO NOT use this for inspiration. It is only used to show all the modules: `templates/demo.html`
232
+ - Complete demo assembly. DO NOT use this for inspiration. It is only used to show all the modules: `demo/demo.html`
230
233
 
231
234
  Before creating markup, open the relevant template and reuse its current structure, tokens, ARIA attributes, and `pgs-option` syntax.
232
235
 
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `mypgs` e' una libreria frontend condivisa per costruire interfacce coerenti tramite attributi `pgs`, SCSS sorgenti, componenti UI e comportamenti JavaScript riutilizzabili.
4
4
 
5
- La libreria nasce come base di design system: layout, spacing, colori, bottoni, form, menu, modali, dropdown, slides, notifiche e pattern ricorrenti vengono definiti una volta sola e riusati nei progetti.
5
+ La libreria nasce come base di design system: layout, spacing, colori, bottoni, form, menu, modali, dropdown, ricerca con suggerimenti, slides, notifiche e pattern ricorrenti vengono definiti una volta sola e riusati nei progetti.
6
6
 
7
7
  ## Cosa contiene
8
8
 
@@ -1,10 +1,12 @@
1
1
  import { pgs } from "./_pgs.js";
2
2
 
3
+ import { PGS_svg } from "./base/_svg.js";
3
4
  import { PGS_accordion } from "./components/_accordion.js";
4
5
  import { PGS_dropdown } from "./components/_dropdown.js";
5
6
  import { PGS_menu } from "./components/_menu.js";
6
7
  import { PGS_modal } from "./components/_modals.js";
7
8
  import { PGS_notification } from "./components/_notifications.js";
9
+ import { PGS_search } from "./components/_search.js";
8
10
  import { PGS_slides } from "./components/_slides.js";
9
11
  import { PGS_stepTabs } from "./components/_stepTabs.js";
10
12
  import { PGS_steps } from "./components/_steps.js";
@@ -13,11 +15,13 @@ import { PGS_formValidate } from "./functions/_formValidate.js";
13
15
  import { PGS_scrollHorizontal } from "./functions/_scrollY.js";
14
16
 
15
17
  pgs.registerModules({
18
+ svg: PGS_svg,
16
19
  accordion: PGS_accordion,
17
20
  dropdown: PGS_dropdown,
18
21
  menu: PGS_menu,
19
22
  modal: PGS_modal,
20
23
  notification: PGS_notification,
24
+ search: PGS_search,
21
25
  slides: PGS_slides,
22
26
  stepTabs: PGS_stepTabs,
23
27
  steps: PGS_steps,
@@ -185,10 +185,56 @@ export function pgs(root) {
185
185
  function createOption(attribute) {
186
186
  if (!canAttr) return undefined;
187
187
 
188
+ const read = () => (root.getAttribute(attribute) || "").match(/[^\s[\]]+(?:\[[^\]]*\])?/g) || [];
189
+ const write = values => root.setAttribute(attribute, values.join(" "));
190
+ const getKey = value => String(value).trim().match(/^[^\s[\]]+/)?.[0] || "";
191
+ const getValues = values => values
192
+ .flat()
193
+ .flatMap(value => String(value).match(/[^\s[\]]+(?:\[[^\]]*\])?/g) || [])
194
+ .filter(Boolean);
195
+
188
196
  function api() {
189
197
  return api;
190
198
  }
191
199
 
200
+ api.add = function (...values) {
201
+ const current = read();
202
+
203
+ getValues(values).forEach(value => {
204
+ if (!current.includes(value)) current.push(value);
205
+ });
206
+
207
+ write(current);
208
+ return api;
209
+ };
210
+
211
+ api.remove = function (...values) {
212
+ const keys = getValues(values).map(getKey).filter(Boolean);
213
+ write(read().filter(value => !keys.includes(getKey(value))));
214
+ return api;
215
+ };
216
+
217
+ api.toggle = function (value, force) {
218
+ const key = getKey(value);
219
+ if (!key) return false;
220
+
221
+ const exists = api.contains(key);
222
+
223
+ if (force !== undefined) {
224
+ if (force && !exists) api.add(value);
225
+ if (!force && exists) api.remove(key);
226
+ return !!force;
227
+ }
228
+
229
+ if (exists) {
230
+ api.remove(key);
231
+ return false;
232
+ }
233
+
234
+ api.add(value);
235
+ return true;
236
+ };
237
+
192
238
  api.contains = function (key) {
193
239
  const source = root.getAttribute(attribute) || "";
194
240
  const safeKey = String(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -208,6 +254,18 @@ export function pgs(root) {
208
254
  return match ? match[1] : undefined;
209
255
  };
210
256
 
257
+ api.setValueBrackets = function (key, value = "") {
258
+ const optionKey = getKey(key);
259
+ if (!optionKey) return api;
260
+
261
+ const option = `${optionKey}[${String(value).trim()}]`;
262
+ const options = read().filter(item => getKey(item) !== optionKey);
263
+
264
+ options.push(option);
265
+ write(options);
266
+ return api;
267
+ };
268
+
211
269
  Object.defineProperty(api, "value", {
212
270
  get() { return root.getAttribute(attribute); },
213
271
  set(v) { root.setAttribute(attribute, v); }
@@ -1,121 +1,43 @@
1
1
  //# DARKMODE
2
2
 
3
+ const EVENT_SVG_CHANGE_COLOR = "pgs:svg:changeColor";
3
4
 
4
- //= CHANGE COLOR SVG & LOTTIE
5
- //+ SEARCH COLOR
6
- function searchColor(type = "svg") {
7
- const ROOT = getComputedStyle(document.documentElement);
8
- const colors = []
9
- for (let I = 0; I < 20; I++) {
10
- const color = ROOT.getPropertyValue('--' + type + '-color-' + I).toLocaleLowerCase().split("&");
11
- if (!color[0] == "" && !color[1] == "") {
12
- let lightDark = [color[0], color[1]]
13
- colors.push(lightDark)
14
- }
15
- }
16
- return colors;
17
- }
18
- const colors_svg_lottie = [searchColor("svg"), searchColor("lottie")];
19
-
20
-
21
- //+ change COLORS
22
- function darkmodeColorSVG() {
23
- function changecolor(svgDoc, type = "svg") {
24
- let isDarkMode = (document.documentElement.getAttribute("data-darkmode") === "true") ? false : true;
25
-
26
- svgDoc.querySelectorAll('[fill], [stroke]').forEach(fillStroke => {
27
-
28
- for (const colors of colors_svg_lottie) {
29
- for (const color of colors) {
30
- let OLD = (color[0] || '').replace(/\s/g, '');
31
- let NEW = (color[1] || '').replace(/\s/g, '');
32
-
33
- ["fill", "stroke"].forEach(attr => {
34
- const current = fillStroke.getAttribute(attr);
35
-
36
- fillStroke.style.transition = "fill 0.5s ease, stroke 0.5s ease";
37
-
38
- if (!isDarkMode) {
39
- if (current == OLD) fillStroke.setAttribute(attr, NEW)
40
- } else {
41
- if (current == NEW) fillStroke.setAttribute(attr, OLD)
42
- }
43
- });
44
- }
45
- }
46
- });
47
- }
48
-
49
- //== OBJECTS
50
- const objects = document.querySelectorAll('object[type="image/svg+xml"]');
51
- objects.forEach(obj => {
52
-
53
- //=== ALL FILL / STROKE
54
- obj.addEventListener("load", () => {
55
- const svgDoc = obj.contentDocument;
56
- if (svgDoc) changecolor(svgDoc, "svg")
57
- });
58
-
59
- //=== In caso l'object sia già caricato
60
- if (obj.contentDocument) {
61
- const event = new Event("load");
62
- obj.dispatchEvent(event);
63
- }
64
- });
65
-
66
- //== LOTTIE
67
- const lottiePlayers = document.querySelectorAll('lottie-player');
68
- lottiePlayers.forEach(lottiePlayer => {
69
-
70
- //=== ALL FILL / STROKE
71
- lottiePlayer.addEventListener("load", () => {
72
- const svg = lottiePlayer.shadowRoot.querySelector('svg');
73
- if (svg) changecolor(svg, "lottie")
74
- });
5
+ //+ CHANGE ICON
6
+ function changeIcon(selector, isDarkMode) {
7
+ selector.forEach(button => {
8
+ const ICON = button.querySelector("i");
9
+ if (!ICON) return;
75
10
 
76
- //=== In caso lottie sia già caricato
77
- if (lottiePlayer.shadowRoot) {
78
- const event = new Event("load");
79
- lottiePlayer.dispatchEvent(event);
80
- }
11
+ ICON.classList.toggle("fa-moon", !isDarkMode);
12
+ ICON.classList.toggle("fa-sun", isDarkMode);
81
13
  });
82
14
  }
83
15
 
16
+ //+ SET STATUS
17
+ function setDarkmodeStatus(toggle = false, button) {
18
+ let isDarkMode = localStorage.getItem("screenIsDarkMode") === "true";
84
19
 
20
+ if (toggle) {
21
+ isDarkMode = !isDarkMode;
22
+ localStorage.setItem("screenIsDarkMode", isDarkMode);
23
+ }
85
24
 
86
- //= BUTTON DARKMODE
87
- //+ CHANGE ICON AND SVG
88
- let toggleDarkmode = pgs(document).querySelectorAll("toggleDarkmode");
89
- if (localStorage.getItem("screenIsDarkMode") === "true") {
90
- document.body.classList.add("darkmode");
91
- document.querySelector(":root").setAttribute("data-darkmode", "true");
92
- document.body.setAttribute("data-darkmode", "true");
93
- }
25
+ // SET
26
+ pgs(document.documentElement).state.toggle("darkmode", isDarkMode);
27
+ pgs(document.body).state.toggle("darkmode", isDarkMode);
28
+ // END SET
94
29
 
95
- function change(selector, isDarkMode) {
96
- selector.forEach(button => {
97
- const ICON = button.querySelector("i");
98
- if (!ICON) return;
99
- ICON.classList.toggle("fa-moon", !isDarkMode);
100
- ICON.classList.toggle("fa-sun", isDarkMode);
101
- });
102
- darkmodeColorSVG();
30
+ changeIcon(button, isDarkMode);
31
+ document.dispatchEvent(new CustomEvent(EVENT_SVG_CHANGE_COLOR, { detail: { isDarkMode } }));
103
32
  }
104
33
 
105
- toggleDarkmode.forEach(button => {
106
34
 
107
- //== EXECUTE IMMEDIATELY
108
- let isDarkMode = document.documentElement.getAttribute("data-darkmode") === "true";
109
- change(toggleDarkmode, isDarkMode);
110
35
 
111
- //== CLICK BUTTON
112
- button.addEventListener("click", () => {
113
- let isDarkMode = (document.documentElement.getAttribute("data-darkmode") === "true") ? false : true;
114
- localStorage.setItem("screenIsDarkMode", isDarkMode);
36
+ //= INIT
37
+ const toggleDarkmode = pgs(document).querySelectorAll("toggleDarkmode");
38
+ setDarkmodeStatus(false, toggleDarkmode);
115
39
 
116
- document.body.classList.toggle("darkmode", isDarkMode);
117
- document.body.setAttribute("data-darkmode", isDarkMode);
118
- document.querySelector(":root").setAttribute("data-darkmode", isDarkMode);
119
- change(toggleDarkmode, isDarkMode);
120
- });
40
+ //= BUTTON DARKMODE
41
+ toggleDarkmode.forEach(button => {
42
+ button.addEventListener("click", () => setDarkmodeStatus(true, toggleDarkmode));
121
43
  });
@@ -0,0 +1,103 @@
1
+ //# SVG & LOTTIE COLORS
2
+
3
+ const svgColors = {
4
+ eventChangeColor: "pgs:svg:changeColor",
5
+ watchedObjects: new WeakSet(),
6
+ watchedLotties: new WeakSet(),
7
+
8
+ _normalizeColor: (color = "") => {
9
+ return color.replace(/\s/g, "").toLocaleLowerCase();
10
+ },
11
+
12
+ _getCurrentDarkmode: () => {
13
+ return pgs(document.documentElement).state.contains("darkmode");
14
+ },
15
+
16
+ searchColor(type = "svg") {
17
+ const ROOT = getComputedStyle(document.documentElement);
18
+ const colors = [];
19
+
20
+ for (let I = 0; I < 20; I++) {
21
+ const color = ROOT.getPropertyValue("--" + type + "-color-" + I).toLocaleLowerCase().split("&").map(value => value.trim());
22
+ if (color[0] && color[1]) colors.push([color[0], color[1]]);
23
+ }
24
+
25
+ return colors;
26
+ },
27
+
28
+ _changeColor(svgDoc, isDarkMode, colors) {
29
+ if (!svgDoc) return;
30
+
31
+ svgDoc.querySelectorAll("[fill], [stroke]").forEach(fillStroke => {
32
+ for (const color of colors) {
33
+ const OLD = svgColors._normalizeColor(color[0]);
34
+ const NEW = svgColors._normalizeColor(color[1]);
35
+
36
+ ["fill", "stroke"].forEach(attr => {
37
+ const current = svgColors._normalizeColor(fillStroke.getAttribute(attr) || "");
38
+ if (!current) return;
39
+
40
+ fillStroke.style.transition = "fill 0.5s ease, stroke 0.5s ease";
41
+
42
+ if (isDarkMode && current === OLD) fillStroke.setAttribute(attr, NEW);
43
+ if (!isDarkMode && current === NEW) fillStroke.setAttribute(attr, OLD);
44
+ });
45
+ }
46
+ });
47
+ },
48
+
49
+ _getLottieSvg(lottiePlayer) {
50
+ return lottiePlayer.shadowRoot?.querySelector("svg") || null;
51
+ },
52
+
53
+ init() {
54
+ document.addEventListener(svgColors.eventChangeColor, event => {
55
+ svgColors.applyColorsSVG(event.detail?.isDarkMode ?? svgColors._getCurrentDarkmode());
56
+ svgColors.applyColorsLottie(event.detail?.isDarkMode ?? svgColors._getCurrentDarkmode());
57
+ });
58
+
59
+ document.addEventListener("DOMContentLoaded", () => {
60
+ svgColors.applyColorsSVG();
61
+ svgColors.applyColorsLottie();
62
+ });
63
+ },
64
+
65
+ applyColorsSVG(isDarkMode = svgColors._getCurrentDarkmode()) {
66
+ const colorsSvg = svgColors.searchColor("svg");
67
+
68
+ if (!pgs(document).querySelector("svgChangeColor")) return;
69
+
70
+ document.querySelectorAll('object[type="image/svg+xml"]').forEach(obj => {
71
+ if (!svgColors.watchedObjects.has(obj)) {
72
+ obj.addEventListener("load", () => svgColors._changeColor(obj.contentDocument, svgColors._getCurrentDarkmode(), svgColors.searchColor("svg")));
73
+ svgColors.watchedObjects.add(obj);
74
+ }
75
+
76
+ if (obj.contentDocument) svgColors._changeColor(obj.contentDocument, isDarkMode, colorsSvg);
77
+ });
78
+
79
+ },
80
+
81
+ applyColorsLottie(isDarkMode = svgColors._getCurrentDarkmode()) {
82
+ const colorsLottie = svgColors.searchColor("svg");
83
+
84
+ if (!pgs(document).querySelector("lottieChangeColor")) return;
85
+
86
+ document.querySelectorAll("lottie-player").forEach(lottiePlayer => {
87
+ if (!svgColors.watchedLotties.has(lottiePlayer)) {
88
+ lottiePlayer.addEventListener("load", () => svgColors._changeColor(svgColors._getLottieSvg(lottiePlayer), svgColors._getCurrentDarkmode(), svgColors.searchColor("svg")));
89
+ svgColors.watchedLotties.add(lottiePlayer);
90
+ }
91
+
92
+ if (lottiePlayer.shadowRoot) svgColors._changeColor(svgColors._getLottieSvg(lottiePlayer), isDarkMode, colorsLottie);
93
+ });
94
+ },
95
+ };
96
+
97
+ svgColors.init();
98
+
99
+ export const PGS_svg = {
100
+ eventChangeColor: svgColors.eventChangeColor,
101
+ applyColorsSVG: isDarkMode => svgColors.applyColorsSVG(isDarkMode),
102
+ applyColorsLottie: isDarkMode => svgColors.applyColorsLottie(isDarkMode),
103
+ };
@@ -11,7 +11,7 @@ function directPgsChild(element, token) {
11
11
  return Array.from(element.children).find(child => pgs(child).contains(token));
12
12
  }
13
13
 
14
- export function PGS_accordion_init(root = document) {
14
+ function PGS_accordion_init(root = document) {
15
15
  pgs(root).querySelectorAll("accordion").forEach((accordion) => {
16
16
  if (API.has(accordion)) return;
17
17
 
@@ -115,7 +115,7 @@ export function PGS_accordion_init(root = document) {
115
115
  PGS_accordion_init();
116
116
 
117
117
  //# API
118
- export function PGS_accordion_api(selector) {
118
+ function PGS_accordion_api(selector) {
119
119
  return API.get(selector);
120
120
  }
121
121
 
@@ -20,6 +20,7 @@ function PGS_menu_init(root = document) {
20
20
  li.querySelector("a").insertAdjacentElement("afterend", button);
21
21
 
22
22
  pgs(li).add("dropdown")
23
+ pgs(li).option.setValueBrackets("position", "bottom right")
23
24
  pgs(button).add("dropdown-button")
24
25
  pgs(button).add("buttonNohover")
25
26
  pgs(ul).add("dropdown-content")
@@ -30,9 +31,6 @@ function PGS_menu_init(root = document) {
30
31
  API.set(MENU, {
31
32
  element: MENU,
32
33
  type: "horizontal",
33
- // items: () => Array.from(MENU.querySelectorAll('nav > ul > li')),
34
- // submenus: () => Array.from(MENU.querySelectorAll('.menu-item-has-children > ul')),
35
- // dropdowns: () => Array.from(MENU.querySelectorAll('.menu-item-has-children')).map(PGS_dropdown_api).filter(Boolean),
36
34
  refresh: () => {
37
35
  PGS_menu_init(MENU.parentNode || document);
38
36
  return API.get(MENU);