@snap/camera-kit 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +56 -54
  2. package/dist/CameraKit.d.ts +7 -0
  3. package/dist/CameraKit.d.ts.map +1 -1
  4. package/dist/CameraKit.js +7 -0
  5. package/dist/CameraKit.js.map +1 -1
  6. package/dist/common/loadScript.d.ts +2 -1
  7. package/dist/common/loadScript.d.ts.map +1 -1
  8. package/dist/common/loadScript.js.map +1 -1
  9. package/dist/configuration.d.ts +15 -9
  10. package/dist/configuration.d.ts.map +1 -1
  11. package/dist/configuration.js +5 -2
  12. package/dist/configuration.js.map +1 -1
  13. package/dist/environment.js +1 -1
  14. package/dist/environment.js.map +1 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/lens-core-module/generated-types.d.ts +13 -1
  19. package/dist/lens-core-module/generated-types.d.ts.map +1 -1
  20. package/dist/lens-core-module/generated-types.js.map +1 -1
  21. package/dist/lens-core-module/loader/lensCoreFactory.d.ts.map +1 -1
  22. package/dist/lens-core-module/loader/lensCoreFactory.js +7 -5
  23. package/dist/lens-core-module/loader/lensCoreFactory.js.map +1 -1
  24. package/dist/lensCoreWasmVersions.js +3 -3
  25. package/dist/lensCoreWasmVersions.js.map +1 -1
  26. package/dist/logger/logger.d.ts +45 -9
  27. package/dist/logger/logger.d.ts.map +1 -1
  28. package/dist/logger/logger.js +21 -1
  29. package/dist/logger/logger.js.map +1 -1
  30. package/dist/logger/registerLogEntriesSubscriber.d.ts.map +1 -1
  31. package/dist/logger/registerLogEntriesSubscriber.js +2 -15
  32. package/dist/logger/registerLogEntriesSubscriber.js.map +1 -1
  33. package/dist/metrics/businessEventsReporter.js +1 -1
  34. package/dist/metrics/businessEventsReporter.js.map +1 -1
  35. package/dist/trusted-types/trustedTypesHandler.d.ts +20 -0
  36. package/dist/trusted-types/trustedTypesHandler.d.ts.map +1 -0
  37. package/dist/trusted-types/trustedTypesHandler.js +30 -0
  38. package/dist/trusted-types/trustedTypesHandler.js.map +1 -0
  39. package/docs/html/assets/hierarchy.js +1 -1
  40. package/docs/html/assets/navigation.js +1 -1
  41. package/docs/html/assets/search.js +1 -1
  42. package/docs/html/classes/CameraKit.html +2 -2
  43. package/docs/html/classes/CameraKitSession.html +2 -2
  44. package/docs/html/classes/CameraKitSource.html +2 -2
  45. package/docs/html/classes/LensPerformanceMeasurement.html +2 -2
  46. package/docs/html/classes/LensPerformanceMetrics.html +2 -2
  47. package/docs/html/classes/LensRepository.html +2 -2
  48. package/docs/html/classes/Transform2D.html +2 -2
  49. package/docs/html/classes/TypedCustomEvent.html +3 -3
  50. package/docs/html/classes/TypedEventTarget.html +2 -2
  51. package/docs/html/enums/Lens_CameraFacing.html +2 -2
  52. package/docs/html/functions/bootstrapCameraKit.html +2 -2
  53. package/docs/html/functions/createExtension.html +2 -2
  54. package/docs/html/functions/createImageSource.html +2 -2
  55. package/docs/html/functions/createMediaStreamSource.html +2 -2
  56. package/docs/html/functions/createVideoSource.html +2 -2
  57. package/docs/html/functions/estimateLensPerformance.html +2 -2
  58. package/docs/html/functions/filePickerFactory.html +2 -2
  59. package/docs/html/functions/getExtensionRequestContext.html +2 -2
  60. package/docs/html/functions/lensSourcesFactory.html +2 -2
  61. package/docs/html/functions/remoteApiServicesFactory.html +1 -1
  62. package/docs/html/hierarchy.html +1 -1
  63. package/docs/html/index.html +19 -19
  64. package/docs/html/interfaces/BitmojiUserInfo.html +2 -2
  65. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +12 -9
  66. package/docs/html/interfaces/CameraKitDeviceOptions.html +3 -3
  67. package/docs/html/interfaces/CameraKitSourceInfo.html +2 -2
  68. package/docs/html/interfaces/CameraKitSourceSubscriber.html +2 -2
  69. package/docs/html/interfaces/ComputedFrameMetrics.html +2 -2
  70. package/docs/html/interfaces/CreateSessionOptions.html +2 -2
  71. package/docs/html/interfaces/EstimatedLensPerformance.html +2 -2
  72. package/docs/html/interfaces/Font.html +2 -2
  73. package/docs/html/interfaces/FriendUserInfo.html +2 -2
  74. package/docs/html/interfaces/FunctionSourceOptions.html +2 -2
  75. package/docs/html/interfaces/Keyboard.html +2 -2
  76. package/docs/html/interfaces/KeyboardActiveEvent.html +2 -2
  77. package/docs/html/interfaces/Lens.html +2 -2
  78. package/docs/html/interfaces/LensCreator.html +2 -2
  79. package/docs/html/interfaces/LensHttpRequest.html +2 -2
  80. package/docs/html/interfaces/LensLaunchData.html +2 -2
  81. package/docs/html/interfaces/LensSource.html +2 -2
  82. package/docs/html/interfaces/LensUserData.html +2 -2
  83. package/docs/html/interfaces/LoadAssetRequest.html +2 -2
  84. package/docs/html/interfaces/MediaStreamSourceOptions.html +3 -3
  85. package/docs/html/interfaces/Preview.html +2 -2
  86. package/docs/html/interfaces/RemoteApiRequest.html +2 -2
  87. package/docs/html/interfaces/RemoteApiResponse.html +2 -2
  88. package/docs/html/interfaces/RemoteApiService.html +2 -2
  89. package/docs/html/interfaces/ScreenRegion.html +2 -2
  90. package/docs/html/interfaces/Snapcode.html +2 -2
  91. package/docs/html/interfaces/UriCancelRequest.html +2 -2
  92. package/docs/html/interfaces/UriRequest.html +2 -2
  93. package/docs/html/interfaces/UriResponse.html +2 -2
  94. package/docs/html/interfaces/VideoSourceOptions.html +3 -3
  95. package/docs/html/modules.html +1 -1
  96. package/docs/html/types/ArgumentValidationError.html +2 -2
  97. package/docs/html/types/AssetLoader.html +2 -2
  98. package/docs/html/types/AssetResponse.html +1 -1
  99. package/docs/html/types/AssetTiming.html +2 -2
  100. package/docs/html/types/BenchmarkError.html +1 -1
  101. package/docs/html/types/BootstrapError.html +2 -2
  102. package/docs/html/types/CacheKeyNotFoundError.html +1 -1
  103. package/docs/html/types/CameraKitSessionEventListener.html +2 -2
  104. package/docs/html/types/CameraKitSessionEvents.html +2 -2
  105. package/docs/html/types/CameraKitSourceError.html +1 -1
  106. package/docs/html/types/ConfigurationError.html +2 -2
  107. package/docs/html/types/FetchHandler.html +1 -1
  108. package/docs/html/types/FilePicker.html +2 -2
  109. package/docs/html/types/FilePickerOptions.html +2 -2
  110. package/docs/html/types/FilePickerResult.html +2 -2
  111. package/docs/html/types/KeyboardEventListener.html +2 -2
  112. package/docs/html/types/KeyboardEvents.html +2 -2
  113. package/docs/html/types/LegalError.html +1 -1
  114. package/docs/html/types/LensAbortError.html +2 -2
  115. package/docs/html/types/LensAssetError.html +2 -2
  116. package/docs/html/types/LensContentValidationError.html +1 -1
  117. package/docs/html/types/LensError.html +1 -1
  118. package/docs/html/types/LensExecutionError.html +2 -2
  119. package/docs/html/types/LensHttpHandler.html +2 -2
  120. package/docs/html/types/LensImagePickerError.html +2 -2
  121. package/docs/html/types/LensLaunchParams.html +2 -2
  122. package/docs/html/types/LensMetricsEvents.html +2 -2
  123. package/docs/html/types/LensPerformanceCluster.html +1 -1
  124. package/docs/html/types/LensView.html +2 -2
  125. package/docs/html/types/LensWait.html +2 -2
  126. package/docs/html/types/LogLevel.html +11 -0
  127. package/docs/html/types/Logger.html +5 -0
  128. package/docs/html/types/Matrix.html +2 -2
  129. package/docs/html/types/PersistentStoreError.html +2 -2
  130. package/docs/html/types/PlatformNotSupportedError.html +2 -2
  131. package/docs/html/types/PublicContainer.html +2 -2
  132. package/docs/html/types/PublicServices.html +2 -2
  133. package/docs/html/types/RemoteApiCancelRequestHandler.html +2 -2
  134. package/docs/html/types/RemoteApiRequestHandler.html +2 -2
  135. package/docs/html/types/RemoteApiServices.html +1 -1
  136. package/docs/html/types/RemoteApiStatus.html +2 -2
  137. package/docs/html/types/RenderTarget.html +2 -2
  138. package/docs/html/types/ScreenRegionType.html +2 -2
  139. package/docs/html/types/ScreenRegions.html +2 -2
  140. package/docs/html/types/Uri.html +1 -1
  141. package/docs/html/types/WebGLError.html +1 -1
  142. package/docs/html/types/Zodiac.html +1 -1
  143. package/docs/html/variables/extensionRequestContext.html +2 -2
  144. package/docs/md/README.md +57 -55
  145. package/docs/md/classes/CameraKit.md +1 -1
  146. package/docs/md/classes/CameraKitSession.md +1 -1
  147. package/docs/md/classes/CameraKitSource.md +1 -1
  148. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  149. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  150. package/docs/md/classes/LensRepository.md +1 -1
  151. package/docs/md/classes/Transform2D.md +1 -1
  152. package/docs/md/classes/TypedCustomEvent.md +1 -1
  153. package/docs/md/classes/TypedEventTarget.md +1 -1
  154. package/docs/md/enumerations/Lens_CameraFacing.md +1 -1
  155. package/docs/md/functions/bootstrapCameraKit.md +1 -1
  156. package/docs/md/functions/createExtension.md +1 -1
  157. package/docs/md/functions/createImageSource.md +1 -1
  158. package/docs/md/functions/createMediaStreamSource.md +1 -1
  159. package/docs/md/functions/createVideoSource.md +1 -1
  160. package/docs/md/functions/estimateLensPerformance.md +1 -1
  161. package/docs/md/functions/filePickerFactory.md +1 -1
  162. package/docs/md/functions/getExtensionRequestContext.md +1 -1
  163. package/docs/md/functions/lensSourcesFactory.md +1 -1
  164. package/docs/md/functions/remoteApiServicesFactory.md +1 -1
  165. package/docs/md/globals.md +4 -2
  166. package/docs/md/interfaces/BitmojiUserInfo.md +1 -1
  167. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +16 -7
  168. package/docs/md/interfaces/CameraKitDeviceOptions.md +1 -1
  169. package/docs/md/interfaces/CameraKitSourceInfo.md +1 -1
  170. package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
  171. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  172. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  173. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  174. package/docs/md/interfaces/Font.md +1 -1
  175. package/docs/md/interfaces/FriendUserInfo.md +1 -1
  176. package/docs/md/interfaces/FunctionSourceOptions.md +1 -1
  177. package/docs/md/interfaces/Keyboard.md +1 -1
  178. package/docs/md/interfaces/KeyboardActiveEvent.md +1 -1
  179. package/docs/md/interfaces/Lens.md +1 -1
  180. package/docs/md/interfaces/LensCreator.md +1 -1
  181. package/docs/md/interfaces/LensHttpRequest.md +1 -1
  182. package/docs/md/interfaces/LensLaunchData.md +1 -1
  183. package/docs/md/interfaces/LensSource.md +1 -1
  184. package/docs/md/interfaces/LensUserData.md +1 -1
  185. package/docs/md/interfaces/LoadAssetRequest.md +1 -1
  186. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  187. package/docs/md/interfaces/Preview.md +1 -1
  188. package/docs/md/interfaces/RemoteApiRequest.md +1 -1
  189. package/docs/md/interfaces/RemoteApiResponse.md +1 -1
  190. package/docs/md/interfaces/RemoteApiService.md +1 -1
  191. package/docs/md/interfaces/ScreenRegion.md +1 -1
  192. package/docs/md/interfaces/Snapcode.md +1 -1
  193. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  194. package/docs/md/interfaces/UriRequest.md +1 -1
  195. package/docs/md/interfaces/UriResponse.md +1 -1
  196. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  197. package/docs/md/type-aliases/ArgumentValidationError.md +1 -1
  198. package/docs/md/type-aliases/AssetLoader.md +1 -1
  199. package/docs/md/type-aliases/AssetResponse.md +1 -1
  200. package/docs/md/type-aliases/AssetTiming.md +1 -1
  201. package/docs/md/type-aliases/BenchmarkError.md +1 -1
  202. package/docs/md/type-aliases/BootstrapError.md +1 -1
  203. package/docs/md/type-aliases/CacheKeyNotFoundError.md +1 -1
  204. package/docs/md/type-aliases/CameraKitSessionEventListener.md +1 -1
  205. package/docs/md/type-aliases/CameraKitSessionEvents.md +1 -1
  206. package/docs/md/type-aliases/CameraKitSourceError.md +1 -1
  207. package/docs/md/type-aliases/ConfigurationError.md +1 -1
  208. package/docs/md/type-aliases/FetchHandler.md +1 -1
  209. package/docs/md/type-aliases/FilePicker.md +1 -1
  210. package/docs/md/type-aliases/FilePickerOptions.md +1 -1
  211. package/docs/md/type-aliases/FilePickerResult.md +1 -1
  212. package/docs/md/type-aliases/KeyboardEventListener.md +1 -1
  213. package/docs/md/type-aliases/KeyboardEvents.md +1 -1
  214. package/docs/md/type-aliases/LegalError.md +1 -1
  215. package/docs/md/type-aliases/LensAbortError.md +1 -1
  216. package/docs/md/type-aliases/LensAssetError.md +1 -1
  217. package/docs/md/type-aliases/LensContentValidationError.md +1 -1
  218. package/docs/md/type-aliases/LensError.md +1 -1
  219. package/docs/md/type-aliases/LensExecutionError.md +1 -1
  220. package/docs/md/type-aliases/LensHttpHandler.md +1 -1
  221. package/docs/md/type-aliases/LensImagePickerError.md +1 -1
  222. package/docs/md/type-aliases/LensLaunchParams.md +1 -1
  223. package/docs/md/type-aliases/LensMetricsEvents.md +1 -1
  224. package/docs/md/type-aliases/LensPerformanceCluster.md +1 -1
  225. package/docs/md/type-aliases/LensView.md +1 -1
  226. package/docs/md/type-aliases/LensWait.md +1 -1
  227. package/docs/md/type-aliases/LogLevel.md +20 -0
  228. package/docs/md/type-aliases/Logger.md +15 -0
  229. package/docs/md/type-aliases/Matrix.md +1 -1
  230. package/docs/md/type-aliases/PersistentStoreError.md +1 -1
  231. package/docs/md/type-aliases/PlatformNotSupportedError.md +1 -1
  232. package/docs/md/type-aliases/PublicContainer.md +1 -1
  233. package/docs/md/type-aliases/PublicServices.md +1 -1
  234. package/docs/md/type-aliases/RemoteApiCancelRequestHandler.md +1 -1
  235. package/docs/md/type-aliases/RemoteApiRequestHandler.md +1 -1
  236. package/docs/md/type-aliases/RemoteApiServices.md +1 -1
  237. package/docs/md/type-aliases/RemoteApiStatus.md +1 -1
  238. package/docs/md/type-aliases/RenderTarget.md +1 -1
  239. package/docs/md/type-aliases/ScreenRegionType.md +1 -1
  240. package/docs/md/type-aliases/ScreenRegions.md +1 -1
  241. package/docs/md/type-aliases/Uri.md +1 -1
  242. package/docs/md/type-aliases/WebGLError.md +1 -1
  243. package/docs/md/type-aliases/Zodiac.md +1 -1
  244. package/docs/md/variables/extensionRequestContext.md +1 -1
  245. package/package.json +3 -2
package/README.md CHANGED
@@ -4,26 +4,28 @@ The Camera Kit Web SDK allows web developers to build Snap's core AR Lens techno
4
4
 
5
5
  ## Minimum browser requirements
6
6
 
7
- - **Chrome 73+**
8
- - **Safari 15+**
9
- - MacOS 12+, iOS 15+, iPadOS 15+
10
- - SIMD: Unsupported
11
- - Web Worker Mode\*: Unsupported
12
- - **Edge 79+**
13
- - Edge is still currently under evaluation. However, since New Edge is Chromium based, the expectations are similar to that of Chrome.
14
- - **Firefox** - Under Evaluation
15
- - Web Worker Mode\*: Firefox 105+
7
+ - **Chrome 95+**
8
+ - **Safari 16+**
9
+ - MacOS 12+, iOS 15+, iPadOS 15+
10
+ - SIMD: Unsupported
11
+ - Web Worker Mode\*: Unsupported
12
+ - **Edge 79+**
13
+ - Edge is still currently under evaluation. However, since New Edge is Chromium based, the expectations are similar to that of Chrome.
14
+ - **Firefox** — Under Evaluation
15
+ - Web Worker Mode\*: Firefox 105+
16
16
 
17
17
  \*Web Worker Mode requires `OffscreenCanvas` support.
18
18
 
19
19
  ## Prerequisites
20
20
 
21
21
  ### Snap Developer set up
22
+
22
23
  You'll need a Snap Developer account, and you'll need to apply for access to Camera Kit Web SDK. You can find more info on that [here](https://docs.snap.com/camera-kit/getting-started/setting-up-accounts).
23
24
 
24
25
  You may also want to familiarize yourself with how to access and manage AR content (i.e. Lenses). You read about that [here](https://docs.snap.com/camera-kit/ar-content/camera-kit-portal).
25
26
 
26
27
  ### Development environment
28
+
27
29
  This guide assumes you've already set up an [NPM](https://www.npmjs.com/) package, you're using [TypeScript](https://www.typescriptlang.org/), and have some way to build and host your project during development (e.g. using [Webpack](https://webpack.js.org/)).
28
30
 
29
31
  #### Using the SDK in a JavaScript project
@@ -36,8 +38,8 @@ If your project already has a [Content Security Policy](https://developer.mozill
36
38
 
37
39
  When it bootstraps, Camera Kit Web SDK downloads an executable WebAssembly file containing the Lens rendering engine. This file is served from an optimized CDN managed by Snap. You'll need to make sure your Content Security Policy allows this file to be executed.
38
40
 
39
- - `connect-src` must include `https://*.snapar.com`, otherwise Camera Kit Web will fail to initialize.
40
- - `script-src` must include `https://cf-st.sc-cdn.net/ blob: 'wasm-unsafe-eval'`.
41
+ - `connect-src` must include `https://*.snapar.com`, otherwise Camera Kit Web will fail to initialize.
42
+ - `script-src` must include `https://cf-st.sc-cdn.net/ blob: 'wasm-unsafe-eval'`.
41
43
 
42
44
  _Note: Some older browser versions may not support the `'wasm-unsafe-eval'` source value, and it may be necessary to use `'unsafe-eval'` to allow Camera Kit's downloaded WebAssembly to run._
43
45
 
@@ -87,8 +89,8 @@ canvasContainer.appendChild(session.output.live);
87
89
 
88
90
  There are actually two different output canvases:
89
91
 
90
- - `live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens.
91
- - `capture`: This canvas renders content intended for presenting to other users.
92
+ - `live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens.
93
+ - `capture`: This canvas renders content intended for presenting to other users.
92
94
 
93
95
  These two output canvases correspond to the two different [RenderTargets](https://docs.snap.com/lens-studio/references/guides/lens-features/scene-set-up/camera#render-target) a Lens may use to render its content. Not all Lenses will render different content to `live` vs. `capture`, so it's important to understand how the Lenses you'll be using use these two different outputs.
94
96
 
@@ -105,10 +107,10 @@ The most common source of input media is the user's webcam. Camera Kit Web SDK p
105
107
  Once we have a `CameraKitSource`, we can tell the `CameraKitSession` to use this source for rendering.
106
108
 
107
109
  ```ts
108
- import { createMediaStreamSource, Transform2D } from "@snap/camera-kit"
110
+ import { createMediaStreamSource, Transform2D } from "@snap/camera-kit";
109
111
 
110
112
  const stream = await navigator.mediaDevices.getUserMedia({ video: true });
111
- const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: 'user' });
113
+ const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: "user" });
112
114
  await session.setSource(source);
113
115
  ```
114
116
 
@@ -116,9 +118,9 @@ In this example, we also mirror the source stream (which feels more natural in m
116
118
 
117
119
  Camera Kit Web SDK has helper methods to create a `CameraKitSource` from:
118
120
 
119
- - A `MediaStream` object, which could come from the user's camera, a WebRTC connection, a `<canvas>` via the [`captureStream()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream), or elsewhere.
120
- - A `<video>` element (i.e. `HTMLVideoElement`)
121
- - An `<img>`element (i.e. `HTMLImageElement`)
121
+ - A `MediaStream` object, which could come from the user's camera, a WebRTC connection, a `<canvas>` via the [`captureStream()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream), or elsewhere.
122
+ - A `<video>` element (i.e. `HTMLVideoElement`)
123
+ - An `<img>`element (i.e. `HTMLImageElement`)
122
124
 
123
125
  ## Loading, applying, and removing Lenses
124
126
 
@@ -134,19 +136,18 @@ const lens = await cameraKit.lensRepository.loadLens("<Lens ID>", "<Lens Group I
134
136
  await session.applyLens(lens);
135
137
 
136
138
  // Loading one or more Lens Groups – Lenses from all groups are returned as a single array of lenses.
137
- const { lenses } = await cameraKit.lensRepository.loadLensGroups([
138
- "<Lens Group ID 1>",
139
- "<Lens Group ID 2>",
140
- ]);
139
+ const { lenses } = await cameraKit.lensRepository.loadLensGroups(["<Lens Group ID 1>", "<Lens Group ID 2>"]);
141
140
  await session.applyLens(lenses[0]);
142
141
  ```
143
142
 
144
143
  ### Removing the Lens
145
144
 
146
145
  You can also remove the currently-applied Lens:
146
+
147
147
  ```ts
148
148
  await session.removeLens();
149
149
  ```
150
+
150
151
  After removing the Lens, when the session renders it will simply render the input media directly to the output canvas.
151
152
 
152
153
  ## Playback
@@ -165,36 +166,36 @@ session.pause();
165
166
  By default, `play()` will only begin rendering the `live` output canvas. You can specify which canvas to render by passing an argument:
166
167
 
167
168
  ```ts
168
- session.play('live');
169
- session.play('capture');
169
+ session.play("live");
170
+ session.play("capture");
170
171
  ```
171
172
 
172
173
  Calling `pause()` with no arguments will pause both outputs. But just like with `play()`, you can pass an argument to select which canvas to pause.
173
174
 
174
175
  ```ts
175
- session.pause('live');
176
- session.pause('capture');
176
+ session.pause("live");
177
+ session.pause("capture");
177
178
  ```
178
179
 
179
- > - _`live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens._
180
- > - _`capture`: This canvas renders content intended for presenting to other users._
180
+ > - _`live`: This canvas renders content intended for the Lens user. Depending on the Lens being used, this canvas may include UI elements, prompts, or other content that is only meant to be seen by the user of the Lens._
181
+ > - _`capture`: This canvas renders content intended for presenting to other users._
181
182
 
182
183
  ## Error Handling
183
184
 
184
- Camera Kit Web SDK methods may throw errors, or return rejected Promises -- these are documented in the [API docs](https://kit.snapchat.com/reference/CameraKit/web/1.10.0/index.html). It is good practice to handle such cases, to provide a good experience to your users.
185
+ Camera Kit Web SDK methods may throw errors, or return rejected Promises -- these are documented in the [API docs](https://kit.snapchat.com/reference/CameraKit/web/1.12.0/index.html). It is good practice to handle such cases, to provide a good experience to your users.
185
186
 
186
187
  Errors may also occur during Lens rendering. For example, Lenses contain their own scripting, which could throw an error. A rendering error could also occur if a Lens attempts to use a feature that is not supported by Camera Kit Web SDK.
187
188
 
188
189
  When a `LensExecutionError` such as these occurs, the Lens is **automatically removed** from the `CameraKitSession`. An error event is emitted so that your application can respond appropriately. You can listen to these error events like so:
189
190
 
190
191
  ```ts
191
- session.events.addEventListener('error', (event) => {
192
- console.error(event.detail.error);
192
+ session.events.addEventListener("error", (event) => {
193
+ console.error(event.detail.error);
193
194
 
194
- if (event.detail.error.name === 'LensExecutionError') {
195
- // The currently-applied Lens encountered a problem that is most likely unrecoverable and the Lens has been removed.
196
- // Your application may want to prevent this Lens from being applied again.
197
- }
195
+ if (event.detail.error.name === "LensExecutionError") {
196
+ // The currently-applied Lens encountered a problem that is most likely unrecoverable and the Lens has been removed.
197
+ // Your application may want to prevent this Lens from being applied again.
198
+ }
198
199
  });
199
200
  ```
200
201
 
@@ -211,14 +212,14 @@ import { boostrapCameraKit, createMediaStreamSource } from "@snap/camera-kit";
211
212
 
212
213
  const canvas = document.getElementById("my-canvas");
213
214
  const session = await cameraKit.createSession({ liveRenderTarget: canvas });
214
- session.events.addEventListener('error', (event) => {
215
- if (event.detail.error.name === 'LensExecutionError') {
216
- console.log('The current Lens encountered an error and was removed.', event.detail.error);
217
- }
215
+ session.events.addEventListener("error", (event) => {
216
+ if (event.detail.error.name === "LensExecutionError") {
217
+ console.log("The current Lens encountered an error and was removed.", event.detail.error);
218
+ }
218
219
  });
219
220
 
220
221
  const stream = await navigator.mediaDevices.getUserMedia({ video: true });
221
- const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: 'user' });
222
+ const source = createMediaStreamSource(stream, { transform: Transform2D.MirrorX, cameraType: "user" });
222
223
  await session.setSource(source);
223
224
 
224
225
  const lens = await cameraKit.lensRepository.loadLens("<Lens ID>", "<Lens Group ID>");
@@ -239,8 +240,8 @@ By default, Camera Kit Web SDK does very minimal logging. Specifying `'console'`
239
240
 
240
241
  ```ts
241
242
  const cameraKit = await bootstrapCameraKit({
242
- apiToken: '<apiToken>',
243
- logger: 'console',
243
+ apiToken: "<apiToken>",
244
+ logger: "console",
244
245
  });
245
246
  ```
246
247
 
@@ -249,7 +250,7 @@ const cameraKit = await bootstrapCameraKit({
249
250
  Some Lenses allow for keyboard input. The SDK provides a `<textarea>` (`HTMLTextAreaElement`) element that can be added to your page, and will send its text to the active Lens whenever the user presses the `Enter` key.
250
251
 
251
252
  ```ts
252
- const textAreaContainer = document.getElementById('text-area-container');
253
+ const textAreaContainer = document.getElementById("text-area-container");
253
254
  const textArea = session.keyboard.getElement();
254
255
  textAreaContainer.appendChild(textArea);
255
256
  ```
@@ -257,14 +258,14 @@ textAreaContainer.appendChild(textArea);
257
258
  Alternatively, an event is emitted when a Lens is expecting text input. You can then implement your own UI and logic for obtaining text input from your users, and then send it back to the Lens. For example, something like:
258
259
 
259
260
  ```ts
260
- const input = document.getElementById('my-text-area');
261
- session.keyboard.addEventListener('active', () => {
262
- input.classList.remove('hidden');
261
+ const input = document.getElementById("my-text-area");
262
+ session.keyboard.addEventListener("active", () => {
263
+ input.classList.remove("hidden");
263
264
  });
264
265
 
265
- input.addEventListener('keyup', () => {
266
- session.keyboard.sendInputToLens(input.value);
267
- })
266
+ input.addEventListener("keyup", () => {
267
+ session.keyboard.sendInputToLens(input.value);
268
+ });
268
269
  ```
269
270
 
270
271
  See an example of this [here](https://camera-kit.snapchat.com/websdk/sample/keyboard).
@@ -280,7 +281,7 @@ Keep in mind that this controls Camera Kit's render resolution, and not (necessa
280
281
  Most of the time you'll not need to set the render size – but it could be useful if your video source is, say, very high resolution. In that case, you may observe better performance by telling Camera Kit to render at a lower resolution.
281
282
 
282
283
  ```ts
283
- await session.setSource(source)
284
+ await session.setSource(source);
284
285
  // This must be done *after* calling `setSource()`
285
286
  await source.setRenderSize(width, height);
286
287
  ```
@@ -293,7 +294,7 @@ When setting up a `CameraKitSource`, you can specify whether or not it is a fron
293
294
 
294
295
  ```ts
295
296
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
296
- const source = createMediaStreamSource(stream, { cameraType: 'environment' });
297
+ const source = createMediaStreamSource(stream, { cameraType: "environment" });
297
298
  await session.setSource(source);
298
299
  ```
299
300
 
@@ -323,7 +324,7 @@ Any `CameraKitSource` can be transformed using a matrix, to rotate, scale, or mi
323
324
  ```ts
324
325
  import { Transform2D } from "@snap/camera-kit";
325
326
 
326
- await session.setSource(source)
327
+ await session.setSource(source);
327
328
  // This must be done *after* calling `setSource()`
328
329
  source.setTransform(Transform2D.MirrorX);
329
330
  ```
@@ -337,8 +338,9 @@ Camera Kit Web SDK reports certain important events which may be of interest to
337
338
  Currently, the only event that may be of interest is the `lensView` event. It is emitted whenever a lens is _removed_ from the `CameraKitSession`, indicating a complete lens view. It contains information about the lens' performance (e.g. fps, frame processing times, etc.) and how long the lens was applied.
338
339
 
339
340
  You may listen to these events like so:
341
+
340
342
  ```ts
341
- cameraKit.metrics.addEventListener('lensView', (event) => {
342
- console.debug(event.detail);
343
+ cameraKit.metrics.addEventListener("lensView", (event) => {
344
+ console.debug(event.detail);
343
345
  });
344
346
  ```
@@ -1,3 +1,4 @@
1
+ /// <reference types="trusted-types" />
1
2
  import type { Container } from "@snap/ts-inject";
2
3
  import type { LensRepository } from "./lens/LensRepository";
3
4
  import type { LensCoreError } from "./lens-core-module/lensCoreError";
@@ -207,6 +208,7 @@ export declare const cameraKitFactory: {
207
208
  setClientInterfaceRequestHandler: (callback: import("./lens-core-module/generated-types").ClientInterfaceRequestHandler) => void;
208
209
  setPreloadedConfiguration: (config: import("./lens-core-module/generated-types").SetPreloadedConfigurationInput) => void;
209
210
  setAllSoundsMuted: (config: import("./lens-core-module/generated-types").SetAllSoundsMutedInput) => void;
211
+ setSystemFontFamilies: (config: import("./lens-core-module/generated-types").SetSystemFontFamiliesInput) => void;
210
212
  setSystemFonts: (config: import("./lens-core-module/generated-types").SetSystemFontsInput) => void;
211
213
  registerBeginWebXrHandler: (handler: ((config: import("./lens-core-module/generated-types").BeginWebXrInput) => void) | null) => void;
212
214
  registerEndWebXrHandler: (handler: (() => void) | null) => void;
@@ -243,6 +245,11 @@ export declare const cameraKitFactory: {
243
245
  onFrameProcessed?: ((arg: import("./lens-core-module/generated-types").OnFrameProcessedParam) => void) | undefined;
244
246
  xrCapabilities?: import("./lens-core-module/generated-types").XrCapabilities | undefined;
245
247
  exceptionHandler?: ((err: LensCoreError) => void) | undefined;
248
+ trustedTypes?: {
249
+ policyName: string;
250
+ getTrustedUrls: () => string[];
251
+ trustUrl: (url: string) => string | TrustedScriptURL;
252
+ } | undefined;
246
253
  }): Promise<void>;
247
254
  provideRemoteAssetsResponse(input: {
248
255
  assetId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"CameraKit.d.ts","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":"AAAA,OAAO,KA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7C,QAAQ,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,cAAc,CAAA;KAAE,CAAC;IAEhD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAA0B;IAE/E,OAAO,CAAC,QAAQ,CAA0B;IAE1C,gBAAgB;;IAEZ;;OAEG;IACM,cAAc,EAAE,cAAc,EAEtB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,EAClC,YAAY,EAAE,mBAAmB,EAClD,UAAU,EAAE,kBAAkB;IAUlC;;;;;;;;;;;;;;;;OAgBG;IAEG,aAAa,CAAC,EAChB,gBAAgB,EAChB,oBAAoB,GACvB,GAAE,oBAAyB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0GxD;;OAEG;IAEG,OAAO;CAMhB;AAED,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkB5B,CAAC"}
package/dist/CameraKit.js CHANGED
@@ -19,6 +19,7 @@ import { errorLoggingDecorator } from "./logger/errorLoggingDecorator";
19
19
  import { TypedEventTarget } from "./events/TypedEventTarget";
20
20
  import { pageVisibilityFactory } from "./common/pageVisibility";
21
21
  import { setPreloadedConfiguration } from "./remote-configuration/preloadConfiguration";
22
+ import { getTrustedTypesHandler } from "./trusted-types/trustedTypesHandler";
22
23
  import { remoteConfigurationFactory } from "./remote-configuration/remoteConfiguration";
23
24
  import { registerGeoDataProvider } from "./geo/registerGeoDataProvider";
24
25
  import { frameEventsFactory } from "./session/frameEvents";
@@ -56,10 +57,16 @@ export let CameraKit = (() => {
56
57
  }
57
58
  };
58
59
  const config = this.container.get(configurationToken);
60
+ const trustedTypesHandler = getTrustedTypesHandler(config.trustedTypesPolicyName);
59
61
  yield this.lensCore.initialize({
60
62
  canvas: liveRenderTarget,
61
63
  shouldUseWorker: !renderWhileTabHidden && config.shouldUseWorker,
62
64
  exceptionHandler,
65
+ trustedTypes: {
66
+ policyName: trustedTypesHandler.policyName,
67
+ getTrustedUrls: trustedTypesHandler.getTrustedUrls,
68
+ trustUrl: trustedTypesHandler.trustUrl,
69
+ },
63
70
  });
64
71
  if (this.lensCore.setGpuIndex) {
65
72
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;A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G,EAAE,CAAC;gBACvB,CAAC;aAAA;;;yCAjHA,qBAAqB,CAAC,MAAM,CAAC;mCA2G7B,qBAAqB,CAAC,MAAM,CAAC;YA1G9B,wLAAM,aAAa,wCAqGlB;YAMD,sKAAM,OAAO,wCAKZ;;;;AAIL,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACtC,WAAW,EACX;IACI,qBAAqB,CAAC,KAAK;IAC3B,yBAAyB,CAAC,KAAK;IAC/B,eAAe,CAAC,KAAK;IACrB,qBAAqB,CAAC,KAAK;IAC3B,0BAA0B,CAAC,KAAK;IAChC,SAAS;CACH,EACV,CACI,cAA8B,EAC9B,OAA2B,EAC3B,QAAkB,EAClB,cAA8B,EAC9B,mBAAwC,EACxC,SAAkC,EACpC,EAAE,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,CAAC,CACxG,CAAC","sourcesContent":["import type { Container } from \"@snap/ts-inject\";\nimport { CONTAINER, Injectable } from \"@snap/ts-inject\";\nimport { firstValueFrom } from \"rxjs\";\nimport type { LensRepository } from \"./lens/LensRepository\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { LensCoreError } from \"./lens-core-module/lensCoreError\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { CameraKitSession } from \"./session/CameraKitSession\";\nimport { cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport type { RootServices } from \"./RootServices\";\nimport { registerUriHandlers } from \"./uri-handlers/uriHandlersRegister\";\nimport type { MetricsEventTarget } from \"./metrics/metricsEventTarget\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError, lensAbortError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport type { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport type { LensView } from \"./metrics/reporters/reportLensView\";\nimport type { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport type { PageVisibility } from \"./common/pageVisibility\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\nimport type { RemoteConfiguration } from \"./remote-configuration/remoteConfiguration\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { registerGeoDataProvider } from \"./geo/registerGeoDataProvider\";\nimport { frameEventsFactory } from \"./session/frameEvents\";\n\nconst logger = getLogger(\"CameraKit\");\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCore,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n private readonly remoteConfig: RemoteConfiguration,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @errorLoggingDecorator(logger)\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) => {\n if (error.name === \"LensCoreAbortError\") {\n logger.error(\n lensAbortError(\n \"Unrecoverable error occurred during lens execution. \" +\n \"The CameraKitSession will be destroyed.\",\n error\n )\n );\n } else {\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n }\n };\n\n const config = this.container.get(configurationToken);\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawning a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n await this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && config.shouldUseWorker,\n exceptionHandler,\n });\n\n if (this.lensCore.setGpuIndex) {\n // NOTE: setGpuIndex was added in LensCore@292. This check ensures compatibility with older versions.\n\n // Camera Kit allows a performance cluster to be provided during bootstrap.\n // This cluster is passed to the LENS_FEATURE_GPU_INDEX config as LENS_CLUSTER_ORIG_4,\n // which maps the cluster to a GPU index.\n try {\n await this.lensCore.setGpuIndex({\n gpuIndex: await firstValueFrom(this.remoteConfig.getGpuIndexConfig()),\n });\n } catch (cause) {\n // LensCore initialization can proceed without the GPU index,\n // as it is mainly needed for ML lenses.\n logger.error(new Error(\"Cannot set GPU index.\", { cause }));\n }\n }\n\n if (config.fonts.length > 0) {\n this.lensCore.setSystemFonts({\n fonts: config.fonts,\n });\n }\n\n await this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(frameEventsFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(registerGeoDataProvider)\n .run(setPreloadedConfiguration)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @errorLoggingDecorator(logger)\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n remoteConfigurationFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCore,\n pageVisibility: PageVisibility,\n remoteConfiguration: RemoteConfiguration,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, remoteConfiguration, metrics)\n);\n"]}
1
+ {"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SA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C,KAAK;IAC/B,eAAe,CAAC,KAAK;IACrB,qBAAqB,CAAC,KAAK;IAC3B,0BAA0B,CAAC,KAAK;IAChC,SAAS;CACH,EACV,CACI,cAA8B,EAC9B,OAA2B,EAC3B,QAAkB,EAClB,cAA8B,EAC9B,mBAAwC,EACxC,SAAkC,EACpC,EAAE,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,CAAC,CACxG,CAAC","sourcesContent":["import type { Container } from \"@snap/ts-inject\";\nimport { CONTAINER, Injectable } from \"@snap/ts-inject\";\nimport { firstValueFrom } from \"rxjs\";\nimport type { LensRepository } from \"./lens/LensRepository\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { LensCoreError } from \"./lens-core-module/lensCoreError\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { CameraKitSession } from \"./session/CameraKitSession\";\nimport { cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport type { RootServices } from \"./RootServices\";\nimport { registerUriHandlers } from \"./uri-handlers/uriHandlersRegister\";\nimport type { MetricsEventTarget } from \"./metrics/metricsEventTarget\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError, lensAbortError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport type { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport type { LensView } from \"./metrics/reporters/reportLensView\";\nimport type { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport type { PageVisibility } from \"./common/pageVisibility\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\nimport type { RemoteConfiguration } from \"./remote-configuration/remoteConfiguration\";\nimport { getTrustedTypesHandler } from \"./trusted-types/trustedTypesHandler\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { registerGeoDataProvider } from \"./geo/registerGeoDataProvider\";\nimport { frameEventsFactory } from \"./session/frameEvents\";\n\nconst logger = getLogger(\"CameraKit\");\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCore,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n private readonly remoteConfig: RemoteConfiguration,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @errorLoggingDecorator(logger)\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) => {\n if (error.name === \"LensCoreAbortError\") {\n logger.error(\n lensAbortError(\n \"Unrecoverable error occurred during lens execution. \" +\n \"The CameraKitSession will be destroyed.\",\n error\n )\n );\n } else {\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n }\n };\n\n const config = this.container.get(configurationToken);\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawning a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n const trustedTypesHandler = getTrustedTypesHandler(config.trustedTypesPolicyName);\n await this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && config.shouldUseWorker,\n exceptionHandler,\n trustedTypes: {\n policyName: trustedTypesHandler.policyName,\n getTrustedUrls: trustedTypesHandler.getTrustedUrls,\n trustUrl: trustedTypesHandler.trustUrl,\n },\n });\n\n if (this.lensCore.setGpuIndex) {\n // NOTE: setGpuIndex was added in LensCore@292. This check ensures compatibility with older versions.\n\n // Camera Kit allows a performance cluster to be provided during bootstrap.\n // This cluster is passed to the LENS_FEATURE_GPU_INDEX config as LENS_CLUSTER_ORIG_4,\n // which maps the cluster to a GPU index.\n try {\n await this.lensCore.setGpuIndex({\n gpuIndex: await firstValueFrom(this.remoteConfig.getGpuIndexConfig()),\n });\n } catch (cause) {\n // LensCore initialization can proceed without the GPU index,\n // as it is mainly needed for ML lenses.\n logger.error(new Error(\"Cannot set GPU index.\", { cause }));\n }\n }\n\n if (config.fonts.length > 0) {\n this.lensCore.setSystemFonts({\n fonts: config.fonts,\n });\n }\n\n await this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(frameEventsFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(registerGeoDataProvider)\n .run(setPreloadedConfiguration)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @errorLoggingDecorator(logger)\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n remoteConfigurationFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCore,\n pageVisibility: PageVisibility,\n remoteConfiguration: RemoteConfiguration,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, remoteConfiguration, metrics)\n);\n"]}
@@ -1,7 +1,8 @@
1
+ /// <reference types="trusted-types" />
1
2
  /**
2
3
  * Adds script element to document body and starts downloading provided script URL.
3
4
  * @param scriptUri Script URL.
4
5
  * @returns Script element added.
5
6
  */
6
- export declare function loadScript(scriptUri: string): Promise<HTMLScriptElement>;
7
+ export declare function loadScript(scriptUri: string | TrustedScriptURL): Promise<HTMLScriptElement>;
7
8
  //# sourceMappingURL=loadScript.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/common/loadScript.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAaxE"}
1
+ {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/common/loadScript.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAc3F"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadScript.js","sourceRoot":"","sources":["../../src/common/loadScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAOnD,MAAM,UAAU,UAAU,CAAC,SAAiB;IACxC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACvD,aAAa,CAAC,GAAG,GAAG,SAAS,CAAC;QAC9B,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC;QAC3B,KAAK,CACD,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EACxE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAChE;aACI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACb,SAAS,EAAE,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { fromEvent, merge, take, tap } from \"rxjs\";\n\n/**\n * Adds script element to document body and starts downloading provided script URL.\n * @param scriptUri Script URL.\n * @returns Script element added.\n */\nexport function loadScript(scriptUri: string): Promise<HTMLScriptElement> {\n return new Promise((resolve, reject) => {\n const scriptElement = document.createElement(\"script\");\n scriptElement.src = scriptUri;\n scriptElement.async = true;\n merge(\n fromEvent(scriptElement, \"load\").pipe(tap(() => resolve(scriptElement))),\n fromEvent(scriptElement, \"error\").pipe(tap((e) => reject(e)))\n )\n .pipe(take(1))\n .subscribe();\n document.body.appendChild(scriptElement);\n });\n}\n"]}
1
+ {"version":3,"file":"loadScript.js","sourceRoot":"","sources":["../../src/common/loadScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAOnD,MAAM,UAAU,UAAU,CAAC,SAAoC;IAC3D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAEvD,aAAa,CAAC,GAAG,GAAG,SAAmB,CAAC;QACxC,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC;QAC3B,KAAK,CACD,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EACxE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAChE;aACI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACb,SAAS,EAAE,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { fromEvent, merge, take, tap } from \"rxjs\";\n\n/**\n * Adds script element to document body and starts downloading provided script URL.\n * @param scriptUri Script URL.\n * @returns Script element added.\n */\nexport function loadScript(scriptUri: string | TrustedScriptURL): Promise<HTMLScriptElement> {\n return new Promise((resolve, reject) => {\n const scriptElement = document.createElement(\"script\");\n // Safety: TrustedScriptURL is safe to assign to script.src\n scriptElement.src = scriptUri as string;\n scriptElement.async = true;\n merge(\n fromEvent(scriptElement, \"load\").pipe(tap(() => resolve(scriptElement))),\n fromEvent(scriptElement, \"error\").pipe(tap((e) => reject(e)))\n )\n .pipe(take(1))\n .subscribe();\n document.body.appendChild(scriptElement);\n });\n}\n"]}
@@ -1,15 +1,16 @@
1
1
  import type { EstimatedLensPerformance } from "./benchmark/estimateLensPerformanceCluster";
2
2
  import type { Lens } from "./lens/Lens";
3
- import type { LogLevelName } from "./logger/logger";
3
+ import { type Logger, type LogLevel } from "./logger/logger";
4
4
  interface CameraKitRuntimeConfiguration {
5
5
  lensPerformance: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;
6
- logger: "noop" | "console";
7
- logLevel: LogLevelName;
6
+ logger: Logger;
7
+ logLevel: LogLevel;
8
8
  shouldUseWorker: boolean;
9
9
  apiHostname: CameraKitApiHostname;
10
10
  userAgentFlavor: "release" | "debug";
11
11
  fonts: Font[];
12
12
  lensHttpHandler?: LensHttpHandler;
13
+ trustedTypesPolicyName: string;
13
14
  }
14
15
  export type CameraKitApiHostname = "camera-kit-api.snapar.com" | "api-kit.snapchat.com";
15
16
  /**
@@ -86,17 +87,17 @@ export interface CameraKitBootstrapConfiguration {
86
87
  * Determine where to print CameraKit log messages. By default no logs will be printed.
87
88
  *
88
89
  * CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a
89
- * host application. The printing of these can be controlled via the following
90
- * options:
91
- * - `noop`: log messages are ignored.
92
- * - `console`: log messages are printed to console.
90
+ * host application. The printing of these can be controlled via the following options:
91
+ * - `"noop"`: log messages are ignored.
92
+ * - `"console"`: log messages are printed to console.
93
+ * - A custom {@link Logger} instance can be provided to integrate with an existing logging system.
93
94
  */
94
- logger?: "noop" | "console";
95
+ logger?: "noop" | "console" | Logger;
95
96
  /**
96
97
  * Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:
97
98
  * error > warn > log = info > debug. Default value is "info".
98
99
  */
99
- logLevel?: LogLevelName;
100
+ logLevel?: LogLevel;
100
101
  /**
101
102
  * Some lenses may decide to modify their behavior based on the performance of the current environment. If you are
102
103
  * using such lenses, providing an estimation of lens performance may lead to better user experience (especially on
@@ -197,6 +198,11 @@ export interface CameraKitBootstrapConfiguration {
197
198
  * ```
198
199
  */
199
200
  lensHttpHandler?: LensHttpHandler;
201
+ /**
202
+ * The name of the Trusted Types policy to use when loading scripts.
203
+ * Defaults to "snap-camera-kit".
204
+ */
205
+ trustedTypesPolicyName?: string;
200
206
  }
201
207
  /**
202
208
  * This type represents the result of merging user-supplied config with default config -- as such, it has no nullable
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAG3F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA0BpD,UAAU,6BAA6B;IACnC,eAAe,EAAE,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC9E,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,oBAAoB,CAAC;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e,CAAC,EAAE,eAAe,CAAC;IAElC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,GAAG,+BAA+B,CAAC;AAErG,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAelD,gBAAgB;AAChB,eAAO,MAAM,mCAAmC,kBAAmB,+BAA+B;;;;CA2BjG,CAAC"}
@@ -1,14 +1,16 @@
1
1
  import { Injectable } from "@snap/ts-inject";
2
2
  import { copyDefinedProperties } from "./common/copyDefinedProperties";
3
3
  import { getConfigurationOverrides } from "./configurationOverrides";
4
+ import { mapLogger, noopLogger } from "./logger/logger";
4
5
  const defaultConfiguration = {
5
6
  lensPerformance: { cluster: 0, benchmarks: [], webglRendererInfo: "unknown" },
6
- logger: "noop",
7
+ logger: noopLogger,
7
8
  logLevel: "info",
8
9
  shouldUseWorker: true,
9
10
  apiHostname: "camera-kit-api.snapar.com",
10
11
  userAgentFlavor: "release",
11
12
  fonts: [],
13
+ trustedTypesPolicyName: "snap-camera-kit",
12
14
  };
13
15
  export const configurationToken = "configuration";
14
16
  function isHandledAppleDevice() {
@@ -21,11 +23,12 @@ export const createCameraKitConfigurationFactory = (configuration) => {
21
23
  console.warn("Configuration overrides applied", overrides);
22
24
  }
23
25
  return Injectable(configurationToken, () => {
26
+ var _a;
24
27
  const safeConfig = Object.assign(Object.assign({}, configuration), { lensPerformance: configuration.lensPerformance instanceof Promise
25
28
  ?
26
29
  configuration.lensPerformance.catch(() => defaultConfiguration.lensPerformance)
27
30
  : configuration.lensPerformance });
28
- return Object.assign(Object.assign(Object.assign(Object.assign({}, defaultConfiguration), { shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker }), copyDefinedProperties(safeConfig)), copyDefinedProperties(overrides !== null && overrides !== void 0 ? overrides : {}));
31
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaultConfiguration), { shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker }), copyDefinedProperties(safeConfig)), copyDefinedProperties(overrides !== null && overrides !== void 0 ? overrides : {})), { logger: mapLogger((_a = safeConfig.logger) !== null && _a !== void 0 ? _a : overrides === null || overrides === void 0 ? void 0 : overrides.logger) });
29
32
  });
30
33
  };
31
34
  //# sourceMappingURL=configuration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAerE,MAAM,oBAAoB,GAAmF;IAIzG,eAAe,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAE;IAC7E,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,2BAA2B;IACxC,eAAe,EAAE,SAAS;IAC1B,KAAK,EAAE,EAAE;CACZ,CAAC;AAiOF,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAKlD,SAAS,oBAAoB;IAIzB,OAAO,CACH,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC3C,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU,IAAI,SAAS,CAAC,cAAc,GAAG,CAAC,CAAC,CACtE,CAAC;AACN,CAAC;AAGD,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,aAA8C,EAAE,EAAE;IAElG,MAAM,SAAS,GAAG,yBAAyB,EAAE,CAAC;IAC9C,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;KAC9D;IACD,OAAO,UAAU,CAAC,kBAAkB,EAAE,GAA2B,EAAE;QAG/D,MAAM,UAAU,mCACT,aAAa,KAChB,eAAe,EACX,aAAa,CAAC,eAAe,YAAY,OAAO;gBAC5C,CAAC;oBACC,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,eAAgB,CAAC;gBAClF,CAAC,CAAC,aAAa,CAAC,eAAe,GAC1C,CAAC;QACF,mEACO,oBAAoB,KAGvB,eAAe,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,CAAC,eAAe,KACnF,qBAAqB,CAAC,UAAU,CAAC,GACjC,qBAAqB,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,EAC3C;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { Injectable } from \"@snap/ts-inject\";\nimport type { EstimatedLensPerformance } from \"./benchmark/estimateLensPerformanceCluster\";\nimport { copyDefinedProperties } from \"./common/copyDefinedProperties\";\nimport { getConfigurationOverrides } from \"./configurationOverrides\";\nimport type { Lens } from \"./lens/Lens\";\nimport type { LogLevelName } from \"./logger/logger\";\n\n/**\n * From T, pick the set of properties whose values are optional. Create a new type containing only those properties.\n */\ntype PickOptionals<T> = {\n [K in keyof T as T[K] extends Exclude<T[K], undefined> ? never : K]: T[K];\n};\n\n/**\n * Defaults are provided for runtime configuration and any optional bootstrap configuration properties which require\n * defaults.\n */\nconst defaultConfiguration: CameraKitRuntimeConfiguration & PickOptionals<CameraKitBootstrapConfiguration> = {\n // If the applications doesn't provide performance data (e.g. via estimateLensPerformance), we'll use 0 to indicate\n // no performance estimation occurred. This is indicative of typical performance-targeting logic, which often\n // defaults to the lowest-tier experience in the absence of performance cluster data.\n lensPerformance: { cluster: 0, benchmarks: [], webglRendererInfo: \"unknown\" },\n logger: \"noop\",\n logLevel: \"info\",\n shouldUseWorker: true,\n apiHostname: \"camera-kit-api.snapar.com\",\n userAgentFlavor: \"release\",\n fonts: [],\n};\n\ninterface CameraKitRuntimeConfiguration {\n lensPerformance: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n logger: \"noop\" | \"console\";\n logLevel: LogLevelName;\n shouldUseWorker: boolean;\n apiHostname: CameraKitApiHostname;\n userAgentFlavor: \"release\" | \"debug\";\n fonts: Font[];\n lensHttpHandler?: LensHttpHandler;\n}\n\nexport type CameraKitApiHostname = \"camera-kit-api.snapar.com\" | \"api-kit.snapchat.com\";\n\n/**\n * Represents a font to be used by Camera Kit for text rendering.\n */\nexport interface Font {\n /**\n * A unique name for the font.\n */\n name: string;\n\n /**\n * A buffer containing the font data (e.g., the contents of a `.ttf` file).\n */\n data: ArrayBuffer;\n}\n\n/**\n * Represents context for an HTTP request made by a Lens.\n *\n * This interface provides detailed information about the request, such as its identifier,\n * method, data payload, headers, and associated Lens object.\n */\nexport interface LensHttpRequest {\n /**\n * The URL of the HTTP request.\n */\n url: string;\n\n /**\n * A unique identifier for the HTTP request.\n */\n identifier: string;\n\n /**\n * The HTTP method of the request (e.g., GET, POST, PUT, DELETE).\n */\n method: string;\n\n /**\n * The raw data payload for the HTTP request, represented as an `ArrayBuffer`.\n */\n data: ArrayBuffer;\n\n /**\n * The headers included in the HTTP request.\n */\n headers: Record<string, string>;\n\n /**\n * The {@link Lens} that initiated this request.\n */\n lens: Lens;\n}\n\n/**\n * A handler function for customizing HTTP requests made by a Lens.\n *\n * This function is called whenever a Lens makes an HTTP request.\n * It allows you to modify the request or response, integrate custom HTTP libraries,\n * add authentication, or log request details.\n *\n * @param url - The URL for the HTTP request.\n * @param init - The initial configuration for the HTTP request, following the Fetch API's `RequestInit`.\n * @param lensRequest - Additional context about the Lens-specific request.\n * @returns A Promise resolving to the HTTP response (`Response`).\n */\nexport type LensHttpHandler = (url: string, init: RequestInit, lensRequest: LensHttpRequest) => Promise<Response>;\n\n/**\n * Configuration which must be provided when calling {@link bootstrapCameraKit}. These values are used to create various\n * CameraKit components.\n *\n * @category Bootstrapping and Configuration\n */\nexport interface CameraKitBootstrapConfiguration {\n /**\n * Long-lived token granting your application access to CameraKit APIs. This is found in the SnapKit Dev Portal,\n * where it's called the API Token.\n */\n apiToken: string;\n\n /**\n * Determine where to print CameraKit log messages. By default no logs will be printed.\n *\n * CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a\n * host application. The printing of these can be controlled via the following\n * options:\n * - `noop`: log messages are ignored.\n * - `console`: log messages are printed to console.\n */\n logger?: \"noop\" | \"console\";\n\n /**\n * Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:\n * error > warn > log = info > debug. Default value is \"info\".\n */\n logLevel?: LogLevelName;\n\n /**\n * Some lenses may decide to modify their behavior based on the performance of the current environment. If you are\n * using such lenses, providing an estimation of lens performance may lead to better user experience (especially on\n * low-performance devices).\n *\n * Running the {@link estimateLensPerformance} function will run benchmarks and estimate an appropriate lens\n * performance cluster (i.e. a performance rating) based on the current environment.\n *\n * Lower cluster = worse expected performance capability.\n *\n * @example\n * ```ts\n * import { bootstrapCameraKit, estimateLensPerformance } from '@snap/camera-kit`\n *\n * const cameraKit = await bootstrapCameraKit({\n * apiToken: '...',\n * lensPerformance: estimateLensPerformance(),\n * })\n * ```\n */\n lensPerformance?: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes (e.g. during development or within a CI pipeline), it may be necessary to download\n * these assets from somewhere else.\n *\n * This configuration option allows the application to specify URLs to be used for both the WebAssembly and JS glue\n * file that are used to run and interact with CameraKit's rendering engine.\n */\n lensCoreOverrideUrls?: { wasm: string; js: string };\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes during development or within a CI pipeline, it may be necessary to download these\n * assets from somewhere else. With a provided `wasmEndpointOverride`, asset URLs will be automatically generated\n * based on this root endpoint.\n */\n wasmEndpointOverride?: string;\n\n /**\n * Applications may optionally provide a unique identifier called analyticsId. This ID would enable Camera Kit to\n * improve data reporting and accuracy and to better support potential needs related to an application's lens and\n * user analytics.\n */\n analyticsId?: string;\n\n /**\n * An array of fonts to be used by Camera Kit for text rendering.\n *\n * Lenses usually have their own font assets, but emojis are often not embedded.\n * As a result, you may need to provide additional fonts (e.g., an emoji font) to ensure all glyphs render\n * correctly.\n *\n * @example\n * fonts: [\n * {\n * name: 'EmojiFont',\n * data: emojiFontArrayBuffer, // Your emoji font data goes here\n * },\n * ]\n */\n fonts?: Font[];\n\n /**\n * An optional custom HTTP handler for requests made by a Lens.\n *\n * This handler allows you to intercept and customize the behavior of HTTP requests,\n * such as adding authentication headers, logging request details, or replacing the default\n * HTTP library used by the Lens system.\n *\n * If not specified, the Lens system will use a default HTTP implementation.\n *\n * @example\n * Here is an example of how to configure a custom `LensHttpHandler` to add an authentication token:\n *\n * ```typescript\n * const customLensHttpHandler: LensHttpHandler = async (url, init, lensRequest) => {\n * // Add an authentication token to the headers\n * const sessionToken = await getAuthToken();\n * const updatedInit = {\n * ...init,\n * headers: {\n * ...init.headers,\n * 'Authorization': `Bearer ${sessionToken}`,\n * },\n * };\n *\n * // Log the request details for debugging\n * console.log(`Requesting ${lensRequest.url} from lens: ${lensRequest.lens.name}`);\n *\n * // Use fetch to perform the HTTP request\n * return fetch(url, updatedInit);\n * };\n *\n * const cameraKit = bootstrapCameraKit({\n * apiToken,\n * lensHttpHandler: customLensHttpHandler,\n * });\n * ```\n */\n lensHttpHandler?: LensHttpHandler;\n}\n\n/**\n * This type represents the result of merging user-supplied config with default config -- as such, it has no nullable\n * fields, making it a more convenient type for other components to use.\n *\n * @internal\n */\nexport type CameraKitConfiguration = CameraKitRuntimeConfiguration & CameraKitBootstrapConfiguration;\n\n/** @internal */\nexport const configurationToken = \"configuration\";\n\n/**\n * Returns true if given browser is iPhone, iPad or iPod.\n */\nfunction isHandledAppleDevice() {\n // We use the same approach LC uses:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/LensCore/blob/285ac47cad7fe5268f38d1bab82d51b7b19d6b48/Src/PlatformSpecific/WebAssembly/WebEnvironmentInfo.cpp#L81\n return (\n /iPad|iPhone|iPod/.test(navigator.platform) ||\n (navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 2)\n );\n}\n\n/** @internal */\nexport const createCameraKitConfigurationFactory = (configuration: CameraKitBootstrapConfiguration) => {\n // always leave debug mode warning about overrides in console\n const overrides = getConfigurationOverrides();\n if (overrides) {\n console.warn(\"Configuration overrides applied\", overrides);\n }\n return Injectable(configurationToken, (): CameraKitConfiguration => {\n // We'll ensure that we handle errors on any Promises passed as config values, otherwise we either must\n // handle them separately wherever they're used, or rejections would go unhandled.\n const safeConfig: CameraKitBootstrapConfiguration = {\n ...configuration,\n lensPerformance:\n configuration.lensPerformance instanceof Promise\n ? // Safety: defaultConfiguration.lensPerformance is defined (it's hardcoded above).\n configuration.lensPerformance.catch(() => defaultConfiguration.lensPerformance!)\n : configuration.lensPerformance,\n };\n return {\n ...defaultConfiguration,\n // TODO: Safari 17 has an issue with offscreen canvas which results in stuttering effect on iOS.\n // Once Safari has that fixed, we should remove this check, see https://jira.sc-corp.net/browse/CAMKIT-5985\n shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker,\n ...copyDefinedProperties(safeConfig),\n ...copyDefinedProperties(overrides ?? {}),\n };\n });\n};\n"]}
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,UAAU,EAA8B,MAAM,iBAAiB,CAAC;AAapF,MAAM,oBAAoB,GAAmF;IAIzG,eAAe,EAAE,EAAE,OAA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E,SAAS,CAAC,MAAA,UAAU,CAAC,MAAM,mCAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,IAC3D;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { Injectable } from \"@snap/ts-inject\";\nimport type { EstimatedLensPerformance } from \"./benchmark/estimateLensPerformanceCluster\";\nimport { copyDefinedProperties } from \"./common/copyDefinedProperties\";\nimport { getConfigurationOverrides } from \"./configurationOverrides\";\nimport type { Lens } from \"./lens/Lens\";\nimport { mapLogger, noopLogger, type Logger, type LogLevel } from \"./logger/logger\";\n\n/**\n * From T, pick the set of properties whose values are optional. Create a new type containing only those properties.\n */\ntype PickOptionals<T> = {\n [K in keyof T as T[K] extends Exclude<T[K], undefined> ? never : K]: T[K];\n};\n\n/**\n * Defaults are provided for runtime configuration and any optional bootstrap configuration properties which require\n * defaults.\n */\nconst defaultConfiguration: CameraKitRuntimeConfiguration & PickOptionals<CameraKitBootstrapConfiguration> = {\n // If the applications doesn't provide performance data (e.g. via estimateLensPerformance), we'll use 0 to indicate\n // no performance estimation occurred. This is indicative of typical performance-targeting logic, which often\n // defaults to the lowest-tier experience in the absence of performance cluster data.\n lensPerformance: { cluster: 0, benchmarks: [], webglRendererInfo: \"unknown\" },\n logger: noopLogger,\n logLevel: \"info\",\n shouldUseWorker: true,\n apiHostname: \"camera-kit-api.snapar.com\",\n userAgentFlavor: \"release\",\n fonts: [],\n trustedTypesPolicyName: \"snap-camera-kit\",\n};\n\ninterface CameraKitRuntimeConfiguration {\n lensPerformance: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n logger: Logger;\n logLevel: LogLevel;\n shouldUseWorker: boolean;\n apiHostname: CameraKitApiHostname;\n userAgentFlavor: \"release\" | \"debug\";\n fonts: Font[];\n lensHttpHandler?: LensHttpHandler;\n trustedTypesPolicyName: string;\n}\n\nexport type CameraKitApiHostname = \"camera-kit-api.snapar.com\" | \"api-kit.snapchat.com\";\n\n/**\n * Represents a font to be used by Camera Kit for text rendering.\n */\nexport interface Font {\n /**\n * A unique name for the font.\n */\n name: string;\n\n /**\n * A buffer containing the font data (e.g., the contents of a `.ttf` file).\n */\n data: ArrayBuffer;\n}\n\n/**\n * Represents context for an HTTP request made by a Lens.\n *\n * This interface provides detailed information about the request, such as its identifier,\n * method, data payload, headers, and associated Lens object.\n */\nexport interface LensHttpRequest {\n /**\n * The URL of the HTTP request.\n */\n url: string;\n\n /**\n * A unique identifier for the HTTP request.\n */\n identifier: string;\n\n /**\n * The HTTP method of the request (e.g., GET, POST, PUT, DELETE).\n */\n method: string;\n\n /**\n * The raw data payload for the HTTP request, represented as an `ArrayBuffer`.\n */\n data: ArrayBuffer;\n\n /**\n * The headers included in the HTTP request.\n */\n headers: Record<string, string>;\n\n /**\n * The {@link Lens} that initiated this request.\n */\n lens: Lens;\n}\n\n/**\n * A handler function for customizing HTTP requests made by a Lens.\n *\n * This function is called whenever a Lens makes an HTTP request.\n * It allows you to modify the request or response, integrate custom HTTP libraries,\n * add authentication, or log request details.\n *\n * @param url - The URL for the HTTP request.\n * @param init - The initial configuration for the HTTP request, following the Fetch API's `RequestInit`.\n * @param lensRequest - Additional context about the Lens-specific request.\n * @returns A Promise resolving to the HTTP response (`Response`).\n */\nexport type LensHttpHandler = (url: string, init: RequestInit, lensRequest: LensHttpRequest) => Promise<Response>;\n\n/**\n * Configuration which must be provided when calling {@link bootstrapCameraKit}. These values are used to create various\n * CameraKit components.\n *\n * @category Bootstrapping and Configuration\n */\nexport interface CameraKitBootstrapConfiguration {\n /**\n * Long-lived token granting your application access to CameraKit APIs. This is found in the SnapKit Dev Portal,\n * where it's called the API Token.\n */\n apiToken: string;\n\n /**\n * Determine where to print CameraKit log messages. By default no logs will be printed.\n *\n * CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a\n * host application. The printing of these can be controlled via the following options:\n * - `\"noop\"`: log messages are ignored.\n * - `\"console\"`: log messages are printed to console.\n * - A custom {@link Logger} instance can be provided to integrate with an existing logging system.\n */\n logger?: \"noop\" | \"console\" | Logger;\n\n /**\n * Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:\n * error > warn > log = info > debug. Default value is \"info\".\n */\n logLevel?: LogLevel;\n\n /**\n * Some lenses may decide to modify their behavior based on the performance of the current environment. If you are\n * using such lenses, providing an estimation of lens performance may lead to better user experience (especially on\n * low-performance devices).\n *\n * Running the {@link estimateLensPerformance} function will run benchmarks and estimate an appropriate lens\n * performance cluster (i.e. a performance rating) based on the current environment.\n *\n * Lower cluster = worse expected performance capability.\n *\n * @example\n * ```ts\n * import { bootstrapCameraKit, estimateLensPerformance } from '@snap/camera-kit`\n *\n * const cameraKit = await bootstrapCameraKit({\n * apiToken: '...',\n * lensPerformance: estimateLensPerformance(),\n * })\n * ```\n */\n lensPerformance?: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes (e.g. during development or within a CI pipeline), it may be necessary to download\n * these assets from somewhere else.\n *\n * This configuration option allows the application to specify URLs to be used for both the WebAssembly and JS glue\n * file that are used to run and interact with CameraKit's rendering engine.\n */\n lensCoreOverrideUrls?: { wasm: string; js: string };\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes during development or within a CI pipeline, it may be necessary to download these\n * assets from somewhere else. With a provided `wasmEndpointOverride`, asset URLs will be automatically generated\n * based on this root endpoint.\n */\n wasmEndpointOverride?: string;\n\n /**\n * Applications may optionally provide a unique identifier called analyticsId. This ID would enable Camera Kit to\n * improve data reporting and accuracy and to better support potential needs related to an application's lens and\n * user analytics.\n */\n analyticsId?: string;\n\n /**\n * An array of fonts to be used by Camera Kit for text rendering.\n *\n * Lenses usually have their own font assets, but emojis are often not embedded.\n * As a result, you may need to provide additional fonts (e.g., an emoji font) to ensure all glyphs render\n * correctly.\n *\n * @example\n * fonts: [\n * {\n * name: 'EmojiFont',\n * data: emojiFontArrayBuffer, // Your emoji font data goes here\n * },\n * ]\n */\n fonts?: Font[];\n\n /**\n * An optional custom HTTP handler for requests made by a Lens.\n *\n * This handler allows you to intercept and customize the behavior of HTTP requests,\n * such as adding authentication headers, logging request details, or replacing the default\n * HTTP library used by the Lens system.\n *\n * If not specified, the Lens system will use a default HTTP implementation.\n *\n * @example\n * Here is an example of how to configure a custom `LensHttpHandler` to add an authentication token:\n *\n * ```typescript\n * const customLensHttpHandler: LensHttpHandler = async (url, init, lensRequest) => {\n * // Add an authentication token to the headers\n * const sessionToken = await getAuthToken();\n * const updatedInit = {\n * ...init,\n * headers: {\n * ...init.headers,\n * 'Authorization': `Bearer ${sessionToken}`,\n * },\n * };\n *\n * // Log the request details for debugging\n * console.log(`Requesting ${lensRequest.url} from lens: ${lensRequest.lens.name}`);\n *\n * // Use fetch to perform the HTTP request\n * return fetch(url, updatedInit);\n * };\n *\n * const cameraKit = bootstrapCameraKit({\n * apiToken,\n * lensHttpHandler: customLensHttpHandler,\n * });\n * ```\n */\n lensHttpHandler?: LensHttpHandler;\n\n /**\n * The name of the Trusted Types policy to use when loading scripts.\n * Defaults to \"snap-camera-kit\".\n */\n trustedTypesPolicyName?: string;\n}\n\n/**\n * This type represents the result of merging user-supplied config with default config -- as such, it has no nullable\n * fields, making it a more convenient type for other components to use.\n *\n * @internal\n */\nexport type CameraKitConfiguration = CameraKitRuntimeConfiguration & CameraKitBootstrapConfiguration;\n\n/** @internal */\nexport const configurationToken = \"configuration\";\n\n/**\n * Returns true if given browser is iPhone, iPad or iPod.\n */\nfunction isHandledAppleDevice() {\n // We use the same approach LC uses:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/LensCore/blob/285ac47cad7fe5268f38d1bab82d51b7b19d6b48/Src/PlatformSpecific/WebAssembly/WebEnvironmentInfo.cpp#L81\n return (\n /iPad|iPhone|iPod/.test(navigator.platform) ||\n (navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 2)\n );\n}\n\n/** @internal */\nexport const createCameraKitConfigurationFactory = (configuration: CameraKitBootstrapConfiguration) => {\n // always leave debug mode warning about overrides in console\n const overrides = getConfigurationOverrides();\n if (overrides) {\n console.warn(\"Configuration overrides applied\", overrides);\n }\n return Injectable(configurationToken, (): CameraKitConfiguration => {\n // We'll ensure that we handle errors on any Promises passed as config values, otherwise we either must\n // handle them separately wherever they're used, or rejections would go unhandled.\n const safeConfig: CameraKitBootstrapConfiguration = {\n ...configuration,\n lensPerformance:\n configuration.lensPerformance instanceof Promise\n ? // Safety: defaultConfiguration.lensPerformance is defined (it's hardcoded above).\n configuration.lensPerformance.catch(() => defaultConfiguration.lensPerformance!)\n : configuration.lensPerformance,\n };\n return {\n ...defaultConfiguration,\n // TODO: Safari 17 has an issue with offscreen canvas which results in stuttering effect on iOS.\n // Once Safari has that fixed, we should remove this check, see https://jira.sc-corp.net/browse/CAMKIT-5985\n shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker,\n ...copyDefinedProperties(safeConfig),\n ...copyDefinedProperties(overrides ?? {}),\n logger: mapLogger(safeConfig.logger ?? overrides?.logger),\n };\n });\n};\n"]}
@@ -1,2 +1,2 @@
1
- export default { PACKAGE_VERSION: "1.10.0" };
1
+ export default { PACKAGE_VERSION: "1.12.0" };
2
2
  //# sourceMappingURL=environment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["export default { PACKAGE_VERSION: \"1.10.0\" };\n"]}
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["export default { PACKAGE_VERSION: \"1.12.0\" };\n"]}