@flare-engine/share 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @flare-engine/share
2
+
3
+ Cross-platform screenshot capture (Skia `makeImageSnapshot`) + share-sheet orchestration with pluggable transports. `captureScreenshot(source, opts?)` returns `{ bytes, base64, format, width, height }`. `ShareManager` cascades through registered transports — first one whose `canShare(payload)` returns true wins. Built-in transports cover Web Share API, Web Clipboard fallback, and native RN `Share`. `createScreenshotScene` wires a one-shot capture scene for store-asset workflows.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @flare-engine/share
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { captureScreenshot, ShareManager, createNativeShareTransport,
15
+ createWebShareTransport, createWebClipboardTransport } from '@flare-engine/share';
16
+
17
+ const shot = captureScreenshot(skiaCanvasRef.current, { format: 'png' });
18
+
19
+ const share = new ShareManager()
20
+ .register(createNativeShareTransport(Share))
21
+ .register(createWebShareTransport(navigator, File))
22
+ .register(createWebClipboardTransport(navigator));
23
+
24
+ await share.share({ message: 'Pan Tvardowski!', url: 'https://…', image: shot.bytes });
25
+ ```
26
+
27
+ See [API spec](../../docs/design/api-specs.md#flare-engineshare--5kb-raw) and [skill reference](../../.github/skills/flare-share/SKILL.md).
28
+
29
+ ## License
30
+
31
+ MIT
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Cross-platform screenshot capture. The Flare renderer owns a Skia surface;
3
+ * callers hand us a capturable reference + the target image format, and we
4
+ * return a PNG/JPEG byte buffer plus a base64 encoding for sharing.
5
+ */
6
+ type ImageFormat = 'png' | 'jpeg';
7
+ 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;
12
+ }
13
+ interface Screenshot {
14
+ bytes: Uint8Array;
15
+ base64: string;
16
+ format: ImageFormat;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ /**
21
+ * Minimal shape of a Skia image that exposes `encodeToBytes` (RN Skia) or
22
+ * `encodeToBase64`. We only rely on one of these — the capture wrapper tries
23
+ * bytes first and falls back.
24
+ */
25
+ interface SkiaImageLike {
26
+ width(): number;
27
+ height(): number;
28
+ encodeToBytes?(format?: number, quality?: number): Uint8Array | null;
29
+ encodeToBase64?(format?: number, quality?: number): string | null;
30
+ }
31
+ /** Source that yields the current Skia image for capture. */
32
+ interface CaptureSource {
33
+ makeImageSnapshot(): SkiaImageLike | null;
34
+ }
35
+ declare function captureScreenshot(source: CaptureSource, options?: CaptureOptions): Screenshot | null;
36
+ declare function bytesToBase64(bytes: Uint8Array): string;
37
+ declare function base64ToBytes(input: string): Uint8Array;
38
+
39
+ 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;
48
+ }
49
+ 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';
54
+ }
55
+ /**
56
+ * Platform adapter that knows how to hand a payload to the OS share sheet.
57
+ * The host app picks an adapter based on its runtime (web vs iOS/Android).
58
+ */
59
+ interface ShareTransport {
60
+ readonly name: ShareResult['via'];
61
+ canShare(payload: SharePayload): boolean;
62
+ share(payload: SharePayload): Promise<ShareResult>;
63
+ }
64
+ 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
+ };
77
+ }
78
+ interface FileCtorLike {
79
+ new (parts: BlobPart[], name: string, options?: {
80
+ type?: string;
81
+ }): File;
82
+ }
83
+ declare function createWebShareTransport(nav: WebNavigatorLike, fileCtor?: FileCtorLike): ShareTransport;
84
+ declare function createWebClipboardTransport(nav: WebNavigatorLike): ShareTransport;
85
+ interface NativeShareLike {
86
+ share(content: {
87
+ title?: string;
88
+ message?: string;
89
+ url?: string;
90
+ }): Promise<{
91
+ action?: string;
92
+ }>;
93
+ }
94
+ interface ExpoSharingLike {
95
+ isAvailableAsync(): Promise<boolean>;
96
+ shareAsync(uri: string, options?: {
97
+ dialogTitle?: string;
98
+ mimeType?: string;
99
+ }): Promise<void>;
100
+ }
101
+ declare function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport;
102
+ 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;
133
+ }
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
+
161
+ 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 };
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Cross-platform screenshot capture. The Flare renderer owns a Skia surface;
3
+ * callers hand us a capturable reference + the target image format, and we
4
+ * return a PNG/JPEG byte buffer plus a base64 encoding for sharing.
5
+ */
6
+ type ImageFormat = 'png' | 'jpeg';
7
+ 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;
12
+ }
13
+ interface Screenshot {
14
+ bytes: Uint8Array;
15
+ base64: string;
16
+ format: ImageFormat;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ /**
21
+ * Minimal shape of a Skia image that exposes `encodeToBytes` (RN Skia) or
22
+ * `encodeToBase64`. We only rely on one of these — the capture wrapper tries
23
+ * bytes first and falls back.
24
+ */
25
+ interface SkiaImageLike {
26
+ width(): number;
27
+ height(): number;
28
+ encodeToBytes?(format?: number, quality?: number): Uint8Array | null;
29
+ encodeToBase64?(format?: number, quality?: number): string | null;
30
+ }
31
+ /** Source that yields the current Skia image for capture. */
32
+ interface CaptureSource {
33
+ makeImageSnapshot(): SkiaImageLike | null;
34
+ }
35
+ declare function captureScreenshot(source: CaptureSource, options?: CaptureOptions): Screenshot | null;
36
+ declare function bytesToBase64(bytes: Uint8Array): string;
37
+ declare function base64ToBytes(input: string): Uint8Array;
38
+
39
+ 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;
48
+ }
49
+ 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';
54
+ }
55
+ /**
56
+ * Platform adapter that knows how to hand a payload to the OS share sheet.
57
+ * The host app picks an adapter based on its runtime (web vs iOS/Android).
58
+ */
59
+ interface ShareTransport {
60
+ readonly name: ShareResult['via'];
61
+ canShare(payload: SharePayload): boolean;
62
+ share(payload: SharePayload): Promise<ShareResult>;
63
+ }
64
+ 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
+ };
77
+ }
78
+ interface FileCtorLike {
79
+ new (parts: BlobPart[], name: string, options?: {
80
+ type?: string;
81
+ }): File;
82
+ }
83
+ declare function createWebShareTransport(nav: WebNavigatorLike, fileCtor?: FileCtorLike): ShareTransport;
84
+ declare function createWebClipboardTransport(nav: WebNavigatorLike): ShareTransport;
85
+ interface NativeShareLike {
86
+ share(content: {
87
+ title?: string;
88
+ message?: string;
89
+ url?: string;
90
+ }): Promise<{
91
+ action?: string;
92
+ }>;
93
+ }
94
+ interface ExpoSharingLike {
95
+ isAvailableAsync(): Promise<boolean>;
96
+ shareAsync(uri: string, options?: {
97
+ dialogTitle?: string;
98
+ mimeType?: string;
99
+ }): Promise<void>;
100
+ }
101
+ declare function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport;
102
+ 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;
133
+ }
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
+
161
+ 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 };
package/dist/index.js ADDED
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ShareManager: () => ShareManager,
24
+ base64ToBytes: () => base64ToBytes,
25
+ bytesToBase64: () => bytesToBase64,
26
+ captureScreenshot: () => captureScreenshot,
27
+ createNativeShareTransport: () => createNativeShareTransport,
28
+ createScreenshotScene: () => createScreenshotScene,
29
+ createWebClipboardTransport: () => createWebClipboardTransport,
30
+ createWebShareTransport: () => createWebShareTransport
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // src/capture.ts
35
+ var FORMAT_CODES = { png: 3, jpeg: 2 };
36
+ function captureScreenshot(source, options = {}) {
37
+ const image = source.makeImageSnapshot();
38
+ if (!image) return null;
39
+ const format = options.format ?? "png";
40
+ const quality = options.quality ?? 90;
41
+ const code = FORMAT_CODES[format];
42
+ let bytes = null;
43
+ let base64 = null;
44
+ if (image.encodeToBytes) {
45
+ bytes = image.encodeToBytes(code, quality) ?? null;
46
+ }
47
+ if (image.encodeToBase64) {
48
+ base64 = image.encodeToBase64(code, quality) ?? null;
49
+ }
50
+ if (!bytes && !base64) return null;
51
+ if (!bytes && base64) bytes = base64ToBytes(base64);
52
+ if (!base64 && bytes) base64 = bytesToBase64(bytes);
53
+ return {
54
+ bytes,
55
+ base64,
56
+ format,
57
+ width: image.width(),
58
+ height: image.height()
59
+ };
60
+ }
61
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
62
+ function bytesToBase64(bytes) {
63
+ let out = "";
64
+ const len = bytes.length;
65
+ for (let i = 0; i < len; i += 3) {
66
+ const b0 = bytes[i] ?? 0;
67
+ const b1 = bytes[i + 1];
68
+ const b2 = bytes[i + 2];
69
+ const hasB1 = b1 !== void 0;
70
+ const hasB2 = b2 !== void 0;
71
+ const n = b0 << 16 | (hasB1 ? b1 : 0) << 8 | (hasB2 ? b2 : 0);
72
+ out += BASE64_CHARS[n >> 18 & 63];
73
+ out += BASE64_CHARS[n >> 12 & 63];
74
+ out += hasB1 ? BASE64_CHARS[n >> 6 & 63] : "=";
75
+ out += hasB2 ? BASE64_CHARS[n & 63] : "=";
76
+ }
77
+ return out;
78
+ }
79
+ function base64ToBytes(input) {
80
+ const clean = input.replace(/[^A-Za-z0-9+/=]/g, "");
81
+ const padded = clean.replace(/=+$/, "");
82
+ const len = padded.length;
83
+ const outLen = Math.floor(len * 3 / 4);
84
+ const out = new Uint8Array(outLen);
85
+ let p = 0;
86
+ for (let i = 0; i < len; i += 4) {
87
+ const c0 = BASE64_CHARS.indexOf(padded[i] ?? "A");
88
+ const c1 = BASE64_CHARS.indexOf(padded[i + 1] ?? "A");
89
+ const c2 = BASE64_CHARS.indexOf(padded[i + 2] ?? "A");
90
+ const c3 = BASE64_CHARS.indexOf(padded[i + 3] ?? "A");
91
+ const n = c0 << 18 | c1 << 12 | c2 << 6 | c3;
92
+ if (p < outLen) out[p++] = n >> 16 & 255;
93
+ if (p < outLen) out[p++] = n >> 8 & 255;
94
+ if (p < outLen) out[p++] = n & 255;
95
+ }
96
+ return out;
97
+ }
98
+
99
+ // src/share.ts
100
+ function createWebShareTransport(nav, fileCtor) {
101
+ return {
102
+ name: "web-share",
103
+ canShare(payload) {
104
+ if (!nav.share) return false;
105
+ if (!payload.screenshot) return true;
106
+ if (!fileCtor || !nav.canShare) return false;
107
+ try {
108
+ const f = new fileCtor(
109
+ [payload.screenshot.bytes],
110
+ "screenshot.png",
111
+ {
112
+ type: `image/${payload.screenshot.format}`
113
+ }
114
+ );
115
+ return nav.canShare({ files: [f] });
116
+ } catch {
117
+ return false;
118
+ }
119
+ },
120
+ async share(payload) {
121
+ if (!nav.share) return { dispatched: false, via: "web-share" };
122
+ const data = {};
123
+ if (payload.title !== void 0) data.title = payload.title;
124
+ if (payload.message !== void 0) data.text = payload.message;
125
+ if (payload.url !== void 0) data.url = payload.url;
126
+ if (payload.screenshot && fileCtor) {
127
+ const file = new fileCtor(
128
+ [payload.screenshot.bytes],
129
+ `screenshot.${payload.screenshot.format}`,
130
+ { type: `image/${payload.screenshot.format}` }
131
+ );
132
+ data.files = [file];
133
+ }
134
+ await nav.share(data);
135
+ return { dispatched: true, via: "web-share" };
136
+ }
137
+ };
138
+ }
139
+ function createWebClipboardTransport(nav) {
140
+ return {
141
+ name: "web-clipboard",
142
+ canShare(payload) {
143
+ return Boolean(nav.clipboard && (payload.url ?? payload.message));
144
+ },
145
+ async share(payload) {
146
+ if (!nav.clipboard) return { dispatched: false, via: "web-clipboard" };
147
+ const text = [payload.message, payload.url].filter((s) => Boolean(s)).join(" ");
148
+ if (text.length === 0) return { dispatched: false, via: "web-clipboard" };
149
+ await nav.clipboard.writeText(text);
150
+ return { dispatched: true, via: "web-clipboard" };
151
+ }
152
+ };
153
+ }
154
+ function createNativeShareTransport(rnShare) {
155
+ return {
156
+ name: "native",
157
+ canShare() {
158
+ return true;
159
+ },
160
+ async share(payload) {
161
+ const content = {};
162
+ if (payload.title !== void 0) content.title = payload.title;
163
+ if (payload.message !== void 0) content.message = payload.message;
164
+ if (payload.url !== void 0) content.url = payload.url;
165
+ const res = await rnShare.share(content);
166
+ return { dispatched: res.action !== "dismissed", via: "native" };
167
+ }
168
+ };
169
+ }
170
+ var ShareManager = class {
171
+ transports = [];
172
+ register(t) {
173
+ this.transports.push(t);
174
+ return this;
175
+ }
176
+ async share(payload) {
177
+ for (const t of this.transports) {
178
+ if (t.canShare(payload)) return t.share(payload);
179
+ }
180
+ return { dispatched: false, via: "noop" };
181
+ }
182
+ };
183
+
184
+ // src/screenshot-scene.ts
185
+ function createScreenshotScene(options) {
186
+ const { source, targets, setup, defaults } = options;
187
+ async function captureOne(target) {
188
+ if (setup) await setup(target);
189
+ const shot = captureScreenshot(source, {
190
+ format: target.format ?? defaults?.format,
191
+ quality: target.quality ?? defaults?.quality
192
+ });
193
+ if (!shot) return null;
194
+ return { target, screenshot: shot };
195
+ }
196
+ return {
197
+ targets,
198
+ async capture(id) {
199
+ for (let i = 0; i < targets.length; i++) {
200
+ const t = targets[i];
201
+ if (t && t.id === id) return captureOne(t);
202
+ }
203
+ return null;
204
+ },
205
+ async captureAll() {
206
+ const results = [];
207
+ for (let i = 0; i < targets.length; i++) {
208
+ const t = targets[i];
209
+ if (!t) continue;
210
+ const r = await captureOne(t);
211
+ if (r) results.push(r);
212
+ }
213
+ return results;
214
+ }
215
+ };
216
+ }
217
+ // Annotate the CommonJS export names for ESM import in node:
218
+ 0 && (module.exports = {
219
+ ShareManager,
220
+ base64ToBytes,
221
+ bytesToBase64,
222
+ captureScreenshot,
223
+ createNativeShareTransport,
224
+ createScreenshotScene,
225
+ createWebClipboardTransport,
226
+ createWebShareTransport
227
+ });
228
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/capture.ts","../src/share.ts","../src/screenshot-scene.ts"],"sourcesContent":["export {\n captureScreenshot,\n bytesToBase64,\n base64ToBytes,\n type CaptureOptions,\n type CaptureSource,\n type ImageFormat,\n type Screenshot,\n type SkiaImageLike,\n} from './capture.js';\nexport {\n ShareManager,\n createWebShareTransport,\n createWebClipboardTransport,\n createNativeShareTransport,\n type ExpoSharingLike,\n type NativeShareLike,\n type ShareResult,\n type SharePayload,\n type ShareTransport,\n} from './share.js';\nexport {\n type ScreenshotScene,\n type ScreenshotSceneOptions,\n type ScreenshotTarget,\n type ScreenshotResult,\n createScreenshotScene,\n} from './screenshot-scene.js';\n","/**\n * Cross-platform screenshot capture. The Flare renderer owns a Skia surface;\n * callers hand us a capturable reference + the target image format, and we\n * return a PNG/JPEG byte buffer plus a base64 encoding for sharing.\n */\n\nexport type ImageFormat = 'png' | 'jpeg';\n\nexport interface CaptureOptions {\n /** Output format, defaults to `png`. */\n format?: ImageFormat;\n /** JPEG quality (0–100). Ignored for PNG. Defaults to 90. */\n quality?: number;\n}\n\nexport interface Screenshot {\n bytes: Uint8Array;\n base64: string;\n format: ImageFormat;\n width: number;\n height: number;\n}\n\n/**\n * Minimal shape of a Skia image that exposes `encodeToBytes` (RN Skia) or\n * `encodeToBase64`. We only rely on one of these — the capture wrapper tries\n * bytes first and falls back.\n */\nexport interface SkiaImageLike {\n width(): number;\n height(): number;\n encodeToBytes?(format?: number, quality?: number): Uint8Array | null;\n encodeToBase64?(format?: number, quality?: number): string | null;\n}\n\n/** Source that yields the current Skia image for capture. */\nexport interface CaptureSource {\n makeImageSnapshot(): SkiaImageLike | null;\n}\n\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 3, jpeg: 2 };\n\nexport function captureScreenshot(\n source: CaptureSource,\n options: CaptureOptions = {},\n): Screenshot | null {\n const image = source.makeImageSnapshot();\n if (!image) return null;\n const format = options.format ?? 'png';\n const quality = options.quality ?? 90;\n const code = FORMAT_CODES[format];\n\n let bytes: Uint8Array | null = null;\n let base64: string | null = null;\n\n if (image.encodeToBytes) {\n bytes = image.encodeToBytes(code, quality) ?? null;\n }\n if (image.encodeToBase64) {\n base64 = image.encodeToBase64(code, quality) ?? null;\n }\n\n if (!bytes && !base64) return null;\n if (!bytes && base64) bytes = base64ToBytes(base64);\n if (!base64 && bytes) base64 = bytesToBase64(bytes);\n\n return {\n bytes: bytes as Uint8Array,\n base64: base64 as string,\n format,\n width: image.width(),\n height: image.height(),\n };\n}\n\n// --- base64 helpers (platform-agnostic, UTF-8 safe for binary) -------------\n\nconst BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nexport function bytesToBase64(bytes: Uint8Array): string {\n let out = '';\n const len = bytes.length;\n for (let i = 0; i < len; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1];\n const b2 = bytes[i + 2];\n const hasB1 = b1 !== undefined;\n const hasB2 = b2 !== undefined;\n const n = (b0 << 16) | ((hasB1 ? b1 : 0) << 8) | (hasB2 ? b2 : 0);\n out += BASE64_CHARS[(n >> 18) & 63];\n out += BASE64_CHARS[(n >> 12) & 63];\n out += hasB1 ? BASE64_CHARS[(n >> 6) & 63] : '=';\n out += hasB2 ? BASE64_CHARS[n & 63] : '=';\n }\n return out;\n}\n\nexport function base64ToBytes(input: string): Uint8Array {\n const clean = input.replace(/[^A-Za-z0-9+/=]/g, '');\n const padded = clean.replace(/=+$/, '');\n const len = padded.length;\n const outLen = Math.floor((len * 3) / 4);\n const out = new Uint8Array(outLen);\n let p = 0;\n for (let i = 0; i < len; i += 4) {\n const c0 = BASE64_CHARS.indexOf(padded[i] ?? 'A');\n const c1 = BASE64_CHARS.indexOf(padded[i + 1] ?? 'A');\n const c2 = BASE64_CHARS.indexOf(padded[i + 2] ?? 'A');\n const c3 = BASE64_CHARS.indexOf(padded[i + 3] ?? 'A');\n const n = (c0 << 18) | (c1 << 12) | (c2 << 6) | c3;\n if (p < outLen) out[p++] = (n >> 16) & 0xff;\n if (p < outLen) out[p++] = (n >> 8) & 0xff;\n if (p < outLen) out[p++] = n & 0xff;\n }\n return out;\n}\n","import type { Screenshot } from './capture.js';\n\nexport interface SharePayload {\n /** Short title shown by the share sheet (native). */\n title?: string;\n /** Message body (web fallback = clipboard, some native sheets show it). */\n message?: string;\n /** URL to share. */\n url?: string;\n /** Optional screenshot to share as an image attachment. */\n screenshot?: Screenshot;\n}\n\nexport interface ShareResult {\n /** Whether the share action was kicked off successfully. */\n dispatched: boolean;\n /** Name of the transport that handled the request. */\n via: 'web-share' | 'web-clipboard' | 'native' | 'noop';\n}\n\n/**\n * Platform adapter that knows how to hand a payload to the OS share sheet.\n * The host app picks an adapter based on its runtime (web vs iOS/Android).\n */\nexport interface ShareTransport {\n readonly name: ShareResult['via'];\n canShare(payload: SharePayload): boolean;\n share(payload: SharePayload): Promise<ShareResult>;\n}\n\n// ---------- Web Share API adapter -----------------------------------------\n\ninterface WebNavigatorLike {\n share?(data: { title?: string; text?: string; url?: string; files?: File[] }): Promise<void>;\n canShare?(data: { files?: File[] }): boolean;\n clipboard?: {\n writeText(text: string): Promise<void>;\n };\n}\n\ninterface FileCtorLike {\n new (parts: BlobPart[], name: string, options?: { type?: string }): File;\n}\n\nexport function createWebShareTransport(\n nav: WebNavigatorLike,\n fileCtor?: FileCtorLike,\n): ShareTransport {\n return {\n name: 'web-share',\n canShare(payload) {\n if (!nav.share) return false;\n if (!payload.screenshot) return true;\n if (!fileCtor || !nav.canShare) return false;\n try {\n const f = new fileCtor(\n [payload.screenshot.bytes as unknown as BlobPart],\n 'screenshot.png',\n {\n type: `image/${payload.screenshot.format}`,\n },\n );\n return nav.canShare({ files: [f] });\n } catch {\n return false;\n }\n },\n async share(payload) {\n if (!nav.share) return { dispatched: false, via: 'web-share' };\n const data: { title?: string; text?: string; url?: string; files?: File[] } = {};\n if (payload.title !== undefined) data.title = payload.title;\n if (payload.message !== undefined) data.text = payload.message;\n if (payload.url !== undefined) data.url = payload.url;\n if (payload.screenshot && fileCtor) {\n const file = new fileCtor(\n [payload.screenshot.bytes as unknown as BlobPart],\n `screenshot.${payload.screenshot.format}`,\n { type: `image/${payload.screenshot.format}` },\n );\n data.files = [file];\n }\n await nav.share(data);\n return { dispatched: true, via: 'web-share' };\n },\n };\n}\n\nexport function createWebClipboardTransport(nav: WebNavigatorLike): ShareTransport {\n return {\n name: 'web-clipboard',\n canShare(payload) {\n return Boolean(nav.clipboard && (payload.url ?? payload.message));\n },\n async share(payload) {\n if (!nav.clipboard) return { dispatched: false, via: 'web-clipboard' };\n const text = [payload.message, payload.url].filter((s): s is string => Boolean(s)).join(' ');\n if (text.length === 0) return { dispatched: false, via: 'web-clipboard' };\n await nav.clipboard.writeText(text);\n return { dispatched: true, via: 'web-clipboard' };\n },\n };\n}\n\n// ---------- Native (RN Share / expo-sharing-shaped) adapter ---------------\n\nexport interface NativeShareLike {\n share(content: { title?: string; message?: string; url?: string }): Promise<{ action?: string }>;\n}\n\nexport interface ExpoSharingLike {\n isAvailableAsync(): Promise<boolean>;\n shareAsync(uri: string, options?: { dialogTitle?: string; mimeType?: string }): Promise<void>;\n}\n\nexport function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport {\n return {\n name: 'native',\n canShare() {\n return true;\n },\n async share(payload) {\n const content: { title?: string; message?: string; url?: string } = {};\n if (payload.title !== undefined) content.title = payload.title;\n if (payload.message !== undefined) content.message = payload.message;\n if (payload.url !== undefined) content.url = payload.url;\n const res = await rnShare.share(content);\n return { dispatched: res.action !== 'dismissed', via: 'native' };\n },\n };\n}\n\n// ---------- Manager -------------------------------------------------------\n\nexport class ShareManager {\n private transports: ShareTransport[] = [];\n\n register(t: ShareTransport): this {\n this.transports.push(t);\n return this;\n }\n\n async share(payload: SharePayload): Promise<ShareResult> {\n for (const t of this.transports) {\n if (t.canShare(payload)) return t.share(payload);\n }\n return { dispatched: false, via: 'noop' };\n }\n}\n","/**\n * ScreenshotScene — controller for batch-capturing store-page screenshots\n * (Play, App Store, Steam) at fixed dimensions.\n *\n * The caller supplies a `CaptureSource` (typically the Skia surface driven\n * by the game's render loop) and a list of `ScreenshotTarget`s. An optional\n * `setup` hook runs before each capture — games use it to stage the camera,\n * mute HUD, pause the sim, etc.\n *\n * Extracted from Pan Tvardowski per Phase 11.14 (M9.6). Pure orchestration:\n * the pixel push is owned by the engine renderer; this module only decides\n * when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n type ImageFormat,\n type Screenshot,\n captureScreenshot,\n} from './capture.js';\n\nexport interface ScreenshotTarget {\n /** Stable id — used as the lookup key in `capture(id)`. */\n readonly id: string;\n /** Target width in pixels (store-spec). */\n readonly width: number;\n /** Target height in pixels (store-spec). */\n readonly height: number;\n /** Output format override. Defaults to the scene-level default. */\n readonly format?: ImageFormat;\n /** JPEG quality override. Defaults to the scene-level default. */\n readonly quality?: number;\n}\n\nexport interface ScreenshotResult {\n readonly target: ScreenshotTarget;\n readonly screenshot: Screenshot;\n}\n\nexport interface ScreenshotSceneOptions {\n /** Source of the current frame — exposes `makeImageSnapshot`. */\n readonly source: CaptureSource;\n /** Store-screenshot specs to capture. */\n readonly targets: readonly ScreenshotTarget[];\n /**\n * Called once before each capture. Typical uses: resize the render target,\n * position the camera, toggle HUD. May be async so callers can wait for a\n * next-frame settle (`await new Promise(queueMicrotask)`).\n */\n readonly setup?: (target: ScreenshotTarget) => void | Promise<void>;\n /** Default capture options — per-target values override. */\n readonly defaults?: CaptureOptions;\n}\n\nexport interface ScreenshotScene {\n readonly targets: readonly ScreenshotTarget[];\n /** Capture one target by id. Returns `null` if the id is unknown or capture failed. */\n capture(id: string): Promise<ScreenshotResult | null>;\n /** Capture every configured target in order. Skips failed captures. */\n captureAll(): Promise<readonly ScreenshotResult[]>;\n}\n\nexport function createScreenshotScene(options: ScreenshotSceneOptions): ScreenshotScene {\n const { source, targets, setup, defaults } = options;\n\n async function captureOne(target: ScreenshotTarget): Promise<ScreenshotResult | null> {\n if (setup) await setup(target);\n const shot = captureScreenshot(source, {\n format: target.format ?? defaults?.format,\n quality: target.quality ?? defaults?.quality,\n });\n if (!shot) return null;\n return { target, screenshot: shot };\n }\n\n return {\n targets,\n async capture(id) {\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i];\n if (t && t.id === id) return captureOne(t);\n }\n return null;\n },\n async captureAll() {\n const results: ScreenshotResult[] = [];\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i];\n if (!t) continue;\n const r = await captureOne(t);\n if (r) results.push(r);\n }\n return results;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwCA,IAAM,eAA4C,EAAE,KAAK,GAAG,MAAM,EAAE;AAE7D,SAAS,kBACd,QACA,UAA0B,CAAC,GACR;AACnB,QAAM,QAAQ,OAAO,kBAAkB;AACvC,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,OAAO,aAAa,MAAM;AAEhC,MAAI,QAA2B;AAC/B,MAAI,SAAwB;AAE5B,MAAI,MAAM,eAAe;AACvB,YAAQ,MAAM,cAAc,MAAM,OAAO,KAAK;AAAA,EAChD;AACA,MAAI,MAAM,gBAAgB;AACxB,aAAS,MAAM,eAAe,MAAM,OAAO,KAAK;AAAA,EAClD;AAEA,MAAI,CAAC,SAAS,CAAC,OAAQ,QAAO;AAC9B,MAAI,CAAC,SAAS,OAAQ,SAAQ,cAAc,MAAM;AAClD,MAAI,CAAC,UAAU,MAAO,UAAS,cAAc,KAAK;AAElD,SAAO;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AAC/B,UAAI,EAAE,SAAS,OAAO,EAAG,QAAO,EAAE,MAAM,OAAO;AAAA,IACjD;AACA,WAAO,EAAE,YAAY,OAAO,KAAK,OAAO;AAAA,EAC1C;AACF;;;ACpFO,SAAS,sBAAsB,SAAkD;AACtF,QAAM,EAAE,QAAQ,SAAS,OAAO,SAAS,IAAI;AAE7C,iBAAe,WAAW,QAA4D;AACpF,QAAI,MAAO,OAAM,MAAM,MAAM;AAC7B,UAAM,OAAO,kBAAkB,QAAQ;AAAA,MACrC,QAAQ,OAAO,UAAU,UAAU;AAAA,MACnC,SAAS,OAAO,WAAW,UAAU;AAAA,IACvC,CAAC;AACD,QAAI,CAAC,KAAM,QAAO;AAClB,WAAO,EAAE,QAAQ,YAAY,KAAK;AAAA,EACpC;AAEA,SAAO;AAAA,IACL;AAAA,IACA,MAAM,QAAQ,IAAI;AAChB,eAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,cAAM,IAAI,QAAQ,CAAC;AACnB,YAAI,KAAK,EAAE,OAAO,GAAI,QAAO,WAAW,CAAC;AAAA,MAC3C;AACA,aAAO;AAAA,IACT;AAAA,IACA,MAAM,aAAa;AACjB,YAAM,UAA8B,CAAC;AACrC,eAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,cAAM,IAAI,QAAQ,CAAC;AACnB,YAAI,CAAC,EAAG;AACR,cAAM,IAAI,MAAM,WAAW,CAAC;AAC5B,YAAI,EAAG,SAAQ,KAAK,CAAC;AAAA,MACvB;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,194 @@
1
+ // src/capture.ts
2
+ var FORMAT_CODES = { png: 3, jpeg: 2 };
3
+ function captureScreenshot(source, options = {}) {
4
+ const image = source.makeImageSnapshot();
5
+ if (!image) return null;
6
+ const format = options.format ?? "png";
7
+ const quality = options.quality ?? 90;
8
+ const code = FORMAT_CODES[format];
9
+ let bytes = null;
10
+ let base64 = null;
11
+ if (image.encodeToBytes) {
12
+ bytes = image.encodeToBytes(code, quality) ?? null;
13
+ }
14
+ if (image.encodeToBase64) {
15
+ base64 = image.encodeToBase64(code, quality) ?? null;
16
+ }
17
+ if (!bytes && !base64) return null;
18
+ if (!bytes && base64) bytes = base64ToBytes(base64);
19
+ if (!base64 && bytes) base64 = bytesToBase64(bytes);
20
+ return {
21
+ bytes,
22
+ base64,
23
+ format,
24
+ width: image.width(),
25
+ height: image.height()
26
+ };
27
+ }
28
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
29
+ function bytesToBase64(bytes) {
30
+ let out = "";
31
+ const len = bytes.length;
32
+ for (let i = 0; i < len; i += 3) {
33
+ const b0 = bytes[i] ?? 0;
34
+ const b1 = bytes[i + 1];
35
+ const b2 = bytes[i + 2];
36
+ const hasB1 = b1 !== void 0;
37
+ const hasB2 = b2 !== void 0;
38
+ const n = b0 << 16 | (hasB1 ? b1 : 0) << 8 | (hasB2 ? b2 : 0);
39
+ out += BASE64_CHARS[n >> 18 & 63];
40
+ out += BASE64_CHARS[n >> 12 & 63];
41
+ out += hasB1 ? BASE64_CHARS[n >> 6 & 63] : "=";
42
+ out += hasB2 ? BASE64_CHARS[n & 63] : "=";
43
+ }
44
+ return out;
45
+ }
46
+ function base64ToBytes(input) {
47
+ const clean = input.replace(/[^A-Za-z0-9+/=]/g, "");
48
+ const padded = clean.replace(/=+$/, "");
49
+ const len = padded.length;
50
+ const outLen = Math.floor(len * 3 / 4);
51
+ const out = new Uint8Array(outLen);
52
+ let p = 0;
53
+ for (let i = 0; i < len; i += 4) {
54
+ const c0 = BASE64_CHARS.indexOf(padded[i] ?? "A");
55
+ const c1 = BASE64_CHARS.indexOf(padded[i + 1] ?? "A");
56
+ const c2 = BASE64_CHARS.indexOf(padded[i + 2] ?? "A");
57
+ const c3 = BASE64_CHARS.indexOf(padded[i + 3] ?? "A");
58
+ const n = c0 << 18 | c1 << 12 | c2 << 6 | c3;
59
+ if (p < outLen) out[p++] = n >> 16 & 255;
60
+ if (p < outLen) out[p++] = n >> 8 & 255;
61
+ if (p < outLen) out[p++] = n & 255;
62
+ }
63
+ return out;
64
+ }
65
+
66
+ // src/share.ts
67
+ function createWebShareTransport(nav, fileCtor) {
68
+ return {
69
+ name: "web-share",
70
+ canShare(payload) {
71
+ if (!nav.share) return false;
72
+ if (!payload.screenshot) return true;
73
+ if (!fileCtor || !nav.canShare) return false;
74
+ try {
75
+ const f = new fileCtor(
76
+ [payload.screenshot.bytes],
77
+ "screenshot.png",
78
+ {
79
+ type: `image/${payload.screenshot.format}`
80
+ }
81
+ );
82
+ return nav.canShare({ files: [f] });
83
+ } catch {
84
+ return false;
85
+ }
86
+ },
87
+ async share(payload) {
88
+ if (!nav.share) return { dispatched: false, via: "web-share" };
89
+ const data = {};
90
+ if (payload.title !== void 0) data.title = payload.title;
91
+ if (payload.message !== void 0) data.text = payload.message;
92
+ if (payload.url !== void 0) data.url = payload.url;
93
+ if (payload.screenshot && fileCtor) {
94
+ const file = new fileCtor(
95
+ [payload.screenshot.bytes],
96
+ `screenshot.${payload.screenshot.format}`,
97
+ { type: `image/${payload.screenshot.format}` }
98
+ );
99
+ data.files = [file];
100
+ }
101
+ await nav.share(data);
102
+ return { dispatched: true, via: "web-share" };
103
+ }
104
+ };
105
+ }
106
+ function createWebClipboardTransport(nav) {
107
+ return {
108
+ name: "web-clipboard",
109
+ canShare(payload) {
110
+ return Boolean(nav.clipboard && (payload.url ?? payload.message));
111
+ },
112
+ async share(payload) {
113
+ if (!nav.clipboard) return { dispatched: false, via: "web-clipboard" };
114
+ const text = [payload.message, payload.url].filter((s) => Boolean(s)).join(" ");
115
+ if (text.length === 0) return { dispatched: false, via: "web-clipboard" };
116
+ await nav.clipboard.writeText(text);
117
+ return { dispatched: true, via: "web-clipboard" };
118
+ }
119
+ };
120
+ }
121
+ function createNativeShareTransport(rnShare) {
122
+ return {
123
+ name: "native",
124
+ canShare() {
125
+ return true;
126
+ },
127
+ async share(payload) {
128
+ const content = {};
129
+ if (payload.title !== void 0) content.title = payload.title;
130
+ if (payload.message !== void 0) content.message = payload.message;
131
+ if (payload.url !== void 0) content.url = payload.url;
132
+ const res = await rnShare.share(content);
133
+ return { dispatched: res.action !== "dismissed", via: "native" };
134
+ }
135
+ };
136
+ }
137
+ var ShareManager = class {
138
+ transports = [];
139
+ register(t) {
140
+ this.transports.push(t);
141
+ return this;
142
+ }
143
+ async share(payload) {
144
+ for (const t of this.transports) {
145
+ if (t.canShare(payload)) return t.share(payload);
146
+ }
147
+ return { dispatched: false, via: "noop" };
148
+ }
149
+ };
150
+
151
+ // src/screenshot-scene.ts
152
+ function createScreenshotScene(options) {
153
+ const { source, targets, setup, defaults } = options;
154
+ async function captureOne(target) {
155
+ if (setup) await setup(target);
156
+ const shot = captureScreenshot(source, {
157
+ format: target.format ?? defaults?.format,
158
+ quality: target.quality ?? defaults?.quality
159
+ });
160
+ if (!shot) return null;
161
+ return { target, screenshot: shot };
162
+ }
163
+ return {
164
+ targets,
165
+ async capture(id) {
166
+ for (let i = 0; i < targets.length; i++) {
167
+ const t = targets[i];
168
+ if (t && t.id === id) return captureOne(t);
169
+ }
170
+ return null;
171
+ },
172
+ async captureAll() {
173
+ const results = [];
174
+ for (let i = 0; i < targets.length; i++) {
175
+ const t = targets[i];
176
+ if (!t) continue;
177
+ const r = await captureOne(t);
178
+ if (r) results.push(r);
179
+ }
180
+ return results;
181
+ }
182
+ };
183
+ }
184
+ export {
185
+ ShareManager,
186
+ base64ToBytes,
187
+ bytesToBase64,
188
+ captureScreenshot,
189
+ createNativeShareTransport,
190
+ createScreenshotScene,
191
+ createWebClipboardTransport,
192
+ createWebShareTransport
193
+ };
194
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/capture.ts","../src/share.ts","../src/screenshot-scene.ts"],"sourcesContent":["/**\n * Cross-platform screenshot capture. The Flare renderer owns a Skia surface;\n * callers hand us a capturable reference + the target image format, and we\n * return a PNG/JPEG byte buffer plus a base64 encoding for sharing.\n */\n\nexport type ImageFormat = 'png' | 'jpeg';\n\nexport interface CaptureOptions {\n /** Output format, defaults to `png`. */\n format?: ImageFormat;\n /** JPEG quality (0–100). Ignored for PNG. Defaults to 90. */\n quality?: number;\n}\n\nexport interface Screenshot {\n bytes: Uint8Array;\n base64: string;\n format: ImageFormat;\n width: number;\n height: number;\n}\n\n/**\n * Minimal shape of a Skia image that exposes `encodeToBytes` (RN Skia) or\n * `encodeToBase64`. We only rely on one of these — the capture wrapper tries\n * bytes first and falls back.\n */\nexport interface SkiaImageLike {\n width(): number;\n height(): number;\n encodeToBytes?(format?: number, quality?: number): Uint8Array | null;\n encodeToBase64?(format?: number, quality?: number): string | null;\n}\n\n/** Source that yields the current Skia image for capture. */\nexport interface CaptureSource {\n makeImageSnapshot(): SkiaImageLike | null;\n}\n\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 3, jpeg: 2 };\n\nexport function captureScreenshot(\n source: CaptureSource,\n options: CaptureOptions = {},\n): Screenshot | null {\n const image = source.makeImageSnapshot();\n if (!image) return null;\n const format = options.format ?? 'png';\n const quality = options.quality ?? 90;\n const code = FORMAT_CODES[format];\n\n let bytes: Uint8Array | null = null;\n let base64: string | null = null;\n\n if (image.encodeToBytes) {\n bytes = image.encodeToBytes(code, quality) ?? null;\n }\n if (image.encodeToBase64) {\n base64 = image.encodeToBase64(code, quality) ?? null;\n }\n\n if (!bytes && !base64) return null;\n if (!bytes && base64) bytes = base64ToBytes(base64);\n if (!base64 && bytes) base64 = bytesToBase64(bytes);\n\n return {\n bytes: bytes as Uint8Array,\n base64: base64 as string,\n format,\n width: image.width(),\n height: image.height(),\n };\n}\n\n// --- base64 helpers (platform-agnostic, UTF-8 safe for binary) -------------\n\nconst BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nexport function bytesToBase64(bytes: Uint8Array): string {\n let out = '';\n const len = bytes.length;\n for (let i = 0; i < len; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1];\n const b2 = bytes[i + 2];\n const hasB1 = b1 !== undefined;\n const hasB2 = b2 !== undefined;\n const n = (b0 << 16) | ((hasB1 ? b1 : 0) << 8) | (hasB2 ? b2 : 0);\n out += BASE64_CHARS[(n >> 18) & 63];\n out += BASE64_CHARS[(n >> 12) & 63];\n out += hasB1 ? BASE64_CHARS[(n >> 6) & 63] : '=';\n out += hasB2 ? BASE64_CHARS[n & 63] : '=';\n }\n return out;\n}\n\nexport function base64ToBytes(input: string): Uint8Array {\n const clean = input.replace(/[^A-Za-z0-9+/=]/g, '');\n const padded = clean.replace(/=+$/, '');\n const len = padded.length;\n const outLen = Math.floor((len * 3) / 4);\n const out = new Uint8Array(outLen);\n let p = 0;\n for (let i = 0; i < len; i += 4) {\n const c0 = BASE64_CHARS.indexOf(padded[i] ?? 'A');\n const c1 = BASE64_CHARS.indexOf(padded[i + 1] ?? 'A');\n const c2 = BASE64_CHARS.indexOf(padded[i + 2] ?? 'A');\n const c3 = BASE64_CHARS.indexOf(padded[i + 3] ?? 'A');\n const n = (c0 << 18) | (c1 << 12) | (c2 << 6) | c3;\n if (p < outLen) out[p++] = (n >> 16) & 0xff;\n if (p < outLen) out[p++] = (n >> 8) & 0xff;\n if (p < outLen) out[p++] = n & 0xff;\n }\n return out;\n}\n","import type { Screenshot } from './capture.js';\n\nexport interface SharePayload {\n /** Short title shown by the share sheet (native). */\n title?: string;\n /** Message body (web fallback = clipboard, some native sheets show it). */\n message?: string;\n /** URL to share. */\n url?: string;\n /** Optional screenshot to share as an image attachment. */\n screenshot?: Screenshot;\n}\n\nexport interface ShareResult {\n /** Whether the share action was kicked off successfully. */\n dispatched: boolean;\n /** Name of the transport that handled the request. */\n via: 'web-share' | 'web-clipboard' | 'native' | 'noop';\n}\n\n/**\n * Platform adapter that knows how to hand a payload to the OS share sheet.\n * The host app picks an adapter based on its runtime (web vs iOS/Android).\n */\nexport interface ShareTransport {\n readonly name: ShareResult['via'];\n canShare(payload: SharePayload): boolean;\n share(payload: SharePayload): Promise<ShareResult>;\n}\n\n// ---------- Web Share API adapter -----------------------------------------\n\ninterface WebNavigatorLike {\n share?(data: { title?: string; text?: string; url?: string; files?: File[] }): Promise<void>;\n canShare?(data: { files?: File[] }): boolean;\n clipboard?: {\n writeText(text: string): Promise<void>;\n };\n}\n\ninterface FileCtorLike {\n new (parts: BlobPart[], name: string, options?: { type?: string }): File;\n}\n\nexport function createWebShareTransport(\n nav: WebNavigatorLike,\n fileCtor?: FileCtorLike,\n): ShareTransport {\n return {\n name: 'web-share',\n canShare(payload) {\n if (!nav.share) return false;\n if (!payload.screenshot) return true;\n if (!fileCtor || !nav.canShare) return false;\n try {\n const f = new fileCtor(\n [payload.screenshot.bytes as unknown as BlobPart],\n 'screenshot.png',\n {\n type: `image/${payload.screenshot.format}`,\n },\n );\n return nav.canShare({ files: [f] });\n } catch {\n return false;\n }\n },\n async share(payload) {\n if (!nav.share) return { dispatched: false, via: 'web-share' };\n const data: { title?: string; text?: string; url?: string; files?: File[] } = {};\n if (payload.title !== undefined) data.title = payload.title;\n if (payload.message !== undefined) data.text = payload.message;\n if (payload.url !== undefined) data.url = payload.url;\n if (payload.screenshot && fileCtor) {\n const file = new fileCtor(\n [payload.screenshot.bytes as unknown as BlobPart],\n `screenshot.${payload.screenshot.format}`,\n { type: `image/${payload.screenshot.format}` },\n );\n data.files = [file];\n }\n await nav.share(data);\n return { dispatched: true, via: 'web-share' };\n },\n };\n}\n\nexport function createWebClipboardTransport(nav: WebNavigatorLike): ShareTransport {\n return {\n name: 'web-clipboard',\n canShare(payload) {\n return Boolean(nav.clipboard && (payload.url ?? payload.message));\n },\n async share(payload) {\n if (!nav.clipboard) return { dispatched: false, via: 'web-clipboard' };\n const text = [payload.message, payload.url].filter((s): s is string => Boolean(s)).join(' ');\n if (text.length === 0) return { dispatched: false, via: 'web-clipboard' };\n await nav.clipboard.writeText(text);\n return { dispatched: true, via: 'web-clipboard' };\n },\n };\n}\n\n// ---------- Native (RN Share / expo-sharing-shaped) adapter ---------------\n\nexport interface NativeShareLike {\n share(content: { title?: string; message?: string; url?: string }): Promise<{ action?: string }>;\n}\n\nexport interface ExpoSharingLike {\n isAvailableAsync(): Promise<boolean>;\n shareAsync(uri: string, options?: { dialogTitle?: string; mimeType?: string }): Promise<void>;\n}\n\nexport function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport {\n return {\n name: 'native',\n canShare() {\n return true;\n },\n async share(payload) {\n const content: { title?: string; message?: string; url?: string } = {};\n if (payload.title !== undefined) content.title = payload.title;\n if (payload.message !== undefined) content.message = payload.message;\n if (payload.url !== undefined) content.url = payload.url;\n const res = await rnShare.share(content);\n return { dispatched: res.action !== 'dismissed', via: 'native' };\n },\n };\n}\n\n// ---------- Manager -------------------------------------------------------\n\nexport class ShareManager {\n private transports: ShareTransport[] = [];\n\n register(t: ShareTransport): this {\n this.transports.push(t);\n return this;\n }\n\n async share(payload: SharePayload): Promise<ShareResult> {\n for (const t of this.transports) {\n if (t.canShare(payload)) return t.share(payload);\n }\n return { dispatched: false, via: 'noop' };\n }\n}\n","/**\n * ScreenshotScene — controller for batch-capturing store-page screenshots\n * (Play, App Store, Steam) at fixed dimensions.\n *\n * The caller supplies a `CaptureSource` (typically the Skia surface driven\n * by the game's render loop) and a list of `ScreenshotTarget`s. An optional\n * `setup` hook runs before each capture — games use it to stage the camera,\n * mute HUD, pause the sim, etc.\n *\n * Extracted from Pan Tvardowski per Phase 11.14 (M9.6). Pure orchestration:\n * the pixel push is owned by the engine renderer; this module only decides\n * when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n type ImageFormat,\n type Screenshot,\n captureScreenshot,\n} from './capture.js';\n\nexport interface ScreenshotTarget {\n /** Stable id — used as the lookup key in `capture(id)`. */\n readonly id: string;\n /** Target width in pixels (store-spec). */\n readonly width: number;\n /** Target height in pixels (store-spec). */\n readonly height: number;\n /** Output format override. Defaults to the scene-level default. */\n readonly format?: ImageFormat;\n /** JPEG quality override. Defaults to the scene-level default. */\n readonly quality?: number;\n}\n\nexport interface ScreenshotResult {\n readonly target: ScreenshotTarget;\n readonly screenshot: Screenshot;\n}\n\nexport interface ScreenshotSceneOptions {\n /** Source of the current frame — exposes `makeImageSnapshot`. */\n readonly source: CaptureSource;\n /** Store-screenshot specs to capture. */\n readonly targets: readonly ScreenshotTarget[];\n /**\n * Called once before each capture. Typical uses: resize the render target,\n * position the camera, toggle HUD. May be async so callers can wait for a\n * next-frame settle (`await new Promise(queueMicrotask)`).\n */\n readonly setup?: (target: ScreenshotTarget) => void | Promise<void>;\n /** Default capture options — per-target values override. */\n readonly defaults?: CaptureOptions;\n}\n\nexport interface ScreenshotScene {\n readonly targets: readonly ScreenshotTarget[];\n /** Capture one target by id. Returns `null` if the id is unknown or capture failed. */\n capture(id: string): Promise<ScreenshotResult | null>;\n /** Capture every configured target in order. Skips failed captures. */\n captureAll(): Promise<readonly ScreenshotResult[]>;\n}\n\nexport function createScreenshotScene(options: ScreenshotSceneOptions): ScreenshotScene {\n const { source, targets, setup, defaults } = options;\n\n async function captureOne(target: ScreenshotTarget): Promise<ScreenshotResult | null> {\n if (setup) await setup(target);\n const shot = captureScreenshot(source, {\n format: target.format ?? defaults?.format,\n quality: target.quality ?? defaults?.quality,\n });\n if (!shot) return null;\n return { target, screenshot: shot };\n }\n\n return {\n targets,\n async capture(id) {\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i];\n if (t && t.id === id) return captureOne(t);\n }\n return null;\n },\n async captureAll() {\n const results: ScreenshotResult[] = [];\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i];\n if (!t) continue;\n const r = await captureOne(t);\n if (r) results.push(r);\n }\n return results;\n },\n };\n}\n"],"mappings":";AAwCA,IAAM,eAA4C,EAAE,KAAK,GAAG,MAAM,EAAE;AAE7D,S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A,aAAO;AAAA,IACT;AAAA,IACA,MAAM,aAAa;AACjB,YAAM,UAA8B,CAAC;AACrC,eAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,cAAM,IAAI,QAAQ,CAAC;AACnB,YAAI,CAAC,EAAG;AACR,cAAM,IAAI,MAAM,WAAW,CAAC;AAC5B,YAAI,EAAG,SAAQ,KAAK,CAAC;AAAA,MACvB;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@flare-engine/share",
3
+ "version": "0.1.0",
4
+ "description": "Screenshot capture + cross-platform share sheet",
5
+ "keywords": ["flare-engine", "share", "screenshot", "skia"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/share"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "publishConfig": {
35
+ "access": "restricted",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "sideEffects": false
39
+ }