@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
package/src/print.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Print rules shared by the editor's pages and the read-only renderer's (`renderDocument`), so
3
+ * that the editor's `print()` and `@folijs/pdf`'s `exportPdf` print pages the same way (11.12).
4
+ */
5
+
6
+ /**
7
+ * The attribute naming a page's page setup (its index among the document's) for print.
8
+ * @internal
9
+ */
10
+ export const SHEET_ATTR = "data-foli-sheet";
11
+
12
+ /**
13
+ * A page setup as print sees it: its sheet's size (CSS lengths) and its `SHEET_ATTR` value.
14
+ * @internal
15
+ */
16
+ export interface PrintSheet {
17
+ readonly width: string;
18
+ readonly height: string;
19
+ readonly index: number;
20
+ }
21
+
22
+ /**
23
+ * Print rules for the page elements `pages` selects: one sheet of its page setup's size per page
24
+ * (`last`'s, the document's last section, where named pages are not supported), without margins
25
+ * (the page's padding holds them). A page is exactly as tall as a sheet (the flow keeps content
26
+ * inside it; the exact height absorbs its half-pixel slack), with no gap after it. Content taller
27
+ * than a page (a line taller than a page) is not cut: it prints over the next sheet. `name` makes
28
+ * the named pages unique on the web page.
29
+ * @internal
30
+ */
31
+ export function printStyles(
32
+ pages: string,
33
+ last: Pick<PrintSheet, "width" | "height">,
34
+ sheets: readonly PrintSheet[],
35
+ name: string,
36
+ ): string {
37
+ // Sections with other page sizes: a named page each (engines without named pages print
38
+ // every sheet at the last section's size).
39
+ const named = sheets.every((s) => s.width === last.width && s.height === last.height)
40
+ ? ""
41
+ : sheets
42
+ .map(({ width, height, index }) => {
43
+ const page = `foli-${name}-${index}`;
44
+ return (
45
+ `@page ${page}{size:${width} ${height};margin:0}` +
46
+ `${pages}[${SHEET_ATTR}="${index}"]{page:${page};height:${height}!important}`
47
+ );
48
+ })
49
+ .join("");
50
+ return (
51
+ `@media print{@page{size:${last.width} ${last.height};margin:0}` +
52
+ `${pages}{height:${last.height}!important;margin-block:0!important;` +
53
+ `break-after:page;break-inside:avoid}${pages}:last-child{break-after:auto}${named}}`
54
+ );
55
+ }
package/src/render.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import type { Node as ModelNode } from "@folijs/core";
2
2
 
3
- /** Marks the <br> of an explicit page break. */
3
+ /**
4
+ * Marks the <br> of an explicit page break.
5
+ * @internal
6
+ */
4
7
  export const PAGE_BREAK_ATTR = "data-page-break";
5
8
 
6
9
  /**
7
10
  * A rendered inline leaf (a text node or hard break) and where it sits in its block's content.
8
11
  * A text node split across fragments is two leaves, one per fragment.
12
+ * @internal
9
13
  */
10
14
  export interface LeafDesc {
11
15
  readonly dom: Node;
@@ -16,6 +20,7 @@ export interface LeafDesc {
16
20
  /**
17
21
  * View descriptor of one block: the model node, its elements and its leaves. A block split
18
22
  * across pages has one element per page (its fragments, in order); `dom` is the first.
23
+ * @internal
19
24
  */
20
25
  export interface BlockDesc {
21
26
  readonly node: ModelNode;