@flare-engine/share 0.4.10 → 0.4.11
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 +12 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,10 +26,21 @@ const share = new ShareManager()
|
|
|
26
26
|
.register(createWebClipboardTransport(navigator));
|
|
27
27
|
|
|
28
28
|
if (shot) {
|
|
29
|
-
await share.share({ message: 'New high score!
|
|
29
|
+
await share.share({ message: 'New high score! https://example.com', screenshot: shot });
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
Platform notes:
|
|
34
|
+
|
|
35
|
+
- `createWebShareTransport` attaches the screenshot as a `File` when the browser's
|
|
36
|
+
`navigator.canShare({ files })` accepts it.
|
|
37
|
+
- `createNativeShareTransport` attaches it on iOS as a `data:image/<format>;base64,…` URL, only
|
|
38
|
+
when `url` is unset — an explicit `url` wins and no image is attached then. Android's RN `Share`
|
|
39
|
+
forwards only `title` and `message`, so put a link in `message`; the image is not attached there,
|
|
40
|
+
and a payload with a screenshot but no `message` opens an empty sheet that still reports
|
|
41
|
+
`dispatched: true`.
|
|
42
|
+
- `createWebClipboardTransport` copies `message` and `url` text only.
|
|
43
|
+
|
|
33
44
|
See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-engineshare--5kb-raw).
|
|
34
45
|
|
|
35
46
|
## License
|
package/dist/index.d.mts
CHANGED
|
@@ -80,7 +80,10 @@ interface SharePayload {
|
|
|
80
80
|
message?: string;
|
|
81
81
|
/** URL to share. */
|
|
82
82
|
url?: string;
|
|
83
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Optional screenshot to share as an image attachment. Web attaches it as a `File`; native
|
|
85
|
+
* attaches it on iOS only, and only when `url` is unset (see `createNativeShareTransport`).
|
|
86
|
+
*/
|
|
84
87
|
screenshot?: Screenshot;
|
|
85
88
|
}
|
|
86
89
|
interface ShareResult {
|
|
@@ -135,6 +138,13 @@ interface ExpoSharingLike {
|
|
|
135
138
|
mimeType?: string;
|
|
136
139
|
}): Promise<void>;
|
|
137
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a
|
|
143
|
+
* `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit
|
|
144
|
+
* `url` takes precedence and no image is attached then. Android's RN `Share` forwards only
|
|
145
|
+
* `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload
|
|
146
|
+
* with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.
|
|
147
|
+
*/
|
|
138
148
|
export declare function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport;
|
|
139
149
|
export declare class ShareManager {
|
|
140
150
|
private transports;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","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;;wBAOP,kBACd,QAAQ,eACR,UAAS,iBACR;wBAkCa,cAAc,OAAO;wBAkBrB,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;;U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;;;;;;;;wBAUlE,2BAA2B,SAAS,kBAAkB;qBAyBzD;UACH;EAER,SAAS,GAAG;EAKN,MAAM,SAAS,eAAe,QAAQ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,10 @@ interface SharePayload {
|
|
|
80
80
|
message?: string;
|
|
81
81
|
/** URL to share. */
|
|
82
82
|
url?: string;
|
|
83
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Optional screenshot to share as an image attachment. Web attaches it as a `File`; native
|
|
85
|
+
* attaches it on iOS only, and only when `url` is unset (see `createNativeShareTransport`).
|
|
86
|
+
*/
|
|
84
87
|
screenshot?: Screenshot;
|
|
85
88
|
}
|
|
86
89
|
interface ShareResult {
|
|
@@ -135,6 +138,13 @@ interface ExpoSharingLike {
|
|
|
135
138
|
mimeType?: string;
|
|
136
139
|
}): Promise<void>;
|
|
137
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a
|
|
143
|
+
* `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit
|
|
144
|
+
* `url` takes precedence and no image is attached then. Android's RN `Share` forwards only
|
|
145
|
+
* `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload
|
|
146
|
+
* with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.
|
|
147
|
+
*/
|
|
138
148
|
export declare function createNativeShareTransport(rnShare: NativeShareLike): ShareTransport;
|
|
139
149
|
export declare class ShareManager {
|
|
140
150
|
private transports;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,iBA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E,UAAU;IAAQ,QAAQ;;EAC1B;IACE,UAAU,eAAe;;;UAIZ;OACV,OAAO,YAAY,cAAc;IAAY;MAAkB;;wBAGtD,wBACd,KAAK,kBACL,WAAW,eACV;wBAwCa,4BAA4B,KAAK,mBAAmB;UAkBnD;EACf,MAAM;IAAW;IAAgB;IAAkB;MAAiB;IAAU;;;UAG/D;EACf,oBAAoB;EACpB,WAAW,aAAa;IAAY;IAAsB;MAAsB;;;;;;;;;wBAUlE,2BAA2B,SAAS,kBAAkB;qBAyBzD;UACH;EAER,SAAS,GAAG;EAKN,MAAM,SAAS,eAAe,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -166,6 +166,13 @@ function createWebClipboardTransport(nav) {
|
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a
|
|
171
|
+
* `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit
|
|
172
|
+
* `url` takes precedence and no image is attached then. Android's RN `Share` forwards only
|
|
173
|
+
* `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload
|
|
174
|
+
* with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.
|
|
175
|
+
*/
|
|
169
176
|
function createNativeShareTransport(rnShare) {
|
|
170
177
|
return {
|
|
171
178
|
name: "native",
|
|
@@ -177,6 +184,10 @@ function createNativeShareTransport(rnShare) {
|
|
|
177
184
|
if (payload.title !== void 0) content.title = payload.title;
|
|
178
185
|
if (payload.message !== void 0) content.message = payload.message;
|
|
179
186
|
if (payload.url !== void 0) content.url = payload.url;
|
|
187
|
+
else if (payload.screenshot !== void 0) {
|
|
188
|
+
const { format, base64 } = payload.screenshot;
|
|
189
|
+
content.url = `data:image/${format};base64,${base64}`;
|
|
190
|
+
}
|
|
180
191
|
return {
|
|
181
192
|
dispatched: (await rnShare.share(content)).action === "sharedAction",
|
|
182
193
|
via: "native"
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/capture.ts","../src/screenshot-scene.ts","../src/share.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\n// Must equal RN-Skia's ImageFormat enum: JPEG=3, PNG=4, WEBP=6\n// (@shopify/react-native-skia 2.4.18). Locked by the contract test in capture.test.ts.\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 4, jpeg: 3 };\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","/**\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 * Pure orchestration: the pixel push is owned by the engine renderer; this\n * module only decides when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n captureScreenshot,\n type ImageFormat,\n type Screenshot,\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","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\nexport interface 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\nexport interface 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.${payload.screenshot.format}`,\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 // RN Share resolves to Share.sharedAction ('sharedAction') or\n // Share.dismissedAction ('dismissedAction') — never a bare 'dismissed'.\n return { dispatched: res.action === 'sharedAction', 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"],"mappings":";;AA0CA,MAAM,eAA4C;CAAE,KAAK;CAAG,MAAM;AAAE;AAEpE,SAAgB,kBACd,QACA,UAA0B,CAAC,GACR;CACnB,MAAM,QAAQ,OAAO,kBAAkB;CACvC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,aAAa;CAE1B,IAAI,QAA2B;CAC/B,IAAI,SAAwB;CAE5B,IAAI,MAAM,eACR,QAAQ,MAAM,cAAc,MAAM,OAAO,KAAK;CAEhD,IAAI,MAAM,gBACR,SAAS,MAAM,eAAe,MAAM,OAAO,KAAK;CAGlD,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;CAC9B,IAAI,CAAC,SAAS,QAAQ,QAAQ,cAAc,MAAM;CAClD,IAAI,CAAC,UAAU,OAAO,SAAS,cAAc,KAAK;CAElD,OAAO;EACE;EACC;EACR;EACA,OAAO,MAAM,MAAM;EACnB,QAAQ,MAAM,OAAO;CACvB;AACF;AAIA,MAAM,eAAe;AAErB,SAAgB,cAAc,OAA2B;CACvD,IAAI,MAAM;CACV,MAAM,MAAM,MAAM;CAClB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK,GAAG;EAC/B,MAAM,KAAK,MAAM,MAAM;EACvB,MAAM,KAAK,MAAM,IAAI;EACrB,MAAM,KAAK,MAAM,IAAI;EACrB,MAAM,QAAQ,OAAO,KAAA;EACrB,MAAM,QAAQ,OAAO,KAAA;EACrB,MAAM,IAAK,MAAM,MAAQ,QAAQ,KAAK,MAAM,KAAM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,MAAM,SAA6C;EACvD,KAAK,MAAM,KAAK,KAAK,YACnB,IAAI,EAAE,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,OAAO;EAEjD,OAAO;GAAE,YAAY;GAAO,KAAK;EAAO;CAC1C;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/capture.ts","../src/screenshot-scene.ts","../src/share.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\n// Must equal RN-Skia's ImageFormat enum: JPEG=3, PNG=4, WEBP=6\n// (@shopify/react-native-skia 2.4.18). Locked by the contract test in capture.test.ts.\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 4, jpeg: 3 };\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","/**\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 * Pure orchestration: the pixel push is owned by the engine renderer; this\n * module only decides when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n captureScreenshot,\n type ImageFormat,\n type Screenshot,\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","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 /**\n * Optional screenshot to share as an image attachment. Web attaches it as a `File`; native\n * attaches it on iOS only, and only when `url` is unset (see `createNativeShareTransport`).\n */\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\nexport interface 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\nexport interface 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.${payload.screenshot.format}`,\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\n/**\n * Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a\n * `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit\n * `url` takes precedence and no image is attached then. Android's RN `Share` forwards only\n * `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload\n * with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.\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 else if (payload.screenshot !== undefined) {\n const { format, base64 } = payload.screenshot;\n content.url = `data:image/${format};base64,${base64}`;\n }\n const res = await rnShare.share(content);\n // RN Share resolves to Share.sharedAction ('sharedAction') or\n // Share.dismissedAction ('dismissedAction') — never a bare 'dismissed'.\n return { dispatched: res.action === 'sharedAction', 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"],"mappings":";;AA0CA,MAAM,eAA4C;CAAE,KAAK;CAAG,MAAM;AAAE;AAEpE,SAAgB,kBACd,QACA,UAA0B,CAAC,GACR;CACnB,MAAM,QAAQ,OAAO,kBAAkB;CACvC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,aAAa;CAE1B,IAAI,QAA2B;CAC/B,IAAI,SAAwB;CAE5B,IAAI,MAAM,eACR,QAAQ,MAAM,cAAc,MAAM,OAAO,KAAK;CAEhD,IAAI,MAAM,gBACR,SAAS,MAAM,eAAe,MAAM,OAAO,KAAK;CAGlD,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;CAC9B,IAAI,CAAC,SAAS,QAAQ,QAAQ,c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C;CACnF,OAAO;EACL,MAAM;EACN,WAAW;GACT,OAAO;EACT;EACA,MAAM,MAAM,SAAS;GACnB,MAAM,UAA8D,CAAC;GACrE,IAAI,QAAQ,UAAU,KAAA,GAAW,QAAQ,QAAQ,QAAQ;GACzD,IAAI,QAAQ,YAAY,KAAA,GAAW,QAAQ,UAAU,QAAQ;GAC7D,IAAI,QAAQ,QAAQ,KAAA,GAAW,QAAQ,MAAM,QAAQ;QAChD,IAAI,QAAQ,eAAe,KAAA,GAAW;IACzC,MAAM,EAAE,QAAQ,WAAW,QAAQ;IACnC,QAAQ,MAAM,cAAc,OAAO,UAAU;GAC/C;GAIA,OAAO;IAAE,aAAY,MAHH,QAAQ,MAAM,OAAO,EAAA,CAGd,WAAW;IAAgB,KAAK;GAAS;EACpE;CACF;AACF;AAIA,IAAa,eAAb,MAA0B;CACxB,aAAuC,CAAC;CAExC,SAAS,GAAyB;EAChC,KAAK,WAAW,KAAK,CAAC;EACtB,OAAO;CACT;CAEA,MAAM,MAAM,SAA6C;EACvD,KAAK,MAAM,KAAK,KAAK,YACnB,IAAI,EAAE,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,OAAO;EAEjD,OAAO;GAAE,YAAY;GAAO,KAAK;EAAO;CAC1C;AACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -165,6 +165,13 @@ function createWebClipboardTransport(nav) {
|
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a
|
|
170
|
+
* `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit
|
|
171
|
+
* `url` takes precedence and no image is attached then. Android's RN `Share` forwards only
|
|
172
|
+
* `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload
|
|
173
|
+
* with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.
|
|
174
|
+
*/
|
|
168
175
|
function createNativeShareTransport(rnShare) {
|
|
169
176
|
return {
|
|
170
177
|
name: "native",
|
|
@@ -176,6 +183,10 @@ function createNativeShareTransport(rnShare) {
|
|
|
176
183
|
if (payload.title !== void 0) content.title = payload.title;
|
|
177
184
|
if (payload.message !== void 0) content.message = payload.message;
|
|
178
185
|
if (payload.url !== void 0) content.url = payload.url;
|
|
186
|
+
else if (payload.screenshot !== void 0) {
|
|
187
|
+
const { format, base64 } = payload.screenshot;
|
|
188
|
+
content.url = `data:image/${format};base64,${base64}`;
|
|
189
|
+
}
|
|
179
190
|
return {
|
|
180
191
|
dispatched: (await rnShare.share(content)).action === "sharedAction",
|
|
181
192
|
via: "native"
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/capture.ts","../src/screenshot-scene.ts","../src/share.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\n// Must equal RN-Skia's ImageFormat enum: JPEG=3, PNG=4, WEBP=6\n// (@shopify/react-native-skia 2.4.18). Locked by the contract test in capture.test.ts.\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 4, jpeg: 3 };\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","/**\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 * Pure orchestration: the pixel push is owned by the engine renderer; this\n * module only decides when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n captureScreenshot,\n type ImageFormat,\n type Screenshot,\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","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\nexport interface 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\nexport interface 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.${payload.screenshot.format}`,\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 // RN Share resolves to Share.sharedAction ('sharedAction') or\n // Share.dismissedAction ('dismissedAction') — never a bare 'dismissed'.\n return { dispatched: res.action === 'sharedAction', 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"],"mappings":";AA0CA,MAAM,eAA4C;CAAE,KAAK;CAAG,MAAM;AAAE;AAEpE,SAAgB,kBACd,QACA,UAA0B,CAAC,GACR;CACnB,MAAM,QAAQ,OAAO,kBAAkB;CACvC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,aAAa;CAE1B,IAAI,QAA2B;CAC/B,IAAI,SAAwB;CAE5B,IAAI,MAAM,eACR,QAAQ,MAAM,cAAc,MAAM,OAAO,KAAK;CAEhD,IAAI,MAAM,gBACR,SAAS,MAAM,eAAe,MAAM,OAAO,KAAK;CAGlD,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;CAC9B,IAAI,CAAC,SAAS,QAAQ,QAAQ,cAAc,MAAM;CAClD,IAAI,CAAC,UAAU,OAAO,SAAS,cAAc,KAAK;CAElD,OAAO;EACE;EACC;EACR;EAC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AC;GACrE,IAAI,QAAQ,UAAU,KAAA,GAAW,QAAQ,QAAQ,QAAQ;GACzD,IAAI,QAAQ,YAAY,KAAA,GAAW,QAAQ,UAAU,QAAQ;GAC7D,IAAI,QAAQ,QAAQ,KAAA,GAAW,QAAQ,MAAM,QAAQ;GAIrD,OAAO;IAAE,aAAY,MAHH,QAAQ,MAAM,OAAO,EAAA,CAGd,WAAW;IAAgB,KAAK;GAAS;EACpE;CACF;AACF;AAIA,IAAa,eAAb,MAA0B;CACxB,aAAuC,CAAC;CAExC,SAAS,GAAyB;EAChC,KAAK,WAAW,KAAK,CAAC;EACtB,OAAO;CACT;CAEA,MAAM,MAAM,SAA6C;EACvD,KAAK,MAAM,KAAK,KAAK,YACnB,IAAI,EAAE,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,OAAO;EAEjD,OAAO;GAAE,YAAY;GAAO,KAAK;EAAO;CAC1C;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/capture.ts","../src/screenshot-scene.ts","../src/share.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\n// Must equal RN-Skia's ImageFormat enum: JPEG=3, PNG=4, WEBP=6\n// (@shopify/react-native-skia 2.4.18). Locked by the contract test in capture.test.ts.\nconst FORMAT_CODES: Record<ImageFormat, number> = { png: 4, jpeg: 3 };\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","/**\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 * Pure orchestration: the pixel push is owned by the engine renderer; this\n * module only decides when and at what size to call `makeImageSnapshot`.\n */\n\nimport {\n type CaptureOptions,\n type CaptureSource,\n captureScreenshot,\n type ImageFormat,\n type Screenshot,\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","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 /**\n * Optional screenshot to share as an image attachment. Web attaches it as a `File`; native\n * attaches it on iOS only, and only when `url` is unset (see `createNativeShareTransport`).\n */\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\nexport interface 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\nexport interface 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.${payload.screenshot.format}`,\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\n/**\n * Wraps an RN `Share`-shaped module. When `url` is unset, a `screenshot` goes out as a\n * `data:image/<format>;base64,…` URL, which iOS's share sheet attaches as the image; an explicit\n * `url` takes precedence and no image is attached then. Android's RN `Share` forwards only\n * `title` and `message`, so there neither `url` nor the screenshot reaches the sheet: a payload\n * with a screenshot and no `message` opens an empty sheet and still reports `dispatched: true`.\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 else if (payload.screenshot !== undefined) {\n const { format, base64 } = payload.screenshot;\n content.url = `data:image/${format};base64,${base64}`;\n }\n const res = await rnShare.share(content);\n // RN Share resolves to Share.sharedAction ('sharedAction') or\n // Share.dismissedAction ('dismissedAction') — never a bare 'dismissed'.\n return { dispatched: res.action === 'sharedAction', 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"],"mappings":";AA0CA,MAAM,eAA4C;CAAE,KAAK;CAAG,MAAM;AAAE;AAEpE,SAAgB,kBACd,QACA,UAA0B,CAA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
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/share",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"description": "Screenshot capture + cross-platform share sheet",
|
|
5
5
|
"keywords": ["flare-engine", "share", "screenshot", "skia", "react-native", "typescript"],
|
|
6
6
|
"license": "Apache-2.0",
|