@folijs/view 0.6.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +161 -0
- package/README.md +1 -1
- package/dist/clipboard.d.ts +1 -51
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +65 -13
- package/dist/clipboard.js.map +1 -1
- package/dist/extension.d.ts +90 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +152 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layout/flow.d.ts +1 -282
- package/dist/layout/flow.d.ts.map +1 -1
- package/dist/layout/flow.js +21 -4
- package/dist/layout/flow.js.map +1 -1
- package/dist/print.d.ts +1 -17
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +5 -1
- package/dist/print.js.map +1 -1
- package/dist/render.d.ts +1 -24
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +4 -1
- package/dist/render.js.map +1 -1
- package/dist/view.d.ts +34 -67
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +209 -24
- package/dist/view.js.map +1 -1
- package/dist/word/blocks.d.ts +0 -175
- package/dist/word/blocks.d.ts.map +1 -1
- package/dist/word/blocks.js +106 -24
- package/dist/word/blocks.js.map +1 -1
- package/dist/word/columns.d.ts +1 -22
- package/dist/word/columns.d.ts.map +1 -1
- package/dist/word/columns.js +15 -3
- package/dist/word/columns.js.map +1 -1
- package/dist/word/controls.d.ts +1 -62
- package/dist/word/controls.d.ts.map +1 -1
- package/dist/word/controls.js +6 -1
- package/dist/word/controls.js.map +1 -1
- package/dist/word/edit.d.ts +1 -83
- package/dist/word/edit.d.ts.map +1 -1
- package/dist/word/edit.js +183 -5
- package/dist/word/edit.js.map +1 -1
- package/dist/word/matches.d.ts +1 -22
- package/dist/word/matches.d.ts.map +1 -1
- package/dist/word/matches.js +6 -1
- package/dist/word/matches.js.map +1 -1
- package/dist/word/notes.d.ts +0 -103
- package/dist/word/notes.d.ts.map +1 -1
- package/dist/word/notes.js +15 -4
- package/dist/word/notes.js.map +1 -1
- package/dist/word/pages.d.ts +15 -10
- package/dist/word/pages.d.ts.map +1 -1
- package/dist/word/pages.js +3 -2
- package/dist/word/pages.js.map +1 -1
- package/dist/word/regions.d.ts +0 -111
- package/dist/word/regions.d.ts.map +1 -1
- package/dist/word/regions.js +19 -5
- package/dist/word/regions.js.map +1 -1
- package/dist/word/table.d.ts +1 -78
- package/dist/word/table.d.ts.map +1 -1
- package/dist/word/table.js +13 -3
- package/dist/word/table.js.map +1 -1
- package/package.json +6 -3
- package/src/clipboard.ts +91 -21
- package/src/extension.ts +267 -0
- package/src/index.ts +10 -0
- package/src/layout/flow.ts +59 -13
- package/src/print.ts +9 -2
- package/src/render.ts +6 -1
- package/src/view.ts +245 -40
- package/src/word/blocks.ts +124 -30
- package/src/word/columns.ts +19 -4
- package/src/word/controls.ts +13 -3
- package/src/word/edit.ts +207 -9
- package/src/word/matches.ts +6 -1
- package/src/word/notes.ts +19 -6
- package/src/word/pages.ts +19 -3
- package/src/word/regions.ts +27 -8
- package/src/word/table.ts +33 -8
package/src/word/blocks.ts
CHANGED
|
@@ -8,38 +8,61 @@ import {
|
|
|
8
8
|
type FieldDisplay,
|
|
9
9
|
type FoliDocument,
|
|
10
10
|
fieldDisplay,
|
|
11
|
-
type ListMarker,
|
|
12
11
|
type MarkJSON,
|
|
13
12
|
type NodeJSON,
|
|
14
|
-
type ParagraphFormat,
|
|
15
|
-
Resolver,
|
|
16
13
|
type ResourceJSON,
|
|
17
|
-
type RunFormat,
|
|
18
14
|
type SectionJSON,
|
|
19
15
|
} from "@folijs/core";
|
|
16
|
+
import {
|
|
17
|
+
CUSTOM_TYPE,
|
|
18
|
+
foreignTextOf,
|
|
19
|
+
type ListMarker,
|
|
20
|
+
type ParagraphFormat,
|
|
21
|
+
Resolver,
|
|
22
|
+
type RunFormat,
|
|
23
|
+
} from "@folijs/core/internal";
|
|
20
24
|
|
|
21
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Marks the <br> of an explicit page break (the page flow ends the page after its line).
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
22
29
|
export const WORD_PAGE_BREAK_ATTR = "data-page-break";
|
|
23
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Marks the <br> of an explicit column break (the flow ends the column after its line).
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
24
34
|
export const WORD_COLUMN_BREAK_ATTR = "data-column-break";
|
|
25
35
|
|
|
26
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* CSS px per twip (1/1440 inch; CSS: 96 px per inch).
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
27
40
|
export const PX_PER_TWIP = 96 / 1440;
|
|
28
41
|
/** EMU (DrawingML's unit: 914 400 per inch) per CSS px. */
|
|
29
42
|
export const EMU_PER_PX = 914_400 / 96;
|
|
30
43
|
|
|
31
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* The URL to show a picture's image from (its resource key), if one is known.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
32
48
|
export type ImageSource = (key: string) => string | undefined;
|
|
33
49
|
|
|
34
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Marks a picture's element (its resource key).
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
35
54
|
export const PICTURE_ATTR = "data-foli-picture";
|
|
36
55
|
|
|
37
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The accessible name of a picture with no alt text that is not decorative.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
38
60
|
export const NO_ALT_LABEL = "Picture without alt text";
|
|
39
61
|
|
|
40
62
|
/**
|
|
41
63
|
* The URL a resource gives on its own: an image `data:` URL, or a web or `blob:` URL; none for
|
|
42
64
|
* an image in a package part (the app's resolver gives one) or anything else.
|
|
65
|
+
* @internal
|
|
43
66
|
*/
|
|
44
67
|
export function ownImageUrl(resource: ResourceJSON | undefined): string | undefined {
|
|
45
68
|
const data = resource?.data;
|
|
@@ -52,6 +75,7 @@ export function ownImageUrl(resource: ResourceJSON | undefined): string | undefi
|
|
|
52
75
|
* A picture as shown: its image at its size, or, when no URL is known for it, a box of that size
|
|
53
76
|
* with its alt text. A picture with no alt text that is not decorative is marked (`data-foli-
|
|
54
77
|
* no-alt`); a decorative one has an empty alt.
|
|
78
|
+
* @internal
|
|
55
79
|
*/
|
|
56
80
|
export function pictureElement(
|
|
57
81
|
attrs: Record<string, unknown>,
|
|
@@ -97,10 +121,16 @@ export function pictureElement(
|
|
|
97
121
|
return element;
|
|
98
122
|
}
|
|
99
123
|
|
|
100
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Marks the element holding a floating picture (its wrapping), drawn at its paragraph's start.
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
101
128
|
export const FLOAT_ATTR = "data-foli-float";
|
|
102
129
|
|
|
103
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* A section's page, in CSS px: what a floating picture is positioned against.
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
104
134
|
export interface FloatGeometry {
|
|
105
135
|
readonly pageWidth: number;
|
|
106
136
|
readonly pageHeight: number;
|
|
@@ -110,7 +140,10 @@ export interface FloatGeometry {
|
|
|
110
140
|
readonly textHeight: number;
|
|
111
141
|
}
|
|
112
142
|
|
|
113
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The page geometry of `section` (Word's Letter page and margins where it does not say).
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
114
147
|
export function floatGeometry(section: SectionJSON | undefined): FloatGeometry {
|
|
115
148
|
const m = section?.margins ?? {};
|
|
116
149
|
const width = section?.pageSize?.width ?? 12_240;
|
|
@@ -206,6 +239,7 @@ function floatTop(
|
|
|
206
239
|
* earlier float's (CSS), and `clear` stacks it below earlier floats on its side: several floats
|
|
207
240
|
* in a paragraph, or one above a float of an earlier paragraph, add their offsets down and do
|
|
208
241
|
* not sit side by side.
|
|
242
|
+
* @internal
|
|
209
243
|
*/
|
|
210
244
|
export function floatElements(
|
|
211
245
|
attrs: Record<string, unknown>,
|
|
@@ -294,20 +328,27 @@ const AUTHOR_COLORS = [
|
|
|
294
328
|
"#5D4037",
|
|
295
329
|
];
|
|
296
330
|
|
|
297
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* The color of `author`'s changes: always the same for a name.
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
298
335
|
export function authorColor(author: string): string {
|
|
299
336
|
let hash = 0;
|
|
300
337
|
for (const c of author) hash = (hash * 31 + (c.codePointAt(0) ?? 0)) >>> 0;
|
|
301
338
|
return AUTHOR_COLORS[hash % AUTHOR_COLORS.length] as string;
|
|
302
339
|
}
|
|
303
340
|
|
|
304
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* The bar beside a paragraph with changes (`markup` and `simple`), drawn in the margin.
|
|
343
|
+
* @internal
|
|
344
|
+
*/
|
|
305
345
|
export const CHANGE_BAR = "-4px 0 0 0 #6B6B6B";
|
|
306
346
|
|
|
307
347
|
/**
|
|
308
348
|
* The element around an inserted or deleted run: `ins` or `del` (named for screen readers by
|
|
309
349
|
* its title), styled for `review`. Deleted text not shown is hidden, not left out: the editable
|
|
310
350
|
* view maps positions through it.
|
|
351
|
+
* @internal
|
|
311
352
|
*/
|
|
312
353
|
export function changeElement(
|
|
313
354
|
doc: Document,
|
|
@@ -329,6 +370,7 @@ export function changeElement(
|
|
|
329
370
|
return element;
|
|
330
371
|
}
|
|
331
372
|
|
|
373
|
+
/** @internal */
|
|
332
374
|
export interface BlockOptions {
|
|
333
375
|
/** `markup` (the default): insertions underlined, deletions struck through; `simple`, `final`: as if accepted. */
|
|
334
376
|
review?: ReviewView;
|
|
@@ -352,15 +394,24 @@ export interface BlockOptions {
|
|
|
352
394
|
notes?: { references?: ReadonlyMap<string, string>; mark?: string };
|
|
353
395
|
}
|
|
354
396
|
|
|
355
|
-
/**
|
|
397
|
+
/**
|
|
398
|
+
* On the element showing a note reference's number: the note's story.
|
|
399
|
+
* @internal
|
|
400
|
+
*/
|
|
356
401
|
export const NOTE_REF_ATTR = "data-foli-note-ref";
|
|
357
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* On a number drawn for a note, at its reference or its mark: not text of the document.
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
358
406
|
export const NOTE_NUMBER_ATTR = "data-foli-note-number";
|
|
359
407
|
|
|
360
408
|
/** Word's footnote separator is two inches long; its continuation line here is the same. */
|
|
361
409
|
const SEPARATOR_WIDTH = 192;
|
|
362
410
|
|
|
363
|
-
/**
|
|
411
|
+
/**
|
|
412
|
+
* The line a separator run draws, when `xml` is one (`w:separator`, `w:continuationSeparator`).
|
|
413
|
+
* @internal
|
|
414
|
+
*/
|
|
364
415
|
export function separatorElement(xml: Element | null, doc: Document): HTMLElement | null {
|
|
365
416
|
if (!xml) return null;
|
|
366
417
|
const found = [xml, ...xml.getElementsByTagName("*")].some(
|
|
@@ -379,7 +430,10 @@ export function separatorElement(xml: Element | null, doc: Document): HTMLElemen
|
|
|
379
430
|
return line;
|
|
380
431
|
}
|
|
381
432
|
|
|
382
|
-
/**
|
|
433
|
+
/**
|
|
434
|
+
* The source for a document's pictures: the app's URL, else the resource's own.
|
|
435
|
+
* @internal
|
|
436
|
+
*/
|
|
383
437
|
export function imageSource(
|
|
384
438
|
resources: Readonly<Record<string, ResourceJSON>> | undefined,
|
|
385
439
|
resolve?: (key: string, resource: ResourceJSON) => string | null | undefined,
|
|
@@ -393,7 +447,10 @@ export function imageSource(
|
|
|
393
447
|
};
|
|
394
448
|
}
|
|
395
449
|
|
|
396
|
-
/**
|
|
450
|
+
/**
|
|
451
|
+
* A rendered block and what the page flow needs to know about it.
|
|
452
|
+
* @internal
|
|
453
|
+
*/
|
|
397
454
|
export interface WordBlock {
|
|
398
455
|
element: HTMLElement;
|
|
399
456
|
/** Indices in the document's content of the nodes it shows (several when paragraphs merged). */
|
|
@@ -423,7 +480,10 @@ const SUBSTITUTES: Record<string, string[]> = {
|
|
|
423
480
|
const SERIF = new Set(["cambria", "times new roman", "georgia", "garamond", "book antiqua"]);
|
|
424
481
|
const MONOSPACE = new Set(["courier new", "consolas", "courier"]);
|
|
425
482
|
|
|
426
|
-
/**
|
|
483
|
+
/**
|
|
484
|
+
* A CSS font-family list for a Word font name: the font, its substitutes, a generic family.
|
|
485
|
+
* @internal
|
|
486
|
+
*/
|
|
427
487
|
export function fontStack(name: string | null): string {
|
|
428
488
|
const font = name ?? "Times New Roman";
|
|
429
489
|
const key = font.toLowerCase();
|
|
@@ -484,10 +544,16 @@ const BORDER_STYLES: Record<string, string> = {
|
|
|
484
544
|
nil: "none",
|
|
485
545
|
};
|
|
486
546
|
|
|
487
|
-
/**
|
|
547
|
+
/**
|
|
548
|
+
* The one font name a run shows for Latin text.
|
|
549
|
+
* @internal
|
|
550
|
+
*/
|
|
488
551
|
export const latin = (run: RunFormat) => run.font.ascii ?? run.font.hAnsi;
|
|
489
552
|
|
|
490
|
-
/**
|
|
553
|
+
/**
|
|
554
|
+
* A line height in CSS for text in `run` (`ratio`: its font's normal line height ratio).
|
|
555
|
+
* @internal
|
|
556
|
+
*/
|
|
491
557
|
export function lineHeight(paragraph: ParagraphFormat, run: RunFormat, ratio: number): string {
|
|
492
558
|
const sizePx = (run.size / 2) * (96 / 72);
|
|
493
559
|
const { line, lineRule } = paragraph.spacing;
|
|
@@ -497,7 +563,10 @@ export function lineHeight(paragraph: ParagraphFormat, run: RunFormat, ratio: nu
|
|
|
497
563
|
return String((ratio * line) / 240);
|
|
498
564
|
}
|
|
499
565
|
|
|
500
|
-
/**
|
|
566
|
+
/**
|
|
567
|
+
* Run formatting as inline CSS on `element`.
|
|
568
|
+
* @internal
|
|
569
|
+
*/
|
|
501
570
|
export function styleRun(element: HTMLElement, run: RunFormat, line: string): void {
|
|
502
571
|
const { style } = element;
|
|
503
572
|
style.fontFamily = fontStack(latin(run));
|
|
@@ -531,7 +600,10 @@ export function styleRun(element: HTMLElement, run: RunFormat, line: string): vo
|
|
|
531
600
|
if (run.hidden) style.display = "none";
|
|
532
601
|
}
|
|
533
602
|
|
|
534
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* Paragraph properties as inline CSS on `element` (spacing is the flow's).
|
|
605
|
+
* @internal
|
|
606
|
+
*/
|
|
535
607
|
export function styleParagraph(element: HTMLElement, paragraph: ParagraphFormat): void {
|
|
536
608
|
const { style } = element;
|
|
537
609
|
style.margin = "0";
|
|
@@ -565,7 +637,10 @@ export function styleParagraph(element: HTMLElement, paragraph: ParagraphFormat)
|
|
|
565
637
|
*/
|
|
566
638
|
const NOT_INLINE = new Set(["txbxContent", "Fallback"]);
|
|
567
639
|
|
|
568
|
-
/**
|
|
640
|
+
/**
|
|
641
|
+
* Text a run of opaque XML shows: its `w:t` elements (field results, content controls).
|
|
642
|
+
* @internal
|
|
643
|
+
*/
|
|
569
644
|
export function opaqueText(element: Element): string {
|
|
570
645
|
let text = "";
|
|
571
646
|
for (const node of element.children) {
|
|
@@ -577,7 +652,10 @@ export function opaqueText(element: Element): string {
|
|
|
577
652
|
return text;
|
|
578
653
|
}
|
|
579
654
|
|
|
580
|
-
/**
|
|
655
|
+
/**
|
|
656
|
+
* Opaque XML's text, a line per paragraph (`w:p`), or its runs' text when it has none.
|
|
657
|
+
* @internal
|
|
658
|
+
*/
|
|
581
659
|
export function opaqueParagraphsText(element: Element): string {
|
|
582
660
|
const paragraphs = [...element.getElementsByTagName("*")].filter((e) => e.localName === "p");
|
|
583
661
|
if (element.localName === "p") paragraphs.unshift(element);
|
|
@@ -605,6 +683,7 @@ const CELL_CONTENT = new Set(["p", "tbl"]);
|
|
|
605
683
|
/**
|
|
606
684
|
* Parses verbatim WordprocessingML (opaque content) into an inert XML document, declaring the
|
|
607
685
|
* prefixes it uses; null when it is not well-formed.
|
|
686
|
+
* @internal
|
|
608
687
|
*/
|
|
609
688
|
export function parseOpaque(xml: string, doc: Document): Element | null {
|
|
610
689
|
const view = doc.defaultView;
|
|
@@ -627,6 +706,7 @@ export function parseOpaque(xml: string, doc: Document): Element | null {
|
|
|
627
706
|
/**
|
|
628
707
|
* Renders a document's blocks. `final` review merges a paragraph whose mark was deleted into
|
|
629
708
|
* the next one, as accepting the deletion does.
|
|
709
|
+
* @internal
|
|
630
710
|
*/
|
|
631
711
|
export function renderBlocks(
|
|
632
712
|
document: FoliDocument,
|
|
@@ -779,6 +859,7 @@ function joinDisplays(before: FieldDisplay, length: number, after: FieldDisplay)
|
|
|
779
859
|
/**
|
|
780
860
|
* Whether a paragraph's line holds nothing but inline pictures: Word's line then ends at the
|
|
781
861
|
* picture's foot (its PDFs of the corpus: no room below it for the text it does not have).
|
|
862
|
+
* @internal
|
|
782
863
|
*/
|
|
783
864
|
export function onlyPictures<T>(
|
|
784
865
|
inline: Iterable<T>,
|
|
@@ -813,12 +894,16 @@ const INVISIBLE = new Set([
|
|
|
813
894
|
* flow does not lay out (a table cell). Adjacent margins collapse to the larger: Word's rule. In
|
|
814
895
|
* a document where the two spaces add up this margin holds both, so the collapse gives the sum
|
|
815
896
|
* and no paragraph's shading or border grows.
|
|
897
|
+
* @internal
|
|
816
898
|
*/
|
|
817
899
|
export function marginAbove(before: number, above: number, resolver: Resolver): number {
|
|
818
900
|
return resolver.addsParagraphSpacing ? before + above : before;
|
|
819
901
|
}
|
|
820
902
|
|
|
821
|
-
/**
|
|
903
|
+
/**
|
|
904
|
+
* A paragraph's element: a heading of its outline level (1-6), else a paragraph.
|
|
905
|
+
* @internal
|
|
906
|
+
*/
|
|
822
907
|
export function tagOf(paragraph: ParagraphFormat): string {
|
|
823
908
|
const level = paragraph.outlineLevel;
|
|
824
909
|
return level !== null && level >= 0 && level < 6 ? `h${level + 1}` : "p";
|
|
@@ -857,7 +942,10 @@ const SYMBOLS: Record<string, string> = {
|
|
|
857
942
|
"\uF0FC": "\u2713", // Wingdings: check mark
|
|
858
943
|
};
|
|
859
944
|
|
|
860
|
-
/**
|
|
945
|
+
/**
|
|
946
|
+
* A list marker: its text, then what follows it (a tab to the text's indent, a space).
|
|
947
|
+
* @internal
|
|
948
|
+
*/
|
|
861
949
|
export function markerElement(
|
|
862
950
|
marker: ListMarker,
|
|
863
951
|
paragraph: ParagraphFormat,
|
|
@@ -982,6 +1070,8 @@ function renderInline(
|
|
|
982
1070
|
else if (node.type === "noteReference")
|
|
983
1071
|
text = context.notes?.references?.get(String(attrs.story)) ?? "";
|
|
984
1072
|
else if (node.type === "noteMark") text = context.notes?.mark ?? "";
|
|
1073
|
+
// A custom node without its extension here (ADR-0008): its `.docx` text, else its type.
|
|
1074
|
+
else if (CUSTOM_TYPE.test(node.type)) text = foreignTextOf(node) ?? `[${node.type}]`;
|
|
985
1075
|
else if (node.type === "opaqueInline") {
|
|
986
1076
|
const xml = parseOpaque(String(attrs.xml ?? ""), doc);
|
|
987
1077
|
const separator = separatorElement(xml, doc);
|
|
@@ -1032,6 +1122,7 @@ function renderInline(
|
|
|
1032
1122
|
* A block the model keeps opaque (tables until Phase 10, block content controls), shown from
|
|
1033
1123
|
* its XML: a table as a table of its cells' paragraphs, anything else as its paragraphs. Only
|
|
1034
1124
|
* text is read: no formatting beyond the paragraph styles.
|
|
1125
|
+
* @internal
|
|
1035
1126
|
*/
|
|
1036
1127
|
export function opaqueBlock(
|
|
1037
1128
|
node: NodeJSON,
|
|
@@ -1275,7 +1366,10 @@ function opaqueTable(
|
|
|
1275
1366
|
return table;
|
|
1276
1367
|
}
|
|
1277
1368
|
|
|
1278
|
-
/**
|
|
1369
|
+
/**
|
|
1370
|
+
* A border of the model (`BorderJSON`) as CSS; undefined when it says none.
|
|
1371
|
+
* @internal
|
|
1372
|
+
*/
|
|
1279
1373
|
export function borderJsonCss(
|
|
1280
1374
|
border: { style?: string; size?: number; color?: string } | undefined,
|
|
1281
1375
|
) {
|
package/src/word/columns.ts
CHANGED
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
import { type SectionJSON, sectionColumns } from "@folijs/core";
|
|
5
5
|
import { PX_PER_TWIP } from "./blocks.js";
|
|
6
6
|
|
|
7
|
+
/** @internal */
|
|
7
8
|
export const BAND_CLASS = "foli-band";
|
|
9
|
+
/** @internal */
|
|
8
10
|
export const COLUMN_CLASS = "foli-column";
|
|
9
11
|
|
|
10
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A section's columns in CSS px.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
11
16
|
export interface ColumnsPx {
|
|
12
17
|
widths: number[];
|
|
13
18
|
gaps: number[];
|
|
14
19
|
separator: boolean;
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
/** @internal */
|
|
17
23
|
export function columnsPx(section: SectionJSON): ColumnsPx {
|
|
18
24
|
const { widths, gaps, separator } = sectionColumns(section);
|
|
19
25
|
return {
|
|
@@ -23,11 +29,17 @@ export function columnsPx(section: SectionJSON): ColumnsPx {
|
|
|
23
29
|
};
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* What identifies a band's look: the same key, the same elements can stay.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
27
36
|
export const columnsKey = ({ widths, gaps, separator }: ColumnsPx) =>
|
|
28
37
|
`${widths.join(" ")}|${gaps.join(" ")}|${separator}`;
|
|
29
38
|
|
|
30
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Gives `band` and its `columns` their widths, spaces and the lines between them.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
31
43
|
export function styleBand(band: HTMLElement, columns: readonly HTMLElement[], c: ColumnsPx): void {
|
|
32
44
|
band.className = BAND_CLASS;
|
|
33
45
|
band.style.display = "flex";
|
|
@@ -53,7 +65,10 @@ export function styleBand(band: HTMLElement, columns: readonly HTMLElement[], c:
|
|
|
53
65
|
});
|
|
54
66
|
}
|
|
55
67
|
|
|
56
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* A new band of `c`'s columns.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
57
72
|
export function bandElement(
|
|
58
73
|
doc: Document,
|
|
59
74
|
c: ColumnsPx,
|
package/src/word/controls.ts
CHANGED
|
@@ -16,11 +16,13 @@ import {
|
|
|
16
16
|
type EditorState,
|
|
17
17
|
setControlValue,
|
|
18
18
|
TextSelection,
|
|
19
|
-
wordContext,
|
|
20
19
|
} from "@folijs/core";
|
|
20
|
+
import { wordContext } from "@folijs/core/internal";
|
|
21
21
|
|
|
22
|
+
/** @internal */
|
|
22
23
|
export const CONTROL_UI_ATTR = "data-foli-control-ui";
|
|
23
24
|
|
|
25
|
+
/** @internal */
|
|
24
26
|
export const CONTROL_STYLES =
|
|
25
27
|
`[${CONTROL_UI_ATTR}]{font:11px/16px system-ui,sans-serif;color:#1f3a5f;white-space:nowrap;user-select:none;-webkit-user-select:none}` +
|
|
26
28
|
`[data-foli-control-frame]{position:absolute;box-sizing:border-box;border:1px solid #8aa4c8;pointer-events:none}` +
|
|
@@ -33,8 +35,12 @@ export const CONTROL_STYLES =
|
|
|
33
35
|
`[data-foli-control-status]{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}` +
|
|
34
36
|
`@media print{[${CONTROL_UI_ATTR}]{display:none}}`;
|
|
35
37
|
|
|
36
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* A rectangle of the screen.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
37
42
|
export type Box = Pick<DOMRect, "left" | "top" | "right" | "bottom" | "width" | "height">;
|
|
43
|
+
/** @internal */
|
|
38
44
|
export const boxOf = (left: number, top: number, width: number, height: number): Box => ({
|
|
39
45
|
left,
|
|
40
46
|
top,
|
|
@@ -44,7 +50,10 @@ export const boxOf = (left: number, top: number, width: number, height: number):
|
|
|
44
50
|
bottom: top + height,
|
|
45
51
|
});
|
|
46
52
|
|
|
47
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* What the chrome needs of its view.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
48
57
|
export interface ControlChromeHost {
|
|
49
58
|
readonly host: HTMLElement;
|
|
50
59
|
readonly editor: Editor;
|
|
@@ -94,6 +103,7 @@ function lines(rects: readonly Box[]): Box[] {
|
|
|
94
103
|
return out;
|
|
95
104
|
}
|
|
96
105
|
|
|
106
|
+
/** @internal */
|
|
97
107
|
export class ControlChrome {
|
|
98
108
|
private drawn: HTMLElement[] = [];
|
|
99
109
|
private hovered: ControlRange | null = null;
|