@odx/foundation 1.0.0-beta.0 → 1.0.0-beta.1

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.
@@ -22,6 +22,8 @@ export interface FormatOptions {
22
22
  }
23
23
  export interface LocalizationOptions {
24
24
  defaultLocale: () => LocaleInput;
25
+ fallbackLanguage: () => Intl.UnicodeBCP47LocaleIdentifier;
26
+ fallbackTranslation: (key: string) => string;
25
27
  }
26
28
  export type I18nOptions = LocalizationOptions & FormatOptions;
27
29
  export declare function setI18nOptions(options?: Partial<I18nOptions> | null): void;
@@ -12,4 +12,4 @@ export interface IsLocalized {
12
12
  formatRelativeTime: typeof formatRelativeTime;
13
13
  }
14
14
  export declare const IsLocalized: <T extends Constructor<CustomElement>>(superClass: T) => Constructor<IsLocalized> & T;
15
- //# sourceMappingURL=is-localized.mixin.d.ts.map
15
+ //# sourceMappingURL=is-localized.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import { ReadonlySignal } from '@lit-labs/preact-signals';
2
2
  import { LocaleInput } from './models.js';
3
- export type TranslateContext = Record<string, string | number | boolean> | string | number | boolean | null;
4
3
  type Translation = {
5
4
  [key: string]: Translation | string;
6
5
  };
6
+ export type TranslateContext = Record<string, string | number | boolean> | string | number | boolean | null;
7
7
  export declare function interpolate(value: string, context: Record<string, string | number>): string;
8
8
  export declare function setTranslation(locale: LocaleInput, translation: Translation): void;
9
9
  export declare function translate(key: string, contextInput?: TranslateContext, locale?: LocaleInput | null): ReadonlySignal<string>;
@@ -1,6 +1,6 @@
1
1
  export * from './lib/config.js';
2
2
  export * from './lib/format.js';
3
- export * from './lib/is-localized.mixin.js';
3
+ export * from './lib/is-localized.js';
4
4
  export * from './lib/localization.js';
5
5
  export * from './lib/models.js';
6
6
  export * from './lib/translate.js';
package/dist/i18n.js CHANGED
@@ -5,6 +5,8 @@ import { k as flattenObject, l as isNotNil } from './vendor-C_WVAD3D.js';
5
5
 
6
6
  const I18nOptions = createOptions({
7
7
  defaultLocale: () => navigator.language,
8
+ fallbackLanguage: () => "en",
9
+ fallbackTranslation: (key) => key,
8
10
  relativeTimeFormatOptions: { minUnit: "minute" }
9
11
  });
10
12
  const i18nOptions = signal(null);
@@ -79,7 +81,6 @@ function syncDocumentLanguage(root = document.documentElement) {
79
81
  });
80
82
  }
81
83
 
82
- const fallbackLocale = "en";
83
84
  const translations = signal({});
84
85
  function interpolate(value, context) {
85
86
  return value.replaceAll(/\{\{\s*([^}\s]+)\s*}}/g, (match, variableName) => {
@@ -92,11 +93,13 @@ function setTranslation(locale, translation) {
92
93
  }
93
94
  function translate(key, contextInput, locale) {
94
95
  return computed(() => {
95
- const translationRecord = getTranslationRecord(locale);
96
- if (!translationRecord) return key;
97
- const value = translationRecord?.[key] ?? getTranslationRecord(fallbackLocale)?.[key] ?? "";
96
+ const translation = getTranslationRecord(locale);
97
+ if (!translation) return key;
98
+ const { fallbackLanguage, fallbackTranslation: fallbackTranslateKey } = getI18nOptions();
99
+ const fallbackTranslation = getTranslationRecord(fallbackLanguage());
100
+ const value = translation?.[key] ?? fallbackTranslation?.[key] ?? fallbackTranslateKey(key);
98
101
  const context = typeof contextInput === "object" || contextInput === void 0 ? flattenObject(contextInput ?? {}) : { $implicit: contextInput.toString() };
99
- return interpolate(value, { ...getTranslationRecord(fallbackLocale), ...translationRecord, ...context });
102
+ return interpolate(value, { ...fallbackTranslation, ...translation, ...context });
100
103
  });
101
104
  }
102
105
  function getTranslationRecord(localeInput) {
@@ -1,5 +1,4 @@
1
1
  import { CSSResultGroup, HTMLTemplateResult, LitElement, TemplateResult } from 'lit';
2
- export declare function isCustomElementClass(candidate: unknown): candidate is typeof CustomElement;
3
2
  export declare function customElement(selector?: keyof HTMLElementTagNameMap, styles?: Array<string | CSSResultGroup>): (target: typeof CustomElement) => void;
4
3
  export declare class CustomElement extends LitElement {
5
4
  static selector: string;
package/dist/loader.js CHANGED
@@ -1,11 +1,10 @@
1
- import { isCustomElementClass } from '@odx/foundation';
2
1
  import * as cdkComponents from '@odx/foundation/cdk';
3
2
  import * as components from '@odx/foundation/components';
4
3
 
5
4
  async function defineCustomElements() {
6
5
  for (const entry of Object.values({ ...components, ...cdkComponents })) {
7
- if (!isCustomElementClass(entry)) continue;
8
- entry.define();
6
+ if (typeof entry !== "function") continue;
7
+ entry.define?.();
9
8
  }
10
9
  }
11
10
  defineCustomElements();
package/dist/main.js CHANGED
@@ -156,24 +156,23 @@ const emptySlotFallbackFix = directive(SlotFallbackDirective);
156
156
 
157
157
  const customElementStyles = "@layer reset,base,variant,state,theme,override;@layer reset{:is(*){box-sizing:border-box;scrollbar-width:thin}:before,:after{box-sizing:border-box}[popover]{border:none;outline:none}img,picture,video,canvas,svg{display:block;max-width:100%;margin:0}input,button,textarea,select{font:inherit;margin:0}p,h1,h2,h3,h4,h5,h6{overflow-wrap:break-word;margin:0}p{text-wrap:pretty}h1,h2,h3,h4,h5,h6{text-wrap:balance}#root,#__next{isolation:isolate;margin:0}}@layer base{h1,h2,h3,h4,h5,h6{display:block;font-family:var(--odx-typography-font-family-brand);font-size:var(--_font-size);font-weight:var(--odx-typography-font-weight-semibold);line-height:var(--_line-height)}h6{--_font-size: var(--odx-breakpoint-font-size-heading-6);--_line-height: var(--odx-breakpoint-line-height-heading-6)}h5{--_font-size: var(--odx-breakpoint-font-size-heading-5);--_line-height: var(--odx-breakpoint-line-height-heading-5)}h4{--_font-size: var(--odx-breakpoint-font-size-heading-4);--_line-height: var(--odx-breakpoint-line-height-heading-4)}h3{--_font-size: var(--odx-breakpoint-font-size-heading-3);--_line-height: var(--odx-breakpoint-line-height-heading-3)}h2{--_font-size: var(--odx-breakpoint-font-size-heading-2);--_line-height: var(--odx-breakpoint-line-height-heading-2)}h1{--_font-size: var(--odx-breakpoint-font-size-heading-1);--_line-height: var(--odx-breakpoint-line-height-heading-1)}[odxPreventTextOverflow]{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}}@layer reset{:host{border:none;border-color:transparent;outline:none}}";
158
158
 
159
- function toCSSResult(value) {
160
- return value instanceof CSSResult || value instanceof CSSStyleSheet ? value : unsafeCSS(value);
161
- }
162
- function isCustomElementClass(candidate) {
163
- if (!candidate || typeof candidate !== "function") return false;
164
- return "selector" in candidate && "define" in candidate && typeof candidate.define === "function";
159
+ function mergeStyleSheets(...stylesheets) {
160
+ const mergedStyles = [];
161
+ for (const styles of stylesheets) {
162
+ if (!styles) continue;
163
+ mergedStyles.push(styles instanceof CSSResult || styles instanceof CSSStyleSheet ? styles : unsafeCSS(styles));
164
+ }
165
+ return uniqBy(mergedStyles.flat(10), String);
165
166
  }
166
167
  function customElement(selector, styles = []) {
167
168
  return (target) => {
168
- const preparedStyles = [customElementStyles, target.styles ?? [], ...styles].filter(Boolean).flat(2).map(toCSSResult);
169
- if (selector) {
170
- target.styles = uniqBy(preparedStyles, String);
171
- target.selector = selector;
172
- target.define = () => {
173
- if (customElements.get(selector)) return;
174
- customElements.define(selector, target);
175
- };
176
- }
169
+ if (!selector) return;
170
+ target.selector = selector;
171
+ target.styles = mergeStyleSheets(customElementStyles, target.styles, ...styles);
172
+ target.define = () => {
173
+ if (customElements.get(selector)) return;
174
+ customElements.define(selector, target);
175
+ };
177
176
  };
178
177
  }
179
178
  class CustomElement extends LitElement {
@@ -1127,4 +1126,4 @@ class SharedResizeObserverInstance {
1127
1126
  }
1128
1127
  const SharedResizeObserver = new SharedResizeObserverInstance();
1129
1128
 
1130
- export { CanBeDisabled, CanBeExpanded, CanBeReadonly, CanBeRequired, CanBeSelected, CanBeValidated, CheckboxFormControl, CheckboxGroupFormControl, CustomElement, FocusTrapController, FormControl, KeyboardKey, NumberControl, OptionControl, RadioGroupFormControl, SelectFormControl, SharedIntersectionObserver, SharedResizeObserver, WithLoadingState, clearUniqueIdCache, createIntersectionObserver, createMutationObserver, createOptions, createResizeObserver, customElement, dedupeMixin, emptySlotFallbackFix, findClosestDocument, forwardEvent, fromAriaBooleanAttribute, getAssignedElements, getElementFromEvent, getKeyboardEventInfo, getUniqueId, isCustomElementClass, optionalAttr, optionalSlot, parseDate, requestUpdateOnAriaChange, searchTextContent, toAriaBooleanAttribute, toPx, toggleAttribute, waitForAnimations };
1129
+ export { CanBeDisabled, CanBeExpanded, CanBeReadonly, CanBeRequired, CanBeSelected, CanBeValidated, CheckboxFormControl, CheckboxGroupFormControl, CustomElement, FocusTrapController, FormControl, KeyboardKey, NumberControl, OptionControl, RadioGroupFormControl, SelectFormControl, SharedIntersectionObserver, SharedResizeObserver, WithLoadingState, clearUniqueIdCache, createIntersectionObserver, createMutationObserver, createOptions, createResizeObserver, customElement, dedupeMixin, emptySlotFallbackFix, findClosestDocument, forwardEvent, fromAriaBooleanAttribute, getAssignedElements, getElementFromEvent, getKeyboardEventInfo, getUniqueId, optionalAttr, optionalSlot, parseDate, requestUpdateOnAriaChange, searchTextContent, toAriaBooleanAttribute, toPx, toggleAttribute, waitForAnimations };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odx/foundation",
3
3
  "description": "A library of Web Component building blocks for ODX",
4
- "version": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "author": "Drägerwerk AG & Co.KGaA",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "homepage": "https://odx.draeger.com",
@@ -21,7 +21,7 @@
21
21
  "devDependencies": {
22
22
  "@floating-ui/dom": "1.6.13",
23
23
  "@odx/typescript-config": "*",
24
- "@spectrum-web-components/reactive-controllers": "1.3.0",
24
+ "@spectrum-web-components/reactive-controllers": "1.4.0",
25
25
  "es-toolkit": "1.33.0",
26
26
  "focus-trap": "7.6.4",
27
27
  "ts-lit-plugin": "2.0.2",
@@ -32,7 +32,7 @@
32
32
  "peerDependencies": {
33
33
  "@odx/icons": "^4.0.0-rc.15"
34
34
  },
35
- "sideEffects": ["dist/loader.js", "dist/i18n.js", "*.css"],
35
+ "sideEffects": ["dist/loader.js", "*.css"],
36
36
  "exports": {
37
37
  ".": {
38
38
  "import": "./dist/main.js",