pixi-silk 1.0.2 → 1.2.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/CHANGELOG.md +18 -0
- package/README.md +3 -2
- package/dist/SilkGraphics.d.ts +2 -1
- package/dist/SilkGraphics.js +6 -1
- package/dist/app.d.ts +8 -1
- package/dist/app.js +5 -1
- package/dist/batch.d.ts +2 -1
- package/dist/batch.js +4 -3
- package/dist/glass/GlassFilter.js +2 -1
- package/dist/shader-slot.js +3 -1
- package/dist/shader.js +4 -2
- package/dist/text/SilkText.d.ts +143 -6
- package/dist/text/SilkText.js +264 -35
- package/dist/text/atlas.d.ts +52 -2
- package/dist/text/atlas.js +231 -27
- package/dist/text/bidi.d.ts +36 -0
- package/dist/text/bidi.js +632 -0
- package/dist/text/cluster.d.ts +37 -0
- package/dist/text/cluster.js +277 -0
- package/dist/text/label.d.ts +20 -0
- package/dist/text/label.js +27 -1
- package/dist/text/layout.d.ts +162 -11
- package/dist/text/layout.js +541 -58
- package/dist/text/rich.d.ts +84 -0
- package/dist/text/rich.js +218 -0
- package/dist/text/shader.js +35 -5
- package/dist/text.d.ts +7 -4
- package/dist/text.js +6 -3
- package/dist/ui/textedit.d.ts +17 -2
- package/dist/ui/textedit.js +55 -18
- package/dist/webgl1/glsl100.js +123 -0
- package/dist/webgl1/hooks.js +137 -0
- package/dist/webgl1/programs.js +244 -0
- package/dist/webgl1.d.ts +41 -0
- package/dist/webgl1.js +104 -0
- package/package.json +14 -12
- package/skills/pixi-silk/SKILL.md +1 -0
- package/skills/pixi-silk-text/SKILL.md +57 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# pixi-silk
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#16](https://github.com/schmooky/pixi-silk/pull/16) [`5b6a88d`](https://github.com/schmooky/pixi-silk/commit/5b6a88df440cb281eb4c3249f0c327675e84c014) Thanks [@igaming-bulochka](https://github.com/igaming-bulochka)! - WebGL1 support as an opt-in: `enableWebGL1` from the new `pixi-silk/webgl1` entry point, or `createSilkApp({ webgl1: enableWebGL1 })`. When Pixi falls back to a WebGL1 context, SilkGraphics, SilkText and Glass draw with GLSL ES 1.00 shaders built from the WebGL2 sources. Apps without the import do not ship them. On WebGL1 nothing batches, and paths past 4096 edges draw in part with a warning. Without the opt-in, `createSilkApp` now logs an error on WebGL1 instead of failing to compile the shader. `enableWebGL1` returns `false` with an error on a device without `OES_texture_float`, `OES_texture_half_float`, `OES_standard_derivatives` or fragment `highp`, where the shaders cannot run. Without `OES_texture_half_float_linear` the gradient ramps filter nearest and the shaders blend them, so gradients look the same. The renderers guide lists the costs and limits of WebGL1.
|
|
8
|
+
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- SilkText: text that fits its box, full bidi, colour emoji. `maxLines`, `maxWidth` and `maxHeight` cut what does not fit and end it in `ellipsis`, and `shrinkToFit` shrinks the font first, down to `minFontSize` (`renderedFontSize` and `truncated` report it). `align: 'justify'` stretches wrapped lines, with kashida in Arabic. Tabs line up on `tabSize` stops. Letter spacing is not applied inside Arabic words or words of shaped scripts. The bidi pass now handles isolates, embeddings and overrides, and pairs brackets. A caret can stand at both places an offset has where the direction changes, and word jumps follow the screen. Emoji keep their colours, from a second texture. Thai and Lao are baked a cluster at a time, and `atlas.usage` reports how full the atlas is. Icons centre on the letters in text without capitals.
|
|
14
|
+
|
|
15
|
+
- Inline objects and editing polish. `silkRichLabel()` gives widgets labels that hold icons. `SilkRichText` has an `anchor`, and its objects follow the anchor and the text object's position and scale. `TextEditor` takes `inlines`: typed `{name}` tokens show their object, the caret steps over a token and one Backspace deletes it. The arrow keys move by what is on screen in lines that mix directions (`caretVisual`). Lines break beside inline boxes next to Chinese, Japanese or Korean text, and a box stays with the letters and digits next to it. `tabularNumbers` covers every decimal digit set, and digits of Burmese, Thai and the Indic scripts are clusters of their own.
|
|
16
|
+
|
|
17
|
+
- SilkText lays out right-to-left text. Arabic and Hebrew paragraphs are reordered with the Unicode bidi algorithm, so numbers, prices, percentages and Latin words inside them keep reading left to right, and brackets are mirrored. Joined Arabic letters are baked as one glyph per run, so they shape with the font. New `direction` style (`ltr`, `rtl`, `auto`), and `align` takes `start` and `end` (the default is now `start`, which is `left` for left-to-right text). Carets, hit testing and selection boxes follow the visual order, and the left arrow in `TextEditor` moves forward in a right-to-left paragraph.
|
|
18
|
+
|
|
19
|
+
- SilkText handles every script without clipping. Glyphs are baked from the ink found in the pixels, not the `measureText` box, so stacked Burmese, Thai and Vietnamese marks are never cut. Lines grow to fit the tallest ink and the outline. Burmese, Thai, Khmer, Lao, the Indic scripts, emoji sequences and combining accents are baked a word or a cluster at a time so Canvas shapes them. Lines wrap between Chinese and Japanese characters (with kinsoku), Korean syllables (or only at spaces with the new `wordBreak: 'keep-all'`) and Thai or Burmese words. Outlines are drawn for every glyph before any fill, so they never cover a neighbouring letter. New inline objects: `{name}` tokens with `inlines` reserve aligned boxes (`inlineRects()`), and the new `SilkRichText` places sprites, SilkGraphics or any container in them.
|
|
20
|
+
|
|
3
21
|
## 1.0.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ imports.
|
|
|
45
45
|
| `pixi-silk/layout`, `pixi-silk/ui/layout` | A flex layout engine and the Pixi containers built on it |
|
|
46
46
|
| `pixi-silk/glass`, `pixi-silk/glow` | Glass and glow filters |
|
|
47
47
|
| `pixi-silk/webgpu` | The WGSL shader, for WebGPU in your own Pixi app |
|
|
48
|
+
| `pixi-silk/webgl1` | Opt-in shaders for Pixi's WebGL1 fallback |
|
|
48
49
|
| `pixi-silk/ui/*` | Buttons, radial menus, counters and the editor kit |
|
|
49
50
|
|
|
50
51
|
[Choose an entry point](https://pixi-silk.schmooky.dev/docs/choose-an-entry-point/) lists every
|
|
@@ -57,9 +58,9 @@ may change in a minor release.
|
|
|
57
58
|
- WebGL2 or WebGPU. WebGL2 is the default. For WebGPU, pass `preference: 'webgpu'` to
|
|
58
59
|
`createSilkApp`, or call `enableWebGPU()` from `pixi-silk/webgpu` before the first
|
|
59
60
|
`SilkGraphics` in your own Pixi app
|
|
61
|
+
- WebGL1 is opt-in: pass `webgl1: enableWebGL1` from `pixi-silk/webgl1` to `createSilkApp`
|
|
60
62
|
|
|
61
|
-
It does not do texture fills or SVG documents
|
|
62
|
-
scripts. The [FAQ](https://pixi-silk.schmooky.dev/faq/) lists the other limits.
|
|
63
|
+
It does not do texture fills or SVG documents. The [FAQ](https://pixi-silk.schmooky.dev/faq/) lists the other limits.
|
|
63
64
|
|
|
64
65
|
## For AI agents
|
|
65
66
|
|
package/dist/SilkGraphics.d.ts
CHANGED
|
@@ -166,7 +166,8 @@ export declare class SilkGeometry extends Geometry {
|
|
|
166
166
|
* object is one instanced draw call, and `enableSilkBatching()` merges neighbours further.
|
|
167
167
|
*
|
|
168
168
|
* It renders on WebGL2. For WebGPU, call `enableWebGPU()` from `pixi-silk/webgpu` before the first
|
|
169
|
-
* SilkGraphics, or create the app with `createSilkApp({ preference: 'webgpu' })`.
|
|
169
|
+
* SilkGraphics, or create the app with `createSilkApp({ preference: 'webgpu' })`. For Pixi's WebGL1
|
|
170
|
+
* fallback, use `enableWebGL1()` from `pixi-silk/webgl1`.
|
|
170
171
|
*
|
|
171
172
|
* Shapes go on the active path and are painted by {@link SilkGraphics.fill | fill()} or
|
|
172
173
|
* {@link SilkGraphics.stroke | stroke()}. `stroke()` right after `fill()` paints the same shapes.
|
package/dist/SilkGraphics.js
CHANGED
|
@@ -6,6 +6,7 @@ import { Gradient } from "./gradient.js";
|
|
|
6
6
|
import { joinPolygon, nearWindows } from "./stroke.js";
|
|
7
7
|
import { hitTest } from "./hit.js";
|
|
8
8
|
import { drawPath, parseSvgPath } from "./path.js";
|
|
9
|
+
import { silkGl1 } from "./shader-slot.js";
|
|
9
10
|
import { createSilkShader } from "./shader.js";
|
|
10
11
|
import { Bounds, Buffer, BufferImageSource, BufferUsage, Color, Geometry, Mesh } from "pixi.js";
|
|
11
12
|
//#region src/SilkGraphics.ts
|
|
@@ -322,7 +323,8 @@ var SilkGeometry = class extends Geometry {
|
|
|
322
323
|
* object is one instanced draw call, and `enableSilkBatching()` merges neighbours further.
|
|
323
324
|
*
|
|
324
325
|
* It renders on WebGL2. For WebGPU, call `enableWebGPU()` from `pixi-silk/webgpu` before the first
|
|
325
|
-
* SilkGraphics, or create the app with `createSilkApp({ preference: 'webgpu' })`.
|
|
326
|
+
* SilkGraphics, or create the app with `createSilkApp({ preference: 'webgpu' })`. For Pixi's WebGL1
|
|
327
|
+
* fallback, use `enableWebGL1()` from `pixi-silk/webgl1`.
|
|
326
328
|
*
|
|
327
329
|
* Shapes go on the active path and are painted by {@link SilkGraphics.fill | fill()} or
|
|
328
330
|
* {@link SilkGraphics.stroke | stroke()}. `stroke()` right after `fill()` paints the same shapes.
|
|
@@ -404,6 +406,7 @@ var SilkGraphics = class SilkGraphics extends Mesh {
|
|
|
404
406
|
});
|
|
405
407
|
this.renderPipeId = options.batch === false ? "mesh" : SilkGraphics._pipeId;
|
|
406
408
|
this._polySource = polys;
|
|
409
|
+
if (shader.resources.uInstances) silkGl1.hooks?.attach(geometry);
|
|
407
410
|
this._f = geometry.instanceBuffer.data;
|
|
408
411
|
this._uniforms = shader.resources.silkUniforms;
|
|
409
412
|
this._silk = this._uniforms.uniforms.uSilk;
|
|
@@ -1100,6 +1103,7 @@ var SilkGraphics = class SilkGraphics extends Mesh {
|
|
|
1100
1103
|
const shader = this.shader;
|
|
1101
1104
|
super.destroy(options);
|
|
1102
1105
|
geometry.destroy(true);
|
|
1106
|
+
if (shader) silkGl1.hooks?.release(shader);
|
|
1103
1107
|
shader?.destroy();
|
|
1104
1108
|
this._polySource.destroy();
|
|
1105
1109
|
}
|
|
@@ -1154,6 +1158,7 @@ var SilkGraphics = class SilkGraphics extends Mesh {
|
|
|
1154
1158
|
}
|
|
1155
1159
|
src.update();
|
|
1156
1160
|
}
|
|
1161
|
+
if (this.shader?.resources.uInstances) silkGl1.hooks?.commit(geometry, this.shader, this._f, this._count);
|
|
1157
1162
|
}
|
|
1158
1163
|
/** Appends the edges of every subpath of a filled path (each closed). Returns the first texel. */
|
|
1159
1164
|
_pushEdges(subpaths) {
|
package/dist/app.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Application, ApplicationOptions } from "pixi.js";
|
|
1
|
+
import { Application, ApplicationOptions, Renderer } from "pixi.js";
|
|
2
2
|
//#region src/app.d.ts
|
|
3
3
|
/** Options of {@link createSilkApp}: Pixi application options plus the element to fill, DPR limits and touch behaviour. */
|
|
4
4
|
export interface SilkAppOptions extends Partial<ApplicationOptions> {
|
|
@@ -29,6 +29,13 @@ export interface SilkAppOptions extends Partial<ApplicationOptions> {
|
|
|
29
29
|
* the WGSL shader from `pixi-silk/webgpu` before it resolves, so SilkGraphics render on either.
|
|
30
30
|
*/
|
|
31
31
|
preference?: ApplicationOptions["preference"];
|
|
32
|
+
/**
|
|
33
|
+
* Opt-in WebGL1 support: pass `enableWebGL1` from `pixi-silk/webgl1`. Pixi falls back to a
|
|
34
|
+
* WebGL1 context when the browser has no WebGL2, and the app then calls this function before
|
|
35
|
+
* it resolves. Without it, silk shapes draw nothing on WebGL1 and the app logs an error. The
|
|
36
|
+
* option takes the function rather than a flag, so apps that leave it out do not ship the code.
|
|
37
|
+
*/
|
|
38
|
+
webgl1?: (renderer: Renderer) => unknown;
|
|
32
39
|
}
|
|
33
40
|
/** What {@link createSilkApp} returns: the Pixi application, its CSS size and resolution, and helpers to change or destroy it. */
|
|
34
41
|
export interface SilkApp {
|
package/dist/app.js
CHANGED
|
@@ -19,7 +19,7 @@ import { Application, Filter } from "pixi.js";
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
async function createSilkApp(options) {
|
|
22
|
-
const { parent, maxResolution = 3, fixedResolution, onResize, inheritFilterResolution = true, touchAction = "pan-y pinch-zoom", ...rest } = options;
|
|
22
|
+
const { parent, maxResolution = 3, fixedResolution, onResize, inheritFilterResolution = true, touchAction = "pan-y pinch-zoom", webgl1, ...rest } = options;
|
|
23
23
|
if (inheritFilterResolution) Filter.defaultOptions.resolution = "inherit";
|
|
24
24
|
let forced = fixedResolution ?? null;
|
|
25
25
|
const dpr = () => Math.min(forced ?? window.devicePixelRatio ?? 1, forced ? 16 : maxResolution);
|
|
@@ -50,6 +50,10 @@ async function createSilkApp(options) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
if (app.renderer.name === "webgpu") (await import("./webgpu.js")).enableWebGPU();
|
|
53
|
+
else if (app.renderer.context.webGLVersion === 1) {
|
|
54
|
+
if (webgl1) webgl1(app.renderer);
|
|
55
|
+
else console.error("pixi-silk: Pixi started WebGL1. Pass { webgl1: enableWebGL1 } from 'pixi-silk/webgl1' to draw on it.");
|
|
56
|
+
}
|
|
53
57
|
const canvas = app.canvas;
|
|
54
58
|
canvas.style.touchAction = touchAction;
|
|
55
59
|
canvas.style.display = "block";
|
package/dist/batch.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare class SilkPipe implements RenderPipe<SilkGraphics> {
|
|
|
21
21
|
constructor(renderer: Renderer);
|
|
22
22
|
/**
|
|
23
23
|
* Whether this renderer batches. WebGPU needs the WGSL program (`enableWebGPU()`), or the batch
|
|
24
|
-
* would have no program to draw with: without it, objects go to the mesh pipe as before.
|
|
24
|
+
* would have no program to draw with: without it, objects go to the mesh pipe as before. The
|
|
25
|
+
* WebGL1 program (`enableWebGL1()`) cannot batch, so WebGL draws one call per object then.
|
|
25
26
|
*/
|
|
26
27
|
private get _batching();
|
|
27
28
|
/** Adds `g` to the current run when it can share its draw, or starts a new run. */
|
package/dist/batch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { silkGpu } from "./shader-slot.js";
|
|
1
|
+
import { silkGl1, silkGpu } from "./shader-slot.js";
|
|
2
2
|
import { createSilkShader } from "./shader.js";
|
|
3
3
|
import { SilkGeometry, SilkGraphics } from "./SilkGraphics.js";
|
|
4
4
|
import { BindGroup, BufferImageSource, ExtensionType, Matrix, RendererType, State, UniformGroup } from "pixi.js";
|
|
@@ -165,10 +165,11 @@ var SilkPipe = class {
|
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Whether this renderer batches. WebGPU needs the WGSL program (`enableWebGPU()`), or the batch
|
|
168
|
-
* would have no program to draw with: without it, objects go to the mesh pipe as before.
|
|
168
|
+
* would have no program to draw with: without it, objects go to the mesh pipe as before. The
|
|
169
|
+
* WebGL1 program (`enableWebGL1()`) cannot batch, so WebGL draws one call per object then.
|
|
169
170
|
*/
|
|
170
171
|
get _batching() {
|
|
171
|
-
return this._renderer.type === RendererType.WEBGL
|
|
172
|
+
return this._renderer.type === RendererType.WEBGL ? silkGl1.hooks === null : silkGpu.program !== null;
|
|
172
173
|
}
|
|
173
174
|
/** Adds `g` to the current run when it can share its draw, or starts a new run. */
|
|
174
175
|
addRenderable(g, set) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { silkGl1 } from "../shader-slot.js";
|
|
1
2
|
import { glassWgsl } from "./glass-wgsl.js";
|
|
2
3
|
import { Filter, GlProgram, GpuProgram, Texture, UniformGroup } from "pixi.js";
|
|
3
4
|
//#region src/glass/GlassFilter.ts
|
|
@@ -210,7 +211,7 @@ var GlassFilter = class extends Filter {
|
|
|
210
211
|
}
|
|
211
212
|
});
|
|
212
213
|
super({
|
|
213
|
-
glProgram: program,
|
|
214
|
+
glProgram: silkGl1.hooks?.program("silk-glass", glassVertex, glassFragment) ?? program,
|
|
214
215
|
gpuProgram,
|
|
215
216
|
resources: {
|
|
216
217
|
glassUniforms: u,
|
package/dist/shader-slot.js
CHANGED
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* `createSilkShader` reads the slot when a SilkGraphics is created.
|
|
6
6
|
*/
|
|
7
7
|
const silkGpu = { program: null };
|
|
8
|
+
/** @internal Set by `enableWebGL1()` from `pixi-silk/webgl1`. */
|
|
9
|
+
const silkGl1 = { hooks: null };
|
|
8
10
|
//#endregion
|
|
9
|
-
export { silkGpu };
|
|
11
|
+
export { silkGl1, silkGpu };
|
package/dist/shader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GradientAtlas } from "./atlas.js";
|
|
2
|
-
import { silkGpu } from "./shader-slot.js";
|
|
2
|
+
import { silkGl1, silkGpu } from "./shader-slot.js";
|
|
3
3
|
import { BufferImageSource, GlProgram, Shader, UniformGroup } from "pixi.js";
|
|
4
4
|
//#region src/shader.ts
|
|
5
5
|
/** @internal Vertex stage of the uber program (GLSL ES 3.00). */
|
|
@@ -911,6 +911,7 @@ function emptyBatchTable() {
|
|
|
911
911
|
* batched draw: 3 texels per object (matrix a b c d, then tx ty and path texel base, then tint).
|
|
912
912
|
*/
|
|
913
913
|
function createSilkShader(settings, polys, batch = emptyBatchTable()) {
|
|
914
|
+
const gl1 = silkGl1.hooks;
|
|
914
915
|
program ??= GlProgram.from({
|
|
915
916
|
vertex,
|
|
916
917
|
fragment,
|
|
@@ -919,9 +920,10 @@ function createSilkShader(settings, polys, batch = emptyBatchTable()) {
|
|
|
919
920
|
preferredFragmentPrecision: "highp"
|
|
920
921
|
});
|
|
921
922
|
return new Shader({
|
|
922
|
-
glProgram: program,
|
|
923
|
+
glProgram: gl1 ? gl1.program("silk-sdf", vertex, fragment) : program,
|
|
923
924
|
gpuProgram: silkGpu.program ?? void 0,
|
|
924
925
|
resources: {
|
|
926
|
+
...gl1?.resources("silk-sdf"),
|
|
925
927
|
uGradients: GradientAtlas.shared.source,
|
|
926
928
|
uPolys: polys,
|
|
927
929
|
uBatch: batch,
|
package/dist/text/SilkText.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Gradient } from "../gradient.js";
|
|
2
2
|
import { SdfAtlas } from "./atlas.js";
|
|
3
|
+
import { TextDirection } from "./bidi.js";
|
|
4
|
+
import { WordBreak } from "./cluster.js";
|
|
3
5
|
import { CaretHit, CaretRect, LayoutLine, TextAlign, TextLayout, TextRect } from "./layout.js";
|
|
4
6
|
import { Bounds, Buffer, ColorSource, DestroyOptions, Geometry, Mesh, ObservablePoint, PointData, Shader } from "pixi.js";
|
|
5
7
|
//#region src/text/SilkText.d.ts
|
|
@@ -41,8 +43,14 @@ export interface SilkTextStyle {
|
|
|
41
43
|
letterSpacing?: number;
|
|
42
44
|
/** Distance between baselines. 0 uses the font's ascent plus descent, like PixiJS `Text`. Default 0. */
|
|
43
45
|
lineHeight?: number;
|
|
44
|
-
/** Alignment of the lines. Default `
|
|
46
|
+
/** Alignment of the lines. `start` is left for left-to-right paragraphs and right for right-to-left ones. Default `start`. */
|
|
45
47
|
align?: TextAlign;
|
|
48
|
+
/**
|
|
49
|
+
* Base direction of each paragraph: `ltr`, `rtl`, or `auto` to take it from the first strong
|
|
50
|
+
* character. Arabic and Hebrew read right to left either way. Numbers and Latin words inside them
|
|
51
|
+
* keep their order. Default `auto`.
|
|
52
|
+
*/
|
|
53
|
+
direction?: TextDirection;
|
|
46
54
|
/** Breaks lines at spaces to fit `wordWrapWidth`. Default false. */
|
|
47
55
|
wordWrap?: boolean;
|
|
48
56
|
/** Width that `wordWrap` breaks lines at, in local units. Default 100. */
|
|
@@ -61,6 +69,75 @@ export interface SilkTextStyle {
|
|
|
61
69
|
dilate?: number;
|
|
62
70
|
/** Width of the anti-aliasing ramp in device pixels. Larger is softer. Default 1. */
|
|
63
71
|
aaWidth?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Where lines may break without spaces. `normal` breaks between Chinese, Japanese and Korean
|
|
74
|
+
* characters, `keep-all` keeps them together up to the next space. Default `normal`.
|
|
75
|
+
*/
|
|
76
|
+
wordBreak?: WordBreak;
|
|
77
|
+
/**
|
|
78
|
+
* Room for inline objects, by name. `{icon}` in the text, with `icon` listed here, becomes a box
|
|
79
|
+
* that flows with the text. Read the boxes back with {@link SilkText.inlineRects}, or use
|
|
80
|
+
* {@link SilkRichText} to place sprites and graphics in them. Default none.
|
|
81
|
+
*/
|
|
82
|
+
inlines?: Record<string, TextInline>;
|
|
83
|
+
/** Most lines to show. Past it the text is cut and the last line ends in `ellipsis`. 0 for no limit. Default 0. */
|
|
84
|
+
maxLines?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Widest the text may be, in local units, when `wordWrap` is off. A longer line is cut and ends
|
|
87
|
+
* in `ellipsis`, or with `shrinkToFit` the font shrinks first. 0 for no limit. Default 0.
|
|
88
|
+
*/
|
|
89
|
+
maxWidth?: number;
|
|
90
|
+
/** Tallest the text box may be, in local units. Lines past it are cut, or the font shrinks first. 0 for no limit. Default 0. */
|
|
91
|
+
maxHeight?: number;
|
|
92
|
+
/** What a cut line ends with. `null` cuts without a mark. Default an ellipsis, U+2026. */
|
|
93
|
+
ellipsis?: string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Shrinks the font, down to `minFontSize`, until the text fits `maxWidth`, `maxHeight` and
|
|
96
|
+
* `maxLines`. What still does not fit is cut. Wrapping moves with the size. Default false.
|
|
97
|
+
*/
|
|
98
|
+
shrinkToFit?: boolean;
|
|
99
|
+
/** Smallest size `shrinkToFit` goes down to, in local units. 0 for half the font size. Default 0. */
|
|
100
|
+
minFontSize?: number;
|
|
101
|
+
/** Tab stops every this many space widths, measured from the start of the line. Default 8. */
|
|
102
|
+
tabSize?: number;
|
|
103
|
+
}
|
|
104
|
+
/** How an inline box sits on the line. */
|
|
105
|
+
export type InlineAlign = "baseline" | "middle" | "center" | "top" | "bottom";
|
|
106
|
+
/** A box for an inline object, as {@link SilkTextStyle.inlines} lists them. Sizes are in local units. */
|
|
107
|
+
export interface TextInline {
|
|
108
|
+
/** Width of the object. */
|
|
109
|
+
width: number;
|
|
110
|
+
/** Height of the object. */
|
|
111
|
+
height: number;
|
|
112
|
+
/**
|
|
113
|
+
* Vertical placement. `middle` centres the box on the middle of capital letters and digits, the
|
|
114
|
+
* place for icons next to numbers. In text with neither, such as Arabic, Chinese or lower case,
|
|
115
|
+
* it centres on the middle of the letters. `center` centres it on the line box. `baseline` puts
|
|
116
|
+
* its bottom on the baseline, `top` and `bottom` align it with the font's ascent and descent.
|
|
117
|
+
* Default `middle`.
|
|
118
|
+
*/
|
|
119
|
+
align?: InlineAlign;
|
|
120
|
+
/** Moves the box down (positive) or up after alignment. Default 0. */
|
|
121
|
+
offsetY?: number;
|
|
122
|
+
/** Space left and right of the box. Default 0. */
|
|
123
|
+
margin?: number;
|
|
124
|
+
}
|
|
125
|
+
/** Where an inline object goes, as {@link SilkText.inlineRects} returns them, in local units. */
|
|
126
|
+
export interface InlineRect {
|
|
127
|
+
/** Name of the inline, as written between braces. */
|
|
128
|
+
name: string;
|
|
129
|
+
/** Left edge of the object, margin excluded. */
|
|
130
|
+
x: number;
|
|
131
|
+
/** Top edge of the object. */
|
|
132
|
+
y: number;
|
|
133
|
+
/** Width of the object. */
|
|
134
|
+
width: number;
|
|
135
|
+
/** Height of the object. */
|
|
136
|
+
height: number;
|
|
137
|
+
/** Line it sits on. */
|
|
138
|
+
line: number;
|
|
139
|
+
/** Offset of its `{name}` token in the text. */
|
|
140
|
+
index: number;
|
|
64
141
|
}
|
|
65
142
|
/** Options of a {@link SilkText}: the style plus the text, anchor and atlas. */
|
|
66
143
|
export interface SilkTextOptions extends SilkTextStyle {
|
|
@@ -102,9 +179,12 @@ export declare class SilkTextGeometry extends Geometry {
|
|
|
102
179
|
* `measureText`, so line breaks and widths match PixiJS `Text`. Style changes relayout once, on the
|
|
103
180
|
* next render or the next read of {@link SilkText.layout}.
|
|
104
181
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
182
|
+
* Any common script works. Arabic and Hebrew paragraphs are reordered with the Unicode bidi
|
|
183
|
+
* algorithm, and numbers and Latin words inside them keep reading left to right. Words of scripts
|
|
184
|
+
* that need shaping (Arabic, Burmese, Thai, the Indic scripts) are baked whole, so Canvas shapes
|
|
185
|
+
* them, and lines grow to fit stacked marks. `{name}` tokens make room for inline objects, see
|
|
186
|
+
* {@link SilkRichText}. Emoji keep their colours. It has no per-character styles. Works with Pixi's
|
|
187
|
+
* WebGL2 and WebGPU renderers.
|
|
108
188
|
*
|
|
109
189
|
* @example
|
|
110
190
|
* ```ts
|
|
@@ -127,6 +207,9 @@ export declare class SilkText extends Mesh<SilkTextGeometry, Shader> {
|
|
|
127
207
|
private _version;
|
|
128
208
|
private _f;
|
|
129
209
|
private _count;
|
|
210
|
+
private _passes;
|
|
211
|
+
private _size;
|
|
212
|
+
private _inlineBoxes;
|
|
130
213
|
private readonly _uniforms;
|
|
131
214
|
private _gradKey;
|
|
132
215
|
private readonly _scratch;
|
|
@@ -175,6 +258,10 @@ export declare class SilkText extends Mesh<SilkTextGeometry, Shader> {
|
|
|
175
258
|
get align(): TextAlign;
|
|
176
259
|
/** Sets {@link SilkText.align}. */
|
|
177
260
|
set align(v: TextAlign);
|
|
261
|
+
/** Base direction of each paragraph: `ltr`, `rtl` or `auto` (from the first strong character). */
|
|
262
|
+
get direction(): TextDirection;
|
|
263
|
+
/** Sets {@link SilkText.direction}. */
|
|
264
|
+
set direction(v: TextDirection);
|
|
178
265
|
/** Breaks lines at spaces to fit {@link SilkText.wordWrapWidth}. */
|
|
179
266
|
get wordWrap(): boolean;
|
|
180
267
|
/** Sets {@link SilkText.wordWrap}. */
|
|
@@ -223,14 +310,62 @@ export declare class SilkText extends Mesh<SilkTextGeometry, Shader> {
|
|
|
223
310
|
* take, for example to grapheme cluster boundaries.
|
|
224
311
|
*/
|
|
225
312
|
caretAt(point: PointData, isStop?: (index: number) => boolean): CaretHit;
|
|
226
|
-
/**
|
|
227
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Where a caret at `index` sits, in local units. `upstream` picks the end of a wrapped line,
|
|
315
|
+
* `leading` the place before the next character where the direction changes.
|
|
316
|
+
*/
|
|
317
|
+
caretRect(index: number, upstream?: boolean, leading?: boolean): CaretRect;
|
|
228
318
|
/** Highlight boxes of the text from `from` to `to`, one per line, in local units. */
|
|
229
319
|
rangeRects(from: number, to: number): TextRect[];
|
|
230
320
|
/** The laid-out lines: text, width and baseline of each, in layout units (see {@link SilkText.layout}). Relayouts first if needed. */
|
|
231
321
|
get lines(): readonly LayoutLine[];
|
|
232
322
|
/** Glyph instances drawn: characters with ink. Spaces, shadows and outlines are not counted. */
|
|
233
323
|
get glyphCount(): number;
|
|
324
|
+
/**
|
|
325
|
+
* Where the inline objects of the text go, one rectangle per `{name}` token, in local units.
|
|
326
|
+
* Bidi and wrapping move them with the text. See {@link SilkTextStyle.inlines}.
|
|
327
|
+
*/
|
|
328
|
+
inlineRects(): InlineRect[];
|
|
329
|
+
/** Room for inline objects, by name. Set a new object to change it, mutating this one does nothing. */
|
|
330
|
+
get inlines(): Record<string, TextInline>;
|
|
331
|
+
/** Sets {@link SilkText.inlines}. */
|
|
332
|
+
set inlines(v: Record<string, TextInline>);
|
|
333
|
+
/** Most lines to show, 0 for no limit. See {@link SilkTextStyle.maxLines}. */
|
|
334
|
+
get maxLines(): number;
|
|
335
|
+
/** Sets {@link SilkText.maxLines}. */
|
|
336
|
+
set maxLines(v: number);
|
|
337
|
+
/** Widest the text may be when it does not wrap, 0 for no limit. See {@link SilkTextStyle.maxWidth}. */
|
|
338
|
+
get maxWidth(): number;
|
|
339
|
+
/** Sets {@link SilkText.maxWidth}. */
|
|
340
|
+
set maxWidth(v: number);
|
|
341
|
+
/** Tallest the text box may be, 0 for no limit. See {@link SilkTextStyle.maxHeight}. */
|
|
342
|
+
get maxHeight(): number;
|
|
343
|
+
/** Sets {@link SilkText.maxHeight}. */
|
|
344
|
+
set maxHeight(v: number);
|
|
345
|
+
/** What a cut line ends with, or `null` for no mark. */
|
|
346
|
+
get ellipsis(): string | null;
|
|
347
|
+
/** Sets {@link SilkText.ellipsis}. */
|
|
348
|
+
set ellipsis(v: string | null);
|
|
349
|
+
/** Shrinks the font to fit `maxWidth`, `maxHeight` and `maxLines`. See {@link SilkTextStyle.shrinkToFit}. */
|
|
350
|
+
get shrinkToFit(): boolean;
|
|
351
|
+
/** Sets {@link SilkText.shrinkToFit}. */
|
|
352
|
+
set shrinkToFit(v: boolean);
|
|
353
|
+
/** Smallest size `shrinkToFit` goes to, 0 for half the font size. */
|
|
354
|
+
get minFontSize(): number;
|
|
355
|
+
/** Sets {@link SilkText.minFontSize}. */
|
|
356
|
+
set minFontSize(v: number);
|
|
357
|
+
/** Tab stops every this many space widths. */
|
|
358
|
+
get tabSize(): number;
|
|
359
|
+
/** Sets {@link SilkText.tabSize}. */
|
|
360
|
+
set tabSize(v: number);
|
|
361
|
+
/** The font size the text is drawn at: `fontSize`, or smaller when `shrinkToFit` had to shrink it. */
|
|
362
|
+
get renderedFontSize(): number;
|
|
363
|
+
/** True when the text did not fit its limits and was cut. */
|
|
364
|
+
get truncated(): boolean;
|
|
365
|
+
/** Where lines may break without spaces: `normal` or `keep-all`. */
|
|
366
|
+
get wordBreak(): WordBreak;
|
|
367
|
+
/** Sets {@link SilkText.wordBreak}. */
|
|
368
|
+
set wordBreak(v: WordBreak);
|
|
234
369
|
override get bounds(): Bounds;
|
|
235
370
|
/** Hit test against the text box (local coordinates). */
|
|
236
371
|
override containsPoint(point: PointData): boolean;
|
|
@@ -240,6 +375,8 @@ export declare class SilkText extends Mesh<SilkTextGeometry, Shader> {
|
|
|
240
375
|
*/
|
|
241
376
|
updateText(): void;
|
|
242
377
|
override destroy(options?: DestroyOptions): void;
|
|
378
|
+
/** The inline boxes in layout terms: advance with margins, and the height above and below the baseline. */
|
|
379
|
+
private _resolveInlines;
|
|
243
380
|
private _set;
|
|
244
381
|
private _invalidate;
|
|
245
382
|
private _build;
|