-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript typings #54
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @fileoverview Created manually by @tomasdev using: | ||
* ``` | ||
* npx -p typescript tsc hbjs.js --declaration --allowJs --emitDeclarationOnly | ||
* ``` | ||
* And then renaming the output to re-use types, and fix types (i.e. updating | ||
* the type if comment documentation had it as _object_ but in reality it was | ||
* _string_) to remove all `any` usages. | ||
*/ | ||
|
||
declare type HarfbuzzPointer = string; | ||
declare type HarfbuzzModule = WebAssembly.Instance; | ||
declare interface HarfbuzzBlob { | ||
ptr: HarfbuzzPointer; | ||
destroy: () => void; | ||
} | ||
declare interface HarfbuzzAxis { | ||
min: number; | ||
default: number; | ||
max: number; | ||
} | ||
declare interface HarfbuzzFace { | ||
ptr: HarfbuzzPointer; | ||
reference_table: (table: string) => Uint8Array; | ||
getAxisInfos: () => Record<string, HarfbuzzAxis>; | ||
destroy: () => void; | ||
} | ||
declare interface HarfbuzzVariations { | ||
[axisName: string]: number; | ||
} | ||
declare interface HarfbuzzFont { | ||
ptr: HarfbuzzPointer; | ||
glyphToPath: (glyphId: number) => string; | ||
glyphToJson: (glyphId: number) => Array<{type: string; values: number[];}>; | ||
setScale: (xScale: number, yScale: number) => void; | ||
setVariations: (variations: HarfbuzzVariations) => void; | ||
destroy: () => void; | ||
} | ||
declare type HarfbuzzDirection = 'ltr' | 'rtl' | 'ttb' | 'btt'; | ||
declare type HarfbuzzFlag = 'BOT' | 'EOT' | 'PRESERVE_DEFAULT_IGNORABLES' | | ||
'REMOVE_DEFAULT_IGNORABLES' | 'DO_NOT_INSERT_DOTTED_CIRCLE'; | ||
declare interface HarfbuzzBuffer { | ||
ptr: HarfbuzzPointer; | ||
addText: (text: string) => void; | ||
guessSegmentProperties: () => | ||
any; // any = return of exports.hb_buffer_guess_segment_properties(ptr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The C++ |
||
setDirection: (dir: HarfbuzzDirection) => void; | ||
setFlags: (flags: HarfbuzzFlag[]) => void; | ||
setLanguage: (language: string) => void; | ||
setScript: (script: string) => void; | ||
setClusterLevel: (level: number) => void; | ||
json: (font?: HarfbuzzFont) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't have an argument, should just be |
||
g: number; | ||
cl: number; | ||
ax: number; | ||
ay: number; | ||
dx: number; | ||
dy: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add |
||
}[]; | ||
destroy: () => void; | ||
} | ||
declare type HarfbuzzJson = object; | ||
declare interface HarfbuzzJs { | ||
createBlob: (blob: ArrayBufferLike) => HarfbuzzBlob; | ||
createFace: (blob: HarfbuzzBlob, index: number) => HarfbuzzFace; | ||
createFont: (face: HarfbuzzFace) => HarfbuzzFont; | ||
createBuffer: () => HarfbuzzBuffer; | ||
shape: | ||
(font: HarfbuzzFont, buffer: HarfbuzzBuffer, features?: string) => void; | ||
shapeWithTrace: | ||
(font: HarfbuzzFont, buffer: HarfbuzzBuffer, features: string, | ||
stop_at: number, stop_phase: number) => HarfbuzzJson; | ||
} | ||
declare function hbjs(instance: HarfbuzzModule): HarfbuzzJs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most people will be doing I tried a few things but couldn't get declare namespace HarfBuzzJsInit {
type HbFace = {};
...
type Harfbuzz = {
createBlob
...
};
}
// declaring a const with the same name as the namespace above
// lets people do `import {HbFace} from 'harfbuzzjs'
declare const HarfbuzzJsInit: Promise<HarfBuzzJsInit.HarfBuzz>;
export = HarfBuzzJsInit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
number