@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,129 @@
1
+ import { __awaiter } from "tslib";
2
+ import { createFramebuffer, createProgram, createTexture, promiseSync, setUniform1i, setUniform4f } from "./webglUtils";
3
+ const vertexSource = `#version 300 es
4
+
5
+ precision mediump float;
6
+ precision mediump int;
7
+
8
+ in vec2 pos;
9
+
10
+ void main() {
11
+ gl_Position = vec4(pos, 0.0, 1.0);
12
+ }
13
+ `;
14
+ const fragmentSource = `#version 300 es
15
+
16
+ precision mediump float;
17
+ precision mediump int;
18
+
19
+ uniform int LOOP_COUNT;
20
+ uniform vec4 v0;
21
+ uniform vec4 v1;
22
+ uniform vec4 v2;
23
+
24
+ out vec4 fragColor;
25
+
26
+ #define REPEAT_2(x) x; x
27
+ #define REPEAT_4(x) REPEAT_2(x); REPEAT_2(x)
28
+ #define REPEAT_8(x) REPEAT_4(x); REPEAT_4(x)
29
+ #define REPEAT_16(x) REPEAT_8(x); REPEAT_8(x)
30
+ #define REPEAT_32(x) REPEAT_16(x); REPEAT_16(x)
31
+
32
+ void main() {
33
+ vec4 r = v2;
34
+ for (int i = 0; i < LOOP_COUNT; i++) {
35
+ REPEAT_32(r = r * v1 + v0);
36
+ }
37
+ fragColor = r;
38
+ }
39
+ `;
40
+ const width = 1024;
41
+ const height = 1024;
42
+ const budgetMs = 300;
43
+ const maxLoopCount = 1000;
44
+ function prepareBenchmark(gl) {
45
+ const texture = createTexture(gl, width, height);
46
+ const framebuffer = createFramebuffer(gl, texture);
47
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
48
+ const buffer = gl.createBuffer();
49
+ if (!buffer) {
50
+ throw new Error("Failed to create WebGLBuffer.");
51
+ }
52
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
53
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, 1, -1, -1, 1, -1, 1, 1]), gl.STATIC_DRAW);
54
+ gl.viewport(0, 0, width, height);
55
+ gl.disable(gl.CULL_FACE);
56
+ gl.disable(gl.DEPTH_TEST);
57
+ const program = createProgram(gl, vertexSource, fragmentSource);
58
+ gl.useProgram(program);
59
+ const posLocation = gl.getAttribLocation(program, "pos");
60
+ gl.enableVertexAttribArray(posLocation);
61
+ gl.vertexAttribPointer(posLocation, 2, gl.FLOAT, false, 0, 0);
62
+ setUniform4f(gl, program, "v0", [1.15, 1.23, 1.47, 1.84]);
63
+ setUniform4f(gl, program, "v1", [1.65, 1.22, 1.69, 1.04]);
64
+ setUniform4f(gl, program, "v2", [1.05, 1.3, 1.55, 1.23]);
65
+ return {
66
+ program,
67
+ cleanupBenchmark: () => {
68
+ gl.deleteProgram(program);
69
+ gl.deleteBuffer(buffer);
70
+ gl.deleteFramebuffer(framebuffer);
71
+ gl.deleteTexture(texture);
72
+ },
73
+ };
74
+ }
75
+ function runBenchmark(gl, program) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ yield promiseSync(gl);
78
+ const start = performance.now();
79
+ const flops = [];
80
+ let loopCount = 20;
81
+ while (true) {
82
+ setUniform1i(gl, program, "LOOP_COUNT", loopCount);
83
+ const iterationStart = performance.now();
84
+ gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
85
+ yield promiseSync(gl);
86
+ const iterationEnd = performance.now();
87
+ const duration = iterationEnd - iterationStart;
88
+ flops.push(loopCount / duration);
89
+ const remainingBudgetMs = budgetMs - (iterationEnd - start);
90
+ if (remainingBudgetMs < 0)
91
+ break;
92
+ if (loopCount < maxLoopCount) {
93
+ loopCount += remainingBudgetMs < duration ? 10 : (0.6 * loopCount * remainingBudgetMs) / duration;
94
+ }
95
+ }
96
+ const maxFlops = Math.max(...flops) * (8 * 32) * width * height;
97
+ return maxFlops / 1e6;
98
+ });
99
+ }
100
+ /**
101
+ * These are obtained from historical performance data gathered from end-user devices. Keys are gflops, values are the
102
+ * corresponding performance rating.
103
+ *
104
+ * To compute the performance rating given a gflops value, find the nearest key in this map and look up the rating.
105
+ */
106
+ export const gflopsClusterCenters = new Map([
107
+ [34, 1],
108
+ [134, 2],
109
+ [385, 3],
110
+ [783, 4],
111
+ [1484, 5],
112
+ [2313, 6],
113
+ ]);
114
+ /**
115
+ * This benchmark is the same that's run on non-web (e.g. native mobile) platforms, and produces results that can be
116
+ * compared to those gathered on those platforms – this allows us to cluster results and determine a performance rating
117
+ * based on historical data gathered elsewhere.
118
+ *
119
+ * @internal
120
+ */
121
+ export function benchmarkGflops(gl) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const { program, cleanupBenchmark } = prepareBenchmark(gl);
124
+ const gflops = yield runBenchmark(gl, program);
125
+ cleanupBenchmark();
126
+ return { name: "gflops", value: gflops };
127
+ });
128
+ }
129
+ //# sourceMappingURL=benchmarkGflops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmarkGflops.js","sourceRoot":"","sources":["../../src/benchmark/benchmarkGflops.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAExH,MAAM,YAAY,GAAG;;;;;;;;;;CAUpB,CAAC;AAEF,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBtB,CAAC;AAEF,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,MAAM,GAAG,IAAI,CAAC;AACpB,MA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C;QAC/C,gBAAgB,EAAE,CAAC;QACnB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC7C,CAAC;CAAA","sourcesContent":["import { BenchmarkResult, LensPerformanceCluster } from \"./estimateLensPerformanceCluster\";\nimport { createFramebuffer, createProgram, createTexture, promiseSync, setUniform1i, setUniform4f } from \"./webglUtils\";\n\nconst vertexSource = `#version 300 es\n\nprecision mediump float;\nprecision mediump int;\n\nin vec2 pos;\n\nvoid main() {\n gl_Position = vec4(pos, 0.0, 1.0);\n}\n`;\n\nconst fragmentSource = `#version 300 es\n\nprecision mediump float;\nprecision mediump int;\n\nuniform int LOOP_COUNT;\nuniform vec4 v0;\nuniform vec4 v1;\nuniform vec4 v2;\n\nout vec4 fragColor;\n\n#define REPEAT_2(x) x; x\n#define REPEAT_4(x) REPEAT_2(x); REPEAT_2(x)\n#define REPEAT_8(x) REPEAT_4(x); REPEAT_4(x)\n#define REPEAT_16(x) REPEAT_8(x); REPEAT_8(x)\n#define REPEAT_32(x) REPEAT_16(x); REPEAT_16(x)\n\nvoid main() {\n vec4 r = v2;\n for (int i = 0; i < LOOP_COUNT; i++) {\n REPEAT_32(r = r * v1 + v0);\n }\n fragColor = r;\n}\n`;\n\nconst width = 1024;\nconst height = 1024;\nconst budgetMs = 300;\nconst maxLoopCount = 1000;\n\nfunction prepareBenchmark(gl: WebGL2RenderingContext): { program: WebGLProgram; cleanupBenchmark: () => void } {\n const texture = createTexture(gl, width, height);\n const framebuffer = createFramebuffer(gl, texture);\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n\n const buffer = gl.createBuffer();\n if (!buffer) {\n throw new Error(\"Failed to create WebGLBuffer.\");\n }\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, 1, -1, -1, 1, -1, 1, 1]), gl.STATIC_DRAW);\n\n gl.viewport(0, 0, width, height);\n gl.disable(gl.CULL_FACE);\n gl.disable(gl.DEPTH_TEST);\n\n const program = createProgram(gl, vertexSource, fragmentSource);\n gl.useProgram(program);\n\n const posLocation = gl.getAttribLocation(program, \"pos\");\n gl.enableVertexAttribArray(posLocation);\n gl.vertexAttribPointer(posLocation, 2, gl.FLOAT, false, 0, 0);\n\n setUniform4f(gl, program, \"v0\", [1.15, 1.23, 1.47, 1.84]);\n setUniform4f(gl, program, \"v1\", [1.65, 1.22, 1.69, 1.04]);\n setUniform4f(gl, program, \"v2\", [1.05, 1.3, 1.55, 1.23]);\n\n return {\n program,\n cleanupBenchmark: () => {\n gl.deleteProgram(program);\n gl.deleteBuffer(buffer);\n gl.deleteFramebuffer(framebuffer);\n gl.deleteTexture(texture);\n },\n };\n}\n\nasync function runBenchmark(gl: WebGL2RenderingContext, program: WebGLProgram): Promise<number> {\n await promiseSync(gl);\n\n const start = performance.now();\n const flops: number[] = [];\n\n let loopCount = 20;\n while (true) {\n setUniform1i(gl, program, \"LOOP_COUNT\", loopCount);\n\n const iterationStart = performance.now();\n\n gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);\n await promiseSync(gl);\n\n const iterationEnd = performance.now();\n const duration = iterationEnd - iterationStart;\n flops.push(loopCount / duration);\n\n const remainingBudgetMs = budgetMs - (iterationEnd - start);\n if (remainingBudgetMs < 0) break;\n\n if (loopCount < maxLoopCount) {\n loopCount += remainingBudgetMs < duration ? 10 : (0.6 * loopCount * remainingBudgetMs) / duration;\n }\n }\n\n const maxFlops = Math.max(...flops) * (8 * 32) * width * height;\n return maxFlops / 1e6;\n}\n\n/**\n * These are obtained from historical performance data gathered from end-user devices. Keys are gflops, values are the\n * corresponding performance rating.\n *\n * To compute the performance rating given a gflops value, find the nearest key in this map and look up the rating.\n */\nexport const gflopsClusterCenters = new Map<number, LensPerformanceCluster>([\n [34, 1],\n [134, 2],\n [385, 3],\n [783, 4],\n [1484, 5],\n [2313, 6],\n]);\n\n/**\n * This benchmark is the same that's run on non-web (e.g. native mobile) platforms, and produces results that can be\n * compared to those gathered on those platforms – this allows us to cluster results and determine a performance rating\n * based on historical data gathered elsewhere.\n *\n * @internal\n */\nexport async function benchmarkGflops(gl: WebGL2RenderingContext): Promise<BenchmarkResult> {\n const { program, cleanupBenchmark } = prepareBenchmark(gl);\n const gflops = await runBenchmark(gl, program);\n cleanupBenchmark();\n return { name: \"gflops\", value: gflops };\n}\n"]}
@@ -0,0 +1,33 @@
1
+ /** @category Bootstrapping and Configuration */
2
+ export declare type LensPerformanceCluster = 0 | 1 | 2 | 3 | 4 | 5 | 6;
3
+ /** @internal */
4
+ export declare type BenchmarkResult = {
5
+ name: string;
6
+ value: number;
7
+ };
8
+ /**
9
+ * Some lenses may decide to modify their behavior based on the performance of the current environment. If you are
10
+ * using such lenses, providing an estimation of lens performance may lead to better user experience (especially on
11
+ * low-performance devices).
12
+ *
13
+ * The cluster value will be an integer from 1-6 which classifies expected lens performance, where 6 is the highest-
14
+ * performing cluster and 1 the lowest.
15
+ *
16
+ * All the raw benchmark results used to estimate the performance cluster are also included for reporting purposes.
17
+ *
18
+ * @category Bootstrapping and Configuration
19
+ */
20
+ export interface EstimatedLensPerformance {
21
+ cluster: LensPerformanceCluster;
22
+ benchmarks: BenchmarkResult[];
23
+ webglRendererInfo: string;
24
+ }
25
+ /**
26
+ * Run benchmarks which attempt to predict expected lens performance, and assign a cluster (i.e. a performance rating)
27
+ * which the CameraKit SDK can use to optimize certain lenses.
28
+ *
29
+ * @returns A rating from 1-6, indicating expected Lens performance.
30
+ *
31
+ * @category Bootstrapping and Configuration
32
+ */
33
+ export declare function estimateLensPerformance(): Promise<EstimatedLensPerformance>;
@@ -0,0 +1,48 @@
1
+ import { __awaiter } from "tslib";
2
+ import { benchmarkError } from "../namedErrors";
3
+ import { gflopsClusterCenters, benchmarkGflops } from "./benchmarkGflops";
4
+ const findNearest = (n, arr) => arr.reduce((a, b) => (Math.abs(a - n) <= Math.abs(b - n) ? a : b));
5
+ const webglContextAttributes = {
6
+ alpha: false,
7
+ antialias: false,
8
+ premultipliedAlpha: false,
9
+ preserveDrawingBuffer: false,
10
+ depth: false,
11
+ stencil: false,
12
+ failIfMajorPerformanceCaveat: false,
13
+ powerPreference: "high-performance",
14
+ };
15
+ /**
16
+ * Run benchmarks which attempt to predict expected lens performance, and assign a cluster (i.e. a performance rating)
17
+ * which the CameraKit SDK can use to optimize certain lenses.
18
+ *
19
+ * @returns A rating from 1-6, indicating expected Lens performance.
20
+ *
21
+ * @category Bootstrapping and Configuration
22
+ */
23
+ export function estimateLensPerformance() {
24
+ var _a;
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ // Prepare performance measurement.
27
+ const canvas = document.createElement("canvas");
28
+ const gl = canvas.getContext("webgl2", webglContextAttributes);
29
+ if (!gl)
30
+ throw benchmarkError("WebGL2 is required to compute performance, but it is not supported.");
31
+ const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
32
+ const webglRendererInfo = debugInfo ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : "unknown";
33
+ // Measure performance (just GFLOPS for now, but could add more benchmarks in the future).
34
+ const gflops = yield benchmarkGflops(gl);
35
+ // Combine performance results and compute a performance rating. Right now we just run a single benchmark, so this
36
+ // is pretty trivial.
37
+ const nearestGflopsClusterCenter = findNearest(gflops.value, Array.from(gflopsClusterCenters.keys()));
38
+ // This should always find a value, but just in case something strange happens inside `findNearest`, we'll default
39
+ // to zero (instead of asserting .get() will always be defined).
40
+ const gflopsCluster = (_a = gflopsClusterCenters.get(nearestGflopsClusterCenter)) !== null && _a !== void 0 ? _a : 0;
41
+ return {
42
+ cluster: gflopsCluster,
43
+ benchmarks: [gflops],
44
+ webglRendererInfo,
45
+ };
46
+ });
47
+ }
48
+ //# sourceMappingURL=estimateLensPerformanceCluster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateLensPerformanceCluster.js","sourceRoot":"","sources":["../../src/benchmark/estimateLensPerformanceCluster.ts"],"names":[],"mappings":";AAAA,OAAO,E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ClH,qBAAqB;QACrB,MAAM,0BAA0B,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAEtG,kHAAkH;QAClH,gEAAgE;QAChE,MAAM,aAAa,GAAG,MAAA,oBAAoB,CAAC,GAAG,CAAC,0BAA0B,CAAC,mCAAI,CAAC,CAAC;QAEhF,OAAO;YACH,OAAO,EAAE,aAAa;YACtB,UAAU,EAAE,CAAC,MAAM,CAAC;YACpB,iBAAiB;SACpB,CAAC;;CACL","sourcesContent":["import { benchmarkError } from \"../namedErrors\";\nimport { gflopsClusterCenters, benchmarkGflops } from \"./benchmarkGflops\";\n\nconst findNearest = (n: number, arr: number[]) => arr.reduce((a, b) => (Math.abs(a - n) <= Math.abs(b - n) ? a : b));\n\nconst webglContextAttributes: WebGLContextAttributes = {\n alpha: false,\n antialias: false,\n premultipliedAlpha: false,\n preserveDrawingBuffer: false,\n depth: false,\n stencil: false,\n failIfMajorPerformanceCaveat: false,\n powerPreference: \"high-performance\",\n};\n\n/** @category Bootstrapping and Configuration */\nexport type LensPerformanceCluster = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n/** @internal */\nexport type BenchmarkResult = { name: string; value: number };\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 * The cluster value will be an integer from 1-6 which classifies expected lens performance, where 6 is the highest-\n * performing cluster and 1 the lowest.\n *\n * All the raw benchmark results used to estimate the performance cluster are also included for reporting purposes.\n *\n * @category Bootstrapping and Configuration\n */\nexport interface EstimatedLensPerformance {\n cluster: LensPerformanceCluster;\n benchmarks: BenchmarkResult[];\n webglRendererInfo: string;\n}\n\n/**\n * Run benchmarks which attempt to predict expected lens performance, and assign a cluster (i.e. a performance rating)\n * which the CameraKit SDK can use to optimize certain lenses.\n *\n * @returns A rating from 1-6, indicating expected Lens performance.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function estimateLensPerformance(): Promise<EstimatedLensPerformance> {\n // Prepare performance measurement.\n const canvas = document.createElement(\"canvas\");\n const gl = canvas.getContext(\"webgl2\", webglContextAttributes);\n if (!gl) throw benchmarkError(\"WebGL2 is required to compute performance, but it is not supported.\");\n\n const debugInfo = gl.getExtension(\"WEBGL_debug_renderer_info\");\n const webglRendererInfo = debugInfo ? (gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) as string) : \"unknown\";\n\n // Measure performance (just GFLOPS for now, but could add more benchmarks in the future).\n const gflops = await benchmarkGflops(gl);\n\n // Combine performance results and compute a performance rating. Right now we just run a single benchmark, so this\n // is pretty trivial.\n const nearestGflopsClusterCenter = findNearest(gflops.value, Array.from(gflopsClusterCenters.keys()));\n\n // This should always find a value, but just in case something strange happens inside `findNearest`, we'll default\n // to zero (instead of asserting .get() will always be defined).\n const gflopsCluster = gflopsClusterCenters.get(nearestGflopsClusterCenter) ?? 0;\n\n return {\n cluster: gflopsCluster,\n benchmarks: [gflops],\n webglRendererInfo,\n };\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export declare function createProgram(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram;
2
+ export declare function createShader(gl: WebGL2RenderingContext, source: string, type: number): WebGLShader;
3
+ export declare function createTexture(gl: WebGL2RenderingContext, width: number, height: number): WebGLTexture;
4
+ export declare function createFramebuffer(gl: WebGL2RenderingContext, texture: WebGLTexture): WebGLFramebuffer;
5
+ export declare function setUniform1i(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, data: number): void;
6
+ export declare function setUniform4f(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, data: [number, number, number, number]): void;
7
+ export declare function promiseSync(gl: WebGL2RenderingContext): Promise<void>;
@@ -0,0 +1,87 @@
1
+ import { webGLError } from "../namedErrors";
2
+ const webGLEntityCreationError = (name) => webGLError(`Could not create ${name}.`);
3
+ export function createProgram(gl, vertexSource, fragmentSource) {
4
+ const vertexShader = createShader(gl, vertexSource, gl.VERTEX_SHADER);
5
+ const fragmentShader = createShader(gl, fragmentSource, gl.FRAGMENT_SHADER);
6
+ const program = gl.createProgram();
7
+ if (!program)
8
+ throw webGLEntityCreationError("WebGLProgram");
9
+ gl.attachShader(program, vertexShader);
10
+ gl.deleteShader(vertexShader);
11
+ gl.attachShader(program, fragmentShader);
12
+ gl.deleteShader(fragmentShader);
13
+ gl.linkProgram(program);
14
+ const success = gl.getProgramParameter(program, gl.LINK_STATUS);
15
+ if (!success) {
16
+ const message = gl.getProgramInfoLog(program);
17
+ gl.deleteProgram(program);
18
+ throw webGLError(`WebGLProgram linking failed with status: ${message}`);
19
+ }
20
+ return program;
21
+ }
22
+ export function createShader(gl, source, type) {
23
+ const shader = gl.createShader(type);
24
+ if (!shader)
25
+ throw webGLEntityCreationError(`WebGLShader (type ${type})`);
26
+ gl.shaderSource(shader, source);
27
+ gl.compileShader(shader);
28
+ const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
29
+ if (!success) {
30
+ const message = gl.getShaderInfoLog(shader);
31
+ gl.deleteShader(shader);
32
+ throw webGLError(`WebGLShader (type ${type}) compilation failed with status: ${message}`);
33
+ }
34
+ return shader;
35
+ }
36
+ export function createTexture(gl, width, height) {
37
+ const texture = gl.createTexture();
38
+ if (!texture)
39
+ throw webGLEntityCreationError("WebGLTexture");
40
+ gl.bindTexture(gl.TEXTURE_2D, texture);
41
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
42
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
43
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
44
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
45
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
46
+ return texture;
47
+ }
48
+ export function createFramebuffer(gl, texture) {
49
+ const framebuffer = gl.createFramebuffer();
50
+ if (!framebuffer)
51
+ throw webGLEntityCreationError("WebGLFramebuffer");
52
+ gl.bindTexture(gl.TEXTURE_2D, texture);
53
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
54
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
55
+ return framebuffer;
56
+ }
57
+ export function setUniform1i(gl, program, name, data) {
58
+ gl.uniform1i(gl.getUniformLocation(program, name), data);
59
+ }
60
+ export function setUniform4f(gl, program, name, data) {
61
+ gl.uniform4f(gl.getUniformLocation(program, name), ...data);
62
+ }
63
+ export function promiseSync(gl) {
64
+ const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
65
+ if (!sync)
66
+ throw webGLEntityCreationError("WebGLSync");
67
+ gl.flush();
68
+ return new Promise((resolve, reject) => {
69
+ const waitForSync = () => {
70
+ const glEnum = gl.clientWaitSync(sync, 0, 0);
71
+ switch (glEnum) {
72
+ case gl.TIMEOUT_EXPIRED:
73
+ setTimeout(waitForSync);
74
+ return;
75
+ case gl.WAIT_FAILED:
76
+ gl.deleteSync(sync);
77
+ return reject();
78
+ case gl.ALREADY_SIGNALED:
79
+ case gl.CONDITION_SATISFIED:
80
+ gl.deleteSync(sync);
81
+ return resolve();
82
+ }
83
+ };
84
+ waitForSync();
85
+ });
86
+ }
87
+ //# sourceMappingURL=webglUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webglUtils.js","sourceRoot":"","sources":["../../src/benchmark/webglUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,CAAC,oBAAoB,IAAI,GAA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AK,EAAE,CAAC;IACX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,WAAW,GAAG,GAAS,EAAE;YAC3B,MAAM,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7C,QAAQ,MAAM,EAAE;gBACZ,KAAK,EAAE,CAAC,eAAe;oBACnB,UAAU,CAAC,WAAW,CAAC,CAAC;oBACxB,OAAO;gBACX,KAAK,EAAE,CAAC,WAAW;oBACf,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACpB,OAAO,MAAM,EAAE,CAAC;gBACpB,KAAK,EAAE,CAAC,gBAAgB,CAAC;gBACzB,KAAK,EAAE,CAAC,mBAAmB;oBACvB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBACpB,OAAO,OAAO,EAAE,CAAC;aACxB;QACL,CAAC,CAAC;QACF,WAAW,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { webGLError } from \"../namedErrors\";\n\nconst webGLEntityCreationError = (name: string) => webGLError(`Could not create ${name}.`);\n\nexport function createProgram(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram {\n const vertexShader = createShader(gl, vertexSource, gl.VERTEX_SHADER);\n const fragmentShader = createShader(gl, fragmentSource, gl.FRAGMENT_SHADER);\n const program = gl.createProgram();\n if (!program) throw webGLEntityCreationError(\"WebGLProgram\");\n gl.attachShader(program, vertexShader);\n gl.deleteShader(vertexShader);\n\n gl.attachShader(program, fragmentShader);\n gl.deleteShader(fragmentShader);\n\n gl.linkProgram(program);\n\n const success = gl.getProgramParameter(program, gl.LINK_STATUS);\n if (!success) {\n const message = gl.getProgramInfoLog(program);\n gl.deleteProgram(program);\n throw webGLError(`WebGLProgram linking failed with status: ${message}`);\n }\n\n return program;\n}\n\nexport function createShader(gl: WebGL2RenderingContext, source: string, type: number): WebGLShader {\n const shader = gl.createShader(type);\n if (!shader) throw webGLEntityCreationError(`WebGLShader (type ${type})`);\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);\n if (!success) {\n const message = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw webGLError(`WebGLShader (type ${type}) compilation failed with status: ${message}`);\n }\n return shader;\n}\n\nexport function createTexture(gl: WebGL2RenderingContext, width: number, height: number): WebGLTexture {\n const texture = gl.createTexture();\n if (!texture) throw webGLEntityCreationError(\"WebGLTexture\");\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n return texture;\n}\n\nexport function createFramebuffer(gl: WebGL2RenderingContext, texture: WebGLTexture): WebGLFramebuffer {\n const framebuffer = gl.createFramebuffer();\n if (!framebuffer) throw webGLEntityCreationError(\"WebGLFramebuffer\");\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n return framebuffer;\n}\n\nexport function setUniform1i(gl: WebGL2RenderingContext, program: WebGLProgram, name: string, data: number): void {\n gl.uniform1i(gl.getUniformLocation(program, name), data);\n}\n\nexport function setUniform4f(\n gl: WebGL2RenderingContext,\n program: WebGLProgram,\n name: string,\n data: [number, number, number, number]\n): void {\n gl.uniform4f(gl.getUniformLocation(program, name), ...data);\n}\n\nexport function promiseSync(gl: WebGL2RenderingContext): Promise<void> {\n const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);\n if (!sync) throw webGLEntityCreationError(\"WebGLSync\");\n gl.flush();\n return new Promise((resolve, reject) => {\n const waitForSync = (): void => {\n const glEnum = gl.clientWaitSync(sync, 0, 0);\n switch (glEnum) {\n case gl.TIMEOUT_EXPIRED:\n setTimeout(waitForSync);\n return;\n case gl.WAIT_FAILED:\n gl.deleteSync(sync);\n return reject();\n case gl.ALREADY_SIGNALED:\n case gl.CONDITION_SATISFIED:\n gl.deleteSync(sync);\n return resolve();\n }\n };\n waitForSync();\n });\n}\n"]}
@@ -0,0 +1,96 @@
1
+ import { Container } from "./dependency-injection/Container";
2
+ import { CameraKit } from "./CameraKit";
3
+ import { CameraKitBootstrapConfiguration } from "./configuration";
4
+ import { PublicServices } from "./dependency-injection/RootServices";
5
+ import { PartialContainer } from "./dependency-injection/PartialContainer";
6
+ /**
7
+ * For more advanced use-cases, this DI Container holds services for which a custom implementation may be provided by
8
+ * the application.
9
+ *
10
+ * @category Bootstrapping and Configuration
11
+ */
12
+ export declare type PublicContainer = Container<PublicServices>;
13
+ /**
14
+ * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return
15
+ * an instance of {@link CameraKit}.
16
+ *
17
+ * CameraKit must be provided with some configuration (the application's API token), and there are some additional
18
+ * configurations which are optional.
19
+ *
20
+ * Descriptions of the available configurations can be found in the documentation for
21
+ * {@link CameraKitBootstrapConfiguration}
22
+ *
23
+ * ---
24
+ *
25
+ * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common
26
+ * use cases.
27
+ *
28
+ * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their
29
+ * own custom implementations of certain CameraKit components. This functionality will only be needed by applications
30
+ * with very specific, more advanced requirements.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // The most common way to bootstrap:
35
+ * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })
36
+ *
37
+ * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.
38
+ * const cameraKit = await bootstrapCameraKit(config, (container) => {
39
+ * return container.provides(myCustomRemoteMediaAssetLoaderFactory)
40
+ * })
41
+ * ```
42
+ *
43
+ * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.
44
+ * @param provide Optional function that can make modifications to CameraKit's root DI container.
45
+ * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.
46
+ *
47
+ * @throws
48
+ * - {@link ConfigurationError} when provided configuration object is invalid
49
+ * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit
50
+ * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine
51
+ * WebAssembly binary.
52
+ *
53
+ * @category Bootstrapping and Configuration
54
+ */
55
+ export declare function bootstrapCameraKit(configuration: CameraKitBootstrapConfiguration, provide?: (c: PublicContainer) => PublicContainer): Promise<CameraKit>;
56
+ /**
57
+ * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.
58
+ *
59
+ * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,
60
+ * replacing the default implementation that loads remote lens assets with a custom implementation that returns
61
+ * different assets based on some business logic within the application.
62
+ *
63
+ * An extension is implemented as a [PartialContainer] – a collection of factory functions, each with its own
64
+ * dependencies, which each provide some "Service." A Service can be of any type, and the CameraKit SDK defines its
65
+ * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.
66
+ *
67
+ * Here's an example of how extensions might be used:
68
+ * ```ts
69
+ * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'
70
+ *
71
+ * const myCustomRemoteAssetLoader = Injectable(
72
+ * remoteMediaAssetLoaderFactory.token,
73
+ * [remoteMediaAssetLoaderFactory.token] as const,
74
+ * (defaultLoader: AssetLoader): AssetLoader => {
75
+ * return async (asset, lens) => {
76
+ * if (lens?.id === MY_SPECIAL_LENS) {
77
+ * return (await fetch('my/asset.glb')).arrayBuffer()
78
+ * }
79
+ * return defaultLoader(asset, lens)
80
+ * }
81
+ * },
82
+ * )
83
+ *
84
+ * const myExtension = createExtension().provides(myCustomeRemoteAssetLoader)
85
+ * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension))
86
+ * ```
87
+ *
88
+ * This also enables greater modularity – the person/team creating the extension can do so in their own package, which
89
+ * could be shared by many applications that all require the same functionality.
90
+ *
91
+ * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided
92
+ * to CameraKit's DI container during {@link bootstrapCameraKit}.
93
+ *
94
+ * @category Bootstrapping and Configuration
95
+ */
96
+ export declare function createExtension(): PartialContainer;
@@ -0,0 +1,204 @@
1
+ import { __awaiter } from "tslib";
2
+ import { lensRepositoryFactory } from "./lens/LensRepository";
3
+ import { Container } from "./dependency-injection/Container";
4
+ import { cameraKitFactory } from "./CameraKit";
5
+ import { lensCoreFactory } from "./lens-core-module/loader/lensCoreFactory";
6
+ import { Injectable } from "./dependency-injection/Injectable";
7
+ import { remoteMediaAssetLoaderFactory } from "./lens/assets/remoteMediaAssetLoaderFactory";
8
+ import { deviceDependentAssetLoaderFactory } from "./lens/assets/deviceDependentAssetLoader";
9
+ import { staticAssetLoaderFactory } from "./lens/assets/staticAssetLoader";
10
+ import { defaultFetchHandlerFactory } from "./handlers/defaultFetchHandler";
11
+ import { cameraKitServiceFetchHandlerFactory } from "./handlers/cameraKitServiceFetchHandlerFactory";
12
+ import { createCameraKitConfigurationFactory } from "./configuration";
13
+ import { PartialContainer } from "./dependency-injection/PartialContainer";
14
+ import { metricsHandlerFactory } from "./metrics/metricsHandler";
15
+ import { operationalMetricReporterFactory } from "./metrics/operationalMetricsReporter";
16
+ import { lensSourcesFactory } from "./extensions/LensSources";
17
+ import { uriHandlersFactory } from "./extensions/UriHandlers";
18
+ import { assert } from "./common/assertions";
19
+ import { isSafeString } from "./common/typeguards";
20
+ import { metricsEventTargetFactory } from "./metrics/metricsEventTarget";
21
+ import { reportGloballyScopedMetrics } from "./metrics/reporters/reporters";
22
+ import { getLogger } from "./logger/logger";
23
+ import { logEntriesFactory } from "./logger/logEntries";
24
+ import { assertPlatformSupported } from "./assertPlatformSupported";
25
+ import { lensPersistenceStoreFactory } from "./lens/LensPersistenceStore";
26
+ import { remoteConfigurationFactory } from "./remote-configuration/remoteConfiguration";
27
+ import { lensAssetRepositoryFactory } from "./lens/assets/LensAssetRepository";
28
+ import { legalStateFactory } from "./legal/legalState";
29
+ import { legalPromptFactory } from "./legal/legalPrompt";
30
+ import { bootstrapError, configurationError } from "./namedErrors";
31
+ import { businessEventsReporterFactory } from "./metrics/businessEventsReporter";
32
+ import { reportGlobalException } from "./metrics/reporters/reportGlobalException";
33
+ import { registerLogEntriesSubscriber } from "./logger/registerLogEntriesSubscriber";
34
+ const logger = getLogger("bootstrapCameraKit");
35
+ // The following errors are not wrapped with BootstrapError and bubble up as is.
36
+ const nonWrappableErrors = [
37
+ "ConfigurationError",
38
+ "PlatformNotSupportedError",
39
+ ];
40
+ /**
41
+ * Returns true if given error has to be wrapped with BoostrapError.
42
+ */
43
+ function shouldWrapError(error) {
44
+ if (error instanceof Error) {
45
+ return !nonWrappableErrors.some((name) => error.name === name);
46
+ }
47
+ return true;
48
+ }
49
+ /**
50
+ * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return
51
+ * an instance of {@link CameraKit}.
52
+ *
53
+ * CameraKit must be provided with some configuration (the application's API token), and there are some additional
54
+ * configurations which are optional.
55
+ *
56
+ * Descriptions of the available configurations can be found in the documentation for
57
+ * {@link CameraKitBootstrapConfiguration}
58
+ *
59
+ * ---
60
+ *
61
+ * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common
62
+ * use cases.
63
+ *
64
+ * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their
65
+ * own custom implementations of certain CameraKit components. This functionality will only be needed by applications
66
+ * with very specific, more advanced requirements.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * // The most common way to bootstrap:
71
+ * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })
72
+ *
73
+ * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.
74
+ * const cameraKit = await bootstrapCameraKit(config, (container) => {
75
+ * return container.provides(myCustomRemoteMediaAssetLoaderFactory)
76
+ * })
77
+ * ```
78
+ *
79
+ * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.
80
+ * @param provide Optional function that can make modifications to CameraKit's root DI container.
81
+ * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.
82
+ *
83
+ * @throws
84
+ * - {@link ConfigurationError} when provided configuration object is invalid
85
+ * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit
86
+ * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine
87
+ * WebAssembly binary.
88
+ *
89
+ * @category Bootstrapping and Configuration
90
+ */
91
+ export function bootstrapCameraKit(configuration, provide) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ try {
94
+ const startTimeMs = performance.now();
95
+ assert(isSafeString(configuration.apiToken), configurationError("Unsafe apiToken"));
96
+ const configurationFactory = createCameraKitConfigurationFactory(configuration);
97
+ // Public container holds services which applications can overwrite with their own implementations.
98
+ const defaultPublicContainer = Container.provides(configurationFactory)
99
+ .provides(defaultFetchHandlerFactory)
100
+ .provides(remoteMediaAssetLoaderFactory)
101
+ .provides(lensSourcesFactory)
102
+ .provides(uriHandlersFactory);
103
+ const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;
104
+ // Now that the client's provide() function has completed and the configuration override is ready,
105
+ // we create another container to initialize the logger. This ensures that logging is available
106
+ // as we continue bootstrapping. We don't initialize the logger as part of the defaultPublicContainer
107
+ // because we don't want applications to provide their own logger implementations,
108
+ // and we're not interested in errors thrown by their provide() function.
109
+ // Below is the minimum required container to report errors to Blizzard.
110
+ const telemetryContainer = Container.provides(publicContainer)
111
+ .provides(logEntriesFactory)
112
+ .provides(cameraKitServiceFetchHandlerFactory)
113
+ .provides(metricsEventTargetFactory)
114
+ .provides(metricsHandlerFactory)
115
+ .provides(operationalMetricReporterFactory)
116
+ .provides(reportGlobalException)
117
+ .run(businessEventsReporterFactory)
118
+ .run(registerLogEntriesSubscriber);
119
+ // Run the exception logger so that it can subscribe to log events -- we can't use `Container.run()` because
120
+ // reportGlobalException is also used as a dependency by other Services (and run does not provide Services,
121
+ // it just runs them once).
122
+ telemetryContainer.get(reportGlobalException.token);
123
+ // At this point, logger is configured to report to console and Blizzard.
124
+ assertPlatformSupported();
125
+ // LensCore is a foundational component which must be created asynchronously.
126
+ // But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>
127
+ // (which means they become async themselves). So we'll create a DI container which provides Promise<LensCore>,
128
+ // wait for that promise once here, then create a new DI container that just contains LensCore.
129
+ const lensCore = yield telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token);
130
+ const container = telemetryContainer
131
+ .provides(Injectable(lensCoreFactory.token, () => lensCore))
132
+ .provides(remoteConfigurationFactory)
133
+ .provides(lensPersistenceStoreFactory)
134
+ .provides(deviceDependentAssetLoaderFactory)
135
+ .provides(staticAssetLoaderFactory)
136
+ .provides(lensAssetRepositoryFactory)
137
+ .provides(lensRepositoryFactory)
138
+ .provides(legalPromptFactory)
139
+ .provides(legalStateFactory)
140
+ .provides(cameraKitFactory)
141
+ // We'll run a PartialContainer containing reporters for globally-scoped metrics. Running this container
142
+ // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain
143
+ // actions occur). This PartialContainer also includes the service which listens to locally-reported metrics
144
+ // and sends them to our backend.
145
+ .run(reportGloballyScopedMetrics);
146
+ const cameraKit = container.get(cameraKitFactory.token);
147
+ const bootstrapTimeMs = performance.now() - startTimeMs;
148
+ const reporter = container.get(operationalMetricReporterFactory.token);
149
+ reporter.timer("bootstrap_time", bootstrapTimeMs);
150
+ return cameraKit;
151
+ }
152
+ catch (error) {
153
+ if (shouldWrapError(error)) {
154
+ error = bootstrapError("Failed to bootstrap Camera Kit.", error);
155
+ }
156
+ logger.error(error);
157
+ throw error;
158
+ }
159
+ });
160
+ }
161
+ /**
162
+ * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.
163
+ *
164
+ * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,
165
+ * replacing the default implementation that loads remote lens assets with a custom implementation that returns
166
+ * different assets based on some business logic within the application.
167
+ *
168
+ * An extension is implemented as a [PartialContainer] – a collection of factory functions, each with its own
169
+ * dependencies, which each provide some "Service." A Service can be of any type, and the CameraKit SDK defines its
170
+ * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.
171
+ *
172
+ * Here's an example of how extensions might be used:
173
+ * ```ts
174
+ * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'
175
+ *
176
+ * const myCustomRemoteAssetLoader = Injectable(
177
+ * remoteMediaAssetLoaderFactory.token,
178
+ * [remoteMediaAssetLoaderFactory.token] as const,
179
+ * (defaultLoader: AssetLoader): AssetLoader => {
180
+ * return async (asset, lens) => {
181
+ * if (lens?.id === MY_SPECIAL_LENS) {
182
+ * return (await fetch('my/asset.glb')).arrayBuffer()
183
+ * }
184
+ * return defaultLoader(asset, lens)
185
+ * }
186
+ * },
187
+ * )
188
+ *
189
+ * const myExtension = createExtension().provides(myCustomeRemoteAssetLoader)
190
+ * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension))
191
+ * ```
192
+ *
193
+ * This also enables greater modularity – the person/team creating the extension can do so in their own package, which
194
+ * could be shared by many applications that all require the same functionality.
195
+ *
196
+ * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided
197
+ * to CameraKit's DI container during {@link bootstrapCameraKit}.
198
+ *
199
+ * @category Bootstrapping and Configuration
200
+ */
201
+ export function createExtension() {
202
+ return new PartialContainer({});
203
+ }
204
+ //# sourceMappingURL=bootstrapCameraKit.js.map