@folijs/view 0.5.0 → 0.6.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 (61) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/clipboard.d.ts +3 -1
  3. package/dist/clipboard.d.ts.map +1 -1
  4. package/dist/clipboard.js.map +1 -1
  5. package/dist/layout/flow.d.ts +193 -20
  6. package/dist/layout/flow.d.ts.map +1 -1
  7. package/dist/layout/flow.js +789 -101
  8. package/dist/layout/flow.js.map +1 -1
  9. package/dist/print.d.ts +22 -0
  10. package/dist/print.d.ts.map +1 -0
  11. package/dist/print.js +31 -0
  12. package/dist/print.js.map +1 -0
  13. package/dist/view.d.ts +220 -7
  14. package/dist/view.d.ts.map +1 -1
  15. package/dist/view.js +1753 -208
  16. package/dist/view.js.map +1 -1
  17. package/dist/word/blocks.d.ts +30 -1
  18. package/dist/word/blocks.d.ts.map +1 -1
  19. package/dist/word/blocks.js +193 -40
  20. package/dist/word/blocks.js.map +1 -1
  21. package/dist/word/columns.d.ts +23 -0
  22. package/dist/word/columns.d.ts.map +1 -0
  23. package/dist/word/columns.js +51 -0
  24. package/dist/word/columns.js.map +1 -0
  25. package/dist/word/controls.d.ts +63 -0
  26. package/dist/word/controls.d.ts.map +1 -0
  27. package/dist/word/controls.js +411 -0
  28. package/dist/word/controls.js.map +1 -0
  29. package/dist/word/edit.d.ts +17 -5
  30. package/dist/word/edit.d.ts.map +1 -1
  31. package/dist/word/edit.js +157 -26
  32. package/dist/word/edit.js.map +1 -1
  33. package/dist/word/matches.d.ts +23 -0
  34. package/dist/word/matches.d.ts.map +1 -0
  35. package/dist/word/matches.js +97 -0
  36. package/dist/word/matches.js.map +1 -0
  37. package/dist/word/notes.d.ts +105 -0
  38. package/dist/word/notes.d.ts.map +1 -0
  39. package/dist/word/notes.js +392 -0
  40. package/dist/word/notes.js.map +1 -0
  41. package/dist/word/pages.d.ts +18 -13
  42. package/dist/word/pages.d.ts.map +1 -1
  43. package/dist/word/pages.js +420 -229
  44. package/dist/word/pages.js.map +1 -1
  45. package/dist/word/regions.d.ts +113 -0
  46. package/dist/word/regions.d.ts.map +1 -0
  47. package/dist/word/regions.js +374 -0
  48. package/dist/word/regions.js.map +1 -0
  49. package/package.json +2 -2
  50. package/src/clipboard.ts +3 -0
  51. package/src/layout/flow.ts +945 -110
  52. package/src/print.ts +48 -0
  53. package/src/view.ts +1957 -229
  54. package/src/word/blocks.ts +219 -36
  55. package/src/word/columns.ts +66 -0
  56. package/src/word/controls.ts +447 -0
  57. package/src/word/edit.ts +175 -23
  58. package/src/word/matches.ts +99 -0
  59. package/src/word/notes.ts +451 -0
  60. package/src/word/pages.ts +501 -220
  61. package/src/word/regions.ts +469 -0
package/src/print.ts ADDED
@@ -0,0 +1,48 @@
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
+ /** The attribute naming a page's page setup (its index among the document's) for print. */
7
+ export const SHEET_ATTR = "data-foli-sheet";
8
+
9
+ /** A page setup as print sees it: its sheet's size (CSS lengths) and its `SHEET_ATTR` value. */
10
+ export interface PrintSheet {
11
+ readonly width: string;
12
+ readonly height: string;
13
+ readonly index: number;
14
+ }
15
+
16
+ /**
17
+ * Print rules for the page elements `pages` selects: one sheet of its page setup's size per page
18
+ * (`last`'s, the document's last section, where named pages are not supported), without margins
19
+ * (the page's padding holds them). A page is exactly as tall as a sheet (the flow keeps content
20
+ * inside it; the exact height absorbs its half-pixel slack), with no gap after it. Content taller
21
+ * than a page (a line taller than a page) is not cut: it prints over the next sheet. `name` makes
22
+ * the named pages unique on the web page.
23
+ */
24
+ export function printStyles(
25
+ pages: string,
26
+ last: Pick<PrintSheet, "width" | "height">,
27
+ sheets: readonly PrintSheet[],
28
+ name: string,
29
+ ): string {
30
+ // Sections with other page sizes: a named page each (engines without named pages print
31
+ // every sheet at the last section's size).
32
+ const named = sheets.every((s) => s.width === last.width && s.height === last.height)
33
+ ? ""
34
+ : sheets
35
+ .map(({ width, height, index }) => {
36
+ const page = `foli-${name}-${index}`;
37
+ return (
38
+ `@page ${page}{size:${width} ${height};margin:0}` +
39
+ `${pages}[${SHEET_ATTR}="${index}"]{page:${page};height:${height}!important}`
40
+ );
41
+ })
42
+ .join("");
43
+ return (
44
+ `@media print{@page{size:${last.width} ${last.height};margin:0}` +
45
+ `${pages}{height:${last.height}!important;margin-block:0!important;` +
46
+ `break-after:page;break-inside:avoid}${pages}:last-child{break-after:auto}${named}}`
47
+ );
48
+ }