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,30 @@
|
|
|
1
|
+
import { _document } from "@amateras/core/env";
|
|
2
|
+
|
|
3
|
+
const documentElementStyle = _document.documentElement.style;
|
|
4
|
+
|
|
5
|
+
export class $CSSVariable<V = string> {
|
|
6
|
+
name: string;
|
|
7
|
+
value: V;
|
|
8
|
+
constructor(key: string, value: V) {
|
|
9
|
+
this.name = key;
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set(value: string) {
|
|
14
|
+
documentElementStyle.setProperty(`${this.name}`, value);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
reset() {
|
|
19
|
+
documentElementStyle.removeProperty(`${this.name}`);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
default(value: string | $CSSVariable) {
|
|
24
|
+
return `var(${this.name}, ${value})`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toString() {
|
|
28
|
+
return `var(${this.name})`
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/dom",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/utils": "workspace:*"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"node-html-parser": "^7.0.1"
|
|
9
|
+
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#structure/*": "./src/structure/*.ts",
|
|
12
|
+
"#lib/*": "./src/lib/*.ts",
|
|
13
|
+
"#node/*": "./src/node/*.ts"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./structure/*": "./src/structure/*.ts",
|
|
17
|
+
"./lib/*": "./src/lib/*.ts",
|
|
18
|
+
"./node/*": "./src/node/*.ts"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { HTMLAbbrElement } from "#structure/html/HTMLAbbrElement";
|
|
2
|
+
import { HTMLAddressElement } from "#structure/html/HTMLAddressElement";
|
|
3
|
+
import { HTMLAnchorElement } from "#structure/html/HTMLAnchorElement";
|
|
4
|
+
import { HTMLAreaElement } from "#structure/html/HTMLAreaElement";
|
|
5
|
+
import { HTMLArticleElement } from "#structure/html/HTMLArticleElement";
|
|
6
|
+
import { HTMLAsideElement } from "#structure/html/HTMLAsideElement";
|
|
7
|
+
import { HTMLAudioElement } from "#structure/html/HTMLAudioElement";
|
|
8
|
+
import { HTMLBDIElement } from "#structure/html/HTMLBDIElement";
|
|
9
|
+
import { HTMLBDOElement } from "#structure/html/HTMLBDOElement";
|
|
10
|
+
import { HTMLBElement } from "#structure/html/HTMLBElement";
|
|
11
|
+
import { HTMLBRElement } from "#structure/html/HTMLBRElement";
|
|
12
|
+
import { HTMLBaseElement } from "#structure/html/HTMLBaseElement";
|
|
13
|
+
import { HTMLBodyElement } from "#structure/html/HTMLBodyElement";
|
|
14
|
+
import { HTMLButtonElement } from "#structure/html/HTMLButtonElement";
|
|
15
|
+
import { HTMLCanvasElement } from "#structure/html/HTMLCanvasElement";
|
|
16
|
+
import { HTMLCiteElement } from "#structure/html/HTMLCiteElement";
|
|
17
|
+
import { HTMLCodeElement } from "#structure/html/HTMLCodeElement";
|
|
18
|
+
import { HTMLDDElement } from "#structure/html/HTMLDDElement";
|
|
19
|
+
import { HTMLDFNElement } from "#structure/html/HTMLDFNElement";
|
|
20
|
+
import { HTMLDListElement } from "#structure/html/HTMLDListElement";
|
|
21
|
+
import { HTMLDTElement } from "#structure/html/HTMLDTElement";
|
|
22
|
+
import { HTMLDataElement } from "#structure/html/HTMLDataElement";
|
|
23
|
+
import { HTMLDataListElement } from "#structure/html/HTMLDataListElement";
|
|
24
|
+
import { HTMLDetailsElement } from "#structure/html/HTMLDetailsElement";
|
|
25
|
+
import { HTMLDialogElement } from "#structure/html/HTMLDialogElement";
|
|
26
|
+
import { HTMLDivElement } from "#structure/html/HTMLDivElement";
|
|
27
|
+
import { HTMLEMElement } from "#structure/html/HTMLEMElement";
|
|
28
|
+
import { HTMLEmbedElement } from "#structure/html/HTMLEmbedElement";
|
|
29
|
+
import { HTMLFieldSetElement } from "#structure/html/HTMLFieldSetElement";
|
|
30
|
+
import { HTMLFigCaptionElement } from "#structure/html/HTMLFigCaptionElement";
|
|
31
|
+
import { HTMLFigureElement } from "#structure/html/HTMLFigureElement";
|
|
32
|
+
import { HTMLFooterElement } from "#structure/html/HTMLFooterElement";
|
|
33
|
+
import { HTMLFormElement } from "#structure/html/HTMLFormElement";
|
|
34
|
+
import { HTMLHGroupElement } from "#structure/html/HTMLHGroupElement";
|
|
35
|
+
import { HTMLHRElement } from "#structure/html/HTMLHRElement";
|
|
36
|
+
import { HTMLHeadElement } from "#structure/html/HTMLHeadElement";
|
|
37
|
+
import { HTMLHeaderElement } from "#structure/html/HTMLHeaderElement";
|
|
38
|
+
import { HTMLHeadingElement } from "#structure/html/HTMLHeadingElement";
|
|
39
|
+
import { HTMLHtmlElement } from "#structure/html/HTMLHtmlElement";
|
|
40
|
+
import { HTMLIElement } from "#structure/html/HTMLIElement";
|
|
41
|
+
import { HTMLIFrameElement } from "#structure/html/HTMLIFrameElement";
|
|
42
|
+
import { HTMLImageElement } from "#structure/html/HTMLImageElement";
|
|
43
|
+
import { HTMLInputElement } from "#structure/html/HTMLInputElement";
|
|
44
|
+
import { HTMLKBDElement } from "#structure/html/HTMLKBDElement";
|
|
45
|
+
import { HTMLLIElement } from "#structure/html/HTMLLIElement";
|
|
46
|
+
import { HTMLLabelElement } from "#structure/html/HTMLLabelElement";
|
|
47
|
+
import { HTMLLegendElement } from "#structure/html/HTMLLegendElement";
|
|
48
|
+
import { HTMLLinkElement } from "#structure/html/HTMLLinkElement";
|
|
49
|
+
import { HTMLMainElement } from "#structure/html/HTMLMainElement";
|
|
50
|
+
import { HTMLMapElement } from "#structure/html/HTMLMapElement";
|
|
51
|
+
import { HTMLMarkElement } from "#structure/html/HTMLMarkElement";
|
|
52
|
+
import { HTMLMenuElement } from "#structure/html/HTMLMenuElement";
|
|
53
|
+
import { HTMLMetaElement } from "#structure/html/HTMLMetaElement";
|
|
54
|
+
import { HTMLMeterElement } from "#structure/html/HTMLMeterElement";
|
|
55
|
+
import { HTMLModElement } from "#structure/html/HTMLModElement";
|
|
56
|
+
import { HTMLNavElement } from "#structure/html/HTMLNavElement";
|
|
57
|
+
import { HTMLNoscriptElement } from "#structure/html/HTMLNoscriptElement";
|
|
58
|
+
import { HTMLOListElement } from "#structure/html/HTMLOListElement";
|
|
59
|
+
import { HTMLObjectElement } from "#structure/html/HTMLObjectElement";
|
|
60
|
+
import { HTMLOptionElement } from "#structure/html/HTMLOptionElement";
|
|
61
|
+
import { HTMLOptGroupElement } from "#structure/html/HTMLOptGroupElement";
|
|
62
|
+
import { HTMLOutputElement } from "#structure/html/HTMLOutputElement";
|
|
63
|
+
import { HTMLParagraphElement } from "#structure/html/HTMLParagraphElement";
|
|
64
|
+
import { HTMLPictureElement } from "#structure/html/HTMLPictureElement";
|
|
65
|
+
import { HTMLPreElement } from "#structure/html/HTMLPreElement";
|
|
66
|
+
import { HTMLProgressElement } from "#structure/html/HTMLProgressElement";
|
|
67
|
+
import { HTMLQuoteElement } from "#structure/html/HTMLQuoteElement";
|
|
68
|
+
import { HTMLRPElement } from "#structure/html/HTMLRPElement";
|
|
69
|
+
import { HTMLRTElement } from "#structure/html/HTMLRTElement";
|
|
70
|
+
import { HTMLRubyElement } from "#structure/html/HTMLRubyElement";
|
|
71
|
+
import { HTMLSElement } from "#structure/html/HTMLSElement";
|
|
72
|
+
import { HTMLSampElement } from "#structure/html/HTMLSampElement";
|
|
73
|
+
import { HTMLScriptElement } from "#structure/html/HTMLScriptElement";
|
|
74
|
+
import { HTMLSectionElement } from "#structure/html/HTMLSectionElement";
|
|
75
|
+
import { HTMLSelectElement } from "#structure/html/HTMLSelectElement";
|
|
76
|
+
import { HTMLSmallElement } from "#structure/html/HTMLSmallElement";
|
|
77
|
+
import { HTMLSlotElement } from "#structure/html/HTMLSlotElement";
|
|
78
|
+
import { HTMLSourceElement } from "#structure/html/HTMLSourceElement";
|
|
79
|
+
import { HTMLSpanElement } from "#structure/html/HTMLSpanElement";
|
|
80
|
+
import { HTMLStrongElement } from "#structure/html/HTMLStrongElement";
|
|
81
|
+
import { HTMLStyleElement } from "#structure/html/HTMLStyleElement";
|
|
82
|
+
import { HTMLSubElement } from "#structure/html/HTMLSubElement";
|
|
83
|
+
import { HTMLSupElement } from "#structure/html/HTMLSupElement";
|
|
84
|
+
import { HTMLSummaryElement } from "#structure/html/HTMLSummaryElement";
|
|
85
|
+
import { HTMLTableCaptionElement } from "#structure/html/HTMLTableCaptionElement";
|
|
86
|
+
import { HTMLTableCellElement } from "#structure/html/HTMLTableCellElement";
|
|
87
|
+
import { HTMLTableColElement } from "#structure/html/HTMLTableColElement";
|
|
88
|
+
import { HTMLTableElement } from "#structure/html/HTMLTableElement";
|
|
89
|
+
import { HTMLTableRowElement } from "#structure/html/HTMLTableRowElement";
|
|
90
|
+
import { HTMLTableSectionElement } from "#structure/html/HTMLTableSectionElement";
|
|
91
|
+
import { HTMLTemplateElement } from "#structure/html/HTMLTemplateElement";
|
|
92
|
+
import { HTMLTextAreaElement } from "#structure/html/HTMLTextAreaElement";
|
|
93
|
+
import { HTMLTimeElement } from "#structure/html/HTMLTimeElement";
|
|
94
|
+
import { HTMLTitleElement } from "#structure/html/HTMLTitleElement";
|
|
95
|
+
import { HTMLTrackElement } from "#structure/html/HTMLTrackElement";
|
|
96
|
+
import { HTMLUElement } from "#structure/html/HTMLUElement";
|
|
97
|
+
import { HTMLUListElement } from "#structure/html/HTMLUListElement";
|
|
98
|
+
import { HTMLVarElement } from "#structure/html/HTMLVarElement";
|
|
99
|
+
import { HTMLVideoElement } from "#structure/html/HTMLVideoElement";
|
|
100
|
+
import { HTMLWBRElement } from "#structure/html/HTMLWBRElement";
|
|
101
|
+
|
|
102
|
+
export const htmlElementMap = new Map()
|
|
103
|
+
.set('a', HTMLAnchorElement)
|
|
104
|
+
.set('abbr', HTMLAbbrElement)
|
|
105
|
+
.set('address', HTMLAddressElement)
|
|
106
|
+
.set('area', HTMLAreaElement)
|
|
107
|
+
.set('article', HTMLArticleElement)
|
|
108
|
+
.set('aside', HTMLAsideElement)
|
|
109
|
+
.set('audio', HTMLAudioElement)
|
|
110
|
+
.set('b', HTMLBElement)
|
|
111
|
+
.set('bdi', HTMLBDIElement)
|
|
112
|
+
.set('bdo', HTMLBDOElement)
|
|
113
|
+
.set('blockquote', HTMLQuoteElement)
|
|
114
|
+
.set('br', HTMLBRElement)
|
|
115
|
+
.set('base', HTMLBaseElement)
|
|
116
|
+
.set('body', HTMLBodyElement)
|
|
117
|
+
.set('button', HTMLButtonElement)
|
|
118
|
+
.set('canvas', HTMLCanvasElement)
|
|
119
|
+
.set('caption', HTMLTableCaptionElement)
|
|
120
|
+
.set('cite', HTMLCiteElement)
|
|
121
|
+
.set('code', HTMLCodeElement)
|
|
122
|
+
.set('col', HTMLTableColElement)
|
|
123
|
+
.set('colgroup', HTMLTableColElement)
|
|
124
|
+
.set('data', HTMLDataElement)
|
|
125
|
+
.set('datalist', HTMLDataListElement)
|
|
126
|
+
.set('dd', HTMLDDElement)
|
|
127
|
+
.set('del', HTMLModElement)
|
|
128
|
+
.set('details', HTMLDetailsElement)
|
|
129
|
+
.set('dfn', HTMLDFNElement)
|
|
130
|
+
.set('dialog', HTMLDialogElement)
|
|
131
|
+
.set('div', HTMLDivElement)
|
|
132
|
+
.set('dl', HTMLDListElement)
|
|
133
|
+
.set('dt', HTMLDTElement)
|
|
134
|
+
.set('em', HTMLEMElement)
|
|
135
|
+
.set('embed', HTMLEmbedElement)
|
|
136
|
+
.set('fieldset', HTMLFieldSetElement)
|
|
137
|
+
.set('figcaption', HTMLFigCaptionElement)
|
|
138
|
+
.set('figure', HTMLFigureElement)
|
|
139
|
+
.set('footer', HTMLFooterElement)
|
|
140
|
+
.set('form', HTMLFormElement)
|
|
141
|
+
.set('h1', HTMLHeadingElement)
|
|
142
|
+
.set('h2', HTMLHeadingElement)
|
|
143
|
+
.set('h3', HTMLHeadingElement)
|
|
144
|
+
.set('h4', HTMLHeadingElement)
|
|
145
|
+
.set('h5', HTMLHeadingElement)
|
|
146
|
+
.set('h6', HTMLHeadingElement)
|
|
147
|
+
.set('head', HTMLHeadElement)
|
|
148
|
+
.set('header', HTMLHeaderElement)
|
|
149
|
+
.set('hgroup', HTMLHGroupElement)
|
|
150
|
+
.set('hr', HTMLHRElement)
|
|
151
|
+
.set('html', HTMLHtmlElement)
|
|
152
|
+
.set('i', HTMLIElement)
|
|
153
|
+
.set('iframe', HTMLIFrameElement)
|
|
154
|
+
.set('img', HTMLImageElement)
|
|
155
|
+
.set('input', HTMLInputElement)
|
|
156
|
+
.set('ins', HTMLModElement)
|
|
157
|
+
.set('kbd', HTMLKBDElement)
|
|
158
|
+
.set('label', HTMLLabelElement)
|
|
159
|
+
.set('legend', HTMLLegendElement)
|
|
160
|
+
.set('li', HTMLLIElement)
|
|
161
|
+
.set('link', HTMLLinkElement)
|
|
162
|
+
.set('main', HTMLMainElement)
|
|
163
|
+
.set('map', HTMLMapElement)
|
|
164
|
+
.set('mark', HTMLMarkElement)
|
|
165
|
+
.set('menu', HTMLMenuElement)
|
|
166
|
+
.set('meta', HTMLMetaElement)
|
|
167
|
+
.set('meter', HTMLMeterElement)
|
|
168
|
+
.set('nav', HTMLNavElement)
|
|
169
|
+
.set('noscript', HTMLNoscriptElement)
|
|
170
|
+
.set('object', HTMLObjectElement)
|
|
171
|
+
.set('ol', HTMLOListElement)
|
|
172
|
+
.set('optgroup', HTMLOptGroupElement)
|
|
173
|
+
.set('option', HTMLOptionElement)
|
|
174
|
+
.set('output', HTMLOutputElement)
|
|
175
|
+
.set('p', HTMLParagraphElement)
|
|
176
|
+
.set('picture', HTMLPictureElement)
|
|
177
|
+
.set('pre', HTMLPreElement)
|
|
178
|
+
.set('progress', HTMLProgressElement)
|
|
179
|
+
.set('q', HTMLQuoteElement)
|
|
180
|
+
.set('rp', HTMLRPElement)
|
|
181
|
+
.set('rt', HTMLRTElement)
|
|
182
|
+
.set('ruby', HTMLRubyElement)
|
|
183
|
+
.set('s', HTMLSElement)
|
|
184
|
+
.set('samp', HTMLSampElement)
|
|
185
|
+
.set('script', HTMLScriptElement)
|
|
186
|
+
.set('section', HTMLSectionElement)
|
|
187
|
+
.set('select', HTMLSelectElement)
|
|
188
|
+
.set('small', HTMLSmallElement)
|
|
189
|
+
.set('slot', HTMLSlotElement)
|
|
190
|
+
.set('source', HTMLSourceElement)
|
|
191
|
+
.set('span', HTMLSpanElement)
|
|
192
|
+
.set('strong', HTMLStrongElement)
|
|
193
|
+
.set('style', HTMLStyleElement)
|
|
194
|
+
.set('sub', HTMLSubElement)
|
|
195
|
+
.set('summary', HTMLSummaryElement)
|
|
196
|
+
.set('sup', HTMLSupElement)
|
|
197
|
+
.set('table', HTMLTableElement)
|
|
198
|
+
.set('tbody', HTMLTableSectionElement)
|
|
199
|
+
.set('td', HTMLTableCellElement)
|
|
200
|
+
.set('template', HTMLTemplateElement)
|
|
201
|
+
.set('textarea', HTMLTextAreaElement)
|
|
202
|
+
.set('tfoot', HTMLTableSectionElement)
|
|
203
|
+
.set('th', HTMLTableCellElement)
|
|
204
|
+
.set('thead', HTMLTableSectionElement)
|
|
205
|
+
.set('time', HTMLTimeElement)
|
|
206
|
+
.set('title', HTMLTitleElement)
|
|
207
|
+
.set('tr', HTMLTableRowElement)
|
|
208
|
+
.set('track', HTMLTrackElement)
|
|
209
|
+
.set('u', HTMLUElement)
|
|
210
|
+
.set('ul', HTMLUListElement)
|
|
211
|
+
.set('var', HTMLVarElement)
|
|
212
|
+
.set('video', HTMLVideoElement)
|
|
213
|
+
.set('wbr', HTMLWBRElement)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Element } from "#structure/Element"
|
|
2
|
+
import { _Object_assign, _Object_defineProperty, _Object_entries, forEach } from "@amateras/utils"
|
|
3
|
+
|
|
4
|
+
export const assignAttributes = (target: any, props: {[key: string]: any}) => {
|
|
5
|
+
forEach(_Object_entries(props), ([name]) => {
|
|
6
|
+
_Object_defineProperty(target.prototype, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get(this: Element) {
|
|
9
|
+
return this.getAttribute(name)
|
|
10
|
+
},
|
|
11
|
+
set(this: Element, value: any) {
|
|
12
|
+
this.setAttribute(name, value);
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { _Object_assign, forEach } from "@amateras/utils";
|
|
2
|
+
|
|
3
|
+
export class DOMTokenList extends Set {
|
|
4
|
+
constructor(tokens?: string[]) {
|
|
5
|
+
super(tokens);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
add(...tokens: string[]) {
|
|
9
|
+
forEach(tokens, token => super.add(token));
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
remove(...tokens: string[]) {
|
|
14
|
+
forEach(tokens, token => super.delete(token));
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_Object_assign(globalThis, { DOMTokenList })
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { _Object_assign } from "@amateras/utils"
|
|
2
|
+
import { Node } from "./Node";
|
|
3
|
+
import { HTMLElement } from "./HTMLElement";
|
|
4
|
+
import { htmlElementMap } from "#lib/HTMLElementMap";
|
|
5
|
+
import { Text } from "./Text";
|
|
6
|
+
|
|
7
|
+
export class Document extends Node {
|
|
8
|
+
adoptedStyleSheets = [];
|
|
9
|
+
documentElement = this.createElement('html');
|
|
10
|
+
head = this.createElement('head');
|
|
11
|
+
body = this.createElement('body');
|
|
12
|
+
#ele_title: null | HTMLElement = null;
|
|
13
|
+
constructor() {
|
|
14
|
+
super('#document');
|
|
15
|
+
this.appendChild(this.documentElement);
|
|
16
|
+
this.documentElement.appendChild(this.head);
|
|
17
|
+
this.documentElement.appendChild(this.body);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
createElement(nodeName: string): HTMLElement {
|
|
21
|
+
const constructor = htmlElementMap.get(nodeName);
|
|
22
|
+
if (constructor) return new constructor();
|
|
23
|
+
return new HTMLElement(nodeName)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set title(title: string) {
|
|
27
|
+
if (title.length) {
|
|
28
|
+
this.#ele_title?.remove();
|
|
29
|
+
this.#ele_title = this.createElement('title');
|
|
30
|
+
this.#ele_title.appendChild(new Text(title))
|
|
31
|
+
this.head.appendChild(this.#ele_title);
|
|
32
|
+
} else this.#ele_title?.remove();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_Object_assign(globalThis, { Document })
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { _Array_from, _Object_assign, _Object_entries, forEach, isArray, isString, isUndefined } from "@amateras/utils";
|
|
2
|
+
import { Node } from "./Node";
|
|
3
|
+
import { DOMTokenList } from "./DOMTokenList";
|
|
4
|
+
import { assignAttributes } from "#lib/assignAttributes";
|
|
5
|
+
import { Text } from "./Text";
|
|
6
|
+
import { HTMLElement as ParserHTMLElement, Node as ParserNode, TextNode, parse as htmlParse } from 'node-html-parser';
|
|
7
|
+
import type { Document } from "./Document";
|
|
8
|
+
|
|
9
|
+
export class Element extends Node {
|
|
10
|
+
#attributes = new Map<string, any>();
|
|
11
|
+
#classList = new DOMTokenList();
|
|
12
|
+
readonly tagname: string
|
|
13
|
+
|
|
14
|
+
static defaultAttributes = {
|
|
15
|
+
id: ''
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(nodeName: string) {
|
|
19
|
+
super(nodeName.toUpperCase())
|
|
20
|
+
this.tagname = nodeName.toUpperCase();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get attributes() {
|
|
24
|
+
return _Array_from(this.#attributes).map(([name, value]) => ({name, value}))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get innerHTML() {
|
|
28
|
+
const children = _Array_from(this.childNodes).map(node => node.toString());
|
|
29
|
+
return children.join('');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set innerHTML(html: string) {
|
|
33
|
+
const element = htmlParse(html);
|
|
34
|
+
const createChildElement = (target: Node, ele: ParserNode) => {
|
|
35
|
+
forEach(element.childNodes, node => {
|
|
36
|
+
if (node instanceof TextNode) target.appendChild(new Text(node.textContent));
|
|
37
|
+
const ele = (document as unknown as Document).createElement(node.rawTagName);
|
|
38
|
+
if (node instanceof ParserHTMLElement) {
|
|
39
|
+
forEach(Object.entries(node.attributes), ([key, value]) => ele.setAttribute(key, value))
|
|
40
|
+
}
|
|
41
|
+
target.appendChild(ele);
|
|
42
|
+
createChildElement(ele, node);
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
createChildElement(this, element);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get outerHTML() {
|
|
50
|
+
const nodeName = this.nodeName.toLowerCase();
|
|
51
|
+
const attr = _Array_from(this.attributes).map(({name, value}) => {
|
|
52
|
+
//@ts-expect-error
|
|
53
|
+
const defaultValue = this.constructor.defaultAttributes[name];
|
|
54
|
+
if (isArray(defaultValue)) value = defaultValue[value ? 1 : 2];
|
|
55
|
+
return `${name}${isString(value) && value ? `="${value}"` : ``}`;
|
|
56
|
+
})
|
|
57
|
+
const IS_SELF_CLOSING = ['img', 'meta', 'input'].includes(nodeName);
|
|
58
|
+
this.#classList.size && attr.unshift(`class="${_Array_from(this.classList).join(' ')}"`)
|
|
59
|
+
return `<${nodeName}${attr.length ? ` ${attr.join(' ')}` : ''}>${this.innerHTML}${IS_SELF_CLOSING ? '' : `</${nodeName}>`}`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set outerHTML(html: string) {
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
toString() {
|
|
67
|
+
return this.outerHTML;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setAttribute(key: string, value: string) {
|
|
71
|
+
this.#attributes.set(key, value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getAttribute(key: string) {
|
|
75
|
+
const value = this.#attributes.get(key)
|
|
76
|
+
if (!isUndefined(value)) return value;
|
|
77
|
+
//@ts-expect-error
|
|
78
|
+
const defaultValue = this.constructor.defaultAttributes[key];
|
|
79
|
+
if (isArray(defaultValue)) return defaultValue[0]
|
|
80
|
+
return defaultValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get classList(): DOMTokenList {
|
|
84
|
+
return this.#classList
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
set classList(tokens: string) {
|
|
88
|
+
this.#classList = new DOMTokenList(tokens.split(' '));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
set textContent(text: string) {
|
|
92
|
+
forEach(this.childNodes, node => node.remove());
|
|
93
|
+
this.appendChild(new Text(text));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get textContent() {
|
|
97
|
+
const strings = _Array_from(this.childNodes).map(node => {
|
|
98
|
+
if (node instanceof Text) return node.textContent;
|
|
99
|
+
else if (node instanceof Element) return node.textContent;
|
|
100
|
+
})
|
|
101
|
+
return strings.join('')
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
assignAttributes(Element, Element.defaultAttributes)
|
|
106
|
+
_Object_assign(globalThis, { Element })
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { _Array_from, _Object_assign, _Object_entries } from "@amateras/utils";
|
|
2
|
+
import { Element } from "./Element";
|
|
3
|
+
import { assignAttributes } from "#lib/assignAttributes";
|
|
4
|
+
|
|
5
|
+
export class HTMLElement extends Element {
|
|
6
|
+
#style: Partial<CSSStyleDeclaration> = {}
|
|
7
|
+
|
|
8
|
+
static defaultAttributes = {
|
|
9
|
+
...Element.defaultAttributes,
|
|
10
|
+
autocapitalize: false,
|
|
11
|
+
dir: '',
|
|
12
|
+
draggable: false,
|
|
13
|
+
hidden: false,
|
|
14
|
+
inert: [false, ''],
|
|
15
|
+
lang: '',
|
|
16
|
+
popover: null,
|
|
17
|
+
spellcheck: true,
|
|
18
|
+
title: '',
|
|
19
|
+
translate: [true, 'yes', 'no'],
|
|
20
|
+
writingSuggestions: 'true',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get attributes() {
|
|
24
|
+
const style = _Object_entries(this.#style).filter(([_, value]) => value).map(([key, value]) => `${key}:${value}`).join(';')
|
|
25
|
+
const attrs = super.attributes;
|
|
26
|
+
if (style) attrs.push({name: 'style', value: style})
|
|
27
|
+
return attrs
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get style() { return this.#style }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
assignAttributes(HTMLElement, HTMLElement.defaultAttributes)
|
|
34
|
+
_Object_assign(globalThis, { HTMLElement })
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { _Array_from, _null, _Object_assign, isUndefined } from "@amateras/utils";
|
|
2
|
+
import { NodeList } from "./NodeList";
|
|
3
|
+
|
|
4
|
+
export class Node extends EventTarget {
|
|
5
|
+
readonly nodeName: string
|
|
6
|
+
constructor(nodeName: string) {
|
|
7
|
+
super();
|
|
8
|
+
this.nodeName = nodeName;
|
|
9
|
+
}
|
|
10
|
+
#childNodes = new NodeList();
|
|
11
|
+
get childNodes() { return this.#childNodes }
|
|
12
|
+
|
|
13
|
+
parentElement: null | Node = _null;
|
|
14
|
+
|
|
15
|
+
appendChild(node: Node) {
|
|
16
|
+
this.#childNodes.delete(node);
|
|
17
|
+
this.#childNodes.add(node);
|
|
18
|
+
node.parentElement = this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
insertBefore(node: Node, target: Node) {
|
|
22
|
+
this.#childNodes.delete(node);
|
|
23
|
+
const nodeList = _Array_from(this.childNodes);
|
|
24
|
+
const index = nodeList.indexOf(target);
|
|
25
|
+
if (isUndefined(target) || index === -1) this.appendChild(node);
|
|
26
|
+
else {
|
|
27
|
+
this.#childNodes = new NodeList([...nodeList.slice(0, index - 1), node, ...nodeList.slice(index)]);
|
|
28
|
+
node.parentElement = this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
remove() {
|
|
33
|
+
this.parentElement?.childNodes.delete(this);
|
|
34
|
+
this.parentElement = _null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
contains(node: Node) {
|
|
38
|
+
for (const childNode of this.#childNodes) {
|
|
39
|
+
if (node === childNode) return true;
|
|
40
|
+
else if (node.contains(node)) return true;
|
|
41
|
+
}
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toString() {}
|
|
46
|
+
|
|
47
|
+
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void {}
|
|
48
|
+
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_Object_assign(globalThis, { Node })
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { _Object_assign } from "@amateras/utils";
|
|
2
|
+
import { Node } from "./Node";
|
|
3
|
+
|
|
4
|
+
export class Text extends Node {
|
|
5
|
+
#textContent: string;
|
|
6
|
+
constructor(str: string) {
|
|
7
|
+
super('#text');
|
|
8
|
+
this.#textContent = str;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get textContent() {
|
|
12
|
+
return this.#textContent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
toString() {
|
|
16
|
+
return this.#textContent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_Object_assign(globalThis, { Text })
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Document } from "./Document";
|
|
2
|
+
import { History } from "./History";
|
|
3
|
+
import { Location } from "./Location";
|
|
4
|
+
import { Storage } from "./Storage";
|
|
5
|
+
|
|
6
|
+
export class Window extends EventTarget {
|
|
7
|
+
document = new Document();
|
|
8
|
+
location = new Location();
|
|
9
|
+
history = new History();
|
|
10
|
+
sessionStorage = new Storage();
|
|
11
|
+
localStorage = new Storage();
|
|
12
|
+
|
|
13
|
+
scrollTo = () => {}
|
|
14
|
+
}
|
|
@@ -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 HTMLAbbrElement extends HTMLElement {
|
|
6
|
+
static defaultAttributes = {
|
|
7
|
+
...HTMLElement.defaultAttributes
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super('abbr')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
assignAttributes(HTMLAbbrElement, HTMLAbbrElement.defaultAttributes)
|
|
16
|
+
_Object_assign(globalThis, { HTMLAbbrElement })
|
|
@@ -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 HTMLAddressElement extends HTMLElement {
|
|
6
|
+
static defaultAttributes = {
|
|
7
|
+
...HTMLElement.defaultAttributes
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super('address')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
assignAttributes(HTMLAddressElement, HTMLAddressElement.defaultAttributes)
|
|
16
|
+
_Object_assign(globalThis, { HTMLAddressElement })
|