rtf-codec 0.0.0 → 1.1.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/LICENSE +21 -0
- package/README.md +226 -0
- package/dist/base64.cjs +66 -0
- package/dist/base64.d.cts +7 -0
- package/dist/base64.d.ts +7 -0
- package/dist/base64.js +62 -0
- package/dist/bytes.cjs +25 -0
- package/dist/bytes.d.cts +6 -0
- package/dist/bytes.d.ts +6 -0
- package/dist/bytes.js +22 -0
- package/dist/cell-format.cjs +142 -0
- package/dist/cell-format.d.cts +25 -0
- package/dist/cell-format.d.ts +25 -0
- package/dist/cell-format.js +137 -0
- package/dist/codec.cjs +29 -0
- package/dist/codec.d.cts +2344 -0
- package/dist/codec.d.ts +2344 -0
- package/dist/codec.js +26 -0
- package/dist/codepage.cjs +98 -0
- package/dist/codepage.d.cts +10 -0
- package/dist/codepage.d.ts +10 -0
- package/dist/codepage.js +92 -0
- package/dist/constructs.cjs +131 -0
- package/dist/constructs.d.cts +31 -0
- package/dist/constructs.d.ts +31 -0
- package/dist/constructs.js +121 -0
- package/dist/diagnostics-BgG_KAiN.d.cts +52 -0
- package/dist/diagnostics-BgG_KAiN.d.ts +52 -0
- package/dist/diagnostics.cjs +76 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +68 -0
- package/dist/group.cjs +40 -0
- package/dist/group.d.cts +11 -0
- package/dist/group.d.ts +11 -0
- package/dist/group.js +38 -0
- package/dist/header.cjs +433 -0
- package/dist/header.d.cts +44 -0
- package/dist/header.d.ts +44 -0
- package/dist/header.js +431 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/list-id.cjs +30 -0
- package/dist/list-id.d.cts +16 -0
- package/dist/list-id.d.ts +16 -0
- package/dist/list-id.js +27 -0
- package/dist/options.cjs +7 -0
- package/dist/options.d.cts +18 -0
- package/dist/options.d.ts +18 -0
- package/dist/options.js +5 -0
- package/dist/read.cjs +1211 -0
- package/dist/read.d.cts +16 -0
- package/dist/read.d.ts +16 -0
- package/dist/read.js +1209 -0
- package/dist/tokenize.cjs +155 -0
- package/dist/tokenize.d.cts +25 -0
- package/dist/tokenize.d.ts +25 -0
- package/dist/tokenize.js +154 -0
- package/dist/units.cjs +43 -0
- package/dist/units.d.cts +17 -0
- package/dist/units.d.ts +17 -0
- package/dist/units.js +29 -0
- package/dist/write.cjs +532 -0
- package/dist/write.d.cts +7 -0
- package/dist/write.d.ts +7 -0
- package/dist/write.js +530 -0
- package/package.json +95 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/tokenize.ts
|
|
3
|
+
const MAX_CONTROL_WORD_LETTERS = 32;
|
|
4
|
+
const MAX_PARAMETER_DIGITS = 10;
|
|
5
|
+
const BACKSLASH = 92;
|
|
6
|
+
const OPEN_BRACE = 123;
|
|
7
|
+
const CLOSE_BRACE = 125;
|
|
8
|
+
const APOSTROPHE = 39;
|
|
9
|
+
const MINUS = 45;
|
|
10
|
+
const SPACE = 32;
|
|
11
|
+
const CARRIAGE_RETURN = 13;
|
|
12
|
+
const LINE_FEED = 10;
|
|
13
|
+
function isAsciiLetter(byte) {
|
|
14
|
+
return byte >= 65 && byte <= 90 || byte >= 97 && byte <= 122;
|
|
15
|
+
}
|
|
16
|
+
function isAsciiDigit(byte) {
|
|
17
|
+
return byte >= 48 && byte <= 57;
|
|
18
|
+
}
|
|
19
|
+
function hexDigitValue(byte) {
|
|
20
|
+
if (isAsciiDigit(byte)) return byte - 48;
|
|
21
|
+
if (byte >= 97 && byte <= 102) return byte - 97 + 10;
|
|
22
|
+
if (byte >= 65 && byte <= 70) return byte - 65 + 10;
|
|
23
|
+
}
|
|
24
|
+
function scanControlWord(input, start) {
|
|
25
|
+
let cursor = start;
|
|
26
|
+
let name = "";
|
|
27
|
+
while (cursor < input.length && name.length < MAX_CONTROL_WORD_LETTERS && isAsciiLetter(input[cursor] ?? 0)) {
|
|
28
|
+
name += String.fromCharCode(input[cursor] ?? 0);
|
|
29
|
+
cursor += 1;
|
|
30
|
+
}
|
|
31
|
+
let param;
|
|
32
|
+
let negative = false;
|
|
33
|
+
if (cursor < input.length && input[cursor] === MINUS) {
|
|
34
|
+
negative = true;
|
|
35
|
+
cursor += 1;
|
|
36
|
+
}
|
|
37
|
+
let digits = "";
|
|
38
|
+
while (cursor < input.length && digits.length < MAX_PARAMETER_DIGITS && isAsciiDigit(input[cursor] ?? 0)) {
|
|
39
|
+
digits += String.fromCharCode(input[cursor] ?? 0);
|
|
40
|
+
cursor += 1;
|
|
41
|
+
}
|
|
42
|
+
if (digits.length > 0) param = negative ? -Number(digits) : Number(digits);
|
|
43
|
+
else if (negative) cursor -= 1;
|
|
44
|
+
if (cursor < input.length && input[cursor] === SPACE) cursor += 1;
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
param,
|
|
48
|
+
next: cursor
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function tokenizeRtf(input) {
|
|
52
|
+
const tokens = [];
|
|
53
|
+
let cursor = 0;
|
|
54
|
+
let textStart = -1;
|
|
55
|
+
let pendingText = [];
|
|
56
|
+
const flushText = () => {
|
|
57
|
+
if (textStart === -1) return;
|
|
58
|
+
tokens.push({
|
|
59
|
+
kind: "text",
|
|
60
|
+
bytes: Uint8Array.from(pendingText)
|
|
61
|
+
});
|
|
62
|
+
textStart = -1;
|
|
63
|
+
pendingText = [];
|
|
64
|
+
};
|
|
65
|
+
const pushTextByte = (byte) => {
|
|
66
|
+
if (textStart === -1) textStart = cursor;
|
|
67
|
+
pendingText.push(byte);
|
|
68
|
+
};
|
|
69
|
+
while (cursor < input.length) {
|
|
70
|
+
const byte = input[cursor] ?? 0;
|
|
71
|
+
if (byte === OPEN_BRACE) {
|
|
72
|
+
flushText();
|
|
73
|
+
tokens.push({ kind: "groupStart" });
|
|
74
|
+
cursor += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (byte === CLOSE_BRACE) {
|
|
78
|
+
flushText();
|
|
79
|
+
tokens.push({ kind: "groupEnd" });
|
|
80
|
+
cursor += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (byte === CARRIAGE_RETURN || byte === LINE_FEED) {
|
|
84
|
+
cursor += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (byte !== BACKSLASH) {
|
|
88
|
+
pushTextByte(byte);
|
|
89
|
+
cursor += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const after = input[cursor + 1];
|
|
93
|
+
if (after === void 0) {
|
|
94
|
+
pushTextByte(byte);
|
|
95
|
+
cursor += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (after === CARRIAGE_RETURN || after === LINE_FEED) {
|
|
99
|
+
flushText();
|
|
100
|
+
tokens.push({
|
|
101
|
+
kind: "controlWord",
|
|
102
|
+
name: "par"
|
|
103
|
+
});
|
|
104
|
+
cursor += 2;
|
|
105
|
+
if (after === CARRIAGE_RETURN && input[cursor] === LINE_FEED) cursor += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (after === APOSTROPHE) {
|
|
109
|
+
const high = hexDigitValue(input[cursor + 2] ?? 0);
|
|
110
|
+
const low = hexDigitValue(input[cursor + 3] ?? 0);
|
|
111
|
+
if (high !== void 0 && low !== void 0) {
|
|
112
|
+
flushText();
|
|
113
|
+
tokens.push({
|
|
114
|
+
kind: "hex",
|
|
115
|
+
byte: high * 16 + low
|
|
116
|
+
});
|
|
117
|
+
cursor += 4;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!isAsciiLetter(after)) {
|
|
122
|
+
flushText();
|
|
123
|
+
tokens.push({
|
|
124
|
+
kind: "controlSymbol",
|
|
125
|
+
symbol: String.fromCharCode(after)
|
|
126
|
+
});
|
|
127
|
+
cursor += 2;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const scan = scanControlWord(input, cursor + 1);
|
|
131
|
+
flushText();
|
|
132
|
+
if (scan.name === "bin" && scan.param !== void 0 && scan.param > 0) {
|
|
133
|
+
const end = Math.min(scan.next + scan.param, input.length);
|
|
134
|
+
tokens.push({
|
|
135
|
+
kind: "binary",
|
|
136
|
+
bytes: input.slice(scan.next, end)
|
|
137
|
+
});
|
|
138
|
+
cursor = end;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
tokens.push(scan.param === void 0 ? {
|
|
142
|
+
kind: "controlWord",
|
|
143
|
+
name: scan.name
|
|
144
|
+
} : {
|
|
145
|
+
kind: "controlWord",
|
|
146
|
+
name: scan.name,
|
|
147
|
+
param: scan.param
|
|
148
|
+
});
|
|
149
|
+
cursor = scan.next;
|
|
150
|
+
}
|
|
151
|
+
flushText();
|
|
152
|
+
return tokens;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
exports.tokenizeRtf = tokenizeRtf;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/tokenize.d.ts
|
|
2
|
+
type RtfToken = {
|
|
3
|
+
readonly kind: "groupStart";
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: "groupEnd";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "controlWord";
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly param?: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "controlSymbol";
|
|
12
|
+
readonly symbol: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "hex";
|
|
15
|
+
readonly byte: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: "text";
|
|
18
|
+
readonly bytes: Uint8Array;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "binary";
|
|
21
|
+
readonly bytes: Uint8Array;
|
|
22
|
+
};
|
|
23
|
+
declare function tokenizeRtf(input: Uint8Array): RtfToken[];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { RtfToken, tokenizeRtf };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/tokenize.d.ts
|
|
2
|
+
type RtfToken = {
|
|
3
|
+
readonly kind: "groupStart";
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: "groupEnd";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "controlWord";
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly param?: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "controlSymbol";
|
|
12
|
+
readonly symbol: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "hex";
|
|
15
|
+
readonly byte: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: "text";
|
|
18
|
+
readonly bytes: Uint8Array;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "binary";
|
|
21
|
+
readonly bytes: Uint8Array;
|
|
22
|
+
};
|
|
23
|
+
declare function tokenizeRtf(input: Uint8Array): RtfToken[];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { RtfToken, tokenizeRtf };
|
package/dist/tokenize.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//#region src/tokenize.ts
|
|
2
|
+
const MAX_CONTROL_WORD_LETTERS = 32;
|
|
3
|
+
const MAX_PARAMETER_DIGITS = 10;
|
|
4
|
+
const BACKSLASH = 92;
|
|
5
|
+
const OPEN_BRACE = 123;
|
|
6
|
+
const CLOSE_BRACE = 125;
|
|
7
|
+
const APOSTROPHE = 39;
|
|
8
|
+
const MINUS = 45;
|
|
9
|
+
const SPACE = 32;
|
|
10
|
+
const CARRIAGE_RETURN = 13;
|
|
11
|
+
const LINE_FEED = 10;
|
|
12
|
+
function isAsciiLetter(byte) {
|
|
13
|
+
return byte >= 65 && byte <= 90 || byte >= 97 && byte <= 122;
|
|
14
|
+
}
|
|
15
|
+
function isAsciiDigit(byte) {
|
|
16
|
+
return byte >= 48 && byte <= 57;
|
|
17
|
+
}
|
|
18
|
+
function hexDigitValue(byte) {
|
|
19
|
+
if (isAsciiDigit(byte)) return byte - 48;
|
|
20
|
+
if (byte >= 97 && byte <= 102) return byte - 97 + 10;
|
|
21
|
+
if (byte >= 65 && byte <= 70) return byte - 65 + 10;
|
|
22
|
+
}
|
|
23
|
+
function scanControlWord(input, start) {
|
|
24
|
+
let cursor = start;
|
|
25
|
+
let name = "";
|
|
26
|
+
while (cursor < input.length && name.length < MAX_CONTROL_WORD_LETTERS && isAsciiLetter(input[cursor] ?? 0)) {
|
|
27
|
+
name += String.fromCharCode(input[cursor] ?? 0);
|
|
28
|
+
cursor += 1;
|
|
29
|
+
}
|
|
30
|
+
let param;
|
|
31
|
+
let negative = false;
|
|
32
|
+
if (cursor < input.length && input[cursor] === MINUS) {
|
|
33
|
+
negative = true;
|
|
34
|
+
cursor += 1;
|
|
35
|
+
}
|
|
36
|
+
let digits = "";
|
|
37
|
+
while (cursor < input.length && digits.length < MAX_PARAMETER_DIGITS && isAsciiDigit(input[cursor] ?? 0)) {
|
|
38
|
+
digits += String.fromCharCode(input[cursor] ?? 0);
|
|
39
|
+
cursor += 1;
|
|
40
|
+
}
|
|
41
|
+
if (digits.length > 0) param = negative ? -Number(digits) : Number(digits);
|
|
42
|
+
else if (negative) cursor -= 1;
|
|
43
|
+
if (cursor < input.length && input[cursor] === SPACE) cursor += 1;
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
param,
|
|
47
|
+
next: cursor
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function tokenizeRtf(input) {
|
|
51
|
+
const tokens = [];
|
|
52
|
+
let cursor = 0;
|
|
53
|
+
let textStart = -1;
|
|
54
|
+
let pendingText = [];
|
|
55
|
+
const flushText = () => {
|
|
56
|
+
if (textStart === -1) return;
|
|
57
|
+
tokens.push({
|
|
58
|
+
kind: "text",
|
|
59
|
+
bytes: Uint8Array.from(pendingText)
|
|
60
|
+
});
|
|
61
|
+
textStart = -1;
|
|
62
|
+
pendingText = [];
|
|
63
|
+
};
|
|
64
|
+
const pushTextByte = (byte) => {
|
|
65
|
+
if (textStart === -1) textStart = cursor;
|
|
66
|
+
pendingText.push(byte);
|
|
67
|
+
};
|
|
68
|
+
while (cursor < input.length) {
|
|
69
|
+
const byte = input[cursor] ?? 0;
|
|
70
|
+
if (byte === OPEN_BRACE) {
|
|
71
|
+
flushText();
|
|
72
|
+
tokens.push({ kind: "groupStart" });
|
|
73
|
+
cursor += 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (byte === CLOSE_BRACE) {
|
|
77
|
+
flushText();
|
|
78
|
+
tokens.push({ kind: "groupEnd" });
|
|
79
|
+
cursor += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (byte === CARRIAGE_RETURN || byte === LINE_FEED) {
|
|
83
|
+
cursor += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (byte !== BACKSLASH) {
|
|
87
|
+
pushTextByte(byte);
|
|
88
|
+
cursor += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const after = input[cursor + 1];
|
|
92
|
+
if (after === void 0) {
|
|
93
|
+
pushTextByte(byte);
|
|
94
|
+
cursor += 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (after === CARRIAGE_RETURN || after === LINE_FEED) {
|
|
98
|
+
flushText();
|
|
99
|
+
tokens.push({
|
|
100
|
+
kind: "controlWord",
|
|
101
|
+
name: "par"
|
|
102
|
+
});
|
|
103
|
+
cursor += 2;
|
|
104
|
+
if (after === CARRIAGE_RETURN && input[cursor] === LINE_FEED) cursor += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (after === APOSTROPHE) {
|
|
108
|
+
const high = hexDigitValue(input[cursor + 2] ?? 0);
|
|
109
|
+
const low = hexDigitValue(input[cursor + 3] ?? 0);
|
|
110
|
+
if (high !== void 0 && low !== void 0) {
|
|
111
|
+
flushText();
|
|
112
|
+
tokens.push({
|
|
113
|
+
kind: "hex",
|
|
114
|
+
byte: high * 16 + low
|
|
115
|
+
});
|
|
116
|
+
cursor += 4;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!isAsciiLetter(after)) {
|
|
121
|
+
flushText();
|
|
122
|
+
tokens.push({
|
|
123
|
+
kind: "controlSymbol",
|
|
124
|
+
symbol: String.fromCharCode(after)
|
|
125
|
+
});
|
|
126
|
+
cursor += 2;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const scan = scanControlWord(input, cursor + 1);
|
|
130
|
+
flushText();
|
|
131
|
+
if (scan.name === "bin" && scan.param !== void 0 && scan.param > 0) {
|
|
132
|
+
const end = Math.min(scan.next + scan.param, input.length);
|
|
133
|
+
tokens.push({
|
|
134
|
+
kind: "binary",
|
|
135
|
+
bytes: input.slice(scan.next, end)
|
|
136
|
+
});
|
|
137
|
+
cursor = end;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
tokens.push(scan.param === void 0 ? {
|
|
141
|
+
kind: "controlWord",
|
|
142
|
+
name: scan.name
|
|
143
|
+
} : {
|
|
144
|
+
kind: "controlWord",
|
|
145
|
+
name: scan.name,
|
|
146
|
+
param: scan.param
|
|
147
|
+
});
|
|
148
|
+
cursor = scan.next;
|
|
149
|
+
}
|
|
150
|
+
flushText();
|
|
151
|
+
return tokens;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
export { tokenizeRtf };
|
package/dist/units.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/units.ts
|
|
3
|
+
const TWIPS_PER_POINT = 20;
|
|
4
|
+
const HALF_POINTS_PER_POINT = 2;
|
|
5
|
+
const PIXELS_PER_INCH = 96;
|
|
6
|
+
const POINTS_PER_INCH = 72;
|
|
7
|
+
function twipsToPoints(twips) {
|
|
8
|
+
return twips / 20;
|
|
9
|
+
}
|
|
10
|
+
function pointsToTwips(points) {
|
|
11
|
+
return Math.round(points * 20);
|
|
12
|
+
}
|
|
13
|
+
function halfPointsToPoints(halfPoints) {
|
|
14
|
+
return halfPoints / 2;
|
|
15
|
+
}
|
|
16
|
+
function pointsToHalfPoints(points) {
|
|
17
|
+
return Math.round(points * 2);
|
|
18
|
+
}
|
|
19
|
+
function pixelsToPoints(pixels) {
|
|
20
|
+
return pixels * POINTS_PER_INCH / PIXELS_PER_INCH;
|
|
21
|
+
}
|
|
22
|
+
const DEFAULT_PAPER_WIDTH_TWIPS = 12240;
|
|
23
|
+
const DEFAULT_PAPER_HEIGHT_TWIPS = 15840;
|
|
24
|
+
const DEFAULT_MARGIN_LEFT_TWIPS = 1800;
|
|
25
|
+
const DEFAULT_MARGIN_RIGHT_TWIPS = 1800;
|
|
26
|
+
const DEFAULT_MARGIN_TOP_TWIPS = 1440;
|
|
27
|
+
const DEFAULT_MARGIN_BOTTOM_TWIPS = 1440;
|
|
28
|
+
const DEFAULT_FONT_SIZE_HALF_POINTS = 24;
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.DEFAULT_FONT_SIZE_HALF_POINTS = DEFAULT_FONT_SIZE_HALF_POINTS;
|
|
31
|
+
exports.DEFAULT_MARGIN_BOTTOM_TWIPS = DEFAULT_MARGIN_BOTTOM_TWIPS;
|
|
32
|
+
exports.DEFAULT_MARGIN_LEFT_TWIPS = DEFAULT_MARGIN_LEFT_TWIPS;
|
|
33
|
+
exports.DEFAULT_MARGIN_RIGHT_TWIPS = DEFAULT_MARGIN_RIGHT_TWIPS;
|
|
34
|
+
exports.DEFAULT_MARGIN_TOP_TWIPS = DEFAULT_MARGIN_TOP_TWIPS;
|
|
35
|
+
exports.DEFAULT_PAPER_HEIGHT_TWIPS = DEFAULT_PAPER_HEIGHT_TWIPS;
|
|
36
|
+
exports.DEFAULT_PAPER_WIDTH_TWIPS = DEFAULT_PAPER_WIDTH_TWIPS;
|
|
37
|
+
exports.HALF_POINTS_PER_POINT = HALF_POINTS_PER_POINT;
|
|
38
|
+
exports.TWIPS_PER_POINT = TWIPS_PER_POINT;
|
|
39
|
+
exports.halfPointsToPoints = halfPointsToPoints;
|
|
40
|
+
exports.pixelsToPoints = pixelsToPoints;
|
|
41
|
+
exports.pointsToHalfPoints = pointsToHalfPoints;
|
|
42
|
+
exports.pointsToTwips = pointsToTwips;
|
|
43
|
+
exports.twipsToPoints = twipsToPoints;
|
package/dist/units.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/units.d.ts
|
|
2
|
+
declare const TWIPS_PER_POINT = 20;
|
|
3
|
+
declare const HALF_POINTS_PER_POINT = 2;
|
|
4
|
+
declare function twipsToPoints(twips: number): number;
|
|
5
|
+
declare function pointsToTwips(points: number): number;
|
|
6
|
+
declare function halfPointsToPoints(halfPoints: number): number;
|
|
7
|
+
declare function pointsToHalfPoints(points: number): number;
|
|
8
|
+
declare function pixelsToPoints(pixels: number): number;
|
|
9
|
+
declare const DEFAULT_PAPER_WIDTH_TWIPS = 12240;
|
|
10
|
+
declare const DEFAULT_PAPER_HEIGHT_TWIPS = 15840;
|
|
11
|
+
declare const DEFAULT_MARGIN_LEFT_TWIPS = 1800;
|
|
12
|
+
declare const DEFAULT_MARGIN_RIGHT_TWIPS = 1800;
|
|
13
|
+
declare const DEFAULT_MARGIN_TOP_TWIPS = 1440;
|
|
14
|
+
declare const DEFAULT_MARGIN_BOTTOM_TWIPS = 1440;
|
|
15
|
+
declare const DEFAULT_FONT_SIZE_HALF_POINTS = 24;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_FONT_SIZE_HALF_POINTS, DEFAULT_MARGIN_BOTTOM_TWIPS, DEFAULT_MARGIN_LEFT_TWIPS, DEFAULT_MARGIN_RIGHT_TWIPS, DEFAULT_MARGIN_TOP_TWIPS, DEFAULT_PAPER_HEIGHT_TWIPS, DEFAULT_PAPER_WIDTH_TWIPS, HALF_POINTS_PER_POINT, TWIPS_PER_POINT, halfPointsToPoints, pixelsToPoints, pointsToHalfPoints, pointsToTwips, twipsToPoints };
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/units.d.ts
|
|
2
|
+
declare const TWIPS_PER_POINT = 20;
|
|
3
|
+
declare const HALF_POINTS_PER_POINT = 2;
|
|
4
|
+
declare function twipsToPoints(twips: number): number;
|
|
5
|
+
declare function pointsToTwips(points: number): number;
|
|
6
|
+
declare function halfPointsToPoints(halfPoints: number): number;
|
|
7
|
+
declare function pointsToHalfPoints(points: number): number;
|
|
8
|
+
declare function pixelsToPoints(pixels: number): number;
|
|
9
|
+
declare const DEFAULT_PAPER_WIDTH_TWIPS = 12240;
|
|
10
|
+
declare const DEFAULT_PAPER_HEIGHT_TWIPS = 15840;
|
|
11
|
+
declare const DEFAULT_MARGIN_LEFT_TWIPS = 1800;
|
|
12
|
+
declare const DEFAULT_MARGIN_RIGHT_TWIPS = 1800;
|
|
13
|
+
declare const DEFAULT_MARGIN_TOP_TWIPS = 1440;
|
|
14
|
+
declare const DEFAULT_MARGIN_BOTTOM_TWIPS = 1440;
|
|
15
|
+
declare const DEFAULT_FONT_SIZE_HALF_POINTS = 24;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_FONT_SIZE_HALF_POINTS, DEFAULT_MARGIN_BOTTOM_TWIPS, DEFAULT_MARGIN_LEFT_TWIPS, DEFAULT_MARGIN_RIGHT_TWIPS, DEFAULT_MARGIN_TOP_TWIPS, DEFAULT_PAPER_HEIGHT_TWIPS, DEFAULT_PAPER_WIDTH_TWIPS, HALF_POINTS_PER_POINT, TWIPS_PER_POINT, halfPointsToPoints, pixelsToPoints, pointsToHalfPoints, pointsToTwips, twipsToPoints };
|
package/dist/units.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/units.ts
|
|
2
|
+
const TWIPS_PER_POINT = 20;
|
|
3
|
+
const HALF_POINTS_PER_POINT = 2;
|
|
4
|
+
const PIXELS_PER_INCH = 96;
|
|
5
|
+
const POINTS_PER_INCH = 72;
|
|
6
|
+
function twipsToPoints(twips) {
|
|
7
|
+
return twips / 20;
|
|
8
|
+
}
|
|
9
|
+
function pointsToTwips(points) {
|
|
10
|
+
return Math.round(points * 20);
|
|
11
|
+
}
|
|
12
|
+
function halfPointsToPoints(halfPoints) {
|
|
13
|
+
return halfPoints / 2;
|
|
14
|
+
}
|
|
15
|
+
function pointsToHalfPoints(points) {
|
|
16
|
+
return Math.round(points * 2);
|
|
17
|
+
}
|
|
18
|
+
function pixelsToPoints(pixels) {
|
|
19
|
+
return pixels * POINTS_PER_INCH / PIXELS_PER_INCH;
|
|
20
|
+
}
|
|
21
|
+
const DEFAULT_PAPER_WIDTH_TWIPS = 12240;
|
|
22
|
+
const DEFAULT_PAPER_HEIGHT_TWIPS = 15840;
|
|
23
|
+
const DEFAULT_MARGIN_LEFT_TWIPS = 1800;
|
|
24
|
+
const DEFAULT_MARGIN_RIGHT_TWIPS = 1800;
|
|
25
|
+
const DEFAULT_MARGIN_TOP_TWIPS = 1440;
|
|
26
|
+
const DEFAULT_MARGIN_BOTTOM_TWIPS = 1440;
|
|
27
|
+
const DEFAULT_FONT_SIZE_HALF_POINTS = 24;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { DEFAULT_FONT_SIZE_HALF_POINTS, DEFAULT_MARGIN_BOTTOM_TWIPS, DEFAULT_MARGIN_LEFT_TWIPS, DEFAULT_MARGIN_RIGHT_TWIPS, DEFAULT_MARGIN_TOP_TWIPS, DEFAULT_PAPER_HEIGHT_TWIPS, DEFAULT_PAPER_WIDTH_TWIPS, HALF_POINTS_PER_POINT, TWIPS_PER_POINT, halfPointsToPoints, pixelsToPoints, pointsToHalfPoints, pointsToTwips, twipsToPoints };
|