southnote-mini-sdk 1.0.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/app.js +22 -0
- package/app.json +53 -0
- package/app.wxss +15 -0
- package/assets/file/badwords.js +63008 -0
- package/assets/file/rules.js +38 -0
- package/assets/images/emoji/smile001.png +0 -0
- package/assets/images/emoji/smile002.png +0 -0
- package/assets/images/emoji/smile003.png +0 -0
- package/assets/images/emoji/smile004.png +0 -0
- package/assets/images/emoji/smile005.png +0 -0
- package/assets/images/emoji/smile006.png +0 -0
- package/assets/images/emoji/smile007.png +0 -0
- package/assets/images/emoji/smile008.png +0 -0
- package/assets/images/emoji/smile009.png +0 -0
- package/assets/images/emoji/smile010.png +0 -0
- package/assets/images/emoji/smile011.png +0 -0
- package/assets/images/emoji/smile012.png +0 -0
- package/assets/images/emoji/smile013.png +0 -0
- package/assets/images/emoji/smile014.png +0 -0
- package/assets/images/emoji/smile015.png +0 -0
- package/assets/images/emoji/smile016.png +0 -0
- package/assets/images/emoji/smile017.png +0 -0
- package/assets/images/emoji/smile018.png +0 -0
- package/assets/images/emoji/smile019.png +0 -0
- package/assets/images/emoji/smile020.png +0 -0
- package/assets/images/emoji/smile021.png +0 -0
- package/assets/images/emoji/smile022.png +0 -0
- package/assets/images/emoji/smile023.png +0 -0
- package/assets/images/emoji/smile024.png +0 -0
- package/assets/images/emoji/smile025.png +0 -0
- package/assets/images/emoji/smile026.png +0 -0
- package/assets/images/emoji/smile027.png +0 -0
- package/assets/images/emoji/smile028.png +0 -0
- package/assets/images/emoji/smile029.png +0 -0
- package/assets/images/emoji/smile030.png +0 -0
- package/assets/images/emoji/smile031.png +0 -0
- package/assets/images/emoji/smile032.png +0 -0
- package/assets/images/emoji/smile033.png +0 -0
- package/assets/images/emoji/smile034.png +0 -0
- package/assets/images/emoji/smile035.png +0 -0
- package/assets/images/emoji/smile036.png +0 -0
- package/assets/images/emoji/smile037.png +0 -0
- package/assets/images/emoji/smile038.png +0 -0
- package/assets/images/emoji/smile039.png +0 -0
- package/assets/images/emoji/smile040.png +0 -0
- package/assets/images/emoji/smile041.png +0 -0
- package/assets/images/emoji/smile042.png +0 -0
- package/assets/images/emoji/smile043.png +0 -0
- package/assets/images/emoji/smile044.png +0 -0
- package/assets/images/emoji/smile045.png +0 -0
- package/assets/images/emoji/smile046.png +0 -0
- package/assets/images/emoji/smile047.png +0 -0
- package/assets/images/emoji/smile048.png +0 -0
- package/assets/images/emoji/smile049.png +0 -0
- package/assets/images/emoji/smile050.png +0 -0
- package/assets/images/emoji/smile051.png +0 -0
- package/assets/images/emoji/smile052.png +0 -0
- package/assets/images/icons/age1.png +0 -0
- package/assets/images/icons/age2.png +0 -0
- package/assets/images/icons/age3.png +0 -0
- package/assets/images/icons/attachment.png +0 -0
- package/assets/images/icons/clear.png +0 -0
- package/assets/images/icons/edit_input.png +0 -0
- package/assets/images/icons/header_placeholder.png +0 -0
- package/assets/images/icons/home_collect.png +0 -0
- package/assets/images/icons/home_collected.png +0 -0
- package/assets/images/icons/home_comment.png +0 -0
- package/assets/images/icons/home_like.png +0 -0
- package/assets/images/icons/home_liked.png +0 -0
- package/assets/images/icons/home_message.png +0 -0
- package/assets/images/icons/home_share.png +0 -0
- package/assets/images/icons/icon_more.png +0 -0
- package/assets/images/icons/input_game.png +0 -0
- package/assets/images/icons/logo.png +0 -0
- package/assets/images/icons/lv1.png +0 -0
- package/assets/images/icons/lv2.png +0 -0
- package/assets/images/icons/lv3.png +0 -0
- package/assets/images/icons/lv4.png +0 -0
- package/assets/images/icons/search.png +0 -0
- package/assets/images/icons/sex1.png +0 -0
- package/assets/images/icons/sex2.png +0 -0
- package/assets/images/icons/sign_empty.png +0 -0
- package/assets/images/icons/sign_login.png +0 -0
- package/assets/wheel/wheel_bg.png +0 -0
- package/assets/wheel/wheel_bg2.png +0 -0
- package/assets/wheel/wheel_fore.png +0 -0
- package/assets/wheel/wheel_to.png +0 -0
- package/components/bottomSheet/bottomSheet.js +473 -0
- package/components/bottomSheet/bottomSheet.json +3 -0
- package/components/bottomSheet/bottomSheet.wxml +73 -0
- package/components/bottomSheet/bottomSheet.wxss +238 -0
- package/components/experience-item/experience-item.js +105 -0
- package/components/experience-item/experience-item.json +4 -0
- package/components/experience-item/experience-item.wxml +39 -0
- package/components/experience-item/experience-item.wxss +110 -0
- package/components/grid-item/grid-item.js +8 -0
- package/components/grid-item/grid-item.json +4 -0
- package/components/grid-item/grid-item.wxml +62 -0
- package/components/grid-item/grid-item.wxss +191 -0
- package/components/post-item/post-item.js +1085 -0
- package/components/post-item/post-item.json +4 -0
- package/components/post-item/post-item.wxml +427 -0
- package/components/post-item/post-item.wxss +525 -0
- package/components/wiki-renderer/wiki-renderer.js +636 -0
- package/components/wiki-renderer/wiki-renderer.json +12 -0
- package/components/wiki-renderer/wiki-renderer.wxml +150 -0
- package/components/wiki-renderer/wiki-renderer.wxss +412 -0
- package/components/wiki-tabs/wiki-tabs.js +52 -0
- package/components/wiki-tabs/wiki-tabs.json +3 -0
- package/components/wiki-tabs/wiki-tabs.wxml +28 -0
- package/components/wiki-tabs/wiki-tabs.wxss +43 -0
- package/index.js +49 -0
- package/package.json +35 -0
- package/pages/addGame/addGame.js +454 -0
- package/pages/addGame/addGame.json +3 -0
- package/pages/addGame/addGame.wxml +71 -0
- package/pages/addGame/addGame.wxss +110 -0
- package/pages/addSubject/addSubject.js +199 -0
- package/pages/addSubject/addSubject.json +4 -0
- package/pages/addSubject/addSubject.wxml +78 -0
- package/pages/addSubject/addSubject.wxss +85 -0
- package/pages/commonLogin/commonLogin.js +269 -0
- package/pages/commonLogin/commonLogin.json +4 -0
- package/pages/commonLogin/commonLogin.wxml +57 -0
- package/pages/commonLogin/commonLogin.wxss +177 -0
- package/pages/copyOfficial/copyOfficial.js +25 -0
- package/pages/copyOfficial/copyOfficial.json +3 -0
- package/pages/copyOfficial/copyOfficial.wxml +22 -0
- package/pages/copyOfficial/copyOfficial.wxss +49 -0
- package/pages/demo/demo.js +23 -0
- package/pages/demo/demo.json +3 -0
- package/pages/demo/demo.wxml +8 -0
- package/pages/demo/demo.wxss +24 -0
- package/pages/game/game.js +1254 -0
- package/pages/game/game.json +8 -0
- package/pages/game/game.wxml +371 -0
- package/pages/game/game.wxss +672 -0
- package/pages/home/home.js +665 -0
- package/pages/home/home.json +10 -0
- package/pages/home/home.wxml +115 -0
- package/pages/home/home.wxss +231 -0
- package/pages/lottery-winners/lottery-winners.js +60 -0
- package/pages/lottery-winners/lottery-winners.json +4 -0
- package/pages/lottery-winners/lottery-winners.wxml +53 -0
- package/pages/lottery-winners/lottery-winners.wxss +127 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.js +178 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.json +5 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxml +93 -0
- package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxss +177 -0
- package/pages/message/messageEntire/messageEntire.js +112 -0
- package/pages/message/messageEntire/messageEntire.json +4 -0
- package/pages/message/messageEntire/messageEntire.wxml +44 -0
- package/pages/message/messageEntire/messageEntire.wxss +88 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.js +147 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.json +5 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxml +84 -0
- package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxss +166 -0
- package/pages/message/messageNewFans/messageNewFans.js +139 -0
- package/pages/message/messageNewFans/messageNewFans.json +5 -0
- package/pages/message/messageNewFans/messageNewFans.wxml +35 -0
- package/pages/message/messageNewFans/messageNewFans.wxss +85 -0
- package/pages/officialWebview/officialWebview.js +13 -0
- package/pages/officialWebview/officialWebview.json +3 -0
- package/pages/officialWebview/officialWebview.wxml +2 -0
- package/pages/officialWebview/officialWebview.wxss +1 -0
- package/pages/post/post.js +1856 -0
- package/pages/post/post.json +6 -0
- package/pages/post/post.wxml +694 -0
- package/pages/post/post.wxss +1003 -0
- package/pages/post-editor/post-editor.js +465 -0
- package/pages/post-editor/post-editor.json +4 -0
- package/pages/post-editor/post-editor.wxml +63 -0
- package/pages/post-editor/post-editor.wxss +195 -0
- package/pages/postDialog/postDialog.js +560 -0
- package/pages/postDialog/postDialog.json +6 -0
- package/pages/postDialog/postDialog.wxml +377 -0
- package/pages/postDialog/postDialog.wxss +979 -0
- package/pages/report-category/report-category.js +29 -0
- package/pages/report-category/report-category.json +4 -0
- package/pages/report-category/report-category.wxml +14 -0
- package/pages/report-category/report-category.wxss +43 -0
- package/pages/report-form/report-form.js +65 -0
- package/pages/report-form/report-form.json +3 -0
- package/pages/report-form/report-form.wxml +11 -0
- package/pages/report-form/report-form.wxss +44 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.js +273 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.json +3 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.wxml +82 -0
- package/pages/sevenDaySignDetail/sevenDaySignDetail.wxss +173 -0
- package/pages/topic/topic.js +266 -0
- package/pages/topic/topic.json +6 -0
- package/pages/topic/topic.wxml +77 -0
- package/pages/topic/topic.wxss +162 -0
- package/pages/user/user.js +939 -0
- package/pages/user/user.json +5 -0
- package/pages/user/user.wxml +179 -0
- package/pages/user/user.wxss +340 -0
- package/pages/userDatum/userDatum.js +24 -0
- package/pages/userDatum/userDatum.json +4 -0
- package/pages/userDatum/userDatum.wxml +36 -0
- package/pages/userDatum/userDatum.wxss +41 -0
- package/pages/userGameLib/userGameLib.js +105 -0
- package/pages/userGameLib/userGameLib.json +4 -0
- package/pages/userGameLib/userGameLib.wxml +42 -0
- package/pages/userGameLib/userGameLib.wxss +119 -0
- package/pages/webview/webview.js +25 -0
- package/pages/webview/webview.json +3 -0
- package/pages/webview/webview.wxml +22 -0
- package/pages/webview/webview.wxss +50 -0
- package/pages/wheelActivivty/wheelActivivty.js +492 -0
- package/pages/wheelActivivty/wheelActivivty.json +8 -0
- package/pages/wheelActivivty/wheelActivivty.wxml +131 -0
- package/pages/wheelActivivty/wheelActivivty.wxss +459 -0
- package/pages/wiki/wiki.js +138 -0
- package/pages/wiki/wiki.json +6 -0
- package/pages/wiki/wiki.wxml +20 -0
- package/pages/wiki/wiki.wxss +44 -0
- package/request/JKRequest.js +177 -0
- package/services/home.js +603 -0
- package/towxml/config.js +291 -0
- package/towxml/decode.js +35 -0
- package/towxml/decode.json +11 -0
- package/towxml/decode.wxml +137 -0
- package/towxml/decode.wxss +0 -0
- package/towxml/img/img.js +98 -0
- package/towxml/img/img.json +3 -0
- package/towxml/img/img.wxml +1 -0
- package/towxml/img/img.wxss +0 -0
- package/towxml/index.js +19 -0
- package/towxml/latex/latex.js +53 -0
- package/towxml/latex/latex.json +5 -0
- package/towxml/latex/latex.wxml +1 -0
- package/towxml/latex/latex.wxss +0 -0
- package/towxml/parse/highlight/highlight.js +1 -0
- package/towxml/parse/highlight/index.js +8 -0
- package/towxml/parse/highlight/languages/bash.js +111 -0
- package/towxml/parse/highlight/languages/c-like.js +236 -0
- package/towxml/parse/highlight/languages/c.js +22 -0
- package/towxml/parse/highlight/languages/css.js +132 -0
- package/towxml/parse/highlight/languages/dart.js +134 -0
- package/towxml/parse/highlight/languages/go.js +63 -0
- package/towxml/parse/highlight/languages/htmlbars.js +80 -0
- package/towxml/parse/highlight/languages/java.js +125 -0
- package/towxml/parse/highlight/languages/javascript.js +265 -0
- package/towxml/parse/highlight/languages/json.js +52 -0
- package/towxml/parse/highlight/languages/less.js +148 -0
- package/towxml/parse/highlight/languages/nginx.js +101 -0
- package/towxml/parse/highlight/languages/php.js +161 -0
- package/towxml/parse/highlight/languages/python-repl.js +29 -0
- package/towxml/parse/highlight/languages/python.js +131 -0
- package/towxml/parse/highlight/languages/scss.js +122 -0
- package/towxml/parse/highlight/languages/shell.js +22 -0
- package/towxml/parse/highlight/languages/typescript.js +215 -0
- package/towxml/parse/highlight/languages/xml.js +139 -0
- package/towxml/parse/highlight/style/github.wxss +99 -0
- package/towxml/parse/highlight/style/monokai.wxss +70 -0
- package/towxml/parse/index.js +118 -0
- package/towxml/parse/markdown/index.js +67 -0
- package/towxml/parse/markdown/markdown.js +4 -0
- package/towxml/parse/markdown/plugins/echarts.js +11 -0
- package/towxml/parse/markdown/plugins/emoji.js +2 -0
- package/towxml/parse/markdown/plugins/ins.js +1 -0
- package/towxml/parse/markdown/plugins/latex.js +158 -0
- package/towxml/parse/markdown/plugins/mark.js +1 -0
- package/towxml/parse/markdown/plugins/sub.js +1 -0
- package/towxml/parse/markdown/plugins/sup.js +1 -0
- package/towxml/parse/markdown/plugins/todo.js +147 -0
- package/towxml/parse/markdown/plugins/yuml.js +20 -0
- package/towxml/parse/parse2/Parser.js +492 -0
- package/towxml/parse/parse2/Tokenizer.js +903 -0
- package/towxml/parse/parse2/domelementtype/index.js +55 -0
- package/towxml/parse/parse2/domhandler/index.js +145 -0
- package/towxml/parse/parse2/domhandler/node.js +474 -0
- package/towxml/parse/parse2/entities/decode.js +179 -0
- package/towxml/parse/parse2/entities/decode_codepoint.js +60 -0
- package/towxml/parse/parse2/entities/encode.js +77 -0
- package/towxml/parse/parse2/entities/escape.js +112 -0
- package/towxml/parse/parse2/entities/generated/decode-data-html.js +9 -0
- package/towxml/parse/parse2/entities/generated/decode-data-xml.js +9 -0
- package/towxml/parse/parse2/entities/generated/encode-html.js +12 -0
- package/towxml/parse/parse2/entities/index.js +137 -0
- package/towxml/parse/parse2/index.js +8 -0
- package/towxml/style/main.wxss +419 -0
- package/towxml/style/theme/dark.wxss +73 -0
- package/towxml/style/theme/light.wxss +63 -0
- package/towxml/table/table.js +11 -0
- package/towxml/table/table.json +6 -0
- package/towxml/table/table.wxml +24 -0
- package/towxml/table/table.wxss +0 -0
- package/towxml/todogroup/todogroup.js +20 -0
- package/towxml/todogroup/todogroup.json +6 -0
- package/towxml/todogroup/todogroup.wxml +12 -0
- package/towxml/todogroup/todogroup.wxss +3 -0
- package/towxml/towxml.js +22 -0
- package/towxml/towxml.json +6 -0
- package/towxml/towxml.wxml +5 -0
- package/towxml/towxml.wxss +8 -0
- package/towxml/yuml/yuml.js +51 -0
- package/towxml/yuml/yuml.json +5 -0
- package/towxml/yuml/yuml.wxml +5 -0
- package/towxml/yuml/yuml.wxss +0 -0
- package/utils/auth.js +17 -0
- package/utils/base64.js +67 -0
- package/utils/compressImage.js +41 -0
- package/utils/exp.js +49 -0
- package/utils/formatPost.js +18 -0
- package/utils/parseContent.js +191 -0
- package/utils/query-select.js +9 -0
- package/utils/sensitive.js +82 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
|
|
4
|
+
/** Types of elements found in htmlparser2's DOM */
|
|
5
|
+
var ElementType;
|
|
6
|
+
(function (ElementType) {
|
|
7
|
+
/** Type for the root element of a document */
|
|
8
|
+
ElementType["Root"] = "root";
|
|
9
|
+
/** Type for Text */
|
|
10
|
+
ElementType["Text"] = "text";
|
|
11
|
+
/** Type for <? ... ?> */
|
|
12
|
+
ElementType["Directive"] = "directive";
|
|
13
|
+
/** Type for <!-- ... --> */
|
|
14
|
+
ElementType["Comment"] = "comment";
|
|
15
|
+
/** Type for <script> tags */
|
|
16
|
+
ElementType["Script"] = "script";
|
|
17
|
+
/** Type for <style> tags */
|
|
18
|
+
ElementType["Style"] = "style";
|
|
19
|
+
/** Type for Any tag */
|
|
20
|
+
ElementType["Tag"] = "tag";
|
|
21
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
22
|
+
ElementType["CDATA"] = "cdata";
|
|
23
|
+
/** Type for <!doctype ...> */
|
|
24
|
+
ElementType["Doctype"] = "doctype";
|
|
25
|
+
})(ElementType = exports.ElementType || (exports.ElementType = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Tests whether an element is a tag or not.
|
|
28
|
+
*
|
|
29
|
+
* @param elem Element to test
|
|
30
|
+
*/
|
|
31
|
+
function isTag(elem) {
|
|
32
|
+
return (elem.type === ElementType.Tag ||
|
|
33
|
+
elem.type === ElementType.Script ||
|
|
34
|
+
elem.type === ElementType.Style);
|
|
35
|
+
}
|
|
36
|
+
exports.isTag = isTag;
|
|
37
|
+
// Exports for backwards compatibility
|
|
38
|
+
/** Type for the root element of a document */
|
|
39
|
+
exports.Root = ElementType.Root;
|
|
40
|
+
/** Type for Text */
|
|
41
|
+
exports.Text = ElementType.Text;
|
|
42
|
+
/** Type for <? ... ?> */
|
|
43
|
+
exports.Directive = ElementType.Directive;
|
|
44
|
+
/** Type for <!-- ... --> */
|
|
45
|
+
exports.Comment = ElementType.Comment;
|
|
46
|
+
/** Type for <script> tags */
|
|
47
|
+
exports.Script = ElementType.Script;
|
|
48
|
+
/** Type for <style> tags */
|
|
49
|
+
exports.Style = ElementType.Style;
|
|
50
|
+
/** Type for Any tag */
|
|
51
|
+
exports.Tag = ElementType.Tag;
|
|
52
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
53
|
+
exports.CDATA = ElementType.CDATA;
|
|
54
|
+
/** Type for <!doctype ...> */
|
|
55
|
+
exports.Doctype = ElementType.Doctype;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var domelementtype_1 = require("../domelementtype/index.js");
|
|
2
|
+
var node_js_1 = require("./node.js");
|
|
3
|
+
var defaultOpts = {
|
|
4
|
+
withStartIndices: false,
|
|
5
|
+
withEndIndices: false,
|
|
6
|
+
xmlMode: false,
|
|
7
|
+
};
|
|
8
|
+
var DomHandler = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* @param callback Called once parsing has completed.
|
|
11
|
+
* @param options Settings for the handler.
|
|
12
|
+
* @param elementCB Callback whenever a tag is closed.
|
|
13
|
+
*/
|
|
14
|
+
function DomHandler(callback, options, elementCB) {
|
|
15
|
+
/** The elements of the DOM */
|
|
16
|
+
this.dom = [];
|
|
17
|
+
/** The root element for the DOM */
|
|
18
|
+
this.root = new node_js_1.Document(this.dom);
|
|
19
|
+
/** Indicated whether parsing has been completed. */
|
|
20
|
+
this.done = false;
|
|
21
|
+
/** Stack of open tags. */
|
|
22
|
+
this.tagStack = [this.root];
|
|
23
|
+
/** A data node that is still being written to. */
|
|
24
|
+
this.lastNode = null;
|
|
25
|
+
/** Reference to the parser instance. Used for location information. */
|
|
26
|
+
this.parser = null;
|
|
27
|
+
// Make it possible to skip arguments, for backwards-compatibility
|
|
28
|
+
if (typeof options === "function") {
|
|
29
|
+
elementCB = options;
|
|
30
|
+
options = defaultOpts;
|
|
31
|
+
}
|
|
32
|
+
if (typeof callback === "object") {
|
|
33
|
+
options = callback;
|
|
34
|
+
callback = undefined;
|
|
35
|
+
}
|
|
36
|
+
this.callback = callback !== null && callback !== void 0 ? callback : null;
|
|
37
|
+
this.options = options !== null && options !== void 0 ? options : defaultOpts;
|
|
38
|
+
this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
|
|
39
|
+
}
|
|
40
|
+
DomHandler.prototype.onparserinit = function (parser) {
|
|
41
|
+
this.parser = parser;
|
|
42
|
+
};
|
|
43
|
+
// Resets the handler back to starting state
|
|
44
|
+
DomHandler.prototype.onreset = function () {
|
|
45
|
+
this.dom = [];
|
|
46
|
+
this.root = new node_js_1.Document(this.dom);
|
|
47
|
+
this.done = false;
|
|
48
|
+
this.tagStack = [this.root];
|
|
49
|
+
this.lastNode = null;
|
|
50
|
+
this.parser = null;
|
|
51
|
+
};
|
|
52
|
+
// Signals the handler that parsing is done
|
|
53
|
+
DomHandler.prototype.onend = function () {
|
|
54
|
+
if (this.done)
|
|
55
|
+
return;
|
|
56
|
+
this.done = true;
|
|
57
|
+
this.parser = null;
|
|
58
|
+
this.handleCallback(null);
|
|
59
|
+
};
|
|
60
|
+
DomHandler.prototype.onerror = function (error) {
|
|
61
|
+
this.handleCallback(error);
|
|
62
|
+
};
|
|
63
|
+
DomHandler.prototype.onclosetag = function () {
|
|
64
|
+
this.lastNode = null;
|
|
65
|
+
var elem = this.tagStack.pop();
|
|
66
|
+
if (this.options.withEndIndices) {
|
|
67
|
+
elem.endIndex = this.parser.endIndex;
|
|
68
|
+
}
|
|
69
|
+
if (this.elementCB)
|
|
70
|
+
this.elementCB(elem);
|
|
71
|
+
};
|
|
72
|
+
DomHandler.prototype.onopentag = function (name, attribs) {
|
|
73
|
+
var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined;
|
|
74
|
+
var element = new node_js_1.Element(name, attribs, undefined, type);
|
|
75
|
+
this.addNode(element);
|
|
76
|
+
this.tagStack.push(element);
|
|
77
|
+
};
|
|
78
|
+
DomHandler.prototype.ontext = function (data) {
|
|
79
|
+
var lastNode = this.lastNode;
|
|
80
|
+
if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) {
|
|
81
|
+
lastNode.data += data;
|
|
82
|
+
if (this.options.withEndIndices) {
|
|
83
|
+
lastNode.endIndex = this.parser.endIndex;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
var node = new node_js_1.Text(data);
|
|
88
|
+
this.addNode(node);
|
|
89
|
+
this.lastNode = node;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
DomHandler.prototype.oncomment = function (data) {
|
|
93
|
+
if (this.lastNode && this.lastNode.type === domelementtype_1.ElementType.Comment) {
|
|
94
|
+
this.lastNode.data += data;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
var node = new node_js_1.Comment(data);
|
|
98
|
+
this.addNode(node);
|
|
99
|
+
this.lastNode = node;
|
|
100
|
+
};
|
|
101
|
+
DomHandler.prototype.oncommentend = function () {
|
|
102
|
+
this.lastNode = null;
|
|
103
|
+
};
|
|
104
|
+
DomHandler.prototype.oncdatastart = function () {
|
|
105
|
+
var text = new node_js_1.Text("");
|
|
106
|
+
var node = new node_js_1.CDATA([text]);
|
|
107
|
+
this.addNode(node);
|
|
108
|
+
text.parent = node;
|
|
109
|
+
this.lastNode = text;
|
|
110
|
+
};
|
|
111
|
+
DomHandler.prototype.oncdataend = function () {
|
|
112
|
+
this.lastNode = null;
|
|
113
|
+
};
|
|
114
|
+
DomHandler.prototype.onprocessinginstruction = function (name, data) {
|
|
115
|
+
var node = new node_js_1.ProcessingInstruction(name, data);
|
|
116
|
+
this.addNode(node);
|
|
117
|
+
};
|
|
118
|
+
DomHandler.prototype.handleCallback = function (error) {
|
|
119
|
+
if (typeof this.callback === "function") {
|
|
120
|
+
this.callback(error, this.dom);
|
|
121
|
+
}
|
|
122
|
+
else if (error) {
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
DomHandler.prototype.addNode = function (node) {
|
|
127
|
+
var parent = this.tagStack[this.tagStack.length - 1];
|
|
128
|
+
var previousSibling = parent.children[parent.children.length - 1];
|
|
129
|
+
if (this.options.withStartIndices) {
|
|
130
|
+
node.startIndex = this.parser.startIndex;
|
|
131
|
+
}
|
|
132
|
+
if (this.options.withEndIndices) {
|
|
133
|
+
node.endIndex = this.parser.endIndex;
|
|
134
|
+
}
|
|
135
|
+
parent.children.push(node);
|
|
136
|
+
if (previousSibling) {
|
|
137
|
+
node.prev = previousSibling;
|
|
138
|
+
previousSibling.next = node;
|
|
139
|
+
}
|
|
140
|
+
node.parent = parent;
|
|
141
|
+
this.lastNode = null;
|
|
142
|
+
};
|
|
143
|
+
return DomHandler;
|
|
144
|
+
}());
|
|
145
|
+
module.exports = DomHandler;
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.cloneNode = exports.hasChildren = exports.isDocument = exports.isDirective = exports.isComment = exports.isText = exports.isCDATA = exports.isTag = exports.Element = exports.Document = exports.CDATA = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0;
|
|
30
|
+
var domelementtype_1 = require("../domelementtype/index.js");
|
|
31
|
+
/**
|
|
32
|
+
* This object will be used as the prototype for Nodes when creating a
|
|
33
|
+
* DOM-Level-1-compliant structure.
|
|
34
|
+
*/
|
|
35
|
+
var Node = /** @class */ (function () {
|
|
36
|
+
function Node() {
|
|
37
|
+
/** Parent of the node */
|
|
38
|
+
this.parent = null;
|
|
39
|
+
/** Previous sibling */
|
|
40
|
+
this.prev = null;
|
|
41
|
+
/** Next sibling */
|
|
42
|
+
this.next = null;
|
|
43
|
+
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
|
|
44
|
+
this.startIndex = null;
|
|
45
|
+
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
|
|
46
|
+
this.endIndex = null;
|
|
47
|
+
}
|
|
48
|
+
Object.defineProperty(Node.prototype, "parentNode", {
|
|
49
|
+
// Read-write aliases for properties
|
|
50
|
+
/**
|
|
51
|
+
* Same as {@link parent}.
|
|
52
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
53
|
+
*/
|
|
54
|
+
get: function () {
|
|
55
|
+
return this.parent;
|
|
56
|
+
},
|
|
57
|
+
set: function (parent) {
|
|
58
|
+
this.parent = parent;
|
|
59
|
+
},
|
|
60
|
+
enumerable: false,
|
|
61
|
+
configurable: true
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(Node.prototype, "previousSibling", {
|
|
64
|
+
/**
|
|
65
|
+
* Same as {@link prev}.
|
|
66
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
67
|
+
*/
|
|
68
|
+
get: function () {
|
|
69
|
+
return this.prev;
|
|
70
|
+
},
|
|
71
|
+
set: function (prev) {
|
|
72
|
+
this.prev = prev;
|
|
73
|
+
},
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: true
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(Node.prototype, "nextSibling", {
|
|
78
|
+
/**
|
|
79
|
+
* Same as {@link next}.
|
|
80
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
81
|
+
*/
|
|
82
|
+
get: function () {
|
|
83
|
+
return this.next;
|
|
84
|
+
},
|
|
85
|
+
set: function (next) {
|
|
86
|
+
this.next = next;
|
|
87
|
+
},
|
|
88
|
+
enumerable: false,
|
|
89
|
+
configurable: true
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Clone this node, and optionally its children.
|
|
93
|
+
*
|
|
94
|
+
* @param recursive Clone child nodes as well.
|
|
95
|
+
* @returns A clone of the node.
|
|
96
|
+
*/
|
|
97
|
+
Node.prototype.cloneNode = function (recursive) {
|
|
98
|
+
if (recursive === void 0) { recursive = false; }
|
|
99
|
+
return cloneNode(this, recursive);
|
|
100
|
+
};
|
|
101
|
+
return Node;
|
|
102
|
+
}());
|
|
103
|
+
exports.Node = Node;
|
|
104
|
+
/**
|
|
105
|
+
* A node that contains some data.
|
|
106
|
+
*/
|
|
107
|
+
var DataNode = /** @class */ (function (_super) {
|
|
108
|
+
__extends(DataNode, _super);
|
|
109
|
+
/**
|
|
110
|
+
* @param data The content of the data node
|
|
111
|
+
*/
|
|
112
|
+
function DataNode(data) {
|
|
113
|
+
var _this = _super.call(this) || this;
|
|
114
|
+
_this.data = data;
|
|
115
|
+
return _this;
|
|
116
|
+
}
|
|
117
|
+
Object.defineProperty(DataNode.prototype, "nodeValue", {
|
|
118
|
+
/**
|
|
119
|
+
* Same as {@link data}.
|
|
120
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
121
|
+
*/
|
|
122
|
+
get: function () {
|
|
123
|
+
return this.data;
|
|
124
|
+
},
|
|
125
|
+
set: function (data) {
|
|
126
|
+
this.data = data;
|
|
127
|
+
},
|
|
128
|
+
enumerable: false,
|
|
129
|
+
configurable: true
|
|
130
|
+
});
|
|
131
|
+
return DataNode;
|
|
132
|
+
}(Node));
|
|
133
|
+
exports.DataNode = DataNode;
|
|
134
|
+
/**
|
|
135
|
+
* Text within the document.
|
|
136
|
+
*/
|
|
137
|
+
var Text = /** @class */ (function (_super) {
|
|
138
|
+
__extends(Text, _super);
|
|
139
|
+
function Text() {
|
|
140
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
141
|
+
_this.type = domelementtype_1.ElementType.Text;
|
|
142
|
+
return _this;
|
|
143
|
+
}
|
|
144
|
+
Object.defineProperty(Text.prototype, "nodeType", {
|
|
145
|
+
get: function () {
|
|
146
|
+
return 3;
|
|
147
|
+
},
|
|
148
|
+
enumerable: false,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
return Text;
|
|
152
|
+
}(DataNode));
|
|
153
|
+
exports.Text = Text;
|
|
154
|
+
/**
|
|
155
|
+
* Comments within the document.
|
|
156
|
+
*/
|
|
157
|
+
var Comment = /** @class */ (function (_super) {
|
|
158
|
+
__extends(Comment, _super);
|
|
159
|
+
function Comment() {
|
|
160
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
161
|
+
_this.type = domelementtype_1.ElementType.Comment;
|
|
162
|
+
return _this;
|
|
163
|
+
}
|
|
164
|
+
Object.defineProperty(Comment.prototype, "nodeType", {
|
|
165
|
+
get: function () {
|
|
166
|
+
return 8;
|
|
167
|
+
},
|
|
168
|
+
enumerable: false,
|
|
169
|
+
configurable: true
|
|
170
|
+
});
|
|
171
|
+
return Comment;
|
|
172
|
+
}(DataNode));
|
|
173
|
+
exports.Comment = Comment;
|
|
174
|
+
/**
|
|
175
|
+
* Processing instructions, including doc types.
|
|
176
|
+
*/
|
|
177
|
+
var ProcessingInstruction = /** @class */ (function (_super) {
|
|
178
|
+
__extends(ProcessingInstruction, _super);
|
|
179
|
+
function ProcessingInstruction(name, data) {
|
|
180
|
+
var _this = _super.call(this, data) || this;
|
|
181
|
+
_this.name = name;
|
|
182
|
+
_this.type = domelementtype_1.ElementType.Directive;
|
|
183
|
+
return _this;
|
|
184
|
+
}
|
|
185
|
+
Object.defineProperty(ProcessingInstruction.prototype, "nodeType", {
|
|
186
|
+
get: function () {
|
|
187
|
+
return 1;
|
|
188
|
+
},
|
|
189
|
+
enumerable: false,
|
|
190
|
+
configurable: true
|
|
191
|
+
});
|
|
192
|
+
return ProcessingInstruction;
|
|
193
|
+
}(DataNode));
|
|
194
|
+
exports.ProcessingInstruction = ProcessingInstruction;
|
|
195
|
+
/**
|
|
196
|
+
* A `Node` that can have children.
|
|
197
|
+
*/
|
|
198
|
+
var NodeWithChildren = /** @class */ (function (_super) {
|
|
199
|
+
__extends(NodeWithChildren, _super);
|
|
200
|
+
/**
|
|
201
|
+
* @param children Children of the node. Only certain node types can have children.
|
|
202
|
+
*/
|
|
203
|
+
function NodeWithChildren(children) {
|
|
204
|
+
var _this = _super.call(this) || this;
|
|
205
|
+
_this.children = children;
|
|
206
|
+
return _this;
|
|
207
|
+
}
|
|
208
|
+
Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
|
|
209
|
+
// Aliases
|
|
210
|
+
/** First child of the node. */
|
|
211
|
+
get: function () {
|
|
212
|
+
var _a;
|
|
213
|
+
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
|
|
214
|
+
},
|
|
215
|
+
enumerable: false,
|
|
216
|
+
configurable: true
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
|
|
219
|
+
/** Last child of the node. */
|
|
220
|
+
get: function () {
|
|
221
|
+
return this.children.length > 0
|
|
222
|
+
? this.children[this.children.length - 1]
|
|
223
|
+
: null;
|
|
224
|
+
},
|
|
225
|
+
enumerable: false,
|
|
226
|
+
configurable: true
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
|
|
229
|
+
/**
|
|
230
|
+
* Same as {@link children}.
|
|
231
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
232
|
+
*/
|
|
233
|
+
get: function () {
|
|
234
|
+
return this.children;
|
|
235
|
+
},
|
|
236
|
+
set: function (children) {
|
|
237
|
+
this.children = children;
|
|
238
|
+
},
|
|
239
|
+
enumerable: false,
|
|
240
|
+
configurable: true
|
|
241
|
+
});
|
|
242
|
+
return NodeWithChildren;
|
|
243
|
+
}(Node));
|
|
244
|
+
exports.NodeWithChildren = NodeWithChildren;
|
|
245
|
+
var CDATA = /** @class */ (function (_super) {
|
|
246
|
+
__extends(CDATA, _super);
|
|
247
|
+
function CDATA() {
|
|
248
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
249
|
+
_this.type = domelementtype_1.ElementType.CDATA;
|
|
250
|
+
return _this;
|
|
251
|
+
}
|
|
252
|
+
Object.defineProperty(CDATA.prototype, "nodeType", {
|
|
253
|
+
get: function () {
|
|
254
|
+
return 4;
|
|
255
|
+
},
|
|
256
|
+
enumerable: false,
|
|
257
|
+
configurable: true
|
|
258
|
+
});
|
|
259
|
+
return CDATA;
|
|
260
|
+
}(NodeWithChildren));
|
|
261
|
+
exports.CDATA = CDATA;
|
|
262
|
+
/**
|
|
263
|
+
* The root node of the document.
|
|
264
|
+
*/
|
|
265
|
+
var Document = /** @class */ (function (_super) {
|
|
266
|
+
__extends(Document, _super);
|
|
267
|
+
function Document() {
|
|
268
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
269
|
+
_this.type = domelementtype_1.ElementType.Root;
|
|
270
|
+
return _this;
|
|
271
|
+
}
|
|
272
|
+
Object.defineProperty(Document.prototype, "nodeType", {
|
|
273
|
+
get: function () {
|
|
274
|
+
return 9;
|
|
275
|
+
},
|
|
276
|
+
enumerable: false,
|
|
277
|
+
configurable: true
|
|
278
|
+
});
|
|
279
|
+
return Document;
|
|
280
|
+
}(NodeWithChildren));
|
|
281
|
+
exports.Document = Document;
|
|
282
|
+
/**
|
|
283
|
+
* An element within the DOM.
|
|
284
|
+
*/
|
|
285
|
+
var Element = /** @class */ (function (_super) {
|
|
286
|
+
__extends(Element, _super);
|
|
287
|
+
/**
|
|
288
|
+
* @param name Name of the tag, eg. `div`, `span`.
|
|
289
|
+
* @param attribs Object mapping attribute names to attribute values.
|
|
290
|
+
* @param children Children of the node.
|
|
291
|
+
*/
|
|
292
|
+
function Element(name, attribs, children, type) {
|
|
293
|
+
if (children === void 0) { children = []; }
|
|
294
|
+
if (type === void 0) { type = name === "script"
|
|
295
|
+
? domelementtype_1.ElementType.Script
|
|
296
|
+
: name === "style"
|
|
297
|
+
? domelementtype_1.ElementType.Style
|
|
298
|
+
: domelementtype_1.ElementType.Tag; }
|
|
299
|
+
var _this = _super.call(this, children) || this;
|
|
300
|
+
_this.name = name;
|
|
301
|
+
_this.attribs = attribs;
|
|
302
|
+
_this.type = type;
|
|
303
|
+
return _this;
|
|
304
|
+
}
|
|
305
|
+
Object.defineProperty(Element.prototype, "nodeType", {
|
|
306
|
+
get: function () {
|
|
307
|
+
return 1;
|
|
308
|
+
},
|
|
309
|
+
enumerable: false,
|
|
310
|
+
configurable: true
|
|
311
|
+
});
|
|
312
|
+
Object.defineProperty(Element.prototype, "tagName", {
|
|
313
|
+
// DOM Level 1 aliases
|
|
314
|
+
/**
|
|
315
|
+
* Same as {@link name}.
|
|
316
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
317
|
+
*/
|
|
318
|
+
get: function () {
|
|
319
|
+
return this.name;
|
|
320
|
+
},
|
|
321
|
+
set: function (name) {
|
|
322
|
+
this.name = name;
|
|
323
|
+
},
|
|
324
|
+
enumerable: false,
|
|
325
|
+
configurable: true
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(Element.prototype, "attributes", {
|
|
328
|
+
get: function () {
|
|
329
|
+
var _this = this;
|
|
330
|
+
return Object.keys(this.attribs).map(function (name) {
|
|
331
|
+
var _a, _b;
|
|
332
|
+
return ({
|
|
333
|
+
name: name,
|
|
334
|
+
value: _this.attribs[name],
|
|
335
|
+
namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
|
|
336
|
+
prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
enumerable: false,
|
|
341
|
+
configurable: true
|
|
342
|
+
});
|
|
343
|
+
return Element;
|
|
344
|
+
}(NodeWithChildren));
|
|
345
|
+
exports.Element = Element;
|
|
346
|
+
/**
|
|
347
|
+
* @param node Node to check.
|
|
348
|
+
* @returns `true` if the node is a `Element`, `false` otherwise.
|
|
349
|
+
*/
|
|
350
|
+
function isTag(node) {
|
|
351
|
+
return (0, domelementtype_1.isTag)(node);
|
|
352
|
+
}
|
|
353
|
+
exports.isTag = isTag;
|
|
354
|
+
/**
|
|
355
|
+
* @param node Node to check.
|
|
356
|
+
* @returns `true` if the node has the type `CDATA`, `false` otherwise.
|
|
357
|
+
*/
|
|
358
|
+
function isCDATA(node) {
|
|
359
|
+
return node.type === domelementtype_1.ElementType.CDATA;
|
|
360
|
+
}
|
|
361
|
+
exports.isCDATA = isCDATA;
|
|
362
|
+
/**
|
|
363
|
+
* @param node Node to check.
|
|
364
|
+
* @returns `true` if the node has the type `Text`, `false` otherwise.
|
|
365
|
+
*/
|
|
366
|
+
function isText(node) {
|
|
367
|
+
return node.type === domelementtype_1.ElementType.Text;
|
|
368
|
+
}
|
|
369
|
+
exports.isText = isText;
|
|
370
|
+
/**
|
|
371
|
+
* @param node Node to check.
|
|
372
|
+
* @returns `true` if the node has the type `Comment`, `false` otherwise.
|
|
373
|
+
*/
|
|
374
|
+
function isComment(node) {
|
|
375
|
+
return node.type === domelementtype_1.ElementType.Comment;
|
|
376
|
+
}
|
|
377
|
+
exports.isComment = isComment;
|
|
378
|
+
/**
|
|
379
|
+
* @param node Node to check.
|
|
380
|
+
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
|
|
381
|
+
*/
|
|
382
|
+
function isDirective(node) {
|
|
383
|
+
return node.type === domelementtype_1.ElementType.Directive;
|
|
384
|
+
}
|
|
385
|
+
exports.isDirective = isDirective;
|
|
386
|
+
/**
|
|
387
|
+
* @param node Node to check.
|
|
388
|
+
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
|
|
389
|
+
*/
|
|
390
|
+
function isDocument(node) {
|
|
391
|
+
return node.type === domelementtype_1.ElementType.Root;
|
|
392
|
+
}
|
|
393
|
+
exports.isDocument = isDocument;
|
|
394
|
+
/**
|
|
395
|
+
* @param node Node to check.
|
|
396
|
+
* @returns `true` if the node has children, `false` otherwise.
|
|
397
|
+
*/
|
|
398
|
+
function hasChildren(node) {
|
|
399
|
+
return Object.prototype.hasOwnProperty.call(node, "children");
|
|
400
|
+
}
|
|
401
|
+
exports.hasChildren = hasChildren;
|
|
402
|
+
/**
|
|
403
|
+
* Clone a node, and optionally its children.
|
|
404
|
+
*
|
|
405
|
+
* @param recursive Clone child nodes as well.
|
|
406
|
+
* @returns A clone of the node.
|
|
407
|
+
*/
|
|
408
|
+
function cloneNode(node, recursive) {
|
|
409
|
+
if (recursive === void 0) { recursive = false; }
|
|
410
|
+
var result;
|
|
411
|
+
if (isText(node)) {
|
|
412
|
+
result = new Text(node.data);
|
|
413
|
+
}
|
|
414
|
+
else if (isComment(node)) {
|
|
415
|
+
result = new Comment(node.data);
|
|
416
|
+
}
|
|
417
|
+
else if (isTag(node)) {
|
|
418
|
+
var children = recursive ? cloneChildren(node.children) : [];
|
|
419
|
+
var clone_1 = new Element(node.name, __assign({}, node.attribs), children);
|
|
420
|
+
children.forEach(function (child) { return (child.parent = clone_1); });
|
|
421
|
+
if (node.namespace != null) {
|
|
422
|
+
clone_1.namespace = node.namespace;
|
|
423
|
+
}
|
|
424
|
+
if (node["x-attribsNamespace"]) {
|
|
425
|
+
clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
|
|
426
|
+
}
|
|
427
|
+
if (node["x-attribsPrefix"]) {
|
|
428
|
+
clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
|
|
429
|
+
}
|
|
430
|
+
result = clone_1;
|
|
431
|
+
}
|
|
432
|
+
else if (isCDATA(node)) {
|
|
433
|
+
var children = recursive ? cloneChildren(node.children) : [];
|
|
434
|
+
var clone_2 = new CDATA(children);
|
|
435
|
+
children.forEach(function (child) { return (child.parent = clone_2); });
|
|
436
|
+
result = clone_2;
|
|
437
|
+
}
|
|
438
|
+
else if (isDocument(node)) {
|
|
439
|
+
var children = recursive ? cloneChildren(node.children) : [];
|
|
440
|
+
var clone_3 = new Document(children);
|
|
441
|
+
children.forEach(function (child) { return (child.parent = clone_3); });
|
|
442
|
+
if (node["x-mode"]) {
|
|
443
|
+
clone_3["x-mode"] = node["x-mode"];
|
|
444
|
+
}
|
|
445
|
+
result = clone_3;
|
|
446
|
+
}
|
|
447
|
+
else if (isDirective(node)) {
|
|
448
|
+
var instruction = new ProcessingInstruction(node.name, node.data);
|
|
449
|
+
if (node["x-name"] != null) {
|
|
450
|
+
instruction["x-name"] = node["x-name"];
|
|
451
|
+
instruction["x-publicId"] = node["x-publicId"];
|
|
452
|
+
instruction["x-systemId"] = node["x-systemId"];
|
|
453
|
+
}
|
|
454
|
+
result = instruction;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
throw new Error("Not implemented yet: ".concat(node.type));
|
|
458
|
+
}
|
|
459
|
+
result.startIndex = node.startIndex;
|
|
460
|
+
result.endIndex = node.endIndex;
|
|
461
|
+
if (node.sourceCodeLocation != null) {
|
|
462
|
+
result.sourceCodeLocation = node.sourceCodeLocation;
|
|
463
|
+
}
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
exports.cloneNode = cloneNode;
|
|
467
|
+
function cloneChildren(childs) {
|
|
468
|
+
var children = childs.map(function (child) { return cloneNode(child, true); });
|
|
469
|
+
for (var i = 1; i < children.length; i++) {
|
|
470
|
+
children[i].prev = children[i - 1];
|
|
471
|
+
children[i - 1].next = children[i];
|
|
472
|
+
}
|
|
473
|
+
return children;
|
|
474
|
+
}
|