amateras 0.5.0 → 0.7.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 (290) hide show
  1. package/README.md +23 -26
  2. package/index.ts +1 -0
  3. package/package.json +32 -27
  4. package/packages/core/package.json +32 -0
  5. package/packages/core/src/env.browser.ts +21 -0
  6. package/packages/core/src/env.node.ts +21 -0
  7. package/packages/core/src/global.ts +18 -0
  8. package/packages/core/src/index.ts +96 -0
  9. package/packages/core/src/lib/assignNodeProperties.ts +11 -0
  10. package/packages/core/src/lib/assignProperties.ts +57 -0
  11. package/packages/core/src/lib/chain.ts +17 -0
  12. package/packages/core/src/lib/dom.ts +20 -0
  13. package/packages/core/src/main.ts +4 -0
  14. package/{src → packages/core/src}/node/$Element.ts +25 -47
  15. package/packages/core/src/node/$EventTarget.ts +48 -0
  16. package/{src → packages/core/src}/node/$HTMLElement.ts +1 -1
  17. package/{src → packages/core/src}/node/$Node.ts +64 -73
  18. package/packages/core/src/node/$Virtual.ts +65 -0
  19. package/packages/css/package.json +17 -0
  20. package/{ext/css/src/lib → packages/css/src/ext}/colors/amber.ts +2 -2
  21. package/{ext/css/src/lib → packages/css/src/ext}/colors/blackwhite.ts +2 -2
  22. package/{ext/css/src/lib → packages/css/src/ext}/colors/blue.ts +2 -2
  23. package/{ext/css/src/lib → packages/css/src/ext}/colors/cyan.ts +2 -2
  24. package/{ext/css/src/lib → packages/css/src/ext}/colors/emerald.ts +2 -2
  25. package/{ext/css/src/lib → packages/css/src/ext}/colors/fuchsia.ts +2 -2
  26. package/{ext/css/src/lib → packages/css/src/ext}/colors/gray.ts +2 -2
  27. package/{ext/css/src/lib → packages/css/src/ext}/colors/green.ts +2 -2
  28. package/{ext/css/src/lib → packages/css/src/ext}/colors/indigo.ts +2 -2
  29. package/{ext/css/src/lib → packages/css/src/ext}/colors/lime.ts +2 -2
  30. package/{ext/css/src/lib → packages/css/src/ext}/colors/neutral.ts +2 -2
  31. package/{ext/css/src/lib → packages/css/src/ext}/colors/orange.ts +2 -2
  32. package/{ext/css/src/lib → packages/css/src/ext}/colors/pink.ts +2 -2
  33. package/{ext/css/src/lib → packages/css/src/ext}/colors/purple.ts +2 -2
  34. package/{ext/css/src/lib → packages/css/src/ext}/colors/red.ts +2 -2
  35. package/{ext/css/src/lib → packages/css/src/ext}/colors/rose.ts +2 -2
  36. package/{ext/css/src/lib → packages/css/src/ext}/colors/sky.ts +2 -2
  37. package/{ext/css/src/lib → packages/css/src/ext}/colors/slate.ts +2 -2
  38. package/{ext/css/src/lib → packages/css/src/ext}/colors/stone.ts +2 -2
  39. package/{ext/css/src/lib → packages/css/src/ext}/colors/teal.ts +2 -2
  40. package/{ext/css/src/lib → packages/css/src/ext}/colors/violet.ts +2 -2
  41. package/{ext/css/src/lib → packages/css/src/ext}/colors/yellow.ts +2 -2
  42. package/{ext/css/src/lib → packages/css/src/ext}/colors/zinc.ts +2 -2
  43. package/packages/css/src/ext/container.ts +32 -0
  44. package/packages/css/src/ext/keyframes.ts +54 -0
  45. package/packages/css/src/ext/media.ts +32 -0
  46. package/packages/css/src/ext/property.ts +48 -0
  47. package/packages/css/src/ext/variable.ts +51 -0
  48. package/{ext → packages}/css/src/index.ts +107 -183
  49. package/{ext → packages}/css/src/lib/colorAssign.ts +1 -1
  50. package/packages/css/src/lib/utils.ts +11 -0
  51. package/{ext → packages}/css/src/structure/$CSSContainerRule.ts +1 -1
  52. package/{ext → packages}/css/src/structure/$CSSKeyframesRule.ts +0 -1
  53. package/{ext → packages}/css/src/structure/$CSSMediaRule.ts +1 -1
  54. package/packages/css/src/structure/$CSSProperty.ts +19 -0
  55. package/{ext → packages}/css/src/structure/$CSSRule.ts +1 -1
  56. package/{ext → packages}/css/src/structure/$CSSStyleRule.ts +1 -1
  57. package/packages/css/src/structure/$CSSVariable.ts +30 -0
  58. package/packages/dom/package.json +20 -0
  59. package/packages/dom/src/lib/HTMLElementMap.ts +213 -0
  60. package/packages/dom/src/lib/assignAttributes.ts +16 -0
  61. package/packages/dom/src/structure/CSS.ts +7 -0
  62. package/packages/dom/src/structure/CSSStyleSheet.ts +10 -0
  63. package/packages/dom/src/structure/DOMTokenList.ts +19 -0
  64. package/packages/dom/src/structure/Document.ts +36 -0
  65. package/packages/dom/src/structure/Element.ts +106 -0
  66. package/packages/dom/src/structure/HTMLElement.ts +34 -0
  67. package/packages/dom/src/structure/History.ts +11 -0
  68. package/packages/dom/src/structure/Location.ts +9 -0
  69. package/packages/dom/src/structure/Node.ts +51 -0
  70. package/packages/dom/src/structure/NodeList.ts +10 -0
  71. package/packages/dom/src/structure/Storage.ts +8 -0
  72. package/packages/dom/src/structure/Text.ts +20 -0
  73. package/packages/dom/src/structure/Window.ts +14 -0
  74. package/packages/dom/src/structure/html/HTMLAbbrElement.ts +16 -0
  75. package/packages/dom/src/structure/html/HTMLAddressElement.ts +16 -0
  76. package/packages/dom/src/structure/html/HTMLAnchorElement.ts +25 -0
  77. package/packages/dom/src/structure/html/HTMLAreaElement.ts +26 -0
  78. package/packages/dom/src/structure/html/HTMLArticleElement.ts +16 -0
  79. package/packages/dom/src/structure/html/HTMLAsideElement.ts +16 -0
  80. package/packages/dom/src/structure/html/HTMLAudioElement.ts +16 -0
  81. package/packages/dom/src/structure/html/HTMLBDIElement.ts +16 -0
  82. package/packages/dom/src/structure/html/HTMLBDOElement.ts +16 -0
  83. package/packages/dom/src/structure/html/HTMLBElement.ts +16 -0
  84. package/packages/dom/src/structure/html/HTMLBRElement.ts +17 -0
  85. package/packages/dom/src/structure/html/HTMLBaseElement.ts +18 -0
  86. package/packages/dom/src/structure/html/HTMLBodyElement.ts +22 -0
  87. package/packages/dom/src/structure/html/HTMLButtonElement.ts +26 -0
  88. package/packages/dom/src/structure/html/HTMLCanvasElement.ts +18 -0
  89. package/packages/dom/src/structure/html/HTMLCiteElement.ts +16 -0
  90. package/packages/dom/src/structure/html/HTMLCodeElement.ts +16 -0
  91. package/packages/dom/src/structure/html/HTMLDDElement.ts +16 -0
  92. package/packages/dom/src/structure/html/HTMLDFNElement.ts +16 -0
  93. package/packages/dom/src/structure/html/HTMLDListElement.ts +17 -0
  94. package/packages/dom/src/structure/html/HTMLDTElement.ts +16 -0
  95. package/packages/dom/src/structure/html/HTMLDataElement.ts +17 -0
  96. package/packages/dom/src/structure/html/HTMLDataListElement.ts +16 -0
  97. package/packages/dom/src/structure/html/HTMLDetailsElement.ts +17 -0
  98. package/packages/dom/src/structure/html/HTMLDialogElement.ts +18 -0
  99. package/packages/dom/src/structure/html/HTMLDivElement.ts +17 -0
  100. package/packages/dom/src/structure/html/HTMLEMElement.ts +16 -0
  101. package/packages/dom/src/structure/html/HTMLEmbedElement.ts +20 -0
  102. package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +19 -0
  103. package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +16 -0
  104. package/packages/dom/src/structure/html/HTMLFigureElement.ts +16 -0
  105. package/packages/dom/src/structure/html/HTMLFooterElement.ts +16 -0
  106. package/packages/dom/src/structure/html/HTMLFormElement.ts +24 -0
  107. package/packages/dom/src/structure/html/HTMLHGroupElement.ts +16 -0
  108. package/packages/dom/src/structure/html/HTMLHRElement.ts +21 -0
  109. package/packages/dom/src/structure/html/HTMLHeadElement.ts +16 -0
  110. package/packages/dom/src/structure/html/HTMLHeaderElement.ts +16 -0
  111. package/packages/dom/src/structure/html/HTMLHeadingElement.ts +17 -0
  112. package/packages/dom/src/structure/html/HTMLHtmlElement.ts +18 -0
  113. package/packages/dom/src/structure/html/HTMLIElement.ts +16 -0
  114. package/packages/dom/src/structure/html/HTMLIFrameElement.ts +31 -0
  115. package/packages/dom/src/structure/html/HTMLImageElement.ts +38 -0
  116. package/packages/dom/src/structure/html/HTMLInputElement.ts +55 -0
  117. package/packages/dom/src/structure/html/HTMLKBDElement.ts +16 -0
  118. package/packages/dom/src/structure/html/HTMLLIElement.ts +18 -0
  119. package/packages/dom/src/structure/html/HTMLLabelElement.ts +18 -0
  120. package/packages/dom/src/structure/html/HTMLLegendElement.ts +17 -0
  121. package/packages/dom/src/structure/html/HTMLLinkElement.ts +31 -0
  122. package/packages/dom/src/structure/html/HTMLMainElement.ts +16 -0
  123. package/packages/dom/src/structure/html/HTMLMapElement.ts +17 -0
  124. package/packages/dom/src/structure/html/HTMLMarkElement.ts +16 -0
  125. package/packages/dom/src/structure/html/HTMLMediaElement.ts +48 -0
  126. package/packages/dom/src/structure/html/HTMLMenuElement.ts +18 -0
  127. package/packages/dom/src/structure/html/HTMLMetaElement.ts +22 -0
  128. package/packages/dom/src/structure/html/HTMLMeterElement.ts +23 -0
  129. package/packages/dom/src/structure/html/HTMLModElement.ts +18 -0
  130. package/packages/dom/src/structure/html/HTMLNavElement.ts +16 -0
  131. package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +16 -0
  132. package/packages/dom/src/structure/html/HTMLOListElement.ts +20 -0
  133. package/packages/dom/src/structure/html/HTMLObjectElement.ts +34 -0
  134. package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +18 -0
  135. package/packages/dom/src/structure/html/HTMLOptionElement.ts +20 -0
  136. package/packages/dom/src/structure/html/HTMLOutputElement.ts +20 -0
  137. package/packages/dom/src/structure/html/HTMLParagraphElement.ts +17 -0
  138. package/packages/dom/src/structure/html/HTMLPictureElement.ts +16 -0
  139. package/packages/dom/src/structure/html/HTMLPreElement.ts +17 -0
  140. package/packages/dom/src/structure/html/HTMLProgressElement.ts +19 -0
  141. package/packages/dom/src/structure/html/HTMLQuoteElement.ts +17 -0
  142. package/packages/dom/src/structure/html/HTMLRPElement.ts +16 -0
  143. package/packages/dom/src/structure/html/HTMLRTElement.ts +16 -0
  144. package/packages/dom/src/structure/html/HTMLRubyElement.ts +16 -0
  145. package/packages/dom/src/structure/html/HTMLSElement.ts +16 -0
  146. package/packages/dom/src/structure/html/HTMLSampElement.ts +16 -0
  147. package/packages/dom/src/structure/html/HTMLScriptElement.ts +27 -0
  148. package/packages/dom/src/structure/html/HTMLSectionElement.ts +16 -0
  149. package/packages/dom/src/structure/html/HTMLSelectElement.ts +27 -0
  150. package/packages/dom/src/structure/html/HTMLSlotElement.ts +17 -0
  151. package/packages/dom/src/structure/html/HTMLSmallElement.ts +16 -0
  152. package/packages/dom/src/structure/html/HTMLSourceElement.ts +21 -0
  153. package/packages/dom/src/structure/html/HTMLSpanElement.ts +16 -0
  154. package/packages/dom/src/structure/html/HTMLStrongElement.ts +16 -0
  155. package/packages/dom/src/structure/html/HTMLStyleElement.ts +18 -0
  156. package/packages/dom/src/structure/html/HTMLSubElement.ts +16 -0
  157. package/packages/dom/src/structure/html/HTMLSummaryElement.ts +16 -0
  158. package/packages/dom/src/structure/html/HTMLSupElement.ts +16 -0
  159. package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +17 -0
  160. package/packages/dom/src/structure/html/HTMLTableCellElement.ts +31 -0
  161. package/packages/dom/src/structure/html/HTMLTableColElement.ts +23 -0
  162. package/packages/dom/src/structure/html/HTMLTableElement.ts +26 -0
  163. package/packages/dom/src/structure/html/HTMLTableRowElement.ts +23 -0
  164. package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +20 -0
  165. package/packages/dom/src/structure/html/HTMLTemplateElement.ts +17 -0
  166. package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +33 -0
  167. package/packages/dom/src/structure/html/HTMLTimeElement.ts +17 -0
  168. package/packages/dom/src/structure/html/HTMLTitleElement.ts +17 -0
  169. package/packages/dom/src/structure/html/HTMLTrackElement.ts +21 -0
  170. package/packages/dom/src/structure/html/HTMLUElement.ts +16 -0
  171. package/packages/dom/src/structure/html/HTMLUListElement.ts +18 -0
  172. package/packages/dom/src/structure/html/HTMLVarElement.ts +16 -0
  173. package/packages/dom/src/structure/html/HTMLVideoElement.ts +22 -0
  174. package/packages/dom/src/structure/html/HTMLWBRElement.ts +16 -0
  175. package/packages/html/package.json +18 -0
  176. package/{ext/html/html.ts → packages/html/src/index.ts} +1 -1
  177. package/{ext/html → packages/html/src}/node/$Anchor.ts +4 -4
  178. package/packages/html/src/node/$Canvas.ts +38 -0
  179. package/{ext/html → packages/html/src}/node/$Dialog.ts +4 -4
  180. package/{ext/html → packages/html/src}/node/$Form.ts +4 -4
  181. package/{ext/html → packages/html/src}/node/$Image.ts +4 -4
  182. package/{ext/html → packages/html/src}/node/$Input.ts +4 -4
  183. package/{ext/html → packages/html/src}/node/$Label.ts +4 -4
  184. package/{ext/html → packages/html/src}/node/$Media.ts +4 -4
  185. package/{ext/html → packages/html/src}/node/$OptGroup.ts +4 -4
  186. package/{ext/html → packages/html/src}/node/$Option.ts +4 -4
  187. package/{ext/html → packages/html/src}/node/$Select.ts +4 -4
  188. package/{ext/html → packages/html/src}/node/$TextArea.ts +4 -4
  189. package/{ext → packages}/i18n/README.md +20 -0
  190. package/packages/i18n/package.json +19 -0
  191. package/packages/i18n/src/index.ts +140 -0
  192. package/{ext → packages}/i18n/src/structure/I18n.ts +12 -8
  193. package/{ext → packages}/i18n/src/structure/I18nDictionary.ts +1 -1
  194. package/packages/i18n/src/structure/I18nTranslation.ts +41 -0
  195. package/packages/idb/package.json +19 -0
  196. package/{ext → packages}/idb/src/index.ts +2 -2
  197. package/{ext → packages}/idb/src/lib/$IDBRequest.ts +1 -1
  198. package/{ext → packages}/idb/src/structure/$IDB.ts +1 -1
  199. package/{ext → packages}/idb/src/structure/$IDBCursor.ts +1 -1
  200. package/{ext → packages}/idb/src/structure/$IDBIndex.ts +1 -1
  201. package/{ext → packages}/idb/src/structure/$IDBStore.ts +1 -1
  202. package/{ext → packages}/idb/src/structure/$IDBStoreBase.ts +1 -1
  203. package/{ext → packages}/idb/src/structure/$IDBTransaction.ts +1 -1
  204. package/{ext → packages}/idb/src/structure/builder/$IDBBuilder.ts +9 -10
  205. package/{ext → packages}/idb/src/structure/builder/$IDBStoreBuilder.ts +1 -1
  206. package/packages/markdown/README.md +53 -0
  207. package/packages/markdown/package.json +19 -0
  208. package/packages/markdown/src/index.ts +3 -0
  209. package/packages/markdown/src/lib/type.ts +26 -0
  210. package/packages/markdown/src/lib/util.ts +21 -0
  211. package/packages/markdown/src/structure/Markdown.ts +54 -0
  212. package/packages/markdown/src/structure/MarkdownLexer.ts +111 -0
  213. package/packages/markdown/src/structure/MarkdownParser.ts +34 -0
  214. package/packages/markdown/src/syntax/alert.ts +46 -0
  215. package/packages/markdown/src/syntax/blockquote.ts +35 -0
  216. package/packages/markdown/src/syntax/bold.ts +11 -0
  217. package/packages/markdown/src/syntax/code.ts +11 -0
  218. package/packages/markdown/src/syntax/codeblock.ts +44 -0
  219. package/packages/markdown/src/syntax/heading.ts +14 -0
  220. package/packages/markdown/src/syntax/horizontalRule.ts +11 -0
  221. package/packages/markdown/src/syntax/image.ts +23 -0
  222. package/packages/markdown/src/syntax/italic.ts +11 -0
  223. package/packages/markdown/src/syntax/link.ts +46 -0
  224. package/packages/markdown/src/syntax/list.ts +121 -0
  225. package/packages/markdown/src/syntax/table.ts +67 -0
  226. package/packages/markdown/src/syntax/text.ts +19 -0
  227. package/packages/router/README.md +175 -0
  228. package/packages/router/package.json +19 -0
  229. package/packages/router/src/index.ts +68 -0
  230. package/packages/router/src/node/Page.ts +38 -0
  231. package/packages/router/src/node/Router.ts +212 -0
  232. package/{ext/router → packages/router/src}/node/RouterAnchor.ts +13 -2
  233. package/packages/router/src/structure/PageBuilder.ts +24 -0
  234. package/packages/router/src/structure/Route.ts +105 -0
  235. package/packages/signal/README.md +93 -0
  236. package/packages/signal/package.json +18 -0
  237. package/packages/signal/src/index.ts +221 -0
  238. package/{src → packages/signal/src}/structure/Signal.ts +6 -10
  239. package/packages/ssr/package.json +19 -0
  240. package/packages/ssr/src/index.ts +38 -0
  241. package/packages/ui/lib/VirtualScroll.ts +25 -0
  242. package/packages/ui/node/Accordian.ts +97 -0
  243. package/packages/ui/node/Carousel.ts +20 -0
  244. package/packages/ui/node/Form.ts +54 -0
  245. package/packages/ui/node/Grid.ts +0 -0
  246. package/packages/ui/node/Modal.ts +45 -0
  247. package/packages/ui/node/Table.ts +43 -0
  248. package/packages/ui/node/Tabs.ts +129 -0
  249. package/packages/ui/node/Toast.ts +16 -0
  250. package/packages/ui/node/Waterfall.ts +94 -0
  251. package/packages/ui/package.json +21 -0
  252. package/packages/utils/package.json +17 -0
  253. package/{src → packages/utils/src}/global.ts +9 -15
  254. package/packages/utils/src/index.ts +90 -0
  255. package/tsconfig.json +1 -1
  256. package/ext/css/package.json +0 -9
  257. package/ext/css/src/structure/$CSSVariable.ts +0 -12
  258. package/ext/html/node/$Canvas.ts +0 -16
  259. package/ext/i18n/package.json +0 -10
  260. package/ext/i18n/src/index.ts +0 -54
  261. package/ext/i18n/src/node/I18nText.ts +0 -35
  262. package/ext/idb/package.json +0 -13
  263. package/ext/markdown/index.ts +0 -121
  264. package/ext/markdown/package.json +0 -8
  265. package/ext/router/README.md +0 -81
  266. package/ext/router/index.ts +0 -73
  267. package/ext/router/node/Page.ts +0 -27
  268. package/ext/router/node/Route.ts +0 -54
  269. package/ext/router/node/Router.ts +0 -149
  270. package/ext/ssr/env.ts +0 -61
  271. package/ext/ssr/index.ts +0 -49
  272. package/ext/ssr/package.json +0 -10
  273. package/src/core.ts +0 -114
  274. package/src/index.ts +0 -3
  275. package/src/lib/assign.ts +0 -38
  276. package/src/lib/assignHelper.ts +0 -18
  277. package/src/lib/chain.ts +0 -13
  278. package/src/lib/debounce.ts +0 -7
  279. package/src/lib/env.ts +0 -2
  280. package/src/lib/native.ts +0 -40
  281. package/src/lib/randomId.ts +0 -9
  282. package/src/lib/sleep.ts +0 -3
  283. package/src/lib/toArray.ts +0 -9
  284. package/src/lib/trycatch.ts +0 -17
  285. package/src/node.ts +0 -10
  286. /package/{ext → packages}/css/README.md +0 -0
  287. /package/{ext/css/src/lib → packages/css/src/ext}/colors.ts +0 -0
  288. /package/{ext → packages}/css/src/structure/$CSSDeclaration.ts +0 -0
  289. /package/{ext → packages}/idb/README.md +0 -0
  290. /package/{ext → packages}/idb/src/core.ts +0 -0
@@ -0,0 +1,16 @@
1
+ import { assignAttributes } from "#lib/assignAttributes";
2
+ import { HTMLElement } from "#structure/HTMLElement";
3
+ import { _Object_assign } from "@amateras/utils";
4
+
5
+ export class HTMLUElement extends HTMLElement {
6
+ static defaultAttributes = {
7
+ ...HTMLElement.defaultAttributes
8
+ }
9
+
10
+ constructor() {
11
+ super('u')
12
+ }
13
+ }
14
+
15
+ assignAttributes(HTMLUElement, HTMLUElement.defaultAttributes)
16
+ _Object_assign(globalThis, { HTMLUElement })
@@ -0,0 +1,18 @@
1
+ import { assignAttributes } from "#lib/assignAttributes";
2
+ import { HTMLElement } from "#structure/HTMLElement";
3
+ import { _Object_assign } from "@amateras/utils";
4
+
5
+ export class HTMLUListElement extends HTMLElement {
6
+ static defaultAttributes = {
7
+ ...HTMLElement.defaultAttributes,
8
+ compact: false,
9
+ type: ''
10
+ }
11
+
12
+ constructor() {
13
+ super('ul')
14
+ }
15
+ }
16
+
17
+ assignAttributes(HTMLUListElement, HTMLUListElement.defaultAttributes)
18
+ _Object_assign(globalThis, { HTMLUListElement })
@@ -0,0 +1,16 @@
1
+ import { assignAttributes } from "#lib/assignAttributes";
2
+ import { HTMLElement } from "#structure/HTMLElement";
3
+ import { _Object_assign } from "@amateras/utils";
4
+
5
+ export class HTMLVarElement extends HTMLElement {
6
+ static defaultAttributes = {
7
+ ...HTMLElement.defaultAttributes
8
+ }
9
+
10
+ constructor() {
11
+ super('var')
12
+ }
13
+ }
14
+
15
+ assignAttributes(HTMLVarElement, HTMLVarElement.defaultAttributes)
16
+ _Object_assign(globalThis, { HTMLVarElement })
@@ -0,0 +1,22 @@
1
+ import { assignAttributes } from "#lib/assignAttributes";
2
+ import { HTMLMediaElement } from "#structure/html/HTMLMediaElement";
3
+ import { _Object_assign } from "@amateras/utils";
4
+
5
+ export class HTMLVideoElement extends HTMLMediaElement {
6
+ static defaultAttributes = {
7
+ ...HTMLMediaElement.defaultAttributes,
8
+ disablePictureInPicture: false,
9
+ height: '',
10
+ poster: '',
11
+ videoHeight: 0,
12
+ videoWidth: 0,
13
+ width: ''
14
+ }
15
+
16
+ constructor() {
17
+ super('video')
18
+ }
19
+ }
20
+
21
+ assignAttributes(HTMLVideoElement, HTMLVideoElement.defaultAttributes)
22
+ _Object_assign(globalThis, { HTMLVideoElement })
@@ -0,0 +1,16 @@
1
+ import { assignAttributes } from "#lib/assignAttributes";
2
+ import { HTMLElement } from "#structure/HTMLElement";
3
+ import { _Object_assign } from "@amateras/utils";
4
+
5
+ export class HTMLWBRElement extends HTMLElement {
6
+ static defaultAttributes = {
7
+ ...HTMLElement.defaultAttributes
8
+ }
9
+
10
+ constructor() {
11
+ super('wbr')
12
+ }
13
+ }
14
+
15
+ assignAttributes(HTMLWBRElement, HTMLWBRElement.defaultAttributes)
16
+ _Object_assign(globalThis, { HTMLWBRElement })
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@amateras/html",
3
+ "peerDependencies": {
4
+ "@amateras/core": "workspace:*",
5
+ "@amateras/utils": "workspace:*"
6
+ },
7
+ "imports": {
8
+ "#structure/*": "./src/structure/*.ts",
9
+ "#lib/*": "./src/lib/*.ts",
10
+ "#node/*": "./src/node/*.ts"
11
+ },
12
+ "exports": {
13
+ ".": "./src/index.ts",
14
+ "./structure/*": "./src/structure/*.ts",
15
+ "./lib/*": "./src/lib/*.ts",
16
+ "./node/*": "./src/node/*.ts"
17
+ }
18
+ }
@@ -1,4 +1,4 @@
1
- import '#core';
1
+ import '@amateras/core';
2
2
  import './node/$Anchor';
3
3
  import './node/$Dialog';
4
4
  import './node/$Form';
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Anchor extends $HTMLElement<HTMLAnchorElement> {
5
5
  constructor() {
@@ -42,8 +42,8 @@ export interface $Anchor extends $HTMLElement<HTMLAnchorElement> {
42
42
 
43
43
  export type AnchorTarget = '_self' | '_blank' | '_parent' | '_top' | '_unfenced_top' | '' | '_replace';
44
44
 
45
- declare module '#core' {
45
+ declare module '@amateras/core' {
46
46
  export function $(nodeName: 'a'): $Anchor
47
47
  }
48
48
 
49
- assignHelper(HTMLAnchorElement, $Anchor, 'a');
49
+ assignProperties(HTMLAnchorElement, $Anchor, 'a');
@@ -0,0 +1,38 @@
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
+
4
+ export class $Canvas extends $HTMLElement<HTMLCanvasElement> {
5
+ constructor() {
6
+ super('canvas');
7
+ }
8
+ }
9
+
10
+ export interface $Canvas extends $HTMLElement<HTMLCanvasElement> {
11
+ /** {@link HTMLCanvasElement.height} */
12
+ height(height: $Parameter<number>): this;
13
+ height(): number;
14
+ /** {@link HTMLCanvasElement.width} */
15
+ width(width: $Parameter<number>): this;
16
+ width(): number;
17
+
18
+ /** {@link HTMLCanvasElement.captureStream} */
19
+ captureStream(frameRequestRate?: number): MediaStream;
20
+ /** {@link HTMLCanvasElement.getContext} */
21
+ getContext(contextId: "2d", options?: CanvasRenderingContext2DSettings): CanvasRenderingContext2D | null;
22
+ getContext(contextId: "bitmaprenderer", options?: ImageBitmapRenderingContextSettings): ImageBitmapRenderingContext | null;
23
+ getContext(contextId: "webgl", options?: WebGLContextAttributes): WebGLRenderingContext | null;
24
+ getContext(contextId: "webgl2", options?: WebGLContextAttributes): WebGL2RenderingContext | null;
25
+ getContext(contextId: string, options?: any): RenderingContext | null;
26
+ /** {@link HTMLCanvasElement.toBlob} */
27
+ toBlob(callback: BlobCallback, type?: string, quality?: number): this;
28
+ /** {@link HTMLCanvasElement.toDataURL} */
29
+ toDataURL(type?: string, quality?: number): string;
30
+ /** {@link HTMLCanvasElement.transferControlToOffscreen} */
31
+ transferControlToOffscreen(): OffscreenCanvas;
32
+ }
33
+
34
+ assignProperties(HTMLCanvasElement, $Canvas, 'canvas');
35
+
36
+ declare module "@amateras/core" {
37
+ export function $(nodeName: 'canvas'): $Canvas
38
+ }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Dialog extends $HTMLElement<HTMLDialogElement> {
5
5
  constructor() {
@@ -9,8 +9,8 @@ export class $Dialog extends $HTMLElement<HTMLDialogElement> {
9
9
 
10
10
  export interface $Dialog extends $HTMLElement<HTMLDialogElement> {}
11
11
 
12
- assignHelper(HTMLDialogElement, $Dialog, 'dialog');
12
+ assignProperties(HTMLDialogElement, $Dialog, 'dialog');
13
13
 
14
- declare module '#core' {
14
+ declare module "@amateras/core" {
15
15
  export function $(nodeName: 'dialog'): $Dialog
16
16
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Form extends $HTMLElement<HTMLFormElement> {
5
5
  constructor() {
@@ -9,8 +9,8 @@ export class $Form extends $HTMLElement<HTMLFormElement> {
9
9
 
10
10
  export interface $Form extends $HTMLElement<HTMLFormElement> {}
11
11
 
12
- assignHelper(HTMLFormElement, $Form, 'form');
12
+ assignProperties(HTMLFormElement, $Form, 'form');
13
13
 
14
- declare module '#core' {
14
+ declare module "@amateras/core" {
15
15
  export function $(nodeName: 'form'): $Form
16
16
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Image extends $HTMLElement<HTMLImageElement> {
5
5
  constructor() {
@@ -65,8 +65,8 @@ export interface $Image extends $HTMLElement<HTMLImageElement> {
65
65
  width(): number;
66
66
  }
67
67
 
68
- assignHelper(HTMLImageElement, $Image, 'img');
68
+ assignProperties(HTMLImageElement, $Image, 'img');
69
69
 
70
- declare module '#core' {
70
+ declare module "@amateras/core" {
71
71
  export function $(nodeName: 'img'): $Image
72
72
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Input extends $HTMLElement<HTMLInputElement> {
5
5
  constructor() {
@@ -186,8 +186,8 @@ export type InputType =
186
186
  | 'url'
187
187
  | 'week';
188
188
 
189
- assignHelper(HTMLInputElement, $Input, 'input');
189
+ assignProperties(HTMLInputElement, $Input, 'input');
190
190
 
191
- declare module '#core' {
191
+ declare module "@amateras/core" {
192
192
  export function $(nodeName: 'input'): $Input
193
193
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Label extends $HTMLElement<HTMLLabelElement> {
5
5
  constructor() {
@@ -18,8 +18,8 @@ export interface $Label extends $HTMLElement<HTMLLabelElement> {
18
18
  htmlFor(): string;
19
19
  }
20
20
 
21
- assignHelper(HTMLLabelElement, $Label, 'label');
21
+ assignProperties(HTMLLabelElement, $Label, 'label');
22
22
 
23
- declare module '#core' {
23
+ declare module "@amateras/core" {
24
24
  export function $(nodeName: 'label'): $Label
25
25
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Media extends $HTMLElement<HTMLMediaElement> {
5
5
  constructor() {
@@ -9,8 +9,8 @@ export class $Media extends $HTMLElement<HTMLMediaElement> {
9
9
 
10
10
  export interface $Media extends $HTMLElement<HTMLMediaElement> {}
11
11
 
12
- assignHelper(HTMLMediaElement, $Media, 'media');
12
+ assignProperties(HTMLMediaElement, $Media, 'media');
13
13
 
14
- declare module '#core' {
14
+ declare module "@amateras/core" {
15
15
  export function $(nodeName: 'media'): $Media
16
16
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $OptGroup extends $HTMLElement<HTMLOptGroupElement> {
5
5
  constructor() {
@@ -16,8 +16,8 @@ export interface $OptGroup extends $HTMLElement<HTMLOptGroupElement> {
16
16
  label(): string;
17
17
  }
18
18
 
19
- assignHelper(HTMLOptGroupElement, $OptGroup, 'optgroup');
19
+ assignProperties(HTMLOptGroupElement, $OptGroup, 'optgroup');
20
20
 
21
- declare module '#core' {
21
+ declare module "@amateras/core" {
22
22
  export function $(nodeName: 'optgroup'): $OptGroup
23
23
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Option extends $HTMLElement<HTMLOptionElement> {
5
5
  constructor() {
@@ -33,8 +33,8 @@ export interface $Option extends $HTMLElement<HTMLOptionElement> {
33
33
  value(): string;
34
34
  }
35
35
 
36
- assignHelper(HTMLOptionElement, $Option, 'option');
36
+ assignProperties(HTMLOptionElement, $Option, 'option');
37
37
 
38
- declare module '#core' {
38
+ declare module "@amateras/core" {
39
39
  export function $(nodeName: 'option'): $Option
40
40
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $Select extends $HTMLElement<HTMLSelectElement> {
5
5
  constructor() {
@@ -69,8 +69,8 @@ export interface $Select extends $HTMLElement<HTMLSelectElement> {
69
69
  showPicker(): this;
70
70
  }
71
71
 
72
- assignHelper(HTMLSelectElement, $Select, 'select');
72
+ assignProperties(HTMLSelectElement, $Select, 'select');
73
73
 
74
- declare module '#core' {
74
+ declare module "@amateras/core" {
75
75
  export function $(nodeName: 'select'): $Select
76
76
  }
@@ -1,5 +1,5 @@
1
- import { assignHelper } from "#lib/assignHelper";
2
- import { $HTMLElement } from "#node/$HTMLElement";
1
+ import { assignProperties } from "@amateras/core/lib/assignProperties";
2
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
3
 
4
4
  export class $TextArea extends $HTMLElement<HTMLTextAreaElement> {
5
5
  constructor() {
@@ -9,8 +9,8 @@ export class $TextArea extends $HTMLElement<HTMLTextAreaElement> {
9
9
 
10
10
  export interface $TextArea extends $HTMLElement<HTMLTextAreaElement> {}
11
11
 
12
- assignHelper(HTMLTextAreaElement, $TextArea, 'textarea');
12
+ assignProperties(HTMLTextAreaElement, $TextArea, 'textarea');
13
13
 
14
- declare module '#core' {
14
+ declare module "@amateras/core" {
15
15
  export function $(nodeName: 'textarea'): $TextArea
16
16
  }
@@ -50,4 +50,24 @@ const $t = $.i18n()
50
50
  // set 'zh' as locale language
51
51
  // and fetch file automatically from path
52
52
  .locale('zh');
53
+ ```
54
+
55
+ ## Directory Shortcut
56
+
57
+ ```ts
58
+ const $t = $.i18n('en')
59
+ .add('en', {
60
+ page1: {
61
+ section2: {
62
+ button3: {
63
+ text: 'Too deep!'
64
+ }
65
+ }
66
+ }
67
+ })
68
+
69
+ const $t_button = $t.dir('page1.section2.button3');
70
+
71
+ $t_button('text') // Too deep!
72
+ $t('page1.section2.button3.text') // Too deep!
53
73
  ```
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@amateras/i18n",
3
+ "peerDependencies": {
4
+ "@amateras/core": "workspace:*",
5
+ "@amateras/signal": "workspace:*",
6
+ "@amateras/utils": "workspace:*"
7
+ },
8
+ "imports": {
9
+ "#structure/*": "./src/structure/*.ts",
10
+ "#lib/*": "./src/lib/*.ts",
11
+ "#node/*": "./src/node/*.ts"
12
+ },
13
+ "exports": {
14
+ ".": "./src/index.ts",
15
+ "./structure/*": "./src/structure/*.ts",
16
+ "./lib/*": "./src/lib/*.ts",
17
+ "./node/*": "./src/node/*.ts"
18
+ }
19
+ }
@@ -0,0 +1,140 @@
1
+ import "@amateras/core"
2
+ import { _Array_from, _instanceof, _Object_assign } from "@amateras/utils"
3
+ import { I18n } from "#structure/I18n"
4
+ import { I18nDictionary, type I18nDictionaryContext, type I18nDictionaryContextImporter } from "#structure/I18nDictionary";
5
+ import { $Node, type $NodeContentResolver } from "@amateras/core/node/$Node";
6
+ import { I18nTranslation as _I18nTranslation, I18nTranslation, type I18nTranslationOptions } from "#structure/I18nTranslation";
7
+
8
+ $Node.setters.add((value, set) => {
9
+ if (_instanceof(value, _I18nTranslation)) {
10
+ value.content$.signal.subscribe(set);
11
+ return value.content$.value();
12
+ }
13
+ })
14
+
15
+ _Object_assign($, {
16
+ i18n(defaultLocale: string) {
17
+ const i18n = new I18n(defaultLocale);
18
+ const i18nFn = (key: string, options?: I18nTranslationOptions) => i18n.translate(key, options);
19
+ _Object_assign(i18nFn, {
20
+ i18n,
21
+ locale(locale: string) {
22
+ if (!arguments.length) return i18n.locale();
23
+ i18n.locale(locale);
24
+ return this;
25
+ },
26
+ add(lang: string, context: I18nDictionaryContext | I18nDictionaryContextImporter) {
27
+ i18n.map.set(lang, new I18nDictionary(context));
28
+ return this;
29
+ },
30
+ delete(lang: string) {
31
+ i18n.map.delete(lang);
32
+ return this;
33
+ },
34
+ dir(path: string) {
35
+ return (key: string, options?: I18nTranslationOptions) => i18n.translate(`${path}.${key}`, options)
36
+ }
37
+ })
38
+ return i18nFn
39
+ }
40
+ })
41
+
42
+ type ResolvedAsyncDictionary<F extends I18nDictionaryContextImporter> = Awaited<ReturnType<F>>['default'];
43
+
44
+ type I18nTranslationKey<T> =
45
+ T extends I18nDictionaryContext
46
+ ? {
47
+ [K in keyof T]: K extends string
48
+ ? K extends '_'
49
+ ? never
50
+ : T[K] extends string
51
+ ? `${K}`
52
+ : '_' extends keyof T[K]
53
+ ? `${K}` | `${K}.${I18nTranslationKey<T[K]>}`
54
+ : `${K}.${I18nTranslationKey<T[K]>}`
55
+ : never;
56
+ }[keyof T]
57
+ : never;
58
+
59
+ type I18nTranslationDirKey<T> =
60
+ T extends I18nDictionaryContext
61
+ ? {
62
+ [K in keyof T]: K extends string
63
+ ? T[K] extends string
64
+ ? never
65
+ : `${K}` | `${K}.${I18nTranslationDirKey<T[K]>}`
66
+ : never;
67
+ }[keyof T]
68
+ : never;
69
+
70
+ type I18nTranslationParams<K extends string, T extends I18nDictionaryContext> =
71
+ FindTranslationByKey<K, T> extends infer O
72
+ ? O extends string
73
+ ? FindParam<O>
74
+ : never
75
+ : never
76
+
77
+ type FindParam<T extends string> =
78
+ T extends `${string}$${infer Param}$${infer Rest}`
79
+ ? Param extends `${string}${' '}${string}`
80
+ ? Prettify<{} & FindParam<Rest>>
81
+ : Prettify<Record<Param, $NodeContentResolver<I18nTranslation>> & FindParam<Rest>>
82
+ : {}
83
+
84
+ type FindTranslationByKey<K extends string, T extends I18nDictionaryContext> =
85
+ K extends `${infer Prefix}.${infer Rest}`
86
+ ? Prefix extends keyof T
87
+ ? T[Prefix] extends I18nDictionaryContext
88
+ ? FindTranslationByKey<Rest, T[Prefix]>
89
+ : T[Prefix]
90
+ : ''
91
+ : T[K] extends object
92
+ ? '_' extends keyof T[K]
93
+ ? T[K]['_']
94
+ : never
95
+ : T[K]
96
+
97
+ type GetDictionaryContextByKey<K extends string, T extends I18nDictionaryContext> =
98
+ K extends `${infer Prefix}.${infer Rest}`
99
+ ? Prefix extends keyof T
100
+ ? T[Prefix] extends I18nDictionaryContext
101
+ ? GetDictionaryContextByKey<Rest, T[Prefix]>
102
+ : never
103
+ : never
104
+ : T[K] extends object
105
+ ? T[K]
106
+ : never
107
+
108
+ type Mixin<A, B> =
109
+ (Omit<A, keyof B> & Omit<B, keyof A>) & {
110
+ [key in (keyof A & keyof B)]:
111
+ A[key] extends object
112
+ ? B[key] extends object
113
+ ? Mixin<A[key], B[key]>
114
+ : A[key] | B[key]
115
+ : A[key] | B[key]
116
+ }
117
+
118
+ declare module "@amateras/core" {
119
+ export namespace $ {
120
+ export interface I18nFunction<D extends I18nDictionaryContext = {}> {
121
+ <K extends I18nTranslationKey<D>, P extends I18nTranslationParams<K, D>>(path: K, ...params: P extends Record<string, never> ? [] : [P]): I18nTranslation;
122
+ i18n: I18n;
123
+ locale(): string;
124
+ locale(lang?: $Parameter<string>): this;
125
+ add<F extends I18nDictionaryContext | I18nDictionaryContextImporter>(lang: string, dictionary: F): I18nFunction<Mixin<D, (F extends I18nDictionaryContextImporter ? ResolvedAsyncDictionary<F> : F)>>;
126
+ delete(lang: string): this;
127
+ dir<K extends I18nTranslationDirKey<D>>(path: K): I18nFunction<GetDictionaryContextByKey<K, D>>
128
+ }
129
+ export function i18n(defaultLocale: string): I18nFunction;
130
+ export type I18nTranslation = _I18nTranslation;
131
+
132
+ export interface $NodeContentMap {
133
+ i18n: I18nTranslation
134
+ }
135
+
136
+ export interface $NodeParameterMap<T> {
137
+ i18n: I18nTranslation
138
+ }
139
+ }
140
+ }
@@ -1,6 +1,7 @@
1
- import { _instanceof } from "amateras/lib/native";
2
- import { I18nText, type I18nTextOptions } from "#node/I18nText";
1
+ import '@amateras/signal';
2
+ import { _instanceof, _null } from "@amateras/utils";
3
3
  import { I18nDictionary } from "#structure/I18nDictionary";
4
+ import { I18nTranslation, type I18nTranslationOptions } from "./I18nTranslation";
4
5
 
5
6
  export class I18n {
6
7
  locale$ = $.signal<string>('');
@@ -22,19 +23,22 @@ export class I18n {
22
23
  locale(): string;
23
24
  locale(locale: string): this;
24
25
  locale(locale?: string) {
25
- if (!arguments.length) return this.locale$();
26
- if (locale) this.locale$.set(locale)
26
+ if (!arguments.length) return this.locale$.value();
27
+ if (locale) {
28
+ if (!this.map.has(locale)) locale = locale.split('-')[0]!;
29
+ if (this.map.has(locale)) this.locale$.set(locale)
30
+ }
27
31
  return this;
28
32
  }
29
33
 
30
- dictionary(locale = this.locale$()) {
31
- if (!locale) return null;
34
+ dictionary(locale = this.locale$.value()) {
35
+ if (!locale) return _null;
32
36
  const dictionary = this.map.get(locale);
33
37
  return dictionary;
34
38
  }
35
39
 
36
- translate(key: string, options?: I18nTextOptions) {
37
- return new I18nText(this, key, options);
40
+ translate(key: string, options?: I18nTranslationOptions) {
41
+ return new I18nTranslation(this, key, options);
38
42
  }
39
43
  }
40
44
 
@@ -1,4 +1,4 @@
1
- import { _instanceof, isFunction, isObject } from "amateras/lib/native";
1
+ import { _instanceof, isFunction, isObject } from "@amateras/utils";
2
2
 
3
3
  export class I18nDictionary {
4
4
  #context: I18nDictionaryContext | Promise<I18nDictionaryContext> | null = null;
@@ -0,0 +1,41 @@
1
+ import { _Array_from, _null, isUndefined } from "@amateras/utils";
2
+ import type { I18n } from "#structure/I18n";
3
+ import { $Node, type $NodeContentResolver, type $NodeContentTypes } from "@amateras/core/node/$Node";
4
+ import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
5
+
6
+ export class I18nTranslation extends $HTMLElement {
7
+ i18n: I18n;
8
+ key: string;
9
+ options: I18nTranslationOptions | undefined;
10
+ content$ = $.signal('');
11
+ constructor(i18n: I18n, key: string, options?: I18nTranslationOptions) {
12
+ super('t')
13
+ this.i18n = i18n;
14
+ this.key = key;
15
+ this.options = options;
16
+ i18n.locale$.signal.subscribe(() => this.update())
17
+ this.update();
18
+ }
19
+
20
+ async update() {
21
+ const {key, i18n, options} = this;
22
+ const contentUpdate = (content: $NodeContentResolver<this>) => {
23
+ this.content(content);
24
+ this.content$.set(this.textContent() ?? '')
25
+ }
26
+ update: {
27
+ const dictionary = i18n.dictionary();
28
+ if (!dictionary) { contentUpdate(key); break update }
29
+ const target = await dictionary.find(key);
30
+ if (isUndefined(target)) break update;
31
+ const snippets = target.split(/\$[a-zA-Z0-9_]+\$/);
32
+ if (snippets.length === 1 || !options) { contentUpdate(target); break update }
33
+ const matches = target.matchAll(/(\$([a-zA-Z0-9_]+)\$)/g);
34
+ const content = snippets.map(text => [text, options[matches.next().value?.at(2)!] ?? null]).flat();
35
+ contentUpdate(content);
36
+ }
37
+ return this;
38
+ }
39
+ }
40
+
41
+ export type I18nTranslationOptions = {[key: string]: any}