@ncukondo/search-hub 0.12.0 → 0.12.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/dist/_virtual/_commonjsHelpers.js +30 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/aliases.js +5 -0
- package/dist/_virtual/aliases.js.map +1 -0
- package/dist/_virtual/attributes.js +5 -0
- package/dist/_virtual/attributes.js.map +1 -0
- package/dist/_virtual/back.js +5 -0
- package/dist/_virtual/back.js.map +1 -0
- package/dist/_virtual/comment.js +5 -0
- package/dist/_virtual/comment.js.map +1 -0
- package/dist/_virtual/compile.js +5 -0
- package/dist/_virtual/compile.js.map +1 -0
- package/dist/_virtual/compile2.js +5 -0
- package/dist/_virtual/compile2.js.map +1 -0
- package/dist/_virtual/decode-data-html.js +5 -0
- package/dist/_virtual/decode-data-html.js.map +1 -0
- package/dist/_virtual/decode-data-xml.js +5 -0
- package/dist/_virtual/decode-data-xml.js.map +1 -0
- package/dist/_virtual/decode.js +5 -0
- package/dist/_virtual/decode.js.map +1 -0
- package/dist/_virtual/decode_codepoint.js +5 -0
- package/dist/_virtual/decode_codepoint.js.map +1 -0
- package/dist/_virtual/encode-html.js +5 -0
- package/dist/_virtual/encode-html.js.map +1 -0
- package/dist/_virtual/encode.js +5 -0
- package/dist/_virtual/encode.js.map +1 -0
- package/dist/_virtual/escape.js +5 -0
- package/dist/_virtual/escape.js.map +1 -0
- package/dist/_virtual/feeds.js +5 -0
- package/dist/_virtual/feeds.js.map +1 -0
- package/dist/_virtual/filters.js +5 -0
- package/dist/_virtual/filters.js.map +1 -0
- package/dist/_virtual/foreignNames.js +5 -0
- package/dist/_virtual/foreignNames.js.map +1 -0
- package/dist/_virtual/general.js +5 -0
- package/dist/_virtual/general.js.map +1 -0
- package/dist/_virtual/he.js +5 -0
- package/dist/_virtual/he.js.map +1 -0
- package/dist/_virtual/helpers.js +5 -0
- package/dist/_virtual/helpers.js.map +1 -0
- package/dist/_virtual/html.js +5 -0
- package/dist/_virtual/html.js.map +1 -0
- package/dist/_virtual/index.js +6 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/index10.js +5 -0
- package/dist/_virtual/index10.js.map +1 -0
- package/dist/_virtual/index11.js +5 -0
- package/dist/_virtual/index11.js.map +1 -0
- package/dist/_virtual/index2.js +5 -0
- package/dist/_virtual/index2.js.map +1 -0
- package/dist/_virtual/index3.js +5 -0
- package/dist/_virtual/index3.js.map +1 -0
- package/dist/_virtual/index4.js +5 -0
- package/dist/_virtual/index4.js.map +1 -0
- package/dist/_virtual/index5.js +7 -0
- package/dist/_virtual/index5.js.map +1 -0
- package/dist/_virtual/index6.js +5 -0
- package/dist/_virtual/index6.js.map +1 -0
- package/dist/_virtual/index7.js +5 -0
- package/dist/_virtual/index7.js.map +1 -0
- package/dist/_virtual/index8.js +5 -0
- package/dist/_virtual/index8.js.map +1 -0
- package/dist/_virtual/index9.js +5 -0
- package/dist/_virtual/index9.js.map +1 -0
- package/dist/_virtual/legacy.js +5 -0
- package/dist/_virtual/legacy.js.map +1 -0
- package/dist/_virtual/manipulation.js +5 -0
- package/dist/_virtual/manipulation.js.map +1 -0
- package/dist/_virtual/matcher.js +5 -0
- package/dist/_virtual/matcher.js.map +1 -0
- package/dist/_virtual/node.js +5 -0
- package/dist/_virtual/node.js.map +1 -0
- package/dist/_virtual/node2.js +5 -0
- package/dist/_virtual/node2.js.map +1 -0
- package/dist/_virtual/parse.js +5 -0
- package/dist/_virtual/parse.js.map +1 -0
- package/dist/_virtual/parse2.js +5 -0
- package/dist/_virtual/parse2.js.map +1 -0
- package/dist/_virtual/pseudos.js +5 -0
- package/dist/_virtual/pseudos.js.map +1 -0
- package/dist/_virtual/querying.js +5 -0
- package/dist/_virtual/querying.js.map +1 -0
- package/dist/_virtual/sort.js +5 -0
- package/dist/_virtual/sort.js.map +1 -0
- package/dist/_virtual/stringify.js +5 -0
- package/dist/_virtual/stringify.js.map +1 -0
- package/dist/_virtual/subselects.js +5 -0
- package/dist/_virtual/subselects.js.map +1 -0
- package/dist/_virtual/text.js +5 -0
- package/dist/_virtual/text.js.map +1 -0
- package/dist/_virtual/traversal.js +5 -0
- package/dist/_virtual/traversal.js.map +1 -0
- package/dist/_virtual/type.js +5 -0
- package/dist/_virtual/type.js.map +1 -0
- package/dist/_virtual/valid.js +5 -0
- package/dist/_virtual/valid.js.map +1 -0
- package/dist/_virtual/void-tag.js +5 -0
- package/dist/_virtual/void-tag.js.map +1 -0
- package/dist/cli/commands/fulltext/attach.js +1 -1
- package/dist/cli/commands/fulltext/attach.js.map +1 -1
- package/dist/cli/commands/fulltext/check.d.ts +1 -2
- package/dist/cli/commands/fulltext/check.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/check.js +4 -2
- package/dist/cli/commands/fulltext/check.js.map +1 -1
- package/dist/cli/commands/fulltext/convert.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/convert.js +8 -8
- package/dist/cli/commands/fulltext/convert.js.map +1 -1
- package/dist/cli/commands/fulltext/fetch.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/fetch.js +10 -6
- package/dist/cli/commands/fulltext/fetch.js.map +1 -1
- package/dist/cli/commands/fulltext/index.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/index.js +2 -0
- package/dist/cli/commands/fulltext/index.js.map +1 -1
- package/dist/cli/commands/fulltext/init.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/init.js +6 -5
- package/dist/cli/commands/fulltext/init.js.map +1 -1
- package/dist/cli/commands/fulltext/pending.d.ts +1 -1
- package/dist/cli/commands/fulltext/pending.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/pending.js +4 -2
- package/dist/cli/commands/fulltext/pending.js.map +1 -1
- package/dist/cli/commands/fulltext/status.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/status.js +4 -2
- package/dist/cli/commands/fulltext/status.js.map +1 -1
- package/dist/cli/commands/fulltext/sync.d.ts.map +1 -1
- package/dist/cli/commands/fulltext/sync.js +6 -2
- package/dist/cli/commands/fulltext/sync.js.map +1 -1
- package/dist/cli/commands/review/types.d.ts +1 -1
- package/dist/cli/commands/review/types.d.ts.map +1 -1
- package/dist/cli/commands/review/types.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +7 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/config/schema.d.ts +2 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +6 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/{fulltext → integration}/attach-shared.d.ts +2 -2
- package/dist/integration/attach-shared.d.ts.map +1 -0
- package/dist/integration/attach-shared.js.map +1 -0
- package/dist/integration/fulltext-attach.js +1 -1
- package/dist/integration/fulltext-attach.js.map +1 -1
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/citation-key.js +1 -1
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/citation-key.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/arxiv-html-parser.js +434 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/arxiv-html-parser.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/index.js +93 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/index.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/jats-parser.js +1060 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/jats-parser.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/convert/markdown-writer.js +146 -117
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/convert/markdown-writer.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/discovery/arxiv.js +8 -1
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/arxiv.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/discovery/core.js +6 -3
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/core.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/index.js +139 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/index.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/ncbi-id-converter.js +46 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/ncbi-id-converter.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/discovery/pmc.js +8 -4
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/pmc.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/discovery/unpaywall.js +43 -9
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/discovery/unpaywall.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/arxiv-html.js +48 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/arxiv-html.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/downloader.js +64 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/downloader.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/orchestrator.js +236 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/orchestrator.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/download/pmc-xml.js +2 -1
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/download/pmc-xml.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/meta.js +15 -10
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/meta.js.map +1 -0
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/paths.js.map +1 -0
- package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/readme.js +8 -4
- package/dist/node_modules/@ncukondo/academic-fulltext/dist/readme.js.map +1 -0
- package/dist/node_modules/boolbase/index.js +19 -0
- package/dist/node_modules/boolbase/index.js.map +1 -0
- package/dist/node_modules/css-select/lib/attributes.js +203 -0
- package/dist/node_modules/css-select/lib/attributes.js.map +1 -0
- package/dist/node_modules/css-select/lib/compile.js +141 -0
- package/dist/node_modules/css-select/lib/compile.js.map +1 -0
- package/dist/node_modules/css-select/lib/general.js +154 -0
- package/dist/node_modules/css-select/lib/general.js.map +1 -0
- package/dist/node_modules/css-select/lib/index.js +128 -0
- package/dist/node_modules/css-select/lib/index.js.map +1 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/aliases.js +40 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/aliases.js.map +1 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/filters.js +163 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/filters.js.map +1 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/index.js +71 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/index.js.map +1 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/pseudos.js +93 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/pseudos.js.map +1 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/subselects.js +111 -0
- package/dist/node_modules/css-select/lib/pseudo-selectors/subselects.js.map +1 -0
- package/dist/node_modules/css-select/lib/sort.js +78 -0
- package/dist/node_modules/css-select/lib/sort.js.map +1 -0
- package/dist/node_modules/css-what/lib/es/index.js +12 -0
- package/dist/node_modules/css-what/lib/es/index.js.map +1 -0
- package/dist/node_modules/css-what/lib/es/parse.js +349 -0
- package/dist/node_modules/css-what/lib/es/parse.js.map +1 -0
- package/dist/node_modules/css-what/lib/es/stringify.js +102 -0
- package/dist/node_modules/css-what/lib/es/stringify.js.map +1 -0
- package/dist/node_modules/css-what/lib/es/types.js +37 -0
- package/dist/node_modules/css-what/lib/es/types.js.map +1 -0
- package/dist/node_modules/dom-serializer/lib/foreignNames.js +117 -0
- package/dist/node_modules/dom-serializer/lib/foreignNames.js.map +1 -0
- package/dist/node_modules/dom-serializer/lib/index.js +207 -0
- package/dist/node_modules/dom-serializer/lib/index.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/decode.js +368 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/decode.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/decode_codepoint.js +70 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/decode_codepoint.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/encode.js +61 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/encode.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/escape.js +79 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/escape.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/decode-data-html.js +18 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/decode-data-html.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/decode-data-xml.js +18 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/decode-data-xml.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/encode-html.js +19 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/generated/encode-html.js.map +1 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/index.js +139 -0
- package/dist/node_modules/dom-serializer/node_modules/entities/lib/index.js.map +1 -0
- package/dist/node_modules/domelementtype/lib/index.js +40 -0
- package/dist/node_modules/domelementtype/lib/index.js.map +1 -0
- package/dist/node_modules/domhandler/lib/index.js +167 -0
- package/dist/node_modules/domhandler/lib/index.js.map +1 -0
- package/dist/node_modules/domhandler/lib/node.js +439 -0
- package/dist/node_modules/domhandler/lib/node.js.map +1 -0
- package/dist/node_modules/domutils/lib/feeds.js +146 -0
- package/dist/node_modules/domutils/lib/feeds.js.map +1 -0
- package/dist/node_modules/domutils/lib/helpers.js +97 -0
- package/dist/node_modules/domutils/lib/helpers.js.map +1 -0
- package/dist/node_modules/domutils/lib/index.js +65 -0
- package/dist/node_modules/domutils/lib/index.js.map +1 -0
- package/dist/node_modules/domutils/lib/legacy.js +124 -0
- package/dist/node_modules/domutils/lib/legacy.js.map +1 -0
- package/dist/node_modules/domutils/lib/manipulation.js +107 -0
- package/dist/node_modules/domutils/lib/manipulation.js.map +1 -0
- package/dist/node_modules/domutils/lib/querying.js +102 -0
- package/dist/node_modules/domutils/lib/querying.js.map +1 -0
- package/dist/node_modules/domutils/lib/stringify.js +65 -0
- package/dist/node_modules/domutils/lib/stringify.js.map +1 -0
- package/dist/node_modules/domutils/lib/traversal.js +69 -0
- package/dist/node_modules/domutils/lib/traversal.js.map +1 -0
- package/dist/node_modules/he/he.js +256 -0
- package/dist/node_modules/he/he.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/back.js +16 -0
- package/dist/node_modules/node-html-parser/dist/back.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/index.js +48 -0
- package/dist/node_modules/node-html-parser/dist/index.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/matcher.js +112 -0
- package/dist/node_modules/node-html-parser/dist/matcher.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/nodes/comment.js +41 -0
- package/dist/node_modules/node-html-parser/dist/nodes/comment.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/nodes/html.js +1048 -0
- package/dist/node_modules/node-html-parser/dist/nodes/html.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/nodes/node.js +49 -0
- package/dist/node_modules/node-html-parser/dist/nodes/node.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/nodes/text.js +106 -0
- package/dist/node_modules/node-html-parser/dist/nodes/text.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/nodes/type.js +19 -0
- package/dist/node_modules/node-html-parser/dist/nodes/type.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/parse.js +20 -0
- package/dist/node_modules/node-html-parser/dist/parse.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/valid.js +19 -0
- package/dist/node_modules/node-html-parser/dist/valid.js.map +1 -0
- package/dist/node_modules/node-html-parser/dist/void-tag.js +36 -0
- package/dist/node_modules/node-html-parser/dist/void-tag.js.map +1 -0
- package/dist/node_modules/nth-check/lib/compile.js +76 -0
- package/dist/node_modules/nth-check/lib/compile.js.map +1 -0
- package/dist/node_modules/nth-check/lib/index.js +36 -0
- package/dist/node_modules/nth-check/lib/index.js.map +1 -0
- package/dist/node_modules/nth-check/lib/parse.js +69 -0
- package/dist/node_modules/nth-check/lib/parse.js.map +1 -0
- package/package.json +2 -2
- package/dist/fulltext/attach-shared.d.ts.map +0 -1
- package/dist/fulltext/attach-shared.js.map +0 -1
- package/dist/fulltext/citation-key.d.ts +0 -15
- package/dist/fulltext/citation-key.d.ts.map +0 -1
- package/dist/fulltext/citation-key.js.map +0 -1
- package/dist/fulltext/convert/index.d.ts +0 -20
- package/dist/fulltext/convert/index.d.ts.map +0 -1
- package/dist/fulltext/convert/index.js +0 -50
- package/dist/fulltext/convert/index.js.map +0 -1
- package/dist/fulltext/convert/jats-parser.d.ts +0 -36
- package/dist/fulltext/convert/jats-parser.d.ts.map +0 -1
- package/dist/fulltext/convert/jats-parser.js +0 -887
- package/dist/fulltext/convert/jats-parser.js.map +0 -1
- package/dist/fulltext/convert/markdown-writer.d.ts +0 -6
- package/dist/fulltext/convert/markdown-writer.d.ts.map +0 -1
- package/dist/fulltext/convert/markdown-writer.js.map +0 -1
- package/dist/fulltext/convert/types.d.ts +0 -141
- package/dist/fulltext/convert/types.d.ts.map +0 -1
- package/dist/fulltext/discovery/arxiv.d.ts +0 -11
- package/dist/fulltext/discovery/arxiv.d.ts.map +0 -1
- package/dist/fulltext/discovery/arxiv.js.map +0 -1
- package/dist/fulltext/discovery/core.d.ts +0 -11
- package/dist/fulltext/discovery/core.d.ts.map +0 -1
- package/dist/fulltext/discovery/core.js.map +0 -1
- package/dist/fulltext/discovery/index.d.ts +0 -28
- package/dist/fulltext/discovery/index.d.ts.map +0 -1
- package/dist/fulltext/discovery/index.js +0 -75
- package/dist/fulltext/discovery/index.js.map +0 -1
- package/dist/fulltext/discovery/pmc.d.ts +0 -19
- package/dist/fulltext/discovery/pmc.d.ts.map +0 -1
- package/dist/fulltext/discovery/pmc.js.map +0 -1
- package/dist/fulltext/discovery/unpaywall.d.ts +0 -11
- package/dist/fulltext/discovery/unpaywall.d.ts.map +0 -1
- package/dist/fulltext/discovery/unpaywall.js.map +0 -1
- package/dist/fulltext/download/downloader.d.ts +0 -21
- package/dist/fulltext/download/downloader.d.ts.map +0 -1
- package/dist/fulltext/download/downloader.js +0 -59
- package/dist/fulltext/download/downloader.js.map +0 -1
- package/dist/fulltext/download/orchestrator.d.ts +0 -33
- package/dist/fulltext/download/orchestrator.d.ts.map +0 -1
- package/dist/fulltext/download/orchestrator.js +0 -125
- package/dist/fulltext/download/orchestrator.js.map +0 -1
- package/dist/fulltext/download/pmc-xml.d.ts +0 -13
- package/dist/fulltext/download/pmc-xml.d.ts.map +0 -1
- package/dist/fulltext/download/pmc-xml.js.map +0 -1
- package/dist/fulltext/meta.d.ts +0 -25
- package/dist/fulltext/meta.d.ts.map +0 -1
- package/dist/fulltext/meta.js.map +0 -1
- package/dist/fulltext/paths.d.ts +0 -12
- package/dist/fulltext/paths.d.ts.map +0 -1
- package/dist/fulltext/paths.js.map +0 -1
- package/dist/fulltext/readme.d.ts +0 -4
- package/dist/fulltext/readme.d.ts.map +0 -1
- package/dist/fulltext/readme.js.map +0 -1
- package/dist/fulltext/types.d.ts +0 -90
- package/dist/fulltext/types.d.ts.map +0 -1
- /package/dist/{fulltext → integration}/attach-shared.js +0 -0
- /package/dist/{fulltext → node_modules/@ncukondo/academic-fulltext/dist}/paths.js +0 -0
|
@@ -0,0 +1,1048 @@
|
|
|
1
|
+
import { __exports as html } from "../../../../_virtual/html.js";
|
|
2
|
+
import { __require as requireLib } from "../../../css-select/lib/index.js";
|
|
3
|
+
import { __require as requireHe } from "../../../he/he.js";
|
|
4
|
+
import { __require as requireBack } from "../back.js";
|
|
5
|
+
import { __require as requireMatcher } from "../matcher.js";
|
|
6
|
+
import { __require as requireVoidTag } from "../void-tag.js";
|
|
7
|
+
import { __require as requireComment } from "./comment.js";
|
|
8
|
+
import { __require as requireNode } from "./node.js";
|
|
9
|
+
import { __require as requireText } from "./text.js";
|
|
10
|
+
import { __require as requireType } from "./type.js";
|
|
11
|
+
var hasRequiredHtml;
|
|
12
|
+
function requireHtml() {
|
|
13
|
+
if (hasRequiredHtml) return html;
|
|
14
|
+
hasRequiredHtml = 1;
|
|
15
|
+
var __importDefault = html && html.__importDefault || function(mod) {
|
|
16
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(html, "__esModule", { value: true });
|
|
19
|
+
html.parse = html.base_parse = void 0;
|
|
20
|
+
const css_select_1 = requireLib();
|
|
21
|
+
const he_1 = __importDefault(requireHe());
|
|
22
|
+
const back_1 = __importDefault(/* @__PURE__ */ requireBack());
|
|
23
|
+
const matcher_1 = __importDefault(/* @__PURE__ */ requireMatcher());
|
|
24
|
+
const void_tag_1 = __importDefault(/* @__PURE__ */ requireVoidTag());
|
|
25
|
+
const comment_1 = __importDefault(/* @__PURE__ */ requireComment());
|
|
26
|
+
const node_1 = __importDefault(/* @__PURE__ */ requireNode());
|
|
27
|
+
const text_1 = __importDefault(/* @__PURE__ */ requireText());
|
|
28
|
+
const type_1 = __importDefault(/* @__PURE__ */ requireType());
|
|
29
|
+
function decode(val) {
|
|
30
|
+
return JSON.parse(JSON.stringify(he_1.default.decode(val)));
|
|
31
|
+
}
|
|
32
|
+
const Htags = ["h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup"];
|
|
33
|
+
const Dtags = ["details", "dialog", "dd", "div", "dt"];
|
|
34
|
+
const Ftags = ["fieldset", "figcaption", "figure", "footer", "form"];
|
|
35
|
+
const tableTags = ["table", "td", "tr"];
|
|
36
|
+
const htmlTags = ["address", "article", "aside", "blockquote", "br", "hr", "li", "main", "nav", "ol", "p", "pre", "section", "ul"];
|
|
37
|
+
const kBlockElements = /* @__PURE__ */ new Set();
|
|
38
|
+
function addToKBlockElement(...args) {
|
|
39
|
+
const addToSet = (array) => {
|
|
40
|
+
for (let index = 0; index < array.length; index++) {
|
|
41
|
+
const element = array[index];
|
|
42
|
+
kBlockElements.add(element);
|
|
43
|
+
kBlockElements.add(element.toUpperCase());
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
for (const arg of args)
|
|
47
|
+
addToSet(arg);
|
|
48
|
+
}
|
|
49
|
+
addToKBlockElement(Htags, Dtags, Ftags, tableTags, htmlTags);
|
|
50
|
+
class DOMTokenList {
|
|
51
|
+
_validate(c) {
|
|
52
|
+
if (/\s/.test(c)) {
|
|
53
|
+
throw new Error(`DOMException in DOMTokenList.add: The token '${c}' contains HTML space characters, which are not valid in tokens.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
constructor(valuesInit = [], afterUpdate = () => null) {
|
|
57
|
+
this._set = new Set(valuesInit);
|
|
58
|
+
this._afterUpdate = afterUpdate;
|
|
59
|
+
}
|
|
60
|
+
add(c) {
|
|
61
|
+
this._validate(c);
|
|
62
|
+
this._set.add(c);
|
|
63
|
+
this._afterUpdate(this);
|
|
64
|
+
}
|
|
65
|
+
replace(c1, c2) {
|
|
66
|
+
this._validate(c2);
|
|
67
|
+
this._set.delete(c1);
|
|
68
|
+
this._set.add(c2);
|
|
69
|
+
this._afterUpdate(this);
|
|
70
|
+
}
|
|
71
|
+
remove(c) {
|
|
72
|
+
this._set.delete(c) && this._afterUpdate(this);
|
|
73
|
+
}
|
|
74
|
+
toggle(c) {
|
|
75
|
+
this._validate(c);
|
|
76
|
+
if (this._set.has(c))
|
|
77
|
+
this._set.delete(c);
|
|
78
|
+
else
|
|
79
|
+
this._set.add(c);
|
|
80
|
+
this._afterUpdate(this);
|
|
81
|
+
}
|
|
82
|
+
contains(c) {
|
|
83
|
+
return this._set.has(c);
|
|
84
|
+
}
|
|
85
|
+
get length() {
|
|
86
|
+
return this._set.size;
|
|
87
|
+
}
|
|
88
|
+
values() {
|
|
89
|
+
return this._set.values();
|
|
90
|
+
}
|
|
91
|
+
get value() {
|
|
92
|
+
return Array.from(this._set.values());
|
|
93
|
+
}
|
|
94
|
+
toString() {
|
|
95
|
+
return Array.from(this._set.values()).join(" ");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class HTMLElement extends node_1.default {
|
|
99
|
+
/**
|
|
100
|
+
* Quote attribute values
|
|
101
|
+
* @param attr attribute value
|
|
102
|
+
* @returns {string} quoted value
|
|
103
|
+
*/
|
|
104
|
+
quoteAttribute(attr) {
|
|
105
|
+
if (attr == null) {
|
|
106
|
+
return "null";
|
|
107
|
+
}
|
|
108
|
+
return JSON.stringify(attr.replace(/"/g, """)).replace(/\\t/g, " ").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\/g, "");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates an instance of HTMLElement.
|
|
112
|
+
* @param keyAttrs id and class attribute
|
|
113
|
+
* @param [rawAttrs] attributes in string
|
|
114
|
+
*
|
|
115
|
+
* @memberof HTMLElement
|
|
116
|
+
*/
|
|
117
|
+
constructor(tagName, keyAttrs, rawAttrs = "", parentNode = null, range, voidTag = new void_tag_1.default(), _parseOptions = {}) {
|
|
118
|
+
super(parentNode, range);
|
|
119
|
+
this.rawAttrs = rawAttrs;
|
|
120
|
+
this.voidTag = voidTag;
|
|
121
|
+
this.nodeType = type_1.default.ELEMENT_NODE;
|
|
122
|
+
this.rawTagName = tagName;
|
|
123
|
+
this.rawAttrs = rawAttrs || "";
|
|
124
|
+
this._id = keyAttrs.id || "";
|
|
125
|
+
this.childNodes = [];
|
|
126
|
+
this._parseOptions = _parseOptions;
|
|
127
|
+
this.classList = new DOMTokenList(
|
|
128
|
+
keyAttrs.class ? keyAttrs.class.split(/\s+/) : [],
|
|
129
|
+
(classList) => this.setAttribute("class", classList.toString())
|
|
130
|
+
// eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
131
|
+
);
|
|
132
|
+
if (keyAttrs.id) {
|
|
133
|
+
if (!rawAttrs) {
|
|
134
|
+
this.rawAttrs = `id="${keyAttrs.id}"`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (keyAttrs.class) {
|
|
138
|
+
if (!rawAttrs) {
|
|
139
|
+
const cls = `class="${this.classList.toString()}"`;
|
|
140
|
+
if (this.rawAttrs) {
|
|
141
|
+
this.rawAttrs += ` ${cls}`;
|
|
142
|
+
} else {
|
|
143
|
+
this.rawAttrs = cls;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Remove Child element from childNodes array
|
|
150
|
+
* @param {HTMLElement} node node to remove
|
|
151
|
+
*/
|
|
152
|
+
removeChild(node) {
|
|
153
|
+
this.childNodes = this.childNodes.filter((child) => {
|
|
154
|
+
return child !== node;
|
|
155
|
+
});
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Exchanges given child with new child
|
|
160
|
+
* @param {HTMLElement} oldNode node to exchange
|
|
161
|
+
* @param {HTMLElement} newNode new node
|
|
162
|
+
*/
|
|
163
|
+
exchangeChild(oldNode, newNode) {
|
|
164
|
+
const children = this.childNodes;
|
|
165
|
+
this.childNodes = children.map((child) => {
|
|
166
|
+
if (child === oldNode) {
|
|
167
|
+
return newNode;
|
|
168
|
+
}
|
|
169
|
+
return child;
|
|
170
|
+
});
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
get tagName() {
|
|
174
|
+
return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
|
|
175
|
+
}
|
|
176
|
+
set tagName(newname) {
|
|
177
|
+
this.rawTagName = newname.toLowerCase();
|
|
178
|
+
}
|
|
179
|
+
get localName() {
|
|
180
|
+
return this.rawTagName.toLowerCase();
|
|
181
|
+
}
|
|
182
|
+
get isVoidElement() {
|
|
183
|
+
return this.voidTag.isVoidElement(this.localName);
|
|
184
|
+
}
|
|
185
|
+
get id() {
|
|
186
|
+
return this._id;
|
|
187
|
+
}
|
|
188
|
+
set id(newid) {
|
|
189
|
+
this.setAttribute("id", newid);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get escpaed (as-it) text value of current node and its children.
|
|
193
|
+
* @return {string} text content
|
|
194
|
+
*/
|
|
195
|
+
get rawText() {
|
|
196
|
+
if (/^br$/i.test(this.rawTagName)) {
|
|
197
|
+
return "\n";
|
|
198
|
+
}
|
|
199
|
+
return this.childNodes.reduce((pre, cur) => {
|
|
200
|
+
return pre += cur.rawText;
|
|
201
|
+
}, "");
|
|
202
|
+
}
|
|
203
|
+
get textContent() {
|
|
204
|
+
return decode(this.rawText);
|
|
205
|
+
}
|
|
206
|
+
set textContent(val) {
|
|
207
|
+
const content = [new text_1.default(val, this)];
|
|
208
|
+
this.childNodes = content;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get unescaped text value of current node and its children.
|
|
212
|
+
* @return {string} text content
|
|
213
|
+
*/
|
|
214
|
+
get text() {
|
|
215
|
+
return decode(this.rawText);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get structured Text (with '\n' etc.)
|
|
219
|
+
* @return {string} structured text
|
|
220
|
+
*/
|
|
221
|
+
get structuredText() {
|
|
222
|
+
let currentBlock = [];
|
|
223
|
+
const blocks = [currentBlock];
|
|
224
|
+
function dfs(node) {
|
|
225
|
+
if (node.nodeType === type_1.default.ELEMENT_NODE) {
|
|
226
|
+
if (kBlockElements.has(node.rawTagName)) {
|
|
227
|
+
if (currentBlock.length > 0) {
|
|
228
|
+
blocks.push(currentBlock = []);
|
|
229
|
+
}
|
|
230
|
+
node.childNodes.forEach(dfs);
|
|
231
|
+
if (currentBlock.length > 0) {
|
|
232
|
+
blocks.push(currentBlock = []);
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
node.childNodes.forEach(dfs);
|
|
236
|
+
}
|
|
237
|
+
} else if (node.nodeType === type_1.default.TEXT_NODE) {
|
|
238
|
+
if (node.isWhitespace) {
|
|
239
|
+
currentBlock.prependWhitespace = true;
|
|
240
|
+
} else {
|
|
241
|
+
let text = node.trimmedText;
|
|
242
|
+
if (currentBlock.prependWhitespace) {
|
|
243
|
+
text = ` ${text}`;
|
|
244
|
+
currentBlock.prependWhitespace = false;
|
|
245
|
+
}
|
|
246
|
+
currentBlock.push(text);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
dfs(this);
|
|
251
|
+
return blocks.map((block) => {
|
|
252
|
+
return block.join("").replace(/\s{2,}/g, " ");
|
|
253
|
+
}).join("\n").replace(/\s+$/, "");
|
|
254
|
+
}
|
|
255
|
+
toString() {
|
|
256
|
+
const tag = this.rawTagName;
|
|
257
|
+
if (tag) {
|
|
258
|
+
const attrs = this.rawAttrs ? ` ${this.rawAttrs}` : "";
|
|
259
|
+
return this.voidTag.formatNode(tag, attrs, this.innerHTML);
|
|
260
|
+
}
|
|
261
|
+
return this.innerHTML;
|
|
262
|
+
}
|
|
263
|
+
get innerHTML() {
|
|
264
|
+
return this.childNodes.map((child) => {
|
|
265
|
+
return child.toString();
|
|
266
|
+
}).join("");
|
|
267
|
+
}
|
|
268
|
+
set innerHTML(content) {
|
|
269
|
+
const r = parse(content, this._parseOptions);
|
|
270
|
+
const nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
|
|
271
|
+
resetParent(nodes, this);
|
|
272
|
+
resetParent(this.childNodes, null);
|
|
273
|
+
this.childNodes = nodes;
|
|
274
|
+
}
|
|
275
|
+
set_content(content, options = {}) {
|
|
276
|
+
if (content instanceof node_1.default) {
|
|
277
|
+
content = [content];
|
|
278
|
+
} else if (typeof content == "string") {
|
|
279
|
+
options = Object.assign(Object.assign({}, this._parseOptions), options);
|
|
280
|
+
const r = parse(content, options);
|
|
281
|
+
content = r.childNodes.length ? r.childNodes : [new text_1.default(r.innerHTML, this)];
|
|
282
|
+
}
|
|
283
|
+
resetParent(this.childNodes, null);
|
|
284
|
+
resetParent(content, this);
|
|
285
|
+
this.childNodes = content;
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
replaceWith(...nodes) {
|
|
289
|
+
const parent = this.parentNode;
|
|
290
|
+
const content = nodes.map((node) => {
|
|
291
|
+
if (node instanceof node_1.default) {
|
|
292
|
+
return [node];
|
|
293
|
+
} else if (typeof node == "string") {
|
|
294
|
+
const r = parse(node, this._parseOptions);
|
|
295
|
+
return r.childNodes.length ? r.childNodes : [new text_1.default(node, this)];
|
|
296
|
+
}
|
|
297
|
+
return [];
|
|
298
|
+
}).flat();
|
|
299
|
+
const idx = parent.childNodes.findIndex((child) => {
|
|
300
|
+
return child === this;
|
|
301
|
+
});
|
|
302
|
+
resetParent([this], null);
|
|
303
|
+
parent.childNodes = [...parent.childNodes.slice(0, idx), ...resetParent(content, parent), ...parent.childNodes.slice(idx + 1)];
|
|
304
|
+
return this;
|
|
305
|
+
}
|
|
306
|
+
get outerHTML() {
|
|
307
|
+
return this.toString();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Trim element from right (in block) after seeing pattern in a TextNode.
|
|
311
|
+
* @param {RegExp} pattern pattern to find
|
|
312
|
+
* @return {HTMLElement} reference to current node
|
|
313
|
+
*/
|
|
314
|
+
trimRight(pattern) {
|
|
315
|
+
for (let i = 0; i < this.childNodes.length; i++) {
|
|
316
|
+
const childNode = this.childNodes[i];
|
|
317
|
+
if (childNode.nodeType === type_1.default.ELEMENT_NODE) {
|
|
318
|
+
childNode.trimRight(pattern);
|
|
319
|
+
} else {
|
|
320
|
+
const index = childNode.rawText.search(pattern);
|
|
321
|
+
if (index > -1) {
|
|
322
|
+
childNode.rawText = childNode.rawText.substr(0, index);
|
|
323
|
+
this.childNodes.length = i + 1;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Get DOM structure
|
|
331
|
+
* @return {string} structure
|
|
332
|
+
*/
|
|
333
|
+
get structure() {
|
|
334
|
+
const res = [];
|
|
335
|
+
let indention = 0;
|
|
336
|
+
function write(str) {
|
|
337
|
+
res.push(" ".repeat(indention) + str);
|
|
338
|
+
}
|
|
339
|
+
function dfs(node) {
|
|
340
|
+
const idStr = node._id ? `#${node._id}` : "";
|
|
341
|
+
const classStr = node.classList.length ? `.${node.classList.value.join(".")}` : "";
|
|
342
|
+
write(`${node.rawTagName}${idStr}${classStr}`);
|
|
343
|
+
indention++;
|
|
344
|
+
node.childNodes.forEach((childNode) => {
|
|
345
|
+
if (childNode.nodeType === type_1.default.ELEMENT_NODE) {
|
|
346
|
+
dfs(childNode);
|
|
347
|
+
} else if (childNode.nodeType === type_1.default.TEXT_NODE) {
|
|
348
|
+
if (!childNode.isWhitespace) {
|
|
349
|
+
write("#text");
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
indention--;
|
|
354
|
+
}
|
|
355
|
+
dfs(this);
|
|
356
|
+
return res.join("\n");
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Remove whitespaces in this sub tree.
|
|
360
|
+
* @return {HTMLElement} pointer to this
|
|
361
|
+
*/
|
|
362
|
+
removeWhitespace() {
|
|
363
|
+
let o = 0;
|
|
364
|
+
this.childNodes.forEach((node) => {
|
|
365
|
+
if (node.nodeType === type_1.default.TEXT_NODE) {
|
|
366
|
+
if (node.isWhitespace) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
node.rawText = node.trimmedRawText;
|
|
370
|
+
} else if (node.nodeType === type_1.default.ELEMENT_NODE) {
|
|
371
|
+
node.removeWhitespace();
|
|
372
|
+
}
|
|
373
|
+
this.childNodes[o++] = node;
|
|
374
|
+
});
|
|
375
|
+
this.childNodes.length = o;
|
|
376
|
+
const attrs = Object.keys(this.rawAttributes).map((key) => {
|
|
377
|
+
const val = this.rawAttributes[key];
|
|
378
|
+
return `${key}=${JSON.stringify(val)}`;
|
|
379
|
+
}).join(" ");
|
|
380
|
+
this.rawAttrs = attrs;
|
|
381
|
+
delete this._rawAttrs;
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Query CSS selector to find matching nodes.
|
|
386
|
+
* @param {string} selector Simplified CSS selector
|
|
387
|
+
* @return {HTMLElement[]} matching elements
|
|
388
|
+
*/
|
|
389
|
+
querySelectorAll(selector) {
|
|
390
|
+
return (0, css_select_1.selectAll)(selector, this, {
|
|
391
|
+
xmlMode: true,
|
|
392
|
+
adapter: matcher_1.default
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Query CSS Selector to find matching node.
|
|
397
|
+
* @param {string} selector Simplified CSS selector
|
|
398
|
+
* @return {(HTMLElement|null)} matching node
|
|
399
|
+
*/
|
|
400
|
+
querySelector(selector) {
|
|
401
|
+
return (0, css_select_1.selectOne)(selector, this, {
|
|
402
|
+
xmlMode: true,
|
|
403
|
+
adapter: matcher_1.default
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* find elements by their tagName
|
|
408
|
+
* @param {string} tagName the tagName of the elements to select
|
|
409
|
+
*/
|
|
410
|
+
getElementsByTagName(tagName) {
|
|
411
|
+
const upperCasedTagName = tagName.toUpperCase();
|
|
412
|
+
const re = [];
|
|
413
|
+
const stack = [];
|
|
414
|
+
let currentNodeReference = this;
|
|
415
|
+
let index = 0;
|
|
416
|
+
while (index !== void 0) {
|
|
417
|
+
let child;
|
|
418
|
+
do {
|
|
419
|
+
child = currentNodeReference.childNodes[index++];
|
|
420
|
+
} while (index < currentNodeReference.childNodes.length && child === void 0);
|
|
421
|
+
if (child === void 0) {
|
|
422
|
+
currentNodeReference = currentNodeReference.parentNode;
|
|
423
|
+
index = stack.pop();
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (child.nodeType === type_1.default.ELEMENT_NODE) {
|
|
427
|
+
if (tagName === "*" || child.tagName === upperCasedTagName)
|
|
428
|
+
re.push(child);
|
|
429
|
+
if (child.childNodes.length > 0) {
|
|
430
|
+
stack.push(index);
|
|
431
|
+
currentNodeReference = child;
|
|
432
|
+
index = 0;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return re;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* find element by it's id
|
|
440
|
+
* @param {string} id the id of the element to select
|
|
441
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
442
|
+
*/
|
|
443
|
+
getElementById(id) {
|
|
444
|
+
const stack = [];
|
|
445
|
+
let currentNodeReference = this;
|
|
446
|
+
let index = 0;
|
|
447
|
+
while (index !== void 0) {
|
|
448
|
+
let child;
|
|
449
|
+
do {
|
|
450
|
+
child = currentNodeReference.childNodes[index++];
|
|
451
|
+
} while (index < currentNodeReference.childNodes.length && child === void 0);
|
|
452
|
+
if (child === void 0) {
|
|
453
|
+
currentNodeReference = currentNodeReference.parentNode;
|
|
454
|
+
index = stack.pop();
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (child.nodeType === type_1.default.ELEMENT_NODE) {
|
|
458
|
+
if (child._id === id) {
|
|
459
|
+
return child;
|
|
460
|
+
}
|
|
461
|
+
if (child.childNodes.length > 0) {
|
|
462
|
+
stack.push(index);
|
|
463
|
+
currentNodeReference = child;
|
|
464
|
+
index = 0;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
|
472
|
+
* @param selector a DOMString containing a selector list
|
|
473
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
474
|
+
*/
|
|
475
|
+
closest(selector) {
|
|
476
|
+
const mapChild = /* @__PURE__ */ new Map();
|
|
477
|
+
let el = this;
|
|
478
|
+
let old = null;
|
|
479
|
+
function findOne(test, elems) {
|
|
480
|
+
let elem = null;
|
|
481
|
+
for (let i = 0, l = elems.length; i < l && !elem; i++) {
|
|
482
|
+
const el2 = elems[i];
|
|
483
|
+
if (test(el2)) {
|
|
484
|
+
elem = el2;
|
|
485
|
+
} else {
|
|
486
|
+
const child = mapChild.get(el2);
|
|
487
|
+
if (child) {
|
|
488
|
+
elem = findOne(test, [child]);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return elem;
|
|
493
|
+
}
|
|
494
|
+
while (el) {
|
|
495
|
+
mapChild.set(el, old);
|
|
496
|
+
old = el;
|
|
497
|
+
el = el.parentNode;
|
|
498
|
+
}
|
|
499
|
+
el = this;
|
|
500
|
+
while (el) {
|
|
501
|
+
const e = (0, css_select_1.selectOne)(selector, el, {
|
|
502
|
+
xmlMode: true,
|
|
503
|
+
adapter: Object.assign(Object.assign({}, matcher_1.default), {
|
|
504
|
+
getChildren(node) {
|
|
505
|
+
const child = mapChild.get(node);
|
|
506
|
+
return child && [child];
|
|
507
|
+
},
|
|
508
|
+
getSiblings(node) {
|
|
509
|
+
return [node];
|
|
510
|
+
},
|
|
511
|
+
findOne,
|
|
512
|
+
findAll() {
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
})
|
|
516
|
+
});
|
|
517
|
+
if (e) {
|
|
518
|
+
return e;
|
|
519
|
+
}
|
|
520
|
+
el = el.parentNode;
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Append a child node to childNodes
|
|
526
|
+
* @param {Node} node node to append
|
|
527
|
+
* @return {Node} node appended
|
|
528
|
+
*/
|
|
529
|
+
appendChild(node) {
|
|
530
|
+
this.append(node);
|
|
531
|
+
return node;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Get attributes
|
|
535
|
+
* @access private
|
|
536
|
+
* @return {Object} parsed and unescaped attributes
|
|
537
|
+
*/
|
|
538
|
+
get attrs() {
|
|
539
|
+
if (this._attrs) {
|
|
540
|
+
return this._attrs;
|
|
541
|
+
}
|
|
542
|
+
this._attrs = {};
|
|
543
|
+
const attrs = this.rawAttributes;
|
|
544
|
+
for (const key in attrs) {
|
|
545
|
+
const val = attrs[key] || "";
|
|
546
|
+
this._attrs[key.toLowerCase()] = decode(val);
|
|
547
|
+
}
|
|
548
|
+
return this._attrs;
|
|
549
|
+
}
|
|
550
|
+
get attributes() {
|
|
551
|
+
const ret_attrs = {};
|
|
552
|
+
const attrs = this.rawAttributes;
|
|
553
|
+
for (const key in attrs) {
|
|
554
|
+
const val = attrs[key] || "";
|
|
555
|
+
ret_attrs[key] = decode(val);
|
|
556
|
+
}
|
|
557
|
+
return ret_attrs;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Get escaped (as-is) attributes
|
|
561
|
+
* @return {Object} parsed attributes
|
|
562
|
+
*/
|
|
563
|
+
get rawAttributes() {
|
|
564
|
+
if (this._rawAttrs) {
|
|
565
|
+
return this._rawAttrs;
|
|
566
|
+
}
|
|
567
|
+
const attrs = {};
|
|
568
|
+
if (this.rawAttrs) {
|
|
569
|
+
const re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-._:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
|
|
570
|
+
let match;
|
|
571
|
+
while (match = re.exec(this.rawAttrs)) {
|
|
572
|
+
const key = match[1];
|
|
573
|
+
let val = match[2] || null;
|
|
574
|
+
if (val && (val[0] === `'` || val[0] === `"`))
|
|
575
|
+
val = val.slice(1, val.length - 1);
|
|
576
|
+
attrs[key] = attrs[key] || val;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
this._rawAttrs = attrs;
|
|
580
|
+
return attrs;
|
|
581
|
+
}
|
|
582
|
+
removeAttribute(key) {
|
|
583
|
+
const attrs = this.rawAttributes;
|
|
584
|
+
delete attrs[key];
|
|
585
|
+
if (this._attrs) {
|
|
586
|
+
delete this._attrs[key];
|
|
587
|
+
}
|
|
588
|
+
this.rawAttrs = Object.keys(attrs).map((name) => {
|
|
589
|
+
const val = this.quoteAttribute(attrs[name]);
|
|
590
|
+
if (val === "null" || val === '""')
|
|
591
|
+
return name;
|
|
592
|
+
return `${name}=${val}`;
|
|
593
|
+
}).join(" ");
|
|
594
|
+
if (key === "id") {
|
|
595
|
+
this._id = "";
|
|
596
|
+
}
|
|
597
|
+
return this;
|
|
598
|
+
}
|
|
599
|
+
hasAttribute(key) {
|
|
600
|
+
return key.toLowerCase() in this.attrs;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Get an attribute
|
|
604
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
605
|
+
*/
|
|
606
|
+
getAttribute(key) {
|
|
607
|
+
return this.attrs[key.toLowerCase()];
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Set an attribute value to the HTMLElement
|
|
611
|
+
* @param {string} key The attribute name
|
|
612
|
+
* @param {string} value The value to set, or null / undefined to remove an attribute
|
|
613
|
+
*/
|
|
614
|
+
setAttribute(key, value) {
|
|
615
|
+
if (arguments.length < 2) {
|
|
616
|
+
throw new Error("Failed to execute 'setAttribute' on 'Element'");
|
|
617
|
+
}
|
|
618
|
+
const k2 = key.toLowerCase();
|
|
619
|
+
const attrs = this.rawAttributes;
|
|
620
|
+
for (const k in attrs) {
|
|
621
|
+
if (k.toLowerCase() === k2) {
|
|
622
|
+
key = k;
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
attrs[key] = String(value);
|
|
627
|
+
if (this._attrs) {
|
|
628
|
+
this._attrs[k2] = decode(attrs[key]);
|
|
629
|
+
}
|
|
630
|
+
this.rawAttrs = Object.keys(attrs).map((name) => {
|
|
631
|
+
const val = this.quoteAttribute(attrs[name]);
|
|
632
|
+
if (val === "null" || val === '""')
|
|
633
|
+
return name;
|
|
634
|
+
return `${name}=${val}`;
|
|
635
|
+
}).join(" ");
|
|
636
|
+
if (key === "id") {
|
|
637
|
+
this._id = value;
|
|
638
|
+
}
|
|
639
|
+
return this;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Replace all the attributes of the HTMLElement by the provided attributes
|
|
643
|
+
* @param {Attributes} attributes the new attribute set
|
|
644
|
+
*/
|
|
645
|
+
setAttributes(attributes) {
|
|
646
|
+
if (this._attrs) {
|
|
647
|
+
delete this._attrs;
|
|
648
|
+
}
|
|
649
|
+
if (this._rawAttrs) {
|
|
650
|
+
delete this._rawAttrs;
|
|
651
|
+
}
|
|
652
|
+
this.rawAttrs = Object.keys(attributes).map((name) => {
|
|
653
|
+
const val = attributes[name];
|
|
654
|
+
if (val === "null" || val === '""')
|
|
655
|
+
return name;
|
|
656
|
+
return `${name}=${this.quoteAttribute(String(val))}`;
|
|
657
|
+
}).join(" ");
|
|
658
|
+
if ("id" in attributes) {
|
|
659
|
+
this._id = attributes["id"];
|
|
660
|
+
}
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
insertAdjacentHTML(where, html2) {
|
|
664
|
+
if (arguments.length < 2) {
|
|
665
|
+
throw new Error("2 arguments required");
|
|
666
|
+
}
|
|
667
|
+
const p = parse(html2, this._parseOptions);
|
|
668
|
+
if (where === "afterend") {
|
|
669
|
+
this.after(...p.childNodes);
|
|
670
|
+
} else if (where === "afterbegin") {
|
|
671
|
+
this.prepend(...p.childNodes);
|
|
672
|
+
} else if (where === "beforeend") {
|
|
673
|
+
this.append(...p.childNodes);
|
|
674
|
+
} else if (where === "beforebegin") {
|
|
675
|
+
this.before(...p.childNodes);
|
|
676
|
+
} else {
|
|
677
|
+
throw new Error(`The value provided ('${where}') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'`);
|
|
678
|
+
}
|
|
679
|
+
return this;
|
|
680
|
+
}
|
|
681
|
+
/** Prepend nodes or strings to this node's children. */
|
|
682
|
+
prepend(...insertable) {
|
|
683
|
+
const nodes = resolveInsertable(insertable);
|
|
684
|
+
resetParent(nodes, this);
|
|
685
|
+
this.childNodes.unshift(...nodes);
|
|
686
|
+
}
|
|
687
|
+
/** Append nodes or strings to this node's children. */
|
|
688
|
+
append(...insertable) {
|
|
689
|
+
const nodes = resolveInsertable(insertable);
|
|
690
|
+
resetParent(nodes, this);
|
|
691
|
+
this.childNodes.push(...nodes);
|
|
692
|
+
}
|
|
693
|
+
/** Insert nodes or strings before this node. */
|
|
694
|
+
before(...insertable) {
|
|
695
|
+
const nodes = resolveInsertable(insertable);
|
|
696
|
+
const siblings = this.parentNode.childNodes;
|
|
697
|
+
resetParent(nodes, this.parentNode);
|
|
698
|
+
siblings.splice(siblings.indexOf(this), 0, ...nodes);
|
|
699
|
+
}
|
|
700
|
+
/** Insert nodes or strings after this node. */
|
|
701
|
+
after(...insertable) {
|
|
702
|
+
const nodes = resolveInsertable(insertable);
|
|
703
|
+
const siblings = this.parentNode.childNodes;
|
|
704
|
+
resetParent(nodes, this.parentNode);
|
|
705
|
+
siblings.splice(siblings.indexOf(this) + 1, 0, ...nodes);
|
|
706
|
+
}
|
|
707
|
+
get nextSibling() {
|
|
708
|
+
if (this.parentNode) {
|
|
709
|
+
const children = this.parentNode.childNodes;
|
|
710
|
+
let i = 0;
|
|
711
|
+
while (i < children.length) {
|
|
712
|
+
const child = children[i++];
|
|
713
|
+
if (this === child)
|
|
714
|
+
return children[i] || null;
|
|
715
|
+
}
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
get nextElementSibling() {
|
|
720
|
+
if (this.parentNode) {
|
|
721
|
+
const children = this.parentNode.childNodes;
|
|
722
|
+
let i = 0;
|
|
723
|
+
let find = false;
|
|
724
|
+
while (i < children.length) {
|
|
725
|
+
const child = children[i++];
|
|
726
|
+
if (find) {
|
|
727
|
+
if (child instanceof HTMLElement) {
|
|
728
|
+
return child || null;
|
|
729
|
+
}
|
|
730
|
+
} else if (this === child) {
|
|
731
|
+
find = true;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
get previousSibling() {
|
|
738
|
+
if (this.parentNode) {
|
|
739
|
+
const children = this.parentNode.childNodes;
|
|
740
|
+
let i = children.length;
|
|
741
|
+
while (i > 0) {
|
|
742
|
+
const child = children[--i];
|
|
743
|
+
if (this === child)
|
|
744
|
+
return children[i - 1] || null;
|
|
745
|
+
}
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
get previousElementSibling() {
|
|
750
|
+
if (this.parentNode) {
|
|
751
|
+
const children = this.parentNode.childNodes;
|
|
752
|
+
let i = children.length;
|
|
753
|
+
let find = false;
|
|
754
|
+
while (i > 0) {
|
|
755
|
+
const child = children[--i];
|
|
756
|
+
if (find) {
|
|
757
|
+
if (child instanceof HTMLElement) {
|
|
758
|
+
return child || null;
|
|
759
|
+
}
|
|
760
|
+
} else if (this === child) {
|
|
761
|
+
find = true;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
/** Get all childNodes of type {@link HTMLElement}. */
|
|
768
|
+
get children() {
|
|
769
|
+
const children = [];
|
|
770
|
+
for (const childNode of this.childNodes) {
|
|
771
|
+
if (childNode instanceof HTMLElement) {
|
|
772
|
+
children.push(childNode);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return children;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Get the first child node.
|
|
779
|
+
* @return The first child or undefined if none exists.
|
|
780
|
+
*/
|
|
781
|
+
get firstChild() {
|
|
782
|
+
return this.childNodes[0];
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Get the first child node of type {@link HTMLElement}.
|
|
786
|
+
* @return The first child element or undefined if none exists.
|
|
787
|
+
*/
|
|
788
|
+
get firstElementChild() {
|
|
789
|
+
return this.children[0];
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Get the last child node.
|
|
793
|
+
* @return The last child or undefined if none exists.
|
|
794
|
+
*/
|
|
795
|
+
get lastChild() {
|
|
796
|
+
return (0, back_1.default)(this.childNodes);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Get the last child node of type {@link HTMLElement}.
|
|
800
|
+
* @return The last child element or undefined if none exists.
|
|
801
|
+
*/
|
|
802
|
+
get lastElementChild() {
|
|
803
|
+
return this.children[this.children.length - 1];
|
|
804
|
+
}
|
|
805
|
+
get childElementCount() {
|
|
806
|
+
return this.children.length;
|
|
807
|
+
}
|
|
808
|
+
get classNames() {
|
|
809
|
+
return this.classList.toString();
|
|
810
|
+
}
|
|
811
|
+
/** Clone this Node */
|
|
812
|
+
clone() {
|
|
813
|
+
return parse(this.toString(), this._parseOptions).firstChild;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
html.default = HTMLElement;
|
|
817
|
+
const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z@\xB7\xC0-\xD6\xD8-\xF6\u00F8-\u03A1\u03A3-\u03D9\u03DB-\u03EF\u03F7-\u03FF\u0400-\u04FF\u0500-\u052F\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E00-\u1E9B\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u2132\u214E\u2160-\u2188\u2C60-\u2C7F\uA722-\uA787\uA78B-\uA78E\uA790-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA7FF\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64-\uAB65\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\x37F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gu;
|
|
818
|
+
const kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
|
|
819
|
+
const kElementsClosedByOpening = {
|
|
820
|
+
li: { li: true, LI: true },
|
|
821
|
+
LI: { li: true, LI: true },
|
|
822
|
+
p: { p: true, div: true, P: true, DIV: true },
|
|
823
|
+
P: { p: true, div: true, P: true, DIV: true },
|
|
824
|
+
b: { div: true, DIV: true },
|
|
825
|
+
B: { div: true, DIV: true },
|
|
826
|
+
td: { td: true, th: true, TD: true, TH: true },
|
|
827
|
+
TD: { td: true, th: true, TD: true, TH: true },
|
|
828
|
+
th: { td: true, th: true, TD: true, TH: true },
|
|
829
|
+
TH: { td: true, th: true, TD: true, TH: true },
|
|
830
|
+
h1: { h1: true, H1: true },
|
|
831
|
+
H1: { h1: true, H1: true },
|
|
832
|
+
h2: { h2: true, H2: true },
|
|
833
|
+
H2: { h2: true, H2: true },
|
|
834
|
+
h3: { h3: true, H3: true },
|
|
835
|
+
H3: { h3: true, H3: true },
|
|
836
|
+
h4: { h4: true, H4: true },
|
|
837
|
+
H4: { h4: true, H4: true },
|
|
838
|
+
h5: { h5: true, H5: true },
|
|
839
|
+
H5: { h5: true, H5: true },
|
|
840
|
+
h6: { h6: true, H6: true },
|
|
841
|
+
H6: { h6: true, H6: true }
|
|
842
|
+
};
|
|
843
|
+
const kElementsClosedByClosing = {
|
|
844
|
+
li: { ul: true, ol: true, UL: true, OL: true },
|
|
845
|
+
LI: { ul: true, ol: true, UL: true, OL: true },
|
|
846
|
+
a: { div: true, DIV: true },
|
|
847
|
+
A: { div: true, DIV: true },
|
|
848
|
+
b: { div: true, DIV: true },
|
|
849
|
+
B: { div: true, DIV: true },
|
|
850
|
+
i: { div: true, DIV: true },
|
|
851
|
+
I: { div: true, DIV: true },
|
|
852
|
+
p: { div: true, DIV: true },
|
|
853
|
+
P: { div: true, DIV: true },
|
|
854
|
+
td: { tr: true, table: true, TR: true, TABLE: true },
|
|
855
|
+
TD: { tr: true, table: true, TR: true, TABLE: true },
|
|
856
|
+
th: { tr: true, table: true, TR: true, TABLE: true },
|
|
857
|
+
TH: { tr: true, table: true, TR: true, TABLE: true }
|
|
858
|
+
};
|
|
859
|
+
const kElementsClosedByClosingExcept = {
|
|
860
|
+
p: { a: true, audio: true, del: true, ins: true, map: true, noscript: true, video: true }
|
|
861
|
+
};
|
|
862
|
+
const frameflag = "documentfragmentcontainer";
|
|
863
|
+
function base_parse(data, options = {}) {
|
|
864
|
+
var _a, _b;
|
|
865
|
+
const voidTag = new void_tag_1.default((_a = options === null || options === void 0 ? void 0 : options.voidTag) === null || _a === void 0 ? void 0 : _a.closingSlash, (_b = options === null || options === void 0 ? void 0 : options.voidTag) === null || _b === void 0 ? void 0 : _b.tags);
|
|
866
|
+
const elements = options.blockTextElements || {
|
|
867
|
+
script: true,
|
|
868
|
+
noscript: true,
|
|
869
|
+
style: true,
|
|
870
|
+
pre: true
|
|
871
|
+
};
|
|
872
|
+
const element_names = Object.keys(elements);
|
|
873
|
+
const kBlockTextElements = element_names.map((it) => new RegExp(`^${it}$`, "i"));
|
|
874
|
+
const kIgnoreElements = element_names.filter((it) => Boolean(elements[it])).map((it) => new RegExp(`^${it}$`, "i"));
|
|
875
|
+
function element_should_be_ignore(tag) {
|
|
876
|
+
return kIgnoreElements.some((it) => it.test(tag));
|
|
877
|
+
}
|
|
878
|
+
function is_block_text_element(tag) {
|
|
879
|
+
return kBlockTextElements.some((it) => it.test(tag));
|
|
880
|
+
}
|
|
881
|
+
const createRange = (startPos, endPos) => [startPos - frameFlagOffset, endPos - frameFlagOffset];
|
|
882
|
+
const root = new HTMLElement(null, {}, "", null, [0, data.length], voidTag, options);
|
|
883
|
+
let currentParent = root;
|
|
884
|
+
const stack = [root];
|
|
885
|
+
let lastTextPos = -1;
|
|
886
|
+
let noNestedTagIndex = void 0;
|
|
887
|
+
let match;
|
|
888
|
+
data = `<${frameflag}>${data}</${frameflag}>`;
|
|
889
|
+
const { lowerCaseTagName, fixNestedATags } = options;
|
|
890
|
+
const dataEndPos = data.length - (frameflag.length + 2);
|
|
891
|
+
const frameFlagOffset = frameflag.length + 2;
|
|
892
|
+
while (match = kMarkupPattern.exec(data)) {
|
|
893
|
+
let { 0: matchText, 1: leadingSlash, 2: tagName, 3: attributes, 4: closingSlash } = match;
|
|
894
|
+
const matchLength = matchText.length;
|
|
895
|
+
const tagStartPos = kMarkupPattern.lastIndex - matchLength;
|
|
896
|
+
const tagEndPos = kMarkupPattern.lastIndex;
|
|
897
|
+
if (lastTextPos > -1) {
|
|
898
|
+
if (lastTextPos + matchLength < tagEndPos) {
|
|
899
|
+
const text = data.substring(lastTextPos, tagStartPos);
|
|
900
|
+
currentParent.appendChild(new text_1.default(text, currentParent, createRange(lastTextPos, tagStartPos)));
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
lastTextPos = kMarkupPattern.lastIndex;
|
|
904
|
+
if (tagName === frameflag)
|
|
905
|
+
continue;
|
|
906
|
+
if (matchText[1] === "!") {
|
|
907
|
+
if (options.comment) {
|
|
908
|
+
const text = data.substring(tagStartPos + 4, tagEndPos - 3);
|
|
909
|
+
currentParent.appendChild(new comment_1.default(text, currentParent, createRange(tagStartPos, tagEndPos)));
|
|
910
|
+
}
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
if (lowerCaseTagName)
|
|
914
|
+
tagName = tagName.toLowerCase();
|
|
915
|
+
if (!leadingSlash) {
|
|
916
|
+
const attrs = {};
|
|
917
|
+
for (let attMatch; attMatch = kAttributePattern.exec(attributes); ) {
|
|
918
|
+
const { 1: key, 2: val } = attMatch;
|
|
919
|
+
const isQuoted = val[0] === `'` || val[0] === `"`;
|
|
920
|
+
attrs[key.toLowerCase()] = isQuoted ? val.slice(1, val.length - 1) : val;
|
|
921
|
+
}
|
|
922
|
+
const parentTagName = currentParent.rawTagName;
|
|
923
|
+
if (!closingSlash && kElementsClosedByOpening[parentTagName]) {
|
|
924
|
+
if (kElementsClosedByOpening[parentTagName][tagName]) {
|
|
925
|
+
stack.pop();
|
|
926
|
+
currentParent = (0, back_1.default)(stack);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (fixNestedATags && (tagName === "a" || tagName === "A")) {
|
|
930
|
+
if (noNestedTagIndex !== void 0) {
|
|
931
|
+
stack.splice(noNestedTagIndex);
|
|
932
|
+
currentParent = (0, back_1.default)(stack);
|
|
933
|
+
}
|
|
934
|
+
noNestedTagIndex = stack.length;
|
|
935
|
+
}
|
|
936
|
+
const tagEndPos2 = kMarkupPattern.lastIndex;
|
|
937
|
+
const tagStartPos2 = tagEndPos2 - matchLength;
|
|
938
|
+
currentParent = currentParent.appendChild(
|
|
939
|
+
// Initialize range (end position updated later for closed tags)
|
|
940
|
+
new HTMLElement(tagName, attrs, attributes.slice(1), null, createRange(tagStartPos2, tagEndPos2), voidTag, options)
|
|
941
|
+
);
|
|
942
|
+
stack.push(currentParent);
|
|
943
|
+
if (is_block_text_element(tagName)) {
|
|
944
|
+
const closeMarkup = `</${tagName}>`;
|
|
945
|
+
const closeIndex = lowerCaseTagName ? data.toLocaleLowerCase().indexOf(closeMarkup, kMarkupPattern.lastIndex) : data.indexOf(closeMarkup, kMarkupPattern.lastIndex);
|
|
946
|
+
const textEndPos = closeIndex === -1 ? dataEndPos : closeIndex;
|
|
947
|
+
if (element_should_be_ignore(tagName)) {
|
|
948
|
+
const text = data.substring(tagEndPos2, textEndPos);
|
|
949
|
+
if (text.length > 0 && /\S/.test(text)) {
|
|
950
|
+
currentParent.appendChild(new text_1.default(text, currentParent, createRange(tagEndPos2, textEndPos)));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (closeIndex === -1) {
|
|
954
|
+
lastTextPos = kMarkupPattern.lastIndex = data.length + 1;
|
|
955
|
+
} else {
|
|
956
|
+
lastTextPos = kMarkupPattern.lastIndex = closeIndex + closeMarkup.length;
|
|
957
|
+
leadingSlash = "/";
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
|
|
962
|
+
while (true) {
|
|
963
|
+
if (noNestedTagIndex != null && (tagName === "a" || tagName === "A"))
|
|
964
|
+
noNestedTagIndex = void 0;
|
|
965
|
+
if (currentParent.rawTagName === tagName) {
|
|
966
|
+
currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
|
|
967
|
+
stack.pop();
|
|
968
|
+
currentParent = (0, back_1.default)(stack);
|
|
969
|
+
break;
|
|
970
|
+
} else {
|
|
971
|
+
const parentTagName = currentParent.tagName;
|
|
972
|
+
if (kElementsClosedByClosing[parentTagName]) {
|
|
973
|
+
if (kElementsClosedByClosing[parentTagName][tagName]) {
|
|
974
|
+
stack.pop();
|
|
975
|
+
currentParent = (0, back_1.default)(stack);
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
const openTag = currentParent.rawTagName ? currentParent.rawTagName.toLowerCase() : "";
|
|
980
|
+
if (kElementsClosedByClosingExcept[openTag]) {
|
|
981
|
+
const closingTag = tagName.toLowerCase();
|
|
982
|
+
if (stack.length > 1) {
|
|
983
|
+
const possibleContainer = stack[stack.length - 2];
|
|
984
|
+
if (possibleContainer && possibleContainer.rawTagName && possibleContainer.rawTagName.toLowerCase() === closingTag && !kElementsClosedByClosingExcept[openTag][closingTag]) {
|
|
985
|
+
currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
|
|
986
|
+
stack.pop();
|
|
987
|
+
currentParent = (0, back_1.default)(stack);
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return stack;
|
|
998
|
+
}
|
|
999
|
+
html.base_parse = base_parse;
|
|
1000
|
+
function parse(data, options = {}) {
|
|
1001
|
+
const stack = base_parse(data, options);
|
|
1002
|
+
const [root] = stack;
|
|
1003
|
+
while (stack.length > 1) {
|
|
1004
|
+
const last = stack.pop();
|
|
1005
|
+
const oneBefore = (0, back_1.default)(stack);
|
|
1006
|
+
if (last.parentNode && last.parentNode.parentNode) {
|
|
1007
|
+
if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {
|
|
1008
|
+
if (options.parseNoneClosedTags !== true) {
|
|
1009
|
+
oneBefore.removeChild(last);
|
|
1010
|
+
last.childNodes.forEach((child) => {
|
|
1011
|
+
oneBefore.parentNode.appendChild(child);
|
|
1012
|
+
});
|
|
1013
|
+
stack.pop();
|
|
1014
|
+
}
|
|
1015
|
+
} else {
|
|
1016
|
+
if (options.parseNoneClosedTags !== true) {
|
|
1017
|
+
oneBefore.removeChild(last);
|
|
1018
|
+
last.childNodes.forEach((child) => {
|
|
1019
|
+
oneBefore.appendChild(child);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return root;
|
|
1026
|
+
}
|
|
1027
|
+
html.parse = parse;
|
|
1028
|
+
function resolveInsertable(insertable) {
|
|
1029
|
+
return insertable.map((val) => {
|
|
1030
|
+
if (typeof val === "string") {
|
|
1031
|
+
return new text_1.default(val);
|
|
1032
|
+
}
|
|
1033
|
+
val.remove();
|
|
1034
|
+
return val;
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function resetParent(nodes, parent) {
|
|
1038
|
+
return nodes.map((node) => {
|
|
1039
|
+
node.parentNode = parent;
|
|
1040
|
+
return node;
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return html;
|
|
1044
|
+
}
|
|
1045
|
+
export {
|
|
1046
|
+
requireHtml as __require
|
|
1047
|
+
};
|
|
1048
|
+
//# sourceMappingURL=html.js.map
|