@snap/camera-kit 0.7.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 (554) hide show
  1. package/LICENSE.md +6247 -0
  2. package/README.md +166 -0
  3. package/docs/html/.nojekyll +1 -0
  4. package/docs/html/assets/highlight.css +106 -0
  5. package/docs/html/assets/main.js +54 -0
  6. package/docs/html/assets/search.js +1 -0
  7. package/docs/html/assets/style.css +1225 -0
  8. package/docs/html/assets/widgets.png +0 -0
  9. package/docs/html/assets/widgets@2x.png +0 -0
  10. package/docs/html/classes/CameraKit.html +121 -0
  11. package/docs/html/classes/CameraKitSession.html +347 -0
  12. package/docs/html/classes/CameraKitSource.html +152 -0
  13. package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
  14. package/docs/html/classes/LensPerformanceMetrics.html +76 -0
  15. package/docs/html/classes/LensRepository.html +171 -0
  16. package/docs/html/classes/LensSources.html +82 -0
  17. package/docs/html/classes/Transform2D.html +99 -0
  18. package/docs/html/classes/TypedCustomEvent.html +109 -0
  19. package/docs/html/classes/TypedEventTarget.html +146 -0
  20. package/docs/html/functions/Injectable.html +193 -0
  21. package/docs/html/functions/bootstrapCameraKit.html +158 -0
  22. package/docs/html/functions/createExtension.html +127 -0
  23. package/docs/html/functions/createImageSource.html +123 -0
  24. package/docs/html/functions/createMediaStreamSource.html +123 -0
  25. package/docs/html/functions/createUserMediaSource.html +127 -0
  26. package/docs/html/functions/createVideoSource.html +124 -0
  27. package/docs/html/functions/estimateLensPerformance.html +116 -0
  28. package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
  29. package/docs/html/functions/lensSourcesFactory.html +116 -0
  30. package/docs/html/functions/uriHandlersFactory.html +118 -0
  31. package/docs/html/index.html +208 -0
  32. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
  33. package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
  34. package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
  35. package/docs/html/interfaces/CreateSessionOptions.html +77 -0
  36. package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
  37. package/docs/html/interfaces/Lens.html +115 -0
  38. package/docs/html/interfaces/LensSource.html +113 -0
  39. package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
  40. package/docs/html/interfaces/UriCancelRequest.html +65 -0
  41. package/docs/html/interfaces/UriHandler.html +128 -0
  42. package/docs/html/interfaces/UriRequest.html +80 -0
  43. package/docs/html/interfaces/UriResponse.html +80 -0
  44. package/docs/html/interfaces/VideoSourceOptions.html +60 -0
  45. package/docs/html/modules.html +198 -0
  46. package/docs/html/types/AssetLoader.html +126 -0
  47. package/docs/html/types/AssetTiming.html +116 -0
  48. package/docs/html/types/BenchmarkError.html +107 -0
  49. package/docs/html/types/BootstrapError.html +110 -0
  50. package/docs/html/types/CacheKeyNotFoundError.html +107 -0
  51. package/docs/html/types/CameraKitDeviceInfo.html +114 -0
  52. package/docs/html/types/CameraKitSessionEventListener.html +109 -0
  53. package/docs/html/types/CameraKitSessionEvents.html +118 -0
  54. package/docs/html/types/CameraKitSourceError.html +107 -0
  55. package/docs/html/types/CameraKitSourceInfo.html +107 -0
  56. package/docs/html/types/CameraKitSourceOptions.html +113 -0
  57. package/docs/html/types/ConfigurationError.html +109 -0
  58. package/docs/html/types/Keyboard.html +196 -0
  59. package/docs/html/types/KeyboardEvents.html +109 -0
  60. package/docs/html/types/LegalError.html +107 -0
  61. package/docs/html/types/LensAssetError.html +109 -0
  62. package/docs/html/types/LensContentValidationError.html +107 -0
  63. package/docs/html/types/LensError.html +107 -0
  64. package/docs/html/types/LensExecutionError.html +114 -0
  65. package/docs/html/types/LensImagePickerError.html +110 -0
  66. package/docs/html/types/LensLaunchParams.html +109 -0
  67. package/docs/html/types/LensMetricsEvents.html +110 -0
  68. package/docs/html/types/LensPerformanceCluster.html +107 -0
  69. package/docs/html/types/LensView.html +119 -0
  70. package/docs/html/types/LensWait.html +111 -0
  71. package/docs/html/types/PersistentStoreError.html +109 -0
  72. package/docs/html/types/PlatformNotSupportedError.html +110 -0
  73. package/docs/html/types/PublicContainer.html +110 -0
  74. package/docs/html/types/RenderTarget.html +111 -0
  75. package/docs/html/types/Uri.html +107 -0
  76. package/docs/html/types/UriHandlers.html +109 -0
  77. package/docs/html/types/WebGLError.html +107 -0
  78. package/docs/html/variables/extensionRequestContext.html +109 -0
  79. package/docs/md/.nojekyll +1 -0
  80. package/docs/md/README.md +168 -0
  81. package/docs/md/classes/CameraKit.md +94 -0
  82. package/docs/md/classes/CameraKitSession.md +359 -0
  83. package/docs/md/classes/CameraKitSource.md +110 -0
  84. package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
  85. package/docs/md/classes/LensPerformanceMetrics.md +37 -0
  86. package/docs/md/classes/LensRepository.md +145 -0
  87. package/docs/md/classes/LensSources.md +29 -0
  88. package/docs/md/classes/Transform2D.md +55 -0
  89. package/docs/md/classes/TypedCustomEvent.md +65 -0
  90. package/docs/md/classes/TypedEventTarget.md +103 -0
  91. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
  92. package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
  93. package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
  94. package/docs/md/interfaces/CreateSessionOptions.md +35 -0
  95. package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
  96. package/docs/md/interfaces/Lens.md +84 -0
  97. package/docs/md/interfaces/LensSource.md +68 -0
  98. package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
  99. package/docs/md/interfaces/UriCancelRequest.md +22 -0
  100. package/docs/md/interfaces/UriHandler.md +63 -0
  101. package/docs/md/interfaces/UriRequest.md +43 -0
  102. package/docs/md/interfaces/UriResponse.md +43 -0
  103. package/docs/md/interfaces/VideoSourceOptions.md +15 -0
  104. package/docs/md/modules.md +827 -0
  105. package/lib/CameraKit.d.ts +170 -0
  106. package/lib/CameraKit.js +145 -0
  107. package/lib/CameraKit.js.map +1 -0
  108. package/lib/__tests__/data.d.ts +9 -0
  109. package/lib/__tests__/data.js +50 -0
  110. package/lib/__tests__/data.js.map +1 -0
  111. package/lib/__tests__/deferred.d.ts +16 -0
  112. package/lib/__tests__/deferred.js +29 -0
  113. package/lib/__tests__/deferred.js.map +1 -0
  114. package/lib/__tests__/jest.matchers.d.ts +17 -0
  115. package/lib/__tests__/jest.matchers.js +67 -0
  116. package/lib/__tests__/jest.matchers.js.map +1 -0
  117. package/lib/assertPlatformSupported.d.ts +4 -0
  118. package/lib/assertPlatformSupported.js +10 -0
  119. package/lib/assertPlatformSupported.js.map +1 -0
  120. package/lib/benchmark/benchmarkGflops.d.ts +16 -0
  121. package/lib/benchmark/benchmarkGflops.js +129 -0
  122. package/lib/benchmark/benchmarkGflops.js.map +1 -0
  123. package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
  124. package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
  125. package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
  126. package/lib/benchmark/webglUtils.d.ts +7 -0
  127. package/lib/benchmark/webglUtils.js +87 -0
  128. package/lib/benchmark/webglUtils.js.map +1 -0
  129. package/lib/bootstrapCameraKit.d.ts +96 -0
  130. package/lib/bootstrapCameraKit.js +204 -0
  131. package/lib/bootstrapCameraKit.js.map +1 -0
  132. package/lib/common/__mocks__/loadScript.d.ts +1 -0
  133. package/lib/common/__mocks__/loadScript.js +10 -0
  134. package/lib/common/__mocks__/loadScript.js.map +1 -0
  135. package/lib/common/assertions.d.ts +27 -0
  136. package/lib/common/assertions.js +39 -0
  137. package/lib/common/assertions.js.map +1 -0
  138. package/lib/common/cameraKitUserAgent.d.ts +34 -0
  139. package/lib/common/cameraKitUserAgent.js +216 -0
  140. package/lib/common/cameraKitUserAgent.js.map +1 -0
  141. package/lib/common/copyDefinedProperties.d.ts +13 -0
  142. package/lib/common/copyDefinedProperties.js +16 -0
  143. package/lib/common/copyDefinedProperties.js.map +1 -0
  144. package/lib/common/entries.d.ts +3 -0
  145. package/lib/common/entries.js +3 -0
  146. package/lib/common/entries.js.map +1 -0
  147. package/lib/common/errorHelpers.d.ts +10 -0
  148. package/lib/common/errorHelpers.js +24 -0
  149. package/lib/common/errorHelpers.js.map +1 -0
  150. package/lib/common/getFilename.d.ts +1 -0
  151. package/lib/common/getFilename.js +4 -0
  152. package/lib/common/getFilename.js.map +1 -0
  153. package/lib/common/index.d.ts +2 -0
  154. package/lib/common/index.js +3 -0
  155. package/lib/common/index.js.map +1 -0
  156. package/lib/common/loadScript.d.ts +1 -0
  157. package/lib/common/loadScript.js +11 -0
  158. package/lib/common/loadScript.js.map +1 -0
  159. package/lib/common/locale.d.ts +2 -0
  160. package/lib/common/locale.js +11 -0
  161. package/lib/common/locale.js.map +1 -0
  162. package/lib/common/localization.d.ts +43 -0
  163. package/lib/common/localization.js +43 -0
  164. package/lib/common/localization.js.map +1 -0
  165. package/lib/common/memoize.d.ts +8 -0
  166. package/lib/common/memoize.js +15 -0
  167. package/lib/common/memoize.js.map +1 -0
  168. package/lib/common/pageVisibility.d.ts +20 -0
  169. package/lib/common/pageVisibility.js +62 -0
  170. package/lib/common/pageVisibility.js.map +1 -0
  171. package/lib/common/time.d.ts +1 -0
  172. package/lib/common/time.js +2 -0
  173. package/lib/common/time.js.map +1 -0
  174. package/lib/common/typeguards.d.ts +53 -0
  175. package/lib/common/typeguards.js +92 -0
  176. package/lib/common/typeguards.js.map +1 -0
  177. package/lib/common/types.d.ts +10 -0
  178. package/lib/common/types.js +2 -0
  179. package/lib/common/types.js.map +1 -0
  180. package/lib/common/validate.d.ts +14 -0
  181. package/lib/common/validate.js +104 -0
  182. package/lib/common/validate.js.map +1 -0
  183. package/lib/configuration.d.ts +92 -0
  184. package/lib/configuration.js +36 -0
  185. package/lib/configuration.js.map +1 -0
  186. package/lib/configurationOverrides.d.ts +12 -0
  187. package/lib/configurationOverrides.js +41 -0
  188. package/lib/configurationOverrides.js.map +1 -0
  189. package/lib/dependency-injection/Container.d.ts +177 -0
  190. package/lib/dependency-injection/Container.js +160 -0
  191. package/lib/dependency-injection/Container.js.map +1 -0
  192. package/lib/dependency-injection/Injectable.d.ts +39 -0
  193. package/lib/dependency-injection/Injectable.js +18 -0
  194. package/lib/dependency-injection/Injectable.js.map +1 -0
  195. package/lib/dependency-injection/PartialContainer.d.ts +81 -0
  196. package/lib/dependency-injection/PartialContainer.js +85 -0
  197. package/lib/dependency-injection/PartialContainer.js.map +1 -0
  198. package/lib/dependency-injection/RootServices.d.ts +62 -0
  199. package/lib/dependency-injection/RootServices.js +2 -0
  200. package/lib/dependency-injection/RootServices.js.map +1 -0
  201. package/lib/dependency-injection/types.d.ts +56 -0
  202. package/lib/dependency-injection/types.js +2 -0
  203. package/lib/dependency-injection/types.js.map +1 -0
  204. package/lib/environment.json +1 -0
  205. package/lib/events/TypedCustomEvent.d.ts +10 -0
  206. package/lib/events/TypedCustomEvent.js +11 -0
  207. package/lib/events/TypedCustomEvent.js.map +1 -0
  208. package/lib/events/TypedEventTarget.d.ts +25 -0
  209. package/lib/events/TypedEventTarget.js +57 -0
  210. package/lib/events/TypedEventTarget.js.map +1 -0
  211. package/lib/events/scan.d.ts +15 -0
  212. package/lib/events/scan.js +46 -0
  213. package/lib/events/scan.js.map +1 -0
  214. package/lib/extensions/LensSources.d.ts +58 -0
  215. package/lib/extensions/LensSources.js +50 -0
  216. package/lib/extensions/LensSources.js.map +1 -0
  217. package/lib/extensions/UriHandlers.d.ts +54 -0
  218. package/lib/extensions/UriHandlers.js +93 -0
  219. package/lib/extensions/UriHandlers.js.map +1 -0
  220. package/lib/extensions/extensionRequestContext.d.ts +4 -0
  221. package/lib/extensions/extensionRequestContext.js +14 -0
  222. package/lib/extensions/extensionRequestContext.js.map +1 -0
  223. package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
  224. package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
  225. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
  226. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
  227. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
  228. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
  229. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
  230. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
  231. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
  232. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
  233. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
  234. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
  235. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
  236. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
  237. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
  238. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
  239. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
  240. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
  241. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
  242. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
  243. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
  244. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
  245. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
  246. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
  247. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
  248. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
  249. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
  250. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
  251. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
  252. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
  253. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
  254. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
  255. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
  256. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
  257. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
  258. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
  259. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
  260. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
  261. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
  262. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
  263. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
  264. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
  265. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
  266. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
  267. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
  268. package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
  269. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
  270. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
  271. package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
  272. package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
  273. package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
  274. package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
  275. package/lib/generated-proto/pb_schema/common/value.js +204 -0
  276. package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
  277. package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
  278. package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
  279. package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
  280. package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
  281. package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
  282. package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
  283. package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
  284. package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
  285. package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
  286. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
  287. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
  288. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
  289. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
  290. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
  291. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
  292. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
  293. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
  294. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
  295. package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
  296. package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
  297. package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
  298. package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
  299. package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
  300. package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
  301. package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
  302. package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
  303. package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
  304. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
  305. package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
  306. package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
  307. package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
  308. package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
  309. package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
  310. package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
  311. package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
  312. package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
  313. package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
  314. package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
  315. package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
  316. package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
  317. package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
  318. package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
  319. package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
  320. package/lib/handlers/HandlerChainBuilder.js +187 -0
  321. package/lib/handlers/HandlerChainBuilder.js.map +1 -0
  322. package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
  323. package/lib/handlers/arrayBufferParsingHandler.js +18 -0
  324. package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
  325. package/lib/handlers/batchingHandler.d.ts +25 -0
  326. package/lib/handlers/batchingHandler.js +79 -0
  327. package/lib/handlers/batchingHandler.js.map +1 -0
  328. package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
  329. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
  330. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
  331. package/lib/handlers/debugHandler.d.ts +8 -0
  332. package/lib/handlers/debugHandler.js +27 -0
  333. package/lib/handlers/debugHandler.js.map +1 -0
  334. package/lib/handlers/defaultFetchHandler.d.ts +15 -0
  335. package/lib/handlers/defaultFetchHandler.js +29 -0
  336. package/lib/handlers/defaultFetchHandler.js.map +1 -0
  337. package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
  338. package/lib/handlers/headersModifyingFetchHandler.js +13 -0
  339. package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
  340. package/lib/handlers/index.d.ts +2 -0
  341. package/lib/handlers/index.js +3 -0
  342. package/lib/handlers/index.js.map +1 -0
  343. package/lib/handlers/mappingHandler.d.ts +15 -0
  344. package/lib/handlers/mappingHandler.js +65 -0
  345. package/lib/handlers/mappingHandler.js.map +1 -0
  346. package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
  347. package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
  348. package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
  349. package/lib/handlers/persistingHandler.d.ts +14 -0
  350. package/lib/handlers/persistingHandler.js +71 -0
  351. package/lib/handlers/persistingHandler.js.map +1 -0
  352. package/lib/handlers/rateLimitingHandler.d.ts +20 -0
  353. package/lib/handlers/rateLimitingHandler.js +43 -0
  354. package/lib/handlers/rateLimitingHandler.js.map +1 -0
  355. package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
  356. package/lib/handlers/requestStateEmittingHandler.js +43 -0
  357. package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
  358. package/lib/handlers/responseCachingHandler.d.ts +27 -0
  359. package/lib/handlers/responseCachingHandler.js +94 -0
  360. package/lib/handlers/responseCachingHandler.js.map +1 -0
  361. package/lib/handlers/retryingHandler.d.ts +37 -0
  362. package/lib/handlers/retryingHandler.js +73 -0
  363. package/lib/handlers/retryingHandler.js.map +1 -0
  364. package/lib/handlers/timeoutHandler.d.ts +18 -0
  365. package/lib/handlers/timeoutHandler.js +30 -0
  366. package/lib/handlers/timeoutHandler.js.map +1 -0
  367. package/lib/index.d.ts +33 -0
  368. package/lib/index.js +32 -0
  369. package/lib/index.js.map +1 -0
  370. package/lib/legal/legalPrompt.d.ts +17 -0
  371. package/lib/legal/legalPrompt.js +144 -0
  372. package/lib/legal/legalPrompt.js.map +1 -0
  373. package/lib/legal/legalState.d.ts +50 -0
  374. package/lib/legal/legalState.js +149 -0
  375. package/lib/legal/legalState.js.map +1 -0
  376. package/lib/lens/Lens.d.ts +71 -0
  377. package/lib/lens/Lens.js +63 -0
  378. package/lib/lens/Lens.js.map +1 -0
  379. package/lib/lens/LensLaunchParams.d.ts +19 -0
  380. package/lib/lens/LensLaunchParams.js +38 -0
  381. package/lib/lens/LensLaunchParams.js.map +1 -0
  382. package/lib/lens/LensPersistenceStore.d.ts +7 -0
  383. package/lib/lens/LensPersistenceStore.js +20 -0
  384. package/lib/lens/LensPersistenceStore.js.map +1 -0
  385. package/lib/lens/LensRepository.d.ts +134 -0
  386. package/lib/lens/LensRepository.js +239 -0
  387. package/lib/lens/LensRepository.js.map +1 -0
  388. package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
  389. package/lib/lens/assets/LensAssetRepository.js +179 -0
  390. package/lib/lens/assets/LensAssetRepository.js.map +1 -0
  391. package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
  392. package/lib/lens/assets/LensAssetsProvider.js +41 -0
  393. package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
  394. package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
  395. package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
  396. package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
  397. package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
  398. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
  399. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
  400. package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
  401. package/lib/lens/assets/staticAssetLoader.js +24 -0
  402. package/lib/lens/assets/staticAssetLoader.js.map +1 -0
  403. package/lib/lens/index.d.ts +7 -0
  404. package/lib/lens/index.js +7 -0
  405. package/lib/lens/index.js.map +1 -0
  406. package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
  407. package/lib/lens/lensEnvelopeUtil.js +19 -0
  408. package/lib/lens/lensEnvelopeUtil.js.map +1 -0
  409. package/lib/lens/lensHttpUtil.d.ts +4 -0
  410. package/lib/lens/lensHttpUtil.js +30 -0
  411. package/lib/lens/lensHttpUtil.js.map +1 -0
  412. package/lib/lens-client-interface/exif.d.ts +20 -0
  413. package/lib/lens-client-interface/exif.js +61 -0
  414. package/lib/lens-client-interface/exif.js.map +1 -0
  415. package/lib/lens-client-interface/imagePicker.d.ts +7 -0
  416. package/lib/lens-client-interface/imagePicker.js +128 -0
  417. package/lib/lens-client-interface/imagePicker.js.map +1 -0
  418. package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
  419. package/lib/lens-client-interface/lensClientInterface.js +30 -0
  420. package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
  421. package/lib/lens-core-module/generated-types.d.ts +426 -0
  422. package/lib/lens-core-module/generated-types.js +2 -0
  423. package/lib/lens-core-module/generated-types.js.map +1 -0
  424. package/lib/lens-core-module/index.d.ts +2 -0
  425. package/lib/lens-core-module/index.js +3 -0
  426. package/lib/lens-core-module/index.js.map +1 -0
  427. package/lib/lens-core-module/loader/index.d.ts +1 -0
  428. package/lib/lens-core-module/loader/index.js +2 -0
  429. package/lib/lens-core-module/loader/index.js.map +1 -0
  430. package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
  431. package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
  432. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
  433. package/lib/lensCoreWasmVersions.json +5 -0
  434. package/lib/logger/errorLoggingDecorator.d.ts +9 -0
  435. package/lib/logger/errorLoggingDecorator.js +32 -0
  436. package/lib/logger/errorLoggingDecorator.js.map +1 -0
  437. package/lib/logger/logEntries.d.ts +15 -0
  438. package/lib/logger/logEntries.js +14 -0
  439. package/lib/logger/logEntries.js.map +1 -0
  440. package/lib/logger/logger.d.ts +35 -0
  441. package/lib/logger/logger.js +48 -0
  442. package/lib/logger/logger.js.map +1 -0
  443. package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
  444. package/lib/logger/registerLogEntriesSubscriber.js +23 -0
  445. package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
  446. package/lib/media-sources/CameraKitSource.d.ts +88 -0
  447. package/lib/media-sources/CameraKitSource.js +140 -0
  448. package/lib/media-sources/CameraKitSource.js.map +1 -0
  449. package/lib/media-sources/FunctionSource.d.ts +30 -0
  450. package/lib/media-sources/FunctionSource.js +132 -0
  451. package/lib/media-sources/FunctionSource.js.map +1 -0
  452. package/lib/media-sources/ImageSource.d.ts +13 -0
  453. package/lib/media-sources/ImageSource.js +28 -0
  454. package/lib/media-sources/ImageSource.js.map +1 -0
  455. package/lib/media-sources/MediaStreamSource.d.ts +41 -0
  456. package/lib/media-sources/MediaStreamSource.js +146 -0
  457. package/lib/media-sources/MediaStreamSource.js.map +1 -0
  458. package/lib/media-sources/VideoSource.d.ts +21 -0
  459. package/lib/media-sources/VideoSource.js +38 -0
  460. package/lib/media-sources/VideoSource.js.map +1 -0
  461. package/lib/metrics/businessEventsReporter.d.ts +37 -0
  462. package/lib/metrics/businessEventsReporter.js +160 -0
  463. package/lib/metrics/businessEventsReporter.js.map +1 -0
  464. package/lib/metrics/metricsEventTarget.d.ts +41 -0
  465. package/lib/metrics/metricsEventTarget.js +11 -0
  466. package/lib/metrics/metricsEventTarget.js.map +1 -0
  467. package/lib/metrics/metricsHandler.d.ts +9 -0
  468. package/lib/metrics/metricsHandler.js +13 -0
  469. package/lib/metrics/metricsHandler.js.map +1 -0
  470. package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
  471. package/lib/metrics/operationalMetricsReporter.js +108 -0
  472. package/lib/metrics/operationalMetricsReporter.js.map +1 -0
  473. package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
  474. package/lib/metrics/reporters/reportBenchmarks.js +29 -0
  475. package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
  476. package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
  477. package/lib/metrics/reporters/reportGlobalException.js +68 -0
  478. package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
  479. package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
  480. package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
  481. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
  482. package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
  483. package/lib/metrics/reporters/reportLegalState.js +34 -0
  484. package/lib/metrics/reporters/reportLegalState.js.map +1 -0
  485. package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
  486. package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
  487. package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
  488. package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
  489. package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
  490. package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
  491. package/lib/metrics/reporters/reportLensView.d.ts +36 -0
  492. package/lib/metrics/reporters/reportLensView.js +101 -0
  493. package/lib/metrics/reporters/reportLensView.js.map +1 -0
  494. package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
  495. package/lib/metrics/reporters/reportLensWait.js +56 -0
  496. package/lib/metrics/reporters/reportLensWait.js.map +1 -0
  497. package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
  498. package/lib/metrics/reporters/reportSessionException.js +12 -0
  499. package/lib/metrics/reporters/reportSessionException.js.map +1 -0
  500. package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
  501. package/lib/metrics/reporters/reportUserSession.js +67 -0
  502. package/lib/metrics/reporters/reportUserSession.js.map +1 -0
  503. package/lib/metrics/reporters/reporters.d.ts +44 -0
  504. package/lib/metrics/reporters/reporters.js +33 -0
  505. package/lib/metrics/reporters/reporters.js.map +1 -0
  506. package/lib/namedErrors.d.ts +107 -0
  507. package/lib/namedErrors.js +56 -0
  508. package/lib/namedErrors.js.map +1 -0
  509. package/lib/persistence/ExpiringPersistence.d.ts +20 -0
  510. package/lib/persistence/ExpiringPersistence.js +58 -0
  511. package/lib/persistence/ExpiringPersistence.js.map +1 -0
  512. package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
  513. package/lib/persistence/IndexedDBPersistence.js +180 -0
  514. package/lib/persistence/IndexedDBPersistence.js.map +1 -0
  515. package/lib/persistence/Persistence.d.ts +25 -0
  516. package/lib/persistence/Persistence.js +10 -0
  517. package/lib/persistence/Persistence.js.map +1 -0
  518. package/lib/remote-configuration/cofHandler.d.ts +21 -0
  519. package/lib/remote-configuration/cofHandler.js +75 -0
  520. package/lib/remote-configuration/cofHandler.js.map +1 -0
  521. package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
  522. package/lib/remote-configuration/remoteConfiguration.js +43 -0
  523. package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
  524. package/lib/session/CameraKitSession.d.ts +252 -0
  525. package/lib/session/CameraKitSession.js +439 -0
  526. package/lib/session/CameraKitSession.js.map +1 -0
  527. package/lib/session/CameraKitSessionEvents.d.ts +33 -0
  528. package/lib/session/CameraKitSessionEvents.js +21 -0
  529. package/lib/session/CameraKitSessionEvents.js.map +1 -0
  530. package/lib/session/LensKeyboard.d.ts +89 -0
  531. package/lib/session/LensKeyboard.js +95 -0
  532. package/lib/session/LensKeyboard.js.map +1 -0
  533. package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
  534. package/lib/session/LensPerformanceMeasurement.js +91 -0
  535. package/lib/session/LensPerformanceMeasurement.js.map +1 -0
  536. package/lib/session/LensPerformanceMetrics.d.ts +31 -0
  537. package/lib/session/LensPerformanceMetrics.js +58 -0
  538. package/lib/session/LensPerformanceMetrics.js.map +1 -0
  539. package/lib/session/index.d.ts +1 -0
  540. package/lib/session/index.js +2 -0
  541. package/lib/session/index.js.map +1 -0
  542. package/lib/session/lensState.d.ts +29 -0
  543. package/lib/session/lensState.js +160 -0
  544. package/lib/session/lensState.js.map +1 -0
  545. package/lib/session/sessionState.d.ts +10 -0
  546. package/lib/session/sessionState.js +12 -0
  547. package/lib/session/sessionState.js.map +1 -0
  548. package/lib/transforms/Transform2D.d.ts +17 -0
  549. package/lib/transforms/Transform2D.js +18 -0
  550. package/lib/transforms/Transform2D.js.map +1 -0
  551. package/lib/transforms/index.d.ts +1 -0
  552. package/lib/transforms/index.js +2 -0
  553. package/lib/transforms/index.js.map +1 -0
  554. package/package.json +62 -0
@@ -0,0 +1,11 @@
1
+ import { FetchHandler } from "../../handlers/defaultFetchHandler";
2
+ import { RemoteConfiguration } from "../../remote-configuration/remoteConfiguration";
3
+ import { AssetLoader } from "./LensAssetRepository";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare const deviceDependentAssetLoaderFactory: {
8
+ (args_0: FetchHandler<Response>, args_1: RemoteConfiguration): AssetLoader;
9
+ token: "deviceDependentAssetLoader";
10
+ dependencies: readonly ["defaultFetchHandler", "remoteConfiguration"];
11
+ };
@@ -0,0 +1,58 @@
1
+ import { __awaiter } from "tslib";
2
+ import { catchError, firstValueFrom, map, mergeMap } from "rxjs";
3
+ import { isRecord, isString } from "../../common/typeguards";
4
+ import { Injectable } from "../../dependency-injection/Injectable";
5
+ import { createArrayBufferParsingHandler } from "../../handlers/arrayBufferParsingHandler";
6
+ import { defaultFetchHandlerFactory } from "../../handlers/defaultFetchHandler";
7
+ import { HandlerChainBuilder } from "../../handlers/HandlerChainBuilder";
8
+ import { remoteConfigurationFactory } from "../../remote-configuration/remoteConfiguration";
9
+ const hasStringValue = (value) => {
10
+ return isRecord(value) && isString(value.stringValue);
11
+ };
12
+ const isAssetConfig = (value) => {
13
+ return isRecord(value) && isString(value.url) && (value.checksum === undefined || isString(value.checksum));
14
+ };
15
+ /**
16
+ * @internal
17
+ */
18
+ export const deviceDependentAssetLoaderFactory = Injectable("deviceDependentAssetLoader", [defaultFetchHandlerFactory.token, remoteConfigurationFactory.token], (fetchHandler, remoteConfiguration) => {
19
+ const assetHandler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;
20
+ return function deviceDependentAssetLoader({ assetId }) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const loadingFailed = (reason, cause) => new Error(`Cannot load device-dependent asset ${assetId}. ${reason}`, { cause });
23
+ return firstValueFrom(remoteConfiguration.get(assetId).pipe(catchError((error) => {
24
+ throw loadingFailed("COF config failed to load.", error);
25
+ }), map((configs) => {
26
+ if (configs.length === 0) {
27
+ throw loadingFailed(`No COF config found corresponding to that assetId.`);
28
+ }
29
+ // All of the deviceDependent asset configs will only have one value, so we can safely use the
30
+ // first (i.e. only) element in the configs list.
31
+ const [{ value }] = configs;
32
+ // Asset configurations are all JSON-encoded in the `stringValue` property. If it doesn't
33
+ // exists, we can't fetch the asset.
34
+ if (!hasStringValue(value))
35
+ throw loadingFailed("COF config malformed (missing stringValue)");
36
+ let assetConfig;
37
+ try {
38
+ assetConfig = JSON.parse(value.stringValue);
39
+ }
40
+ catch (parseError) {
41
+ throw loadingFailed("COF config malformed (JSON parse error)", parseError);
42
+ }
43
+ // Asset configurations have a `url` and `checksum` property. Otherwise we're dealing with some
44
+ // other kind of configuration, and cannot fetch the asset.
45
+ if (!isAssetConfig(assetConfig))
46
+ throw loadingFailed("COF config malformed (missing URL)");
47
+ return assetConfig;
48
+ }), mergeMap(({ url, checksum }) => __awaiter(this, void 0, void 0, function* () {
49
+ // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed
50
+ const [data, response] = yield assetHandler(url, { cache: "force-cache" });
51
+ if (!response.ok)
52
+ throw response;
53
+ return { data, checksum };
54
+ }))));
55
+ });
56
+ };
57
+ });
58
+ //# sourceMappingURL=deviceDependentAssetLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceDependentAssetL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M,YAAY,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC3E,IAAI,CAAC,QAAQ,CAAC,EAAE;oBAAE,MAAM,QAAQ,CAAC;gBACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC9B,CAAC,CAAA,CAAC,CACL,CACJ,CAAC;QACN,CAAC;KAAA,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { catchError, firstValueFrom, map, mergeMap } from \"rxjs\";\nimport { isRecord, isString } from \"../../common/typeguards\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { createArrayBufferParsingHandler } from \"../../handlers/arrayBufferParsingHandler\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { HandlerChainBuilder } from \"../../handlers/HandlerChainBuilder\";\nimport { RemoteConfiguration, remoteConfigurationFactory } from \"../../remote-configuration/remoteConfiguration\";\nimport { AssetLoader, AssetResponse } from \"./LensAssetRepository\";\n\ninterface AssetConfig {\n url: string;\n checksum?: string;\n}\n\nconst hasStringValue = (value: unknown): value is { stringValue: string } => {\n return isRecord(value) && isString(value.stringValue);\n};\n\nconst isAssetConfig = (value: unknown): value is AssetConfig => {\n return isRecord(value) && isString(value.url) && (value.checksum === undefined || isString(value.checksum));\n};\n\n/**\n * @internal\n */\nexport const deviceDependentAssetLoaderFactory = Injectable(\n \"deviceDependentAssetLoader\",\n [defaultFetchHandlerFactory.token, remoteConfigurationFactory.token] as const,\n (fetchHandler: FetchHandler, remoteConfiguration: RemoteConfiguration): AssetLoader => {\n const assetHandler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;\n\n return async function deviceDependentAssetLoader({ assetId }): Promise<AssetResponse> {\n const loadingFailed = (reason: string, cause?: unknown) =>\n new Error(`Cannot load device-dependent asset ${assetId}. ${reason}`, { cause });\n\n return firstValueFrom(\n remoteConfiguration.get(assetId).pipe(\n catchError((error) => {\n throw loadingFailed(\"COF config failed to load.\", error);\n }),\n map((configs) => {\n if (configs.length === 0) {\n throw loadingFailed(`No COF config found corresponding to that assetId.`);\n }\n // All of the deviceDependent asset configs will only have one value, so we can safely use the\n // first (i.e. only) element in the configs list.\n const [{ value }] = configs;\n\n // Asset configurations are all JSON-encoded in the `stringValue` property. If it doesn't\n // exists, we can't fetch the asset.\n if (!hasStringValue(value)) throw loadingFailed(\"COF config malformed (missing stringValue)\");\n\n let assetConfig: unknown;\n try {\n assetConfig = JSON.parse(value.stringValue);\n } catch (parseError) {\n throw loadingFailed(\"COF config malformed (JSON parse error)\", parseError);\n }\n\n // Asset configurations have a `url` and `checksum` property. Otherwise we're dealing with some\n // other kind of configuration, and cannot fetch the asset.\n if (!isAssetConfig(assetConfig)) throw loadingFailed(\"COF config malformed (missing URL)\");\n\n return assetConfig;\n }),\n mergeMap(async ({ url, checksum }) => {\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n const [data, response] = await assetHandler(url, { cache: \"force-cache\" });\n if (!response.ok) throw response;\n return { data, checksum };\n })\n )\n );\n };\n }\n);\n"]}
@@ -0,0 +1,10 @@
1
+ import { FetchHandler } from "../../handlers/defaultFetchHandler";
2
+ import { AssetLoader } from "./LensAssetRepository";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const remoteMediaAssetLoaderFactory: {
7
+ (args_0: FetchHandler<Response>): AssetLoader;
8
+ token: "remoteMediaAssetLoader";
9
+ dependencies: readonly ["defaultFetchHandler"];
10
+ };
@@ -0,0 +1,26 @@
1
+ import { __awaiter } from "tslib";
2
+ import { Injectable } from "../../dependency-injection/Injectable";
3
+ import { createArrayBufferParsingHandler } from "../../handlers/arrayBufferParsingHandler";
4
+ import { defaultFetchHandlerFactory } from "../../handlers/defaultFetchHandler";
5
+ import { HandlerChainBuilder } from "../../handlers/HandlerChainBuilder";
6
+ /**
7
+ * @internal
8
+ */
9
+ export const remoteMediaAssetLoaderFactory = Injectable("remoteMediaAssetLoader", [defaultFetchHandlerFactory.token], (fetchHandler) => {
10
+ const handler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;
11
+ return function remoteMediaAssetLoader(asset) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ // as a default option assuming that RemoteMedia asset type contains asset url in assetId
14
+ // this behaviour could be changed by providing own implementation for RemoteMedia asset loader
15
+ // const cameraKit = bootstrapCameraKit(config, container => {
16
+ // return container.provides(Injectable(
17
+ // remoteMediaAssetLoaderFactory.token, ...
18
+ // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed
19
+ const [buffer, response] = yield handler(asset.assetId, { cache: "force-cache" });
20
+ if (!response.ok)
21
+ throw response;
22
+ return buffer;
23
+ });
24
+ };
25
+ });
26
+ //# sourceMappingURL=remoteMediaAssetLoaderFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remoteMediaAssetLoaderFactory.js","sourceRoot":"","sources":["../../../src/lens/assets/remoteMediaAssetLoaderFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGzE;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CACnD,wBAAwB,EACxB,CAAC,0BAA0B,CAAC,KAAK,CAAU,EAC3C,CAAC,YAA0B,EAAe,EAAE;IACxC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IAErG,OAAO,SAAe,sBAAsB,CAAC,KAAK;;YAC9C,yFAAyF;YACzF,+FAA+F;YAC/F,gEAAgE;YAChE,4CAA4C;YAC5C,iDAAiD;YACjD,yFAAyF;YACzF,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;YAClF,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,MAAM,QAAQ,CAAC;YACjC,OAAO,MAAM,CAAC;QAClB,CAAC;KAAA,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { createArrayBufferParsingHandler } from \"../../handlers/arrayBufferParsingHandler\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { HandlerChainBuilder } from \"../../handlers/HandlerChainBuilder\";\nimport { AssetLoader } from \"./LensAssetRepository\";\n\n/**\n * @internal\n */\nexport const remoteMediaAssetLoaderFactory = Injectable(\n \"remoteMediaAssetLoader\",\n [defaultFetchHandlerFactory.token] as const,\n (fetchHandler: FetchHandler): AssetLoader => {\n const handler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;\n\n return async function remoteMediaAssetLoader(asset) {\n // as a default option assuming that RemoteMedia asset type contains asset url in assetId\n // this behaviour could be changed by providing own implementation for RemoteMedia asset loader\n // const cameraKit = bootstrapCameraKit(config, container => {\n // return container.provides(Injectable(\n // remoteMediaAssetLoaderFactory.token, ...\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n const [buffer, response] = await handler(asset.assetId, { cache: \"force-cache\" });\n if (!response.ok) throw response;\n return buffer;\n };\n }\n);\n"]}
@@ -0,0 +1,10 @@
1
+ import { FetchHandler } from "../../handlers/defaultFetchHandler";
2
+ import { AssetLoader } from "./LensAssetRepository";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const staticAssetLoaderFactory: {
7
+ (args_0: FetchHandler<Response>): AssetLoader;
8
+ token: "staticAssetLoader";
9
+ dependencies: readonly ["defaultFetchHandler"];
10
+ };
@@ -0,0 +1,24 @@
1
+ import { __awaiter } from "tslib";
2
+ import { Injectable } from "../../dependency-injection/Injectable";
3
+ import { createArrayBufferParsingHandler } from "../../handlers/arrayBufferParsingHandler";
4
+ import { defaultFetchHandlerFactory } from "../../handlers/defaultFetchHandler";
5
+ import { HandlerChainBuilder } from "../../handlers/HandlerChainBuilder";
6
+ /**
7
+ * @internal
8
+ */
9
+ export const staticAssetLoaderFactory = Injectable("staticAssetLoader", [defaultFetchHandlerFactory.token], (fetchHandler) => {
10
+ const handler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;
11
+ return (asset, _lens, assetManifest) => __awaiter(void 0, void 0, void 0, function* () {
12
+ var _a;
13
+ const assetUrl = (_a = assetManifest === null || assetManifest === void 0 ? void 0 : assetManifest.find((manifest) => manifest.id === asset.assetId)) === null || _a === void 0 ? void 0 : _a.assetUrl;
14
+ if (!assetUrl) {
15
+ throw new Error(`Cannot load lens asset ${asset.assetId}. Static asset URL could not be found.`);
16
+ }
17
+ // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed
18
+ const [buffer, response] = yield handler(assetUrl, { cache: "force-cache" });
19
+ if (!response.ok)
20
+ throw response;
21
+ return buffer;
22
+ });
23
+ });
24
+ //# sourceMappingURL=staticAssetLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticAssetLoader.js","sourceRoot":"","sources":["../../../src/lens/assets/staticAssetLoader.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,0BAA0B,EAAgB,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGzE;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAC9C,mBAAmB,EACnB,CAAC,0BAA0B,CAAC,KAAK,CAAU,EAC3C,CAAC,YAA0B,EAAe,EAAE;IACxC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IAErG,OAAO,CAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;;QACzC,MAAM,QAAQ,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,0CAAE,QAAQ,CAAC;QAC5F,IAAI,CAAC,QAAQ,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,wCAAwC,CAAC,CAAC;SACpG;QACD,yFAAyF;QACzF,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,QAAQ,CAAC;QACjC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAA,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { createArrayBufferParsingHandler } from \"../../handlers/arrayBufferParsingHandler\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { HandlerChainBuilder } from \"../../handlers/HandlerChainBuilder\";\nimport { AssetLoader } from \"./LensAssetRepository\";\n\n/**\n * @internal\n */\nexport const staticAssetLoaderFactory = Injectable(\n \"staticAssetLoader\",\n [defaultFetchHandlerFactory.token] as const,\n (fetchHandler: FetchHandler): AssetLoader => {\n const handler = new HandlerChainBuilder(fetchHandler).map(createArrayBufferParsingHandler()).handler;\n\n return async (asset, _lens, assetManifest) => {\n const assetUrl = assetManifest?.find((manifest) => manifest.id === asset.assetId)?.assetUrl;\n if (!assetUrl) {\n throw new Error(`Cannot load lens asset ${asset.assetId}. Static asset URL could not be found.`);\n }\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n const [buffer, response] = await handler(assetUrl, { cache: \"force-cache\" });\n if (!response.ok) throw response;\n return buffer;\n };\n }\n);\n"]}
@@ -0,0 +1,7 @@
1
+ export { Lens_CameraFacing, LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type, LensAssetManifestItem, } from "../generated-proto/pb_schema/camera_kit/v3/lens";
2
+ export { LensProto, ContentProto, Lens, isLens, isPreview, toPublicLens } from "./Lens";
3
+ export { AssetTiming, LensRepository, lensRepositoryFactory } from "./LensRepository";
4
+ export { lensSourcesFactory, LensSources } from "../extensions/LensSources";
5
+ export { LensAssetRepository } from "./assets/LensAssetRepository";
6
+ export { remoteMediaAssetLoaderFactory } from "./assets/remoteMediaAssetLoaderFactory";
7
+ export { AssetLoader } from "./assets/LensAssetRepository";
@@ -0,0 +1,7 @@
1
+ export { Lens_CameraFacing, LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type, LensAssetManifestItem, } from "../generated-proto/pb_schema/camera_kit/v3/lens";
2
+ export { isLens, isPreview, toPublicLens } from "./Lens";
3
+ export { LensRepository, lensRepositoryFactory } from "./LensRepository";
4
+ export { lensSourcesFactory, LensSources } from "../extensions/LensSources";
5
+ export { LensAssetRepository } from "./assets/LensAssetRepository";
6
+ export { remoteMediaAssetLoaderFactory } from "./assets/remoteMediaAssetLoaderFactory";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,mCAAmC,EACnC,0BAA0B,EAC1B,qBAAqB,GACxB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAiC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACxF,OAAO,EAAe,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["export {\n Lens_CameraFacing,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n LensAssetManifestItem,\n} from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nexport { LensProto, ContentProto, Lens, isLens, isPreview, toPublicLens } from \"./Lens\";\nexport { AssetTiming, LensRepository, lensRepositoryFactory } from \"./LensRepository\";\nexport { lensSourcesFactory, LensSources } from \"../extensions/LensSources\";\nexport { LensAssetRepository } from \"./assets/LensAssetRepository\";\nexport { remoteMediaAssetLoaderFactory } from \"./assets/remoteMediaAssetLoaderFactory\";\nexport { AssetLoader } from \"./assets/LensAssetRepository\";\n"]}
@@ -0,0 +1,5 @@
1
+ import { LensProto } from "./Lens";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function decodeEnvelopes(envelopes: ArrayBuffer[]): LensProto[];
@@ -0,0 +1,19 @@
1
+ import { Envelope } from "../generated-proto/pb_schema/camera_kit/v3/export";
2
+ /**
3
+ * @internal
4
+ */
5
+ function decodeEnvelope(envelope) {
6
+ try {
7
+ return Envelope.decode(new Uint8Array(envelope)).lenses;
8
+ }
9
+ catch (_a) {
10
+ throw new Error("Invalid lens envelope");
11
+ }
12
+ }
13
+ /**
14
+ * @internal
15
+ */
16
+ export function decodeEnvelopes(envelopes) {
17
+ return envelopes.reduce((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);
18
+ }
19
+ //# sourceMappingURL=lensEnvelopeUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAC5C;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,SAAS,CAAC,MAAM,CAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { LensProto } from \"./Lens\";\n\n/**\n * @internal\n */\nfunction decodeEnvelope(envelope: ArrayBuffer) {\n try {\n return Envelope.decode(new Uint8Array(envelope)).lenses;\n } catch {\n throw new Error(\"Invalid lens envelope\");\n }\n}\n\n/**\n * @internal\n */\nexport function decodeEnvelopes(envelopes: ArrayBuffer[]) {\n return envelopes.reduce<LensProto[]>((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { FetchHandler } from "../handlers/defaultFetchHandler";
2
+ import { LensProto } from "./Lens";
3
+ export declare function retrieveCameraKitLens(httpClient: FetchHandler, lensId: string, groupId: string): Promise<LensProto>;
4
+ export declare function retrieveCameraKitLensGroup(httpClient: FetchHandler, groupId: string): Promise<LensProto[]>;
@@ -0,0 +1,30 @@
1
+ import { __awaiter } from "tslib";
2
+ import { isGetGroupResponse, isLensProto } from "./Lens";
3
+ const BASE_PATH = "https://api-kit.snapchat.com/com.snap.camerakit.v3.Lenses";
4
+ function getRequestId(res) {
5
+ return res.headers.get("x-request-id");
6
+ }
7
+ export function retrieveCameraKitLens(httpClient, lensId, groupId) {
8
+ return __awaiter(this, void 0, void 0, function* () {
9
+ const url = [BASE_PATH, "groups", groupId, "lenses", lensId].join("/");
10
+ const response = yield httpClient(url, { credentials: "include" });
11
+ const body = yield response.json();
12
+ const lens = body.lens;
13
+ if (!isLensProto(lens)) {
14
+ throw new Error(`Expected request to ${url} to return a Lens. Got:\n\n${JSON.stringify(body)} with request-id of "${getRequestId(response)}"`);
15
+ }
16
+ return lens;
17
+ });
18
+ }
19
+ export function retrieveCameraKitLensGroup(httpClient, groupId) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const url = [BASE_PATH, "groups", groupId].join("/");
22
+ const response = yield httpClient(url, { credentials: "include" });
23
+ const body = yield response.json();
24
+ if (!isGetGroupResponse(body)) {
25
+ throw new Error(`Expected request to ${url} to return a LensGroup. Got:\n\n${JSON.stringify(body)} with request-id of "${getRequestId(response)}"`);
26
+ }
27
+ return body.lenses;
28
+ });
29
+ }
30
+ //# sourceMappingURL=lensHttpUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lensHttpUtil.js","sourceRoot":"","sources":["../../src/lens/lensHttpUtil.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAa,MAAM,QAAQ,CAAC;AAEpE,MAAM,SAAS,GAAG,2DAA2D,CAAC;AAE9E,SAAS,YAAY,CAAC,GAAa;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAgB,qBAAqB,CACvC,UAAwB,EACxB,MAAc,EACd,OAAe;;QAEf,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;QACnE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CACX,uBAAuB,GAAG,8BAA8B,IAAI,CAAC,SAAS,CAClE,IAAI,CACP,wBAAwB,YAAY,CAAC,QAAQ,CAAC,GAAG,CACrD,CAAC;SACL;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CAAA;AAED,MAAM,UAAgB,0BAA0B,CAAC,UAAwB,EAAE,OAAe;;QACtF,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;QACnE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CACX,uBAAuB,GAAG,mCAAmC,IAAI,CAAC,SAAS,CACvE,IAAI,CACP,wBAAwB,YAAY,CAAC,QAAQ,CAAC,GAAG,CACrD,CAAC;SACL;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CAAA","sourcesContent":["import { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { isGetGroupResponse, isLensProto, LensProto } from \"./Lens\";\n\nconst BASE_PATH = \"https://api-kit.snapchat.com/com.snap.camerakit.v3.Lenses\";\n\nfunction getRequestId(res: Response) {\n return res.headers.get(\"x-request-id\");\n}\n\nexport async function retrieveCameraKitLens(\n httpClient: FetchHandler,\n lensId: string,\n groupId: string\n): Promise<LensProto> {\n const url = [BASE_PATH, \"groups\", groupId, \"lenses\", lensId].join(\"/\");\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n const lens = body.lens;\n if (!isLensProto(lens)) {\n throw new Error(\n `Expected request to ${url} to return a Lens. Got:\\n\\n${JSON.stringify(\n body\n )} with request-id of \"${getRequestId(response)}\"`\n );\n }\n return lens;\n}\n\nexport async function retrieveCameraKitLensGroup(httpClient: FetchHandler, groupId: string): Promise<LensProto[]> {\n const url = [BASE_PATH, \"groups\", groupId].join(\"/\");\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n if (!isGetGroupResponse(body)) {\n throw new Error(\n `Expected request to ${url} to return a LensGroup. Got:\\n\\n${JSON.stringify(\n body\n )} with request-id of \"${getRequestId(response)}\"`\n );\n }\n return body.lenses;\n}\n"]}
@@ -0,0 +1,20 @@
1
+ export declare const enum Orientation {
2
+ TopLeft = 1,
3
+ TopRight = 2,
4
+ BottomRight = 3,
5
+ BottomLeft = 4,
6
+ LeftTop = 5,
7
+ RightTop = 6,
8
+ RightBottom = 7,
9
+ LeftBottom = 8
10
+ }
11
+ /**
12
+ * Parses JPEG EXIF metadata and returns Orientation tag of it, or undefined if not applicable.
13
+ *
14
+ * Adopted from https://stackoverflow.com/a/32490603
15
+ *
16
+ * @internal
17
+ * @param data JPEG binary.
18
+ * @returns Orientation tag value or undefined.
19
+ */
20
+ export declare function extractJpegOrientationTag(data: ArrayBuffer): Orientation | undefined;
@@ -0,0 +1,61 @@
1
+ const JPEG_ID = 0xffd8;
2
+ const APP1_MARKER = 0xffe1;
3
+ const EXIF_ID = 0x45786966;
4
+ const LITTLE_ENDIAN = 0x4949;
5
+ const ORIENTATION_TAG_OFFSET = 0x0112;
6
+ // http://sylvana.net/jpegcrop/exif_orientation.html
7
+ export var Orientation;
8
+ (function (Orientation) {
9
+ Orientation[Orientation["TopLeft"] = 1] = "TopLeft";
10
+ Orientation[Orientation["TopRight"] = 2] = "TopRight";
11
+ Orientation[Orientation["BottomRight"] = 3] = "BottomRight";
12
+ Orientation[Orientation["BottomLeft"] = 4] = "BottomLeft";
13
+ Orientation[Orientation["LeftTop"] = 5] = "LeftTop";
14
+ Orientation[Orientation["RightTop"] = 6] = "RightTop";
15
+ Orientation[Orientation["RightBottom"] = 7] = "RightBottom";
16
+ Orientation[Orientation["LeftBottom"] = 8] = "LeftBottom";
17
+ })(Orientation || (Orientation = {}));
18
+ /**
19
+ * Parses JPEG EXIF metadata and returns Orientation tag of it, or undefined if not applicable.
20
+ *
21
+ * Adopted from https://stackoverflow.com/a/32490603
22
+ *
23
+ * @internal
24
+ * @param data JPEG binary.
25
+ * @returns Orientation tag value or undefined.
26
+ */
27
+ export function extractJpegOrientationTag(data) {
28
+ const view = new DataView(data);
29
+ if (view.getUint16(0, false) !== JPEG_ID)
30
+ return undefined;
31
+ const length = view.byteLength;
32
+ let offset = 2;
33
+ while (offset < length) {
34
+ if (view.getUint16(offset + 2, false) <= 8)
35
+ return undefined;
36
+ let marker = view.getUint16(offset, false);
37
+ offset += 2;
38
+ if (marker === APP1_MARKER) {
39
+ if (view.getUint32((offset += 2), false) !== EXIF_ID) {
40
+ return undefined;
41
+ }
42
+ let little = view.getUint16((offset += 6), false) === LITTLE_ENDIAN;
43
+ offset += view.getUint32(offset + 4, little);
44
+ let tags = view.getUint16(offset, little);
45
+ offset += 2;
46
+ for (let i = 0; i < tags; i++) {
47
+ if (view.getUint16(offset + i * 12, little) === ORIENTATION_TAG_OFFSET) {
48
+ return view.getUint16(offset + i * 12 + 8, little);
49
+ }
50
+ }
51
+ }
52
+ else if ((marker & 0xff00) !== 0xff00) {
53
+ break;
54
+ }
55
+ else {
56
+ offset += view.getUint16(offset, false);
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ //# sourceMappingURL=exif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exif.js","sourceRoot":"","sources":["../../src/lens-client-interface/exif.ts"],"names":[],"mappings":"AAAA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CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,aAAa,CAAC;YACpE,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;YAC7C,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC1C,MAAM,IAAI,CAAC,CAAC;YACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;gBAC3B,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,KAAK,sBAAsB,EAAE;oBACpE,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAgB,CAAC;iBACrE;aACJ;SACJ;aAAM,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM,EAAE;YACrC,MAAM;SACT;aAAM;YACH,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAC3C;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["const JPEG_ID = 0xffd8;\nconst APP1_MARKER = 0xffe1;\nconst EXIF_ID = 0x45786966;\nconst LITTLE_ENDIAN = 0x4949;\nconst ORIENTATION_TAG_OFFSET = 0x0112;\n\n// http://sylvana.net/jpegcrop/exif_orientation.html\nexport const enum Orientation {\n TopLeft = 1,\n TopRight = 2,\n BottomRight = 3,\n BottomLeft = 4,\n LeftTop = 5,\n RightTop = 6,\n RightBottom = 7,\n LeftBottom = 8,\n}\n\n/**\n * Parses JPEG EXIF metadata and returns Orientation tag of it, or undefined if not applicable.\n *\n * Adopted from https://stackoverflow.com/a/32490603\n *\n * @internal\n * @param data JPEG binary.\n * @returns Orientation tag value or undefined.\n */\nexport function extractJpegOrientationTag(data: ArrayBuffer): Orientation | undefined {\n const view = new DataView(data);\n\n if (view.getUint16(0, false) !== JPEG_ID) return undefined;\n\n const length = view.byteLength;\n let offset = 2;\n\n while (offset < length) {\n if (view.getUint16(offset + 2, false) <= 8) return undefined;\n let marker = view.getUint16(offset, false);\n offset += 2;\n\n if (marker === APP1_MARKER) {\n if (view.getUint32((offset += 2), false) !== EXIF_ID) {\n return undefined;\n }\n\n let little = view.getUint16((offset += 6), false) === LITTLE_ENDIAN;\n offset += view.getUint32(offset + 4, little);\n let tags = view.getUint16(offset, little);\n offset += 2;\n for (let i = 0; i < tags; i++) {\n if (view.getUint16(offset + i * 12, little) === ORIENTATION_TAG_OFFSET) {\n return view.getUint16(offset + i * 12 + 8, little) as Orientation;\n }\n }\n } else if ((marker & 0xff00) !== 0xff00) {\n break;\n } else {\n offset += view.getUint16(offset, false);\n }\n }\n return undefined;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { ClientInterfaceData, LensCoreModule } from "../lens-core-module/generated-types";
2
+ /**
3
+ * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCoreModule): Promise<void>;
@@ -0,0 +1,128 @@
1
+ import { __awaiter } from "tslib";
2
+ import { fileOpen } from "browser-fs-access";
3
+ import { getLogger } from "../logger/logger";
4
+ import { extractJpegOrientationTag } from "./exif";
5
+ const logger = getLogger("lensClientInterfaceImagePicker");
6
+ // Common MIME types supported by all browsers as per:
7
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
8
+ const mimeTypes = {
9
+ image: [
10
+ "image/avif",
11
+ "image/bmp",
12
+ "image/gif",
13
+ "image/jpeg",
14
+ "image/png",
15
+ "image/svg+xml",
16
+ "image/tiff",
17
+ "image/webp",
18
+ ],
19
+ video: [
20
+ "video/3gpp",
21
+ "video/3gpp2",
22
+ "video/mp2t",
23
+ "video/mp4",
24
+ "video/mpeg",
25
+ "video/ogg",
26
+ "video/quicktime",
27
+ "video/webm",
28
+ "video/x-msvideo",
29
+ ],
30
+ };
31
+ function* enumerateSupportedVideoTypes(types) {
32
+ // test video element to perform MIME types support check
33
+ const testVideoElement = typeof document !== "undefined" ? document.createElement("video") : undefined;
34
+ for (const type of types) {
35
+ if ((testVideoElement === null || testVideoElement === void 0 ? void 0 : testVideoElement.canPlayType(type)) || false) {
36
+ yield type;
37
+ }
38
+ }
39
+ }
40
+ function readFileAsArrayBuffer(file) {
41
+ return new Promise((resolve, reject) => {
42
+ const reader = new FileReader();
43
+ reader.addEventListener("load", (event) => {
44
+ // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()
45
+ resolve(event.target.result);
46
+ });
47
+ reader.addEventListener("error", (event) => {
48
+ reject(event.target.error);
49
+ });
50
+ reader.readAsArrayBuffer(file);
51
+ });
52
+ }
53
+ function getMimeType({ ImageEnabled, VideoEnabled }) {
54
+ const types = [];
55
+ if (ImageEnabled === "1")
56
+ types.push(...mimeTypes.image);
57
+ if (VideoEnabled === "1")
58
+ types.push(...enumerateSupportedVideoTypes(mimeTypes.video));
59
+ if (types.length === 0) {
60
+ throw new Error("Unknown media type requested");
61
+ }
62
+ return types;
63
+ }
64
+ function getOrientation(data, lensCore) {
65
+ var _a;
66
+ const orientationMap = {
67
+ [1 /* Orientation.TopLeft */]: lensCore.ExternalMediaOrientation.CW0,
68
+ [2 /* Orientation.TopRight */]: lensCore.ExternalMediaOrientation.CW0,
69
+ [3 /* Orientation.BottomRight */]: lensCore.ExternalMediaOrientation.CW180,
70
+ [4 /* Orientation.BottomLeft */]: lensCore.ExternalMediaOrientation.CW180,
71
+ [5 /* Orientation.LeftTop */]: lensCore.ExternalMediaOrientation.CW90,
72
+ [6 /* Orientation.RightTop */]: lensCore.ExternalMediaOrientation.CW90,
73
+ [7 /* Orientation.RightBottom */]: lensCore.ExternalMediaOrientation.CW270,
74
+ [8 /* Orientation.LeftBottom */]: lensCore.ExternalMediaOrientation.CW270,
75
+ };
76
+ try {
77
+ return orientationMap[(_a = extractJpegOrientationTag(data)) !== null && _a !== void 0 ? _a : 1 /* Orientation.TopLeft */];
78
+ }
79
+ catch (error) {
80
+ logger.info("Error occured while reading EXIF orientation tag", error);
81
+ return lensCore.ExternalMediaOrientation.CW0;
82
+ }
83
+ }
84
+ /**
85
+ * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.
86
+ *
87
+ * @internal
88
+ */
89
+ export function pickClientImage(clientInterfaceData, lensCore) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const mimeTypes = getMimeType(clientInterfaceData);
92
+ logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);
93
+ const file = yield fileOpen({ mimeTypes });
94
+ logger.debug(`Selected file MIME type: ${file.type}`);
95
+ const data = yield readFileAsArrayBuffer(file);
96
+ if (file.type.startsWith("image/")) {
97
+ lensCore.provideExternalImage({
98
+ data,
99
+ orientation: getOrientation(data, lensCore),
100
+ // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces
101
+ // from an image to apply the effect on, using each of their native face detectors (not using LensCore).
102
+ // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect
103
+ // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:
104
+ // - hook up some external web face tracking library
105
+ // - make LensCore to expose face tracker to external clients
106
+ faceRects: [
107
+ {
108
+ origin: {
109
+ x: 0,
110
+ y: 0,
111
+ },
112
+ size: {
113
+ width: 1,
114
+ height: 1,
115
+ },
116
+ },
117
+ ],
118
+ });
119
+ }
120
+ else {
121
+ lensCore.provideExternalVideo({
122
+ data,
123
+ orientation: lensCore.ExternalMediaOrientation.CW0,
124
+ });
125
+ }
126
+ });
127
+ }
128
+ //# sourceMappingURL=imagePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imagePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EA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fileOpen, FileWithHandle } from \"browser-fs-access\";\nimport { ClientInterfaceData, LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCoreModule) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occured while reading EXIF orientation tag\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCoreModule) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await fileOpen({ mimeTypes });\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { LensCoreModule } from "../lens-core-module/generated-types";
2
+ /**
3
+ * Registers client interface handler in LensCore.
4
+ *
5
+ * @internal
6
+ * @param lensCore LensCore instance to register in.
7
+ * @param sessionErrors EventTarget to dispatch errors in.
8
+ */
9
+ export declare const registerLensClientInterfaceHandler: {
10
+ (args_0: LensCoreModule): void;
11
+ token: "registerLensClientInterfaceHandler";
12
+ dependencies: readonly ["lensCore"];
13
+ };
@@ -0,0 +1,30 @@
1
+ import { __awaiter } from "tslib";
2
+ import { lensImagePickerError } from "../namedErrors";
3
+ import { Injectable } from "../dependency-injection/Injectable";
4
+ import { lensCoreFactory } from "../lens-core-module";
5
+ import { getLogger } from "../logger/logger";
6
+ import { pickClientImage } from "./imagePicker";
7
+ const logger = getLogger("lensClientInterface");
8
+ /**
9
+ * Registers client interface handler in LensCore.
10
+ *
11
+ * @internal
12
+ * @param lensCore LensCore instance to register in.
13
+ * @param sessionErrors EventTarget to dispatch errors in.
14
+ */
15
+ export const registerLensClientInterfaceHandler = Injectable("registerLensClientInterfaceHandler", [lensCoreFactory.token], (lensCore) => {
16
+ // Make sure we are compatible with previous LensCore versions
17
+ if (!lensCore.setClientInterfaceRequestHandler) {
18
+ logger.warn("Current LensCore version doesn't support lens client interface requests");
19
+ return;
20
+ }
21
+ lensCore.setClientInterfaceRequestHandler(({ data, interfaceControl, interfaceAction }) => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (interfaceControl === lensCore.InterfaceControl.ImagePicker &&
23
+ interfaceAction === lensCore.InterfaceAction.Show) {
24
+ yield pickClientImage(data, lensCore).catch((error) => {
25
+ logger.error(lensImagePickerError("Failed to pick an image.", error));
26
+ });
27
+ }
28
+ }));
29
+ });
30
+ //# sourceMappingURL=lensClientInterface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAwB,EAAE,EAAE;IACzB,8DAA8D;IAC9D,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,EAAE;QAC5F,IACI,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC,WAAW;YAC1D,eAAe,KAAK,QAAQ,CAAC,eAAe,CAAC,IAAI,EACnD;YACE,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { lensCoreFactory } from \"../lens-core-module\";\nimport { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { getLogger } from \"../logger/logger\";\nimport { pickClientImage } from \"./imagePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCoreModule) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore).catch((error) => {\n logger.error(lensImagePickerError(\"Failed to pick an image.\", error));\n });\n }\n });\n }\n);\n"]}