@lukso/core 1.2.5 → 1.2.6-dev.14d5261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-O2MNO3WV.js → chunk-FYBOO4QG.js} +2 -1
- package/dist/{chunk-O2MNO3WV.js.map → chunk-FYBOO4QG.js.map} +1 -1
- package/dist/{chunk-GBVTZLYF.cjs → chunk-XC6DJ5HO.cjs} +2 -1
- package/dist/chunk-XC6DJ5HO.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/mixins/index.cjs +2 -2
- package/dist/mixins/index.js +1 -1
- package/dist/mixins/theme.cjs +2 -2
- package/dist/mixins/theme.js +1 -1
- package/package.json +1 -1
- package/src/mixins/theme.ts +1 -0
- package/dist/chunk-GBVTZLYF.cjs.map +0 -1
|
@@ -82,6 +82,7 @@ function withTheme(Base) {
|
|
|
82
82
|
const root = super.createRenderRoot();
|
|
83
83
|
this.themeRoot = document.createElement("div");
|
|
84
84
|
this.themeRoot.setAttribute("data-theme-root", "");
|
|
85
|
+
this.themeRoot.style.width = "inherit";
|
|
85
86
|
root.appendChild(this.themeRoot);
|
|
86
87
|
return this.themeRoot;
|
|
87
88
|
}
|
|
@@ -110,4 +111,4 @@ function withTheme(Base) {
|
|
|
110
111
|
export {
|
|
111
112
|
withTheme
|
|
112
113
|
};
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
114
|
+
//# sourceMappingURL=chunk-FYBOO4QG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mixins/theme.ts"],"sourcesContent":["/**\n * Theme Mixin\n *\n * Mixin to add theme detection and management to a Lit component\n */\n\nimport type { LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\n\nexport type Theme = 'light' | 'dark' | 'auto'\n\n/**\n * Interface for components that have theme management capabilities\n */\nexport interface ThemeMixin {\n theme: Theme\n isDark: boolean\n updateTheme(): void\n}\n\n/**\n * Type helper for the constructor returned by withTheme\n */\nexport type ThemeMixinConstructor<T extends typeof LitElement> = (new (\n ...args: any[]\n) => InstanceType<T> & ThemeMixin) &\n T\n\n/**\n * Mixin to add theme management to a Lit component\n *\n * Provides a `theme` property and `isDark` state that automatically handles:\n * - Manual theme selection ('light' or 'dark')\n * - Auto theme detection based on system preferences\n * - Reactive updates when system theme changes\n * - Automatically wraps all rendered content in a themed div with 'dark' class when dark mode is active\n *\n * All content rendered by the component will be inside a theme-root div that receives the dark class.\n * Components can use render() normally - no changes needed.\n *\n * @typeParam T - The Lit component class being extended\n * @returns Extended class with theme management capabilities\n *\n * @example\n * ```typescript\n * import { LitElement, html } from 'lit';\n * import { customElement } from 'lit/decorators.js';\n * import { withTheme } from '@lukso/core/mixins';\n *\n * @customElement('my-component')\n * export class MyComponent extends withTheme(LitElement) {\n * render() {\n * return html`\n * <div class=\"text-neutral-20 dark:text-neutral-100\">\n * Current theme: ${this.theme}\n * </div>\n * `;\n * }\n * }\n * ```\n */\nexport function withTheme<T extends typeof LitElement>(\n Base: T\n): ThemeMixinConstructor<T> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n class Mixin extends (Base as any) {\n /**\n * Theme mode: 'light', 'dark', or 'auto' (follows system preference)\n */\n @property({ type: String, reflect: true })\n theme: Theme = 'light'\n\n /**\n * Computed state indicating if dark mode is active\n */\n @state()\n protected isDark = false\n\n /**\n * The theme root element that wraps all rendered content and receives the dark class\n */\n private themeRoot!: HTMLDivElement\n\n private mediaQueryList: MediaQueryList | null = null\n\n connectedCallback(): void {\n super.connectedCallback()\n this.updateTheme()\n this.updateHostClass()\n\n // Listen for system theme changes when in 'auto' mode\n if (this.theme === 'auto') {\n this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n\n if (this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n updated(changedProperties: Map<string, any>): void {\n super.updated(changedProperties)\n\n // Handle theme changes\n if (changedProperties.has('theme')) {\n this.updateTheme()\n\n // Update media query listener when theme mode changes\n if (this.theme === 'auto' && !this.mediaQueryList) {\n this.mediaQueryList = window.matchMedia(\n '(prefers-color-scheme: dark)'\n )\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n } else if (this.theme !== 'auto' && this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n this.mediaQueryList = null\n }\n }\n\n // Update host class when isDark changes\n if (changedProperties.has('isDark')) {\n this.updateHostClass()\n }\n }\n\n /**\n * Handle system theme changes\n *\n * @param event - Media query list event\n */\n private handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n this.isDark = event.matches\n }\n\n /**\n * Update isDark state based on theme property\n */\n protected updateTheme(): void {\n if (this.theme === 'auto') {\n this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n } else {\n this.isDark = this.theme === 'dark'\n }\n }\n\n /**\n * Create the render root with a themed wrapper div\n */\n createRenderRoot(): Element | ShadowRoot {\n const root = super.createRenderRoot()\n\n this.themeRoot = document.createElement('div')\n this.themeRoot.setAttribute('data-theme-root', '')\n\n root.appendChild(this.themeRoot)\n return this.themeRoot\n }\n\n /**\n * Update the host element's and theme root's class based on isDark state\n */\n private updateHostClass(): void {\n if (this.isDark) {\n this.classList.add('dark')\n this.themeRoot.classList.add('dark')\n } else {\n this.classList.remove('dark')\n this.themeRoot.classList.remove('dark')\n }\n }\n }\n\n return Mixin as unknown as ThemeMixinConstructor<T>\n}\n"],"mappings":";;;;;AAOA,SAAS,UAAU,aAAa;AAsDzB,SAAS,UACd,MAC0B;AAAA,EAE1B,MAAM,cAAe,KAAa;AAAA,IAAlC;AAAA;AAKE,mBAAe;AAMf,WAAU,SAAS;AAOnB,WAAQ,iBAAwC;AAgEhD;AAAA;AA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iB;AAEpC,WAAK,YAAY,SAAS,cAAc,KAAK;AAC7C,WAAK,UAAU,aAAa,mBAAmB,EAAE;
|
|
1
|
+
{"version":3,"sources":["../src/mixins/theme.ts"],"sourcesContent":["/**\n * Theme Mixin\n *\n * Mixin to add theme detection and management to a Lit component\n */\n\nimport type { LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\n\nexport type Theme = 'light' | 'dark' | 'auto'\n\n/**\n * Interface for components that have theme management capabilities\n */\nexport interface ThemeMixin {\n theme: Theme\n isDark: boolean\n updateTheme(): void\n}\n\n/**\n * Type helper for the constructor returned by withTheme\n */\nexport type ThemeMixinConstructor<T extends typeof LitElement> = (new (\n ...args: any[]\n) => InstanceType<T> & ThemeMixin) &\n T\n\n/**\n * Mixin to add theme management to a Lit component\n *\n * Provides a `theme` property and `isDark` state that automatically handles:\n * - Manual theme selection ('light' or 'dark')\n * - Auto theme detection based on system preferences\n * - Reactive updates when system theme changes\n * - Automatically wraps all rendered content in a themed div with 'dark' class when dark mode is active\n *\n * All content rendered by the component will be inside a theme-root div that receives the dark class.\n * Components can use render() normally - no changes needed.\n *\n * @typeParam T - The Lit component class being extended\n * @returns Extended class with theme management capabilities\n *\n * @example\n * ```typescript\n * import { LitElement, html } from 'lit';\n * import { customElement } from 'lit/decorators.js';\n * import { withTheme } from '@lukso/core/mixins';\n *\n * @customElement('my-component')\n * export class MyComponent extends withTheme(LitElement) {\n * render() {\n * return html`\n * <div class=\"text-neutral-20 dark:text-neutral-100\">\n * Current theme: ${this.theme}\n * </div>\n * `;\n * }\n * }\n * ```\n */\nexport function withTheme<T extends typeof LitElement>(\n Base: T\n): ThemeMixinConstructor<T> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n class Mixin extends (Base as any) {\n /**\n * Theme mode: 'light', 'dark', or 'auto' (follows system preference)\n */\n @property({ type: String, reflect: true })\n theme: Theme = 'light'\n\n /**\n * Computed state indicating if dark mode is active\n */\n @state()\n protected isDark = false\n\n /**\n * The theme root element that wraps all rendered content and receives the dark class\n */\n private themeRoot!: HTMLDivElement\n\n private mediaQueryList: MediaQueryList | null = null\n\n connectedCallback(): void {\n super.connectedCallback()\n this.updateTheme()\n this.updateHostClass()\n\n // Listen for system theme changes when in 'auto' mode\n if (this.theme === 'auto') {\n this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n\n if (this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n updated(changedProperties: Map<string, any>): void {\n super.updated(changedProperties)\n\n // Handle theme changes\n if (changedProperties.has('theme')) {\n this.updateTheme()\n\n // Update media query listener when theme mode changes\n if (this.theme === 'auto' && !this.mediaQueryList) {\n this.mediaQueryList = window.matchMedia(\n '(prefers-color-scheme: dark)'\n )\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n } else if (this.theme !== 'auto' && this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n this.mediaQueryList = null\n }\n }\n\n // Update host class when isDark changes\n if (changedProperties.has('isDark')) {\n this.updateHostClass()\n }\n }\n\n /**\n * Handle system theme changes\n *\n * @param event - Media query list event\n */\n private handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n this.isDark = event.matches\n }\n\n /**\n * Update isDark state based on theme property\n */\n protected updateTheme(): void {\n if (this.theme === 'auto') {\n this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n } else {\n this.isDark = this.theme === 'dark'\n }\n }\n\n /**\n * Create the render root with a themed wrapper div\n */\n createRenderRoot(): Element | ShadowRoot {\n const root = super.createRenderRoot()\n\n this.themeRoot = document.createElement('div')\n this.themeRoot.setAttribute('data-theme-root', '')\n this.themeRoot.style.width = 'inherit'\n\n root.appendChild(this.themeRoot)\n return this.themeRoot\n }\n\n /**\n * Update the host element's and theme root's class based on isDark state\n */\n private updateHostClass(): void {\n if (this.isDark) {\n this.classList.add('dark')\n this.themeRoot.classList.add('dark')\n } else {\n this.classList.remove('dark')\n this.themeRoot.classList.remove('dark')\n }\n }\n }\n\n return Mixin as unknown as ThemeMixinConstructor<T>\n}\n"],"mappings":";;;;;AAOA,SAAS,UAAU,aAAa;AAsDzB,SAAS,UACd,MAC0B;AAAA,EAE1B,MAAM,cAAe,KAAa;AAAA,IAAlC;AAAA;AAKE,mBAAe;AAMf,WAAU,SAAS;AAOnB,WAAQ,iBAAwC;AAgEhD;AAAA;AAAA;AAAA;AAAA;AAAA,WAAQ,yBAAyB,CAAC,UAAqC;AACrE,aAAK,SAAS,MAAM;AAAA,MACtB;AAAA;AAAA,IAhEA,oBAA0B;AACxB,YAAM,kBAAkB;AACxB,WAAK,YAAY;AACjB,WAAK,gBAAgB;AAGrB,UAAI,KAAK,UAAU,QAAQ;AACzB,aAAK,iBAAiB,OAAO,WAAW,8BAA8B;AACtE,aAAK,eAAe;AAAA,UAClB;AAAA,UACA,KAAK;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAAA,IAEA,uBAA6B;AAC3B,YAAM,qBAAqB;AAE3B,UAAI,KAAK,gBAAgB;AACvB,aAAK,eAAe;AAAA,UAClB;AAAA,UACA,KAAK;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAAA,IAEA,QAAQ,mBAA2C;AACjD,YAAM,QAAQ,iBAAiB;AAG/B,UAAI,kBAAkB,IAAI,OAAO,GAAG;AAClC,aAAK,YAAY;AAGjB,YAAI,KAAK,UAAU,UAAU,CAAC,KAAK,gBAAgB;AACjD,eAAK,iBAAiB,OAAO;AAAA,YAC3B;AAAA,UACF;AACA,eAAK,eAAe;AAAA,YAClB;AAAA,YACA,KAAK;AAAA,UACP;AAAA,QACF,WAAW,KAAK,UAAU,UAAU,KAAK,gBAAgB;AACvD,eAAK,eAAe;AAAA,YAClB;AAAA,YACA,KAAK;AAAA,UACP;AACA,eAAK,iBAAiB;AAAA,QACxB;AAAA,MACF;AAGA,UAAI,kBAAkB,IAAI,QAAQ,GAAG;AACnC,aAAK,gBAAgB;AAAA,MACvB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAcU,cAAoB;AAC5B,UAAI,KAAK,UAAU,QAAQ;AACzB,aAAK,SAAS,OAAO,WAAW,8BAA8B,EAAE;AAAA,MAClE,OAAO;AACL,aAAK,SAAS,KAAK,UAAU;AAAA,MAC/B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,mBAAyC;AACvC,YAAM,OAAO,MAAM,iBAAiB;AAEpC,WAAK,YAAY,SAAS,cAAc,KAAK;AAC7C,WAAK,UAAU,aAAa,mBAAmB,EAAE;AACjD,WAAK,UAAU,MAAM,QAAQ;AAE7B,WAAK,YAAY,KAAK,SAAS;AAC/B,aAAO,KAAK;AAAA,IACd;AAAA;AAAA;AAAA;AAAA,IAKQ,kBAAwB;AAC9B,UAAI,KAAK,QAAQ;AACf,aAAK,UAAU,IAAI,MAAM;AACzB,aAAK,UAAU,UAAU,IAAI,MAAM;AAAA,MACrC,OAAO;AACL,aAAK,UAAU,OAAO,MAAM;AAC5B,aAAK,UAAU,UAAU,OAAO,MAAM;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAtHE;AAAA,IADC,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK,CAAC;AAAA,KAJrC,MAKJ;AAMU;AAAA,IADT,MAAM;AAAA,KAVH,MAWM;AAkHZ,SAAO;AACT;","names":[]}
|
|
@@ -82,6 +82,7 @@ function withTheme(Base) {
|
|
|
82
82
|
const root = super.createRenderRoot();
|
|
83
83
|
this.themeRoot = document.createElement("div");
|
|
84
84
|
this.themeRoot.setAttribute("data-theme-root", "");
|
|
85
|
+
this.themeRoot.style.width = "inherit";
|
|
85
86
|
root.appendChild(this.themeRoot);
|
|
86
87
|
return this.themeRoot;
|
|
87
88
|
}
|
|
@@ -110,4 +111,4 @@ function withTheme(Base) {
|
|
|
110
111
|
|
|
111
112
|
|
|
112
113
|
exports.withTheme = withTheme;
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
114
|
+
//# sourceMappingURL=chunk-XC6DJ5HO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-XC6DJ5HO.cjs","../src/mixins/theme.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACGA,iDAAgC;AAsDzB,SAAS,SAAA,CACd,IAAA,EAC0B;AAAA,EAE1B,MAAM,MAAA,QAAe,KAAa;AAAA,IAAlC,WAAA,CAAA,EAAA;AAAA,MAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAKE,MAAA,IAAA,CAAA,MAAA,EAAe,OAAA;AAMf,MAAA,IAAA,CAAU,OAAA,EAAS,KAAA;AAOnB,MAAA,IAAA,CAAQ,eAAA,EAAwC,IAAA;AAgEhD;AAAA;AAAA;AAAA;AAAA;AAAA,MAAA,IAAA,CAAQ,uBAAA,EAAyB,CAAC,KAAA,EAAA,GAAqC;AACrE,QAAA,IAAA,CAAK,OAAA,EAAS,KAAA,CAAM,OAAA;AAAA,MACtB,CAAA;AAAA,IAAA;AAAA,IAhEA,iBAAA,CAAA,EAA0B;AACxB,MAAA,KAAA,CAAM,iBAAA,CAAkB,CAAA;AACxB,MAAA,IAAA,CAAK,WAAA,CAAY,CAAA;AACjB,MAAA,IAAA,CAAK,eAAA,CAAgB,CAAA;AAGrB,MAAA,GAAA,CAAI,IAAA,CAAK,MAAA,IAAU,MAAA,EAAQ;AACzB,QAAA,IAAA,CAAK,eAAA,EAAiB,MAAA,CAAO,UAAA,CAAW,8BAA8B,CAAA;AACtE,QAAA,IAAA,CAAK,cAAA,CAAe,gBAAA;AAAA,UAClB,QAAA;AAAA,UACA,IAAA,CAAK;AAAA,QACP,CAAA;AAAA,MACF;AAAA,IACF;AAAA,IAEA,oBAAA,CA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CAAA;AAAA,IADT,iCAAA;AAAM,EAAA,CAAA,EAVH,KAAA,CAWM,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAkHZ,EAAA,OAAO,KAAA;AACT;ADlFA;AACA;AACE;AACF,8BAAC","file":"/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-XC6DJ5HO.cjs","sourcesContent":[null,"/**\n * Theme Mixin\n *\n * Mixin to add theme detection and management to a Lit component\n */\n\nimport type { LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\n\nexport type Theme = 'light' | 'dark' | 'auto'\n\n/**\n * Interface for components that have theme management capabilities\n */\nexport interface ThemeMixin {\n theme: Theme\n isDark: boolean\n updateTheme(): void\n}\n\n/**\n * Type helper for the constructor returned by withTheme\n */\nexport type ThemeMixinConstructor<T extends typeof LitElement> = (new (\n ...args: any[]\n) => InstanceType<T> & ThemeMixin) &\n T\n\n/**\n * Mixin to add theme management to a Lit component\n *\n * Provides a `theme` property and `isDark` state that automatically handles:\n * - Manual theme selection ('light' or 'dark')\n * - Auto theme detection based on system preferences\n * - Reactive updates when system theme changes\n * - Automatically wraps all rendered content in a themed div with 'dark' class when dark mode is active\n *\n * All content rendered by the component will be inside a theme-root div that receives the dark class.\n * Components can use render() normally - no changes needed.\n *\n * @typeParam T - The Lit component class being extended\n * @returns Extended class with theme management capabilities\n *\n * @example\n * ```typescript\n * import { LitElement, html } from 'lit';\n * import { customElement } from 'lit/decorators.js';\n * import { withTheme } from '@lukso/core/mixins';\n *\n * @customElement('my-component')\n * export class MyComponent extends withTheme(LitElement) {\n * render() {\n * return html`\n * <div class=\"text-neutral-20 dark:text-neutral-100\">\n * Current theme: ${this.theme}\n * </div>\n * `;\n * }\n * }\n * ```\n */\nexport function withTheme<T extends typeof LitElement>(\n Base: T\n): ThemeMixinConstructor<T> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n class Mixin extends (Base as any) {\n /**\n * Theme mode: 'light', 'dark', or 'auto' (follows system preference)\n */\n @property({ type: String, reflect: true })\n theme: Theme = 'light'\n\n /**\n * Computed state indicating if dark mode is active\n */\n @state()\n protected isDark = false\n\n /**\n * The theme root element that wraps all rendered content and receives the dark class\n */\n private themeRoot!: HTMLDivElement\n\n private mediaQueryList: MediaQueryList | null = null\n\n connectedCallback(): void {\n super.connectedCallback()\n this.updateTheme()\n this.updateHostClass()\n\n // Listen for system theme changes when in 'auto' mode\n if (this.theme === 'auto') {\n this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n\n if (this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n updated(changedProperties: Map<string, any>): void {\n super.updated(changedProperties)\n\n // Handle theme changes\n if (changedProperties.has('theme')) {\n this.updateTheme()\n\n // Update media query listener when theme mode changes\n if (this.theme === 'auto' && !this.mediaQueryList) {\n this.mediaQueryList = window.matchMedia(\n '(prefers-color-scheme: dark)'\n )\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n } else if (this.theme !== 'auto' && this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n this.mediaQueryList = null\n }\n }\n\n // Update host class when isDark changes\n if (changedProperties.has('isDark')) {\n this.updateHostClass()\n }\n }\n\n /**\n * Handle system theme changes\n *\n * @param event - Media query list event\n */\n private handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n this.isDark = event.matches\n }\n\n /**\n * Update isDark state based on theme property\n */\n protected updateTheme(): void {\n if (this.theme === 'auto') {\n this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n } else {\n this.isDark = this.theme === 'dark'\n }\n }\n\n /**\n * Create the render root with a themed wrapper div\n */\n createRenderRoot(): Element | ShadowRoot {\n const root = super.createRenderRoot()\n\n this.themeRoot = document.createElement('div')\n this.themeRoot.setAttribute('data-theme-root', '')\n this.themeRoot.style.width = 'inherit'\n\n root.appendChild(this.themeRoot)\n return this.themeRoot\n }\n\n /**\n * Update the host element's and theme root's class based on isDark state\n */\n private updateHostClass(): void {\n if (this.isDark) {\n this.classList.add('dark')\n this.themeRoot.classList.add('dark')\n } else {\n this.classList.remove('dark')\n this.themeRoot.classList.remove('dark')\n }\n }\n }\n\n return Mixin as unknown as ThemeMixinConstructor<T>\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var _chunkKPIUNN26cjs = require('./chunk-KPIUNN26.cjs');
|
|
|
33
33
|
var _chunkIDQ6WJY5cjs = require('./chunk-IDQ6WJY5.cjs');
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var _chunkXC6DJ5HOcjs = require('./chunk-XC6DJ5HO.cjs');
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
var _chunkNJQVWIZLcjs = require('./chunk-NJQVWIZL.cjs');
|
|
@@ -60,5 +60,5 @@ require('./chunk-ZBDE64SD.cjs');
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
exports.EXTENSION_STORE_LINKS = _chunkQU6NUTY6cjs.EXTENSION_STORE_LINKS; exports.GRAPHQL_ENDPOINT_MAINNET = _chunkLUT5BHYLcjs.GRAPHQL_ENDPOINT_MAINNET; exports.GRAPHQL_ENDPOINT_TESTNET = _chunkLUT5BHYLcjs.GRAPHQL_ENDPOINT_TESTNET; exports.LUKSO_CHAINS_BY_ID = _chunkMCNNULYXcjs.LUKSO_CHAINS_BY_ID; exports.SUPPORTED_NETWORK_IDS = _chunkLUT5BHYLcjs.SUPPORTED_NETWORK_IDS; exports.UrlConverter = _chunkQU6NUTY6cjs.UrlConverter; exports.UrlResolver = _chunkQU6NUTY6cjs.UrlResolver; exports.browserInfo = _chunkQU6NUTY6cjs.browserInfo; exports.clearIntlService = _chunkIDQ6WJY5cjs.clearIntlService; exports.createIntlService = _chunkIDQ6WJY5cjs.createIntlService; exports.defaultConfig = _chunkIDQ6WJY5cjs.defaultConfig; exports.deviceService = _chunkNJQVWIZLcjs.deviceService; exports.getChainById = _chunkMCNNULYXcjs.getChainById; exports.getIntlService = _chunkIDQ6WJY5cjs.getIntlService; exports.luksoMainnet = _chunkMCNNULYXcjs.luksoMainnet; exports.luksoTestnet = _chunkMCNNULYXcjs.luksoTestnet; exports.setIntlService = _chunkIDQ6WJY5cjs.setIntlService; exports.slug = _chunkQU6NUTY6cjs.slug; exports.withDeviceService = _chunkUQSIH233cjs.withDeviceService; exports.withIntlService = _chunkKPIUNN26cjs.withIntlService; exports.withTheme =
|
|
63
|
+
exports.EXTENSION_STORE_LINKS = _chunkQU6NUTY6cjs.EXTENSION_STORE_LINKS; exports.GRAPHQL_ENDPOINT_MAINNET = _chunkLUT5BHYLcjs.GRAPHQL_ENDPOINT_MAINNET; exports.GRAPHQL_ENDPOINT_TESTNET = _chunkLUT5BHYLcjs.GRAPHQL_ENDPOINT_TESTNET; exports.LUKSO_CHAINS_BY_ID = _chunkMCNNULYXcjs.LUKSO_CHAINS_BY_ID; exports.SUPPORTED_NETWORK_IDS = _chunkLUT5BHYLcjs.SUPPORTED_NETWORK_IDS; exports.UrlConverter = _chunkQU6NUTY6cjs.UrlConverter; exports.UrlResolver = _chunkQU6NUTY6cjs.UrlResolver; exports.browserInfo = _chunkQU6NUTY6cjs.browserInfo; exports.clearIntlService = _chunkIDQ6WJY5cjs.clearIntlService; exports.createIntlService = _chunkIDQ6WJY5cjs.createIntlService; exports.defaultConfig = _chunkIDQ6WJY5cjs.defaultConfig; exports.deviceService = _chunkNJQVWIZLcjs.deviceService; exports.getChainById = _chunkMCNNULYXcjs.getChainById; exports.getIntlService = _chunkIDQ6WJY5cjs.getIntlService; exports.luksoMainnet = _chunkMCNNULYXcjs.luksoMainnet; exports.luksoTestnet = _chunkMCNNULYXcjs.luksoTestnet; exports.setIntlService = _chunkIDQ6WJY5cjs.setIntlService; exports.slug = _chunkQU6NUTY6cjs.slug; exports.withDeviceService = _chunkUQSIH233cjs.withDeviceService; exports.withIntlService = _chunkKPIUNN26cjs.withIntlService; exports.withTheme = _chunkXC6DJ5HOcjs.withTheme;
|
|
64
64
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/dist/mixins/index.cjs
CHANGED
|
@@ -8,12 +8,12 @@ var _chunkKPIUNN26cjs = require('../chunk-KPIUNN26.cjs');
|
|
|
8
8
|
require('../chunk-IDQ6WJY5.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkXC6DJ5HOcjs = require('../chunk-XC6DJ5HO.cjs');
|
|
12
12
|
require('../chunk-NJQVWIZL.cjs');
|
|
13
13
|
require('../chunk-ZBDE64SD.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
exports.withDeviceService = _chunkUQSIH233cjs.withDeviceService; exports.withIntlService = _chunkKPIUNN26cjs.withIntlService; exports.withTheme =
|
|
18
|
+
exports.withDeviceService = _chunkUQSIH233cjs.withDeviceService; exports.withIntlService = _chunkKPIUNN26cjs.withIntlService; exports.withTheme = _chunkXC6DJ5HOcjs.withTheme;
|
|
19
19
|
//# sourceMappingURL=index.cjs.map
|
package/dist/mixins/index.js
CHANGED
package/dist/mixins/theme.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkXC6DJ5HOcjs = require('../chunk-XC6DJ5HO.cjs');
|
|
4
4
|
require('../chunk-ZBDE64SD.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.withTheme =
|
|
7
|
+
exports.withTheme = _chunkXC6DJ5HOcjs.withTheme;
|
|
8
8
|
//# sourceMappingURL=theme.cjs.map
|
package/dist/mixins/theme.js
CHANGED
package/package.json
CHANGED
package/src/mixins/theme.ts
CHANGED
|
@@ -168,6 +168,7 @@ export function withTheme<T extends typeof LitElement>(
|
|
|
168
168
|
|
|
169
169
|
this.themeRoot = document.createElement('div')
|
|
170
170
|
this.themeRoot.setAttribute('data-theme-root', '')
|
|
171
|
+
this.themeRoot.style.width = 'inherit'
|
|
171
172
|
|
|
172
173
|
root.appendChild(this.themeRoot)
|
|
173
174
|
return this.themeRoot
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-GBVTZLYF.cjs","../src/mixins/theme.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACGA,iDAAgC;AAsDzB,SAAS,SAAA,CACd,IAAA,EAC0B;AAAA,EAE1B,MAAM,MAAA,QAAe,KAAa;AAAA,IAAlC,WAAA,CAAA,EAAA;AAAA,MAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAKE,MAAA,IAAA,CAAA,MAAA,EAAe,OAAA;AAMf,MAAA,IAAA,CAAU,OAAA,EAAS,KAAA;AAOnB,MAAA,IAAA,CAAQ,eAAA,EAAwC,IAAA;AAgEhD;AAAA;AAAA;AAAA;AAAA;AAAA,MAAA,IAAA,CAAQ,uBAAA,EAAyB,CAAC,KAAA,EAAA,GAAqC;AACrE,QAAA,IAAA,CAAK,OAAA,EAAS,KAAA,CAAM,OAAA;AAAA,MACtB,CAAA;AAAA,IAAA;AAAA,IAhEA,iBAAA,CAAA,EAA0B;AACxB,MAAA,KAAA,CAAM,iBAAA,CAAkB,CAAA;AACxB,MAAA,IAAA,CAAK,WAAA,CAAY,CAAA;AACjB,MAAA,IAAA,CAAK,eAAA,CAAgB,CAAA;AAGrB,MAAA,GAAA,CAAI,IAAA,CAAK,MAAA,IAAU,MAAA,EAAQ;AACzB,QAAA,IAAA,CAAK,eAAA,EAAiB,MAAA,CAAO,UAAA,CAAW,8BAA8B,CAAA;AACtE,QAAA,IAAA,CAAK,cAAA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AA,EAAA,OAAA,EAAA,CAAA,CAAA;AAMU,EAAA,+CAAA;AAAA,IADT,iCAAA;AAAM,EAAA,CAAA,EAVH,KAAA,CAWM,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAiHZ,EAAA,OAAO,KAAA;AACT;ADlFA;AACA;AACE;AACF,8BAAC","file":"/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-GBVTZLYF.cjs","sourcesContent":[null,"/**\n * Theme Mixin\n *\n * Mixin to add theme detection and management to a Lit component\n */\n\nimport type { LitElement } from 'lit'\nimport { property, state } from 'lit/decorators.js'\n\nexport type Theme = 'light' | 'dark' | 'auto'\n\n/**\n * Interface for components that have theme management capabilities\n */\nexport interface ThemeMixin {\n theme: Theme\n isDark: boolean\n updateTheme(): void\n}\n\n/**\n * Type helper for the constructor returned by withTheme\n */\nexport type ThemeMixinConstructor<T extends typeof LitElement> = (new (\n ...args: any[]\n) => InstanceType<T> & ThemeMixin) &\n T\n\n/**\n * Mixin to add theme management to a Lit component\n *\n * Provides a `theme` property and `isDark` state that automatically handles:\n * - Manual theme selection ('light' or 'dark')\n * - Auto theme detection based on system preferences\n * - Reactive updates when system theme changes\n * - Automatically wraps all rendered content in a themed div with 'dark' class when dark mode is active\n *\n * All content rendered by the component will be inside a theme-root div that receives the dark class.\n * Components can use render() normally - no changes needed.\n *\n * @typeParam T - The Lit component class being extended\n * @returns Extended class with theme management capabilities\n *\n * @example\n * ```typescript\n * import { LitElement, html } from 'lit';\n * import { customElement } from 'lit/decorators.js';\n * import { withTheme } from '@lukso/core/mixins';\n *\n * @customElement('my-component')\n * export class MyComponent extends withTheme(LitElement) {\n * render() {\n * return html`\n * <div class=\"text-neutral-20 dark:text-neutral-100\">\n * Current theme: ${this.theme}\n * </div>\n * `;\n * }\n * }\n * ```\n */\nexport function withTheme<T extends typeof LitElement>(\n Base: T\n): ThemeMixinConstructor<T> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n class Mixin extends (Base as any) {\n /**\n * Theme mode: 'light', 'dark', or 'auto' (follows system preference)\n */\n @property({ type: String, reflect: true })\n theme: Theme = 'light'\n\n /**\n * Computed state indicating if dark mode is active\n */\n @state()\n protected isDark = false\n\n /**\n * The theme root element that wraps all rendered content and receives the dark class\n */\n private themeRoot!: HTMLDivElement\n\n private mediaQueryList: MediaQueryList | null = null\n\n connectedCallback(): void {\n super.connectedCallback()\n this.updateTheme()\n this.updateHostClass()\n\n // Listen for system theme changes when in 'auto' mode\n if (this.theme === 'auto') {\n this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n\n if (this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n }\n }\n\n updated(changedProperties: Map<string, any>): void {\n super.updated(changedProperties)\n\n // Handle theme changes\n if (changedProperties.has('theme')) {\n this.updateTheme()\n\n // Update media query listener when theme mode changes\n if (this.theme === 'auto' && !this.mediaQueryList) {\n this.mediaQueryList = window.matchMedia(\n '(prefers-color-scheme: dark)'\n )\n this.mediaQueryList.addEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n } else if (this.theme !== 'auto' && this.mediaQueryList) {\n this.mediaQueryList.removeEventListener(\n 'change',\n this.handleMediaQueryChange\n )\n this.mediaQueryList = null\n }\n }\n\n // Update host class when isDark changes\n if (changedProperties.has('isDark')) {\n this.updateHostClass()\n }\n }\n\n /**\n * Handle system theme changes\n *\n * @param event - Media query list event\n */\n private handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n this.isDark = event.matches\n }\n\n /**\n * Update isDark state based on theme property\n */\n protected updateTheme(): void {\n if (this.theme === 'auto') {\n this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n } else {\n this.isDark = this.theme === 'dark'\n }\n }\n\n /**\n * Create the render root with a themed wrapper div\n */\n createRenderRoot(): Element | ShadowRoot {\n const root = super.createRenderRoot()\n\n this.themeRoot = document.createElement('div')\n this.themeRoot.setAttribute('data-theme-root', '')\n\n root.appendChild(this.themeRoot)\n return this.themeRoot\n }\n\n /**\n * Update the host element's and theme root's class based on isDark state\n */\n private updateHostClass(): void {\n if (this.isDark) {\n this.classList.add('dark')\n this.themeRoot.classList.add('dark')\n } else {\n this.classList.remove('dark')\n this.themeRoot.classList.remove('dark')\n }\n }\n }\n\n return Mixin as unknown as ThemeMixinConstructor<T>\n}\n"]}
|