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
package/README.md
CHANGED
|
@@ -29,37 +29,33 @@ $('p').css(paragraphStyle).content([
|
|
|
29
29
|
])
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## State Management
|
|
33
33
|
```ts
|
|
34
34
|
import 'amateras';
|
|
35
|
+
import 'amateras/signal';
|
|
35
36
|
|
|
37
|
+
// define a signal with value 0
|
|
36
38
|
const count$ = $.signal(0);
|
|
37
39
|
|
|
38
|
-
$
|
|
39
|
-
|
|
40
|
-
.content('Click me')
|
|
41
|
-
.class('class1', 'class2')
|
|
42
|
-
.on('click', () => count$(oldValue => oldValue + 1)),
|
|
43
|
-
$('p').content($`Clicked ${count$} times.`)
|
|
44
|
-
])
|
|
45
|
-
```
|
|
40
|
+
// this variable will be auto recalculate when count$ changes
|
|
41
|
+
const doubleCount$ = $.compute(() => count$() * 2);
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
import 'amateras';
|
|
43
|
+
// the console message will fired when count$ changes
|
|
44
|
+
$.effect(() => console.log( count$() ))
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
$(document.body).content([
|
|
47
|
+
// Display Counts
|
|
48
|
+
$('p').content( $`Counts: ${count$}` ),
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
// Display Double Counts
|
|
51
|
+
$('p').content( $`Double Counts: ${doubleCount$}` ),
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
$('
|
|
58
|
-
$('p').content($`Double: ${doubleCount$}`)
|
|
53
|
+
// Create a button that make counts plus 1 on click
|
|
54
|
+
$('button').content('Add Count').on('click', () => count$.set(value => value + 1))
|
|
59
55
|
])
|
|
60
56
|
```
|
|
61
57
|
|
|
62
|
-
## HTMLElement Methods Import
|
|
58
|
+
## HTMLElement Native Methods Import
|
|
63
59
|
```ts
|
|
64
60
|
import 'amateras';
|
|
65
61
|
import 'amateras/html';
|
|
@@ -102,10 +98,11 @@ $(document.body).content([
|
|
|
102
98
|
The packages size result using Vite 7.0 with default bundle settings, polyfills code included.
|
|
103
99
|
| Package name | Size | Size(gzip) | Description |
|
|
104
100
|
| --- | --- | --- | --- |
|
|
105
|
-
| amateras |
|
|
106
|
-
| amateras/html | 0.
|
|
107
|
-
| [amateras/
|
|
108
|
-
| [amateras/
|
|
109
|
-
| [amateras/
|
|
110
|
-
| [amateras/
|
|
111
|
-
| amateras/
|
|
101
|
+
| amateras | 4.79 kB | 2.20 kB | Core |
|
|
102
|
+
| amateras/html | 0.98 kB | 0.26 kB | Import HTMLElement types and methods |
|
|
103
|
+
| [amateras/signal](./ext/signal/README.md) | 1.26 kB | 0.49 kB | Reactive data |
|
|
104
|
+
| [amateras/css](./ext/css/README.md) | 3.70 kB | 1.44 kB | Style in JS |
|
|
105
|
+
| [amateras/router](./ext/router/README.md) | 3.70 kB | 1.64 kB | Amateras Router |
|
|
106
|
+
| [amateras/i18n](./ext/i18n/README.md) | 3.02 kB | 1.13 kB | I18n translations |
|
|
107
|
+
| [amateras/idb](./ext/idb/README.md) | 5.39 kB | 2.06 kB | IndexedDB Builder and API Wrapper |
|
|
108
|
+
| [amateras/markdown](./ext/markdown/README.md) | 6.81 kB | 2.68 kB | Markdown Converter |
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@amateras/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amateras",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Amateras is a DOM Utility library.",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -14,33 +14,38 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/defaultkavy/amateras",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"imports": {
|
|
18
|
-
"#core": "./src/core.ts",
|
|
19
|
-
"#node/*": "./src/node/*.ts",
|
|
20
|
-
"#lib/*": "./src/lib/*.ts",
|
|
21
|
-
"#structure/*": "./src/structure/*.ts",
|
|
22
|
-
"#html": "./ext/html/html.ts",
|
|
23
|
-
"#html/*": "./ext/html/node/*.ts"
|
|
24
|
-
},
|
|
25
17
|
"exports": {
|
|
26
|
-
".": "./
|
|
27
|
-
"./
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
".": "./index.ts",
|
|
19
|
+
"./env": {
|
|
20
|
+
"browser": "./packages/core/src/env.browser.ts",
|
|
21
|
+
"node": "./packages/core/src/env.node.ts",
|
|
22
|
+
"default": "./packages/core/src/env.browser.ts"
|
|
23
|
+
},
|
|
24
|
+
"./node/*": "./packages/core/src/node/*.ts",
|
|
25
|
+
"./lib/*": "./packages/core/src/lib/*.ts",
|
|
30
26
|
"./structure/*": "./src/structure/*.ts",
|
|
31
|
-
"./
|
|
32
|
-
"./
|
|
33
|
-
"./
|
|
34
|
-
"./
|
|
35
|
-
"./css
|
|
36
|
-
"./
|
|
37
|
-
"./
|
|
38
|
-
"./
|
|
39
|
-
"./
|
|
40
|
-
"./idb
|
|
41
|
-
"./
|
|
27
|
+
"./core": "./packages/core/src/index.ts",
|
|
28
|
+
"./utils": "./packages/utils/src/index.ts",
|
|
29
|
+
"./html": "./packages/html/src/index.ts",
|
|
30
|
+
"./html/*": "./packages/html/node/*.ts",
|
|
31
|
+
"./css": "./packages/css/src/index.ts",
|
|
32
|
+
"./css/*": "./packages/css/src/ext/*.ts",
|
|
33
|
+
"./router": "./packages/router/src/index.ts",
|
|
34
|
+
"./ssr": "./packages/ssr/src/index.ts",
|
|
35
|
+
"./i18n": "./packages/i18n/src/index.ts",
|
|
36
|
+
"./idb": "./packages/idb/src/index.ts",
|
|
37
|
+
"./idb/core": "./packages/idb/src/core.ts",
|
|
38
|
+
"./markdown": "./packages/markdown/src/index.ts",
|
|
39
|
+
"./markdown/syntax/*": "./packages/markdown/src/syntax/*.ts",
|
|
40
|
+
"./signal": "./packages/signal/src/index.ts",
|
|
41
|
+
"./ui/*": "./packages/ui/*.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@amateras/core": "workspace:*"
|
|
42
45
|
},
|
|
43
|
-
"workspaces":
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
+
"workspaces": {
|
|
47
|
+
"packages": [
|
|
48
|
+
"packages/*"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
46
51
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/core",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@amateras/utils": "workspace:*",
|
|
5
|
+
"@amateras/dom": "workspace:*"
|
|
6
|
+
},
|
|
7
|
+
"imports": {
|
|
8
|
+
"#structure/*": "./src/structure/*.ts",
|
|
9
|
+
"#lib/*": "./src/lib/*.ts",
|
|
10
|
+
"#node/*": "./src/node/*.ts",
|
|
11
|
+
"#env": {
|
|
12
|
+
"browser": "./src/env.browser.ts",
|
|
13
|
+
"node": "./src/env.node.ts",
|
|
14
|
+
"default": "./src/env.browser.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"browser": "./src/index.ts",
|
|
20
|
+
"node": "./src/main.ts",
|
|
21
|
+
"default": "./src/index.ts"
|
|
22
|
+
},
|
|
23
|
+
"./env": {
|
|
24
|
+
"browser": "./src/env.browser.ts",
|
|
25
|
+
"node": "./src/env.node.ts",
|
|
26
|
+
"default": "./src/env.browser.ts"
|
|
27
|
+
},
|
|
28
|
+
"./structure/*": "./src/structure/*.ts",
|
|
29
|
+
"./lib/*": "./src/lib/*.ts",
|
|
30
|
+
"./node/*": "./src/node/*.ts"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// window and document
|
|
2
|
+
export const _window = window;
|
|
3
|
+
export const _document = document;
|
|
4
|
+
|
|
5
|
+
interface onclient {
|
|
6
|
+
(): boolean;
|
|
7
|
+
(fn: Function): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface onserver {
|
|
11
|
+
(): boolean;
|
|
12
|
+
(fn: Function): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const onclient: onclient = (fn?: Function) => {
|
|
16
|
+
if (fn) return fn();
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
export const onserver: onserver = (fn?: Function) => {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// window and document
|
|
2
|
+
export const _window = window;
|
|
3
|
+
export const _document = document;
|
|
4
|
+
|
|
5
|
+
interface onclient {
|
|
6
|
+
(): boolean;
|
|
7
|
+
(fn: Function): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface onserver {
|
|
11
|
+
(): boolean;
|
|
12
|
+
(fn: Function): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const onclient: onclient = (fn?: Function) => {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
export const onserver: onserver = (fn?: Function) => {
|
|
19
|
+
if (fn) return fn();
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { $Element } from '#node/$Element';
|
|
2
|
+
import type { $Node } from '#node/$Node';
|
|
3
|
+
import * as core from './index';
|
|
4
|
+
import type { $EventTarget } from '#node/$EventTarget';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
export import $ = core.$;
|
|
8
|
+
type $Parameter<T> = T | undefined | $.$NodeParameterExtends<T>
|
|
9
|
+
interface Node {
|
|
10
|
+
readonly $: $Node
|
|
11
|
+
}
|
|
12
|
+
interface EventTarget {
|
|
13
|
+
readonly $: $EventTarget
|
|
14
|
+
}
|
|
15
|
+
interface Element {
|
|
16
|
+
readonly $: $Element
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import './global';
|
|
2
|
+
import './lib/assignNodeProperties';
|
|
3
|
+
import { $Element } from "#node/$Element";
|
|
4
|
+
import { $Node, type $NodeContentResolver, type $NodeContentTypes } from '#node/$Node';
|
|
5
|
+
import { _instanceof, isString, isFunction, _Object_assign, isObject, isNull, _Object_entries, _Object_defineProperty, forEach, isNumber, _Array_from, isUndefined, _bind, _null } from '@amateras/utils';
|
|
6
|
+
import { $HTMLElement } from '#node/$HTMLElement';
|
|
7
|
+
import { _document } from '#env';
|
|
8
|
+
import { $EventTarget, type $Event } from '#node/$EventTarget';
|
|
9
|
+
|
|
10
|
+
const nodeNameMap: {[key: string]: Constructor<$EventTarget>} = {}
|
|
11
|
+
|
|
12
|
+
type $NodeBuilder = (...args: any[]) => $NodeContentResolver<$Node>
|
|
13
|
+
type BuilderResultResolver<F> = F extends Constructor<$Node> ? InstanceType<F> : F extends $NodeBuilder ? ReturnType<F> : never;
|
|
14
|
+
type BuilderParameterResolver<F> = F extends Constructor<$Node> ? ConstructorParameters<F> : F extends $NodeBuilder ? Parameters<F> : never;
|
|
15
|
+
|
|
16
|
+
type $Type<T extends EventTarget> = T extends HTMLElement ? $HTMLElement : T extends Element ? $Element : T extends (Node | ChildNode) ? $Node : T extends EventTarget ? $EventTarget : never;
|
|
17
|
+
|
|
18
|
+
/** Builder function */
|
|
19
|
+
export function $<F extends $NodeBuilder | Constructor<$Node> | number, T extends $NodeBuilder | Constructor<$Node>>(
|
|
20
|
+
resolver: F,
|
|
21
|
+
...args: F extends number ? [T, ...BuilderParameterResolver<T>] : BuilderParameterResolver<F>
|
|
22
|
+
): F extends number
|
|
23
|
+
? number extends F
|
|
24
|
+
? BuilderResultResolver<T>[]
|
|
25
|
+
: Repeat<BuilderResultResolver<T>, F>
|
|
26
|
+
: BuilderResultResolver<F>;
|
|
27
|
+
/** Get {@link $Node} from {@link NodeList} */
|
|
28
|
+
export function $<T extends HTMLElement | Element | Node | ChildNode>(nodes: NodeListOf<T>): $Type<T>[];
|
|
29
|
+
/** Get self */
|
|
30
|
+
export function $<E extends $EventTarget | null | undefined>($node: E, ...args: any[]): E extends $EventTarget ? E : null;
|
|
31
|
+
/** Convert {@link Window} to {@link $EventTarget} */
|
|
32
|
+
export function $<W extends Window>(node: W): $EventTarget<WindowEventMap>;
|
|
33
|
+
/** Convert {@link Document} to {@link $Node} */
|
|
34
|
+
export function $<D extends Document>(node: D): $Node<DocumentEventMap>;
|
|
35
|
+
/** Convert {@link EventTarget} base to {@link $EventTarget} base*/
|
|
36
|
+
export function $<H extends EventTarget | null | undefined>(target: H, ...args: any[]): H extends EventTarget ? $Type<H> : null;
|
|
37
|
+
export function $<E extends Record<string, Event>>(target: EventTarget, ...args: any[]): $EventTarget<E>;
|
|
38
|
+
/** Convert string and variables to {@link $NodeContentTypes} array */
|
|
39
|
+
export function $<K extends TemplateStringsArray>(string: K, ...values: any[]): $NodeContentTypes[];
|
|
40
|
+
/** Get {@link Event.currentTarget} in {@link $EventTarget} type from {@link Event} */
|
|
41
|
+
export function $<Ev extends $Event<$Element, Event>>(event: Ev): Ev['currentTarget']['$'];
|
|
42
|
+
/** Create {@link $Node} base object from extensions */
|
|
43
|
+
export function $<K extends keyof $.$NodeMap, T extends $.$NodeMap[K]>(tagname: K, ...args: ConstructorParameters<T>): InstanceType<T>;
|
|
44
|
+
/** Create {@link $HTMLElement} by tagname */
|
|
45
|
+
export function $<K extends keyof HTMLElementTagNameMap>(tagname: K): $HTMLElement<HTMLElementTagNameMap[K]>;
|
|
46
|
+
/** Create {@link $HTMLElement} by custom tagname */
|
|
47
|
+
export function $(tagname: string): $HTMLElement<HTMLElement>
|
|
48
|
+
/** Create multiple {@link $HTMLElement} objects by tagname */
|
|
49
|
+
export function $<N extends number, K extends keyof HTMLElementTagNameMap>(number: N, tagname: K): number extends N ? $HTMLElement<HTMLElementTagNameMap[K]>[] : Repeat<$HTMLElement<HTMLElementTagNameMap[K]>, N>;
|
|
50
|
+
/** Create multiple {@link $HTMLElement} objects by custom tagname */
|
|
51
|
+
export function $<N extends number>(number: N, tagname: string): number extends N ? $HTMLElement<HTMLElement>[] : Repeat<$HTMLElement<HTMLElement>, N>;
|
|
52
|
+
export function $(resolver: string | number | null | undefined | Element | HTMLElement | $Node | Function | TemplateStringsArray | Event | NodeListOf<Node | ChildNode> | EventTarget, ...args: any[]) {
|
|
53
|
+
if (isNull(resolver) || isUndefined(resolver)) return null;
|
|
54
|
+
if (_instanceof(resolver, $Node)) return resolver;
|
|
55
|
+
if (isString(resolver) && nodeNameMap[resolver]) return new nodeNameMap[resolver](...args);
|
|
56
|
+
if (isFunction(resolver))
|
|
57
|
+
if (resolver.prototype?.constructor) return new resolver.prototype.constructor(...args);
|
|
58
|
+
else return resolver(...args);
|
|
59
|
+
if (resolver instanceof Array) {
|
|
60
|
+
const iterate = args.values();
|
|
61
|
+
return resolver.map(str => [str ?? undefined, iterate.next().value]).flat().filter(item => item);
|
|
62
|
+
}
|
|
63
|
+
if (_instanceof(resolver, Node) && _instanceof(resolver.$, $Node)) return resolver.$;
|
|
64
|
+
if (_instanceof(resolver, Event)) return $(resolver.currentTarget as Element);
|
|
65
|
+
if (isNumber(resolver)) return _Array_from({length: resolver}).map(_ => $(args[0], ...args.slice(1)));
|
|
66
|
+
if (_instanceof(resolver, HTMLElement)) return new $HTMLElement(resolver);
|
|
67
|
+
if (_instanceof(resolver, Element)) return new $Element(resolver);
|
|
68
|
+
if (_instanceof(resolver, Node)) return new $Node(resolver as any);
|
|
69
|
+
if (_instanceof(resolver, EventTarget)) return new $EventTarget(resolver as any);
|
|
70
|
+
if (_instanceof(resolver, NodeList)) return _Array_from(resolver).map($);
|
|
71
|
+
return new $HTMLElement(resolver);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export namespace $ {
|
|
75
|
+
// css
|
|
76
|
+
const _stylesheet = new CSSStyleSheet();
|
|
77
|
+
export const stylesheet = _stylesheet;
|
|
78
|
+
_document.adoptedStyleSheets.push(_stylesheet);
|
|
79
|
+
export const style = _bind(_stylesheet.insertRule, _stylesheet);
|
|
80
|
+
// node map
|
|
81
|
+
export interface $NodeMap {}
|
|
82
|
+
// node content amp
|
|
83
|
+
export interface $NodeContentMap {}
|
|
84
|
+
export type $NodeContentTypeExtends = $NodeContentMap[keyof $NodeContentMap]
|
|
85
|
+
// attr value map
|
|
86
|
+
export interface $NodeParameterMap<T> {}
|
|
87
|
+
export type $NodeParameterExtends<T> = $NodeParameterMap<T>[keyof $NodeParameterMap<T>]
|
|
88
|
+
|
|
89
|
+
export const assign = (...resolver: [nodeName: string, $node: Constructor<$EventTarget>][]) => {
|
|
90
|
+
forEach(resolver, ([nodeName, $node]) => nodeNameMap[nodeName] = $node);
|
|
91
|
+
return $;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type $ = typeof $;
|
|
96
|
+
globalThis.$ = $;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { $HTMLElement } from '#node/$HTMLElement';
|
|
2
|
+
import { assignProperties } from '#lib/assignProperties';
|
|
3
|
+
import { $Element } from '#node/$Element';
|
|
4
|
+
import { $Node, $Text } from '#node/$Node';
|
|
5
|
+
import { $EventTarget } from '#node/$EventTarget';
|
|
6
|
+
|
|
7
|
+
assignProperties(EventTarget, $EventTarget);
|
|
8
|
+
assignProperties(Node, $Node);
|
|
9
|
+
assignProperties(Text, $Text);
|
|
10
|
+
assignProperties(Element, $Element);
|
|
11
|
+
assignProperties(HTMLElement, $HTMLElement);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { $EventTarget } from "#node/$EventTarget";
|
|
2
|
+
import { $Node } from "#node/$Node";
|
|
3
|
+
import { _instanceof, _null, _Object_defineProperty, _Object_entries, _Object_getOwnPropertyDescriptors, forEach, isUndefined } from "@amateras/utils";
|
|
4
|
+
|
|
5
|
+
const assigner = (target: any, {set, get, fn}: {
|
|
6
|
+
set?: string[],
|
|
7
|
+
get?: string[],
|
|
8
|
+
fn?: string[]
|
|
9
|
+
}) => {
|
|
10
|
+
const [GET, SET, FN] = ['get', 'set', 'fn'] as const;
|
|
11
|
+
const filterAndMap = (type: 'get' | 'set' | 'fn', arr: string[] | undefined) => arr?.map(prop => [type, prop]) ?? []
|
|
12
|
+
const list = [...filterAndMap(GET, get), ...filterAndMap(SET, set), ...filterAndMap(FN, fn)] as [string, string][];
|
|
13
|
+
forEach(list, ([type, prop]) =>
|
|
14
|
+
_Object_defineProperty(target.prototype, prop, {
|
|
15
|
+
...(type === GET ? {
|
|
16
|
+
get() { return this.node[prop as any] }
|
|
17
|
+
} : {
|
|
18
|
+
writable: true,
|
|
19
|
+
...(type === SET ? {
|
|
20
|
+
// set
|
|
21
|
+
value(this, args: any) {
|
|
22
|
+
if (!arguments.length) return this.node[prop];
|
|
23
|
+
let set = (value: any) => !isUndefined(value) && (this.node[prop] = value);
|
|
24
|
+
for (const setter of $Node.setters) {
|
|
25
|
+
const result = setter(args, set);
|
|
26
|
+
if (!isUndefined(result)) return set(result), this;
|
|
27
|
+
}
|
|
28
|
+
set(args)
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
} : {
|
|
32
|
+
// fn
|
|
33
|
+
value(this, ...args : any[]) {
|
|
34
|
+
let result = this.node[prop](...args.map(value => _instanceof(value, $Node) ? value.node : value ?? _null))
|
|
35
|
+
return isUndefined(result) ? this : result;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const assignProperties = (object: Constructor<EventTarget>, target: Constructor<$EventTarget>, tagname?: string) => {
|
|
45
|
+
const [set, get, fn] = [[], [], []] as [string[], string[], string[]]
|
|
46
|
+
// assign native object properties to target
|
|
47
|
+
forEach(_Object_entries(_Object_getOwnPropertyDescriptors(object.prototype)), ([prop, value]) => {
|
|
48
|
+
if (!(prop in target.prototype)) {
|
|
49
|
+
if (value.get && !value.set) get.push(prop);
|
|
50
|
+
else if (value.value) fn.push(prop);
|
|
51
|
+
else if (value.get && value.set) set.push(prop);
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
assigner(target, {set, get, fn})
|
|
55
|
+
// register tagname
|
|
56
|
+
if (tagname) $.assign([tagname, target])
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { $Node } from "#node/$Node";
|
|
2
|
+
import { isUndefined } from "@amateras/utils";
|
|
3
|
+
|
|
4
|
+
export const chain: chain = <T, R, V>(_this: T, args: IArguments | null, get: (() => R) | null, value: V, set: (value: Exclude<V, undefined>) => any) => {
|
|
5
|
+
if (args && get && !args.length) return get();
|
|
6
|
+
if (isUndefined(value)) return _this;
|
|
7
|
+
for (const setter of $Node.setters) {
|
|
8
|
+
const result = setter(value, set);
|
|
9
|
+
if (!isUndefined(result)) return set(result), _this;
|
|
10
|
+
}
|
|
11
|
+
return set(value as any), _this;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface chain {
|
|
15
|
+
<T, V>(_this: T, args: null, get: null, value: V, set: (value: Exclude<V, undefined | $.$NodeParameterExtends<V>>) => any): T
|
|
16
|
+
<T, R, V>(_this: T, args: IArguments, get: (() => R), value: V, set: (value: Exclude<V, undefined | $.$NodeParameterExtends<V>>) => any): T | R
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { _Object_assign } from "@amateras/utils";
|
|
2
|
+
import "@amateras/dom/structure/NodeList";
|
|
3
|
+
import '@amateras/dom/structure/Node';
|
|
4
|
+
import '@amateras/dom/structure/Text';
|
|
5
|
+
import '@amateras/dom/structure/Document';
|
|
6
|
+
import '@amateras/dom/structure/Element';
|
|
7
|
+
import '@amateras/dom/structure/HTMLElement';
|
|
8
|
+
import '@amateras/dom/structure/CSSStyleSheet';
|
|
9
|
+
import '@amateras/dom/structure/CSS';
|
|
10
|
+
|
|
11
|
+
import '@amateras/dom/structure/html/HTMLAnchorElement';
|
|
12
|
+
|
|
13
|
+
import { Window } from "@amateras/dom/structure/Window";
|
|
14
|
+
|
|
15
|
+
const window = new Window();
|
|
16
|
+
|
|
17
|
+
_Object_assign(globalThis, {
|
|
18
|
+
window,
|
|
19
|
+
...window,
|
|
20
|
+
})
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { _document } from "#lib/env";
|
|
1
|
+
import { _Array_from, _instanceof, _Object_assign, _Object_entries, _Object_fromEntries, forEach, isNull, isNumber, isString, isUndefined } from "@amateras/utils";
|
|
2
|
+
import { _document } from "#env";
|
|
3
|
+
import { $Node } from "./$Node";
|
|
5
4
|
|
|
6
|
-
export class $Element<Ele extends Element = Element, EvMap = ElementEventMap> extends $Node {
|
|
5
|
+
export class $Element<Ele extends Element = Element, EvMap = ElementEventMap> extends $Node<EvMap> {
|
|
7
6
|
declare node: Ele
|
|
8
7
|
constructor(resolver: Ele | string) {
|
|
9
8
|
super(_instanceof(resolver, Element) ? resolver : createNode(resolver) as unknown as Ele)
|
|
@@ -13,15 +12,22 @@ export class $Element<Ele extends Element = Element, EvMap = ElementEventMap> ex
|
|
|
13
12
|
|
|
14
13
|
attr(): {[key: string]: string};
|
|
15
14
|
attr(key: string): string | null;
|
|
16
|
-
attr(obj: {[key: string]:
|
|
17
|
-
attr(resolver?: {[key: string]:
|
|
15
|
+
attr(obj: {[key: string]: $Parameter<any| null>}): this;
|
|
16
|
+
attr(resolver?: {[key: string]: $Parameter<any | null>} | string) {
|
|
18
17
|
if (!arguments.length) return _Object_fromEntries(_Array_from(this.attributes).map(attr => [attr.name, attr.value]));
|
|
19
18
|
if (isString(resolver)) return this.getAttribute(resolver);
|
|
20
|
-
if (resolver)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (resolver)
|
|
20
|
+
keyIterate: for (let [key, value] of _Object_entries(resolver)) {
|
|
21
|
+
const set = (value: string | number | boolean | null | undefined) => {
|
|
22
|
+
if (!isUndefined(value) && isNull(value)) this.removeAttribute(key);
|
|
23
|
+
else this.setAttribute(key, `${value}`);
|
|
24
|
+
}
|
|
25
|
+
for (const setter of $Node.setters) {
|
|
26
|
+
const result = setter(value, set);
|
|
27
|
+
if (!isUndefined(result)) { set(result); continue keyIterate; }
|
|
28
|
+
}
|
|
29
|
+
set(value as any);
|
|
30
|
+
}
|
|
25
31
|
return this;
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -42,11 +48,13 @@ export class $Element<Ele extends Element = Element, EvMap = ElementEventMap> ex
|
|
|
42
48
|
toString() {
|
|
43
49
|
return this.outerHTML();
|
|
44
50
|
}
|
|
45
|
-
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions & { callback?: (animation: Animation) => void }) {
|
|
53
|
+
const animation = this.node.animate(keyframes, options);
|
|
54
|
+
if (!isNumber(options)) options?.callback?.(animation);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
50
58
|
|
|
51
59
|
function createNode(nodeName: string) {
|
|
52
60
|
return !_document
|
|
@@ -55,7 +63,7 @@ function createNode(nodeName: string) {
|
|
|
55
63
|
: _document.createElement(nodeName);
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
export interface $Element<Ele extends Element, EvMap> {
|
|
66
|
+
export interface $Element<Ele extends Element, EvMap = ElementEventMap> {
|
|
59
67
|
/** {@link Element.attributes} */
|
|
60
68
|
readonly attributes: NamedNodeMap;
|
|
61
69
|
/** {@link Element.clientHeight} */
|
|
@@ -191,24 +199,8 @@ export interface $Element<Ele extends Element, EvMap> {
|
|
|
191
199
|
setPointerCapture(pointerId: number): this;
|
|
192
200
|
/** {@link Element.toggleAttribute} */
|
|
193
201
|
toggleAttribute(qualifiedName: string, force?: boolean): boolean;
|
|
194
|
-
/** {@link Element.animate} */
|
|
195
|
-
animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions): Animation;
|
|
196
202
|
/** {@link Element.getAnimations} */
|
|
197
203
|
getAnimations(options?: GetAnimationsOptions): Animation[];
|
|
198
|
-
/** {@link Element.append} */
|
|
199
|
-
append(...nodes: (Node | string)[]): this;
|
|
200
|
-
/** {@link Element.prepend} */
|
|
201
|
-
prepend(...nodes: (Node | string)[]): this;
|
|
202
|
-
/** {@link Element.querySelector} */
|
|
203
|
-
querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;
|
|
204
|
-
querySelector<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;
|
|
205
|
-
querySelector<K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null;
|
|
206
|
-
/** {@link Element.querySelectorAll} */
|
|
207
|
-
querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
|
|
208
|
-
querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
|
|
209
|
-
querySelectorAll<K extends keyof MathMLElementTagNameMap>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
|
|
210
|
-
/** {@link Element.replaceChildren} */
|
|
211
|
-
replaceChildren(...nodes: (Node | string)[]): this;
|
|
212
204
|
|
|
213
205
|
/** {@link Element.classList} */
|
|
214
206
|
classList(): DOMTokenList;
|
|
@@ -371,18 +363,4 @@ export interface $Element<Ele extends Element, EvMap> {
|
|
|
371
363
|
/** {@link ARIAMixin.role} */
|
|
372
364
|
role(): string | null;
|
|
373
365
|
role(role: $Parameter<string | null>): this;
|
|
374
|
-
addEventListener<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
375
|
-
addEventListener(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
376
|
-
removeEventListener<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | EventListenerOptions): this;
|
|
377
|
-
removeEventListener(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | EventListenerOptions): this;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
on(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
381
|
-
on<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
382
|
-
|
|
383
|
-
off(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | EventListenerOptions): this;
|
|
384
|
-
off<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | EventListenerOptions): this;
|
|
385
|
-
|
|
386
|
-
once(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
387
|
-
once<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
388
366
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { forEach, isBoolean, toArray } from "@amateras/utils";
|
|
2
|
+
|
|
3
|
+
export class $EventTarget<EvMap = {}> {
|
|
4
|
+
node: EventTarget;
|
|
5
|
+
constructor(node: EventTarget) {
|
|
6
|
+
this.node = node;
|
|
7
|
+
if (node !== window) (node as Mutable<EventTarget>).$ = this;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
on(type: string | string[], listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this {
|
|
11
|
+
forEach(toArray(type), type => this.addEventListener(type, listener, options));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
off(type: string | string[], listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | EventListenerOptions): this {
|
|
16
|
+
forEach(toArray(type), type => this.removeEventListener(type, listener, options));
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
once(type: string | string[], listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this {
|
|
21
|
+
forEach(toArray(type), type => this.on(type, listener, { once: true, ...(isBoolean(options) ? { capture: options } : options ?? {}) }));
|
|
22
|
+
return this
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type $Event<E extends $EventTarget, Ev = any> = Ev & {currentTarget: {$: E}};
|
|
27
|
+
export type $EventListener<E extends $EventTarget, Ev> = (event: $Event<E, Ev>) => void;
|
|
28
|
+
export type $EventListenerObject<E extends $EventTarget, Ev> = { handleEvent(object: $Event<E, Ev>): void; }
|
|
29
|
+
|
|
30
|
+
export interface $EventTarget<EvMap = {}> {
|
|
31
|
+
/** {@link EventTarget.addEventListener} */
|
|
32
|
+
addEventListener<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
33
|
+
addEventListener(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
34
|
+
/** {@link EventTarget.removeEventListener} */
|
|
35
|
+
removeEventListener<K extends keyof EvMap, Ev extends EvMap[K]>(type: K, listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | EventListenerOptions): this;
|
|
36
|
+
removeEventListener(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | EventListenerOptions): this;
|
|
37
|
+
/** {@link EventTarget.dispatchEvent} */
|
|
38
|
+
dispatchEvent(event: Event): boolean;
|
|
39
|
+
|
|
40
|
+
on<K extends keyof EvMap, Ev extends EvMap[K]>(type: K | K[], listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
41
|
+
on(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
42
|
+
|
|
43
|
+
off<K extends keyof EvMap, Ev extends EvMap[K]>(type: K | K[], listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | EventListenerOptions): this;
|
|
44
|
+
off(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | EventListenerOptions): this;
|
|
45
|
+
|
|
46
|
+
once<K extends keyof EvMap, Ev extends EvMap[K]>(type: K | K[], listener: $EventListener<this, Ev> | $EventListenerObject<this, Ev>, options?: boolean | AddEventListenerOptions): this;
|
|
47
|
+
once(type: string, listener: $EventListener<this, Event> | $EventListenerObject<this, Event>, options?: boolean | AddEventListenerOptions): this;
|
|
48
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Object_entries, forEach } from "
|
|
1
|
+
import { _Object_entries, forEach } from "@amateras/utils";
|
|
2
2
|
import { $Element } from "#node/$Element";
|
|
3
3
|
|
|
4
4
|
export class $HTMLElement<Ele extends HTMLElement = HTMLElement, EvMap = HTMLElementEventMap> extends $Element<Ele, EvMap> {
|