omni-viewer-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/THIRD_PARTY_NOTICES.md +49 -0
- package/dist/assets/audio-engine/audio_engine.mjs +2 -0
- package/dist/assets/audio-engine/audio_engine.wasm +0 -0
- package/dist/assets/pdfjs/pdf.worker.min.mjs +21 -0
- package/dist/host/index.d.ts +133 -0
- package/dist/host/index.js +10 -0
- package/dist/i18n/catalog.en.d.ts +1 -0
- package/dist/i18n/catalog.en.js +411 -0
- package/dist/i18n/catalog.ko.d.ts +1 -0
- package/dist/i18n/catalog.ko.js +68 -0
- package/dist/i18n/index.d.ts +18 -0
- package/dist/i18n/index.js +41 -0
- package/dist/licenses/emscripten.txt +101 -0
- package/dist/licenses/kissfft.txt +28 -0
- package/dist/licenses/pdfjs-dist.txt +177 -0
- package/dist/parsers/a2l/index.d.ts +1 -0
- package/dist/parsers/a2l/index.js +1 -0
- package/dist/parsers/archive/index.d.ts +22 -0
- package/dist/parsers/archive/index.js +46 -0
- package/dist/parsers/archive/model.d.ts +29 -0
- package/dist/parsers/archive/model.js +1 -0
- package/dist/parsers/archive/worker.d.ts +21 -0
- package/dist/parsers/archive/worker.js +1 -0
- package/dist/parsers/arxml/index.d.ts +1 -0
- package/dist/parsers/arxml/index.js +1 -0
- package/dist/parsers/asc/index.d.ts +1 -0
- package/dist/parsers/asc/index.js +1 -0
- package/dist/parsers/audio/index.d.ts +9 -0
- package/dist/parsers/audio/index.js +46 -0
- package/dist/parsers/automotive/index.d.ts +33 -0
- package/dist/parsers/automotive/index.js +973 -0
- package/dist/parsers/blf/index.d.ts +1 -0
- package/dist/parsers/blf/index.js +1 -0
- package/dist/parsers/csv/delimiter.d.ts +31 -0
- package/dist/parsers/csv/delimiter.js +151 -0
- package/dist/parsers/csv/index.d.ts +30 -0
- package/dist/parsers/csv/index.js +108 -0
- package/dist/parsers/csv/parseText.d.ts +20 -0
- package/dist/parsers/csv/parseText.js +108 -0
- package/dist/parsers/csv/sort.d.ts +26 -0
- package/dist/parsers/csv/sort.js +224 -0
- package/dist/parsers/csv/statistics.d.ts +49 -0
- package/dist/parsers/csv/statistics.js +150 -0
- package/dist/parsers/dbc/index.d.ts +56 -0
- package/dist/parsers/dbc/index.js +94 -0
- package/dist/parsers/doc-binary/index.d.ts +35 -0
- package/dist/parsers/doc-binary/index.js +267 -0
- package/dist/parsers/doc-binary/vscode-parser.d.ts +142 -0
- package/dist/parsers/doc-binary/vscode-parser.js +3747 -0
- package/dist/parsers/excel/index.d.ts +17 -0
- package/dist/parsers/excel/index.js +406 -0
- package/dist/parsers/excel/model.d.ts +80 -0
- package/dist/parsers/excel/model.js +48 -0
- package/dist/parsers/excel/serialize.d.ts +3 -0
- package/dist/parsers/excel/serialize.js +78 -0
- package/dist/parsers/hdf5/index.d.ts +75 -0
- package/dist/parsers/hdf5/index.js +658 -0
- package/dist/parsers/hdf5/node.d.ts +21 -0
- package/dist/parsers/hdf5/node.js +95 -0
- package/dist/parsers/json/index.d.ts +15 -0
- package/dist/parsers/json/index.js +102 -0
- package/dist/parsers/json/model.d.ts +42 -0
- package/dist/parsers/json/model.js +140 -0
- package/dist/parsers/json/parse.d.ts +22 -0
- package/dist/parsers/json/parse.js +279 -0
- package/dist/parsers/json/tokenizer.d.ts +17 -0
- package/dist/parsers/json/tokenizer.js +175 -0
- package/dist/parsers/jsonl/index.d.ts +14 -0
- package/dist/parsers/jsonl/index.js +18 -0
- package/dist/parsers/jsonl/model.d.ts +23 -0
- package/dist/parsers/jsonl/model.js +1 -0
- package/dist/parsers/jsonl/parse.d.ts +7 -0
- package/dist/parsers/jsonl/parse.js +34 -0
- package/dist/parsers/markdown/index.d.ts +37 -0
- package/dist/parsers/markdown/index.js +59 -0
- package/dist/parsers/mat/index.d.ts +31 -0
- package/dist/parsers/mat/index.js +426 -0
- package/dist/parsers/mermaid/index.d.ts +5 -0
- package/dist/parsers/mermaid/index.js +3 -0
- package/dist/parsers/mf4/index.d.ts +1 -0
- package/dist/parsers/mf4/index.js +1 -0
- package/dist/parsers/parquet/index.d.ts +21 -0
- package/dist/parsers/parquet/index.js +68 -0
- package/dist/parsers/pcap/index.d.ts +1 -0
- package/dist/parsers/pcap/index.js +1 -0
- package/dist/parsers/pcapng/index.d.ts +1 -0
- package/dist/parsers/pcapng/index.js +1 -0
- package/dist/parsers/plantuml/index.d.ts +5 -0
- package/dist/parsers/plantuml/index.js +4 -0
- package/dist/parsers/ppt-binary/index.d.ts +5 -0
- package/dist/parsers/ppt-binary/index.js +62 -0
- package/dist/parsers/ppt-binary/pptBinaryBuildContext.d.ts +12 -0
- package/dist/parsers/ppt-binary/pptBinaryBuildContext.js +40 -0
- package/dist/parsers/ppt-binary/pptBinaryContainer.d.ts +4 -0
- package/dist/parsers/ppt-binary/pptBinaryContainer.js +174 -0
- package/dist/parsers/ppt-binary/pptBinaryTypes.d.ts +125 -0
- package/dist/parsers/ppt-binary/pptBinaryTypes.js +1 -0
- package/dist/parsers/ppt-binary/pptSlideLayouts.d.ts +9 -0
- package/dist/parsers/ppt-binary/pptSlideLayouts.js +510 -0
- package/dist/parsers/ppt-binary/vscode-parser.d.ts +116 -0
- package/dist/parsers/ppt-binary/vscode-parser.js +2853 -0
- package/dist/parsers/ppt-binary/vscode.d.ts +4 -0
- package/dist/parsers/ppt-binary/vscode.js +12 -0
- package/dist/parsers/pptx/index.d.ts +15 -0
- package/dist/parsers/pptx/index.js +88 -0
- package/dist/parsers/pptx/vscode-parser.d.ts +167 -0
- package/dist/parsers/pptx/vscode-parser.js +1503 -0
- package/dist/parsers/pptx/vscode.d.ts +4 -0
- package/dist/parsers/pptx/vscode.js +18 -0
- package/dist/parsers/pptx/zip-reader.d.ts +3 -0
- package/dist/parsers/pptx/zip-reader.js +20 -0
- package/dist/parsers/proto/index.d.ts +90 -0
- package/dist/parsers/proto/index.js +197 -0
- package/dist/parsers/psd/index.d.ts +16 -0
- package/dist/parsers/psd/index.js +10 -0
- package/dist/parsers/shapefile/dbf.d.ts +23 -0
- package/dist/parsers/shapefile/dbf.js +112 -0
- package/dist/parsers/shapefile/index.d.ts +44 -0
- package/dist/parsers/shapefile/index.js +119 -0
- package/dist/parsers/shapefile/reproject.d.ts +10 -0
- package/dist/parsers/shapefile/reproject.js +41 -0
- package/dist/parsers/slide-model.d.ts +106 -0
- package/dist/parsers/slide-model.js +1 -0
- package/dist/parsers/toml/index.d.ts +15 -0
- package/dist/parsers/toml/index.js +18 -0
- package/dist/parsers/toml/model.d.ts +15 -0
- package/dist/parsers/toml/model.js +1 -0
- package/dist/parsers/toml/parse.d.ts +16 -0
- package/dist/parsers/toml/parse.js +266 -0
- package/dist/parsers/types.d.ts +103 -0
- package/dist/parsers/types.js +106 -0
- package/dist/parsers/video/index.d.ts +6 -0
- package/dist/parsers/video/index.js +2 -0
- package/dist/parsers/yaml/index.d.ts +16 -0
- package/dist/parsers/yaml/index.js +58 -0
- package/dist/parsers/yaml/model.d.ts +22 -0
- package/dist/parsers/yaml/model.js +1 -0
- package/dist/parsers/yaml/self-loading.d.ts +3 -0
- package/dist/parsers/yaml/self-loading.js +19 -0
- package/dist/parsers/zip-scan.d.ts +8 -0
- package/dist/parsers/zip-scan.js +80 -0
- package/dist/registry/container.d.ts +17 -0
- package/dist/registry/container.js +49 -0
- package/dist/registry/index.d.ts +133 -0
- package/dist/registry/index.js +348 -0
- package/dist/registry/probe.d.ts +3 -0
- package/dist/registry/probe.js +177 -0
- package/dist/registry/sniff.d.ts +17 -0
- package/dist/registry/sniff.js +57 -0
- package/dist/styles/archive.css +10 -0
- package/dist/styles/audio.css +66 -0
- package/dist/styles/automotive.css +1 -0
- package/dist/styles/csv.css +262 -0
- package/dist/styles/excel.css +212 -0
- package/dist/styles/fallback.css +48 -0
- package/dist/styles/hdf5.css +3 -0
- package/dist/styles/hwp.css +12 -0
- package/dist/styles/image.css +115 -0
- package/dist/styles/json.css +342 -0
- package/dist/styles/jsonl.css +1 -0
- package/dist/styles/markdown.css +10 -0
- package/dist/styles/mat.css +2 -0
- package/dist/styles/mermaid.css +1 -0
- package/dist/styles/parquet.css +2 -0
- package/dist/styles/pdf.css +551 -0
- package/dist/styles/plantuml.css +1 -0
- package/dist/styles/ppt.css +1 -0
- package/dist/styles/proto.css +2 -0
- package/dist/styles/psd.css +1 -0
- package/dist/styles/shapefile.css +25 -0
- package/dist/styles/toml.css +1 -0
- package/dist/styles/video.css +74 -0
- package/dist/styles/word.css +685 -0
- package/dist/styles/yaml.css +1 -0
- package/dist/viewers/a2l/index.d.ts +15 -0
- package/dist/viewers/a2l/index.js +5 -0
- package/dist/viewers/archive/archive-preview-decoder.d.ts +4 -0
- package/dist/viewers/archive/archive-preview-decoder.js +223 -0
- package/dist/viewers/archive/controller.d.ts +24 -0
- package/dist/viewers/archive/controller.js +18 -0
- package/dist/viewers/archive/index.d.ts +25 -0
- package/dist/viewers/archive/index.js +230 -0
- package/dist/viewers/archive/preview.d.ts +2 -0
- package/dist/viewers/archive/preview.js +2 -0
- package/dist/viewers/archive/styles.d.ts +1 -0
- package/dist/viewers/archive/styles.js +11 -0
- package/dist/viewers/arxml/index.d.ts +15 -0
- package/dist/viewers/arxml/index.js +5 -0
- package/dist/viewers/asc/index.d.ts +15 -0
- package/dist/viewers/asc/index.js +5 -0
- package/dist/viewers/audio/controller.d.ts +33 -0
- package/dist/viewers/audio/controller.js +49 -0
- package/dist/viewers/audio/engine.d.ts +44 -0
- package/dist/viewers/audio/engine.js +108 -0
- package/dist/viewers/audio/index.d.ts +92 -0
- package/dist/viewers/audio/index.js +448 -0
- package/dist/viewers/audio/self-loading.d.ts +7 -0
- package/dist/viewers/audio/self-loading.js +42 -0
- package/dist/viewers/audio/styles.d.ts +1 -0
- package/dist/viewers/audio/styles.js +73 -0
- package/dist/viewers/automotive/index.d.ts +8 -0
- package/dist/viewers/automotive/index.js +152 -0
- package/dist/viewers/automotive/styles.d.ts +1 -0
- package/dist/viewers/automotive/styles.js +1 -0
- package/dist/viewers/avro/index.d.ts +15 -0
- package/dist/viewers/avro/index.js +5 -0
- package/dist/viewers/bag/index.d.ts +15 -0
- package/dist/viewers/bag/index.js +5 -0
- package/dist/viewers/blf/index.d.ts +15 -0
- package/dist/viewers/blf/index.js +5 -0
- package/dist/viewers/csv/controller.d.ts +126 -0
- package/dist/viewers/csv/controller.js +598 -0
- package/dist/viewers/csv/index.d.ts +48 -0
- package/dist/viewers/csv/index.js +846 -0
- package/dist/viewers/csv/styles.d.ts +1 -0
- package/dist/viewers/csv/styles.js +267 -0
- package/dist/viewers/db3/index.d.ts +15 -0
- package/dist/viewers/db3/index.js +5 -0
- package/dist/viewers/dbc/index.d.ts +15 -0
- package/dist/viewers/dbc/index.js +5 -0
- package/dist/viewers/diagram.d.ts +14 -0
- package/dist/viewers/diagram.js +95 -0
- package/dist/viewers/excel/controller.d.ts +108 -0
- package/dist/viewers/excel/controller.js +548 -0
- package/dist/viewers/excel/grid.d.ts +28 -0
- package/dist/viewers/excel/grid.js +99 -0
- package/dist/viewers/excel/index.d.ts +37 -0
- package/dist/viewers/excel/index.js +620 -0
- package/dist/viewers/excel/self-loading.d.ts +6 -0
- package/dist/viewers/excel/self-loading.js +13 -0
- package/dist/viewers/excel/styles.d.ts +1 -0
- package/dist/viewers/excel/styles.js +216 -0
- package/dist/viewers/fallback/index.d.ts +17 -0
- package/dist/viewers/fallback/index.js +130 -0
- package/dist/viewers/fallback/styles.d.ts +1 -0
- package/dist/viewers/fallback/styles.js +49 -0
- package/dist/viewers/hdf5/index.d.ts +19 -0
- package/dist/viewers/hdf5/index.js +170 -0
- package/dist/viewers/hdf5/styles.d.ts +1 -0
- package/dist/viewers/hdf5/styles.js +4 -0
- package/dist/viewers/hwp/controller.d.ts +19 -0
- package/dist/viewers/hwp/controller.js +22 -0
- package/dist/viewers/hwp/index.d.ts +39 -0
- package/dist/viewers/hwp/index.js +271 -0
- package/dist/viewers/hwp/self-loading.d.ts +2 -0
- package/dist/viewers/hwp/self-loading.js +6 -0
- package/dist/viewers/hwp/styles.d.ts +1 -0
- package/dist/viewers/hwp/styles.js +13 -0
- package/dist/viewers/image/controller.d.ts +210 -0
- package/dist/viewers/image/controller.js +336 -0
- package/dist/viewers/image/decode.d.ts +54 -0
- package/dist/viewers/image/decode.js +150 -0
- package/dist/viewers/image/index.d.ts +38 -0
- package/dist/viewers/image/index.js +749 -0
- package/dist/viewers/image/limits.d.ts +18 -0
- package/dist/viewers/image/limits.js +20 -0
- package/dist/viewers/image/styles.d.ts +1 -0
- package/dist/viewers/image/styles.js +119 -0
- package/dist/viewers/json/controller.d.ts +89 -0
- package/dist/viewers/json/controller.js +411 -0
- package/dist/viewers/json/index.d.ts +25 -0
- package/dist/viewers/json/index.js +503 -0
- package/dist/viewers/json/styles.d.ts +1 -0
- package/dist/viewers/json/styles.js +346 -0
- package/dist/viewers/json/transforms.d.ts +27 -0
- package/dist/viewers/json/transforms.js +253 -0
- package/dist/viewers/jsonl/controller.d.ts +48 -0
- package/dist/viewers/jsonl/controller.js +136 -0
- package/dist/viewers/jsonl/index.d.ts +22 -0
- package/dist/viewers/jsonl/index.js +184 -0
- package/dist/viewers/jsonl/styles.d.ts +1 -0
- package/dist/viewers/jsonl/styles.js +1 -0
- package/dist/viewers/markdown/controller.d.ts +50 -0
- package/dist/viewers/markdown/controller.js +62 -0
- package/dist/viewers/markdown/index.d.ts +64 -0
- package/dist/viewers/markdown/index.js +425 -0
- package/dist/viewers/markdown/math.d.ts +21 -0
- package/dist/viewers/markdown/math.js +100 -0
- package/dist/viewers/markdown/self-loading.d.ts +5 -0
- package/dist/viewers/markdown/self-loading.js +48 -0
- package/dist/viewers/markdown/styles.d.ts +1 -0
- package/dist/viewers/markdown/styles.js +11 -0
- package/dist/viewers/mat/index.d.ts +19 -0
- package/dist/viewers/mat/index.js +113 -0
- package/dist/viewers/mat/styles.d.ts +1 -0
- package/dist/viewers/mat/styles.js +3 -0
- package/dist/viewers/media.d.ts +9 -0
- package/dist/viewers/media.js +77 -0
- package/dist/viewers/mermaid/index.d.ts +17 -0
- package/dist/viewers/mermaid/index.js +6 -0
- package/dist/viewers/mermaid/self-loading.d.ts +2 -0
- package/dist/viewers/mermaid/self-loading.js +2 -0
- package/dist/viewers/mf4/index.d.ts +15 -0
- package/dist/viewers/mf4/index.js +5 -0
- package/dist/viewers/parquet/controller.d.ts +37 -0
- package/dist/viewers/parquet/controller.js +26 -0
- package/dist/viewers/parquet/index.d.ts +23 -0
- package/dist/viewers/parquet/index.js +134 -0
- package/dist/viewers/parquet/styles.d.ts +1 -0
- package/dist/viewers/parquet/styles.js +3 -0
- package/dist/viewers/pcap/index.d.ts +15 -0
- package/dist/viewers/pcap/index.js +5 -0
- package/dist/viewers/pcapng/index.d.ts +15 -0
- package/dist/viewers/pcapng/index.js +5 -0
- package/dist/viewers/pdf/controller.d.ts +120 -0
- package/dist/viewers/pdf/controller.js +191 -0
- package/dist/viewers/pdf/editing.d.ts +26 -0
- package/dist/viewers/pdf/editing.js +265 -0
- package/dist/viewers/pdf/index.d.ts +88 -0
- package/dist/viewers/pdf/index.js +1400 -0
- package/dist/viewers/pdf/self-loading.d.ts +6 -0
- package/dist/viewers/pdf/self-loading.js +14 -0
- package/dist/viewers/pdf/styles.d.ts +1 -0
- package/dist/viewers/pdf/styles.js +555 -0
- package/dist/viewers/plantuml/index.d.ts +17 -0
- package/dist/viewers/plantuml/index.js +6 -0
- package/dist/viewers/plantuml/self-loading.d.ts +2 -0
- package/dist/viewers/plantuml/self-loading.js +2 -0
- package/dist/viewers/ppt/chart.d.ts +8 -0
- package/dist/viewers/ppt/chart.js +83 -0
- package/dist/viewers/ppt/controller.d.ts +34 -0
- package/dist/viewers/ppt/controller.js +27 -0
- package/dist/viewers/ppt/index.d.ts +33 -0
- package/dist/viewers/ppt/index.js +101 -0
- package/dist/viewers/ppt/render.d.ts +5 -0
- package/dist/viewers/ppt/render.js +144 -0
- package/dist/viewers/ppt/self-loading.d.ts +9 -0
- package/dist/viewers/ppt/self-loading.js +4 -0
- package/dist/viewers/ppt/styles.d.ts +1 -0
- package/dist/viewers/ppt/styles.js +1 -0
- package/dist/viewers/proto/index.d.ts +17 -0
- package/dist/viewers/proto/index.js +170 -0
- package/dist/viewers/proto/styles.d.ts +1 -0
- package/dist/viewers/proto/styles.js +2 -0
- package/dist/viewers/psd/index.d.ts +27 -0
- package/dist/viewers/psd/index.js +39 -0
- package/dist/viewers/psd/self-loading.d.ts +10 -0
- package/dist/viewers/psd/self-loading.js +20 -0
- package/dist/viewers/psd/styles.d.ts +1 -0
- package/dist/viewers/psd/styles.js +1 -0
- package/dist/viewers/reqif/index.d.ts +15 -0
- package/dist/viewers/reqif/index.js +5 -0
- package/dist/viewers/shapefile/index.d.ts +35 -0
- package/dist/viewers/shapefile/index.js +336 -0
- package/dist/viewers/shapefile/self-loading.d.ts +7 -0
- package/dist/viewers/shapefile/self-loading.js +32 -0
- package/dist/viewers/shapefile/styles.d.ts +1 -0
- package/dist/viewers/shapefile/styles.js +28 -0
- package/dist/viewers/stp/index.d.ts +15 -0
- package/dist/viewers/stp/index.js +5 -0
- package/dist/viewers/structured-styles.d.ts +1 -0
- package/dist/viewers/structured-styles.js +1 -0
- package/dist/viewers/structured.d.ts +36 -0
- package/dist/viewers/structured.js +138 -0
- package/dist/viewers/toml/controller.d.ts +38 -0
- package/dist/viewers/toml/controller.js +61 -0
- package/dist/viewers/toml/index.d.ts +18 -0
- package/dist/viewers/toml/index.js +34 -0
- package/dist/viewers/types.d.ts +36 -0
- package/dist/viewers/types.js +9 -0
- package/dist/viewers/video/controller.d.ts +29 -0
- package/dist/viewers/video/controller.js +54 -0
- package/dist/viewers/video/index.d.ts +18 -0
- package/dist/viewers/video/index.js +305 -0
- package/dist/viewers/video/styles.d.ts +1 -0
- package/dist/viewers/video/styles.js +79 -0
- package/dist/viewers/word/controller.d.ts +19 -0
- package/dist/viewers/word/controller.js +22 -0
- package/dist/viewers/word/docx-preprocess.d.ts +63 -0
- package/dist/viewers/word/docx-preprocess.js +136 -0
- package/dist/viewers/word/index.d.ts +32 -0
- package/dist/viewers/word/index.js +187 -0
- package/dist/viewers/word/normalize-docx.d.ts +2 -0
- package/dist/viewers/word/normalize-docx.js +50 -0
- package/dist/viewers/word/paginate.d.ts +1 -0
- package/dist/viewers/word/paginate.js +1035 -0
- package/dist/viewers/word/self-loading.d.ts +2 -0
- package/dist/viewers/word/self-loading.js +7 -0
- package/dist/viewers/word/styles.d.ts +1 -0
- package/dist/viewers/word/styles.js +686 -0
- package/dist/viewers/yaml/controller.d.ts +42 -0
- package/dist/viewers/yaml/controller.js +41 -0
- package/dist/viewers/yaml/index.d.ts +21 -0
- package/dist/viewers/yaml/index.js +20 -0
- package/package.json +375 -0
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
// @ts-nocheck — DOM pagination ported verbatim from the VS Code viewer.
|
|
2
|
+
export function paginateLegacyDocument(wordContent) {
|
|
3
|
+
const legacyRoot = wordContent.querySelector('.ov-doc-legacy');
|
|
4
|
+
if (!legacyRoot)
|
|
5
|
+
return;
|
|
6
|
+
if (legacyRoot.dataset.ovPaginated === 'true') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const sections = Array.from(legacyRoot.children)
|
|
10
|
+
.filter((node) => node.classList && node.classList.contains('ov-doc-legacy-section'));
|
|
11
|
+
if (sections.length === 0) {
|
|
12
|
+
legacyRoot.dataset.ovPaginated = 'true';
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const paginatedSections = [];
|
|
16
|
+
for (const section of sections) {
|
|
17
|
+
let sectionMeta = {};
|
|
18
|
+
const metaNode = section.querySelector('.ov-doc-legacy-section-meta');
|
|
19
|
+
if (metaNode && metaNode.textContent) {
|
|
20
|
+
try {
|
|
21
|
+
sectionMeta = JSON.parse(metaNode.textContent);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.warn('Failed to parse legacy section meta:', error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const blocks = Array.from(section.children)
|
|
28
|
+
.filter((node) => node.classList && node.classList.contains('ov-doc-legacy-block'));
|
|
29
|
+
if (blocks.length === 0) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const shouldClearAfterFloatingMedia = (floatingBlock, block) => {
|
|
33
|
+
if (!floatingBlock || !block) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const floatingSide = floatingBlock.dataset.ovFloatingSide || 'right';
|
|
37
|
+
const floatingWidth = floatingBlock.dataset.ovFloatingWidth || 'regular';
|
|
38
|
+
const floatingPlacement = floatingBlock.dataset.ovFloatingPlacement || '';
|
|
39
|
+
const semanticKind = block.dataset.ovSemanticKind || '';
|
|
40
|
+
const semanticTag = block.dataset.ovSemanticTag || '';
|
|
41
|
+
const textLength = Number.parseInt(block.dataset.ovTextLength || '', 10) || 0;
|
|
42
|
+
if (floatingPlacement === 'center-block' || floatingSide === 'center' || floatingWidth === 'wide') {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (semanticKind === 'table' || semanticKind === 'sheet' || semanticKind === 'list' || semanticKind === 'images' || semanticKind === 'image') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (semanticKind === 'content' && (semanticTag === 'h1' || semanticTag === 'h2')) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (semanticKind === 'content' && textLength > 120) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (floatingWidth === 'narrow' && semanticKind === 'content' && textLength > 0 && textLength <= 80) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return semanticKind === 'content' && textLength > 80;
|
|
58
|
+
};
|
|
59
|
+
for (let index = 0; index < blocks.length - 1; index++) {
|
|
60
|
+
const currentBlock = blocks[index];
|
|
61
|
+
const nextBlock = blocks[index + 1];
|
|
62
|
+
const floatingClearance = Math.max(4, Number.parseInt(currentBlock.dataset.ovFloatingClearance || '0', 10) || 0);
|
|
63
|
+
if (currentBlock.dataset.ovSemanticRole === 'floating-media' && floatingClearance > 0) {
|
|
64
|
+
currentBlock.style.setProperty('--ov-floating-clearance', `${floatingClearance}px`);
|
|
65
|
+
}
|
|
66
|
+
if (currentBlock.dataset.ovSemanticRole === 'floating-media' && shouldClearAfterFloatingMedia(currentBlock, nextBlock)) {
|
|
67
|
+
nextBlock.dataset.ovClearFloat = 'true';
|
|
68
|
+
nextBlock.style.setProperty('--ov-clear-float-padding', `${floatingClearance}px`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const pagesHost = document.createElement('div');
|
|
72
|
+
pagesHost.className = 'ov-doc-legacy-pages';
|
|
73
|
+
section.innerHTML = '';
|
|
74
|
+
section.appendChild(pagesHost);
|
|
75
|
+
const sectionColumnCount = Math.max(1, Number.parseInt(section.dataset.ovColumns || '1', 10) || 1);
|
|
76
|
+
const explicitColumnWidths = (section.dataset.ovColumnWidths || '')
|
|
77
|
+
.split(',')
|
|
78
|
+
.map((value) => Number.parseFloat(value))
|
|
79
|
+
.filter((value) => Number.isFinite(value) && value > 0);
|
|
80
|
+
const explicitColumnSpacings = (section.dataset.ovColumnSpacings || '')
|
|
81
|
+
.split(',')
|
|
82
|
+
.map((value) => Number.parseFloat(value))
|
|
83
|
+
.filter((value) => Number.isFinite(value) && value >= 0);
|
|
84
|
+
const customColumns = section.dataset.ovCustomColumns === 'true'
|
|
85
|
+
&& explicitColumnWidths.length > 1
|
|
86
|
+
&& sectionColumnCount > 1;
|
|
87
|
+
const hasColumns = sectionColumnCount > 1;
|
|
88
|
+
const columnGapMms = resolveColumnGapMms(section, explicitColumnSpacings, sectionColumnCount);
|
|
89
|
+
let createdPageCount = 0;
|
|
90
|
+
const createPageChrome = () => {
|
|
91
|
+
const sectionPageNumber = createdPageCount + 1;
|
|
92
|
+
const headerCandidates = getHeaderFooterCandidateTexts(sectionMeta, 'header', sectionPageNumber);
|
|
93
|
+
const footerCandidates = getHeaderFooterCandidateTexts(sectionMeta, 'footer', sectionPageNumber);
|
|
94
|
+
const activeHeaderMm = estimateHeaderFooterReserveMm(headerCandidates, Number.parseFloat(section.dataset.ovHeaderMm || '0'));
|
|
95
|
+
const activeFooterMm = estimateHeaderFooterReserveMm(footerCandidates, Number.parseFloat(section.dataset.ovFooterMm || '0'));
|
|
96
|
+
const page = document.createElement('section');
|
|
97
|
+
page.className = 'ov-doc-legacy-page';
|
|
98
|
+
page.dataset.ovSectionPageNumber = String(sectionPageNumber);
|
|
99
|
+
const header = document.createElement('div');
|
|
100
|
+
header.className = 'ov-doc-legacy-page-header';
|
|
101
|
+
const content = document.createElement('div');
|
|
102
|
+
content.className = 'ov-doc-legacy-page-content';
|
|
103
|
+
const footer = document.createElement('div');
|
|
104
|
+
footer.className = 'ov-doc-legacy-page-footer';
|
|
105
|
+
header.textContent = '';
|
|
106
|
+
footer.textContent = '';
|
|
107
|
+
if (headerCandidates.length === 0) {
|
|
108
|
+
header.setAttribute('hidden', 'hidden');
|
|
109
|
+
}
|
|
110
|
+
if (footerCandidates.length === 0) {
|
|
111
|
+
footer.setAttribute('hidden', 'hidden');
|
|
112
|
+
}
|
|
113
|
+
content.style.setProperty('--ov-page-active-header-mm', `${activeHeaderMm.toFixed(2)}mm`);
|
|
114
|
+
content.style.setProperty('--ov-page-active-footer-mm', `${activeFooterMm.toFixed(2)}mm`);
|
|
115
|
+
header.style.setProperty('--ov-page-active-header-mm', `${activeHeaderMm.toFixed(2)}mm`);
|
|
116
|
+
footer.style.setProperty('--ov-page-active-footer-mm', `${activeFooterMm.toFixed(2)}mm`);
|
|
117
|
+
page.appendChild(header);
|
|
118
|
+
page.appendChild(content);
|
|
119
|
+
page.appendChild(footer);
|
|
120
|
+
if (hasColumns) {
|
|
121
|
+
content.classList.add('ov-doc-legacy-page-content-custom-columns');
|
|
122
|
+
const columnsWrap = document.createElement('div');
|
|
123
|
+
columnsWrap.className = 'ov-doc-legacy-page-columns';
|
|
124
|
+
const columnCount = customColumns ? explicitColumnWidths.length : sectionColumnCount;
|
|
125
|
+
const templateTracks = [];
|
|
126
|
+
for (let index = 0; index < columnCount; index++) {
|
|
127
|
+
templateTracks.push(customColumns ? `${explicitColumnWidths[index].toFixed(2)}mm` : 'minmax(0, 1fr)');
|
|
128
|
+
if (index < columnCount - 1) {
|
|
129
|
+
templateTracks.push(`${columnGapMms[index].toFixed(2)}mm`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
columnsWrap.style.gridTemplateColumns = templateTracks.join(' ');
|
|
133
|
+
for (let index = 0; index < columnCount; index++) {
|
|
134
|
+
const column = document.createElement('div');
|
|
135
|
+
column.className = 'ov-doc-legacy-page-column';
|
|
136
|
+
columnsWrap.appendChild(column);
|
|
137
|
+
if (index < columnCount - 1) {
|
|
138
|
+
const gap = document.createElement('div');
|
|
139
|
+
gap.className = 'ov-doc-legacy-page-column-gap';
|
|
140
|
+
gap.setAttribute('aria-hidden', 'true');
|
|
141
|
+
columnsWrap.appendChild(gap);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
content.appendChild(columnsWrap);
|
|
145
|
+
}
|
|
146
|
+
pagesHost.appendChild(page);
|
|
147
|
+
createdPageCount += 1;
|
|
148
|
+
return {
|
|
149
|
+
content,
|
|
150
|
+
header,
|
|
151
|
+
footer,
|
|
152
|
+
page,
|
|
153
|
+
columns: hasColumns ? Array.from(content.querySelectorAll(':scope .ov-doc-legacy-page-column')) : [content],
|
|
154
|
+
activeColumnIndex: 0
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const pageHasContent = (page) => page.columns.some((column) => column.children.length > 0);
|
|
158
|
+
const getActiveColumn = (page) => page.columns[page.activeColumnIndex];
|
|
159
|
+
const doesColumnOverflow = (column) => (column.scrollHeight - column.clientHeight) > 1;
|
|
160
|
+
const getColumnRemainingHeight = (column) => Math.max(0, column.clientHeight - column.scrollHeight);
|
|
161
|
+
const ensureNewPage = () => createPageChrome();
|
|
162
|
+
const isTableBlock = (block) => block.classList.contains('ov-doc-legacy-block-table');
|
|
163
|
+
const isListBlock = (block) => (block.classList.contains('ov-doc-legacy-block-content')
|
|
164
|
+
&& !!block.querySelector(':scope > ul, :scope > ol'));
|
|
165
|
+
const isImageGalleryBlock = (block) => block.classList.contains('ov-doc-legacy-block-images');
|
|
166
|
+
const isSheetBlock = (block) => block.classList.contains('ov-doc-legacy-block-sheet');
|
|
167
|
+
const parseBlockMetric = (block, key) => Number.parseInt(block?.dataset?.[key] || '', 10) || 0;
|
|
168
|
+
const isMediaLikeKind = (kind) => ['table', 'sheet', 'image', 'images'].includes(kind);
|
|
169
|
+
const getBlockSemanticKind = (block) => block?.dataset?.ovSemanticKind || '';
|
|
170
|
+
const getBlockSemanticRole = (block) => block?.dataset?.ovSemanticRole || '';
|
|
171
|
+
const estimateListFragmentHeight = (itemCount) => 28 + Math.max(1, itemCount) * 24;
|
|
172
|
+
const estimateTableFragmentHeight = (totalRowCount, headerRowCount) => (32 + Math.max(1, headerRowCount) * 28 + Math.max(0, totalRowCount - headerRowCount) * 24);
|
|
173
|
+
const estimateImageFragmentHeight = (mediaCount) => (mediaCount <= 1 ? 260 : 120 + (Math.ceil(mediaCount / 2) * 180));
|
|
174
|
+
const estimateSheetFragmentHeight = (hasChart, rowCount) => 72 + (hasChart ? 180 : 0) + Math.max(0, rowCount) * 22;
|
|
175
|
+
const estimateGroupHeight = (candidateBlocks) => candidateBlocks.reduce((sum, block) => (sum + parseBlockMetric(block, 'ovEstimatedHeight')), 0);
|
|
176
|
+
const estimateMinimumFollowupHeight = (block) => {
|
|
177
|
+
if (!block) {
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
const explicitMinimum = parseBlockMetric(block, 'ovMinFragmentHeight');
|
|
181
|
+
if (explicitMinimum > 0) {
|
|
182
|
+
return explicitMinimum;
|
|
183
|
+
}
|
|
184
|
+
const semanticKind = getBlockSemanticKind(block);
|
|
185
|
+
const totalEstimate = parseBlockMetric(block, 'ovEstimatedHeight');
|
|
186
|
+
if (semanticKind === 'table') {
|
|
187
|
+
const rowCount = parseBlockMetric(block, 'ovRowCount');
|
|
188
|
+
const minRows = Math.min(rowCount, 3);
|
|
189
|
+
return minRows > 0 ? Math.min(totalEstimate, 44 + (minRows * 24)) : totalEstimate;
|
|
190
|
+
}
|
|
191
|
+
if (semanticKind === 'list') {
|
|
192
|
+
const itemCount = parseBlockMetric(block, 'ovItemCount');
|
|
193
|
+
const minItems = Math.min(itemCount, 2);
|
|
194
|
+
return minItems > 0 ? Math.min(totalEstimate, 24 + (minItems * 24)) : totalEstimate;
|
|
195
|
+
}
|
|
196
|
+
if (isMediaLikeKind(semanticKind)) {
|
|
197
|
+
return totalEstimate;
|
|
198
|
+
}
|
|
199
|
+
return 0;
|
|
200
|
+
};
|
|
201
|
+
const shouldPreflightMoveCompoundGroup = (column, candidateBlocks) => {
|
|
202
|
+
if (!column || column.children.length === 0 || candidateBlocks.length < 2) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const leadBlock = candidateBlocks[0];
|
|
206
|
+
const followBlock = candidateBlocks[1];
|
|
207
|
+
const leadKind = getBlockSemanticKind(leadBlock);
|
|
208
|
+
const leadRole = getBlockSemanticRole(leadBlock);
|
|
209
|
+
const leadTextLength = parseBlockMetric(leadBlock, 'ovTextLength');
|
|
210
|
+
const leadEstimate = parseBlockMetric(leadBlock, 'ovEstimatedHeight');
|
|
211
|
+
const minimumFollowupHeight = estimateMinimumFollowupHeight(followBlock);
|
|
212
|
+
if (leadEstimate <= 0 || minimumFollowupHeight <= 0) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
const isShortLeadContent = ((leadKind === 'content' && leadTextLength > 0 && leadTextLength <= 120)
|
|
216
|
+
|| leadRole === 'caption');
|
|
217
|
+
if (!isShortLeadContent) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
const remainingHeight = getColumnRemainingHeight(column);
|
|
221
|
+
const requiredHeight = leadEstimate + minimumFollowupHeight;
|
|
222
|
+
return requiredHeight > remainingHeight && requiredHeight <= (column.clientHeight * 0.9);
|
|
223
|
+
};
|
|
224
|
+
const shouldPreflightMoveGroup = (column, candidateBlocks) => {
|
|
225
|
+
if (!column || column.children.length === 0 || candidateBlocks.length === 0) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
const estimatedHeight = estimateGroupHeight(candidateBlocks);
|
|
229
|
+
if (estimatedHeight <= 0) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const remainingHeight = getColumnRemainingHeight(column);
|
|
233
|
+
return remainingHeight > 0 && estimatedHeight > remainingHeight && estimatedHeight <= (column.clientHeight * 0.92);
|
|
234
|
+
};
|
|
235
|
+
const shouldKeepWithFollowingBlock = (block, nextBlock) => {
|
|
236
|
+
if (!block || !nextBlock) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
if (block.dataset.ovKeepWithNext === 'true') {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
const semanticKind = block.dataset.ovSemanticKind || '';
|
|
243
|
+
const semanticTag = block.dataset.ovSemanticTag || '';
|
|
244
|
+
const semanticRole = block.dataset.ovSemanticRole || '';
|
|
245
|
+
const nextSemanticKind = nextBlock.dataset.ovSemanticKind || '';
|
|
246
|
+
const nextSemanticRole = nextBlock.dataset.ovSemanticRole || '';
|
|
247
|
+
const textLength = parseBlockMetric(block, 'ovTextLength');
|
|
248
|
+
const nextTextLength = parseBlockMetric(nextBlock, 'ovTextLength');
|
|
249
|
+
const itemCount = parseBlockMetric(block, 'ovItemCount');
|
|
250
|
+
const rowCount = parseBlockMetric(block, 'ovRowCount');
|
|
251
|
+
const hasInlineField = block.dataset.ovInlineField === 'true';
|
|
252
|
+
const hasInlineBreak = block.dataset.ovInlineBreak === 'true';
|
|
253
|
+
if (semanticKind === 'content' && (semanticTag === 'h1' || semanticTag === 'h2')) {
|
|
254
|
+
if (nextSemanticKind === 'content') {
|
|
255
|
+
return nextTextLength > 0 && nextTextLength <= 220;
|
|
256
|
+
}
|
|
257
|
+
return ['list', 'table', 'sheet', 'image', 'images'].includes(nextSemanticKind);
|
|
258
|
+
}
|
|
259
|
+
if (semanticRole === 'caption') {
|
|
260
|
+
return isMediaLikeKind(nextSemanticKind);
|
|
261
|
+
}
|
|
262
|
+
if (semanticRole === 'floating-media' || nextSemanticRole === 'floating-media') {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
if (isMediaLikeKind(semanticKind) && nextSemanticRole === 'caption') {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
if (semanticKind === 'content' && textLength > 0 && textLength <= 48 && nextSemanticKind === 'image') {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
if (semanticKind === 'content'
|
|
272
|
+
&& semanticTag === 'p'
|
|
273
|
+
&& !semanticRole
|
|
274
|
+
&& !hasInlineField
|
|
275
|
+
&& !hasInlineBreak
|
|
276
|
+
&& textLength > 0
|
|
277
|
+
&& textLength <= 96
|
|
278
|
+
&& ['list', 'table', 'image', 'images'].includes(nextSemanticKind)) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
if (semanticKind === 'list' && itemCount > 0 && itemCount <= 3 && isMediaLikeKind(nextSemanticKind)) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
if (semanticKind === 'table' && rowCount > 0 && rowCount <= 4 && nextSemanticRole === 'caption') {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
};
|
|
289
|
+
const moveToNextSlot = (page) => {
|
|
290
|
+
if (page.activeColumnIndex < page.columns.length - 1) {
|
|
291
|
+
page.activeColumnIndex += 1;
|
|
292
|
+
return page;
|
|
293
|
+
}
|
|
294
|
+
return ensureNewPage();
|
|
295
|
+
};
|
|
296
|
+
const createTableFragmentBlock = (sourceBlock, headerRows, bodyRows, keepPageBreakBefore) => {
|
|
297
|
+
const fragmentBlock = sourceBlock.cloneNode(true);
|
|
298
|
+
const table = fragmentBlock.querySelector('table');
|
|
299
|
+
const thead = table?.querySelector('thead');
|
|
300
|
+
const tbody = table?.querySelector('tbody');
|
|
301
|
+
if (!table || !tbody) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
if (thead) {
|
|
305
|
+
thead.innerHTML = '';
|
|
306
|
+
}
|
|
307
|
+
tbody.innerHTML = '';
|
|
308
|
+
headerRows.forEach((row) => {
|
|
309
|
+
if (thead) {
|
|
310
|
+
thead.appendChild(row.cloneNode(true));
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
tbody.appendChild(row.cloneNode(true));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
if (!thead && headerRows.length > 0) {
|
|
317
|
+
fragmentBlock.dataset.ovSyntheticHeaderRows = String(headerRows.length);
|
|
318
|
+
}
|
|
319
|
+
bodyRows.forEach((row) => tbody.appendChild(row.cloneNode(true)));
|
|
320
|
+
if (!keepPageBreakBefore) {
|
|
321
|
+
fragmentBlock.removeAttribute('data-ov-page-break-before');
|
|
322
|
+
}
|
|
323
|
+
fragmentBlock.dataset.ovTableFragment = 'true';
|
|
324
|
+
fragmentBlock.dataset.ovRowCount = String(headerRows.length + bodyRows.length);
|
|
325
|
+
fragmentBlock.dataset.ovEstimatedHeight = String(estimateTableFragmentHeight(headerRows.length + bodyRows.length, headerRows.length));
|
|
326
|
+
return fragmentBlock;
|
|
327
|
+
};
|
|
328
|
+
const splitTableBlockAcrossSlots = (sourceBlock) => {
|
|
329
|
+
const wrapper = sourceBlock.querySelector('.ov-doc-legacy-table');
|
|
330
|
+
const sourceTable = sourceBlock.querySelector('table');
|
|
331
|
+
const sourceHead = sourceTable?.querySelector('thead');
|
|
332
|
+
const sourceBody = sourceTable?.querySelector('tbody');
|
|
333
|
+
if (!sourceTable || !sourceBody) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
let headerRows = sourceHead
|
|
337
|
+
? Array.from(sourceHead.querySelectorAll(':scope > tr'))
|
|
338
|
+
: [];
|
|
339
|
+
if (!sourceHead && headerRows.length === 0) {
|
|
340
|
+
const headerRowCount = Number.parseInt(wrapper?.dataset.ovTableHeaderRows || '0', 10) || 0;
|
|
341
|
+
if (headerRowCount > 0) {
|
|
342
|
+
const bodyRows = Array.from(sourceBody.querySelectorAll(':scope > tr'));
|
|
343
|
+
headerRows = bodyRows.slice(0, headerRowCount);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const dataRows = Array.from(sourceBody.querySelectorAll(':scope > tr'));
|
|
347
|
+
if (dataRows.length < 1) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
let page = currentPage;
|
|
351
|
+
let column = getActiveColumn(page);
|
|
352
|
+
if (sourceBlock.parentNode === column) {
|
|
353
|
+
column.removeChild(sourceBlock);
|
|
354
|
+
}
|
|
355
|
+
if (column.children.length > 0) {
|
|
356
|
+
page = moveToNextSlot(page);
|
|
357
|
+
column = getActiveColumn(page);
|
|
358
|
+
}
|
|
359
|
+
let rowIndex = 0;
|
|
360
|
+
let firstFragment = true;
|
|
361
|
+
while (rowIndex < dataRows.length) {
|
|
362
|
+
const fragmentStartIndex = rowIndex;
|
|
363
|
+
const fragmentRows = [];
|
|
364
|
+
let fragmentBlock = null;
|
|
365
|
+
let retriedSingleRowFragment = false;
|
|
366
|
+
while (true) {
|
|
367
|
+
while (rowIndex < dataRows.length) {
|
|
368
|
+
fragmentRows.push(dataRows[rowIndex]);
|
|
369
|
+
const nextFragment = createTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
370
|
+
if (!nextFragment) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
if (fragmentBlock && fragmentBlock.parentNode === column) {
|
|
374
|
+
column.removeChild(fragmentBlock);
|
|
375
|
+
}
|
|
376
|
+
fragmentBlock = nextFragment;
|
|
377
|
+
column.appendChild(fragmentBlock);
|
|
378
|
+
if (doesColumnOverflow(column)) {
|
|
379
|
+
column.removeChild(fragmentBlock);
|
|
380
|
+
fragmentBlock = null;
|
|
381
|
+
if (fragmentRows.length === 1) {
|
|
382
|
+
const forcedFragment = createTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
383
|
+
if (!forcedFragment) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
forcedFragment.classList.add('ov-doc-legacy-block-overflow');
|
|
387
|
+
column.appendChild(forcedFragment);
|
|
388
|
+
fragmentBlock = forcedFragment;
|
|
389
|
+
rowIndex += 1;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
fragmentRows.pop();
|
|
393
|
+
const fittedFragment = createTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
394
|
+
if (!fittedFragment) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
column.appendChild(fittedFragment);
|
|
398
|
+
fragmentBlock = fittedFragment;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
rowIndex += 1;
|
|
402
|
+
}
|
|
403
|
+
const remainingRows = dataRows.length - rowIndex;
|
|
404
|
+
const singleRowFragment = fragmentRows.length === 1;
|
|
405
|
+
if (fragmentBlock
|
|
406
|
+
&& !fragmentBlock.classList.contains('ov-doc-legacy-block-overflow')
|
|
407
|
+
&& singleRowFragment
|
|
408
|
+
&& remainingRows > 0
|
|
409
|
+
&& !retriedSingleRowFragment) {
|
|
410
|
+
if (fragmentBlock.parentNode === column) {
|
|
411
|
+
column.removeChild(fragmentBlock);
|
|
412
|
+
}
|
|
413
|
+
fragmentRows.length = 0;
|
|
414
|
+
fragmentBlock = null;
|
|
415
|
+
rowIndex = fragmentStartIndex;
|
|
416
|
+
retriedSingleRowFragment = true;
|
|
417
|
+
page = moveToNextSlot(page);
|
|
418
|
+
column = getActiveColumn(page);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
if (!fragmentBlock) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
firstFragment = false;
|
|
427
|
+
if (rowIndex < dataRows.length) {
|
|
428
|
+
page = moveToNextSlot(page);
|
|
429
|
+
column = getActiveColumn(page);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
currentPage = page;
|
|
433
|
+
return true;
|
|
434
|
+
};
|
|
435
|
+
const createListFragmentBlock = (sourceBlock, items, keepPageBreakBefore) => {
|
|
436
|
+
const fragmentBlock = sourceBlock.cloneNode(true);
|
|
437
|
+
const list = fragmentBlock.querySelector(':scope > ul, :scope > ol');
|
|
438
|
+
if (!list) {
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
list.innerHTML = '';
|
|
442
|
+
items.forEach((item) => list.appendChild(item.cloneNode(true)));
|
|
443
|
+
if (!keepPageBreakBefore) {
|
|
444
|
+
fragmentBlock.removeAttribute('data-ov-page-break-before');
|
|
445
|
+
}
|
|
446
|
+
fragmentBlock.dataset.ovListFragment = 'true';
|
|
447
|
+
fragmentBlock.dataset.ovItemCount = String(items.length);
|
|
448
|
+
fragmentBlock.dataset.ovEstimatedHeight = String(estimateListFragmentHeight(items.length));
|
|
449
|
+
return fragmentBlock;
|
|
450
|
+
};
|
|
451
|
+
const splitListBlockAcrossSlots = (sourceBlock) => {
|
|
452
|
+
const sourceList = sourceBlock.querySelector(':scope > ul, :scope > ol');
|
|
453
|
+
if (!sourceList) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
const items = Array.from(sourceList.querySelectorAll(':scope > li'));
|
|
457
|
+
if (items.length < 2) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
let page = currentPage;
|
|
461
|
+
let column = getActiveColumn(page);
|
|
462
|
+
if (sourceBlock.parentNode === column) {
|
|
463
|
+
column.removeChild(sourceBlock);
|
|
464
|
+
}
|
|
465
|
+
if (column.children.length > 0) {
|
|
466
|
+
page = moveToNextSlot(page);
|
|
467
|
+
column = getActiveColumn(page);
|
|
468
|
+
}
|
|
469
|
+
let itemIndex = 0;
|
|
470
|
+
let firstFragment = true;
|
|
471
|
+
while (itemIndex < items.length) {
|
|
472
|
+
const fragmentStartIndex = itemIndex;
|
|
473
|
+
const fragmentItems = [];
|
|
474
|
+
let fragmentBlock = null;
|
|
475
|
+
let retriedSingleItemFragment = false;
|
|
476
|
+
while (true) {
|
|
477
|
+
while (itemIndex < items.length) {
|
|
478
|
+
fragmentItems.push(items[itemIndex]);
|
|
479
|
+
const nextFragment = createListFragmentBlock(sourceBlock, fragmentItems, firstFragment);
|
|
480
|
+
if (!nextFragment) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
if (fragmentBlock && fragmentBlock.parentNode === column) {
|
|
484
|
+
column.removeChild(fragmentBlock);
|
|
485
|
+
}
|
|
486
|
+
fragmentBlock = nextFragment;
|
|
487
|
+
column.appendChild(fragmentBlock);
|
|
488
|
+
if (doesColumnOverflow(column)) {
|
|
489
|
+
column.removeChild(fragmentBlock);
|
|
490
|
+
fragmentBlock = null;
|
|
491
|
+
if (fragmentItems.length === 1) {
|
|
492
|
+
const forcedFragment = createListFragmentBlock(sourceBlock, fragmentItems, firstFragment);
|
|
493
|
+
if (!forcedFragment) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
forcedFragment.classList.add('ov-doc-legacy-block-overflow');
|
|
497
|
+
column.appendChild(forcedFragment);
|
|
498
|
+
fragmentBlock = forcedFragment;
|
|
499
|
+
itemIndex += 1;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
fragmentItems.pop();
|
|
503
|
+
const fittedFragment = createListFragmentBlock(sourceBlock, fragmentItems, firstFragment);
|
|
504
|
+
if (!fittedFragment) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
column.appendChild(fittedFragment);
|
|
508
|
+
fragmentBlock = fittedFragment;
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
itemIndex += 1;
|
|
512
|
+
}
|
|
513
|
+
const remainingItems = items.length - itemIndex;
|
|
514
|
+
const singleItemFragment = fragmentItems.length === 1;
|
|
515
|
+
if (fragmentBlock
|
|
516
|
+
&& !fragmentBlock.classList.contains('ov-doc-legacy-block-overflow')
|
|
517
|
+
&& singleItemFragment
|
|
518
|
+
&& remainingItems > 0
|
|
519
|
+
&& !retriedSingleItemFragment) {
|
|
520
|
+
if (fragmentBlock.parentNode === column) {
|
|
521
|
+
column.removeChild(fragmentBlock);
|
|
522
|
+
}
|
|
523
|
+
fragmentItems.length = 0;
|
|
524
|
+
fragmentBlock = null;
|
|
525
|
+
itemIndex = fragmentStartIndex;
|
|
526
|
+
retriedSingleItemFragment = true;
|
|
527
|
+
page = moveToNextSlot(page);
|
|
528
|
+
column = getActiveColumn(page);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
if (!fragmentBlock) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
firstFragment = false;
|
|
537
|
+
if (itemIndex < items.length) {
|
|
538
|
+
page = moveToNextSlot(page);
|
|
539
|
+
column = getActiveColumn(page);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
currentPage = page;
|
|
543
|
+
return true;
|
|
544
|
+
};
|
|
545
|
+
const createImageGalleryFragmentBlock = (sourceBlock, figures, keepPageBreakBefore) => {
|
|
546
|
+
const fragmentBlock = sourceBlock.cloneNode(true);
|
|
547
|
+
const grid = fragmentBlock.querySelector('.ov-doc-legacy-image-grid');
|
|
548
|
+
const title = fragmentBlock.querySelector(':scope > h2');
|
|
549
|
+
if (!grid) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
grid.innerHTML = '';
|
|
553
|
+
figures.forEach((figure) => grid.appendChild(figure.cloneNode(true)));
|
|
554
|
+
if (title) {
|
|
555
|
+
title.hidden = figures.length <= 1;
|
|
556
|
+
}
|
|
557
|
+
if (!keepPageBreakBefore) {
|
|
558
|
+
fragmentBlock.removeAttribute('data-ov-page-break-before');
|
|
559
|
+
}
|
|
560
|
+
fragmentBlock.dataset.ovImageFragment = 'true';
|
|
561
|
+
fragmentBlock.dataset.ovMediaCount = String(figures.length);
|
|
562
|
+
fragmentBlock.dataset.ovEstimatedHeight = String(estimateImageFragmentHeight(figures.length));
|
|
563
|
+
fragmentBlock.dataset.ovMinFragmentHeight = String(estimateImageFragmentHeight(Math.min(figures.length, 2)));
|
|
564
|
+
return fragmentBlock;
|
|
565
|
+
};
|
|
566
|
+
const splitImageGalleryBlockAcrossSlots = (sourceBlock) => {
|
|
567
|
+
const grid = sourceBlock.querySelector('.ov-doc-legacy-image-grid');
|
|
568
|
+
if (!grid) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
const figures = Array.from(grid.querySelectorAll(':scope > figure'));
|
|
572
|
+
if (figures.length < 2) {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
let page = currentPage;
|
|
576
|
+
let column = getActiveColumn(page);
|
|
577
|
+
if (sourceBlock.parentNode === column) {
|
|
578
|
+
column.removeChild(sourceBlock);
|
|
579
|
+
}
|
|
580
|
+
if (column.children.length > 0) {
|
|
581
|
+
page = moveToNextSlot(page);
|
|
582
|
+
column = getActiveColumn(page);
|
|
583
|
+
}
|
|
584
|
+
let figureIndex = 0;
|
|
585
|
+
let firstFragment = true;
|
|
586
|
+
while (figureIndex < figures.length) {
|
|
587
|
+
const fragmentStartIndex = figureIndex;
|
|
588
|
+
const fragmentFigures = [];
|
|
589
|
+
let fragmentBlock = null;
|
|
590
|
+
let retriedSingleFigureFragment = false;
|
|
591
|
+
while (true) {
|
|
592
|
+
while (figureIndex < figures.length) {
|
|
593
|
+
fragmentFigures.push(figures[figureIndex]);
|
|
594
|
+
const nextFragment = createImageGalleryFragmentBlock(sourceBlock, fragmentFigures, firstFragment);
|
|
595
|
+
if (!nextFragment) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
if (fragmentBlock && fragmentBlock.parentNode === column) {
|
|
599
|
+
column.removeChild(fragmentBlock);
|
|
600
|
+
}
|
|
601
|
+
fragmentBlock = nextFragment;
|
|
602
|
+
column.appendChild(fragmentBlock);
|
|
603
|
+
if (doesColumnOverflow(column)) {
|
|
604
|
+
column.removeChild(fragmentBlock);
|
|
605
|
+
fragmentBlock = null;
|
|
606
|
+
if (fragmentFigures.length === 1) {
|
|
607
|
+
const forcedFragment = createImageGalleryFragmentBlock(sourceBlock, fragmentFigures, firstFragment);
|
|
608
|
+
if (!forcedFragment) {
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
forcedFragment.classList.add('ov-doc-legacy-block-overflow');
|
|
612
|
+
column.appendChild(forcedFragment);
|
|
613
|
+
fragmentBlock = forcedFragment;
|
|
614
|
+
figureIndex += 1;
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
fragmentFigures.pop();
|
|
618
|
+
const fittedFragment = createImageGalleryFragmentBlock(sourceBlock, fragmentFigures, firstFragment);
|
|
619
|
+
if (!fittedFragment) {
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
column.appendChild(fittedFragment);
|
|
623
|
+
fragmentBlock = fittedFragment;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
figureIndex += 1;
|
|
627
|
+
}
|
|
628
|
+
const remainingFigures = figures.length - figureIndex;
|
|
629
|
+
const singleFigureFragment = fragmentFigures.length === 1;
|
|
630
|
+
if (fragmentBlock
|
|
631
|
+
&& !fragmentBlock.classList.contains('ov-doc-legacy-block-overflow')
|
|
632
|
+
&& singleFigureFragment
|
|
633
|
+
&& remainingFigures > 0
|
|
634
|
+
&& !retriedSingleFigureFragment) {
|
|
635
|
+
if (fragmentBlock.parentNode === column) {
|
|
636
|
+
column.removeChild(fragmentBlock);
|
|
637
|
+
}
|
|
638
|
+
fragmentFigures.length = 0;
|
|
639
|
+
fragmentBlock = null;
|
|
640
|
+
figureIndex = fragmentStartIndex;
|
|
641
|
+
retriedSingleFigureFragment = true;
|
|
642
|
+
page = moveToNextSlot(page);
|
|
643
|
+
column = getActiveColumn(page);
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
if (!fragmentBlock) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
firstFragment = false;
|
|
652
|
+
if (figureIndex < figures.length) {
|
|
653
|
+
page = moveToNextSlot(page);
|
|
654
|
+
column = getActiveColumn(page);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
currentPage = page;
|
|
658
|
+
return true;
|
|
659
|
+
};
|
|
660
|
+
const createSheetFragmentBlock = (sourceBlock, options) => {
|
|
661
|
+
const fragmentBlock = sourceBlock.cloneNode(true);
|
|
662
|
+
const chart = fragmentBlock.querySelector('.ov-doc-embedded-chart');
|
|
663
|
+
const tableWrap = fragmentBlock.querySelector('.ov-doc-embedded-table-wrap');
|
|
664
|
+
const rowCount = options.rowCount || 0;
|
|
665
|
+
if (chart) {
|
|
666
|
+
chart.hidden = !options.includeChart;
|
|
667
|
+
}
|
|
668
|
+
if (tableWrap) {
|
|
669
|
+
tableWrap.hidden = !options.includeTable;
|
|
670
|
+
}
|
|
671
|
+
if (!options.keepPageBreakBefore) {
|
|
672
|
+
fragmentBlock.removeAttribute('data-ov-page-break-before');
|
|
673
|
+
}
|
|
674
|
+
fragmentBlock.dataset.ovSheetFragment = 'true';
|
|
675
|
+
fragmentBlock.dataset.ovRowCount = String(rowCount);
|
|
676
|
+
fragmentBlock.dataset.ovEstimatedHeight = String(estimateSheetFragmentHeight(!!options.includeChart, rowCount));
|
|
677
|
+
fragmentBlock.dataset.ovMinFragmentHeight = String(estimateSheetFragmentHeight(!!options.includeChart, Math.min(rowCount, 3)));
|
|
678
|
+
return fragmentBlock;
|
|
679
|
+
};
|
|
680
|
+
const createSheetTableFragmentBlock = (sourceBlock, headerRows, bodyRows, keepPageBreakBefore) => {
|
|
681
|
+
const fragmentBlock = createSheetFragmentBlock(sourceBlock, {
|
|
682
|
+
includeChart: false,
|
|
683
|
+
includeTable: true,
|
|
684
|
+
rowCount: headerRows.length + bodyRows.length,
|
|
685
|
+
keepPageBreakBefore
|
|
686
|
+
});
|
|
687
|
+
const table = fragmentBlock?.querySelector('.ov-doc-embedded-table-wrap table');
|
|
688
|
+
const thead = table?.querySelector('thead');
|
|
689
|
+
const tbody = table?.querySelector('tbody');
|
|
690
|
+
if (!fragmentBlock || !table || !tbody) {
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
if (thead) {
|
|
694
|
+
thead.innerHTML = '';
|
|
695
|
+
headerRows.forEach((row) => thead.appendChild(row.cloneNode(true)));
|
|
696
|
+
}
|
|
697
|
+
tbody.innerHTML = '';
|
|
698
|
+
bodyRows.forEach((row) => tbody.appendChild(row.cloneNode(true)));
|
|
699
|
+
fragmentBlock.dataset.ovSheetTableFragment = 'true';
|
|
700
|
+
fragmentBlock.dataset.ovRowCount = String(headerRows.length + bodyRows.length);
|
|
701
|
+
fragmentBlock.dataset.ovEstimatedHeight = String(estimateSheetFragmentHeight(false, headerRows.length + bodyRows.length));
|
|
702
|
+
fragmentBlock.dataset.ovMinFragmentHeight = String(estimateSheetFragmentHeight(false, Math.min(headerRows.length + bodyRows.length, 3)));
|
|
703
|
+
return fragmentBlock;
|
|
704
|
+
};
|
|
705
|
+
const splitSheetTableAcrossSlots = (sourceBlock, startPage, includeChartFirst) => {
|
|
706
|
+
const table = sourceBlock.querySelector('.ov-doc-embedded-table-wrap table');
|
|
707
|
+
const thead = table?.querySelector('thead');
|
|
708
|
+
const tbody = table?.querySelector('tbody');
|
|
709
|
+
if (!table || !tbody) {
|
|
710
|
+
return { success: false, page: startPage };
|
|
711
|
+
}
|
|
712
|
+
const headerRows = thead
|
|
713
|
+
? Array.from(thead.querySelectorAll(':scope > tr'))
|
|
714
|
+
: [];
|
|
715
|
+
const dataRows = Array.from(tbody.querySelectorAll(':scope > tr'));
|
|
716
|
+
if (dataRows.length < 1) {
|
|
717
|
+
return { success: false, page: startPage };
|
|
718
|
+
}
|
|
719
|
+
let page = startPage;
|
|
720
|
+
let column = getActiveColumn(page);
|
|
721
|
+
let rowIndex = 0;
|
|
722
|
+
let firstFragment = includeChartFirst;
|
|
723
|
+
while (rowIndex < dataRows.length) {
|
|
724
|
+
const fragmentStartIndex = rowIndex;
|
|
725
|
+
const fragmentRows = [];
|
|
726
|
+
let fragmentBlock = null;
|
|
727
|
+
let retriedSingleRowFragment = false;
|
|
728
|
+
while (true) {
|
|
729
|
+
while (rowIndex < dataRows.length) {
|
|
730
|
+
fragmentRows.push(dataRows[rowIndex]);
|
|
731
|
+
const nextFragment = createSheetTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
732
|
+
if (!nextFragment) {
|
|
733
|
+
return { success: false, page };
|
|
734
|
+
}
|
|
735
|
+
if (fragmentBlock && fragmentBlock.parentNode === column) {
|
|
736
|
+
column.removeChild(fragmentBlock);
|
|
737
|
+
}
|
|
738
|
+
fragmentBlock = nextFragment;
|
|
739
|
+
column.appendChild(fragmentBlock);
|
|
740
|
+
if (doesColumnOverflow(column)) {
|
|
741
|
+
column.removeChild(fragmentBlock);
|
|
742
|
+
fragmentBlock = null;
|
|
743
|
+
if (fragmentRows.length === 1) {
|
|
744
|
+
const forcedFragment = createSheetTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
745
|
+
if (!forcedFragment) {
|
|
746
|
+
return { success: false, page };
|
|
747
|
+
}
|
|
748
|
+
forcedFragment.classList.add('ov-doc-legacy-block-overflow');
|
|
749
|
+
column.appendChild(forcedFragment);
|
|
750
|
+
fragmentBlock = forcedFragment;
|
|
751
|
+
rowIndex += 1;
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
fragmentRows.pop();
|
|
755
|
+
const fittedFragment = createSheetTableFragmentBlock(sourceBlock, headerRows, fragmentRows, firstFragment);
|
|
756
|
+
if (!fittedFragment) {
|
|
757
|
+
return { success: false, page };
|
|
758
|
+
}
|
|
759
|
+
column.appendChild(fittedFragment);
|
|
760
|
+
fragmentBlock = fittedFragment;
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
rowIndex += 1;
|
|
764
|
+
}
|
|
765
|
+
const remainingRows = dataRows.length - rowIndex;
|
|
766
|
+
const singleRowFragment = fragmentRows.length === 1;
|
|
767
|
+
if (fragmentBlock
|
|
768
|
+
&& !fragmentBlock.classList.contains('ov-doc-legacy-block-overflow')
|
|
769
|
+
&& singleRowFragment
|
|
770
|
+
&& remainingRows > 0
|
|
771
|
+
&& !retriedSingleRowFragment) {
|
|
772
|
+
if (fragmentBlock.parentNode === column) {
|
|
773
|
+
column.removeChild(fragmentBlock);
|
|
774
|
+
}
|
|
775
|
+
fragmentRows.length = 0;
|
|
776
|
+
fragmentBlock = null;
|
|
777
|
+
rowIndex = fragmentStartIndex;
|
|
778
|
+
retriedSingleRowFragment = true;
|
|
779
|
+
page = moveToNextSlot(page);
|
|
780
|
+
column = getActiveColumn(page);
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
if (!fragmentBlock) {
|
|
786
|
+
return { success: false, page };
|
|
787
|
+
}
|
|
788
|
+
firstFragment = false;
|
|
789
|
+
if (rowIndex < dataRows.length) {
|
|
790
|
+
page = moveToNextSlot(page);
|
|
791
|
+
column = getActiveColumn(page);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return { success: true, page };
|
|
795
|
+
};
|
|
796
|
+
const splitSheetBlockAcrossSlots = (sourceBlock) => {
|
|
797
|
+
const chart = sourceBlock.querySelector('.ov-doc-embedded-chart');
|
|
798
|
+
const tableWrap = sourceBlock.querySelector('.ov-doc-embedded-table-wrap');
|
|
799
|
+
if (!chart || !tableWrap) {
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
const rowCount = parseBlockMetric(sourceBlock, 'ovRowCount');
|
|
803
|
+
let page = currentPage;
|
|
804
|
+
let column = getActiveColumn(page);
|
|
805
|
+
if (sourceBlock.parentNode === column) {
|
|
806
|
+
column.removeChild(sourceBlock);
|
|
807
|
+
}
|
|
808
|
+
const chartFragment = createSheetFragmentBlock(sourceBlock, {
|
|
809
|
+
includeChart: true,
|
|
810
|
+
includeTable: false,
|
|
811
|
+
rowCount: 0,
|
|
812
|
+
keepPageBreakBefore: true
|
|
813
|
+
});
|
|
814
|
+
const tableFragment = createSheetFragmentBlock(sourceBlock, {
|
|
815
|
+
includeChart: false,
|
|
816
|
+
includeTable: true,
|
|
817
|
+
rowCount,
|
|
818
|
+
keepPageBreakBefore: false
|
|
819
|
+
});
|
|
820
|
+
if (!chartFragment || !tableFragment) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
column.appendChild(chartFragment);
|
|
824
|
+
if (doesColumnOverflow(column)) {
|
|
825
|
+
column.removeChild(chartFragment);
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
const splitResult = splitSheetTableAcrossSlots(sourceBlock, page, false);
|
|
829
|
+
if (splitResult.success) {
|
|
830
|
+
currentPage = splitResult.page;
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
column.appendChild(tableFragment);
|
|
834
|
+
if (doesColumnOverflow(column)) {
|
|
835
|
+
column.removeChild(tableFragment);
|
|
836
|
+
page = moveToNextSlot(page);
|
|
837
|
+
column = getActiveColumn(page);
|
|
838
|
+
column.appendChild(tableFragment);
|
|
839
|
+
if (doesColumnOverflow(column)) {
|
|
840
|
+
if (tableFragment.parentNode === column) {
|
|
841
|
+
column.removeChild(tableFragment);
|
|
842
|
+
}
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
currentPage = page;
|
|
847
|
+
return true;
|
|
848
|
+
};
|
|
849
|
+
const placeBlocks = (candidateBlocks) => {
|
|
850
|
+
let page = currentPage;
|
|
851
|
+
let column = getActiveColumn(page);
|
|
852
|
+
while (candidateBlocks.some((block) => block.dataset.ovPageBreakBefore === 'true') && pageHasContent(page)) {
|
|
853
|
+
page = ensureNewPage();
|
|
854
|
+
column = getActiveColumn(page);
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
if (shouldPreflightMoveCompoundGroup(column, candidateBlocks) || shouldPreflightMoveGroup(column, candidateBlocks)) {
|
|
858
|
+
page = moveToNextSlot(page);
|
|
859
|
+
column = getActiveColumn(page);
|
|
860
|
+
}
|
|
861
|
+
for (const block of candidateBlocks) {
|
|
862
|
+
column.appendChild(block);
|
|
863
|
+
}
|
|
864
|
+
while (doesColumnOverflow(column)) {
|
|
865
|
+
candidateBlocks.forEach((block) => {
|
|
866
|
+
if (block.parentNode === column) {
|
|
867
|
+
column.removeChild(block);
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
const nextPage = moveToNextSlot(page);
|
|
871
|
+
if (nextPage === page && getActiveColumn(nextPage) === column) {
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
page = nextPage;
|
|
875
|
+
column = getActiveColumn(page);
|
|
876
|
+
candidateBlocks.forEach((block) => column.appendChild(block));
|
|
877
|
+
if (candidateBlocks.length === 1 && isTableBlock(candidateBlocks[0])) {
|
|
878
|
+
const didSplit = splitTableBlockAcrossSlots(candidateBlocks[0]);
|
|
879
|
+
if (didSplit) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (candidateBlocks.length === 1 && isListBlock(candidateBlocks[0])) {
|
|
884
|
+
const didSplit = splitListBlockAcrossSlots(candidateBlocks[0]);
|
|
885
|
+
if (didSplit) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
if (candidateBlocks.length === 1 && isImageGalleryBlock(candidateBlocks[0])) {
|
|
890
|
+
const didSplit = splitImageGalleryBlockAcrossSlots(candidateBlocks[0]);
|
|
891
|
+
if (didSplit) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (candidateBlocks.length === 1 && isSheetBlock(candidateBlocks[0])) {
|
|
896
|
+
const didSplit = splitSheetBlockAcrossSlots(candidateBlocks[0]);
|
|
897
|
+
if (didSplit) {
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (doesColumnOverflow(column) && candidateBlocks.length === 1 && column.children.length === 1) {
|
|
902
|
+
candidateBlocks[0].classList.add('ov-doc-legacy-block-overflow');
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
currentPage = page;
|
|
907
|
+
};
|
|
908
|
+
const collectKeepTogetherBlocks = (startIndex) => {
|
|
909
|
+
const grouped = [blocks[startIndex]];
|
|
910
|
+
let nextIndex = startIndex + 1;
|
|
911
|
+
while (nextIndex < blocks.length && shouldKeepWithFollowingBlock(grouped[grouped.length - 1], blocks[nextIndex])) {
|
|
912
|
+
grouped.push(blocks[nextIndex]);
|
|
913
|
+
nextIndex += 1;
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
grouped,
|
|
917
|
+
nextIndex
|
|
918
|
+
};
|
|
919
|
+
};
|
|
920
|
+
let currentPage = createPageChrome();
|
|
921
|
+
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
|
|
922
|
+
const { grouped, nextIndex } = collectKeepTogetherBlocks(blockIndex);
|
|
923
|
+
placeBlocks(grouped);
|
|
924
|
+
blockIndex = nextIndex - 1;
|
|
925
|
+
}
|
|
926
|
+
paginatedSections.push({ section, sectionMeta, pagesHost });
|
|
927
|
+
}
|
|
928
|
+
const totalDocumentPages = paginatedSections.reduce((sum, entry) => sum + entry.pagesHost.children.length, 0);
|
|
929
|
+
let globalPageNumber = 0;
|
|
930
|
+
for (const entry of paginatedSections) {
|
|
931
|
+
const sectionPageCount = entry.pagesHost.children.length;
|
|
932
|
+
Array.from(entry.pagesHost.children).forEach((pageNode, index) => {
|
|
933
|
+
const sectionPageNumber = index + 1;
|
|
934
|
+
globalPageNumber += 1;
|
|
935
|
+
const headerNode = pageNode.querySelector('.ov-doc-legacy-page-header');
|
|
936
|
+
const footerNode = pageNode.querySelector('.ov-doc-legacy-page-footer');
|
|
937
|
+
if (headerNode) {
|
|
938
|
+
headerNode.textContent = resolveHeaderFooterText(entry.sectionMeta, 'header', globalPageNumber, totalDocumentPages, sectionPageNumber, sectionPageCount);
|
|
939
|
+
}
|
|
940
|
+
if (footerNode) {
|
|
941
|
+
footerNode.textContent = resolveHeaderFooterText(entry.sectionMeta, 'footer', globalPageNumber, totalDocumentPages, sectionPageNumber, sectionPageCount);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
legacyRoot.dataset.ovPaginated = 'true';
|
|
946
|
+
}
|
|
947
|
+
function resolveHeaderFooterText(meta, type, pageNumber, totalPages, sectionPageNumber, sectionPageCount) {
|
|
948
|
+
const sourceText = getHeaderFooterSourceText(meta, type, pageNumber, sectionPageNumber);
|
|
949
|
+
return renderHeaderFooterFields(sourceText, pageNumber, totalPages, sectionPageNumber, sectionPageCount, meta);
|
|
950
|
+
}
|
|
951
|
+
function getHeaderFooterCandidateTexts(meta, type, sectionPageNumber) {
|
|
952
|
+
if (!meta || typeof meta !== 'object') {
|
|
953
|
+
return [];
|
|
954
|
+
}
|
|
955
|
+
const firstKey = type === 'header' ? 'firstHeaderText' : 'firstFooterText';
|
|
956
|
+
const evenKey = type === 'header' ? 'evenHeaderText' : 'evenFooterText';
|
|
957
|
+
const oddKey = type === 'header' ? 'oddHeaderText' : 'oddFooterText';
|
|
958
|
+
const candidates = [];
|
|
959
|
+
const seen = new Set();
|
|
960
|
+
if (sectionPageNumber === 1) {
|
|
961
|
+
const firstValue = typeof meta[firstKey] === 'string' ? meta[firstKey].trim() : '';
|
|
962
|
+
if (firstValue) {
|
|
963
|
+
seen.add(firstValue);
|
|
964
|
+
candidates.push(firstValue);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
[oddKey, evenKey].forEach((key) => {
|
|
968
|
+
const value = typeof meta[key] === 'string' ? meta[key].trim() : '';
|
|
969
|
+
if (value && !seen.has(value)) {
|
|
970
|
+
seen.add(value);
|
|
971
|
+
candidates.push(value);
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
return candidates;
|
|
975
|
+
}
|
|
976
|
+
function getHeaderFooterSourceText(meta, type, pageNumber, sectionPageNumber) {
|
|
977
|
+
if (!meta || typeof meta !== 'object') {
|
|
978
|
+
return '';
|
|
979
|
+
}
|
|
980
|
+
const isFirstPage = sectionPageNumber === 1;
|
|
981
|
+
const isEvenPage = pageNumber % 2 === 0;
|
|
982
|
+
const firstKey = type === 'header' ? 'firstHeaderText' : 'firstFooterText';
|
|
983
|
+
const evenKey = type === 'header' ? 'evenHeaderText' : 'evenFooterText';
|
|
984
|
+
const oddKey = type === 'header' ? 'oddHeaderText' : 'oddFooterText';
|
|
985
|
+
return ((isFirstPage && typeof meta[firstKey] === 'string' && meta[firstKey].trim() && meta[firstKey])
|
|
986
|
+
|| (isEvenPage && typeof meta[evenKey] === 'string' && meta[evenKey].trim() && meta[evenKey])
|
|
987
|
+
|| (typeof meta[oddKey] === 'string' && meta[oddKey].trim() && meta[oddKey])
|
|
988
|
+
|| (typeof meta[evenKey] === 'string' && meta[evenKey].trim() && meta[evenKey])
|
|
989
|
+
|| '');
|
|
990
|
+
}
|
|
991
|
+
function estimateHeaderFooterReserveMm(textOrCandidates, fallbackMm) {
|
|
992
|
+
const safeFallback = Number.isFinite(fallbackMm) && fallbackMm > 0 ? fallbackMm : 0;
|
|
993
|
+
const candidates = Array.isArray(textOrCandidates)
|
|
994
|
+
? textOrCandidates
|
|
995
|
+
: [textOrCandidates];
|
|
996
|
+
const normalizedCandidates = candidates
|
|
997
|
+
.map((value) => String(value || '').trim())
|
|
998
|
+
.filter((value) => value.length > 0);
|
|
999
|
+
if (normalizedCandidates.length === 0) {
|
|
1000
|
+
return 0;
|
|
1001
|
+
}
|
|
1002
|
+
const estimatedMm = normalizedCandidates.reduce((maxMm, normalized) => {
|
|
1003
|
+
const explicitLines = normalized.split(/\r?\n/).length;
|
|
1004
|
+
const estimatedWrappedLines = Math.max(explicitLines, Math.ceil(normalized.length / 48));
|
|
1005
|
+
return Math.max(maxMm, 2.5 + (estimatedWrappedLines * 4.8));
|
|
1006
|
+
}, 0);
|
|
1007
|
+
return Math.max(safeFallback, Math.min(28, estimatedMm));
|
|
1008
|
+
}
|
|
1009
|
+
function resolveColumnGapMms(section, explicitColumnSpacings, sectionColumnCount) {
|
|
1010
|
+
const computedGap = Number.parseFloat(window.getComputedStyle(section).getPropertyValue('--ov-column-gap-mm'));
|
|
1011
|
+
const fallbackGap = Number.isFinite(computedGap) && computedGap >= 0 ? computedGap : 12.7;
|
|
1012
|
+
const gapCount = Math.max(0, sectionColumnCount - 1);
|
|
1013
|
+
const resolved = [];
|
|
1014
|
+
for (let index = 0; index < gapCount; index++) {
|
|
1015
|
+
const explicitGap = explicitColumnSpacings[index];
|
|
1016
|
+
resolved.push(Number.isFinite(explicitGap) && explicitGap >= 0 ? explicitGap : fallbackGap);
|
|
1017
|
+
}
|
|
1018
|
+
return resolved;
|
|
1019
|
+
}
|
|
1020
|
+
function renderHeaderFooterFields(text, pageNumber, totalPages, sectionPageNumber, sectionPageCount, meta) {
|
|
1021
|
+
const sectionNumber = Number.isFinite(Number(meta?.sectionNumber))
|
|
1022
|
+
? Number(meta.sectionNumber)
|
|
1023
|
+
: 1;
|
|
1024
|
+
const sectionCount = Number.isFinite(Number(meta?.sectionCount))
|
|
1025
|
+
? Number(meta.sectionCount)
|
|
1026
|
+
: 1;
|
|
1027
|
+
return String(text || '')
|
|
1028
|
+
.replace(/\bSECTIONPAGES\b/gi, sectionPageCount > 0 ? String(sectionPageCount) : '')
|
|
1029
|
+
.replace(/\bSECTIONS\b/gi, sectionCount > 0 ? String(sectionCount) : '')
|
|
1030
|
+
.replace(/\bNUMPAGES\b/gi, totalPages > 0 ? String(totalPages) : '')
|
|
1031
|
+
.replace(/\bPAGE\b/gi, pageNumber > 0 ? String(pageNumber) : '')
|
|
1032
|
+
.replace(/\bSECTION\b/gi, sectionNumber > 0 ? String(sectionNumber) : '1')
|
|
1033
|
+
.replace(/\bSECTIONPAGE\b/gi, sectionPageNumber > 0 ? String(sectionPageNumber) : '')
|
|
1034
|
+
.trim();
|
|
1035
|
+
}
|