wulf.js 0.0.0-stage → 1.8.4
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/LICENSE +21 -0
- package/README.md +870 -2
- package/changelog.md +291 -0
- package/dist/index.cjs.js +4247 -0
- package/dist/index.cjs.js.map +7 -0
- package/dist/index.esm.js +4230 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.global.js +4250 -0
- package/dist/index.global.js.map +7 -0
- package/dist/index.global.min.js +3 -0
- package/dist/index.global.min.js.map +7 -0
- package/dist/mask.cjs.js +2782 -0
- package/dist/mask.cjs.js.map +7 -0
- package/dist/mask.css +1 -0
- package/dist/mask.css.map +7 -0
- package/dist/mask.esm.js +2759 -0
- package/dist/mask.esm.js.map +7 -0
- package/dist/mask.global.js +2785 -0
- package/dist/mask.global.js.map +7 -0
- package/dist/mask.global.min.js +3 -0
- package/dist/mask.global.min.js.map +7 -0
- package/dist/masonry.cjs.js +572 -0
- package/dist/masonry.cjs.js.map +7 -0
- package/dist/masonry.css +1 -0
- package/dist/masonry.css.map +7 -0
- package/dist/masonry.esm.js +549 -0
- package/dist/masonry.esm.js.map +7 -0
- package/dist/masonry.global.js +575 -0
- package/dist/masonry.global.js.map +7 -0
- package/dist/masonry.global.min.js +3 -0
- package/dist/masonry.global.min.js.map +7 -0
- package/dist/scroll.cjs.js +500 -0
- package/dist/scroll.cjs.js.map +7 -0
- package/dist/scroll.css +1 -0
- package/dist/scroll.css.map +7 -0
- package/dist/scroll.esm.js +477 -0
- package/dist/scroll.esm.js.map +7 -0
- package/dist/scroll.global.js +503 -0
- package/dist/scroll.global.js.map +7 -0
- package/dist/scroll.global.min.js +3 -0
- package/dist/scroll.global.min.js.map +7 -0
- package/dist/toast.cjs.js +433 -0
- package/dist/toast.cjs.js.map +7 -0
- package/dist/toast.css +1 -0
- package/dist/toast.css.map +7 -0
- package/dist/toast.esm.js +410 -0
- package/dist/toast.esm.js.map +7 -0
- package/dist/toast.global.js +436 -0
- package/dist/toast.global.js.map +7 -0
- package/dist/toast.global.min.js +3 -0
- package/dist/toast.global.min.js.map +7 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/mask/AmountEngine.d.ts +72 -0
- package/dist/types/mask/BaseInputMask.d.ts +173 -0
- package/dist/types/mask/EmailEngine.d.ts +42 -0
- package/dist/types/mask/InputAmountMask.d.ts +70 -0
- package/dist/types/mask/InputEmailMask.d.ts +65 -0
- package/dist/types/mask/InputMask.d.ts +116 -0
- package/dist/types/mask/MaskEngine.d.ts +102 -0
- package/dist/types/mask/MaskHistory.d.ts +48 -0
- package/dist/types/mask/MaskKeyboard.d.ts +28 -0
- package/dist/types/mask/index.d.ts +28 -0
- package/dist/types/mask/types.d.ts +137 -0
- package/dist/types/masonry/LayoutEngine.d.ts +29 -0
- package/dist/types/masonry/Masonry.d.ts +63 -0
- package/dist/types/masonry/index.d.ts +7 -0
- package/dist/types/masonry/types.d.ts +125 -0
- package/dist/types/scroll/ScrollBlock.d.ts +94 -0
- package/dist/types/scroll/index.d.ts +8 -0
- package/dist/types/scroll/types.d.ts +76 -0
- package/dist/types/toast/Toast.d.ts +15 -0
- package/dist/types/toast/ToastInstance.d.ts +52 -0
- package/dist/types/toast/ToastManager.d.ts +34 -0
- package/dist/types/toast/index.d.ts +6 -0
- package/dist/types/toast/types.d.ts +68 -0
- package/package.json +99 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var Wulf=(()=>{var R=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var N=(u,t)=>{for(var e in t)R(u,e,{get:t[e],enumerable:!0})},G=(u,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!O.call(u,s)&&s!==e&&R(u,s,{get:()=>t[s],enumerable:!(r=W(t,s))||r.enumerable});return u};var B=u=>G(R({},"__esModule",{value:!0}),u);var _={};N(_,{LayoutEngine:()=>p,Masonry:()=>b,default:()=>$});var p=class{static parseGutter(t){return typeof t=="number"?{x:Math.max(0,t),y:Math.max(0,t)}:t&&typeof t=="object"?{x:Math.max(0,Number(t.x)||0),y:Math.max(0,Number(t.y)||0)}:{x:0,y:0}}static resolveColumnWidth(t,e,r){if(typeof r=="number"&&r>0)return r;if(typeof r=="string"){let i=t.querySelector(r);if(i){let n=i.getBoundingClientRect().width;if(n>0)return n}let o=parseFloat(r);if(!isNaN(o)&&o>0)return r.endsWith("%")?t.getBoundingClientRect().width*o/100:o}if(r instanceof HTMLElement){let i=r.getBoundingClientRect().width;if(i>0)return i}if(e){let i=e.getBoundingClientRect().width;if(i>0)return i}let s=t.getBoundingClientRect().width;return s>0?s:200}static getItemSpan(t,e,r,s){let i=t.getAttribute("data-masonry-span")||t.dataset.masonrySpan;if(i){let n=parseInt(i,10);if(!isNaN(n)&&n>0)return Math.min(s,n)}let o=t.className.match(/(?:^|\s)(?:span|col-span)-(\d+)(?:\s|$)/);if(o&&o[1]){let n=parseInt(o[1],10);if(!isNaN(n)&&n>0)return Math.min(s,n)}return 1}static calculate(t,e,r){let i=t.getBoundingClientRect().width,{x:o,y:n}=this.parseGutter(r.gutter);if(i<=0||e.length===0)return{cols:1,colWidth:i,gutterX:o,gutterY:n,containerHeight:0,containerWidth:i,positions:[]};let C=e[0]||null,y=this.resolveColumnWidth(t,C,r.columnWidth),l=Math.floor((i+o)/(y+o));l=Math.max(1,l),!r.columnWidth&&l>1&&(y=(i-(l-1)*o)/l);let T=r.fitWidth?l*y+(l-1)*o:void 0,f=new Array(l).fill(0),S=[],A=e.map(m=>{let g=m.getBoundingClientRect().height;return g>0?g:50}),w=0;for(let m=0;m<e.length;m++){let g=e[m],H=A[m],c=this.getItemSpan(g,y,o,l),d=0,v=0;if(r.horizontalOrder){w+c>l&&(w=0),d=w;let h=0;for(let a=0;a<c;a++)f[d+a]>h&&(h=f[d+a]);v=h,w=(d+c)%l}else if(c===1){let h=f[0];d=0;for(let a=1;a<l;a++)f[a]<h&&(h=f[a],d=a);v=h}else{let h=1/0;d=0;for(let a=0;a<=l-c;a++){let M=0;for(let I=0;I<c;I++)f[a+I]>M&&(M=f[a+I]);M<h&&(h=M,d=a)}v=h}let x=c*y+(c-1)*o,z=d*(y+o);S.push({element:g,x:z,y:v,width:x,height:H,column:d,span:c});let D=v+H+n;for(let h=0;h<c;h++)f[d+h]=D}let L=0;for(let m=0;m<l;m++)f[m]>L&&(L=f[m]);let E=Math.max(0,L>0?L-n:0);return{cols:l,colWidth:y,gutterX:o,gutterY:n,containerHeight:E,containerWidth:i,fittedWidth:T,positions:S}}};var b=class{constructor(t,e={}){this.isNativeCSSGrid=!1;this._items=[];this.resizeObserver=null;this.itemResizeObserver=null;this.layoutRafId=null;this.isDestroyed=!1;this.wasRoleInferred=!1;this.wasAriaLabelInferred=!1;this.removeTimers=new Set;this.pendingImageListeners=[];if(typeof t=="string"){let s=document.querySelector(t);if(!s)throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${t}"`);this.root=s}else if(t instanceof HTMLElement)this.root=t;else throw new Error("[Wulf.Masonry] Cible invalide : fournissez un \xE9l\xE9ment HTMLElement ou un s\xE9lecteur valide.");this.originalContainerStyles={height:this.root.style.height,width:this.root.style.width},this.options={itemSelector:e.itemSelector||"> *",columnWidth:e.columnWidth??0,gutter:e.gutter??0,percentPosition:e.percentPosition!==!1,fitWidth:!!e.fitWidth,horizontalOrder:!!e.horizontalOrder,transitionDuration:e.transitionDuration!==void 0?e.transitionDuration:300,stagger:e.stagger||0,resize:e.resize!==!1,autoImages:e.autoImages!==!1,useNativeCSSGrid:e.useNativeCSSGrid!==!1,ariaRole:e.ariaRole||"region",ariaLabel:e.ariaLabel||"Galerie en grille asym\xE9trique",onLayout:e.onLayout||(()=>{}),onItemPlaced:e.onItemPlaced||(()=>{})};let r=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("grid-template-rows","masonry");this.options.useNativeCSSGrid&&r?(this.isNativeCSSGrid=!0,this.root.classList.add("wulf-masonry","wulf-masonry--native")):this.root.classList.add("wulf-masonry"),this.initAccessibility(),this.applyTransitionDuration(),this.reloadItems(),this.initObservers(),this.initImages(),this.layout()}get items(){return[...this._items]}initAccessibility(){this.options.ariaRole&&!this.root.hasAttribute("role")&&(this.root.setAttribute("role",this.options.ariaRole),this.wasRoleInferred=!0),this.options.ariaLabel&&!this.root.hasAttribute("aria-label")&&(this.root.setAttribute("aria-label",this.options.ariaLabel),this.wasAriaLabelInferred=!0)}applyTransitionDuration(){let t=this.options.transitionDuration,e=typeof t=="number"?`${t}ms`:t;this.root.style.setProperty("--wulf-masonry-duration",e)}reloadItems(){if(this.isDestroyed)return;let t=[];if(this.options.itemSelector==="> *")t=Array.from(this.root.children).filter(e=>e instanceof HTMLElement&&!e.hasAttribute("data-masonry-ignore"));else try{t=Array.from(this.root.querySelectorAll(this.options.itemSelector)).filter(e=>e.parentElement===this.root&&!e.hasAttribute("data-masonry-ignore"))}catch{t=Array.from(this.root.children).filter(e=>e instanceof HTMLElement&&!e.hasAttribute("data-masonry-ignore"))}this._items=t;for(let e of this._items)e.classList.add("wulf-masonry-item"),this.itemResizeObserver&&this.itemResizeObserver.observe(e)}initObservers(){if(!this.options.resize||typeof ResizeObserver>"u")return;let t=this.root.getBoundingClientRect().width;this.resizeObserver=new ResizeObserver(e=>{for(let r of e){let s=r.contentRect.width;Math.abs(s-t)>=1&&(t=s,this.scheduleLayout())}}),this.resizeObserver.observe(this.root),this.itemResizeObserver=new ResizeObserver(()=>{this.scheduleLayout()});for(let e of this._items)this.itemResizeObserver.observe(e)}initImages(){if(!this.options.autoImages)return;let t=Array.from(this.root.querySelectorAll("img"));for(let e of t)if(!e.complete){let r=()=>{let s=()=>{this.pendingImageListeners=this.pendingImageListeners.filter(i=>i.handler!==s),this.isDestroyed||this.scheduleLayout()};this.pendingImageListeners.push({img:e,handler:s}),e.addEventListener("load",s,{once:!0})};typeof e.decode=="function"?e.decode().then(()=>{this.isDestroyed||this.scheduleLayout()}).catch(()=>{r()}):r()}}scheduleLayout(){this.isDestroyed||(this.layoutRafId!==null&&cancelAnimationFrame(this.layoutRafId),this.layoutRafId=requestAnimationFrame(()=>{this.layoutRafId=null,this.layout()}))}layout(){if(this.isDestroyed)return;if(this.isNativeCSSGrid){this.options.onLayout([]);return}this.root.setAttribute("aria-busy","true");let t=p.calculate(this.root,this._items,this.options);this.root.style.height=`${t.containerHeight}px`,this.options.fitWidth&&t.fittedWidth!==void 0?(this.root.style.width=`${t.fittedWidth}px`,this.root.classList.add("wulf-masonry--fit-width")):this.root.classList.remove("wulf-masonry--fit-width");let e=this.options.stagger;for(let r=0;r<t.positions.length;r++){let s=t.positions[r],i=s.element;i.style.setProperty("--wulf-masonry-w",`${s.width}px`),i.style.setProperty("--wulf-masonry-x",`${s.x}px`),i.style.setProperty("--wulf-masonry-y",`${s.y}px`),e>0?i.style.transitionDelay=`${r*e}ms`:i.style.removeProperty("transition-delay"),i.classList.remove("wulf-masonry-item--hidden"),this.options.onItemPlaced(i,s)}this.root.setAttribute("aria-busy","false"),this.options.onLayout(t.positions)}append(t){if(this.isDestroyed)return;let e=Array.isArray(t)?t:[t];if(e.length===0)return;let r=document.createDocumentFragment();for(let s of e)s.classList.add("wulf-masonry-item","wulf-masonry-item--hidden"),r.appendChild(s);this.root.appendChild(r),this.reloadItems(),this.initImages(),this.layout()}prepend(t){if(this.isDestroyed)return;let e=Array.isArray(t)?t:[t];if(e.length===0)return;let r=this.root.firstChild,s=document.createDocumentFragment();for(let i of e)i.classList.add("wulf-masonry-item","wulf-masonry-item--hidden"),s.appendChild(i);this.root.insertBefore(s,r),this.reloadItems(),this.initImages(),this.layout()}remove(t){if(this.isDestroyed)return;let e=Array.isArray(t)?t:[t];if(e.length===0)return;for(let i of e)i.classList.add("wulf-masonry-item--hidden");let r=typeof this.options.transitionDuration=="number"?this.options.transitionDuration:300;if(r<=0){for(let i of e)i.parentElement===this.root&&(this.itemResizeObserver&&this.itemResizeObserver.unobserve(i),this.root.removeChild(i));this.reloadItems(),this.layout();return}let s=window.setTimeout(()=>{if(this.removeTimers.delete(s),!this.isDestroyed){for(let i of e)i.parentElement===this.root&&(this.itemResizeObserver&&this.itemResizeObserver.unobserve(i),this.root.removeChild(i));this.reloadItems(),this.layout()}},r);this.removeTimers.add(s)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(let t of this.removeTimers)clearTimeout(t);this.removeTimers.clear();for(let{img:t,handler:e}of this.pendingImageListeners)t.removeEventListener("load",e);this.pendingImageListeners=[],this.layoutRafId!==null&&(cancelAnimationFrame(this.layoutRafId),this.layoutRafId=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.itemResizeObserver&&(this.itemResizeObserver.disconnect(),this.itemResizeObserver=null),this.root.classList.remove("wulf-masonry","wulf-masonry--native","wulf-masonry--fit-width"),this.root.removeAttribute("aria-busy"),this.wasRoleInferred&&this.root.getAttribute("role")===this.options.ariaRole&&this.root.removeAttribute("role"),this.wasAriaLabelInferred&&this.root.getAttribute("aria-label")===this.options.ariaLabel&&this.root.removeAttribute("aria-label"),this.root.style.removeProperty("--wulf-masonry-duration"),this.originalContainerStyles.height?this.root.style.height=this.originalContainerStyles.height:this.root.style.removeProperty("height"),this.originalContainerStyles.width?this.root.style.width=this.originalContainerStyles.width:this.root.style.removeProperty("width");for(let t of this._items)t.classList.remove("wulf-masonry-item","wulf-masonry-item--hidden"),t.style.removeProperty("--wulf-masonry-w"),t.style.removeProperty("--wulf-masonry-x"),t.style.removeProperty("--wulf-masonry-y"),t.style.removeProperty("transition-delay");this._items=[]}}};var $=b;if(typeof window<"u"){let u=window,t=u.Wulf||{};u.Wulf=t,t.Masonry=Object.assign(b,{Masonry:b,LayoutEngine:p})}return B(_);})();
|
|
2
|
+
if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
|
|
3
|
+
//# sourceMappingURL=masonry.global.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/masonry/index.ts", "../src/masonry/LayoutEngine.ts", "../src/masonry/Masonry.ts"],
|
|
4
|
+
"sourcesContent": ["import { Masonry } from './Masonry';\nimport { LayoutEngine } from './LayoutEngine';\n\nexport * from './types';\nexport * from './LayoutEngine';\nexport * from './Masonry';\n\nexport { Masonry, LayoutEngine };\nexport default Masonry;\n\n// Attachement namespace global dans les environnements de navigation (IIFE / Vanilla)\nif (typeof window !== 'undefined') {\n const win = window as unknown as Record<string, unknown>;\n const wulfNamespace = ((win.Wulf as Record<string, unknown>) || {}) as Record<string, unknown>;\n win.Wulf = wulfNamespace;\n\n // Namespace sp\u00E9cifique et exclusif \u00E0 la librairie Masonry : Wulf.Masonry\n wulfNamespace.Masonry = Object.assign(Masonry, {\n Masonry,\n LayoutEngine\n });\n}\n", "import { MasonryGutter, MasonryItemPosition, MasonryOptions } from './types';\n\nexport interface LayoutCalculationResult {\n cols: number;\n colWidth: number;\n gutterX: number;\n gutterY: number;\n containerHeight: number;\n containerWidth: number;\n fittedWidth?: number;\n positions: MasonryItemPosition[];\n}\n\nexport class LayoutEngine {\n /**\n * Normalise les goutti\u00E8res horizontales et verticales.\n */\n public static parseGutter(gutterOption?: number | MasonryGutter): MasonryGutter {\n if (typeof gutterOption === 'number') {\n return { x: Math.max(0, gutterOption), y: Math.max(0, gutterOption) };\n }\n if (gutterOption && typeof gutterOption === 'object') {\n return {\n x: Math.max(0, Number(gutterOption.x) || 0),\n y: Math.max(0, Number(gutterOption.y) || 0)\n };\n }\n return { x: 0, y: 0 };\n }\n\n /**\n * R\u00E9sout la largeur effective d'une colonne en pixels.\n */\n public static resolveColumnWidth(\n container: HTMLElement,\n firstItem: HTMLElement | null,\n columnWidthOption?: number | string | HTMLElement\n ): number {\n if (typeof columnWidthOption === 'number' && columnWidthOption > 0) {\n return columnWidthOption;\n }\n\n if (typeof columnWidthOption === 'string') {\n const el = container.querySelector<HTMLElement>(columnWidthOption);\n if (el) {\n const w = el.getBoundingClientRect().width;\n if (w > 0) return w;\n }\n const parsed = parseFloat(columnWidthOption);\n if (!isNaN(parsed) && parsed > 0) {\n if (columnWidthOption.endsWith('%')) {\n const containerW = container.getBoundingClientRect().width;\n return (containerW * parsed) / 100;\n }\n return parsed;\n }\n }\n\n if (columnWidthOption instanceof HTMLElement) {\n const w = columnWidthOption.getBoundingClientRect().width;\n if (w > 0) return w;\n }\n\n if (firstItem) {\n const w = firstItem.getBoundingClientRect().width;\n if (w > 0) return w;\n }\n\n const containerW = container.getBoundingClientRect().width;\n return containerW > 0 ? containerW : 200;\n }\n\n /**\n * Extrait le facteur d'\u00E9talement (span) d'un item sur plusieurs colonnes.\n */\n public static getItemSpan(item: HTMLElement, colWidth: number, gutterX: number, maxCols: number): number {\n const dataSpan = item.getAttribute('data-masonry-span') || item.dataset.masonrySpan;\n if (dataSpan) {\n const parsed = parseInt(dataSpan, 10);\n if (!isNaN(parsed) && parsed > 0) {\n return Math.min(maxCols, parsed);\n }\n }\n\n // D\u00E9tection par classe utilitaire (ex: span-2, col-span-2)\n const match = item.className.match(/(?:^|\\s)(?:span|col-span)-(\\d+)(?:\\s|$)/);\n if (match && match[1]) {\n const parsed = parseInt(match[1], 10);\n if (!isNaN(parsed) && parsed > 0) {\n return Math.min(maxCols, parsed);\n }\n }\n\n return 1;\n }\n\n /**\n * Calcule les positions optimales de tous les items.\n */\n public static calculate(\n container: HTMLElement,\n items: HTMLElement[],\n options: MasonryOptions\n ): LayoutCalculationResult {\n const containerRect = container.getBoundingClientRect();\n const containerWidth = containerRect.width;\n const { x: gutterX, y: gutterY } = this.parseGutter(options.gutter);\n\n if (containerWidth <= 0 || items.length === 0) {\n return {\n cols: 1,\n colWidth: containerWidth,\n gutterX,\n gutterY,\n containerHeight: 0,\n containerWidth,\n positions: []\n };\n }\n\n const firstItem = items[0] || null;\n let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);\n\n // Calcul du nombre de colonnes possibles\n // (cols * colWidth) + (cols - 1) * gutterX <= containerWidth\n let cols = Math.floor((containerWidth + gutterX) / (colWidth + gutterX));\n cols = Math.max(1, cols);\n\n // Si percentPosition ou fitWidth, ajustement pr\u00E9cis de la largeur de colonne pour remplir l'espace\n if (!options.columnWidth && cols > 1) {\n colWidth = (containerWidth - (cols - 1) * gutterX) / cols;\n }\n\n const fittedWidth = options.fitWidth ? cols * colWidth + (cols - 1) * gutterX : undefined;\n\n // Tableau de suivi des hauteurs cumul\u00E9es pour chaque colonne\n const colHeights = new Array(cols).fill(0);\n const positions: MasonryItemPosition[] = [];\n\n // Mesure par lot pr\u00E9alable (Batch Read) de toutes les hauteurs d'items pour \u00E9viter le layout thrashing\n const itemHeights = items.map((item) => {\n // Si l'\u00E9l\u00E9ment a d\u00E9j\u00E0 une hauteur calcul\u00E9e\n const h = item.getBoundingClientRect().height;\n return h > 0 ? h : 50;\n });\n\n let currentHCol = 0; // Pointeur pour le mode horizontalOrder\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const itemH = itemHeights[i];\n const span = this.getItemSpan(item, colWidth, gutterX, cols);\n\n let targetCol = 0;\n let targetY = 0;\n\n if (options.horizontalOrder) {\n // Mode respectant l'ordre naturel gauche -> droite\n if (currentHCol + span > cols) {\n currentHCol = 0;\n }\n targetCol = currentHCol;\n\n // Calcul de la hauteur maximale sous le span requis\n let maxY = 0;\n for (let s = 0; s < span; s++) {\n if (colHeights[targetCol + s] > maxY) {\n maxY = colHeights[targetCol + s];\n }\n }\n targetY = maxY;\n currentHCol = (targetCol + span) % cols;\n } else {\n // Mode shortest-column classique (optimisation de tassement)\n if (span === 1) {\n let minH = colHeights[0];\n targetCol = 0;\n for (let c = 1; c < cols; c++) {\n if (colHeights[c] < minH) {\n minH = colHeights[c];\n targetCol = c;\n }\n }\n targetY = minH;\n } else {\n // Pour un item multi-colonnes, trouve le groupe de colonnes cons\u00E9cutives dont le max est minimal\n let bestMax = Infinity;\n targetCol = 0;\n for (let c = 0; c <= cols - span; c++) {\n let maxInSpan = 0;\n for (let s = 0; s < span; s++) {\n if (colHeights[c + s] > maxInSpan) {\n maxInSpan = colHeights[c + s];\n }\n }\n if (maxInSpan < bestMax) {\n bestMax = maxInSpan;\n targetCol = c;\n }\n }\n targetY = bestMax;\n }\n }\n\n const itemW = span * colWidth + (span - 1) * gutterX;\n const targetX = targetCol * (colWidth + gutterX);\n\n positions.push({\n element: item,\n x: targetX,\n y: targetY,\n width: itemW,\n height: itemH,\n column: targetCol,\n span\n });\n\n // Mise \u00E0 jour des hauteurs pour toutes les colonnes occup\u00E9es par ce span\n const nextY = targetY + itemH + gutterY;\n for (let s = 0; s < span; s++) {\n colHeights[targetCol + s] = nextY;\n }\n }\n\n // Hauteur totale du conteneur (la plus haute colonne, moins la derni\u00E8re marge)\n let maxColH = 0;\n for (let c = 0; c < cols; c++) {\n if (colHeights[c] > maxColH) {\n maxColH = colHeights[c];\n }\n }\n const containerHeight = Math.max(0, maxColH > 0 ? maxColH - gutterY : 0);\n\n return {\n cols,\n colWidth,\n gutterX,\n gutterY,\n containerHeight,\n containerWidth,\n fittedWidth,\n positions\n };\n }\n}\n", "import { IMasonry, MasonryItemPosition, MasonryOptions } from './types';\nimport { LayoutEngine } from './LayoutEngine';\n\nexport class Masonry implements IMasonry {\n public readonly root: HTMLElement;\n public readonly isNativeCSSGrid: boolean = false;\n private _items: HTMLElement[] = [];\n private options: Required<MasonryOptions>;\n\n private resizeObserver: ResizeObserver | null = null;\n private itemResizeObserver: ResizeObserver | null = null;\n private layoutRafId: number | null = null;\n private isDestroyed: boolean = false;\n private wasRoleInferred: boolean = false;\n private wasAriaLabelInferred: boolean = false;\n private removeTimers: Set<number> = new Set();\n private pendingImageListeners: Array<{ img: HTMLImageElement; handler: () => void }> = [];\n\n private originalContainerStyles: {\n height: string;\n width: string;\n };\n\n constructor(target: HTMLElement | string, options: MasonryOptions = {}) {\n if (typeof target === 'string') {\n const el = document.querySelector<HTMLElement>(target);\n if (!el) {\n throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\u00E9lecteur : \"${target}\"`);\n }\n this.root = el;\n } else if (target instanceof HTMLElement) {\n this.root = target;\n } else {\n throw new Error('[Wulf.Masonry] Cible invalide : fournissez un \u00E9l\u00E9ment HTMLElement ou un s\u00E9lecteur valide.');\n }\n\n // Sauvegarde des styles initiaux pour destruction propre\n this.originalContainerStyles = {\n height: this.root.style.height,\n width: this.root.style.width\n };\n\n // Fusion avec les options par d\u00E9faut\n this.options = {\n itemSelector: options.itemSelector || '> *',\n columnWidth: options.columnWidth ?? 0,\n gutter: options.gutter ?? 0,\n percentPosition: options.percentPosition !== false,\n fitWidth: Boolean(options.fitWidth),\n horizontalOrder: Boolean(options.horizontalOrder),\n transitionDuration: options.transitionDuration !== undefined ? options.transitionDuration : 300,\n stagger: options.stagger || 0,\n resize: options.resize !== false,\n autoImages: options.autoImages !== false,\n useNativeCSSGrid: options.useNativeCSSGrid !== false,\n ariaRole: options.ariaRole || 'region',\n ariaLabel: options.ariaLabel || 'Galerie en grille asym\u00E9trique',\n onLayout: options.onLayout || (() => {}),\n onItemPlaced: options.onItemPlaced || (() => {})\n };\n\n // D\u00E9tection de la compatibilit\u00E9 CSS Grid Level 3 masonry\n const supportsNativeCSS =\n typeof CSS !== 'undefined' &&\n typeof CSS.supports === 'function' &&\n CSS.supports('grid-template-rows', 'masonry');\n\n if (this.options.useNativeCSSGrid && supportsNativeCSS) {\n this.isNativeCSSGrid = true;\n this.root.classList.add('wulf-masonry', 'wulf-masonry--native');\n } else {\n this.root.classList.add('wulf-masonry');\n }\n\n this.initAccessibility();\n this.applyTransitionDuration();\n this.reloadItems();\n this.initObservers();\n this.initImages();\n\n // Premier calcul de disposition\n this.layout();\n }\n\n public get items(): HTMLElement[] {\n return [...this._items];\n }\n\n /**\n * Initialise les attributs WAI-ARIA du conteneur.\n */\n private initAccessibility(): void {\n if (this.options.ariaRole && !this.root.hasAttribute('role')) {\n this.root.setAttribute('role', this.options.ariaRole);\n this.wasRoleInferred = true;\n }\n if (this.options.ariaLabel && !this.root.hasAttribute('aria-label')) {\n this.root.setAttribute('aria-label', this.options.ariaLabel);\n this.wasAriaLabelInferred = true;\n }\n }\n\n /**\n * Configure les variables CSS de transition sur le conteneur.\n */\n private applyTransitionDuration(): void {\n const dur = this.options.transitionDuration;\n const durValue = typeof dur === 'number' ? `${dur}ms` : dur;\n this.root.style.setProperty('--wulf-masonry-duration', durValue);\n }\n\n /**\n * R\u00E9indexe les \u00E9l\u00E9ments enfants cibl\u00E9s par la disposition.\n */\n public reloadItems(): void {\n if (this.isDestroyed) return;\n\n let matched: HTMLElement[] = [];\n if (this.options.itemSelector === '> *') {\n matched = Array.from(this.root.children).filter(\n (el): el is HTMLElement => el instanceof HTMLElement && !el.hasAttribute('data-masonry-ignore')\n );\n } else {\n try {\n matched = Array.from(this.root.querySelectorAll<HTMLElement>(this.options.itemSelector)).filter(\n (el) => el.parentElement === this.root && !el.hasAttribute('data-masonry-ignore')\n );\n } catch {\n matched = Array.from(this.root.children).filter(\n (el): el is HTMLElement => el instanceof HTMLElement && !el.hasAttribute('data-masonry-ignore')\n );\n }\n }\n\n this._items = matched;\n\n // Association de la classe d'item et observation\n for (const item of this._items) {\n item.classList.add('wulf-masonry-item');\n if (this.itemResizeObserver) {\n this.itemResizeObserver.observe(item);\n }\n }\n }\n\n /**\n * Active ResizeObserver sur le conteneur et les \u00E9l\u00E9ments individuels.\n */\n private initObservers(): void {\n if (!this.options.resize || typeof ResizeObserver === 'undefined') return;\n\n // Surveillance de la largeur du conteneur\n let prevWidth = this.root.getBoundingClientRect().width;\n this.resizeObserver = new ResizeObserver((entries) => {\n for (const entry of entries) {\n const currentWidth = entry.contentRect.width;\n if (Math.abs(currentWidth - prevWidth) >= 1) {\n prevWidth = currentWidth;\n this.scheduleLayout();\n }\n }\n });\n this.resizeObserver.observe(this.root);\n\n // Surveillance des changements de hauteur internes des items\n this.itemResizeObserver = new ResizeObserver(() => {\n this.scheduleLayout();\n });\n\n for (const item of this._items) {\n this.itemResizeObserver.observe(item);\n }\n }\n\n /**\n * D\u00E9tecte les balises <img> sans dimensions pr\u00E9d\u00E9finies et attend leur d\u00E9codage/chargement.\n */\n private initImages(): void {\n if (!this.options.autoImages) return;\n\n const images = Array.from(this.root.querySelectorAll<HTMLImageElement>('img'));\n for (const img of images) {\n if (!img.complete) {\n const attachLoadListener = () => {\n const onLoad = () => {\n this.pendingImageListeners = this.pendingImageListeners.filter((l) => l.handler !== onLoad);\n if (!this.isDestroyed) this.scheduleLayout();\n };\n this.pendingImageListeners.push({ img, handler: onLoad });\n img.addEventListener('load', onLoad, { once: true });\n };\n\n if (typeof img.decode === 'function') {\n img.decode().then(() => {\n if (!this.isDestroyed) this.scheduleLayout();\n }).catch(() => {\n attachLoadListener();\n });\n } else {\n attachLoadListener();\n }\n }\n }\n }\n\n /**\n * Planifie un recalcul au prochain tick d'animation via requestAnimationFrame.\n */\n private scheduleLayout(): void {\n if (this.isDestroyed) return;\n if (this.layoutRafId !== null) {\n cancelAnimationFrame(this.layoutRafId);\n }\n this.layoutRafId = requestAnimationFrame(() => {\n this.layoutRafId = null;\n this.layout();\n });\n }\n\n /**\n * Calcule et applique les nouvelles coordonn\u00E9es GPU de chaque item.\n */\n public layout(): void {\n if (this.isDestroyed) return;\n\n // Si d\u00E9l\u00E9gation native CSS active, pas de positionnement JS requis\n if (this.isNativeCSSGrid) {\n this.options.onLayout([]);\n return;\n }\n\n this.root.setAttribute('aria-busy', 'true');\n\n // \u00C9tape 1 : Lecture group\u00E9e (Batch Read via LayoutEngine)\n const result = LayoutEngine.calculate(this.root, this._items, this.options);\n\n // \u00C9tape 2 : \u00C9criture group\u00E9e (Batch Write)\n this.root.style.height = `${result.containerHeight}px`;\n\n if (this.options.fitWidth && result.fittedWidth !== undefined) {\n this.root.style.width = `${result.fittedWidth}px`;\n this.root.classList.add('wulf-masonry--fit-width');\n } else {\n this.root.classList.remove('wulf-masonry--fit-width');\n }\n\n const stagger = this.options.stagger;\n\n for (let i = 0; i < result.positions.length; i++) {\n const pos = result.positions[i];\n const item = pos.element;\n\n item.style.setProperty('--wulf-masonry-w', `${pos.width}px`);\n item.style.setProperty('--wulf-masonry-x', `${pos.x}px`);\n item.style.setProperty('--wulf-masonry-y', `${pos.y}px`);\n\n if (stagger > 0) {\n item.style.transitionDelay = `${i * stagger}ms`;\n } else {\n item.style.removeProperty('transition-delay');\n }\n\n item.classList.remove('wulf-masonry-item--hidden');\n this.options.onItemPlaced(item, pos);\n }\n\n this.root.setAttribute('aria-busy', 'false');\n this.options.onLayout(result.positions);\n }\n\n /**\n * Ajoute de nouveaux \u00E9l\u00E9ments \u00E0 la fin du conteneur.\n */\n public append(elements: HTMLElement | HTMLElement[]): void {\n if (this.isDestroyed) return;\n const list = Array.isArray(elements) ? elements : [elements];\n if (list.length === 0) return;\n\n const frag = document.createDocumentFragment();\n for (const el of list) {\n el.classList.add('wulf-masonry-item', 'wulf-masonry-item--hidden');\n frag.appendChild(el);\n }\n this.root.appendChild(frag);\n\n this.reloadItems();\n this.initImages();\n this.layout();\n }\n\n /**\n * Ajoute de nouveaux \u00E9l\u00E9ments au d\u00E9but du conteneur.\n */\n public prepend(elements: HTMLElement | HTMLElement[]): void {\n if (this.isDestroyed) return;\n const list = Array.isArray(elements) ? elements : [elements];\n if (list.length === 0) return;\n\n const first = this.root.firstChild;\n const frag = document.createDocumentFragment();\n for (const el of list) {\n el.classList.add('wulf-masonry-item', 'wulf-masonry-item--hidden');\n frag.appendChild(el);\n }\n this.root.insertBefore(frag, first);\n\n this.reloadItems();\n this.initImages();\n this.layout();\n }\n\n /**\n * Supprime des \u00E9l\u00E9ments avec animation de fondu/sortie.\n */\n public remove(elements: HTMLElement | HTMLElement[]): void {\n if (this.isDestroyed) return;\n const list = Array.isArray(elements) ? elements : [elements];\n if (list.length === 0) return;\n\n for (const el of list) {\n el.classList.add('wulf-masonry-item--hidden');\n }\n\n const dur = typeof this.options.transitionDuration === 'number' ? this.options.transitionDuration : 300;\n\n if (dur <= 0) {\n for (const el of list) {\n if (el.parentElement === this.root) {\n if (this.itemResizeObserver) {\n this.itemResizeObserver.unobserve(el);\n }\n this.root.removeChild(el);\n }\n }\n this.reloadItems();\n this.layout();\n return;\n }\n\n const timerId = window.setTimeout(() => {\n this.removeTimers.delete(timerId);\n if (this.isDestroyed) return;\n for (const el of list) {\n if (el.parentElement === this.root) {\n if (this.itemResizeObserver) {\n this.itemResizeObserver.unobserve(el);\n }\n this.root.removeChild(el);\n }\n }\n this.reloadItems();\n this.layout();\n }, dur);\n this.removeTimers.add(timerId);\n }\n\n /**\n * Lib\u00E8re les ressources, d\u00E9connecte les observateurs et nettoie les styles inject\u00E9s.\n */\n public destroy(): void {\n if (this.isDestroyed) return;\n this.isDestroyed = true;\n\n for (const timerId of this.removeTimers) {\n clearTimeout(timerId);\n }\n this.removeTimers.clear();\n\n for (const { img, handler } of this.pendingImageListeners) {\n img.removeEventListener('load', handler);\n }\n this.pendingImageListeners = [];\n\n if (this.layoutRafId !== null) {\n cancelAnimationFrame(this.layoutRafId);\n this.layoutRafId = null;\n }\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n }\n\n if (this.itemResizeObserver) {\n this.itemResizeObserver.disconnect();\n this.itemResizeObserver = null;\n }\n\n // Nettoyage des classes et attributs sur le conteneur\n this.root.classList.remove('wulf-masonry', 'wulf-masonry--native', 'wulf-masonry--fit-width');\n this.root.removeAttribute('aria-busy');\n if (this.wasRoleInferred && this.root.getAttribute('role') === this.options.ariaRole) {\n this.root.removeAttribute('role');\n }\n if (this.wasAriaLabelInferred && this.root.getAttribute('aria-label') === this.options.ariaLabel) {\n this.root.removeAttribute('aria-label');\n }\n this.root.style.removeProperty('--wulf-masonry-duration');\n\n if (this.originalContainerStyles.height) {\n this.root.style.height = this.originalContainerStyles.height;\n } else {\n this.root.style.removeProperty('height');\n }\n\n if (this.originalContainerStyles.width) {\n this.root.style.width = this.originalContainerStyles.width;\n } else {\n this.root.style.removeProperty('width');\n }\n\n // Nettoyage des styles sur les items\n for (const item of this._items) {\n item.classList.remove('wulf-masonry-item', 'wulf-masonry-item--hidden');\n item.style.removeProperty('--wulf-masonry-w');\n item.style.removeProperty('--wulf-masonry-x');\n item.style.removeProperty('--wulf-masonry-y');\n item.style.removeProperty('transition-delay');\n }\n\n this._items = [];\n }\n}\n\nexport default Masonry;\n"],
|
|
5
|
+
"mappings": "wbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,YAAAC,EAAA,YAAAC,ICaO,IAAMC,EAAN,KAAmB,CAIxB,OAAc,YAAYC,EAAsD,CAC9E,OAAI,OAAOA,GAAiB,SACnB,CAAE,EAAG,KAAK,IAAI,EAAGA,CAAY,EAAG,EAAG,KAAK,IAAI,EAAGA,CAAY,CAAE,EAElEA,GAAgB,OAAOA,GAAiB,SACnC,CACL,EAAG,KAAK,IAAI,EAAG,OAAOA,EAAa,CAAC,GAAK,CAAC,EAC1C,EAAG,KAAK,IAAI,EAAG,OAAOA,EAAa,CAAC,GAAK,CAAC,CAC5C,EAEK,CAAE,EAAG,EAAG,EAAG,CAAE,CACtB,CAKA,OAAc,mBACZC,EACAC,EACAC,EACQ,CACR,GAAI,OAAOA,GAAsB,UAAYA,EAAoB,EAC/D,OAAOA,EAGT,GAAI,OAAOA,GAAsB,SAAU,CACzC,IAA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A,EAAK,MAAM,eAAe,kBAAkB,EAG9C,KAAK,OAAS,CAAC,EACjB,CACF,EF9ZA,IAAOqB,EAAQC,EAGf,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMC,EAAM,OACNC,EAAkBD,EAAI,MAAoC,CAAC,EACjEA,EAAI,KAAOC,EAGXA,EAAc,QAAU,OAAO,OAAOF,EAAS,CAC7C,QAAAA,EACA,aAAAG,CACF,CAAC,CACH",
|
|
6
|
+
"names": ["index_exports", "__export", "LayoutEngine", "Masonry", "index_default", "LayoutEngine", "gutterOption", "container", "firstItem", "columnWidthOption", "el", "w", "parsed", "containerW", "item", "colWidth", "gutterX", "maxCols", "dataSpan", "match", "items", "options", "containerWidth", "gutterY", "cols", "fittedWidth", "colHeights", "positions", "itemHeights", "h", "currentHCol", "i", "itemH", "span", "targetCol", "targetY", "maxY", "s", "minH", "c", "bestMax", "maxInSpan", "itemW", "targetX", "nextY", "maxColH", "containerHeight", "Masonry", "target", "options", "el", "supportsNativeCSS", "dur", "durValue", "matched", "item", "prevWidth", "entries", "entry", "currentWidth", "images", "img", "attachLoadListener", "onLoad", "l", "result", "LayoutEngine", "stagger", "i", "pos", "elements", "list", "frag", "first", "timerId", "handler", "index_default", "Masonry", "win", "wulfNamespace", "LayoutEngine"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/scroll/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Scroll: () => Scroll,
|
|
24
|
+
ScrollBlock: () => ScrollBlock,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/scroll/ScrollBlock.ts
|
|
30
|
+
var idCounter = 0;
|
|
31
|
+
var ScrollBlock = class {
|
|
32
|
+
constructor(element, options) {
|
|
33
|
+
this.createdViewport = false;
|
|
34
|
+
this.isDragging = false;
|
|
35
|
+
this.dragStartPos = 0;
|
|
36
|
+
this.dragStartScroll = 0;
|
|
37
|
+
this.atBottom = false;
|
|
38
|
+
this.atTop = true;
|
|
39
|
+
this.atRight = false;
|
|
40
|
+
this.atLeft = true;
|
|
41
|
+
const resolvedElement = typeof element === "string" ? document.querySelector(element) : element;
|
|
42
|
+
if (!resolvedElement) {
|
|
43
|
+
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
44
|
+
}
|
|
45
|
+
this.root = resolvedElement;
|
|
46
|
+
this.options = {
|
|
47
|
+
axis: options?.axis || "y",
|
|
48
|
+
autoHide: options?.autoHide ?? true,
|
|
49
|
+
autoHideDelay: options?.autoHideDelay ?? 1e3,
|
|
50
|
+
alwaysVisible: options?.alwaysVisible ?? false,
|
|
51
|
+
ariaLabel: options?.ariaLabel || "Zone de contenu d\xE9filable",
|
|
52
|
+
minThumbSize: options?.minThumbSize ?? 24,
|
|
53
|
+
edgeThreshold: options?.edgeThreshold ?? 10,
|
|
54
|
+
onScroll: options?.onScroll || (() => {
|
|
55
|
+
}),
|
|
56
|
+
onTotalScroll: options?.onTotalScroll || (() => {
|
|
57
|
+
}),
|
|
58
|
+
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
this.boundOnScroll = this.handleScroll.bind(this);
|
|
62
|
+
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
63
|
+
this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
|
|
64
|
+
this.boundOnFocusIn = this.handleFocusIn.bind(this);
|
|
65
|
+
this.boundOnFocusOut = this.handleFocusOut.bind(this);
|
|
66
|
+
this.boundPointerMove = this.handlePointerMove.bind(this);
|
|
67
|
+
this.boundPointerUp = this.handlePointerUp.bind(this);
|
|
68
|
+
this.viewport = this.setupViewport();
|
|
69
|
+
this.setupAccessibility();
|
|
70
|
+
this.setupScrollbars();
|
|
71
|
+
this.setupEventListeners();
|
|
72
|
+
this.setupObserver();
|
|
73
|
+
this.update();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Prépare le viewport défilant sans altérer les éléments enfants.
|
|
77
|
+
*/
|
|
78
|
+
setupViewport() {
|
|
79
|
+
this.root.classList.add("wulf-scrollblock");
|
|
80
|
+
if (this.options.alwaysVisible) {
|
|
81
|
+
this.root.classList.add("is-always-visible");
|
|
82
|
+
}
|
|
83
|
+
if (this.options.axis === "both") {
|
|
84
|
+
this.root.classList.add("has-both-axes");
|
|
85
|
+
}
|
|
86
|
+
const existingViewport = this.root.querySelector(":scope > .wulf-scrollblock-viewport");
|
|
87
|
+
if (existingViewport) {
|
|
88
|
+
return existingViewport;
|
|
89
|
+
}
|
|
90
|
+
const viewport = document.createElement("div");
|
|
91
|
+
viewport.className = "wulf-scrollblock-viewport";
|
|
92
|
+
while (this.root.firstChild) {
|
|
93
|
+
viewport.appendChild(this.root.firstChild);
|
|
94
|
+
}
|
|
95
|
+
this.root.appendChild(viewport);
|
|
96
|
+
this.createdViewport = true;
|
|
97
|
+
return viewport;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Configure les attributs WAI-ARIA pour une accessibilité maximale.
|
|
101
|
+
*/
|
|
102
|
+
setupAccessibility() {
|
|
103
|
+
if (!this.viewport.id) {
|
|
104
|
+
idCounter += 1;
|
|
105
|
+
this.viewport.id = `wulf-scrollblock-vp-${idCounter}`;
|
|
106
|
+
}
|
|
107
|
+
this.viewport.setAttribute("role", "region");
|
|
108
|
+
this.viewport.setAttribute("aria-label", this.options.ariaLabel);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
112
|
+
*/
|
|
113
|
+
setupScrollbars() {
|
|
114
|
+
if (this.options.axis === "y" || this.options.axis === "both") {
|
|
115
|
+
this.trackY = document.createElement("div");
|
|
116
|
+
this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
|
|
117
|
+
this.trackY.setAttribute("aria-hidden", "true");
|
|
118
|
+
this.thumbY = document.createElement("div");
|
|
119
|
+
this.thumbY.className = "wulf-scrollblock-thumb";
|
|
120
|
+
this.thumbY.setAttribute("role", "scrollbar");
|
|
121
|
+
this.thumbY.setAttribute("aria-orientation", "vertical");
|
|
122
|
+
this.thumbY.setAttribute("aria-controls", this.viewport.id);
|
|
123
|
+
this.thumbY.setAttribute("aria-valuenow", "0");
|
|
124
|
+
this.thumbY.setAttribute("aria-valuemin", "0");
|
|
125
|
+
this.thumbY.setAttribute("aria-valuemax", "100");
|
|
126
|
+
this.thumbY.setAttribute("aria-label", "D\xE9filement vertical");
|
|
127
|
+
this.trackY.appendChild(this.thumbY);
|
|
128
|
+
this.root.appendChild(this.trackY);
|
|
129
|
+
this.attachTrackListeners(this.trackY, this.thumbY, "y");
|
|
130
|
+
}
|
|
131
|
+
if (this.options.axis === "x" || this.options.axis === "both") {
|
|
132
|
+
this.trackX = document.createElement("div");
|
|
133
|
+
this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
|
|
134
|
+
this.trackX.setAttribute("aria-hidden", "true");
|
|
135
|
+
this.thumbX = document.createElement("div");
|
|
136
|
+
this.thumbX.className = "wulf-scrollblock-thumb";
|
|
137
|
+
this.thumbX.setAttribute("role", "scrollbar");
|
|
138
|
+
this.thumbX.setAttribute("aria-orientation", "horizontal");
|
|
139
|
+
this.thumbX.setAttribute("aria-controls", this.viewport.id);
|
|
140
|
+
this.thumbX.setAttribute("aria-valuenow", "0");
|
|
141
|
+
this.thumbX.setAttribute("aria-valuemin", "0");
|
|
142
|
+
this.thumbX.setAttribute("aria-valuemax", "100");
|
|
143
|
+
this.thumbX.setAttribute("aria-label", "D\xE9filement horizontal");
|
|
144
|
+
this.trackX.appendChild(this.thumbX);
|
|
145
|
+
this.root.appendChild(this.trackX);
|
|
146
|
+
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Attache les écouteurs sur un rail et son curseur.
|
|
151
|
+
*/
|
|
152
|
+
attachTrackListeners(track, thumb, axis) {
|
|
153
|
+
thumb.addEventListener("pointerdown", (e) => {
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
e.stopPropagation();
|
|
156
|
+
this.isDragging = true;
|
|
157
|
+
this.dragAxis = axis;
|
|
158
|
+
this.dragPointerId = e.pointerId;
|
|
159
|
+
this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
|
|
160
|
+
this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
161
|
+
thumb.setPointerCapture(e.pointerId);
|
|
162
|
+
thumb.classList.add("is-active");
|
|
163
|
+
this.root.classList.add("is-dragging");
|
|
164
|
+
window.addEventListener("pointermove", this.boundPointerMove);
|
|
165
|
+
window.addEventListener("pointerup", this.boundPointerUp);
|
|
166
|
+
window.addEventListener("pointercancel", this.boundPointerUp);
|
|
167
|
+
});
|
|
168
|
+
track.addEventListener("pointerdown", (e) => {
|
|
169
|
+
if (e.target === thumb) return;
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
const rect = track.getBoundingClientRect();
|
|
172
|
+
const clickPos = axis === "y" ? e.clientY - rect.top : e.clientX - rect.left;
|
|
173
|
+
const trackSize = axis === "y" ? rect.height : rect.width;
|
|
174
|
+
const clientSize = axis === "y" ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
175
|
+
const scrollSize = axis === "y" ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
176
|
+
const ratio = clickPos / trackSize;
|
|
177
|
+
const targetScroll = ratio * (scrollSize - clientSize);
|
|
178
|
+
this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Écouteurs globaux sur le viewport et les interactions.
|
|
183
|
+
*/
|
|
184
|
+
setupEventListeners() {
|
|
185
|
+
this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true });
|
|
186
|
+
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
187
|
+
this.root.addEventListener("mouseenter", this.boundOnMouseEnter);
|
|
188
|
+
this.root.addEventListener("mouseleave", this.boundOnMouseLeave);
|
|
189
|
+
this.root.addEventListener("focusin", this.boundOnFocusIn);
|
|
190
|
+
this.root.addEventListener("focusout", this.boundOnFocusOut);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Initialise le ResizeObserver réactif.
|
|
195
|
+
*/
|
|
196
|
+
setupObserver() {
|
|
197
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
198
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
199
|
+
window.requestAnimationFrame(() => this.update());
|
|
200
|
+
});
|
|
201
|
+
this.resizeObserver.observe(this.root);
|
|
202
|
+
this.resizeObserver.observe(this.viewport);
|
|
203
|
+
if (this.viewport.firstElementChild) {
|
|
204
|
+
this.resizeObserver.observe(this.viewport.firstElementChild);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Déplacement lors du glissement du curseur.
|
|
210
|
+
*/
|
|
211
|
+
handlePointerMove(e) {
|
|
212
|
+
if (!this.isDragging || !this.dragAxis) return;
|
|
213
|
+
const isY = this.dragAxis === "y";
|
|
214
|
+
const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
|
|
215
|
+
const track = isY ? this.trackY : this.trackX;
|
|
216
|
+
const thumb = isY ? this.thumbY : this.thumbX;
|
|
217
|
+
if (!track || !thumb) return;
|
|
218
|
+
const trackSize = isY ? track.clientHeight : track.clientWidth;
|
|
219
|
+
const thumbSize = isY ? thumb.clientHeight : thumb.clientWidth;
|
|
220
|
+
const clientSize = isY ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
221
|
+
const scrollSize = isY ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
222
|
+
const maxScroll = scrollSize - clientSize;
|
|
223
|
+
const maxThumbTravel = trackSize - thumbSize;
|
|
224
|
+
if (maxThumbTravel <= 0 || maxScroll <= 0) return;
|
|
225
|
+
const ratio = maxScroll / maxThumbTravel;
|
|
226
|
+
const nextScroll = this.dragStartScroll + delta * ratio;
|
|
227
|
+
if (isY) {
|
|
228
|
+
this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
229
|
+
} else {
|
|
230
|
+
this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Relâchement de la capture du pointeur.
|
|
235
|
+
*/
|
|
236
|
+
handlePointerUp(e) {
|
|
237
|
+
if (!this.isDragging) return;
|
|
238
|
+
if (this.dragPointerId !== void 0) {
|
|
239
|
+
const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
|
|
240
|
+
if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
|
|
241
|
+
activeThumb.releasePointerCapture(this.dragPointerId);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
245
|
+
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
246
|
+
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
247
|
+
this.isDragging = false;
|
|
248
|
+
this.dragAxis = void 0;
|
|
249
|
+
this.dragPointerId = void 0;
|
|
250
|
+
this.thumbY?.classList.remove("is-active");
|
|
251
|
+
this.thumbX?.classList.remove("is-active");
|
|
252
|
+
this.root.classList.remove("is-dragging");
|
|
253
|
+
this.scheduleAutoHide();
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Gestionnaire d'événement de défilement natif.
|
|
257
|
+
*/
|
|
258
|
+
handleScroll() {
|
|
259
|
+
this.syncThumbs();
|
|
260
|
+
const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
|
|
261
|
+
const maxTop = Math.max(0, scrollHeight - clientHeight);
|
|
262
|
+
const maxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
263
|
+
const progressY = maxTop > 0 ? scrollTop / maxTop : 0;
|
|
264
|
+
const progressX = maxLeft > 0 ? scrollLeft / maxLeft : 0;
|
|
265
|
+
this.options.onScroll({
|
|
266
|
+
top: scrollTop,
|
|
267
|
+
left: scrollLeft,
|
|
268
|
+
maxTop,
|
|
269
|
+
maxLeft,
|
|
270
|
+
progressY: Math.round(progressY * 100),
|
|
271
|
+
progressX: Math.round(progressX * 100)
|
|
272
|
+
});
|
|
273
|
+
const threshold = this.options.edgeThreshold;
|
|
274
|
+
if (maxTop > 0) {
|
|
275
|
+
const nowBottom = scrollTop >= maxTop - threshold;
|
|
276
|
+
const nowTop = scrollTop <= threshold;
|
|
277
|
+
if (nowBottom && !this.atBottom) {
|
|
278
|
+
this.options.onTotalScroll("bottom");
|
|
279
|
+
}
|
|
280
|
+
if (nowTop && !this.atTop) {
|
|
281
|
+
this.options.onTotalScrollBack("top");
|
|
282
|
+
}
|
|
283
|
+
this.atBottom = nowBottom;
|
|
284
|
+
this.atTop = nowTop;
|
|
285
|
+
}
|
|
286
|
+
if (maxLeft > 0) {
|
|
287
|
+
const nowRight = scrollLeft >= maxLeft - threshold;
|
|
288
|
+
const nowLeft = scrollLeft <= threshold;
|
|
289
|
+
if (nowRight && !this.atRight) {
|
|
290
|
+
this.options.onTotalScroll("right");
|
|
291
|
+
}
|
|
292
|
+
if (nowLeft && !this.atLeft) {
|
|
293
|
+
this.options.onTotalScrollBack("left");
|
|
294
|
+
}
|
|
295
|
+
this.atRight = nowRight;
|
|
296
|
+
this.atLeft = nowLeft;
|
|
297
|
+
}
|
|
298
|
+
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
299
|
+
this.root.classList.add("is-scrolling");
|
|
300
|
+
this.scheduleAutoHide();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Synchronise la position physique et ARIA des curseurs.
|
|
305
|
+
*/
|
|
306
|
+
syncThumbs() {
|
|
307
|
+
const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
|
|
308
|
+
if (this.thumbY && this.trackY) {
|
|
309
|
+
const maxScrollY = scrollHeight - clientHeight;
|
|
310
|
+
const trackHeight = this.trackY.clientHeight;
|
|
311
|
+
const thumbHeight = this.thumbY.clientHeight;
|
|
312
|
+
const maxTravelY = trackHeight - thumbHeight;
|
|
313
|
+
if (maxScrollY > 0 && maxTravelY > 0) {
|
|
314
|
+
const ratioY = scrollTop / maxScrollY;
|
|
315
|
+
const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
|
|
316
|
+
this.thumbY.style.transform = `translate3d(0, ${posY}px, 0)`;
|
|
317
|
+
this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (this.thumbX && this.trackX) {
|
|
321
|
+
const maxScrollX = scrollWidth - clientWidth;
|
|
322
|
+
const trackWidth = this.trackX.clientWidth;
|
|
323
|
+
const thumbWidth = this.thumbX.clientWidth;
|
|
324
|
+
const maxTravelX = trackWidth - thumbWidth;
|
|
325
|
+
if (maxScrollX > 0 && maxTravelX > 0) {
|
|
326
|
+
const ratioX = scrollLeft / maxScrollX;
|
|
327
|
+
const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
|
|
328
|
+
this.thumbX.style.transform = `translate3d(${posX}px, 0, 0)`;
|
|
329
|
+
this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
handleMouseEnter() {
|
|
334
|
+
this.root.classList.add("is-visible");
|
|
335
|
+
this.clearAutoHideTimer();
|
|
336
|
+
}
|
|
337
|
+
handleMouseLeave() {
|
|
338
|
+
this.scheduleAutoHide();
|
|
339
|
+
}
|
|
340
|
+
handleFocusIn() {
|
|
341
|
+
this.root.classList.add("is-visible");
|
|
342
|
+
this.clearAutoHideTimer();
|
|
343
|
+
}
|
|
344
|
+
handleFocusOut() {
|
|
345
|
+
this.scheduleAutoHide();
|
|
346
|
+
}
|
|
347
|
+
clearAutoHideTimer() {
|
|
348
|
+
if (this.hideTimer) {
|
|
349
|
+
window.clearTimeout(this.hideTimer);
|
|
350
|
+
this.hideTimer = void 0;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
scheduleAutoHide() {
|
|
354
|
+
if (this.options.alwaysVisible || !this.options.autoHide || this.isDragging) return;
|
|
355
|
+
this.clearAutoHideTimer();
|
|
356
|
+
this.hideTimer = window.setTimeout(() => {
|
|
357
|
+
this.root.classList.remove("is-scrolling");
|
|
358
|
+
this.root.classList.remove("is-visible");
|
|
359
|
+
}, this.options.autoHideDelay);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Recalcule les dimensions et la visibilité des barres.
|
|
363
|
+
*/
|
|
364
|
+
update() {
|
|
365
|
+
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
366
|
+
const canScrollY = scrollHeight > clientHeight;
|
|
367
|
+
const canScrollX = scrollWidth > clientWidth;
|
|
368
|
+
this.root.classList.toggle("has-scroll-y", canScrollY);
|
|
369
|
+
this.root.classList.toggle("has-scroll-x", canScrollX);
|
|
370
|
+
if (canScrollY || canScrollX) {
|
|
371
|
+
this.viewport.setAttribute("tabindex", "0");
|
|
372
|
+
} else {
|
|
373
|
+
this.viewport.removeAttribute("tabindex");
|
|
374
|
+
}
|
|
375
|
+
if (this.trackY && this.thumbY) {
|
|
376
|
+
if (canScrollY) {
|
|
377
|
+
const trackHeight = this.trackY.clientHeight;
|
|
378
|
+
const calculatedHeight = Math.max(
|
|
379
|
+
this.options.minThumbSize,
|
|
380
|
+
trackHeight * (clientHeight / scrollHeight)
|
|
381
|
+
);
|
|
382
|
+
this.thumbY.style.height = `${calculatedHeight}px`;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (this.trackX && this.thumbX) {
|
|
386
|
+
if (canScrollX) {
|
|
387
|
+
const trackWidth = this.trackX.clientWidth;
|
|
388
|
+
const calculatedWidth = Math.max(
|
|
389
|
+
this.options.minThumbSize,
|
|
390
|
+
trackWidth * (clientWidth / scrollWidth)
|
|
391
|
+
);
|
|
392
|
+
this.thumbX.style.width = `${calculatedWidth}px`;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
this.syncThumbs();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Défilement programmatique direct ou lissé.
|
|
399
|
+
*/
|
|
400
|
+
scrollTo(target, options) {
|
|
401
|
+
const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
402
|
+
const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
|
|
403
|
+
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion;
|
|
404
|
+
const behavior = shouldSmooth ? "smooth" : "auto";
|
|
405
|
+
const maxTop = Math.max(0, this.viewport.scrollHeight - this.viewport.clientHeight);
|
|
406
|
+
const maxLeft = Math.max(0, this.viewport.scrollWidth - this.viewport.clientWidth);
|
|
407
|
+
let targetTop;
|
|
408
|
+
let targetLeft;
|
|
409
|
+
if (typeof target === "number") {
|
|
410
|
+
targetTop = target;
|
|
411
|
+
} else if (typeof target === "string") {
|
|
412
|
+
switch (target) {
|
|
413
|
+
case "top":
|
|
414
|
+
targetTop = 0;
|
|
415
|
+
break;
|
|
416
|
+
case "bottom":
|
|
417
|
+
targetTop = maxTop;
|
|
418
|
+
break;
|
|
419
|
+
case "left":
|
|
420
|
+
targetLeft = 0;
|
|
421
|
+
break;
|
|
422
|
+
case "right":
|
|
423
|
+
targetLeft = maxLeft;
|
|
424
|
+
break;
|
|
425
|
+
default: {
|
|
426
|
+
let el = null;
|
|
427
|
+
try {
|
|
428
|
+
el = this.viewport.querySelector(target);
|
|
429
|
+
} catch {
|
|
430
|
+
el = null;
|
|
431
|
+
}
|
|
432
|
+
if (el) {
|
|
433
|
+
targetTop = el.offsetTop;
|
|
434
|
+
targetLeft = el.offsetLeft;
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
} else if (target instanceof HTMLElement) {
|
|
440
|
+
targetTop = target.offsetTop;
|
|
441
|
+
targetLeft = target.offsetLeft;
|
|
442
|
+
} else if (typeof target === "object") {
|
|
443
|
+
targetTop = target.top;
|
|
444
|
+
targetLeft = target.left;
|
|
445
|
+
}
|
|
446
|
+
this.viewport.scrollTo({
|
|
447
|
+
top: targetTop !== void 0 ? Math.max(0, Math.min(maxTop, targetTop)) : void 0,
|
|
448
|
+
left: targetLeft !== void 0 ? Math.max(0, Math.min(maxLeft, targetLeft)) : void 0,
|
|
449
|
+
behavior
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Détruit le composant et libère toutes les ressources.
|
|
454
|
+
*/
|
|
455
|
+
destroy() {
|
|
456
|
+
this.clearAutoHideTimer();
|
|
457
|
+
if (this.resizeObserver) {
|
|
458
|
+
this.resizeObserver.disconnect();
|
|
459
|
+
}
|
|
460
|
+
this.viewport.removeEventListener("scroll", this.boundOnScroll);
|
|
461
|
+
this.root.removeEventListener("mouseenter", this.boundOnMouseEnter);
|
|
462
|
+
this.root.removeEventListener("mouseleave", this.boundOnMouseLeave);
|
|
463
|
+
this.root.removeEventListener("focusin", this.boundOnFocusIn);
|
|
464
|
+
this.root.removeEventListener("focusout", this.boundOnFocusOut);
|
|
465
|
+
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
466
|
+
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
467
|
+
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
468
|
+
this.trackY?.remove();
|
|
469
|
+
this.trackX?.remove();
|
|
470
|
+
this.root.classList.remove(
|
|
471
|
+
"wulf-scrollblock",
|
|
472
|
+
"has-scroll-y",
|
|
473
|
+
"has-scroll-x",
|
|
474
|
+
"has-both-axes",
|
|
475
|
+
"is-visible",
|
|
476
|
+
"is-scrolling",
|
|
477
|
+
"is-dragging",
|
|
478
|
+
"is-always-visible"
|
|
479
|
+
);
|
|
480
|
+
if (this.createdViewport && this.viewport.parentElement === this.root) {
|
|
481
|
+
while (this.viewport.firstChild) {
|
|
482
|
+
this.root.insertBefore(this.viewport.firstChild, this.viewport);
|
|
483
|
+
}
|
|
484
|
+
this.viewport.remove();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/scroll/index.ts
|
|
490
|
+
var Scroll = {
|
|
491
|
+
ScrollBlock
|
|
492
|
+
};
|
|
493
|
+
var index_default = ScrollBlock;
|
|
494
|
+
if (typeof window !== "undefined") {
|
|
495
|
+
const win = window;
|
|
496
|
+
const wulfNamespace = win.Wulf || {};
|
|
497
|
+
win.Wulf = wulfNamespace;
|
|
498
|
+
wulfNamespace.Scroll = Scroll;
|
|
499
|
+
}
|
|
500
|
+
//# sourceMappingURL=scroll.cjs.js.map
|