@folijs/view 0.5.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +1 -1
  3. package/dist/clipboard.d.ts +1 -49
  4. package/dist/clipboard.d.ts.map +1 -1
  5. package/dist/clipboard.js +65 -13
  6. package/dist/clipboard.js.map +1 -1
  7. package/dist/extension.d.ts +90 -0
  8. package/dist/extension.d.ts.map +1 -0
  9. package/dist/extension.js +152 -0
  10. package/dist/extension.js.map +1 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout/flow.d.ts +1 -109
  15. package/dist/layout/flow.d.ts.map +1 -1
  16. package/dist/layout/flow.js +808 -103
  17. package/dist/layout/flow.js.map +1 -1
  18. package/dist/print.d.ts +6 -0
  19. package/dist/print.d.ts.map +1 -0
  20. package/dist/print.js +35 -0
  21. package/dist/print.js.map +1 -0
  22. package/dist/render.d.ts +1 -24
  23. package/dist/render.d.ts.map +1 -1
  24. package/dist/render.js +4 -1
  25. package/dist/render.js.map +1 -1
  26. package/dist/view.d.ts +244 -64
  27. package/dist/view.d.ts.map +1 -1
  28. package/dist/view.js +1945 -215
  29. package/dist/view.js.map +1 -1
  30. package/dist/word/blocks.d.ts +0 -146
  31. package/dist/word/blocks.d.ts.map +1 -1
  32. package/dist/word/blocks.js +294 -59
  33. package/dist/word/blocks.js.map +1 -1
  34. package/dist/word/columns.d.ts +2 -0
  35. package/dist/word/columns.d.ts.map +1 -0
  36. package/dist/word/columns.js +63 -0
  37. package/dist/word/columns.js.map +1 -0
  38. package/dist/word/controls.d.ts +2 -0
  39. package/dist/word/controls.d.ts.map +1 -0
  40. package/dist/word/controls.js +416 -0
  41. package/dist/word/controls.js.map +1 -0
  42. package/dist/word/edit.d.ts +1 -71
  43. package/dist/word/edit.d.ts.map +1 -1
  44. package/dist/word/edit.js +338 -29
  45. package/dist/word/edit.js.map +1 -1
  46. package/dist/word/matches.d.ts +2 -0
  47. package/dist/word/matches.d.ts.map +1 -0
  48. package/dist/word/matches.js +102 -0
  49. package/dist/word/matches.js.map +1 -0
  50. package/dist/word/notes.d.ts +2 -0
  51. package/dist/word/notes.d.ts.map +1 -0
  52. package/dist/word/notes.js +403 -0
  53. package/dist/word/notes.js.map +1 -0
  54. package/dist/word/pages.d.ts +30 -20
  55. package/dist/word/pages.d.ts.map +1 -1
  56. package/dist/word/pages.js +421 -229
  57. package/dist/word/pages.js.map +1 -1
  58. package/dist/word/regions.d.ts +2 -0
  59. package/dist/word/regions.d.ts.map +1 -0
  60. package/dist/word/regions.js +388 -0
  61. package/dist/word/regions.js.map +1 -0
  62. package/dist/word/table.d.ts +1 -78
  63. package/dist/word/table.d.ts.map +1 -1
  64. package/dist/word/table.js +13 -3
  65. package/dist/word/table.js.map +1 -1
  66. package/package.json +6 -3
  67. package/src/clipboard.ts +93 -20
  68. package/src/extension.ts +267 -0
  69. package/src/index.ts +10 -0
  70. package/src/layout/flow.ts +997 -116
  71. package/src/print.ts +55 -0
  72. package/src/render.ts +6 -1
  73. package/src/view.ts +2178 -245
  74. package/src/word/blocks.ts +339 -62
  75. package/src/word/columns.ts +81 -0
  76. package/src/word/controls.ts +457 -0
  77. package/src/word/edit.ts +381 -31
  78. package/src/word/matches.ts +104 -0
  79. package/src/word/notes.ts +464 -0
  80. package/src/word/pages.ts +518 -221
  81. package/src/word/regions.ts +488 -0
  82. package/src/word/table.ts +33 -8
@@ -1,152 +1,6 @@
1
- /**
2
- * Schema v3 blocks as DOM, formatted as Word formats them (8.6b): every paragraph's and run's
3
- * effective formatting from `Resolver` as inline CSS, list markers, tracked changes, comment
4
- * anchors, and content the model keeps opaque shown as text. Read-only: built with
5
- * createElement/textContent only (never innerHTML); the page layout is in `pages.ts`.
6
- */
7
- import { type FoliDocument, type ListMarker, type NodeJSON, type ParagraphFormat, Resolver, type ResourceJSON, type RunFormat, type SectionJSON } from "@folijs/core";
8
- /** Marks the <br> of an explicit page break (the page flow ends the page after its line). */
9
- export declare const WORD_PAGE_BREAK_ATTR = "data-page-break";
10
- /** CSS px per twip (1/1440 inch; CSS: 96 px per inch). */
11
- export declare const PX_PER_TWIP: number;
12
1
  /** EMU (DrawingML's unit: 914 400 per inch) per CSS px. */
13
2
  export declare const EMU_PER_PX: number;
14
- /** The URL to show a picture's image from (its resource key), if one is known. */
15
- export type ImageSource = (key: string) => string | undefined;
16
- /** Marks a picture's element (its resource key). */
17
- export declare const PICTURE_ATTR = "data-foli-picture";
18
- /** The accessible name of a picture with no alt text that is not decorative. */
19
- export declare const NO_ALT_LABEL = "Picture without alt text";
20
- /**
21
- * The URL a resource gives on its own: an image `data:` URL, or a web or `blob:` URL; none for
22
- * an image in a package part (the app's resolver gives one) or anything else.
23
- */
24
- export declare function ownImageUrl(resource: ResourceJSON | undefined): string | undefined;
25
- /**
26
- * A picture as shown: its image at its size, or, when no URL is known for it, a box of that size
27
- * with its alt text. A picture with no alt text that is not decorative is marked (`data-foli-
28
- * no-alt`); a decorative one has an empty alt.
29
- */
30
- export declare function pictureElement(attrs: Record<string, unknown>, doc: Document, image?: ImageSource): HTMLElement;
31
- /** Marks the element holding a floating picture (its wrapping), drawn at its paragraph's start. */
32
- export declare const FLOAT_ATTR = "data-foli-float";
33
- /** A section's page, in CSS px: what a floating picture is positioned against. */
34
- export interface FloatGeometry {
35
- readonly pageWidth: number;
36
- readonly pageHeight: number;
37
- readonly marginLeft: number;
38
- readonly marginTop: number;
39
- readonly textWidth: number;
40
- readonly textHeight: number;
41
- }
42
- /** The page geometry of `section` (Word's Letter page and margins where it does not say). */
43
- export declare function floatGeometry(section: SectionJSON | undefined): FloatGeometry;
44
- /**
45
- * A floating picture (10.9, ADR-0006) as CSS floats lay it out, put first in its anchor
46
- * paragraph: `holder` holds the picture (`FLOAT_ATTR`), `nodes` go in the paragraph (a
47
- * zero-width spacer float before it gives its offset from the paragraph's top).
48
- * - Square (tight and through shown as square): a float on the side the picture is on, its
49
- * distance from the text as its margin; text goes on the other side only.
50
- * - Top and bottom: a float as wide as the paragraph, the picture in it at its position.
51
- * - Behind and in front of text: absolutely positioned on the page (z-index -1 or 1; the page is
52
- * the containing block and its own stacking context).
53
- * shortcut: a wrapping picture placed against the page or its margins vertically is drawn at
54
- * its paragraph's top; horizontal positions are against the paragraph's box (its indents in);
55
- * all against `geometry` (one section's page), not each page's. A float's top is never above an
56
- * earlier float's (CSS), and `clear` stacks it below earlier floats on its side: several floats
57
- * in a paragraph, or one above a float of an earlier paragraph, add their offsets down and do
58
- * not sit side by side.
59
- */
60
- export declare function floatElements(attrs: Record<string, unknown>, doc: Document, image: ImageSource | undefined, geometry: FloatGeometry): {
61
- nodes: HTMLElement[];
62
- holder: HTMLElement;
63
- };
64
3
  /** Which version of tracked changes to show. */
65
4
  /** How tracked changes show (`@folijs/core`'s, for `renderDocument` too). */
66
5
  export type { ReviewView } from "@folijs/core";
67
- import type { ReviewView } from "@folijs/core";
68
- /** The color of `author`'s changes: always the same for a name. */
69
- export declare function authorColor(author: string): string;
70
- /** The bar beside a paragraph with changes (`markup` and `simple`), drawn in the margin. */
71
- export declare const CHANGE_BAR = "-4px 0 0 0 #6B6B6B";
72
- /**
73
- * The element around an inserted or deleted run: `ins` or `del` (named for screen readers by
74
- * its title), styled for `review`. Deleted text not shown is hidden, not left out: the editable
75
- * view maps positions through it.
76
- */
77
- export declare function changeElement(doc: Document, inserted: boolean, author: string, date: string | null, review: ReviewView): HTMLElement;
78
- export interface BlockOptions {
79
- /** `markup` (the default): insertions underlined, deletions struck through; `simple`, `final`: as if accepted. */
80
- review?: ReviewView;
81
- /**
82
- * The ratio of a font's normal line height to its size (`fontFamily`: a CSS font-family
83
- * list). Word's single line spacing is the font's own line height; multiples scale it.
84
- * Measured by the page layout; 1.2 when nothing measures (no layout engine).
85
- */
86
- lineRatio?: (fontFamily: string) => number;
87
- /**
88
- * The URL to show a picture's image from (`key` in `resources`): the app's (a package part's
89
- * object URL…); `null` (or "") shows the picture's box. Left out, or undefined for a key: the
90
- * resource's own image `data:` URL or web URL (fetched as it is shown).
91
- */
92
- resource?: (key: string, resource: ResourceJSON) => string | null | undefined;
93
- }
94
- /** The source for a document's pictures: the app's URL, else the resource's own. */
95
- export declare function imageSource(resources: Readonly<Record<string, ResourceJSON>> | undefined, resolve?: (key: string, resource: ResourceJSON) => string | null | undefined): ImageSource;
96
- /** A rendered block and what the page flow needs to know about it. */
97
- export interface WordBlock {
98
- element: HTMLElement;
99
- /** Indices in the document's content of the nodes it shows (several when paragraphs merged). */
100
- nodes: number[];
101
- /** Space before and after, in CSS px (Word adds them: the flow places them). */
102
- before: number;
103
- after: number;
104
- keepNext: boolean;
105
- keepLines: boolean;
106
- pageBreakBefore: boolean;
107
- /** The page setup of the section this block ends (null: the section goes on). */
108
- section: SectionJSON | null;
109
- }
110
- /** A CSS font-family list for a Word font name: the font, its substitutes, a generic family. */
111
- export declare function fontStack(name: string | null): string;
112
- /** The one font name a run shows for Latin text. */
113
- export declare const latin: (run: RunFormat) => string | null;
114
- /** A line height in CSS for text in `run` (`ratio`: its font's normal line height ratio). */
115
- export declare function lineHeight(paragraph: ParagraphFormat, run: RunFormat, ratio: number): string;
116
- /** Run formatting as inline CSS on `element`. */
117
- export declare function styleRun(element: HTMLElement, run: RunFormat, line: string): void;
118
- /** Paragraph properties as inline CSS on `element` (spacing is the flow's). */
119
- export declare function styleParagraph(element: HTMLElement, paragraph: ParagraphFormat): void;
120
- /** Text a run of opaque XML shows: its `w:t` elements (field results, content controls). */
121
- export declare function opaqueText(element: Element): string;
122
- /** Opaque XML's text, a line per paragraph (`w:p`), or its runs' text when it has none. */
123
- export declare function opaqueParagraphsText(element: Element): string;
124
- /**
125
- * Parses verbatim WordprocessingML (opaque content) into an inert XML document, declaring the
126
- * prefixes it uses; null when it is not well-formed.
127
- */
128
- export declare function parseOpaque(xml: string, doc: Document): Element | null;
129
- /**
130
- * Renders a document's blocks. `final` review merges a paragraph whose mark was deleted into
131
- * the next one, as accepting the deletion does.
132
- */
133
- export declare function renderBlocks(document: FoliDocument, doc: Document, options?: BlockOptions): WordBlock[];
134
- /** A paragraph's element: a heading of its outline level (1-6), else a paragraph. */
135
- export declare function tagOf(paragraph: ParagraphFormat): string;
136
- /** A list marker: its text, then what follows it (a tab to the text's indent, a space). */
137
- export declare function markerElement(marker: ListMarker, paragraph: ParagraphFormat, doc: Document, ratio: (family: string) => number): HTMLElement;
138
- /**
139
- * A block the model keeps opaque (tables until Phase 10, block content controls), shown from
140
- * its XML: a table as a table of its cells' paragraphs, anything else as its paragraphs. Only
141
- * text is read: no formatting beyond the paragraph styles.
142
- */
143
- export declare function opaqueBlock(node: NodeJSON, index: number, resolver: Resolver, doc: Document, ratio: (family: string) => number, image?: ImageSource,
144
- /** The page floating pictures in its cells are placed against. */
145
- geometry?: FloatGeometry): WordBlock;
146
- /** A border of the model (`BorderJSON`) as CSS; undefined when it says none. */
147
- export declare function borderJsonCss(border: {
148
- style?: string;
149
- size?: number;
150
- color?: string;
151
- } | undefined): string | undefined;
152
6
  //# sourceMappingURL=blocks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/word/blocks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,QAAQ,EACR,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAEtB,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,0DAA0D;AAC1D,eAAO,MAAM,WAAW,QAAY,CAAC;AACrC,2DAA2D;AAC3D,eAAO,MAAM,UAAU,QAAe,CAAC;AAEvC,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAA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