bidi-shaper
Version:
Logical→visual Unicode BiDi (UAX #9) reordering + Arabic contextual shaping for renderers outside the browser (PDF, canvas, WebGL, SVG, terminals, games). Zero dependencies.
38 lines (34 loc) • 1.61 kB
TypeScript
import { R as RenderOptions } from '../render-BhplWt64.js';
/**
* jsPDF adapter (`bidi-shaper/jspdf`).
*
* jsPDF draws text runs left-to-right with no shaping. Either process each
* string yourself with {@link rtlText}, or call {@link installJsPdfShaper}
* once so every doc.text() is processed automatically via jsPDF's
* `preProcessText` plugin event.
*
* The output uses Arabic presentation forms (U+FB50–U+FEFF), which jsPDF's
* built-in arabic parser does not touch — the two do not double-process.
* Your embedded font must include those glyphs (most Arabic TTFs do).
*/
/** A jsPDF `preProcessText` event payload (structurally typed — no jspdf dependency). */
interface JsPdfTextPayload {
text: string | string[];
}
/** The static jsPDF API object (`jsPDF.API`), as far as this adapter needs it. */
interface JsPdfStaticApi {
events: Array<[string, (payload: JsPdfTextPayload) => void]>;
}
/** Shape + reorder one string (or each string of an array) for doc.text(). */
declare function rtlText(text: string, options?: RenderOptions): string;
declare function rtlText(text: string[], options?: RenderOptions): string[];
/**
* Register a `preProcessText` hook on `jsPDF.API` so every subsequent
* doc.text() call is shaped and reordered transparently.
*
* import { jsPDF } from 'jspdf';
* import { installJsPdfShaper } from 'bidi-shaper/jspdf';
* installJsPdfShaper(jsPDF.API);
*/
declare function installJsPdfShaper(api: JsPdfStaticApi, options?: RenderOptions): void;
export { type JsPdfStaticApi, type JsPdfTextPayload, RenderOptions, installJsPdfShaper, rtlText };