mypgs 1.5.0 → 1.5.1

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/index.d.ts CHANGED
@@ -61,6 +61,14 @@ declare global {
61
61
 
62
62
  interface PgsBag extends PgsElementApi {}
63
63
 
64
+ namespace React {
65
+ interface HTMLAttributes<T> {
66
+ /** Use pgsHtml in JSX/TSX. The Vite plugin converts it to pgs. */
67
+ pgs?: never;
68
+ pgsHtml?: string;
69
+ }
70
+ }
71
+
64
72
  var pgs: PgsFunction;
65
73
  }
66
74
 
@@ -2238,6 +2238,147 @@ function PGS_scrollHorizontal(querySelector, dataSpeed) {
2238
2238
  }
2239
2239
 
2240
2240
 
2241
+ /***/ },
2242
+
2243
+ /***/ "./assets/javascript/layout/_header.js"
2244
+ /*!*********************************************!*\
2245
+ !*** ./assets/javascript/layout/_header.js ***!
2246
+ \*********************************************/
2247
+ () {
2248
+
2249
+ //# HEADER
2250
+ const header = pgs(document).querySelector("header");
2251
+
2252
+ //= HEADER
2253
+ function PGS_header(selectHeader = document) {
2254
+
2255
+ if (!header) return;
2256
+
2257
+ const headerElements = pgs(header).querySelectorAll("header-element");
2258
+
2259
+ if (!headerElements.length) return;
2260
+
2261
+ headerElements.forEach(selectHeader => {
2262
+
2263
+ //== ACTIVE MOBILE
2264
+ let menuAttivate = false;
2265
+ let childsWidthSAVE;
2266
+
2267
+ function mobileActive(headerElement) {
2268
+
2269
+ //=== header
2270
+ let style = window.getComputedStyle(headerElement);
2271
+ let padding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
2272
+ let gap = parseFloat(style.gap);
2273
+ let headerElementWidth = parseInt(headerElement.offsetWidth - padding);
2274
+ let childsWidth;
2275
+
2276
+ if (menuAttivate) {
2277
+ childsWidth = childsWidthSAVE;
2278
+ } else {
2279
+ let childs = [];
2280
+
2281
+ // Esclude l'area mobile dedicata e l'hamburger, poi misura i figli sempre visibili su desktop.
2282
+ Array.from(headerElement.children)
2283
+ .filter(el => !pgs(el).contains("header-element-onlyMobile"))
2284
+ .forEach(child => {
2285
+ if (pgs(child).contains("header-element-hamburger")) return;
2286
+ childs.push(...child.children);
2287
+ });
2288
+
2289
+ gap = Math.round(gap * (childs.length - 1));
2290
+ let childsReduce = childs.reduce((totalWidth, child) => totalWidth + child.offsetWidth, 0) - 2;
2291
+
2292
+ childsWidth = childsReduce + gap;
2293
+ }
2294
+
2295
+ //===set data
2296
+ if (window.innerWidth < 600) {
2297
+ pgs(header).state.add("mobileActive");
2298
+ pgs(selectHeader).state.add("mobileActive");
2299
+ } else if (headerElementWidth < childsWidth) {
2300
+ pgs(header).state.add("mobileActive");
2301
+ pgs(headerElement).state.add("mobileActive");
2302
+ menuAttivate = true;
2303
+ childsWidthSAVE = childsWidth;
2304
+ } else {
2305
+ pgs(header).state.remove("mobileActive");
2306
+ pgs(headerElement).state.remove("mobileActive");
2307
+ }
2308
+ }
2309
+
2310
+ //== observer (throttled to avoid ResizeObserver loop warnings)
2311
+ let resizeRafId = 0;
2312
+ const scheduleMobileActive = () => {
2313
+ if (resizeRafId) return;
2314
+ resizeRafId = requestAnimationFrame(() => {
2315
+ resizeRafId = 0;
2316
+ mobileActive(selectHeader);
2317
+ });
2318
+ };
2319
+
2320
+ let observer = new ResizeObserver(scheduleMobileActive);
2321
+ observer.observe(selectHeader);
2322
+ scheduleMobileActive();
2323
+ });
2324
+
2325
+ // Ripristina la posizione dell'header quando si esce dalla modalità mobile
2326
+ window.addEventListener("resize", () => {
2327
+ if (window.innerWidth > 768) header.style.transform = "translateY(0)";
2328
+ });
2329
+ }
2330
+ PGS_header();
2331
+
2332
+
2333
+ //= HEADER HEIGHT
2334
+ function headerHeight() {
2335
+ if (!header) return;
2336
+ const wordPressBar = window.getComputedStyle(document.documentElement).marginTop ?? 0;
2337
+ const headerHeight = header.offsetHeight
2338
+ const height = headerHeight + parseInt(wordPressBar);
2339
+ const scrollHeight = document.querySelector("header").getAttribute("data-header-scroll") === "true" ? 0 : height;
2340
+
2341
+ document.documentElement.style.setProperty("--heightOfHeader", `${height}px`);
2342
+ document.documentElement.style.setProperty("--heightOfHeaderScroll", `${scrollHeight}px`);
2343
+ }
2344
+ headerHeight()
2345
+ window.addEventListener("resize", headerHeight);
2346
+ window.addEventListener("scroll", headerHeight);
2347
+
2348
+
2349
+
2350
+
2351
+ //= SCROLL
2352
+ // Nasconde l'header quando si scorre verso il basso e lo mostra quando si scorre verso l'alto su dispositivi con larghezza fino a 900px.
2353
+ let lastScrollY = window.scrollY;
2354
+ window.addEventListener("scroll", () => {
2355
+ if (!header) return;
2356
+ let currentScrollY = window.scrollY;
2357
+
2358
+ if (window.innerHeight <= 900) {
2359
+ if (currentScrollY >= 80) {
2360
+ if (currentScrollY > lastScrollY) {
2361
+ header.style.transform = "translateY(-100%)";
2362
+ header.setAttribute("data-header-scroll", true)
2363
+ } else {
2364
+ header.style.transform = "translateY(0px)";
2365
+ header.setAttribute("data-header-scroll", false)
2366
+ }
2367
+ } else {
2368
+ header.style.transform = "translateY(0)"; // Mostra sempre l'header se il scroll è inferiore a 80px
2369
+ header.setAttribute("data-header-scroll", false)
2370
+ }
2371
+ }
2372
+ lastScrollY = currentScrollY;
2373
+
2374
+ });
2375
+
2376
+
2377
+
2378
+
2379
+
2380
+
2381
+
2241
2382
  /***/ },
2242
2383
 
2243
2384
  /***/ "./assets/javascript/patterns/_cookieConsent.js"
@@ -2463,147 +2604,6 @@ if (document.readyState === 'loading') {
2463
2604
  }
2464
2605
 
2465
2606
 
2466
- /***/ },
2467
-
2468
- /***/ "./assets/javascript/patterns/_header.js"
2469
- /*!***********************************************!*\
2470
- !*** ./assets/javascript/patterns/_header.js ***!
2471
- \***********************************************/
2472
- () {
2473
-
2474
- //# HEADER
2475
- const header = pgs(document).querySelector("header");
2476
-
2477
- //= HEADER
2478
- function PGS_header(selectHeader = document) {
2479
-
2480
- if (!header) return;
2481
-
2482
- const headerElements = pgs(header).querySelectorAll("header-element");
2483
-
2484
- if (!headerElements.length) return;
2485
-
2486
- headerElements.forEach(selectHeader => {
2487
-
2488
- //== ACTIVE MOBILE
2489
- let menuAttivate = false;
2490
- let childsWidthSAVE;
2491
-
2492
- function mobileActive(headerElement) {
2493
-
2494
- //=== header
2495
- let style = window.getComputedStyle(headerElement);
2496
- let padding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
2497
- let gap = parseFloat(style.gap);
2498
- let headerElementWidth = parseInt(headerElement.offsetWidth - padding);
2499
- let childsWidth;
2500
-
2501
- if (menuAttivate) {
2502
- childsWidth = childsWidthSAVE;
2503
- } else {
2504
- let childs = [];
2505
-
2506
- // Esclude l'area mobile dedicata e l'hamburger, poi misura i figli sempre visibili su desktop.
2507
- Array.from(headerElement.children)
2508
- .filter(el => !pgs(el).contains("header-element-onlyMobile"))
2509
- .forEach(child => {
2510
- if (pgs(child).contains("header-element-hamburger")) return;
2511
- childs.push(...child.children);
2512
- });
2513
-
2514
- gap = Math.round(gap * (childs.length - 1));
2515
- let childsReduce = childs.reduce((totalWidth, child) => totalWidth + child.offsetWidth, 0) - 2;
2516
-
2517
- childsWidth = childsReduce + gap;
2518
- }
2519
-
2520
- //===set data
2521
- if (window.innerWidth < 600) {
2522
- pgs(header).state.add("mobileActive");
2523
- pgs(selectHeader).state.add("mobileActive");
2524
- } else if (headerElementWidth < childsWidth) {
2525
- pgs(header).state.add("mobileActive");
2526
- pgs(headerElement).state.add("mobileActive");
2527
- menuAttivate = true;
2528
- childsWidthSAVE = childsWidth;
2529
- } else {
2530
- pgs(header).state.remove("mobileActive");
2531
- pgs(headerElement).state.remove("mobileActive");
2532
- }
2533
- }
2534
-
2535
- //== observer (throttled to avoid ResizeObserver loop warnings)
2536
- let resizeRafId = 0;
2537
- const scheduleMobileActive = () => {
2538
- if (resizeRafId) return;
2539
- resizeRafId = requestAnimationFrame(() => {
2540
- resizeRafId = 0;
2541
- mobileActive(selectHeader);
2542
- });
2543
- };
2544
-
2545
- let observer = new ResizeObserver(scheduleMobileActive);
2546
- observer.observe(selectHeader);
2547
- scheduleMobileActive();
2548
- });
2549
-
2550
- // Ripristina la posizione dell'header quando si esce dalla modalità mobile
2551
- window.addEventListener("resize", () => {
2552
- if (window.innerWidth > 768) header.style.transform = "translateY(0)";
2553
- });
2554
- }
2555
- PGS_header();
2556
-
2557
-
2558
- //= HEADER HEIGHT
2559
- function headerHeight() {
2560
- if (!header) return;
2561
- const wordPressBar = window.getComputedStyle(document.documentElement).marginTop ?? 0;
2562
- const headerHeight = header.offsetHeight
2563
- const height = headerHeight + parseInt(wordPressBar);
2564
- const scrollHeight = document.querySelector("header").getAttribute("data-header-scroll") === "true" ? 0 : height;
2565
-
2566
- document.documentElement.style.setProperty("--heightOfHeader", `${height}px`);
2567
- document.documentElement.style.setProperty("--heightOfHeaderScroll", `${scrollHeight}px`);
2568
- }
2569
- headerHeight()
2570
- window.addEventListener("resize", headerHeight);
2571
- window.addEventListener("scroll", headerHeight);
2572
-
2573
-
2574
-
2575
-
2576
- //= SCROLL
2577
- // Nasconde l'header quando si scorre verso il basso e lo mostra quando si scorre verso l'alto su dispositivi con larghezza fino a 900px.
2578
- let lastScrollY = window.scrollY;
2579
- window.addEventListener("scroll", () => {
2580
- if (!header) return;
2581
- let currentScrollY = window.scrollY;
2582
-
2583
- if (window.innerHeight <= 900) {
2584
- if (currentScrollY >= 80) {
2585
- if (currentScrollY > lastScrollY) {
2586
- header.style.transform = "translateY(-100%)";
2587
- header.setAttribute("data-header-scroll", true)
2588
- } else {
2589
- header.style.transform = "translateY(0px)";
2590
- header.setAttribute("data-header-scroll", false)
2591
- }
2592
- } else {
2593
- header.style.transform = "translateY(0)"; // Mostra sempre l'header se il scroll è inferiore a 80px
2594
- header.setAttribute("data-header-scroll", false)
2595
- }
2596
- }
2597
- lastScrollY = currentScrollY;
2598
-
2599
- });
2600
-
2601
-
2602
-
2603
-
2604
-
2605
-
2606
-
2607
2607
  /***/ }
2608
2608
 
2609
2609
  /******/ });
@@ -2721,8 +2721,8 @@ __webpack_require__.r(__webpack_exports__);
2721
2721
  /* harmony import */ var _components_summary_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./components/_summary.js */ "./assets/javascript/components/_summary.js");
2722
2722
  /* harmony import */ var _components_notifications_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./components/_notifications.js */ "./assets/javascript/components/_notifications.js");
2723
2723
  /* harmony import */ var _imports_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./_imports.js */ "./assets/javascript/_imports.js");
2724
- /* harmony import */ var _patterns_header_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./patterns/_header.js */ "./assets/javascript/patterns/_header.js");
2725
- /* harmony import */ var _patterns_header_js__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(_patterns_header_js__WEBPACK_IMPORTED_MODULE_13__);
2724
+ /* harmony import */ var _layout_header_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./layout/_header.js */ "./assets/javascript/layout/_header.js");
2725
+ /* harmony import */ var _layout_header_js__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(_layout_header_js__WEBPACK_IMPORTED_MODULE_13__);
2726
2726
  /* harmony import */ var _patterns_cookieConsent_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./patterns/_cookieConsent.js */ "./assets/javascript/patterns/_cookieConsent.js");
2727
2727
  /* harmony import */ var _patterns_cookieConsent_js__WEBPACK_IMPORTED_MODULE_14___default = /*#__PURE__*/__webpack_require__.n(_patterns_cookieConsent_js__WEBPACK_IMPORTED_MODULE_14__);
2728
2728
  //= PGS
@@ -2747,9 +2747,11 @@ __webpack_require__.r(__webpack_exports__);
2747
2747
  //= IMPORT REGISTRY
2748
2748
 
2749
2749
 
2750
- //= PATTERNS
2750
+ //= LAYOUT
2751
2751
 
2752
2752
 
2753
+ //= PATTERNS
2754
+
2753
2755
 
2754
2756
  })();
2755
2757