@driftengine/core 4.11.0 → 4.11.1

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.
Files changed (56) hide show
  1. package/CHANGELOG.json +36 -0
  2. package/README.md +1 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +1 -1
  5. package/dist/render/ambientOcclusionPass.d.ts +3 -2
  6. package/dist/render/ambientOcclusionPass.js +4 -2
  7. package/dist/render/backend/api.d.ts +21 -1
  8. package/dist/render/backend/webgl2/renderer.d.ts +45 -4
  9. package/dist/render/backend/webgl2/renderer.js +112 -19
  10. package/dist/render/backend/webgpu/renderer.d.ts +52 -1
  11. package/dist/render/backend/webgpu/renderer.js +237 -89
  12. package/dist/render/instances.d.ts +13 -1
  13. package/dist/render/instances.js +10 -0
  14. package/dist/render/occlusionFade.d.ts +21 -0
  15. package/dist/render/occlusionFade.js +27 -0
  16. package/dist/render/sceneTarget.d.ts +2 -0
  17. package/dist/render/sceneTarget.js +1 -1
  18. package/dist/render/shaders/ambientOcclusion.js +12 -1
  19. package/dist/render/shaders/flat/index.js +9 -2
  20. package/dist/render/shaders/flat/layered.d.ts +15 -7
  21. package/dist/render/shaders/flat/layered.js +114 -31
  22. package/dist/render/shaders/flat/main.d.ts +1 -1
  23. package/dist/render/shaders/flat/main.js +10 -3
  24. package/dist/render/shaders/flat/normalMap.d.ts +1 -1
  25. package/dist/render/shaders/flat/normalMap.js +11 -2
  26. package/dist/render/shaders/generated/ambientOcclusion.wgsl.d.ts +6 -1
  27. package/dist/render/shaders/generated/ambientOcclusion.wgsl.js +6 -1
  28. package/dist/render/shaders/generated/flat.wgsl.d.ts +48 -48
  29. package/dist/render/shaders/generated/flat.wgsl.js +71 -71
  30. package/dist/render/surfaceLayers.d.ts +83 -15
  31. package/dist/render/surfaceLayers.js +69 -13
  32. package/dist/render/surfaceTexture.d.ts +13 -4
  33. package/dist/render/transmission.d.ts +21 -0
  34. package/dist/render/transmission.js +21 -0
  35. package/dist/ui/splash.d.ts +42 -2
  36. package/dist/ui/splash.js +78 -13
  37. package/package.json +6 -6
  38. package/src/index.ts +2 -0
  39. package/src/render/ambientOcclusionPass.ts +4 -1
  40. package/src/render/backend/api.ts +31 -0
  41. package/src/render/backend/webgl2/renderer.ts +130 -20
  42. package/src/render/backend/webgpu/renderer.ts +371 -139
  43. package/src/render/instances.ts +18 -1
  44. package/src/render/occlusionFade.ts +29 -0
  45. package/src/render/sceneTarget.ts +3 -0
  46. package/src/render/shaders/ambientOcclusion.ts +12 -1
  47. package/src/render/shaders/flat/index.ts +9 -2
  48. package/src/render/shaders/flat/layered.ts +114 -31
  49. package/src/render/shaders/flat/main.ts +10 -3
  50. package/src/render/shaders/flat/normalMap.ts +11 -2
  51. package/src/render/shaders/generated/ambientOcclusion.wgsl.ts +6 -1
  52. package/src/render/shaders/generated/flat.wgsl.ts +71 -71
  53. package/src/render/surfaceLayers.ts +138 -19
  54. package/src/render/surfaceTexture.ts +13 -4
  55. package/src/render/transmission.ts +27 -0
  56. package/src/ui/splash.ts +83 -14
@@ -1,7 +1,8 @@
1
1
  /**
2
- * A material blended from layers by a mask: `SurfaceMaterial.layers`, and the two vectors
3
- * `shaders/flat/layered.ts` reads it from.
2
+ * A material blended from layers by a mask: `SurfaceMaterial.layers`, the four vectors
3
+ * `shaders/flat/layered.ts` reads it from, and the decisions both backends take about it.
4
4
  */
5
+ import type { SurfaceProjection } from './surfaceProjection.ts';
5
6
 
6
7
  /** The most layers a material blends: a base and one for each of the mask's four channels. */
7
8
  export const MAX_SURFACE_LAYERS = 5;
@@ -12,33 +13,89 @@ export const MAX_SURFACE_LAYERS = 5;
12
13
  * **Layer `i` is layer `i` of the material's arrays**: `albedo`, `normal` and `orm` each an array
13
14
  * whose layers are the material's layers in order, read at the mesh's coordinates times
14
15
  * `repeats[i]`, so rock can repeat forty times across a cliff while the moss on it repeats three.
15
- * **The mask** is read at the mesh's own coordinates and lays each layer over those before it: red
16
- * lays layer 1 over the base, green layer 2 over that, blue layer 3, alpha layer 4. Its layer 0 is
17
- * read, from where a shading model's map goes, which is why a layered material carries no
18
- * `modelMap`. `emissiveLayer` gives the material's emissive map to one layer, glowing where that
19
- * layer shows and nowhere it is covered; absent, the map glows as on any material.
16
+ * Where the material has a `projection`, the layers are read at the world's horizontal position
17
+ * instead, so a repeat is so many a metre (with the projection's own scale at 1). **The mask** is
18
+ * read at the mesh's own coordinates and lays each layer over those before it: red lays layer 1
19
+ * over the base, green layer 2 over that, blue layer 3, alpha layer 4. `emissiveLayer` gives the
20
+ * material's emissive map to one layer, glowing where that layer shows and nowhere it is covered;
21
+ * absent, the map glows as on any material.
22
+ *
23
+ * **Maps beyond the layers ride the material's own arrays, after its layers**, so they take no
24
+ * texture binding of their own — the lit stage has none to spare: a mask the ORM array carries
25
+ * (`mask: 'orm'`) is the ORM array's layer just past the layers, an `addMask` the one after that,
26
+ * and `meshNormal` the normal array's layer just past the layers. Each shares its array's size and
27
+ * format, so a four-channel mask wants an array that stores four.
20
28
  *
21
29
  * **What it gives up**: every layer's maps are read wherever any shows, three reads a layer, so five
22
30
  * layers are fifteen reads where one material is three; layers share an array's size and format; a
23
- * cutout reads the base layer's alpha; and the mask is sampled linear, so it is uploaded as data
31
+ * cutout reads the base layer's alpha; a mask read where a model's map goes leaves no room for one,
32
+ * so a lightmapped surface carries its mask in its ORM array or its vertices; a triplanar projection
33
+ * lays layers on the horizontal plane alone; and a mask is sampled linear, so it is uploaded as data
24
34
  * (`colorSpace: 'linear'`).
25
35
  */
26
36
  export interface SurfaceLayers<Texture> {
27
- /** The weights, red to alpha laying layers 1 to 4, read at the mesh's coordinates. */
28
- readonly mask: Texture;
37
+ /**
38
+ * Where the weights come from, red to alpha laying layers 1 to 4: a map read where a shading
39
+ * model's map goes; `'orm'`, the ORM array's layer just past the layers; or `'vertex'`, the
40
+ * vertex colour's red, green and blue, which then weights the layers instead of tinting them.
41
+ */
42
+ readonly mask: Texture | 'orm' | 'vertex';
29
43
  /** Each layer's repeats across the mesh's coordinates, base first: one to five of them. */
30
44
  readonly repeats: readonly number[];
31
45
  /** The layer the emissive map glows on, 0 to 4. Absent: everywhere, as on any material. */
32
46
  readonly emissiveLayer?: number;
47
+ /**
48
+ * How the layers combine. `'over'`, the default, lays each over the ones before it by its
49
+ * channel. `'sum'` mixes the base toward the sum of each layer times its channel, by the channels'
50
+ * sum held to 1: two layers at half each are both half there, where laying over would let the
51
+ * second cover half of the first.
52
+ */
53
+ readonly blend?: 'over' | 'sum';
54
+ /**
55
+ * A second mask added to one layer's weight, read where the layers are (the world, under a
56
+ * `projection`) times `repeat`, its red times `intensity`: sand drifting into the gravel's layer at
57
+ * a scale of its own. The ORM array's layer after the layers and any mask it carries.
58
+ */
59
+ readonly addMask?: {
60
+ readonly layer: number;
61
+ readonly repeat: number;
62
+ readonly intensity: number;
63
+ };
64
+ /**
65
+ * One layer weighted by how much the surface faces up rather than by its mask channel:
66
+ * `saturate(bias + sharpness × (up / 2 + 1/2))`, `up` the world normal's upward share before any
67
+ * normal map. Snow on the tops of rocks, moss on a ledge.
68
+ */
69
+ readonly facing?: {
70
+ readonly layer: number;
71
+ readonly bias: number;
72
+ readonly sharpness: number;
73
+ };
74
+ /**
75
+ * A normal map read at the mesh's own coordinates and tangents, the normal array's layer just past
76
+ * the layers, under the layers' blended normal: the large shapes of a rock or a cliff, which a
77
+ * layer repeating forty times across it cannot carry.
78
+ */
79
+ readonly meshNormal?: boolean;
33
80
  }
34
81
 
35
- /** Floats `packSurfaceLayers` writes: two vectors. */
36
- export const LAYER_FLOATS = 8;
82
+ /** Floats `packSurfaceLayers` writes: four vectors. */
83
+ export const LAYER_FLOATS = 16;
84
+
85
+ /** Where the mask is read, as the fourth float of the second vector carries it. */
86
+ const MASK_SOURCE = { map: 0, orm: 1, vertex: 2 } as const;
37
87
 
38
88
  /**
39
- * `layers` into `out`: the five repeats (1 for a layer not given), then how many layers there are
40
- * and which one glows (−1 for none); zeros, no layers, where there are none. A repeat that is not a
41
- * positive number is 1, so a layer is never laid at a scale that collapses it to a point.
89
+ * `layers` into `out`, four vectors. The first five floats are the repeats (1 for a layer not
90
+ * given), then how many layers there are, which one glows (−1 for none) and where the mask comes
91
+ * from (0 a map, 1 the ORM array, 2 the vertex colour). Then the blend (0 over, 1 sum), whether a
92
+ * mesh normal is laid under the layers, the added mask's layer (−1 for none) and repeat; its
93
+ * intensity; and the facing layer (−1 for none), its bias and its sharpness. Zeros, no layers, where
94
+ * there are none.
95
+ *
96
+ * A repeat that is not a positive number is 1, so a layer is never laid at a scale that collapses it
97
+ * to a point; a glow, an added mask or a facing layer naming a layer there is not is none, and the
98
+ * base, which no channel lays, is not one an added mask or the facing can name.
42
99
  */
43
100
  export function packSurfaceLayers<Texture>(
44
101
  layers: SurfaceLayers<Texture> | null | undefined,
@@ -47,11 +104,73 @@ export function packSurfaceLayers<Texture>(
47
104
  out.fill(0);
48
105
  if (layers === null || layers === undefined || layers.repeats.length === 0) return;
49
106
  const count = Math.min(layers.repeats.length, MAX_SURFACE_LAYERS);
50
- for (let i = 0; i < MAX_SURFACE_LAYERS; i++) {
51
- const repeat = i < count ? (layers.repeats[i] as number) : 1;
52
- out[i] = Number.isFinite(repeat) && repeat > 0 ? repeat : 1;
53
- }
107
+ for (let i = 0; i < MAX_SURFACE_LAYERS; i++) out[i] = positive(i < count ? layers.repeats[i] : 1);
54
108
  out[5] = count;
55
109
  const glow = layers.emissiveLayer;
56
110
  out[6] = glow !== undefined && Number.isInteger(glow) && glow >= 0 && glow < count ? glow : -1;
111
+ out[7] =
112
+ layers.mask === 'orm'
113
+ ? MASK_SOURCE.orm
114
+ : layers.mask === 'vertex'
115
+ ? MASK_SOURCE.vertex
116
+ : MASK_SOURCE.map;
117
+ out[8] = layers.blend === 'sum' ? 1 : 0;
118
+ out[9] = layers.meshNormal === true ? 1 : 0;
119
+ const added = layers.addMask;
120
+ const addLayer = laidLayer(added?.layer, count);
121
+ out[10] = addLayer;
122
+ out[11] = addLayer < 0 ? 0 : positive(added?.repeat);
123
+ out[12] = addLayer < 0 ? 0 : finite(added?.intensity);
124
+ const facing = layers.facing;
125
+ const faceLayer = laidLayer(facing?.layer, count);
126
+ out[13] = faceLayer;
127
+ out[14] = faceLayer < 0 ? 0 : finite(facing?.bias);
128
+ out[15] = faceLayer < 0 ? 0 : finite(facing?.sharpness);
129
+ }
130
+
131
+ /** The texture a layered material's mask is, where it is one rather than another array or the vertices. */
132
+ export function layerMaskMap<Texture>(
133
+ layers: SurfaceLayers<Texture> | null | undefined,
134
+ ): Texture | null {
135
+ const mask = layers?.mask;
136
+ return mask === undefined || mask === 'orm' || mask === 'vertex' ? null : mask;
137
+ }
138
+
139
+ /**
140
+ * Whether a material's layers can be drawn beside its `modelMap`: always, unless the mask is a map,
141
+ * which is read where a model's map goes and so cannot share the slot with one — a lightmap's page
142
+ * among them. The backends draw such a material as one layer and say so once.
143
+ */
144
+ export function layersFitBeside<Texture>(
145
+ layers: SurfaceLayers<Texture>,
146
+ modelMap: Texture | null | undefined,
147
+ ): boolean {
148
+ return modelMap === null || modelMap === undefined || layerMaskMap(layers) === null;
149
+ }
150
+
151
+ /**
152
+ * The projection a layered material is drawn with: a triplanar one is laid on the horizontal plane,
153
+ * at its own scale, since every layer's maps read three times over would be forty-five reads a pixel.
154
+ * Anything else as it was. Whether to say so is the caller's.
155
+ */
156
+ export function layeredProjection<Texture>(
157
+ projection: SurfaceProjection | null | undefined,
158
+ layers: SurfaceLayers<Texture> | null | undefined,
159
+ ): SurfaceProjection | null {
160
+ if (projection === null || projection === undefined) return null;
161
+ if (layers === null || layers === undefined || projection.kind !== 'triplanar') return projection;
162
+ return { kind: 'planar', scale: projection.scale };
163
+ }
164
+
165
+ /** A layer an added mask or the facing may name: one a channel lays, 1 to `count − 1`, or −1. */
166
+ function laidLayer(layer: number | undefined, count: number): number {
167
+ return layer !== undefined && Number.isInteger(layer) && layer >= 1 && layer < count ? layer : -1;
168
+ }
169
+
170
+ function positive(value: number | undefined): number {
171
+ return value !== undefined && Number.isFinite(value) && value > 0 ? value : 1;
172
+ }
173
+
174
+ function finite(value: number | undefined): number {
175
+ return value !== undefined && Number.isFinite(value) ? value : 0;
57
176
  }
@@ -235,12 +235,21 @@ export interface SurfaceMaterial<Texture = SurfaceTexture> {
235
235
  * light through by its own rule (`TranslucentMeshOptions.glass`).
236
236
  */
237
237
  diffuseTransmission?: number;
238
+ /**
239
+ * The colour the light from behind takes through the surface, linear, in place of its own colour:
240
+ * a banner whose cloth glows a flat red behind a printed face, a leaf whose veins are not what the
241
+ * light through it shows. Absent, the surface's colour, as `diffuseTransmission` has always used.
242
+ * Each component is held at zero or above. Read only where `diffuseTransmission` lets light through.
243
+ */
244
+ transmissionColor?: readonly [number, number, number] | null;
238
245
  /**
239
246
  * Up to five layers blended by a mask, each at its own repeat: `albedo`, `normal` and `orm` arrays
240
- * whose layers are the material's, and a mask laying each over the ones before it. Absent, the
241
- * material is one layer, as every material was. **A lit switch**, compiled in the first time a
242
- * material asks. The mask is read where `modelMap` goes, so a material carries one or the other.
243
- * See `surfaceLayers.ts` for what it gives up.
247
+ * whose layers are the material's, and a mask laying each over the ones before it or summing them,
248
+ * from a map, the ORM array or the vertex colour; under a `projection` the layers are placed by the
249
+ * world. Absent, the material is one layer, as every material was. **A lit switch**, compiled in the
250
+ * first time a material asks. A mask that is a map is read where `modelMap` goes, so such a
251
+ * material carries one or the other; a lightmapped one keeps its mask in its ORM array or its
252
+ * vertices. See `surfaceLayers.ts` for the rest and what it gives up.
244
253
  */
245
254
  layers?: SurfaceLayers<Texture> | null;
246
255
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A thin surface's light from behind as the lit stage reads it: `SurfaceMaterial.diffuseTransmission`
3
+ * and `transmissionColor` into the four lanes of the glass tint an opaque material leaves unused.
4
+ *
5
+ * **The colour rides lanes glass owns**, because the lit stage's uniform rows are spent
6
+ * (`flat/preamble.ts`): a pane writes its own tint there for its draw, so whatever binds a pane
7
+ * puts this back after it, or the next draw of the material lets light through in the pane's colour.
8
+ * **−1 in the colour lanes means "the albedo"**, which is what a material naming no colour has
9
+ * always let through, so a scene that names none draws to the bit as it did.
10
+ */
11
+
12
+ /** What a material lets through from behind and in which colour, as the glass tint carries it. */
13
+ export interface Transmission {
14
+ readonly diffuseTransmission?: number;
15
+ readonly transmissionColor?: readonly [number, number, number] | null;
16
+ }
17
+
18
+ /**
19
+ * `material` into `out`: the colour, or −1 three times where it names none, then the amount held
20
+ * to 0..1. A colour component below zero is held at zero, so a mistyped colour lets no light
21
+ * through rather than reading as "the albedo".
22
+ */
23
+ export function resolveTransmission(material: Transmission | null, out: Float32Array): void {
24
+ const colour = material?.transmissionColor ?? null;
25
+ for (let i = 0; i < 3; i++) out[i] = colour === null ? -1 : Math.max(colour[i] ?? 0, 0) || 0;
26
+ out[3] = Math.min(Math.max(material?.diffuseTransmission ?? 0, 0), 1) || 0;
27
+ }
package/src/ui/splash.ts CHANGED
@@ -101,8 +101,9 @@ export const SPLASH_FADE_MS = 420;
101
101
  /**
102
102
  * When the badge gives the screen to the game. Two conditions and a cap, each for a named failure.
103
103
  *
104
- * - **The game has painted.** Swapping before that shows the empty canvas the badge exists to
105
- * cover.
104
+ * - **The game has painted**, and every promise it asked the badge to wait for has settled
105
+ * (`holdSplash`). Swapping before that shows the empty canvas, or the half-loaded first screen,
106
+ * the badge exists to cover.
106
107
  * - **The minimum has passed.** A badge that vanishes the instant a fast machine paints is a
107
108
  * flicker, and the machines that boot fastest are the ones a developer tests on.
108
109
  * - **The cap overrides both**, and is checked first so that a minimum longer than the cap
@@ -138,6 +139,65 @@ export interface MountedSplash {
138
139
  present(): void;
139
140
  /** Take it down now, whatever the clock says. Idempotent. */
140
141
  release(): void;
142
+ /** Keep it up until `until` settles as well, under `capMs`. False once it has left. */
143
+ holdUntil(until: PromiseLike<unknown>, capMs?: number): boolean;
144
+ }
145
+
146
+ /**
147
+ * What a badge waits for besides the clock: the game's first frame, and every promise the game asked
148
+ * it to wait for (`holdSplash`), under the cap the game named, the longest of several, or the engine's.
149
+ *
150
+ * **A hold settles whichever way its promise does.** A load that failed must not pin the logo: the
151
+ * game is shown, broken and visible, which is the cap's own argument. Pure apart from the promises,
152
+ * so the rule is testable in Node.
153
+ */
154
+ export class SplashState {
155
+ /** Whether a frame of the game has reached the screen. */
156
+ painted = false;
157
+ private pending = 0;
158
+ /** The longest cap a hold has named, or 0 for none. */
159
+ private asked = 0;
160
+
161
+ /** The longest the badge may stay: the cap a hold named, the longest of several, or the engine's. */
162
+ get capMs(): number {
163
+ return this.asked > 0 ? this.asked : SPLASH_HARD_CAP_MS;
164
+ }
165
+
166
+ /** Wait for `until` too, under `capMs` where it names one; `settled` once it has. */
167
+ hold(until: PromiseLike<unknown>, capMs: number | undefined, settled: () => void): void {
168
+ this.pending += 1;
169
+ if (capMs !== undefined && Number.isFinite(capMs) && capMs > this.asked) this.asked = capMs;
170
+ const done = (): void => {
171
+ this.pending -= 1;
172
+ settled();
173
+ };
174
+ Promise.resolve(until).then(done, done);
175
+ }
176
+
177
+ /** Painted, with every hold settled: what `splashDecision` calls the content being ready. */
178
+ get ready(): boolean {
179
+ return this.painted && this.pending === 0;
180
+ }
181
+ }
182
+
183
+ /** The badge on the page, which `holdSplash` holds. One screen, so one badge: see `bootGate.ts`. */
184
+ let mounted: MountedSplash | null = null;
185
+
186
+ /**
187
+ * Keep the engine's badge up until `until` settles, as well as until the game's first frame: a game
188
+ * whose first screen loads for longer than that frame — a stage, figures and their pictures on a
189
+ * first visit — is seen whole rather than loading. **`capMs` is the game's own ceiling** on the
190
+ * badge in place of the engine's twenty seconds, longer for a slow first visit or shorter, so a load
191
+ * that never settles is still shown in the end; the longest of several holds' wins, and the minimum
192
+ * hold is unchanged.
193
+ *
194
+ * **Frames run while the game loads behind the plate**, since a load may need them, and are held
195
+ * once it has settled, for whatever is left of the minimum, as they are after a first frame with no
196
+ * hold. Returns whether there was a badge to hold: none in a packaged build, whose shell shows its
197
+ * own until the first frame, nor where `splash: false` or `?splash=0` turned it off.
198
+ */
199
+ export function holdSplash(until: PromiseLike<unknown>, options: { capMs?: number } = {}): boolean {
200
+ return mounted?.holdUntil(until, options.capMs) ?? false;
141
201
  }
142
202
 
143
203
  /**
@@ -275,18 +335,19 @@ export function mountSplash(options: SplashOptions = {}): MountedSplash | null {
275
335
  }
276
336
  }
277
337
 
278
- let painted = false;
338
+ const state = new SplashState();
279
339
  let leaving = false;
280
340
  let timer: ReturnType<typeof setTimeout> | null = null;
281
341
 
282
342
  /*
283
- * **Freeze the game the moment it has proved it can draw.**
343
+ * **Freeze the game the moment it has proved it can draw and has loaded.**
284
344
  *
285
- * `painted` is the first `endFrame`, and everything after it until the plate leaves is time the
286
- * game would otherwise spend running behind an opaque screen. `bootGate` is read by `startLoop`
345
+ * Ready is the first `endFrame` with every hold settled (`SplashState`), and everything after it
346
+ * until the plate leaves is time the game would otherwise spend running behind an opaque screen.
347
+ * Before it, frames run: a load the game is holding the badge for may need them. `bootGate` is read by `startLoop`
287
348
  * and named by neither of them; see its own comment for why the state is shared that way.
288
349
  */
289
- const openGate = holdFrames(() => painted && !leaving);
350
+ const openGate = holdFrames(() => state.ready && !leaving);
290
351
 
291
352
  const remove = (): void => {
292
353
  /* Leaving the top layer is what `hidePopover` is for. `remove()` alone takes the element out
@@ -304,6 +365,7 @@ export function mountSplash(options: SplashOptions = {}): MountedSplash | null {
304
365
  const release = (): void => {
305
366
  if (leaving) return;
306
367
  leaving = true;
368
+ if (mounted === badge) mounted = null;
307
369
  /* Before the fade, not after it: the game resumes as the plate becomes transparent, so what
308
370
  shows through is a running frame rather than the still one it was frozen on. */
309
371
  openGate();
@@ -325,23 +387,30 @@ export function mountSplash(options: SplashOptions = {}): MountedSplash | null {
325
387
  const settle = (): void => {
326
388
  if (leaving) return;
327
389
  const elapsed = performance.now() - started;
328
- if (splashDecision(elapsed, minMs, painted) === 'swap') {
390
+ if (splashDecision(elapsed, minMs, state.ready, state.capMs) === 'swap') {
329
391
  release();
330
392
  return;
331
393
  }
332
394
  if (timer !== null) clearTimeout(timer);
333
- const next = painted ? minMs - elapsed : SPLASH_HARD_CAP_MS - elapsed;
395
+ const next = state.ready ? minMs - elapsed : state.capMs - elapsed;
334
396
  timer = setTimeout(settle, Math.max(0, next));
335
397
  };
336
398
 
337
- settle();
338
-
339
- return {
399
+ const badge: MountedSplash = {
340
400
  present(): void {
341
- if (painted || leaving) return;
342
- painted = true;
401
+ if (state.painted || leaving) return;
402
+ state.painted = true;
343
403
  settle();
344
404
  },
345
405
  release,
406
+ holdUntil(until: PromiseLike<unknown>, capMs?: number): boolean {
407
+ if (leaving) return false;
408
+ state.hold(until, capMs, settle);
409
+ settle();
410
+ return true;
411
+ },
346
412
  };
413
+ mounted = badge;
414
+ settle();
415
+ return badge;
347
416
  }