{"version":3,"file":"scheme.module.js","sources":["../../.config/config.js","../../src/core/api.js","../../src/scheme/script/scheme/scheme-value.js","../../src/scheme/script/scheme/scheme-attribute.js","../../src/scheme/script/scheme/scheme-theme.js","../../src/scheme/script/scheme/scheme-emission.js","../../src/scheme/script/scheme/scheme-event.js","../../src/scheme/script/scheme/scheme.js","../../src/scheme/script/scheme/scheme-selector.js","../../src/scheme/index.js","../../src/scheme/main.js"],"sourcesContent":["const config = {\r\n prefix: 'fr',\r\n namespace: 'dsfr',\r\n organisation: '@gouvfr',\r\n version: '1.11.2'\r\n};\r\n\r\nexport default config;\r\n","import config from './config.js';\nconst api = window[config.namespace];\nexport default api;\n","export const SchemeValue = {\n SYSTEM: 'system',\n LIGHT: 'light',\n DARK: 'dark'\n};\n","import api from '../../api';\n\nexport const SchemeAttribute = {\n THEME: api.internals.ns.attr('theme'),\n SCHEME: api.internals.ns.attr('scheme'),\n TRANSITION: api.internals.ns.attr('transition')\n};\n","export const SchemeTheme = {\n LIGHT: 'light',\n DARK: 'dark'\n};\n","import api from '../../api';\n\nexport const SchemeEmission = {\n SCHEME: api.internals.ns.emission('scheme', 'scheme'),\n THEME: api.internals.ns.emission('scheme', 'theme'),\n ASK: api.internals.ns.emission('scheme', 'ask')\n};\n","import api from '../../api.js';\n\nconst SchemeEvent = {\n SCHEME: api.internals.ns.event('scheme'),\n THEME: api.internals.ns.event('theme')\n};\n\nexport { SchemeEvent };\n","import api from '../../api.js';\nimport { SchemeValue } from './scheme-value.js';\nimport { SchemeAttribute } from './scheme-attribute.js';\nimport { SchemeTheme } from './scheme-theme.js';\nimport { SchemeEmission } from './scheme-emission.js';\nimport { SchemeEvent } from './scheme-event.js';\n\nclass Scheme extends api.core.Instance {\n constructor () {\n super(false);\n }\n\n static get instanceClassName () {\n return 'Scheme';\n }\n\n init () {\n this.changing = this.change.bind(this);\n\n if (this.hasAttribute(SchemeAttribute.TRANSITION)) {\n this.removeAttribute(SchemeAttribute.TRANSITION);\n this.request(this.restoreTransition.bind(this));\n }\n\n const scheme = api.internals.support.supportLocalStorage() ? localStorage.getItem('scheme') : '';\n const schemeAttr = this.getAttribute(SchemeAttribute.SCHEME);\n\n switch (scheme) {\n case SchemeValue.DARK:\n case SchemeValue.LIGHT:\n case SchemeValue.SYSTEM:\n this.scheme = scheme;\n break;\n\n default:\n switch (schemeAttr) {\n case SchemeValue.DARK:\n this.scheme = SchemeValue.DARK;\n break;\n\n case SchemeValue.LIGHT:\n this.scheme = SchemeValue.LIGHT;\n break;\n\n default:\n this.scheme = SchemeValue.SYSTEM;\n }\n }\n\n this.addAscent(SchemeEmission.ASK, this.ask.bind(this));\n this.addAscent(SchemeEmission.SCHEME, this.apply.bind(this));\n }\n\n get proxy () {\n const scope = this;\n\n const proxyAccessors = {\n get scheme () {\n return scope.scheme;\n },\n set scheme (value) {\n scope.scheme = value;\n }\n };\n\n return api.internals.property.completeAssign(super.proxy, proxyAccessors);\n }\n\n restoreTransition () {\n this.setAttribute(SchemeAttribute.TRANSITION, '');\n }\n\n ask () {\n this.descend(SchemeEmission.SCHEME, this.scheme);\n }\n\n apply (value) {\n this.scheme = value;\n }\n\n get scheme () {\n return this._scheme;\n }\n\n set scheme (value) {\n if (this._scheme === value) return;\n this._scheme = value;\n switch (value) {\n case SchemeValue.SYSTEM:\n this.listenPreferences();\n break;\n\n case SchemeValue.DARK:\n this.unlistenPreferences();\n this.theme = SchemeTheme.DARK;\n break;\n\n case SchemeValue.LIGHT:\n this.unlistenPreferences();\n this.theme = SchemeTheme.LIGHT;\n break;\n\n default:\n this.scheme = SchemeValue.SYSTEM;\n return;\n }\n\n this.descend(SchemeEmission.SCHEME, value);\n if (api.internals.support.supportLocalStorage()) {\n localStorage.setItem('scheme', value);\n }\n this.setAttribute(SchemeAttribute.SCHEME, value);\n this.dispatch(SchemeEvent.SCHEME, { scheme: this._scheme });\n }\n\n get theme () {\n return this._theme;\n }\n\n set theme (value) {\n if (this._theme === value) return;\n switch (value) {\n case SchemeTheme.LIGHT:\n case SchemeTheme.DARK:\n this._theme = value;\n this.setAttribute(SchemeAttribute.THEME, value);\n this.descend(SchemeEmission.THEME, value);\n this.dispatch(SchemeEvent.THEME, { theme: this._theme });\n document.documentElement.style.colorScheme = value === SchemeTheme.DARK ? 'dark' : '';\n break;\n }\n }\n\n listenPreferences () {\n if (this.isListening) return;\n this.isListening = true;\n this.mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n if (this.mediaQuery.addEventListener) this.mediaQuery.addEventListener('change', this.changing);\n this.change();\n }\n\n unlistenPreferences () {\n if (!this.isListening) return;\n this.isListening = false;\n this.mediaQuery.removeEventListener('change', this.changing);\n this.mediaQuery = null;\n }\n\n change () {\n if (!this.isListening) return;\n this.theme = this.mediaQuery.matches ? SchemeTheme.DARK : SchemeTheme.LIGHT;\n }\n\n mutate (attributeNames) {\n if (attributeNames.indexOf(SchemeAttribute.SCHEME) > -1) this.scheme = this.getAttribute(SchemeAttribute.SCHEME);\n if (attributeNames.indexOf(SchemeAttribute.THEME) > -1) this.theme = this.getAttribute(SchemeAttribute.THEME);\n }\n\n dispose () {\n this.unlistenPreferences();\n }\n}\n\nexport { Scheme };\n","import api from '../../api.js';\n\nexport const SchemeSelector = {\n SCHEME: `:root${api.internals.ns.attr.selector('theme')}, :root${api.internals.ns.attr.selector('scheme')}`,\n SWITCH_THEME: api.internals.ns.selector('switch-theme'),\n RADIO_BUTTONS: `input[name=\"${api.internals.ns('radios-theme')}\"]`\n};\n","import api from './api.js';\nimport { Scheme } from './script/scheme/scheme.js';\nimport { SchemeValue } from './script/scheme/scheme-value.js';\nimport { SchemeSelector } from './script/scheme/scheme-selector.js';\nimport { SchemeEmission } from './script/scheme/scheme-emission.js';\nimport { SchemeTheme } from './script/scheme/scheme-theme.js';\nimport { SchemeEvent } from './script/scheme/scheme-event';\n\napi.scheme = {\n Scheme: Scheme,\n SchemeValue: SchemeValue,\n SchemeSelector: SchemeSelector,\n SchemeEmission: SchemeEmission,\n SchemeTheme: SchemeTheme,\n SchemeEvent: SchemeEvent\n};\n\nexport default api;\n","import api from './index.js';\n\napi.internals.register(api.scheme.SchemeSelector.SCHEME, api.scheme.Scheme);\n\nexport default api;\n"],"names":[],"mappings":";;AAAA,MAAM,MAAM,GAAG;AACf,EAAE,MAAM,EAAE,IAAI;AACd,EAAE,SAAS,EAAE,MAAM;AACnB,EAAE,YAAY,EAAE,SAAS;AACzB,EAAE,OAAO,EAAE,QAAQ;AACnB,CAAC;;ACJD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;;ACD7B,MAAM,WAAW,GAAG;AAC3B,EAAE,MAAM,EAAE,QAAQ;AAClB,EAAE,KAAK,EAAE,OAAO;AAChB,EAAE,IAAI,EAAE,MAAM;AACd,CAAC;;ACFM,MAAM,eAAe,GAAG;AAC/B,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;AACvC,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;AACzC,EAAE,UAAU,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC;AACjD,CAAC;;ACNM,MAAM,WAAW,GAAG;AAC3B,EAAE,KAAK,EAAE,OAAO;AAChB,EAAE,IAAI,EAAE,MAAM;AACd,CAAC;;ACDM,MAAM,cAAc,GAAG;AAC9B,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACvD,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;AACrD,EAAE,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;AACjD,CAAC;;ACJD,MAAM,WAAW,GAAG;A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