@flare-engine/react 0.1.0 → 0.2.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.
package/dist/index.mjs CHANGED
@@ -35,16 +35,7 @@ function useSafeArea() {
35
35
 
36
36
  // src/skia-bridge.ts
37
37
  import {
38
- CAVE_INTERIOR_SKSL,
39
- FIRE_SKSL,
40
- FOG_SKSL,
41
- FOREST_CANOPY_SKSL,
42
- MOON_CRATER_SKSL,
43
- MOUNTAIN_HILLS_SKSL,
44
- RIVER_WAVE_SKSL,
45
- ROOFS_CITY_SKSL,
46
- WATER_SKSL,
47
- flashIntensity
38
+ createFrameRenderer
48
39
  } from "@flare-engine/render";
49
40
  function detachSnapshot(surface) {
50
41
  const snap = surface.makeImageSnapshot();
@@ -53,521 +44,8 @@ function detachSnapshot(surface) {
53
44
  }
54
45
  return snap;
55
46
  }
56
- var BLEND_SRC_OVER = 3;
57
- var BLEND_SRC_IN = 5;
58
- var OUTLINE_OFFSETS = [
59
- [1, 0],
60
- [-1, 0],
61
- [0, 1],
62
- [0, -1],
63
- [Math.SQRT1_2, Math.SQRT1_2],
64
- [Math.SQRT1_2, -Math.SQRT1_2],
65
- [-Math.SQRT1_2, Math.SQRT1_2],
66
- [-Math.SQRT1_2, -Math.SQRT1_2]
67
- ];
68
47
  function createSkiaFrameRenderer(Skia2) {
69
- const defaultPaint = Skia2.Paint();
70
- let tintPaint = null;
71
- let flashPaint = null;
72
- let grayscalePaint = null;
73
- let outlinePaint = null;
74
- let customPaint = null;
75
- let waterPaint = null;
76
- let waterRuntimeEffect = null;
77
- let fogPaint = null;
78
- let fogRuntimeEffect = null;
79
- let firePaint = null;
80
- let fireRuntimeEffect = null;
81
- let roofsCityPaint = null;
82
- let roofsCityEffect = null;
83
- let forestCanopyPaint = null;
84
- let forestCanopyEffect = null;
85
- let riverWavePaint = null;
86
- let riverWaveEffect = null;
87
- let moonCraterPaint = null;
88
- let moonCraterEffect = null;
89
- let caveInteriorPaint = null;
90
- let caveInteriorEffect = null;
91
- let mountainHillsPaint = null;
92
- let mountainHillsEffect = null;
93
- const roofsCityUniforms = new Array(10).fill(0);
94
- const forestCanopyUniforms = new Array(10).fill(0);
95
- const riverWaveUniforms = new Array(10).fill(0);
96
- const moonCraterUniforms = new Array(10).fill(0);
97
- const caveInteriorUniforms = new Array(10).fill(0);
98
- const mountainHillsUniforms = new Array(10).fill(0);
99
- const recorder = Skia2.PictureRecorder();
100
- const recordingBounds = Skia2.XYWHRect(0, 0, 0, 0);
101
- const srcRects = [];
102
- const xforms = [];
103
- const stretchSrcRects = [];
104
- const stretchDstRects = [];
105
- let stretchPaint = null;
106
- const clearColor = new Float32Array(4);
107
- const tintColor = new Float32Array(4);
108
- const flashColor = new Float32Array(4);
109
- const outlineColor = new Float32Array(4);
110
- const grayMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
111
- const customUniforms = [];
112
- const waterUniforms = new Array(11).fill(0);
113
- const fogUniforms = new Array(9).fill(0);
114
- const fireUniforms = new Array(11).fill(0);
115
- let currentFrameTime = 0;
116
- let current = null;
117
- let _boundRuntime = null;
118
- let _boundChain = null;
119
- const _loggedOnce = /* @__PURE__ */ new Set();
120
- function logOnce(msg) {
121
- if (_loggedOnce.has(msg)) return;
122
- _loggedOnce.add(msg);
123
- console.warn(`[postfx] ${msg}`);
124
- }
125
- const canvas = {
126
- save: () => current?.save() ?? 0,
127
- restore: () => {
128
- current?.restore();
129
- },
130
- translate: (x, y) => {
131
- current?.translate(x, y);
132
- },
133
- scale: (sx, sy) => {
134
- current?.scale(sx, sy);
135
- },
136
- rotate: (radians, cx, cy) => {
137
- current?.rotate(radians, cx, cy);
138
- },
139
- clear: (argb) => {
140
- if (current === null) return;
141
- clearColor[0] = (argb >>> 16 & 255) / 255;
142
- clearColor[1] = (argb >>> 8 & 255) / 255;
143
- clearColor[2] = (argb & 255) / 255;
144
- clearColor[3] = (argb >>> 24 & 255) / 255;
145
- current.clear(clearColor);
146
- }
147
- };
148
- function ensurePoolCapacity(n) {
149
- while (srcRects.length < n) {
150
- srcRects.push(Skia2.XYWHRect(0, 0, 0, 0));
151
- xforms.push(Skia2.RSXform(1, 0, 0, 0));
152
- }
153
- }
154
- function ensureStretchPoolCapacity(n) {
155
- while (stretchSrcRects.length < n) {
156
- stretchSrcRects.push(Skia2.XYWHRect(0, 0, 0, 0));
157
- stretchDstRects.push(Skia2.XYWHRect(0, 0, 0, 0));
158
- }
159
- }
160
- function fillSrcRects(commands, n) {
161
- for (let i = 0; i < n; i++) {
162
- const cmd = commands[i];
163
- srcRects[i]?.setXYWH(cmd.srcX, cmd.srcY, cmd.srcW, cmd.srcH);
164
- }
165
- }
166
- function fillXforms(commands, n, dx, dy) {
167
- for (let i = 0; i < n; i++) {
168
- const cmd = commands[i];
169
- const scale = cmd.srcW === 0 ? 1 : cmd.dstW / cmd.srcW;
170
- if (cmd.rotation === 0) {
171
- xforms[i]?.set(scale, 0, cmd.dstX + dx, cmd.dstY + dy);
172
- } else {
173
- const c = Math.cos(cmd.rotation);
174
- const s = Math.sin(cmd.rotation);
175
- const scos = scale * c;
176
- const ssin = scale * s;
177
- const px = cmd.dstX + cmd.anchorX * cmd.dstW + dx;
178
- const py = cmd.dstY + cmd.anchorY * cmd.dstH + dy;
179
- const axSrc = cmd.anchorX * cmd.srcW;
180
- const aySrc = cmd.anchorY * cmd.srcH;
181
- xforms[i]?.set(
182
- scos,
183
- ssin,
184
- px - scos * axSrc + ssin * aySrc,
185
- py - ssin * axSrc - scos * aySrc
186
- );
187
- }
188
- }
189
- }
190
- function applyTint(effect) {
191
- if (tintPaint === null) tintPaint = Skia2.Paint();
192
- writeColor(tintColor, effect.color, effect.amount);
193
- tintPaint.setColorFilter(Skia2.ColorFilter.MakeBlend(tintColor, BLEND_SRC_OVER));
194
- return tintPaint;
195
- }
196
- function applyFlash(effect) {
197
- if (flashPaint === null) flashPaint = Skia2.Paint();
198
- writeColor(flashColor, effect.color, flashIntensity(effect));
199
- flashPaint.setColorFilter(Skia2.ColorFilter.MakeBlend(flashColor, BLEND_SRC_OVER));
200
- return flashPaint;
201
- }
202
- function applyGrayscale(effect) {
203
- if (grayscalePaint === null) grayscalePaint = Skia2.Paint();
204
- writeGrayscaleMatrix(grayMatrix, effect.amount);
205
- grayscalePaint.setColorFilter(Skia2.ColorFilter.MakeMatrix(grayMatrix));
206
- return grayscalePaint;
207
- }
208
- function applyOutlinePaint(effect) {
209
- if (outlinePaint === null) outlinePaint = Skia2.Paint();
210
- writeColor(outlineColor, effect.color, 1);
211
- outlinePaint.setColorFilter(Skia2.ColorFilter.MakeBlend(outlineColor, BLEND_SRC_IN));
212
- return outlinePaint;
213
- }
214
- function applyCustom(effect) {
215
- if (customPaint === null) customPaint = Skia2.Paint();
216
- const shader = effect.shader;
217
- const floatCount = shader.getUniformFloatCount();
218
- while (customUniforms.length < floatCount) customUniforms.push(0);
219
- customUniforms.length = floatCount;
220
- fillCustomUniforms(effect, shader, customUniforms);
221
- customPaint.setShader(shader.makeShader(customUniforms));
222
- return customPaint;
223
- }
224
- function applyWater(effect, time) {
225
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
226
- if (waterRuntimeEffect === null) {
227
- const compiled = Skia2.RuntimeEffect.Make(WATER_SKSL);
228
- if (compiled === null) return defaultPaint;
229
- waterRuntimeEffect = compiled;
230
- }
231
- if (waterPaint === null) waterPaint = Skia2.Paint();
232
- waterUniforms[0] = 0;
233
- waterUniforms[1] = 0;
234
- waterUniforms[2] = effect.color.r;
235
- waterUniforms[3] = effect.color.g;
236
- waterUniforms[4] = effect.color.b;
237
- waterUniforms[5] = effect.foamColor.r;
238
- waterUniforms[6] = effect.foamColor.g;
239
- waterUniforms[7] = effect.foamColor.b;
240
- waterUniforms[8] = effect.waveSpeed;
241
- waterUniforms[9] = effect.waveAmplitude;
242
- waterUniforms[10] = time;
243
- waterPaint.setShader(waterRuntimeEffect.makeShader(waterUniforms));
244
- return waterPaint;
245
- }
246
- function applyFog(effect, time) {
247
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
248
- if (fogRuntimeEffect === null) {
249
- const compiled = Skia2.RuntimeEffect.Make(FOG_SKSL);
250
- if (compiled === null) return defaultPaint;
251
- fogRuntimeEffect = compiled;
252
- }
253
- if (fogPaint === null) fogPaint = Skia2.Paint();
254
- fogUniforms[0] = 0;
255
- fogUniforms[1] = 0;
256
- fogUniforms[2] = effect.color.r;
257
- fogUniforms[3] = effect.color.g;
258
- fogUniforms[4] = effect.color.b;
259
- fogUniforms[5] = effect.density;
260
- fogUniforms[6] = effect.speed;
261
- fogUniforms[7] = effect.scale;
262
- fogUniforms[8] = time;
263
- fogPaint.setShader(fogRuntimeEffect.makeShader(fogUniforms));
264
- return fogPaint;
265
- }
266
- function applyFire(effect, time) {
267
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
268
- if (fireRuntimeEffect === null) {
269
- const compiled = Skia2.RuntimeEffect.Make(FIRE_SKSL);
270
- if (compiled === null) return defaultPaint;
271
- fireRuntimeEffect = compiled;
272
- }
273
- if (firePaint === null) firePaint = Skia2.Paint();
274
- fireUniforms[0] = 0;
275
- fireUniforms[1] = 0;
276
- fireUniforms[2] = effect.color.r;
277
- fireUniforms[3] = effect.color.g;
278
- fireUniforms[4] = effect.color.b;
279
- fireUniforms[5] = effect.tipColor.r;
280
- fireUniforms[6] = effect.tipColor.g;
281
- fireUniforms[7] = effect.tipColor.b;
282
- fireUniforms[8] = effect.speed;
283
- fireUniforms[9] = effect.intensity;
284
- fireUniforms[10] = time;
285
- firePaint.setShader(fireRuntimeEffect.makeShader(fireUniforms));
286
- return firePaint;
287
- }
288
- function applyRoofsCity(effect) {
289
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
290
- if (roofsCityEffect === null) {
291
- const compiled = Skia2.RuntimeEffect.Make(ROOFS_CITY_SKSL);
292
- if (compiled === null) return defaultPaint;
293
- roofsCityEffect = compiled;
294
- }
295
- if (roofsCityPaint === null) roofsCityPaint = Skia2.Paint();
296
- roofsCityUniforms[0] = effect.resolutionW;
297
- roofsCityUniforms[1] = effect.resolutionH;
298
- roofsCityUniforms[2] = effect.skyColor.r;
299
- roofsCityUniforms[3] = effect.skyColor.g;
300
- roofsCityUniforms[4] = effect.skyColor.b;
301
- roofsCityUniforms[5] = effect.roofColor.r;
302
- roofsCityUniforms[6] = effect.roofColor.g;
303
- roofsCityUniforms[7] = effect.roofColor.b;
304
- roofsCityUniforms[8] = effect.scrollOffsetY;
305
- roofsCityUniforms[9] = effect.density;
306
- roofsCityPaint.setShader(roofsCityEffect.makeShader(roofsCityUniforms));
307
- return roofsCityPaint;
308
- }
309
- function applyForestCanopy(effect) {
310
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
311
- if (forestCanopyEffect === null) {
312
- const compiled = Skia2.RuntimeEffect.Make(FOREST_CANOPY_SKSL);
313
- if (compiled === null) return defaultPaint;
314
- forestCanopyEffect = compiled;
315
- }
316
- if (forestCanopyPaint === null) forestCanopyPaint = Skia2.Paint();
317
- forestCanopyUniforms[0] = effect.resolutionW;
318
- forestCanopyUniforms[1] = effect.resolutionH;
319
- forestCanopyUniforms[2] = effect.skyColor.r;
320
- forestCanopyUniforms[3] = effect.skyColor.g;
321
- forestCanopyUniforms[4] = effect.skyColor.b;
322
- forestCanopyUniforms[5] = effect.leafColor.r;
323
- forestCanopyUniforms[6] = effect.leafColor.g;
324
- forestCanopyUniforms[7] = effect.leafColor.b;
325
- forestCanopyUniforms[8] = effect.scrollOffsetY;
326
- forestCanopyUniforms[9] = effect.density;
327
- forestCanopyPaint.setShader(forestCanopyEffect.makeShader(forestCanopyUniforms));
328
- return forestCanopyPaint;
329
- }
330
- function applyRiverWave(effect) {
331
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
332
- if (riverWaveEffect === null) {
333
- const compiled = Skia2.RuntimeEffect.Make(RIVER_WAVE_SKSL);
334
- if (compiled === null) return defaultPaint;
335
- riverWaveEffect = compiled;
336
- }
337
- if (riverWavePaint === null) riverWavePaint = Skia2.Paint();
338
- riverWaveUniforms[0] = effect.resolutionW;
339
- riverWaveUniforms[1] = effect.resolutionH;
340
- riverWaveUniforms[2] = effect.waterColor.r;
341
- riverWaveUniforms[3] = effect.waterColor.g;
342
- riverWaveUniforms[4] = effect.waterColor.b;
343
- riverWaveUniforms[5] = effect.foamColor.r;
344
- riverWaveUniforms[6] = effect.foamColor.g;
345
- riverWaveUniforms[7] = effect.foamColor.b;
346
- riverWaveUniforms[8] = effect.scrollOffsetY;
347
- riverWaveUniforms[9] = effect.waveScale;
348
- riverWavePaint.setShader(riverWaveEffect.makeShader(riverWaveUniforms));
349
- return riverWavePaint;
350
- }
351
- function applyMoonCrater(effect) {
352
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
353
- if (moonCraterEffect === null) {
354
- const compiled = Skia2.RuntimeEffect.Make(MOON_CRATER_SKSL);
355
- if (compiled === null) return defaultPaint;
356
- moonCraterEffect = compiled;
357
- }
358
- if (moonCraterPaint === null) moonCraterPaint = Skia2.Paint();
359
- moonCraterUniforms[0] = effect.resolutionW;
360
- moonCraterUniforms[1] = effect.resolutionH;
361
- moonCraterUniforms[2] = effect.moonColor.r;
362
- moonCraterUniforms[3] = effect.moonColor.g;
363
- moonCraterUniforms[4] = effect.moonColor.b;
364
- moonCraterUniforms[5] = effect.craterColor.r;
365
- moonCraterUniforms[6] = effect.craterColor.g;
366
- moonCraterUniforms[7] = effect.craterColor.b;
367
- moonCraterUniforms[8] = effect.scrollOffsetY;
368
- moonCraterUniforms[9] = effect.craterCount;
369
- moonCraterPaint.setShader(moonCraterEffect.makeShader(moonCraterUniforms));
370
- return moonCraterPaint;
371
- }
372
- function applyCaveInterior(effect) {
373
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
374
- if (caveInteriorEffect === null) {
375
- const compiled = Skia2.RuntimeEffect.Make(CAVE_INTERIOR_SKSL);
376
- if (compiled === null) return defaultPaint;
377
- caveInteriorEffect = compiled;
378
- }
379
- if (caveInteriorPaint === null) caveInteriorPaint = Skia2.Paint();
380
- caveInteriorUniforms[0] = effect.resolutionW;
381
- caveInteriorUniforms[1] = effect.resolutionH;
382
- caveInteriorUniforms[2] = effect.caveColor.r;
383
- caveInteriorUniforms[3] = effect.caveColor.g;
384
- caveInteriorUniforms[4] = effect.caveColor.b;
385
- caveInteriorUniforms[5] = effect.glowColor.r;
386
- caveInteriorUniforms[6] = effect.glowColor.g;
387
- caveInteriorUniforms[7] = effect.glowColor.b;
388
- caveInteriorUniforms[8] = effect.scrollOffsetY;
389
- caveInteriorUniforms[9] = effect.stalactiteCount;
390
- caveInteriorPaint.setShader(caveInteriorEffect.makeShader(caveInteriorUniforms));
391
- return caveInteriorPaint;
392
- }
393
- function applyMountainHills(effect) {
394
- if (Skia2.RuntimeEffect === void 0) return defaultPaint;
395
- if (mountainHillsEffect === null) {
396
- const compiled = Skia2.RuntimeEffect.Make(MOUNTAIN_HILLS_SKSL);
397
- if (compiled === null) return defaultPaint;
398
- mountainHillsEffect = compiled;
399
- }
400
- if (mountainHillsPaint === null) mountainHillsPaint = Skia2.Paint();
401
- mountainHillsUniforms[0] = effect.resolutionW;
402
- mountainHillsUniforms[1] = effect.resolutionH;
403
- mountainHillsUniforms[2] = effect.skyColor.r;
404
- mountainHillsUniforms[3] = effect.skyColor.g;
405
- mountainHillsUniforms[4] = effect.skyColor.b;
406
- mountainHillsUniforms[5] = effect.hillColor.r;
407
- mountainHillsUniforms[6] = effect.hillColor.g;
408
- mountainHillsUniforms[7] = effect.hillColor.b;
409
- mountainHillsUniforms[8] = effect.scrollOffsetY;
410
- mountainHillsUniforms[9] = effect.ridgeScale;
411
- mountainHillsPaint.setShader(mountainHillsEffect.makeShader(mountainHillsUniforms));
412
- return mountainHillsPaint;
413
- }
414
- function drawOutlined(canvas2, image, commands, n, effect, alpha) {
415
- const paint = applyOutlinePaint(effect);
416
- paint.setAlphaf(alpha);
417
- const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
418
- for (let k = 0; k < OUTLINE_OFFSETS.length; k++) {
419
- const offset = OUTLINE_OFFSETS[k];
420
- fillXforms(commands, n, offset[0] * effect.width, offset[1] * effect.width);
421
- const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
422
- canvas2.drawAtlas(image, srcs, dsts, paint);
423
- }
424
- paint.setAlphaf(1);
425
- defaultPaint.setAlphaf(alpha);
426
- fillXforms(commands, n, 0, 0);
427
- const mainDsts = xforms.length === n ? xforms : xforms.slice(0, n);
428
- canvas2.drawAtlas(image, srcs, mainDsts, defaultPaint);
429
- defaultPaint.setAlphaf(1);
430
- }
431
- function resolveEffectPaint(effect) {
432
- switch (effect.type) {
433
- case "tint":
434
- return applyTint(effect);
435
- case "flash":
436
- return applyFlash(effect);
437
- case "grayscale":
438
- return applyGrayscale(effect);
439
- case "custom":
440
- return applyCustom(effect);
441
- case "water":
442
- return applyWater(effect, currentFrameTime);
443
- case "fog":
444
- return applyFog(effect, currentFrameTime);
445
- case "fire":
446
- return applyFire(effect, currentFrameTime);
447
- case "outline":
448
- return applyOutlinePaint(effect);
449
- case "roofs-city":
450
- return applyRoofsCity(effect);
451
- case "forest-canopy":
452
- return applyForestCanopy(effect);
453
- case "river-wave":
454
- return applyRiverWave(effect);
455
- case "moon-crater":
456
- return applyMoonCrater(effect);
457
- case "cave-interior":
458
- return applyCaveInterior(effect);
459
- case "mountain-hills":
460
- return applyMountainHills(effect);
461
- }
462
- }
463
- return {
464
- canvas,
465
- beginFrame(viewportWidth, viewportHeight, time = 0, pixelDensity = 1) {
466
- if (viewportWidth === 0 || viewportHeight === 0) return;
467
- _boundRuntime = null;
468
- _boundChain = null;
469
- currentFrameTime = time;
470
- const pd = pixelDensity;
471
- recordingBounds.setXYWH(0, 0, viewportWidth * pd, viewportHeight * pd);
472
- current = recorder.beginRecording(recordingBounds);
473
- if (pd !== 1) current.scale(pd, pd);
474
- },
475
- drawAtlas(image, commands) {
476
- if (current === null) return;
477
- const n = commands.length;
478
- if (n === 0) return;
479
- const effect = commands[0]?.effect;
480
- const alpha = commands[0]?.alpha ?? 1;
481
- const skImage = image;
482
- if (effect?.type === "roofs-city" || effect?.type === "forest-canopy" || effect?.type === "river-wave" || effect?.type === "moon-crater" || effect?.type === "cave-interior" || effect?.type === "mountain-hills") {
483
- const paint2 = resolveEffectPaint(effect);
484
- paint2.setAlphaf(alpha);
485
- for (let i = 0; i < n; i++) {
486
- const cmd = commands[i];
487
- const rect = Skia2.XYWHRect(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
488
- current.drawRect(rect, paint2);
489
- }
490
- paint2.setAlphaf(1);
491
- return;
492
- }
493
- if (commands[0]?.stretch) {
494
- if (stretchPaint === null) stretchPaint = Skia2.Paint();
495
- ensureStretchPoolCapacity(n);
496
- stretchPaint.setAlphaf(alpha);
497
- for (let i = 0; i < n; i++) {
498
- const cmd = commands[i];
499
- const srcR = stretchSrcRects[i];
500
- const dstR = stretchDstRects[i];
501
- srcR.setXYWH(cmd.srcX, cmd.srcY, cmd.srcW, cmd.srcH);
502
- dstR.setXYWH(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
503
- current.drawImageRect(skImage, srcR, dstR, stretchPaint);
504
- }
505
- stretchPaint.setAlphaf(1);
506
- return;
507
- }
508
- ensurePoolCapacity(n);
509
- fillSrcRects(commands, n);
510
- if (effect?.type === "outline") {
511
- drawOutlined(current, skImage, commands, n, effect, alpha);
512
- return;
513
- }
514
- fillXforms(commands, n, 0, 0);
515
- const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
516
- const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
517
- const paint = effect === void 0 ? defaultPaint : resolveEffectPaint(effect);
518
- paint.setAlphaf(alpha);
519
- current.drawAtlas(skImage, srcs, dsts, paint);
520
- paint.setAlphaf(1);
521
- },
522
- setPostFxBinding(runtime, chain) {
523
- _boundRuntime = runtime;
524
- _boundChain = chain;
525
- },
526
- buildPostFxPasses(runtime, chain, width, height) {
527
- const rt = runtime ?? _boundRuntime;
528
- const ch = chain ?? _boundChain;
529
- if (rt === null || !rt.supported) return [];
530
- if (rt.buildPass === void 0) {
531
- logOnce("buildPostFxPasses: runtime.supported but buildPass absent \u2014 no passes");
532
- return [];
533
- }
534
- if (ch === null) return [];
535
- const passes = rt.buildPass(ch, width, height);
536
- if (passes.length === 0) return [];
537
- const out = [];
538
- for (const pass of passes) {
539
- const shader = pass.shader;
540
- const uniformCount = typeof shader.getUniformCount === "function" ? shader.getUniformCount() : 0;
541
- const uniforms = {};
542
- for (let i = 0; i < uniformCount; i++) {
543
- const name = typeof shader.getUniformName === "function" ? shader.getUniformName(i) : String(i);
544
- const info = typeof shader.getUniform === "function" ? shader.getUniform(i) : { columns: 1, rows: 1, slot: i };
545
- const size = info.columns * info.rows;
546
- if (size === 1) {
547
- uniforms[name] = pass.uniforms[info.slot] ?? 0;
548
- } else {
549
- const vec = [];
550
- for (let k = 0; k < size; k++) {
551
- vec.push(pass.uniforms[info.slot + k] ?? 0);
552
- }
553
- uniforms[name] = vec;
554
- }
555
- }
556
- out.push({
557
- id: pass.id,
558
- source: shader,
559
- uniforms,
560
- children: pass.children
561
- });
562
- }
563
- return out;
564
- },
565
- endFrame() {
566
- if (current === null) return null;
567
- current = null;
568
- return recorder.finishRecordingAsPicture();
569
- }
570
- };
48
+ return createFrameRenderer(Skia2);
571
49
  }
572
50
  function renderShapesToImage(skia, opts) {
573
51
  if (skia.Surface === void 0) return null;
@@ -580,7 +58,7 @@ function renderShapesToImage(skia, opts) {
580
58
  const paint = skia.Paint();
581
59
  for (const shape of opts.shapes) {
582
60
  unpackArgb(scratch, shape.color);
583
- paint.setColor(scratch);
61
+ if (paint.setColor) paint.setColor(scratch);
584
62
  const rect = skia.XYWHRect(shape.x, shape.y, shape.w, shape.h);
585
63
  canvas.drawRect(rect, paint);
586
64
  }
@@ -592,56 +70,6 @@ function unpackArgb(out, argb) {
592
70
  out[2] = (argb & 255) / 255;
593
71
  out[3] = (argb >>> 24 & 255) / 255;
594
72
  }
595
- function writeColor(out, color, alphaMul) {
596
- out[0] = color.r;
597
- out[1] = color.g;
598
- out[2] = color.b;
599
- out[3] = color.a * alphaMul;
600
- }
601
- function writeGrayscaleMatrix(out, amount) {
602
- const inv = 1 - amount;
603
- const lr = 0.299 * amount;
604
- const lg = 0.587 * amount;
605
- const lb = 0.114 * amount;
606
- out[0] = inv + lr;
607
- out[1] = lg;
608
- out[2] = lb;
609
- out[3] = 0;
610
- out[4] = 0;
611
- out[5] = lr;
612
- out[6] = inv + lg;
613
- out[7] = lb;
614
- out[8] = 0;
615
- out[9] = 0;
616
- out[10] = lr;
617
- out[11] = lg;
618
- out[12] = inv + lb;
619
- out[13] = 0;
620
- out[14] = 0;
621
- out[15] = 0;
622
- out[16] = 0;
623
- out[17] = 0;
624
- out[18] = 1;
625
- out[19] = 0;
626
- }
627
- function fillCustomUniforms(effect, shader, out) {
628
- const count = shader.getUniformCount();
629
- for (let i = 0; i < out.length; i++) out[i] = 0;
630
- for (let i = 0; i < count; i++) {
631
- const info = shader.getUniform(i);
632
- const name = shader.getUniformName(i);
633
- const value = effect.uniforms[name];
634
- const size = info.columns * info.rows;
635
- if (value === void 0) continue;
636
- if (typeof value === "number") {
637
- out[info.slot] = value;
638
- continue;
639
- }
640
- for (let k = 0; k < size; k++) {
641
- out[info.slot + k] = value[k] ?? 0;
642
- }
643
- }
644
- }
645
73
 
646
74
  // src/game-view.tsx
647
75
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -1007,6 +435,77 @@ var styles4 = StyleSheet4.create({
1007
435
  height: "100%"
1008
436
  }
1009
437
  });
438
+
439
+ // src/overlay-hooks.ts
440
+ import { easeOutCubic } from "@flare-engine/math";
441
+ import { useEffect as useEffect3, useRef as useRef4, useState as useState4 } from "react";
442
+ function useOverlayFade(visible, durationMs = 300) {
443
+ const target = visible ? 1 : 0;
444
+ const [opacity, setOpacity] = useState4(target);
445
+ const opacityRef = useRef4(opacity);
446
+ const startRef = useRef4(null);
447
+ const rafRef = useRef4(null);
448
+ opacityRef.current = opacity;
449
+ useEffect3(() => {
450
+ if (typeof requestAnimationFrame === "undefined") {
451
+ setOpacity(target);
452
+ return;
453
+ }
454
+ const from = opacityRef.current;
455
+ startRef.current = null;
456
+ if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
457
+ const step = (now) => {
458
+ if (startRef.current === null) startRef.current = now;
459
+ const t = Math.min((now - startRef.current) / durationMs, 1);
460
+ setOpacity(from + (target - from) * t);
461
+ if (t < 1) {
462
+ rafRef.current = requestAnimationFrame(step);
463
+ }
464
+ };
465
+ rafRef.current = requestAnimationFrame(step);
466
+ return () => {
467
+ if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
468
+ };
469
+ }, [target, durationMs]);
470
+ return opacity;
471
+ }
472
+ function useCountUp(target, durationMs = 600) {
473
+ const [value, setValue] = useState4(target);
474
+ const valueRef = useRef4(value);
475
+ const startRef = useRef4(null);
476
+ const rafRef = useRef4(null);
477
+ valueRef.current = value;
478
+ useEffect3(() => {
479
+ if (typeof requestAnimationFrame === "undefined") {
480
+ setValue(target);
481
+ return;
482
+ }
483
+ const from = valueRef.current;
484
+ startRef.current = null;
485
+ if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
486
+ const step = (now) => {
487
+ if (startRef.current === null) startRef.current = now;
488
+ const t = Math.min((now - startRef.current) / durationMs, 1);
489
+ setValue(from + (target - from) * easeOutCubic(t));
490
+ if (t < 1) {
491
+ rafRef.current = requestAnimationFrame(step);
492
+ }
493
+ };
494
+ rafRef.current = requestAnimationFrame(step);
495
+ return () => {
496
+ if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
497
+ };
498
+ }, [target, durationMs]);
499
+ return value;
500
+ }
501
+ function useSignalState(signal, initial) {
502
+ const [state, setState] = useState4(initial);
503
+ useEffect3(() => {
504
+ const disposer = signal.add(setState);
505
+ return disposer;
506
+ }, [signal]);
507
+ return state;
508
+ }
1010
509
  export {
1011
510
  GameContext,
1012
511
  GameView,
@@ -1016,9 +515,12 @@ export {
1016
515
  VirtualJoystick,
1017
516
  createSkiaFrameRenderer,
1018
517
  renderShapesToImage,
518
+ useCountUp,
1019
519
  useEntity,
1020
520
  useGame,
1021
521
  useGameLoop,
1022
- useSafeArea
522
+ useOverlayFade,
523
+ useSafeArea,
524
+ useSignalState
1023
525
  };
1024
526
  //# sourceMappingURL=index.mjs.map