@flare-engine/share 0.2.1 → 0.3.0

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/capture.d.ts
1
2
  /**
2
3
  * Cross-platform screenshot capture. The Flare renderer owns a Skia surface;
3
4
  * callers hand us a capturable reference + the target image format, and we
@@ -5,17 +6,17 @@
5
6
  */
6
7
  type ImageFormat = 'png' | 'jpeg';
7
8
  interface CaptureOptions {
8
- /** Output format, defaults to `png`. */
9
- format?: ImageFormat;
10
- /** JPEG quality (0–100). Ignored for PNG. Defaults to 90. */
11
- quality?: number;
9
+ /** Output format, defaults to `png`. */
10
+ format?: ImageFormat;
11
+ /** JPEG quality (0–100). Ignored for PNG. Defaults to 90. */
12
+ quality?: number;
12
13
  }
13
14
  interface Screenshot {
14
- bytes: Uint8Array;
15
- base64: string;
16
- format: ImageFormat;
17
- width: number;
18
- height: number;
15
+ bytes: Uint8Array;
16
+ base64: string;
17
+ format: ImageFormat;
18
+ width: number;
19
+ height: number;
19
20
  }
20
21
  /**
21
22
  * Minimal shape of a Skia image that exposes `encodeToBytes` (RN Skia) or
@@ -23,139 +24,128 @@ interface Screenshot {
23
24
  * bytes first and falls back.
24
25
  */
25
26
  interface SkiaImageLike {
26
- width(): number;
27
- height(): number;
28
- encodeToBytes?(format?: number, quality?: number): Uint8Array | null;
29
- encodeToBase64?(format?: number, quality?: number): string | null;
27
+ width(): number;
28
+ height(): number;
29
+ encodeToBytes?(format?: number, quality?: number): Uint8Array | null;
30
+ encodeToBase64?(format?: number, quality?: number): string | null;
30
31
  }
31
32
  /** Source that yields the current Skia image for capture. */
32
33
  interface CaptureSource {
33
- makeImageSnapshot(): SkiaImageLike | null;
34
+ makeImageSnapshot(): SkiaImageLike | null;
34
35
  }
35
36
  declare function captureScreenshot(source: CaptureSource, options?: CaptureOptions): Screenshot | null;
36
37
  declare function bytesToBase64(bytes: Uint8Array): string;
37
38
  declare function base64ToBytes(input: string): Uint8Array;
38
-
39
+ //#endregion
40
+ //#region src/screenshot-scene.d.ts
41
+ interface ScreenshotTarget {
42
+ /** Stable id — used as the lookup key in `capture(id)`. */
43
+ readonly id: string;
44
+ /** Target width in pixels (store-spec). */
45
+ readonly width: number;
46
+ /** Target height in pixels (store-spec). */
47
+ readonly height: number;
48
+ /** Output format override. Defaults to the scene-level default. */
49
+ readonly format?: ImageFormat;
50
+ /** JPEG quality override. Defaults to the scene-level default. */
51
+ readonly quality?: number;
52
+ }
53
+ interface ScreenshotResult {
54
+ readonly target: ScreenshotTarget;
55
+ readonly screenshot: Screenshot;
56
+ }
57
+ interface ScreenshotSceneOptions {
58
+ /** Source of the current frame — exposes `makeImageSnapshot`. */
59
+ readonly source: CaptureSource;
60
+ /** Store-screenshot specs to capture. */
61
+ readonly targets: readonly ScreenshotTarget[];
62
+ /**
63
+ * Called once before each capture. Typical uses: resize the render target,
64
+ * position the camera, toggle HUD. May be async so callers can wait for a
65
+ * next-frame settle (`await new Promise(queueMicrotask)`).
66
+ */
67
+ readonly setup?: (target: ScreenshotTarget) => void | Promise<void>;
68
+ /** Default capture options — per-target values override. */
69
+ readonly defaults?: CaptureOptions;
70
+ }
71
+ interface ScreenshotScene {
72
+ readonly targets: readonly ScreenshotTarget[];
73
+ /** Capture one target by id. Returns `null` if the id is unknown or capture failed. */
74
+ capture(id: string): Promise<ScreenshotResult | null>;
75
+ /** Capture every configured target in order. Skips failed captures. */
76
+ captureAll(): Promise<readonly ScreenshotResult[]>;
77
+ }
78
+ declare function createScreenshotScene(options: ScreenshotSceneOptions): ScreenshotScene;
79
+ //#endregion
80
+ //#region src/share.d.ts
39
81
  interface SharePayload {
40
- /** Short title shown by the share sheet (native). */
41
- title?: string;
42
- /** Message body (web fallback = clipboard, some native sheets show it). */
43
- message?: string;
44
- /** URL to share. */
45
- url?: string;
46
- /** Optional screenshot to share as an image attachment. */
47
- screenshot?: Screenshot;
82
+ /** Short title shown by the share sheet (native). */
83
+ title?: string;
84
+ /** Message body (web fallback = clipboard, some native sheets show it). */
85
+ message?: string;
86
+ /** URL to share. */
87
+ url?: string;
88
+ /** Optional screenshot to share as an image attachment. */
89
+ screenshot?: Screenshot;
48
90
  }
49
91
  interface ShareResult {
50
- /** Whether the share action was kicked off successfully. */
51
- dispatched: boolean;
52
- /** Name of the transport that handled the request. */
53
- via: 'web-share' | 'web-clipboard' | 'native' | 'noop';
92
+ /** Whether the share action was kicked off successfully. */
93
+ dispatched: boolean;
94
+ /** Name of the transport that handled the request. */
95
+ via: 'web-share' | 'web-clipboard' | 'native' | 'noop';
54
96
  }
55
97
  /**
56
98
  * Platform adapter that knows how to hand a payload to the OS share sheet.
57
99
  * The host app picks an adapter based on its runtime (web vs iOS/Android).
58
100
  */
59
101
  interface ShareTransport {
60
- readonly name: ShareResult['via'];
61
- canShare(payload: SharePayload): boolean;
62
- share(payload: SharePayload): Promise<ShareResult>;
102
+ readonly name: ShareResult['via'];
103
+ canShare(payload: SharePayload): boolean;
104
+ share(payload: SharePayload): Promise<ShareResult>;
63
105
  }
64
106
  interface WebNavigatorLike {
65
- share?(data: {
66
- title?: string;
67
- text?: string;
68
- url?: string;
69
- files?: File[];
70
- }): Promise<void>;
71
- canShare?(data: {
72
- files?: File[];
73
- }): boolean;
74
- clipboard?: {
75
- writeText(text: string): Promise<void>;
76
- };
107
+ share?(data: {
108
+ title?: string;
109
+ text?: string;
110
+ url?: string;
111
+ files?: File[];
112
+ }): Promise<void>;
113
+ canShare?(data: {
114
+ files?: File[];
115
+ }): boolean;
116
+ clipboard?: {
117
+ writeText(text: string): Promise<void>;
118
+ };
77
119
  }
78
120
  interface FileCtorLike {
79
- new (parts: BlobPart[], name: string, options?: {
80
- type?: string;
81
- }): File;
121
+ new (parts: BlobPart[], name: string, options?: {
122
+ type?: string;
123
+ }): File;
82
124
  }
83
125
  declare function createWebShareTransport(nav: WebNavigatorLike, fileCtor?: FileCtorLike): ShareTransport;
84
126
  declare function createWebClipboardTransport(nav: WebNavigatorLike): ShareTransport;
85
127
  interface NativeShareLike {
86
- share(content: {
87
- title?: string;
88
- message?: string;
89
- url?: string;
90
- }): Promise<{
91
- action?: string;
92
- }>;
128
+ share(content: {
129
+ title?: string;
130
+ message?: string;
131
+ url?: string;
132
+ }): Promise<{
133
+ action?: string;
134
+ }>;
93
135
  }
94
136
  interface ExpoSharingLike {
95
- isAvailableAsync(): Promise<boolean>;
96
- shareAsync(uri: string, options?: {
97
- dialogTitle?: string;
98
- mimeType?: string;
99
- }): Promise<void>;
137
+ isAvailableAsync(): Promise<boolean>;
138
+ shareAsync(uri: string, options?: {
139
+ dialogTitle?: string;
140
+ mimeType?: string;
141
+ }): Promise<void>;
100
142
  }
101
143
  declare function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport;
102
144
  declare class ShareManager {
103
- private transports;
104
- register(t: ShareTransport): this;
105
- share(payload: SharePayload): Promise<ShareResult>;
106
- }
107
-
108
- /**
109
- * ScreenshotScene — controller for batch-capturing store-page screenshots
110
- * (Play, App Store, Steam) at fixed dimensions.
111
- *
112
- * The caller supplies a `CaptureSource` (typically the Skia surface driven
113
- * by the game's render loop) and a list of `ScreenshotTarget`s. An optional
114
- * `setup` hook runs before each capture — games use it to stage the camera,
115
- * mute HUD, pause the sim, etc.
116
- *
117
- * Extracted from Pan Tvardowski per Phase 11.14 (M9.6). Pure orchestration:
118
- * the pixel push is owned by the engine renderer; this module only decides
119
- * when and at what size to call `makeImageSnapshot`.
120
- */
121
-
122
- interface ScreenshotTarget {
123
- /** Stable id — used as the lookup key in `capture(id)`. */
124
- readonly id: string;
125
- /** Target width in pixels (store-spec). */
126
- readonly width: number;
127
- /** Target height in pixels (store-spec). */
128
- readonly height: number;
129
- /** Output format override. Defaults to the scene-level default. */
130
- readonly format?: ImageFormat;
131
- /** JPEG quality override. Defaults to the scene-level default. */
132
- readonly quality?: number;
145
+ private transports;
146
+ register(t: ShareTransport): this;
147
+ share(payload: SharePayload): Promise<ShareResult>;
133
148
  }
134
- interface ScreenshotResult {
135
- readonly target: ScreenshotTarget;
136
- readonly screenshot: Screenshot;
137
- }
138
- interface ScreenshotSceneOptions {
139
- /** Source of the current frame — exposes `makeImageSnapshot`. */
140
- readonly source: CaptureSource;
141
- /** Store-screenshot specs to capture. */
142
- readonly targets: readonly ScreenshotTarget[];
143
- /**
144
- * Called once before each capture. Typical uses: resize the render target,
145
- * position the camera, toggle HUD. May be async so callers can wait for a
146
- * next-frame settle (`await new Promise(queueMicrotask)`).
147
- */
148
- readonly setup?: (target: ScreenshotTarget) => void | Promise<void>;
149
- /** Default capture options — per-target values override. */
150
- readonly defaults?: CaptureOptions;
151
- }
152
- interface ScreenshotScene {
153
- readonly targets: readonly ScreenshotTarget[];
154
- /** Capture one target by id. Returns `null` if the id is unknown or capture failed. */
155
- capture(id: string): Promise<ScreenshotResult | null>;
156
- /** Capture every configured target in order. Skips failed captures. */
157
- captureAll(): Promise<readonly ScreenshotResult[]>;
158
- }
159
- declare function createScreenshotScene(options: ScreenshotSceneOptions): ScreenshotScene;
160
-
149
+ //#endregion
161
150
  export { type CaptureOptions, type CaptureSource, type ExpoSharingLike, type ImageFormat, type NativeShareLike, type Screenshot, type ScreenshotResult, type ScreenshotScene, type ScreenshotSceneOptions, type ScreenshotTarget, ShareManager, type SharePayload, type ShareResult, type ShareTransport, type SkiaImageLike, base64ToBytes, bytesToBase64, captureScreenshot, createNativeShareTransport, createScreenshotScene, createWebClipboardTransport, createWebShareTransport };
151
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/capture.ts","../src/screenshot-scene.ts","../src/share.ts"],"mappings":";;;;;;KAMY;UAEK;;EAEf,SAAS;;EAET;;UAGe;EACf,OAAO;EACP;EACA,QAAQ;EACR;EACA;;;;;;;UAQe;EACf;EACA;EACA,eAAe,iBAAiB,mBAAmB;EACnD,gBAAgB,iBAAiB;;;UAIlB;EACf,qBAAqB;;iBAOP,kBACd,QAAQ,eACR,UAAS,iBACR;iBAkCa,cAAc,OAAO;iBAkBrB,cAAc,gBAAgB;;;UC9E7B;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;WAET;;UAGM;WACN,QAAQ;WACR,YAAY;;UAGN;;WAEN,QAAQ;;WAER,kBAAkB;;;;;;WAMlB,SAAS,QAAQ,4BAA4B;;WAE7C,WAAW;;UAGL;WACN,kBAAkB;;EAE3B,QAAQ,aAAa,QAAQ;;EAE7B,cAAc,iBAAiB;;iBAGjB,sBAAsB,SAAS,yBAAyB;;;UC5DvD;;EAEf;;EAEA;;EAEA;;EAEA,aAAa;;UAGE;;EAEf;;EAEA;;;;;;UAOe;WACN,MAAM;EACf,SAAS,SAAS;EAClB,MAAM,SAAS,eAAe,QAAQ;;UAK9B;EACR,OAAO;IAAQ;IAAgB;IAAe;IAAc,QAAQ;MAAW;EAC/E,UAAU;IAAQ,QAAQ;;EAC1B;IACE,UAAU,eAAe;;;UAInB;OACH,OAAO,YAAY,cAAc;IAAY;MAAkB;;iBAGtD,wBACd,KAAK,kBACL,WAAW,eACV;iBAwCa,4BAA4B,KAAK,mBAAmB;UAkBnD;EACf,MAAM;IAAW;IAAgB;IAAkB;MAAiB;IAAU;;;UAG/D;EACf,oBAAoB;EACpB,WAAW,aAAa;IAAY;IAAsB;MAAsB;;iBAGlE,2BAA2B,SAAS,kBAAkB;cAqBzD;UACH;EAER,SAAS,GAAG;EAKN,MAAM,SAAS,eAAe,QAAQ"}