@docen/utils 0.0.9 → 0.0.10
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +94 -6
- package/dist/index.d.mts +94 -6
- package/dist/index.d.ts +94 -6
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const DOCX_DPI=96;function convertTwipToPixels(
|
|
1
|
+
"use strict";const DOCX_DPI=96,TWIPS_PER_INCH=1440,EMUS_PER_INCH=914400,HALF_POINTS_PER_PIXEL=1.5,PIXELS_PER_HALF_POINT=.6666666666666666,DEFAULT_CODE_FONT="Consolas",CHECKBOX_SYMBOLS={checked:"\u2611",unchecked:"\u2610"},DOCX_STYLE_NAMES={CODE_BLOCK:"CodeBlock",CODE_PREFIX:"Code"},TEXT_ALIGN_MAP={tiptapToDocx:{left:"left",right:"right",center:"center",justify:"both"},docxToTipTap:{left:"left",right:"right",center:"center",both:"justify"}},PAGE_DIMENSIONS={A4_WIDTH_TWIP:11906,DEFAULT_MARGIN_TWIP:1440},o=96;function convertTwipToPixels(e){return Math.round(e*o/1440)}function convertTwipToCssString(e){return`${convertTwipToPixels(e)}px`}function convertPixelsToTwip(e){return Math.round(e*(1440/o))}function convertEmuToPixels(e){return Math.round(e/(914400/o))}function convertPixelsToEmu(e){return Math.round(e*(914400/o))}function convertEmuStringToPixels(e){const r=parseInt(e,10);if(!isNaN(r))return convertEmuToPixels(r)}const p=/^(-?[\d.]+)(px|pt|em|rem|%|)?$/,f={px:1,pt:1.333,em:16,rem:16,"%":.16};function convertCssLengthToPixels(e){if(!e)return 0;e=e.trim();const r=e.match(p);if(!r)return 0;const t=parseFloat(r[1]);if(isNaN(t))return 0;const n=r[2]||"px",i=f[n]??1;return Math.round(t*i)}const a=/^([\d.]+)(in|mm|cm|pt|pc|pi)$/,x={in:1,mm:1/25.4,cm:1/2.54,pt:1/72,pc:1/6,pi:1/6};function convertMeasureToInches(e){if(typeof e=="number")return e;const r=e.match(a);if(r){const n=parseFloat(r[1]),i=r[2],s=x[i];return s!==void 0?n*s:n}const t=parseFloat(e);return isNaN(t)?6.5:t}function convertMeasureToPixels(e){if(typeof e=="number")return e;const r=convertMeasureToInches(e);return Math.round(r*96)}const COLOR_NAME_TO_HEX={black:"#000000",white:"#FFFFFF",red:"#FF0000",green:"#008000",blue:"#0000FF",yellow:"#FFFF00",orange:"#FFA500",purple:"#800080",pink:"#FFC0CB",brown:"#A52A2A",gray:"#808080",grey:"#808080",cyan:"#00FFFF",magenta:"#FF00FF",lime:"#00FF00",navy:"#000080",teal:"#008080",maroon:"#800000",olive:"#808000",silver:"#C0C0C0",gold:"#FFD700",indigo:"#4B0082",violet:"#EE82EE",aqua:"#00FFFF",fuchsia:"#FF00FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkviolet:"#9400D3",lightblue:"#ADD8E6",lightcyan:"#E0FFFF",lightgreen:"#90EE90",lightgrey:"#D3D3D3",lightpink:"#FFB6C1",lightyellow:"#FFFFE0"};function convertColorToHex(e){if(e)return e.startsWith("#")?e:COLOR_NAME_TO_HEX[e.toLowerCase()]||e}function normalizeHexColor(e){return e.startsWith("#")?e:`#${e}`}function findChild(e,r){if(!e.children)return null;for(const t of e.children)if(t.type==="element"&&t.name===r)return t;return null}function findDeepChild(e,r){if(!e.children)return null;for(const t of e.children)if(t.type==="element"){if(t.name===r)return t;const n=findDeepChild(t,r);if(n)return n}return null}function findDeepChildren(e,r){const t=[];if(!e.children)return t;for(const n of e.children)n.type==="element"&&(n.name===r&&t.push(n),t.push(...findDeepChildren(n,r)));return t}function parseTwipAttr(e,r){const t=e[r];if(!t)return;const n=parseInt(t,10);if(!isNaN(n))return t}function createStringValidator(e){return r=>e.includes(r)}exports.CHECKBOX_SYMBOLS=CHECKBOX_SYMBOLS,exports.COLOR_NAME_TO_HEX=COLOR_NAME_TO_HEX,exports.DEFAULT_CODE_FONT=DEFAULT_CODE_FONT,exports.DOCX_DPI=96,exports.DOCX_STYLE_NAMES=DOCX_STYLE_NAMES,exports.EMUS_PER_INCH=914400,exports.HALF_POINTS_PER_PIXEL=1.5,exports.PAGE_DIMENSIONS=PAGE_DIMENSIONS,exports.PIXELS_PER_HALF_POINT=PIXELS_PER_HALF_POINT,exports.TEXT_ALIGN_MAP=TEXT_ALIGN_MAP,exports.TWIPS_PER_INCH=1440,exports.convertColorToHex=convertColorToHex,exports.convertCssLengthToPixels=convertCssLengthToPixels,exports.convertEmuStringToPixels=convertEmuStringToPixels,exports.convertEmuToPixels=convertEmuToPixels,exports.convertMeasureToInches=convertMeasureToInches,exports.convertMeasureToPixels=convertMeasureToPixels,exports.convertPixelsToEmu=convertPixelsToEmu,exports.convertPixelsToTwip=convertPixelsToTwip,exports.convertTwipToCssString=convertTwipToCssString,exports.convertTwipToPixels=convertTwipToPixels,exports.createStringValidator=createStringValidator,exports.findChild=findChild,exports.findDeepChild=findDeepChild,exports.findDeepChildren=findDeepChildren,exports.normalizeHexColor=normalizeHexColor,exports.parseTwipAttr=parseTwipAttr;
|
package/dist/index.d.cts
CHANGED
|
@@ -4,11 +4,6 @@ import { Root, Element } from 'E:\\tiptap-extension\\node_modules\\.pnpm\\@types
|
|
|
4
4
|
* Unit conversion utilities for DOCX processing
|
|
5
5
|
* Handles conversions between TWIPs, EMUs, pixels, and other units
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
* DOCX DPI (dots per inch) for pixel conversions
|
|
9
|
-
* Word uses 96 DPI internally
|
|
10
|
-
*/
|
|
11
|
-
declare const DOCX_DPI = 96;
|
|
12
7
|
/**
|
|
13
8
|
* Convert TWIPs to CSS pixels (returns number)
|
|
14
9
|
* @param twip - Value in TWIPs (1 inch = 1440 TWIPs)
|
|
@@ -75,6 +70,7 @@ declare function convertEmuStringToPixels(emuStr: string): number | undefined;
|
|
|
75
70
|
* convertCssLengthToPixels("20px") // returns 20
|
|
76
71
|
* convertCssLengthToPixels("1.5em") // returns 24
|
|
77
72
|
* convertCssLengthToPixels("100%") // returns 16
|
|
73
|
+
* convertCssLengthToPixels("20") // returns 20 (unitless treated as px)
|
|
78
74
|
*/
|
|
79
75
|
declare function convertCssLengthToPixels(value: string): number;
|
|
80
76
|
/**
|
|
@@ -188,5 +184,97 @@ declare function parseTwipAttr(attributes: Record<string, any> | {
|
|
|
188
184
|
[key: string]: string | undefined;
|
|
189
185
|
}, name: string): string | undefined;
|
|
190
186
|
|
|
191
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Shared constants for DOCX processing
|
|
189
|
+
* Used across @docen/export-docx and @docen/import-docx packages
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* DOCX DPI (dots per inch) for pixel conversions
|
|
193
|
+
* Word uses 96 DPI internally
|
|
194
|
+
*/
|
|
195
|
+
declare const DOCX_DPI = 96;
|
|
196
|
+
/**
|
|
197
|
+
* TWIP (Twentieth of a Point) conversion constants
|
|
198
|
+
* 1 inch = 1440 TWIPs
|
|
199
|
+
*/
|
|
200
|
+
declare const TWIPS_PER_INCH = 1440;
|
|
201
|
+
/**
|
|
202
|
+
* EMU (English Metric Unit) conversion constants
|
|
203
|
+
* 1 inch = 914400 EMUs
|
|
204
|
+
*/
|
|
205
|
+
declare const EMUS_PER_INCH = 914400;
|
|
206
|
+
/**
|
|
207
|
+
* Font size conversion factors
|
|
208
|
+
* DOCX uses half-points, TipTap uses pixels
|
|
209
|
+
* 1px ≈ 0.75pt, 1pt = 2 half-points
|
|
210
|
+
* So: px * 0.75 * 2 = px * 1.5
|
|
211
|
+
*/
|
|
212
|
+
declare const HALF_POINTS_PER_PIXEL = 1.5;
|
|
213
|
+
declare const PIXELS_PER_HALF_POINT: number;
|
|
214
|
+
/**
|
|
215
|
+
* Default code font family
|
|
216
|
+
*/
|
|
217
|
+
declare const DEFAULT_CODE_FONT = "Consolas";
|
|
218
|
+
/**
|
|
219
|
+
* Checkbox symbols for task lists
|
|
220
|
+
*/
|
|
221
|
+
declare const CHECKBOX_SYMBOLS: {
|
|
222
|
+
readonly checked: "☑";
|
|
223
|
+
readonly unchecked: "☐";
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* DOCX style names
|
|
227
|
+
*/
|
|
228
|
+
declare const DOCX_STYLE_NAMES: {
|
|
229
|
+
readonly CODE_BLOCK: "CodeBlock";
|
|
230
|
+
readonly CODE_PREFIX: "Code";
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Text alignment mappings
|
|
234
|
+
*/
|
|
235
|
+
declare const TEXT_ALIGN_MAP: {
|
|
236
|
+
/** TipTap to DOCX alignment mapping */
|
|
237
|
+
readonly tiptapToDocx: {
|
|
238
|
+
readonly left: "left";
|
|
239
|
+
readonly right: "right";
|
|
240
|
+
readonly center: "center";
|
|
241
|
+
readonly justify: "both";
|
|
242
|
+
};
|
|
243
|
+
/** DOCX to TipTap alignment mapping */
|
|
244
|
+
readonly docxToTipTap: {
|
|
245
|
+
readonly left: "left";
|
|
246
|
+
readonly right: "right";
|
|
247
|
+
readonly center: "center";
|
|
248
|
+
readonly both: "justify";
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Common page dimensions in TWIPs
|
|
253
|
+
*/
|
|
254
|
+
declare const PAGE_DIMENSIONS: {
|
|
255
|
+
/** A4 width in TWIPs (8.27 inches = 11906 TWIPs) */
|
|
256
|
+
readonly A4_WIDTH_TWIP: 11906;
|
|
257
|
+
/** Default 1 inch margin in TWIPs */
|
|
258
|
+
readonly DEFAULT_MARGIN_TWIP: 1440;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Type guard utilities for DOCX processing
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* Type guard factory function
|
|
266
|
+
* Creates a type guard function that checks if a value is one of the valid values
|
|
267
|
+
*
|
|
268
|
+
* @param validValues - Readonly array of valid string values
|
|
269
|
+
* @returns Type guard function
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* const isValidAlign = createStringValidator(["left", "right", "center"] as const);
|
|
273
|
+
* if (isValidAlign(value)) {
|
|
274
|
+
* // value is typed as "left" | "right" | "center"
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
declare function createStringValidator<T extends string>(validValues: readonly T[]): (value: string) => value is T;
|
|
278
|
+
|
|
279
|
+
export { CHECKBOX_SYMBOLS, COLOR_NAME_TO_HEX, DEFAULT_CODE_FONT, DOCX_DPI, DOCX_STYLE_NAMES, EMUS_PER_INCH, HALF_POINTS_PER_PIXEL, PAGE_DIMENSIONS, PIXELS_PER_HALF_POINT, TEXT_ALIGN_MAP, TWIPS_PER_INCH, convertColorToHex, convertCssLengthToPixels, convertEmuStringToPixels, convertEmuToPixels, convertMeasureToInches, convertMeasureToPixels, convertPixelsToEmu, convertPixelsToTwip, convertTwipToCssString, convertTwipToPixels, createStringValidator, findChild, findDeepChild, findDeepChildren, normalizeHexColor, parseTwipAttr };
|
|
192
280
|
export type { PositiveUniversalMeasure };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,11 +4,6 @@ import { Root, Element } from 'E:\\tiptap-extension\\node_modules\\.pnpm\\@types
|
|
|
4
4
|
* Unit conversion utilities for DOCX processing
|
|
5
5
|
* Handles conversions between TWIPs, EMUs, pixels, and other units
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
* DOCX DPI (dots per inch) for pixel conversions
|
|
9
|
-
* Word uses 96 DPI internally
|
|
10
|
-
*/
|
|
11
|
-
declare const DOCX_DPI = 96;
|
|
12
7
|
/**
|
|
13
8
|
* Convert TWIPs to CSS pixels (returns number)
|
|
14
9
|
* @param twip - Value in TWIPs (1 inch = 1440 TWIPs)
|
|
@@ -75,6 +70,7 @@ declare function convertEmuStringToPixels(emuStr: string): number | undefined;
|
|
|
75
70
|
* convertCssLengthToPixels("20px") // returns 20
|
|
76
71
|
* convertCssLengthToPixels("1.5em") // returns 24
|
|
77
72
|
* convertCssLengthToPixels("100%") // returns 16
|
|
73
|
+
* convertCssLengthToPixels("20") // returns 20 (unitless treated as px)
|
|
78
74
|
*/
|
|
79
75
|
declare function convertCssLengthToPixels(value: string): number;
|
|
80
76
|
/**
|
|
@@ -188,5 +184,97 @@ declare function parseTwipAttr(attributes: Record<string, any> | {
|
|
|
188
184
|
[key: string]: string | undefined;
|
|
189
185
|
}, name: string): string | undefined;
|
|
190
186
|
|
|
191
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Shared constants for DOCX processing
|
|
189
|
+
* Used across @docen/export-docx and @docen/import-docx packages
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* DOCX DPI (dots per inch) for pixel conversions
|
|
193
|
+
* Word uses 96 DPI internally
|
|
194
|
+
*/
|
|
195
|
+
declare const DOCX_DPI = 96;
|
|
196
|
+
/**
|
|
197
|
+
* TWIP (Twentieth of a Point) conversion constants
|
|
198
|
+
* 1 inch = 1440 TWIPs
|
|
199
|
+
*/
|
|
200
|
+
declare const TWIPS_PER_INCH = 1440;
|
|
201
|
+
/**
|
|
202
|
+
* EMU (English Metric Unit) conversion constants
|
|
203
|
+
* 1 inch = 914400 EMUs
|
|
204
|
+
*/
|
|
205
|
+
declare const EMUS_PER_INCH = 914400;
|
|
206
|
+
/**
|
|
207
|
+
* Font size conversion factors
|
|
208
|
+
* DOCX uses half-points, TipTap uses pixels
|
|
209
|
+
* 1px ≈ 0.75pt, 1pt = 2 half-points
|
|
210
|
+
* So: px * 0.75 * 2 = px * 1.5
|
|
211
|
+
*/
|
|
212
|
+
declare const HALF_POINTS_PER_PIXEL = 1.5;
|
|
213
|
+
declare const PIXELS_PER_HALF_POINT: number;
|
|
214
|
+
/**
|
|
215
|
+
* Default code font family
|
|
216
|
+
*/
|
|
217
|
+
declare const DEFAULT_CODE_FONT = "Consolas";
|
|
218
|
+
/**
|
|
219
|
+
* Checkbox symbols for task lists
|
|
220
|
+
*/
|
|
221
|
+
declare const CHECKBOX_SYMBOLS: {
|
|
222
|
+
readonly checked: "☑";
|
|
223
|
+
readonly unchecked: "☐";
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* DOCX style names
|
|
227
|
+
*/
|
|
228
|
+
declare const DOCX_STYLE_NAMES: {
|
|
229
|
+
readonly CODE_BLOCK: "CodeBlock";
|
|
230
|
+
readonly CODE_PREFIX: "Code";
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Text alignment mappings
|
|
234
|
+
*/
|
|
235
|
+
declare const TEXT_ALIGN_MAP: {
|
|
236
|
+
/** TipTap to DOCX alignment mapping */
|
|
237
|
+
readonly tiptapToDocx: {
|
|
238
|
+
readonly left: "left";
|
|
239
|
+
readonly right: "right";
|
|
240
|
+
readonly center: "center";
|
|
241
|
+
readonly justify: "both";
|
|
242
|
+
};
|
|
243
|
+
/** DOCX to TipTap alignment mapping */
|
|
244
|
+
readonly docxToTipTap: {
|
|
245
|
+
readonly left: "left";
|
|
246
|
+
readonly right: "right";
|
|
247
|
+
readonly center: "center";
|
|
248
|
+
readonly both: "justify";
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Common page dimensions in TWIPs
|
|
253
|
+
*/
|
|
254
|
+
declare const PAGE_DIMENSIONS: {
|
|
255
|
+
/** A4 width in TWIPs (8.27 inches = 11906 TWIPs) */
|
|
256
|
+
readonly A4_WIDTH_TWIP: 11906;
|
|
257
|
+
/** Default 1 inch margin in TWIPs */
|
|
258
|
+
readonly DEFAULT_MARGIN_TWIP: 1440;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Type guard utilities for DOCX processing
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* Type guard factory function
|
|
266
|
+
* Creates a type guard function that checks if a value is one of the valid values
|
|
267
|
+
*
|
|
268
|
+
* @param validValues - Readonly array of valid string values
|
|
269
|
+
* @returns Type guard function
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* const isValidAlign = createStringValidator(["left", "right", "center"] as const);
|
|
273
|
+
* if (isValidAlign(value)) {
|
|
274
|
+
* // value is typed as "left" | "right" | "center"
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
declare function createStringValidator<T extends string>(validValues: readonly T[]): (value: string) => value is T;
|
|
278
|
+
|
|
279
|
+
export { CHECKBOX_SYMBOLS, COLOR_NAME_TO_HEX, DEFAULT_CODE_FONT, DOCX_DPI, DOCX_STYLE_NAMES, EMUS_PER_INCH, HALF_POINTS_PER_PIXEL, PAGE_DIMENSIONS, PIXELS_PER_HALF_POINT, TEXT_ALIGN_MAP, TWIPS_PER_INCH, convertColorToHex, convertCssLengthToPixels, convertEmuStringToPixels, convertEmuToPixels, convertMeasureToInches, convertMeasureToPixels, convertPixelsToEmu, convertPixelsToTwip, convertTwipToCssString, convertTwipToPixels, createStringValidator, findChild, findDeepChild, findDeepChildren, normalizeHexColor, parseTwipAttr };
|
|
192
280
|
export type { PositiveUniversalMeasure };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ import { Root, Element } from 'E:\\tiptap-extension\\node_modules\\.pnpm\\@types
|
|
|
4
4
|
* Unit conversion utilities for DOCX processing
|
|
5
5
|
* Handles conversions between TWIPs, EMUs, pixels, and other units
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
* DOCX DPI (dots per inch) for pixel conversions
|
|
9
|
-
* Word uses 96 DPI internally
|
|
10
|
-
*/
|
|
11
|
-
declare const DOCX_DPI = 96;
|
|
12
7
|
/**
|
|
13
8
|
* Convert TWIPs to CSS pixels (returns number)
|
|
14
9
|
* @param twip - Value in TWIPs (1 inch = 1440 TWIPs)
|
|
@@ -75,6 +70,7 @@ declare function convertEmuStringToPixels(emuStr: string): number | undefined;
|
|
|
75
70
|
* convertCssLengthToPixels("20px") // returns 20
|
|
76
71
|
* convertCssLengthToPixels("1.5em") // returns 24
|
|
77
72
|
* convertCssLengthToPixels("100%") // returns 16
|
|
73
|
+
* convertCssLengthToPixels("20") // returns 20 (unitless treated as px)
|
|
78
74
|
*/
|
|
79
75
|
declare function convertCssLengthToPixels(value: string): number;
|
|
80
76
|
/**
|
|
@@ -188,5 +184,97 @@ declare function parseTwipAttr(attributes: Record<string, any> | {
|
|
|
188
184
|
[key: string]: string | undefined;
|
|
189
185
|
}, name: string): string | undefined;
|
|
190
186
|
|
|
191
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Shared constants for DOCX processing
|
|
189
|
+
* Used across @docen/export-docx and @docen/import-docx packages
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* DOCX DPI (dots per inch) for pixel conversions
|
|
193
|
+
* Word uses 96 DPI internally
|
|
194
|
+
*/
|
|
195
|
+
declare const DOCX_DPI = 96;
|
|
196
|
+
/**
|
|
197
|
+
* TWIP (Twentieth of a Point) conversion constants
|
|
198
|
+
* 1 inch = 1440 TWIPs
|
|
199
|
+
*/
|
|
200
|
+
declare const TWIPS_PER_INCH = 1440;
|
|
201
|
+
/**
|
|
202
|
+
* EMU (English Metric Unit) conversion constants
|
|
203
|
+
* 1 inch = 914400 EMUs
|
|
204
|
+
*/
|
|
205
|
+
declare const EMUS_PER_INCH = 914400;
|
|
206
|
+
/**
|
|
207
|
+
* Font size conversion factors
|
|
208
|
+
* DOCX uses half-points, TipTap uses pixels
|
|
209
|
+
* 1px ≈ 0.75pt, 1pt = 2 half-points
|
|
210
|
+
* So: px * 0.75 * 2 = px * 1.5
|
|
211
|
+
*/
|
|
212
|
+
declare const HALF_POINTS_PER_PIXEL = 1.5;
|
|
213
|
+
declare const PIXELS_PER_HALF_POINT: number;
|
|
214
|
+
/**
|
|
215
|
+
* Default code font family
|
|
216
|
+
*/
|
|
217
|
+
declare const DEFAULT_CODE_FONT = "Consolas";
|
|
218
|
+
/**
|
|
219
|
+
* Checkbox symbols for task lists
|
|
220
|
+
*/
|
|
221
|
+
declare const CHECKBOX_SYMBOLS: {
|
|
222
|
+
readonly checked: "☑";
|
|
223
|
+
readonly unchecked: "☐";
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* DOCX style names
|
|
227
|
+
*/
|
|
228
|
+
declare const DOCX_STYLE_NAMES: {
|
|
229
|
+
readonly CODE_BLOCK: "CodeBlock";
|
|
230
|
+
readonly CODE_PREFIX: "Code";
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Text alignment mappings
|
|
234
|
+
*/
|
|
235
|
+
declare const TEXT_ALIGN_MAP: {
|
|
236
|
+
/** TipTap to DOCX alignment mapping */
|
|
237
|
+
readonly tiptapToDocx: {
|
|
238
|
+
readonly left: "left";
|
|
239
|
+
readonly right: "right";
|
|
240
|
+
readonly center: "center";
|
|
241
|
+
readonly justify: "both";
|
|
242
|
+
};
|
|
243
|
+
/** DOCX to TipTap alignment mapping */
|
|
244
|
+
readonly docxToTipTap: {
|
|
245
|
+
readonly left: "left";
|
|
246
|
+
readonly right: "right";
|
|
247
|
+
readonly center: "center";
|
|
248
|
+
readonly both: "justify";
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Common page dimensions in TWIPs
|
|
253
|
+
*/
|
|
254
|
+
declare const PAGE_DIMENSIONS: {
|
|
255
|
+
/** A4 width in TWIPs (8.27 inches = 11906 TWIPs) */
|
|
256
|
+
readonly A4_WIDTH_TWIP: 11906;
|
|
257
|
+
/** Default 1 inch margin in TWIPs */
|
|
258
|
+
readonly DEFAULT_MARGIN_TWIP: 1440;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Type guard utilities for DOCX processing
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* Type guard factory function
|
|
266
|
+
* Creates a type guard function that checks if a value is one of the valid values
|
|
267
|
+
*
|
|
268
|
+
* @param validValues - Readonly array of valid string values
|
|
269
|
+
* @returns Type guard function
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* const isValidAlign = createStringValidator(["left", "right", "center"] as const);
|
|
273
|
+
* if (isValidAlign(value)) {
|
|
274
|
+
* // value is typed as "left" | "right" | "center"
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
declare function createStringValidator<T extends string>(validValues: readonly T[]): (value: string) => value is T;
|
|
278
|
+
|
|
279
|
+
export { CHECKBOX_SYMBOLS, COLOR_NAME_TO_HEX, DEFAULT_CODE_FONT, DOCX_DPI, DOCX_STYLE_NAMES, EMUS_PER_INCH, HALF_POINTS_PER_PIXEL, PAGE_DIMENSIONS, PIXELS_PER_HALF_POINT, TEXT_ALIGN_MAP, TWIPS_PER_INCH, convertColorToHex, convertCssLengthToPixels, convertEmuStringToPixels, convertEmuToPixels, convertMeasureToInches, convertMeasureToPixels, convertPixelsToEmu, convertPixelsToTwip, convertTwipToCssString, convertTwipToPixels, createStringValidator, findChild, findDeepChild, findDeepChildren, normalizeHexColor, parseTwipAttr };
|
|
192
280
|
export type { PositiveUniversalMeasure };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d=96,h=1440,p=914400,E=1.5,_=.6666666666666666,C="Consolas",T={checked:"\u2611",unchecked:"\u2610"},m={CODE_BLOCK:"CodeBlock",CODE_PREFIX:"Code"},P={tiptapToDocx:{left:"left",right:"right",center:"center",justify:"both"},docxToTipTap:{left:"left",right:"right",center:"center",both:"justify"}},g={A4_WIDTH_TWIP:11906,DEFAULT_MARGIN_TWIP:1440},o=96;function u(r){return Math.round(r*o/1440)}function I(r){return`${u(r)}px`}function D(r){return Math.round(r*(1440/o))}function a(r){return Math.round(r/(914400/o))}function N(r){return Math.round(r*(914400/o))}function A(r){const n=parseInt(r,10);if(!isNaN(n))return a(n)}const k=/^(-?[\d.]+)(px|pt|em|rem|%|)?$/,v={px:1,pt:1.333,em:16,rem:16,"%":.16};function x(r){if(!r)return 0;r=r.trim();const n=r.match(k);if(!n)return 0;const e=parseFloat(n[1]);if(isNaN(e))return 0;const t=n[2]||"px",i=v[t]??1;return Math.round(e*i)}const y=/^([\d.]+)(in|mm|cm|pt|pc|pi)$/,B={in:1,mm:1/25.4,cm:1/2.54,pt:1/72,pc:1/6,pi:1/6};function l(r){if(typeof r=="number")return r;const n=r.match(y);if(n){const t=parseFloat(n[1]),i=n[2],c=B[i];return c!==void 0?t*c:t}const e=parseFloat(r);return isNaN(e)?6.5:e}function M(r){if(typeof r=="number")return r;const n=l(r);return Math.round(n*96)}const s={black:"#000000",white:"#FFFFFF",red:"#FF0000",green:"#008000",blue:"#0000FF",yellow:"#FFFF00",orange:"#FFA500",purple:"#800080",pink:"#FFC0CB",brown:"#A52A2A",gray:"#808080",grey:"#808080",cyan:"#00FFFF",magenta:"#FF00FF",lime:"#00FF00",navy:"#000080",teal:"#008080",maroon:"#800000",olive:"#808000",silver:"#C0C0C0",gold:"#FFD700",indigo:"#4B0082",violet:"#EE82EE",aqua:"#00FFFF",fuchsia:"#FF00FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkviolet:"#9400D3",lightblue:"#ADD8E6",lightcyan:"#E0FFFF",lightgreen:"#90EE90",lightgrey:"#D3D3D3",lightpink:"#FFB6C1",lightyellow:"#FFFFE0"};function O(r){if(r)return r.startsWith("#")?r:s[r.toLowerCase()]||r}function S(r){return r.startsWith("#")?r:`#${r}`}function H(r,n){if(!r.children)return null;for(const e of r.children)if(e.type==="element"&&e.name===n)return e;return null}function F(r,n){if(!r.children)return null;for(const e of r.children)if(e.type==="element"){if(e.name===n)return e;const t=F(e,n);if(t)return t}return null}function f(r,n){const e=[];if(!r.children)return e;for(const t of r.children)t.type==="element"&&(t.name===n&&e.push(t),e.push(...f(t,n)));return e}function L(r,n){const e=r[n];if(!e)return;const t=parseInt(e,10);if(!isNaN(t))return e}function R(r){return n=>r.includes(n)}export{T as CHECKBOX_SYMBOLS,s as COLOR_NAME_TO_HEX,C as DEFAULT_CODE_FONT,d as DOCX_DPI,m as DOCX_STYLE_NAMES,p as EMUS_PER_INCH,E as HALF_POINTS_PER_PIXEL,g as PAGE_DIMENSIONS,_ as PIXELS_PER_HALF_POINT,P as TEXT_ALIGN_MAP,h as TWIPS_PER_INCH,O as convertColorToHex,x as convertCssLengthToPixels,A as convertEmuStringToPixels,a as convertEmuToPixels,l as convertMeasureToInches,M as convertMeasureToPixels,N as convertPixelsToEmu,D as convertPixelsToTwip,I as convertTwipToCssString,u as convertTwipToPixels,R as createStringValidator,H as findChild,F as findDeepChild,f as findDeepChildren,S as normalizeHexColor,L as parseTwipAttr};
|