docxkeun 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +166 -16
  3. package/dist/api/editor.d.ts +231 -7
  4. package/dist/api/editor.js +1125 -26
  5. package/dist/api/headers.d.ts +51 -0
  6. package/dist/api/headers.js +133 -0
  7. package/dist/api/index.d.ts +6 -1
  8. package/dist/api/index.js +4 -1
  9. package/dist/api/lists.d.ts +37 -0
  10. package/dist/api/lists.js +132 -0
  11. package/dist/api/parts.js +1 -0
  12. package/dist/api/positions.js +1 -0
  13. package/dist/api/revisions.d.ts +61 -0
  14. package/dist/api/revisions.js +401 -0
  15. package/dist/api/selection.d.ts +57 -0
  16. package/dist/api/selection.js +91 -0
  17. package/dist/api/tables.d.ts +60 -0
  18. package/dist/api/tables.js +138 -0
  19. package/dist/charts/color.d.ts +45 -0
  20. package/dist/charts/color.js +322 -0
  21. package/dist/charts/format.d.ts +12 -0
  22. package/dist/charts/format.js +459 -0
  23. package/dist/charts/index.d.ts +11 -0
  24. package/dist/charts/index.js +8 -0
  25. package/dist/charts/model.d.ts +225 -0
  26. package/dist/charts/model.js +758 -0
  27. package/dist/charts/outline.d.ts +17 -0
  28. package/dist/charts/outline.js +214 -0
  29. package/dist/charts/render.d.ts +20 -0
  30. package/dist/charts/render.js +1772 -0
  31. package/dist/drawing/arrows.d.ts +37 -0
  32. package/dist/drawing/arrows.js +99 -0
  33. package/dist/drawing/formula.d.ts +40 -0
  34. package/dist/drawing/formula.js +159 -0
  35. package/dist/drawing/geometry.d.ts +61 -0
  36. package/dist/drawing/geometry.js +286 -0
  37. package/dist/drawing/index.d.ts +12 -0
  38. package/dist/drawing/index.js +8 -0
  39. package/dist/drawing/presets.d.ts +72 -0
  40. package/dist/drawing/presets.js +2874 -0
  41. package/dist/fonts/shaping/apply.d.ts +94 -0
  42. package/dist/fonts/shaping/apply.js +349 -0
  43. package/dist/fonts/shaping/arabic.d.ts +28 -0
  44. package/dist/fonts/shaping/arabic.js +235 -0
  45. package/dist/fonts/shaping/buffer.d.ts +53 -0
  46. package/dist/fonts/shaping/buffer.js +95 -0
  47. package/dist/fonts/shaping/gdef.d.ts +30 -0
  48. package/dist/fonts/shaping/gdef.js +66 -0
  49. package/dist/fonts/shaping/gpos.d.ts +86 -0
  50. package/dist/fonts/shaping/gpos.js +428 -0
  51. package/dist/fonts/shaping/gsub.d.ts +65 -0
  52. package/dist/fonts/shaping/gsub.js +313 -0
  53. package/dist/fonts/shaping/index.d.ts +32 -0
  54. package/dist/fonts/shaping/index.js +402 -0
  55. package/dist/fonts/shaping/indic.d.ts +6 -0
  56. package/dist/fonts/shaping/indic.js +805 -0
  57. package/dist/fonts/shaping/layout-common.d.ts +124 -0
  58. package/dist/fonts/shaping/layout-common.js +349 -0
  59. package/dist/fonts/shaping/plan.d.ts +87 -0
  60. package/dist/fonts/shaping/plan.js +152 -0
  61. package/dist/fonts/shaping/scripts.d.ts +26 -0
  62. package/dist/fonts/shaping/scripts.js +160 -0
  63. package/dist/fonts/shaping/shaper.d.ts +23 -0
  64. package/dist/fonts/shaping/shaper.js +5 -0
  65. package/dist/fonts/shaping/unicode.d.ts +34 -0
  66. package/dist/fonts/shaping/unicode.js +138 -0
  67. package/dist/images/bmp.d.ts +9 -0
  68. package/dist/images/bmp.js +234 -0
  69. package/dist/images/gif.d.ts +9 -0
  70. package/dist/images/gif.js +215 -0
  71. package/dist/images/index.d.ts +18 -0
  72. package/dist/images/index.js +63 -0
  73. package/dist/images/png-encode.d.ts +4 -0
  74. package/dist/images/png-encode.js +73 -0
  75. package/dist/images/size.d.ts +10 -0
  76. package/dist/images/size.js +83 -0
  77. package/dist/images/tiff.d.ts +14 -0
  78. package/dist/images/tiff.js +407 -0
  79. package/dist/index.d.ts +7 -2
  80. package/dist/index.js +5 -0
  81. package/dist/layout/bidi.d.ts +18 -0
  82. package/dist/layout/bidi.js +71 -0
  83. package/dist/layout/blocks.d.ts +20 -3
  84. package/dist/layout/blocks.js +88 -58
  85. package/dist/layout/cache.d.ts +31 -0
  86. package/dist/layout/cache.js +38 -0
  87. package/dist/layout/drawing.d.ts +30 -0
  88. package/dist/layout/drawing.js +120 -0
  89. package/dist/layout/engine.d.ts +3 -0
  90. package/dist/layout/engine.js +218 -11
  91. package/dist/layout/index.d.ts +1 -0
  92. package/dist/layout/index.js +1 -0
  93. package/dist/layout/lines.d.ts +63 -5
  94. package/dist/layout/lines.js +245 -20
  95. package/dist/layout/paint.d.ts +25 -3
  96. package/dist/layout/paint.js +26 -10
  97. package/dist/layout/shapes.d.ts +7 -0
  98. package/dist/layout/shapes.js +338 -0
  99. package/dist/layout/style.d.ts +4 -0
  100. package/dist/layout/style.js +2 -0
  101. package/dist/layout/types.d.ts +89 -2
  102. package/dist/math/boxes.d.ts +88 -0
  103. package/dist/math/boxes.js +166 -0
  104. package/dist/math/index.d.ts +29 -0
  105. package/dist/math/index.js +44 -0
  106. package/dist/math/layout.d.ts +13 -0
  107. package/dist/math/layout.js +771 -0
  108. package/dist/math/linear.d.ts +3 -0
  109. package/dist/math/linear.js +152 -0
  110. package/dist/math/omml.d.ts +15 -0
  111. package/dist/math/omml.js +57 -0
  112. package/dist/math/paths.d.ts +61 -0
  113. package/dist/math/paths.js +450 -0
  114. package/dist/math/symbols.d.ts +49 -0
  115. package/dist/math/symbols.js +269 -0
  116. package/dist/math/text.d.ts +53 -0
  117. package/dist/math/text.js +316 -0
  118. package/dist/metafile/canvas.d.ts +80 -0
  119. package/dist/metafile/canvas.js +515 -0
  120. package/dist/metafile/dib.d.ts +27 -0
  121. package/dist/metafile/dib.js +300 -0
  122. package/dist/metafile/emf.d.ts +31 -0
  123. package/dist/metafile/emf.js +591 -0
  124. package/dist/metafile/geometry.d.ts +49 -0
  125. package/dist/metafile/geometry.js +85 -0
  126. package/dist/metafile/index.d.ts +27 -0
  127. package/dist/metafile/index.js +34 -0
  128. package/dist/metafile/reader.d.ts +28 -0
  129. package/dist/metafile/reader.js +59 -0
  130. package/dist/metafile/state.d.ts +118 -0
  131. package/dist/metafile/state.js +172 -0
  132. package/dist/metafile/text.d.ts +17 -0
  133. package/dist/metafile/text.js +130 -0
  134. package/dist/metafile/wmf.d.ts +33 -0
  135. package/dist/metafile/wmf.js +395 -0
  136. package/dist/model/content.d.ts +92 -7
  137. package/dist/model/content.js +251 -17
  138. package/dist/model/document.d.ts +34 -1
  139. package/dist/model/document.js +80 -1
  140. package/dist/model/fields.d.ts +4 -0
  141. package/dist/model/fields.js +10 -0
  142. package/dist/model/numbering.d.ts +2 -0
  143. package/dist/model/numbering.js +22 -0
  144. package/dist/model/props.d.ts +2 -0
  145. package/dist/model/props.js +3 -0
  146. package/dist/opc/index.d.ts +1 -1
  147. package/dist/opc/package.d.ts +34 -0
  148. package/dist/opc/package.js +58 -4
  149. package/dist/pdf/export.js +97 -6
  150. package/dist/pdf/images.d.ts +7 -0
  151. package/dist/pdf/images.js +39 -2
  152. package/dist/render/activity.d.ts +179 -0
  153. package/dist/render/activity.js +1003 -0
  154. package/dist/render/clipboard.d.ts +29 -0
  155. package/dist/render/clipboard.js +401 -0
  156. package/dist/render/comments.d.ts +166 -0
  157. package/dist/render/comments.js +779 -0
  158. package/dist/render/context-menu.d.ts +124 -0
  159. package/dist/render/context-menu.js +525 -0
  160. package/dist/render/editing.d.ts +146 -5
  161. package/dist/render/editing.js +678 -53
  162. package/dist/render/index.d.ts +12 -0
  163. package/dist/render/index.js +11 -0
  164. package/dist/render/navigation-panel.d.ts +76 -0
  165. package/dist/render/navigation-panel.js +431 -0
  166. package/dist/render/selection.js +5 -0
  167. package/dist/render/svg.d.ts +4 -6
  168. package/dist/render/svg.js +69 -7
  169. package/dist/render/toolbar.d.ts +83 -0
  170. package/dist/render/toolbar.js +505 -0
  171. package/dist/render/ui/comment-layout.d.ts +39 -0
  172. package/dist/render/ui/comment-layout.js +79 -0
  173. package/dist/render/ui/icons.d.ts +6 -0
  174. package/dist/render/ui/icons.js +38 -0
  175. package/dist/render/ui/menu.d.ts +38 -0
  176. package/dist/render/ui/menu.js +274 -0
  177. package/dist/render/ui/nav-model.d.ts +11 -0
  178. package/dist/render/ui/nav-model.js +34 -0
  179. package/dist/render/ui/overflow.d.ts +5 -0
  180. package/dist/render/ui/overflow.js +18 -0
  181. package/dist/render/ui/popover.d.ts +18 -0
  182. package/dist/render/ui/popover.js +109 -0
  183. package/dist/render/ui/theme.d.ts +2 -0
  184. package/dist/render/ui/theme.js +29 -0
  185. package/dist/render/undo.d.ts +76 -0
  186. package/dist/render/undo.js +144 -0
  187. package/dist/render/viewer.d.ts +100 -7
  188. package/dist/render/viewer.js +304 -92
  189. package/dist/security/policy.d.ts +3 -0
  190. package/dist/security/policy.js +6 -2
  191. package/dist/security/protection.d.ts +1 -0
  192. package/dist/security/protection.js +1 -1
  193. package/dist/text/bidi-data.d.ts +53 -0
  194. package/dist/text/bidi-data.js +318 -0
  195. package/dist/text/bidi.d.ts +37 -0
  196. package/dist/text/bidi.js +508 -0
  197. package/dist/xml/ns.d.ts +5 -0
  198. package/dist/xml/ns.js +7 -0
  199. package/package.json +9 -2
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Lookup application machinery shared by GSUB and GPOS: lookup-flag glyph filtering, the
3
+ * "skipping iterator" that walks past ignored glyphs (marks for a ligature, default-ignorables,
4
+ * glyphs of other syllables), contextual rule matching and nested-lookup application.
5
+ *
6
+ * The semantics follow HarfBuzz's hb_ot_apply_context_t so fonts tuned against it (and
7
+ * Uniscribe/DirectWrite, which it mirrors) behave the same: e.g. ZWJ is transparent to
8
+ * input matching unless a feature asks for manual joiners, ZWNJ is always visible to GSUB
9
+ * input but ignored by GPOS.
10
+ */
11
+ import { type GlyphInfo } from './buffer.js';
12
+ import { type Gdef } from './gdef.js';
13
+ import { type ContextualSubtable, type LookupRecord } from './layout-common.js';
14
+ export declare const MAX_NESTING = 16;
15
+ /** How the skipping iterator treats glyphs for one match. */
16
+ export interface Matcher {
17
+ /** LookupFlag bits, with the mark filtering set index in the high 16 bits. */
18
+ props: number;
19
+ ignoreZwnj: boolean;
20
+ ignoreZwj: boolean;
21
+ /** Feature mask a matched glyph must carry (-1: any). */
22
+ mask: number;
23
+ /** Syllable a matched glyph must belong to (0: any). */
24
+ syllable: number;
25
+ }
26
+ type MatchFn = (info: GlyphInfo) => boolean;
27
+ export interface InputMatch {
28
+ positions: number[];
29
+ end: number;
30
+ totalComponents: number;
31
+ }
32
+ /** Applies one lookup (by index) at a buffer position; returns the next position or -1. */
33
+ export type LookupDispatcher = (ctx: ApplyContext, lookupIndex: number, i: number) => number;
34
+ /** Lookup props as HarfBuzz packs them: flags plus the mark filtering set in the high half. */
35
+ export declare function lookupProps(flag: number, markFilteringSet: number): number;
36
+ export declare class ApplyContext {
37
+ readonly buffer: GlyphInfo[];
38
+ readonly gdef: Gdef;
39
+ readonly tableIndex: 0 | 1;
40
+ readonly direction: 'ltr' | 'rtl';
41
+ readonly dispatch: LookupDispatcher;
42
+ lookupMask: number;
43
+ lookupProps: number;
44
+ autoZwj: boolean;
45
+ autoZwnj: boolean;
46
+ perSyllable: boolean;
47
+ nestingLeft: number;
48
+ /** Budget of nested-lookup calls, against fonts whose contextual lookups recurse wildly. */
49
+ opsLeft: number;
50
+ private nextLigId;
51
+ /**
52
+ * @param tableIndex 0 for GSUB, 1 for GPOS
53
+ * @param dispatch applies a lookup of this table once at a position (used for nesting)
54
+ */
55
+ constructor(buffer: GlyphInfo[], gdef: Gdef, tableIndex: 0 | 1, direction: 'ltr' | 'rtl', dispatch: LookupDispatcher);
56
+ allocLigId(): number;
57
+ /** Whether lookup flags let a glyph through (LookupFlag Ignore*, mark filtering). */
58
+ checkGlyphProperty(info: GlyphInfo, props: number): boolean;
59
+ inputMatcher(start: number): Matcher;
60
+ contextMatcher(start: number): Matcher;
61
+ private maySkip;
62
+ private mayMatch;
63
+ /** Next glyph after `i` that isn't skipped and matches `fn`, or -1 at a blocking glyph. */
64
+ next(i: number, m: Matcher, fn?: MatchFn): number;
65
+ prev(i: number, m: Matcher, fn?: MatchFn): number;
66
+ /**
67
+ * Matches `count` input glyphs starting at `i` (which the caller already matched as
68
+ * component 0). Ligature-id checks keep components of different earlier ligatures (and
69
+ * marks attached to them) from being glued together.
70
+ */
71
+ matchInput(i: number, count: number, fn: (info: GlyphInfo, k: number) => boolean): InputMatch | undefined;
72
+ private ligBaseSkippable;
73
+ /** Backtrack glyphs before `i`; `fn(info, 0)` is the nearest one. */
74
+ matchBacktrack(i: number, count: number, fn: (info: GlyphInfo, k: number) => boolean): boolean;
75
+ /** Lookahead glyphs after `last` (the last input glyph). */
76
+ matchLookahead(last: number, count: number, fn: (info: GlyphInfo, k: number) => boolean): boolean;
77
+ /** Applies a nested lookup at one position, with that lookup's own flags. */
78
+ recurse(lookupIndex: number, pos: number): boolean;
79
+ /**
80
+ * Runs a contextual rule's nested lookups over the matched input. Nested substitutions may
81
+ * grow or shrink the buffer, so match positions after the edited one are shifted the way
82
+ * HarfBuzz does it. Returns the (adjusted) end of the matched input.
83
+ */
84
+ applyNested(records: readonly LookupRecord[], positions: number[], matchEnd: number): number;
85
+ /** Context / chaining-context subtable at position `i`. */
86
+ applyContextual(st: ContextualSubtable, i: number): number;
87
+ private applyRule;
88
+ /**
89
+ * Applies a lookup over the whole buffer (or backwards for reverse-chaining lookups),
90
+ * only at glyphs carrying `mask` and passing the lookup flags.
91
+ */
92
+ applyLookup(lookupIndex: number, props: number, mask: number, reverse: boolean): void;
93
+ }
94
+ export {};
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Lookup application machinery shared by GSUB and GPOS: lookup-flag glyph filtering, the
3
+ * "skipping iterator" that walks past ignored glyphs (marks for a ligature, default-ignorables,
4
+ * glyphs of other syllables), contextual rule matching and nested-lookup application.
5
+ *
6
+ * The semantics follow HarfBuzz's hb_ot_apply_context_t so fonts tuned against it (and
7
+ * Uniscribe/DirectWrite, which it mirrors) behave the same: e.g. ZWJ is transparent to
8
+ * input matching unless a feature asks for manual joiners, ZWNJ is always visible to GSUB
9
+ * input but ignored by GPOS.
10
+ */
11
+ import { ligComp, ligNumComps } from './buffer.js';
12
+ import { GlyphProps } from './gdef.js';
13
+ import { classOf, LookupFlag } from './layout-common.js';
14
+ import { UFlag } from './unicode.js';
15
+ export const MAX_NESTING = 16;
16
+ const MAX_CONTEXT = 64;
17
+ const SKIP_NO = 0;
18
+ const SKIP_YES = 1;
19
+ const SKIP_MAYBE = 2;
20
+ const MATCH_NO = 0;
21
+ const MATCH_YES = 1;
22
+ const MATCH_MAYBE = 2;
23
+ /** Lookup props as HarfBuzz packs them: flags plus the mark filtering set in the high half. */
24
+ export function lookupProps(flag, markFilteringSet) {
25
+ return (flag & 0xffff) | (flag & LookupFlag.UseMarkFilteringSet ? (markFilteringSet & 0xffff) * 0x10000 : 0);
26
+ }
27
+ export class ApplyContext {
28
+ buffer;
29
+ gdef;
30
+ tableIndex;
31
+ direction;
32
+ dispatch;
33
+ lookupMask = 1;
34
+ lookupProps = 0;
35
+ autoZwj = true;
36
+ autoZwnj = true;
37
+ perSyllable = false;
38
+ nestingLeft = MAX_NESTING;
39
+ /** Budget of nested-lookup calls, against fonts whose contextual lookups recurse wildly. */
40
+ opsLeft;
41
+ nextLigId = 1;
42
+ /**
43
+ * @param tableIndex 0 for GSUB, 1 for GPOS
44
+ * @param dispatch applies a lookup of this table once at a position (used for nesting)
45
+ */
46
+ constructor(buffer, gdef, tableIndex, direction, dispatch) {
47
+ this.buffer = buffer;
48
+ this.gdef = gdef;
49
+ this.tableIndex = tableIndex;
50
+ this.direction = direction;
51
+ this.dispatch = dispatch;
52
+ this.opsLeft = Math.max(16384, buffer.length * 256);
53
+ }
54
+ allocLigId() {
55
+ return this.nextLigId++;
56
+ }
57
+ /** Whether lookup flags let a glyph through (LookupFlag Ignore*, mark filtering). */
58
+ checkGlyphProperty(info, props) {
59
+ const gp = info.props;
60
+ if (gp & props & LookupFlag.IgnoreFlags)
61
+ return false;
62
+ if (gp & GlyphProps.Mark) {
63
+ if (props & LookupFlag.UseMarkFilteringSet)
64
+ return this.gdef.markSetCovers(props >>> 16, info.glyph);
65
+ if (props & LookupFlag.MarkAttachmentType)
66
+ return (props & LookupFlag.MarkAttachmentType) === (gp & GlyphProps.MarkAttachClass);
67
+ }
68
+ return true;
69
+ }
70
+ inputMatcher(start) {
71
+ return {
72
+ props: this.lookupProps,
73
+ ignoreZwnj: this.tableIndex === 1,
74
+ ignoreZwj: this.tableIndex === 1 || this.autoZwj,
75
+ mask: this.lookupMask,
76
+ syllable: this.tableIndex === 0 && this.perSyllable ? (this.buffer[start]?.syllable ?? 0) : 0,
77
+ };
78
+ }
79
+ contextMatcher(start) {
80
+ return {
81
+ props: this.lookupProps,
82
+ ignoreZwnj: this.tableIndex === 1 || this.autoZwnj,
83
+ ignoreZwj: true,
84
+ mask: -1,
85
+ syllable: this.tableIndex === 0 && this.perSyllable ? (this.buffer[start]?.syllable ?? 0) : 0,
86
+ };
87
+ }
88
+ maySkip(info, m) {
89
+ if (!this.checkGlyphProperty(info, m.props))
90
+ return SKIP_YES;
91
+ const u = info.uflags;
92
+ if (u & UFlag.DefaultIgnorable &&
93
+ !(info.props & GlyphProps.Substituted) &&
94
+ (m.ignoreZwnj || !(u & UFlag.Zwnj)) &&
95
+ (m.ignoreZwj || !(u & UFlag.Zwj))) {
96
+ return SKIP_MAYBE;
97
+ }
98
+ return SKIP_NO;
99
+ }
100
+ mayMatch(info, m, fn) {
101
+ if (!(info.mask & m.mask) || (m.syllable && m.syllable !== info.syllable))
102
+ return MATCH_NO;
103
+ if (fn)
104
+ return fn(info) ? MATCH_YES : MATCH_NO;
105
+ return MATCH_MAYBE;
106
+ }
107
+ /** Next glyph after `i` that isn't skipped and matches `fn`, or -1 at a blocking glyph. */
108
+ next(i, m, fn) {
109
+ const buf = this.buffer;
110
+ for (let j = i + 1; j < buf.length; j++) {
111
+ const info = buf[j];
112
+ const skip = this.maySkip(info, m);
113
+ if (skip === SKIP_YES)
114
+ continue;
115
+ const match = this.mayMatch(info, m, fn);
116
+ if (match === MATCH_YES || (match === MATCH_MAYBE && skip === SKIP_NO))
117
+ return j;
118
+ if (skip === SKIP_NO)
119
+ return -1;
120
+ }
121
+ return -1;
122
+ }
123
+ prev(i, m, fn) {
124
+ const buf = this.buffer;
125
+ for (let j = i - 1; j >= 0; j--) {
126
+ const info = buf[j];
127
+ const skip = this.maySkip(info, m);
128
+ if (skip === SKIP_YES)
129
+ continue;
130
+ const match = this.mayMatch(info, m, fn);
131
+ if (match === MATCH_YES || (match === MATCH_MAYBE && skip === SKIP_NO))
132
+ return j;
133
+ if (skip === SKIP_NO)
134
+ return -1;
135
+ }
136
+ return -1;
137
+ }
138
+ /**
139
+ * Matches `count` input glyphs starting at `i` (which the caller already matched as
140
+ * component 0). Ligature-id checks keep components of different earlier ligatures (and
141
+ * marks attached to them) from being glued together.
142
+ */
143
+ matchInput(i, count, fn) {
144
+ const buf = this.buffer;
145
+ const m = this.inputMatcher(i);
146
+ const first = buf[i];
147
+ const firstLigId = first.ligId;
148
+ const firstLigComp = ligComp(first);
149
+ let total = ligNumComps(first);
150
+ const positions = [i];
151
+ let j = i;
152
+ for (let k = 1; k < count; k++) {
153
+ j = this.next(j, m, (info) => fn(info, k));
154
+ if (j < 0)
155
+ return undefined;
156
+ const info = buf[j];
157
+ const thisLigId = info.ligId;
158
+ const thisLigComp = ligComp(info);
159
+ if (firstLigId && firstLigComp) {
160
+ // All components must hang off the same earlier ligature component, unless that
161
+ // ligature itself is ignored by this lookup.
162
+ if ((firstLigId !== thisLigId || firstLigComp !== thisLigComp) && !this.ligBaseSkippable(i, firstLigId, m))
163
+ return undefined;
164
+ }
165
+ else if (thisLigId && thisLigComp && thisLigId !== firstLigId) {
166
+ return undefined;
167
+ }
168
+ total += ligNumComps(info);
169
+ positions.push(j);
170
+ }
171
+ return { positions, end: j + 1, totalComponents: total };
172
+ }
173
+ ligBaseSkippable(i, ligId, m) {
174
+ const buf = this.buffer;
175
+ for (let j = i - 1; j >= 0 && buf[j].ligId === ligId; j--) {
176
+ if (ligComp(buf[j]) === 0)
177
+ return this.maySkip(buf[j], m) === SKIP_YES;
178
+ }
179
+ return false;
180
+ }
181
+ /** Backtrack glyphs before `i`; `fn(info, 0)` is the nearest one. */
182
+ matchBacktrack(i, count, fn) {
183
+ const m = this.contextMatcher(i);
184
+ let j = i;
185
+ for (let k = 0; k < count; k++) {
186
+ j = this.prev(j, m, (info) => fn(info, k));
187
+ if (j < 0)
188
+ return false;
189
+ }
190
+ return true;
191
+ }
192
+ /** Lookahead glyphs after `last` (the last input glyph). */
193
+ matchLookahead(last, count, fn) {
194
+ const m = this.contextMatcher(last);
195
+ let j = last;
196
+ for (let k = 0; k < count; k++) {
197
+ j = this.next(j, m, (info) => fn(info, k));
198
+ if (j < 0)
199
+ return false;
200
+ }
201
+ return true;
202
+ }
203
+ /** Applies a nested lookup at one position, with that lookup's own flags. */
204
+ recurse(lookupIndex, pos) {
205
+ if (this.nestingLeft <= 0 || this.opsLeft-- <= 0)
206
+ return false;
207
+ const savedProps = this.lookupProps;
208
+ this.nestingLeft--;
209
+ const applied = this.dispatch(this, lookupIndex, pos) >= 0;
210
+ this.nestingLeft++;
211
+ this.lookupProps = savedProps;
212
+ return applied;
213
+ }
214
+ /**
215
+ * Runs a contextual rule's nested lookups over the matched input. Nested substitutions may
216
+ * grow or shrink the buffer, so match positions after the edited one are shifted the way
217
+ * HarfBuzz does it. Returns the (adjusted) end of the matched input.
218
+ */
219
+ applyNested(records, positions, matchEnd) {
220
+ const buf = this.buffer;
221
+ let count = positions.length;
222
+ let end = matchEnd;
223
+ for (const rec of records) {
224
+ const idx = rec.sequenceIndex;
225
+ if (idx >= count)
226
+ continue;
227
+ const origLen = buf.length;
228
+ const at = positions[idx];
229
+ if (at >= origLen)
230
+ continue;
231
+ if (!this.recurse(rec.lookupIndex, at))
232
+ continue;
233
+ let delta = buf.length - origLen;
234
+ if (!delta)
235
+ continue;
236
+ end += delta;
237
+ if (end < at) {
238
+ delta += at - end;
239
+ end = at;
240
+ }
241
+ let next = idx + 1;
242
+ if (delta > 0) {
243
+ if (delta + count > MAX_CONTEXT)
244
+ break;
245
+ }
246
+ else {
247
+ delta = Math.max(delta, next - count);
248
+ next -= delta;
249
+ }
250
+ const moved = positions.slice(next, count);
251
+ for (let k = 0; k < moved.length; k++)
252
+ positions[next + delta + k] = moved[k];
253
+ next += delta;
254
+ count += delta;
255
+ positions.length = count;
256
+ for (let j = idx + 1; j < next; j++)
257
+ positions[j] = positions[j - 1] + 1;
258
+ for (; next < count; next++)
259
+ positions[next] = positions[next] + delta;
260
+ }
261
+ return end;
262
+ }
263
+ /** Context / chaining-context subtable at position `i`. */
264
+ applyContextual(st, i) {
265
+ const glyph = this.buffer[i].glyph;
266
+ switch (st.kind) {
267
+ case 'ctx-glyphs': {
268
+ const ci = st.coverage.get(glyph);
269
+ const rules = ci === undefined ? undefined : st.ruleSets[ci];
270
+ if (!rules)
271
+ return -1;
272
+ for (const r of rules) {
273
+ const next = this.applyRule(i, r.input.length + 1, (info, k) => info.glyph === r.input[k - 1], r.backtrack.length, (info, k) => info.glyph === r.backtrack[k], r.lookahead.length, (info, k) => info.glyph === r.lookahead[k], r.lookups);
274
+ if (next >= 0)
275
+ return next;
276
+ }
277
+ return -1;
278
+ }
279
+ case 'ctx-classes': {
280
+ if (!st.coverage.has(glyph))
281
+ return -1;
282
+ const rules = st.ruleSets[classOf(st.inputClasses, glyph)];
283
+ if (!rules)
284
+ return -1;
285
+ for (const r of rules) {
286
+ const next = this.applyRule(i, r.input.length + 1, (info, k) => classOf(st.inputClasses, info.glyph) === r.input[k - 1], r.backtrack.length, (info, k) => classOf(st.backtrackClasses, info.glyph) === r.backtrack[k], r.lookahead.length, (info, k) => classOf(st.lookaheadClasses, info.glyph) === r.lookahead[k], r.lookups);
287
+ if (next >= 0)
288
+ return next;
289
+ }
290
+ return -1;
291
+ }
292
+ case 'ctx-coverage': {
293
+ if (!st.input[0]?.has(glyph))
294
+ return -1;
295
+ return this.applyRule(i, st.input.length, (info, k) => st.input[k]?.has(info.glyph) ?? false, st.backtrack.length, (info, k) => st.backtrack[k]?.has(info.glyph) ?? false, st.lookahead.length, (info, k) => st.lookahead[k]?.has(info.glyph) ?? false, st.lookups);
296
+ }
297
+ }
298
+ }
299
+ applyRule(i, inputCount, inputFn, backCount, backFn, aheadCount, aheadFn, records) {
300
+ const match = this.matchInput(i, inputCount, inputFn);
301
+ if (!match)
302
+ return -1;
303
+ if (!this.matchLookahead(match.end - 1, aheadCount, aheadFn))
304
+ return -1;
305
+ if (!this.matchBacktrack(i, backCount, backFn))
306
+ return -1;
307
+ // The end only moves back to `i` when nested lookups deleted glyphs, so this always
308
+ // makes progress.
309
+ return this.applyNested(records, match.positions, match.end);
310
+ }
311
+ /**
312
+ * Applies a lookup over the whole buffer (or backwards for reverse-chaining lookups),
313
+ * only at glyphs carrying `mask` and passing the lookup flags.
314
+ */
315
+ applyLookup(lookupIndex, props, mask, reverse) {
316
+ const buf = this.buffer;
317
+ this.lookupMask = mask;
318
+ this.lookupProps = props;
319
+ if (reverse) {
320
+ for (let i = buf.length - 1; i >= 0; i--) {
321
+ const info = buf[i];
322
+ if (info.mask & mask && this.checkGlyphProperty(info, props)) {
323
+ this.dispatch(this, lookupIndex, i);
324
+ this.lookupProps = props;
325
+ }
326
+ }
327
+ return;
328
+ }
329
+ // Only successful applications can fail to advance, so only they count against the
330
+ // budget that stops a looping or exploding font.
331
+ const maxLength = Math.max(256, buf.length * 32);
332
+ let budget = Math.max(1024, buf.length * 16);
333
+ let i = 0;
334
+ while (i < buf.length) {
335
+ const info = buf[i];
336
+ if (info.mask & mask && this.checkGlyphProperty(info, props)) {
337
+ const next = this.dispatch(this, lookupIndex, i);
338
+ this.lookupProps = props;
339
+ if (next >= 0) {
340
+ if (--budget <= 0 || buf.length > maxLength)
341
+ return;
342
+ i = next;
343
+ continue;
344
+ }
345
+ }
346
+ i++;
347
+ }
348
+ }
349
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Arabic-style shaper (Arabic, Syriac, N'Ko, Mongolian): joining analysis picks each letter's
3
+ * contextual form (isol / fina / medi / init, plus Syriac fin2 / fin3 / med2 after Alaph),
4
+ * and those forms are applied as per-glyph features one stage at a time before rlig (where
5
+ * fonts form lam-alef), calt, liga and mset. Positioning then runs curs (cursive joining,
6
+ * e.g. Nastaliq), kern, mark and mkmk.
7
+ *
8
+ * Joining types are from Unicode's ArabicShaping.txt for the Arabic, Arabic Supplement,
9
+ * Arabic Extended-A/B, Syriac, N'Ko and Mongolian blocks. Characters not listed are
10
+ * non-joining, except marks and format controls, which are transparent.
11
+ *
12
+ * For fonts with no Arabic GSUB forms at all, a fallback maps letters to their Unicode
13
+ * presentation forms (U+FB50..U+FEFC) when the font has those glyphs.
14
+ */
15
+ import { type GlyphInfo } from './buffer.js';
16
+ import type { Shaper } from './shaper.js';
17
+ export declare const ISOL = 0;
18
+ export declare const FINA = 1;
19
+ export declare const FIN2 = 2;
20
+ export declare const FIN3 = 3;
21
+ export declare const MEDI = 4;
22
+ export declare const MED2 = 5;
23
+ export declare const INIT = 6;
24
+ export declare const NONE = 7;
25
+ export declare const ARABIC_FEATURES: readonly ['isol', 'fina', 'fin2', 'fin3', 'medi', 'med2', 'init'];
26
+ /** Stores each glyph's joining action (ISOL..INIT or NONE) in `info.cat`. */
27
+ export declare function arabicJoining(buf: GlyphInfo[]): void;
28
+ export declare const arabicShaper: Shaper;