@snap/react-camera-kit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +37 -0
- package/README.md +130 -0
- package/dist/cjs/CameraKitProvider.d.ts +203 -0
- package/dist/cjs/CameraKitProvider.d.ts.map +1 -0
- package/dist/cjs/CameraKitProvider.js +542 -0
- package/dist/cjs/CameraKitProvider.js.map +1 -0
- package/dist/cjs/Canvas.d.ts +7 -0
- package/dist/cjs/Canvas.d.ts.map +1 -0
- package/dist/cjs/Canvas.js +50 -0
- package/dist/cjs/Canvas.js.map +1 -0
- package/dist/cjs/LensPlayer.d.ts +101 -0
- package/dist/cjs/LensPlayer.d.ts.map +1 -0
- package/dist/cjs/LensPlayer.js +67 -0
- package/dist/cjs/LensPlayer.js.map +1 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internal/bootstrapUtils.d.ts +13 -0
- package/dist/cjs/internal/bootstrapUtils.d.ts.map +1 -0
- package/dist/cjs/internal/bootstrapUtils.js +29 -0
- package/dist/cjs/internal/bootstrapUtils.js.map +1 -0
- package/dist/cjs/internal/error.d.ts +2 -0
- package/dist/cjs/internal/error.d.ts.map +1 -0
- package/dist/cjs/internal/error.js +30 -0
- package/dist/cjs/internal/error.js.map +1 -0
- package/dist/cjs/internal/isMobile.d.ts +5 -0
- package/dist/cjs/internal/isMobile.d.ts.map +1 -0
- package/dist/cjs/internal/isMobile.js +15 -0
- package/dist/cjs/internal/isMobile.js.map +1 -0
- package/dist/cjs/internal/logging.d.ts +40 -0
- package/dist/cjs/internal/logging.d.ts.map +1 -0
- package/dist/cjs/internal/logging.js +63 -0
- package/dist/cjs/internal/logging.js.map +1 -0
- package/dist/cjs/internal/metrics.d.ts +29 -0
- package/dist/cjs/internal/metrics.d.ts.map +1 -0
- package/dist/cjs/internal/metrics.js +128 -0
- package/dist/cjs/internal/metrics.js.map +1 -0
- package/dist/cjs/internal/sessionUtils.d.ts +3 -0
- package/dist/cjs/internal/sessionUtils.d.ts.map +1 -0
- package/dist/cjs/internal/sessionUtils.js +17 -0
- package/dist/cjs/internal/sessionUtils.js.map +1 -0
- package/dist/cjs/internal/sourceUtils.d.ts +22 -0
- package/dist/cjs/internal/sourceUtils.d.ts.map +1 -0
- package/dist/cjs/internal/sourceUtils.js +143 -0
- package/dist/cjs/internal/sourceUtils.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +96 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +26 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/useApplyLens.d.ts +25 -0
- package/dist/cjs/useApplyLens.d.ts.map +1 -0
- package/dist/cjs/useApplyLens.js +87 -0
- package/dist/cjs/useApplyLens.js.map +1 -0
- package/dist/cjs/useApplySource.d.ts +11 -0
- package/dist/cjs/useApplySource.d.ts.map +1 -0
- package/dist/cjs/useApplySource.js +66 -0
- package/dist/cjs/useApplySource.js.map +1 -0
- package/dist/cjs/usePlaybackOptions.d.ts +38 -0
- package/dist/cjs/usePlaybackOptions.d.ts.map +1 -0
- package/dist/cjs/usePlaybackOptions.js +51 -0
- package/dist/cjs/usePlaybackOptions.js.map +1 -0
- package/dist/cjs/version.d.ts +3 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +6 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/CameraKitProvider.d.ts +203 -0
- package/dist/esm/CameraKitProvider.d.ts.map +1 -0
- package/dist/esm/CameraKitProvider.js +533 -0
- package/dist/esm/CameraKitProvider.js.map +1 -0
- package/dist/esm/Canvas.d.ts +7 -0
- package/dist/esm/Canvas.d.ts.map +1 -0
- package/dist/esm/Canvas.js +45 -0
- package/dist/esm/Canvas.js.map +1 -0
- package/dist/esm/LensPlayer.d.ts +101 -0
- package/dist/esm/LensPlayer.d.ts.map +1 -0
- package/dist/esm/LensPlayer.js +63 -0
- package/dist/esm/LensPlayer.js.map +1 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/bootstrapUtils.d.ts +13 -0
- package/dist/esm/internal/bootstrapUtils.d.ts.map +1 -0
- package/dist/esm/internal/bootstrapUtils.js +26 -0
- package/dist/esm/internal/bootstrapUtils.js.map +1 -0
- package/dist/esm/internal/error.d.ts +2 -0
- package/dist/esm/internal/error.d.ts.map +1 -0
- package/dist/esm/internal/error.js +27 -0
- package/dist/esm/internal/error.js.map +1 -0
- package/dist/esm/internal/isMobile.d.ts +5 -0
- package/dist/esm/internal/isMobile.d.ts.map +1 -0
- package/dist/esm/internal/isMobile.js +12 -0
- package/dist/esm/internal/isMobile.js.map +1 -0
- package/dist/esm/internal/logging.d.ts +40 -0
- package/dist/esm/internal/logging.d.ts.map +1 -0
- package/dist/esm/internal/logging.js +58 -0
- package/dist/esm/internal/logging.js.map +1 -0
- package/dist/esm/internal/metrics.d.ts +29 -0
- package/dist/esm/internal/metrics.d.ts.map +1 -0
- package/dist/esm/internal/metrics.js +91 -0
- package/dist/esm/internal/metrics.js.map +1 -0
- package/dist/esm/internal/sessionUtils.d.ts +3 -0
- package/dist/esm/internal/sessionUtils.d.ts.map +1 -0
- package/dist/esm/internal/sessionUtils.js +14 -0
- package/dist/esm/internal/sessionUtils.js.map +1 -0
- package/dist/esm/internal/sourceUtils.d.ts +22 -0
- package/dist/esm/internal/sourceUtils.d.ts.map +1 -0
- package/dist/esm/internal/sourceUtils.js +139 -0
- package/dist/esm/internal/sourceUtils.js.map +1 -0
- package/dist/esm/types.d.ts +96 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/useApplyLens.d.ts +25 -0
- package/dist/esm/useApplyLens.d.ts.map +1 -0
- package/dist/esm/useApplyLens.js +81 -0
- package/dist/esm/useApplyLens.js.map +1 -0
- package/dist/esm/useApplySource.d.ts +11 -0
- package/dist/esm/useApplySource.d.ts.map +1 -0
- package/dist/esm/useApplySource.js +60 -0
- package/dist/esm/useApplySource.js.map +1 -0
- package/dist/esm/usePlaybackOptions.d.ts +38 -0
- package/dist/esm/usePlaybackOptions.d.ts.map +1 -0
- package/dist/esm/usePlaybackOptions.js +48 -0
- package/dist/esm/usePlaybackOptions.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CaptureCanvas = exports.LiveCanvas = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const CameraKitProvider_1 = require("./CameraKitProvider");
|
|
7
|
+
// --- Internal helper hookup -------------------------------------------------
|
|
8
|
+
function attachCanvas(container, canvas) {
|
|
9
|
+
if (!container.contains(canvas))
|
|
10
|
+
container.appendChild(canvas);
|
|
11
|
+
}
|
|
12
|
+
function detachCanvas(container, canvas) {
|
|
13
|
+
if (container?.contains(canvas))
|
|
14
|
+
container.removeChild(canvas);
|
|
15
|
+
}
|
|
16
|
+
// --- Live child -------------------------------------------------------------
|
|
17
|
+
const LiveCanvas = ({ className, style }) => {
|
|
18
|
+
const { currentSession } = (0, CameraKitProvider_1.useInternalCameraKit)();
|
|
19
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
if (!currentSession || !containerRef.current)
|
|
22
|
+
return;
|
|
23
|
+
attachCanvas(containerRef.current, currentSession.output.live);
|
|
24
|
+
currentSession.play("live");
|
|
25
|
+
return () => {
|
|
26
|
+
detachCanvas(containerRef.current, currentSession.output.live);
|
|
27
|
+
currentSession.pause("live");
|
|
28
|
+
};
|
|
29
|
+
}, [currentSession]);
|
|
30
|
+
return (0, jsx_runtime_1.jsx)("div", { ref: containerRef, className: className, style: style });
|
|
31
|
+
};
|
|
32
|
+
exports.LiveCanvas = LiveCanvas;
|
|
33
|
+
// --- Capture child ----------------------------------------------------------
|
|
34
|
+
const CaptureCanvas = ({ className, style }) => {
|
|
35
|
+
const { currentSession } = (0, CameraKitProvider_1.useInternalCameraKit)();
|
|
36
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
37
|
+
(0, react_1.useEffect)(() => {
|
|
38
|
+
if (!currentSession || !containerRef.current)
|
|
39
|
+
return;
|
|
40
|
+
attachCanvas(containerRef.current, currentSession.output.capture);
|
|
41
|
+
currentSession.play("capture");
|
|
42
|
+
return () => {
|
|
43
|
+
detachCanvas(containerRef.current, currentSession.output.capture);
|
|
44
|
+
currentSession.pause("capture");
|
|
45
|
+
};
|
|
46
|
+
}, [currentSession]);
|
|
47
|
+
return (0, jsx_runtime_1.jsx)("div", { ref: containerRef, className: className, style: style });
|
|
48
|
+
};
|
|
49
|
+
exports.CaptureCanvas = CaptureCanvas;
|
|
50
|
+
//# sourceMappingURL=Canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../../src/Canvas.tsx"],"names":[],"mappings":";;;;AAAA,iCAA0C;AAC1C,2DAA2D;AAO3D,+EAA+E;AAC/E,SAAS,YAAY,CAAC,SAAsB,EAAE,MAAyB;IACrE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,YAAY,CAAC,SAA6B,EAAE,MAAyB;IAC5E,IAAI,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC;QAAE,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAED,+EAA+E;AACxE,MAAM,UAAU,GAA+B,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;IAC7E,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,wCAAoB,GAAE,CAAC;IAClD,MAAM,YAAY,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAElD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,cAAc,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,OAAO;QAErD,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/D,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE5B,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/D,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,OAAO,gCAAK,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;AACxE,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB;AAEF,+EAA+E;AACxE,MAAM,aAAa,GAA+B,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;IAChF,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,wCAAoB,GAAE,CAAC;IAClD,MAAM,YAAY,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAElD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,cAAc,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,OAAO;QAErD,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClE,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE/B,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,YAAY,CAAC,OAAQ,EAAE,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACnE,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,OAAO,gCAAK,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;AACxE,CAAC,CAAC;AAjBW,QAAA,aAAa,iBAiBxB","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useInternalCameraKit } from \"./CameraKitProvider\";\n\nexport interface CanvasChildProps {\n className?: string;\n style?: React.CSSProperties;\n}\n\n// --- Internal helper hookup -------------------------------------------------\nfunction attachCanvas(container: HTMLElement, canvas: HTMLCanvasElement) {\n if (!container.contains(canvas)) container.appendChild(canvas);\n}\n\nfunction detachCanvas(container: HTMLElement | null, canvas: HTMLCanvasElement) {\n if (container?.contains(canvas)) container.removeChild(canvas);\n}\n\n// --- Live child -------------------------------------------------------------\nexport const LiveCanvas: React.FC<CanvasChildProps> = ({ className, style }) => {\n const { currentSession } = useInternalCameraKit();\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!currentSession || !containerRef.current) return;\n\n attachCanvas(containerRef.current, currentSession.output.live);\n currentSession.play(\"live\");\n\n return () => {\n detachCanvas(containerRef.current, currentSession.output.live);\n currentSession.pause(\"live\");\n };\n }, [currentSession]);\n\n return <div ref={containerRef} className={className} style={style} />;\n};\n\n// --- Capture child ----------------------------------------------------------\nexport const CaptureCanvas: React.FC<CanvasChildProps> = ({ className, style }) => {\n const { currentSession } = useInternalCameraKit();\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!currentSession || !containerRef.current) return;\n\n attachCanvas(containerRef.current, currentSession.output.capture);\n currentSession.play(\"capture\");\n\n return () => {\n detachCanvas(containerRef.current!, currentSession.output.capture);\n currentSession.pause(\"capture\");\n };\n }, [currentSession]);\n\n return <div ref={containerRef} className={className} style={style} />;\n};\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { CameraKitSessionEvents, Lens, LensLaunchData, ScreenRegions } from "@snap/camera-kit";
|
|
3
|
+
import { CanvasType, OutputSize, SourceInput } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Props for the LensPlayer component.
|
|
6
|
+
*/
|
|
7
|
+
export interface LensPlayerProps {
|
|
8
|
+
/** The media source to apply (camera, video, or image). Defaults to camera if not specified. */
|
|
9
|
+
source?: SourceInput;
|
|
10
|
+
/** Optional output size configuration for the rendering canvas. */
|
|
11
|
+
outputSize?: OutputSize;
|
|
12
|
+
/** The unique identifier of the Lens to apply. */
|
|
13
|
+
lensId?: string;
|
|
14
|
+
/** The group ID containing the Lens. Required when lensId is provided. */
|
|
15
|
+
lensGroupId?: string;
|
|
16
|
+
/** Optional launch parameters to pass to the Lens.. */
|
|
17
|
+
lensLaunchData?: LensLaunchData;
|
|
18
|
+
/** Optional async guard that must resolve before the Lens is considered ready.
|
|
19
|
+
* The guard is called when the lens is in loading state,
|
|
20
|
+
* and when the promise returned by the function resolves, it will transition to the ready state.
|
|
21
|
+
* If the promise doesn't resolve within 2 seconds, the ready state is forced. */
|
|
22
|
+
lensReadyGuard?: () => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Trigger to refresh the current Lens. When this value changes,
|
|
25
|
+
* the Lens will be removed and reapplied. Useful for restarting
|
|
26
|
+
* the Lens experience without moving LensPlayer to another component.
|
|
27
|
+
*/
|
|
28
|
+
refreshTrigger?: unknown;
|
|
29
|
+
/** Which canvas to render: "live" for real-time preview or "capture" for snapshot. Defaults to "live". */
|
|
30
|
+
canvasType?: CanvasType;
|
|
31
|
+
/**
|
|
32
|
+
* A maximum FPS, rendering will not exceed this limit.
|
|
33
|
+
*
|
|
34
|
+
* This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example,
|
|
35
|
+
* the input media source has a low FPS – CameraKit would then not try to render more
|
|
36
|
+
* frequently than the source produces new frames.
|
|
37
|
+
*
|
|
38
|
+
* This may also be useful to gracefully degrade performance in situations where
|
|
39
|
+
* lowering FPS is preferable over alternatives.
|
|
40
|
+
*/
|
|
41
|
+
fpsLimit?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to mute all sounds. Unmuted by default.
|
|
44
|
+
*/
|
|
45
|
+
muted?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Configuration object containing the current set of screen regions.
|
|
48
|
+
*
|
|
49
|
+
* Screen regions define areas of the screen that have special meaning for Lens rendering,
|
|
50
|
+
* such as safe rendering areas, UI button locations, keyboard areas, etc. This allows lenses
|
|
51
|
+
* to adapt their content placement based on the host application's UI layout.
|
|
52
|
+
*/
|
|
53
|
+
screenRegions?: ScreenRegions;
|
|
54
|
+
/**
|
|
55
|
+
* A callback to handle Lens playback errors.
|
|
56
|
+
*/
|
|
57
|
+
onError?: (error: CameraKitSessionEvents["detail"]["error"], lens: Lens) => void;
|
|
58
|
+
/** CSS class name to apply to the wrapper or canvas element. */
|
|
59
|
+
className?: string;
|
|
60
|
+
/** Inline styles to apply to the wrapper or canvas element. */
|
|
61
|
+
style?: React.CSSProperties;
|
|
62
|
+
/** Custom children to render instead of the default canvas. When provided, children are wrapped in a styled div. */
|
|
63
|
+
children?: ReactNode;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A declarative, all-in-one component for rendering Camera Kit Lenses.
|
|
67
|
+
*
|
|
68
|
+
* LensPlayer combines source management, lens application, and playback controls into a single
|
|
69
|
+
* component. It handles the complexity of coordinating multiple hooks and provides a simple
|
|
70
|
+
* prop-based API for common use cases.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* // Basic lens player with camera source
|
|
75
|
+
* <LensPlayer lensId="lens-123" lensGroupId="my-group" />
|
|
76
|
+
*
|
|
77
|
+
* // With custom source and output size
|
|
78
|
+
* <LensPlayer
|
|
79
|
+
* source={{ kind: "video", element: videoElement }}
|
|
80
|
+
* outputSize={{ mode: "fixed", width: 1280, height: 720 }}
|
|
81
|
+
* lensId="lens-123"
|
|
82
|
+
* lensGroupId="my-group"
|
|
83
|
+
* />
|
|
84
|
+
*
|
|
85
|
+
* // With playback controls and error handling
|
|
86
|
+
* <LensPlayer
|
|
87
|
+
* lensId="lens-123"
|
|
88
|
+
* lensGroupId="my-group"
|
|
89
|
+
* fpsLimit={30}
|
|
90
|
+
* muted={true}
|
|
91
|
+
* onError={(error) => console.error("Playback error:", error)}
|
|
92
|
+
* />
|
|
93
|
+
*
|
|
94
|
+
* // With custom children instead of default canvas
|
|
95
|
+
* <LensPlayer lensId="lens-123" lensGroupId="my-group">
|
|
96
|
+
* <div>Custom UI overlaying the Lens <LiveCanvas /></div>
|
|
97
|
+
* </LensPlayer>
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare const LensPlayer: React.FC<LensPlayerProps>;
|
|
101
|
+
//# sourceMappingURL=LensPlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LensPlayer.d.ts","sourceRoot":"","sources":["../../src/LensPlayer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAO9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,gGAAgG;IAChG,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB,mEAAmE;IACnE,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,uDAAuD;IACvD,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;qFAGiF;IACjF,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAErC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAEjF,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B,oHAAoH;IACpH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA8ChD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LensPlayer = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const useApplySource_1 = require("./useApplySource");
|
|
7
|
+
const useApplyLens_1 = require("./useApplyLens");
|
|
8
|
+
const usePlaybackOptions_1 = require("./usePlaybackOptions");
|
|
9
|
+
const Canvas_1 = require("./Canvas");
|
|
10
|
+
const CameraKitProvider_1 = require("./CameraKitProvider");
|
|
11
|
+
/**
|
|
12
|
+
* A declarative, all-in-one component for rendering Camera Kit Lenses.
|
|
13
|
+
*
|
|
14
|
+
* LensPlayer combines source management, lens application, and playback controls into a single
|
|
15
|
+
* component. It handles the complexity of coordinating multiple hooks and provides a simple
|
|
16
|
+
* prop-based API for common use cases.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* // Basic lens player with camera source
|
|
21
|
+
* <LensPlayer lensId="lens-123" lensGroupId="my-group" />
|
|
22
|
+
*
|
|
23
|
+
* // With custom source and output size
|
|
24
|
+
* <LensPlayer
|
|
25
|
+
* source={{ kind: "video", element: videoElement }}
|
|
26
|
+
* outputSize={{ mode: "fixed", width: 1280, height: 720 }}
|
|
27
|
+
* lensId="lens-123"
|
|
28
|
+
* lensGroupId="my-group"
|
|
29
|
+
* />
|
|
30
|
+
*
|
|
31
|
+
* // With playback controls and error handling
|
|
32
|
+
* <LensPlayer
|
|
33
|
+
* lensId="lens-123"
|
|
34
|
+
* lensGroupId="my-group"
|
|
35
|
+
* fpsLimit={30}
|
|
36
|
+
* muted={true}
|
|
37
|
+
* onError={(error) => console.error("Playback error:", error)}
|
|
38
|
+
* />
|
|
39
|
+
*
|
|
40
|
+
* // With custom children instead of default canvas
|
|
41
|
+
* <LensPlayer lensId="lens-123" lensGroupId="my-group">
|
|
42
|
+
* <div>Custom UI overlaying the Lens <LiveCanvas /></div>
|
|
43
|
+
* </LensPlayer>
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const LensPlayer = ({ source, outputSize, lensId, lensGroupId, lensLaunchData, lensReadyGuard, refreshTrigger, canvasType, fpsLimit, muted, screenRegions, onError, className, style, children, }) => {
|
|
47
|
+
(0, usePlaybackOptions_1.usePlaybackOptions)({ fpsLimit, muted, screenRegions, onError });
|
|
48
|
+
(0, useApplySource_1.useApplySource)(source, outputSize);
|
|
49
|
+
(0, useApplyLens_1.useApplyLens)(lensId, lensGroupId, lensLaunchData, lensReadyGuard);
|
|
50
|
+
// Handle refresh trigger - only refresh when the value actually changes (not on mount)
|
|
51
|
+
const { refreshLens } = (0, CameraKitProvider_1.useCameraKit)();
|
|
52
|
+
const prevRefreshTrigger = (0, react_1.useRef)(refreshTrigger);
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
if (prevRefreshTrigger.current !== refreshTrigger) {
|
|
55
|
+
prevRefreshTrigger.current = refreshTrigger;
|
|
56
|
+
refreshLens();
|
|
57
|
+
}
|
|
58
|
+
}, [refreshTrigger, refreshLens]);
|
|
59
|
+
if (children) {
|
|
60
|
+
// If custom children were provided, we wrap them to allow styling at the outer div.
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: className, style: style, children: children }));
|
|
62
|
+
}
|
|
63
|
+
// Otherwise, we render the asked (or by default live) canvas.
|
|
64
|
+
return canvasType === "capture" ? ((0, jsx_runtime_1.jsx)(Canvas_1.CaptureCanvas, { className: className, style: style })) : ((0, jsx_runtime_1.jsx)(Canvas_1.LiveCanvas, { className: className, style: style }));
|
|
65
|
+
};
|
|
66
|
+
exports.LensPlayer = LensPlayer;
|
|
67
|
+
//# sourceMappingURL=LensPlayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LensPlayer.js","sourceRoot":"","sources":["../../src/LensPlayer.tsx"],"names":[],"mappings":";;;;AAAA,iCAAqD;AAGrD,qDAAkD;AAClD,iDAA8C;AAC9C,6DAA0D;AAC1D,qCAAqD;AACrD,2DAAmD;AA8EnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,UAAU,GAA8B,CAAC,EACpD,MAAM,EACN,UAAU,EACV,MAAM,EACN,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,QAAQ,EACR,KAAK,EACL,aAAa,EACb,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,GACT,EAAE,EAAE;IACH,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,IAAA,+BAAc,EAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACnC,IAAA,2BAAY,EAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;IAElE,uFAAuF;IACvF,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,gCAAY,GAAE,CAAC;IACvC,MAAM,kBAAkB,GAAG,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAClD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,kBAAkB,CAAC,OAAO,KAAK,cAAc,EAAE,CAAC;YAClD,kBAAkB,CAAC,OAAO,GAAG,cAAc,CAAC;YAC5C,WAAW,EAAE,CAAC;QAChB,CAAC;IACH,CAAC,EAAE,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC;IAElC,IAAI,QAAQ,EAAE,CAAC;QACb,oFAAoF;QACpF,OAAO,CACL,gCAAK,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,YACpC,QAAQ,GACL,CACP,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,OAAO,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,CAChC,uBAAC,sBAAa,IAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI,CACtD,CAAC,CAAC,CAAC,CACF,uBAAC,mBAAU,IAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAI,CACnD,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,UAAU,cA8CrB","sourcesContent":["import { ReactNode, useEffect, useRef } from \"react\";\nimport { CameraKitSessionEvents, Lens, LensLaunchData, ScreenRegions } from \"@snap/camera-kit\";\nimport { CanvasType, OutputSize, SourceInput } from \"./types\";\nimport { useApplySource } from \"./useApplySource\";\nimport { useApplyLens } from \"./useApplyLens\";\nimport { usePlaybackOptions } from \"./usePlaybackOptions\";\nimport { CaptureCanvas, LiveCanvas } from \"./Canvas\";\nimport { useCameraKit } from \"./CameraKitProvider\";\n\n/**\n * Props for the LensPlayer component.\n */\nexport interface LensPlayerProps {\n /** The media source to apply (camera, video, or image). Defaults to camera if not specified. */\n source?: SourceInput;\n\n /** Optional output size configuration for the rendering canvas. */\n outputSize?: OutputSize;\n\n /** The unique identifier of the Lens to apply. */\n lensId?: string;\n\n /** The group ID containing the Lens. Required when lensId is provided. */\n lensGroupId?: string;\n\n /** Optional launch parameters to pass to the Lens.. */\n lensLaunchData?: LensLaunchData;\n\n /** Optional async guard that must resolve before the Lens is considered ready.\n * The guard is called when the lens is in loading state,\n * and when the promise returned by the function resolves, it will transition to the ready state.\n * If the promise doesn't resolve within 2 seconds, the ready state is forced. */\n lensReadyGuard?: () => Promise<void>;\n\n /**\n * Trigger to refresh the current Lens. When this value changes,\n * the Lens will be removed and reapplied. Useful for restarting\n * the Lens experience without moving LensPlayer to another component.\n */\n refreshTrigger?: unknown;\n\n /** Which canvas to render: \"live\" for real-time preview or \"capture\" for snapshot. Defaults to \"live\". */\n canvasType?: CanvasType;\n\n /**\n * A maximum FPS, rendering will not exceed this limit.\n *\n * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example,\n * the input media source has a low FPS – CameraKit would then not try to render more\n * frequently than the source produces new frames.\n *\n * This may also be useful to gracefully degrade performance in situations where\n * lowering FPS is preferable over alternatives.\n */\n fpsLimit?: number;\n\n /**\n * Whether to mute all sounds. Unmuted by default.\n */\n muted?: boolean;\n\n /**\n * Configuration object containing the current set of screen regions.\n *\n * Screen regions define areas of the screen that have special meaning for Lens rendering,\n * such as safe rendering areas, UI button locations, keyboard areas, etc. This allows lenses\n * to adapt their content placement based on the host application's UI layout.\n */\n screenRegions?: ScreenRegions;\n\n /**\n * A callback to handle Lens playback errors.\n */\n onError?: (error: CameraKitSessionEvents[\"detail\"][\"error\"], lens: Lens) => void;\n\n /** CSS class name to apply to the wrapper or canvas element. */\n className?: string;\n\n /** Inline styles to apply to the wrapper or canvas element. */\n style?: React.CSSProperties;\n\n /** Custom children to render instead of the default canvas. When provided, children are wrapped in a styled div. */\n children?: ReactNode;\n}\n\n/**\n * A declarative, all-in-one component for rendering Camera Kit Lenses.\n *\n * LensPlayer combines source management, lens application, and playback controls into a single\n * component. It handles the complexity of coordinating multiple hooks and provides a simple\n * prop-based API for common use cases.\n *\n * @example\n * ```tsx\n * // Basic lens player with camera source\n * <LensPlayer lensId=\"lens-123\" lensGroupId=\"my-group\" />\n *\n * // With custom source and output size\n * <LensPlayer\n * source={{ kind: \"video\", element: videoElement }}\n * outputSize={{ mode: \"fixed\", width: 1280, height: 720 }}\n * lensId=\"lens-123\"\n * lensGroupId=\"my-group\"\n * />\n *\n * // With playback controls and error handling\n * <LensPlayer\n * lensId=\"lens-123\"\n * lensGroupId=\"my-group\"\n * fpsLimit={30}\n * muted={true}\n * onError={(error) => console.error(\"Playback error:\", error)}\n * />\n *\n * // With custom children instead of default canvas\n * <LensPlayer lensId=\"lens-123\" lensGroupId=\"my-group\">\n * <div>Custom UI overlaying the Lens <LiveCanvas /></div>\n * </LensPlayer>\n * ```\n */\nexport const LensPlayer: React.FC<LensPlayerProps> = ({\n source,\n outputSize,\n lensId,\n lensGroupId,\n lensLaunchData,\n lensReadyGuard,\n refreshTrigger,\n canvasType,\n fpsLimit,\n muted,\n screenRegions,\n onError,\n className,\n style,\n children,\n}) => {\n usePlaybackOptions({ fpsLimit, muted, screenRegions, onError });\n useApplySource(source, outputSize);\n useApplyLens(lensId, lensGroupId, lensLaunchData, lensReadyGuard);\n\n // Handle refresh trigger - only refresh when the value actually changes (not on mount)\n const { refreshLens } = useCameraKit();\n const prevRefreshTrigger = useRef(refreshTrigger);\n useEffect(() => {\n if (prevRefreshTrigger.current !== refreshTrigger) {\n prevRefreshTrigger.current = refreshTrigger;\n refreshLens();\n }\n }, [refreshTrigger, refreshLens]);\n\n if (children) {\n // If custom children were provided, we wrap them to allow styling at the outer div.\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n }\n\n // Otherwise, we render the asked (or by default live) canvas.\n return canvasType === \"capture\" ? (\n <CaptureCanvas className={className} style={style} />\n ) : (\n <LiveCanvas className={className} style={style} />\n );\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { CameraKitProvider, useCameraKit } from "./CameraKitProvider";
|
|
2
|
+
export type { MetricEventHandlerFactory } from "./CameraKitProvider";
|
|
3
|
+
export type { CameraKitLogger, LogLevel } from "./internal/logging";
|
|
4
|
+
export { createConsoleLogger, createNoopLogger } from "./internal/logging";
|
|
5
|
+
export { LensPlayer } from "./LensPlayer";
|
|
6
|
+
export type { LensPlayerProps } from "./LensPlayer";
|
|
7
|
+
export { LiveCanvas, CaptureCanvas } from "./Canvas";
|
|
8
|
+
export type { CanvasChildProps } from "./Canvas";
|
|
9
|
+
export { useApplyLens } from "./useApplyLens";
|
|
10
|
+
export { useApplySource } from "./useApplySource";
|
|
11
|
+
export { usePlaybackOptions } from "./usePlaybackOptions";
|
|
12
|
+
export type { PlaybackOptions } from "./usePlaybackOptions";
|
|
13
|
+
export type { SourceStatus, LensStatus, CurrentSource, CurrentLens, CameraSourceInput, VideoSourceInput, ImageSourceInput, SourceInput, CameraSourceOutput, VideoSourceOutput, ImageSourceOutput, SourceOutput, FixedOutputSize, MatchInputSize, OutputSize, SourceOptions, CameraFacing, CameraConstraints, CameraRotation, CanvasType, CameraInfo, } from "./types";
|
|
14
|
+
export { NO_CURRENT_LENS, isCameraSource, isVideoSource, isImageSource, CameraRotationOptions } from "./types";
|
|
15
|
+
export { createCameraKitSource, DEFAULT_CAMERA_DEVICE_ID, defaultStreamResolution } from "./internal/sourceUtils";
|
|
16
|
+
export type { SourceApplication, TupleOf } from "./internal/sourceUtils";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGrE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,YAAY,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,UAAU,EACV,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,UAAU,GACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAG/G,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAClH,YAAY,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultStreamResolution = exports.DEFAULT_CAMERA_DEVICE_ID = exports.createCameraKitSource = exports.CameraRotationOptions = exports.isImageSource = exports.isVideoSource = exports.isCameraSource = exports.NO_CURRENT_LENS = exports.usePlaybackOptions = exports.useApplySource = exports.useApplyLens = exports.CaptureCanvas = exports.LiveCanvas = exports.LensPlayer = exports.createNoopLogger = exports.createConsoleLogger = exports.useCameraKit = exports.CameraKitProvider = void 0;
|
|
4
|
+
// Main components
|
|
5
|
+
var CameraKitProvider_1 = require("./CameraKitProvider");
|
|
6
|
+
Object.defineProperty(exports, "CameraKitProvider", { enumerable: true, get: function () { return CameraKitProvider_1.CameraKitProvider; } });
|
|
7
|
+
Object.defineProperty(exports, "useCameraKit", { enumerable: true, get: function () { return CameraKitProvider_1.useCameraKit; } });
|
|
8
|
+
var logging_1 = require("./internal/logging");
|
|
9
|
+
Object.defineProperty(exports, "createConsoleLogger", { enumerable: true, get: function () { return logging_1.createConsoleLogger; } });
|
|
10
|
+
Object.defineProperty(exports, "createNoopLogger", { enumerable: true, get: function () { return logging_1.createNoopLogger; } });
|
|
11
|
+
var LensPlayer_1 = require("./LensPlayer");
|
|
12
|
+
Object.defineProperty(exports, "LensPlayer", { enumerable: true, get: function () { return LensPlayer_1.LensPlayer; } });
|
|
13
|
+
var Canvas_1 = require("./Canvas");
|
|
14
|
+
Object.defineProperty(exports, "LiveCanvas", { enumerable: true, get: function () { return Canvas_1.LiveCanvas; } });
|
|
15
|
+
Object.defineProperty(exports, "CaptureCanvas", { enumerable: true, get: function () { return Canvas_1.CaptureCanvas; } });
|
|
16
|
+
// Hooks
|
|
17
|
+
var useApplyLens_1 = require("./useApplyLens");
|
|
18
|
+
Object.defineProperty(exports, "useApplyLens", { enumerable: true, get: function () { return useApplyLens_1.useApplyLens; } });
|
|
19
|
+
var useApplySource_1 = require("./useApplySource");
|
|
20
|
+
Object.defineProperty(exports, "useApplySource", { enumerable: true, get: function () { return useApplySource_1.useApplySource; } });
|
|
21
|
+
var usePlaybackOptions_1 = require("./usePlaybackOptions");
|
|
22
|
+
Object.defineProperty(exports, "usePlaybackOptions", { enumerable: true, get: function () { return usePlaybackOptions_1.usePlaybackOptions; } });
|
|
23
|
+
var types_1 = require("./types");
|
|
24
|
+
Object.defineProperty(exports, "NO_CURRENT_LENS", { enumerable: true, get: function () { return types_1.NO_CURRENT_LENS; } });
|
|
25
|
+
Object.defineProperty(exports, "isCameraSource", { enumerable: true, get: function () { return types_1.isCameraSource; } });
|
|
26
|
+
Object.defineProperty(exports, "isVideoSource", { enumerable: true, get: function () { return types_1.isVideoSource; } });
|
|
27
|
+
Object.defineProperty(exports, "isImageSource", { enumerable: true, get: function () { return types_1.isImageSource; } });
|
|
28
|
+
Object.defineProperty(exports, "CameraRotationOptions", { enumerable: true, get: function () { return types_1.CameraRotationOptions; } });
|
|
29
|
+
// Source utilities
|
|
30
|
+
var sourceUtils_1 = require("./internal/sourceUtils");
|
|
31
|
+
Object.defineProperty(exports, "createCameraKitSource", { enumerable: true, get: function () { return sourceUtils_1.createCameraKitSource; } });
|
|
32
|
+
Object.defineProperty(exports, "DEFAULT_CAMERA_DEVICE_ID", { enumerable: true, get: function () { return sourceUtils_1.DEFAULT_CAMERA_DEVICE_ID; } });
|
|
33
|
+
Object.defineProperty(exports, "defaultStreamResolution", { enumerable: true, get: function () { return sourceUtils_1.defaultStreamResolution; } });
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,kBAAkB;AAClB,yDAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAAE,iHAAA,YAAY,OAAA;AAKxC,8CAA2E;AAAlE,8GAAA,mBAAmB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAE9C,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAGnB,mCAAqD;AAA5C,oGAAA,UAAU,OAAA;AAAE,uGAAA,aAAa,OAAA;AAGlC,QAAQ;AACR,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AA4B3B,iCAA+G;AAAtG,wGAAA,eAAe,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,8GAAA,qBAAqB,OAAA;AAE7F,mBAAmB;AACnB,sDAAkH;AAAzG,oHAAA,qBAAqB,OAAA;AAAE,uHAAA,wBAAwB,OAAA;AAAE,sHAAA,uBAAuB,OAAA","sourcesContent":["// Main components\nexport { CameraKitProvider, useCameraKit } from \"./CameraKitProvider\";\nexport type { MetricEventHandlerFactory } from \"./CameraKitProvider\";\n\n// Logging\nexport type { CameraKitLogger, LogLevel } from \"./internal/logging\";\nexport { createConsoleLogger, createNoopLogger } from \"./internal/logging\";\n\nexport { LensPlayer } from \"./LensPlayer\";\nexport type { LensPlayerProps } from \"./LensPlayer\";\n\nexport { LiveCanvas, CaptureCanvas } from \"./Canvas\";\nexport type { CanvasChildProps } from \"./Canvas\";\n\n// Hooks\nexport { useApplyLens } from \"./useApplyLens\";\nexport { useApplySource } from \"./useApplySource\";\nexport { usePlaybackOptions } from \"./usePlaybackOptions\";\nexport type { PlaybackOptions } from \"./usePlaybackOptions\";\n\n// Types\nexport type {\n SourceStatus,\n LensStatus,\n CurrentSource,\n CurrentLens,\n CameraSourceInput,\n VideoSourceInput,\n ImageSourceInput,\n SourceInput,\n CameraSourceOutput,\n VideoSourceOutput,\n ImageSourceOutput,\n SourceOutput,\n FixedOutputSize,\n MatchInputSize,\n OutputSize,\n SourceOptions,\n CameraFacing,\n CameraConstraints,\n CameraRotation,\n CanvasType,\n CameraInfo,\n} from \"./types\";\n\nexport { NO_CURRENT_LENS, isCameraSource, isVideoSource, isImageSource, CameraRotationOptions } from \"./types\";\n\n// Source utilities\nexport { createCameraKitSource, DEFAULT_CAMERA_DEVICE_ID, defaultStreamResolution } from \"./internal/sourceUtils\";\nexport type { SourceApplication, TupleOf } from \"./internal/sourceUtils\";\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CameraKit, CameraKitBootstrapConfiguration, CameraKitSession, CreateSessionOptions, PublicContainer } from "@snap/camera-kit";
|
|
2
|
+
import { CameraKitLogger } from "./logging";
|
|
3
|
+
export interface BootstrapResult {
|
|
4
|
+
kit: CameraKit;
|
|
5
|
+
session: CameraKitSession;
|
|
6
|
+
destroy: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Bootstraps CameraKit and creates a session with proper cancellation support.
|
|
10
|
+
* Cleans up resources if the operation is aborted via the AbortSignal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function bootstrapCameraKitWithSession(config: CameraKitBootstrapConfiguration, extendContainer: ((container: PublicContainer) => PublicContainer) | undefined, sessionOptions: CreateSessionOptions, signal: AbortSignal, log: CameraKitLogger): Promise<BootstrapResult>;
|
|
13
|
+
//# sourceMappingURL=bootstrapUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrapUtils.d.ts","sourceRoot":"","sources":["../../../src/internal/bootstrapUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,+BAA+B,EAC/B,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,+BAA+B,EACvC,eAAe,EAAE,CAAC,CAAC,SAAS,EAAE,eAAe,KAAK,eAAe,CAAC,GAAG,SAAS,EAC9E,cAAc,EAAE,oBAAoB,EACpC,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,eAAe,CAAC,CAwB1B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bootstrapCameraKitWithSession = bootstrapCameraKitWithSession;
|
|
4
|
+
const camera_kit_1 = require("@snap/camera-kit");
|
|
5
|
+
/**
|
|
6
|
+
* Bootstraps CameraKit and creates a session with proper cancellation support.
|
|
7
|
+
* Cleans up resources if the operation is aborted via the AbortSignal.
|
|
8
|
+
*/
|
|
9
|
+
async function bootstrapCameraKitWithSession(config, extendContainer, sessionOptions, signal, log) {
|
|
10
|
+
// Bootstrap the CameraKit SDK
|
|
11
|
+
const kit = await (0, camera_kit_1.bootstrapCameraKit)(config, extendContainer);
|
|
12
|
+
function destroy() {
|
|
13
|
+
return kit.destroy().catch((error) => log.error("kit_destroy_failed", error));
|
|
14
|
+
}
|
|
15
|
+
// Check if aborted after bootstrap
|
|
16
|
+
if (signal.aborted) {
|
|
17
|
+
destroy();
|
|
18
|
+
signal.throwIfAborted();
|
|
19
|
+
}
|
|
20
|
+
// Create session
|
|
21
|
+
const session = await kit.createSession(sessionOptions);
|
|
22
|
+
// Check if aborted after session creation
|
|
23
|
+
if (signal.aborted) {
|
|
24
|
+
destroy();
|
|
25
|
+
signal.throwIfAborted();
|
|
26
|
+
}
|
|
27
|
+
return { kit, session, destroy };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=bootstrapUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrapUtils.js","sourceRoot":"","sources":["../../../src/internal/bootstrapUtils.ts"],"names":[],"mappings":";;AAoBA,sEA8BC;AAlDD,iDAO0B;AAS1B;;;GAGG;AACI,KAAK,UAAU,6BAA6B,CACjD,MAAuC,EACvC,eAA8E,EAC9E,cAAoC,EACpC,MAAmB,EACnB,GAAoB;IAEpB,8BAA8B;IAC9B,MAAM,GAAG,GAAG,MAAM,IAAA,+BAAkB,EAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE9D,SAAS,OAAO;QACd,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,mCAAmC;IACnC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;QACV,MAAM,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;IAED,iBAAiB;IACjB,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAExD,0CAA0C;IAC1C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;QACV,MAAM,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import {\n bootstrapCameraKit,\n CameraKit,\n CameraKitBootstrapConfiguration,\n CameraKitSession,\n CreateSessionOptions,\n PublicContainer,\n} from \"@snap/camera-kit\";\nimport { CameraKitLogger } from \"./logging\";\n\nexport interface BootstrapResult {\n kit: CameraKit;\n session: CameraKitSession;\n destroy: () => Promise<void>;\n}\n\n/**\n * Bootstraps CameraKit and creates a session with proper cancellation support.\n * Cleans up resources if the operation is aborted via the AbortSignal.\n */\nexport async function bootstrapCameraKitWithSession(\n config: CameraKitBootstrapConfiguration,\n extendContainer: ((container: PublicContainer) => PublicContainer) | undefined,\n sessionOptions: CreateSessionOptions,\n signal: AbortSignal,\n log: CameraKitLogger,\n): Promise<BootstrapResult> {\n // Bootstrap the CameraKit SDK\n const kit = await bootstrapCameraKit(config, extendContainer);\n\n function destroy() {\n return kit.destroy().catch((error) => log.error(\"kit_destroy_failed\", error));\n }\n\n // Check if aborted after bootstrap\n if (signal.aborted) {\n destroy();\n signal.throwIfAborted();\n }\n\n // Create session\n const session = await kit.createSession(sessionOptions);\n\n // Check if aborted after session creation\n if (signal.aborted) {\n destroy();\n signal.throwIfAborted();\n }\n\n return { kit, session, destroy };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/internal/error.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CA8BnE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureError = ensureError;
|
|
4
|
+
function ensureError(error, context) {
|
|
5
|
+
if (error instanceof Error)
|
|
6
|
+
return error;
|
|
7
|
+
const contextPrefix = context ? `[${context}] ` : "";
|
|
8
|
+
try {
|
|
9
|
+
// Handle primitive types more explicitly
|
|
10
|
+
if (typeof error === "string") {
|
|
11
|
+
return new Error(`${contextPrefix}${error}`);
|
|
12
|
+
}
|
|
13
|
+
if (error === null || error === undefined) {
|
|
14
|
+
return new Error(`${contextPrefix}An unknown error occurred (${error})`);
|
|
15
|
+
}
|
|
16
|
+
// Try to extract useful info from error-like objects
|
|
17
|
+
const errorObj = error;
|
|
18
|
+
const message = errorObj.message || errorObj.error || "Unknown error";
|
|
19
|
+
const details = JSON.stringify(error, null, 2);
|
|
20
|
+
return new Error(`${contextPrefix}Non-Error exception: ${message}\nDetails: ${details}`);
|
|
21
|
+
}
|
|
22
|
+
catch (serializationError) {
|
|
23
|
+
// Provide more info about what failed
|
|
24
|
+
return new Error(`${contextPrefix}Non-Error exception thrown. ` +
|
|
25
|
+
`Type: ${typeof error}, ` +
|
|
26
|
+
`Constructor: ${error?.constructor?.name ?? "unknown"}, ` +
|
|
27
|
+
`Serialization failed: ${serializationError instanceof Error ? serializationError.message : "unknown reason"}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/internal/error.ts"],"names":[],"mappings":";;AAAA,kCA8BC;AA9BD,SAAgB,WAAW,CAAC,KAAc,EAAE,OAAgB;IAC1D,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC;IAEzC,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAErD,IAAI,CAAC;QACH,yCAAyC;QACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,8BAA8B,KAAK,GAAG,CAAC,CAAC;QAC3E,CAAC;QAED,qDAAqD;QACrD,MAAM,QAAQ,GAAG,KAAgC,CAAC;QAClD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,KAAK,IAAI,eAAe,CAAC;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAE/C,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,wBAAwB,OAAO,cAAc,OAAO,EAAE,CAAC,CAAC;IAC3F,CAAC;IAAC,OAAO,kBAAkB,EAAE,CAAC;QAC5B,sCAAsC;QACtC,OAAO,IAAI,KAAK,CACd,GAAG,aAAa,8BAA8B;YAC5C,SAAS,OAAO,KAAK,IAAI;YACzB,gBAAgB,KAAK,EAAE,WAAW,EAAE,IAAI,IAAI,SAAS,IAAI;YACzD,yBAAyB,kBAAkB,YAAY,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE,CACjH,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["export function ensureError(error: unknown, context?: string): Error {\n if (error instanceof Error) return error;\n\n const contextPrefix = context ? `[${context}] ` : \"\";\n\n try {\n // Handle primitive types more explicitly\n if (typeof error === \"string\") {\n return new Error(`${contextPrefix}${error}`);\n }\n\n if (error === null || error === undefined) {\n return new Error(`${contextPrefix}An unknown error occurred (${error})`);\n }\n\n // Try to extract useful info from error-like objects\n const errorObj = error as Record<string, unknown>;\n const message = errorObj.message || errorObj.error || \"Unknown error\";\n const details = JSON.stringify(error, null, 2);\n\n return new Error(`${contextPrefix}Non-Error exception: ${message}\\nDetails: ${details}`);\n } catch (serializationError) {\n // Provide more info about what failed\n return new Error(\n `${contextPrefix}Non-Error exception thrown. ` +\n `Type: ${typeof error}, ` +\n `Constructor: ${error?.constructor?.name ?? \"unknown\"}, ` +\n `Serialization failed: ${serializationError instanceof Error ? serializationError.message : \"unknown reason\"}`,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMobile.d.ts","sourceRoot":"","sources":["../../../src/internal/isMobile.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,QAAQ,IAAI,OAAO,CASlC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Detects if the current device is a mobile device
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isMobile = isMobile;
|
|
7
|
+
function isMobile() {
|
|
8
|
+
if (typeof navigator === "undefined" || typeof window === "undefined") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
// Check user agent for mobile indicators
|
|
12
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
13
|
+
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=isMobile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMobile.js","sourceRoot":"","sources":["../../../src/internal/isMobile.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,4BASC;AATD,SAAgB,QAAQ;IACtB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,yCAAyC;IACzC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,IAAK,MAAc,CAAC,KAAK,CAAC;IAEnF,OAAO,gEAAgE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * Detects if the current device is a mobile device\n */\n\nexport function isMobile(): boolean {\n if (typeof navigator === \"undefined\" || typeof window === \"undefined\") {\n return false;\n }\n\n // Check user agent for mobile indicators\n const userAgent = navigator.userAgent || navigator.vendor || (window as any).opera;\n\n return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent);\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable logging interface for react-camera-kit.
|
|
3
|
+
* Vendor-neutral design allows integrating with any logging system.
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
6
|
+
/**
|
|
7
|
+
* Logger interface that matches console.log signature.
|
|
8
|
+
* Can be implemented by any logging library.
|
|
9
|
+
* Users only need to implement the basic log methods - child logger creation is handled internally.
|
|
10
|
+
*/
|
|
11
|
+
export interface CameraKitLogger {
|
|
12
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
14
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
15
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Logger interface that matches console.log signature.
|
|
19
|
+
* Can be implemented by any logging library.
|
|
20
|
+
* Users only need to implement the basic log methods - child logger creation is handled internally.
|
|
21
|
+
*/
|
|
22
|
+
export interface InternalLogger extends CameraKitLogger {
|
|
23
|
+
logLevel: LogLevel;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a child logger with a namespace prefix.
|
|
27
|
+
* This is used internally to create namespaced loggers for different parts of the library.
|
|
28
|
+
*/
|
|
29
|
+
export declare function wrapLogger(inner: InternalLogger, namespace: string): InternalLogger;
|
|
30
|
+
/**
|
|
31
|
+
* Console-based logger implementation with timestamps.
|
|
32
|
+
* Log level can be controlled via the setLevel() method or CameraKitProvider's logLevel prop.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createConsoleLogger(): CameraKitLogger;
|
|
35
|
+
/**
|
|
36
|
+
* No-op logger that discards all log messages.
|
|
37
|
+
* Useful for production environments where logging is handled externally.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createNoopLogger(): CameraKitLogger;
|
|
40
|
+
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/internal/logging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACrD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACpD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACpD,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACtD;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CA0BnF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,CAOrD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,eAAe,CAOlD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pluggable logging interface for react-camera-kit.
|
|
4
|
+
* Vendor-neutral design allows integrating with any logging system.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.wrapLogger = wrapLogger;
|
|
8
|
+
exports.createConsoleLogger = createConsoleLogger;
|
|
9
|
+
exports.createNoopLogger = createNoopLogger;
|
|
10
|
+
const noop = () => { };
|
|
11
|
+
/**
|
|
12
|
+
* Creates a child logger with a namespace prefix.
|
|
13
|
+
* This is used internally to create namespaced loggers for different parts of the library.
|
|
14
|
+
*/
|
|
15
|
+
function wrapLogger(inner, namespace) {
|
|
16
|
+
const levelOrder = ["debug", "info", "warn", "error"];
|
|
17
|
+
const minLevelIndex = levelOrder.indexOf(inner.logLevel);
|
|
18
|
+
function shouldLog(msgLevel) {
|
|
19
|
+
return levelOrder.indexOf(msgLevel) >= minLevelIndex;
|
|
20
|
+
}
|
|
21
|
+
// Create a wrapper that prefixes messages with namespace
|
|
22
|
+
const outer = {
|
|
23
|
+
logLevel: inner.logLevel,
|
|
24
|
+
debug: shouldLog("debug")
|
|
25
|
+
? (message, ...optionalParams) => inner.debug(`[${namespace}] ${message}`, ...optionalParams)
|
|
26
|
+
: noop,
|
|
27
|
+
info: shouldLog("info")
|
|
28
|
+
? (message, ...optionalParams) => inner.info(`[${namespace}] ${message}`, ...optionalParams)
|
|
29
|
+
: noop,
|
|
30
|
+
warn: shouldLog("warn")
|
|
31
|
+
? (message, ...optionalParams) => inner.warn(`[${namespace}] ${message}`, ...optionalParams)
|
|
32
|
+
: noop,
|
|
33
|
+
error: shouldLog("error")
|
|
34
|
+
? (message, ...optionalParams) => inner.error(`[${namespace}] ${message}`, ...optionalParams)
|
|
35
|
+
: noop,
|
|
36
|
+
};
|
|
37
|
+
return outer;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Console-based logger implementation with timestamps.
|
|
41
|
+
* Log level can be controlled via the setLevel() method or CameraKitProvider's logLevel prop.
|
|
42
|
+
*/
|
|
43
|
+
function createConsoleLogger() {
|
|
44
|
+
return {
|
|
45
|
+
debug: (message, ...optionalParams) => console.debug(message, ...optionalParams),
|
|
46
|
+
info: (message, ...optionalParams) => console.info(message, ...optionalParams),
|
|
47
|
+
warn: (message, ...optionalParams) => console.warn(message, ...optionalParams),
|
|
48
|
+
error: (message, ...optionalParams) => console.error(message, ...optionalParams),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* No-op logger that discards all log messages.
|
|
53
|
+
* Useful for production environments where logging is handled externally.
|
|
54
|
+
*/
|
|
55
|
+
function createNoopLogger() {
|
|
56
|
+
return {
|
|
57
|
+
debug: noop,
|
|
58
|
+
info: noop,
|
|
59
|
+
warn: noop,
|
|
60
|
+
error: noop,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../src/internal/logging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA+BH,gCA0BC;AAMD,kDAOC;AAMD,4CAOC;AA1DD,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB;;;GAGG;AACH,SAAgB,UAAU,CAAC,KAAqB,EAAE,SAAiB;IACjE,MAAM,UAAU,GAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClE,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEzD,SAAS,SAAS,CAAC,QAAkB;QACnC,OAAO,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,aAAa,CAAC;IACvD,CAAC;IAED,yDAAyD;IACzD,MAAM,KAAK,GAAmB;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC;YACvB,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,SAAS,KAAK,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC;YAC7F,CAAC,CAAC,IAAI;QACR,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC;YACrB,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,SAAS,KAAK,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC;YAC5F,CAAC,CAAC,IAAI;QACR,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC;YACrB,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,SAAS,KAAK,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC;YAC5F,CAAC,CAAC,IAAI;QACR,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC;YACvB,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,SAAS,KAAK,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC;YAC7F,CAAC,CAAC,IAAI;KACT,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO;QACL,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;QAChF,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;QAC9E,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;QAC9E,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;KACjF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB;IAC9B,OAAO;QACL,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;KACZ,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Pluggable logging interface for react-camera-kit.\n * Vendor-neutral design allows integrating with any logging system.\n */\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\n/**\n * Logger interface that matches console.log signature.\n * Can be implemented by any logging library.\n * Users only need to implement the basic log methods - child logger creation is handled internally.\n */\nexport interface CameraKitLogger {\n debug(message?: any, ...optionalParams: any[]): void;\n info(message?: any, ...optionalParams: any[]): void;\n warn(message?: any, ...optionalParams: any[]): void;\n error(message?: any, ...optionalParams: any[]): void;\n}\n\n/**\n * Logger interface that matches console.log signature.\n * Can be implemented by any logging library.\n * Users only need to implement the basic log methods - child logger creation is handled internally.\n */\nexport interface InternalLogger extends CameraKitLogger {\n logLevel: LogLevel;\n}\n\nconst noop = () => {};\n\n/**\n * Creates a child logger with a namespace prefix.\n * This is used internally to create namespaced loggers for different parts of the library.\n */\nexport function wrapLogger(inner: InternalLogger, namespace: string): InternalLogger {\n const levelOrder: LogLevel[] = [\"debug\", \"info\", \"warn\", \"error\"];\n const minLevelIndex = levelOrder.indexOf(inner.logLevel);\n\n function shouldLog(msgLevel: LogLevel): boolean {\n return levelOrder.indexOf(msgLevel) >= minLevelIndex;\n }\n\n // Create a wrapper that prefixes messages with namespace\n const outer: InternalLogger = {\n logLevel: inner.logLevel,\n debug: shouldLog(\"debug\")\n ? (message, ...optionalParams) => inner.debug(`[${namespace}] ${message}`, ...optionalParams)\n : noop,\n info: shouldLog(\"info\")\n ? (message, ...optionalParams) => inner.info(`[${namespace}] ${message}`, ...optionalParams)\n : noop,\n warn: shouldLog(\"warn\")\n ? (message, ...optionalParams) => inner.warn(`[${namespace}] ${message}`, ...optionalParams)\n : noop,\n error: shouldLog(\"error\")\n ? (message, ...optionalParams) => inner.error(`[${namespace}] ${message}`, ...optionalParams)\n : noop,\n };\n\n return outer;\n}\n\n/**\n * Console-based logger implementation with timestamps.\n * Log level can be controlled via the setLevel() method or CameraKitProvider's logLevel prop.\n */\nexport function createConsoleLogger(): CameraKitLogger {\n return {\n debug: (message, ...optionalParams) => console.debug(message, ...optionalParams),\n info: (message, ...optionalParams) => console.info(message, ...optionalParams),\n warn: (message, ...optionalParams) => console.warn(message, ...optionalParams),\n error: (message, ...optionalParams) => console.error(message, ...optionalParams),\n };\n}\n\n/**\n * No-op logger that discards all log messages.\n * Useful for production environments where logging is handled externally.\n */\nexport function createNoopLogger(): CameraKitLogger {\n return {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n };\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Metric, PublicContainer } from "@snap/camera-kit";
|
|
2
|
+
import { Subject } from "rxjs";
|
|
3
|
+
export type MetricsReporter = ReturnType<typeof createMetricsReporter>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a metrics reporter that pushes Count metrics into a Subject.
|
|
6
|
+
* The subject is wired into Camera Kit's DI container so metrics flow
|
|
7
|
+
* through the SDK's built-in pipeline to the backend.
|
|
8
|
+
*/
|
|
9
|
+
declare function createMetricsReporter(subject: Subject<Metric>): {
|
|
10
|
+
reportCount(name: string): void;
|
|
11
|
+
};
|
|
12
|
+
/** Global metrics reporter — safe to call at any point; events are buffered until the DI wiring is established. */
|
|
13
|
+
export declare const metricsReporter: {
|
|
14
|
+
reportCount(name: string): void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Wraps a user-supplied `extendContainer` (if any) so that our metrics Subject
|
|
18
|
+
* is always provided into Camera Kit's DI container.
|
|
19
|
+
*
|
|
20
|
+
* Newer Camera Kit versions (with `externalMetricsFactory`)
|
|
21
|
+
* use a simpler declarative approach. Older versions fall back to
|
|
22
|
+
* `externalMetricsSubjectFactory` with manual subscribe-and-forward.
|
|
23
|
+
*
|
|
24
|
+
* On re-bootstrap the previous forwarding subscription is torn down automatically
|
|
25
|
+
* (legacy path only; the new path doesn't need that).
|
|
26
|
+
*/
|
|
27
|
+
export declare function extendContainerWithMetrics(userExtendContainer?: (container: PublicContainer) => PublicContainer): (container: PublicContainer) => PublicContainer;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/internal/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,eAAe,EAAgC,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAAc,OAAO,EAAgB,MAAM,MAAM,CAAC;AAuCzD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE;;;;GAIG;AACH,iBAAS,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC;sBAEjC,MAAM;EAQ3B;AAED,mHAAmH;AACnH,eAAO,MAAM,eAAe;sBAXN,MAAM;CAWwC,CAAC;AAErE;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,mBAAmB,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,KAAK,eAAe,GACpE,CAAC,SAAS,EAAE,eAAe,KAAK,eAAe,CAqBjD"}
|