@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.
Files changed (132) hide show
  1. package/LICENSE.md +37 -0
  2. package/README.md +130 -0
  3. package/dist/cjs/CameraKitProvider.d.ts +203 -0
  4. package/dist/cjs/CameraKitProvider.d.ts.map +1 -0
  5. package/dist/cjs/CameraKitProvider.js +542 -0
  6. package/dist/cjs/CameraKitProvider.js.map +1 -0
  7. package/dist/cjs/Canvas.d.ts +7 -0
  8. package/dist/cjs/Canvas.d.ts.map +1 -0
  9. package/dist/cjs/Canvas.js +50 -0
  10. package/dist/cjs/Canvas.js.map +1 -0
  11. package/dist/cjs/LensPlayer.d.ts +101 -0
  12. package/dist/cjs/LensPlayer.d.ts.map +1 -0
  13. package/dist/cjs/LensPlayer.js +67 -0
  14. package/dist/cjs/LensPlayer.js.map +1 -0
  15. package/dist/cjs/index.d.ts +17 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +34 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/internal/bootstrapUtils.d.ts +13 -0
  20. package/dist/cjs/internal/bootstrapUtils.d.ts.map +1 -0
  21. package/dist/cjs/internal/bootstrapUtils.js +29 -0
  22. package/dist/cjs/internal/bootstrapUtils.js.map +1 -0
  23. package/dist/cjs/internal/error.d.ts +2 -0
  24. package/dist/cjs/internal/error.d.ts.map +1 -0
  25. package/dist/cjs/internal/error.js +30 -0
  26. package/dist/cjs/internal/error.js.map +1 -0
  27. package/dist/cjs/internal/isMobile.d.ts +5 -0
  28. package/dist/cjs/internal/isMobile.d.ts.map +1 -0
  29. package/dist/cjs/internal/isMobile.js +15 -0
  30. package/dist/cjs/internal/isMobile.js.map +1 -0
  31. package/dist/cjs/internal/logging.d.ts +40 -0
  32. package/dist/cjs/internal/logging.d.ts.map +1 -0
  33. package/dist/cjs/internal/logging.js +63 -0
  34. package/dist/cjs/internal/logging.js.map +1 -0
  35. package/dist/cjs/internal/metrics.d.ts +29 -0
  36. package/dist/cjs/internal/metrics.d.ts.map +1 -0
  37. package/dist/cjs/internal/metrics.js +128 -0
  38. package/dist/cjs/internal/metrics.js.map +1 -0
  39. package/dist/cjs/internal/sessionUtils.d.ts +3 -0
  40. package/dist/cjs/internal/sessionUtils.d.ts.map +1 -0
  41. package/dist/cjs/internal/sessionUtils.js +17 -0
  42. package/dist/cjs/internal/sessionUtils.js.map +1 -0
  43. package/dist/cjs/internal/sourceUtils.d.ts +22 -0
  44. package/dist/cjs/internal/sourceUtils.d.ts.map +1 -0
  45. package/dist/cjs/internal/sourceUtils.js +143 -0
  46. package/dist/cjs/internal/sourceUtils.js.map +1 -0
  47. package/dist/cjs/package.json +1 -0
  48. package/dist/cjs/types.d.ts +96 -0
  49. package/dist/cjs/types.d.ts.map +1 -0
  50. package/dist/cjs/types.js +26 -0
  51. package/dist/cjs/types.js.map +1 -0
  52. package/dist/cjs/useApplyLens.d.ts +25 -0
  53. package/dist/cjs/useApplyLens.d.ts.map +1 -0
  54. package/dist/cjs/useApplyLens.js +87 -0
  55. package/dist/cjs/useApplyLens.js.map +1 -0
  56. package/dist/cjs/useApplySource.d.ts +11 -0
  57. package/dist/cjs/useApplySource.d.ts.map +1 -0
  58. package/dist/cjs/useApplySource.js +66 -0
  59. package/dist/cjs/useApplySource.js.map +1 -0
  60. package/dist/cjs/usePlaybackOptions.d.ts +38 -0
  61. package/dist/cjs/usePlaybackOptions.d.ts.map +1 -0
  62. package/dist/cjs/usePlaybackOptions.js +51 -0
  63. package/dist/cjs/usePlaybackOptions.js.map +1 -0
  64. package/dist/cjs/version.d.ts +3 -0
  65. package/dist/cjs/version.d.ts.map +1 -0
  66. package/dist/cjs/version.js +6 -0
  67. package/dist/cjs/version.js.map +1 -0
  68. package/dist/esm/CameraKitProvider.d.ts +203 -0
  69. package/dist/esm/CameraKitProvider.d.ts.map +1 -0
  70. package/dist/esm/CameraKitProvider.js +533 -0
  71. package/dist/esm/CameraKitProvider.js.map +1 -0
  72. package/dist/esm/Canvas.d.ts +7 -0
  73. package/dist/esm/Canvas.d.ts.map +1 -0
  74. package/dist/esm/Canvas.js +45 -0
  75. package/dist/esm/Canvas.js.map +1 -0
  76. package/dist/esm/LensPlayer.d.ts +101 -0
  77. package/dist/esm/LensPlayer.d.ts.map +1 -0
  78. package/dist/esm/LensPlayer.js +63 -0
  79. package/dist/esm/LensPlayer.js.map +1 -0
  80. package/dist/esm/index.d.ts +17 -0
  81. package/dist/esm/index.d.ts.map +1 -0
  82. package/dist/esm/index.js +13 -0
  83. package/dist/esm/index.js.map +1 -0
  84. package/dist/esm/internal/bootstrapUtils.d.ts +13 -0
  85. package/dist/esm/internal/bootstrapUtils.d.ts.map +1 -0
  86. package/dist/esm/internal/bootstrapUtils.js +26 -0
  87. package/dist/esm/internal/bootstrapUtils.js.map +1 -0
  88. package/dist/esm/internal/error.d.ts +2 -0
  89. package/dist/esm/internal/error.d.ts.map +1 -0
  90. package/dist/esm/internal/error.js +27 -0
  91. package/dist/esm/internal/error.js.map +1 -0
  92. package/dist/esm/internal/isMobile.d.ts +5 -0
  93. package/dist/esm/internal/isMobile.d.ts.map +1 -0
  94. package/dist/esm/internal/isMobile.js +12 -0
  95. package/dist/esm/internal/isMobile.js.map +1 -0
  96. package/dist/esm/internal/logging.d.ts +40 -0
  97. package/dist/esm/internal/logging.d.ts.map +1 -0
  98. package/dist/esm/internal/logging.js +58 -0
  99. package/dist/esm/internal/logging.js.map +1 -0
  100. package/dist/esm/internal/metrics.d.ts +29 -0
  101. package/dist/esm/internal/metrics.d.ts.map +1 -0
  102. package/dist/esm/internal/metrics.js +91 -0
  103. package/dist/esm/internal/metrics.js.map +1 -0
  104. package/dist/esm/internal/sessionUtils.d.ts +3 -0
  105. package/dist/esm/internal/sessionUtils.d.ts.map +1 -0
  106. package/dist/esm/internal/sessionUtils.js +14 -0
  107. package/dist/esm/internal/sessionUtils.js.map +1 -0
  108. package/dist/esm/internal/sourceUtils.d.ts +22 -0
  109. package/dist/esm/internal/sourceUtils.d.ts.map +1 -0
  110. package/dist/esm/internal/sourceUtils.js +139 -0
  111. package/dist/esm/internal/sourceUtils.js.map +1 -0
  112. package/dist/esm/types.d.ts +96 -0
  113. package/dist/esm/types.d.ts.map +1 -0
  114. package/dist/esm/types.js +20 -0
  115. package/dist/esm/types.js.map +1 -0
  116. package/dist/esm/useApplyLens.d.ts +25 -0
  117. package/dist/esm/useApplyLens.d.ts.map +1 -0
  118. package/dist/esm/useApplyLens.js +81 -0
  119. package/dist/esm/useApplyLens.js.map +1 -0
  120. package/dist/esm/useApplySource.d.ts +11 -0
  121. package/dist/esm/useApplySource.d.ts.map +1 -0
  122. package/dist/esm/useApplySource.js +60 -0
  123. package/dist/esm/useApplySource.js.map +1 -0
  124. package/dist/esm/usePlaybackOptions.d.ts +38 -0
  125. package/dist/esm/usePlaybackOptions.d.ts.map +1 -0
  126. package/dist/esm/usePlaybackOptions.js +48 -0
  127. package/dist/esm/usePlaybackOptions.js.map +1 -0
  128. package/dist/esm/version.d.ts +3 -0
  129. package/dist/esm/version.d.ts.map +1 -0
  130. package/dist/esm/version.js +3 -0
  131. package/dist/esm/version.js.map +1 -0
  132. package/package.json +94 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApplyLens.js","sourceRoot":"","sources":["../../src/useApplyLens.ts"],"names":[],"mappings":";;;;;AA2BA,oCAgEC;AA3FD,iCAAmD;AAEnD,8DAA+B;AAC/B,2DAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,YAAY,CAC1B,MAAe,EACf,WAAoB,EACpB,cAA+B,EAC/B,cAAoC;IAEpC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAA,wCAAoB,GAAE,CAAC;IAC1G,MAAM,GAAG,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IAEtC,M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,OAAO,CAAC;iBACnD,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,SAAS;oBAAE,OAAO;gBACtB,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;YACpE,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzB,GAAG,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;AACzG,CAAC","sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { LensLaunchData } from \"@snap/camera-kit\";\nimport hash from \"stable-hash\";\nimport { useInternalCameraKit } from \"./CameraKitProvider\";\n\n/**\n * Declaratively applies a Lens to the current CameraKit session.\n *\n * This hook synchronizes the active lens with the provided parameters. When the lens ID,\n * group ID, or launch data changes, the hook automatically applies the new lens or removes\n * the current lens if parameters are cleared.\n *\n * @param lensId - The unique identifier of the lens to apply. If undefined, removes the current lens.\n * @param lensGroupId - The group ID containing the lens. Required when lensId is provided.\n * @param lensLaunchData - Optional launch parameters to pass to the lens.\n * @param lensReadyGuard - Optional async guard that must resolve before the lens is considered ready.\n * Useful for coordinating lens application with animations or other async operations.\n *\n * @example\n * ```tsx\n * // Simple lens application\n * useApplyLens(\"lens-id-123\", \"my-group\");\n *\n * // With launch data\n * useApplyLens(\"lens-id-123\", \"my-group\", { launchParams: { hint: \"face\" } });\n * ```\n */\nexport function useApplyLens(\n lensId?: string,\n lensGroupId?: string,\n lensLaunchData?: LensLaunchData,\n lensReadyGuard?: () => Promise<void>,\n) {\n const { cameraKit, sdkStatus, currentSession, applyLens, removeLens, getLogger } = useInternalCameraKit();\n const log = getLogger(\"useApplyLens\");\n\n const launchKey = hash(lensLaunchData);\n const safeLaunchData = useMemo(() => lensLaunchData, [launchKey]);\n\n // Don’t put lensReadyGuard in the dependency array of the “apply-lens” effect:\n // the caller often passes it as an inline function, so its identity\n // changes on every render. Re-running the whole lens-apply sequence just\n // because the guard’s reference changed doesn't make any sense.\n // It does make sense ony next time lens is applied.\n // Instead, we store the latest guard in a ref that we update after each re-render.\n const guardRef = useRef(lensReadyGuard);\n useEffect(() => {\n guardRef.current = lensReadyGuard;\n });\n\n // Synchronize the current CameraKit session with the requested Lens.\n // * Runs when lensId, lensGroupId, or lensLaunchData meaningfully change (see stable-key check).\n // * Applies the Lens once, with an abort-guard so late resolutions don’t touch an unmounted component.\n useEffect(() => {\n if (sdkStatus !== \"ready\" || !cameraKit || !currentSession) return;\n\n if (!lensId || !lensGroupId) {\n removeLens();\n return;\n }\n\n let cancelled = false;\n const started = performance.now();\n\n log.info(\"apply_attempt\", { lensId, groupId: lensGroupId });\n\n (async () => {\n try {\n await applyLens(lensId, lensGroupId, safeLaunchData, guardRef.current);\n if (cancelled) {\n await removeLens();\n return;\n }\n log.info(\"apply_success\", {\n lensId,\n groupId: lensGroupId,\n elapsedMs: Math.round(performance.now() - started),\n });\n } catch (err) {\n if (cancelled) return;\n log.error(\"apply_failure\", { lensId, groupId: lensGroupId }, err);\n }\n })();\n\n return () => {\n cancelled = true;\n removeLens().catch((err) => {\n log.warn(\"remove_on_unmount_failed\", { lensId, groupId: lensGroupId }, err);\n });\n };\n }, [lensId, lensGroupId, launchKey, sdkStatus, cameraKit, currentSession, applyLens, removeLens, log]);\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { OutputSize, SourceInput } from "./types";
2
+ /**
3
+ * Declarative hook to apply a source to the current CameraKit session.
4
+ * This is a thin wrapper around the imperative `applySource` and `removeSource` methods
5
+ * exposed by `useCameraKit()`.
6
+ *
7
+ * @param source - The source input (camera, video, or image)
8
+ * @param outputSize - Optional output size configuration
9
+ */
10
+ export declare function useApplySource(source?: SourceInput, outputSize?: OutputSize): void;
11
+ //# sourceMappingURL=useApplySource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApplySource.d.ts","sourceRoot":"","sources":["../../src/useApplySource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,WAAgC,EAAE,UAAU,CAAC,EAAE,UAAU,QAmD/F"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useApplySource = useApplySource;
7
+ const react_1 = require("react");
8
+ const stable_hash_1 = __importDefault(require("stable-hash"));
9
+ const CameraKitProvider_1 = require("./CameraKitProvider");
10
+ /**
11
+ * Declarative hook to apply a source to the current CameraKit session.
12
+ * This is a thin wrapper around the imperative `applySource` and `removeSource` methods
13
+ * exposed by `useCameraKit()`.
14
+ *
15
+ * @param source - The source input (camera, video, or image)
16
+ * @param outputSize - Optional output size configuration
17
+ */
18
+ function useApplySource(source = { kind: "camera" }, outputSize) {
19
+ const { cameraKit, sdkStatus, currentSession, applySource, removeSource, getLogger } = (0, CameraKitProvider_1.useInternalCameraKit)();
20
+ const log = getLogger("useApplySource");
21
+ // Keeps the same source instance while `sourceKey` stays equal,
22
+ // this is needed because source can be provided as a regular inline object,
23
+ // which is recreated on each re-render.
24
+ const sourceKey = (0, stable_hash_1.default)(source);
25
+ const safeSource = (0, react_1.useMemo)(() => source, [sourceKey]);
26
+ // Stabilize outputSize reference to avoid unnecessary re-applications
27
+ const outputSizeKey = (0, stable_hash_1.default)(outputSize);
28
+ const safeOutputSize = (0, react_1.useMemo)(() => outputSize, [outputSizeKey]);
29
+ // Synchronize the current CameraKit session with the requested source.
30
+ // Runs when source or outputSize meaningfully change (see stable-key check).
31
+ // Applies the source once, with an abort-guard so late resolutions don't affect unmounted components.
32
+ (0, react_1.useEffect)(() => {
33
+ if (sdkStatus !== "ready" || !cameraKit || !currentSession)
34
+ return;
35
+ let cancelled = false;
36
+ const started = performance.now();
37
+ log.info("source_apply_attempt", { kind: safeSource.kind });
38
+ (async () => {
39
+ try {
40
+ await applySource(safeSource, safeOutputSize);
41
+ if (cancelled) {
42
+ log.info("source_remove_attempt", { kind: safeSource.kind, reason: "cancelled" });
43
+ await removeSource();
44
+ return;
45
+ }
46
+ log.info("source_apply_success", {
47
+ kind: safeSource.kind,
48
+ elapsedMs: Math.round(performance.now() - started),
49
+ });
50
+ }
51
+ catch (err) {
52
+ if (cancelled)
53
+ return;
54
+ log.error("source_apply_failure", { kind: safeSource.kind }, err);
55
+ }
56
+ })();
57
+ return () => {
58
+ cancelled = true;
59
+ log.info("source_remove_attempt", { kind: safeSource.kind, reason: "cleanup" });
60
+ removeSource().catch((err) => {
61
+ log.warn("source_remove_on_unmount_failed", { kind: safeSource.kind }, err);
62
+ });
63
+ };
64
+ }, [safeSource, safeOutputSize, sdkStatus, cameraKit, currentSession, applySource, removeSource, log]);
65
+ }
66
+ //# sourceMappingURL=useApplySource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApplySource.js","sourceRoot":"","sources":["../../src/useApplySource.ts"],"names":[],"mappings":";;;;;AAaA,wCAmDC;AAhED,iCAA2C;AAC3C,8DAA+B;AAC/B,2DAA2D;AAG3D;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,UAAuB;IAC9F,MAAM,EAAE,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IAAI,CAAC,sBAAsB,EAAE;oBAC/B,IAAI,EAAE,UAAU,CAAC,IAAI;oBACrB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;iBACnD,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,SAAS;oBAAE,OAAO;gBACtB,GAAG,CAAC,KAAK,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YACpE,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAChF,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC3B,GAAG,CAAC,IAAI,CAAC,iCAAiC,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;AACzG,CAAC","sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport hash from \"stable-hash\";\nimport { useInternalCameraKit } from \"./CameraKitProvider\";\nimport { OutputSize, SourceInput } from \"./types\";\n\n/**\n * Declarative hook to apply a source to the current CameraKit session.\n * This is a thin wrapper around the imperative `applySource` and `removeSource` methods\n * exposed by `useCameraKit()`.\n *\n * @param source - The source input (camera, video, or image)\n * @param outputSize - Optional output size configuration\n */\nexport function useApplySource(source: SourceInput = { kind: \"camera\" }, outputSize?: OutputSize) {\n const { cameraKit, sdkStatus, currentSession, applySource, removeSource, getLogger } = useInternalCameraKit();\n const log = getLogger(\"useApplySource\");\n\n // Keeps the same source instance while `sourceKey` stays equal,\n // this is needed because source can be provided as a regular inline object,\n // which is recreated on each re-render.\n const sourceKey = hash(source);\n const safeSource = useMemo(() => source, [sourceKey]);\n\n // Stabilize outputSize reference to avoid unnecessary re-applications\n const outputSizeKey = hash(outputSize);\n const safeOutputSize = useMemo(() => outputSize, [outputSizeKey]);\n\n // Synchronize the current CameraKit session with the requested source.\n // Runs when source or outputSize meaningfully change (see stable-key check).\n // Applies the source once, with an abort-guard so late resolutions don't affect unmounted components.\n useEffect(() => {\n if (sdkStatus !== \"ready\" || !cameraKit || !currentSession) return;\n\n let cancelled = false;\n const started = performance.now();\n\n log.info(\"source_apply_attempt\", { kind: safeSource.kind });\n\n (async () => {\n try {\n await applySource(safeSource, safeOutputSize);\n if (cancelled) {\n log.info(\"source_remove_attempt\", { kind: safeSource.kind, reason: \"cancelled\" });\n await removeSource();\n return;\n }\n log.info(\"source_apply_success\", {\n kind: safeSource.kind,\n elapsedMs: Math.round(performance.now() - started),\n });\n } catch (err) {\n if (cancelled) return;\n log.error(\"source_apply_failure\", { kind: safeSource.kind }, err);\n }\n })();\n\n return () => {\n cancelled = true;\n log.info(\"source_remove_attempt\", { kind: safeSource.kind, reason: \"cleanup\" });\n removeSource().catch((err) => {\n log.warn(\"source_remove_on_unmount_failed\", { kind: safeSource.kind }, err);\n });\n };\n }, [safeSource, safeOutputSize, sdkStatus, cameraKit, currentSession, applySource, removeSource, log]);\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { CameraKitSessionEvents, Lens, ScreenRegions } from "@snap/camera-kit";
2
+ export interface PlaybackOptions {
3
+ /**
4
+ * A maximum FPS, rendering will not exceed this limit.
5
+ *
6
+ * This may be useful to reduce CPU/GPU resource usage by CameraKit if, for example,
7
+ * the input media source has a low FPS – CameraKit would then not try to render more
8
+ * frequently than the source produces new frames.
9
+ *
10
+ * This may also be useful to gracefully degrade performance in situations where
11
+ * lowering FPS is preferable over alternatives.
12
+ */
13
+ fpsLimit?: number;
14
+ /**
15
+ * Whether to mute all sounds. Unmuted by default.
16
+ */
17
+ muted?: boolean;
18
+ /**
19
+ * Configuration object containing the current set of screen regions.
20
+ *
21
+ * Screen regions define areas of the screen that have special meaning for Lens rendering,
22
+ * such as safe rendering areas, UI button locations, keyboard areas, etc. This allows lenses
23
+ * to adapt their content placement based on the host application's UI layout.
24
+ */
25
+ screenRegions?: ScreenRegions;
26
+ /**
27
+ * A callback to handle Lens playback errors.
28
+ */
29
+ onError?: (error: CameraKitSessionEvents["detail"]["error"], lens: Lens) => void;
30
+ }
31
+ /**
32
+ * Declarative hook to configure Lens playback options (FPS limit, muted state, screen regions).
33
+ * This is a thin wrapper around the imperative session control methods exposed by `useCameraKit()`.
34
+ *
35
+ * @param options - Session control options
36
+ */
37
+ export declare function usePlaybackOptions(options: PlaybackOptions): void;
38
+ //# sourceMappingURL=usePlaybackOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaybackOptions.d.ts","sourceRoot":"","sources":["../../src/usePlaybackOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG/E,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;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;CAClF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,QA2C1D"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePlaybackOptions = usePlaybackOptions;
4
+ const react_1 = require("react");
5
+ const CameraKitProvider_1 = require("./CameraKitProvider");
6
+ /**
7
+ * Declarative hook to configure Lens playback options (FPS limit, muted state, screen regions).
8
+ * This is a thin wrapper around the imperative session control methods exposed by `useCameraKit()`.
9
+ *
10
+ * @param options - Session control options
11
+ */
12
+ function usePlaybackOptions(options) {
13
+ const { currentSession, sdkStatus, setFPSLimit, setMuted, setScreenRegions, getLogger } = (0, CameraKitProvider_1.useInternalCameraKit)();
14
+ const log = getLogger("usePlaybackOptions");
15
+ (0, react_1.useEffect)(() => {
16
+ if (!currentSession || !options.onError)
17
+ return;
18
+ const handleError = (event) => {
19
+ options.onError?.(event.detail.error, event.detail.lens);
20
+ };
21
+ currentSession.events.addEventListener("error", handleError);
22
+ return () => {
23
+ currentSession.events.removeEventListener("error", handleError);
24
+ };
25
+ }, [currentSession, options.onError]);
26
+ (0, react_1.useEffect)(() => {
27
+ if (sdkStatus !== "ready" || !currentSession || options.fpsLimit === undefined)
28
+ return;
29
+ setFPSLimit(options.fpsLimit).catch((error) => {
30
+ log.error("fps_limit_apply_failed", { fpsLimit: options.fpsLimit }, error);
31
+ });
32
+ }, [currentSession, sdkStatus, options.fpsLimit, setFPSLimit, log]);
33
+ (0, react_1.useEffect)(() => {
34
+ if (sdkStatus !== "ready" || !currentSession || options.muted === undefined)
35
+ return;
36
+ try {
37
+ setMuted(options.muted);
38
+ }
39
+ catch (error) {
40
+ log.error("muted_state_apply_failed", { muted: options.muted }, error);
41
+ }
42
+ }, [currentSession, sdkStatus, options.muted, setMuted, log]);
43
+ (0, react_1.useEffect)(() => {
44
+ if (sdkStatus !== "ready" || !currentSession || !options.screenRegions)
45
+ return;
46
+ setScreenRegions(options.screenRegions).catch((error) => {
47
+ log.error("screen_regions_apply_failed", { screenRegions: options.screenRegions }, error);
48
+ });
49
+ }, [currentSession, sdkStatus, options.screenRegions, setScreenRegions, log]);
50
+ }
51
+ //# sourceMappingURL=usePlaybackOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaybackOptions.js","sourceRoot":"","sources":["../../src/usePlaybackOptions.ts"],"names":[],"mappings":";;AA2CA,gDA2CC;AAtFD,iCAAkC;AAElC,2DAA2D;AAmC3D;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,OAAwB;IACzD,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,GAAG,IAAA,wCAAoB,GAAE,CAAC;IACjH,MAAM,GAAG,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAE5C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,cAAc,IAAI,CAAC,OAAO,CAAC,OAAO;YAAE,OAAO;QAEhD,MAAM,WAAW,GAAG,CAAC,KAA6B,EAAE,EAAE;YACpD,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC,CAAC;QAEF,cAAc,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAE7D,OAAO,GAAG,EAAE;YACV,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAClE,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,SAAS,KAAK,OAAO,IAAI,CAAC,cAAc,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO;QAEvF,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EA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raKitSessionEvents, Lens, ScreenRegions } from \"@snap/camera-kit\";\nimport { useInternalCameraKit } from \"./CameraKitProvider\";\n\nexport interface PlaybackOptions {\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\n/**\n * Declarative hook to configure Lens playback options (FPS limit, muted state, screen regions).\n * This is a thin wrapper around the imperative session control methods exposed by `useCameraKit()`.\n *\n * @param options - Session control options\n */\nexport function usePlaybackOptions(options: PlaybackOptions) {\n const { currentSession, sdkStatus, setFPSLimit, setMuted, setScreenRegions, getLogger } = useInternalCameraKit();\n const log = getLogger(\"usePlaybackOptions\");\n\n useEffect(() => {\n if (!currentSession || !options.onError) return;\n\n const handleError = (event: CameraKitSessionEvents) => {\n options.onError?.(event.detail.error, event.detail.lens);\n };\n\n currentSession.events.addEventListener(\"error\", handleError);\n\n return () => {\n currentSession.events.removeEventListener(\"error\", handleError);\n };\n }, [currentSession, options.onError]);\n\n useEffect(() => {\n if (sdkStatus !== \"ready\" || !currentSession || options.fpsLimit === undefined) return;\n\n setFPSLimit(options.fpsLimit).catch((error) => {\n log.error(\"fps_limit_apply_failed\", { fpsLimit: options.fpsLimit }, error);\n });\n }, [currentSession, sdkStatus, options.fpsLimit, setFPSLimit, log]);\n\n useEffect(() => {\n if (sdkStatus !== \"ready\" || !currentSession || options.muted === undefined) return;\n\n try {\n setMuted(options.muted);\n } catch (error) {\n log.error(\"muted_state_apply_failed\", { muted: options.muted }, error);\n }\n }, [currentSession, sdkStatus, options.muted, setMuted, log]);\n\n useEffect(() => {\n if (sdkStatus !== \"ready\" || !currentSession || !options.screenRegions) return;\n\n setScreenRegions(options.screenRegions).catch((error) => {\n log.error(\"screen_regions_apply_failed\", { screenRegions: options.screenRegions }, error);\n });\n }, [currentSession, sdkStatus, options.screenRegions, setScreenRegions, log]);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ /** Package version — auto-synced from package.json by scripts/sync-version.sh. */
2
+ export declare const VERSION = "0.0.1";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ /** Package version — auto-synced from package.json by scripts/sync-version.sh. */
5
+ exports.VERSION = "0.0.1";
6
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,kFAAkF;AACrE,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/** Package version — auto-synced from package.json by scripts/sync-version.sh. */\nexport const VERSION = \"0.0.1\";\n"]}
@@ -0,0 +1,203 @@
1
+ import React, { ReactNode } from "react";
2
+ import { CameraKit, CameraKitBootstrapConfiguration, CameraKitSession, PublicContainer, Lens, LensLaunchData, ScreenRegions, Keyboard } from "@snap/camera-kit";
3
+ import { CurrentLens, CurrentSource, SourceInput, OutputSize } from "./types";
4
+ import { CameraKitLogger, LogLevel } from "./internal/logging";
5
+ export type MetricEventHandlerFactory = () => (event: {
6
+ kind: "bootstrap-attempt" | "bootstrap-success";
7
+ } | {
8
+ kind: "bootstrap-failure" | "lens-failure";
9
+ error: Error;
10
+ }) => void;
11
+ /**
12
+ * Public context interface exposed to consumers via useCameraKit hook.
13
+ * Provides access to Camera Kit SDK state, Lens management, source control, and playback options.
14
+ */
15
+ interface CameraKitContextValue {
16
+ /** Current SDK initialization status. */
17
+ sdkStatus: "uninitialized" | "initializing" | "ready" | "error";
18
+ /** Error that occurred during SDK initialization, if any. */
19
+ sdkError: Error | undefined;
20
+ /** Live canvas element for real-time preview rendering. */
21
+ liveCanvas: HTMLCanvasElement | undefined;
22
+ /** Capture canvas element for snapshot rendering. */
23
+ captureCanvas: HTMLCanvasElement | undefined;
24
+ /** Source state including status, input parameters, and any errors. */
25
+ source: CurrentSource;
26
+ /** Lens state including status, Lens object, and any errors. */
27
+ lens: CurrentLens;
28
+ /**
29
+ * The {@link Keyboard} API enables applications to handle keyboard input requests from lenses.
30
+ * When a lens requests a keyboard, the app displays it in its preferred UI. As users type,
31
+ * the app sends the text back to the lens for display. The lens can also request keyboard dismissal,
32
+ * prompting the app to remove the displayed keyboard.
33
+ */
34
+ keyboard: Keyboard | undefined;
35
+ /** Attempts to re-initialize the SDK after an error. Only available when SDK is in error state. */
36
+ reinitialize: () => void;
37
+ /** Applies a media source (camera, video, or image) to the session. */
38
+ applySource: (input: SourceInput, size?: OutputSize) => Promise<void>;
39
+ /** Removes the current source from the session. */
40
+ removeSource: () => Promise<void>;
41
+ /** Array of lenses that have been loaded via fetchLens or fetchLenses. */
42
+ lenses: Lens[];
43
+ /** Loads a single Lens by ID and group ID. Returns cached Lens if already loaded. */
44
+ fetchLens: (lensId: string, groupId: string) => Promise<Lens>;
45
+ /** Loads all lenses from one or more Lens groups. */
46
+ fetchLenses: (groupId: string | string[]) => Promise<Lens[]>;
47
+ /**
48
+ * Applies a Lens to the current session.
49
+ * @param lensId - The Lens identifier
50
+ * @param groupId - The Lens group identifier
51
+ * @param launchData - Optional launch parameters for the Lens
52
+ * @param lensReadyGuard - Optional async guard for coordinating Lens application
53
+ * @returns Promise that resolves to true if Lens was applied successfully
54
+ */
55
+ applyLens: (lensId: string, groupId: string, launchData?: LensLaunchData, lensReadyGuard?: () => Promise<void>) => Promise<boolean>;
56
+ /** Removes the currently applied Lens from the session. */
57
+ removeLens: () => Promise<boolean>;
58
+ /** Refreshes the current Lens by removing and reapplying it. */
59
+ refreshLens: () => Promise<void>;
60
+ /** Sets the muted state for audio playback. */
61
+ setMuted: (muted: boolean) => void;
62
+ /** Toggles the current muted state. */
63
+ toggleMuted: () => void;
64
+ /** Whether audio is currently muted. */
65
+ isMuted: boolean;
66
+ /** Current FPS limit, if set. */
67
+ fpsLimit: number | undefined;
68
+ /** Sets the maximum FPS for rendering. Useful for reducing resource usage. */
69
+ setFPSLimit: (fpsLimit: number) => Promise<void>;
70
+ /** Current screen regions configuration, if set. */
71
+ screenRegions: ScreenRegions | undefined;
72
+ /** Sets screen regions for Lens-aware UI layout. */
73
+ setScreenRegions: (screenRegions: ScreenRegions) => Promise<void>;
74
+ }
75
+ interface InternalCameraKitContextValue extends CameraKitContextValue {
76
+ cameraKit: CameraKit | undefined;
77
+ currentSession: CameraKitSession | undefined;
78
+ getLogger: (ns: string) => CameraKitLogger;
79
+ }
80
+ /**
81
+ * Props for the CameraKitProvider component.
82
+ * Extends Camera Kit bootstrap configuration with React-specific options.
83
+ */
84
+ interface CameraKitProviderProps extends Omit<CameraKitBootstrapConfiguration, "logger"> {
85
+ /**
86
+ * Optional function to extend the Camera Kit dependency injection container.
87
+ * This is the second parameter to bootstrapCameraKit and allows customization
88
+ * of the SDK's internal dependencies.
89
+ */
90
+ extendContainer?: (container: PublicContainer) => PublicContainer;
91
+ /**
92
+ * Optional factory for creating bootstrap event handlers for metrics/analytics.
93
+ * Useful for tracking SDK initialization success/failure in your analytics system.
94
+ */
95
+ createBootstrapEventHandler?: MetricEventHandlerFactory;
96
+ /**
97
+ * Optional custom logger implementation. If not provided, a no-op logger is used by default.
98
+ * Pass createConsoleLogger() from './logging' for console-based logging in development.
99
+ *
100
+ * @example
101
+ * ```tsx
102
+ * import { createConsoleLogger } from '@snap/react-camera-kit';
103
+ *
104
+ * <CameraKitProvider logger={createConsoleLogger()} logLevel="debug">
105
+ * {children}
106
+ * </CameraKitProvider>
107
+ * ```
108
+ */
109
+ logger?: CameraKitLogger;
110
+ /**
111
+ * Optional log level to control logger verbosity. Defaults to "info" if not specified.
112
+ * Supported levels: "debug", "info", "warn", "error".
113
+ */
114
+ logLevel?: LogLevel;
115
+ /**
116
+ * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame
117
+ * callbacks.
118
+ *
119
+ * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.
120
+ * There is a small performance penalty, and it's a good practice to only render in the background if absolutely
121
+ * necessary.
122
+ */
123
+ renderWhileTabHidden?: boolean;
124
+ /**
125
+ * Optional manual override for bootstrap stability. If provided, the provider will re-bootstrap
126
+ * whenever this value changes, regardless of other config details.
127
+ *
128
+ * Useful when you want explicit control over when the SDK reinitializes.
129
+ */
130
+ stabilityKey?: string | number;
131
+ /**
132
+ * React children to render within the provider.
133
+ */
134
+ children: ReactNode;
135
+ }
136
+ /**
137
+ * Provider component that initializes and manages the Camera Kit SDK.
138
+ *
139
+ * This component handles SDK bootstrapping, session creation, and provides access to
140
+ * Camera Kit functionality through React context. All Camera Kit hooks and components
141
+ * must be used within this provider.
142
+ *
143
+ * The provider automatically manages SDK lifecycle, including initialization, cleanup,
144
+ * and re-initialization when configuration changes.
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * import { CameraKitProvider, createConsoleLogger } from '@snap/react-camera-kit';
149
+ *
150
+ * function App() {
151
+ * return (
152
+ * <CameraKitProvider
153
+ * apiToken="your-api-token"
154
+ * logger={createConsoleLogger()}
155
+ * logLevel="debug"
156
+ * >
157
+ * <YourCameraKitComponents />
158
+ * </CameraKitProvider>
159
+ * );
160
+ * }
161
+ * ```
162
+ */
163
+ export declare const CameraKitProvider: React.FC<CameraKitProviderProps>;
164
+ /**
165
+ * Internal hook with access to Camera Kit internals.
166
+ * Only for use within react-camera-kit library components and hooks.
167
+ *
168
+ * @internal
169
+ */
170
+ export declare const useInternalCameraKit: () => InternalCameraKitContextValue;
171
+ /**
172
+ * Hook to access Camera Kit context and methods.
173
+ *
174
+ * Provides access to SDK state, Lens management, source control, and playback options.
175
+ * Must be used within a CameraKitProvider.
176
+ *
177
+ * @returns Camera Kit context value with state and methods
178
+ * @throws Error if used outside of CameraKitProvider
179
+ *
180
+ * @example
181
+ * ```tsx
182
+ * function MyComponent() {
183
+ * const {
184
+ * sdkStatus,
185
+ * lens,
186
+ * applyLens,
187
+ * removeLens,
188
+ * liveCanvas
189
+ * } = useCameraKit();
190
+ *
191
+ * useEffect(() => {
192
+ * if (sdkStatus === 'ready') {
193
+ * applyLens('lens-id', 'group-id');
194
+ * }
195
+ * }, [sdkStatus, applyLens]);
196
+ *
197
+ * return <div>{lens.status}</div>;
198
+ * }
199
+ * ```
200
+ */
201
+ export declare const useCameraKit: () => CameraKitContextValue;
202
+ export {};
203
+ //# sourceMappingURL=CameraKitProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraKitProvider.d.ts","sourceRoot":"","sources":["../../src/CameraKitProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkD,SAAS,EAAgC,MAAM,OAAO,CAAC;AACvH,OAAO,EACL,SAAS,EACT,+BAA+B,EAC/B,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,cAAc,EAGd,aAAa,EACb,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAmB,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAkB,QAAQ,EAAgC,MAAM,oBAAoB,CAAC;AAU7G,MAAM,MAAM,yBAAyB,GAAG,MAAM,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