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,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/idb",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/signal": "workspace:*",
|
|
6
|
+
"@amateras/utils": "workspace:*"
|
|
7
|
+
},
|
|
8
|
+
"imports": {
|
|
9
|
+
"#structure/*": "./src/structure/*.ts",
|
|
10
|
+
"#lib/*": "./src/lib/*.ts",
|
|
11
|
+
"#node/*": "./src/node/*.ts"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.ts",
|
|
15
|
+
"./structure/*": "./src/structure/*.ts",
|
|
16
|
+
"./lib/*": "./src/lib/*.ts",
|
|
17
|
+
"./node/*": "./src/node/*.ts"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _Object_assign } from "amateras/
|
|
1
|
+
import { _Object_assign } from "@amateras/utils"
|
|
2
2
|
import { $IDBBuilder } from "#structure/builder/$IDBBuilder"
|
|
3
3
|
|
|
4
|
-
declare module 'amateras/core' {
|
|
4
|
+
declare module '@amateras/core' {
|
|
5
5
|
export namespace $ {
|
|
6
6
|
/**
|
|
7
7
|
* Create {@link $IDBBuilder} with IDB name and version number.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Promise } from "
|
|
1
|
+
import { _Promise } from "@amateras/utils";
|
|
2
2
|
|
|
3
3
|
export const $IDBRequest = <T>(req: IDBRequest<T>, handle?: (req: IDBRequest<T>, resolve: (value: T) => void) => void) => {
|
|
4
4
|
return new _Promise<T>((resolve, reject) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Array_from, _null, _Object_assign, _Object_fromEntries, _Promise, isBoolean } from "amateras/
|
|
1
|
+
import { _Array_from, _null, _Object_assign, _Object_fromEntries, _Promise, isBoolean } from "@amateras/utils";
|
|
2
2
|
import { $IDBStore, type $IDBStoreConfig } from "./$IDBStore";
|
|
3
3
|
import { $IDBTransaction } from "./$IDBTransaction";
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _instanceof, _Object_assign, _Promise } from "amateras/
|
|
1
|
+
import { _instanceof, _Object_assign, _Promise } from "@amateras/utils";
|
|
2
2
|
import { $IDBRequest } from "#lib/$IDBRequest";
|
|
3
3
|
import { $IDBStore, type $IDBStoreConfig } from "./$IDBStore";
|
|
4
4
|
import { $IDBIndex } from "./$IDBIndex";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Object_assign } from "amateras/
|
|
1
|
+
import { _Object_assign } from "@amateras/utils";
|
|
2
2
|
import type { $IDBStore, $IDBStoreConfig, QueryMultipleKeyPath } from "./$IDBStore";
|
|
3
3
|
import { $IDBStoreBase } from "./$IDBStoreBase";
|
|
4
4
|
import type { $IDBCursor } from "./$IDBCursor";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _instanceof, _Object_assign, _Promise } from "amateras/
|
|
1
|
+
import { _instanceof, _Object_assign, _Promise } from "@amateras/utils";
|
|
2
2
|
import { $IDBIndex, type $IDBIndexConfig } from "./$IDBIndex";
|
|
3
3
|
import { $IDBRequest } from "#lib/$IDBRequest";
|
|
4
4
|
import { $IDBStoreBase } from "./$IDBStoreBase";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { $IDB, type $IDBConfig } from "#structure/$IDB";
|
|
2
|
-
import { _Array_from, _instanceof, _JSON_stringify, _null, _Object_assign, _Object_fromEntries, _Promise, forEach, isFunction } from "amateras/
|
|
2
|
+
import { _Array_from, _instanceof, _JSON_stringify, _null, _Object_assign, _Object_fromEntries, _Promise, forEach, isFunction, trycatch } from "@amateras/utils";
|
|
3
3
|
import { $IDBStoreBuilder } from "./$IDBStoreBuilder";
|
|
4
4
|
import type { $IDBIndexConfig } from "#structure/$IDBIndex";
|
|
5
5
|
import type { $IDBStoreConfig } from "#structure/$IDBStore";
|
|
6
|
-
import { trycatch } from "amateras/lib/trycatch";
|
|
7
6
|
// optimizer variables
|
|
8
7
|
const objectStoreNames = 'objectStoreNames';
|
|
9
8
|
const deleteObjectStore = 'deleteObjectStore';
|
|
@@ -84,7 +83,7 @@ export class $IDBBuilder<Config extends $IDBConfig = { name: string, stores: {},
|
|
|
84
83
|
const initialCreateDB = () => {
|
|
85
84
|
debug(`No IDB detected, create IDB`);
|
|
86
85
|
const {transaction, result: idb} = initDBRequest;
|
|
87
|
-
forEach(storeMap, (
|
|
86
|
+
forEach(storeMap, ([name, storeBuilder]) => {
|
|
88
87
|
createStoresMap.set(name, storeBuilder);
|
|
89
88
|
createIndexMap.set(storeBuilder, new Map(storeBuilder.indexes))
|
|
90
89
|
})
|
|
@@ -108,11 +107,11 @@ export class $IDBBuilder<Config extends $IDBConfig = { name: string, stores: {},
|
|
|
108
107
|
// get unused stores
|
|
109
108
|
transaction && forEach(_Array_from(transaction[objectStoreNames]), name => storeMap.has(name) && unusedStoreNameList.push(name))
|
|
110
109
|
// check store config matches
|
|
111
|
-
forEach(storeMap, (
|
|
110
|
+
forEach(storeMap, ([storeName, storeBuilder]) => {
|
|
112
111
|
const {keyPath, autoIncrement} = storeBuilder.config;
|
|
113
112
|
const indexMap = new Map();
|
|
114
113
|
const checkIndexes = () =>
|
|
115
|
-
forEach(storeBuilder.indexes, (
|
|
114
|
+
forEach(storeBuilder.indexes, ([indexName, indexBuilder]) => {
|
|
116
115
|
const [index] = trycatch(() => store?.index(indexName));
|
|
117
116
|
const CONFIG_CHANGED = _JSON_stringify(indexBuilder.keyPath) !== _JSON_stringify(index?.keyPath)
|
|
118
117
|
|| !!indexBuilder.multiEntry !== index?.multiEntry
|
|
@@ -182,20 +181,20 @@ export class $IDBBuilder<Config extends $IDBConfig = { name: string, stores: {},
|
|
|
182
181
|
/** 'versionchange' type transaction */
|
|
183
182
|
const transaction = req.transaction as IDBTransaction;
|
|
184
183
|
// create stores
|
|
185
|
-
forEach(createStoresMap, ({config}
|
|
184
|
+
forEach(createStoresMap, ([name, {config}]) => {
|
|
186
185
|
idb[createObjectStore](name, config);
|
|
187
186
|
debug(`Store Created: ${name}`);
|
|
188
187
|
});
|
|
189
188
|
// upgrade stores
|
|
190
|
-
forEach(upgradeStoreMap, ({config}
|
|
189
|
+
forEach(upgradeStoreMap, ([name, {config}]) => {
|
|
191
190
|
idb[deleteObjectStore](name);
|
|
192
191
|
idb[createObjectStore](name, config);
|
|
193
192
|
debug(`Store Upgraded: ${name}`);
|
|
194
193
|
})
|
|
195
194
|
// create indexes
|
|
196
|
-
forEach(createIndexMap, (
|
|
195
|
+
forEach(createIndexMap, ([{config: {name}}, indexMap]) => {
|
|
197
196
|
const store = transaction.objectStore(name);
|
|
198
|
-
forEach(indexMap, ({keyPath, ...config}
|
|
197
|
+
forEach(indexMap, ([indexName, {keyPath, ...config}]) => {
|
|
199
198
|
// if indexes existed, delete and create again
|
|
200
199
|
if (store.indexNames.contains(indexName)) store.deleteIndex(indexName);
|
|
201
200
|
store.createIndex(indexName, keyPath, config);
|
|
@@ -208,7 +207,7 @@ export class $IDBBuilder<Config extends $IDBConfig = { name: string, stores: {},
|
|
|
208
207
|
debug(`Unused Store Deleted: ${name}`);
|
|
209
208
|
});
|
|
210
209
|
// open db again for insert objects
|
|
211
|
-
forEach(cachedObjectMap, (
|
|
210
|
+
forEach(cachedObjectMap, ([storeName, objectList]) => {
|
|
212
211
|
const store = transaction.objectStore(storeName);
|
|
213
212
|
forEach(objectList, ({key, value}) => {
|
|
214
213
|
if (store.autoIncrement || store.keyPath) store.add(value);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# amateras/markdown
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
```ts
|
|
5
|
+
import { Markdown } from 'amateras/markdown';
|
|
6
|
+
|
|
7
|
+
const markdown = new Markdown();
|
|
8
|
+
|
|
9
|
+
markdown.parseHTML('# Title'); // => <h1>Title</h1>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Add Custom Markdown Rules
|
|
13
|
+
```ts
|
|
14
|
+
markdown.lexer.blockTokenizers.set('CUSTOM_TYPE', {
|
|
15
|
+
regex: /#! (.+)/,
|
|
16
|
+
handle: matches => {
|
|
17
|
+
content: lexer.inlineTokenize(matches[1]!)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
markdown.parser.processors.set('CUSTOM_TYPE', token => {
|
|
22
|
+
return `<custom>${markdown.parser.parse(token.content!)}</custom>`
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Import Syntax
|
|
27
|
+
```ts
|
|
28
|
+
import { MarkdownParser, MarkdownLexer } from 'amateras/markdown';
|
|
29
|
+
import { blockquoteProcessor, blockquoteTokenizer } from 'amateras/markdown/syntax/blockquote';
|
|
30
|
+
import { headingProcessor, headingTokenizer } from 'amateras/markdown/syntax/heading';
|
|
31
|
+
|
|
32
|
+
const lexer = new MarkdownLexer();
|
|
33
|
+
const parser = new MarkdownParser();
|
|
34
|
+
|
|
35
|
+
lexer.use(
|
|
36
|
+
blockquoteTokenizer,
|
|
37
|
+
headingTokenizer
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
parser.use(
|
|
41
|
+
blockquoteProcessor,
|
|
42
|
+
headingProcessor
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
function parseHTML(str: string) {
|
|
46
|
+
const tokens = lexer.blockTokenize(str);
|
|
47
|
+
return parser.parse(tokens);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
parseHTML('# Title') // => <h1>Title</h1>
|
|
51
|
+
parseHTML('> This is Blockquote') // => <blockquote>This is Blockquote</blockquote>
|
|
52
|
+
parseHTML('- List') // => - List
|
|
53
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/markdown",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/utils": "workspace:*"
|
|
6
|
+
},
|
|
7
|
+
"imports": {
|
|
8
|
+
"#structure/*": "./src/structure/*.ts",
|
|
9
|
+
"#lib/*": "./src/lib/*.ts",
|
|
10
|
+
"#node/*": "./src/node/*.ts"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.ts",
|
|
14
|
+
"./structure/*": "./src/structure/*.ts",
|
|
15
|
+
"./lib/*": "./src/lib/*.ts",
|
|
16
|
+
"./node/*": "./src/node/*.ts",
|
|
17
|
+
"./syntax/*": "./src/syntax/*.ts"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const INLINE = 'INLINE';
|
|
2
|
+
export const BLOCK = 'BLOCK';
|
|
3
|
+
export const TEXT = 'TEXT';
|
|
4
|
+
export const IMAGE = 'IMAGE';
|
|
5
|
+
export const LINK = 'LINK';
|
|
6
|
+
export const QUICK_LINK = 'QUICK_LINK';
|
|
7
|
+
export const CODE = 'CODE';
|
|
8
|
+
export const ITALIC = 'ITALIC';
|
|
9
|
+
export const BOLD = 'BOLD';
|
|
10
|
+
export const TEXT_LINE = 'TEXT_LINE';
|
|
11
|
+
export const HEADING = 'HEADING';
|
|
12
|
+
export const CODE_START = 'CODE_START';
|
|
13
|
+
export const CODE_LINE = 'CODE_LINE';
|
|
14
|
+
export const CODE_END = 'CODE_END';
|
|
15
|
+
export const UNORDERED_LIST_ITEM = 'UNORDERED_LIST_ITEM';
|
|
16
|
+
export const ORDERED_LIST_ITEM = 'ORDERED_LIST_ITEM';
|
|
17
|
+
export const BLOCKQUOTE = 'BLOCKQUOTE';
|
|
18
|
+
export const ALERT = 'ALERT';
|
|
19
|
+
export const ALERT_LINE = 'ALERT_LINE';
|
|
20
|
+
export const HORIZONTAL_RULE = 'HORIZONTAL_RULE';
|
|
21
|
+
export const TABLE = 'TABLE';
|
|
22
|
+
export const TABLE_ROW = 'TABLE_ROW';
|
|
23
|
+
export const TABLE_COLUMN = 'TABLE_COLUMN';
|
|
24
|
+
export const EMPTY_LINE = 'EMPTY_LINE'
|
|
25
|
+
export const INLINE_TEXT = "INLINE_TEXT";
|
|
26
|
+
export const INLINE_CONTENT = "INLINE_CONTENT"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BlockTokenizer, InlineTokenizer, MarkdownLexer } from "#structure/MarkdownLexer";
|
|
2
|
+
import type { MarkdownParseProcessor, MarkdownParser } from "#structure/MarkdownParser";
|
|
3
|
+
import { forEach } from "@amateras/utils";
|
|
4
|
+
|
|
5
|
+
export const setBlockTokenizer = (lexer: MarkdownLexer, type: string, tokenizer: BlockTokenizer) => lexer.blockTokenizers.set(type, tokenizer);
|
|
6
|
+
export const setInlineTokenizer = (lexer: MarkdownLexer, type: string, tokenizer: InlineTokenizer) => lexer.inlineTokenizers.set(type, tokenizer);
|
|
7
|
+
|
|
8
|
+
export const setProcessor = (parser: MarkdownParser, type: string, processor: MarkdownParseProcessor) => parser.processors.set(type, processor);
|
|
9
|
+
|
|
10
|
+
export const htmltag = (tagname: string, content: string) => `<${tagname}>${content}</${tagname}>`
|
|
11
|
+
|
|
12
|
+
export const htmlEscapeChar = (str: string) => {
|
|
13
|
+
forEach([
|
|
14
|
+
['&', '&'],
|
|
15
|
+
['<', '<'],
|
|
16
|
+
['>', '>'],
|
|
17
|
+
['"', '"'],
|
|
18
|
+
["'", ''']
|
|
19
|
+
] as [string, string][], group => str = str.replaceAll(...group))
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { alertProcessor, alertTokenizer } from "../syntax/alert";
|
|
2
|
+
import { blockquoteProcessor, blockquoteTokenizer } from "../syntax/blockquote";
|
|
3
|
+
import { boldProcessor, boldTokenizer } from "../syntax/bold";
|
|
4
|
+
import { codeProcessor, codeTokenizer } from "../syntax/code";
|
|
5
|
+
import { codeblockProcessor, codeblockTokenizer } from "../syntax/codeblock";
|
|
6
|
+
import { headingProcessor, headingTokenizer } from "../syntax/heading";
|
|
7
|
+
import { horizontalRuleProcessor, horizontalRuleTokenizer } from "../syntax/horizontalRule";
|
|
8
|
+
import { imageProcessor, imageTokenizer } from "../syntax/image";
|
|
9
|
+
import { italicProcessor, italicTokenizer } from "../syntax/italic";
|
|
10
|
+
import { linkProcessor, linkTokenizer } from "../syntax/link";
|
|
11
|
+
import { listProcessor, listTokenizer } from "../syntax/list";
|
|
12
|
+
import { textLineProcessor, textProcessor } from "../syntax/text";
|
|
13
|
+
import { MarkdownLexer } from "./MarkdownLexer";
|
|
14
|
+
import { MarkdownParser } from "./MarkdownParser";
|
|
15
|
+
|
|
16
|
+
export class Markdown {
|
|
17
|
+
lexer = new MarkdownLexer();
|
|
18
|
+
parser = new MarkdownParser();
|
|
19
|
+
constructor() {
|
|
20
|
+
this.lexer.use(
|
|
21
|
+
headingTokenizer,
|
|
22
|
+
codeblockTokenizer,
|
|
23
|
+
listTokenizer,
|
|
24
|
+
alertTokenizer,
|
|
25
|
+
blockquoteTokenizer,
|
|
26
|
+
horizontalRuleTokenizer,
|
|
27
|
+
imageTokenizer, // image tokenizer must before link
|
|
28
|
+
linkTokenizer, // link tokenizer must before bold and italic and code
|
|
29
|
+
codeTokenizer,
|
|
30
|
+
boldTokenizer,
|
|
31
|
+
italicTokenizer,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
this.parser.use(
|
|
35
|
+
textProcessor,
|
|
36
|
+
imageProcessor,
|
|
37
|
+
linkProcessor,
|
|
38
|
+
codeProcessor,
|
|
39
|
+
italicProcessor,
|
|
40
|
+
boldProcessor,
|
|
41
|
+
textLineProcessor,
|
|
42
|
+
headingProcessor,
|
|
43
|
+
codeblockProcessor,
|
|
44
|
+
listProcessor,
|
|
45
|
+
alertProcessor,
|
|
46
|
+
blockquoteProcessor,
|
|
47
|
+
horizontalRuleProcessor
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parseHTML(str: string) {
|
|
52
|
+
return this.parser.parse(this.lexer.blockTokenize(str));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BLOCK, EMPTY_LINE, INLINE_CONTENT, INLINE_TEXT, TEXT_LINE } from "#lib/type";
|
|
2
|
+
import { forEach, isString } from "@amateras/utils";
|
|
3
|
+
|
|
4
|
+
export class MarkdownLexer {
|
|
5
|
+
blockTokenizers = new Map<string, BlockTokenizer>();
|
|
6
|
+
inlineTokenizers = new Map<string, InlineTokenizer>();
|
|
7
|
+
|
|
8
|
+
blockTokenize(str: string) {
|
|
9
|
+
const lines = str?.split(/\r?\n/) ?? [];
|
|
10
|
+
const tokens: BlockToken[] = [];
|
|
11
|
+
let lineIndex = 0;
|
|
12
|
+
lineLoop: while (lineIndex < lines.length) {
|
|
13
|
+
let line = lines[lineIndex];
|
|
14
|
+
if (line === undefined) throw 'LINE ERROR';
|
|
15
|
+
let token: BlockToken | undefined;
|
|
16
|
+
for (const [type, tokenizer] of this.blockTokenizers) {
|
|
17
|
+
const matched = line.match(tokenizer.regex);
|
|
18
|
+
if (matched) {
|
|
19
|
+
const {content, multiLine, data} = tokenizer.handle(matched, lineIndex, lines);
|
|
20
|
+
token = { layout: BLOCK, type, content, data }
|
|
21
|
+
if (multiLine) {
|
|
22
|
+
tokens.push(token);
|
|
23
|
+
tokens.push(...multiLine.tokens)
|
|
24
|
+
lineIndex = multiLine.skip;
|
|
25
|
+
continue lineLoop;
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!token) token = {
|
|
31
|
+
layout: BLOCK,
|
|
32
|
+
...(
|
|
33
|
+
line.length
|
|
34
|
+
? { type: TEXT_LINE, content: this.inlineTokenize(line) }
|
|
35
|
+
: { type: EMPTY_LINE, content: [] }
|
|
36
|
+
)
|
|
37
|
+
};
|
|
38
|
+
tokens.push(token);
|
|
39
|
+
lineIndex++;
|
|
40
|
+
}
|
|
41
|
+
return tokens;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
inlineTokenize(str: string): InlineToken[] {
|
|
45
|
+
const tokens: InlineToken[] = [];
|
|
46
|
+
let remainStr = str;
|
|
47
|
+
while (remainStr.length) {
|
|
48
|
+
let token: InlineToken | undefined;
|
|
49
|
+
for (const [type, tokenizer] of this.inlineTokenizers) {
|
|
50
|
+
const matched = remainStr.match(tokenizer.regex);
|
|
51
|
+
if (matched) {
|
|
52
|
+
const {index, 0: matchStr} = matched;
|
|
53
|
+
// handle before matched string
|
|
54
|
+
if (index != 0) tokens.push(...this.inlineTokenize(remainStr.substring(0, index)));
|
|
55
|
+
// handle matched string
|
|
56
|
+
const {content, data} = tokenizer.handle(matched);
|
|
57
|
+
token = { type, ...(isString(content) ? { layout: INLINE_TEXT, text: content } : { layout: INLINE_CONTENT, content })};
|
|
58
|
+
if (data) token.data = data;
|
|
59
|
+
remainStr = remainStr.substring(index! + matchStr.length);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!token) {
|
|
64
|
+
token = { type: 'TEXT', layout: INLINE_TEXT, text: remainStr };
|
|
65
|
+
remainStr = '';
|
|
66
|
+
}
|
|
67
|
+
tokens.push(token);
|
|
68
|
+
}
|
|
69
|
+
return tokens;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
use(...handle: ((parser: this) => void)[]) {
|
|
73
|
+
forEach(handle, fn => fn(this));
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type BlockTokenizer = {
|
|
79
|
+
regex: RegExp;
|
|
80
|
+
handle: (matches: RegExpMatchArray, position: number, lines: string[]) => { content: (InlineToken | BlockToken)[], multiLine?: BlockTokenizerMultiLine, data?: {[key: string]: any} };
|
|
81
|
+
}
|
|
82
|
+
export type BlockTokenizerMultiLine = {
|
|
83
|
+
skip: number;
|
|
84
|
+
tokens: BlockToken[];
|
|
85
|
+
}
|
|
86
|
+
export type InlineTokenizer = {
|
|
87
|
+
regex: RegExp;
|
|
88
|
+
handle: (matches: RegExpMatchArray) => { content: InlineToken[] | string, data?: {[key: string]: any} }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface TokenBase {
|
|
92
|
+
type: string;
|
|
93
|
+
layout: 'BLOCK' | 'INLINE_CONTENT' | 'INLINE_TEXT';
|
|
94
|
+
content?: Token[];
|
|
95
|
+
text?: string;
|
|
96
|
+
data?: {[key: string]: any};
|
|
97
|
+
}
|
|
98
|
+
export interface BlockToken extends TokenBase {
|
|
99
|
+
layout: 'BLOCK'
|
|
100
|
+
content: Token[];
|
|
101
|
+
}
|
|
102
|
+
export interface InlineTextToken extends TokenBase {
|
|
103
|
+
layout: 'INLINE_TEXT'
|
|
104
|
+
text: string;
|
|
105
|
+
}
|
|
106
|
+
export interface InlineContentToken extends TokenBase {
|
|
107
|
+
layout: 'INLINE_CONTENT'
|
|
108
|
+
content: (InlineToken)[];
|
|
109
|
+
}
|
|
110
|
+
export type InlineToken = InlineTextToken | InlineContentToken;
|
|
111
|
+
export type Token = BlockToken | InlineToken;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { forEach, isString } from "@amateras/utils";
|
|
2
|
+
import { type Token } from "./MarkdownLexer";
|
|
3
|
+
|
|
4
|
+
export class MarkdownParser {
|
|
5
|
+
processors = new Map<string, MarkdownParseProcessor>();
|
|
6
|
+
|
|
7
|
+
parse(tokens: (Token)[]) {
|
|
8
|
+
let html = '';
|
|
9
|
+
let i = 0;
|
|
10
|
+
if (!tokens) return html;
|
|
11
|
+
while (i < tokens.length) {
|
|
12
|
+
const token = tokens[i]!;
|
|
13
|
+
const processor = this.processors.get(token.type);
|
|
14
|
+
if (processor) {
|
|
15
|
+
const result = processor(token, tokens.slice(i));
|
|
16
|
+
if (isString(result)) {
|
|
17
|
+
html += result;
|
|
18
|
+
} else {
|
|
19
|
+
html += result.html;
|
|
20
|
+
i += result.skipTokens;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
i++;
|
|
24
|
+
}
|
|
25
|
+
return html;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
use(...handle: ((parser: this) => void)[]) {
|
|
29
|
+
forEach(handle, fn => fn(this));
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type MarkdownParseProcessor = (token: Token, tokens: Token[]) => (string | { html: string, skipTokens: number })
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ALERT, ALERT_LINE, BLOCK } from "#lib/type";
|
|
2
|
+
import { setBlockTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { BlockToken, MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
import { uppercase } from "@amateras/utils";
|
|
6
|
+
|
|
7
|
+
export const alertProcessor = (parser: MarkdownParser) => setProcessor(parser, ALERT, (token, tokens) => {
|
|
8
|
+
let html = '';
|
|
9
|
+
let i = 1;
|
|
10
|
+
while (i < tokens.length) {
|
|
11
|
+
const token = tokens[i]!;
|
|
12
|
+
if (token.type !== ALERT_LINE) break;
|
|
13
|
+
html += parser.parse(token.content![0]!.content!);
|
|
14
|
+
i++;
|
|
15
|
+
}
|
|
16
|
+
const alertType = token.data?.alertType as string;
|
|
17
|
+
return {
|
|
18
|
+
html: `<blockquote class="alert alert-${alertType}"><p class="alert-title">${uppercase(alertType, 0, 1)}</p>${html}</blockquote>`,
|
|
19
|
+
skipTokens: i
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const alertTokenizer = (lexer: MarkdownLexer) => setBlockTokenizer(lexer, ALERT, {
|
|
24
|
+
regex: /^> ?\[!(?:(?:NOTE)|(?:TIP)|(?:IMPORTANT)|(?:WARNING)|(?:CAUTION))\]/,
|
|
25
|
+
handle(_, position, lines) {
|
|
26
|
+
const tokens: BlockToken[] = [];
|
|
27
|
+
const match = lines[position]!.match(/> ?\[!(.+?)\]/);
|
|
28
|
+
const alertType = match?.[1]?.toLowerCase();
|
|
29
|
+
position++
|
|
30
|
+
while (position < lines.length) {
|
|
31
|
+
const line = lines[position]!;
|
|
32
|
+
const match = line.match(/^> ?(.+)/);
|
|
33
|
+
if (match) tokens.push({ layout: BLOCK, type: ALERT_LINE, content: lexer.blockTokenize(match[1]!) });
|
|
34
|
+
else break;
|
|
35
|
+
position++;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
content: [],
|
|
39
|
+
data: { alertType },
|
|
40
|
+
multiLine: {
|
|
41
|
+
skip: position,
|
|
42
|
+
tokens
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BLOCKQUOTE } from "#lib/type";
|
|
2
|
+
import { htmltag, setBlockTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
|
|
6
|
+
export const blockquoteProcessor = (parser: MarkdownParser) => setProcessor(parser, BLOCKQUOTE, (token, tokens) => {
|
|
7
|
+
let i = 0;
|
|
8
|
+
const blockquote = (deep: number) => {
|
|
9
|
+
let html = '';
|
|
10
|
+
while (i < tokens.length) {
|
|
11
|
+
const {type, content, data} = tokens[i]!;
|
|
12
|
+
if (type !== BLOCKQUOTE) break;
|
|
13
|
+
if (data!.deep > deep) html += blockquote(data!.deep);
|
|
14
|
+
else if (data!.deep < deep) break;
|
|
15
|
+
else { html += parser.parse(content!); i++ }
|
|
16
|
+
}
|
|
17
|
+
return htmltag('blockquote', html)
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
html: blockquote(token.data!.deep),
|
|
21
|
+
skipTokens: i
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const blockquoteTokenizer = (lexer: MarkdownLexer) => setBlockTokenizer(lexer, BLOCKQUOTE, {
|
|
26
|
+
regex: /^(>+) ?(.+)?/,
|
|
27
|
+
handle(matches) {
|
|
28
|
+
return {
|
|
29
|
+
content: lexer.blockTokenize(matches[2] ?? ''),
|
|
30
|
+
data: {
|
|
31
|
+
deep: (matches[1]!.length - 1)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BOLD } from "#lib/type";
|
|
2
|
+
import { htmltag, setInlineTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
|
|
6
|
+
export const boldProcessor = (parser: MarkdownParser) => setProcessor(parser, BOLD, token => htmltag('b', parser.parse(token.content!)))
|
|
7
|
+
|
|
8
|
+
export const boldTokenizer = (lexer: MarkdownLexer) => setInlineTokenizer(lexer, BOLD, {
|
|
9
|
+
regex: /\*\*(.+?\*?)\*\*/,
|
|
10
|
+
handle: matches => ({ content: lexer.inlineTokenize(matches[1]!) })
|
|
11
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CODE } from "#lib/type";
|
|
2
|
+
import { htmlEscapeChar, htmltag, setInlineTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
|
|
6
|
+
export const codeProcessor = (parser: MarkdownParser) => setProcessor(parser, CODE, token => htmltag('code', htmlEscapeChar(token.text!)))
|
|
7
|
+
|
|
8
|
+
export const codeTokenizer = (lexer: MarkdownLexer) => setInlineTokenizer(lexer, CODE, {
|
|
9
|
+
regex: /`(.+?)`/,
|
|
10
|
+
handle: matches => ({ content: matches[1]! })
|
|
11
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BLOCK, CODE_END, CODE_LINE, CODE_START } from "#lib/type";
|
|
2
|
+
import { htmlEscapeChar, setBlockTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { BlockToken, MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
|
|
6
|
+
export const codeblockProcessor = (parser: MarkdownParser) => setProcessor(parser, CODE_START, (token, tokens) => {
|
|
7
|
+
let html = '';
|
|
8
|
+
let i = 1;
|
|
9
|
+
while (i < tokens.length) {
|
|
10
|
+
const token = tokens[i]!;
|
|
11
|
+
if (token.type === CODE_END) break;
|
|
12
|
+
html += token.content![0]!.text;
|
|
13
|
+
i++;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
html: `<pre><code${token.data?.lang ? ` lang="${token.data.lang}"` : ''}>${htmlEscapeChar(html)}</code></pre>`,
|
|
17
|
+
skipTokens: i
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const codeblockTokenizer = (lexer: MarkdownLexer) => setBlockTokenizer(lexer, CODE_START, {
|
|
22
|
+
regex: /^```(\w+)?/,
|
|
23
|
+
handle: (matches, position, lines) => {
|
|
24
|
+
const tokens: BlockToken[] = [];
|
|
25
|
+
position++;
|
|
26
|
+
while (position < lines.length) {
|
|
27
|
+
const line = lines[position]!;
|
|
28
|
+
position++;
|
|
29
|
+
if (line.includes('```')) {
|
|
30
|
+
tokens.push({ layout: BLOCK, type: CODE_END, content: [] })
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
tokens.push({ layout: BLOCK, type: CODE_LINE, content: [{ layout: "INLINE_TEXT", type: 'CODE_TEXT', text: `${line}\n` }] });
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
content: [],
|
|
37
|
+
data: { lang: matches[1] },
|
|
38
|
+
multiLine: {
|
|
39
|
+
skip: position,
|
|
40
|
+
tokens
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HEADING } from "#lib/type";
|
|
2
|
+
import { htmltag, setBlockTokenizer, setProcessor } from "#lib/util";
|
|
3
|
+
import type { MarkdownLexer } from "#structure/MarkdownLexer";
|
|
4
|
+
import type { MarkdownParser } from "#structure/MarkdownParser";
|
|
5
|
+
|
|
6
|
+
export const headingProcessor = (parser: MarkdownParser) => setProcessor(parser, HEADING, token => {
|
|
7
|
+
const tagname = `h${token.data!.level}`;
|
|
8
|
+
return htmltag(tagname, parser.parse(token.content!))
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const headingTokenizer = (lexer: MarkdownLexer) => setBlockTokenizer(lexer, HEADING, {
|
|
12
|
+
regex: /^(#+) (.+)/,
|
|
13
|
+
handle: matches => ({ content: lexer.inlineTokenize(matches[2]!), data: { level: matches[1]!.length } })
|
|
14
|
+
})
|