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,129 @@
|
|
|
1
|
+
import { chain } from "@amateras/core/lib/chain";
|
|
2
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
3
|
+
import type { $Node } from "@amateras/core/node/$Node";
|
|
4
|
+
import { _Array_from, _instanceof, forEach, isUndefined } from "@amateras/utils";
|
|
5
|
+
|
|
6
|
+
const TAB = 'tab';
|
|
7
|
+
const TAB_CONTENT = 'tab-content';
|
|
8
|
+
const TAB_TRIGGER = 'tab-trigger';
|
|
9
|
+
const TAB_CONTAINER = 'tab-container';
|
|
10
|
+
const TAB_LIST = 'tab-list';
|
|
11
|
+
|
|
12
|
+
const DISPLAY_BLOCK = 'display:block'
|
|
13
|
+
|
|
14
|
+
forEach([
|
|
15
|
+
`${TAB}{${DISPLAY_BLOCK}}`,
|
|
16
|
+
`${TAB_CONTENT}{${DISPLAY_BLOCK}}`,
|
|
17
|
+
`${TAB_LIST}{${DISPLAY_BLOCK}}`,
|
|
18
|
+
`${TAB_CONTAINER}{${DISPLAY_BLOCK}}`,
|
|
19
|
+
`${TAB_TRIGGER}{cursor:pointer}`
|
|
20
|
+
], $.style)
|
|
21
|
+
|
|
22
|
+
export class Tabs extends $HTMLElement {
|
|
23
|
+
#value: null | string = null;
|
|
24
|
+
currentContent: null | TabsContent = null;
|
|
25
|
+
$container: null | TabsContainer = null;
|
|
26
|
+
$list: null | TabsList = null;
|
|
27
|
+
constructor() {
|
|
28
|
+
super(TAB);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
value(): string | null;
|
|
32
|
+
value(value: string | undefined): this;
|
|
33
|
+
value(value?: string) {
|
|
34
|
+
return chain(this, arguments, () => this.#value, value, value => {
|
|
35
|
+
this.#value = value;
|
|
36
|
+
this.$container?.content(this.$container.contentMap.get(value));
|
|
37
|
+
this.$list?.check();
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mounted($parent: $Node): void {
|
|
42
|
+
this.$list?.check();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class TabsContainer extends $HTMLElement {
|
|
47
|
+
$tabs?: Tabs;
|
|
48
|
+
contentMap = new Map<string, TabsContent>();
|
|
49
|
+
constructor($tabs?: Tabs) {
|
|
50
|
+
super(TAB_CONTAINER);
|
|
51
|
+
this.$tabs = $tabs;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
mounted($parent: $Node) {
|
|
55
|
+
if (_instanceof($parent, Tabs)) this.$tabs = $parent;
|
|
56
|
+
if (this.$tabs) {
|
|
57
|
+
this.$tabs.$container = this;
|
|
58
|
+
this.content(this.contentMap.get(this.$tabs.value() ?? ''))
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class TabsContent extends $HTMLElement {
|
|
65
|
+
#value: string;
|
|
66
|
+
$container: null | TabsContainer = null;
|
|
67
|
+
constructor(value: string) {
|
|
68
|
+
super(TAB_CONTENT);
|
|
69
|
+
this.#value = value
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
value(): string;
|
|
73
|
+
value(value: string): this;
|
|
74
|
+
value(value?: string) {
|
|
75
|
+
return chain(this, arguments, () => this.#value, value, value => {
|
|
76
|
+
this.#value = value;
|
|
77
|
+
this.$container?.contentMap.set(value, this).delete(this.#value ?? '')
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mounted($parent: $Node) {
|
|
82
|
+
if (!_instanceof($parent, TabsContainer)) return this;
|
|
83
|
+
if ($parent && this.#value) {
|
|
84
|
+
this.$container = $parent;
|
|
85
|
+
$parent.contentMap.set(this.#value, this);
|
|
86
|
+
}
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class TabsList extends $HTMLElement {
|
|
92
|
+
$tabs?: null | Tabs = null;
|
|
93
|
+
triggers = new Map<string, TabsTrigger>();
|
|
94
|
+
constructor($tabs?: Tabs) {
|
|
95
|
+
super(TAB_LIST);
|
|
96
|
+
this.$tabs = $tabs;
|
|
97
|
+
this.on('click', _ => this.check())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
check() {
|
|
101
|
+
this.triggers.forEach($trigger => $trigger.attr({selected: $trigger.value() === this.$tabs?.value() ? '' : null}))
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
mounted($parent: $Node): this {
|
|
106
|
+
if (_instanceof($parent, Tabs)) this.$tabs = $parent, $parent.$list = this;
|
|
107
|
+
if (this.$tabs) forEach(_Array_from(this.childNodes), child => $(child).is(TabsTrigger)?.use($child => {
|
|
108
|
+
this.triggers.set($child.value(), $child);
|
|
109
|
+
$child.$tabs = this.$tabs;
|
|
110
|
+
}));
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class TabsTrigger extends $HTMLElement {
|
|
116
|
+
#value: string;
|
|
117
|
+
$tabs?: null | Tabs = null;
|
|
118
|
+
constructor(value: string) {
|
|
119
|
+
super(TAB_TRIGGER);
|
|
120
|
+
this.#value = value;
|
|
121
|
+
this.on('click', _ => this.$tabs?.value(this.#value ?? undefined))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
value(): string;
|
|
125
|
+
value(value: string): this;
|
|
126
|
+
value(value?: string) {
|
|
127
|
+
return chain(this, arguments, () => this.#value, value, value => this.#value = value)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { _document } from "@amateras/core/env";
|
|
2
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
3
|
+
|
|
4
|
+
$.style('toast{position:absolute}')
|
|
5
|
+
|
|
6
|
+
export class Toast extends $HTMLElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super('toast');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
popup(duration = 3000) {
|
|
12
|
+
$(_document.body).insert(this);
|
|
13
|
+
setTimeout(() => this.remove(), duration)
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { onclient, onserver } from "@amateras/core/env";
|
|
2
|
+
import { chain } from "@amateras/core/lib/chain";
|
|
3
|
+
import type { $Element } from "@amateras/core/node/$Element";
|
|
4
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
5
|
+
import { $Virtual } from "@amateras/core/node/$Virtual";
|
|
6
|
+
import { _Array_from, _instanceof, forEach } from "@amateras/utils";
|
|
7
|
+
|
|
8
|
+
const getRect = (el: $Element) => el.getBoundingClientRect();
|
|
9
|
+
const px = (value: number) => `${value}px`;
|
|
10
|
+
$.style(`waterfall{display:block;position:relative}`)
|
|
11
|
+
|
|
12
|
+
export class Waterfall extends $Virtual {
|
|
13
|
+
#column: number | null = null;
|
|
14
|
+
#columnWidth: number = 200;
|
|
15
|
+
#mode: WaterfallMode = 'fill';
|
|
16
|
+
#gap = 0;
|
|
17
|
+
#width = 0;
|
|
18
|
+
constructor() {
|
|
19
|
+
super('waterfall');
|
|
20
|
+
onclient(() => {
|
|
21
|
+
new ResizeObserver(_ => this.inDOM() && this.#width !== getRect(this).width && (this.dispatchEvent(new Event('resize', {cancelable: true})) && this.layout())).observe(this.node);
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
mode(): WaterfallMode;
|
|
26
|
+
mode(mode: $Parameter<'fill' | 'fixed'>): this;
|
|
27
|
+
mode(mode?: $Parameter<'fill' | 'fixed'>) {
|
|
28
|
+
return chain(this, arguments, () => this.#mode, mode, value => this.#mode = value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
column(): number | null;
|
|
32
|
+
column(column: $Parameter<number | null>): this;
|
|
33
|
+
column(column?: $Parameter<number | null>) {
|
|
34
|
+
return chain(this, arguments, () => this.#column, column, value => this.#column = value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
columnWidth(): number
|
|
38
|
+
columnWidth(width: $Parameter<number>): this
|
|
39
|
+
columnWidth(width?: $Parameter<number>) {
|
|
40
|
+
return chain(this, arguments, () => this.#columnWidth, width, value => this.#columnWidth = value)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
gap(): number;
|
|
44
|
+
gap(gap: $Parameter<number>): this;
|
|
45
|
+
gap(gap?: $Parameter<number>) {
|
|
46
|
+
return chain(this, arguments, () => this.#gap, gap, value => this.#gap = value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
layout() {
|
|
50
|
+
if (onserver()) return;
|
|
51
|
+
const items = _Array_from(this.nodes).map(item => item);
|
|
52
|
+
const { width } = getRect(this);
|
|
53
|
+
this.#width = width;
|
|
54
|
+
const gap = this.#gap;
|
|
55
|
+
const columnCount = (() => {
|
|
56
|
+
if (this.#column) return this.#column;
|
|
57
|
+
const colCount = Math.floor(width / this.#columnWidth) || 1;
|
|
58
|
+
return ((colCount - 1) * gap) + this.#columnWidth * colCount > width ? colCount - 1 || 1 : colCount;
|
|
59
|
+
})()
|
|
60
|
+
const maxColumnWidth = (width - ((columnCount - 1) * gap)) / columnCount
|
|
61
|
+
const columnWidth = this.#mode === 'fill' ? maxColumnWidth : this.#columnWidth;
|
|
62
|
+
const padding = (width - columnWidth * columnCount - gap * (columnCount - 1)) / 2;
|
|
63
|
+
const columns = _Array_from({length: columnCount}).map((_, i) => ({ i, h: 0, x: i * (columnWidth + gap) + padding }))
|
|
64
|
+
const getColumnByHeight = (i: number) => columns.sort((a, b) => a.h - b.h ? a.h - b.h : a.i - b.i).at(i) as typeof columns[number];
|
|
65
|
+
forEach(items, item => {
|
|
66
|
+
if (!_instanceof(item, $HTMLElement)) return;
|
|
67
|
+
const { height, width } = item.attr();
|
|
68
|
+
const shortestSection = getColumnByHeight(0);
|
|
69
|
+
item.style({
|
|
70
|
+
position: 'absolute',
|
|
71
|
+
top: px(shortestSection.h),
|
|
72
|
+
left: px(shortestSection.x),
|
|
73
|
+
width: px(columnWidth),
|
|
74
|
+
});
|
|
75
|
+
if (width && height) {
|
|
76
|
+
// get ratio from attributes and calculate item's height
|
|
77
|
+
let itemHeight = columnWidth / (+width / +height);
|
|
78
|
+
item.style({ height: px(itemHeight) })
|
|
79
|
+
shortestSection.h += +itemHeight + gap;
|
|
80
|
+
} else {
|
|
81
|
+
item.style({ visibility: 'hidden', height: '' })
|
|
82
|
+
if (this.hiddenNodes.has(item)) this.show(item).render().hide(item);
|
|
83
|
+
let itemHeight = getRect(item).height;
|
|
84
|
+
item.style({ visibility: '', height: px(itemHeight) })
|
|
85
|
+
shortestSection.h += +itemHeight + gap;
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
this.style({ height: px(getColumnByHeight(-1).h) });
|
|
89
|
+
this.dispatchEvent(new Event('layout'))
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type WaterfallMode = 'fill' | 'fixed'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/ui",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/html": "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
|
+
"./structure/*": "./src/structure/*.ts",
|
|
15
|
+
"./lib/*": "./src/lib/*.ts",
|
|
16
|
+
"./node/*": "./src/node/*.ts",
|
|
17
|
+
"./waterfall": "./node/Waterfall.ts",
|
|
18
|
+
"./tabs": "./node/Tabs.ts",
|
|
19
|
+
"./virtual-scroll": "./lib/VirtualScroll.ts"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/utils",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*"
|
|
5
|
+
},
|
|
6
|
+
"imports": {
|
|
7
|
+
"#structure/*": "./src/structure/*.ts",
|
|
8
|
+
"#lib/*": "./src/lib/*.ts",
|
|
9
|
+
"#node/*": "./src/node/*.ts"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts",
|
|
13
|
+
"./structure/*": "./src/structure/*.ts",
|
|
14
|
+
"./lib/*": "./src/lib/*.ts",
|
|
15
|
+
"./node/*": "./src/node/*.ts"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
import type { $Element } from '#node/$Element';
|
|
2
|
-
import type { $Node } from '#node/$Node';
|
|
3
|
-
import * as core from '#core';
|
|
4
|
-
import type { Signal } from '#structure/Signal';
|
|
5
|
-
|
|
6
1
|
declare global {
|
|
7
|
-
export import $ = core.$;
|
|
8
2
|
type Nullish = null | undefined;
|
|
9
3
|
type OrArray<T> = T | T[];
|
|
10
4
|
type OrMatrix<T> = T | OrMatrix<T>[];
|
|
11
5
|
type OrPromise<T> = T | Promise<T>;
|
|
12
6
|
type OrNullish<T> = T | Nullish;
|
|
13
7
|
type Constructor<T> = { new (...args: any[]): T }
|
|
14
|
-
type
|
|
8
|
+
type Mutable<T> = {
|
|
9
|
+
-readonly [P in keyof T]: T[P];
|
|
10
|
+
}
|
|
11
|
+
type AsyncFunction<T> = () => Promise<T>;
|
|
15
12
|
type Ok<D> = [data: D, err: null];
|
|
16
13
|
type Err<E> = [data: null, err: E]
|
|
17
14
|
type Result<D, E> = Ok<D> | Err<E>
|
|
18
15
|
type Repeat<T, N extends number, Acc extends T[] = []> =
|
|
19
|
-
Acc['length'] extends
|
|
20
|
-
|
|
16
|
+
Acc['length'] extends 500
|
|
17
|
+
? T[]
|
|
18
|
+
: Acc['length'] extends N
|
|
19
|
+
? Acc
|
|
21
20
|
: Repeat<T, N, [...Acc, T]>;
|
|
22
21
|
type Prettify<T> = {
|
|
23
22
|
[K in keyof T]: T[K];
|
|
24
23
|
} & {};
|
|
25
|
-
|
|
26
|
-
readonly $: $Node
|
|
27
|
-
}
|
|
28
|
-
interface Element {
|
|
29
|
-
readonly $: $Element
|
|
30
|
-
}
|
|
24
|
+
type Narrow<T> = T extends boolean ? boolean : T;
|
|
31
25
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import './global';
|
|
2
|
+
|
|
3
|
+
// Value
|
|
4
|
+
export const _null = null;
|
|
5
|
+
export const _undefined = undefined;
|
|
6
|
+
// Object
|
|
7
|
+
export const _Object_fromEntries = Object.fromEntries;
|
|
8
|
+
export const _Object_entries = Object.entries;
|
|
9
|
+
export const _Object_assign = Object.assign;
|
|
10
|
+
export const _Object_values = Object.values;
|
|
11
|
+
export const _Object_defineProperty = Object.defineProperty;
|
|
12
|
+
export const _Object_getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
|
13
|
+
// Array
|
|
14
|
+
export const _Array_from = Array.from;
|
|
15
|
+
interface forEach {
|
|
16
|
+
<T>(arr: Array<T>, fn: (value: T, index: number, array: Array<T>) => Promise<void>): Promise<void>;
|
|
17
|
+
<T>(arr: Array<T>, fn: (value: T, index: number, array: Array<T>) => void): void;
|
|
18
|
+
<T>(set: Set<T>, fn: (value: T, index: number, set: Set<T>) => Promise<void>): void;
|
|
19
|
+
<T>(set: Set<T>, fn: (value: T, index: number, set: Set<T>) => void): void;
|
|
20
|
+
<K, V>(map: Map<K, V>, fn: (value: [K, V], index: number, map: Map<K, V>) => Promise<void>): void;
|
|
21
|
+
<K, V>(map: Map<K, V>, fn: (value: [K, V], index: number, map: Map<K, V>) => void): void;
|
|
22
|
+
<N extends Node>(set: NodeListOf<N>, fn: (value: N, index: number, parent: NodeListOf<N>) => Promise<void>): void;
|
|
23
|
+
<N extends Node>(set: NodeListOf<N>, fn: (value: N, index: number, parent: NodeListOf<N>) => void): void;
|
|
24
|
+
}
|
|
25
|
+
export const forEach: forEach = async (arr: any, fn: any) => {
|
|
26
|
+
let i = 0;
|
|
27
|
+
let isAsync = isAsyncFunction(fn);
|
|
28
|
+
let handle = async () => { for (let item of arr) { isAsync ? await fn(item, i, arr) : fn(item, i, arr); i++; } }
|
|
29
|
+
return isAsync ? new _Promise<void>(resolve => handle().then(resolve)) : handle();
|
|
30
|
+
};
|
|
31
|
+
// export const forEach: forEach = (arr: any, fn: any) => arr.forEach(fn);
|
|
32
|
+
// type check
|
|
33
|
+
export const _typeof = (target: any, type: 'string' | 'number' | 'object' | 'boolean' | 'function' | 'bigint' | 'symbol' | 'undefined') => typeof target === type;
|
|
34
|
+
export const equal = <T, V extends T>(target: T, ...args: V[]): target is V => !!args.find(a => a === target);
|
|
35
|
+
export const isString = (target: any): target is string => _typeof(target, 'string');
|
|
36
|
+
export const isBoolean = (target: any): target is boolean => _typeof(target, 'boolean');
|
|
37
|
+
export const isNumber = (target: any): target is number => _typeof(target, 'number');
|
|
38
|
+
export const isObject = (target: any): target is object => _typeof(target, 'object');
|
|
39
|
+
export const isFunction = (target: any): target is Function => _typeof(target, 'function');
|
|
40
|
+
export const isAsyncFunction = (target: any): target is AsyncFunction<Awaited<ReturnType<typeof target>>> => _instanceof(target, (async () => 0).constructor as any)
|
|
41
|
+
export const isUndefined = (target: any): target is undefined => target === undefined;
|
|
42
|
+
export const isNull = (target: any): target is null => target === _null;
|
|
43
|
+
export const isArray = Array.isArray;
|
|
44
|
+
export const _instanceof = <T extends (abstract new (...args: any[]) => any)[]>(target: any, ...instance: T): target is InstanceType<T[number]> => !!instance.find(i => target instanceof i);
|
|
45
|
+
// JSON
|
|
46
|
+
export const _JSON_stringify = JSON.stringify;
|
|
47
|
+
export const _JSON_parse = JSON.parse;
|
|
48
|
+
// String
|
|
49
|
+
export const startsWith = (target: string, ...str: string[]) => !!str.find(s => target.startsWith(s));
|
|
50
|
+
// String & Array
|
|
51
|
+
interface slice {
|
|
52
|
+
(target: string, start?: number, end?: number): string;
|
|
53
|
+
<T>(target: Array<T>, start?: number, end?: number): T[];
|
|
54
|
+
}
|
|
55
|
+
export const slice: slice = (target: any, start?: number, end?: number) => target.slice(start, end);
|
|
56
|
+
// Function
|
|
57
|
+
export const _bind = <T extends Function>(target: T, obj: Object): T => target.bind(obj);
|
|
58
|
+
// Promise
|
|
59
|
+
export const _Promise = Promise;
|
|
60
|
+
|
|
61
|
+
// utils function
|
|
62
|
+
export const debounce = () => {
|
|
63
|
+
let timer: number;
|
|
64
|
+
return (fn: Function, timeout: number) => {
|
|
65
|
+
if (timer) clearTimeout(timer);
|
|
66
|
+
timer = setTimeout(fn, timeout);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const LOWER = 'abcdefghijklmnopqrstuvwxyz';
|
|
71
|
+
const UPPER = LOWER.toUpperCase();
|
|
72
|
+
export const randomId = (options?: {length?: number, lettercase?: 'any' | 'lower' | 'upper'}): string => {
|
|
73
|
+
options = {length: 5, lettercase: 'any', ...options};
|
|
74
|
+
const char = options.lettercase === 'any' ? LOWER + UPPER : options.lettercase === 'lower' ? LOWER : UPPER;
|
|
75
|
+
return _Array_from({length: options.length as number}, (_, i) => char[Math.round(Math.random() * char.length)]).join('');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const sleep = async (ms: number) => new _Promise(resolve => setTimeout(resolve, ms));
|
|
79
|
+
|
|
80
|
+
export const toArray = <T>(item: OrArray<T>): T[] => _instanceof(item, Array) ? item : [item];
|
|
81
|
+
|
|
82
|
+
export const trycatch = <D>(callback: () => D): Result<D, Error> => {
|
|
83
|
+
try {
|
|
84
|
+
return [callback(), _null];
|
|
85
|
+
} catch (err) {
|
|
86
|
+
return [_null, _instanceof(err, Error) ? err : new Error(_JSON_stringify(err))];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const uppercase = (str: string, start?: number, end?: number) => `${slice(str, 0, start)}${slice(str, start, end).toUpperCase()}${end ? slice(str, end) : ''}`
|
package/tsconfig.json
CHANGED
package/ext/css/package.json
DELETED
package/ext/html/node/$Canvas.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assignHelper } from "#lib/assignHelper";
|
|
2
|
-
import { $HTMLElement } from "#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
|
-
|
|
12
|
-
assignHelper(HTMLCanvasElement, $Canvas, 'canvas');
|
|
13
|
-
|
|
14
|
-
declare module '#core' {
|
|
15
|
-
export function $(nodeName: 'canvas'): $Canvas
|
|
16
|
-
}
|
package/ext/i18n/package.json
DELETED
package/ext/i18n/src/index.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { _Array_from, _instanceof, _Object_assign } from "amateras/lib/native"
|
|
2
|
-
import { $ } from "amateras/core"
|
|
3
|
-
import { I18n } from "#structure/I18n"
|
|
4
|
-
import type { I18nText as _I18nText, I18nTextOptions } from "#node/I18nText";
|
|
5
|
-
import { I18nDictionary, type I18nDictionaryContext, type I18nDictionaryContextImporter } from "#structure/I18nDictionary";
|
|
6
|
-
|
|
7
|
-
_Object_assign($, {
|
|
8
|
-
i18n(defaultLocale: string) {
|
|
9
|
-
const i18n = new I18n(defaultLocale);
|
|
10
|
-
const i18nFn = (key: string, options?: I18nTextOptions) => i18n.translate(key, options);
|
|
11
|
-
_Object_assign(i18nFn, {
|
|
12
|
-
i18n,
|
|
13
|
-
locale(locale: string) {
|
|
14
|
-
if (!arguments.length) return i18n.locale();
|
|
15
|
-
i18n.locale(locale);
|
|
16
|
-
return this;
|
|
17
|
-
},
|
|
18
|
-
add(lang: string, context: I18nDictionaryContext | I18nDictionaryContextImporter) {
|
|
19
|
-
i18n.map.set(lang, new I18nDictionary(context));
|
|
20
|
-
return this;
|
|
21
|
-
},
|
|
22
|
-
delete(lang: string) {
|
|
23
|
-
i18n.map.delete(lang);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
return i18nFn
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
type ResolvedAsyncDictionary<F extends I18nDictionaryContextImporter> = Awaited<ReturnType<F>>['default'];
|
|
32
|
-
|
|
33
|
-
type DeepKeys<T> = T extends I18nDictionaryContext
|
|
34
|
-
? {
|
|
35
|
-
[K in keyof T]: K extends string
|
|
36
|
-
? K extends '_' ? never : `${K}` | `${K}.${DeepKeys<T[K]>}`
|
|
37
|
-
: never;
|
|
38
|
-
}[keyof T]
|
|
39
|
-
: never;
|
|
40
|
-
|
|
41
|
-
declare module "amateras/core" {
|
|
42
|
-
export namespace $ {
|
|
43
|
-
export interface I18nFunction<D extends I18nDictionaryContext = {}> {
|
|
44
|
-
(path: DeepKeys<D>, ...args: any[]): I18nText;
|
|
45
|
-
i18n: I18n;
|
|
46
|
-
locale(): string;
|
|
47
|
-
locale(lang?: $Parameter<string>): this;
|
|
48
|
-
add<F extends I18nDictionaryContext | I18nDictionaryContextImporter>(lang: string, dictionary: F): I18nFunction<D | (F extends I18nDictionaryContextImporter ? ResolvedAsyncDictionary<F> : F)>;
|
|
49
|
-
delete(lang: string): this;
|
|
50
|
-
}
|
|
51
|
-
export function i18n(defaultLocale: string): I18nFunction;
|
|
52
|
-
export type I18nText = _I18nText;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { _Array_from, isUndefined } from "amateras/lib/native";
|
|
2
|
-
import { $HTMLElement } from "amateras/node/$HTMLElement";
|
|
3
|
-
import type { I18n } from "#structure/I18n";
|
|
4
|
-
|
|
5
|
-
export class I18nText extends $HTMLElement<HTMLElement, { i18nupdate: Event }> {
|
|
6
|
-
i18n: I18n;
|
|
7
|
-
key: string;
|
|
8
|
-
options: I18nTextOptions | undefined;
|
|
9
|
-
constructor(i18n: I18n, key: string, options?: I18nTextOptions) {
|
|
10
|
-
super('text');
|
|
11
|
-
this.i18n = i18n;
|
|
12
|
-
this.key = key;
|
|
13
|
-
this.options = options;
|
|
14
|
-
i18n.locale$.signal.subscribe(() => this.update())
|
|
15
|
-
this.update();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async update() {
|
|
19
|
-
update: {
|
|
20
|
-
const {key, i18n} = this;
|
|
21
|
-
const dictionary = i18n.dictionary();
|
|
22
|
-
if (!dictionary) {this.content(key); break update}
|
|
23
|
-
const target = await dictionary.find(key);
|
|
24
|
-
if (isUndefined(target)) break update;
|
|
25
|
-
const snippets = target.split(/\$[a-zA-Z0-9_]+\$/);
|
|
26
|
-
if (snippets.length === 1 || !this.options) {this.content(target); break update}
|
|
27
|
-
const matches = target.matchAll(/(\$([a-zA-Z0-9_]+)\$)/g);
|
|
28
|
-
this.content(snippets.map(text => [text, this.options?.[matches.next().value?.at(2)!] ?? null]));
|
|
29
|
-
}
|
|
30
|
-
this.dispatchEvent(new Event('i18nupdate'));
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type I18nTextOptions = {[key: string]: any}
|
package/ext/idb/package.json
DELETED