@relax.js/core 1.0.0

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.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -0
  3. package/dist/DataLoader.d.ts +51 -0
  4. package/dist/DependencyInjection.d.ts +271 -0
  5. package/dist/DependencyInjectionOld.d.ts +35 -0
  6. package/dist/Metadata.d.ts +8 -0
  7. package/dist/SequentialId.d.ts +47 -0
  8. package/dist/_alt/src/MustardEngine.d.ts +30 -0
  9. package/dist/_alt/src/MustardParser.d.ts +63 -0
  10. package/dist/_alt/src/MustardParser2.d.ts +35 -0
  11. package/dist/_alt/src/pipes.d.ts +93 -0
  12. package/dist/_alt/src/template.d.ts +166 -0
  13. package/dist/_alt/src/tools.d.ts +4 -0
  14. package/dist/_alt/tests/pipes.tests.d.ts +1 -0
  15. package/dist/_alt/tests/template.tests.d.ts +1 -0
  16. package/dist/_alt/vitest.config.d.ts +2 -0
  17. package/dist/collections/Index.d.ts +1 -0
  18. package/dist/collections/LinkedList.d.ts +75 -0
  19. package/dist/collections/Pager.d.ts +15 -0
  20. package/dist/collections/index.js +2 -0
  21. package/dist/collections/index.js.map +7 -0
  22. package/dist/collections/index.mjs +2 -0
  23. package/dist/collections/index.mjs.map +7 -0
  24. package/dist/components/Table.d.ts +13 -0
  25. package/dist/components/index.d.ts +4 -0
  26. package/dist/components/index.js +128 -0
  27. package/dist/components/index.js.map +7 -0
  28. package/dist/components/index.mjs +128 -0
  29. package/dist/components/index.mjs.map +7 -0
  30. package/dist/components/lists/Table.d.ts +59 -0
  31. package/dist/components/lists/TreeView.d.ts +67 -0
  32. package/dist/components/lists/index.d.ts +2 -0
  33. package/dist/components/loader.d.ts +60 -0
  34. package/dist/components/menus/MenuItem.d.ts +30 -0
  35. package/dist/components/menus/TopMenu.d.ts +16 -0
  36. package/dist/components/menus/index.d.ts +2 -0
  37. package/dist/components/panels/tabs.d.ts +15 -0
  38. package/dist/di/index.d.ts +1 -0
  39. package/dist/di/index.js +2 -0
  40. package/dist/di/index.js.map +7 -0
  41. package/dist/di/index.mjs +2 -0
  42. package/dist/di/index.mjs.map +7 -0
  43. package/dist/elements/CopyAttributes.d.ts +2 -0
  44. package/dist/elements/dom.d.ts +18 -0
  45. package/dist/elements/index.d.ts +2 -0
  46. package/dist/elements/index.js +2 -0
  47. package/dist/elements/index.js.map +7 -0
  48. package/dist/elements/index.mjs +2 -0
  49. package/dist/elements/index.mjs.map +7 -0
  50. package/dist/errors.d.ts +71 -0
  51. package/dist/forms/FormReader.d.ts +182 -0
  52. package/dist/forms/FormValidator.d.ts +114 -0
  53. package/dist/forms/ValidationRules.d.ts +103 -0
  54. package/dist/forms/index.d.ts +4 -0
  55. package/dist/forms/index.js +2 -0
  56. package/dist/forms/index.js.map +7 -0
  57. package/dist/forms/index.mjs +2 -0
  58. package/dist/forms/index.mjs.map +7 -0
  59. package/dist/forms/setFormData.d.ts +49 -0
  60. package/dist/getParentComponent.d.ts +43 -0
  61. package/dist/html/TableRenderer.d.ts +44 -0
  62. package/dist/html/TreeBinder.d.ts +9 -0
  63. package/dist/html/html.d.ts +55 -0
  64. package/dist/html/index.d.ts +5 -0
  65. package/dist/html/index.js +2 -0
  66. package/dist/html/index.js.map +7 -0
  67. package/dist/html/index.mjs +2 -0
  68. package/dist/html/index.mjs.map +7 -0
  69. package/dist/html/template.d.ts +167 -0
  70. package/dist/http/ServerSentEvents.d.ts +116 -0
  71. package/dist/http/SimpleWebSocket.d.ts +153 -0
  72. package/dist/http/http.d.ts +177 -0
  73. package/dist/http/index.d.ts +3 -0
  74. package/dist/http/index.js +2 -0
  75. package/dist/http/index.js.map +7 -0
  76. package/dist/http/index.mjs +2 -0
  77. package/dist/http/index.mjs.map +7 -0
  78. package/dist/i18n/i18n.d.ts +105 -0
  79. package/dist/i18n/icu.d.ts +64 -0
  80. package/dist/i18n/index.d.ts +2 -0
  81. package/dist/i18n/index.js +2 -0
  82. package/dist/i18n/index.js.map +7 -0
  83. package/dist/i18n/index.mjs +2 -0
  84. package/dist/i18n/index.mjs.map +7 -0
  85. package/dist/index.d.ts +16 -0
  86. package/dist/index.js +5 -0
  87. package/dist/index.js.map +7 -0
  88. package/dist/index.mjs +5 -0
  89. package/dist/index.mjs.map +7 -0
  90. package/dist/lib/DataLoader.d.ts +51 -0
  91. package/dist/lib/DependencyInjection.d.ts +271 -0
  92. package/dist/lib/InvokeParent.d.ts +10 -0
  93. package/dist/lib/Pipes.d.ts +236 -0
  94. package/dist/lib/SequentialId.d.ts +47 -0
  95. package/dist/lib/collections/Index.d.ts +1 -0
  96. package/dist/lib/collections/LinkedList.d.ts +75 -0
  97. package/dist/lib/collections/Pager.d.ts +15 -0
  98. package/dist/lib/collections/TableRenderer.d.ts +44 -0
  99. package/dist/lib/di/index.d.ts +1 -0
  100. package/dist/lib/elements/CopyAttributes.d.ts +2 -0
  101. package/dist/lib/elements/dom.d.ts +18 -0
  102. package/dist/lib/elements/index.d.ts +2 -0
  103. package/dist/lib/errors.d.ts +71 -0
  104. package/dist/lib/forms/FormReader.d.ts +182 -0
  105. package/dist/lib/forms/FormValidator.d.ts +114 -0
  106. package/dist/lib/forms/ValidationRules.d.ts +103 -0
  107. package/dist/lib/forms/index.d.ts +4 -0
  108. package/dist/lib/forms/setFormData.d.ts +49 -0
  109. package/dist/lib/getParentComponent.d.ts +43 -0
  110. package/dist/lib/html/TableRenderer.d.ts +44 -0
  111. package/dist/lib/html/TreeBinder.d.ts +9 -0
  112. package/dist/lib/html/html.d.ts +55 -0
  113. package/dist/lib/html/html2.d.ts +55 -0
  114. package/dist/lib/html/index.d.ts +5 -0
  115. package/dist/lib/html/m.d.ts +167 -0
  116. package/dist/lib/html/m2.d.ts +8 -0
  117. package/dist/lib/html/m3.d.ts +0 -0
  118. package/dist/lib/html/template.d.ts +167 -0
  119. package/dist/lib/http/HttpClient.d.ts +153 -0
  120. package/dist/lib/http/ServerSentEvents.d.ts +116 -0
  121. package/dist/lib/http/SimpleWebSocket.d.ts +153 -0
  122. package/dist/lib/http/http.d.ts +177 -0
  123. package/dist/lib/http/index.d.ts +3 -0
  124. package/dist/lib/i18n/i18n.d.ts +105 -0
  125. package/dist/lib/i18n/icu.d.ts +64 -0
  126. package/dist/lib/i18n/index.d.ts +2 -0
  127. package/dist/lib/index.d.ts +16 -0
  128. package/dist/lib/routing/NavigateRouteEvent.d.ts +52 -0
  129. package/dist/lib/routing/RouteLink.d.ts +7 -0
  130. package/dist/lib/routing/Routing.d.ts +270 -0
  131. package/dist/lib/routing/RoutingTarget.d.ts +22 -0
  132. package/dist/lib/routing/index.d.ts +7 -0
  133. package/dist/lib/routing/navigation.d.ts +70 -0
  134. package/dist/lib/routing/routeMatching.d.ts +21 -0
  135. package/dist/lib/routing/routeTargetRegistry.d.ts +23 -0
  136. package/dist/lib/routing/types.d.ts +130 -0
  137. package/dist/lib/templates/NodeTemplate.d.ts +38 -0
  138. package/dist/lib/templates/accessorParser.d.ts +87 -0
  139. package/dist/lib/templates/parseTemplate.d.ts +6 -0
  140. package/dist/lib/templates/tokenizer.d.ts +76 -0
  141. package/dist/lib/tools.d.ts +30 -0
  142. package/dist/lib/utils/index.d.ts +4 -0
  143. package/dist/pipes.d.ts +236 -0
  144. package/dist/routing/NavigateRouteEvent.d.ts +52 -0
  145. package/dist/routing/RouteLink.d.ts +7 -0
  146. package/dist/routing/RoutingTarget.d.ts +22 -0
  147. package/dist/routing/index.d.ts +7 -0
  148. package/dist/routing/index.js +5 -0
  149. package/dist/routing/index.js.map +7 -0
  150. package/dist/routing/index.mjs +5 -0
  151. package/dist/routing/index.mjs.map +7 -0
  152. package/dist/routing/navigation.d.ts +70 -0
  153. package/dist/routing/routeMatching.d.ts +21 -0
  154. package/dist/routing/routeTargetRegistry.d.ts +23 -0
  155. package/dist/routing/types.d.ts +130 -0
  156. package/dist/templates/NodeTemplate.d.ts +38 -0
  157. package/dist/templates/accessorParser.d.ts +87 -0
  158. package/dist/templates/parseTemplate.d.ts +6 -0
  159. package/dist/templates/tokenizer.d.ts +76 -0
  160. package/dist/tools.d.ts +30 -0
  161. package/dist/utils/index.d.ts +4 -0
  162. package/dist/utils/index.js +2 -0
  163. package/dist/utils/index.js.map +7 -0
  164. package/dist/utils/index.mjs +2 -0
  165. package/dist/utils/index.mjs.map +7 -0
  166. package/docs/Architecture.md +333 -0
  167. package/docs/DependencyInjection.md +237 -0
  168. package/docs/Errors.md +87 -0
  169. package/docs/GettingStarted.md +231 -0
  170. package/docs/Pipes.md +211 -0
  171. package/docs/Translations.md +312 -0
  172. package/docs/WhyRelaxjs.md +336 -0
  173. package/docs/elements/dom.md +102 -0
  174. package/docs/forms/creating-form-components.md +924 -0
  175. package/docs/forms/form-api.md +94 -0
  176. package/docs/forms/forms.md +99 -0
  177. package/docs/forms/patterns.md +311 -0
  178. package/docs/forms/reading-writing.md +365 -0
  179. package/docs/forms/validation.md +351 -0
  180. package/docs/html/TableRenderer.md +292 -0
  181. package/docs/html/html.md +175 -0
  182. package/docs/html/index.md +54 -0
  183. package/docs/html/template.md +422 -0
  184. package/docs/http/HttpClient.md +459 -0
  185. package/docs/http/ServerSentEvents.md +184 -0
  186. package/docs/http/index.md +109 -0
  187. package/docs/i18n/i18n.md +309 -0
  188. package/docs/i18n/intl-standard.md +178 -0
  189. package/docs/routing/RouteLink.md +98 -0
  190. package/docs/routing/Routing.md +332 -0
  191. package/docs/routing/RoutingTarget.md +136 -0
  192. package/docs/routing/layouts.md +207 -0
  193. package/docs/utilities.md +143 -0
  194. package/package.json +93 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/i18n/locales/en/r-common.json", "../../src/i18n/locales/en/r-pipes.json", "../../src/i18n/locales/en/r-validation.json", "../../src/i18n/locales/sv/r-common.json", "../../src/i18n/locales/sv/r-pipes.json", "../../src/i18n/locales/sv/r-validation.json", "../../src/utils/index.ts", "../../src/i18n/icu.ts", "../../src/i18n/i18n.ts", "../../src/pipes.ts", "../../src/tools.ts", "../../src/SequentialId.ts", "../../src/errors.ts"],
4
+ "sourcesContent": ["{\r\n \"greeting\": \"Hello, {name}!\",\r\n \"items\": \"{count, plural, one {# item} other {# items}}\"\r\n}\r\n", "{\r\n \"today\": \"today\",\r\n \"yesterday\": \"yesterday\",\r\n \"daysAgo\": \"{count, plural, one {# day ago} other {# days ago}}\",\r\n \"pieces\": \"{count, plural, =0 {none} one {one} other {# pcs}}\"\r\n}\r\n", "{\r\n \"required\": \"This field is required.\",\r\n \"range\": \"Number must be between {min} and {max}, was {actual}.\",\r\n \"digits\": \"Please enter only digits.\"\r\n}\r\n", "{\r\n \"greeting\": \"Hej, {name}!\",\r\n \"items\": \"{count, plural, one {# sak} other {# saker}}\"\r\n}\r\n", "{\r\n \"today\": \"idag\",\r\n \"yesterday\": \"ig\u00E5r\",\r\n \"daysAgo\": \"{count, plural, one {# dag sedan} other {# dagar sedan}}\",\r\n \"pieces\": \"{count, plural, =0 {inga} one {en} other {# st}}\"\r\n}\r\n", "{\r\n \"required\": \"Detta f\u00E4lt \u00E4r obligatoriskt.\",\r\n \"range\": \"Talet m\u00E5ste vara mellan {min} och {max}, var {actual}.\",\r\n \"digits\": \"Ange endast siffror.\"\r\n}\r\n", "export * from '../pipes';\r\nexport * from '../tools';\r\nexport { generateSequentialId } from '../SequentialId';\r\nexport { onError, reportError, RelaxError } from '../errors';\r\n", "/**\r\n * @module icu\r\n * ICU message format support for internationalization.\r\n * Provides pluralization, select, and value interpolation.\r\n *\r\n * @example\r\n * // Simple interpolation\r\n * formatICU('Hello, {name}!', { name: 'World' });\r\n * // Returns: 'Hello, World!'\r\n *\r\n * @example\r\n * // Pluralization\r\n * formatICU('{count, plural, one {# item} other {# items}}', { count: 5 });\r\n * // Returns: '5 items'\r\n *\r\n * @example\r\n * // Select\r\n * formatICU('{gender, select, male {He} female {She} other {They}}', { gender: 'female' });\r\n * // Returns: 'She'\r\n */\r\n\r\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\r\n\r\n/**\r\n * Function type for message formatters.\r\n * Implement this to provide custom message formatting.\r\n */\r\nexport type MessageFormatter = (\r\n message: string,\r\n values?: Record<string, any>,\r\n locale?: string\r\n) => string;\r\n\r\n\r\nfunction getPluralRule(locale: string): Intl.PluralRules {\r\n if (!pluralRulesCache.has(locale)) {\r\n pluralRulesCache.set(locale, new Intl.PluralRules(locale));\r\n }\r\n return pluralRulesCache.get(locale)!;\r\n}\r\n\r\nfunction escapeRegex(s: string): string {\r\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\r\n}\r\n\r\n/**\r\n * Default ICU message formatter implementation.\r\n * Supports simple interpolation, pluralization with exact matches, and select.\r\n *\r\n * @param message - ICU format message string\r\n * @param values - Values to interpolate\r\n * @param locale - Locale for plural rules (default: 'en')\r\n * @returns Formatted message string\r\n *\r\n * @example\r\n * defaultFormatICU('{n, plural, =0 {none} one {# item} other {# items}}', { n: 0 }, 'en');\r\n * // Returns: 'none'\r\n *\r\n * @example\r\n * defaultFormatICU('{role, select, admin {Full access} other {Limited access}}', { role: 'admin' });\r\n * // Returns: 'Full access'\r\n */\r\nexport function defaultFormatICU(\r\n message: string,\r\n values: Record<string, any>,\r\n locale: string = 'en'\r\n): string {\r\n return message.replace(\r\n /\\{(\\w+)(?:, (plural|select),((?:[^{}]*\\{[^{}]*\\})+))?\\}/g,\r\n (_, key, type, categoriesPart) => {\r\n const value = values[key];\r\n\r\n if (type === 'plural') {\r\n const exact = new RegExp(\r\n `=${escapeRegex(String(value))}\\\\s*\\\\{([^{}]*)\\\\}`\r\n ).exec(categoriesPart);\r\n if (exact) {\r\n return exact[1]\r\n .replace(`{${key}}`, String(value))\r\n .replace('#', String(value));\r\n }\r\n\r\n const rules = getPluralRule(locale);\r\n const category = rules.select(value);\r\n const match =\r\n new RegExp(`${category}\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart) ||\r\n new RegExp(`other\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart);\r\n if (match) {\r\n return match[1]\r\n .replace(`{${key}}`, String(value))\r\n .replace('#', String(value));\r\n }\r\n return String(value);\r\n }\r\n\r\n if (type === 'select') {\r\n const escaped = escapeRegex(String(value));\r\n const match =\r\n new RegExp(`\\\\b${escaped}\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart) ||\r\n new RegExp(`\\\\bother\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart);\r\n return match ? match[1] : String(value);\r\n }\r\n\r\n return value !== undefined ? String(value) : `{${key}}`;\r\n },\r\n );\r\n}\r\n\r\n/**\r\n * The active message formatter. Defaults to `defaultFormatICU`.\r\n * Can be replaced with `setMessageFormatter` for custom formatting.\r\n */\r\nexport let formatICU: MessageFormatter = defaultFormatICU;\r\n\r\n/**\r\n * Replaces the default message formatter with a custom implementation.\r\n * Use this to integrate with external i18n libraries like FormatJS.\r\n *\r\n * @param formatter - The custom formatter function\r\n *\r\n * @example\r\n * // Use FormatJS IntlMessageFormat\r\n * import { IntlMessageFormat } from 'intl-messageformat';\r\n *\r\n * setMessageFormatter((message, values, locale) => {\r\n * const fmt = new IntlMessageFormat(message, locale);\r\n * return fmt.format(values);\r\n * });\r\n */\r\nexport function setMessageFormatter(formatter: MessageFormatter) {\r\n formatICU = formatter;\r\n}", "/**\r\n * @module i18n\r\n * Internationalization support with namespace-based translations.\r\n * Uses ICU message format for pluralization, select, and formatting.\r\n *\r\n * @example\r\n * // Initialize locale\r\n * await setLocale('sv');\r\n *\r\n * // Use translations\r\n * const greeting = t('r-common:greeting', { name: 'John' });\r\n * const items = t('shop:items', { count: 5 });\r\n */\r\n\r\nimport { formatICU } from './icu';\r\n\r\ntype Locale = string;\r\ntype Namespace = string;\r\ntype TranslationMap = Record<string, string>;\r\ntype Translations = Record<Namespace, TranslationMap>;\r\n\r\nexport type MissingTranslationHandler = (\r\n key: string,\r\n namespace: string,\r\n locale: string,\r\n) => void;\r\n\r\n/**\r\n * Dispatched on `document` after `setLocale()` completes.\r\n * The `locale` property contains the new normalized locale code.\r\n *\r\n * @example\r\n * document.addEventListener('localechange', (e) => {\r\n * console.log(`Locale changed to ${e.locale}`);\r\n * this.render();\r\n * });\r\n */\r\nexport class LocaleChangeEvent extends Event {\r\n readonly locale: string;\r\n constructor(locale: string) {\r\n super('localechange', { bubbles: false });\r\n this.locale = locale;\r\n }\r\n}\r\n\r\ndeclare global {\r\n interface DocumentEventMap {\r\n localechange: LocaleChangeEvent;\r\n }\r\n}\r\n\r\nconst fallbackLocale: Locale = 'en';\r\nlet currentLocale: Locale = fallbackLocale;\r\nconst loadedNamespaces = new Set<Namespace>();\r\nconst translations: Translations = {};\r\nlet missingHandler: MissingTranslationHandler | null = null;\r\n\r\nfunction normalizeLocale(locale: string): string {\r\n return locale.toLowerCase().split('-')[0];\r\n}\r\n\r\n/**\r\n * Sets the current locale and loads the common namespace.\r\n * Clears previously loaded translations and dispatches a `localechange` event.\r\n *\r\n * @param locale - The locale code (e.g., 'en', 'sv', 'en-US')\r\n *\r\n * @example\r\n * await setLocale('sv');\r\n */\r\nexport async function setLocale(locale: string): Promise<void> {\r\n const normalized = normalizeLocale(locale);\r\n currentLocale = normalized;\r\n loadedNamespaces.clear();\r\n Object.keys(translations).forEach(ns => delete translations[ns]);\r\n await loadNamespace('r-common');\r\n if (typeof document !== 'undefined') {\r\n document.dispatchEvent(new LocaleChangeEvent(normalized));\r\n }\r\n}\r\n\r\n/**\r\n * Loads a translation namespace on demand.\r\n * Falls back to the default locale if translations are not found.\r\n *\r\n * @param namespace - The namespace to load (e.g., 'shop', 'errors')\r\n *\r\n * @example\r\n * await loadNamespace('shop');\r\n * const price = t('shop:priceLabel');\r\n */\r\nexport async function loadNamespace(namespace: Namespace): Promise<void> {\r\n if (loadedNamespaces.has(namespace)) return;\r\n\r\n try {\r\n const module = await import(`./locales/${currentLocale}/${namespace}.json`);\r\n translations[namespace] = module.default;\r\n loadedNamespaces.add(namespace);\r\n } catch (err) {\r\n if (currentLocale !== fallbackLocale) {\r\n const fallback = await import(`./locales/${fallbackLocale}/${namespace}.json`);\r\n translations[namespace] = fallback.default;\r\n loadedNamespaces.add(namespace);\r\n } else {\r\n console.warn(`i18n: Failed to load namespace '${namespace}' for locale '${currentLocale}'`);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Loads multiple translation namespaces in parallel.\r\n *\r\n * @param namespaces - Array of namespace names to load\r\n *\r\n * @example\r\n * await loadNamespaces(['r-pipes', 'r-validation']);\r\n */\r\nexport async function loadNamespaces(namespaces: Namespace[]): Promise<void> {\r\n await Promise.all(namespaces.map(ns => loadNamespace(ns)));\r\n}\r\n\r\n/**\r\n * Translates a key with optional value interpolation.\r\n * Supports ICU message format for pluralization and select.\r\n *\r\n * @param fullKey - Translation key in format 'namespace:key' or just 'key' (uses 'r-common')\r\n * @param values - Values to interpolate into the message\r\n * @returns The translated string, or the key if not found\r\n *\r\n * @example\r\n * // Simple translation\r\n * t('greeting'); // Uses r-common:greeting\r\n *\r\n * // With namespace\r\n * t('errors:notFound');\r\n *\r\n * // With interpolation\r\n * t('welcome', { name: 'John' }); // \"Welcome, John!\"\r\n *\r\n * // With pluralization (ICU format)\r\n * t('items', { count: 5 }); // \"5 items\" or \"5 f\u00F6rem\u00E5l\"\r\n */\r\nexport function t(fullKey: string, values?: Record<string, any>): string {\r\n const [namespace, key] = fullKey.includes(':')\r\n ? fullKey.split(':')\r\n : ['r-common', fullKey];\r\n const message = translations[namespace]?.[key];\r\n if (!message) {\r\n if (missingHandler) missingHandler(key, namespace, currentLocale);\r\n return fullKey;\r\n }\r\n try {\r\n return formatICU(message, values, currentLocale) as string;\r\n } catch {\r\n return fullKey;\r\n }\r\n}\r\n\r\n/**\r\n * Returns the current locale code.\r\n *\r\n * @returns The normalized locale code (e.g., 'en', 'sv')\r\n */\r\nexport function getCurrentLocale(): string {\r\n return currentLocale;\r\n}\r\n\r\n/**\r\n * Registers a handler called when `t()` encounters a missing translation key.\r\n * Pass `null` to remove the handler.\r\n *\r\n * @param handler - Callback receiving the key, namespace, and locale\r\n *\r\n * @example\r\n * onMissingTranslation((key, ns, locale) => {\r\n * console.warn(`Missing: ${ns}:${key} [${locale}]`);\r\n * });\r\n */\r\nexport function onMissingTranslation(handler: MissingTranslationHandler | null): void {\r\n missingHandler = handler;\r\n}\r\n", "/**\r\n * @module pipes\r\n * Data transformation functions (pipes) for use in template expressions.\r\n * Pipes transform values for display, like formatting dates, currencies, or text.\r\n *\r\n * Locale-aware pipes (currency, date, daysAgo, pieces) use the i18n system\r\n * for formatting and translations. Call `setLocale()` before using these pipes.\r\n *\r\n * Pipes can be chained in templates: `{{value | uppercase | shorten:20}}`\r\n *\r\n * @example\r\n * // In templates\r\n * <span>{{user.name | uppercase}}</span>\r\n * <span>{{price | currency}}</span>\r\n * <span>{{createdAt | daysAgo}}</span>\r\n *\r\n * @example\r\n * // Programmatic usage\r\n * import { applyPipes, defaultPipes } from 'relaxjs';\r\n * const result = applyPipes('hello world', ['uppercase', 'shorten:8']);\r\n * // Returns: 'HELLO...'\r\n */\r\n\r\nimport { getCurrentLocale, t } from './i18n/i18n';\r\n\r\n/**\r\n * Type definition for pipe transformation functions.\r\n * Pipes take a value and optional arguments, returning a transformed value.\r\n *\r\n * @example\r\n * // Define a custom pipe\r\n * const reversePipe: PipeFunction = (value: string) => {\r\n * return value.split('').reverse().join('');\r\n * };\r\n */\r\nexport type PipeFunction = (value: any, ...args: any[]) => any;\r\n\r\n\r\n// =============================== Text manipulation pipes ===========================\r\n\r\n\r\n\r\n/**\r\n * Converts a string to uppercase\r\n * @param value The string to convert\r\n * @returns The uppercase string\r\n */\r\nexport function uppercasePipe(value: string): string {\r\n return String(value).toUpperCase();\r\n}\r\n\r\n/**\r\n * Converts a string to uppercase\r\n * @param value The string to convert\r\n * @returns The uppercase string\r\n */\r\nexport function trimPipe(value: string): string {\r\n return String(value).trimEnd().trimStart();\r\n}\r\n\r\n\r\n/**\r\n * Converts a string to lowercase\r\n * @param value The string to convert\r\n * @returns The lowercase string\r\n */\r\nexport function lowercasePipe(value: string): string {\r\n return String(value).toLowerCase();\r\n}\r\n\r\n/**\r\n * Capitalizes the first character of a string\r\n * @param value The string to capitalize\r\n * @returns The capitalized string\r\n */\r\nexport function capitalizePipe(value: string): string {\r\n const str = String(value);\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n\r\n/**\r\n * Shortens a string to a specified length and adds ellipsis.\r\n * @param value The string to shorten\r\n * @param length Maximum length including ellipsis\r\n * @returns The shortened string with ellipsis if needed\r\n */\r\nexport function shortenPipe(value: string, length: string): string {\r\n const str = String(value);\r\n const maxLength = parseInt(length, 10);\r\n return str.length > maxLength\r\n ? str.substring(0, maxLength - 3) + '...'\r\n : str;\r\n}\r\n\r\n// Formatting pipes\r\n/**\r\n * Formats a number as currency using the current locale.\r\n * Uses the i18n system's current locale for formatting.\r\n *\r\n * @param value The number to format\r\n * @param currency Currency code (defaults to USD)\r\n * @returns Formatted currency string\r\n *\r\n * @example\r\n * // In template: {{price | currency}} or {{price | currency:EUR}}\r\n * currencyPipe(1234.56); // \"$1,234.56\" (en) or \"1 234,56 $\" (sv)\r\n * currencyPipe(1234.56, 'SEK'); // \"SEK 1,234.56\" (en) or \"1 234,56 kr\" (sv)\r\n */\r\nexport function currencyPipe(value: number, currency: string = 'USD'): string {\r\n const locale = getCurrentLocale();\r\n return new Intl.NumberFormat(locale, {\r\n style: 'currency',\r\n currency\r\n }).format(value);\r\n}\r\n\r\n/**\r\n * Formats a date value according to the specified format.\r\n * Uses the i18n system's current locale for formatting.\r\n *\r\n * @param value Date value (string, number, or Date object)\r\n * @param format Format type: 'short', 'long', or default (ISO)\r\n * @returns Formatted date string\r\n *\r\n * @example\r\n * // In template: {{date | date:short}} or {{date | date:long}}\r\n * datePipe(new Date(), 'short'); // \"1/15/2024\" (en) or \"2024-01-15\" (sv)\r\n * datePipe(new Date(), 'long'); // \"Monday, January 15, 2024\" (en) or \"m\u00E5ndag 15 januari 2024\" (sv)\r\n */\r\nexport function datePipe(value: string | number | Date, format?: string): string {\r\n const date = new Date(value);\r\n const locale = getCurrentLocale();\r\n if (format === 'short') {\r\n return date.toLocaleDateString(locale);\r\n } else if (format === 'long') {\r\n return date.toLocaleDateString(locale, {\r\n weekday: 'long',\r\n year: 'numeric',\r\n month: 'long',\r\n day: 'numeric'\r\n });\r\n }\r\n return date.toISOString();\r\n}\r\n\r\n/**\r\n * Prints today, yesterday or X days ago.\r\n * Uses the i18n system for translations (requires pipes namespace loaded).\r\n *\r\n * @param value Date value (string, number, or Date object)\r\n * @returns Formatted relative date string\r\n *\r\n * @example\r\n * // In template: {{createdAt | daysAgo}}\r\n * // English: \"today\", \"yesterday\", \"3 days ago\"\r\n * // Swedish: \"idag\", \"ig\u00E5r\", \"3 dagar sedan\"\r\n */\r\nexport function daysAgoPipe(value: string | number | Date): string {\r\n if (!value) {\r\n return 'n/a';\r\n }\r\n\r\n const inputDate = new Date(value);\r\n const today = new Date();\r\n\r\n // Normalize times to midnight to compare only dates\r\n inputDate.setHours(0, 0, 0, 0);\r\n today.setHours(0, 0, 0, 0);\r\n\r\n const diffTime = today.getTime() - inputDate.getTime();\r\n const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24));\r\n\r\n if (diffDays === 0) return t('r-pipes:today');\r\n if (diffDays === 1) return t('r-pipes:yesterday');\r\n return t('r-pipes:daysAgo', { count: diffDays });\r\n}\r\n\r\n/**\r\n * Formats a count as pieces/items.\r\n * Uses the i18n system for translations (requires pipes namespace loaded).\r\n *\r\n * @param value Count value\r\n * @returns Formatted piece count string\r\n *\r\n * @example\r\n * // In template: {{quantity | pieces}}\r\n * // English: \"none\", \"one\", \"3 pcs\"\r\n * // Swedish: \"inga\", \"en\", \"3 st\"\r\n */\r\nexport function piecesPipe(value: string | number): string {\r\n if (value === null || value === undefined) {\r\n return 'n/a';\r\n }\r\n\r\n const count = Number(value);\r\n return t('r-pipes:pieces', { count });\r\n}\r\n\r\n\r\n\r\n// =============================== Array operation pipes ===========================\r\n\r\n\r\n\r\n/**\r\n * Joins array elements with the specified separator\r\n * @param value Array to join\r\n * @param separator Character(s) to use between elements (defaults to comma)\r\n * @returns Joined string or original value if not an array\r\n */\r\nexport function joinPipe(value: any[], separator: string = ','): string | any {\r\n if (!Array.isArray(value)) return value;\r\n return value.join(separator);\r\n}\r\n\r\n/**\r\n * Returns the first element of an array\r\n * @param value Array to extract from\r\n * @returns First element or empty string if array is empty/invalid\r\n */\r\nexport function firstPipe(value: any[]): any {\r\n if (!Array.isArray(value) || value.length === 0) return '';\r\n return value[0];\r\n}\r\n\r\n/**\r\n * Returns the last element of an array\r\n * @param value Array to extract from\r\n * @returns Last element or empty string if array is empty/invalid\r\n */\r\nexport function lastPipe(value: any[]): any {\r\n if (!Array.isArray(value) || value.length === 0) return '';\r\n return value[value.length - 1];\r\n}\r\n\r\n// Object operation pipes\r\n/**\r\n * Returns the keys of an object\r\n * @param value Object to extract keys from\r\n * @returns Array of object keys or empty array if not an object\r\n */\r\nexport function keysPipe(value: object): string[] {\r\n if (typeof value !== 'object' || value === null) return [];\r\n return Object.keys(value);\r\n}\r\n\r\n// Conditional pipes\r\n/**\r\n * Returns a default value if the input is falsy\r\n * @param value Input value to check\r\n * @param defaultValue Value to return if input is falsy\r\n * @returns Original value or default value\r\n */\r\nexport function defaultPipe(value: any, defaultValue: string): any {\r\n return value || defaultValue;\r\n}\r\n\r\n/**\r\n * Implements ternary operator as a pipe\r\n * @param value Condition to evaluate\r\n * @param trueValue Value to return if condition is truthy\r\n * @param falseValue Value to return if condition is falsy\r\n * @returns Selected value based on condition\r\n */\r\nexport function ternaryPipe(value: any, trueValue: string, falseValue: string): string {\r\n return value ? trueValue : falseValue;\r\n}\r\n\r\n\r\n\r\n// =============================== Pipe registry and application ===========================\r\n\r\n\r\n/**\r\n * Interface for a collection of pipe functions.\r\n * Use this to look up pipes by name for template processing.\r\n *\r\n * @example\r\n * // Check if a pipe exists before using\r\n * if (registry.has('currency')) {\r\n * const formatted = registry.get('currency')(price);\r\n * }\r\n */\r\nexport interface PipeRegistry {\r\n /**\r\n * Looks up a pipe by name, returning null if not found.\r\n */\r\n lookup(name: string): PipeFunction | null;\r\n\r\n /**\r\n * Gets a pipe by name, throwing if not found.\r\n */\r\n get(name: string): PipeFunction;\r\n\r\n /**\r\n * Checks if a pipe with the given name exists.\r\n */\r\n has(name: string): boolean;\r\n}\r\n\r\n\r\n/**\r\n * Creates a new pipe registry with all built-in pipes registered.\r\n * Built-in pipes include:\r\n *\r\n * **Text:** uppercase, lowercase, capitalize, trim, shorten\r\n * **Formatting:** currency, date, daysAgo, pieces\r\n * **Arrays:** join, first, last\r\n * **Objects:** keys\r\n * **Conditionals:** default, ternary\r\n *\r\n * @returns A new pipe registry instance\r\n *\r\n * @example\r\n * const registry = createPipeRegistry();\r\n * const upperPipe = registry.get('uppercase');\r\n * console.log(upperPipe('hello')); // 'HELLO'\r\n */\r\nexport function createPipeRegistry(): PipeRegistry {\r\n const pipes = new Map<string, PipeFunction>();\r\n\r\n // Text manipulation\r\n pipes.set('uppercase', uppercasePipe);\r\n pipes.set('lowercase', lowercasePipe);\r\n pipes.set('capitalize', capitalizePipe);\r\n pipes.set('trim', trimPipe);\r\n pipes.set('shorten', shortenPipe);\r\n\r\n // Formatting\r\n pipes.set('currency', currencyPipe);\r\n pipes.set('date', datePipe);\r\n pipes.set('daysAgo', daysAgoPipe);\r\n pipes.set('pieces', piecesPipe);\r\n\r\n // Array operations\r\n pipes.set('join', joinPipe);\r\n pipes.set('first', firstPipe);\r\n pipes.set('last', lastPipe);\r\n\r\n // Object operations\r\n pipes.set('keys', keysPipe);\r\n\r\n // Conditional formatting\r\n pipes.set('default', defaultPipe);\r\n pipes.set('ternary', ternaryPipe);\r\n\r\n return {\r\n lookup(name) {\r\n return pipes.get(name);\r\n },\r\n get(name) {\r\n var pipe = pipes.get(name);\r\n if (!pipe) {\r\n throw Error(\"Pipe '\" + name + \"' not found.\");\r\n }\r\n return pipe;\r\n },\r\n has(name) {\r\n return pipes.has(name);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Default pipe registry instance with all built-in pipes.\r\n * Used by template engines unless a custom registry is provided.\r\n *\r\n * @example\r\n * import { defaultPipes } from 'relaxjs';\r\n *\r\n * if (defaultPipes.has('uppercase')) {\r\n * const result = defaultPipes.get('uppercase')('hello');\r\n * }\r\n */\r\nexport const defaultPipes = createPipeRegistry();\r\n\r\n/**\r\n * Applies a series of pipes to a value sequentially.\r\n * Each pipe transforms the output of the previous pipe.\r\n *\r\n * Pipe arguments are specified after a colon: `shorten:20`\r\n *\r\n * @param value - Initial value to transform\r\n * @param pipes - Array of pipe strings (name and optional arguments separated by ':')\r\n * @param registry - Optional custom pipe registry (uses defaultPipes if not provided)\r\n * @returns The transformed value after applying all pipes\r\n *\r\n * @example\r\n * // Apply single pipe\r\n * applyPipes('hello', ['uppercase']); // 'HELLO'\r\n *\r\n * @example\r\n * // Chain multiple pipes\r\n * applyPipes('hello world', ['uppercase', 'shorten:8']); // 'HELLO...'\r\n *\r\n * @example\r\n * // With pipe arguments\r\n * applyPipes(1234.56, ['currency']); // '$1,234.56'\r\n */\r\nexport function applyPipes(\r\n value: any,\r\n pipes: string[],\r\n registry: PipeRegistry = defaultPipes\r\n): any {\r\n\r\n return pipes.reduce((currentValue, pipe) => {\r\n const [pipeName, ...args] = pipe.split(':').map((p) => p.trim());\r\n\r\n if (!registry.has(pipeName)) {\r\n return `[Pipe ${pipeName} not found]`;\r\n }\r\n\r\n try {\r\n return registry.get(pipeName)(currentValue, ...args);\r\n } catch (error) {\r\n return `[Pipe ${pipeName}, value: ${value}, error: ${error}]`;\r\n }\r\n }, value);\r\n}", "/**\r\n * Resolves a deeply nested value from an object using a path array.\r\n * Safely navigates through the object tree, returning undefined if any\r\n * segment in the path is null or undefined.\r\n *\r\n * Used internally by template engines to access data properties,\r\n * but also useful for general-purpose deep property access.\r\n *\r\n * @param path - Array of property names forming the path to the value\r\n * @param context - The object to resolve the value from\r\n * @returns The resolved value, or undefined if path cannot be resolved\r\n *\r\n * @example\r\n * // Access nested property\r\n * const user = { address: { city: 'Stockholm' } };\r\n * const city = resolveValue(['address', 'city'], user);\r\n * // Returns: 'Stockholm'\r\n *\r\n * @example\r\n * // Safe access with missing properties\r\n * const data = { user: null };\r\n * const name = resolveValue(['user', 'name'], data);\r\n * // Returns: undefined (doesn't throw)\r\n *\r\n * @example\r\n * // Use with template expression paths\r\n * const path = 'user.profile.avatar'.split('.');\r\n * const avatar = resolveValue(path, context);\r\n */\r\nexport function resolveValue(\r\n path: string[],\r\n context: Record<string, any>\r\n): any | undefined {\r\n let value = context;\r\n\r\n for (const key of path) {\r\n if (value === undefined || value === null) {\r\n return undefined;\r\n }\r\n\r\n value = value[key];\r\n }\r\n\r\n return value !== undefined && value !== null ? value : undefined;\r\n}\r\n ", "/**\r\n * @module SequentialId\r\n * Generates compact, time-ordered unique identifiers suitable for distributed systems.\r\n *\r\n * IDs are structured to be:\r\n * - Unique across multiple clients (via baseId)\r\n * - Time-sortable (timestamp is the most significant bits)\r\n * - Compact (Base36 encoding produces short strings)\r\n *\r\n * Bit allocation (58 bits total):\r\n * - 30 bits for timestamp (seconds since January 1, 2025)\r\n * - 8 bits for per-second counter (supports 256 IDs/second)\r\n * - 20 bits for client/endpoint identifier (supports ~1M unique sources)\r\n */\r\n\r\nconst TIMESTAMP_BITS = 30;\r\nconst COUNTER_BITS = 8;\r\nconst BASEID_BITS = 20;\r\n\r\nconst MAX_TIMESTAMP = (1 << TIMESTAMP_BITS) - 1;\r\nconst MAX_COUNTER = (1 << COUNTER_BITS) - 1;\r\nconst MAX_BASEID = (1 << BASEID_BITS) - 1;\r\n\r\nconst EPOCH = Math.floor(new Date('2025-01-01T00:00:00Z').getTime() / 1000);\r\n\r\nlet lastTimestamp = 0;\r\nlet counter = 0;\r\n\r\n/**\r\n * Generates a unique, time-ordered sequential ID.\r\n *\r\n * The ID combines a timestamp, per-second counter, and client identifier\r\n * into a compact Base36 string. IDs generated later will sort after earlier IDs,\r\n * making them suitable for ordered collections.\r\n *\r\n * @param baseId - Unique identifier for the client/endpoint (0 to 1,048,575).\r\n * Use different baseIds for different servers or processes to\r\n * avoid collisions.\r\n * @returns Base36 encoded string representing the unique ID\r\n * @throws Error if baseId is out of valid range\r\n * @throws Error if more than 256 IDs are generated in a single second\r\n * @throws Error if timestamp exceeds range (after year 2045)\r\n *\r\n * @example\r\n * // Generate ID for server instance 1\r\n * const id1 = generateSequentialId(1);\r\n * // Returns something like: 'k2j8m3n5p'\r\n *\r\n * @example\r\n * // Different servers use different baseIds\r\n * const SERVER_ID = parseInt(process.env.SERVER_ID || '0');\r\n * const orderId = generateSequentialId(SERVER_ID);\r\n *\r\n * @example\r\n * // IDs are time-sortable\r\n * const id1 = generateSequentialId(0);\r\n * await delay(1000);\r\n * const id2 = generateSequentialId(0);\r\n * console.log(id1 < id2); // true (lexicographic comparison works)\r\n */\r\nexport function generateSequentialId(baseId: number): string {\r\n if (baseId < 0 || baseId > MAX_BASEID) {\r\n throw new Error(`baseId must be between 0 and ${MAX_BASEID}`);\r\n }\r\n\r\n const now = Math.floor(Date.now() / 1000);\r\n if (now === lastTimestamp) {\r\n counter++;\r\n if (counter > MAX_COUNTER) {\r\n throw new Error('Too many IDs generated in one second');\r\n }\r\n } else {\r\n lastTimestamp = now;\r\n counter = 0;\r\n }\r\n\r\n const timestamp = now - EPOCH;\r\n if (timestamp > MAX_TIMESTAMP) {\r\n throw new Error('Timestamp exceeds allowed range (beyond 2045-01-01)');\r\n }\r\n\r\n const ts = BigInt(timestamp);\r\n const cnt = BigInt(counter);\r\n const uid = BigInt(baseId);\r\n\r\n // [ timestamp (30 bits) | counter (8 bits) | baseId (20 bits) ]\r\n const id =\r\n (ts << BigInt(COUNTER_BITS + BASEID_BITS)) |\r\n (cnt << BigInt(BASEID_BITS)) |\r\n uid;\r\n\r\n return id.toString(36).toLowerCase();\r\n}\r\n", "/**\r\n * Global error handling for Relaxjs.\r\n * Register a handler with `onError()` to intercept errors before they throw.\r\n * Call `ctx.suppress()` in the handler to prevent the error from being thrown.\r\n *\r\n * @example\r\n * import { onError } from 'relaxjs';\r\n *\r\n * onError((error, ctx) => {\r\n * logToService(error.message, error.context);\r\n * showToast(error.message);\r\n * ctx.suppress();\r\n * });\r\n */\r\n\r\n/**\r\n * Passed to error handlers to control error behavior.\r\n * Call `suppress()` to prevent the error from being thrown.\r\n */\r\nexport interface ErrorContext {\r\n suppress(): void;\r\n}\r\n\r\n/**\r\n * Error with structured context for debugging.\r\n * The `context` record contains details like route name, component tag, route data.\r\n *\r\n * @example\r\n * onError((error, ctx) => {\r\n * console.log(error.context.route);\r\n * console.log(error.context.componentTagName);\r\n * });\r\n */\r\nexport class RelaxError extends Error {\r\n constructor(\r\n message: string,\r\n public context: Record<string, unknown>,\r\n ) {\r\n super(message);\r\n }\r\n}\r\n\r\ntype ErrorHandler = (error: RelaxError, ctx: ErrorContext) => void;\r\n\r\nlet handler: ErrorHandler | null = null;\r\n\r\n/**\r\n * Registers a global error handler for Relaxjs errors.\r\n * The handler receives the error and an `ErrorContext`.\r\n * Call `ctx.suppress()` to prevent the error from being thrown.\r\n * Only one handler can be active at a time; subsequent calls replace the previous handler.\r\n *\r\n * @example\r\n * onError((error, ctx) => {\r\n * if (error.context.route === 'optional-panel') {\r\n * ctx.suppress();\r\n * return;\r\n * }\r\n * showErrorDialog(error.message);\r\n * });\r\n */\r\nexport function onError(fn: ErrorHandler) {\r\n handler = fn;\r\n}\r\n\r\n/**\r\n * Reports an error through the global handler.\r\n * Returns the `RelaxError` if it should be thrown, or `null` if the handler suppressed it.\r\n * The caller is responsible for throwing the returned error.\r\n *\r\n * @param message - Human-readable error description\r\n * @param context - Structured data for debugging (route, component, params, cause, etc.)\r\n * @returns The error to throw, or `null` if suppressed\r\n *\r\n * @example\r\n * const error = reportError('Failed to load route component', {\r\n * route: 'user',\r\n * componentTagName: 'user-profile',\r\n * routeData: { id: 123 },\r\n * });\r\n * if (error) throw error;\r\n */\r\nexport function reportError(message: string, context: Record<string, unknown>): RelaxError | null {\r\n const error = new RelaxError(message, context);\r\n if (handler) {\r\n let suppressed = false;\r\n const ctx: ErrorContext = {\r\n suppress() { suppressed = true; },\r\n };\r\n handler(error, ctx);\r\n if (suppressed) {\r\n return null;\r\n }\r\n }\r\n return error;\r\n}\r\n"],
5
+ "mappings": "8sBAAA,IAAAA,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,SAAY,iBACZ,MAAS,+CACb,ICHA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,MAAS,QACT,UAAa,YACb,QAAW,sDACX,OAAU,oDACd,ICLA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,SAAY,0BACZ,MAAS,wDACT,OAAU,2BACd,ICJA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,SAAY,eACZ,MAAS,8CACb,ICHA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,MAAS,OACT,UAAa,UACb,QAAW,2DACX,OAAU,kDACd,ICLA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,KAAA,CAAAA,GAAA,SACI,SAAY,qCACZ,MAAS,4DACT,OAAU,sBACd,ICJA,IAAAC,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,eAAAC,GAAA,mBAAAC,EAAA,uBAAAC,EAAA,iBAAAC,EAAA,aAAAC,EAAA,gBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,EAAA,cAAAC,EAAA,yBAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,YAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,iBAAAC,GAAA,gBAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,kBAAAC,IAAA,eAAAC,GAAAzB,ICqBA,IAAM0B,EAAmB,IA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ACJ,EAIIC,EAA+B,KAiB5B,SAASC,EAAQC,EAAkB,CACtCF,EAAUE,CACd,CAmBO,SAASC,EAAYL,EAAiBC,EAAqD,CAC9F,IAAMK,EAAQ,IAAIP,EAAWC,EAASC,CAAO,EAC7C,GAAIC,EAAS,CACT,IAAIK,EAAa,GAKjB,GADAL,EAAQI,EAHkB,CACtB,UAAW,CAAEC,EAAa,EAAM,CACpC,CACkB,EACdA,EACA,OAAO,IAEf,CACA,OAAOD,CACX",
6
+ "names": ["require_r_common", "__commonJSMin", "exports", "module", "require_r_pipes", "__commonJSMin", "exports", "module", "require_r_validation", "__commonJSMin", "exports", "module", "require_r_common", "__commonJSMin", "exports", "module", "require_r_pipes", "__commonJSMin", "exports", "module", "require_r_validation", "__commonJSMin", "exports", "module", "index_exports", "__export", "RelaxError", "applyPipes", "capitalizePipe", "createPipeRegistry", "currencyPipe", "datePipe", "daysAgoPipe", "defaultPipe", "defaultPipes", "firstPipe", "generateSequentialId", "joinPipe", "keysPipe", "lastPipe", "lowercasePipe", "onError", "piecesPipe", "reportError", "resolveValue", "shortenPipe", "ternaryPipe", "trimPipe", "uppercasePipe", "__toCommonJS", "pluralRulesCache", "getPluralRule", "locale", "escapeRegex", "s", "defaultFormatICU", "message", "values", "_", "key", "type", "categoriesPart", "value", "exact", "category", "match", "escaped", "formatICU", "fallbackLocale", "currentLocale", "translations", "missingHandler", "t", "fullKey", "values", "namespace", "key", "message", "translations", "missingHandler", "currentLocale", "formatICU", "getCurrentLocale", "uppercasePipe", "value", "trimPipe", "lowercasePipe", "capitalizePipe", "str", "shortenPipe", "length", "maxLength", "currencyPipe", "currency", "locale", "getCurrentLocale", "datePipe", "format", "date", "daysAgoPipe", "inputDate", "today", "diffTime", "diffDays", "t", "piecesPipe", "count", "joinPipe", "separator", "firstPipe", "lastPipe", "keysPipe", "defaultPipe", "defaultValue", "ternaryPipe", "trueValue", "falseValue", "createPipeRegistry", "pipes", "name", "pipe", "defaultPipes", "applyPipes", "registry", "currentValue", "pipeName", "args", "p", "error", "resolveValue", "path", "context", "value", "key", "EPOCH", "lastTimestamp", "counter", "generateSequentialId", "baseId", "now", "timestamp", "ts", "cnt", "uid", "RelaxError", "message", "context", "handler", "onError", "fn", "reportError", "error", "suppressed"]
7
+ }
@@ -0,0 +1,2 @@
1
+ var N=Object.create;var S=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var w=e=>t=>{var r=e[t];if(r)return r();throw new Error("Module not found in bundle: "+t)};var c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var F=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of L(t))!H.call(e,o)&&o!==r&&S(e,o,{get:()=>t[o],enumerable:!(n=_(t,o))||n.enumerable});return e};var u=(e,t,r)=>(r=e!=null?N(k(e)):{},F(t||!e||!e.__esModule?S(r,"default",{value:e,enumerable:!0}):r,e));var I=c((he,O)=>{O.exports={greeting:"Hello, {name}!",items:"{count, plural, one {# item} other {# items}}"}});var A=c((Ee,X)=>{X.exports={today:"today",yesterday:"yesterday",daysAgo:"{count, plural, one {# day ago} other {# days ago}}",pieces:"{count, plural, =0 {none} one {one} other {# pcs}}"}});var M=c((Se,v)=>{v.exports={required:"This field is required.",range:"Number must be between {min} and {max}, was {actual}.",digits:"Please enter only digits."}});var R=c((we,q)=>{q.exports={greeting:"Hej, {name}!",items:"{count, plural, one {# sak} other {# saker}}"}});var b=c((Te,z)=>{z.exports={today:"idag",yesterday:"ig\xE5r",daysAgo:"{count, plural, one {# dag sedan} other {# dagar sedan}}",pieces:"{count, plural, =0 {inga} one {en} other {# st}}"}});var D=c((Pe,V)=>{V.exports={required:"Detta f\xE4lt \xE4r obligatoriskt.",range:"Talet m\xE5ste vara mellan {min} och {max}, var {actual}.",digits:"Ange endast siffror."}});var m=new Map;function U(e){return m.has(e)||m.set(e,new Intl.PluralRules(e)),m.get(e)}function T(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(e,t,r="en"){return e.replace(/\{(\w+)(?:, (plural|select),((?:[^{}]*\{[^{}]*\})+))?\}/g,(n,o,i,a)=>{let s=t[o];if(i==="plural"){let p=new RegExp(`=${T(String(s))}\\s*\\{([^{}]*)\\}`).exec(a);if(p)return p[1].replace(`{${o}}`,String(s)).replace("#",String(s));let $=U(r).select(s),E=new RegExp(`${$}\\s*\\{([^{}]*)\\}`).exec(a)||new RegExp("other\\s*\\{([^{}]*)\\}").exec(a);return E?E[1].replace(`{${o}}`,String(s)).replace("#",String(s)):String(s)}if(i==="select"){let p=T(String(s)),f=new RegExp(`\\b${p}\\s*\\{([^{}]*)\\}`).exec(a)||new RegExp("\\bother\\s*\\{([^{}]*)\\}").exec(a);return f?f[1]:String(s)}return s!==void 0?String(s):`{${o}}`})}var P=j;var Me=w({"./locales/en/r-common.json":()=>Promise.resolve().then(()=>u(I())),"./locales/en/r-pipes.json":()=>Promise.resolve().then(()=>u(A())),"./locales/en/r-validation.json":()=>Promise.resolve().then(()=>u(M())),"./locales/sv/r-common.json":()=>Promise.resolve().then(()=>u(R())),"./locales/sv/r-pipes.json":()=>Promise.resolve().then(()=>u(b())),"./locales/sv/r-validation.json":()=>Promise.resolve().then(()=>u(D()))});var Z="en",y=Z;var G={},B=null;function l(e,t){let[r,n]=e.includes(":")?e.split(":"):["r-common",e],o=G[r]?.[n];if(!o)return B&&B(n,r,y),e;try{return P(o,t,y)}catch{return e}}function x(){return y}function J(e){return String(e).toUpperCase()}function Q(e){return String(e).trimEnd().trimStart()}function W(e){return String(e).toLowerCase()}function Y(e){let t=String(e);return t.charAt(0).toUpperCase()+t.slice(1)}function K(e,t){let r=String(e),n=parseInt(t,10);return r.length>n?r.substring(0,n-3)+"...":r}function ee(e,t="USD"){let r=x();return new Intl.NumberFormat(r,{style:"currency",currency:t}).format(e)}function te(e,t){let r=new Date(e),n=x();return t==="short"?r.toLocaleDateString(n):t==="long"?r.toLocaleDateString(n,{weekday:"long",year:"numeric",month:"long",day:"numeric"}):r.toISOString()}function re(e){if(!e)return"n/a";let t=new Date(e),r=new Date;t.setHours(0,0,0,0),r.setHours(0,0,0,0);let n=r.getTime()-t.getTime(),o=Math.round(n/(1e3*60*60*24));return o===0?l("r-pipes:today"):o===1?l("r-pipes:yesterday"):l("r-pipes:daysAgo",{count:o})}function ne(e){if(e==null)return"n/a";let t=Number(e);return l("r-pipes:pieces",{count:t})}function oe(e,t=","){return Array.isArray(e)?e.join(t):e}function se(e){return!Array.isArray(e)||e.length===0?"":e[0]}function ie(e){return!Array.isArray(e)||e.length===0?"":e[e.length-1]}function ae(e){return typeof e!="object"||e===null?[]:Object.keys(e)}function ce(e,t){return e||t}function ue(e,t,r){return e?t:r}function le(){let e=new Map;return e.set("uppercase",J),e.set("lowercase",W),e.set("capitalize",Y),e.set("trim",Q),e.set("shorten",K),e.set("currency",ee),e.set("date",te),e.set("daysAgo",re),e.set("pieces",ne),e.set("join",oe),e.set("first",se),e.set("last",ie),e.set("keys",ae),e.set("default",ce),e.set("ternary",ue),{lookup(t){return e.get(t)},get(t){var r=e.get(t);if(!r)throw Error("Pipe '"+t+"' not found.");return r},has(t){return e.has(t)}}}var pe=le();function Ce(e,t,r=pe){return t.reduce((n,o)=>{let[i,...a]=o.split(":").map(s=>s.trim());if(!r.has(i))return`[Pipe ${i} not found]`;try{return r.get(i)(n,...a)}catch(s){return`[Pipe ${i}, value: ${e}, error: ${s}]`}},e)}function Ne(e,t){let r=t;for(let n of e){if(r==null)return;r=r[n]}return r??void 0}var ge=Math.floor(new Date("2025-01-01T00:00:00Z").getTime()/1e3),C=0,g=0;function de(e){if(e<0||e>1048575)throw new Error("baseId must be between 0 and 1048575");let t=Math.floor(Date.now()/1e3);if(t===C){if(g++,g>255)throw new Error("Too many IDs generated in one second")}else C=t,g=0;let r=t-ge;if(r>1073741823)throw new Error("Timestamp exceeds allowed range (beyond 2045-01-01)");let n=BigInt(r),o=BigInt(g),i=BigInt(e);return(n<<BigInt(28)|o<<BigInt(20)|i).toString(36).toLowerCase()}var d=class extends Error{constructor(r,n){super(r);this.context=n}},h=null;function fe(e){h=e}function me(e,t){let r=new d(e,t);if(h){let n=!1;if(h(r,{suppress(){n=!0}}),n)return null}return r}export{d as RelaxError,Ce as applyPipes,Y as capitalizePipe,le as createPipeRegistry,ee as currencyPipe,te as datePipe,re as daysAgoPipe,ce as defaultPipe,pe as defaultPipes,se as firstPipe,de as generateSequentialId,oe as joinPipe,ae as keysPipe,ie as lastPipe,W as lowercasePipe,fe as onError,ne as piecesPipe,me as reportError,Ne as resolveValue,K as shortenPipe,ue as ternaryPipe,Q as trimPipe,J as uppercasePipe};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/i18n/locales/en/r-common.json", "../../src/i18n/locales/en/r-pipes.json", "../../src/i18n/locales/en/r-validation.json", "../../src/i18n/locales/sv/r-common.json", "../../src/i18n/locales/sv/r-pipes.json", "../../src/i18n/locales/sv/r-validation.json", "../../src/i18n/icu.ts", "../../src/i18n/i18n.ts", "../../src/pipes.ts", "../../src/tools.ts", "../../src/SequentialId.ts", "../../src/errors.ts"],
4
+ "sourcesContent": ["{\r\n \"greeting\": \"Hello, {name}!\",\r\n \"items\": \"{count, plural, one {# item} other {# items}}\"\r\n}\r\n", "{\r\n \"today\": \"today\",\r\n \"yesterday\": \"yesterday\",\r\n \"daysAgo\": \"{count, plural, one {# day ago} other {# days ago}}\",\r\n \"pieces\": \"{count, plural, =0 {none} one {one} other {# pcs}}\"\r\n}\r\n", "{\r\n \"required\": \"This field is required.\",\r\n \"range\": \"Number must be between {min} and {max}, was {actual}.\",\r\n \"digits\": \"Please enter only digits.\"\r\n}\r\n", "{\r\n \"greeting\": \"Hej, {name}!\",\r\n \"items\": \"{count, plural, one {# sak} other {# saker}}\"\r\n}\r\n", "{\r\n \"today\": \"idag\",\r\n \"yesterday\": \"ig\u00E5r\",\r\n \"daysAgo\": \"{count, plural, one {# dag sedan} other {# dagar sedan}}\",\r\n \"pieces\": \"{count, plural, =0 {inga} one {en} other {# st}}\"\r\n}\r\n", "{\r\n \"required\": \"Detta f\u00E4lt \u00E4r obligatoriskt.\",\r\n \"range\": \"Talet m\u00E5ste vara mellan {min} och {max}, var {actual}.\",\r\n \"digits\": \"Ange endast siffror.\"\r\n}\r\n", "/**\r\n * @module icu\r\n * ICU message format support for internationalization.\r\n * Provides pluralization, select, and value interpolation.\r\n *\r\n * @example\r\n * // Simple interpolation\r\n * formatICU('Hello, {name}!', { name: 'World' });\r\n * // Returns: 'Hello, World!'\r\n *\r\n * @example\r\n * // Pluralization\r\n * formatICU('{count, plural, one {# item} other {# items}}', { count: 5 });\r\n * // Returns: '5 items'\r\n *\r\n * @example\r\n * // Select\r\n * formatICU('{gender, select, male {He} female {She} other {They}}', { gender: 'female' });\r\n * // Returns: 'She'\r\n */\r\n\r\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\r\n\r\n/**\r\n * Function type for message formatters.\r\n * Implement this to provide custom message formatting.\r\n */\r\nexport type MessageFormatter = (\r\n message: string,\r\n values?: Record<string, any>,\r\n locale?: string\r\n) => string;\r\n\r\n\r\nfunction getPluralRule(locale: string): Intl.PluralRules {\r\n if (!pluralRulesCache.has(locale)) {\r\n pluralRulesCache.set(locale, new Intl.PluralRules(locale));\r\n }\r\n return pluralRulesCache.get(locale)!;\r\n}\r\n\r\nfunction escapeRegex(s: string): string {\r\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\r\n}\r\n\r\n/**\r\n * Default ICU message formatter implementation.\r\n * Supports simple interpolation, pluralization with exact matches, and select.\r\n *\r\n * @param message - ICU format message string\r\n * @param values - Values to interpolate\r\n * @param locale - Locale for plural rules (default: 'en')\r\n * @returns Formatted message string\r\n *\r\n * @example\r\n * defaultFormatICU('{n, plural, =0 {none} one {# item} other {# items}}', { n: 0 }, 'en');\r\n * // Returns: 'none'\r\n *\r\n * @example\r\n * defaultFormatICU('{role, select, admin {Full access} other {Limited access}}', { role: 'admin' });\r\n * // Returns: 'Full access'\r\n */\r\nexport function defaultFormatICU(\r\n message: string,\r\n values: Record<string, any>,\r\n locale: string = 'en'\r\n): string {\r\n return message.replace(\r\n /\\{(\\w+)(?:, (plural|select),((?:[^{}]*\\{[^{}]*\\})+))?\\}/g,\r\n (_, key, type, categoriesPart) => {\r\n const value = values[key];\r\n\r\n if (type === 'plural') {\r\n const exact = new RegExp(\r\n `=${escapeRegex(String(value))}\\\\s*\\\\{([^{}]*)\\\\}`\r\n ).exec(categoriesPart);\r\n if (exact) {\r\n return exact[1]\r\n .replace(`{${key}}`, String(value))\r\n .replace('#', String(value));\r\n }\r\n\r\n const rules = getPluralRule(locale);\r\n const category = rules.select(value);\r\n const match =\r\n new RegExp(`${category}\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart) ||\r\n new RegExp(`other\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart);\r\n if (match) {\r\n return match[1]\r\n .replace(`{${key}}`, String(value))\r\n .replace('#', String(value));\r\n }\r\n return String(value);\r\n }\r\n\r\n if (type === 'select') {\r\n const escaped = escapeRegex(String(value));\r\n const match =\r\n new RegExp(`\\\\b${escaped}\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart) ||\r\n new RegExp(`\\\\bother\\\\s*\\\\{([^{}]*)\\\\}`).exec(categoriesPart);\r\n return match ? match[1] : String(value);\r\n }\r\n\r\n return value !== undefined ? String(value) : `{${key}}`;\r\n },\r\n );\r\n}\r\n\r\n/**\r\n * The active message formatter. Defaults to `defaultFormatICU`.\r\n * Can be replaced with `setMessageFormatter` for custom formatting.\r\n */\r\nexport let formatICU: MessageFormatter = defaultFormatICU;\r\n\r\n/**\r\n * Replaces the default message formatter with a custom implementation.\r\n * Use this to integrate with external i18n libraries like FormatJS.\r\n *\r\n * @param formatter - The custom formatter function\r\n *\r\n * @example\r\n * // Use FormatJS IntlMessageFormat\r\n * import { IntlMessageFormat } from 'intl-messageformat';\r\n *\r\n * setMessageFormatter((message, values, locale) => {\r\n * const fmt = new IntlMessageFormat(message, locale);\r\n * return fmt.format(values);\r\n * });\r\n */\r\nexport function setMessageFormatter(formatter: MessageFormatter) {\r\n formatICU = formatter;\r\n}", "/**\r\n * @module i18n\r\n * Internationalization support with namespace-based translations.\r\n * Uses ICU message format for pluralization, select, and formatting.\r\n *\r\n * @example\r\n * // Initialize locale\r\n * await setLocale('sv');\r\n *\r\n * // Use translations\r\n * const greeting = t('r-common:greeting', { name: 'John' });\r\n * const items = t('shop:items', { count: 5 });\r\n */\r\n\r\nimport { formatICU } from './icu';\r\n\r\ntype Locale = string;\r\ntype Namespace = string;\r\ntype TranslationMap = Record<string, string>;\r\ntype Translations = Record<Namespace, TranslationMap>;\r\n\r\nexport type MissingTranslationHandler = (\r\n key: string,\r\n namespace: string,\r\n locale: string,\r\n) => void;\r\n\r\n/**\r\n * Dispatched on `document` after `setLocale()` completes.\r\n * The `locale` property contains the new normalized locale code.\r\n *\r\n * @example\r\n * document.addEventListener('localechange', (e) => {\r\n * console.log(`Locale changed to ${e.locale}`);\r\n * this.render();\r\n * });\r\n */\r\nexport class LocaleChangeEvent extends Event {\r\n readonly locale: string;\r\n constructor(locale: string) {\r\n super('localechange', { bubbles: false });\r\n this.locale = locale;\r\n }\r\n}\r\n\r\ndeclare global {\r\n interface DocumentEventMap {\r\n localechange: LocaleChangeEvent;\r\n }\r\n}\r\n\r\nconst fallbackLocale: Locale = 'en';\r\nlet currentLocale: Locale = fallbackLocale;\r\nconst loadedNamespaces = new Set<Namespace>();\r\nconst translations: Translations = {};\r\nlet missingHandler: MissingTranslationHandler | null = null;\r\n\r\nfunction normalizeLocale(locale: string): string {\r\n return locale.toLowerCase().split('-')[0];\r\n}\r\n\r\n/**\r\n * Sets the current locale and loads the common namespace.\r\n * Clears previously loaded translations and dispatches a `localechange` event.\r\n *\r\n * @param locale - The locale code (e.g., 'en', 'sv', 'en-US')\r\n *\r\n * @example\r\n * await setLocale('sv');\r\n */\r\nexport async function setLocale(locale: string): Promise<void> {\r\n const normalized = normalizeLocale(locale);\r\n currentLocale = normalized;\r\n loadedNamespaces.clear();\r\n Object.keys(translations).forEach(ns => delete translations[ns]);\r\n await loadNamespace('r-common');\r\n if (typeof document !== 'undefined') {\r\n document.dispatchEvent(new LocaleChangeEvent(normalized));\r\n }\r\n}\r\n\r\n/**\r\n * Loads a translation namespace on demand.\r\n * Falls back to the default locale if translations are not found.\r\n *\r\n * @param namespace - The namespace to load (e.g., 'shop', 'errors')\r\n *\r\n * @example\r\n * await loadNamespace('shop');\r\n * const price = t('shop:priceLabel');\r\n */\r\nexport async function loadNamespace(namespace: Namespace): Promise<void> {\r\n if (loadedNamespaces.has(namespace)) return;\r\n\r\n try {\r\n const module = await import(`./locales/${currentLocale}/${namespace}.json`);\r\n translations[namespace] = module.default;\r\n loadedNamespaces.add(namespace);\r\n } catch (err) {\r\n if (currentLocale !== fallbackLocale) {\r\n const fallback = await import(`./locales/${fallbackLocale}/${namespace}.json`);\r\n translations[namespace] = fallback.default;\r\n loadedNamespaces.add(namespace);\r\n } else {\r\n console.warn(`i18n: Failed to load namespace '${namespace}' for locale '${currentLocale}'`);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Loads multiple translation namespaces in parallel.\r\n *\r\n * @param namespaces - Array of namespace names to load\r\n *\r\n * @example\r\n * await loadNamespaces(['r-pipes', 'r-validation']);\r\n */\r\nexport async function loadNamespaces(namespaces: Namespace[]): Promise<void> {\r\n await Promise.all(namespaces.map(ns => loadNamespace(ns)));\r\n}\r\n\r\n/**\r\n * Translates a key with optional value interpolation.\r\n * Supports ICU message format for pluralization and select.\r\n *\r\n * @param fullKey - Translation key in format 'namespace:key' or just 'key' (uses 'r-common')\r\n * @param values - Values to interpolate into the message\r\n * @returns The translated string, or the key if not found\r\n *\r\n * @example\r\n * // Simple translation\r\n * t('greeting'); // Uses r-common:greeting\r\n *\r\n * // With namespace\r\n * t('errors:notFound');\r\n *\r\n * // With interpolation\r\n * t('welcome', { name: 'John' }); // \"Welcome, John!\"\r\n *\r\n * // With pluralization (ICU format)\r\n * t('items', { count: 5 }); // \"5 items\" or \"5 f\u00F6rem\u00E5l\"\r\n */\r\nexport function t(fullKey: string, values?: Record<string, any>): string {\r\n const [namespace, key] = fullKey.includes(':')\r\n ? fullKey.split(':')\r\n : ['r-common', fullKey];\r\n const message = translations[namespace]?.[key];\r\n if (!message) {\r\n if (missingHandler) missingHandler(key, namespace, currentLocale);\r\n return fullKey;\r\n }\r\n try {\r\n return formatICU(message, values, currentLocale) as string;\r\n } catch {\r\n return fullKey;\r\n }\r\n}\r\n\r\n/**\r\n * Returns the current locale code.\r\n *\r\n * @returns The normalized locale code (e.g., 'en', 'sv')\r\n */\r\nexport function getCurrentLocale(): string {\r\n return currentLocale;\r\n}\r\n\r\n/**\r\n * Registers a handler called when `t()` encounters a missing translation key.\r\n * Pass `null` to remove the handler.\r\n *\r\n * @param handler - Callback receiving the key, namespace, and locale\r\n *\r\n * @example\r\n * onMissingTranslation((key, ns, locale) => {\r\n * console.warn(`Missing: ${ns}:${key} [${locale}]`);\r\n * });\r\n */\r\nexport function onMissingTranslation(handler: MissingTranslationHandler | null): void {\r\n missingHandler = handler;\r\n}\r\n", "/**\r\n * @module pipes\r\n * Data transformation functions (pipes) for use in template expressions.\r\n * Pipes transform values for display, like formatting dates, currencies, or text.\r\n *\r\n * Locale-aware pipes (currency, date, daysAgo, pieces) use the i18n system\r\n * for formatting and translations. Call `setLocale()` before using these pipes.\r\n *\r\n * Pipes can be chained in templates: `{{value | uppercase | shorten:20}}`\r\n *\r\n * @example\r\n * // In templates\r\n * <span>{{user.name | uppercase}}</span>\r\n * <span>{{price | currency}}</span>\r\n * <span>{{createdAt | daysAgo}}</span>\r\n *\r\n * @example\r\n * // Programmatic usage\r\n * import { applyPipes, defaultPipes } from 'relaxjs';\r\n * const result = applyPipes('hello world', ['uppercase', 'shorten:8']);\r\n * // Returns: 'HELLO...'\r\n */\r\n\r\nimport { getCurrentLocale, t } from './i18n/i18n';\r\n\r\n/**\r\n * Type definition for pipe transformation functions.\r\n * Pipes take a value and optional arguments, returning a transformed value.\r\n *\r\n * @example\r\n * // Define a custom pipe\r\n * const reversePipe: PipeFunction = (value: string) => {\r\n * return value.split('').reverse().join('');\r\n * };\r\n */\r\nexport type PipeFunction = (value: any, ...args: any[]) => any;\r\n\r\n\r\n// =============================== Text manipulation pipes ===========================\r\n\r\n\r\n\r\n/**\r\n * Converts a string to uppercase\r\n * @param value The string to convert\r\n * @returns The uppercase string\r\n */\r\nexport function uppercasePipe(value: string): string {\r\n return String(value).toUpperCase();\r\n}\r\n\r\n/**\r\n * Converts a string to uppercase\r\n * @param value The string to convert\r\n * @returns The uppercase string\r\n */\r\nexport function trimPipe(value: string): string {\r\n return String(value).trimEnd().trimStart();\r\n}\r\n\r\n\r\n/**\r\n * Converts a string to lowercase\r\n * @param value The string to convert\r\n * @returns The lowercase string\r\n */\r\nexport function lowercasePipe(value: string): string {\r\n return String(value).toLowerCase();\r\n}\r\n\r\n/**\r\n * Capitalizes the first character of a string\r\n * @param value The string to capitalize\r\n * @returns The capitalized string\r\n */\r\nexport function capitalizePipe(value: string): string {\r\n const str = String(value);\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n\r\n/**\r\n * Shortens a string to a specified length and adds ellipsis.\r\n * @param value The string to shorten\r\n * @param length Maximum length including ellipsis\r\n * @returns The shortened string with ellipsis if needed\r\n */\r\nexport function shortenPipe(value: string, length: string): string {\r\n const str = String(value);\r\n const maxLength = parseInt(length, 10);\r\n return str.length > maxLength\r\n ? str.substring(0, maxLength - 3) + '...'\r\n : str;\r\n}\r\n\r\n// Formatting pipes\r\n/**\r\n * Formats a number as currency using the current locale.\r\n * Uses the i18n system's current locale for formatting.\r\n *\r\n * @param value The number to format\r\n * @param currency Currency code (defaults to USD)\r\n * @returns Formatted currency string\r\n *\r\n * @example\r\n * // In template: {{price | currency}} or {{price | currency:EUR}}\r\n * currencyPipe(1234.56); // \"$1,234.56\" (en) or \"1 234,56 $\" (sv)\r\n * currencyPipe(1234.56, 'SEK'); // \"SEK 1,234.56\" (en) or \"1 234,56 kr\" (sv)\r\n */\r\nexport function currencyPipe(value: number, currency: string = 'USD'): string {\r\n const locale = getCurrentLocale();\r\n return new Intl.NumberFormat(locale, {\r\n style: 'currency',\r\n currency\r\n }).format(value);\r\n}\r\n\r\n/**\r\n * Formats a date value according to the specified format.\r\n * Uses the i18n system's current locale for formatting.\r\n *\r\n * @param value Date value (string, number, or Date object)\r\n * @param format Format type: 'short', 'long', or default (ISO)\r\n * @returns Formatted date string\r\n *\r\n * @example\r\n * // In template: {{date | date:short}} or {{date | date:long}}\r\n * datePipe(new Date(), 'short'); // \"1/15/2024\" (en) or \"2024-01-15\" (sv)\r\n * datePipe(new Date(), 'long'); // \"Monday, January 15, 2024\" (en) or \"m\u00E5ndag 15 januari 2024\" (sv)\r\n */\r\nexport function datePipe(value: string | number | Date, format?: string): string {\r\n const date = new Date(value);\r\n const locale = getCurrentLocale();\r\n if (format === 'short') {\r\n return date.toLocaleDateString(locale);\r\n } else if (format === 'long') {\r\n return date.toLocaleDateString(locale, {\r\n weekday: 'long',\r\n year: 'numeric',\r\n month: 'long',\r\n day: 'numeric'\r\n });\r\n }\r\n return date.toISOString();\r\n}\r\n\r\n/**\r\n * Prints today, yesterday or X days ago.\r\n * Uses the i18n system for translations (requires pipes namespace loaded).\r\n *\r\n * @param value Date value (string, number, or Date object)\r\n * @returns Formatted relative date string\r\n *\r\n * @example\r\n * // In template: {{createdAt | daysAgo}}\r\n * // English: \"today\", \"yesterday\", \"3 days ago\"\r\n * // Swedish: \"idag\", \"ig\u00E5r\", \"3 dagar sedan\"\r\n */\r\nexport function daysAgoPipe(value: string | number | Date): string {\r\n if (!value) {\r\n return 'n/a';\r\n }\r\n\r\n const inputDate = new Date(value);\r\n const today = new Date();\r\n\r\n // Normalize times to midnight to compare only dates\r\n inputDate.setHours(0, 0, 0, 0);\r\n today.setHours(0, 0, 0, 0);\r\n\r\n const diffTime = today.getTime() - inputDate.getTime();\r\n const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24));\r\n\r\n if (diffDays === 0) return t('r-pipes:today');\r\n if (diffDays === 1) return t('r-pipes:yesterday');\r\n return t('r-pipes:daysAgo', { count: diffDays });\r\n}\r\n\r\n/**\r\n * Formats a count as pieces/items.\r\n * Uses the i18n system for translations (requires pipes namespace loaded).\r\n *\r\n * @param value Count value\r\n * @returns Formatted piece count string\r\n *\r\n * @example\r\n * // In template: {{quantity | pieces}}\r\n * // English: \"none\", \"one\", \"3 pcs\"\r\n * // Swedish: \"inga\", \"en\", \"3 st\"\r\n */\r\nexport function piecesPipe(value: string | number): string {\r\n if (value === null || value === undefined) {\r\n return 'n/a';\r\n }\r\n\r\n const count = Number(value);\r\n return t('r-pipes:pieces', { count });\r\n}\r\n\r\n\r\n\r\n// =============================== Array operation pipes ===========================\r\n\r\n\r\n\r\n/**\r\n * Joins array elements with the specified separator\r\n * @param value Array to join\r\n * @param separator Character(s) to use between elements (defaults to comma)\r\n * @returns Joined string or original value if not an array\r\n */\r\nexport function joinPipe(value: any[], separator: string = ','): string | any {\r\n if (!Array.isArray(value)) return value;\r\n return value.join(separator);\r\n}\r\n\r\n/**\r\n * Returns the first element of an array\r\n * @param value Array to extract from\r\n * @returns First element or empty string if array is empty/invalid\r\n */\r\nexport function firstPipe(value: any[]): any {\r\n if (!Array.isArray(value) || value.length === 0) return '';\r\n return value[0];\r\n}\r\n\r\n/**\r\n * Returns the last element of an array\r\n * @param value Array to extract from\r\n * @returns Last element or empty string if array is empty/invalid\r\n */\r\nexport function lastPipe(value: any[]): any {\r\n if (!Array.isArray(value) || value.length === 0) return '';\r\n return value[value.length - 1];\r\n}\r\n\r\n// Object operation pipes\r\n/**\r\n * Returns the keys of an object\r\n * @param value Object to extract keys from\r\n * @returns Array of object keys or empty array if not an object\r\n */\r\nexport function keysPipe(value: object): string[] {\r\n if (typeof value !== 'object' || value === null) return [];\r\n return Object.keys(value);\r\n}\r\n\r\n// Conditional pipes\r\n/**\r\n * Returns a default value if the input is falsy\r\n * @param value Input value to check\r\n * @param defaultValue Value to return if input is falsy\r\n * @returns Original value or default value\r\n */\r\nexport function defaultPipe(value: any, defaultValue: string): any {\r\n return value || defaultValue;\r\n}\r\n\r\n/**\r\n * Implements ternary operator as a pipe\r\n * @param value Condition to evaluate\r\n * @param trueValue Value to return if condition is truthy\r\n * @param falseValue Value to return if condition is falsy\r\n * @returns Selected value based on condition\r\n */\r\nexport function ternaryPipe(value: any, trueValue: string, falseValue: string): string {\r\n return value ? trueValue : falseValue;\r\n}\r\n\r\n\r\n\r\n// =============================== Pipe registry and application ===========================\r\n\r\n\r\n/**\r\n * Interface for a collection of pipe functions.\r\n * Use this to look up pipes by name for template processing.\r\n *\r\n * @example\r\n * // Check if a pipe exists before using\r\n * if (registry.has('currency')) {\r\n * const formatted = registry.get('currency')(price);\r\n * }\r\n */\r\nexport interface PipeRegistry {\r\n /**\r\n * Looks up a pipe by name, returning null if not found.\r\n */\r\n lookup(name: string): PipeFunction | null;\r\n\r\n /**\r\n * Gets a pipe by name, throwing if not found.\r\n */\r\n get(name: string): PipeFunction;\r\n\r\n /**\r\n * Checks if a pipe with the given name exists.\r\n */\r\n has(name: string): boolean;\r\n}\r\n\r\n\r\n/**\r\n * Creates a new pipe registry with all built-in pipes registered.\r\n * Built-in pipes include:\r\n *\r\n * **Text:** uppercase, lowercase, capitalize, trim, shorten\r\n * **Formatting:** currency, date, daysAgo, pieces\r\n * **Arrays:** join, first, last\r\n * **Objects:** keys\r\n * **Conditionals:** default, ternary\r\n *\r\n * @returns A new pipe registry instance\r\n *\r\n * @example\r\n * const registry = createPipeRegistry();\r\n * const upperPipe = registry.get('uppercase');\r\n * console.log(upperPipe('hello')); // 'HELLO'\r\n */\r\nexport function createPipeRegistry(): PipeRegistry {\r\n const pipes = new Map<string, PipeFunction>();\r\n\r\n // Text manipulation\r\n pipes.set('uppercase', uppercasePipe);\r\n pipes.set('lowercase', lowercasePipe);\r\n pipes.set('capitalize', capitalizePipe);\r\n pipes.set('trim', trimPipe);\r\n pipes.set('shorten', shortenPipe);\r\n\r\n // Formatting\r\n pipes.set('currency', currencyPipe);\r\n pipes.set('date', datePipe);\r\n pipes.set('daysAgo', daysAgoPipe);\r\n pipes.set('pieces', piecesPipe);\r\n\r\n // Array operations\r\n pipes.set('join', joinPipe);\r\n pipes.set('first', firstPipe);\r\n pipes.set('last', lastPipe);\r\n\r\n // Object operations\r\n pipes.set('keys', keysPipe);\r\n\r\n // Conditional formatting\r\n pipes.set('default', defaultPipe);\r\n pipes.set('ternary', ternaryPipe);\r\n\r\n return {\r\n lookup(name) {\r\n return pipes.get(name);\r\n },\r\n get(name) {\r\n var pipe = pipes.get(name);\r\n if (!pipe) {\r\n throw Error(\"Pipe '\" + name + \"' not found.\");\r\n }\r\n return pipe;\r\n },\r\n has(name) {\r\n return pipes.has(name);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Default pipe registry instance with all built-in pipes.\r\n * Used by template engines unless a custom registry is provided.\r\n *\r\n * @example\r\n * import { defaultPipes } from 'relaxjs';\r\n *\r\n * if (defaultPipes.has('uppercase')) {\r\n * const result = defaultPipes.get('uppercase')('hello');\r\n * }\r\n */\r\nexport const defaultPipes = createPipeRegistry();\r\n\r\n/**\r\n * Applies a series of pipes to a value sequentially.\r\n * Each pipe transforms the output of the previous pipe.\r\n *\r\n * Pipe arguments are specified after a colon: `shorten:20`\r\n *\r\n * @param value - Initial value to transform\r\n * @param pipes - Array of pipe strings (name and optional arguments separated by ':')\r\n * @param registry - Optional custom pipe registry (uses defaultPipes if not provided)\r\n * @returns The transformed value after applying all pipes\r\n *\r\n * @example\r\n * // Apply single pipe\r\n * applyPipes('hello', ['uppercase']); // 'HELLO'\r\n *\r\n * @example\r\n * // Chain multiple pipes\r\n * applyPipes('hello world', ['uppercase', 'shorten:8']); // 'HELLO...'\r\n *\r\n * @example\r\n * // With pipe arguments\r\n * applyPipes(1234.56, ['currency']); // '$1,234.56'\r\n */\r\nexport function applyPipes(\r\n value: any,\r\n pipes: string[],\r\n registry: PipeRegistry = defaultPipes\r\n): any {\r\n\r\n return pipes.reduce((currentValue, pipe) => {\r\n const [pipeName, ...args] = pipe.split(':').map((p) => p.trim());\r\n\r\n if (!registry.has(pipeName)) {\r\n return `[Pipe ${pipeName} not found]`;\r\n }\r\n\r\n try {\r\n return registry.get(pipeName)(currentValue, ...args);\r\n } catch (error) {\r\n return `[Pipe ${pipeName}, value: ${value}, error: ${error}]`;\r\n }\r\n }, value);\r\n}", "/**\r\n * Resolves a deeply nested value from an object using a path array.\r\n * Safely navigates through the object tree, returning undefined if any\r\n * segment in the path is null or undefined.\r\n *\r\n * Used internally by template engines to access data properties,\r\n * but also useful for general-purpose deep property access.\r\n *\r\n * @param path - Array of property names forming the path to the value\r\n * @param context - The object to resolve the value from\r\n * @returns The resolved value, or undefined if path cannot be resolved\r\n *\r\n * @example\r\n * // Access nested property\r\n * const user = { address: { city: 'Stockholm' } };\r\n * const city = resolveValue(['address', 'city'], user);\r\n * // Returns: 'Stockholm'\r\n *\r\n * @example\r\n * // Safe access with missing properties\r\n * const data = { user: null };\r\n * const name = resolveValue(['user', 'name'], data);\r\n * // Returns: undefined (doesn't throw)\r\n *\r\n * @example\r\n * // Use with template expression paths\r\n * const path = 'user.profile.avatar'.split('.');\r\n * const avatar = resolveValue(path, context);\r\n */\r\nexport function resolveValue(\r\n path: string[],\r\n context: Record<string, any>\r\n): any | undefined {\r\n let value = context;\r\n\r\n for (const key of path) {\r\n if (value === undefined || value === null) {\r\n return undefined;\r\n }\r\n\r\n value = value[key];\r\n }\r\n\r\n return value !== undefined && value !== null ? value : undefined;\r\n}\r\n ", "/**\r\n * @module SequentialId\r\n * Generates compact, time-ordered unique identifiers suitable for distributed systems.\r\n *\r\n * IDs are structured to be:\r\n * - Unique across multiple clients (via baseId)\r\n * - Time-sortable (timestamp is the most significant bits)\r\n * - Compact (Base36 encoding produces short strings)\r\n *\r\n * Bit allocation (58 bits total):\r\n * - 30 bits for timestamp (seconds since January 1, 2025)\r\n * - 8 bits for per-second counter (supports 256 IDs/second)\r\n * - 20 bits for client/endpoint identifier (supports ~1M unique sources)\r\n */\r\n\r\nconst TIMESTAMP_BITS = 30;\r\nconst COUNTER_BITS = 8;\r\nconst BASEID_BITS = 20;\r\n\r\nconst MAX_TIMESTAMP = (1 << TIMESTAMP_BITS) - 1;\r\nconst MAX_COUNTER = (1 << COUNTER_BITS) - 1;\r\nconst MAX_BASEID = (1 << BASEID_BITS) - 1;\r\n\r\nconst EPOCH = Math.floor(new Date('2025-01-01T00:00:00Z').getTime() / 1000);\r\n\r\nlet lastTimestamp = 0;\r\nlet counter = 0;\r\n\r\n/**\r\n * Generates a unique, time-ordered sequential ID.\r\n *\r\n * The ID combines a timestamp, per-second counter, and client identifier\r\n * into a compact Base36 string. IDs generated later will sort after earlier IDs,\r\n * making them suitable for ordered collections.\r\n *\r\n * @param baseId - Unique identifier for the client/endpoint (0 to 1,048,575).\r\n * Use different baseIds for different servers or processes to\r\n * avoid collisions.\r\n * @returns Base36 encoded string representing the unique ID\r\n * @throws Error if baseId is out of valid range\r\n * @throws Error if more than 256 IDs are generated in a single second\r\n * @throws Error if timestamp exceeds range (after year 2045)\r\n *\r\n * @example\r\n * // Generate ID for server instance 1\r\n * const id1 = generateSequentialId(1);\r\n * // Returns something like: 'k2j8m3n5p'\r\n *\r\n * @example\r\n * // Different servers use different baseIds\r\n * const SERVER_ID = parseInt(process.env.SERVER_ID || '0');\r\n * const orderId = generateSequentialId(SERVER_ID);\r\n *\r\n * @example\r\n * // IDs are time-sortable\r\n * const id1 = generateSequentialId(0);\r\n * await delay(1000);\r\n * const id2 = generateSequentialId(0);\r\n * console.log(id1 < id2); // true (lexicographic comparison works)\r\n */\r\nexport function generateSequentialId(baseId: number): string {\r\n if (baseId < 0 || baseId > MAX_BASEID) {\r\n throw new Error(`baseId must be between 0 and ${MAX_BASEID}`);\r\n }\r\n\r\n const now = Math.floor(Date.now() / 1000);\r\n if (now === lastTimestamp) {\r\n counter++;\r\n if (counter > MAX_COUNTER) {\r\n throw new Error('Too many IDs generated in one second');\r\n }\r\n } else {\r\n lastTimestamp = now;\r\n counter = 0;\r\n }\r\n\r\n const timestamp = now - EPOCH;\r\n if (timestamp > MAX_TIMESTAMP) {\r\n throw new Error('Timestamp exceeds allowed range (beyond 2045-01-01)');\r\n }\r\n\r\n const ts = BigInt(timestamp);\r\n const cnt = BigInt(counter);\r\n const uid = BigInt(baseId);\r\n\r\n // [ timestamp (30 bits) | counter (8 bits) | baseId (20 bits) ]\r\n const id =\r\n (ts << BigInt(COUNTER_BITS + BASEID_BITS)) |\r\n (cnt << BigInt(BASEID_BITS)) |\r\n uid;\r\n\r\n return id.toString(36).toLowerCase();\r\n}\r\n", "/**\r\n * Global error handling for Relaxjs.\r\n * Register a handler with `onError()` to intercept errors before they throw.\r\n * Call `ctx.suppress()` in the handler to prevent the error from being thrown.\r\n *\r\n * @example\r\n * import { onError } from 'relaxjs';\r\n *\r\n * onError((error, ctx) => {\r\n * logToService(error.message, error.context);\r\n * showToast(error.message);\r\n * ctx.suppress();\r\n * });\r\n */\r\n\r\n/**\r\n * Passed to error handlers to control error behavior.\r\n * Call `suppress()` to prevent the error from being thrown.\r\n */\r\nexport interface ErrorContext {\r\n suppress(): void;\r\n}\r\n\r\n/**\r\n * Error with structured context for debugging.\r\n * The `context` record contains details like route name, component tag, route data.\r\n *\r\n * @example\r\n * onError((error, ctx) => {\r\n * console.log(error.context.route);\r\n * console.log(error.context.componentTagName);\r\n * });\r\n */\r\nexport class RelaxError extends Error {\r\n constructor(\r\n message: string,\r\n public context: Record<string, unknown>,\r\n ) {\r\n super(message);\r\n }\r\n}\r\n\r\ntype ErrorHandler = (error: RelaxError, ctx: ErrorContext) => void;\r\n\r\nlet handler: ErrorHandler | null = null;\r\n\r\n/**\r\n * Registers a global error handler for Relaxjs errors.\r\n * The handler receives the error and an `ErrorContext`.\r\n * Call `ctx.suppress()` to prevent the error from being thrown.\r\n * Only one handler can be active at a time; subsequent calls replace the previous handler.\r\n *\r\n * @example\r\n * onError((error, ctx) => {\r\n * if (error.context.route === 'optional-panel') {\r\n * ctx.suppress();\r\n * return;\r\n * }\r\n * showErrorDialog(error.message);\r\n * });\r\n */\r\nexport function onError(fn: ErrorHandler) {\r\n handler = fn;\r\n}\r\n\r\n/**\r\n * Reports an error through the global handler.\r\n * Returns the `RelaxError` if it should be thrown, or `null` if the handler suppressed it.\r\n * The caller is responsible for throwing the returned error.\r\n *\r\n * @param message - Human-readable error description\r\n * @param context - Structured data for debugging (route, component, params, cause, etc.)\r\n * @returns The error to throw, or `null` if suppressed\r\n *\r\n * @example\r\n * const error = reportError('Failed to load route component', {\r\n * route: 'user',\r\n * componentTagName: 'user-profile',\r\n * routeData: { id: 123 },\r\n * });\r\n * if (error) throw error;\r\n */\r\nexport function reportError(message: string, context: Record<string, unknown>): RelaxError | null {\r\n const error = new RelaxError(message, context);\r\n if (handler) {\r\n let suppressed = false;\r\n const ctx: ErrorContext = {\r\n suppress() { suppressed = true; },\r\n };\r\n handler(error, ctx);\r\n if (suppressed) {\r\n return null;\r\n }\r\n }\r\n return error;\r\n}\r\n"],
5
+ "mappings": "omBAAA,IAAAA,EAAAC,EAAA,CAAAC,GAAAC,IAAA,CAAAA,EAAA,SACI,SAAY,iBACZ,MAAS,+CACb,ICHA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,IAAA,CAAAA,EAAA,SACI,MAAS,QACT,UAAa,YACb,QAAW,sDACX,OAAU,oDACd,ICLA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,IAAA,CAAAA,EAAA,SACI,SAAY,0BACZ,MAAS,wDACT,OAAU,2BACd,ICJA,IAAAC,EAAAC,EAAA,CAAAC,GAAAC,IAAA,CAAAA,EAAA,SACI,SAAY,eACZ,MAAS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,EAAM,OAAON,CAAO,EACpBO,EAAM,OAAOL,CAAM,EAQzB,OAJKG,GAAM,OAAO,EAA0B,EACvCC,GAAO,OAAO,EAAW,EAC1BC,GAEM,SAAS,EAAE,EAAE,YAAY,CACvC,CC3DO,IAAMC,EAAN,cAAyB,KAAM,CAClC,YACIC,EACOC,EACT,CACE,MAAMD,CAAO,EAFN,aAAAC,CAGX,CACJ,EAIIC,EAA+B,KAiB5B,SAASC,GAAQC,EAAkB,CACtCF,EAAUE,CACd,CAmBO,SAASC,GAAYL,EAAiBC,EAAqD,CAC9F,IAAMK,EAAQ,IAAIP,EAAWC,EAASC,CAAO,EAC7C,GAAIC,EAAS,CACT,IAAIK,EAAa,GAKjB,GADAL,EAAQI,EAHkB,CACtB,UAAW,CAAEC,EAAa,EAAM,CACpC,CACkB,EACdA,EACA,OAAO,IAEf,CACA,OAAOD,CACX",
6
+ "names": ["require_r_common", "__commonJSMin", "exports", "module", "require_r_pipes", "__commonJSMin", "exports", "module", "require_r_validation", "__commonJSMin", "exports", "module", "require_r_common", "__commonJSMin", "exports", "module", "require_r_pipes", "__commonJSMin", "exports", "module", "require_r_validation", "__commonJSMin", "exports", "module", "pluralRulesCache", "getPluralRule", "locale", "escapeRegex", "s", "defaultFormatICU", "message", "values", "_", "key", "type", "categoriesPart", "value", "exact", "category", "match", "escaped", "formatICU", "fallbackLocale", "currentLocale", "translations", "missingHandler", "t", "fullKey", "values", "namespace", "key", "message", "translations", "missingHandler", "currentLocale", "formatICU", "getCurrentLocale", "uppercasePipe", "value", "trimPipe", "lowercasePipe", "capitalizePipe", "str", "shortenPipe", "length", "maxLength", "currencyPipe", "currency", "locale", "getCurrentLocale", "datePipe", "format", "date", "daysAgoPipe", "inputDate", "today", "diffTime", "diffDays", "t", "piecesPipe", "count", "joinPipe", "separator", "firstPipe", "lastPipe", "keysPipe", "defaultPipe", "defaultValue", "ternaryPipe", "trueValue", "falseValue", "createPipeRegistry", "pipes", "name", "pipe", "defaultPipes", "applyPipes", "registry", "currentValue", "pipeName", "args", "p", "error", "resolveValue", "path", "context", "value", "key", "EPOCH", "lastTimestamp", "counter", "generateSequentialId", "baseId", "now", "timestamp", "ts", "cnt", "uid", "RelaxError", "message", "context", "handler", "onError", "fn", "reportError", "error", "suppressed"]
7
+ }
@@ -0,0 +1,333 @@
1
+ # Architecture Overview
2
+
3
+ Relaxjs is a library for building web applications with Web Components. It emphasizes explicit control, direct DOM manipulation, and predictable behavior.
4
+
5
+ ## Philosophy
6
+
7
+ Unlike modern SPA frameworks, Relaxjs takes an explicit approach:
8
+
9
+ - **No virtual DOM**: The real DOM is the source of truth
10
+ - **No hidden reactivity**: Changes happen when you explicitly make them
11
+ - **No synthetic lifecycle**: Uses native Web Component lifecycle hooks
12
+ - **Full developer control**: You always know what triggered what
13
+
14
+ ## Core Modules
15
+
16
+ ```
17
+ relaxjs/
18
+ ├── Routing # SPA navigation with guards and layouts
19
+ ├── Forms # Data binding, validation, type conversion
20
+ ├── DI # Dependency injection container
21
+ ├── HTTP # Fetch wrapper and WebSocket client
22
+ ├── i18n # Internationalization with ICU support
23
+ ├── Templates # HTML templating with data binding
24
+ └── Components # Pre-built UI components
25
+ ```
26
+
27
+ ## Module Integration
28
+
29
+ ### Application Startup
30
+
31
+ ```typescript
32
+ import { defineRoutes, startRouting } from 'relaxjs/routing';
33
+ import { setLocale } from 'relaxjs/i18n';
34
+ import { serviceCollection } from 'relaxjs/di';
35
+
36
+ class Application extends HTMLElement {
37
+ async connectedCallback() {
38
+ // 1. Register services
39
+ serviceCollection.registerByType(ApiService, { inject: [] });
40
+ serviceCollection.registerByType(AuthService, { inject: [ApiService] });
41
+
42
+ // 2. Set locale
43
+ await setLocale(navigator.language);
44
+
45
+ // 3. Define routes
46
+ defineRoutes([
47
+ { name: 'home', path: '/', componentTagName: 'app-home' },
48
+ { name: 'login', path: '/login', componentTagName: 'login-page' }
49
+ ]);
50
+
51
+ // 4. Start routing
52
+ startRouting();
53
+ }
54
+ }
55
+
56
+ customElements.define('app-main', Application);
57
+ ```
58
+
59
+ ### Component Pattern
60
+
61
+ ```typescript
62
+ class UserProfile extends HTMLElement {
63
+ private form: HTMLFormElement;
64
+ private validator: FormValidator;
65
+
66
+ connectedCallback() {
67
+ this.innerHTML = `
68
+ <form>
69
+ <input name="name" required>
70
+ <input name="email" type="email" required>
71
+ <button type="submit">Save</button>
72
+ </form>
73
+ `;
74
+
75
+ this.form = this.querySelector('form')!;
76
+ this.validator = new FormValidator(this.form, {
77
+ submitCallback: () => this.save()
78
+ });
79
+
80
+ this.loadUser();
81
+ }
82
+
83
+ async loadUser() {
84
+ const api = container.resolve(ApiService);
85
+ const user = await api.get('/user/profile');
86
+ setFormData(this.form, user.as<User>());
87
+ }
88
+
89
+ async save() {
90
+ const data = readData(this.form);
91
+ const api = container.resolve(ApiService);
92
+ await api.put('/user/profile', JSON.stringify(data));
93
+ }
94
+ }
95
+
96
+ customElements.define('user-profile', UserProfile);
97
+ ```
98
+
99
+ ## Data Flow
100
+
101
+ ```
102
+ ┌─────────────────────────────────────────────────────────┐
103
+ │ User Action │
104
+ └─────────────────────────────────────────────────────────┘
105
+
106
+
107
+ ┌─────────────────────────────────────────────────────────┐
108
+ │ Event Handler │
109
+ │ │
110
+ │ element.addEventListener('click', (e) => { │
111
+ │ // Explicit action │
112
+ │ }); │
113
+ └─────────────────────────────────────────────────────────┘
114
+
115
+
116
+ ┌─────────────────────────────────────────────────────────┐
117
+ │ DOM Update │
118
+ │ │
119
+ │ // Direct manipulation │
120
+ │ element.textContent = newValue; │
121
+ │ element.setAttribute('data-state', 'active'); │
122
+ └─────────────────────────────────────────────────────────┘
123
+ ```
124
+
125
+ ## Routing Architecture
126
+
127
+ ```
128
+ ┌──────────────┐ navigate() ┌──────────────────┐
129
+ │ User │ ────────────────► │ Router │
130
+ │ Action │ │ │
131
+ └──────────────┘ │ - Match route │
132
+ │ - Check guards │
133
+ │ - Update URL │
134
+ └────────┬─────────┘
135
+
136
+ NavigateRouteEvent
137
+
138
+
139
+ ┌──────────────────┐
140
+ │ r-route-target│
141
+ │ │
142
+ │ - Load component│
143
+ │ - Pass params │
144
+ └──────────────────┘
145
+ ```
146
+
147
+ ### Multiple Targets
148
+
149
+ ```html
150
+ <body>
151
+ <r-route-target>
152
+ <!-- Main content renders here -->
153
+ </r-route-target>
154
+
155
+ <r-route-target name="modal">
156
+ <!-- Modal content renders here -->
157
+ </r-route-target>
158
+
159
+ <r-route-target name="sidebar">
160
+ <!-- Sidebar content renders here -->
161
+ </r-route-target>
162
+ </body>
163
+ ```
164
+
165
+ ```typescript
166
+ // Navigate to specific target
167
+ navigate('userDetails', { params: { id: '123' }, target: 'modal' });
168
+ ```
169
+
170
+ ## Form Data Flow
171
+
172
+ ```
173
+ ┌─────────────┐ setFormData() ┌─────────────────────────────────────┐
174
+ │ Data │ ──────────────────► │ Form Elements & Custom Components │
175
+ │ Object │ │ │
176
+ └─────────────┘ │ <input> <select> <textarea> │
177
+ │ <r-input> <r-checkbox> (FORM API) │
178
+ ▲ └────────┬────────────────────────────┘
179
+ │ │
180
+ │ readData() User edits
181
+ │ │
182
+ │ ▼
183
+ ┌─────┴───────┐ FormValidator ┌─────────────────┐
184
+ │ Updated │ ◄─────────────────── │ Validation │
185
+ │ Object │ │ │
186
+ └─────────────┘ │ - HTML5 │
187
+ │ - Custom rules │
188
+ │ - FORM API │
189
+ │ components │
190
+ └─────────────────┘
191
+ ```
192
+
193
+ ### Form Component Support
194
+
195
+ The form utilities support both native HTML form elements and modern form-associated custom elements (those implementing the FORM API with `ElementInternals`). This means:
196
+
197
+ - **Native elements**: `<input>`, `<select>`, `<textarea>` work as expected
198
+ - **Custom components**: Web components like `<r-input>`, `<r-checkbox>`, `<r-select>` that use `ElementInternals` and `formAssociated = true` are fully integrated
199
+ - **No API differences**: Both types are handled identically by `setFormData()`, `readData()`, `mapFormToClass()`, and `FormValidator`
200
+
201
+ ## Template Rendering
202
+
203
+ ### Static Templates (html)
204
+
205
+ ```typescript
206
+ const template = html`
207
+ <div class="card">
208
+ <h2>${'title'}</h2>
209
+ <p>${'description'}</p>
210
+ </div>
211
+ `;
212
+
213
+ // Creates new DOM each time
214
+ const fragment = template({ title: 'Hello', description: 'World' });
215
+ container.appendChild(fragment);
216
+ ```
217
+
218
+ ### Updateable Templates (html)
219
+
220
+ ```typescript
221
+ const template = html`
222
+ <div class="user">
223
+ <span>{{name}}</span>
224
+ <span>{{score|number}}</span>
225
+ </div>
226
+ `;
227
+
228
+ const rendered = template({ name: 'John', score: 42 });
229
+ container.appendChild(rendered.fragment);
230
+
231
+ // Later, update without recreating DOM
232
+ rendered.update({ name: 'Jane', score: 100 });
233
+ ```
234
+
235
+ ## Service Architecture
236
+
237
+ ```
238
+ ┌────────────────────────────────────────────────────────┐
239
+ │ ServiceCollection │
240
+ │ │
241
+ │ Register services with metadata: │
242
+ │ - Constructor dependencies │
243
+ │ - Property injections │
244
+ │ - Scope (global/closest) │
245
+ └───────────────────────────┬────────────────────────────┘
246
+
247
+ │ Configuration
248
+
249
+ ┌────────────────────────────────────────────────────────┐
250
+ │ ServiceContainer │
251
+ │ │
252
+ │ Resolve services: │
253
+ │ 1. Check cache (for singletons) │
254
+ │ 2. Resolve dependencies │
255
+ │ 3. Create instance │
256
+ │ 4. Inject properties │
257
+ │ 5. Cache if global scope │
258
+ └────────────────────────────────────────────────────────┘
259
+ ```
260
+
261
+ ## File Organization
262
+
263
+ Recommended project structure:
264
+
265
+ ```
266
+ src/
267
+ ├── components/
268
+ │ ├── forms/ # Form-related components
269
+ │ ├── lists/ # List/table components
270
+ │ └── shared/ # Shared UI components
271
+ ├── pages/ # Route components
272
+ ├── services/ # Business logic services
273
+ ├── guards/ # Route guards
274
+ ├── models/ # TypeScript interfaces/types
275
+ └── app.ts # Application entry point
276
+ ```
277
+
278
+ ## Best Practices
279
+
280
+ 1. **Use native HTML when possible**: Don't create components for things HTML already does well
281
+
282
+ 2. **Keep components small**: Each component should do one thing
283
+
284
+ 3. **Form Components Use FORM API**: When building custom form components, use the HTML Form API with `ElementInternals` and `formAssociated = true`. All RelaxJS form utilities automatically support these components without any special handling:
285
+
286
+ ```typescript
287
+ class CustomCheckbox extends HTMLElement {
288
+ static formAssociated = true;
289
+
290
+ private internals: ElementInternals;
291
+
292
+ constructor() {
293
+ super();
294
+ this.internals = this.attachInternals();
295
+ }
296
+
297
+ connectedCallback() {
298
+ const checkbox = document.createElement('input');
299
+ checkbox.type = 'checkbox';
300
+ this.appendChild(checkbox);
301
+
302
+ checkbox.addEventListener('change', () => {
303
+ this.internals.setFormValue(checkbox.checked ? 'on' : '');
304
+ });
305
+ }
306
+
307
+ get checked() { return (this.querySelector('input') as HTMLInputElement).checked; }
308
+ set checked(v) { (this.querySelector('input') as HTMLInputElement).checked = v; }
309
+
310
+ get value() { return this.getAttribute('value') || 'on'; }
311
+ }
312
+
313
+ customElements.define('r-checkbox', CustomCheckbox);
314
+ ```
315
+
316
+ Once defined, use it seamlessly with form utilities:
317
+
318
+ ```typescript
319
+ const form = document.querySelector('form');
320
+ const data = { termsAccepted: true };
321
+ setFormData(form, data); // Works with <r-checkbox name="termsAccepted"></r-checkbox>
322
+
323
+ const extracted = readData(form); // Extracts values from custom components
324
+ const validator = new FormValidator(form); // Validates custom components
325
+ ```
326
+
327
+ 3. **Explicit over implicit**: Prefer explicit method calls over magic bindings
328
+
329
+ 4. **Type everything**: Use TypeScript interfaces for all data structures
330
+
331
+ 5. **CSS variables for theming**: Use semantic variable names
332
+
333
+ 6. **Form-associated components**: Use `ElementInternals` for custom form controls