ooxml-core 0.8.0 → 0.9.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.
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ // src/text/unicode-script-detection.ts
4
+ function detectFontScript(codePoint) {
5
+ if (codePoint >= 11904 && codePoint <= 40959 || // CJK radicals, unified ideographs
6
+ codePoint >= 44032 && codePoint <= 55215 || // Hangul syllables
7
+ codePoint >= 63744 && codePoint <= 64255 || // CJK compatibility ideographs
8
+ codePoint >= 65072 && codePoint <= 65103 || // CJK compatibility forms
9
+ codePoint >= 131072 && codePoint <= 195103 || // CJK extension B-F
10
+ codePoint >= 12288 && codePoint <= 12351 || // CJK symbols & punctuation
11
+ codePoint >= 12352 && codePoint <= 12447 || // Hiragana
12
+ codePoint >= 12448 && codePoint <= 12543 || // Katakana
13
+ codePoint >= 12784 && codePoint <= 12799 || // Katakana extensions
14
+ codePoint >= 65280 && codePoint <= 65519) {
15
+ return "eastAsia";
16
+ }
17
+ if (codePoint >= 1424 && codePoint <= 1535 || // Hebrew
18
+ codePoint >= 1536 && codePoint <= 1791 || // Arabic
19
+ codePoint >= 1792 && codePoint <= 1871 || // Syriac
20
+ codePoint >= 1872 && codePoint <= 1919 || // Arabic Supplement
21
+ codePoint >= 1920 && codePoint <= 1983 || // Thaana
22
+ codePoint >= 1984 && codePoint <= 2047 || // NKo
23
+ codePoint >= 2048 && codePoint <= 2111 || // Samaritan
24
+ codePoint >= 2304 && codePoint <= 2431 || // Devanagari
25
+ codePoint >= 2432 && codePoint <= 2559 || // Bengali
26
+ codePoint >= 2560 && codePoint <= 2687 || // Gurmukhi
27
+ codePoint >= 2688 && codePoint <= 2815 || // Gujarati
28
+ codePoint >= 2816 && codePoint <= 2943 || // Oriya
29
+ codePoint >= 2944 && codePoint <= 3071 || // Tamil
30
+ codePoint >= 3072 && codePoint <= 3199 || // Telugu
31
+ codePoint >= 3200 && codePoint <= 3327 || // Kannada
32
+ codePoint >= 3328 && codePoint <= 3455 || // Malayalam
33
+ codePoint >= 3456 && codePoint <= 3583 || // Sinhala
34
+ codePoint >= 3584 && codePoint <= 3711 || // Thai
35
+ codePoint >= 3712 && codePoint <= 3839 || // Lao
36
+ codePoint >= 3840 && codePoint <= 4095 || // Tibetan
37
+ codePoint >= 4096 && codePoint <= 4255 || // Myanmar
38
+ codePoint >= 4256 && codePoint <= 4351 || // Georgian
39
+ codePoint >= 6016 && codePoint <= 6143 || // Khmer
40
+ codePoint >= 64336 && codePoint <= 65023 || // Arabic Presentation Forms-A
41
+ codePoint >= 65136 && codePoint <= 65279) {
42
+ return "complexScript";
43
+ }
44
+ if (codePoint >= 8592 && codePoint <= 8703 || // Arrows
45
+ codePoint >= 8704 && codePoint <= 8959 || // Mathematical operators
46
+ codePoint >= 8960 && codePoint <= 9215 || // Misc technical
47
+ codePoint >= 9472 && codePoint <= 9599 || // Box drawing
48
+ codePoint >= 9600 && codePoint <= 9631 || // Block elements
49
+ codePoint >= 9632 && codePoint <= 9727 || // Geometric shapes
50
+ codePoint >= 9728 && codePoint <= 9983 || // Misc symbols
51
+ codePoint >= 9984 && codePoint <= 10175 || // Dingbats
52
+ codePoint >= 57344 && codePoint <= 63743 || // Private Use Area
53
+ codePoint >= 126976 && codePoint <= 129535) {
54
+ return "symbol";
55
+ }
56
+ return "latin";
57
+ }
58
+ function segmentByScript(text) {
59
+ if (!text) {
60
+ return [];
61
+ }
62
+ const runs = [];
63
+ let currentScript = null;
64
+ let currentStart = 0;
65
+ let currentText = "";
66
+ for (let i = 0; i < text.length; i++) {
67
+ const codePoint = text.codePointAt(i);
68
+ if (codePoint === void 0) {
69
+ continue;
70
+ }
71
+ const charLength = codePoint > 65535 ? 2 : 1;
72
+ const char = text.substring(i, i + charLength);
73
+ const isNeutral = codePoint <= 127 && !/[a-zA-Z0-9]/u.test(char);
74
+ const script = isNeutral ? currentScript ?? "latin" : detectFontScript(codePoint);
75
+ if (script !== currentScript && currentScript !== null) {
76
+ runs.push({
77
+ text: currentText,
78
+ script: currentScript,
79
+ startIndex: currentStart
80
+ });
81
+ currentStart = i;
82
+ currentText = "";
83
+ }
84
+ currentScript = script;
85
+ currentText += char;
86
+ if (charLength === 2) {
87
+ i++;
88
+ }
89
+ }
90
+ if (currentText && currentScript) {
91
+ runs.push({
92
+ text: currentText,
93
+ script: currentScript,
94
+ startIndex: currentStart
95
+ });
96
+ }
97
+ return runs;
98
+ }
99
+ function resolveFontForScript(script, fonts) {
100
+ switch (script) {
101
+ case "latin":
102
+ return fonts.latin;
103
+ case "eastAsia":
104
+ return fonts.eastAsia || fonts.latin;
105
+ case "complexScript":
106
+ return fonts.complexScript || fonts.latin;
107
+ case "symbol":
108
+ return fonts.symbol || fonts.latin;
109
+ }
110
+ }
111
+ function hasDistinctScriptFonts(fonts) {
112
+ const base = fonts.latin;
113
+ if (!base) {
114
+ return false;
115
+ }
116
+ return Boolean(fonts.eastAsia) && fonts.eastAsia !== base || Boolean(fonts.complexScript) && fonts.complexScript !== base || Boolean(fonts.symbol) && fonts.symbol !== base;
117
+ }
118
+
119
+ exports.detectFontScript = detectFontScript;
120
+ exports.hasDistinctScriptFonts = hasDistinctScriptFonts;
121
+ exports.resolveFontForScript = resolveFontForScript;
122
+ exports.segmentByScript = segmentByScript;
@@ -0,0 +1,3 @@
1
+ /** Browser-neutral text primitives shared by Office consumers. */
2
+ export { detectFontScript, segmentByScript, resolveFontForScript, hasDistinctScriptFonts, type FontScriptCategory, type ScriptRun, } from './unicode-script-detection.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/text/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EACN,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,SAAS,GACd,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,117 @@
1
+ // src/text/unicode-script-detection.ts
2
+ function detectFontScript(codePoint) {
3
+ if (codePoint >= 11904 && codePoint <= 40959 || // CJK radicals, unified ideographs
4
+ codePoint >= 44032 && codePoint <= 55215 || // Hangul syllables
5
+ codePoint >= 63744 && codePoint <= 64255 || // CJK compatibility ideographs
6
+ codePoint >= 65072 && codePoint <= 65103 || // CJK compatibility forms
7
+ codePoint >= 131072 && codePoint <= 195103 || // CJK extension B-F
8
+ codePoint >= 12288 && codePoint <= 12351 || // CJK symbols & punctuation
9
+ codePoint >= 12352 && codePoint <= 12447 || // Hiragana
10
+ codePoint >= 12448 && codePoint <= 12543 || // Katakana
11
+ codePoint >= 12784 && codePoint <= 12799 || // Katakana extensions
12
+ codePoint >= 65280 && codePoint <= 65519) {
13
+ return "eastAsia";
14
+ }
15
+ if (codePoint >= 1424 && codePoint <= 1535 || // Hebrew
16
+ codePoint >= 1536 && codePoint <= 1791 || // Arabic
17
+ codePoint >= 1792 && codePoint <= 1871 || // Syriac
18
+ codePoint >= 1872 && codePoint <= 1919 || // Arabic Supplement
19
+ codePoint >= 1920 && codePoint <= 1983 || // Thaana
20
+ codePoint >= 1984 && codePoint <= 2047 || // NKo
21
+ codePoint >= 2048 && codePoint <= 2111 || // Samaritan
22
+ codePoint >= 2304 && codePoint <= 2431 || // Devanagari
23
+ codePoint >= 2432 && codePoint <= 2559 || // Bengali
24
+ codePoint >= 2560 && codePoint <= 2687 || // Gurmukhi
25
+ codePoint >= 2688 && codePoint <= 2815 || // Gujarati
26
+ codePoint >= 2816 && codePoint <= 2943 || // Oriya
27
+ codePoint >= 2944 && codePoint <= 3071 || // Tamil
28
+ codePoint >= 3072 && codePoint <= 3199 || // Telugu
29
+ codePoint >= 3200 && codePoint <= 3327 || // Kannada
30
+ codePoint >= 3328 && codePoint <= 3455 || // Malayalam
31
+ codePoint >= 3456 && codePoint <= 3583 || // Sinhala
32
+ codePoint >= 3584 && codePoint <= 3711 || // Thai
33
+ codePoint >= 3712 && codePoint <= 3839 || // Lao
34
+ codePoint >= 3840 && codePoint <= 4095 || // Tibetan
35
+ codePoint >= 4096 && codePoint <= 4255 || // Myanmar
36
+ codePoint >= 4256 && codePoint <= 4351 || // Georgian
37
+ codePoint >= 6016 && codePoint <= 6143 || // Khmer
38
+ codePoint >= 64336 && codePoint <= 65023 || // Arabic Presentation Forms-A
39
+ codePoint >= 65136 && codePoint <= 65279) {
40
+ return "complexScript";
41
+ }
42
+ if (codePoint >= 8592 && codePoint <= 8703 || // Arrows
43
+ codePoint >= 8704 && codePoint <= 8959 || // Mathematical operators
44
+ codePoint >= 8960 && codePoint <= 9215 || // Misc technical
45
+ codePoint >= 9472 && codePoint <= 9599 || // Box drawing
46
+ codePoint >= 9600 && codePoint <= 9631 || // Block elements
47
+ codePoint >= 9632 && codePoint <= 9727 || // Geometric shapes
48
+ codePoint >= 9728 && codePoint <= 9983 || // Misc symbols
49
+ codePoint >= 9984 && codePoint <= 10175 || // Dingbats
50
+ codePoint >= 57344 && codePoint <= 63743 || // Private Use Area
51
+ codePoint >= 126976 && codePoint <= 129535) {
52
+ return "symbol";
53
+ }
54
+ return "latin";
55
+ }
56
+ function segmentByScript(text) {
57
+ if (!text) {
58
+ return [];
59
+ }
60
+ const runs = [];
61
+ let currentScript = null;
62
+ let currentStart = 0;
63
+ let currentText = "";
64
+ for (let i = 0; i < text.length; i++) {
65
+ const codePoint = text.codePointAt(i);
66
+ if (codePoint === void 0) {
67
+ continue;
68
+ }
69
+ const charLength = codePoint > 65535 ? 2 : 1;
70
+ const char = text.substring(i, i + charLength);
71
+ const isNeutral = codePoint <= 127 && !/[a-zA-Z0-9]/u.test(char);
72
+ const script = isNeutral ? currentScript ?? "latin" : detectFontScript(codePoint);
73
+ if (script !== currentScript && currentScript !== null) {
74
+ runs.push({
75
+ text: currentText,
76
+ script: currentScript,
77
+ startIndex: currentStart
78
+ });
79
+ currentStart = i;
80
+ currentText = "";
81
+ }
82
+ currentScript = script;
83
+ currentText += char;
84
+ if (charLength === 2) {
85
+ i++;
86
+ }
87
+ }
88
+ if (currentText && currentScript) {
89
+ runs.push({
90
+ text: currentText,
91
+ script: currentScript,
92
+ startIndex: currentStart
93
+ });
94
+ }
95
+ return runs;
96
+ }
97
+ function resolveFontForScript(script, fonts) {
98
+ switch (script) {
99
+ case "latin":
100
+ return fonts.latin;
101
+ case "eastAsia":
102
+ return fonts.eastAsia || fonts.latin;
103
+ case "complexScript":
104
+ return fonts.complexScript || fonts.latin;
105
+ case "symbol":
106
+ return fonts.symbol || fonts.latin;
107
+ }
108
+ }
109
+ function hasDistinctScriptFonts(fonts) {
110
+ const base = fonts.latin;
111
+ if (!base) {
112
+ return false;
113
+ }
114
+ return Boolean(fonts.eastAsia) && fonts.eastAsia !== base || Boolean(fonts.complexScript) && fonts.complexScript !== base || Boolean(fonts.symbol) && fonts.symbol !== base;
115
+ }
116
+
117
+ export { detectFontScript, hasDistinctScriptFonts, resolveFontForScript, segmentByScript };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Unicode script detection for font fallback.
3
+ *
4
+ * Classifies code points into the font groups historically used by the
5
+ * PowerPoint viewer. This block-based heuristic is not a Unicode Script
6
+ * property implementation or Word's language/hint/bidi font-slot selection.
7
+ * It does not choose or load fonts, shape glyphs or modify document models.
8
+ */
9
+ /** OOXML font script category. */
10
+ export type FontScriptCategory = 'latin' | 'eastAsia' | 'complexScript' | 'symbol';
11
+ /**
12
+ * Detect the OOXML font script category for a single character.
13
+ *
14
+ * Uses Unicode block ranges to determine if a character belongs to:
15
+ * - Latin (Basic Latin, Latin Extended, Greek, Cyrillic, etc.)
16
+ * - East Asian (CJK Unified Ideographs, Hiragana, Katakana, Hangul, etc.)
17
+ * - Complex Script (Arabic, Hebrew, Devanagari, Thai, etc.)
18
+ * - Symbol (Dingbats, Mathematical, etc.)
19
+ */
20
+ export declare function detectFontScript(codePoint: number): FontScriptCategory;
21
+ /** A contiguous run of characters sharing the same font script category. */
22
+ export interface ScriptRun {
23
+ text: string;
24
+ script: FontScriptCategory;
25
+ /** UTF-16 offset in the original string, matching JavaScript string slicing. */
26
+ startIndex: number;
27
+ }
28
+ /**
29
+ * Segment a string into runs of the same font script category.
30
+ * Adjacent characters with the same script are grouped together.
31
+ * Whitespace and ASCII punctuation inherit the previous run's script.
32
+ */
33
+ export declare function segmentByScript(text: string): ScriptRun[];
34
+ /**
35
+ * Resolve the font family for a given script category from available fonts.
36
+ * Falls back to latin when a script-specific font is not available.
37
+ */
38
+ export declare function resolveFontForScript(script: FontScriptCategory, fonts: {
39
+ latin?: string;
40
+ eastAsia?: string;
41
+ complexScript?: string;
42
+ symbol?: string;
43
+ }): string | undefined;
44
+ /**
45
+ * Check whether per-script fonts are actually different from the base latin font.
46
+ * Returns `true` when at least one script-specific font differs.
47
+ */
48
+ export declare function hasDistinctScriptFonts(fonts: {
49
+ latin?: string;
50
+ eastAsia?: string;
51
+ complexScript?: string;
52
+ symbol?: string;
53
+ }): boolean;
54
+ //# sourceMappingURL=unicode-script-detection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unicode-script-detection.d.ts","sourceRoot":"","sources":["../../src/text/unicode-script-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,kCAAkC;AAClC,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,UAAU,GAAG,eAAe,GAAG,QAAQ,CAAC;AAEnF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,CAkEtE;AAED,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAqDzD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE;IACN,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,GACC,MAAM,GAAG,SAAS,CAWpB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAUV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml-core",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared OOXML logic for the Word, PowerPoint and Excel viewers: everything except the UI",
5
5
  "keywords": [
6
6
  "charts",
@@ -66,6 +66,16 @@
66
66
  "import": "./dist/geometry/index.mjs",
67
67
  "require": "./dist/geometry/index.cjs"
68
68
  },
69
+ "./chart": {
70
+ "types": "./dist/chart/index.d.ts",
71
+ "import": "./dist/chart/index.mjs",
72
+ "require": "./dist/chart/index.cjs"
73
+ },
74
+ "./text": {
75
+ "types": "./dist/text/index.d.ts",
76
+ "import": "./dist/text/index.mjs",
77
+ "require": "./dist/text/index.cjs"
78
+ },
69
79
  "./diagram": {
70
80
  "types": "./dist/diagram/index.d.ts",
71
81
  "import": "./dist/diagram/index.mjs",