@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/README.md +1 -1
- package/dist/index.d.mts +27 -86
- package/dist/index.d.ts +27 -86
- package/dist/index.js +81 -567
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -576
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ function HUD() {
|
|
|
29
29
|
</GameView>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
See [API spec](../../docs/design/api-specs.md#flare-enginereact--10kb-gzip)
|
|
32
|
+
See [API spec](../../docs/design/api-specs.md#flare-enginereact--10kb-gzip).
|
|
33
33
|
|
|
34
34
|
## License
|
|
35
35
|
|
package/dist/index.d.mts
CHANGED
|
@@ -5,10 +5,11 @@ import { AudioManager } from '@flare-engine/audio';
|
|
|
5
5
|
import { GameLoop } from '@flare-engine/core';
|
|
6
6
|
import { World, Query } from '@flare-engine/ecs';
|
|
7
7
|
import { InputManager, VirtualJoystickConfig, VirtualJoystickState, VirtualButtonState } from '@flare-engine/input';
|
|
8
|
-
import { Camera2D, Renderer, SpriteBatch,
|
|
8
|
+
import { Camera2D, Renderer, SpriteBatch, FrameRendererCompiledPass, FrameRenderer, FrameRendererPostFxChain, FrameRendererPostFxRuntime, FrameRendererModule } from '@flare-engine/render';
|
|
9
9
|
import { SceneManager } from '@flare-engine/scene';
|
|
10
|
-
import { SkRuntimeEffect, SkImage,
|
|
10
|
+
import { SkRuntimeEffect, SkImage, SkColor, SkImageFilter } from '@shopify/react-native-skia';
|
|
11
11
|
import { ViewStyle } from 'react-native';
|
|
12
|
+
import { Signal } from '@flare-engine/events';
|
|
12
13
|
|
|
13
14
|
/** The value exposed via GameContext. */
|
|
14
15
|
interface GameContextValue {
|
|
@@ -96,8 +97,11 @@ interface RenderShapesOpts {
|
|
|
96
97
|
* Narrow view of the Skia module — only the factories the bridge needs.
|
|
97
98
|
* Declared as its own type so tests can pass a plain mock without pulling
|
|
98
99
|
* in the full `@shopify/react-native-skia` surface.
|
|
100
|
+
*
|
|
101
|
+
* Extends `FrameRendererModule` from `@flare-engine/render` with the
|
|
102
|
+
* native Surface and ImageFilter that are not needed in render-web.
|
|
99
103
|
*/
|
|
100
|
-
type SkiaModuleLike =
|
|
104
|
+
type SkiaModuleLike = FrameRendererModule & {
|
|
101
105
|
RuntimeEffect?: {
|
|
102
106
|
Make(sksl: string): SkRuntimeEffect | null;
|
|
103
107
|
};
|
|
@@ -105,105 +109,38 @@ type SkiaModuleLike = Pick<typeof Skia, 'XYWHRect' | 'RSXform' | 'Paint' | 'Pict
|
|
|
105
109
|
Make(width: number, height: number): SkSurfaceLike | null;
|
|
106
110
|
MakeOffscreen?(width: number, height: number): SkSurfaceLike | null;
|
|
107
111
|
};
|
|
112
|
+
/** Optional — present on device builds; absent in CPU/test mocks (drop-shadow falls back to the default paint). */
|
|
113
|
+
ImageFilter?: {
|
|
114
|
+
MakeDropShadow(dx: number, dy: number, sigmaX: number, sigmaY: number, color: SkColor, input: SkImageFilter | null): SkImageFilter;
|
|
115
|
+
};
|
|
108
116
|
};
|
|
109
117
|
/**
|
|
110
118
|
* A single compiled postfx pass descriptor produced by the runtime.
|
|
111
|
-
*
|
|
119
|
+
* Re-exported from render's FrameRendererCompiledPass for consumer compatibility.
|
|
112
120
|
*/
|
|
113
|
-
|
|
114
|
-
readonly id: string;
|
|
115
|
-
readonly shader: {
|
|
116
|
-
makeShaderWithChildren(uniforms: number[], children: unknown[]): unknown | null;
|
|
117
|
-
/** Required for buildPostFxPasses uniform-name mapping. */
|
|
118
|
-
getUniformCount?(): number;
|
|
119
|
-
getUniformName?(index: number): string;
|
|
120
|
-
getUniform?(index: number): {
|
|
121
|
-
columns: number;
|
|
122
|
-
rows: number;
|
|
123
|
-
slot: number;
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
readonly uniforms: Float32Array;
|
|
127
|
-
readonly children: readonly unknown[];
|
|
128
|
-
}
|
|
121
|
+
type CompiledPassLike = FrameRendererCompiledPass;
|
|
129
122
|
/**
|
|
130
123
|
* Minimal structural view of a PostFxRuntime that the bridge needs.
|
|
131
|
-
*
|
|
132
|
-
* `@flare-engine/postfx`; interfaces are compatible structurally.
|
|
133
|
-
*
|
|
134
|
-
* Runtimes that expose `buildPass` are fully managed by the bridge via the
|
|
135
|
-
* JSX `<Image><RuntimeShader/></Image>` chain in GameView.
|
|
124
|
+
* Re-exported from render's FrameRendererPostFxRuntime for consumer compatibility.
|
|
136
125
|
*/
|
|
137
|
-
|
|
138
|
-
readonly supported: boolean;
|
|
139
|
-
buildPass?(chain: PostFxChainLike, width: number, height: number): readonly CompiledPassLike[];
|
|
140
|
-
}
|
|
126
|
+
type PostFxRuntimeLike = FrameRendererPostFxRuntime;
|
|
141
127
|
/** Minimal structural view of an EffectChain the bridge needs. */
|
|
142
|
-
|
|
143
|
-
enabled(): Iterable<unknown>;
|
|
144
|
-
}
|
|
128
|
+
type PostFxChainLike = FrameRendererPostFxChain;
|
|
145
129
|
/**
|
|
146
130
|
* Frame renderer that bridges a `SpriteBatch` to a Skia `<Picture>`.
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* 1. Call `beginFrame(viewportWidth, viewportHeight)` — opens a fresh
|
|
150
|
-
* picture recording bounded to the viewport. If either dimension is 0
|
|
151
|
-
* (layout not yet resolved) the call is a no-op and `endFrame` returns
|
|
152
|
-
* null for that frame.
|
|
153
|
-
* 2. Call `drawAtlas(image, commands)` one or more times (typically via
|
|
154
|
-
* `batch.flush(bridge.drawAtlas, renderer)`).
|
|
155
|
-
* 3. Call `endFrame()` — returns the recorded `SkPicture` to hand to a
|
|
156
|
-
* `<Picture>` component inside a `<Canvas>`.
|
|
157
|
-
*
|
|
158
|
-
* The `canvas` field is a `CanvasLike` adapter the frame owner installs on
|
|
159
|
-
* the `Renderer` via `renderer.setCanvas(bridge.canvas)`. It forwards to
|
|
160
|
-
* the live recording canvas between `beginFrame` and `endFrame`, and is a
|
|
161
|
-
* no-op otherwise.
|
|
131
|
+
* The implementation lives in `@flare-engine/render` (`createFrameRenderer`);
|
|
132
|
+
* this interface narrows the return type for native-Skia consumers.
|
|
162
133
|
*/
|
|
163
|
-
|
|
164
|
-
readonly canvas: CanvasLike;
|
|
165
|
-
/**
|
|
166
|
-
* Open a fresh picture recording for this frame.
|
|
167
|
-
* @param viewportWidth Logical viewport width (CSS pixels).
|
|
168
|
-
* @param viewportHeight Logical viewport height (CSS pixels).
|
|
169
|
-
* @param time Frame timestamp in seconds (default 0).
|
|
170
|
-
* @param pixelDensity Logical→physical recording scale (default 1). When
|
|
171
|
-
* > 1 the recording bounds are expanded to physical
|
|
172
|
-
* resolution and a matching scale() is baked in so
|
|
173
|
-
* `usePictureAsTexture` fills a physical-size backing.
|
|
174
|
-
*/
|
|
175
|
-
beginFrame(viewportWidth: number, viewportHeight: number, time?: number, pixelDensity?: number): void;
|
|
176
|
-
/**
|
|
177
|
-
* drawAtlas callback compatible with `SpriteBatch.flush`. Accepts
|
|
178
|
-
* `SkImageLike` (the narrow `@flare-engine/assets` type used by the batch) and
|
|
179
|
-
* upcasts to a full Skia `SkImage` at the boundary — in practice callers
|
|
180
|
-
* always supply a real `SkImage`.
|
|
181
|
-
*/
|
|
182
|
-
drawAtlas(image: SkImageLike, commands: SpriteDrawCommand[]): void;
|
|
183
|
-
/**
|
|
184
|
-
* Build the list of postfx pass descriptors for this frame. Called by
|
|
185
|
-
* GameView AFTER endFrame() (picture is final) and BEFORE Canvas commits.
|
|
186
|
-
* Returns an empty array when runtime is null, unsupported, has no buildPass,
|
|
187
|
-
* or the chain has no enabled effects.
|
|
188
|
-
*
|
|
189
|
-
* Uniforms are keyed by SkSL uniform NAME via shader.getUniformName(i).
|
|
190
|
-
* Vector uniforms (columns*rows > 1) become readonly number[].
|
|
191
|
-
*/
|
|
192
|
-
buildPostFxPasses(runtime: PostFxRuntimeLike | null, chain: PostFxChainLike | null, width: number, height: number): readonly PostFxPassDescriptor[];
|
|
193
|
-
/**
|
|
194
|
-
* Publish a (runtime, chain) pair for this frame. Called by the
|
|
195
|
-
* onRenderPostFx hook so GameView can drive buildPostFxPasses after
|
|
196
|
-
* endFrame without changing the PostFxRenderHook signature.
|
|
197
|
-
*/
|
|
198
|
-
setPostFxBinding(runtime: PostFxRuntimeLike | null, chain: PostFxChainLike | null): void;
|
|
199
|
-
endFrame(): SkPicture | null;
|
|
200
|
-
}
|
|
134
|
+
type SkiaFrameRenderer = FrameRenderer;
|
|
201
135
|
/**
|
|
202
136
|
* Create a `SkiaFrameRenderer`.
|
|
203
137
|
*
|
|
204
138
|
* `Skia` is passed in (rather than imported) so unit tests can supply a
|
|
205
139
|
* mock. Production code constructs this once inside `<GameView>` using the
|
|
206
140
|
* real `Skia` import from `@shopify/react-native-skia`.
|
|
141
|
+
*
|
|
142
|
+
* Delegates to `createFrameRenderer` from `@flare-engine/render` — the
|
|
143
|
+
* frame-renderer body is backend-neutral and shared with render-web.
|
|
207
144
|
*/
|
|
208
145
|
declare function createSkiaFrameRenderer(Skia: SkiaModuleLike): SkiaFrameRenderer;
|
|
209
146
|
/**
|
|
@@ -376,4 +313,8 @@ interface LoadingScreenProps {
|
|
|
376
313
|
*/
|
|
377
314
|
declare function LoadingScreen({ progress, style, barColor, trackColor, backgroundColor, }: LoadingScreenProps): React__default.ReactElement;
|
|
378
315
|
|
|
379
|
-
|
|
316
|
+
declare function useOverlayFade(visible: boolean, durationMs?: number): number;
|
|
317
|
+
declare function useCountUp(target: number, durationMs?: number): number;
|
|
318
|
+
declare function useSignalState<T>(signal: Signal<T>, initial: T): T;
|
|
319
|
+
|
|
320
|
+
export { type CompiledPassLike, type GameConfig, GameContext, type GameContextValue, GameView, type GameViewProps, LoadingScreen, type LoadingScreenProps, type PostFxChainLike, type PostFxPassDescriptor, type PostFxRenderHook, type PostFxRuntimeLike, type RenderHook, type RenderShapesOpts, type SafeArea, SafeAreaContext, type ShapeRect, type SkOffscreenCanvasLike, type SkiaFrameRenderer, type SkiaModuleLike, VirtualButton, type VirtualButtonProps, VirtualJoystick, type VirtualJoystickProps, createSkiaFrameRenderer, renderShapesToImage, useCountUp, useEntity, useGame, useGameLoop, useOverlayFade, useSafeArea, useSignalState };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,11 @@ import { AudioManager } from '@flare-engine/audio';
|
|
|
5
5
|
import { GameLoop } from '@flare-engine/core';
|
|
6
6
|
import { World, Query } from '@flare-engine/ecs';
|
|
7
7
|
import { InputManager, VirtualJoystickConfig, VirtualJoystickState, VirtualButtonState } from '@flare-engine/input';
|
|
8
|
-
import { Camera2D, Renderer, SpriteBatch,
|
|
8
|
+
import { Camera2D, Renderer, SpriteBatch, FrameRendererCompiledPass, FrameRenderer, FrameRendererPostFxChain, FrameRendererPostFxRuntime, FrameRendererModule } from '@flare-engine/render';
|
|
9
9
|
import { SceneManager } from '@flare-engine/scene';
|
|
10
|
-
import { SkRuntimeEffect, SkImage,
|
|
10
|
+
import { SkRuntimeEffect, SkImage, SkColor, SkImageFilter } from '@shopify/react-native-skia';
|
|
11
11
|
import { ViewStyle } from 'react-native';
|
|
12
|
+
import { Signal } from '@flare-engine/events';
|
|
12
13
|
|
|
13
14
|
/** The value exposed via GameContext. */
|
|
14
15
|
interface GameContextValue {
|
|
@@ -96,8 +97,11 @@ interface RenderShapesOpts {
|
|
|
96
97
|
* Narrow view of the Skia module — only the factories the bridge needs.
|
|
97
98
|
* Declared as its own type so tests can pass a plain mock without pulling
|
|
98
99
|
* in the full `@shopify/react-native-skia` surface.
|
|
100
|
+
*
|
|
101
|
+
* Extends `FrameRendererModule` from `@flare-engine/render` with the
|
|
102
|
+
* native Surface and ImageFilter that are not needed in render-web.
|
|
99
103
|
*/
|
|
100
|
-
type SkiaModuleLike =
|
|
104
|
+
type SkiaModuleLike = FrameRendererModule & {
|
|
101
105
|
RuntimeEffect?: {
|
|
102
106
|
Make(sksl: string): SkRuntimeEffect | null;
|
|
103
107
|
};
|
|
@@ -105,105 +109,38 @@ type SkiaModuleLike = Pick<typeof Skia, 'XYWHRect' | 'RSXform' | 'Paint' | 'Pict
|
|
|
105
109
|
Make(width: number, height: number): SkSurfaceLike | null;
|
|
106
110
|
MakeOffscreen?(width: number, height: number): SkSurfaceLike | null;
|
|
107
111
|
};
|
|
112
|
+
/** Optional — present on device builds; absent in CPU/test mocks (drop-shadow falls back to the default paint). */
|
|
113
|
+
ImageFilter?: {
|
|
114
|
+
MakeDropShadow(dx: number, dy: number, sigmaX: number, sigmaY: number, color: SkColor, input: SkImageFilter | null): SkImageFilter;
|
|
115
|
+
};
|
|
108
116
|
};
|
|
109
117
|
/**
|
|
110
118
|
* A single compiled postfx pass descriptor produced by the runtime.
|
|
111
|
-
*
|
|
119
|
+
* Re-exported from render's FrameRendererCompiledPass for consumer compatibility.
|
|
112
120
|
*/
|
|
113
|
-
|
|
114
|
-
readonly id: string;
|
|
115
|
-
readonly shader: {
|
|
116
|
-
makeShaderWithChildren(uniforms: number[], children: unknown[]): unknown | null;
|
|
117
|
-
/** Required for buildPostFxPasses uniform-name mapping. */
|
|
118
|
-
getUniformCount?(): number;
|
|
119
|
-
getUniformName?(index: number): string;
|
|
120
|
-
getUniform?(index: number): {
|
|
121
|
-
columns: number;
|
|
122
|
-
rows: number;
|
|
123
|
-
slot: number;
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
readonly uniforms: Float32Array;
|
|
127
|
-
readonly children: readonly unknown[];
|
|
128
|
-
}
|
|
121
|
+
type CompiledPassLike = FrameRendererCompiledPass;
|
|
129
122
|
/**
|
|
130
123
|
* Minimal structural view of a PostFxRuntime that the bridge needs.
|
|
131
|
-
*
|
|
132
|
-
* `@flare-engine/postfx`; interfaces are compatible structurally.
|
|
133
|
-
*
|
|
134
|
-
* Runtimes that expose `buildPass` are fully managed by the bridge via the
|
|
135
|
-
* JSX `<Image><RuntimeShader/></Image>` chain in GameView.
|
|
124
|
+
* Re-exported from render's FrameRendererPostFxRuntime for consumer compatibility.
|
|
136
125
|
*/
|
|
137
|
-
|
|
138
|
-
readonly supported: boolean;
|
|
139
|
-
buildPass?(chain: PostFxChainLike, width: number, height: number): readonly CompiledPassLike[];
|
|
140
|
-
}
|
|
126
|
+
type PostFxRuntimeLike = FrameRendererPostFxRuntime;
|
|
141
127
|
/** Minimal structural view of an EffectChain the bridge needs. */
|
|
142
|
-
|
|
143
|
-
enabled(): Iterable<unknown>;
|
|
144
|
-
}
|
|
128
|
+
type PostFxChainLike = FrameRendererPostFxChain;
|
|
145
129
|
/**
|
|
146
130
|
* Frame renderer that bridges a `SpriteBatch` to a Skia `<Picture>`.
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* 1. Call `beginFrame(viewportWidth, viewportHeight)` — opens a fresh
|
|
150
|
-
* picture recording bounded to the viewport. If either dimension is 0
|
|
151
|
-
* (layout not yet resolved) the call is a no-op and `endFrame` returns
|
|
152
|
-
* null for that frame.
|
|
153
|
-
* 2. Call `drawAtlas(image, commands)` one or more times (typically via
|
|
154
|
-
* `batch.flush(bridge.drawAtlas, renderer)`).
|
|
155
|
-
* 3. Call `endFrame()` — returns the recorded `SkPicture` to hand to a
|
|
156
|
-
* `<Picture>` component inside a `<Canvas>`.
|
|
157
|
-
*
|
|
158
|
-
* The `canvas` field is a `CanvasLike` adapter the frame owner installs on
|
|
159
|
-
* the `Renderer` via `renderer.setCanvas(bridge.canvas)`. It forwards to
|
|
160
|
-
* the live recording canvas between `beginFrame` and `endFrame`, and is a
|
|
161
|
-
* no-op otherwise.
|
|
131
|
+
* The implementation lives in `@flare-engine/render` (`createFrameRenderer`);
|
|
132
|
+
* this interface narrows the return type for native-Skia consumers.
|
|
162
133
|
*/
|
|
163
|
-
|
|
164
|
-
readonly canvas: CanvasLike;
|
|
165
|
-
/**
|
|
166
|
-
* Open a fresh picture recording for this frame.
|
|
167
|
-
* @param viewportWidth Logical viewport width (CSS pixels).
|
|
168
|
-
* @param viewportHeight Logical viewport height (CSS pixels).
|
|
169
|
-
* @param time Frame timestamp in seconds (default 0).
|
|
170
|
-
* @param pixelDensity Logical→physical recording scale (default 1). When
|
|
171
|
-
* > 1 the recording bounds are expanded to physical
|
|
172
|
-
* resolution and a matching scale() is baked in so
|
|
173
|
-
* `usePictureAsTexture` fills a physical-size backing.
|
|
174
|
-
*/
|
|
175
|
-
beginFrame(viewportWidth: number, viewportHeight: number, time?: number, pixelDensity?: number): void;
|
|
176
|
-
/**
|
|
177
|
-
* drawAtlas callback compatible with `SpriteBatch.flush`. Accepts
|
|
178
|
-
* `SkImageLike` (the narrow `@flare-engine/assets` type used by the batch) and
|
|
179
|
-
* upcasts to a full Skia `SkImage` at the boundary — in practice callers
|
|
180
|
-
* always supply a real `SkImage`.
|
|
181
|
-
*/
|
|
182
|
-
drawAtlas(image: SkImageLike, commands: SpriteDrawCommand[]): void;
|
|
183
|
-
/**
|
|
184
|
-
* Build the list of postfx pass descriptors for this frame. Called by
|
|
185
|
-
* GameView AFTER endFrame() (picture is final) and BEFORE Canvas commits.
|
|
186
|
-
* Returns an empty array when runtime is null, unsupported, has no buildPass,
|
|
187
|
-
* or the chain has no enabled effects.
|
|
188
|
-
*
|
|
189
|
-
* Uniforms are keyed by SkSL uniform NAME via shader.getUniformName(i).
|
|
190
|
-
* Vector uniforms (columns*rows > 1) become readonly number[].
|
|
191
|
-
*/
|
|
192
|
-
buildPostFxPasses(runtime: PostFxRuntimeLike | null, chain: PostFxChainLike | null, width: number, height: number): readonly PostFxPassDescriptor[];
|
|
193
|
-
/**
|
|
194
|
-
* Publish a (runtime, chain) pair for this frame. Called by the
|
|
195
|
-
* onRenderPostFx hook so GameView can drive buildPostFxPasses after
|
|
196
|
-
* endFrame without changing the PostFxRenderHook signature.
|
|
197
|
-
*/
|
|
198
|
-
setPostFxBinding(runtime: PostFxRuntimeLike | null, chain: PostFxChainLike | null): void;
|
|
199
|
-
endFrame(): SkPicture | null;
|
|
200
|
-
}
|
|
134
|
+
type SkiaFrameRenderer = FrameRenderer;
|
|
201
135
|
/**
|
|
202
136
|
* Create a `SkiaFrameRenderer`.
|
|
203
137
|
*
|
|
204
138
|
* `Skia` is passed in (rather than imported) so unit tests can supply a
|
|
205
139
|
* mock. Production code constructs this once inside `<GameView>` using the
|
|
206
140
|
* real `Skia` import from `@shopify/react-native-skia`.
|
|
141
|
+
*
|
|
142
|
+
* Delegates to `createFrameRenderer` from `@flare-engine/render` — the
|
|
143
|
+
* frame-renderer body is backend-neutral and shared with render-web.
|
|
207
144
|
*/
|
|
208
145
|
declare function createSkiaFrameRenderer(Skia: SkiaModuleLike): SkiaFrameRenderer;
|
|
209
146
|
/**
|
|
@@ -376,4 +313,8 @@ interface LoadingScreenProps {
|
|
|
376
313
|
*/
|
|
377
314
|
declare function LoadingScreen({ progress, style, barColor, trackColor, backgroundColor, }: LoadingScreenProps): React__default.ReactElement;
|
|
378
315
|
|
|
379
|
-
|
|
316
|
+
declare function useOverlayFade(visible: boolean, durationMs?: number): number;
|
|
317
|
+
declare function useCountUp(target: number, durationMs?: number): number;
|
|
318
|
+
declare function useSignalState<T>(signal: Signal<T>, initial: T): T;
|
|
319
|
+
|
|
320
|
+
export { type CompiledPassLike, type GameConfig, GameContext, type GameContextValue, GameView, type GameViewProps, LoadingScreen, type LoadingScreenProps, type PostFxChainLike, type PostFxPassDescriptor, type PostFxRenderHook, type PostFxRuntimeLike, type RenderHook, type RenderShapesOpts, type SafeArea, SafeAreaContext, type ShapeRect, type SkOffscreenCanvasLike, type SkiaFrameRenderer, type SkiaModuleLike, VirtualButton, type VirtualButtonProps, VirtualJoystick, type VirtualJoystickProps, createSkiaFrameRenderer, renderShapesToImage, useCountUp, useEntity, useGame, useGameLoop, useOverlayFade, useSafeArea, useSignalState };
|