bidi-kit 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +289 -3
- package/bin/bidi-kit.mjs +77 -0
- package/dist/cjs/audit.js +72 -0
- package/dist/cjs/css.js +59 -0
- package/dist/cjs/fonts.js +84 -0
- package/dist/cjs/html.js +96 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/isolate.js +84 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/segment.js +217 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/audit.d.ts +12 -0
- package/dist/esm/audit.js +68 -0
- package/dist/esm/css.d.ts +26 -0
- package/dist/esm/css.js +55 -0
- package/dist/esm/fonts.d.ts +36 -0
- package/dist/esm/fonts.js +78 -0
- package/dist/esm/html.d.ts +32 -0
- package/dist/esm/html.js +89 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/isolate.d.ts +43 -0
- package/dist/esm/isolate.js +77 -0
- package/dist/esm/segment.d.ts +40 -0
- package/dist/esm/segment.js +209 -0
- package/dist/esm/types.d.ts +92 -0
- package/dist/esm/types.js +1 -0
- package/package.json +60 -6
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** The direction of a piece of text, as resolved by the bidi algorithm. */
|
|
2
|
+
export type Direction = "ltr" | "rtl" | "neutral";
|
|
3
|
+
/** A direction that can be written to an attribute: `auto` lets the browser infer it. */
|
|
4
|
+
export type AttributeDirection = Direction | "auto";
|
|
5
|
+
/** One run of text with a single resolved direction. */
|
|
6
|
+
export interface Segment {
|
|
7
|
+
/** The text of the run, exactly as it appears in the input. */
|
|
8
|
+
text: string;
|
|
9
|
+
/** The run's direction. `neutral` means no strong character was found. */
|
|
10
|
+
dir: Direction;
|
|
11
|
+
/** Index of the first character, in UTF-16 code units. */
|
|
12
|
+
start: number;
|
|
13
|
+
/** Index just past the last character, in UTF-16 code units. */
|
|
14
|
+
end: number;
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@link isolate} and {@link toPlainIsolated}. */
|
|
17
|
+
export interface IsolateOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Which isolate to wrap in. `auto` (the default) uses the first-strong
|
|
20
|
+
* isolate, which lets the reader's own bidi algorithm decide.
|
|
21
|
+
*/
|
|
22
|
+
dir?: AttributeDirection;
|
|
23
|
+
}
|
|
24
|
+
/** Options shared by the HTML helpers. */
|
|
25
|
+
export interface HtmlOptions {
|
|
26
|
+
/** `auto` (the default) infers the element's direction from its content. */
|
|
27
|
+
dir?: AttributeDirection;
|
|
28
|
+
/** BCP-47 tag written to `lang`. */
|
|
29
|
+
lang?: string;
|
|
30
|
+
/** Extra class names. */
|
|
31
|
+
class?: string;
|
|
32
|
+
/** A `font-family` value applied as an inline style. */
|
|
33
|
+
font?: string;
|
|
34
|
+
/** Which element to emit. `<bdi>` (the default) isolates by design. */
|
|
35
|
+
element?: "bdi" | "span";
|
|
36
|
+
}
|
|
37
|
+
/** A piece of a paragraph: a string, or an explicit run with its own direction. */
|
|
38
|
+
export type Part = string | {
|
|
39
|
+
text: string;
|
|
40
|
+
dir?: AttributeDirection;
|
|
41
|
+
lang?: string;
|
|
42
|
+
/** A `font-family` value applied as an inline style. */
|
|
43
|
+
font?: string;
|
|
44
|
+
};
|
|
45
|
+
/** Options for {@link paragraph}. */
|
|
46
|
+
export interface ParagraphOptions {
|
|
47
|
+
/** `auto` (the default) resolves from the content's first strong character. */
|
|
48
|
+
dir?: AttributeDirection;
|
|
49
|
+
/** BCP-47 tag written to `lang`. */
|
|
50
|
+
lang?: string;
|
|
51
|
+
/** Extra class names. */
|
|
52
|
+
class?: string;
|
|
53
|
+
/**
|
|
54
|
+
* When true, string parts are treated as trusted HTML and inserted as-is.
|
|
55
|
+
* Never use it with user input.
|
|
56
|
+
*/
|
|
57
|
+
html?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The smallest element shape {@link apply} needs, so it works without the DOM lib. */
|
|
60
|
+
export interface DirectionalElement {
|
|
61
|
+
textContent: string | null;
|
|
62
|
+
setAttribute?(name: string, value: string): void;
|
|
63
|
+
}
|
|
64
|
+
/** Font stacks for the scripts that meet in a mixed paragraph. */
|
|
65
|
+
export type Script = "arabic" | "hebrew" | "latin";
|
|
66
|
+
/** Options for {@link fontFace}. */
|
|
67
|
+
export interface FontFaceOptions {
|
|
68
|
+
/** The family name used in `src` and in the stack. */
|
|
69
|
+
family: string;
|
|
70
|
+
/** One or more `url(...)` or `local(...)` sources. */
|
|
71
|
+
src: string | string[];
|
|
72
|
+
/** Which script the face covers; decides the generated `unicode-range`. */
|
|
73
|
+
script?: Script;
|
|
74
|
+
weight?: string | number;
|
|
75
|
+
style?: string;
|
|
76
|
+
display?: "auto" | "block" | "swap" | "fallback" | "optional";
|
|
77
|
+
/** Overrides the generated `unicode-range`. */
|
|
78
|
+
unicodeRange?: string;
|
|
79
|
+
/** Nudges the rendered size for a fallback face, in percent. */
|
|
80
|
+
sizeAdjust?: string;
|
|
81
|
+
}
|
|
82
|
+
export type AuditRule = "bidi-control-character" | "inline-direction-without-isolation" | "physical-css-property" | "physical-text-align" | "document-without-lang";
|
|
83
|
+
/** One finding from {@link audit}. */
|
|
84
|
+
export interface AuditIssue {
|
|
85
|
+
rule: AuditRule;
|
|
86
|
+
severity: "error" | "warning";
|
|
87
|
+
message: string;
|
|
88
|
+
/** Index of the match in the audited string, in UTF-16 code units. */
|
|
89
|
+
index: number;
|
|
90
|
+
/** The offending text, truncated to keep output readable. */
|
|
91
|
+
snippet: string;
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bidi-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "bidi-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Right-to-left text that behaves: Arabic inside English, French inside Arabic, no bidi glitches.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bidi",
|
|
7
|
+
"rtl",
|
|
8
|
+
"arabic",
|
|
9
|
+
"i18n",
|
|
10
|
+
"unicode",
|
|
11
|
+
"text",
|
|
12
|
+
"font",
|
|
13
|
+
"isolation",
|
|
14
|
+
"hebrew"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Nour Yahyaoui",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/Nour-yahyaoui/ui-storm.git",
|
|
21
|
+
"directory": "packages/bidi-kit"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./dist/cjs/index.js",
|
|
26
|
+
"module": "./dist/esm/index.js",
|
|
27
|
+
"types": "./dist/esm/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/esm/index.d.ts",
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"require": "./dist/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"bin": {
|
|
37
|
+
"bidi-kit": "./bin/bidi-kit.mjs"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"bin",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node scripts/build.mjs",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.esm.json --noEmit",
|
|
51
|
+
"test": "npm run build && node --test tests/*.test.mjs",
|
|
52
|
+
"demo": "node scripts/serve.mjs",
|
|
53
|
+
"prepublishOnly": "npm test",
|
|
54
|
+
"test:only": "node --test tests/*.test.mjs",
|
|
55
|
+
"pack:check": "npm run build && node scripts/check-tarball.mjs"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"typescript": "^5.9.3"
|
|
59
|
+
}
|
|
60
|
+
}
|