drawnui-react 0.1.0-preview.40 → 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 +57 -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 +50 -8
- package/dist/core/Canvas.js +126 -25
- package/dist/core/DesignerActions.d.ts +32 -0
- package/dist/core/DesignerActions.js +68 -0
- 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 +26 -3
- package/dist/core/SkiaControl.js +64 -13
- 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 +2 -0
- package/dist/index.js +2 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -514
- package/dist/react/index.d.ts +24 -1
- package/dist/react/index.js +32 -5
- package/dist/react/reconciler.d.ts +12 -0
- package/dist/react/reconciler.js +22 -46
- package/package.json +24 -2
|
@@ -1,70 +1,306 @@
|
|
|
1
1
|
import { Super } from "./Super";
|
|
2
2
|
const PRIORITY_RANK = { High: 0, Normal: 1, Low: 2 };
|
|
3
3
|
/**
|
|
4
|
-
* Mirrors DrawnUi SkiaImageManager: loads
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Mirrors DrawnUi SkiaImageManager (DrawnUi.Net): loads and decodes image sources, keeps the decoded images in a cache
|
|
5
|
+
* by source for `CacheLongevitySecs`, and shares one decoded image between every control on the same source
|
|
6
|
+
* (`ReuseBitmaps`; off, each caller gets a copy of its own of the one cached copy). `LoadImageManagedAsync` caches and
|
|
7
|
+
* goes through the priority queue (High > Normal > Low, at most `MaxParallelLoads` fetches in flight; the same source
|
|
8
|
+
* requested twice is fetched once); `LoadImageAsync` is a direct load that does not touch the cache. The cache keeps
|
|
9
|
+
* at most `CacheBudgetMb` megabytes of decoded pixels: over it, images no control holds go, the one held longest ago first
|
|
10
|
+
* (as DrawnUI for Rust's image cache); images a control holds never go. Keys are case-insensitive and local paths
|
|
11
|
+
* normalized (backslashes, a leading slash). Sources are URLs (absolute, or relative to the page like
|
|
12
|
+
* "images/photo.jpg").
|
|
13
|
+
*
|
|
14
|
+
* Ownership: CanvasKit images must be deleted by hand. The manager deletes an image it made once no holder draws it
|
|
15
|
+
* and the cache no longer keeps it; a control holds the image it shows (`Hold`) and lets it go (`Free`). Removing an
|
|
16
|
+
* entry from the cache (`RemoveFromCache`, `ClearCache`, expiry, the budget) never deletes an image a control holds.
|
|
9
17
|
*/
|
|
10
18
|
export class SkiaImageManager {
|
|
11
19
|
static Instance = new SkiaImageManager();
|
|
12
|
-
/**
|
|
20
|
+
/** Share one decoded image between every control on the same source (DrawnUi ReuseBitmaps, on by default). */
|
|
13
21
|
static ReuseBitmaps = true;
|
|
22
|
+
/** Use the cache at all (DrawnUi UseCache): off, every load fetches and decodes again. */
|
|
23
|
+
static UseCache = true;
|
|
24
|
+
/** Seconds a cached image is kept before the next load fetches it again (DrawnUi, 30 minutes). */
|
|
25
|
+
static CacheLongevitySecs = 1800;
|
|
26
|
+
/**
|
|
27
|
+
* Most megabytes of decoded pixels the cache keeps (DrawnUi CacheBudgetMb, 128 as DrawnUI for Rust; 0 or less = no
|
|
28
|
+
* limit). Images a control holds never go for it.
|
|
29
|
+
*/
|
|
30
|
+
static CacheBudgetMb = 128;
|
|
14
31
|
/** Fetches in flight at once through the managed queue (C# CreateSemaphoreForLocalFiles: 5). */
|
|
15
32
|
static MaxParallelLoads = 5;
|
|
16
|
-
/**
|
|
33
|
+
/** Retry a failed load (DrawnUi EnableHttpRetry): up to HttpRetryMaxAttempts more times, 100, 200, 400 ms apart. */
|
|
34
|
+
static EnableHttpRetry = true;
|
|
35
|
+
static HttpRetryMaxAttempts = 3;
|
|
36
|
+
/** Base address of relative sources (DrawnUi HttpBaseAddress); unset, they resolve against the page. */
|
|
37
|
+
static HttpBaseAddress;
|
|
38
|
+
/**
|
|
39
|
+
* C# CanReload: raised when a load failed (with its source and why) so the caller may retry later, and when
|
|
40
|
+
* `IsLoadingLocked` is turned off (no arguments).
|
|
41
|
+
*/
|
|
17
42
|
CanReload;
|
|
18
43
|
cache = new Map();
|
|
19
|
-
|
|
44
|
+
/** Every image the manager made and still tracks: cached ones and the copies it handed out. */
|
|
45
|
+
owned = new Map();
|
|
46
|
+
inflight = new Map();
|
|
20
47
|
queue = [];
|
|
21
48
|
waiting = new Map();
|
|
49
|
+
registered = new Map();
|
|
22
50
|
running = 0;
|
|
51
|
+
used = 0;
|
|
52
|
+
tick = 0;
|
|
53
|
+
locked = false;
|
|
54
|
+
unlocked = Promise.resolve();
|
|
55
|
+
unlock;
|
|
23
56
|
/** Queue diagnostics. */
|
|
24
57
|
get QueuedCount() { return this.queue.length; }
|
|
25
58
|
get RunningCount() { return this.running; }
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
/** Megabytes of decoded pixels the cache holds now (DrawnUi CacheMemoryMb). */
|
|
60
|
+
get CacheMemoryMb() { return this.used / (1 << 20); }
|
|
61
|
+
/** The browser says it has no network. */
|
|
62
|
+
get IsOffline() { return typeof navigator !== "undefined" && navigator.onLine === false; }
|
|
63
|
+
/** While true, managed loads wait (DrawnUi IsLoadingLocked); turning it off lets them go and raises CanReload. */
|
|
64
|
+
get IsLoadingLocked() { return this.locked; }
|
|
65
|
+
set IsLoadingLocked(value) {
|
|
66
|
+
if (this.locked === value)
|
|
67
|
+
return;
|
|
68
|
+
this.locked = value;
|
|
69
|
+
if (value)
|
|
70
|
+
this.unlocked = new Promise((r) => { this.unlock = r; });
|
|
71
|
+
else {
|
|
72
|
+
this.unlock?.();
|
|
73
|
+
this.unlock = undefined;
|
|
74
|
+
this.CanReload?.();
|
|
75
|
+
}
|
|
40
76
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!
|
|
44
|
-
throw new Error(
|
|
45
|
-
|
|
77
|
+
/** Registers a source under a name of its own (DrawnUi RegisterImage): loading `alias` loads `source`. */
|
|
78
|
+
RegisterImage(alias, source) {
|
|
79
|
+
if (!alias)
|
|
80
|
+
throw new Error("Image source URL cannot be empty.");
|
|
81
|
+
this.registered.set(SkiaImageManager.Key(alias), source ?? alias);
|
|
82
|
+
}
|
|
83
|
+
/** Cache key: case-insensitive, a local path with forward slashes and no leading slash (DrawnUi GetCacheKey). */
|
|
84
|
+
static Key(source) {
|
|
85
|
+
if (!source || source.includes("://"))
|
|
86
|
+
return source.toLowerCase();
|
|
87
|
+
let key = source.replace(/\\/g, "/");
|
|
88
|
+
if (key.startsWith("/") && !key.startsWith("//"))
|
|
89
|
+
key = key.replace(/^\/+/, "");
|
|
90
|
+
return key.toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
// ---- holders ----
|
|
93
|
+
/** A holder (a control) draws this image now: it is not deleted until let go. Images the manager did not make are ignored. */
|
|
94
|
+
Hold(image) {
|
|
95
|
+
const entry = image && this.owned.get(image);
|
|
96
|
+
if (entry) {
|
|
97
|
+
entry.Holders++;
|
|
98
|
+
entry.Shown = ++this.tick;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** The holder no longer draws it: an image no holder draws and the cache does not keep is deleted. */
|
|
102
|
+
Free(image) {
|
|
103
|
+
const entry = image && this.owned.get(image);
|
|
104
|
+
if (!entry)
|
|
105
|
+
return;
|
|
106
|
+
entry.Holders = Math.max(0, entry.Holders - 1);
|
|
107
|
+
entry.Shown = ++this.tick;
|
|
108
|
+
this.Forget(entry);
|
|
109
|
+
}
|
|
110
|
+
/** Deletes an image nobody keeps any more. */
|
|
111
|
+
Forget(entry) {
|
|
112
|
+
if (entry.Holders > 0 || entry.Cached)
|
|
113
|
+
return;
|
|
114
|
+
this.owned.delete(entry.Image);
|
|
115
|
+
if (!entry.Image.isDeleted())
|
|
116
|
+
entry.Image.delete();
|
|
117
|
+
}
|
|
118
|
+
Track(image, key) {
|
|
119
|
+
let entry = this.owned.get(image);
|
|
120
|
+
if (!entry) {
|
|
121
|
+
entry = { Image: image, Key: key, Bytes: image.width() * image.height() * 4, Cached: false, Expires: 0, Shown: ++this.tick, Holders: 0 };
|
|
122
|
+
this.owned.set(image, entry);
|
|
123
|
+
}
|
|
124
|
+
return entry;
|
|
125
|
+
}
|
|
126
|
+
/** A copy of an image of its own (ReuseBitmaps off), tracked so its holder frees it. */
|
|
127
|
+
Copy(image, key) {
|
|
128
|
+
const CK = Super.CK;
|
|
129
|
+
const info = { width: image.width(), height: image.height(), colorType: CK.ColorType.RGBA_8888, alphaType: CK.AlphaType.Premul, colorSpace: CK.ColorSpace.SRGB };
|
|
130
|
+
const pixels = image.readPixels(0, 0, info);
|
|
131
|
+
const copy = pixels instanceof Uint8Array ? CK.MakeImage(info, pixels, info.width * 4) : null;
|
|
132
|
+
if (!copy)
|
|
133
|
+
return undefined;
|
|
134
|
+
this.Track(copy, key);
|
|
135
|
+
return copy;
|
|
136
|
+
}
|
|
137
|
+
/** What a caller gets of a cached image: the shared one, or a copy of its own (ReuseBitmaps off). */
|
|
138
|
+
HandOut(image, key) {
|
|
46
139
|
if (!image)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
140
|
+
return undefined;
|
|
141
|
+
return SkiaImageManager.ReuseBitmaps ? image : this.Copy(image, key);
|
|
142
|
+
}
|
|
143
|
+
// ---- the cache ----
|
|
144
|
+
/** Puts an image in the cache for `cacheLongevitySecs` (DrawnUi AddToCache); false when cached already or caching is off. */
|
|
145
|
+
AddToCache(uri, image, cacheLongevitySecs = SkiaImageManager.CacheLongevitySecs) {
|
|
146
|
+
if (!SkiaImageManager.UseCache || !uri || !image)
|
|
147
|
+
return false;
|
|
148
|
+
const key = SkiaImageManager.Key(uri);
|
|
149
|
+
this.CleanupExpired(key);
|
|
150
|
+
if (this.cache.has(key))
|
|
151
|
+
return false;
|
|
152
|
+
const entry = this.Track(image, key);
|
|
153
|
+
entry.Cached = true;
|
|
154
|
+
entry.Expires = performance.now() + cacheLongevitySecs * 1000;
|
|
155
|
+
entry.Shown = ++this.tick;
|
|
156
|
+
this.cache.set(key, entry);
|
|
157
|
+
this.used += entry.Bytes;
|
|
158
|
+
this.Trim();
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
/** Replaces the cached image of a source (DrawnUi UpdateInCache, minutes as .NET). */
|
|
162
|
+
UpdateInCache(uri, image, cacheLongevityMinutes) {
|
|
163
|
+
this.RemoveFromCache(uri);
|
|
164
|
+
this.AddToCache(uri, image, cacheLongevityMinutes * 60);
|
|
165
|
+
}
|
|
166
|
+
/** Drops the image from the cache, so the next load reads it again (DrawnUi RemoveFromCache); false when it was not cached. */
|
|
167
|
+
RemoveFromCache(uri) {
|
|
168
|
+
if (!uri)
|
|
169
|
+
return false;
|
|
170
|
+
const entry = this.cache.get(SkiaImageManager.Key(uri));
|
|
171
|
+
if (!entry)
|
|
172
|
+
return false;
|
|
173
|
+
this.Drop(entry);
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
/** Drops every cached image; images controls still show stay until they let them go. */
|
|
177
|
+
ClearCache() { for (const entry of [...this.cache.values()])
|
|
178
|
+
this.Drop(entry); }
|
|
179
|
+
/** RemoveFromCache(source) or ClearCache(). */
|
|
180
|
+
Clear(source) { if (source)
|
|
181
|
+
this.RemoveFromCache(source);
|
|
182
|
+
else
|
|
183
|
+
this.ClearCache(); }
|
|
184
|
+
Drop(entry) {
|
|
185
|
+
if (!entry.Cached)
|
|
186
|
+
return;
|
|
187
|
+
this.cache.delete(entry.Key);
|
|
188
|
+
this.used -= entry.Bytes;
|
|
189
|
+
entry.Cached = false;
|
|
190
|
+
this.Forget(entry);
|
|
191
|
+
}
|
|
192
|
+
CleanupExpired(key) {
|
|
193
|
+
const entry = this.cache.get(key);
|
|
194
|
+
if (entry && entry.Expires <= performance.now())
|
|
195
|
+
this.Drop(entry);
|
|
196
|
+
}
|
|
197
|
+
/** Over the budget: the cached images no holder draws go, the one held longest ago first (DrawnUI for Rust trim). */
|
|
198
|
+
Trim() {
|
|
199
|
+
const budget = SkiaImageManager.CacheBudgetMb * (1 << 20);
|
|
200
|
+
if (SkiaImageManager.CacheBudgetMb <= 0 || this.used <= budget)
|
|
201
|
+
return;
|
|
202
|
+
const idle = [...this.cache.values()].filter((e) => e.Holders === 0).sort((a, b) => a.Shown - b.Shown);
|
|
203
|
+
for (const entry of idle) {
|
|
204
|
+
if (this.used <= budget)
|
|
205
|
+
break;
|
|
206
|
+
this.Drop(entry);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** The cached image of a source, or undefined (DrawnUi GetFromCache): the shared one, or a copy (ReuseBitmaps off). */
|
|
210
|
+
GetFromCache(url) {
|
|
211
|
+
return this.HandOut(this.GetFromCacheInternal(url), SkiaImageManager.Key(url));
|
|
212
|
+
}
|
|
213
|
+
/** The cached image itself, whatever ReuseBitmaps says (DrawnUi GetFromCacheInternal). */
|
|
214
|
+
GetFromCacheInternal(url) {
|
|
215
|
+
if (!SkiaImageManager.UseCache || !url)
|
|
216
|
+
return undefined;
|
|
217
|
+
const key = SkiaImageManager.Key(url);
|
|
218
|
+
this.CleanupExpired(key);
|
|
219
|
+
const entry = this.cache.get(key);
|
|
220
|
+
if (!entry)
|
|
221
|
+
return undefined;
|
|
222
|
+
entry.Shown = ++this.tick;
|
|
223
|
+
return entry.Image;
|
|
224
|
+
}
|
|
225
|
+
// ---- loading ----
|
|
226
|
+
/** The address a source is fetched from: its registered file, against HttpBaseAddress, stamped (Super.ResolveAssetUrl). */
|
|
227
|
+
Address(source) {
|
|
228
|
+
const file = this.registered.get(SkiaImageManager.Key(source)) ?? source;
|
|
229
|
+
const base = SkiaImageManager.HttpBaseAddress;
|
|
230
|
+
return Super.ResolveAssetUrl(base && !file.includes("://") ? new URL(file, base).href : file);
|
|
231
|
+
}
|
|
232
|
+
/** Fetches and decodes a source, retried when it fails (EnableHttpRetry); undefined when it could not be loaded. */
|
|
233
|
+
async Fetch(source, signal) {
|
|
234
|
+
const attempts = SkiaImageManager.EnableHttpRetry ? SkiaImageManager.HttpRetryMaxAttempts : 0;
|
|
235
|
+
let error;
|
|
236
|
+
for (let attempt = 0; attempt <= attempts; attempt++) {
|
|
237
|
+
if (signal?.aborted)
|
|
238
|
+
return { Error: new Error("DrawnUi: image load cancelled") };
|
|
239
|
+
try {
|
|
240
|
+
const response = await fetch(this.Address(source), signal ? { signal } : undefined);
|
|
241
|
+
if (!response.ok)
|
|
242
|
+
error = new Error(`DrawnUi: ${response.status} loading image '${source}'`);
|
|
243
|
+
else {
|
|
244
|
+
const image = Super.CK.MakeImageFromEncoded(await response.arrayBuffer());
|
|
245
|
+
if (image)
|
|
246
|
+
return { Image: image };
|
|
247
|
+
error = new Error(`DrawnUi: cannot decode image '${source}'`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
if (signal?.aborted)
|
|
252
|
+
return { Error: new Error("DrawnUi: image load cancelled") };
|
|
253
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
254
|
+
}
|
|
255
|
+
if (attempt < attempts)
|
|
256
|
+
await new Promise((r) => setTimeout(r, 2 ** attempt * 100));
|
|
257
|
+
}
|
|
258
|
+
return { Error: error };
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Direct load without the queue and the cache (C# LoadImageAsync): a new image the caller owns (delete it, or hand it
|
|
262
|
+
* to a control that holds it); undefined when it could not be loaded.
|
|
263
|
+
*/
|
|
264
|
+
async LoadImageAsync(source, signal) {
|
|
265
|
+
const { Image: image } = await this.Fetch(source, signal);
|
|
266
|
+
if (image)
|
|
267
|
+
this.Track(image, SkiaImageManager.Key(source));
|
|
50
268
|
return image;
|
|
51
269
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Queued, cached load (C# LoadImageManagedAsync): a cached image resolves at once, the rest wait their turn by priority;
|
|
272
|
+
* one fetch serves every request of the same source. Resolves to the shared image (ReuseBitmaps) or a copy of its own,
|
|
273
|
+
* undefined when it could not be loaded (CanReload hears why).
|
|
274
|
+
*/
|
|
275
|
+
async LoadImageManagedAsync(source, signal, priority = "Normal") {
|
|
276
|
+
if (!source)
|
|
277
|
+
return undefined;
|
|
278
|
+
while (this.locked)
|
|
279
|
+
await this.unlocked;
|
|
280
|
+
const key = SkiaImageManager.Key(source);
|
|
281
|
+
if (!SkiaImageManager.UseCache)
|
|
282
|
+
return this.Enqueue(key, source, priority, signal, false);
|
|
283
|
+
const cached = this.GetFromCacheInternal(key);
|
|
55
284
|
if (cached)
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
285
|
+
return this.HandOut(cached, key);
|
|
286
|
+
let task = this.inflight.get(key);
|
|
287
|
+
if (!task) {
|
|
288
|
+
task = this.Enqueue(key, source, priority, signal, true);
|
|
289
|
+
this.inflight.set(key, task);
|
|
290
|
+
void task.finally(() => this.inflight.delete(key));
|
|
291
|
+
}
|
|
292
|
+
return this.HandOut(await task, key);
|
|
293
|
+
}
|
|
294
|
+
Enqueue(key, source, priority, signal, cache) {
|
|
295
|
+
return new Promise((resolve) => {
|
|
296
|
+
const item = { key, source, priority, signal, resolve: cache ? (image) => resolve(image && this.Cached(key, image)) : resolve };
|
|
297
|
+
const same = cache ? this.waiting.get(key) : undefined;
|
|
63
298
|
if (same) {
|
|
64
299
|
same.push(item);
|
|
65
300
|
return;
|
|
66
301
|
} // already queued: one fetch serves every requester
|
|
67
|
-
|
|
302
|
+
if (cache)
|
|
303
|
+
this.waiting.set(key, [item]);
|
|
68
304
|
const rank = PRIORITY_RANK[priority];
|
|
69
305
|
let at = this.queue.length;
|
|
70
306
|
while (at > 0 && PRIORITY_RANK[this.queue[at - 1].priority] > rank)
|
|
@@ -73,50 +309,59 @@ export class SkiaImageManager {
|
|
|
73
309
|
this.Pump();
|
|
74
310
|
});
|
|
75
311
|
}
|
|
312
|
+
/** A fresh image goes into the cache; the cached one (an equal source loaded meanwhile) wins. */
|
|
313
|
+
Cached(key, image) {
|
|
314
|
+
if (this.AddToCache(key, image))
|
|
315
|
+
return image;
|
|
316
|
+
const existing = this.GetFromCacheInternal(key);
|
|
317
|
+
if (existing && existing !== image) {
|
|
318
|
+
this.Forget(this.Track(image, key));
|
|
319
|
+
return existing;
|
|
320
|
+
}
|
|
321
|
+
return image;
|
|
322
|
+
}
|
|
76
323
|
Pump() {
|
|
77
324
|
while (this.running < SkiaImageManager.MaxParallelLoads && this.queue.length > 0) {
|
|
78
325
|
const item = this.queue.shift();
|
|
79
|
-
const requesters = this.waiting.get(item.
|
|
80
|
-
this.waiting.
|
|
326
|
+
const requesters = this.waiting.get(item.key) ?? [item];
|
|
327
|
+
if (this.waiting.get(item.key)?.includes(item))
|
|
328
|
+
this.waiting.delete(item.key);
|
|
81
329
|
if (item.signal?.aborted) {
|
|
82
330
|
for (const r of requesters)
|
|
83
|
-
r.
|
|
331
|
+
r.resolve(undefined);
|
|
84
332
|
continue;
|
|
85
333
|
}
|
|
86
334
|
this.running++;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
335
|
+
void this.Fetch(item.source, item.signal).then(({ Image: image, Error: error }) => {
|
|
336
|
+
if (image)
|
|
337
|
+
this.Track(image, item.key);
|
|
338
|
+
else
|
|
339
|
+
this.CanReload?.(item.source, error);
|
|
340
|
+
// the first requester caches it; the others get what is cached
|
|
341
|
+
for (const r of requesters)
|
|
342
|
+
r.resolve(image);
|
|
343
|
+
}).finally(() => { this.running--; this.Pump(); });
|
|
91
344
|
}
|
|
92
345
|
}
|
|
93
346
|
/** C# PreloadImage: warms the cache for one source; failures are ignored. */
|
|
94
347
|
async PreloadImage(source, priority = "Normal") {
|
|
95
|
-
await this.LoadImageManagedAsync(source, undefined, priority)
|
|
348
|
+
const image = await this.LoadImageManagedAsync(source, undefined, priority);
|
|
349
|
+
// a copy of its own (ReuseBitmaps off, or no cache) nobody will draw
|
|
350
|
+
if (image && this.owned.get(image)?.Cached !== true)
|
|
351
|
+
this.Forget(this.owned.get(image));
|
|
96
352
|
}
|
|
97
353
|
/** Warms the cache so first paint of these images is instant (DrawnUi PreloadImages). Failures are ignored. */
|
|
98
354
|
async PreloadImages(sources, priority = "Normal") {
|
|
99
355
|
await Promise.all(sources.map((s) => this.PreloadImage(s, priority)));
|
|
100
356
|
}
|
|
101
|
-
/** Drops everything still waiting in the queue (C# CancelAll); loads
|
|
357
|
+
/** Drops everything still waiting in the queue (C# CancelAll): those loads resolve to nothing; loads in flight finish. */
|
|
102
358
|
CancelAll() {
|
|
103
359
|
const items = this.queue.splice(0);
|
|
104
360
|
for (const item of items) {
|
|
105
|
-
const requesters = this.waiting.get(item.
|
|
106
|
-
this.waiting.delete(item.
|
|
361
|
+
const requesters = this.waiting.get(item.key) ?? [item];
|
|
362
|
+
this.waiting.delete(item.key);
|
|
107
363
|
for (const r of requesters)
|
|
108
|
-
r.
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/** Drops a cached image (or everything) — decoded images hold GPU/WASM memory. */
|
|
112
|
-
Clear(source) {
|
|
113
|
-
if (source) {
|
|
114
|
-
this.cache.get(source)?.delete();
|
|
115
|
-
this.cache.delete(source);
|
|
116
|
-
return;
|
|
364
|
+
r.resolve(undefined);
|
|
117
365
|
}
|
|
118
|
-
for (const img of this.cache.values())
|
|
119
|
-
img.delete();
|
|
120
|
-
this.cache.clear();
|
|
121
366
|
}
|
|
122
367
|
}
|
package/dist/core/Styles.js
CHANGED
|
@@ -82,9 +82,15 @@ export class SkiaStyles {
|
|
|
82
82
|
const target = control;
|
|
83
83
|
if (atConstruction)
|
|
84
84
|
SkiaStyles.SnapshotDefaults(type, control, keys);
|
|
85
|
+
else if (!SkiaStyles.defaults.has(type)) {
|
|
86
|
+
// a control built in code before any of its class went through the reconciler: the class defaults come from a
|
|
87
|
+
// fresh instance (once per class), so what the code already set still wins
|
|
88
|
+
const fresh = new type();
|
|
89
|
+
SkiaStyles.SnapshotDefaults(type, fresh, keys);
|
|
90
|
+
fresh.Dispose();
|
|
91
|
+
}
|
|
85
92
|
const defaults = atConstruction ? undefined : SkiaStyles.defaults.get(type);
|
|
86
93
|
for (const key of keys) {
|
|
87
|
-
// no snapshot for this class (nothing of it ever went through the reconciler): apply as a plain default
|
|
88
94
|
if (!defaults || Object.is(target[key], defaults[key]))
|
|
89
95
|
target[key] = resolved.Setters[key];
|
|
90
96
|
}
|
package/dist/core/Super.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export declare class Super {
|
|
|
70
70
|
/** Any shaping family (the bidirectional pass needs one, its font does not matter). */
|
|
71
71
|
static AnyShapingFamily(): string | undefined;
|
|
72
72
|
static UseDrawnUi(): DrawnUiBuilder;
|
|
73
|
+
/** C# Super.OpenLink: opens an address in a new browser tab (noopener: the opened page gets no handle on this one). */
|
|
74
|
+
static OpenLink(url: string): void;
|
|
73
75
|
/** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
|
|
74
76
|
static CacheEnabled: boolean;
|
|
75
77
|
/**
|
package/dist/core/Super.js
CHANGED
|
@@ -152,6 +152,8 @@ export class Super {
|
|
|
152
152
|
static AnyShapingFamily() { for (const f of Super.shapingFamilyOfFace.values())
|
|
153
153
|
return f; return undefined; }
|
|
154
154
|
static UseDrawnUi() { return new DrawnUiBuilder(); }
|
|
155
|
+
/** C# Super.OpenLink: opens an address in a new browser tab (noopener: the opened page gets no handle on this one). */
|
|
156
|
+
static OpenLink(url) { window.open(url, "_blank", "noopener"); }
|
|
155
157
|
/** Master switch: false makes every control render uncached (DrawnUi Super.CacheEnabled). */
|
|
156
158
|
static CacheEnabled = true;
|
|
157
159
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from "./controls/RefreshIndicator";
|
|
|
35
35
|
export * from "./core/TextInputProxy";
|
|
36
36
|
export * from "./core/SkiaEffect";
|
|
37
37
|
export * from "./controls/SkiaDrawer";
|
|
38
|
+
export * from "./controls/SkiaShell";
|
|
38
39
|
export * from "./controls/SkiaHotspot";
|
|
39
40
|
export * from "./controls/SkiaShape";
|
|
40
41
|
export * from "./controls/SkiaButton";
|
|
@@ -53,3 +54,4 @@ export * from "./controls/SkiaGif";
|
|
|
53
54
|
export * from "./controls/SkiaScroll";
|
|
54
55
|
export * from "./controls/SkiaDynamicDrawnCell";
|
|
55
56
|
export * from "./core/ViewsAdapter";
|
|
57
|
+
export * from "./core/DesignerActions";
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export * from "./controls/RefreshIndicator";
|
|
|
35
35
|
export * from "./core/TextInputProxy";
|
|
36
36
|
export * from "./core/SkiaEffect";
|
|
37
37
|
export * from "./controls/SkiaDrawer";
|
|
38
|
+
export * from "./controls/SkiaShell";
|
|
38
39
|
export * from "./controls/SkiaHotspot";
|
|
39
40
|
export * from "./controls/SkiaShape";
|
|
40
41
|
export * from "./controls/SkiaButton";
|
|
@@ -53,3 +54,4 @@ export * from "./controls/SkiaGif";
|
|
|
53
54
|
export * from "./controls/SkiaScroll";
|
|
54
55
|
export * from "./controls/SkiaDynamicDrawnCell";
|
|
55
56
|
export * from "./core/ViewsAdapter";
|
|
57
|
+
export * from "./core/DesignerActions";
|
|
@@ -1,55 +1,9 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import { Thickness } from "../core/Types";
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export type ShellArguments = Record<string, unknown>;
|
|
2
|
+
import type { Thickness } from "../core/Types";
|
|
3
|
+
import { type ModalOptions, type PopupOptions, type ShellArguments, type ShellTab, type SkiaShellNavigatedArgs, type SkiaShellNavigatingArgs } from "../controls/SkiaShell";
|
|
4
|
+
export { BuildRoute, ShellDefaults, SplitRoute, type ModalOptions, type NavigationSource, type PopupOptions, type ShellArguments, type ShellTab, type SkiaShellNavigatedArgs, type SkiaShellNavigatingArgs } from "../controls/SkiaShell";
|
|
6
5
|
/** Route name -> page factory receiving the navigation arguments. Pages are plain JSX, rendered inside the shell when navigated to. */
|
|
7
6
|
export type ShellRoutes = Record<string, (args: ShellArguments) => ReactNode>;
|
|
8
|
-
/** C# NavigationSource. */
|
|
9
|
-
export type NavigationSource = "Push" | "Pop";
|
|
10
|
-
/** C# SkiaShellNavigatingArgs: set Cancel to stop the navigation. */
|
|
11
|
-
export interface SkiaShellNavigatingArgs {
|
|
12
|
-
Route: string;
|
|
13
|
-
Source: NavigationSource;
|
|
14
|
-
Cancel: boolean;
|
|
15
|
-
View?: SkiaControl;
|
|
16
|
-
Previous?: SkiaControl;
|
|
17
|
-
}
|
|
18
|
-
/** C# SkiaShellNavigatedArgs. */
|
|
19
|
-
export interface SkiaShellNavigatedArgs {
|
|
20
|
-
Route: string;
|
|
21
|
-
Source: NavigationSource;
|
|
22
|
-
View?: SkiaControl;
|
|
23
|
-
}
|
|
24
|
-
/** "name?a=1&b=2" -> name + arguments (query values are strings). */
|
|
25
|
-
export declare function SplitRoute(route: string): {
|
|
26
|
-
name: string;
|
|
27
|
-
args: ShellArguments;
|
|
28
|
-
};
|
|
29
|
-
/** name + arguments -> "name?a=1" (only string / number / boolean values travel in the route, the rest stays in memory). */
|
|
30
|
-
export declare function BuildRoute(name: string, args?: ShellArguments): string;
|
|
31
|
-
/** C# OpenPopupAsync parameters. */
|
|
32
|
-
export interface PopupOptions {
|
|
33
|
-
animated?: boolean;
|
|
34
|
-
/** A tap outside the content closes the popup (default true). */
|
|
35
|
-
closeWhenBackgroundTapped?: boolean;
|
|
36
|
-
/** Dim + blur the page behind (default true). */
|
|
37
|
-
showOverlay?: boolean;
|
|
38
|
-
backgroundColor?: string;
|
|
39
|
-
}
|
|
40
|
-
/** C# PushModalAsync parameters. */
|
|
41
|
-
export interface ModalOptions {
|
|
42
|
-
/** The modal can be dragged down to close (default false). */
|
|
43
|
-
useGestures?: boolean;
|
|
44
|
-
animated?: boolean;
|
|
45
|
-
/** Dim + blur the page behind (C# freezeBackground; the frozen screenshot is not ported). */
|
|
46
|
-
freezeBackground?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/** A shell tab: its root route and the label shown in the tab bar. */
|
|
49
|
-
export interface ShellTab {
|
|
50
|
-
route: string;
|
|
51
|
-
title: string;
|
|
52
|
-
}
|
|
53
7
|
/** Navigation API, same verbs as DrawnUi SkiaShell. */
|
|
54
8
|
export interface ShellNavigation {
|
|
55
9
|
/** Pushes a registered route; `route` may carry a query ("detail?id=42") and/or explicit arguments (C# GoToAsync(route, animate, arguments)). */
|
|
@@ -114,31 +68,11 @@ export interface SkiaShellProps {
|
|
|
114
68
|
/** Safe-area insets (points) reserved above the nav bar and below the tab bar; default Super.Insets (C# Super.Insets). */
|
|
115
69
|
Insets?: Thickness;
|
|
116
70
|
}
|
|
117
|
-
/** C# SkiaShell static defaults (mutable). */
|
|
118
|
-
export declare const ShellDefaults: {
|
|
119
|
-
ToastBackgroundColor: string;
|
|
120
|
-
ToastTextColor: "#FFFFFF";
|
|
121
|
-
ToastTextFont: string;
|
|
122
|
-
ToastTextSize: number;
|
|
123
|
-
ToastTextMargins: number;
|
|
124
|
-
/** Default overlay tint behind popups / modals. */
|
|
125
|
-
PopupBackgroundColor: string;
|
|
126
|
-
/** Backdrop blur behind popups / modals, points. */
|
|
127
|
-
PopupsBackgroundBlur: number;
|
|
128
|
-
PopupsAnimationSpeed: number;
|
|
129
|
-
PopupsCancelAnimationsAfterMs: number;
|
|
130
|
-
ZIndexModals: number;
|
|
131
|
-
ZIndexPopups: number;
|
|
132
|
-
ZIndexToasts: number;
|
|
133
|
-
/** Accent of the selected tab. */
|
|
134
|
-
TabSelectedColor: string;
|
|
135
|
-
TabColor: string;
|
|
136
|
-
};
|
|
137
71
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally
|
|
141
|
-
*
|
|
142
|
-
*
|
|
72
|
+
* DrawnUi SkiaShell for React: the engine SkiaShell ("drawnui-react/core") with JSX content. A root page (or tabs) plus
|
|
73
|
+
* per-tab stacks of routed pages with a nav bar (pages slide in/out like SkiaViewSwitcher), popups (blurred + dimmed
|
|
74
|
+
* backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally draggable),
|
|
75
|
+
* toasts (bottom banner, slide + fade, auto close). Pages live in the URL hash and the browser back button behaves like
|
|
76
|
+
* C# GoBack (popup, then modal, then page). Navigation via ref or useShell().
|
|
143
77
|
*/
|
|
144
78
|
export declare const SkiaShell: import("react").ForwardRefExoticComponent<SkiaShellProps & import("react").RefAttributes<ShellNavigation>>;
|