@empathyco/x-archetype-utils 2.0.0-alpha.3 → 2.0.0-alpha.30

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # x-archetype-utils
2
2
 
3
- `x-archetype-utils` is a library that provides utilities to ease development. It's used in the [Interface X Archetype](https://github.com/empathyco/x-archetype) project.
3
+ `x-archetype-utils` is a library that provides utilities to ease development. It's used in the [Interface X Archetype](https://github.com/empathyco/x-archetype) project.
4
4
 
5
5
  ## Contributing
6
6
 
@@ -1,9 +1,9 @@
1
- export declare const rollupCssInjectorConfig: {
2
- replace: {
3
- 'export default injectCss;': string;
4
- delimiters: string[];
5
- };
6
- styles: {
7
- mode: (string | ((varname: string) => string))[];
8
- };
9
- };
1
+ export declare const rollupCssInjectorConfig: {
2
+ replace: {
3
+ 'export default injectCss': string;
4
+ delimiters: string[];
5
+ };
6
+ styles: {
7
+ mode: (string | ((varname: string) => string))[];
8
+ };
9
+ };
@@ -1,35 +1,35 @@
1
- /**.
2
- * Self-made interface since Webpack does not provide a type for this object.
3
- * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463
4
- *
5
- * @internal
6
- */
7
- interface webpackFilenameTemplateInfo {
8
- identifier: string;
9
- shortIdentifier: string;
10
- resource: string;
11
- resourcePath: string;
12
- absoluteResourcePath: string;
13
- allLoaders: string;
14
- query: string;
15
- moduleId: string;
16
- hash: string;
17
- namespace: string;
18
- }
19
- export declare const webpackConfig: {
20
- transpileDependencies: string[];
21
- configureWebpack: {
22
- module: {
23
- rules: {
24
- test: RegExp;
25
- enforce: string;
26
- use: string[];
27
- }[];
28
- };
29
- output: {
30
- devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }: webpackFilenameTemplateInfo) => string;
31
- devtoolFallbackModuleFilenameTemplate: string;
32
- };
33
- };
34
- };
35
- export {};
1
+ /**.
2
+ * Self-made interface since Webpack does not provide a type for this object.
3
+ * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463
4
+ *
5
+ * @internal
6
+ */
7
+ interface webpackFilenameTemplateInfo {
8
+ identifier: string;
9
+ shortIdentifier: string;
10
+ resource: string;
11
+ resourcePath: string;
12
+ absoluteResourcePath: string;
13
+ allLoaders: string;
14
+ query: string;
15
+ moduleId: string;
16
+ hash: string;
17
+ namespace: string;
18
+ }
19
+ export declare const webpackConfig: {
20
+ transpileDependencies: string[];
21
+ configureWebpack: {
22
+ module: {
23
+ rules: {
24
+ test: RegExp;
25
+ enforce: string;
26
+ use: string[];
27
+ }[];
28
+ };
29
+ output: {
30
+ devtoolModuleFilenameTemplate: ({ resourcePath, hash, query, }: webpackFilenameTemplateInfo) => string;
31
+ devtoolFallbackModuleFilenameTemplate: string;
32
+ };
33
+ };
34
+ };
35
+ export {};
@@ -1,47 +1,59 @@
1
- import { XCSSInjector } from './css-injector.types';
2
- /**
3
- * Custom CSS injector that allows to inject styles into a host element.
4
- *
5
- * @public
6
- */
7
- export declare class CssInjector implements XCSSInjector {
8
- protected host: Element | ShadowRoot;
9
- protected stylesQueue: string[];
10
- /**
11
- * Initializes the instance of the injector if it's not already initialized and sets it in the
12
- * window object if it's required.
13
- *
14
- * @param setInWindow - Whether to set the injector instance in the window object.
15
- */
16
- constructor(setInWindow?: boolean);
17
- /**
18
- * Adds the styles to the host element.
19
- *
20
- * @param styles - The styles to be added.
21
- */
22
- addStyle(styles: {
23
- source: string;
24
- }): void;
25
- /**
26
- * Sets the host element.
27
- *
28
- * @param host - The host element.
29
- */
30
- setHost(host: Element | ShadowRoot): void;
31
- /**
32
- * Sets the injector instance in the window object.
33
- */
34
- setInWindow(): void;
35
- /**
36
- * Checks if the injector instance is in the window object.
37
- *
38
- * @returns Whether the injector instance is in the window object.
39
- */
40
- isInWindow(): boolean;
41
- }
42
- /**
43
- * Instance of the injector.
44
- *
45
- * @public
46
- */
47
- export declare const cssInjector: CssInjector;
1
+ import { Style, XCSSInjector } from './css-injector.types';
2
+ /**
3
+ * Custom CSS injector that allows to inject styles into a host element.
4
+ *
5
+ * @public
6
+ */
7
+ export declare class CssInjector implements XCSSInjector {
8
+ protected hosts: Set<ShadowRoot | Document>;
9
+ protected stylesToAdopt: CSSStyleSheet[];
10
+ /**
11
+ * Initializes the instance of the injector if it's not already initialized and sets it in the
12
+ * window object if it's required.
13
+ *
14
+ * @param setInWindow - Whether to set the injector instance in the window object.
15
+ */
16
+ constructor(setInWindow?: boolean);
17
+ /**
18
+ * Adds the style to the host element.
19
+ *
20
+ * @param style - The styles to be added.
21
+ * @param style.source - Styles source.
22
+ */
23
+ addStyle(style: Style): void;
24
+ /**
25
+ * Sets the host element. Alias of addHost method.
26
+ *
27
+ * @param host - The host element.
28
+ * @deprecated Use addHost instead.
29
+ */
30
+ setHost(host: Element | ShadowRoot): void;
31
+ /**
32
+ * Adds the element to the hosts set.
33
+ *
34
+ * @param host - The host element.
35
+ */
36
+ addHost(host: Document | ShadowRoot): void;
37
+ /**
38
+ * Removes the element from the hosts set.
39
+ *
40
+ * @param host - The host element to remove.
41
+ */
42
+ removeHost(host: Document | ShadowRoot): void;
43
+ /**
44
+ * Sets the injector instance in the window object.
45
+ */
46
+ setInWindow(): void;
47
+ /**
48
+ * Checks if the injector instance is in the window object.
49
+ *
50
+ * @returns Whether the injector instance is in the window object.
51
+ */
52
+ isInWindow(): boolean;
53
+ }
54
+ /**
55
+ * Instance of the injector.
56
+ *
57
+ * @public
58
+ */
59
+ export declare const cssInjector: CssInjector;
@@ -1,15 +1,22 @@
1
- export interface XCSSInjector {
2
- /** Function that will add the styles to the host. */
3
- addStyle: (styles: {
4
- source: string;
5
- }) => void;
6
- /** Function setting the host for the injector. */
7
- setHost: (el: Element | ShadowRoot) => void;
8
- /** Set injector instance in the window object. */
9
- setInWindow: () => void;
10
- /** Check if the instance is set in the window object. */
11
- isInWindow: () => boolean;
12
- }
13
- export type WindowWithInjector = Window & {
14
- xCSSInjector?: XCSSInjector;
15
- };
1
+ /** The style payload interface. */
2
+ export interface Style {
3
+ /** Css source. */
4
+ source: string;
5
+ }
6
+ export interface XCSSInjector {
7
+ /** Function that will add the styles to the host. */
8
+ addStyle: (style: Style) => void;
9
+ /** @deprecated Use addHost method. */
10
+ setHost: (el: Element | ShadowRoot) => void;
11
+ /** Adds the element to the hosts set. */
12
+ addHost: (el: Document | ShadowRoot) => void;
13
+ /** Removes the element from the hosts set. */
14
+ removeHost: (el: Document | ShadowRoot) => void;
15
+ /** Set injector instance in the window object. */
16
+ setInWindow: () => void;
17
+ /** Check if the instance is set in the window object. */
18
+ isInWindow: () => boolean;
19
+ }
20
+ export type WindowWithInjector = Window & {
21
+ xCSSInjector?: XCSSInjector;
22
+ };
@@ -65,6 +65,7 @@
65
65
  </svg>
66
66
  </div>
67
67
  <div
68
+ data-teleport="empathy-search-box-container"
68
69
  class="x-archetype-header__input-container x-archetype-row__item x-archetype-row__item--span-8 x-archetype-list x-archetype-gap--05"
69
70
  >
70
71
  <div class="x-archetype-pulse-circle"></div>
@@ -95,7 +96,7 @@
95
96
  </div>
96
97
  </header>
97
98
 
98
- <div class="x-archetype-list">
99
+ <div data-teleport="empathy-results-container" class="x-archetype-list">
99
100
  <section class="x-archetype-section1 x-archetype-row">
100
101
  <div class="x-archetype-section1__container">
101
102
  <div class="x-archetype-divider"></div>
@@ -1,74 +1,78 @@
1
- import { App } from 'vue';
2
- import { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n';
3
- import { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
- /**
5
- * I18n settings manager.
6
- *
7
- * @public
8
- */
9
- export declare class I18n<SomeMessages> {
10
- vueI18n: VueI18n<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, Locale, false>;
11
- protected locale: Locale;
12
- protected device: Device;
13
- protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
- protected currentMessages: LocaleMessageObject;
15
- protected fallbackLocale: Locale;
16
- /**
17
- * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
- *
19
- * @param options - The new {@link I18nOptions | i18n options}.
20
- */
21
- constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
22
- /**
23
- * Creates a new {@link I18n} instance.
24
- *
25
- * @param options - The new {@link I18nOptions | i18n options}.
26
- *
27
- * @returns The new instance.
28
- */
29
- static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
30
- /**
31
- * Installs VueI18n plugin.
32
- *
33
- * @param vue - The Vue instance.
34
- */
35
- install(vue: App): void;
36
- /**
37
- * Tries to get a value from the messages object accessing it key by key.
38
- * When a key fails, takes the remaining key parts and tries to access the message
39
- * joining them into a single key.
40
- *
41
- * @param path - A dot separated key to access the message object.
42
- * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
43
- */
44
- protected getMessageWithDotsInKey(path: string): string | null;
45
- /**
46
- * Sets the new locale and updates the messages accordingly.
47
- *
48
- * @param newLocale - The new locale.
49
- *
50
- * @returns The new messages.
51
- */
52
- setLocale(newLocale: Locale): Promise<void>;
53
- /**
54
- * Sets the new device and updates the messages accordingly.
55
- *
56
- * @param newDevice - The new device.
57
- *
58
- * @returns The new messages.
59
- */
60
- setDevice(newDevice: Device): Promise<void>;
61
- /**
62
- * Updates the current messages based on the new locale and/or device.
63
- */
64
- protected changeMessages(): Promise<void>;
65
- /**
66
- * Retrieves the corresponding messages for the set locale and device.
67
- *
68
- * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
69
- * no messages for the current locale, the fallback locale is used instead.
70
- *
71
- * @returns The messages for the current locale and device.
72
- */
73
- protected getCurrentMessages(): Promise<LocaleMessageObject>;
74
- }
1
+ import { App } from 'vue';
2
+ import { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n';
3
+ import { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
+ /**
5
+ * I18n settings manager.
6
+ *
7
+ * @public
8
+ */
9
+ export declare class I18n<SomeMessages> {
10
+ vueI18n: VueI18n<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, Locale, false>;
11
+ protected locale: Locale;
12
+ protected device: Device;
13
+ protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
+ protected currentMessages: LocaleMessageObject;
15
+ protected fallbackLocale: Locale;
16
+ /**
17
+ * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
+ *
19
+ * @param options - The new {@link I18nOptions | i18n options}.
20
+ * @param options.locale - i18n locale.
21
+ * @param options.messages - i18n messages.
22
+ * @param options.device - i18n device.
23
+ * @param options.fallbackLocale - i18n fallbackLocale.
24
+ */
25
+ constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
26
+ /**
27
+ * Creates a new {@link I18n} instance.
28
+ *
29
+ * @param options - The new {@link I18nOptions | i18n options}.
30
+ *
31
+ * @returns The new instance.
32
+ */
33
+ static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
34
+ /**
35
+ * Installs VueI18n plugin.
36
+ *
37
+ * @param vue - The Vue instance.
38
+ */
39
+ install(vue: App): void;
40
+ /**
41
+ * Tries to get a value from the messages object accessing it key by key.
42
+ * When a key fails, takes the remaining key parts and tries to access the message
43
+ * joining them into a single key.
44
+ *
45
+ * @param path - A dot separated key to access the message object.
46
+ * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
47
+ */
48
+ protected getMessageWithDotsInKey(path: string): string | null;
49
+ /**
50
+ * Sets the new locale and updates the messages accordingly.
51
+ *
52
+ * @param newLocale - The new locale.
53
+ *
54
+ * @returns The new messages.
55
+ */
56
+ setLocale(newLocale: Locale): Promise<void>;
57
+ /**
58
+ * Sets the new device and updates the messages accordingly.
59
+ *
60
+ * @param newDevice - The new device.
61
+ *
62
+ * @returns The new messages.
63
+ */
64
+ setDevice(newDevice: Device): Promise<void>;
65
+ /**
66
+ * Updates the current messages based on the new locale and/or device.
67
+ */
68
+ protected changeMessages(): Promise<void>;
69
+ /**
70
+ * Retrieves the corresponding messages for the set locale and device.
71
+ *
72
+ * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
73
+ * no messages for the current locale, the fallback locale is used instead.
74
+ *
75
+ * @returns The messages for the current locale and device.
76
+ */
77
+ protected getCurrentMessages(): Promise<LocaleMessageObject>;
78
+ }
@@ -1,53 +1,53 @@
1
- import { DeepPartial } from '@empathyco/x-utils';
2
- import { I18n as VueI18n } from 'vue-i18n';
3
- /** Supported locales. */
4
- export type Locale = string;
5
- /** Supported devices. */
6
- export type Device = string;
7
- /** Union type containing both eager and lazy messages. */
8
- export type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
- /** A function that loads on demand the messages for a specific locale. */
10
- export type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
- default: MessagesByDevice<SomeMessages>;
12
- }>;
13
- /**
14
- * An object containing a base property with all the existing messages and the overridden ones for
15
- * each device.
16
- */
17
- export interface MessagesByDevice<SomeMessages> {
18
- base: SomeMessages;
19
- [device: Device]: DeepPartial<SomeMessages>;
20
- }
21
- /**
22
- * I18n settings.
23
- */
24
- export interface I18nOptions<SomeMessages> {
25
- /** The initial messages. */
26
- messages: Record<Locale, AnyMessages<SomeMessages>>;
27
- /** The initial device. */
28
- device: Device;
29
- /** The locale to fall back if no matching locale is available. */
30
- fallbackLocale: Locale;
31
- /** The initial locale. */
32
- locale: Locale;
33
- }
34
- /**
35
- * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
- * functions.
37
- */
38
- export interface I18nAPI {
39
- /** The Vue I18n instance that should be passed to the root Vue component. */
40
- readonly vueI18n: Readonly<VueI18n>;
41
- /**
42
- * Sets the new locale.
43
- *
44
- * @param newLocale - The new locale.
45
- */
46
- setLocale: (newLocale: Locale) => Promise<void>;
47
- /**
48
- * Sets the new device.
49
- *
50
- * @param newDevice - The new device.
51
- */
52
- setDevice: (newDevice: Device) => Promise<void>;
53
- }
1
+ import { DeepPartial } from '@empathyco/x-utils';
2
+ import { I18n as VueI18n } from 'vue-i18n';
3
+ /** Supported locales. */
4
+ export type Locale = string;
5
+ /** Supported devices. */
6
+ export type Device = string;
7
+ /** Union type containing both eager and lazy messages. */
8
+ export type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
+ /** A function that loads on demand the messages for a specific locale. */
10
+ export type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
+ default: MessagesByDevice<SomeMessages>;
12
+ }>;
13
+ /**
14
+ * An object containing a base property with all the existing messages and the overridden ones for
15
+ * each device.
16
+ */
17
+ export interface MessagesByDevice<SomeMessages> {
18
+ base: SomeMessages;
19
+ [device: Device]: DeepPartial<SomeMessages>;
20
+ }
21
+ /**
22
+ * I18n settings.
23
+ */
24
+ export interface I18nOptions<SomeMessages> {
25
+ /** The initial messages. */
26
+ messages: Record<Locale, AnyMessages<SomeMessages>>;
27
+ /** The initial device. */
28
+ device: Device;
29
+ /** The locale to fall back if no matching locale is available. */
30
+ fallbackLocale: Locale;
31
+ /** The initial locale. */
32
+ locale: Locale;
33
+ }
34
+ /**
35
+ * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
+ * functions.
37
+ */
38
+ export interface I18nAPI {
39
+ /** The Vue I18n instance that should be passed to the root Vue component. */
40
+ readonly vueI18n: Readonly<VueI18n>;
41
+ /**
42
+ * Sets the new locale.
43
+ *
44
+ * @param newLocale - The new locale.
45
+ */
46
+ setLocale: (newLocale: Locale) => Promise<void>;
47
+ /**
48
+ * Sets the new device.
49
+ *
50
+ * @param newDevice - The new device.
51
+ */
52
+ setDevice: (newDevice: Device) => Promise<void>;
53
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@empathyco/x-deep-merge"),h=require("@empathyco/x-utils"),d=require("vue-i18n"),g={replace:{"export default injectCss":"export default (css) => window.xCSSInjector.addStyle({ source: css });",delimiters:["",""]},styles:{mode:["inject",n=>`window.xCSSInjector.addStyle({ source: ${n} });`]}},p={transpileDependencies:["@empathyco/x-components"],configureWebpack:{module:{rules:[{test:/\.ts|js|vue$/,enforce:"pre",use:["source-map-loader"]}]},output:{devtoolModuleFilenameTemplate:({resourcePath:n,hash:e,query:s})=>n.match(/\.vue$/)&&!s.match(/type=script/)&&!s.match(/\?rollup-plugin-vue=script.ts/)?`webpack-generated:///${n}?${e}`:`sources://${n}`,devtoolFallbackModuleFilenameTemplate:"webpack:///[resource-path]?[hash]"}}};let o=null;class a{constructor(e=!0){return this.hosts=new Set,this.stylesToAdopt=[],o instanceof a||(o=this),e&&this.setInWindow(),o}addStyle(e){const s=new CSSStyleSheet;s.replaceSync(e.source),this.stylesToAdopt.push(s),this.hosts.forEach(t=>t.adoptedStyleSheets=this.stylesToAdopt)}setHost(e){this.addHost(e instanceof ShadowRoot?e:document)}addHost(e){this.hosts.add(e),e.adoptedStyleSheets=this.stylesToAdopt}removeHost(e){this.hosts.delete(e)}setInWindow(){typeof window<"u"&&o&&(window.xCSSInjector=o)}isInWindow(){return typeof window>"u"?!1:window.xCSSInjector===o}}const f=new a(typeof window<"u");class c{constructor({locale:e,messages:s,device:t,fallbackLocale:i}){this.locale=e,this.device=t,this.messages=s,this.fallbackLocale=i}static async create(e){const s=new c(e);return s.currentMessages=await s.getCurrentMessages(),s}install(e){this.vueI18n=d.createI18n({legacy:!1,locale:this.locale,silentFallbackWarn:!0,messages:this.currentMessages?{[this.locale]:this.currentMessages}:{},missing:(s,t)=>this.getMessageWithDotsInKey(t)??`[i18n] Key '${t}' is missing for locale: '${this.locale}'`}),e.use(this.vueI18n)}getMessageWithDotsInKey(e){const s=e.split(".").reduce((t,i,l,r)=>h.isObject(t)?t[i]??t[r.slice(l).join(".")]:t,this.currentMessages);return typeof s=="string"?s:null}async setLocale(e){this.locale!==e&&(this.locale=e,await this.changeMessages(),this.vueI18n.global.locale.value=this.locale)}async setDevice(e){this.device!==e&&(this.device=e,await this.changeMessages())}async changeMessages(){this.currentMessages=await this.getCurrentMessages(),this.vueI18n.global.setLocaleMessage(this.locale,this.currentMessages)}async getCurrentMessages(){const e=this.locale in this.messages?this.messages[this.locale]:this.messages[this.fallbackLocale],s=w(e)?(await e()).default:e;return u.deepMerge({},s.base,s[this.device])}}function w(n){return typeof n=="function"}exports.CssInjector=a;exports.I18n=c;exports.cssInjector=f;exports.rollupCssInjectorConfig=g;exports.webpackConfig=p;
2
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/build/rollup/rollup.config.ts","../src/build/webpack/webpack.config.ts","../src/css-injector/css-injector.ts","../src/i18n/i18n.plugin.ts"],"sourcesContent":["export const rollupCssInjectorConfig = {\n replace: {\n // Replace X CSS injector by our custom one.\n 'export default injectCss':\n 'export default (css) => window.xCSSInjector.addStyle({ source: css });',\n delimiters: ['', ''],\n },\n styles: {\n mode: ['inject', (varname: string) => `window.xCSSInjector.addStyle({ source: ${varname} });`],\n },\n}\n","/**.\n * Self-made interface since Webpack does not provide a type for this object.\n * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463\n *\n * @internal\n */\ninterface webpackFilenameTemplateInfo {\n identifier: string\n shortIdentifier: string\n resource: string\n resourcePath: string\n absoluteResourcePath: string\n allLoaders: string\n query: string\n moduleId: string\n hash: string\n namespace: string\n}\n\nexport const webpackConfig = {\n transpileDependencies: ['@empathyco/x-components'],\n configureWebpack: {\n module: {\n rules: [\n {\n test: /\\.ts|js|vue$/,\n enforce: 'pre',\n use: ['source-map-loader'],\n },\n ],\n },\n output: {\n devtoolModuleFilenameTemplate: ({\n resourcePath,\n hash,\n query,\n }: webpackFilenameTemplateInfo) =>\n resourcePath.match(/\\.vue$/) &&\n !query.match(/type=script/) &&\n !query.match(/\\?rollup-plugin-vue=script.ts/)\n ? `webpack-generated:///${resourcePath}?${hash}`\n : `sources://${resourcePath}`,\n devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]',\n },\n },\n}\n","import type { Style, WindowWithInjector, XCSSInjector } from './css-injector.types'\n\n/** Singleton instance of the injector that will be used across all the initializations. */\nlet instance: CssInjector | null = null\n\n/**\n * Custom CSS injector that allows to inject styles into a host element.\n *\n * @public\n */\nexport class CssInjector implements XCSSInjector {\n protected hosts = new Set<Document | ShadowRoot>()\n protected stylesToAdopt: CSSStyleSheet[] = []\n\n /**\n * Initializes the instance of the injector if it's not already initialized and sets it in the\n * window object if it's required.\n *\n * @param setInWindow - Whether to set the injector instance in the window object.\n */\n public constructor(setInWindow = true) {\n if (!(instance instanceof CssInjector)) {\n // eslint-disable-next-line ts/no-this-alias\n instance = this\n }\n\n if (setInWindow) {\n this.setInWindow()\n }\n\n return instance\n }\n\n /**\n * Adds the style to the host element.\n *\n * @param style - The styles to be added.\n * @param style.source - Styles source.\n */\n addStyle(style: Style): void {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(style.source)\n this.stylesToAdopt.push(sheet)\n this.hosts.forEach(host => (host.adoptedStyleSheets = this.stylesToAdopt))\n }\n\n /**\n * Sets the host element. Alias of addHost method.\n *\n * @param host - The host element.\n * @deprecated Use addHost instead.\n */\n setHost(host: Element | ShadowRoot): void {\n this.addHost(host instanceof ShadowRoot ? host : document)\n }\n\n /**\n * Adds the element to the hosts set.\n *\n * @param host - The host element.\n */\n addHost(host: Document | ShadowRoot): void {\n this.hosts.add(host)\n host.adoptedStyleSheets = this.stylesToAdopt\n }\n\n /**\n * Removes the element from the hosts set.\n *\n * @param host - The host element to remove.\n */\n removeHost(host: Document | ShadowRoot): void {\n this.hosts.delete(host)\n }\n\n /**\n * Sets the injector instance in the window object.\n */\n setInWindow(): void {\n if (typeof window !== 'undefined' && instance) {\n ;(window as WindowWithInjector).xCSSInjector = instance\n }\n }\n\n /**\n * Checks if the injector instance is in the window object.\n *\n * @returns Whether the injector instance is in the window object.\n */\n isInWindow(): boolean {\n return typeof window === 'undefined'\n ? false\n : (window as WindowWithInjector).xCSSInjector === instance\n }\n}\n\n/**\n * Instance of the injector.\n *\n * @public\n */\nexport const cssInjector = new CssInjector(typeof window !== 'undefined')\n","import type { App } from 'vue'\nimport type { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n'\nimport type {\n AnyMessages,\n Device,\n I18nOptions,\n LoadLazyMessagesByDevice,\n Locale,\n} from './i18n.types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport { isObject } from '@empathyco/x-utils'\nimport { createI18n } from 'vue-i18n'\n\n/**\n * I18n settings manager.\n *\n * @public\n */\nexport class I18n<SomeMessages> {\n public vueI18n!: VueI18n<\n Record<string, unknown>,\n Record<string, unknown>,\n Record<string, unknown>,\n Locale,\n false\n >\n protected locale!: Locale\n protected device!: Device\n protected messages!: Record<Locale, AnyMessages<SomeMessages>>\n protected currentMessages!: LocaleMessageObject\n protected fallbackLocale!: Locale\n\n /**\n * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n * @param options.locale - i18n locale.\n * @param options.messages - i18n messages.\n * @param options.device - i18n device.\n * @param options.fallbackLocale - i18n fallbackLocale.\n */\n public constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>) {\n this.locale = locale\n this.device = device\n this.messages = messages\n this.fallbackLocale = fallbackLocale\n }\n\n /**\n * Creates a new {@link I18n} instance.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n *\n * @returns The new instance.\n */\n static async create<SomeMessages>(\n options: I18nOptions<SomeMessages>,\n ): Promise<I18n<SomeMessages>> {\n const instance = new I18n(options)\n instance.currentMessages = await instance.getCurrentMessages()\n return instance\n }\n\n /**\n * Installs VueI18n plugin.\n *\n * @param vue - The Vue instance.\n */\n install(vue: App): void {\n this.vueI18n = createI18n({\n legacy: false,\n locale: this.locale,\n silentFallbackWarn: true,\n // eslint-disable-next-line ts/no-unsafe-assignment\n messages: this.currentMessages ? ({ [this.locale]: this.currentMessages } as any) : {},\n missing: (_, key: string) => {\n return (\n this.getMessageWithDotsInKey(key) ??\n `[i18n] Key '${key}' is missing for locale: '${this.locale}'`\n )\n },\n })\n vue.use(this.vueI18n)\n }\n\n /**\n * Tries to get a value from the messages object accessing it key by key.\n * When a key fails, takes the remaining key parts and tries to access the message\n * joining them into a single key.\n *\n * @param path - A dot separated key to access the message object.\n * @returns The message corresponding to the provided key, or empty string if it doesn't exist.\n */\n protected getMessageWithDotsInKey(path: string): string | null {\n // TO-DO Support function or array messages\n // eslint-disable-next-line ts/no-unsafe-assignment\n const message = path.split('.').reduce<any>(\n (messages, key, index, pathParts) =>\n // eslint-disable-next-line ts/no-unsafe-return\n isObject(messages)\n ? (messages[key] ?? messages[pathParts.slice(index).join('.')])\n : messages,\n this.currentMessages,\n )\n return typeof message === 'string' ? message : null\n }\n\n /**\n * Sets the new locale and updates the messages accordingly.\n *\n * @param newLocale - The new locale.\n *\n * @returns The new messages.\n */\n async setLocale(newLocale: Locale): Promise<void> {\n if (this.locale !== newLocale) {\n this.locale = newLocale\n\n await this.changeMessages()\n this.vueI18n.global.locale.value = this.locale\n }\n }\n\n /**\n * Sets the new device and updates the messages accordingly.\n *\n * @param newDevice - The new device.\n *\n * @returns The new messages.\n */\n async setDevice(newDevice: Device): Promise<void> {\n if (this.device !== newDevice) {\n this.device = newDevice\n\n await this.changeMessages()\n }\n }\n\n /**\n * Updates the current messages based on the new locale and/or device.\n */\n protected async changeMessages(): Promise<void> {\n this.currentMessages = await this.getCurrentMessages()\n\n this.vueI18n.global.setLocaleMessage(this.locale, this.currentMessages)\n }\n\n /**\n * Retrieves the corresponding messages for the set locale and device.\n *\n * @remarks By default, it merges `base` messages with the specific `device` ones. If there are\n * no messages for the current locale, the fallback locale is used instead.\n *\n * @returns The messages for the current locale and device.\n */\n protected async getCurrentMessages(): Promise<LocaleMessageObject> {\n const rawMessages =\n this.locale in this.messages ? this.messages[this.locale] : this.messages[this.fallbackLocale]\n\n const messages = areLazyMessages(rawMessages) ? (await rawMessages()).default : rawMessages\n // eslint-disable-next-line ts/no-unsafe-return\n return deepMerge({}, messages.base, messages[this.device])\n }\n}\n\n/**\n * Type-guard to check if the passed messages should be lazy-loaded.\n *\n * @param messages - The messages to check.\n *\n * @returns True if the messages are lazy or false otherwise.\n */\nfunction areLazyMessages<SomeMessages>(\n messages: AnyMessages<SomeMessages>,\n): messages is LoadLazyMessagesByDevice<SomeMessages> {\n return typeof messages === 'function'\n}\n"],"names":["rollupCssInjectorConfig","varname","webpackConfig","resourcePath","hash","query","instance","CssInjector","setInWindow","style","sheet","host","cssInjector","I18n","locale","messages","device","fallbackLocale","options","vue","createI18n","_","key","path","message","index","pathParts","isObject","newLocale","newDevice","rawMessages","areLazyMessages","deepMerge"],"mappings":"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"}
@@ -1,6 +1,6 @@
1
- export * from './i18n/i18n.plugin';
2
- export * from './i18n/i18n.types';
3
- export * from './build/webpack/webpack.config';
4
- export * from './build/rollup/rollup.config';
5
- export * from './css-injector/css-injector';
6
- export * from './css-injector/css-injector.types';
1
+ export * from './build/rollup/rollup.config';
2
+ export * from './build/webpack/webpack.config';
3
+ export * from './css-injector/css-injector';
4
+ export * from './css-injector/css-injector.types';
5
+ export * from './i18n/i18n.plugin';
6
+ export * from './i18n/i18n.types';