doc-codec 1.0.2 → 1.1.1

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 (112) hide show
  1. package/README.md +192 -50
  2. package/dist/color.cjs +166 -0
  3. package/dist/color.d.cts +20 -0
  4. package/dist/color.d.ts +20 -0
  5. package/dist/color.js +160 -0
  6. package/dist/detect.cjs +3 -0
  7. package/dist/detect.d.cts +3 -1
  8. package/dist/detect.d.ts +3 -1
  9. package/dist/detect.js +3 -1
  10. package/dist/fib/fib.cjs +9 -1
  11. package/dist/fib/fib.d.cts +1 -28
  12. package/dist/fib/fib.d.ts +1 -28
  13. package/dist/fib/fib.js +9 -1
  14. package/dist/fib/offsets.cjs +9 -1
  15. package/dist/fib/offsets.d.cts +8 -0
  16. package/dist/fib/offsets.d.ts +8 -0
  17. package/dist/fib/offsets.js +9 -1
  18. package/dist/fib/write.cjs +43 -0
  19. package/dist/fib/write.d.cts +21 -0
  20. package/dist/fib/write.d.ts +21 -0
  21. package/dist/fib/write.js +42 -0
  22. package/dist/fib-CtsLtF96.d.cts +37 -0
  23. package/dist/fib-CtsLtF96.d.ts +37 -0
  24. package/dist/index.cjs +31 -0
  25. package/dist/index.d.cts +18 -7
  26. package/dist/index.d.ts +18 -7
  27. package/dist/index.js +14 -3
  28. package/dist/list/numbering.cjs +206 -0
  29. package/dist/list/numbering.d.cts +2 -0
  30. package/dist/list/numbering.d.ts +2 -0
  31. package/dist/list/numbering.js +205 -0
  32. package/dist/metadata.cjs +14 -0
  33. package/dist/metadata.d.cts +6 -0
  34. package/dist/metadata.d.ts +6 -0
  35. package/dist/metadata.js +13 -0
  36. package/dist/numbering-Cir-uGdc.d.cts +22 -0
  37. package/dist/numbering-DF1z1PyG.d.ts +22 -0
  38. package/dist/pap-BkFo8dZO.d.ts +29 -0
  39. package/dist/pap-BmelEYEP.d.cts +29 -0
  40. package/dist/prop/chp-write.cjs +47 -0
  41. package/dist/prop/chp-write.d.cts +5 -0
  42. package/dist/prop/chp-write.d.ts +5 -0
  43. package/dist/prop/chp-write.js +46 -0
  44. package/dist/prop/chp.cjs +15 -107
  45. package/dist/prop/chp.d.cts +3 -2
  46. package/dist/prop/chp.d.ts +3 -2
  47. package/dist/prop/chp.js +15 -107
  48. package/dist/prop/fkp-write.cjs +139 -0
  49. package/dist/prop/fkp-write.d.cts +21 -0
  50. package/dist/prop/fkp-write.d.ts +21 -0
  51. package/dist/prop/fkp-write.js +135 -0
  52. package/dist/prop/pap-write.cjs +67 -0
  53. package/dist/prop/pap-write.d.cts +5 -0
  54. package/dist/prop/pap-write.d.ts +5 -0
  55. package/dist/prop/pap-write.js +66 -0
  56. package/dist/prop/pap.cjs +10 -0
  57. package/dist/prop/pap.d.cts +1 -24
  58. package/dist/prop/pap.d.ts +1 -24
  59. package/dist/prop/pap.js +11 -1
  60. package/dist/prop/sep-write.cjs +63 -0
  61. package/dist/prop/sep-write.d.cts +9 -0
  62. package/dist/prop/sep-write.d.ts +9 -0
  63. package/dist/prop/sep-write.js +60 -0
  64. package/dist/prop/sep.cjs +63 -0
  65. package/dist/prop/sep.d.cts +16 -0
  66. package/dist/prop/sep.d.ts +16 -0
  67. package/dist/prop/sep.js +61 -0
  68. package/dist/prop/sprm.d.cts +1 -25
  69. package/dist/prop/sprm.d.ts +1 -25
  70. package/dist/read.cjs +44 -18
  71. package/dist/read.d.cts +21 -4
  72. package/dist/read.d.ts +21 -4
  73. package/dist/read.js +46 -20
  74. package/dist/sprm-Djg5RNiq.d.cts +26 -0
  75. package/dist/sprm-Djg5RNiq.d.ts +26 -0
  76. package/dist/style/fonts.cjs +68 -0
  77. package/dist/style/fonts.d.cts +5 -0
  78. package/dist/style/fonts.d.ts +5 -0
  79. package/dist/style/fonts.js +66 -0
  80. package/dist/style/stsh.cjs +23 -0
  81. package/dist/style/stsh.d.cts +2 -1
  82. package/dist/style/stsh.d.ts +2 -1
  83. package/dist/style/stsh.js +23 -1
  84. package/dist/table/decoration.cjs +220 -0
  85. package/dist/table/decoration.d.cts +41 -0
  86. package/dist/table/decoration.d.ts +41 -0
  87. package/dist/table/decoration.js +205 -0
  88. package/dist/table/read.cjs +192 -0
  89. package/dist/table/read.d.cts +6 -0
  90. package/dist/table/read.d.ts +6 -0
  91. package/dist/table/read.js +191 -0
  92. package/dist/table/tap-write.cjs +125 -0
  93. package/dist/table/tap-write.d.cts +13 -0
  94. package/dist/table/tap-write.d.ts +13 -0
  95. package/dist/table/tap-write.js +124 -0
  96. package/dist/table/tap.cjs +217 -0
  97. package/dist/table/tap.d.cts +29 -0
  98. package/dist/table/tap.d.ts +29 -0
  99. package/dist/table/tap.js +213 -0
  100. package/dist/table/write.cjs +136 -0
  101. package/dist/table/write.d.cts +13 -0
  102. package/dist/table/write.d.ts +13 -0
  103. package/dist/table/write.js +135 -0
  104. package/dist/text/piece-table-write.cjs +24 -0
  105. package/dist/text/piece-table-write.d.cts +4 -0
  106. package/dist/text/piece-table-write.d.ts +4 -0
  107. package/dist/text/piece-table-write.js +23 -0
  108. package/dist/write.cjs +175 -0
  109. package/dist/write.d.cts +5 -0
  110. package/dist/write.d.ts +5 -0
  111. package/dist/write.js +174 -0
  112. package/package.json +3 -3
package/dist/color.cjs ADDED
@@ -0,0 +1,166 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("./errors.cjs");
3
+ const require_bytes = require("./bytes.cjs");
4
+ //#region src/color.ts
5
+ const COLOR_COMPONENT_MAX = 255;
6
+ const ICO_PALETTE = [
7
+ void 0,
8
+ [
9
+ 0,
10
+ 0,
11
+ 0
12
+ ],
13
+ [
14
+ 0,
15
+ 0,
16
+ 255
17
+ ],
18
+ [
19
+ 0,
20
+ 255,
21
+ 255
22
+ ],
23
+ [
24
+ 0,
25
+ 255,
26
+ 0
27
+ ],
28
+ [
29
+ 255,
30
+ 0,
31
+ 255
32
+ ],
33
+ [
34
+ 255,
35
+ 0,
36
+ 0
37
+ ],
38
+ [
39
+ 255,
40
+ 255,
41
+ 0
42
+ ],
43
+ [
44
+ 255,
45
+ 255,
46
+ 255
47
+ ],
48
+ [
49
+ 0,
50
+ 0,
51
+ 128
52
+ ],
53
+ [
54
+ 0,
55
+ 128,
56
+ 128
57
+ ],
58
+ [
59
+ 0,
60
+ 128,
61
+ 0
62
+ ],
63
+ [
64
+ 128,
65
+ 0,
66
+ 128
67
+ ],
68
+ [
69
+ 128,
70
+ 0,
71
+ 128
72
+ ],
73
+ [
74
+ 128,
75
+ 128,
76
+ 0
77
+ ],
78
+ [
79
+ 128,
80
+ 128,
81
+ 128
82
+ ],
83
+ [
84
+ 192,
85
+ 192,
86
+ 192
87
+ ]
88
+ ];
89
+ /** The first Ico value naming a concrete colour: 0x00 is cvAuto and names none, so nearestIco never returns it. */
90
+ const FIRST_CONCRETE_ICO = 1;
91
+ /** The colour an Ico value names, or undefined for 0x00 (fAuto, "the default color for the application", which names no concrete colour). Throws for a value outside the palette's own published bound rather than resolving it to something. */
92
+ function icoColor(value) {
93
+ if (value >= ICO_PALETTE.length) throw new require_errors.DocFormatError(`Ico value 0x${value.toString(16)} is not less than 0x11, the bound [MS-DOC] 2.9.119 places on the palette`);
94
+ const entry = ICO_PALETTE[value];
95
+ if (entry === void 0) return void 0;
96
+ const [r, g, b] = entry;
97
+ return {
98
+ r: r / COLOR_COMPONENT_MAX,
99
+ g: g / COLOR_COMPONENT_MAX,
100
+ b: b / COLOR_COMPONENT_MAX
101
+ };
102
+ }
103
+ /** icoColor's own decorative counterpart: an out-of-range Ico value resolves to undefined (the same "no concrete colour" spelling 0x00/cvAuto already carries) rather than throwing. icoColor's hard bound stays exactly as it is for a run's sprmCIco, where an out-of-range value states a specific, load-bearing colour this reader must not silently drop -- but Brc80.ico and Shd80's icoFore/icoBack (table/decoration.ts) are cosmetic fields already reached through a chain of automatic-colour fallbacks of their own (borderFrom's own AUTOMATIC_BORDER_COLOR, readShd80's own undefined return for an unrecognised pattern), so one out-of-range byte in a single cell's border or fill should not abort reading the entire document the way it correctly does for a run's own explicit, load-bearing colour. */
104
+ function decorativeIcoColor(value) {
105
+ return value >= ICO_PALETTE.length ? void 0 : icoColor(value);
106
+ }
107
+ /**
108
+ * The Ico value whose own colour is closest to `color`, by squared distance in sRGB, over the sixteen entries that name a concrete colour -- 0x00 (cvAuto) is never returned, since it names none. Ties resolve to the lower Ico, which makes the answer depend only on the colour asked about and not on iteration order (it also settles 0x0C/0x0D, the one duplicated pair in the published palette, on 0x0C).
109
+ *
110
+ * This is a genuinely lossy quantisation and is only ever used where [MS-DOC] itself offers no better field: Brc80.ico, the border colour a TC80 can carry at all. Wherever the format has an exact spelling beside it -- Brc.cv, reached through sprmTSetBrc -- this package writes that too, so nothing downstream has to read the approximation back (see table/decoration.ts and the README's own Tables section).
111
+ */
112
+ function nearestIco(color) {
113
+ let best = FIRST_CONCRETE_ICO;
114
+ let bestDistance = Number.POSITIVE_INFINITY;
115
+ for (let value = FIRST_CONCRETE_ICO; value < ICO_PALETTE.length; value += 1) {
116
+ const entry = ICO_PALETTE[value];
117
+ if (entry === void 0) continue;
118
+ const [r, g, b] = entry;
119
+ const dr = color.r - r / COLOR_COMPONENT_MAX;
120
+ const dg = color.g - g / COLOR_COMPONENT_MAX;
121
+ const db = color.b - b / COLOR_COMPONENT_MAX;
122
+ const distance = dr * dr + dg * dg + db * db;
123
+ if (distance < bestDistance) {
124
+ bestDistance = distance;
125
+ best = value;
126
+ }
127
+ }
128
+ return best;
129
+ }
130
+ /** COLORREF's fAuto, [MS-DOC] 2.9.43: "If fAuto is 0xFF, this COLORREF designates the default color for the application", which the specification names cvAuto. */
131
+ const F_AUTO_SET = 255;
132
+ /** COLORREF, [MS-DOC] 2.9.43: red, green and blue bytes followed by fAuto. Returns undefined for cvAuto (fAuto set), which designates the application's own default colour rather than the components beside it -- the caller decides what that means for the property it is reading. */
133
+ function readColorRef(bytes, offset) {
134
+ if (require_bytes.readUint8(bytes, offset + 3) !== 0) return void 0;
135
+ return {
136
+ r: require_bytes.readUint8(bytes, offset) / COLOR_COMPONENT_MAX,
137
+ g: require_bytes.readUint8(bytes, offset + 1) / COLOR_COMPONENT_MAX,
138
+ b: require_bytes.readUint8(bytes, offset + 2) / COLOR_COMPONENT_MAX
139
+ };
140
+ }
141
+ /** The inverse of readColorRef for a concrete colour: red, green, blue, then fAuto 0x00 ("use these components"), the only form this package writes. */
142
+ function colorRefBytes(color) {
143
+ const byte = (component) => Math.round(component * COLOR_COMPONENT_MAX);
144
+ return [
145
+ byte(color.r),
146
+ byte(color.g),
147
+ byte(color.b),
148
+ 0
149
+ ];
150
+ }
151
+ /** cvAuto's own four bytes, [MS-DOC] 2.9.43: components zeroed with fAuto set. Written wherever a COLORREF field exists but this package has no colour to state for it -- a Shd's own cvFore under an ipatAuto pattern, for instance. */
152
+ function autoColorRefBytes() {
153
+ return [
154
+ 0,
155
+ 0,
156
+ 0,
157
+ F_AUTO_SET
158
+ ];
159
+ }
160
+ //#endregion
161
+ exports.autoColorRefBytes = autoColorRefBytes;
162
+ exports.colorRefBytes = colorRefBytes;
163
+ exports.decorativeIcoColor = decorativeIcoColor;
164
+ exports.icoColor = icoColor;
165
+ exports.nearestIco = nearestIco;
166
+ exports.readColorRef = readColorRef;
@@ -0,0 +1,20 @@
1
+ import { Color } from "document-schema.js";
2
+ //#region src/color.d.ts
3
+ /** The colour an Ico value names, or undefined for 0x00 (fAuto, "the default color for the application", which names no concrete colour). Throws for a value outside the palette's own published bound rather than resolving it to something. */
4
+ declare function icoColor(value: number): Color | undefined;
5
+ /** icoColor's own decorative counterpart: an out-of-range Ico value resolves to undefined (the same "no concrete colour" spelling 0x00/cvAuto already carries) rather than throwing. icoColor's hard bound stays exactly as it is for a run's sprmCIco, where an out-of-range value states a specific, load-bearing colour this reader must not silently drop -- but Brc80.ico and Shd80's icoFore/icoBack (table/decoration.ts) are cosmetic fields already reached through a chain of automatic-colour fallbacks of their own (borderFrom's own AUTOMATIC_BORDER_COLOR, readShd80's own undefined return for an unrecognised pattern), so one out-of-range byte in a single cell's border or fill should not abort reading the entire document the way it correctly does for a run's own explicit, load-bearing colour. */
6
+ declare function decorativeIcoColor(value: number): Color | undefined;
7
+ /**
8
+ * The Ico value whose own colour is closest to `color`, by squared distance in sRGB, over the sixteen entries that name a concrete colour -- 0x00 (cvAuto) is never returned, since it names none. Ties resolve to the lower Ico, which makes the answer depend only on the colour asked about and not on iteration order (it also settles 0x0C/0x0D, the one duplicated pair in the published palette, on 0x0C).
9
+ *
10
+ * This is a genuinely lossy quantisation and is only ever used where [MS-DOC] itself offers no better field: Brc80.ico, the border colour a TC80 can carry at all. Wherever the format has an exact spelling beside it -- Brc.cv, reached through sprmTSetBrc -- this package writes that too, so nothing downstream has to read the approximation back (see table/decoration.ts and the README's own Tables section).
11
+ */
12
+ declare function nearestIco(color: Color): number;
13
+ /** COLORREF, [MS-DOC] 2.9.43: red, green and blue bytes followed by fAuto. Returns undefined for cvAuto (fAuto set), which designates the application's own default colour rather than the components beside it -- the caller decides what that means for the property it is reading. */
14
+ declare function readColorRef(bytes: Uint8Array, offset: number): Color | undefined;
15
+ /** The inverse of readColorRef for a concrete colour: red, green, blue, then fAuto 0x00 ("use these components"), the only form this package writes. */
16
+ declare function colorRefBytes(color: Color): number[];
17
+ /** cvAuto's own four bytes, [MS-DOC] 2.9.43: components zeroed with fAuto set. Written wherever a COLORREF field exists but this package has no colour to state for it -- a Shd's own cvFore under an ipatAuto pattern, for instance. */
18
+ declare function autoColorRefBytes(): number[];
19
+ //#endregion
20
+ export { autoColorRefBytes, colorRefBytes, decorativeIcoColor, icoColor, nearestIco, readColorRef };
@@ -0,0 +1,20 @@
1
+ import { Color } from "document-schema.js";
2
+ //#region src/color.d.ts
3
+ /** The colour an Ico value names, or undefined for 0x00 (fAuto, "the default color for the application", which names no concrete colour). Throws for a value outside the palette's own published bound rather than resolving it to something. */
4
+ declare function icoColor(value: number): Color | undefined;
5
+ /** icoColor's own decorative counterpart: an out-of-range Ico value resolves to undefined (the same "no concrete colour" spelling 0x00/cvAuto already carries) rather than throwing. icoColor's hard bound stays exactly as it is for a run's sprmCIco, where an out-of-range value states a specific, load-bearing colour this reader must not silently drop -- but Brc80.ico and Shd80's icoFore/icoBack (table/decoration.ts) are cosmetic fields already reached through a chain of automatic-colour fallbacks of their own (borderFrom's own AUTOMATIC_BORDER_COLOR, readShd80's own undefined return for an unrecognised pattern), so one out-of-range byte in a single cell's border or fill should not abort reading the entire document the way it correctly does for a run's own explicit, load-bearing colour. */
6
+ declare function decorativeIcoColor(value: number): Color | undefined;
7
+ /**
8
+ * The Ico value whose own colour is closest to `color`, by squared distance in sRGB, over the sixteen entries that name a concrete colour -- 0x00 (cvAuto) is never returned, since it names none. Ties resolve to the lower Ico, which makes the answer depend only on the colour asked about and not on iteration order (it also settles 0x0C/0x0D, the one duplicated pair in the published palette, on 0x0C).
9
+ *
10
+ * This is a genuinely lossy quantisation and is only ever used where [MS-DOC] itself offers no better field: Brc80.ico, the border colour a TC80 can carry at all. Wherever the format has an exact spelling beside it -- Brc.cv, reached through sprmTSetBrc -- this package writes that too, so nothing downstream has to read the approximation back (see table/decoration.ts and the README's own Tables section).
11
+ */
12
+ declare function nearestIco(color: Color): number;
13
+ /** COLORREF, [MS-DOC] 2.9.43: red, green and blue bytes followed by fAuto. Returns undefined for cvAuto (fAuto set), which designates the application's own default colour rather than the components beside it -- the caller decides what that means for the property it is reading. */
14
+ declare function readColorRef(bytes: Uint8Array, offset: number): Color | undefined;
15
+ /** The inverse of readColorRef for a concrete colour: red, green, blue, then fAuto 0x00 ("use these components"), the only form this package writes. */
16
+ declare function colorRefBytes(color: Color): number[];
17
+ /** cvAuto's own four bytes, [MS-DOC] 2.9.43: components zeroed with fAuto set. Written wherever a COLORREF field exists but this package has no colour to state for it -- a Shd's own cvFore under an ipatAuto pattern, for instance. */
18
+ declare function autoColorRefBytes(): number[];
19
+ //#endregion
20
+ export { autoColorRefBytes, colorRefBytes, decorativeIcoColor, icoColor, nearestIco, readColorRef };
package/dist/color.js ADDED
@@ -0,0 +1,160 @@
1
+ import { DocFormatError } from "./errors.js";
2
+ import { readUint8 } from "./bytes.js";
3
+ //#region src/color.ts
4
+ const COLOR_COMPONENT_MAX = 255;
5
+ const ICO_PALETTE = [
6
+ void 0,
7
+ [
8
+ 0,
9
+ 0,
10
+ 0
11
+ ],
12
+ [
13
+ 0,
14
+ 0,
15
+ 255
16
+ ],
17
+ [
18
+ 0,
19
+ 255,
20
+ 255
21
+ ],
22
+ [
23
+ 0,
24
+ 255,
25
+ 0
26
+ ],
27
+ [
28
+ 255,
29
+ 0,
30
+ 255
31
+ ],
32
+ [
33
+ 255,
34
+ 0,
35
+ 0
36
+ ],
37
+ [
38
+ 255,
39
+ 255,
40
+ 0
41
+ ],
42
+ [
43
+ 255,
44
+ 255,
45
+ 255
46
+ ],
47
+ [
48
+ 0,
49
+ 0,
50
+ 128
51
+ ],
52
+ [
53
+ 0,
54
+ 128,
55
+ 128
56
+ ],
57
+ [
58
+ 0,
59
+ 128,
60
+ 0
61
+ ],
62
+ [
63
+ 128,
64
+ 0,
65
+ 128
66
+ ],
67
+ [
68
+ 128,
69
+ 0,
70
+ 128
71
+ ],
72
+ [
73
+ 128,
74
+ 128,
75
+ 0
76
+ ],
77
+ [
78
+ 128,
79
+ 128,
80
+ 128
81
+ ],
82
+ [
83
+ 192,
84
+ 192,
85
+ 192
86
+ ]
87
+ ];
88
+ /** The first Ico value naming a concrete colour: 0x00 is cvAuto and names none, so nearestIco never returns it. */
89
+ const FIRST_CONCRETE_ICO = 1;
90
+ /** The colour an Ico value names, or undefined for 0x00 (fAuto, "the default color for the application", which names no concrete colour). Throws for a value outside the palette's own published bound rather than resolving it to something. */
91
+ function icoColor(value) {
92
+ if (value >= ICO_PALETTE.length) throw new DocFormatError(`Ico value 0x${value.toString(16)} is not less than 0x11, the bound [MS-DOC] 2.9.119 places on the palette`);
93
+ const entry = ICO_PALETTE[value];
94
+ if (entry === void 0) return void 0;
95
+ const [r, g, b] = entry;
96
+ return {
97
+ r: r / COLOR_COMPONENT_MAX,
98
+ g: g / COLOR_COMPONENT_MAX,
99
+ b: b / COLOR_COMPONENT_MAX
100
+ };
101
+ }
102
+ /** icoColor's own decorative counterpart: an out-of-range Ico value resolves to undefined (the same "no concrete colour" spelling 0x00/cvAuto already carries) rather than throwing. icoColor's hard bound stays exactly as it is for a run's sprmCIco, where an out-of-range value states a specific, load-bearing colour this reader must not silently drop -- but Brc80.ico and Shd80's icoFore/icoBack (table/decoration.ts) are cosmetic fields already reached through a chain of automatic-colour fallbacks of their own (borderFrom's own AUTOMATIC_BORDER_COLOR, readShd80's own undefined return for an unrecognised pattern), so one out-of-range byte in a single cell's border or fill should not abort reading the entire document the way it correctly does for a run's own explicit, load-bearing colour. */
103
+ function decorativeIcoColor(value) {
104
+ return value >= ICO_PALETTE.length ? void 0 : icoColor(value);
105
+ }
106
+ /**
107
+ * The Ico value whose own colour is closest to `color`, by squared distance in sRGB, over the sixteen entries that name a concrete colour -- 0x00 (cvAuto) is never returned, since it names none. Ties resolve to the lower Ico, which makes the answer depend only on the colour asked about and not on iteration order (it also settles 0x0C/0x0D, the one duplicated pair in the published palette, on 0x0C).
108
+ *
109
+ * This is a genuinely lossy quantisation and is only ever used where [MS-DOC] itself offers no better field: Brc80.ico, the border colour a TC80 can carry at all. Wherever the format has an exact spelling beside it -- Brc.cv, reached through sprmTSetBrc -- this package writes that too, so nothing downstream has to read the approximation back (see table/decoration.ts and the README's own Tables section).
110
+ */
111
+ function nearestIco(color) {
112
+ let best = FIRST_CONCRETE_ICO;
113
+ let bestDistance = Number.POSITIVE_INFINITY;
114
+ for (let value = FIRST_CONCRETE_ICO; value < ICO_PALETTE.length; value += 1) {
115
+ const entry = ICO_PALETTE[value];
116
+ if (entry === void 0) continue;
117
+ const [r, g, b] = entry;
118
+ const dr = color.r - r / COLOR_COMPONENT_MAX;
119
+ const dg = color.g - g / COLOR_COMPONENT_MAX;
120
+ const db = color.b - b / COLOR_COMPONENT_MAX;
121
+ const distance = dr * dr + dg * dg + db * db;
122
+ if (distance < bestDistance) {
123
+ bestDistance = distance;
124
+ best = value;
125
+ }
126
+ }
127
+ return best;
128
+ }
129
+ /** COLORREF's fAuto, [MS-DOC] 2.9.43: "If fAuto is 0xFF, this COLORREF designates the default color for the application", which the specification names cvAuto. */
130
+ const F_AUTO_SET = 255;
131
+ /** COLORREF, [MS-DOC] 2.9.43: red, green and blue bytes followed by fAuto. Returns undefined for cvAuto (fAuto set), which designates the application's own default colour rather than the components beside it -- the caller decides what that means for the property it is reading. */
132
+ function readColorRef(bytes, offset) {
133
+ if (readUint8(bytes, offset + 3) !== 0) return void 0;
134
+ return {
135
+ r: readUint8(bytes, offset) / COLOR_COMPONENT_MAX,
136
+ g: readUint8(bytes, offset + 1) / COLOR_COMPONENT_MAX,
137
+ b: readUint8(bytes, offset + 2) / COLOR_COMPONENT_MAX
138
+ };
139
+ }
140
+ /** The inverse of readColorRef for a concrete colour: red, green, blue, then fAuto 0x00 ("use these components"), the only form this package writes. */
141
+ function colorRefBytes(color) {
142
+ const byte = (component) => Math.round(component * COLOR_COMPONENT_MAX);
143
+ return [
144
+ byte(color.r),
145
+ byte(color.g),
146
+ byte(color.b),
147
+ 0
148
+ ];
149
+ }
150
+ /** cvAuto's own four bytes, [MS-DOC] 2.9.43: components zeroed with fAuto set. Written wherever a COLORREF field exists but this package has no colour to state for it -- a Shd's own cvFore under an ipatAuto pattern, for instance. */
151
+ function autoColorRefBytes() {
152
+ return [
153
+ 0,
154
+ 0,
155
+ 0,
156
+ F_AUTO_SET
157
+ ];
158
+ }
159
+ //#endregion
160
+ export { autoColorRefBytes, colorRefBytes, decorativeIcoColor, icoColor, nearestIco, readColorRef };
package/dist/detect.cjs CHANGED
@@ -5,6 +5,8 @@ let archive_codec = require("archive-codec");
5
5
  //#region src/detect.ts
6
6
  /** The stream a Word Binary File's FIB and text live in, [MS-DOC] 2.1.1. */
7
7
  const WORD_DOCUMENT_STREAM = "WordDocument";
8
+ /** The [MS-OLEPS] Property Set Stream a .doc's title/author/dates live in when present -- a genuinely optional stream, unlike WordDocument, since a valid Word Binary File need not carry document properties at all. */
9
+ const SUMMARY_INFORMATION_STREAM = "SummaryInformation";
8
10
  function isDocBytes(bytes) {
9
11
  if (!(0, archive_codec.isCompoundFile)(bytes)) return false;
10
12
  let streams;
@@ -18,5 +20,6 @@ function isDocBytes(bytes) {
18
20
  return require_bytes.readUint16LE(wordDocument.bytes, 0) === require_fib_offsets.FIB_W_IDENT;
19
21
  }
20
22
  //#endregion
23
+ exports.SUMMARY_INFORMATION_STREAM = SUMMARY_INFORMATION_STREAM;
21
24
  exports.WORD_DOCUMENT_STREAM = WORD_DOCUMENT_STREAM;
22
25
  exports.isDocBytes = isDocBytes;
package/dist/detect.d.cts CHANGED
@@ -1,6 +1,8 @@
1
1
  //#region src/detect.d.ts
2
2
  /** The stream a Word Binary File's FIB and text live in, [MS-DOC] 2.1.1. */
3
3
  declare const WORD_DOCUMENT_STREAM = "WordDocument";
4
+ /** The [MS-OLEPS] Property Set Stream a .doc's title/author/dates live in when present -- a genuinely optional stream, unlike WordDocument, since a valid Word Binary File need not carry document properties at all. */
5
+ declare const SUMMARY_INFORMATION_STREAM = "SummaryInformation";
4
6
  declare function isDocBytes(bytes: Uint8Array<ArrayBuffer>): boolean;
5
7
  //#endregion
6
- export { WORD_DOCUMENT_STREAM, isDocBytes };
8
+ export { SUMMARY_INFORMATION_STREAM, WORD_DOCUMENT_STREAM, isDocBytes };
package/dist/detect.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  //#region src/detect.d.ts
2
2
  /** The stream a Word Binary File's FIB and text live in, [MS-DOC] 2.1.1. */
3
3
  declare const WORD_DOCUMENT_STREAM = "WordDocument";
4
+ /** The [MS-OLEPS] Property Set Stream a .doc's title/author/dates live in when present -- a genuinely optional stream, unlike WordDocument, since a valid Word Binary File need not carry document properties at all. */
5
+ declare const SUMMARY_INFORMATION_STREAM = "SummaryInformation";
4
6
  declare function isDocBytes(bytes: Uint8Array<ArrayBuffer>): boolean;
5
7
  //#endregion
6
- export { WORD_DOCUMENT_STREAM, isDocBytes };
8
+ export { SUMMARY_INFORMATION_STREAM, WORD_DOCUMENT_STREAM, isDocBytes };
package/dist/detect.js CHANGED
@@ -4,6 +4,8 @@ import { isCompoundFile, readCompoundFile } from "archive-codec";
4
4
  //#region src/detect.ts
5
5
  /** The stream a Word Binary File's FIB and text live in, [MS-DOC] 2.1.1. */
6
6
  const WORD_DOCUMENT_STREAM = "WordDocument";
7
+ /** The [MS-OLEPS] Property Set Stream a .doc's title/author/dates live in when present -- a genuinely optional stream, unlike WordDocument, since a valid Word Binary File need not carry document properties at all. */
8
+ const SUMMARY_INFORMATION_STREAM = "SummaryInformation";
7
9
  function isDocBytes(bytes) {
8
10
  if (!isCompoundFile(bytes)) return false;
9
11
  let streams;
@@ -17,4 +19,4 @@ function isDocBytes(bytes) {
17
19
  return readUint16LE(wordDocument.bytes, 0) === FIB_W_IDENT;
18
20
  }
19
21
  //#endregion
20
- export { WORD_DOCUMENT_STREAM, isDocBytes };
22
+ export { SUMMARY_INFORMATION_STREAM, WORD_DOCUMENT_STREAM, isDocBytes };
package/dist/fib/fib.cjs CHANGED
@@ -38,7 +38,15 @@ function parseFib(wordDocument) {
38
38
  fcPlcfBtePapx: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlcfBtePapx),
39
39
  lcbPlcfBtePapx: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbPlcfBtePapx),
40
40
  fcClx: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcClx),
41
- lcbClx: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbClx)
41
+ lcbClx: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbClx),
42
+ fcPlcfSed: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlcfSed),
43
+ lcbPlcfSed: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbPlcfSed),
44
+ fcSttbfFfn: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcSttbfFfn),
45
+ lcbSttbfFfn: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbSttbfFfn),
46
+ fcPlfLst: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlfLst),
47
+ lcbPlfLst: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbPlfLst),
48
+ fcPlfLfo: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlfLfo),
49
+ lcbPlfLfo: fcLcb(require_fib_offsets.FC_LCB_VALUE_INDEX.lcbPlfLfo)
42
50
  };
43
51
  }
44
52
  /** The name of the compound-file stream every `fc` offset in the Fib is relative to, selected by FibBase.fWhichTblStm. */
@@ -1,29 +1,2 @@
1
- //#region src/fib/fib.d.ts
2
- interface Fib {
3
- readonly nFib: number;
4
- /** Set when the last save was an incremental ("fast") save. The piece table is what makes such a document readable at all, so this is informational rather than a refusal. */
5
- readonly fComplex: boolean;
6
- /** 1 selects the "1Table" stream, 0 the "0Table" stream, as the Table stream every fc offset below is relative to. */
7
- readonly fWhichTblStm: 0 | 1;
8
- readonly cbMac: number;
9
- readonly ccpText: number;
10
- readonly ccpFtn: number;
11
- readonly ccpHdd: number;
12
- readonly ccpAtn: number;
13
- readonly ccpEdn: number;
14
- readonly ccpTxbx: number;
15
- readonly ccpHdrTxbx: number;
16
- readonly fcStshf: number;
17
- readonly lcbStshf: number;
18
- readonly fcPlcfBteChpx: number;
19
- readonly lcbPlcfBteChpx: number;
20
- readonly fcPlcfBtePapx: number;
21
- readonly lcbPlcfBtePapx: number;
22
- readonly fcClx: number;
23
- readonly lcbClx: number;
24
- }
25
- declare function parseFib(wordDocument: Uint8Array): Fib;
26
- /** The name of the compound-file stream every `fc` offset in the Fib is relative to, selected by FibBase.fWhichTblStm. */
27
- declare function tableStreamName(fib: Fib): "0Table" | "1Table";
28
- //#endregion
1
+ import { n as parseFib, r as tableStreamName, t as Fib } from "../fib-CtsLtF96.cjs";
29
2
  export { Fib, parseFib, tableStreamName };
package/dist/fib/fib.d.ts CHANGED
@@ -1,29 +1,2 @@
1
- //#region src/fib/fib.d.ts
2
- interface Fib {
3
- readonly nFib: number;
4
- /** Set when the last save was an incremental ("fast") save. The piece table is what makes such a document readable at all, so this is informational rather than a refusal. */
5
- readonly fComplex: boolean;
6
- /** 1 selects the "1Table" stream, 0 the "0Table" stream, as the Table stream every fc offset below is relative to. */
7
- readonly fWhichTblStm: 0 | 1;
8
- readonly cbMac: number;
9
- readonly ccpText: number;
10
- readonly ccpFtn: number;
11
- readonly ccpHdd: number;
12
- readonly ccpAtn: number;
13
- readonly ccpEdn: number;
14
- readonly ccpTxbx: number;
15
- readonly ccpHdrTxbx: number;
16
- readonly fcStshf: number;
17
- readonly lcbStshf: number;
18
- readonly fcPlcfBteChpx: number;
19
- readonly lcbPlcfBteChpx: number;
20
- readonly fcPlcfBtePapx: number;
21
- readonly lcbPlcfBtePapx: number;
22
- readonly fcClx: number;
23
- readonly lcbClx: number;
24
- }
25
- declare function parseFib(wordDocument: Uint8Array): Fib;
26
- /** The name of the compound-file stream every `fc` offset in the Fib is relative to, selected by FibBase.fWhichTblStm. */
27
- declare function tableStreamName(fib: Fib): "0Table" | "1Table";
28
- //#endregion
1
+ import { n as parseFib, r as tableStreamName, t as Fib } from "../fib-CtsLtF96.js";
29
2
  export { Fib, parseFib, tableStreamName };
package/dist/fib/fib.js CHANGED
@@ -37,7 +37,15 @@ function parseFib(wordDocument) {
37
37
  fcPlcfBtePapx: fcLcb(FC_LCB_VALUE_INDEX.fcPlcfBtePapx),
38
38
  lcbPlcfBtePapx: fcLcb(FC_LCB_VALUE_INDEX.lcbPlcfBtePapx),
39
39
  fcClx: fcLcb(FC_LCB_VALUE_INDEX.fcClx),
40
- lcbClx: fcLcb(FC_LCB_VALUE_INDEX.lcbClx)
40
+ lcbClx: fcLcb(FC_LCB_VALUE_INDEX.lcbClx),
41
+ fcPlcfSed: fcLcb(FC_LCB_VALUE_INDEX.fcPlcfSed),
42
+ lcbPlcfSed: fcLcb(FC_LCB_VALUE_INDEX.lcbPlcfSed),
43
+ fcSttbfFfn: fcLcb(FC_LCB_VALUE_INDEX.fcSttbfFfn),
44
+ lcbSttbfFfn: fcLcb(FC_LCB_VALUE_INDEX.lcbSttbfFfn),
45
+ fcPlfLst: fcLcb(FC_LCB_VALUE_INDEX.fcPlfLst),
46
+ lcbPlfLst: fcLcb(FC_LCB_VALUE_INDEX.lcbPlfLst),
47
+ fcPlfLfo: fcLcb(FC_LCB_VALUE_INDEX.fcPlfLfo),
48
+ lcbPlfLfo: fcLcb(FC_LCB_VALUE_INDEX.lcbPlfLfo)
41
49
  };
42
50
  }
43
51
  /** The name of the compound-file stream every `fc` offset in the Fib is relative to, selected by FibBase.fWhichTblStm. */
@@ -30,12 +30,20 @@ const LW_OFFSET = {
30
30
  const FC_LCB_VALUE_INDEX = {
31
31
  fcStshf: 2,
32
32
  lcbStshf: 3,
33
+ fcPlcfSed: 12,
34
+ lcbPlcfSed: 13,
33
35
  fcPlcfBteChpx: 24,
34
36
  lcbPlcfBteChpx: 25,
35
37
  fcPlcfBtePapx: 26,
36
38
  lcbPlcfBtePapx: 27,
39
+ fcSttbfFfn: 30,
40
+ lcbSttbfFfn: 31,
37
41
  fcClx: 66,
38
- lcbClx: 67
42
+ lcbClx: 67,
43
+ fcPlfLst: 146,
44
+ lcbPlfLst: 147,
45
+ fcPlfLfo: 148,
46
+ lcbPlfLfo: 149
39
47
  };
40
48
  const FIB_BASE_FLAG = {
41
49
  fComplex: 4,
@@ -29,12 +29,20 @@ declare const LW_OFFSET: {
29
29
  declare const FC_LCB_VALUE_INDEX: {
30
30
  readonly fcStshf: 2;
31
31
  readonly lcbStshf: 3;
32
+ readonly fcPlcfSed: 12;
33
+ readonly lcbPlcfSed: 13;
32
34
  readonly fcPlcfBteChpx: 24;
33
35
  readonly lcbPlcfBteChpx: 25;
34
36
  readonly fcPlcfBtePapx: 26;
35
37
  readonly lcbPlcfBtePapx: 27;
38
+ readonly fcSttbfFfn: 30;
39
+ readonly lcbSttbfFfn: 31;
36
40
  readonly fcClx: 66;
37
41
  readonly lcbClx: 67;
42
+ readonly fcPlfLst: 146;
43
+ readonly lcbPlfLst: 147;
44
+ readonly fcPlfLfo: 148;
45
+ readonly lcbPlfLfo: 149;
38
46
  };
39
47
  declare const FIB_BASE_FLAG: {
40
48
  readonly fComplex: 4;
@@ -29,12 +29,20 @@ declare const LW_OFFSET: {
29
29
  declare const FC_LCB_VALUE_INDEX: {
30
30
  readonly fcStshf: 2;
31
31
  readonly lcbStshf: 3;
32
+ readonly fcPlcfSed: 12;
33
+ readonly lcbPlcfSed: 13;
32
34
  readonly fcPlcfBteChpx: 24;
33
35
  readonly lcbPlcfBteChpx: 25;
34
36
  readonly fcPlcfBtePapx: 26;
35
37
  readonly lcbPlcfBtePapx: 27;
38
+ readonly fcSttbfFfn: 30;
39
+ readonly lcbSttbfFfn: 31;
36
40
  readonly fcClx: 66;
37
41
  readonly lcbClx: 67;
42
+ readonly fcPlfLst: 146;
43
+ readonly lcbPlfLst: 147;
44
+ readonly fcPlfLfo: 148;
45
+ readonly lcbPlfLfo: 149;
38
46
  };
39
47
  declare const FIB_BASE_FLAG: {
40
48
  readonly fComplex: 4;
@@ -29,12 +29,20 @@ const LW_OFFSET = {
29
29
  const FC_LCB_VALUE_INDEX = {
30
30
  fcStshf: 2,
31
31
  lcbStshf: 3,
32
+ fcPlcfSed: 12,
33
+ lcbPlcfSed: 13,
32
34
  fcPlcfBteChpx: 24,
33
35
  lcbPlcfBteChpx: 25,
34
36
  fcPlcfBtePapx: 26,
35
37
  lcbPlcfBtePapx: 27,
38
+ fcSttbfFfn: 30,
39
+ lcbSttbfFfn: 31,
36
40
  fcClx: 66,
37
- lcbClx: 67
41
+ lcbClx: 67,
42
+ fcPlfLst: 146,
43
+ lcbPlfLst: 147,
44
+ fcPlfLfo: 148,
45
+ lcbPlfLfo: 149
38
46
  };
39
47
  const FIB_BASE_FLAG = {
40
48
  fComplex: 4,
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors.cjs");
3
+ const require_bytes = require("../bytes.cjs");
4
+ const require_fib_offsets = require("./offsets.cjs");
5
+ //#region src/fib/write.ts
6
+ /** [MS-DOC]'s own Fib page: nFib 0x00C1 mandates cbRgFcLcb 0x005D and cswNew 0. */
7
+ const NFIB_WORD_97 = 193;
8
+ const CB_RG_FC_LCB_WORD_97 = 93;
9
+ /** FibBase.nFibBack: "this value SHOULD be 0x00BF" for a document written by an application that does not need older-version compatibility beyond it -- carried verbatim from test-support/fib.ts, which cites the same field. */
10
+ const N_FIB_BACK = 191;
11
+ /** FibBase's own flags word at offset 10: fExtChar "MUST be 1" ([MS-DOC] 2.5.2), independent of fComplex/fWhichTblStm/fEncrypted/fObfuscated (see offsets.ts's own FIB_BASE_FLAG). */
12
+ const FLAG_F_EXT_CHAR = 4096;
13
+ function buildFib(spec) {
14
+ const bytes = /* @__PURE__ */ new Uint8Array(900);
15
+ const view = new DataView(bytes.buffer);
16
+ view.setUint16(0, require_fib_offsets.FIB_W_IDENT, true);
17
+ view.setUint16(2, NFIB_WORD_97, true);
18
+ view.setUint16(10, FLAG_F_EXT_CHAR | require_fib_offsets.FIB_BASE_FLAG.fWhichTblStm, true);
19
+ view.setUint16(12, N_FIB_BACK, true);
20
+ view.setUint16(32, 14, true);
21
+ view.setUint16(62, 22, true);
22
+ const lw = (offset, value) => {
23
+ view.setInt32(64 + offset, value, true);
24
+ };
25
+ lw(require_fib_offsets.LW_OFFSET.cbMac, spec.cbMac);
26
+ lw(require_fib_offsets.LW_OFFSET.ccpText, spec.ccpText);
27
+ view.setUint16(152, CB_RG_FC_LCB_WORD_97, true);
28
+ const pair = (index, fc, lcb) => {
29
+ const offset = 154 + index * 4;
30
+ view.setUint32(offset, fc, true);
31
+ view.setUint32(offset + 4, lcb, true);
32
+ };
33
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcStshf, spec.fcStshf, spec.lcbStshf);
34
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlcfBteChpx, spec.fcPlcfBteChpx, spec.lcbPlcfBteChpx);
35
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlcfBtePapx, spec.fcPlcfBtePapx, spec.lcbPlcfBtePapx);
36
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcSttbfFfn, spec.fcSttbfFfn, spec.lcbSttbfFfn);
37
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcClx, spec.fcClx, spec.lcbClx);
38
+ pair(require_fib_offsets.FC_LCB_VALUE_INDEX.fcPlcfSed, spec.fcPlcfSed, spec.lcbPlcfSed);
39
+ if (require_bytes.readUint16LE(bytes, 0) !== 42476) throw new require_errors.DocFormatError("buildFib produced a Fib whose own wIdent does not read back as 0xA5EC; this is an internal defect, not an input error");
40
+ return bytes;
41
+ }
42
+ //#endregion
43
+ exports.buildFib = buildFib;