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.
- package/README.md +23 -26
- package/index.ts +1 -0
- package/package.json +32 -27
- package/packages/core/package.json +32 -0
- package/packages/core/src/env.browser.ts +21 -0
- package/packages/core/src/env.node.ts +21 -0
- package/packages/core/src/global.ts +18 -0
- package/packages/core/src/index.ts +96 -0
- package/packages/core/src/lib/assignNodeProperties.ts +11 -0
- package/packages/core/src/lib/assignProperties.ts +57 -0
- package/packages/core/src/lib/chain.ts +17 -0
- package/packages/core/src/lib/dom.ts +20 -0
- package/packages/core/src/main.ts +4 -0
- package/{src → packages/core/src}/node/$Element.ts +25 -47
- package/packages/core/src/node/$EventTarget.ts +48 -0
- package/{src → packages/core/src}/node/$HTMLElement.ts +1 -1
- package/{src → packages/core/src}/node/$Node.ts +64 -73
- package/packages/core/src/node/$Virtual.ts +65 -0
- package/packages/css/package.json +17 -0
- package/{ext/css/src/lib → packages/css/src/ext}/colors/amber.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blackwhite.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blue.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/cyan.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/emerald.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/fuchsia.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/gray.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/green.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/indigo.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/lime.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/neutral.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/orange.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/pink.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/purple.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/red.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/rose.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/sky.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/slate.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/stone.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/teal.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/violet.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/yellow.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/zinc.ts +2 -2
- package/packages/css/src/ext/container.ts +32 -0
- package/packages/css/src/ext/keyframes.ts +54 -0
- package/packages/css/src/ext/media.ts +32 -0
- package/packages/css/src/ext/property.ts +48 -0
- package/packages/css/src/ext/variable.ts +51 -0
- package/{ext → packages}/css/src/index.ts +107 -183
- package/{ext → packages}/css/src/lib/colorAssign.ts +1 -1
- package/packages/css/src/lib/utils.ts +11 -0
- package/{ext → packages}/css/src/structure/$CSSContainerRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSKeyframesRule.ts +0 -1
- package/{ext → packages}/css/src/structure/$CSSMediaRule.ts +1 -1
- package/packages/css/src/structure/$CSSProperty.ts +19 -0
- package/{ext → packages}/css/src/structure/$CSSRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSStyleRule.ts +1 -1
- package/packages/css/src/structure/$CSSVariable.ts +30 -0
- package/packages/dom/package.json +20 -0
- package/packages/dom/src/lib/HTMLElementMap.ts +213 -0
- package/packages/dom/src/lib/assignAttributes.ts +16 -0
- package/packages/dom/src/structure/CSS.ts +7 -0
- package/packages/dom/src/structure/CSSStyleSheet.ts +10 -0
- package/packages/dom/src/structure/DOMTokenList.ts +19 -0
- package/packages/dom/src/structure/Document.ts +36 -0
- package/packages/dom/src/structure/Element.ts +106 -0
- package/packages/dom/src/structure/HTMLElement.ts +34 -0
- package/packages/dom/src/structure/History.ts +11 -0
- package/packages/dom/src/structure/Location.ts +9 -0
- package/packages/dom/src/structure/Node.ts +51 -0
- package/packages/dom/src/structure/NodeList.ts +10 -0
- package/packages/dom/src/structure/Storage.ts +8 -0
- package/packages/dom/src/structure/Text.ts +20 -0
- package/packages/dom/src/structure/Window.ts +14 -0
- package/packages/dom/src/structure/html/HTMLAbbrElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAddressElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAnchorElement.ts +25 -0
- package/packages/dom/src/structure/html/HTMLAreaElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLArticleElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAsideElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAudioElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDOElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBRElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLBaseElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLBodyElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLButtonElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLCanvasElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLCiteElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLCodeElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDFNElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDListElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDataElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDataListElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDetailsElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDialogElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLDivElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLEMElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLEmbedElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFigureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFooterElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFormElement.ts +24 -0
- package/packages/dom/src/structure/html/HTMLHGroupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHRElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLHeadElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeaderElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeadingElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLHtmlElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLIFrameElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLImageElement.ts +38 -0
- package/packages/dom/src/structure/html/HTMLInputElement.ts +55 -0
- package/packages/dom/src/structure/html/HTMLKBDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLLIElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLabelElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLegendElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLLinkElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLMainElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMapElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLMarkElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMediaElement.ts +48 -0
- package/packages/dom/src/structure/html/HTMLMenuElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLMetaElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLMeterElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLModElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLNavElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLOListElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLObjectElement.ts +34 -0
- package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLOptionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLOutputElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLParagraphElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLPictureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLPreElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLProgressElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLQuoteElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLRPElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRubyElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSampElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLScriptElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSectionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSelectElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSlotElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLSmallElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSourceElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLSpanElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStrongElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStyleElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLSubElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSummaryElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTableCellElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLTableColElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLTableRowElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLTemplateElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +33 -0
- package/packages/dom/src/structure/html/HTMLTimeElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTitleElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTrackElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLUElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLUListElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLVarElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLVideoElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLWBRElement.ts +16 -0
- package/packages/html/package.json +18 -0
- package/{ext/html/html.ts → packages/html/src/index.ts} +1 -1
- package/{ext/html → packages/html/src}/node/$Anchor.ts +4 -4
- package/packages/html/src/node/$Canvas.ts +38 -0
- package/{ext/html → packages/html/src}/node/$Dialog.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Form.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Image.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Input.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Label.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Media.ts +4 -4
- package/{ext/html → packages/html/src}/node/$OptGroup.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Option.ts +4 -4
- package/{ext/html → packages/html/src}/node/$Select.ts +4 -4
- package/{ext/html → packages/html/src}/node/$TextArea.ts +4 -4
- package/{ext → packages}/i18n/README.md +20 -0
- package/packages/i18n/package.json +19 -0
- package/packages/i18n/src/index.ts +140 -0
- package/{ext → packages}/i18n/src/structure/I18n.ts +12 -8
- package/{ext → packages}/i18n/src/structure/I18nDictionary.ts +1 -1
- package/packages/i18n/src/structure/I18nTranslation.ts +41 -0
- package/packages/idb/package.json +19 -0
- package/{ext → packages}/idb/src/index.ts +2 -2
- package/{ext → packages}/idb/src/lib/$IDBRequest.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDB.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBCursor.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBIndex.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStore.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStoreBase.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBTransaction.ts +1 -1
- package/{ext → packages}/idb/src/structure/builder/$IDBBuilder.ts +9 -10
- package/{ext → packages}/idb/src/structure/builder/$IDBStoreBuilder.ts +1 -1
- package/packages/markdown/README.md +53 -0
- package/packages/markdown/package.json +19 -0
- package/packages/markdown/src/index.ts +3 -0
- package/packages/markdown/src/lib/type.ts +26 -0
- package/packages/markdown/src/lib/util.ts +21 -0
- package/packages/markdown/src/structure/Markdown.ts +54 -0
- package/packages/markdown/src/structure/MarkdownLexer.ts +111 -0
- package/packages/markdown/src/structure/MarkdownParser.ts +34 -0
- package/packages/markdown/src/syntax/alert.ts +46 -0
- package/packages/markdown/src/syntax/blockquote.ts +35 -0
- package/packages/markdown/src/syntax/bold.ts +11 -0
- package/packages/markdown/src/syntax/code.ts +11 -0
- package/packages/markdown/src/syntax/codeblock.ts +44 -0
- package/packages/markdown/src/syntax/heading.ts +14 -0
- package/packages/markdown/src/syntax/horizontalRule.ts +11 -0
- package/packages/markdown/src/syntax/image.ts +23 -0
- package/packages/markdown/src/syntax/italic.ts +11 -0
- package/packages/markdown/src/syntax/link.ts +46 -0
- package/packages/markdown/src/syntax/list.ts +121 -0
- package/packages/markdown/src/syntax/table.ts +67 -0
- package/packages/markdown/src/syntax/text.ts +19 -0
- package/packages/router/README.md +175 -0
- package/packages/router/package.json +19 -0
- package/packages/router/src/index.ts +68 -0
- package/packages/router/src/node/Page.ts +38 -0
- package/packages/router/src/node/Router.ts +212 -0
- package/{ext/router → packages/router/src}/node/RouterAnchor.ts +13 -2
- package/packages/router/src/structure/PageBuilder.ts +24 -0
- package/packages/router/src/structure/Route.ts +105 -0
- package/packages/signal/README.md +93 -0
- package/packages/signal/package.json +18 -0
- package/packages/signal/src/index.ts +221 -0
- package/{src → packages/signal/src}/structure/Signal.ts +6 -10
- package/packages/ssr/package.json +19 -0
- package/packages/ssr/src/index.ts +38 -0
- package/packages/ui/lib/VirtualScroll.ts +25 -0
- package/packages/ui/node/Accordian.ts +97 -0
- package/packages/ui/node/Carousel.ts +20 -0
- package/packages/ui/node/Form.ts +54 -0
- package/packages/ui/node/Grid.ts +0 -0
- package/packages/ui/node/Modal.ts +45 -0
- package/packages/ui/node/Table.ts +43 -0
- package/packages/ui/node/Tabs.ts +129 -0
- package/packages/ui/node/Toast.ts +16 -0
- package/packages/ui/node/Waterfall.ts +94 -0
- package/packages/ui/package.json +21 -0
- package/packages/utils/package.json +17 -0
- package/{src → packages/utils/src}/global.ts +9 -15
- package/packages/utils/src/index.ts +90 -0
- package/tsconfig.json +1 -1
- package/ext/css/package.json +0 -9
- package/ext/css/src/structure/$CSSVariable.ts +0 -12
- package/ext/html/node/$Canvas.ts +0 -16
- package/ext/i18n/package.json +0 -10
- package/ext/i18n/src/index.ts +0 -54
- package/ext/i18n/src/node/I18nText.ts +0 -35
- package/ext/idb/package.json +0 -13
- package/ext/markdown/index.ts +0 -121
- package/ext/markdown/package.json +0 -8
- package/ext/router/README.md +0 -81
- package/ext/router/index.ts +0 -73
- package/ext/router/node/Page.ts +0 -27
- package/ext/router/node/Route.ts +0 -54
- package/ext/router/node/Router.ts +0 -149
- package/ext/ssr/env.ts +0 -61
- package/ext/ssr/index.ts +0 -49
- package/ext/ssr/package.json +0 -10
- package/src/core.ts +0 -114
- package/src/index.ts +0 -3
- package/src/lib/assign.ts +0 -38
- package/src/lib/assignHelper.ts +0 -18
- package/src/lib/chain.ts +0 -13
- package/src/lib/debounce.ts +0 -7
- package/src/lib/env.ts +0 -2
- package/src/lib/native.ts +0 -40
- package/src/lib/randomId.ts +0 -9
- package/src/lib/sleep.ts +0 -3
- package/src/lib/toArray.ts +0 -9
- package/src/lib/trycatch.ts +0 -17
- package/src/node.ts +0 -10
- /package/{ext → packages}/css/README.md +0 -0
- /package/{ext/css/src/lib → packages/css/src/ext}/colors.ts +0 -0
- /package/{ext → packages}/css/src/structure/$CSSDeclaration.ts +0 -0
- /package/{ext → packages}/idb/README.md +0 -0
- /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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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 '
|
|
45
|
+
declare module '@amateras/core' {
|
|
46
46
|
export function $(nodeName: 'a'): $Anchor
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
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 {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
12
|
+
assignProperties(HTMLDialogElement, $Dialog, 'dialog');
|
|
13
13
|
|
|
14
|
-
declare module
|
|
14
|
+
declare module "@amateras/core" {
|
|
15
15
|
export function $(nodeName: 'dialog'): $Dialog
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
12
|
+
assignProperties(HTMLFormElement, $Form, 'form');
|
|
13
13
|
|
|
14
|
-
declare module
|
|
14
|
+
declare module "@amateras/core" {
|
|
15
15
|
export function $(nodeName: 'form'): $Form
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
68
|
+
assignProperties(HTMLImageElement, $Image, 'img');
|
|
69
69
|
|
|
70
|
-
declare module
|
|
70
|
+
declare module "@amateras/core" {
|
|
71
71
|
export function $(nodeName: 'img'): $Image
|
|
72
72
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
189
|
+
assignProperties(HTMLInputElement, $Input, 'input');
|
|
190
190
|
|
|
191
|
-
declare module
|
|
191
|
+
declare module "@amateras/core" {
|
|
192
192
|
export function $(nodeName: 'input'): $Input
|
|
193
193
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
21
|
+
assignProperties(HTMLLabelElement, $Label, 'label');
|
|
22
22
|
|
|
23
|
-
declare module
|
|
23
|
+
declare module "@amateras/core" {
|
|
24
24
|
export function $(nodeName: 'label'): $Label
|
|
25
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
12
|
+
assignProperties(HTMLMediaElement, $Media, 'media');
|
|
13
13
|
|
|
14
|
-
declare module
|
|
14
|
+
declare module "@amateras/core" {
|
|
15
15
|
export function $(nodeName: 'media'): $Media
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
19
|
+
assignProperties(HTMLOptGroupElement, $OptGroup, 'optgroup');
|
|
20
20
|
|
|
21
|
-
declare module
|
|
21
|
+
declare module "@amateras/core" {
|
|
22
22
|
export function $(nodeName: 'optgroup'): $OptGroup
|
|
23
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
36
|
+
assignProperties(HTMLOptionElement, $Option, 'option');
|
|
37
37
|
|
|
38
|
-
declare module
|
|
38
|
+
declare module "@amateras/core" {
|
|
39
39
|
export function $(nodeName: 'option'): $Option
|
|
40
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
72
|
+
assignProperties(HTMLSelectElement, $Select, 'select');
|
|
73
73
|
|
|
74
|
-
declare module
|
|
74
|
+
declare module "@amateras/core" {
|
|
75
75
|
export function $(nodeName: 'select'): $Select
|
|
76
76
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "
|
|
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
|
-
|
|
12
|
+
assignProperties(HTMLTextAreaElement, $TextArea, 'textarea');
|
|
13
13
|
|
|
14
|
-
declare module
|
|
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
|
|
2
|
-
import {
|
|
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)
|
|
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
|
|
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?:
|
|
37
|
-
return new
|
|
40
|
+
translate(key: string, options?: I18nTranslationOptions) {
|
|
41
|
+
return new I18nTranslation(this, key, options);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -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}
|