drawnui-react 0.1.0-preview.41 → 0.1.0-preview.42
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/README.md +47 -0
- package/SKIPPED.md +2 -2
- package/dist/controls/SkiaEditor.js +5 -4
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +32 -5
- package/dist/controls/SkiaLabel.d.ts +17 -2
- package/dist/controls/SkiaLabel.js +38 -12
- package/dist/controls/SkiaLabelFps.d.ts +0 -3
- package/dist/controls/SkiaLabelFps.js +1 -11
- package/dist/controls/SkiaLayout.js +33 -2
- package/dist/controls/SkiaScroll.d.ts +17 -0
- package/dist/controls/SkiaScroll.js +51 -6
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSprite.js +5 -1
- package/dist/core/Accessibility.d.ts +12 -0
- package/dist/core/Accessibility.js +62 -14
- package/dist/core/Canvas.d.ts +31 -8
- package/dist/core/Canvas.js +85 -18
- package/dist/core/Gestures.d.ts +1 -0
- package/dist/core/Props.d.ts +11 -0
- package/dist/core/Props.js +44 -0
- package/dist/core/SkiaControl.d.ts +21 -2
- package/dist/core/SkiaControl.js +55 -11
- package/dist/core/SkiaEffect.d.ts +12 -1
- package/dist/core/SkiaEffect.js +35 -8
- package/dist/core/SkiaImageManager.d.ts +100 -18
- package/dist/core/SkiaImageManager.js +309 -64
- package/dist/core/Styles.js +7 -1
- package/dist/core/Super.d.ts +2 -0
- package/dist/core/Super.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -514
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +8 -4
- package/dist/react/reconciler.d.ts +12 -0
- package/dist/react/reconciler.js +22 -46
- package/package.json +19 -2
|
@@ -121,7 +121,11 @@ export class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
121
121
|
const cached = SkiaSprite.CachedSpriteSheets.get(source);
|
|
122
122
|
if (cached)
|
|
123
123
|
return cached;
|
|
124
|
-
const image = await SkiaImageManager.Instance.
|
|
124
|
+
const image = await SkiaImageManager.Instance.LoadImageManagedAsync(source);
|
|
125
|
+
if (!image)
|
|
126
|
+
throw new Error(`DrawnUi: cannot load sprite sheet '${source}'`);
|
|
127
|
+
// the sheets cache holds it for good (the image manager never deletes an image somebody holds)
|
|
128
|
+
SkiaImageManager.Instance.Hold(image);
|
|
125
129
|
SkiaSprite.CachedSpriteSheets.set(source, image);
|
|
126
130
|
return image;
|
|
127
131
|
}
|
|
@@ -174,8 +174,15 @@ export declare class SkiaAccessibilityManager {
|
|
|
174
174
|
private focusRequest?;
|
|
175
175
|
private popupFocusRoot?;
|
|
176
176
|
private focusAnyInside;
|
|
177
|
+
private popupFocusDeadline;
|
|
177
178
|
/** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
|
|
178
179
|
RequestKeyboardFocus(control: SkiaControl): void;
|
|
180
|
+
/**
|
|
181
|
+
* How long a keyboard focus request waits for its control to take input again (drawnui-cross 6bs): an app that shows
|
|
182
|
+
* the opener of a dialog again only once the dialog is gone (a HUD hidden under it) still gets the keyboard back there.
|
|
183
|
+
*/
|
|
184
|
+
static FocusRequestWaitMs: number;
|
|
185
|
+
private focusRequestDeadline;
|
|
179
186
|
private appFocus?;
|
|
180
187
|
private appFocusDeadline;
|
|
181
188
|
private appFocusThisFrame;
|
|
@@ -203,6 +210,11 @@ export declare class SkiaAccessibilityManager {
|
|
|
203
210
|
set KeyboardScope(v: SkiaControl | undefined);
|
|
204
211
|
/** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
|
|
205
212
|
ActiveModal?: SkiaControl;
|
|
213
|
+
/**
|
|
214
|
+
* The node the overlay names the active modal after (drawnui-cross 6bs): the modal's own when it has a name, else the
|
|
215
|
+
* first named dialog inside it, so a nameless popup host around a dialog reads as that one dialog, not as two.
|
|
216
|
+
*/
|
|
217
|
+
get ActiveModalNode(): AccessibilityNode | undefined;
|
|
206
218
|
private readonly modalReturns;
|
|
207
219
|
/** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
|
|
208
220
|
IsOutsideModal(control: SkiaControl): boolean;
|
|
@@ -262,9 +262,20 @@ export class SkiaAccessibilityManager {
|
|
|
262
262
|
focusRequest;
|
|
263
263
|
popupFocusRoot;
|
|
264
264
|
focusAnyInside = false;
|
|
265
|
+
popupFocusDeadline = 0;
|
|
265
266
|
/** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
|
|
266
|
-
RequestKeyboardFocus(control) {
|
|
267
|
-
this.
|
|
267
|
+
RequestKeyboardFocus(control) {
|
|
268
|
+
if (this.appFocusThisFrame)
|
|
269
|
+
return;
|
|
270
|
+
this.focusRequest = control;
|
|
271
|
+
this.focusRequestDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* How long a keyboard focus request waits for its control to take input again (drawnui-cross 6bs): an app that shows
|
|
275
|
+
* the opener of a dialog again only once the dialog is gone (a HUD hidden under it) still gets the keyboard back there.
|
|
276
|
+
*/
|
|
277
|
+
static FocusRequestWaitMs = 1000;
|
|
278
|
+
focusRequestDeadline = 0;
|
|
268
279
|
appFocus;
|
|
269
280
|
appFocusDeadline = 0;
|
|
270
281
|
appFocusThisFrame = false; // until the frame end: the app said where the focus goes, the library's moves give way
|
|
@@ -313,6 +324,19 @@ export class SkiaAccessibilityManager {
|
|
|
313
324
|
// ---- modal accessibility scope (drawnui-cross 6av, C# AccessibilityModal) ----
|
|
314
325
|
/** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
|
|
315
326
|
ActiveModal;
|
|
327
|
+
/**
|
|
328
|
+
* The node the overlay names the active modal after (drawnui-cross 6bs): the modal's own when it has a name, else the
|
|
329
|
+
* first named dialog inside it, so a nameless popup host around a dialog reads as that one dialog, not as two.
|
|
330
|
+
*/
|
|
331
|
+
get ActiveModalNode() {
|
|
332
|
+
const modal = this.ActiveModal;
|
|
333
|
+
if (!modal)
|
|
334
|
+
return undefined;
|
|
335
|
+
const own = this.Snapshot.find((n) => n.Source === modal);
|
|
336
|
+
if (own?.Label)
|
|
337
|
+
return own;
|
|
338
|
+
return this.Snapshot.find((n) => (n.Role === Aria.RoleDialog || n.Role === Aria.RoleAlertDialog) && !!n.Label && n.Source !== modal && IsInside(n.Source, modal)) ?? own;
|
|
339
|
+
}
|
|
316
340
|
// where the keyboard was when each modal became active, to go back there when it goes
|
|
317
341
|
modalReturns = new Map();
|
|
318
342
|
/** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
|
|
@@ -336,18 +360,27 @@ export class SkiaAccessibilityManager {
|
|
|
336
360
|
this.ActiveModal = next;
|
|
337
361
|
this.ForceRebuildOnNextFrame(); // readers and Tab switch to the new scope in this frame
|
|
338
362
|
const keyboard = this.FocusedNode;
|
|
339
|
-
if (next && keyboard && !IsInside(keyboard, next)) {
|
|
340
|
-
// the keyboard is in use: into the modal, and back here when it goes
|
|
341
|
-
this.modalReturns.set(next, keyboard);
|
|
342
|
-
this.popupFocusRoot = next;
|
|
343
|
-
this.focusAnyInside = true;
|
|
344
|
-
}
|
|
345
363
|
const back = previous && this.modalReturns.get(previous);
|
|
346
364
|
if (previous)
|
|
347
365
|
this.modalReturns.delete(previous);
|
|
348
366
|
// back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
|
|
349
367
|
const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
|
|
350
|
-
|
|
368
|
+
const fromPrevious = !!back && (!keyboard || leftWithIt || IsInside(keyboard, previous));
|
|
369
|
+
if (next) {
|
|
370
|
+
// the keyboard is in use: into the modal, and back to `from` when it goes. A dialog handing over to another (How to
|
|
371
|
+
// play, then Paused) passes its own return on, in the same frame or while that return is still waiting (6bs).
|
|
372
|
+
const waiting = this.focusRequest && !this.focusRequest.IsDisposed && !IsInside(this.focusRequest, next) ? this.focusRequest : undefined;
|
|
373
|
+
const from = fromPrevious ? back : waiting ?? (keyboard && !leftWithIt && !IsInside(keyboard, next) ? keyboard : undefined);
|
|
374
|
+
if (from) {
|
|
375
|
+
this.modalReturns.set(next, from);
|
|
376
|
+
this.popupFocusRoot = next;
|
|
377
|
+
this.focusAnyInside = true;
|
|
378
|
+
this.popupFocusDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs;
|
|
379
|
+
if (from === this.focusRequest)
|
|
380
|
+
this.focusRequest = undefined;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (fromPrevious && (!next || IsInside(back, next)))
|
|
351
384
|
this.RequestKeyboardFocus(back);
|
|
352
385
|
}
|
|
353
386
|
/** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
|
|
@@ -367,8 +400,8 @@ export class SkiaAccessibilityManager {
|
|
|
367
400
|
* A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
|
|
368
401
|
* choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
|
|
369
402
|
*/
|
|
370
|
-
FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; }
|
|
371
|
-
ProcessFocusRequests(scale, w, h) {
|
|
403
|
+
FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; this.popupFocusDeadline = performance.now() + SkiaAccessibilityManager.FocusRequestWaitMs; }
|
|
404
|
+
ProcessFocusRequests(scale, w, h, requestFrame) {
|
|
372
405
|
const request = this.focusRequest, root = this.popupFocusRoot;
|
|
373
406
|
this.focusRequest = this.popupFocusRoot = undefined;
|
|
374
407
|
if (root && !root.IsDisposed && root.Superview) {
|
|
@@ -384,9 +417,23 @@ export class SkiaAccessibilityManager {
|
|
|
384
417
|
this.FocusFromKeyboard(target.Source, scale, w, h);
|
|
385
418
|
return;
|
|
386
419
|
}
|
|
420
|
+
// a modal with nothing to take input yet (its buttons show a moment later): looked at again on the next frames, for a moment
|
|
421
|
+
if (this.focusAnyInside && performance.now() < this.popupFocusDeadline) {
|
|
422
|
+
this.popupFocusRoot = root;
|
|
423
|
+
this.focusRequest ??= request;
|
|
424
|
+
requestFrame();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
387
427
|
}
|
|
388
|
-
if (request
|
|
428
|
+
if (!request || request.IsDisposed || !request.Superview)
|
|
429
|
+
return;
|
|
430
|
+
if (request.AccessibilityCanInteract)
|
|
389
431
|
this.FocusFromKeyboard(request, scale, w, h);
|
|
432
|
+
// not taking input yet (shown again only after a dialog closed): asked again on the next frames, for a moment
|
|
433
|
+
else if (performance.now() < this.focusRequestDeadline) {
|
|
434
|
+
this.focusRequest = request;
|
|
435
|
+
requestFrame();
|
|
436
|
+
}
|
|
390
437
|
}
|
|
391
438
|
/** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
|
|
392
439
|
ProcessGroupFocus(scale, w, h, requestFrame) {
|
|
@@ -483,7 +530,7 @@ export class SkiaAccessibilityManager {
|
|
|
483
530
|
if (this.appFocus)
|
|
484
531
|
this.ProcessAppFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
|
|
485
532
|
if (this.focusRequest || this.popupFocusRoot)
|
|
486
|
-
this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
|
|
533
|
+
this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx, requestFrame);
|
|
487
534
|
this.appFocusThisFrame = false;
|
|
488
535
|
if (this.nodes.size === 0 && this.Snapshot.length === 0)
|
|
489
536
|
return;
|
|
@@ -513,7 +560,8 @@ export class SkiaAccessibilityManager {
|
|
|
513
560
|
n.OnAccessibilityUnregistered();
|
|
514
561
|
continue;
|
|
515
562
|
} // detached from the tree
|
|
516
|
-
|
|
563
|
+
// at opacity 0 a control is not seen, so it is not read either (DrawnUi.Net 4bd759e8)
|
|
564
|
+
if (!n.IsVisible || n.Opacity <= 0 || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
|
|
517
565
|
continue;
|
|
518
566
|
if (modal && this.IsOutsideModal(n))
|
|
519
567
|
continue; // a modal is shown: only its nodes, and those of popup windows over it
|
package/dist/core/Canvas.d.ts
CHANGED
|
@@ -145,13 +145,25 @@ export declare class Canvas {
|
|
|
145
145
|
private frameId;
|
|
146
146
|
private disposed;
|
|
147
147
|
private readonly observer;
|
|
148
|
+
/**
|
|
149
|
+
* The device pixels the element covers, as the browser reports them (ResizeObserver device-pixel-content-box). At a
|
|
150
|
+
* fractional display scale the rounded CSS size can be a pixel off (701.3 x 333.3 CSS px at 1.25 cover 877 x 416 device
|
|
151
|
+
* px), and the browser would then resample the whole canvas, softening every glyph.
|
|
152
|
+
*/
|
|
153
|
+
private devicePixels?;
|
|
154
|
+
/** The element's CSS width when the device-pixel box was reported. */
|
|
155
|
+
private devicePixelsCss;
|
|
148
156
|
/** The WebGL context is lost: no frames until the browser restores it. */
|
|
149
157
|
private contextLost;
|
|
150
158
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
159
|
+
* The GPU context generation, unique across canvases: a new one when this canvas is made and when its WebGL context
|
|
160
|
+
* is restored. Every GPU object made under another one (Image caches, picture caches that may replay them, kept
|
|
161
|
+
* composite surfaces, effect textures; also those a control brought from another canvas) is remade at its next draw
|
|
162
|
+
* (DrawnUi.Rust Gpu::epoch). A texture of another WebGL context draws nothing.
|
|
153
163
|
*/
|
|
154
164
|
GpuEpoch: number;
|
|
165
|
+
private static gpuEpochs;
|
|
166
|
+
private static NextGpuEpoch;
|
|
155
167
|
/** `init` runs before the first frame is drawn: the place to attach `WillFirstTimeDraw` / `WasDrawn` for that frame. */
|
|
156
168
|
constructor(Element: HTMLCanvasElement, init?: (canvas: Canvas) => void);
|
|
157
169
|
/** Request a redraw (full measure + arrange + render) on the next animation frame. */
|
|
@@ -166,15 +178,26 @@ export declare class Canvas {
|
|
|
166
178
|
* redrawn content lands in the same paint and no blank frame is ever shown while dragging.
|
|
167
179
|
*/
|
|
168
180
|
private OnResized;
|
|
169
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* Registers the WebGL context without `WEBGL_polygon_mode` (drawnui-cross 6bt): Emscripten turns on every extension it
|
|
183
|
+
* knows while it registers a context, nothing here draws with that one, and WebKit warns "non-portable extension
|
|
184
|
+
* enabled" for it. The lookup is hidden only for this synchronous call (creating the context here first would change
|
|
185
|
+
* the attributes CanvasKit asks for).
|
|
186
|
+
*/
|
|
187
|
+
private static WithoutPolygonMode;
|
|
188
|
+
/**
|
|
189
|
+
* WebGL context lost: keep the browser restoring it (preventDefault) and stop the frames. The old Skia context is
|
|
190
|
+
* abandoned here, while the context is lost: WebGL ignores every call on a lost context without a word, so the GL
|
|
191
|
+
* deletes Skia makes while it lets go of its objects stay silent (done after the restore, they reach the new
|
|
192
|
+
* generation and every one logs "object does not belong to this context"). CanvasKit has no `abandonContext`;
|
|
193
|
+
* `releaseResourcesAndAbandonContext` is its only way, and after it freeing an old image or surface makes no GL call.
|
|
194
|
+
*/
|
|
170
195
|
private readonly onContextLost;
|
|
171
196
|
/**
|
|
172
197
|
* WebGL context restored (as DrawnUi.Rust and the C# Wasm / Blazor heads): every GL object of the lost generation is
|
|
173
|
-
* gone
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* GL call. Then the same WebGL object is registered again (the old handle deleted first, which clears the canvas'
|
|
177
|
-
* context object) with a new GrContext and surface; GpuEpoch makes the old generation's GPU objects remake themselves.
|
|
198
|
+
* gone, and the old Skia context was abandoned when it was lost. The same WebGL object is registered again (the old
|
|
199
|
+
* handle deleted first, which clears the canvas' context object) with a new GrContext and surface; GpuEpoch makes the
|
|
200
|
+
* old generation's GPU objects remake themselves.
|
|
178
201
|
*/
|
|
179
202
|
private readonly onContextRestored;
|
|
180
203
|
/** Draws one frame immediately (outside the rAF loop) and presents it. */
|
package/dist/core/Canvas.js
CHANGED
|
@@ -193,13 +193,25 @@ export class Canvas {
|
|
|
193
193
|
frameId = 0;
|
|
194
194
|
disposed = false;
|
|
195
195
|
observer;
|
|
196
|
+
/**
|
|
197
|
+
* The device pixels the element covers, as the browser reports them (ResizeObserver device-pixel-content-box). At a
|
|
198
|
+
* fractional display scale the rounded CSS size can be a pixel off (701.3 x 333.3 CSS px at 1.25 cover 877 x 416 device
|
|
199
|
+
* px), and the browser would then resample the whole canvas, softening every glyph.
|
|
200
|
+
*/
|
|
201
|
+
devicePixels;
|
|
202
|
+
/** The element's CSS width when the device-pixel box was reported. */
|
|
203
|
+
devicePixelsCss = 0;
|
|
196
204
|
/** The WebGL context is lost: no frames until the browser restores it. */
|
|
197
205
|
contextLost = false;
|
|
198
206
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
207
|
+
* The GPU context generation, unique across canvases: a new one when this canvas is made and when its WebGL context
|
|
208
|
+
* is restored. Every GPU object made under another one (Image caches, picture caches that may replay them, kept
|
|
209
|
+
* composite surfaces, effect textures; also those a control brought from another canvas) is remade at its next draw
|
|
210
|
+
* (DrawnUi.Rust Gpu::epoch). A texture of another WebGL context draws nothing.
|
|
201
211
|
*/
|
|
202
|
-
GpuEpoch =
|
|
212
|
+
GpuEpoch = Canvas.NextGpuEpoch();
|
|
213
|
+
static gpuEpochs = 0;
|
|
214
|
+
static NextGpuEpoch() { return ++Canvas.gpuEpochs; }
|
|
203
215
|
/** `init` runs before the first frame is drawn: the place to attach `WillFirstTimeDraw` / `WasDrawn` for that frame. */
|
|
204
216
|
constructor(Element, init) {
|
|
205
217
|
this.Element = Element;
|
|
@@ -216,8 +228,22 @@ export class Canvas {
|
|
|
216
228
|
window.addEventListener("blur", this.onWindowInactive);
|
|
217
229
|
window.addEventListener("focus", this.onWindowActive);
|
|
218
230
|
this.Hover.RootAt = (x, y) => this.popupLayer?.At(x, y) ?? this.content;
|
|
219
|
-
this.observer = new ResizeObserver(() =>
|
|
220
|
-
|
|
231
|
+
this.observer = new ResizeObserver((entries) => {
|
|
232
|
+
const entry = entries[entries.length - 1];
|
|
233
|
+
const box = entry?.devicePixelContentBoxSize?.[0];
|
|
234
|
+
if (box) {
|
|
235
|
+
this.devicePixels = [box.inlineSize, box.blockSize];
|
|
236
|
+
this.devicePixelsCss = entry.contentBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;
|
|
237
|
+
}
|
|
238
|
+
this.OnResized();
|
|
239
|
+
});
|
|
240
|
+
// browsers without the device-pixel box (Safari) take the rounded size
|
|
241
|
+
try {
|
|
242
|
+
this.observer.observe(Element, { box: "device-pixel-content-box" });
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
this.observer.observe(Element);
|
|
246
|
+
}
|
|
221
247
|
this.OnResized();
|
|
222
248
|
}
|
|
223
249
|
/** Request a redraw (full measure + arrange + render) on the next animation frame. */
|
|
@@ -249,7 +275,7 @@ export class Canvas {
|
|
|
249
275
|
const CK = Super.CK;
|
|
250
276
|
if (this.RenderingMode === "Accelerated") {
|
|
251
277
|
if (!this.grContext) {
|
|
252
|
-
this.glHandle = CK.GetWebGLContext(this.Element);
|
|
278
|
+
this.glHandle = Canvas.WithoutPolygonMode(() => CK.GetWebGLContext(this.Element));
|
|
253
279
|
this.grContext = (this.glHandle ? CK.MakeWebGLContext(this.glHandle) : null) ?? undefined;
|
|
254
280
|
}
|
|
255
281
|
if (this.grContext) {
|
|
@@ -266,9 +292,16 @@ export class Canvas {
|
|
|
266
292
|
* redrawn content lands in the same paint and no blank frame is ever shown while dragging.
|
|
267
293
|
*/
|
|
268
294
|
OnResized() {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
295
|
+
let dpr = window.devicePixelRatio || 1;
|
|
296
|
+
// the device-pixel box can disagree with devicePixelRatio (DPR emulation in DevTools or Playwright, some zoom cases):
|
|
297
|
+
// past 2% the scale follows the box, so the layout keeps the element's CSS size (DrawnUi.Rust e7ff239)
|
|
298
|
+
if (this.devicePixels && this.devicePixelsCss > 0) {
|
|
299
|
+
const boxScale = this.devicePixels[0] / this.devicePixelsCss;
|
|
300
|
+
if (Math.abs(boxScale - dpr) > dpr * 0.02)
|
|
301
|
+
dpr = boxScale;
|
|
302
|
+
}
|
|
303
|
+
const w = Math.max(1, this.devicePixels?.[0] ?? Math.round(this.Element.clientWidth * dpr));
|
|
304
|
+
const h = Math.max(1, this.devicePixels?.[1] ?? Math.round(this.Element.clientHeight * dpr));
|
|
272
305
|
if (this.surface && this.Element.width === w && this.Element.height === h && this.RenderingScale === dpr)
|
|
273
306
|
return;
|
|
274
307
|
this.RenderingScale = dpr;
|
|
@@ -282,7 +315,31 @@ export class Canvas {
|
|
|
282
315
|
throw new Error("DrawnUi: cannot create surface");
|
|
283
316
|
this.DrawNow();
|
|
284
317
|
}
|
|
285
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* Registers the WebGL context without `WEBGL_polygon_mode` (drawnui-cross 6bt): Emscripten turns on every extension it
|
|
320
|
+
* knows while it registers a context, nothing here draws with that one, and WebKit warns "non-portable extension
|
|
321
|
+
* enabled" for it. The lookup is hidden only for this synchronous call (creating the context here first would change
|
|
322
|
+
* the attributes CanvasKit asks for).
|
|
323
|
+
*/
|
|
324
|
+
static WithoutPolygonMode(make) {
|
|
325
|
+
const prototypes = [globalThis.WebGL2RenderingContext?.prototype, globalThis.WebGLRenderingContext?.prototype]
|
|
326
|
+
.filter((p) => !!p);
|
|
327
|
+
const originals = prototypes.map((p) => p.getExtension);
|
|
328
|
+
prototypes.forEach((p, i) => { p.getExtension = function (name) { return name === "WEBGL_polygon_mode" ? null : originals[i].call(this, name); }; });
|
|
329
|
+
try {
|
|
330
|
+
return make();
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
prototypes.forEach((p, i) => { p.getExtension = originals[i]; });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* WebGL context lost: keep the browser restoring it (preventDefault) and stop the frames. The old Skia context is
|
|
338
|
+
* abandoned here, while the context is lost: WebGL ignores every call on a lost context without a word, so the GL
|
|
339
|
+
* deletes Skia makes while it lets go of its objects stay silent (done after the restore, they reach the new
|
|
340
|
+
* generation and every one logs "object does not belong to this context"). CanvasKit has no `abandonContext`;
|
|
341
|
+
* `releaseResourcesAndAbandonContext` is its only way, and after it freeing an old image or surface makes no GL call.
|
|
342
|
+
*/
|
|
286
343
|
onContextLost = (e) => {
|
|
287
344
|
e.preventDefault();
|
|
288
345
|
this.contextLost = true;
|
|
@@ -290,20 +347,24 @@ export class Canvas {
|
|
|
290
347
|
cancelAnimationFrame(this.frameId);
|
|
291
348
|
this.frameId = 0;
|
|
292
349
|
}
|
|
350
|
+
if (this.grContext)
|
|
351
|
+
this.grContext.releaseResourcesAndAbandonContext();
|
|
352
|
+
this.surface?.dispose();
|
|
353
|
+
this.surface = undefined;
|
|
354
|
+
this.grContext?.delete();
|
|
355
|
+
this.grContext = undefined;
|
|
293
356
|
};
|
|
294
357
|
/**
|
|
295
358
|
* WebGL context restored (as DrawnUi.Rust and the C# Wasm / Blazor heads): every GL object of the lost generation is
|
|
296
|
-
* gone
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* GL call. Then the same WebGL object is registered again (the old handle deleted first, which clears the canvas'
|
|
300
|
-
* context object) with a new GrContext and surface; GpuEpoch makes the old generation's GPU objects remake themselves.
|
|
359
|
+
* gone, and the old Skia context was abandoned when it was lost. The same WebGL object is registered again (the old
|
|
360
|
+
* handle deleted first, which clears the canvas' context object) with a new GrContext and surface; GpuEpoch makes the
|
|
361
|
+
* old generation's GPU objects remake themselves.
|
|
301
362
|
*/
|
|
302
363
|
onContextRestored = () => {
|
|
303
364
|
if (this.disposed)
|
|
304
365
|
return;
|
|
305
366
|
if (this.grContext)
|
|
306
|
-
this.grContext.releaseResourcesAndAbandonContext();
|
|
367
|
+
this.grContext.releaseResourcesAndAbandonContext(); // lost before this Canvas listened
|
|
307
368
|
this.surface?.dispose();
|
|
308
369
|
this.surface = undefined;
|
|
309
370
|
this.grContext?.delete();
|
|
@@ -313,7 +374,7 @@ export class Canvas {
|
|
|
313
374
|
this.glHandle = undefined;
|
|
314
375
|
}
|
|
315
376
|
this.contextLost = false;
|
|
316
|
-
this.GpuEpoch
|
|
377
|
+
this.GpuEpoch = Canvas.NextGpuEpoch();
|
|
317
378
|
this.surface = this.CreateSurface(this.Element.width, this.Element.height);
|
|
318
379
|
this.DrawNow();
|
|
319
380
|
};
|
|
@@ -564,7 +625,12 @@ export class Canvas {
|
|
|
564
625
|
this.observer.disconnect();
|
|
565
626
|
this.content?.Dispose();
|
|
566
627
|
this.Content = undefined;
|
|
628
|
+
this.DrainDisposeQueue(); // what the last frames handed over for deletion goes while the context lives
|
|
567
629
|
this.ReleaseSurface();
|
|
630
|
+
// GPU objects that outlive this canvas (a control the app keeps and shows on another canvas) are freed later, under
|
|
631
|
+
// another WebGL context: the abandoned Skia context makes no GL call when they go (as DrawnUi.Net Cells 81b89f1a)
|
|
632
|
+
if (this.grContext && !this.contextLost)
|
|
633
|
+
this.grContext.releaseResourcesAndAbandonContext();
|
|
568
634
|
this.grContext?.delete();
|
|
569
635
|
this.grContext = undefined;
|
|
570
636
|
if (this.glHandle) {
|
|
@@ -746,7 +812,8 @@ export class Canvas {
|
|
|
746
812
|
// horizontal events alone (C# ba03cb20)
|
|
747
813
|
const factor = e.deltaMode === 1 ? 40 : e.deltaMode === 2 ? 800 : 1;
|
|
748
814
|
const horizontal = Math.abs(e.deltaX) > Math.abs(e.deltaY);
|
|
749
|
-
|
|
815
|
+
// IsZoom: Ctrl / Cmd + wheel, or a touchpad pinch (browsers send it as a Ctrl wheel), as AppoMobi WheelEventArgs.IsZoom
|
|
816
|
+
args.Wheel = { Delta: (horizontal ? e.deltaX : e.deltaY) * factor, IsHorizontal: horizontal, IsZoom: e.ctrlKey || e.metaKey };
|
|
750
817
|
this.tooltip.CloseOnInput();
|
|
751
818
|
if (this.gestures === "Lock") {
|
|
752
819
|
e.preventDefault();
|
package/dist/core/Gestures.d.ts
CHANGED
|
@@ -126,6 +126,7 @@ export declare class TouchActionEventArgs {
|
|
|
126
126
|
Wheel: {
|
|
127
127
|
Delta: number;
|
|
128
128
|
IsHorizontal?: boolean;
|
|
129
|
+
IsZoom?: boolean;
|
|
129
130
|
};
|
|
130
131
|
/**
|
|
131
132
|
* AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A declared set of property values: names as the C# properties (the JSX props of a control). */
|
|
2
|
+
export type ControlProps = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Assigns the changed values of `next` straight onto the control (same names as the C# properties), as the React
|
|
5
|
+
* renderer does with JSX props; a value `prev` had and `next` lacks goes back to the control's default. Handler values
|
|
6
|
+
* (functions) are swapped without invalidating. Then the control is invalidated as little as the change needs: a size
|
|
7
|
+
* change re-measures, a look change redraws, a transform change only repaints the composition.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ApplyProps(inst: {
|
|
10
|
+
Update(): void;
|
|
11
|
+
}, prev: ControlProps | null, next: ControlProps): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SkiaControl } from "./SkiaControl";
|
|
2
|
+
/** Not properties of the control: React's own keys. */
|
|
3
|
+
const SKIP = new Set(["children", "key", "ref"]);
|
|
4
|
+
/** Props that change how the subtree is composited, not what it contains: repaint, keep caches (DrawnUi RedrawCanvas). */
|
|
5
|
+
const REPAINT_ONLY = new Set(["TranslationX", "TranslationY", "TranslationZ", "Rotation", "RotationX", "RotationY", "RotationZ", "ScaleX", "ScaleY", "Scale", "SkewX", "SkewY", "AnchorX", "AnchorY", "Opacity"]);
|
|
6
|
+
/** Props that change only how a control looks, never its size (C# NeedDraw): an ImageComposite above redraws only its area. */
|
|
7
|
+
const isDrawOnly = (k) => k.endsWith("Color") || k === "FillGradient" || k === "StrokeGradient";
|
|
8
|
+
/**
|
|
9
|
+
* Assigns the changed values of `next` straight onto the control (same names as the C# properties), as the React
|
|
10
|
+
* renderer does with JSX props; a value `prev` had and `next` lacks goes back to the control's default. Handler values
|
|
11
|
+
* (functions) are swapped without invalidating. Then the control is invalidated as little as the change needs: a size
|
|
12
|
+
* change re-measures, a look change redraws, a transform change only repaints the composition.
|
|
13
|
+
*/
|
|
14
|
+
export function ApplyProps(inst, prev, next) {
|
|
15
|
+
let changed = false, repaint = false, layout = false;
|
|
16
|
+
for (const k in next) {
|
|
17
|
+
if (SKIP.has(k) || (prev && prev[k] === next[k]))
|
|
18
|
+
continue;
|
|
19
|
+
inst[k] = next[k];
|
|
20
|
+
if (typeof next[k] === "function")
|
|
21
|
+
continue;
|
|
22
|
+
if (REPAINT_ONLY.has(k))
|
|
23
|
+
repaint = true;
|
|
24
|
+
else {
|
|
25
|
+
changed = true;
|
|
26
|
+
if (!isDrawOnly(k))
|
|
27
|
+
layout = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (prev)
|
|
31
|
+
for (const k in prev)
|
|
32
|
+
if (!SKIP.has(k) && !(k in next)) {
|
|
33
|
+
inst[k] = new inst.constructor()[k];
|
|
34
|
+
changed = layout = true;
|
|
35
|
+
}
|
|
36
|
+
if (changed && prev) {
|
|
37
|
+
if (layout || !(inst instanceof SkiaControl))
|
|
38
|
+
inst.Update();
|
|
39
|
+
else
|
|
40
|
+
inst.UpdateDraw();
|
|
41
|
+
}
|
|
42
|
+
else if (repaint && prev)
|
|
43
|
+
inst.RepaintComposition?.();
|
|
44
|
+
}
|
|
@@ -215,6 +215,12 @@ export declare class SkiaControl {
|
|
|
215
215
|
private OutsideClip;
|
|
216
216
|
/** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
|
|
217
217
|
GetTransformedDirtyBounds(): SKRect;
|
|
218
|
+
/**
|
|
219
|
+
* Where the control will be drawn next, from its current transform values: a translation set since the last render is
|
|
220
|
+
* already in (a composite parent erases and clips to this area before the child renders again).
|
|
221
|
+
*/
|
|
222
|
+
GetCurrentDirtyBounds(): SKRect;
|
|
223
|
+
private MapBounds;
|
|
218
224
|
/** Current cache, if any. */
|
|
219
225
|
RenderObject?: CachedObject;
|
|
220
226
|
private cacheDirty;
|
|
@@ -318,6 +324,12 @@ export declare class SkiaControl {
|
|
|
318
324
|
* `Children` list drops only these, so a control's own parts keep their place.
|
|
319
325
|
*/
|
|
320
326
|
IsChildrenItem: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* C# UpdateNonStop (fluent): keeps frames coming while this control is on a canvas, for visuals that change by
|
|
329
|
+
* themselves (a time-driven shader, a clock drawn in code). An endless no-op animator, as C#; it waits for the canvas
|
|
330
|
+
* when the control is not on one yet and stops when the control is disposed. It holds the canvas at full frame rate.
|
|
331
|
+
*/
|
|
332
|
+
UpdateNonStop(): this;
|
|
321
333
|
AddSubView(_control: SkiaControl): void;
|
|
322
334
|
InsertSubView(_index: number, control: SkiaControl): void;
|
|
323
335
|
RemoveSubView(_control: SkiaControl): void;
|
|
@@ -489,6 +501,11 @@ export declare class SkiaControl {
|
|
|
489
501
|
protected static SmartMax(a: number, b: number): number;
|
|
490
502
|
/** DrawnUi SmartMin: smaller of two sizes, an infinite one loses. */
|
|
491
503
|
protected static SmartMin(a: number, b: number): number;
|
|
504
|
+
/**
|
|
505
|
+
* Center (as DrawnUI for Rust and .NET): the box centered in the whole space, then moved by the full margin difference
|
|
506
|
+
* (start minus end), kept inside the space when it fits.
|
|
507
|
+
*/
|
|
508
|
+
private static Centered;
|
|
492
509
|
private static Align;
|
|
493
510
|
/** Called after DrawingRect changed; layouts arrange children here. */
|
|
494
511
|
protected OnLayoutChanged(): void;
|
|
@@ -642,10 +659,12 @@ export declare class SkiaControl {
|
|
|
642
659
|
private static DeepArea;
|
|
643
660
|
/**
|
|
644
661
|
* DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
|
|
645
|
-
* stops here (ancestors composite again, nothing above re-measures).
|
|
646
|
-
* NeedMeasure
|
|
662
|
+
* stops here (ancestors composite again, nothing above re-measures). It measures itself again in its last slot when it
|
|
663
|
+
* draws with NeedMeasure set. Used by SkiaScroll for its scroll bars and by SkiaLabelFps.
|
|
647
664
|
*/
|
|
648
665
|
IsParentIndependent: boolean;
|
|
666
|
+
/** The slot its parent last arranged it in (a parent-independent control measures itself again there). */
|
|
667
|
+
private arrangedIn?;
|
|
649
668
|
/** Size or content may have changed: this control and all ancestors remeasure and re-record. */
|
|
650
669
|
InvalidateMeasure(): void;
|
|
651
670
|
/** Hit rect in pixels (no transforms in this port, so it is DrawingRect). */
|