@codegouvfr/react-dsfr
Version:
French State Design System React integration library
4 lines (3 loc) • 28.5 kB
JavaScript
/*! DSFR v1.8.5 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
const e=window.dsfr,t={GROUP:e.internals.ns.selector("accordions-group"),COLLAPSE:`${e.internals.ns.selector("accordion")} > ${e.internals.ns.selector("collapse")}`};class s extends e.core.CollapsesGroup{static get instanceClassName(){return"AccordionsGroup"}validate(e){return e.node.matches(t.COLLAPSE)}}e.accordion={AccordionSelector:t,AccordionsGroup:s},e.internals.register(e.accordion.AccordionSelector.GROUP,e.accordion.AccordionsGroup);const i={EQUISIZED_BUTTON:`${e.internals.ns.selector("btns-group--equisized")} ${e.internals.ns.selector("btn")}`,EQUISIZED_GROUP:e.internals.ns.selector("btns-group--equisized")};e.button={ButtonSelector:i},e.internals.register(e.button.ButtonSelector.EQUISIZED_BUTTON,e.core.Equisized),e.internals.register(e.button.ButtonSelector.EQUISIZED_GROUP,e.core.EquisizedsGroup);class n extends e.core.Instance{constructor(){super(),this.count=0,this.focusing=this.focus.bind(this)}static get instanceClassName(){return"Breadcrumb"}init(){this.getCollapse(),this.isResizing=!0}get proxy(){const e=this;return Object.assign(super.proxy,{focus:e.focus.bind(e),disclose:e.collapse.disclose.bind(e.collapse)})}getCollapse(){const t=this.collapse;t?t.listen(e.core.DisclosureEvent.DISCLOSE,this.focusing):this.addAscent(e.core.DisclosureEmission.ADDED,this.getCollapse.bind(this))}resize(){const t=this.collapse,s=this.links;t&&s.length&&(this.isBreakpoint(e.core.Breakpoints.MD)?t.buttonHasFocus&&s[0].focus():s.indexOf(document.activeElement)>-1&&t.focus())}get links(){return[...this.querySelectorAll("a[href]")]}get collapse(){return this.element.getDescendantInstances(e.core.Collapse.instanceClassName,null,!0)[0]}focus(){this.count=0,this._focus()}_focus(){const e=this.links[0];e&&(e.focus(),this.request(this.verify.bind(this)))}verify(){if(this.count++,this.count>100)return;const e=this.links[0];e&&document.activeElement!==e&&this._focus()}}const r={BREADCRUMB:e.internals.ns.selector("breadcrumb")};e.breadcrumb={BreadcrumbSelector:r,Breadcrumb:n},e.internals.register(e.breadcrumb.BreadcrumbSelector.BREADCRUMB,e.breadcrumb.Breadcrumb);class a extends e.core.Instance{static get instanceClassName(){return"ToggleInput"}get isChecked(){return this.hasAttribute("checked")}}class o extends e.core.Instance{static get instanceClassName(){return"ToggleStatusLabel"}init(){this.register(`input[id="${this.getAttribute("for")}"]`,a),this.update(),this.isSwappingFont=!0}get proxy(){return Object.assign(super.proxy,{update:this.update.bind(this)})}get input(){return this.getRegisteredInstances("ToggleInput")[0]}update(){this.node.style.removeProperty("--toggle-status-width");const e=this.input.isChecked,t=getComputedStyle(this.node,":before");let s=parseFloat(t.width);this.input.node.checked=!e;const i=getComputedStyle(this.node,":before"),n=parseFloat(i.width);n>s&&(s=n),this.input.node.checked=e,this.node.style.setProperty("--toggle-status-width",s/16+"rem")}swapFont(e){this.update()}}const l={STATUS_LABEL:`${e.internals.ns.selector("toggle__label")}${e.internals.ns.attr.selector("checked-label")}${e.internals.ns.attr.selector("unchecked-label")}`};e.toggle={ToggleStatusLabel:o,ToggleSelector:l},e.internals.register(e.toggle.ToggleSelector.STATUS_LABEL,e.toggle.ToggleStatusLabel);const c={LIST:e.internals.ns.selector("sidemenu__list"),COLLAPSE:`${e.internals.ns.selector("sidemenu__item")} > ${e.internals.ns.selector("collapse")}`};class h extends e.core.CollapsesGroup{static get instanceClassName(){return"SidemenuList"}validate(e){return e.node.matches(c.COLLAPSE)}}e.sidemenu={SidemenuList:h,SidemenuSelector:c},e.internals.register(e.sidemenu.SidemenuSelector.LIST,e.sidemenu.SidemenuList);const d={MODAL:e.internals.ns.selector("modal"),SCROLL_SHADOW:e.internals.ns.selector("scroll-shadow"),BODY:e.internals.ns.selector("modal__body")};class u extends e.core.DisclosureButton{constructor(){super(e.core.DisclosureType.OPENED)}static get instanceClassName(){return"ModalButton"}}const g={CONCEALING_BACKDROP:e.internals.ns.attr("concealing-backdrop")};class p extends e.core.Disclosure{constructor(){super(e.core.DisclosureType.OPENED,d.MODAL,u,"ModalsGroup"),this.scrolling=this.resize.bind(this,!1),this.resizing=this.resize.bind(this,!0)}static get instanceClassName(){return"Modal"}init(){super.init(),this.listen("click",this.click.bind(this)),this.listenKey(e.core.KeyCodes.ESCAPE,this.conceal.bind(this,!1,!1),!0,!0)}get body(){return this.element.getDescendantInstances("ModalBody","Modal")[0]}click(e){e.target===this.node&&"false"!==this.getAttribute(g.CONCEALING_BACKDROP)&&this.conceal()}disclose(e){return!!super.disclose(e)&&(this.body&&this.body.activate(),this.isScrollLocked=!0,this.setAttribute("aria-modal","true"),this.setAttribute("open","true"),!0)}conceal(e,t){return!!super.conceal(e,t)&&(this.isScrollLocked=!1,this.removeAttribute("aria-modal"),this.removeAttribute("open"),this.body&&this.body.deactivate(),!0)}}const m=['[tabindex="0"]',"a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details","iframe"].join(),b=['[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'].join(),S=(e,t)=>{if(!(e instanceof Element))return!1;const s=window.getComputedStyle(e);if(!s)return!1;if("hidden"===s.visibility)return!1;for(void 0===t&&(t=e);t.contains(e);){if("none"===s.display)return!1;e=e.parentElement}return!0};class T{constructor(e,t){this.element=null,this.activeElement=null,this.onTrap=e,this.onUntrap=t,this.waiting=this.wait.bind(this),this.handling=this.handle.bind(this),this.focusing=this.maintainFocus.bind(this),this.current=null}get trapped(){return null!==this.element}trap(e){this.trapped&&this.untrap(),this.element=e,this.isTrapping=!0,this.wait(),this.onTrap&&this.onTrap()}wait(){S(this.element)?this.trapping():window.requestAnimationFrame(this.waiting)}trapping(){if(!this.isTrapping)return;this.isTrapping=!1;const e=this.focusables;e.length&&e[0].focus(),this.element.setAttribute("aria-modal",!0),window.addEventListener("keydown",this.handling),document.body.addEventListener("focus",this.focusing,!0)}stun(e){for(const t of e.children)t!==this.element&&(t.contains(this.element)?this.stun(t):this.stunneds.push(new f(t)))}maintainFocus(e){if(!this.element.contains(e.target)){const t=this.focusables;if(0===t.length)return;const s=t[0];e.preventDefault(),s.focus()}}handle(e){if(9!==e.keyCode)return;const t=this.focusables;if(0===t.length)return;const s=t[0],i=t[t.length-1],n=t.indexOf(document.activeElement);e.shiftKey?!this.element.contains(document.activeElement)||n<1?(e.preventDefault(),i.focus()):(document.activeElement.tabIndex>0||t[n-1].tabIndex>0)&&(e.preventDefault(),t[n-1].focus()):this.element.contains(document.activeElement)&&n!==t.length-1&&-1!==n?document.activeElement.tabIndex>0&&(e.preventDefault(),t[n+1].focus()):(e.preventDefault(),s.focus())}get focusables(){let t=e.internals.dom.querySelectorAllArray(this.element,m);const s=e.internals.dom.querySelectorAllArray(document.documentElement,'input[type="radio"]');if(s.length){const e={};for(const t of s){const s=t.getAttribute("name");void 0===e[s]&&(e[s]=new A(s)),e[s].push(t)}t=t.filter((t=>{if("input"!==t.tagName.toLowerCase()||"radio"!==t.getAttribute("type").toLowerCase())return!0;const s=t.getAttribute("name");return e[s].keep(t)}))}const i=e.internals.dom.querySelectorAllArray(this.element,b);i.sort(((e,t)=>e.tabIndex-t.tabIndex));const n=t.filter((e=>-1===i.indexOf(e)));return i.concat(n).filter((e=>"-1"!==e.tabIndex&&S(e,this.element)))}untrap(){this.trapped&&(this.isTrapping=!1,this.element.removeAttribute("aria-modal"),window.removeEventListener("keydown",this.handling),document.body.removeEventListener("focus",this.focusing,!0),this.element=null,this.onUntrap&&this.onUntrap())}dispose(){this.untrap()}}class f{constructor(e){this.element=e,this.inert=e.getAttribute("inert"),this.element.setAttribute("inert","")}unstun(){null===this.inert?this.element.removeAttribute("inert"):this.element.setAttribute("inert",this.inert)}}class A{constructor(e){this.name=e,this.buttons=[]}push(e){this.buttons.push(e),(e===document.activeElement||e.checked||void 0===this.selected)&&(this.selected=e)}keep(e){return this.selected===e}}class E extends e.core.DisclosuresGroup{constructor(){super("Modal",!1),this.focusTrap=new T}static get instanceClassName(){return"ModalsGroup"}apply(e,t){super.apply(e,t),null===this.current?this.focusTrap.untrap():this.focusTrap.trap(this.current.node)}}class L extends e.core.Instance{static get instanceClassName(){return"ModalBody"}init(){this.listen("scroll",this.shade.bind(this))}activate(){this.isResizing=!0,this.resize()}deactivate(){this.isResizing=!1}shade(){this.node.scrollHeight>this.node.clientHeight?this.node.offsetHeight+this.node.scrollTop>=this.node.scrollHeight?this.removeClass(d.SCROLL_SHADOW):this.addClass(d.SCROLL_SHADOW):this.removeClass(d.SCROLL_SHADOW)}resize(){this.adjust(),this.request(this.adjust.bind(this))}adjust(){const t=32*(this.isBreakpoint(e.core.Breakpoints.MD)?2:1);this.isLegacy?this.style.maxHeight=window.innerHeight-t+"px":this.style.setProperty("--modal-max-height",window.innerHeight-t+"px"),this.shade()}}e.modal={Modal:p,ModalButton:u,ModalBody:L,ModalsGroup:E,ModalSelector:d},e.internals.register(e.modal.ModalSelector.MODAL,e.modal.Modal),e.internals.register(e.modal.ModalSelector.BODY,e.modal.ModalBody),e.internals.register(e.core.RootSelector.ROOT,e.modal.ModalsGroup);const _={TOGGLE:e.internals.ns.emission("password","toggle"),ADJUST:e.internals.ns.emission("password","adjust")};class D extends e.core.Instance{static get instanceClassName(){return"PasswordToggle"}init(){this.listen("click",this.toggle.bind(this)),this.ascend(_.ADJUST,this.width),this.isSwappingFont=!0,this._isChecked=this.isChecked}get width(){const e=getComputedStyle(this.node.parentNode);return parseInt(e.width)}get isChecked(){return this.node.checked}set isChecked(e){this._isChecked=e,this.ascend(_.TOGGLE,e)}toggle(){this.isChecked=!this._isChecked}swapFont(e){this.ascend(_.ADJUST,this.width)}}class C extends e.core.Instance{static get instanceClassName(){return"Password"}init(){this.addAscent(_.TOGGLE,this.toggle.bind(this)),this.addAscent(_.ADJUST,this.adjust.bind(this))}toggle(e){this.descend(_.TOGGLE,e)}adjust(e){this.descend(_.ADJUST,e)}}const I={PASSWORD:e.internals.ns.selector("password"),INPUT:e.internals.ns.selector("password__input"),LABEL:e.internals.ns.selector("password__label"),TOOGLE:`${e.internals.ns.selector("password__checkbox")} input[type="checkbox"]`};class y extends e.core.Instance{static get instanceClassName(){return"PasswordInput"}init(){this.addDescent(_.TOGGLE,this.toggle.bind(this)),this._isRevealed="password"===this.hasAttribute("type"),this.listen("keydown",this.capslock.bind(this)),this.listen("keyup",this.capslock.bind(this))}toggle(e){this.isRevealed=e,this.setAttribute("type",e?"text":"password")}get isRevealed(){return this._isRevealed}capslock(t){t.getModifierState("CapsLock")?this.node.parentNode.setAttribute(e.internals.ns.attr("capslock"),""):this.node.parentNode.removeAttribute(e.internals.ns.attr("capslock"))}set isRevealed(e){this._isRevealed=e,this.setAttribute("type",e?"text":"password")}}class v extends e.core.Instance{static get instanceClassName(){return"PasswordLabel"}init(){this.addDescent(_.ADJUST,this.adjust.bind(this))}adjust(e){const t=Math.ceil(e/16);this.node.style.paddingRight=t+"rem"}}e.password={Password:C,PasswordToggle:D,PasswordSelector:I,PasswordInput:y,PasswordLabel:v},e.internals.register(e.password.PasswordSelector.INPUT,e.password.PasswordInput),e.internals.register(e.password.PasswordSelector.PASSWORD,e.password.Password),e.internals.register(e.password.PasswordSelector.TOOGLE,e.password.PasswordToggle),e.internals.register(e.password.PasswordSelector.LABEL,e.password.PasswordLabel);const N={NAVIGATION:e.internals.ns.selector("nav"),COLLAPSE:`${e.internals.ns.selector("nav__item")} > ${e.internals.ns.selector("collapse")}`,ITEM:e.internals.ns.selector("nav__item"),ITEM_RIGHT:e.internals.ns("nav__item--align-right"),MENU:e.internals.ns.selector("menu")};class O extends e.core.Instance{constructor(){super(),this._isRightAligned=!1}static get instanceClassName(){return"NavigationItem"}init(){this.addAscent(e.core.DisclosureEmission.ADDED,this.calculate.bind(this)),this.addAscent(e.core.DisclosureEmission.REMOVED,this.calculate.bind(this)),this.isResizing=!0,this.calculate()}resize(){this.calculate()}calculate(){const t=this.element.getDescendantInstances(e.core.Collapse.instanceClassName,null,!0)[0];if(t&&this.isBreakpoint(e.core.Breakpoints.LG)&&t.element.node.matches(N.MENU)){const e=this.element.node.parentElement.getBoundingClientRect().right,s=t.element.node.getBoundingClientRect().width,i=this.element.node.getBoundingClientRect().left;this.isRightAligned=i+s>e}else this.isRightAligned=!1}get isRightAligned(){return this._isRightAligned}set isRightAligned(t){this._isRightAligned!==t&&(this._isRightAligned=t,t?e.internals.dom.addClass(this.element.node,N.ITEM_RIGHT):e.internals.dom.removeClass(this.element.node,N.ITEM_RIGHT))}}const w={NONE:-1,INSIDE:0,OUTSIDE:1};class P extends e.core.CollapsesGroup{static get instanceClassName(){return"Navigation"}init(){super.init(),this.clicked=!1,this.out=!1,this.listen("focusout",this.focusOut.bind(this)),this.listen("mousedown",this.down.bind(this))}validate(e){return e.element.node.matches(N.COLLAPSE)}down(t){this.isBreakpoint(e.core.Breakpoints.LG)&&-1!==this.index&&this.current&&(this.position=this.current.node.contains(t.target)?w.INSIDE:w.OUTSIDE,this.requestPosition())}focusOut(t){this.isBreakpoint(e.core.Breakpoints.LG)&&(this.out=!0,this.requestPosition())}requestPosition(){this.isRequesting||(this.isRequesting=!0,this.request(this.getPosition.bind(this)))}getPosition(){if(this.out)switch(this.position){case w.OUTSIDE:this.index=-1;break;case w.INSIDE:this.current&&!this.current.node.contains(document.activeElement)&&this.current.focus();break;default:this.index>-1&&!this.current.hasFocus&&(this.index=-1)}this.request(this.requested.bind(this))}requested(){this.position=w.NONE,this.out=!1,this.isRequesting=!1}get index(){return super.index}set index(e){-1===e&&null!==this.current&&this.current.hasFocus&&this.current.focus(),super.index=e}}e.navigation={Navigation:P,NavigationItem:O,NavigationMousePosition:w,NavigationSelector:N},e.internals.register(e.navigation.NavigationSelector.NAVIGATION,e.navigation.Navigation),e.internals.register(e.navigation.NavigationSelector.ITEM,e.navigation.NavigationItem);class H extends e.core.DisclosureButton{constructor(){super(e.core.DisclosureType.SELECT)}static get instanceClassName(){return"TabButton"}apply(e){super.apply(e),this.isPrimary&&(this.setAttribute("tabindex",e?"0":"-1"),e&&this.list&&this.list.focalize(this))}get list(){return this.element.getAscendantInstance("TabsList","TabsGroup")}}const k={TAB:e.internals.ns.selector("tabs__tab"),GROUP:e.internals.ns.selector("tabs"),PANEL:e.internals.ns.selector("tabs__panel"),LIST:e.internals.ns.selector("tabs__list"),SHADOW:e.internals.ns.selector("tabs__shadow"),SHADOW_LEFT:e.internals.ns.selector("tabs__shadow--left"),SHADOW_RIGHT:e.internals.ns.selector("tabs__shadow--right"),PANEL_START:e.internals.ns.selector("tabs__panel--direction-start"),PANEL_END:e.internals.ns.selector("tabs__panel--direction-end")},R="direction-start",x="direction-end",M="none";class G extends e.core.Disclosure{constructor(){super(e.core.DisclosureType.SELECT,k.PANEL,H,"TabsGroup"),this._direction=M,this._isPreventingTransition=!1}static get instanceClassName(){return"TabPanel"}get direction(){return this._direction}set direction(e){if(e!==this._direction){switch(this._direction){case R:this.removeClass(k.PANEL_START);break;case x:this.removeClass(k.PANEL_END);break;case M:break;default:return}switch(this._direction=e,this._direction){case R:this.addClass(k.PANEL_START);break;case x:this.addClass(k.PANEL_END)}}}get isPreventingTransition(){return this._isPreventingTransition}set isPreventingTransition(t){this._isPreventingTransition!==t&&(t?this.addClass(e.internals.motion.TransitionSelector.NONE):this.removeClass(e.internals.motion.TransitionSelector.NONE),this._isPreventingTransition=!0===t)}translate(e,t){this.isPreventingTransition=t,this.direction=e}reset(){this.group.index=0}}class B extends e.core.DisclosuresGroup{constructor(){super("TabPanel")}static get instanceClassName(){return"TabsGroup"}init(){super.init(),this.listen("transitionend",this.transitionend.bind(this)),this.listenKey(e.core.KeyCodes.RIGHT,this.pressRight.bind(this),!0,!0),this.listenKey(e.core.KeyCodes.LEFT,this.pressLeft.bind(this),!0,!0),this.listenKey(e.core.KeyCodes.HOME,this.pressHome.bind(this),!0,!0),this.listenKey(e.core.KeyCodes.END,this.pressEnd.bind(this),!0,!0),this.isRendering=!0,this.list&&this.list.apply()}get list(){return this.element.getDescendantInstances("TabsList","TabsGroup",!0)[0]}transitionend(e){this.isPreventingTransition=!0}get buttonHasFocus(){return this.members.some((e=>e.buttonHasFocus))}pressRight(){this.buttonHasFocus&&(this.index<this.length-1?this.index++:this.index=0,this.focus())}pressLeft(){this.buttonHasFocus&&(this.index>0?this.index--:this.index=this.length-1,this.focus())}pressHome(){this.buttonHasFocus&&(this.index=0,this.focus())}pressEnd(){this.buttonHasFocus&&(this.index=this.length-1,this.focus())}focus(){this.current&&this.current.focus()}apply(){for(let e=0;e<this._index;e++)this.members[e].translate(R);this.current.translate(M);for(let e=this._index+1;e<this.length;e++)this.members[e].translate(x);this.isPreventingTransition=!1}get isPreventingTransition(){return this._isPreventingTransition}set isPreventingTransition(t){this._isPreventingTransition!==t&&(t?this.addClass(e.internals.motion.TransitionSelector.NONE):this.removeClass(e.internals.motion.TransitionSelector.NONE),this._isPreventingTransition=!0===t)}render(){if(null===this.current)return;const e=Math.round(this.current.node.offsetHeight);if(this.panelHeight===e)return;this.panelHeight=e;let t=0;this.list&&(t=this.list.node.offsetHeight),this.style.setProperty("--tabs-height",this.panelHeight+t+"px")}}class $ extends e.core.Instance{static get instanceClassName(){return"TabsList"}init(){this.listen("scroll",this.scroll.bind(this)),this.isResizing=!0}get group(){return this.element.getAscendantInstance("TabsGroup","TabsList")}focalize(e){const t=e.getRect(),s=this.getRect(),i=this.node.scrollLeft;t.left<s.left?this.node.scrollTo(i-s.left+t.left-16,0):t.right>s.right&&this.node.scrollTo(i-s.right+t.right+16,0)}get isScrolling(){return this._isScrolling}set isScrolling(e){this._isScrolling!==e&&(this._isScrolling=e,this.apply())}apply(){this.group&&(this._isScrolling?(this.group.addClass(k.SHADOW),this.scroll()):(this.group.removeClass(k.SHADOW_RIGHT),this.group.removeClass(k.SHADOW_LEFT),this.group.removeClass(k.SHADOW)))}scroll(){if(!this.group)return;const e=this.node.scrollLeft,t=e<=16,s=this.node.scrollWidth-this.node.clientWidth-16,i=Math.abs(e)>=s,n="rtl"===document.documentElement.getAttribute("dir"),r=n?k.SHADOW_RIGHT:k.SHADOW_LEFT,a=n?k.SHADOW_LEFT:k.SHADOW_RIGHT;t?this.group.removeClass(r):this.group.addClass(r),i?this.group.removeClass(a):this.group.addClass(a)}resize(){this.isScrolling=this.node.scrollWidth>this.node.clientWidth+16,this.setProperty("--tab-list-height",`${this.getRect().height}px`)}dispose(){this.isScrolling=!1}}e.tab={TabPanel:G,TabButton:H,TabsGroup:B,TabsList:$,TabSelector:k},e.internals.register(e.tab.TabSelector.PANEL,e.tab.TabPanel),e.internals.register(e.tab.TabSelector.GROUP,e.tab.TabsGroup),e.internals.register(e.tab.TabSelector.LIST,e.tab.TabsList);const U={SCROLLABLE:e.internals.ns.emission("table","scrollable"),CHANGE:e.internals.ns.emission("table","change"),CAPTION_HEIGHT:e.internals.ns.emission("table","captionheight")};class W extends e.core.Instance{static get instanceClassName(){return"Table"}init(){this.addAscent(U.CAPTION_HEIGHT,this.setCaptionHeight.bind(this))}setCaptionHeight(e){this.setProperty("--table-offset",`calc(${e}px + 1rem)`)}}const F={TABLE:e.internals.ns.selector("table"),SHADOW:e.internals.ns.selector("table__shadow"),SHADOW_LEFT:e.internals.ns.selector("table__shadow--left"),SHADOW_RIGHT:e.internals.ns.selector("table__shadow--right"),ELEMENT:`${e.internals.ns.selector("table")}:not(${e.internals.ns.selector("table--no-scroll")}) table`,CAPTION:`${e.internals.ns.selector("table")} table caption`};class q extends e.core.Instance{static get instanceClassName(){return"TableElement"}init(){this.listen("scroll",this.scroll.bind(this)),this.content=this.querySelector("tbody"),this.isResizing=!0}get isScrolling(){return this._isScrolling}set isScrolling(e){this._isScrolling!==e&&(this._isScrolling=e,e?(this.addClass(F.SHADOW),this.scroll()):(this.removeClass(F.SHADOW),this.removeClass(F.SHADOW_LEFT),this.removeClass(F.SHADOW_RIGHT)))}scroll(){const e=this.node.scrollLeft<=8,t=this.content.offsetWidth-this.node.offsetWidth-8,s=Math.abs(this.node.scrollLeft)>=t,i="rtl"===document.documentElement.getAttribute("dir"),n=i?F.SHADOW_RIGHT:F.SHADOW_LEFT,r=i?F.SHADOW_LEFT:F.SHADOW_RIGHT;e?this.removeClass(n):this.addClass(n),s?this.removeClass(r):this.addClass(r)}resize(){this.isScrolling=this.content.offsetWidth>this.node.offsetWidth}dispose(){this.isScrolling=!1}}class z extends e.core.Instance{static get instanceClassName(){return"TableCaption"}init(){this.height=0,this.isResizing=!0}resize(){const e=this.getRect().height;this.height!==e&&(this.height=e,this.ascend(U.CAPTION_HEIGHT,e))}}e.table={Table:W,TableElement:q,TableCaption:z,TableSelector:F},e.internals.register(e.table.TableSelector.TABLE,e.table.Table),e.internals.register(e.table.TableSelector.ELEMENT,e.table.TableElement),e.internals.register(e.table.TableSelector.CAPTION,e.table.TableCaption);const K={DISMISS:e.internals.ns.event("dismiss")};class j extends e.core.Instance{static get instanceClassName(){return"TagDismissible"}init(){this.listen("click",this.click.bind(this))}click(){switch(this.focusClosest(),e.mode){case e.Modes.ANGULAR:case e.Modes.REACT:case e.Modes.VUE:this.request(this.verify.bind(this));break;default:this.remove()}this.dispatch(K.DISMISS)}verify(){document.body.contains(this.node)&&e.inspector.warn(`a TagDismissible has just been dismissed and should be removed from the dom. In ${e.mode} mode, the api doesn't handle dom modification. An event ${K.DISMISS} is dispatched by the element to trigger the removal`)}}const V={PRESSABLE:`${e.internals.ns.selector("tag")}[aria-pressed]`,DISMISSIBLE:`${e.internals.ns.selector("tag--dismiss")}`};e.tag={TagDismissible:j,TagSelector:V,TagEvent:K},e.internals.register(e.tag.TagSelector.PRESSABLE,e.core.Toggle),e.internals.register(e.tag.TagSelector.DISMISSIBLE,e.tag.TagDismissible);const J={DOWNLOAD_ASSESS_FILE:`${e.internals.ns.attr.selector("assess-file")}`,DOWNLOAD_DETAIL:`${e.internals.ns.selector("download__detail")}`};class Y extends e.core.Instance{static get instanceClassName(){return"AssessFile"}init(){this.lang=this.getLang(this.node),this.href=this.getAttribute("href"),this.hreflang=this.getAttribute("hreflang"),this.file={},this.detail=this.querySelector(J.DOWNLOAD_DETAIL),this.update()}getFileLength(){void 0!==this.href?fetch(this.href,{method:"HEAD",mode:"cors"}).then((e=>{this.length=e.headers.get("content-length")||-1,-1===this.length&&console.warn("Impossible de détecter le poids du fichier "+this.href+'\nErreur de récupération de l\'en-tête HTTP : "content-length"'),this.update()})):this.length=-1}update(){if(this.isLegacy&&(this.length=-1),!this.length)return void this.getFileLength();const e=[];if(this.detail){if(this.href){const t=this.parseExtension(this.href);t&&e.push(t.toUpperCase())}-1!==this.length&&e.push(this.bytesToSize(this.length)),this.hreflang&&e.push(this.getLangDisplayName(this.hreflang)),this.detail.innerHTML=e.join(" - ")}}getLang(e){return e.lang?e.lang:document.documentElement===e?window.navigator.language:this.getLang(e.parentElement)}parseExtension(e){return e.match(/\.(\w{1,9})(?:$|[?#])/)[0].replace(".","")}getLangDisplayName(e){if(this.isLegacy)return e;const t=new Intl.DisplayNames([this.lang],{type:"language"}).of(e);return t.charAt(0).toUpperCase()+t.slice(1)}bytesToSize(t){if(-1===t)return null;let s=["octets","ko","Mo","Go","To"];"bytes"===this.getAttribute(e.internals.ns.attr("assess-file"))&&(s=["bytes","KB","MB","GB","TB"]);const i=parseInt(Math.floor(Math.log(t)/Math.log(1e3)),10);if(0===i)return`${t} ${s[i]}`;const n=t/1e3**i,r=Math.round(100*(n+Number.EPSILON))/100;return`${String(r).replace(".",",")} ${s[i]}`}}e.download={DownloadSelector:J,AssessFile:Y},e.internals.register(e.download.DownloadSelector.DOWNLOAD_ASSESS_FILE,e.download.AssessFile);const Q={HEADER:e.internals.ns.selector("header"),TOOLS_LINKS:e.internals.ns.selector("header__tools-links"),MENU_LINKS:e.internals.ns.selector("header__menu-links"),BUTTONS:`${e.internals.ns.selector("header__tools-links")} ${e.internals.ns.selector("btns-group")}, ${e.internals.ns.selector("header__tools-links")} ${e.internals.ns.selector("links-group")}`,MODALS:`${e.internals.ns.selector("header__search")}${e.internals.ns.selector("modal")}, ${e.internals.ns.selector("header__menu")}${e.internals.ns.selector("modal")}`};class Z extends e.core.Instance{static get instanceClassName(){return"HeaderLinks"}init(){const t=this.queryParentSelector(Q.HEADER);this.toolsLinks=t.querySelector(Q.TOOLS_LINKS),this.menuLinks=t.querySelector(Q.MENU_LINKS);const s=this.toolsLinks.innerHTML.replace(/ +/g," "),i=this.menuLinks.innerHTML.replace(/ +/g," ");let n=s.replace(/(<nav[.\s\S]*-translate [.\s\S]*) id="(.*?)"([.\s\S]*<\/nav>)/gm,'$1 id="$2-mobile"$3');if(n=n.replace(/(<nav[.\s\S]*-translate [.\s\S]*) aria-controls="(.*?)"([.\s\S]*<\/nav>)/gm,'$1 aria-controls="$2-mobile"$3'),n!==i)switch(e.mode){case e.Modes.ANGULAR:case e.Modes.REACT:case e.Modes.VUE:e.inspector.warn(`header__tools-links content is different from header__menu-links content.\nAs you're using a dynamic framework, you should handle duplication of this content yourself, please refer to documentation:\n${e.header.doc}`);break;default:this.menuLinks.innerHTML=n}}}class X extends e.core.Instance{static get instanceClassName(){return"HeaderModal"}init(){this.isResizing=!0}resize(){this.isBreakpoint(e.core.Breakpoints.LG)?this.unqualify():this.qualify()}qualify(){this.setAttribute("role","dialog");const e=this.element.getInstance("Modal");if(!e)return;const t=e.buttons;let s="";for(const e of t)if(s=e.id||s,e.isPrimary&&s)break;this.setAttribute("aria-labelledby",s)}unqualify(){const e=this.element.getInstance("Modal");e&&e.conceal(),this.removeAttribute("role"),this.removeAttribute("aria-labelledby")}}e.header={HeaderLinks:Z,HeaderModal:X,HeaderSelector:Q,doc:"https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/en-tete"},e.internals.register(e.header.HeaderSelector.BUTTONS,e.header.HeaderLinks),e.internals.register(e.header.HeaderSelector.MODALS,e.header.HeaderModal);const ee={DISPLAY:e.internals.ns.selector("display"),RADIO_BUTTONS:`input[name="${e.internals.ns("radios-theme")}"]`,FIELDSET:e.internals.ns.selector("fieldset")};class te extends e.core.Instance{static get instanceClassName(){return"Display"}init(){if(this.radios=this.querySelectorAll(ee.RADIO_BUTTONS),e.scheme){this.changing=this.change.bind(this);for(const e of this.radios)e.addEventListener("change",this.changing);this.addDescent(e.scheme.SchemeEmission.SCHEME,this.apply.bind(this)),this.ascend(e.scheme.SchemeEmission.ASK)}else this.querySelector(ee.FIELDSET).setAttribute("disabled","")}get scheme(){return this._scheme}set scheme(t){if(this._scheme!==t&&e.scheme)switch(t){case e.scheme.SchemeValue.SYSTEM:case e.scheme.SchemeValue.LIGHT:case e.scheme.SchemeValue.DARK:this._scheme=t;for(const e of this.radios)e.checked=e.value===t;this.ascend(e.scheme.SchemeEmission.SCHEME,t)}}change(){for(const e of this.radios)if(e.checked)return void(this.scheme=e.value)}apply(e){this.scheme=e}dispose(){for(const e of this.radios)e.removeEventListener("change",this.changing)}}e.display={Display:te,DisplaySelector:ee},e.internals.register(e.display.DisplaySelector.DISPLAY,e.display.Display);
//# sourceMappingURL=component.module.min.js.map