@websolutespa/bom-next 3.0.1 → 3.0.2
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/CHANGELOG.md +1 -1
- package/dist/_virtual/_rolldown/runtime.js +24 -0
- package/dist/client/client.d.ts +9 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +18 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/extra.d.ts +17 -0
- package/dist/client/extra.d.ts.map +1 -0
- package/dist/client/extra.js +13 -0
- package/dist/client/extra.js.map +1 -0
- package/dist/client/label.d.ts +15 -0
- package/dist/client/label.d.ts.map +1 -0
- package/dist/client/label.js +20 -0
- package/dist/client/label.js.map +1 -0
- package/dist/client/layout.d.ts +18 -0
- package/dist/client/layout.d.ts.map +1 -0
- package/dist/client/layout.js +13 -0
- package/dist/client/layout.js.map +1 -0
- package/dist/client/local.collection.d.ts +32 -0
- package/dist/client/local.collection.d.ts.map +1 -0
- package/dist/client/local.collection.js +49 -0
- package/dist/client/local.collection.js.map +1 -0
- package/dist/client/metadata.d.ts +43 -0
- package/dist/client/metadata.d.ts.map +1 -0
- package/dist/client/metadata.js +146 -0
- package/dist/client/metadata.js.map +1 -0
- package/dist/client/page.d.ts +404 -0
- package/dist/client/page.d.ts.map +1 -0
- package/dist/client/page.js +13 -0
- package/dist/client/page.js.map +1 -0
- package/dist/client/useApi.d.ts +21 -0
- package/dist/client/useApi.d.ts.map +1 -0
- package/dist/client/useApi.js +65 -0
- package/dist/client/useApi.js.map +1 -0
- package/dist/client/useCollectionApi.d.ts +21 -0
- package/dist/client/useCollectionApi.d.ts.map +1 -0
- package/dist/client/useCollectionApi.js +65 -0
- package/dist/client/useCollectionApi.js.map +1 -0
- package/dist/client/useExtra.d.ts +9 -0
- package/dist/client/useExtra.d.ts.map +1 -0
- package/dist/client/useExtra.js +13 -0
- package/dist/client/useExtra.js.map +1 -0
- package/dist/client/useHttp.d.ts +15 -0
- package/dist/client/useHttp.d.ts.map +1 -0
- package/dist/client/useHttp.js +70 -0
- package/dist/client/useHttp.js.map +1 -0
- package/dist/client/useLabel.d.ts +9 -0
- package/dist/client/useLabel.d.ts.map +1 -0
- package/dist/client/useLabel.js +13 -0
- package/dist/client/useLabel.js.map +1 -0
- package/dist/client/useLayout.d.ts +9 -0
- package/dist/client/useLayout.d.ts.map +1 -0
- package/dist/client/useLayout.js +13 -0
- package/dist/client/useLayout.js.map +1 -0
- package/dist/client/useLink.d.ts +7 -0
- package/dist/client/useLink.d.ts.map +1 -0
- package/dist/client/useLink.js +15 -0
- package/dist/client/useLink.js.map +1 -0
- package/dist/client/useMetaData.d.ts +9 -0
- package/dist/client/useMetaData.d.ts.map +1 -0
- package/dist/client/useMetaData.js +13 -0
- package/dist/client/useMetaData.js.map +1 -0
- package/dist/client/usePage.d.ts +394 -0
- package/dist/client/usePage.d.ts.map +1 -0
- package/dist/client/usePage.js +13 -0
- package/dist/client/usePage.js.map +1 -0
- package/dist/client/useUser.d.ts +9 -0
- package/dist/client/useUser.d.ts.map +1 -0
- package/dist/client/useUser.js +13 -0
- package/dist/client/useUser.js.map +1 -0
- package/dist/client/user.d.ts +20 -0
- package/dist/client/user.d.ts.map +1 -0
- package/dist/client/user.js +33 -0
- package/dist/client/user.js.map +1 -0
- package/dist/exports/client.d.ts +20 -979
- package/dist/exports/client.js +19 -5734
- package/dist/exports/instrumentation.d.ts +2 -13
- package/dist/exports/instrumentation.js +1 -24
- package/dist/exports/proxy.d.ts +5 -71
- package/dist/exports/proxy.js +4 -253
- package/dist/exports/server.d.ts +19 -402
- package/dist/exports/server.js +18 -1973
- package/dist/index.d.ts +18 -499
- package/dist/index.js +10 -200
- package/dist/instrumentation/client.d.ts +8 -0
- package/dist/instrumentation/client.d.ts.map +1 -0
- package/dist/instrumentation/client.js +15 -0
- package/dist/instrumentation/client.js.map +1 -0
- package/dist/instrumentation/sentry/capture.requestError.js +10 -0
- package/dist/instrumentation/sentry/capture.requestError.js.map +1 -0
- package/dist/instrumentation/sentry/capture.routerTransitionStart.js +7 -0
- package/dist/instrumentation/sentry/capture.routerTransitionStart.js.map +1 -0
- package/dist/instrumentation/server.d.ts +13 -0
- package/dist/instrumentation/server.d.ts.map +1 -0
- package/dist/instrumentation/server.js +19 -0
- package/dist/instrumentation/server.js.map +1 -0
- package/dist/{types2.d.ts → instrumentation/types.d.ts} +2 -2
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/lib/breadcrumb.d.ts +15 -0
- package/dist/lib/breadcrumb.d.ts.map +1 -0
- package/dist/lib/breadcrumb.js +20 -0
- package/dist/lib/breadcrumb.js.map +1 -0
- package/dist/lib/const.d.ts +9 -0
- package/dist/lib/const.d.ts.map +1 -0
- package/dist/lib/const.js +9 -0
- package/dist/lib/const.js.map +1 -0
- package/dist/lib/http.d.ts +36 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/{http.js → lib/http.js} +1 -1
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/label.d.ts +16 -0
- package/dist/lib/label.d.ts.map +1 -0
- package/dist/lib/label.js +33 -0
- package/dist/lib/label.js.map +1 -0
- package/dist/lib/layout.defaults.d.ts +9 -0
- package/dist/lib/layout.defaults.d.ts.map +1 -0
- package/dist/lib/layout.defaults.js +161 -0
- package/dist/lib/layout.defaults.js.map +1 -0
- package/dist/lib/link.d.ts +9 -0
- package/dist/lib/link.d.ts.map +1 -0
- package/dist/lib/link.js +16 -0
- package/dist/lib/link.js.map +1 -0
- package/dist/lib/meta-data.d.ts +56 -0
- package/dist/lib/meta-data.d.ts.map +1 -0
- package/dist/lib/open-graph.d.ts +143 -0
- package/dist/lib/open-graph.d.ts.map +1 -0
- package/dist/lib/pagination.d.ts +27 -0
- package/dist/lib/pagination.d.ts.map +1 -0
- package/dist/lib/pagination.js +39 -0
- package/dist/lib/pagination.js.map +1 -0
- package/dist/lib/route.d.ts +17 -0
- package/dist/lib/route.d.ts.map +1 -0
- package/dist/{route.js → lib/route.js} +1 -1
- package/dist/lib/route.js.map +1 -0
- package/dist/lib/store.d.ts +27 -0
- package/dist/lib/store.d.ts.map +1 -0
- package/dist/{store.js → lib/store.js} +1 -24
- package/dist/lib/store.js.map +1 -0
- package/dist/lib/structured-data.d.ts +9 -0
- package/dist/lib/structured-data.d.ts.map +1 -0
- package/dist/lib/twitter-card.d.ts +43 -0
- package/dist/lib/twitter-card.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +13 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +35 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/mock.d.ts +127 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +75 -0
- package/dist/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js.map +1 -0
- package/dist/node_modules/deepmerge/dist/cjs.js +86 -0
- package/dist/node_modules/deepmerge/dist/cjs.js.map +1 -0
- package/dist/node_modules/dom-serializer/lib/esm/foreignNames.js +105 -0
- package/dist/node_modules/dom-serializer/lib/esm/foreignNames.js.map +1 -0
- package/dist/node_modules/dom-serializer/lib/esm/index.js +146 -0
- package/dist/node_modules/dom-serializer/lib/esm/index.js.map +1 -0
- package/dist/node_modules/domelementtype/lib/esm/index.js +53 -0
- package/dist/node_modules/domelementtype/lib/esm/index.js.map +1 -0
- package/dist/node_modules/domhandler/lib/esm/index.js +130 -0
- package/dist/node_modules/domhandler/lib/esm/index.js.map +1 -0
- package/dist/node_modules/domhandler/lib/esm/node.js +307 -0
- package/dist/node_modules/domhandler/lib/esm/node.js.map +1 -0
- package/dist/node_modules/entities/lib/esm/decode.js +363 -0
- package/dist/node_modules/entities/lib/esm/decode.js.map +1 -0
- package/dist/node_modules/entities/lib/esm/decode_codepoint.js +59 -0
- package/dist/node_modules/entities/lib/esm/decode_codepoint.js.map +1 -0
- package/dist/node_modules/entities/lib/esm/escape.js +85 -0
- package/dist/node_modules/entities/lib/esm/escape.js.map +1 -0
- package/dist/node_modules/entities/lib/esm/generated/decode-data-html.js +6 -0
- package/dist/node_modules/entities/lib/esm/generated/decode-data-html.js.map +1 -0
- package/dist/node_modules/entities/lib/esm/generated/decode-data-xml.js +6 -0
- package/dist/node_modules/entities/lib/esm/generated/decode-data-xml.js.map +1 -0
- package/dist/node_modules/html-to-text/lib/html-to-text.js +1816 -0
- package/dist/node_modules/html-to-text/lib/html-to-text.js.map +1 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Parser.js +435 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Parser.js.map +1 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Tokenizer.js +736 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Tokenizer.js.map +1 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/index.js +19 -0
- package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/index.js.map +1 -0
- package/dist/node_modules/leac/lib/leac.js +101 -0
- package/dist/node_modules/leac/lib/leac.js.map +1 -0
- package/dist/node_modules/parseley/lib/parseley.js +310 -0
- package/dist/node_modules/parseley/lib/parseley.js.map +1 -0
- package/dist/node_modules/peberminta/lib/core.js +149 -0
- package/dist/node_modules/peberminta/lib/core.js.map +1 -0
- package/dist/node_modules/selderee/lib/selderee.js +319 -0
- package/dist/node_modules/selderee/lib/selderee.js.map +1 -0
- package/dist/proxy/protected-route.d.ts +9 -0
- package/dist/proxy/protected-route.d.ts.map +1 -0
- package/dist/proxy/protected-route.js +40 -0
- package/dist/proxy/protected-route.js.map +1 -0
- package/dist/proxy/proxy.d.ts +31 -0
- package/dist/proxy/proxy.d.ts.map +1 -0
- package/dist/proxy/proxy.js +49 -0
- package/dist/proxy/proxy.js.map +1 -0
- package/dist/proxy/route-auto-detection.d.ts +12 -0
- package/dist/proxy/route-auto-detection.d.ts.map +1 -0
- package/dist/proxy/route-auto-detection.js +82 -0
- package/dist/proxy/route-auto-detection.js.map +1 -0
- package/dist/proxy/route-proxy.d.ts +36 -0
- package/dist/proxy/route-proxy.d.ts.map +1 -0
- package/dist/proxy/route-proxy.js +103 -0
- package/dist/proxy/route-proxy.js.map +1 -0
- package/dist/server/context.d.ts +30 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +106 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/handlers/auth.handler.d.ts +10 -0
- package/dist/server/handlers/auth.handler.d.ts.map +1 -0
- package/dist/server/handlers/auth.handler.js +29 -0
- package/dist/server/handlers/auth.handler.js.map +1 -0
- package/dist/server/handlers/captions.handler.d.ts +10 -0
- package/dist/server/handlers/captions.handler.d.ts.map +1 -0
- package/dist/server/handlers/captions.handler.js +33 -0
- package/dist/server/handlers/captions.handler.js.map +1 -0
- package/dist/server/handlers/collection.handler.d.ts +36 -0
- package/dist/server/handlers/collection.handler.d.ts.map +1 -0
- package/dist/server/handlers/collection.handler.js +166 -0
- package/dist/server/handlers/collection.handler.js.map +1 -0
- package/dist/server/handlers/error-response.js +24 -0
- package/dist/server/handlers/error-response.js.map +1 -0
- package/dist/server/handlers/index.handler.d.ts +9 -0
- package/dist/server/handlers/index.handler.d.ts.map +1 -0
- package/dist/server/handlers/index.handler.js +145 -0
- package/dist/server/handlers/index.handler.js.map +1 -0
- package/dist/server/handlers/preview.handler.d.ts +9 -0
- package/dist/server/handlers/preview.handler.d.ts.map +1 -0
- package/dist/server/handlers/preview.handler.js +15 -0
- package/dist/server/handlers/preview.handler.js.map +1 -0
- package/dist/server/handlers/registry.handler.d.ts +16 -0
- package/dist/server/handlers/registry.handler.d.ts.map +1 -0
- package/dist/server/handlers/registry.handler.js +260 -0
- package/dist/server/handlers/registry.handler.js.map +1 -0
- package/dist/server/handlers/route.handler.d.ts +20 -0
- package/dist/server/handlers/route.handler.d.ts.map +1 -0
- package/dist/server/handlers/route.handler.js +122 -0
- package/dist/server/handlers/route.handler.js.map +1 -0
- package/dist/server/handlers/sitemap.handler.d.ts +30 -0
- package/dist/server/handlers/sitemap.handler.d.ts.map +1 -0
- package/dist/server/handlers/sitemap.handler.js +338 -0
- package/dist/server/handlers/sitemap.handler.js.map +1 -0
- package/dist/server/handlers/static-params.handler.d.ts +24 -0
- package/dist/server/handlers/static-params.handler.d.ts.map +1 -0
- package/dist/server/handlers/static-params.handler.js +56 -0
- package/dist/server/handlers/static-params.handler.js.map +1 -0
- package/dist/server/handlers/vars.handler.d.ts +10 -0
- package/dist/server/handlers/vars.handler.d.ts.map +1 -0
- package/dist/server/handlers/vars.handler.js +159 -0
- package/dist/server/handlers/vars.handler.js.map +1 -0
- package/dist/server/layout.js +88 -0
- package/dist/server/layout.js.map +1 -0
- package/dist/server/lazy.d.ts +11 -0
- package/dist/server/lazy.d.ts.map +1 -0
- package/dist/server/lazy.js +33 -0
- package/dist/server/lazy.js.map +1 -0
- package/dist/server/local-api.d.ts +9 -0
- package/dist/server/local-api.d.ts.map +1 -0
- package/dist/server/local-api.js +60 -0
- package/dist/server/local-api.js.map +1 -0
- package/dist/server/metadata.d.ts +21 -0
- package/dist/server/metadata.d.ts.map +1 -0
- package/dist/server/metadata.js +20 -0
- package/dist/server/metadata.js.map +1 -0
- package/dist/server/mixer-payload.d.ts +63 -0
- package/dist/server/mixer-payload.d.ts.map +1 -0
- package/dist/server/mixer.d.ts +214 -0
- package/dist/server/mixer.d.ts.map +1 -0
- package/dist/server/mixer.js +355 -0
- package/dist/server/mixer.js.map +1 -0
- package/dist/server/page.d.ts +22 -0
- package/dist/server/page.d.ts.map +1 -0
- package/dist/server/page.js +57 -0
- package/dist/server/page.js.map +1 -0
- package/dist/server/utils.d.ts +12 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/{utils2.js → server/utils.js} +3 -3
- package/dist/server/utils.js.map +1 -0
- package/dist/server/utmz.d.ts +9 -0
- package/dist/server/utmz.d.ts.map +1 -0
- package/dist/server/utmz.js +14 -0
- package/dist/server/utmz.js.map +1 -0
- package/dist/types.d.ts +6 -61
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/client.js.map +0 -1
- package/dist/exports/instrumentation.d.ts.map +0 -1
- package/dist/exports/instrumentation.js.map +0 -1
- package/dist/exports/proxy.d.ts.map +0 -1
- package/dist/exports/proxy.js.map +0 -1
- package/dist/exports/server.d.ts.map +0 -1
- package/dist/exports/server.js.map +0 -1
- package/dist/http.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index2.d.ts +0 -4
- package/dist/route.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/types2.d.ts.map +0 -1
- package/dist/utils.js +0 -78
- package/dist/utils.js.map +0 -1
- package/dist/utils2.js.map +0 -1
- /package/dist/{config.client.js → instrumentation/sentry/config.client.js} +0 -0
- /package/dist/{config.edge.js → instrumentation/sentry/config.edge.js} +0 -0
- /package/dist/{config.server.js → instrumentation/sentry/config.server.js} +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CDATA, Comment, Directive, Doctype, Root, Script, Style, Tag, Text } from "../../../domelementtype/lib/esm/index.js";
|
|
2
|
+
import { encodeXML, escapeAttribute, escapeText } from "../../../entities/lib/esm/escape.js";
|
|
3
|
+
import { attributeNames, elementNames } from "./foreignNames.js";
|
|
4
|
+
//#region ../../node_modules/dom-serializer/lib/esm/index.js
|
|
5
|
+
/**
|
|
6
|
+
* Mixed-case SVG and MathML tags & attributes
|
|
7
|
+
* recognized by the HTML parser.
|
|
8
|
+
*
|
|
9
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
10
|
+
*/
|
|
11
|
+
const unencodedElements = /* @__PURE__ */ new Set([
|
|
12
|
+
"style",
|
|
13
|
+
"script",
|
|
14
|
+
"xmp",
|
|
15
|
+
"iframe",
|
|
16
|
+
"noembed",
|
|
17
|
+
"noframes",
|
|
18
|
+
"plaintext",
|
|
19
|
+
"noscript"
|
|
20
|
+
]);
|
|
21
|
+
function replaceQuotes(value) {
|
|
22
|
+
return value.replace(/"/g, """);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Format attributes
|
|
26
|
+
*/
|
|
27
|
+
function formatAttributes(attributes, opts) {
|
|
28
|
+
var _a;
|
|
29
|
+
if (!attributes) return;
|
|
30
|
+
const encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false ? replaceQuotes : opts.xmlMode || opts.encodeEntities !== "utf8" ? encodeXML : escapeAttribute;
|
|
31
|
+
return Object.keys(attributes).map((key) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : "";
|
|
34
|
+
if (opts.xmlMode === "foreign") key = (_b = attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;
|
|
35
|
+
if (!opts.emptyAttrs && !opts.xmlMode && value === "") return key;
|
|
36
|
+
return `${key}="${encode(value)}"`;
|
|
37
|
+
}).join(" ");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Self-enclosing tags
|
|
41
|
+
*/
|
|
42
|
+
const singleTag = /* @__PURE__ */ new Set([
|
|
43
|
+
"area",
|
|
44
|
+
"base",
|
|
45
|
+
"basefont",
|
|
46
|
+
"br",
|
|
47
|
+
"col",
|
|
48
|
+
"command",
|
|
49
|
+
"embed",
|
|
50
|
+
"frame",
|
|
51
|
+
"hr",
|
|
52
|
+
"img",
|
|
53
|
+
"input",
|
|
54
|
+
"isindex",
|
|
55
|
+
"keygen",
|
|
56
|
+
"link",
|
|
57
|
+
"meta",
|
|
58
|
+
"param",
|
|
59
|
+
"source",
|
|
60
|
+
"track",
|
|
61
|
+
"wbr"
|
|
62
|
+
]);
|
|
63
|
+
/**
|
|
64
|
+
* Renders a DOM node or an array of DOM nodes to a string.
|
|
65
|
+
*
|
|
66
|
+
* Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
|
|
67
|
+
*
|
|
68
|
+
* @param node Node to be rendered.
|
|
69
|
+
* @param options Changes serialization behavior
|
|
70
|
+
*/
|
|
71
|
+
function render(node, options = {}) {
|
|
72
|
+
const nodes = "length" in node ? node : [node];
|
|
73
|
+
let output = "";
|
|
74
|
+
for (let i = 0; i < nodes.length; i++) output += renderNode(nodes[i], options);
|
|
75
|
+
return output;
|
|
76
|
+
}
|
|
77
|
+
function renderNode(node, options) {
|
|
78
|
+
switch (node.type) {
|
|
79
|
+
case Root: return render(node.children, options);
|
|
80
|
+
case Doctype:
|
|
81
|
+
case Directive: return renderDirective(node);
|
|
82
|
+
case Comment: return renderComment(node);
|
|
83
|
+
case CDATA: return renderCdata(node);
|
|
84
|
+
case Script:
|
|
85
|
+
case Style:
|
|
86
|
+
case Tag: return renderTag(node, options);
|
|
87
|
+
case Text: return renderText(node, options);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const foreignModeIntegrationPoints = /* @__PURE__ */ new Set([
|
|
91
|
+
"mi",
|
|
92
|
+
"mo",
|
|
93
|
+
"mn",
|
|
94
|
+
"ms",
|
|
95
|
+
"mtext",
|
|
96
|
+
"annotation-xml",
|
|
97
|
+
"foreignObject",
|
|
98
|
+
"desc",
|
|
99
|
+
"title"
|
|
100
|
+
]);
|
|
101
|
+
const foreignElements = /* @__PURE__ */ new Set(["svg", "math"]);
|
|
102
|
+
function renderTag(elem, opts) {
|
|
103
|
+
var _a;
|
|
104
|
+
if (opts.xmlMode === "foreign") {
|
|
105
|
+
elem.name = (_a = elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;
|
|
106
|
+
if (elem.parent && foreignModeIntegrationPoints.has(elem.parent.name)) opts = {
|
|
107
|
+
...opts,
|
|
108
|
+
xmlMode: false
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (!opts.xmlMode && foreignElements.has(elem.name)) opts = {
|
|
112
|
+
...opts,
|
|
113
|
+
xmlMode: "foreign"
|
|
114
|
+
};
|
|
115
|
+
let tag = `<${elem.name}`;
|
|
116
|
+
const attribs = formatAttributes(elem.attribs, opts);
|
|
117
|
+
if (attribs) tag += ` ${attribs}`;
|
|
118
|
+
if (elem.children.length === 0 && (opts.xmlMode ? opts.selfClosingTags !== false : opts.selfClosingTags && singleTag.has(elem.name))) {
|
|
119
|
+
if (!opts.xmlMode) tag += " ";
|
|
120
|
+
tag += "/>";
|
|
121
|
+
} else {
|
|
122
|
+
tag += ">";
|
|
123
|
+
if (elem.children.length > 0) tag += render(elem.children, opts);
|
|
124
|
+
if (opts.xmlMode || !singleTag.has(elem.name)) tag += `</${elem.name}>`;
|
|
125
|
+
}
|
|
126
|
+
return tag;
|
|
127
|
+
}
|
|
128
|
+
function renderDirective(elem) {
|
|
129
|
+
return `<${elem.data}>`;
|
|
130
|
+
}
|
|
131
|
+
function renderText(elem, opts) {
|
|
132
|
+
var _a;
|
|
133
|
+
let data = elem.data || "";
|
|
134
|
+
if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false && !(!opts.xmlMode && elem.parent && unencodedElements.has(elem.parent.name))) data = opts.xmlMode || opts.encodeEntities !== "utf8" ? encodeXML(data) : escapeText(data);
|
|
135
|
+
return data;
|
|
136
|
+
}
|
|
137
|
+
function renderCdata(elem) {
|
|
138
|
+
return `<![CDATA[${elem.children[0].data}]]>`;
|
|
139
|
+
}
|
|
140
|
+
function renderComment(elem) {
|
|
141
|
+
return `<!--${elem.data}-->`;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { render as default, render };
|
|
145
|
+
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ElementType.Root","ElementType.Doctype","ElementType.Directive","ElementType.Comment","ElementType.CDATA","ElementType.Script","ElementType.Style","ElementType.Tag","ElementType.Text"],"sources":["../../../../../../../node_modules/dom-serializer/lib/esm/index.js"],"sourcesContent":["/*\n * Module dependencies\n */\nimport * as ElementType from \"domelementtype\";\nimport { encodeXML, escapeAttribute, escapeText } from \"entities\";\n/**\n * Mixed-case SVG and MathML tags & attributes\n * recognized by the HTML parser.\n *\n * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign\n */\nimport { elementNames, attributeNames } from \"./foreignNames.js\";\nconst unencodedElements = new Set([\n \"style\",\n \"script\",\n \"xmp\",\n \"iframe\",\n \"noembed\",\n \"noframes\",\n \"plaintext\",\n \"noscript\",\n]);\nfunction replaceQuotes(value) {\n return value.replace(/\"/g, \""\");\n}\n/**\n * Format attributes\n */\nfunction formatAttributes(attributes, opts) {\n var _a;\n if (!attributes)\n return;\n const encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false\n ? replaceQuotes\n : opts.xmlMode || opts.encodeEntities !== \"utf8\"\n ? encodeXML\n : escapeAttribute;\n return Object.keys(attributes)\n .map((key) => {\n var _a, _b;\n const value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : \"\";\n if (opts.xmlMode === \"foreign\") {\n /* Fix up mixed-case attribute names */\n key = (_b = attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;\n }\n if (!opts.emptyAttrs && !opts.xmlMode && value === \"\") {\n return key;\n }\n return `${key}=\"${encode(value)}\"`;\n })\n .join(\" \");\n}\n/**\n * Self-enclosing tags\n */\nconst singleTag = new Set([\n \"area\",\n \"base\",\n \"basefont\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"frame\",\n \"hr\",\n \"img\",\n \"input\",\n \"isindex\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n/**\n * Renders a DOM node or an array of DOM nodes to a string.\n *\n * Can be thought of as the equivalent of the `outerHTML` of the passed node(s).\n *\n * @param node Node to be rendered.\n * @param options Changes serialization behavior\n */\nexport function render(node, options = {}) {\n const nodes = \"length\" in node ? node : [node];\n let output = \"\";\n for (let i = 0; i < nodes.length; i++) {\n output += renderNode(nodes[i], options);\n }\n return output;\n}\nexport default render;\nfunction renderNode(node, options) {\n switch (node.type) {\n case ElementType.Root:\n return render(node.children, options);\n // @ts-expect-error We don't use `Doctype` yet\n case ElementType.Doctype:\n case ElementType.Directive:\n return renderDirective(node);\n case ElementType.Comment:\n return renderComment(node);\n case ElementType.CDATA:\n return renderCdata(node);\n case ElementType.Script:\n case ElementType.Style:\n case ElementType.Tag:\n return renderTag(node, options);\n case ElementType.Text:\n return renderText(node, options);\n }\n}\nconst foreignModeIntegrationPoints = new Set([\n \"mi\",\n \"mo\",\n \"mn\",\n \"ms\",\n \"mtext\",\n \"annotation-xml\",\n \"foreignObject\",\n \"desc\",\n \"title\",\n]);\nconst foreignElements = new Set([\"svg\", \"math\"]);\nfunction renderTag(elem, opts) {\n var _a;\n // Handle SVG / MathML in HTML\n if (opts.xmlMode === \"foreign\") {\n /* Fix up mixed-case element names */\n elem.name = (_a = elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;\n /* Exit foreign mode at integration points */\n if (elem.parent &&\n foreignModeIntegrationPoints.has(elem.parent.name)) {\n opts = { ...opts, xmlMode: false };\n }\n }\n if (!opts.xmlMode && foreignElements.has(elem.name)) {\n opts = { ...opts, xmlMode: \"foreign\" };\n }\n let tag = `<${elem.name}`;\n const attribs = formatAttributes(elem.attribs, opts);\n if (attribs) {\n tag += ` ${attribs}`;\n }\n if (elem.children.length === 0 &&\n (opts.xmlMode\n ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags\n opts.selfClosingTags !== false\n : // User explicitly asked for self-closing tags, even in HTML mode\n opts.selfClosingTags && singleTag.has(elem.name))) {\n if (!opts.xmlMode)\n tag += \" \";\n tag += \"/>\";\n }\n else {\n tag += \">\";\n if (elem.children.length > 0) {\n tag += render(elem.children, opts);\n }\n if (opts.xmlMode || !singleTag.has(elem.name)) {\n tag += `</${elem.name}>`;\n }\n }\n return tag;\n}\nfunction renderDirective(elem) {\n return `<${elem.data}>`;\n}\nfunction renderText(elem, opts) {\n var _a;\n let data = elem.data || \"\";\n // If entities weren't decoded, no need to encode them back\n if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false &&\n !(!opts.xmlMode &&\n elem.parent &&\n unencodedElements.has(elem.parent.name))) {\n data =\n opts.xmlMode || opts.encodeEntities !== \"utf8\"\n ? encodeXML(data)\n : escapeText(data);\n }\n return data;\n}\nfunction renderCdata(elem) {\n return `<![CDATA[${elem.children[0].data}]]>`;\n}\nfunction renderComment(elem) {\n return `<!--${elem.data}-->`;\n}\n"],"x_google_ignoreList":[0],"mappings":"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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region ../../node_modules/domelementtype/lib/esm/index.js
|
|
2
|
+
/** Types of elements found in htmlparser2's DOM */
|
|
3
|
+
var ElementType;
|
|
4
|
+
(function(ElementType) {
|
|
5
|
+
/** Type for the root element of a document */
|
|
6
|
+
ElementType["Root"] = "root";
|
|
7
|
+
/** Type for Text */
|
|
8
|
+
ElementType["Text"] = "text";
|
|
9
|
+
/** Type for <? ... ?> */
|
|
10
|
+
ElementType["Directive"] = "directive";
|
|
11
|
+
/** Type for <!-- ... --> */
|
|
12
|
+
ElementType["Comment"] = "comment";
|
|
13
|
+
/** Type for <script> tags */
|
|
14
|
+
ElementType["Script"] = "script";
|
|
15
|
+
/** Type for <style> tags */
|
|
16
|
+
ElementType["Style"] = "style";
|
|
17
|
+
/** Type for Any tag */
|
|
18
|
+
ElementType["Tag"] = "tag";
|
|
19
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
20
|
+
ElementType["CDATA"] = "cdata";
|
|
21
|
+
/** Type for <!doctype ...> */
|
|
22
|
+
ElementType["Doctype"] = "doctype";
|
|
23
|
+
})(ElementType || (ElementType = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Tests whether an element is a tag or not.
|
|
26
|
+
*
|
|
27
|
+
* @param elem Element to test
|
|
28
|
+
*/
|
|
29
|
+
function isTag(elem) {
|
|
30
|
+
return elem.type === ElementType.Tag || elem.type === ElementType.Script || elem.type === ElementType.Style;
|
|
31
|
+
}
|
|
32
|
+
/** Type for the root element of a document */
|
|
33
|
+
const Root = ElementType.Root;
|
|
34
|
+
/** Type for Text */
|
|
35
|
+
const Text = ElementType.Text;
|
|
36
|
+
/** Type for <? ... ?> */
|
|
37
|
+
const Directive = ElementType.Directive;
|
|
38
|
+
/** Type for <!-- ... --> */
|
|
39
|
+
const Comment = ElementType.Comment;
|
|
40
|
+
/** Type for <script> tags */
|
|
41
|
+
const Script = ElementType.Script;
|
|
42
|
+
/** Type for <style> tags */
|
|
43
|
+
const Style = ElementType.Style;
|
|
44
|
+
/** Type for Any tag */
|
|
45
|
+
const Tag = ElementType.Tag;
|
|
46
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
47
|
+
const CDATA = ElementType.CDATA;
|
|
48
|
+
/** Type for <!doctype ...> */
|
|
49
|
+
const Doctype = ElementType.Doctype;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { CDATA, Comment, Directive, Doctype, ElementType, Root, Script, Style, Tag, Text, isTag };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../node_modules/domelementtype/lib/esm/index.js"],"sourcesContent":["/** Types of elements found in htmlparser2's DOM */\nexport var ElementType;\n(function (ElementType) {\n /** Type for the root element of a document */\n ElementType[\"Root\"] = \"root\";\n /** Type for Text */\n ElementType[\"Text\"] = \"text\";\n /** Type for <? ... ?> */\n ElementType[\"Directive\"] = \"directive\";\n /** Type for <!-- ... --> */\n ElementType[\"Comment\"] = \"comment\";\n /** Type for <script> tags */\n ElementType[\"Script\"] = \"script\";\n /** Type for <style> tags */\n ElementType[\"Style\"] = \"style\";\n /** Type for Any tag */\n ElementType[\"Tag\"] = \"tag\";\n /** Type for <![CDATA[ ... ]]> */\n ElementType[\"CDATA\"] = \"cdata\";\n /** Type for <!doctype ...> */\n ElementType[\"Doctype\"] = \"doctype\";\n})(ElementType || (ElementType = {}));\n/**\n * Tests whether an element is a tag or not.\n *\n * @param elem Element to test\n */\nexport function isTag(elem) {\n return (elem.type === ElementType.Tag ||\n elem.type === ElementType.Script ||\n elem.type === ElementType.Style);\n}\n// Exports for backwards compatibility\n/** Type for the root element of a document */\nexport const Root = ElementType.Root;\n/** Type for Text */\nexport const Text = ElementType.Text;\n/** Type for <? ... ?> */\nexport const Directive = ElementType.Directive;\n/** Type for <!-- ... --> */\nexport const Comment = ElementType.Comment;\n/** Type for <script> tags */\nexport const Script = ElementType.Script;\n/** Type for <style> tags */\nexport const Style = ElementType.Style;\n/** Type for Any tag */\nexport const Tag = ElementType.Tag;\n/** Type for <![CDATA[ ... ]]> */\nexport const CDATA = ElementType.CDATA;\n/** Type for <!doctype ...> */\nexport const Doctype = ElementType.Doctype;\n"],"x_google_ignoreList":[0],"mappings":";;AACA,IAAW;CACV,SAAU,aAAa;;CAEpB,YAAY,UAAU;;CAEtB,YAAY,UAAU;;CAEtB,YAAY,eAAe;;CAE3B,YAAY,aAAa;;CAEzB,YAAY,YAAY;;CAExB,YAAY,WAAW;;CAEvB,YAAY,SAAS;;CAErB,YAAY,WAAW;;CAEvB,YAAY,aAAa;AAC7B,EAAA,CAAG,gBAAgB,cAAc,CAAC,EAAE;;;;;;AAMpC,SAAgB,MAAM,MAAM;CACxB,OAAQ,KAAK,SAAS,YAAY,OAC9B,KAAK,SAAS,YAAY,UAC1B,KAAK,SAAS,YAAY;AAClC;;AAGA,MAAa,OAAO,YAAY;;AAEhC,MAAa,OAAO,YAAY;;AAEhC,MAAa,YAAY,YAAY;;AAErC,MAAa,UAAU,YAAY;;AAEnC,MAAa,SAAS,YAAY;;AAElC,MAAa,QAAQ,YAAY;;AAEjC,MAAa,MAAM,YAAY;;AAE/B,MAAa,QAAQ,YAAY;;AAEjC,MAAa,UAAU,YAAY"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ElementType } from "../../../domelementtype/lib/esm/index.js";
|
|
2
|
+
import { CDATA, Comment, DataNode, Document, Element, Node, NodeWithChildren, ProcessingInstruction, Text, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText } from "./node.js";
|
|
3
|
+
//#region ../../node_modules/domhandler/lib/esm/index.js
|
|
4
|
+
const defaultOpts = {
|
|
5
|
+
withStartIndices: false,
|
|
6
|
+
withEndIndices: false,
|
|
7
|
+
xmlMode: false
|
|
8
|
+
};
|
|
9
|
+
var DomHandler = class {
|
|
10
|
+
/**
|
|
11
|
+
* @param callback Called once parsing has completed.
|
|
12
|
+
* @param options Settings for the handler.
|
|
13
|
+
* @param elementCB Callback whenever a tag is closed.
|
|
14
|
+
*/
|
|
15
|
+
constructor(callback, options, elementCB) {
|
|
16
|
+
/** The elements of the DOM */
|
|
17
|
+
this.dom = [];
|
|
18
|
+
/** The root element for the DOM */
|
|
19
|
+
this.root = new Document(this.dom);
|
|
20
|
+
/** Indicated whether parsing has been completed. */
|
|
21
|
+
this.done = false;
|
|
22
|
+
/** Stack of open tags. */
|
|
23
|
+
this.tagStack = [this.root];
|
|
24
|
+
/** A data node that is still being written to. */
|
|
25
|
+
this.lastNode = null;
|
|
26
|
+
/** Reference to the parser instance. Used for location information. */
|
|
27
|
+
this.parser = null;
|
|
28
|
+
if (typeof options === "function") {
|
|
29
|
+
elementCB = options;
|
|
30
|
+
options = defaultOpts;
|
|
31
|
+
}
|
|
32
|
+
if (typeof callback === "object") {
|
|
33
|
+
options = callback;
|
|
34
|
+
callback = void 0;
|
|
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
|
+
onparserinit(parser) {
|
|
41
|
+
this.parser = parser;
|
|
42
|
+
}
|
|
43
|
+
onreset() {
|
|
44
|
+
this.dom = [];
|
|
45
|
+
this.root = new Document(this.dom);
|
|
46
|
+
this.done = false;
|
|
47
|
+
this.tagStack = [this.root];
|
|
48
|
+
this.lastNode = null;
|
|
49
|
+
this.parser = null;
|
|
50
|
+
}
|
|
51
|
+
onend() {
|
|
52
|
+
if (this.done) return;
|
|
53
|
+
this.done = true;
|
|
54
|
+
this.parser = null;
|
|
55
|
+
this.handleCallback(null);
|
|
56
|
+
}
|
|
57
|
+
onerror(error) {
|
|
58
|
+
this.handleCallback(error);
|
|
59
|
+
}
|
|
60
|
+
onclosetag() {
|
|
61
|
+
this.lastNode = null;
|
|
62
|
+
const elem = this.tagStack.pop();
|
|
63
|
+
if (this.options.withEndIndices) elem.endIndex = this.parser.endIndex;
|
|
64
|
+
if (this.elementCB) this.elementCB(elem);
|
|
65
|
+
}
|
|
66
|
+
onopentag(name, attribs) {
|
|
67
|
+
const type = this.options.xmlMode ? ElementType.Tag : void 0;
|
|
68
|
+
const element = new Element(name, attribs, void 0, type);
|
|
69
|
+
this.addNode(element);
|
|
70
|
+
this.tagStack.push(element);
|
|
71
|
+
}
|
|
72
|
+
ontext(data) {
|
|
73
|
+
const { lastNode } = this;
|
|
74
|
+
if (lastNode && lastNode.type === ElementType.Text) {
|
|
75
|
+
lastNode.data += data;
|
|
76
|
+
if (this.options.withEndIndices) lastNode.endIndex = this.parser.endIndex;
|
|
77
|
+
} else {
|
|
78
|
+
const node = new Text(data);
|
|
79
|
+
this.addNode(node);
|
|
80
|
+
this.lastNode = node;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
oncomment(data) {
|
|
84
|
+
if (this.lastNode && this.lastNode.type === ElementType.Comment) {
|
|
85
|
+
this.lastNode.data += data;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const node = new Comment(data);
|
|
89
|
+
this.addNode(node);
|
|
90
|
+
this.lastNode = node;
|
|
91
|
+
}
|
|
92
|
+
oncommentend() {
|
|
93
|
+
this.lastNode = null;
|
|
94
|
+
}
|
|
95
|
+
oncdatastart() {
|
|
96
|
+
const text = new Text("");
|
|
97
|
+
const node = new CDATA([text]);
|
|
98
|
+
this.addNode(node);
|
|
99
|
+
text.parent = node;
|
|
100
|
+
this.lastNode = text;
|
|
101
|
+
}
|
|
102
|
+
oncdataend() {
|
|
103
|
+
this.lastNode = null;
|
|
104
|
+
}
|
|
105
|
+
onprocessinginstruction(name, data) {
|
|
106
|
+
const node = new ProcessingInstruction(name, data);
|
|
107
|
+
this.addNode(node);
|
|
108
|
+
}
|
|
109
|
+
handleCallback(error) {
|
|
110
|
+
if (typeof this.callback === "function") this.callback(error, this.dom);
|
|
111
|
+
else if (error) throw error;
|
|
112
|
+
}
|
|
113
|
+
addNode(node) {
|
|
114
|
+
const parent = this.tagStack[this.tagStack.length - 1];
|
|
115
|
+
const previousSibling = parent.children[parent.children.length - 1];
|
|
116
|
+
if (this.options.withStartIndices) node.startIndex = this.parser.startIndex;
|
|
117
|
+
if (this.options.withEndIndices) node.endIndex = this.parser.endIndex;
|
|
118
|
+
parent.children.push(node);
|
|
119
|
+
if (previousSibling) {
|
|
120
|
+
node.prev = previousSibling;
|
|
121
|
+
previousSibling.next = node;
|
|
122
|
+
}
|
|
123
|
+
node.parent = parent;
|
|
124
|
+
this.lastNode = null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
//#endregion
|
|
128
|
+
export { CDATA, Comment, DataNode, Document, DomHandler, DomHandler as default, Element, Node, NodeWithChildren, ProcessingInstruction, Text, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../node_modules/domhandler/lib/esm/index.js"],"sourcesContent":["import { ElementType } from \"domelementtype\";\nimport { Element, Text, Comment, CDATA, Document, ProcessingInstruction, } from \"./node.js\";\nexport * from \"./node.js\";\n// Default options\nconst defaultOpts = {\n withStartIndices: false,\n withEndIndices: false,\n xmlMode: false,\n};\nexport class DomHandler {\n /**\n * @param callback Called once parsing has completed.\n * @param options Settings for the handler.\n * @param elementCB Callback whenever a tag is closed.\n */\n constructor(callback, options, elementCB) {\n /** The elements of the DOM */\n this.dom = [];\n /** The root element for the DOM */\n this.root = new Document(this.dom);\n /** Indicated whether parsing has been completed. */\n this.done = false;\n /** Stack of open tags. */\n this.tagStack = [this.root];\n /** A data node that is still being written to. */\n this.lastNode = null;\n /** Reference to the parser instance. Used for location information. */\n this.parser = null;\n // Make it possible to skip arguments, for backwards-compatibility\n if (typeof options === \"function\") {\n elementCB = options;\n options = defaultOpts;\n }\n if (typeof callback === \"object\") {\n options = callback;\n callback = undefined;\n }\n this.callback = callback !== null && callback !== void 0 ? callback : null;\n this.options = options !== null && options !== void 0 ? options : defaultOpts;\n this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;\n }\n onparserinit(parser) {\n this.parser = parser;\n }\n // Resets the handler back to starting state\n onreset() {\n this.dom = [];\n this.root = new Document(this.dom);\n this.done = false;\n this.tagStack = [this.root];\n this.lastNode = null;\n this.parser = null;\n }\n // Signals the handler that parsing is done\n onend() {\n if (this.done)\n return;\n this.done = true;\n this.parser = null;\n this.handleCallback(null);\n }\n onerror(error) {\n this.handleCallback(error);\n }\n onclosetag() {\n this.lastNode = null;\n const elem = this.tagStack.pop();\n if (this.options.withEndIndices) {\n elem.endIndex = this.parser.endIndex;\n }\n if (this.elementCB)\n this.elementCB(elem);\n }\n onopentag(name, attribs) {\n const type = this.options.xmlMode ? ElementType.Tag : undefined;\n const element = new Element(name, attribs, undefined, type);\n this.addNode(element);\n this.tagStack.push(element);\n }\n ontext(data) {\n const { lastNode } = this;\n if (lastNode && lastNode.type === ElementType.Text) {\n lastNode.data += data;\n if (this.options.withEndIndices) {\n lastNode.endIndex = this.parser.endIndex;\n }\n }\n else {\n const node = new Text(data);\n this.addNode(node);\n this.lastNode = node;\n }\n }\n oncomment(data) {\n if (this.lastNode && this.lastNode.type === ElementType.Comment) {\n this.lastNode.data += data;\n return;\n }\n const node = new Comment(data);\n this.addNode(node);\n this.lastNode = node;\n }\n oncommentend() {\n this.lastNode = null;\n }\n oncdatastart() {\n const text = new Text(\"\");\n const node = new CDATA([text]);\n this.addNode(node);\n text.parent = node;\n this.lastNode = text;\n }\n oncdataend() {\n this.lastNode = null;\n }\n onprocessinginstruction(name, data) {\n const node = new ProcessingInstruction(name, data);\n this.addNode(node);\n }\n handleCallback(error) {\n if (typeof this.callback === \"function\") {\n this.callback(error, this.dom);\n }\n else if (error) {\n throw error;\n }\n }\n addNode(node) {\n const parent = this.tagStack[this.tagStack.length - 1];\n const previousSibling = parent.children[parent.children.length - 1];\n if (this.options.withStartIndices) {\n node.startIndex = this.parser.startIndex;\n }\n if (this.options.withEndIndices) {\n node.endIndex = this.parser.endIndex;\n }\n parent.children.push(node);\n if (previousSibling) {\n node.prev = previousSibling;\n previousSibling.next = node;\n }\n node.parent = parent;\n this.lastNode = null;\n }\n}\nexport default DomHandler;\n"],"x_google_ignoreList":[0],"mappings":"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"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { ElementType, isTag as isTag$1 } from "../../../domelementtype/lib/esm/index.js";
|
|
2
|
+
//#region ../../node_modules/domhandler/lib/esm/node.js
|
|
3
|
+
/**
|
|
4
|
+
* This object will be used as the prototype for Nodes when creating a
|
|
5
|
+
* DOM-Level-1-compliant structure.
|
|
6
|
+
*/
|
|
7
|
+
var Node = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
/** Parent of the node */
|
|
10
|
+
this.parent = null;
|
|
11
|
+
/** Previous sibling */
|
|
12
|
+
this.prev = null;
|
|
13
|
+
/** Next sibling */
|
|
14
|
+
this.next = null;
|
|
15
|
+
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
|
|
16
|
+
this.startIndex = null;
|
|
17
|
+
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
|
|
18
|
+
this.endIndex = null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Same as {@link parent}.
|
|
22
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
23
|
+
*/
|
|
24
|
+
get parentNode() {
|
|
25
|
+
return this.parent;
|
|
26
|
+
}
|
|
27
|
+
set parentNode(parent) {
|
|
28
|
+
this.parent = parent;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link prev}.
|
|
32
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
33
|
+
*/
|
|
34
|
+
get previousSibling() {
|
|
35
|
+
return this.prev;
|
|
36
|
+
}
|
|
37
|
+
set previousSibling(prev) {
|
|
38
|
+
this.prev = prev;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Same as {@link next}.
|
|
42
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
43
|
+
*/
|
|
44
|
+
get nextSibling() {
|
|
45
|
+
return this.next;
|
|
46
|
+
}
|
|
47
|
+
set nextSibling(next) {
|
|
48
|
+
this.next = next;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Clone this node, and optionally its children.
|
|
52
|
+
*
|
|
53
|
+
* @param recursive Clone child nodes as well.
|
|
54
|
+
* @returns A clone of the node.
|
|
55
|
+
*/
|
|
56
|
+
cloneNode(recursive = false) {
|
|
57
|
+
return cloneNode(this, recursive);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A node that contains some data.
|
|
62
|
+
*/
|
|
63
|
+
var DataNode = class extends Node {
|
|
64
|
+
/**
|
|
65
|
+
* @param data The content of the data node
|
|
66
|
+
*/
|
|
67
|
+
constructor(data) {
|
|
68
|
+
super();
|
|
69
|
+
this.data = data;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Same as {@link data}.
|
|
73
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
74
|
+
*/
|
|
75
|
+
get nodeValue() {
|
|
76
|
+
return this.data;
|
|
77
|
+
}
|
|
78
|
+
set nodeValue(data) {
|
|
79
|
+
this.data = data;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Text within the document.
|
|
84
|
+
*/
|
|
85
|
+
var Text = class extends DataNode {
|
|
86
|
+
constructor() {
|
|
87
|
+
super(...arguments);
|
|
88
|
+
this.type = ElementType.Text;
|
|
89
|
+
}
|
|
90
|
+
get nodeType() {
|
|
91
|
+
return 3;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Comments within the document.
|
|
96
|
+
*/
|
|
97
|
+
var Comment = class extends DataNode {
|
|
98
|
+
constructor() {
|
|
99
|
+
super(...arguments);
|
|
100
|
+
this.type = ElementType.Comment;
|
|
101
|
+
}
|
|
102
|
+
get nodeType() {
|
|
103
|
+
return 8;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Processing instructions, including doc types.
|
|
108
|
+
*/
|
|
109
|
+
var ProcessingInstruction = class extends DataNode {
|
|
110
|
+
constructor(name, data) {
|
|
111
|
+
super(data);
|
|
112
|
+
this.name = name;
|
|
113
|
+
this.type = ElementType.Directive;
|
|
114
|
+
}
|
|
115
|
+
get nodeType() {
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* A `Node` that can have children.
|
|
121
|
+
*/
|
|
122
|
+
var NodeWithChildren = class extends Node {
|
|
123
|
+
/**
|
|
124
|
+
* @param children Children of the node. Only certain node types can have children.
|
|
125
|
+
*/
|
|
126
|
+
constructor(children) {
|
|
127
|
+
super();
|
|
128
|
+
this.children = children;
|
|
129
|
+
}
|
|
130
|
+
/** First child of the node. */
|
|
131
|
+
get firstChild() {
|
|
132
|
+
var _a;
|
|
133
|
+
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
|
|
134
|
+
}
|
|
135
|
+
/** Last child of the node. */
|
|
136
|
+
get lastChild() {
|
|
137
|
+
return this.children.length > 0 ? this.children[this.children.length - 1] : null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Same as {@link children}.
|
|
141
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
142
|
+
*/
|
|
143
|
+
get childNodes() {
|
|
144
|
+
return this.children;
|
|
145
|
+
}
|
|
146
|
+
set childNodes(children) {
|
|
147
|
+
this.children = children;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var CDATA = class extends NodeWithChildren {
|
|
151
|
+
constructor() {
|
|
152
|
+
super(...arguments);
|
|
153
|
+
this.type = ElementType.CDATA;
|
|
154
|
+
}
|
|
155
|
+
get nodeType() {
|
|
156
|
+
return 4;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The root node of the document.
|
|
161
|
+
*/
|
|
162
|
+
var Document = class extends NodeWithChildren {
|
|
163
|
+
constructor() {
|
|
164
|
+
super(...arguments);
|
|
165
|
+
this.type = ElementType.Root;
|
|
166
|
+
}
|
|
167
|
+
get nodeType() {
|
|
168
|
+
return 9;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* An element within the DOM.
|
|
173
|
+
*/
|
|
174
|
+
var Element = class extends NodeWithChildren {
|
|
175
|
+
/**
|
|
176
|
+
* @param name Name of the tag, eg. `div`, `span`.
|
|
177
|
+
* @param attribs Object mapping attribute names to attribute values.
|
|
178
|
+
* @param children Children of the node.
|
|
179
|
+
*/
|
|
180
|
+
constructor(name, attribs, children = [], type = name === "script" ? ElementType.Script : name === "style" ? ElementType.Style : ElementType.Tag) {
|
|
181
|
+
super(children);
|
|
182
|
+
this.name = name;
|
|
183
|
+
this.attribs = attribs;
|
|
184
|
+
this.type = type;
|
|
185
|
+
}
|
|
186
|
+
get nodeType() {
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Same as {@link name}.
|
|
191
|
+
* [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
|
192
|
+
*/
|
|
193
|
+
get tagName() {
|
|
194
|
+
return this.name;
|
|
195
|
+
}
|
|
196
|
+
set tagName(name) {
|
|
197
|
+
this.name = name;
|
|
198
|
+
}
|
|
199
|
+
get attributes() {
|
|
200
|
+
return Object.keys(this.attribs).map((name) => {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
return {
|
|
203
|
+
name,
|
|
204
|
+
value: this.attribs[name],
|
|
205
|
+
namespace: (_a = this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
|
|
206
|
+
prefix: (_b = this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name]
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* @param node Node to check.
|
|
213
|
+
* @returns `true` if the node is a `Element`, `false` otherwise.
|
|
214
|
+
*/
|
|
215
|
+
function isTag(node) {
|
|
216
|
+
return isTag$1(node);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @param node Node to check.
|
|
220
|
+
* @returns `true` if the node has the type `CDATA`, `false` otherwise.
|
|
221
|
+
*/
|
|
222
|
+
function isCDATA(node) {
|
|
223
|
+
return node.type === ElementType.CDATA;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* @param node Node to check.
|
|
227
|
+
* @returns `true` if the node has the type `Text`, `false` otherwise.
|
|
228
|
+
*/
|
|
229
|
+
function isText(node) {
|
|
230
|
+
return node.type === ElementType.Text;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @param node Node to check.
|
|
234
|
+
* @returns `true` if the node has the type `Comment`, `false` otherwise.
|
|
235
|
+
*/
|
|
236
|
+
function isComment(node) {
|
|
237
|
+
return node.type === ElementType.Comment;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @param node Node to check.
|
|
241
|
+
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
|
|
242
|
+
*/
|
|
243
|
+
function isDirective(node) {
|
|
244
|
+
return node.type === ElementType.Directive;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @param node Node to check.
|
|
248
|
+
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
|
|
249
|
+
*/
|
|
250
|
+
function isDocument(node) {
|
|
251
|
+
return node.type === ElementType.Root;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Clone a node, and optionally its children.
|
|
255
|
+
*
|
|
256
|
+
* @param recursive Clone child nodes as well.
|
|
257
|
+
* @returns A clone of the node.
|
|
258
|
+
*/
|
|
259
|
+
function cloneNode(node, recursive = false) {
|
|
260
|
+
let result;
|
|
261
|
+
if (isText(node)) result = new Text(node.data);
|
|
262
|
+
else if (isComment(node)) result = new Comment(node.data);
|
|
263
|
+
else if (isTag(node)) {
|
|
264
|
+
const children = recursive ? cloneChildren(node.children) : [];
|
|
265
|
+
const clone = new Element(node.name, { ...node.attribs }, children);
|
|
266
|
+
children.forEach((child) => child.parent = clone);
|
|
267
|
+
if (node.namespace != null) clone.namespace = node.namespace;
|
|
268
|
+
if (node["x-attribsNamespace"]) clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
|
|
269
|
+
if (node["x-attribsPrefix"]) clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
|
|
270
|
+
result = clone;
|
|
271
|
+
} else if (isCDATA(node)) {
|
|
272
|
+
const children = recursive ? cloneChildren(node.children) : [];
|
|
273
|
+
const clone = new CDATA(children);
|
|
274
|
+
children.forEach((child) => child.parent = clone);
|
|
275
|
+
result = clone;
|
|
276
|
+
} else if (isDocument(node)) {
|
|
277
|
+
const children = recursive ? cloneChildren(node.children) : [];
|
|
278
|
+
const clone = new Document(children);
|
|
279
|
+
children.forEach((child) => child.parent = clone);
|
|
280
|
+
if (node["x-mode"]) clone["x-mode"] = node["x-mode"];
|
|
281
|
+
result = clone;
|
|
282
|
+
} else if (isDirective(node)) {
|
|
283
|
+
const instruction = new ProcessingInstruction(node.name, node.data);
|
|
284
|
+
if (node["x-name"] != null) {
|
|
285
|
+
instruction["x-name"] = node["x-name"];
|
|
286
|
+
instruction["x-publicId"] = node["x-publicId"];
|
|
287
|
+
instruction["x-systemId"] = node["x-systemId"];
|
|
288
|
+
}
|
|
289
|
+
result = instruction;
|
|
290
|
+
} else throw new Error(`Not implemented yet: ${node.type}`);
|
|
291
|
+
result.startIndex = node.startIndex;
|
|
292
|
+
result.endIndex = node.endIndex;
|
|
293
|
+
if (node.sourceCodeLocation != null) result.sourceCodeLocation = node.sourceCodeLocation;
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
function cloneChildren(childs) {
|
|
297
|
+
const children = childs.map((child) => cloneNode(child, true));
|
|
298
|
+
for (let i = 1; i < children.length; i++) {
|
|
299
|
+
children[i].prev = children[i - 1];
|
|
300
|
+
children[i - 1].next = children[i];
|
|
301
|
+
}
|
|
302
|
+
return children;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
export { CDATA, Comment, DataNode, Document, Element, Node, NodeWithChildren, ProcessingInstruction, Text, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText };
|
|
306
|
+
|
|
307
|
+
//# sourceMappingURL=node.js.map
|