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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { InlineAlign, SilkText, SilkTextOptions } from "./SilkText.js";
|
|
2
|
+
import { Container, DestroyOptions } from "pixi.js";
|
|
3
|
+
//#region src/text/rich.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A size for an inline object: local units, or a size that follows the font. `em` is the font size,
|
|
6
|
+
* `cap` the height of capital letters and digits, `line` the line height.
|
|
7
|
+
*/
|
|
8
|
+
export type InlineSize = number | "em" | "cap" | "line";
|
|
9
|
+
/** An object that flows with the text of a {@link SilkRichText}. */
|
|
10
|
+
export interface RichInline {
|
|
11
|
+
/**
|
|
12
|
+
* What to show: a Sprite, a SilkGraphics or any container. Pass a function to show the object
|
|
13
|
+
* more than once: it is called once per `{name}` token. One instance only fills the first token.
|
|
14
|
+
*/
|
|
15
|
+
object: Container | (() => Container);
|
|
16
|
+
/** Width of the box. Default from the object's bounds, scaled to `height` when that is set. */
|
|
17
|
+
width?: InlineSize;
|
|
18
|
+
/**
|
|
19
|
+
* Height of the box. The object is scaled to fit the box, keeping its aspect, and centred in it.
|
|
20
|
+
* Default from the object's bounds, scaled to `width` when that is set.
|
|
21
|
+
*/
|
|
22
|
+
height?: InlineSize;
|
|
23
|
+
/** Vertical placement, as in {@link TextInline.align}. Default `middle`. */
|
|
24
|
+
align?: InlineAlign;
|
|
25
|
+
/** Moves the object down (positive) or up after alignment, in local units. Default 0. */
|
|
26
|
+
offsetY?: number;
|
|
27
|
+
/** Space left and right of the object, in local units. Default 0. */
|
|
28
|
+
margin?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Options of a {@link SilkRichText}: the options of its {@link SilkText} plus the inline objects. */
|
|
31
|
+
export interface SilkRichTextOptions extends Omit<SilkTextOptions, "inlines"> {
|
|
32
|
+
/** Objects shown where `{name}` appears in the text, by name. Default none. */
|
|
33
|
+
inlines?: Record<string, RichInline>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A {@link SilkText} with sprites, SilkGraphics or any container inside its lines. Write `{name}`
|
|
37
|
+
* in the text and list the object under `inlines`. Each token takes a box that flows with the
|
|
38
|
+
* text: it wraps, aligns and follows right-to-left order like a character, and the line grows when
|
|
39
|
+
* the object is taller than the text. The object is scaled to the box and placed in it every frame,
|
|
40
|
+
* so it follows text, style, anchor and size changes.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { Sprite, Texture } from 'pixi.js';
|
|
45
|
+
* import { SilkGraphics } from 'pixi-silk';
|
|
46
|
+
* import { SilkRichText } from 'pixi-silk/text';
|
|
47
|
+
*
|
|
48
|
+
* const status = new SilkRichText({
|
|
49
|
+
* text: 'Synced {dot} 2 min ago, rated {star} 4.8',
|
|
50
|
+
* fontSize: 24,
|
|
51
|
+
* inlines: {
|
|
52
|
+
* dot: { object: new Sprite(Texture.WHITE), height: 'cap', margin: 2 },
|
|
53
|
+
* star: { object: () => new SilkGraphics().star(0, 0, 5, 10, 5).fill(0xffd60a), height: 'em' },
|
|
54
|
+
* },
|
|
55
|
+
* });
|
|
56
|
+
* app.stage.addChild(status);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare class SilkRichText extends Container {
|
|
60
|
+
/** The text. Style it through this object, except for `inlines`, which this container owns. */
|
|
61
|
+
readonly textObject: SilkText;
|
|
62
|
+
private readonly _placer;
|
|
63
|
+
constructor(options?: SilkRichTextOptions);
|
|
64
|
+
/** The text, with `{name}` tokens where inline objects go. */
|
|
65
|
+
get text(): string;
|
|
66
|
+
/** Sets {@link SilkRichText.text}. */
|
|
67
|
+
set text(v: string | number);
|
|
68
|
+
/**
|
|
69
|
+
* Point of the text box at the position, as on {@link SilkText.anchor}: (0, 0) top left, (0.5,
|
|
70
|
+
* 0.5) centre. The inline objects move with it.
|
|
71
|
+
*/
|
|
72
|
+
get anchor(): SilkText["anchor"];
|
|
73
|
+
/** The inline objects by name. Set a new object to change them. Objects that left are removed, not destroyed. */
|
|
74
|
+
get inlines(): Record<string, RichInline>;
|
|
75
|
+
/** Sets {@link SilkRichText.inlines}. */
|
|
76
|
+
set inlines(v: Record<string, RichInline>);
|
|
77
|
+
/**
|
|
78
|
+
* Measures the objects, lays the text out around them and moves them into their boxes. Runs
|
|
79
|
+
* before every render, so call it only to read positions in the same frame as a change.
|
|
80
|
+
*/
|
|
81
|
+
sync(): void;
|
|
82
|
+
override destroy(options?: DestroyOptions): void;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { SilkText } from "./SilkText.js";
|
|
2
|
+
import { Container } from "pixi.js";
|
|
3
|
+
//#region src/text/rich.ts
|
|
4
|
+
const resolve = (v, em, cap, line) => v === "em" ? em : v === "cap" ? cap : v === "line" ? line : v;
|
|
5
|
+
/**
|
|
6
|
+
* @internal Keeps the inline objects of a {@link SilkText} in their boxes. {@link SilkRichText} and
|
|
7
|
+
* `TextEditor` use it. Objects go into the text's parent, so the text must have one before `sync`.
|
|
8
|
+
*/
|
|
9
|
+
var InlinePlacer = class {
|
|
10
|
+
_defs;
|
|
11
|
+
_placed = /* @__PURE__ */ new Map();
|
|
12
|
+
_key = "";
|
|
13
|
+
_text;
|
|
14
|
+
constructor(text, defs = {}) {
|
|
15
|
+
this._text = text;
|
|
16
|
+
this._defs = defs;
|
|
17
|
+
}
|
|
18
|
+
/** The definitions, by name. */
|
|
19
|
+
get defs() {
|
|
20
|
+
return this._defs;
|
|
21
|
+
}
|
|
22
|
+
/** Sets {@link InlinePlacer.defs}. Objects that left are removed, factory-made ones destroyed. */
|
|
23
|
+
set defs(v) {
|
|
24
|
+
for (const [name, placed] of this._placed) {
|
|
25
|
+
if (v[name]?.object === this._defs[name]?.object) continue;
|
|
26
|
+
for (const o of placed.made) o.destroy({ children: true });
|
|
27
|
+
placed.single?.parent?.removeChild(placed.single);
|
|
28
|
+
this._placed.delete(name);
|
|
29
|
+
}
|
|
30
|
+
this._defs = v;
|
|
31
|
+
this._key = "";
|
|
32
|
+
}
|
|
33
|
+
/** Measures the objects, gives the text their boxes and moves each object into its box. */
|
|
34
|
+
sync() {
|
|
35
|
+
const t = this._text;
|
|
36
|
+
const host = t.parent;
|
|
37
|
+
const em = t.fontSize;
|
|
38
|
+
const atlas = t.atlas;
|
|
39
|
+
const font = {
|
|
40
|
+
family: t.fontFamily,
|
|
41
|
+
weight: t.fontWeight,
|
|
42
|
+
style: t.fontStyle
|
|
43
|
+
};
|
|
44
|
+
const names = Object.keys(this._defs);
|
|
45
|
+
if (!names.length && !this._key) return;
|
|
46
|
+
const cap = atlas.ink(font, "H").ascent * (em / atlas.size) || em * .7;
|
|
47
|
+
const line = t.lineHeight > 0 ? t.lineHeight : (atlas.metrics(font).ascent + atlas.metrics(font).descent) * (em / atlas.size);
|
|
48
|
+
const boxes = {};
|
|
49
|
+
const fits = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
const def = this._defs[name];
|
|
52
|
+
const b = this._sample(name, def).getLocalBounds();
|
|
53
|
+
const bw = Math.max(b.width, 1e-6);
|
|
54
|
+
const bh = Math.max(b.height, 1e-6);
|
|
55
|
+
let w = resolve(def.width, em, cap, line);
|
|
56
|
+
let h = resolve(def.height, em, cap, line);
|
|
57
|
+
let scale = 1;
|
|
58
|
+
if (w !== void 0 && h !== void 0) scale = Math.min(w / bw, h / bh);
|
|
59
|
+
else if (h !== void 0) scale = h / bh;
|
|
60
|
+
else if (w !== void 0) scale = w / bw;
|
|
61
|
+
w ??= bw * scale;
|
|
62
|
+
h ??= bh * scale;
|
|
63
|
+
boxes[name] = {
|
|
64
|
+
width: w,
|
|
65
|
+
height: h,
|
|
66
|
+
align: def.align,
|
|
67
|
+
offsetY: def.offsetY,
|
|
68
|
+
margin: def.margin
|
|
69
|
+
};
|
|
70
|
+
fits.set(name, {
|
|
71
|
+
scale,
|
|
72
|
+
bx: b.x,
|
|
73
|
+
by: b.y,
|
|
74
|
+
bw,
|
|
75
|
+
bh
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const key = JSON.stringify(boxes);
|
|
79
|
+
if (key !== this._key) {
|
|
80
|
+
this._key = key;
|
|
81
|
+
t.inlines = boxes;
|
|
82
|
+
}
|
|
83
|
+
const used = /* @__PURE__ */ new Map();
|
|
84
|
+
const shown = /* @__PURE__ */ new Set();
|
|
85
|
+
let at = host ? host.getChildIndex(t) + 1 : 0;
|
|
86
|
+
for (const r of t.inlineRects()) {
|
|
87
|
+
const def = this._defs[r.name];
|
|
88
|
+
const fit = fits.get(r.name);
|
|
89
|
+
if (!def || !fit || !host) continue;
|
|
90
|
+
const n = used.get(r.name) ?? 0;
|
|
91
|
+
const obj = this._occurrence(r.name, def, n);
|
|
92
|
+
used.set(r.name, n + 1);
|
|
93
|
+
if (!obj) continue;
|
|
94
|
+
const s = fit.scale;
|
|
95
|
+
const tx = t.x + (r.x + (r.width - fit.bw * s) / 2 - fit.bx * s) * t.scale.x;
|
|
96
|
+
const ty = t.y + (r.y + (r.height - fit.bh * s) / 2 - fit.by * s) * t.scale.y;
|
|
97
|
+
obj.scale.set(s * t.scale.x, s * t.scale.y);
|
|
98
|
+
obj.position.set(tx, ty);
|
|
99
|
+
obj.visible = true;
|
|
100
|
+
if (obj.parent !== host) host.addChildAt(obj, Math.min(at, host.children.length));
|
|
101
|
+
at = host.getChildIndex(obj) + 1;
|
|
102
|
+
shown.add(obj);
|
|
103
|
+
}
|
|
104
|
+
for (const placed of this._placed.values()) for (const o of [...placed.made, ...placed.single ? [placed.single] : []]) if (!shown.has(o)) o.visible = false;
|
|
105
|
+
}
|
|
106
|
+
/** Destroys the objects factories made and takes given instances out of the text's parent. */
|
|
107
|
+
destroy() {
|
|
108
|
+
for (const placed of this._placed.values()) {
|
|
109
|
+
for (const o of placed.made) o.destroy({ children: true });
|
|
110
|
+
placed.single?.parent?.removeChild(placed.single);
|
|
111
|
+
}
|
|
112
|
+
this._placed.clear();
|
|
113
|
+
}
|
|
114
|
+
_entry(name) {
|
|
115
|
+
let p = this._placed.get(name);
|
|
116
|
+
if (!p) {
|
|
117
|
+
p = {
|
|
118
|
+
made: [],
|
|
119
|
+
single: null
|
|
120
|
+
};
|
|
121
|
+
this._placed.set(name, p);
|
|
122
|
+
}
|
|
123
|
+
return p;
|
|
124
|
+
}
|
|
125
|
+
/** An object to measure: the instance, or the first one a factory made. */
|
|
126
|
+
_sample(name, def) {
|
|
127
|
+
const p = this._entry(name);
|
|
128
|
+
if (typeof def.object !== "function") {
|
|
129
|
+
p.single = def.object;
|
|
130
|
+
return def.object;
|
|
131
|
+
}
|
|
132
|
+
if (!p.made.length) p.made.push(def.object());
|
|
133
|
+
return p.made[0];
|
|
134
|
+
}
|
|
135
|
+
_occurrence(name, def, n) {
|
|
136
|
+
const p = this._entry(name);
|
|
137
|
+
if (typeof def.object !== "function") return n === 0 ? def.object : null;
|
|
138
|
+
while (p.made.length <= n) p.made.push(def.object());
|
|
139
|
+
return p.made[n];
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* A {@link SilkText} with sprites, SilkGraphics or any container inside its lines. Write `{name}`
|
|
144
|
+
* in the text and list the object under `inlines`. Each token takes a box that flows with the
|
|
145
|
+
* text: it wraps, aligns and follows right-to-left order like a character, and the line grows when
|
|
146
|
+
* the object is taller than the text. The object is scaled to the box and placed in it every frame,
|
|
147
|
+
* so it follows text, style, anchor and size changes.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { Sprite, Texture } from 'pixi.js';
|
|
152
|
+
* import { SilkGraphics } from 'pixi-silk';
|
|
153
|
+
* import { SilkRichText } from 'pixi-silk/text';
|
|
154
|
+
*
|
|
155
|
+
* const status = new SilkRichText({
|
|
156
|
+
* text: 'Synced {dot} 2 min ago, rated {star} 4.8',
|
|
157
|
+
* fontSize: 24,
|
|
158
|
+
* inlines: {
|
|
159
|
+
* dot: { object: new Sprite(Texture.WHITE), height: 'cap', margin: 2 },
|
|
160
|
+
* star: { object: () => new SilkGraphics().star(0, 0, 5, 10, 5).fill(0xffd60a), height: 'em' },
|
|
161
|
+
* },
|
|
162
|
+
* });
|
|
163
|
+
* app.stage.addChild(status);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
var SilkRichText = class extends Container {
|
|
167
|
+
/** The text. Style it through this object, except for `inlines`, which this container owns. */
|
|
168
|
+
textObject;
|
|
169
|
+
_placer;
|
|
170
|
+
constructor(options = {}) {
|
|
171
|
+
const { inlines = {}, label, ...rest } = options;
|
|
172
|
+
super({ label: label ?? "SilkRichText" });
|
|
173
|
+
this.textObject = new SilkText(rest);
|
|
174
|
+
this.addChild(this.textObject);
|
|
175
|
+
this._placer = new InlinePlacer(this.textObject, inlines);
|
|
176
|
+
this.onRender = () => this.sync();
|
|
177
|
+
this.sync();
|
|
178
|
+
}
|
|
179
|
+
/** The text, with `{name}` tokens where inline objects go. */
|
|
180
|
+
get text() {
|
|
181
|
+
return this.textObject.text;
|
|
182
|
+
}
|
|
183
|
+
/** Sets {@link SilkRichText.text}. */
|
|
184
|
+
set text(v) {
|
|
185
|
+
this.textObject.text = v;
|
|
186
|
+
this.sync();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Point of the text box at the position, as on {@link SilkText.anchor}: (0, 0) top left, (0.5,
|
|
190
|
+
* 0.5) centre. The inline objects move with it.
|
|
191
|
+
*/
|
|
192
|
+
get anchor() {
|
|
193
|
+
return this.textObject.anchor;
|
|
194
|
+
}
|
|
195
|
+
/** The inline objects by name. Set a new object to change them. Objects that left are removed, not destroyed. */
|
|
196
|
+
get inlines() {
|
|
197
|
+
return this._placer.defs;
|
|
198
|
+
}
|
|
199
|
+
/** Sets {@link SilkRichText.inlines}. */
|
|
200
|
+
set inlines(v) {
|
|
201
|
+
this._placer.defs = v;
|
|
202
|
+
this.sync();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Measures the objects, lays the text out around them and moves them into their boxes. Runs
|
|
206
|
+
* before every render, so call it only to read positions in the same frame as a change.
|
|
207
|
+
*/
|
|
208
|
+
sync() {
|
|
209
|
+
this._placer.sync();
|
|
210
|
+
}
|
|
211
|
+
destroy(options) {
|
|
212
|
+
this._placer.destroy();
|
|
213
|
+
this.onRender = null;
|
|
214
|
+
super.destroy(options);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
export { InlinePlacer, SilkRichText };
|
package/dist/text/shader.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GradientAtlas } from "../atlas.js";
|
|
2
|
+
import { silkGl1 } from "../shader-slot.js";
|
|
2
3
|
import { GlProgram, GpuProgram, Shader, UniformGroup } from "pixi.js";
|
|
3
4
|
//#region src/text/shader.ts
|
|
4
5
|
/** @internal Vertex stage (GLSL ES 3.00). */
|
|
@@ -45,6 +46,7 @@ flat in vec4 vTint;
|
|
|
45
46
|
flat in float vPx;
|
|
46
47
|
uniform highp sampler2D uAtlas;
|
|
47
48
|
uniform highp sampler2D uGradients;
|
|
49
|
+
uniform highp sampler2D uColorAtlas;
|
|
48
50
|
uniform vec4 uFill;
|
|
49
51
|
uniform vec4 uOutline;
|
|
50
52
|
uniform vec4 uShadow;
|
|
@@ -141,7 +143,15 @@ oc = cover(d - line, aa);
|
|
|
141
143
|
}
|
|
142
144
|
if (uFx.y <= 0.0) oc = 0.0;
|
|
143
145
|
vec4 fill = uPaint.x > 0.5 ? uFill * gradientColor(vPos) : uFill;
|
|
144
|
-
|
|
146
|
+
if (vMeta.z >= 0.0)
|
|
147
|
+
{
|
|
148
|
+
vec2 cuv = (vTex - vCell.xy + vMeta.zw) / vec2(textureSize(uColorAtlas, 0));
|
|
149
|
+
fill = textureLod(uColorAtlas, cuv, 0.0) * uFill.a;
|
|
150
|
+
fc = 1.0;
|
|
151
|
+
}
|
|
152
|
+
if (vMeta.y > 1.5) col = fill * fc;
|
|
153
|
+
else if (vMeta.y > 0.5) col = uOutline * oc;
|
|
154
|
+
else col = fill * fc + uOutline * (oc * (1.0 - fill.a * fc));
|
|
145
155
|
}
|
|
146
156
|
col *= vTint;
|
|
147
157
|
if (col.a <= 0.0) discard;
|
|
@@ -175,6 +185,8 @@ uPaint: vec4<f32>,
|
|
|
175
185
|
@group(2) @binding(2) var uAtlasSampler: sampler;
|
|
176
186
|
@group(2) @binding(3) var uGradients: texture_2d<f32>;
|
|
177
187
|
@group(2) @binding(4) var uGradientsSampler: sampler;
|
|
188
|
+
@group(2) @binding(5) var uColorAtlas: texture_2d<f32>;
|
|
189
|
+
@group(2) @binding(6) var uColorSampler: sampler;
|
|
178
190
|
struct VSOutput {
|
|
179
191
|
@builtin(position) position: vec4<f32>,
|
|
180
192
|
@location(0) vPos: vec2<f32>,
|
|
@@ -296,8 +308,20 @@ var fill = u.uFill;
|
|
|
296
308
|
if (u.uPaint.x > 0.5) {
|
|
297
309
|
fill = fill * gradientColor(input.vPos);
|
|
298
310
|
}
|
|
311
|
+
let cuv = (input.vTex - input.vCell.xy + input.vMeta.zw) / vec2<f32>(textureDimensions(uColorAtlas));
|
|
312
|
+
let colour = textureSampleLevel(uColorAtlas, uColorSampler, cuv, 0.0);
|
|
313
|
+
if (input.vMeta.z >= 0.0) {
|
|
314
|
+
fill = colour * u.uFill.a;
|
|
315
|
+
fc = 1.0;
|
|
316
|
+
}
|
|
317
|
+
if (input.vMeta.y > 1.5) {
|
|
318
|
+
col = fill * fc;
|
|
319
|
+
} else if (input.vMeta.y > 0.5) {
|
|
320
|
+
col = u.uOutline * oc;
|
|
321
|
+
} else {
|
|
299
322
|
col = fill * fc + u.uOutline * (oc * (1.0 - fill.a * fc));
|
|
300
323
|
}
|
|
324
|
+
}
|
|
301
325
|
col *= input.vTint;
|
|
302
326
|
if (col.a <= 0.0) {
|
|
303
327
|
discard;
|
|
@@ -307,7 +331,7 @@ return col;
|
|
|
307
331
|
let glProgram = null;
|
|
308
332
|
let gpuProgram = null;
|
|
309
333
|
/** @internal Builds the shader of one SilkText: shared programs, its own uniforms. */
|
|
310
|
-
function createTextShader(atlas) {
|
|
334
|
+
function createTextShader(atlas, colors = atlas) {
|
|
311
335
|
glProgram ??= GlProgram.from({
|
|
312
336
|
vertex: textVertex,
|
|
313
337
|
fragment: textFragment,
|
|
@@ -326,15 +350,17 @@ function createTextShader(atlas) {
|
|
|
326
350
|
entryPoint: "mainFragment"
|
|
327
351
|
}
|
|
328
352
|
});
|
|
353
|
+
const gl1 = silkGl1.hooks;
|
|
329
354
|
const gradients = GradientAtlas.shared.source;
|
|
330
355
|
const v4 = () => ({
|
|
331
356
|
value: /* @__PURE__ */ new Float32Array(4),
|
|
332
357
|
type: "vec4<f32>"
|
|
333
358
|
});
|
|
334
|
-
|
|
335
|
-
glProgram,
|
|
359
|
+
const shader = new Shader({
|
|
360
|
+
glProgram: gl1 ? gl1.program("silk-text", textVertex, textFragment) : glProgram,
|
|
336
361
|
gpuProgram,
|
|
337
362
|
resources: {
|
|
363
|
+
...gl1?.resources("silk-text"),
|
|
338
364
|
textUniforms: new UniformGroup({
|
|
339
365
|
uFill: v4(),
|
|
340
366
|
uOutline: v4(),
|
|
@@ -347,9 +373,13 @@ function createTextShader(atlas) {
|
|
|
347
373
|
uAtlas: atlas,
|
|
348
374
|
uAtlasSampler: atlas.style,
|
|
349
375
|
uGradients: gradients,
|
|
350
|
-
uGradientsSampler: gradients.style
|
|
376
|
+
uGradientsSampler: gradients.style,
|
|
377
|
+
uColorAtlas: colors,
|
|
378
|
+
uColorSampler: colors.style
|
|
351
379
|
}
|
|
352
380
|
});
|
|
381
|
+
gl1?.syncSizes(shader);
|
|
382
|
+
return shader;
|
|
353
383
|
}
|
|
354
384
|
//#endregion
|
|
355
385
|
export { createTextShader, textFragment, textVertex, textWgsl };
|
package/dist/text.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FontMetrics, FontSpec, Glyph, GlyphContext, SdfAtlas, SdfAtlasOptions, fontString } from "./text/atlas.js";
|
|
2
|
+
import { BidiClass, TextDirection, bidiClass, hasRtl, mirror, paragraphLevel, resetWhitespace, resolveLevels, visualOrder } from "./text/bidi.js";
|
|
3
|
+
import { Cluster, WordBreak, clusters } from "./text/cluster.js";
|
|
2
4
|
import { sdfFromAlpha } from "./text/edt.js";
|
|
3
|
-
import { CaretHit, CaretRect, LayoutLine, LayoutOptions, PlacedGlyph, TextAlign, TextLayout, TextMeasurer, TextRect, caretAtPoint, caretRect, caretX, layoutText, lineOfIndex, rangeRects } from "./text/layout.js";
|
|
4
|
-
import { ResolvedTextStyle, SilkText, SilkTextGeometry, SilkTextOptions, SilkTextStyle, TextOutline, TextShadow } from "./text/SilkText.js";
|
|
5
|
-
import {
|
|
5
|
+
import { CaretHit, CaretRect, CaretStop, InlineMetrics, InlineToken, LayoutLine, LayoutOptions, LineRun, PlacedGlyph, TextAlign, TextLayout, TextMeasurer, TextRect, caretAtPoint, caretRect, caretVisual, caretX, inlineTokens, layoutText, lineOfIndex, rangeRects } from "./text/layout.js";
|
|
6
|
+
import { InlineAlign, InlineRect, ResolvedTextStyle, SilkText, SilkTextGeometry, SilkTextOptions, SilkTextStyle, TextInline, TextOutline, TextShadow } from "./text/SilkText.js";
|
|
7
|
+
import { InlineSize, RichInline, SilkRichText, SilkRichTextOptions } from "./text/rich.js";
|
|
8
|
+
import { silkLabel, silkRichLabel } from "./text/label.js";
|
|
6
9
|
import { WordSegment, graphemeStops, isMac, nextWordStop, paragraphAt, previousWordStop, wordAt, wordSegments } from "./text/segment.js";
|
|
7
|
-
export { type CaretHit, type CaretRect, type FontMetrics, type FontSpec, type Glyph, type GlyphContext, type LayoutLine, type LayoutOptions, type PlacedGlyph, type ResolvedTextStyle, SdfAtlas, type SdfAtlasOptions, SilkText, SilkTextGeometry, type SilkTextOptions, type SilkTextStyle, type TextAlign, type TextLayout, type TextMeasurer, type TextOutline, type TextRect, type TextShadow, type WordSegment, caretAtPoint, caretRect, caretX, fontString, graphemeStops, isMac, layoutText, lineOfIndex, nextWordStop, paragraphAt, previousWordStop, rangeRects, sdfFromAlpha, silkLabel, wordAt, wordSegments };
|
|
10
|
+
export { type BidiClass, type CaretHit, type CaretRect, type CaretStop, type Cluster, type FontMetrics, type FontSpec, type Glyph, type GlyphContext, type InlineAlign, type InlineMetrics, type InlineRect, type InlineSize, type InlineToken, type LayoutLine, type LayoutOptions, type LineRun, type PlacedGlyph, type ResolvedTextStyle, type RichInline, SdfAtlas, type SdfAtlasOptions, SilkRichText, type SilkRichTextOptions, SilkText, SilkTextGeometry, type SilkTextOptions, type SilkTextStyle, type TextAlign, type TextDirection, type TextInline, type TextLayout, type TextMeasurer, type TextOutline, type TextRect, type TextShadow, type WordBreak, type WordSegment, bidiClass, caretAtPoint, caretRect, caretVisual, caretX, clusters, fontString, graphemeStops, hasRtl, inlineTokens, isMac, layoutText, lineOfIndex, mirror, nextWordStop, paragraphAt, paragraphLevel, previousWordStop, rangeRects, resetWhitespace, resolveLevels, sdfFromAlpha, silkLabel, silkRichLabel, visualOrder, wordAt, wordSegments };
|
package/dist/text.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { sdfFromAlpha } from "./text/edt.js";
|
|
2
2
|
import { SdfAtlas, fontString } from "./text/atlas.js";
|
|
3
|
-
import {
|
|
3
|
+
import { bidiClass, hasRtl, mirror, paragraphLevel, resetWhitespace, resolveLevels, visualOrder } from "./text/bidi.js";
|
|
4
|
+
import { clusters } from "./text/cluster.js";
|
|
5
|
+
import { caretAtPoint, caretRect, caretVisual, caretX, inlineTokens, layoutText, lineOfIndex, rangeRects } from "./text/layout.js";
|
|
4
6
|
import { SilkText, SilkTextGeometry } from "./text/SilkText.js";
|
|
5
|
-
import {
|
|
7
|
+
import { SilkRichText } from "./text/rich.js";
|
|
8
|
+
import { silkLabel, silkRichLabel } from "./text/label.js";
|
|
6
9
|
import { graphemeStops, isMac, nextWordStop, paragraphAt, previousWordStop, wordAt, wordSegments } from "./text/segment.js";
|
|
7
|
-
export { SdfAtlas, SilkText, SilkTextGeometry, caretAtPoint, caretRect, caretX, fontString, graphemeStops, isMac, layoutText, lineOfIndex, nextWordStop, paragraphAt, previousWordStop, rangeRects, sdfFromAlpha, silkLabel, wordAt, wordSegments };
|
|
10
|
+
export { SdfAtlas, SilkRichText, SilkText, SilkTextGeometry, bidiClass, caretAtPoint, caretRect, caretVisual, caretX, clusters, fontString, graphemeStops, hasRtl, inlineTokens, isMac, layoutText, lineOfIndex, mirror, nextWordStop, paragraphAt, paragraphLevel, previousWordStop, rangeRects, resetWhitespace, resolveLevels, sdfFromAlpha, silkLabel, silkRichLabel, visualOrder, wordAt, wordSegments };
|
package/dist/ui/textedit.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ReadSignal, Signal } from "../signal.js";
|
|
|
2
2
|
import { HistoryLike } from "../history.js";
|
|
3
3
|
import { CaretHit } from "../text/layout.js";
|
|
4
4
|
import { SilkText, SilkTextOptions } from "../text/SilkText.js";
|
|
5
|
+
import { RichInline } from "../text/rich.js";
|
|
5
6
|
import { ColorSource, Container, DestroyOptions, PointData, Ticker } from "pixi.js";
|
|
6
7
|
//#region src/ui/textedit.d.ts
|
|
7
8
|
/** A selection: where it started (`anchor`) and where the caret is (`focus`). Equal for a plain caret. */
|
|
@@ -27,7 +28,7 @@ export interface TextEditorTheme {
|
|
|
27
28
|
/** Default colours of a {@link TextEditor}: a blue caret and highlight. Override single values with the `theme` option. */
|
|
28
29
|
export declare const TEXT_EDITOR_THEME: Readonly<TextEditorTheme>;
|
|
29
30
|
/** Options of a {@link TextEditor}: the text style plus how it edits. */
|
|
30
|
-
export interface TextEditorOptions extends Omit<SilkTextOptions, "wordWrap" | "wordWrapWidth" | "label"> {
|
|
31
|
+
export interface TextEditorOptions extends Omit<SilkTextOptions, "wordWrap" | "wordWrapWidth" | "label" | "inlines"> {
|
|
31
32
|
/** Starting text. Default empty. */
|
|
32
33
|
text?: string;
|
|
33
34
|
/** Several lines (a text area) or one (an input). Default true. */
|
|
@@ -79,6 +80,11 @@ export interface TextEditorOptions extends Omit<SilkTextOptions, "wordWrap" | "w
|
|
|
79
80
|
caretWidth?: number;
|
|
80
81
|
/** Ticker driving the caret blink. Default `Ticker.shared`. `null` for manual {@link TextEditor.tick}. */
|
|
81
82
|
ticker?: Ticker | null;
|
|
83
|
+
/**
|
|
84
|
+
* Objects shown where `{name}` appears in the text, as in {@link SilkRichText}. Typing a token
|
|
85
|
+
* turns it into its object, the caret steps over it whole and one Backspace deletes it. Default none.
|
|
86
|
+
*/
|
|
87
|
+
inlines?: Record<string, RichInline>;
|
|
82
88
|
}
|
|
83
89
|
/** The reactive state of a {@link TextEditor}. */
|
|
84
90
|
export interface TextEditorState {
|
|
@@ -110,7 +116,9 @@ export type TextEditKind = "type" | "delete" | "forward" | "paste" | "cut" | "ne
|
|
|
110
116
|
* Events: `focus`, `blur`, `input` (every edit), `change` (on commit, when the text changed), `submit`
|
|
111
117
|
* (Enter in a single-line editor) and `tab`. The same values are on {@link TextEditor.state}.
|
|
112
118
|
*
|
|
113
|
-
*
|
|
119
|
+
* Right-to-left and mixed-direction text edits in place: the arrow keys move the way they point on
|
|
120
|
+
* screen, and a selection across a change of direction shows as several boxes. `{name}` tokens show
|
|
121
|
+
* inline objects (see `inlines`). Mixed styles in one editor are not supported.
|
|
114
122
|
*
|
|
115
123
|
* Experimental: the API may change in a minor release.
|
|
116
124
|
*
|
|
@@ -163,6 +171,8 @@ export declare class TextEditor extends Container {
|
|
|
163
171
|
private _anchor;
|
|
164
172
|
private _focus;
|
|
165
173
|
private _upstream;
|
|
174
|
+
/** The caret goes with the character after it, where one offset has two places on screen. */
|
|
175
|
+
private _lead;
|
|
166
176
|
private _prefX;
|
|
167
177
|
private _stops;
|
|
168
178
|
private _stopSet;
|
|
@@ -191,11 +201,16 @@ export declare class TextEditor extends Container {
|
|
|
191
201
|
private _keepFocus;
|
|
192
202
|
private _focusedAt;
|
|
193
203
|
private readonly _mac;
|
|
204
|
+
private readonly _placer;
|
|
194
205
|
constructor(options?: TextEditorOptions);
|
|
195
206
|
/** The text. Setting it replaces the text and puts the caret at the end, without an undo step. */
|
|
196
207
|
get value(): string;
|
|
197
208
|
/** Sets {@link TextEditor.value}. */
|
|
198
209
|
set value(v: string);
|
|
210
|
+
/** Objects shown where `{name}` appears in the text. Set a new object to change them. */
|
|
211
|
+
get inlines(): Record<string, RichInline>;
|
|
212
|
+
/** Sets {@link TextEditor.inlines}. */
|
|
213
|
+
set inlines(v: Record<string, RichInline>);
|
|
199
214
|
/** True while the editor has keyboard focus. */
|
|
200
215
|
get focused(): boolean;
|
|
201
216
|
/** True for a multi-line editor. */
|