@snap/camera-kit 0.13.2 → 0.14.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 (234) hide show
  1. package/docs/html/assets/search.js +1 -1
  2. package/docs/html/classes/CameraKit.html +4 -3
  3. package/docs/html/classes/CameraKitSession.html +4 -3
  4. package/docs/html/classes/CameraKitSource.html +4 -3
  5. package/docs/html/classes/LensPerformanceMeasurement.html +4 -3
  6. package/docs/html/classes/LensPerformanceMetrics.html +4 -3
  7. package/docs/html/classes/LensRepository.html +6 -5
  8. package/docs/html/classes/LensSources.html +4 -3
  9. package/docs/html/classes/Transform2D.html +4 -3
  10. package/docs/html/classes/TypedCustomEvent.html +4 -3
  11. package/docs/html/classes/TypedEventTarget.html +4 -3
  12. package/docs/html/functions/Injectable.html +4 -3
  13. package/docs/html/functions/bootstrapCameraKit.html +4 -3
  14. package/docs/html/functions/createExtension.html +4 -3
  15. package/docs/html/functions/createImageSource.html +4 -3
  16. package/docs/html/functions/createMediaStreamSource.html +4 -3
  17. package/docs/html/functions/createUserMediaSource.html +4 -3
  18. package/docs/html/functions/createVideoSource.html +4 -3
  19. package/docs/html/functions/estimateLensPerformance.html +4 -3
  20. package/docs/html/functions/getRequiredBootstrapURLs.html +4 -3
  21. package/docs/html/functions/lensSourcesFactory.html +4 -3
  22. package/docs/html/functions/remoteApiServicesFactory.html +4 -3
  23. package/docs/html/index.html +5 -4
  24. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +16 -5
  25. package/docs/html/interfaces/CameraKitSourceSubscriber.html +5 -4
  26. package/docs/html/interfaces/ComputedFrameMetrics.html +4 -3
  27. package/docs/html/interfaces/CreateSessionOptions.html +4 -3
  28. package/docs/html/interfaces/EstimatedLensPerformance.html +4 -3
  29. package/docs/html/interfaces/Lens.html +13 -3
  30. package/docs/html/interfaces/LensSource.html +4 -3
  31. package/docs/html/interfaces/MediaStreamSourceOptions.html +4 -3
  32. package/docs/html/interfaces/Preview.html +4 -3
  33. package/docs/html/interfaces/RemoteApiRequest.html +4 -3
  34. package/docs/html/interfaces/RemoteApiResponse.html +4 -3
  35. package/docs/html/interfaces/RemoteApiService.html +4 -3
  36. package/docs/html/interfaces/Snapcode.html +4 -3
  37. package/docs/html/interfaces/UriCancelRequest.html +4 -3
  38. package/docs/html/interfaces/UriRequest.html +4 -3
  39. package/docs/html/interfaces/UriResponse.html +4 -3
  40. package/docs/html/interfaces/VideoSourceOptions.html +4 -3
  41. package/docs/html/modules.html +6 -4
  42. package/docs/html/types/AssetLoader.html +4 -3
  43. package/docs/html/types/AssetTiming.html +4 -3
  44. package/docs/html/types/BenchmarkError.html +4 -3
  45. package/docs/html/types/BootstrapError.html +4 -3
  46. package/docs/html/types/CacheKeyNotFoundError.html +4 -3
  47. package/docs/html/types/CameraKitDeviceInfo.html +4 -3
  48. package/docs/html/types/CameraKitDeviceOptions.html +4 -3
  49. package/docs/html/types/CameraKitSessionEventListener.html +4 -3
  50. package/docs/html/types/CameraKitSessionEvents.html +6 -5
  51. package/docs/html/types/CameraKitSourceError.html +4 -3
  52. package/docs/html/types/CameraKitSourceInfo.html +4 -3
  53. package/docs/html/types/CameraKitSourceOptions.html +4 -3
  54. package/docs/html/types/ConfigurationError.html +4 -3
  55. package/docs/html/types/Keyboard.html +4 -3
  56. package/docs/html/types/KeyboardEvents.html +4 -3
  57. package/docs/html/types/LegalError.html +4 -3
  58. package/docs/html/types/LensAbortError.html +119 -0
  59. package/docs/html/types/LensAssetError.html +4 -3
  60. package/docs/html/types/LensContentValidationError.html +4 -3
  61. package/docs/html/types/LensError.html +4 -3
  62. package/docs/html/types/LensExecutionError.html +4 -3
  63. package/docs/html/types/LensImagePickerError.html +4 -3
  64. package/docs/html/types/LensLaunchParams.html +4 -3
  65. package/docs/html/types/LensMetricsEvents.html +4 -3
  66. package/docs/html/types/LensPerformanceCluster.html +4 -3
  67. package/docs/html/types/LensView.html +4 -3
  68. package/docs/html/types/LensWait.html +4 -3
  69. package/docs/html/types/PersistentStoreError.html +4 -3
  70. package/docs/html/types/PlatformNotSupportedError.html +4 -3
  71. package/docs/html/types/PublicContainer.html +4 -3
  72. package/docs/html/types/RemoteApiRequestHandler.html +4 -3
  73. package/docs/html/types/RemoteApiServices.html +4 -3
  74. package/docs/html/types/RemoteApiStatus.html +4 -3
  75. package/docs/html/types/RenderTarget.html +4 -3
  76. package/docs/html/types/Uri.html +4 -3
  77. package/docs/html/types/WebGLError.html +4 -3
  78. package/docs/html/variables/extensionRequestContext.html +4 -3
  79. package/docs/md/classes/CameraKit.md +1 -1
  80. package/docs/md/classes/CameraKitSession.md +1 -1
  81. package/docs/md/classes/CameraKitSource.md +1 -1
  82. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  83. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  84. package/docs/md/classes/LensRepository.md +3 -3
  85. package/docs/md/classes/LensSources.md +1 -1
  86. package/docs/md/classes/Transform2D.md +1 -1
  87. package/docs/md/classes/TypedCustomEvent.md +1 -1
  88. package/docs/md/classes/TypedEventTarget.md +1 -1
  89. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +13 -2
  90. package/docs/md/interfaces/CameraKitSourceSubscriber.md +3 -3
  91. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  92. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  93. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  94. package/docs/md/interfaces/Lens.md +11 -1
  95. package/docs/md/interfaces/LensSource.md +1 -1
  96. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  97. package/docs/md/interfaces/Preview.md +1 -1
  98. package/docs/md/interfaces/RemoteApiRequest.md +1 -1
  99. package/docs/md/interfaces/RemoteApiResponse.md +1 -1
  100. package/docs/md/interfaces/RemoteApiService.md +1 -1
  101. package/docs/md/interfaces/Snapcode.md +1 -1
  102. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  103. package/docs/md/interfaces/UriRequest.md +1 -1
  104. package/docs/md/interfaces/UriResponse.md +1 -1
  105. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  106. package/docs/md/modules.md +24 -4
  107. package/lib/CameraKit.d.ts +139 -7
  108. package/lib/CameraKit.js +19 -19
  109. package/lib/CameraKit.js.map +1 -1
  110. package/lib/__tests__/data.d.ts +9 -4
  111. package/lib/__tests__/data.js +19 -9
  112. package/lib/__tests__/data.js.map +1 -1
  113. package/lib/bootstrapCameraKit.js +2 -2
  114. package/lib/bootstrapCameraKit.js.map +1 -1
  115. package/lib/common/localization.js +7 -31
  116. package/lib/common/localization.js.map +1 -1
  117. package/lib/configuration.d.ts +7 -0
  118. package/lib/configuration.js +1 -0
  119. package/lib/configuration.js.map +1 -1
  120. package/lib/configurationOverrides.d.ts +2 -2
  121. package/lib/configurationOverrides.js +11 -6
  122. package/lib/configurationOverrides.js.map +1 -1
  123. package/lib/dependency-injection/RootServices.d.ts +2 -2
  124. package/lib/dependency-injection/RootServices.js.map +1 -1
  125. package/lib/environment.json +1 -1
  126. package/lib/extensions/extensionRequestContext.js +4 -4
  127. package/lib/extensions/extensionRequestContext.js.map +1 -1
  128. package/lib/extensions/uriHandlersRegister.d.ts +2 -2
  129. package/lib/extensions/uriHandlersRegister.js.map +1 -1
  130. package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +272 -0
  131. package/lib/generated-proto/blizzard/cameraKitEvents.js +38 -24
  132. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
  133. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +2 -2
  134. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -1
  135. package/lib/index.d.ts +2 -1
  136. package/lib/index.js +2 -1
  137. package/lib/index.js.map +1 -1
  138. package/lib/lens/Lens.d.ts +9 -1
  139. package/lib/lens/Lens.js +2 -1
  140. package/lib/lens/Lens.js.map +1 -1
  141. package/lib/lens/LensPersistenceStore.d.ts +2 -2
  142. package/lib/lens/LensPersistenceStore.js.map +1 -1
  143. package/lib/lens/LensRepository.d.ts +2 -2
  144. package/lib/lens/LensRepository.js +5 -4
  145. package/lib/lens/LensRepository.js.map +1 -1
  146. package/lib/lens/assets/LensAssetRepository.d.ts +4 -4
  147. package/lib/lens/assets/LensAssetRepository.js +1 -3
  148. package/lib/lens/assets/LensAssetRepository.js.map +1 -1
  149. package/lib/lens/assets/LensAssetsProvider.d.ts +9 -3
  150. package/lib/lens/assets/LensAssetsProvider.js +12 -5
  151. package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
  152. package/lib/lens-client-interface/imagePicker.d.ts +2 -2
  153. package/lib/lens-client-interface/imagePicker.js.map +1 -1
  154. package/lib/lens-client-interface/lensClientInterface.d.ts +2 -2
  155. package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
  156. package/lib/lens-core-module/generated-types.d.ts +4 -2
  157. package/lib/lens-core-module/generated-types.js.map +1 -1
  158. package/lib/lens-core-module/index.d.ts +1 -0
  159. package/lib/lens-core-module/index.js +1 -0
  160. package/lib/lens-core-module/index.js.map +1 -1
  161. package/lib/lens-core-module/lensCore.d.ts +41 -0
  162. package/lib/lens-core-module/lensCore.js +54 -0
  163. package/lib/lens-core-module/lensCore.js.map +1 -0
  164. package/lib/lens-core-module/lensCoreError.d.ts +15 -0
  165. package/lib/lens-core-module/lensCoreError.js +43 -0
  166. package/lib/lens-core-module/lensCoreError.js.map +1 -0
  167. package/lib/lens-core-module/loader/lensCoreFactory.d.ts +1 -2
  168. package/lib/lens-core-module/loader/lensCoreFactory.js +24 -26
  169. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
  170. package/lib/lensCoreWasmVersions.json +3 -3
  171. package/lib/logger/registerLogEntriesSubscriber.js +2 -2
  172. package/lib/logger/registerLogEntriesSubscriber.js.map +1 -1
  173. package/lib/media-sources/CameraKitSource.d.ts +3 -3
  174. package/lib/media-sources/CameraKitSource.js +22 -31
  175. package/lib/media-sources/CameraKitSource.js.map +1 -1
  176. package/lib/media-sources/FunctionSource.js +33 -36
  177. package/lib/media-sources/FunctionSource.js.map +1 -1
  178. package/lib/media-sources/MediaStreamSource.js +11 -15
  179. package/lib/media-sources/MediaStreamSource.js.map +1 -1
  180. package/lib/metrics/businessEventsReporter.js +114 -108
  181. package/lib/metrics/businessEventsReporter.js.map +1 -1
  182. package/lib/metrics/reporters/reportGlobalException.js +25 -7
  183. package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
  184. package/lib/metrics/reporters/reportHttpMetrics.js +2 -2
  185. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
  186. package/lib/metrics/reporters/reportLensView.js +5 -3
  187. package/lib/metrics/reporters/reportLensView.js.map +1 -1
  188. package/lib/metrics/reporters/reportLensWait.js +8 -2
  189. package/lib/metrics/reporters/reportLensWait.js.map +1 -1
  190. package/lib/metrics/reporters/reportPlatformCapabilities.d.ts +12 -0
  191. package/lib/metrics/reporters/reportPlatformCapabilities.js +18 -0
  192. package/lib/metrics/reporters/reportPlatformCapabilities.js.map +1 -0
  193. package/lib/metrics/reporters/reporters.d.ts +2 -1
  194. package/lib/metrics/reporters/reporters.js +3 -1
  195. package/lib/metrics/reporters/reporters.js.map +1 -1
  196. package/lib/namedErrors.d.ts +17 -0
  197. package/lib/namedErrors.js +2 -0
  198. package/lib/namedErrors.js.map +1 -1
  199. package/lib/platform/assertPlatformSupported.d.ts +4 -0
  200. package/lib/platform/assertPlatformSupported.js +15 -0
  201. package/lib/platform/assertPlatformSupported.js.map +1 -0
  202. package/lib/platform/cameraKitUserAgent.d.ts +2 -0
  203. package/lib/platform/cameraKitUserAgent.js +20 -0
  204. package/lib/platform/cameraKitUserAgent.js.map +1 -0
  205. package/lib/platform/platformCapabilities.d.ts +50 -0
  206. package/lib/platform/platformCapabilities.js +121 -0
  207. package/lib/platform/platformCapabilities.js.map +1 -0
  208. package/lib/{common/cameraKitUserAgent.d.ts → platform/platformInfo.d.ts} +13 -10
  209. package/lib/{common/cameraKitUserAgent.js → platform/platformInfo.js} +94 -100
  210. package/lib/platform/platformInfo.js.map +1 -0
  211. package/lib/remote-configuration/cofHandler.js +2 -2
  212. package/lib/remote-configuration/cofHandler.js.map +1 -1
  213. package/lib/remote-configuration/preloadConfiguration.d.ts +2 -2
  214. package/lib/remote-configuration/preloadConfiguration.js.map +1 -1
  215. package/lib/session/CameraKitSession.d.ts +3 -3
  216. package/lib/session/CameraKitSession.js +23 -30
  217. package/lib/session/CameraKitSession.js.map +1 -1
  218. package/lib/session/CameraKitSessionEvents.d.ts +7 -3
  219. package/lib/session/CameraKitSessionEvents.js +17 -0
  220. package/lib/session/CameraKitSessionEvents.js.map +1 -1
  221. package/lib/session/LensPerformanceMetrics.d.ts +2 -2
  222. package/lib/session/LensPerformanceMetrics.js +4 -3
  223. package/lib/session/LensPerformanceMetrics.js.map +1 -1
  224. package/lib/session/lensState.d.ts +2 -2
  225. package/lib/session/lensState.js +36 -37
  226. package/lib/session/lensState.js.map +1 -1
  227. package/package.json +2 -2
  228. package/lib/assertPlatformSupported.d.ts +0 -6
  229. package/lib/assertPlatformSupported.js +0 -21
  230. package/lib/assertPlatformSupported.js.map +0 -1
  231. package/lib/common/cameraKitUserAgent.js.map +0 -1
  232. package/lib/common/locale.d.ts +0 -2
  233. package/lib/common/locale.js +0 -11
  234. package/lib/common/locale.js.map +0 -1
@@ -1,6 +1,5 @@
1
1
  import { defineAction, defineActions, defineState, defineStates, dispatch, forActions, inStates, StateMachine, } from "@snap/state-management";
2
2
  import { catchError, exhaustMap, from, map, merge, mergeMap, Observable, of, switchMap, take, takeUntil, tap, } from "rxjs";
3
- import { ensureError } from "../common/errorHelpers";
4
3
  import { Injectable } from "../dependency-injection/Injectable";
5
4
  import { lensRepositoryFactory } from "../lens/LensRepository";
6
5
  import { lensCoreFactory } from "../lens-core-module";
@@ -121,7 +120,8 @@ export const lensStateFactory = Injectable("lensState", [
121
120
  // replaceLenses has the property that if it fails, LensCore guarantees that no
122
121
  // lenses are active – so we can safely dispatch applyLensFailed and transition
123
122
  // to noLensApplied state.
124
- lensCore.replaceLenses({
123
+ lensCore
124
+ .replaceLenses({
125
125
  lenses: [
126
126
  Object.assign(Object.assign({}, lensInput), { onTurnOn: () => dispatch("turnedOn"), onResourcesLoaded: () => dispatch("resourcesLoaded"),
127
127
  // onFirstFrameProcessed marks the end of the lens application for
@@ -135,31 +135,30 @@ export const lensStateFactory = Injectable("lensState", [
135
135
  dispatch("firstFrameProcessed");
136
136
  }, onTurnOff: () => dispatch("turnedOff") }),
137
137
  ],
138
- onSuccess: () => {
139
- coreTimer.measure("success");
140
- // We emit applyLensComplete (and applyLensFailed, below) on an
141
- // Observable, which is piped to `dispatch` this allows `switchMap` to
142
- // properly cancel the dispatch of these actions if a new applyLens
143
- // arrives while we're waiting for onSuccess/onFailure.
144
- //
145
- // That's desirable behavior, because we don't want the applyingLens
146
- // state due to a *subsequent applyLens action* to be transitioned to
147
- // lensApplied by this action.
148
- subscriber.next(lensState.actions.applyLensComplete(lens));
149
- subscriber.complete();
150
- },
151
- onFailure: (reason) => {
152
- coreTimer.measure("failure");
153
- applyTimer.measure("failure");
154
- applyTimer.stopAndReport(operationalMetricsReporter);
155
- const lensCoreError = ensureError(reason);
156
- const message = `Failed to apply lens ${lensInput.lensId}.`;
157
- const error = /validation failed/.test(lensCoreError.message)
158
- ? lensContentValidationError(message, lensCoreError)
159
- : lensError(message, lensCoreError);
160
- subscriber.next(lensState.actions.applyLensFailed({ error, lens }));
161
- subscriber.complete();
162
- },
138
+ })
139
+ .then(() => {
140
+ coreTimer.measure("success");
141
+ // We emit applyLensComplete (and applyLensFailed, below) on an
142
+ // Observable, which is piped to `dispatch` this allows `switchMap` to
143
+ // properly cancel the dispatch of these actions if a new applyLens
144
+ // arrives while we're waiting for onSuccess/onFailure.
145
+ //
146
+ // That's desirable behavior, because we don't want the applyingLens
147
+ // state due to a *subsequent applyLens action* to be transitioned to
148
+ // lensApplied by this action.
149
+ subscriber.next(lensState.actions.applyLensComplete(lens));
150
+ subscriber.complete();
151
+ })
152
+ .catch((lensCoreError) => {
153
+ coreTimer.measure("failure");
154
+ applyTimer.measure("failure");
155
+ applyTimer.stopAndReport(operationalMetricsReporter);
156
+ const message = `Failed to apply lens ${lensInput.lensId}.`;
157
+ const error = /validation failed/.test(lensCoreError.message)
158
+ ? lensContentValidationError(message, lensCoreError)
159
+ : lensError(message, lensCoreError);
160
+ subscriber.next(lensState.actions.applyLensFailed({ error, lens }));
161
+ subscriber.complete();
163
162
  });
164
163
  })), catchError((error) => {
165
164
  applyTimer.measure("failure");
@@ -182,16 +181,16 @@ export const lensStateFactory = Injectable("lensState", [
182
181
  */
183
182
  lensState.events
184
183
  .pipe(inStates("lensApplied", "noLensApplied"), forActions("removeLens"), mergeMap(() => new Observable((subscriber) => {
185
- lensCore.clearAllLenses({
186
- onSuccess: () => {
187
- subscriber.next(lensState.actions.removeLensComplete());
188
- subscriber.complete();
189
- },
190
- onFailure: (lensCoreError) => {
191
- const error = new Error("Failed to remove lenses.", { cause: lensCoreError });
192
- subscriber.next(lensState.actions.removeLensFailed(error));
193
- subscriber.complete();
194
- },
184
+ lensCore
185
+ .clearAllLenses()
186
+ .then(() => {
187
+ subscriber.next(lensState.actions.removeLensComplete());
188
+ subscriber.complete();
189
+ })
190
+ .catch((lensCoreError) => {
191
+ const error = new Error("Failed to remove lenses.", { cause: lensCoreError });
192
+ subscriber.next(lensState.actions.removeLensFailed(error));
193
+ subscriber.complete();
195
194
  });
196
195
  })), dispatch(lensState))
197
196
  .subscribe({
@@ -1 +1 @@
1
- {"version":3,"file":"lensState.js","sourceRoot":"","sources":["../../src/session/lensState.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,YAAY,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,UAAU,EACV,UAAU,EACV,IAAI,EACJ,GAAG,EACH,KAAK,EACL,QAAQ,EACR,UAAU,E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,CAAC,SAAS,CAAC,CACtB;SACA,SAAS,CAAC;QACP,KAAK,EAAE,MAAM,CAAC,KAAK;KACtB,CAAC,CAAC;IAEP,SAAS,CAAC,MAAM;SACX,IAAI,CACD,QAAQ,CAAC,cAAc,CAAC,EACxB,UAAU,CAAC,YAAY,CAAC,EACxB,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CACd,SAAS,CAAC,MAAM,CAAC,IAAI;IACjB,qDAAqD;IACrD,QAAQ,CAAC,aAAa,CAAC;IACvB,6FAA6F;IAC7F,oFAAoF;IACpF,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,EACzD,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CACf,CACJ,EACD,QAAQ,CAAC,SAAS,CAAC,CACtB;SACA,SAAS,CAAC;QACP,KAAK,EAAE,MAAM,CAAC,KAAK;KACtB,CAAC,CAAC;IAEP,kBAAkB;IAClB,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAEhG,OAAO,SAAS,CAAC;AACrB,CAAC,CACJ,CAAC","sourcesContent":["import {\n Actions,\n defineAction,\n defineActions,\n defineState,\n defineStates,\n dispatch,\n forActions,\n inStates,\n StateMachine,\n} from \"@snap/state-management\";\nimport {\n catchError,\n exhaustMap,\n from,\n map,\n merge,\n mergeMap,\n Observable,\n of,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { ensureError } from \"../common/errorHelpers\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { Lens } from \"../lens/Lens\";\nimport { LensRepository, lensRepositoryFactory } from \"../lens/LensRepository\";\nimport { lensCoreFactory, LensCoreModule } from \"../lens-core-module\";\nimport { AddLensInput } from \"../lens-core-module/generated-types\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { lensPersistenceStoreFactory } from \"../lens/LensPersistenceStore\";\nimport { createLaunchData, LensLaunchParams } from \"../lens/LensLaunchParams\";\nimport { LegalState, legalStateFactory } from \"../legal/legalState\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"../lens/assets/LensAssetRepository\";\nimport {\n legalError,\n LegalError,\n lensContentValidationError,\n LensContentValidationError,\n lensError,\n LensError,\n} from \"../namedErrors\";\nimport { getLogger } from \"../logger/logger\";\nimport { Timer } from \"../metrics/operational/Timer\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../metrics/operational/operationalMetricsReporter\";\nimport { unsubscribed } from \"../observable-operators/unsubscribed\";\n\nconst logger = getLogger(\"LensState\");\n\nconst createLensState = () => {\n const actions = defineActions(\n defineAction(\"applyLens\")<{ lens: Lens; launchParams?: LensLaunchParams }>(),\n defineAction(\"downloadComplete\")<Lens>(),\n defineAction(\"turnedOn\")<Lens>(),\n defineAction(\"resourcesLoaded\")<Lens>(),\n defineAction(\"firstFrameProcessed\")<Lens>(),\n defineAction(\"applyLensComplete\")<Lens>(),\n defineAction(\"applyLensFailed\")<{ error: LensErrors; lens: Lens }>(),\n defineAction(\"applyLensAborted\")<Lens>(),\n\n defineAction(\"removeLens\")(),\n defineAction(\"turnedOff\")<Lens>(),\n defineAction(\"removeLensComplete\")(),\n defineAction(\"removeLensFailed\")<Error>()\n );\n\n const states = defineStates(\n defineState(\"noLensApplied\")(),\n defineState(\"applyingLens\")<Lens>(),\n defineState(\"lensApplied\")<Lens>()\n );\n\n return new StateMachine(actions, states, states.noLensApplied(), (events) =>\n merge(\n events.pipe(\n // We allow a new lens to be applied at any time, no matter the state.\n inStates(\"noLensApplied\", \"applyingLens\", \"lensApplied\"),\n forActions(\"applyLens\"),\n map(([a]) => states.applyingLens(a.data.lens))\n ),\n events.pipe(\n inStates(\"applyingLens\"),\n forActions(\"applyLensComplete\"),\n map(([a]) => states.lensApplied(a.data))\n ),\n events.pipe(\n inStates(\"applyingLens\"),\n forActions(\"applyLensFailed\"),\n map(() => states.noLensApplied())\n ),\n events.pipe(\n inStates(\"lensApplied\"),\n forActions(\"removeLensComplete\"),\n map(() => states.noLensApplied())\n )\n )\n );\n};\n\nexport type LensErrors = LegalError | LensContentValidationError | LensError;\n\nexport type LensState = ReturnType<typeof createLensState>;\n\nexport const lensStateFactory = Injectable(\n \"lensState\",\n [\n lensCoreFactory.token,\n lensRepositoryFactory.token,\n lensAssetRepositoryFactory.token,\n lensPersistenceStoreFactory.token,\n legalStateFactory.token,\n operationalMetricReporterFactory.token,\n ] as const,\n (\n lensCore: LensCoreModule,\n lensRepository: LensRepository,\n lensAssetRepository: LensAssetRepository,\n lensPersistence: IndexedDBPersistence<ArrayBuffer>,\n legalState: LegalState,\n operationalMetricsReporter: OperationalMetricsReporter\n ): LensState => {\n const lensState = createLensState();\n let firstLensApply = true;\n\n /**\n * Apply lens\n */\n lensState.events\n .pipe(\n forActions(\"applyLens\"),\n\n // Determine the legal state (e.g. terms have been accepted). Using exhaustMap means while we are\n // ascertaining legal status (which may include prompting the end user to accept terms), we will ignore\n // any new applyLens actions.\n exhaustMap(([a]) =>\n of(legalState.actions.requestLegalPrompt()).pipe(\n dispatch(legalState),\n inStates(\"accepted\", \"rejected\"),\n take(1),\n map(([, { name }]) => {\n if (name === \"accepted\") return a;\n return lensState.actions.applyLensFailed({\n error: legalError(\n `Failed to apply lens ${a.data.lens.id}. Required legal terms were not accepted.`\n ),\n lens: a.data.lens,\n });\n })\n )\n ),\n\n // The use of switchMap is important so that if we get a new applyLens action while we're still\n // downloading lens content for a previously-requested lens, we can cancel those requests and ensure\n // that lenses are applied in the order they're requested.\n switchMap((a) => {\n if (a.name === \"applyLensFailed\") return of(a);\n\n const { lens } = a.data;\n // Convenience method making dispatching an action with Lens data less verbose.\n const dispatch = (action: Extract<Actions<LensState>, { data: Lens }>[\"name\"]) => {\n lensState.dispatch(action, lens);\n };\n\n // We record if this was the first lens apply for this page load, since there may be additional\n // sources of latency (e.g. remote configuration that needs to be loaded) on the first apply that\n // are not present for subsequent applies.\n const applyTimer = new Timer(\"lens\").mark(\"apply\", { first: `${firstLensApply}` });\n firstLensApply = false;\n\n return of(a.data).pipe(\n mergeMap(({ lens, launchParams }) =>\n // If retrieval throws an error, we still want to proceed with the lens\n // because persisted data is not a necessity.\n from(lensPersistence.retrieve(lens.id).catch(() => undefined)).pipe(\n map((persistentStore) => ({ lens, launchParams, persistentStore }))\n )\n ),\n\n map(({ lens, launchParams, persistentStore }) => {\n const launchData = createLaunchData({\n launchParams,\n persistentStore,\n });\n\n const lensDetails = lensRepository.getLensMetadata(lens.id);\n if (!lensDetails) {\n throw new Error(\n `Cannot apply lens ${lens.id}. It has not been loaded by the Lens ` +\n `repository. Use CameraKit.lensRepository.loadLens (or loadLensGroups) ` +\n `to load lens metadata before calling CameraKitSession.applyLens.`\n );\n }\n\n const { content } = lensDetails;\n if (!content) {\n throw new Error(\n `Cannot apply lens ${lens.id}. Metadata retrieved for this lens does not ` +\n `include the lens content URL.`\n );\n }\n\n return { lens, launchData, content };\n }),\n\n // Load lens assets and the lens itself in parallel. Both count toward lens download time.\n // TODO: use RxJS fetch utilities so that these requests can be cancelled on unsubscribe.\n mergeMap(({ lens, launchData, content }) => {\n const networkTimer = applyTimer.mark(\"network\");\n\n return from(\n Promise.all([\n lensRepository.getLensContent(lens).finally(() => networkTimer.measure(\"lens\")),\n content.assetManifest.length > 0\n ? lensAssetRepository\n .cacheAssets(content.assetManifest, lens)\n .finally(() => networkTimer.measure(\"assets\"))\n : Promise.resolve(),\n ])\n ).pipe(\n tap(() => {\n networkTimer.measure();\n lensState.dispatch(\"downloadComplete\", lens);\n }),\n map(([{ lensBuffer, lensChecksum }]): AddLensInput => {\n // NOTE: cached array buffer has to be copied each time in order to be reused,\n // otherwise the original cached copy would be detached by LensCore\n // One optimization can be done here: do not copy the array if getLensContent()\n // returned uncached buffer\n const lensDataBuffer = lensBuffer.slice(0);\n // LensCore chokes trying if launchData is set to undefined; we must omit it.\n return launchData === undefined\n ? { lensId: lens.id, lensDataBuffer, lensChecksum }\n : { lensId: lens.id, lensDataBuffer, lensChecksum, launchData };\n })\n );\n }),\n\n // If removeLens is dispatched while downloading, cancel download, don't apply the lens.\n takeUntil(lensState.events.pipe(forActions(\"removeLens\"))),\n\n // Once the lens has downloaded, we can call replaceLenses. We're not concerned about\n // waiting for prior in-progress calls to replaceLenses to complete, because LensCore\n // guarantees that calls to replaceLenses will always be processed sequentially in the order\n // they are received.\n mergeMap(\n (lensInput) =>\n new Observable<Actions<LensState>>((subscriber) => {\n const coreTimer = applyTimer.mark(\"core\");\n\n // replaceLenses has the property that if it fails, LensCore guarantees that no\n // lenses are active – so we can safely dispatch applyLensFailed and transition\n // to noLensApplied state.\n lensCore.replaceLenses({\n lenses: [\n {\n ...lensInput,\n onTurnOn: () => dispatch(\"turnedOn\"),\n onResourcesLoaded: () => dispatch(\"resourcesLoaded\"),\n\n // onFirstFrameProcessed marks the end of the lens application for\n // the end-user -- this is when they see the newly applied lens\n // begin to render. As such, this is where we stop our overall\n // latency measurement and report latency metrics.\n onFirstFrameProcessed: () => {\n coreTimer.measure(\"first-frame\");\n applyTimer.measure(\"success\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n dispatch(\"firstFrameProcessed\");\n },\n onTurnOff: () => dispatch(\"turnedOff\"),\n },\n ],\n onSuccess: () => {\n coreTimer.measure(\"success\");\n\n // We emit applyLensComplete (and applyLensFailed, below) on an\n // Observable, which is piped to `dispatch` – this allows `switchMap` to\n // properly cancel the dispatch of these actions if a new applyLens\n // arrives while we're waiting for onSuccess/onFailure.\n //\n // That's desirable behavior, because we don't want the applyingLens\n // state due to a *subsequent applyLens action* to be transitioned to\n // lensApplied by this action.\n subscriber.next(lensState.actions.applyLensComplete(lens));\n subscriber.complete();\n },\n onFailure: (reason) => {\n coreTimer.measure(\"failure\");\n applyTimer.measure(\"failure\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n\n const lensCoreError = ensureError(reason);\n const message = `Failed to apply lens ${lensInput.lensId}.`;\n const error = /validation failed/.test(lensCoreError.message)\n ? lensContentValidationError(message, lensCoreError)\n : lensError(message, lensCoreError);\n\n subscriber.next(lensState.actions.applyLensFailed({ error, lens }));\n subscriber.complete();\n },\n });\n })\n ),\n catchError((error: LensErrors) => {\n applyTimer.measure(\"failure\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n return of(lensState.actions.applyLensFailed({ error, lens }));\n }),\n\n // If a new applyLens is received, `switchMap` will unsubscribe from this inner observable,\n // which stops the current lens application. When this happens we can record a separate metric\n // to measure aborted lens applications.\n unsubscribed(() => {\n applyTimer.measure(\"abort\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n })\n );\n }),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n /**\n * Remove lens\n */\n lensState.events\n .pipe(\n inStates(\"lensApplied\", \"noLensApplied\"),\n forActions(\"removeLens\"),\n mergeMap(\n () =>\n new Observable<Actions<LensState>>((subscriber) => {\n lensCore.clearAllLenses({\n onSuccess: () => {\n subscriber.next(lensState.actions.removeLensComplete());\n subscriber.complete();\n },\n onFailure: (lensCoreError: unknown) => {\n const error = new Error(\"Failed to remove lenses.\", { cause: lensCoreError });\n subscriber.next(lensState.actions.removeLensFailed(error));\n subscriber.complete();\n },\n });\n })\n ),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n lensState.events\n .pipe(\n inStates(\"applyingLens\"),\n forActions(\"removeLens\"),\n switchMap(([a]) =>\n lensState.events.pipe(\n // Wait to remove the lens until it has been applied.\n inStates(\"lensApplied\"),\n // But cancel the removal if a new applyLens supercedes the current lens. The goal here is to\n // make sure the latest apply/remove pre-empts any previous request to apply/remove.\n takeUntil(lensState.events.pipe(forActions(\"applyLens\"))),\n map(() => a)\n )\n ),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n // Log transitions\n lensState.events.subscribe(([a, s]) => logger.debug(`Action: \"${a.name}\", state: \"${s.name}\"`));\n\n return lensState;\n }\n);\n"]}
1
+ {"version":3,"file":"lensState.js","sourceRoot":"","sources":["../../src/session/lensState.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,YAAY,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,UAAU,EACV,UAAU,EACV,IAAI,EACJ,GAAG,EACH,KAAK,EACL,QAAQ,EACR,UAAU,EACV,EAAE,EACF,SAAS,EACT,IAAI,EACJ,SAAS,EACT,GAAG,GACN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE,OAAO,EAAkB,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAY,MAAM,qBAAqB,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAoB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAuB,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AACrG,OAAO,EACH,UAAU,EAEV,0BAA0B,EAE1B,SAAS,GAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EACH,gCAAgC,GAEnC,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;AAEtC,MAAM,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ates,\n dispatch,\n forActions,\n inStates,\n StateMachine,\n} from \"@snap/state-management\";\nimport {\n catchError,\n exhaustMap,\n from,\n map,\n merge,\n mergeMap,\n Observable,\n of,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { Lens } from \"../lens/Lens\";\nimport { LensRepository, lensRepositoryFactory } from \"../lens/LensRepository\";\nimport { lensCoreFactory, LensCore } from \"../lens-core-module\";\nimport { AddLensInput } from \"../lens-core-module/generated-types\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { lensPersistenceStoreFactory } from \"../lens/LensPersistenceStore\";\nimport { createLaunchData, LensLaunchParams } from \"../lens/LensLaunchParams\";\nimport { LegalState, legalStateFactory } from \"../legal/legalState\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"../lens/assets/LensAssetRepository\";\nimport {\n legalError,\n LegalError,\n lensContentValidationError,\n LensContentValidationError,\n lensError,\n LensError,\n} from \"../namedErrors\";\nimport { getLogger } from \"../logger/logger\";\nimport { Timer } from \"../metrics/operational/Timer\";\nimport {\n operationalMetricReporterFactory,\n OperationalMetricsReporter,\n} from \"../metrics/operational/operationalMetricsReporter\";\nimport { unsubscribed } from \"../observable-operators/unsubscribed\";\n\nconst logger = getLogger(\"LensState\");\n\nconst createLensState = () => {\n const actions = defineActions(\n defineAction(\"applyLens\")<{ lens: Lens; launchParams?: LensLaunchParams }>(),\n defineAction(\"downloadComplete\")<Lens>(),\n defineAction(\"turnedOn\")<Lens>(),\n defineAction(\"resourcesLoaded\")<Lens>(),\n defineAction(\"firstFrameProcessed\")<Lens>(),\n defineAction(\"applyLensComplete\")<Lens>(),\n defineAction(\"applyLensFailed\")<{ error: LensErrors; lens: Lens }>(),\n defineAction(\"applyLensAborted\")<Lens>(),\n\n defineAction(\"removeLens\")(),\n defineAction(\"turnedOff\")<Lens>(),\n defineAction(\"removeLensComplete\")(),\n defineAction(\"removeLensFailed\")<Error>()\n );\n\n const states = defineStates(\n defineState(\"noLensApplied\")(),\n defineState(\"applyingLens\")<Lens>(),\n defineState(\"lensApplied\")<Lens>()\n );\n\n return new StateMachine(actions, states, states.noLensApplied(), (events) =>\n merge(\n events.pipe(\n // We allow a new lens to be applied at any time, no matter the state.\n inStates(\"noLensApplied\", \"applyingLens\", \"lensApplied\"),\n forActions(\"applyLens\"),\n map(([a]) => states.applyingLens(a.data.lens))\n ),\n events.pipe(\n inStates(\"applyingLens\"),\n forActions(\"applyLensComplete\"),\n map(([a]) => states.lensApplied(a.data))\n ),\n events.pipe(\n inStates(\"applyingLens\"),\n forActions(\"applyLensFailed\"),\n map(() => states.noLensApplied())\n ),\n events.pipe(\n inStates(\"lensApplied\"),\n forActions(\"removeLensComplete\"),\n map(() => states.noLensApplied())\n )\n )\n );\n};\n\nexport type LensErrors = LegalError | LensContentValidationError | LensError;\n\nexport type LensState = ReturnType<typeof createLensState>;\n\nexport const lensStateFactory = Injectable(\n \"lensState\",\n [\n lensCoreFactory.token,\n lensRepositoryFactory.token,\n lensAssetRepositoryFactory.token,\n lensPersistenceStoreFactory.token,\n legalStateFactory.token,\n operationalMetricReporterFactory.token,\n ] as const,\n (\n lensCore: LensCore,\n lensRepository: LensRepository,\n lensAssetRepository: LensAssetRepository,\n lensPersistence: IndexedDBPersistence<ArrayBuffer>,\n legalState: LegalState,\n operationalMetricsReporter: OperationalMetricsReporter\n ): LensState => {\n const lensState = createLensState();\n let firstLensApply = true;\n\n /**\n * Apply lens\n */\n lensState.events\n .pipe(\n forActions(\"applyLens\"),\n\n // Determine the legal state (e.g. terms have been accepted). Using exhaustMap means while we are\n // ascertaining legal status (which may include prompting the end user to accept terms), we will ignore\n // any new applyLens actions.\n exhaustMap(([a]) =>\n of(legalState.actions.requestLegalPrompt()).pipe(\n dispatch(legalState),\n inStates(\"accepted\", \"rejected\"),\n take(1),\n map(([, { name }]) => {\n if (name === \"accepted\") return a;\n return lensState.actions.applyLensFailed({\n error: legalError(\n `Failed to apply lens ${a.data.lens.id}. Required legal terms were not accepted.`\n ),\n lens: a.data.lens,\n });\n })\n )\n ),\n\n // The use of switchMap is important so that if we get a new applyLens action while we're still\n // downloading lens content for a previously-requested lens, we can cancel those requests and ensure\n // that lenses are applied in the order they're requested.\n switchMap((a) => {\n if (a.name === \"applyLensFailed\") return of(a);\n\n const { lens } = a.data;\n // Convenience method making dispatching an action with Lens data less verbose.\n const dispatch = (action: Extract<Actions<LensState>, { data: Lens }>[\"name\"]) => {\n lensState.dispatch(action, lens);\n };\n\n // We record if this was the first lens apply for this page load, since there may be additional\n // sources of latency (e.g. remote configuration that needs to be loaded) on the first apply that\n // are not present for subsequent applies.\n const applyTimer = new Timer(\"lens\").mark(\"apply\", { first: `${firstLensApply}` });\n firstLensApply = false;\n\n return of(a.data).pipe(\n mergeMap(({ lens, launchParams }) =>\n // If retrieval throws an error, we still want to proceed with the lens\n // because persisted data is not a necessity.\n from(lensPersistence.retrieve(lens.id).catch(() => undefined)).pipe(\n map((persistentStore) => ({ lens, launchParams, persistentStore }))\n )\n ),\n\n map(({ lens, launchParams, persistentStore }) => {\n const launchData = createLaunchData({\n launchParams,\n persistentStore,\n });\n\n const lensDetails = lensRepository.getLensMetadata(lens.id);\n if (!lensDetails) {\n throw new Error(\n `Cannot apply lens ${lens.id}. It has not been loaded by the Lens ` +\n `repository. Use CameraKit.lensRepository.loadLens (or loadLensGroups) ` +\n `to load lens metadata before calling CameraKitSession.applyLens.`\n );\n }\n\n const { content } = lensDetails;\n if (!content) {\n throw new Error(\n `Cannot apply lens ${lens.id}. Metadata retrieved for this lens does not ` +\n `include the lens content URL.`\n );\n }\n\n return { lens, launchData, content };\n }),\n\n // Load lens assets and the lens itself in parallel. Both count toward lens download time.\n // TODO: use RxJS fetch utilities so that these requests can be cancelled on unsubscribe.\n mergeMap(({ lens, launchData, content }) => {\n const networkTimer = applyTimer.mark(\"network\");\n\n return from(\n Promise.all([\n lensRepository.getLensContent(lens).finally(() => networkTimer.measure(\"lens\")),\n content.assetManifest.length > 0\n ? lensAssetRepository\n .cacheAssets(content.assetManifest, lens)\n .finally(() => networkTimer.measure(\"assets\"))\n : Promise.resolve(),\n ])\n ).pipe(\n tap(() => {\n networkTimer.measure();\n lensState.dispatch(\"downloadComplete\", lens);\n }),\n map(([{ lensBuffer, lensChecksum }]): AddLensInput => {\n // NOTE: cached array buffer has to be copied each time in order to be reused,\n // otherwise the original cached copy would be detached by LensCore\n // One optimization can be done here: do not copy the array if getLensContent()\n // returned uncached buffer\n const lensDataBuffer = lensBuffer.slice(0);\n // LensCore chokes trying if launchData is set to undefined; we must omit it.\n return launchData === undefined\n ? { lensId: lens.id, lensDataBuffer, lensChecksum }\n : { lensId: lens.id, lensDataBuffer, lensChecksum, launchData };\n })\n );\n }),\n\n // If removeLens is dispatched while downloading, cancel download, don't apply the lens.\n takeUntil(lensState.events.pipe(forActions(\"removeLens\"))),\n\n // Once the lens has downloaded, we can call replaceLenses. We're not concerned about\n // waiting for prior in-progress calls to replaceLenses to complete, because LensCore\n // guarantees that calls to replaceLenses will always be processed sequentially in the order\n // they are received.\n mergeMap(\n (lensInput) =>\n new Observable<Actions<LensState>>((subscriber) => {\n const coreTimer = applyTimer.mark(\"core\");\n\n // replaceLenses has the property that if it fails, LensCore guarantees that no\n // lenses are active – so we can safely dispatch applyLensFailed and transition\n // to noLensApplied state.\n lensCore\n .replaceLenses({\n lenses: [\n {\n ...lensInput,\n onTurnOn: () => dispatch(\"turnedOn\"),\n onResourcesLoaded: () => dispatch(\"resourcesLoaded\"),\n\n // onFirstFrameProcessed marks the end of the lens application for\n // the end-user -- this is when they see the newly applied lens\n // begin to render. As such, this is where we stop our overall\n // latency measurement and report latency metrics.\n onFirstFrameProcessed: () => {\n coreTimer.measure(\"first-frame\");\n applyTimer.measure(\"success\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n dispatch(\"firstFrameProcessed\");\n },\n onTurnOff: () => dispatch(\"turnedOff\"),\n },\n ],\n })\n .then(() => {\n coreTimer.measure(\"success\");\n\n // We emit applyLensComplete (and applyLensFailed, below) on an\n // Observable, which is piped to `dispatch` – this allows `switchMap` to\n // properly cancel the dispatch of these actions if a new applyLens\n // arrives while we're waiting for onSuccess/onFailure.\n //\n // That's desirable behavior, because we don't want the applyingLens\n // state due to a *subsequent applyLens action* to be transitioned to\n // lensApplied by this action.\n subscriber.next(lensState.actions.applyLensComplete(lens));\n subscriber.complete();\n })\n .catch((lensCoreError) => {\n coreTimer.measure(\"failure\");\n applyTimer.measure(\"failure\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n\n const message = `Failed to apply lens ${lensInput.lensId}.`;\n const error = /validation failed/.test(lensCoreError.message)\n ? lensContentValidationError(message, lensCoreError)\n : lensError(message, lensCoreError);\n\n subscriber.next(lensState.actions.applyLensFailed({ error, lens }));\n subscriber.complete();\n });\n })\n ),\n catchError((error: LensErrors) => {\n applyTimer.measure(\"failure\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n return of(lensState.actions.applyLensFailed({ error, lens }));\n }),\n\n // If a new applyLens is received, `switchMap` will unsubscribe from this inner observable,\n // which stops the current lens application. When this happens we can record a separate metric\n // to measure aborted lens applications.\n unsubscribed(() => {\n applyTimer.measure(\"abort\");\n applyTimer.stopAndReport(operationalMetricsReporter);\n })\n );\n }),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n /**\n * Remove lens\n */\n lensState.events\n .pipe(\n inStates(\"lensApplied\", \"noLensApplied\"),\n forActions(\"removeLens\"),\n mergeMap(\n () =>\n new Observable<Actions<LensState>>((subscriber) => {\n lensCore\n .clearAllLenses()\n .then(() => {\n subscriber.next(lensState.actions.removeLensComplete());\n subscriber.complete();\n })\n .catch((lensCoreError) => {\n const error = new Error(\"Failed to remove lenses.\", { cause: lensCoreError });\n subscriber.next(lensState.actions.removeLensFailed(error));\n subscriber.complete();\n });\n })\n ),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n lensState.events\n .pipe(\n inStates(\"applyingLens\"),\n forActions(\"removeLens\"),\n switchMap(([a]) =>\n lensState.events.pipe(\n // Wait to remove the lens until it has been applied.\n inStates(\"lensApplied\"),\n // But cancel the removal if a new applyLens supercedes the current lens. The goal here is to\n // make sure the latest apply/remove pre-empts any previous request to apply/remove.\n takeUntil(lensState.events.pipe(forActions(\"applyLens\"))),\n map(() => a)\n )\n ),\n dispatch(lensState)\n )\n .subscribe({\n error: logger.error,\n });\n\n // Log transitions\n lensState.events.subscribe(([a, s]) => logger.debug(`Action: \"${a.name}\", state: \"${s.name}\"`));\n\n return lensState;\n }\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap/camera-kit",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Camera Kit Web",
6
6
  "homepage": "https://ar.snap.com/camera-kit",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@improbable-eng/grpc-web": "^0.15.0",
52
- "@snap/state-management": "^0.1.1",
52
+ "@snap/state-management": "^0.14.0",
53
53
  "browser-fs-access": "^0.31.1",
54
54
  "browser-headers": "^0.4.1",
55
55
  "long": "^4.0.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Assert that the current platform supports the necessary WebGL features.
3
- * Specifically, it checks for WebGL or WebGL2 support and ensures that
4
- * the maximum texture size is at least 1024.
5
- */
6
- export declare function assertPlatformSupported(): void;
@@ -1,21 +0,0 @@
1
- import { assert } from "./common/assertions";
2
- import { platformNotSupportedError } from "./namedErrors";
3
- const minTextureSize = 1024;
4
- /**
5
- * Assert that the current platform supports the necessary WebGL features.
6
- * Specifically, it checks for WebGL or WebGL2 support and ensures that
7
- * the maximum texture size is at least 1024.
8
- */
9
- export function assertPlatformSupported() {
10
- const canvas = document.createElement("canvas");
11
- const webglContext = canvas.getContext("webgl2") || canvas.getContext("webgl");
12
- const maxTextureSize = webglContext === null || webglContext === void 0 ? void 0 : webglContext.getParameter(webglContext.MAX_TEXTURE_SIZE);
13
- assert(!!webglContext, platformNotSupportedError("Camera Kit cannot be bootstrapped because the browser does not support WebGL canvas rendering context."));
14
- // Assert that the maximum texture size supported by WebGL is at least 1024.
15
- // This is based on the information available at https://web3dsurvey.com/webgl/parameters/MAX_TEXTURE_SIZE
16
- // and ensures that the application avoids future errors due to incompatibility with smaller texture sizes.
17
- assert(maxTextureSize >= minTextureSize, platformNotSupportedError(
18
- // eslint-disable-next-line max-len
19
- `Camera Kit cannot be bootstrapped because this browser's WebGL MAX_TEXTURE_SIZE is ${maxTextureSize}, which is below the minimum requirement of ${minTextureSize}.`));
20
- }
21
- //# sourceMappingURL=assertPlatformSupported.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertPlatformSupported.js","sourceRoot":"","sources":["../src/assertPlatformSupported.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACnC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC/E,MAAM,cAAc,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAEjF,MAAM,CACF,CAAC,CAAC,YAAY,EACd,yBAAyB,CACrB,wGAAwG,CAC3G,CACJ,CAAC;IAEF,4EAA4E;IAC5E,0GAA0G;IAC1G,2GAA2G;IAC3G,MAAM,CACF,cAAc,IAAI,cAAc,EAChC,yBAAyB;IACrB,mCAAmC;IACnC,sFAAsF,cAAc,+CAA+C,cAAc,GAAG,CACvK,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { assert } from \"./common/assertions\";\nimport { platformNotSupportedError } from \"./namedErrors\";\n\nconst minTextureSize = 1024;\n\n/**\n * Assert that the current platform supports the necessary WebGL features.\n * Specifically, it checks for WebGL or WebGL2 support and ensures that\n * the maximum texture size is at least 1024.\n */\nexport function assertPlatformSupported() {\n const canvas = document.createElement(\"canvas\");\n const webglContext = canvas.getContext(\"webgl2\") || canvas.getContext(\"webgl\");\n const maxTextureSize = webglContext?.getParameter(webglContext.MAX_TEXTURE_SIZE);\n\n assert(\n !!webglContext,\n platformNotSupportedError(\n \"Camera Kit cannot be bootstrapped because the browser does not support WebGL canvas rendering context.\"\n )\n );\n\n // Assert that the maximum texture size supported by WebGL is at least 1024.\n // This is based on the information available at https://web3dsurvey.com/webgl/parameters/MAX_TEXTURE_SIZE\n // and ensures that the application avoids future errors due to incompatibility with smaller texture sizes.\n assert(\n maxTextureSize >= minTextureSize,\n platformNotSupportedError(\n // eslint-disable-next-line max-len\n `Camera Kit cannot be bootstrapped because this browser's WebGL MAX_TEXTURE_SIZE is ${maxTextureSize}, which is below the minimum requirement of ${minTextureSize}.`\n )\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cameraKitUserAgent.js","sourceRoot":"","sources":["../../src/common/cameraKitUserAgent.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAC9C,OAAO,YAAY,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAuBxC;;;GAGG;AACH,SAAS,iBAAiB,CAAC,KAAc;IACrC,OAAO,CACH,QAAQ,CAAC,KAAK,CAAC;QACf,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9B,KAAK,CAAC,QAAQ,CAAC,CAA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AE,CAAC","sourcesContent":["import environment from \"../environment.json\";\nimport lensCoreWasm from \"../lensCoreWasmVersions.json\";\nimport { locale } from \"./locale\";\nimport { isRecord } from \"./typeguards\";\n\ntype BrandArray = Array<{ brand: string; version: string }>;\n\ninterface NavigatorUAData {\n brands: BrandArray;\n mobile: boolean;\n platform: string;\n}\n\nexport type ConnectionType = \"bluetooth\" | \"cellular\" | \"ethernet\" | \"none\" | \"wifi\" | \"wimax\" | \"other\" | \"unknown\";\n\ndeclare global {\n interface Navigator {\n userAgentData?: NavigatorUAData;\n connection?: {\n // This currently has extremely limited support in browsers.\n // https://wicg.github.io/netinfo/#dom-networkinformation-type\n type?: ConnectionType;\n };\n }\n}\n\n/**\n * Some user agents may not properly implement the NavigatorUAData interface, so we have to do our own validation here\n * to make sure we're dealing with a well-formed value.\n */\nfunction isNavigatorUAData(value: unknown): value is NavigatorUAData {\n return (\n isRecord(value) &&\n Array.isArray(value[\"brands\"]) &&\n value[\"brands\"].every((brand) => {\n return isRecord(brand) && typeof brand[\"brand\"] === \"string\" && typeof brand[\"version\"] === \"string\";\n }) &&\n typeof value[\"mobile\"] === \"boolean\" &&\n typeof value[\"platform\"] === \"string\"\n );\n}\n\n/**\n * Parse the platform (i.e. OS) version.\n *\n * From limited testing, this seems to often produce incorrect results – the userAgent string does not typically include\n * the actual OS version.\n *\n * Better results could be obtained from [NavigatorUAData.getHighEntropyValues]\n * (https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues), but this presents two\n * problems: 1) it's currently only supported on Chrome and 2) browsers may prompt the user for permission to share\n * this information.\n *\n * So, at least for now, we'll be satisfied with the incorrect version number.\n */\nfunction parsePlatformVersion(userAgent: string) {\n // possible platform version values inside of user agent string\n // \" 11;\"\n // \" 10_15_7)\"\n // \" 13_5_1 \"\n // \" 10.0;\"\n // \" 15_1 \"\n const versionMatch = userAgent.match(/\\s([\\d][\\d_.]*[\\d])(;|\\)|\\s)/);\n\n if (versionMatch != null) {\n return versionMatch[1].replace(/_/g, \".\");\n }\n\n return \"\";\n}\n\n/**\n * In the future, we may invest in more robust device-detection (e.g. a UA string database), but for now this will give\n * us some sense of device usage.\n */\nfunction parseDeviceModel(userAgent: string) {\n // from user agent like \"(Linux; Android 11; Pixel 2)\" extact \"Pixel 2\"\n const userAgentWithModel = userAgent.match(/;[^;]+?;([^\\)]+?)\\)/);\n\n if (userAgentWithModel) {\n return userAgentWithModel[1].trim();\n }\n\n // from user agent like \"... (iPad; CPU OS 15_1 like Mac OS X) ...\" extract \"IPad\"\n const userAgentWithModel2 = userAgent.match(/\\(([^;]+);/);\n\n if (userAgentWithModel2) {\n return userAgentWithModel2[1].trim();\n }\n\n return \"unknown\";\n}\n\n/**\n * Some browsers (e.g. Safari) do not support the `Navigator.userAgentData` API. We'll attempt a sort of polyfill by\n * parsing the data found in [NavigatorUAData](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData) from\n * the raw user agent string.\n */\nfunction parseUserAgentData(userAgent: string): NavigatorUAData {\n let brand: BrandArray[number];\n\n // Parse UA string for Chromium-based browsers (e.g. Chrome, Edge)\n if (/Chrome/.test(userAgent)) {\n const versionMatch = userAgent.match(/Chrome\\/([\\d.]+)/);\n brand = {\n brand: \"Chrome\",\n version: versionMatch !== null ? versionMatch[1] : \"unknown\",\n };\n }\n\n // Parse UA string for Safari (very important for this to only be done if Chrome is not found – Chrome userAgent\n // strings will contain \"Safari\")\n else if (/Safari/.test(userAgent)) {\n let versionMatch = userAgent.match(/Version\\/([\\d.]+)/);\n if (versionMatch === null) versionMatch = userAgent.match(/Safari\\/([\\d.]+)/);\n brand = {\n brand: \"Safari\",\n version: versionMatch !== null ? versionMatch[1] : \"unknown\",\n };\n }\n\n // Parse UA for unknown browser.\n // TODO: will be changed, default value support should be added on a COF server side.\n else {\n brand = {\n brand: \"Firefox\",\n version: \"0\",\n };\n }\n\n // We're not using `mobile` for anything, and we have no consistent way to determine this from the UA string.\n // We'll set it to false, but this should not be used – instead, we'll need to rely on more sophisticated methods\n // (e.g. a userAgent database) to determine actual device.\n const mobile = false;\n const platform = parsePlaftformName(userAgent);\n\n return {\n brands: [brand],\n mobile,\n platform,\n };\n}\n\n/* eslint-disable max-len */\n/**\n * The `brands` array found in [NavigatorUAData](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData) is\n * intentionally designed to discourage standardized processing. This method of extracting brand information will be\n * inherently brittle, and it relies on us matching some well-known brands.\n *\n * For more detail from the spec:\n * See https://wicg.github.io/ua-client-hints/#monkeypatch-html-windoworworkerglobalscope\n * And https://wicg.github.io/ua-client-hints/#grease\n *\n * We also must match the list of known brands allowed by the backend, defined here:\n * https://github.sc-corp.net/Snapchat/useragent/blob/9333afe7cc6ac00503ad46cb234bcf94006dff98/java/useragent/src/main/java/snapchat/client/UserAgent.java#L124\n */\n/* eslint-enable */\ntype KnownBrand = \"Chrome\" | \"Safari\" | \"Firefox\";\nfunction normalizeBrands(brands: BrandArray): BrandArray {\n const knownBrands = new Map<string, KnownBrand>([\n [\"Chrome\", \"Chrome\"],\n [\"Chromium\", \"Chrome\"],\n [\"Firefox\", \"Firefox\"],\n [\"Microsoft Edge\", \"Chrome\"],\n [\"Safari\", \"Safari\"],\n ]);\n\n const normalizedBrands = brands\n .filter(({ brand }) => knownBrands.has(brand))\n .map((brand) => {\n return {\n // Safety: we've filtered out brands which do not appear as keys in `knownBrands`, so this cannot return\n // undefined.\n brand: knownBrands.get(brand.brand)!,\n version: brand.version,\n };\n });\n\n // TODO: default \"unknown\" value should be added on COF server side. For now we'll use Firefox.\n if (normalizedBrands.length === 0) return [{ brand: \"Firefox\", version: \"0\" }];\n return normalizedBrands;\n}\n\n/* eslint-disable max-len */\n/**\n * We must ensure the data we get from `navigator.userAgentData` is normalized to match what our backend expects to\n * see in our custom CameraKitWeb userAgent string.\n *\n * This string is defined here:\n * https://github.sc-corp.net/Snapchat/useragent/blob/9333afe7cc6ac00503ad46cb234bcf94006dff98/java/useragent/src/main/java/snapchat/client/UserAgent.java#L124\n */\n/* eslint-enable */\nfunction normalizeUserAgentData(userAgentData: NavigatorUAData): NavigatorUAData {\n return {\n brands: normalizeBrands(userAgentData.brands),\n mobile: userAgentData.mobile,\n platform: parsePlaftformName(userAgentData.platform),\n };\n}\n\n/* eslint-disable max-len */\n/**\n * The backend defines the allowed list of known platforms which will pass their RegEx test when found in our custom\n * CameraKitWeb userAgent string.\n *\n * See https://github.sc-corp.net/Snapchat/useragent/blob/9333afe7cc6ac00503ad46cb234bcf94006dff98/java/useragent/src/main/java/snapchat/client/UserAgent.java#L124\n */\n/* eslint-enable */\ntype KnownPlatform = \"macos\" | \"windows\" | \"linux\" | \"android\" | \"ios\" | \"ipados\" | \"unknown\";\nfunction parsePlaftformName(userAgent: string): KnownPlatform {\n const knownPlatforms = new Map<string, KnownPlatform>([\n [\"android\", \"android\"],\n [\"linux\", \"linux\"],\n [\"iphone os\", \"ios\"],\n [\"ipad\", \"ipados\"],\n [\"mac os\", \"macos\"],\n [\"macos\", \"macos\"],\n [\"windows\", \"windows\"],\n ]);\n\n const normalizedUserAgent = userAgent.toLowerCase();\n for (const [match, platform] of knownPlatforms.entries()) {\n if (normalizedUserAgent.includes(match)) return platform;\n }\n return \"unknown\";\n}\n\n/**\n * We'll use the application's origin as an identifier – this isn't used for any kind of authentication, but it may be\n * useful metadata to have in the future.\n *\n * We also need to handle cases in which the SDK is used in a child browsing context (e.g. an iframe), which may not\n * have a hostname – in this case we'll check each ancestor context until we find a valid hostname.\n */\nfunction parseApplicationOrigin(): string {\n let origin = location.hostname;\n // Firefox does not implement ancestorOrigins, so we need a fallback.\n // Context here: https://github.com/whatwg/html/issues/1918\n const ancestorOrigins =\n location.ancestorOrigins === undefined\n ? typeof window !== \"undefined\"\n ? [window.parent.origin, window.top?.origin ?? \"\"]\n : []\n : Array.from(location.ancestorOrigins ?? []);\n\n while (origin === \"\" && ancestorOrigins.length > 0) {\n // Safety: ancestorOrigins must contain at least one element, so shift() will always be defined.\n origin = new URL(ancestorOrigins.shift()!).hostname;\n }\n return origin;\n}\n\nfunction getCameraKitUserAgent(): CameraKitUserAgent {\n const userAgent = navigator.userAgent ?? \"\";\n // [NavigatorUAData](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData) is currently only\n // available on Chromium-based browsers – it's nice because it gives us clear, well-documented information. But\n // we'll have to fallback to parsing the userAgent string when it's not available.\n const userAgentData = isNavigatorUAData(navigator.userAgentData)\n ? normalizeUserAgentData(navigator.userAgentData)\n : parseUserAgentData(userAgent);\n\n const platformVersion = parsePlatformVersion(userAgent);\n const deviceModel = parseDeviceModel(userAgent);\n\n // In cases where we've parsed the userAgent string to find the brand, there will only ever be a single brand –\n // in browsers which support NavigatorUAData there could be more than one (e.g. Chrome and Chromium), but they\n // should be equivalent for our purposes.\n const browser = userAgentData.brands[0];\n const origin = parseApplicationOrigin();\n\n const sdkLongVersion = environment.PACKAGE_VERSION;\n // Remove any `-prerelease` or `+buildmetadata` portions from the semver string.\n const sdkShortVersion = sdkLongVersion.replace(/[-+]\\S+$/, \"\");\n\n // Set this to `debug` manually while testing / root-causing.\n const flavor: \"release\" | \"debug\" = \"release\";\n\n // This full string is defined here:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/useragent/blob/9333afe7cc6ac00503ad46cb234bcf94006dff98/java/useragent/src/main/java/snapchat/client/UserAgent.java#L124\n const cameraKitUserAgent =\n `CameraKitWeb/${sdkShortVersion} ` +\n `${flavor === \"release\" ? \"\" : \"DEBUG\"}` +\n `(${deviceModel}; ${userAgentData.platform} ${platformVersion}) ` +\n `${browser.brand}/${browser.version} ` +\n `Core/${lensCoreWasm.version} ` +\n // We overload appId, using the origin instead of the true appId parsed from the apiToken -- we do this because\n // origin is human-readable, and this is used to populate the appId dimension in operational metrics.\n `AppId/${origin}`;\n\n return {\n osType: userAgentData.platform,\n osVersion: platformVersion,\n locale,\n sdkShortVersion,\n sdkLongVersion,\n flavor,\n lensCoreVersion: `${lensCoreWasm.version}`,\n deviceModel,\n browser,\n origin,\n userAgent: cameraKitUserAgent,\n connectionType: navigator.connection?.type,\n };\n}\n\n/** @internal */\nexport interface CameraKitUserAgent {\n osType: string;\n osVersion: string;\n locale: string;\n sdkShortVersion: string;\n sdkLongVersion: string;\n flavor: \"release\" | \"debug\";\n lensCoreVersion: string;\n deviceModel: string;\n browser: { brand: string; version: string };\n origin: string;\n userAgent: string;\n connectionType: ConnectionType | undefined;\n}\n\n/** @internal */\nexport const cameraKitUserAgent = getCameraKitUserAgent();\n"]}
@@ -1,2 +0,0 @@
1
- export declare const locale: string;
2
- export declare const fullLocale: string;
@@ -1,11 +0,0 @@
1
- export const locale = navigator.language;
2
- // Below adds qvalue to languages as per a backend issue:
3
- // https://github.sc-corp.net/Snapchat/phantom/pull/196781
4
- // More on qvalues: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
5
- export const fullLocale = navigator.languages
6
- .map((lang, index) => {
7
- const qvalue = Math.max(0, (10 - index) / 10);
8
- return `${lang};q=${qvalue.toFixed(1)}`;
9
- })
10
- .join(", ");
11
- //# sourceMappingURL=locale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/common/locale.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC;AAEzC,yDAAyD;AACzD,0DAA0D;AAC1D,oFAAoF;AACpF,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,SAAS;KACxC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,OAAO,GAAG,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5C,CAAC,CAAC;KACD,IAAI,CAAC,IAAI,CAAC,CAAC","sourcesContent":["export const locale = navigator.language;\n\n// Below adds qvalue to languages as per a backend issue:\n// https://github.sc-corp.net/Snapchat/phantom/pull/196781\n// More on qvalues: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values\nexport const fullLocale = navigator.languages\n .map((lang, index) => {\n const qvalue = Math.max(0, (10 - index) / 10);\n return `${lang};q=${qvalue.toFixed(1)}`;\n })\n .join(\", \");\n"]}