timingsrc 1.2.5 → 1.2.7

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 (166) hide show
  1. package/README.md +0 -1
  2. package/build/es2019/factories/compute-velocity.d.ts +2 -0
  3. package/build/es2019/factories/compute-velocity.d.ts.map +1 -0
  4. package/build/es2019/factories/compute-velocity.js +2 -0
  5. package/build/es2019/factories/compute-velocity.js.map +1 -0
  6. package/build/es2019/factories/default-set-timingsrc.d.ts +9 -2
  7. package/build/es2019/factories/default-set-timingsrc.d.ts.map +1 -1
  8. package/build/es2019/factories/default-set-timingsrc.js +6 -3
  9. package/build/es2019/factories/default-set-timingsrc.js.map +1 -1
  10. package/build/es2019/factories/set-current-time.d.ts +1 -2
  11. package/build/es2019/factories/set-current-time.d.ts.map +1 -1
  12. package/build/es2019/factories/set-current-time.js.map +1 -1
  13. package/build/es2019/factories/set-playback-rate.d.ts +1 -2
  14. package/build/es2019/factories/set-playback-rate.d.ts.map +1 -1
  15. package/build/es2019/factories/set-playback-rate.js.map +1 -1
  16. package/build/es2019/factories/set-timingsrc-with-custom-update-function.d.ts +6 -2
  17. package/build/es2019/factories/set-timingsrc-with-custom-update-function.d.ts.map +1 -1
  18. package/build/es2019/factories/set-timingsrc-with-custom-update-function.js +3 -1
  19. package/build/es2019/factories/set-timingsrc-with-custom-update-function.js.map +1 -1
  20. package/build/es2019/factories/set-timingsrc.d.ts +5 -2
  21. package/build/es2019/factories/set-timingsrc.d.ts.map +1 -1
  22. package/build/es2019/factories/set-timingsrc.js +1 -3
  23. package/build/es2019/factories/set-timingsrc.js.map +1 -1
  24. package/build/es2019/factories/update-gradually.d.ts +7 -2
  25. package/build/es2019/factories/update-gradually.d.ts.map +1 -1
  26. package/build/es2019/factories/update-gradually.js +18 -7
  27. package/build/es2019/factories/update-gradually.js.map +1 -1
  28. package/build/es2019/factories/update-media-element.d.ts +5 -2
  29. package/build/es2019/factories/update-media-element.d.ts.map +1 -1
  30. package/build/es2019/factories/update-media-element.js.map +1 -1
  31. package/build/es2019/factories/update-stepwise-factory.d.ts +12 -2
  32. package/build/es2019/factories/update-stepwise-factory.d.ts.map +1 -1
  33. package/build/es2019/factories/update-stepwise-factory.js +98 -25
  34. package/build/es2019/factories/update-stepwise-factory.js.map +1 -1
  35. package/build/es2019/factories/window.d.ts +1 -2
  36. package/build/es2019/factories/window.d.ts.map +1 -1
  37. package/build/es2019/factories/window.js.map +1 -1
  38. package/build/es2019/functions/determine-supported-playback-rate-values.d.ts +2 -1
  39. package/build/es2019/functions/determine-supported-playback-rate-values.d.ts.map +1 -1
  40. package/build/es2019/functions/determine-supported-playback-rate-values.js.map +1 -1
  41. package/build/es2019/functions/update-vector-with-new-position.d.ts +6 -0
  42. package/build/es2019/functions/update-vector-with-new-position.d.ts.map +1 -0
  43. package/build/es2019/functions/update-vector-with-new-position.js +5 -0
  44. package/build/es2019/functions/update-vector-with-new-position.js.map +1 -0
  45. package/build/es2019/module.d.ts +11 -3
  46. package/build/es2019/module.d.ts.map +1 -1
  47. package/build/es2019/module.js +3 -1
  48. package/build/es2019/module.js.map +1 -1
  49. package/build/es2019/types/index.d.ts +1 -17
  50. package/build/es2019/types/index.d.ts.map +1 -1
  51. package/build/es2019/types/index.js +1 -17
  52. package/build/es2019/types/index.js.map +1 -1
  53. package/build/es2019/types/update-function.d.ts +1 -1
  54. package/build/es2019/types/update-function.d.ts.map +1 -1
  55. package/build/es2019/types/update-vector-with-custom-state.d.ts +3 -0
  56. package/build/es2019/types/update-vector-with-custom-state.d.ts.map +1 -0
  57. package/build/es2019/types/update-vector-with-custom-state.js +2 -0
  58. package/build/es2019/types/update-vector-with-custom-state.js.map +1 -0
  59. package/build/es5/bundle.js +167 -63
  60. package/package.json +16 -16
  61. package/src/factories/compute-velocity.ts +2 -0
  62. package/src/factories/default-set-timingsrc.ts +30 -19
  63. package/src/factories/set-current-time.ts +2 -4
  64. package/src/factories/set-playback-rate.ts +2 -4
  65. package/src/factories/set-timingsrc-with-custom-update-function.ts +24 -9
  66. package/src/factories/set-timingsrc.ts +14 -4
  67. package/src/factories/update-gradually.ts +37 -8
  68. package/src/factories/update-media-element.ts +18 -3
  69. package/src/factories/update-stepwise-factory.ts +133 -38
  70. package/src/factories/window.ts +1 -3
  71. package/src/functions/determine-supported-playback-rate-values.ts +3 -1
  72. package/src/functions/update-vector-with-new-position.ts +9 -0
  73. package/src/module.ts +4 -0
  74. package/src/types/index.ts +1 -17
  75. package/src/types/update-function.ts +5 -1
  76. package/src/types/update-vector-with-custom-state.ts +5 -0
  77. package/build/es2019/types/default-timingsrc-factory.d.ts +0 -8
  78. package/build/es2019/types/default-timingsrc-factory.d.ts.map +0 -1
  79. package/build/es2019/types/default-timingsrc-factory.js +0 -2
  80. package/build/es2019/types/default-timingsrc-factory.js.map +0 -1
  81. package/build/es2019/types/determine-supported-playback-rate-values-function.d.ts +0 -2
  82. package/build/es2019/types/determine-supported-playback-rate-values-function.d.ts.map +0 -1
  83. package/build/es2019/types/determine-supported-playback-rate-values-function.js +0 -2
  84. package/build/es2019/types/determine-supported-playback-rate-values-function.js.map +0 -1
  85. package/build/es2019/types/pause-function.d.ts +0 -2
  86. package/build/es2019/types/pause-function.d.ts.map +0 -1
  87. package/build/es2019/types/pause-function.js +0 -2
  88. package/build/es2019/types/pause-function.js.map +0 -1
  89. package/build/es2019/types/play-function.d.ts +0 -2
  90. package/build/es2019/types/play-function.d.ts.map +0 -1
  91. package/build/es2019/types/play-function.js +0 -2
  92. package/build/es2019/types/play-function.js.map +0 -1
  93. package/build/es2019/types/set-current-time-factory.d.ts +0 -3
  94. package/build/es2019/types/set-current-time-factory.d.ts.map +0 -1
  95. package/build/es2019/types/set-current-time-factory.js +0 -2
  96. package/build/es2019/types/set-current-time-factory.js.map +0 -1
  97. package/build/es2019/types/set-current-time-function.d.ts +0 -2
  98. package/build/es2019/types/set-current-time-function.d.ts.map +0 -1
  99. package/build/es2019/types/set-current-time-function.js +0 -2
  100. package/build/es2019/types/set-current-time-function.js.map +0 -1
  101. package/build/es2019/types/set-playback-rate-factory.d.ts +0 -3
  102. package/build/es2019/types/set-playback-rate-factory.d.ts.map +0 -1
  103. package/build/es2019/types/set-playback-rate-factory.js +0 -2
  104. package/build/es2019/types/set-playback-rate-factory.js.map +0 -1
  105. package/build/es2019/types/set-playback-rate-function.d.ts +0 -2
  106. package/build/es2019/types/set-playback-rate-function.d.ts.map +0 -1
  107. package/build/es2019/types/set-playback-rate-function.js +0 -2
  108. package/build/es2019/types/set-playback-rate-function.js.map +0 -1
  109. package/build/es2019/types/set-timingsrc-factory.d.ts +0 -5
  110. package/build/es2019/types/set-timingsrc-factory.d.ts.map +0 -1
  111. package/build/es2019/types/set-timingsrc-factory.js +0 -2
  112. package/build/es2019/types/set-timingsrc-factory.js.map +0 -1
  113. package/build/es2019/types/set-timingsrc-function.d.ts +0 -4
  114. package/build/es2019/types/set-timingsrc-function.d.ts.map +0 -1
  115. package/build/es2019/types/set-timingsrc-function.js +0 -2
  116. package/build/es2019/types/set-timingsrc-function.js.map +0 -1
  117. package/build/es2019/types/set-timingsrc-with-custom-update-function-factory.d.ts +0 -5
  118. package/build/es2019/types/set-timingsrc-with-custom-update-function-factory.d.ts.map +0 -1
  119. package/build/es2019/types/set-timingsrc-with-custom-update-function-factory.js +0 -2
  120. package/build/es2019/types/set-timingsrc-with-custom-update-function-factory.js.map +0 -1
  121. package/build/es2019/types/set-timingsrc-with-custom-update-function-function.d.ts +0 -5
  122. package/build/es2019/types/set-timingsrc-with-custom-update-function-function.d.ts.map +0 -1
  123. package/build/es2019/types/set-timingsrc-with-custom-update-function-function.js +0 -2
  124. package/build/es2019/types/set-timingsrc-with-custom-update-function-function.js.map +0 -1
  125. package/build/es2019/types/update-gradually-factory.d.ts +0 -4
  126. package/build/es2019/types/update-gradually-factory.d.ts.map +0 -1
  127. package/build/es2019/types/update-gradually-factory.js +0 -2
  128. package/build/es2019/types/update-gradually-factory.js.map +0 -1
  129. package/build/es2019/types/update-media-element-factory.d.ts +0 -7
  130. package/build/es2019/types/update-media-element-factory.d.ts.map +0 -1
  131. package/build/es2019/types/update-media-element-factory.js +0 -2
  132. package/build/es2019/types/update-media-element-factory.js.map +0 -1
  133. package/build/es2019/types/update-media-element-function.d.ts +0 -2
  134. package/build/es2019/types/update-media-element-function.d.ts.map +0 -1
  135. package/build/es2019/types/update-media-element-function.js +0 -2
  136. package/build/es2019/types/update-media-element-function.js.map +0 -1
  137. package/build/es2019/types/update-stepwise-factory-factory.d.ts +0 -4
  138. package/build/es2019/types/update-stepwise-factory-factory.d.ts.map +0 -1
  139. package/build/es2019/types/update-stepwise-factory-factory.js +0 -2
  140. package/build/es2019/types/update-stepwise-factory-factory.js.map +0 -1
  141. package/build/es2019/types/update-stepwise-factory.d.ts +0 -3
  142. package/build/es2019/types/update-stepwise-factory.d.ts.map +0 -1
  143. package/build/es2019/types/update-stepwise-factory.js +0 -2
  144. package/build/es2019/types/update-stepwise-factory.js.map +0 -1
  145. package/build/es2019/types/window-factory.d.ts +0 -2
  146. package/build/es2019/types/window-factory.d.ts.map +0 -1
  147. package/build/es2019/types/window-factory.js +0 -2
  148. package/build/es2019/types/window-factory.js.map +0 -1
  149. package/src/types/default-timingsrc-factory.ts +0 -15
  150. package/src/types/determine-supported-playback-rate-values-function.ts +0 -1
  151. package/src/types/pause-function.ts +0 -1
  152. package/src/types/play-function.ts +0 -1
  153. package/src/types/set-current-time-factory.ts +0 -3
  154. package/src/types/set-current-time-function.ts +0 -1
  155. package/src/types/set-playback-rate-factory.ts +0 -3
  156. package/src/types/set-playback-rate-function.ts +0 -1
  157. package/src/types/set-timingsrc-factory.ts +0 -8
  158. package/src/types/set-timingsrc-function.ts +0 -8
  159. package/src/types/set-timingsrc-with-custom-update-function-factory.ts +0 -10
  160. package/src/types/set-timingsrc-with-custom-update-function-function.ts +0 -10
  161. package/src/types/update-gradually-factory.ts +0 -9
  162. package/src/types/update-media-element-factory.ts +0 -12
  163. package/src/types/update-media-element-function.ts +0 -8
  164. package/src/types/update-stepwise-factory-factory.ts +0 -4
  165. package/src/types/update-stepwise-factory.ts +0 -3
  166. package/src/types/window-factory.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,0CAA0C,EAAE,MAAM,uDAAuD,CAAC;AACnH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oCAAoC,EAAE,MAAM,sDAAsD,CAAC;AAC5G,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;AAE5F,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,KAAK,EAAE,IAAI,EAAE,oBAAoB,CAAC,IAAI,OAAO,EAAE,CAAC,EAAE,qBAAqB,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC;AAE5I,MAAM,CAAC,MAAM,oCAAoC,GAAG,0CAA0C,CAC1F,cAAc,EACd,QAAQ,EACR,EAAE,EACF,kBAAkB,CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CACjD,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,oCAAoC,EACpC,oCAAoC,EACpC,YAAY,EAAE,CACjB,CAAC"}
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,0CAA0C,EAAE,MAAM,uDAAuD,CAAC;AACnH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oCAAoC,EAAE,MAAM,sDAAsD,CAAC;AAC5G,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAE1F,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;AAE5F,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,KAAK,EAAE,IAAI,EAAE,oBAAoB,CAAC,IAAI,OAAO,EAAE,CAAC,EAAE,qBAAqB,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC;AAE5I,MAAM,CAAC,MAAM,oCAAoC,GAAG,0CAA0C,CAC1F,cAAc,EACd,QAAQ,EACR,EAAE,EACF,kBAAkB,CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CACjD,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,oCAAoC,EACpC,oCAAoC,EACpC,2BAA2B,EAC3B,YAAY,EAAE,CACjB,CAAC"}
@@ -1,20 +1,4 @@
1
- export * from './default-timingsrc-factory';
2
- export * from './determine-supported-playback-rate-values-function';
3
- export * from './pause-function';
4
- export * from './play-function';
5
1
  export * from './prepare-timing-state-vector-function';
6
- export * from './set-current-time-factory';
7
- export * from './set-current-time-function';
8
- export * from './set-playback-rate-factory';
9
- export * from './set-playback-rate-function';
10
- export * from './set-timingsrc-factory';
11
- export * from './set-timingsrc-function';
12
- export * from './set-timingsrc-with-custom-update-function-factory';
13
- export * from './set-timingsrc-with-custom-update-function-function';
14
2
  export * from './update-function';
15
- export * from './update-gradually-factory';
16
- export * from './update-media-element-factory';
17
- export * from './update-stepwise-factory';
18
- export * from './update-stepwise-factory-factory';
19
- export * from './window-factory';
3
+ export * from './update-vector-with-custom-state';
20
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qDAAqD,CAAC;AACpE,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qDAAqD,CAAC;AACpE,cAAc,sDAAsD,CAAC;AACrE,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC"}
@@ -1,20 +1,4 @@
1
- export * from './default-timingsrc-factory';
2
- export * from './determine-supported-playback-rate-values-function';
3
- export * from './pause-function';
4
- export * from './play-function';
5
1
  export * from './prepare-timing-state-vector-function';
6
- export * from './set-current-time-factory';
7
- export * from './set-current-time-function';
8
- export * from './set-playback-rate-factory';
9
- export * from './set-playback-rate-function';
10
- export * from './set-timingsrc-factory';
11
- export * from './set-timingsrc-function';
12
- export * from './set-timingsrc-with-custom-update-function-factory';
13
- export * from './set-timingsrc-with-custom-update-function-function';
14
2
  export * from './update-function';
15
- export * from './update-gradually-factory';
16
- export * from './update-media-element-factory';
17
- export * from './update-stepwise-factory';
18
- export * from './update-stepwise-factory-factory';
19
- export * from './window-factory';
3
+ export * from './update-vector-with-custom-state';
20
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qDAAqD,CAAC;AACpE,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qDAAqD,CAAC;AACpE,cAAc,sDAAsD,CAAC;AACrE,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { ITimingStateVector } from 'timing-object';
2
2
  import { IUpdateVector } from '../interfaces';
3
- export declare type TUpdateFunction = (timingStateVector: ITimingStateVector, currentTime: number) => IUpdateVector;
3
+ export declare type TUpdateFunction<UpdateVectorWithCustomState extends IUpdateVector> = (timingStateVector: ITimingStateVector, currentTime: number, previousUpdateVectorWithCustomState: null | UpdateVectorWithCustomState) => UpdateVectorWithCustomState;
4
4
  //# sourceMappingURL=update-function.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update-function.d.ts","sourceRoot":"","sources":["../../../src/types/update-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,oBAAY,eAAe,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,KAAK,aAAa,CAAC"}
1
+ {"version":3,"file":"update-function.d.ts","sourceRoot":"","sources":["../../../src/types/update-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,oBAAY,eAAe,CAAC,2BAA2B,SAAS,aAAa,IAAI,CAC7E,iBAAiB,EAAE,kBAAkB,EACrC,WAAW,EAAE,MAAM,EACnB,mCAAmC,EAAE,IAAI,GAAG,2BAA2B,KACtE,2BAA2B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { TUpdateFunction } from './update-function';
2
+ export declare type TUpdateVectorWithCustomState<UpdateFunction> = UpdateFunction extends TUpdateFunction<infer UpdateVectorWithCustomState> ? UpdateVectorWithCustomState : never;
3
+ //# sourceMappingURL=update-vector-with-custom-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-vector-with-custom-state.d.ts","sourceRoot":"","sources":["../../../src/types/update-vector-with-custom-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,oBAAY,4BAA4B,CAAC,cAAc,IAAI,cAAc,SAAS,eAAe,CAAC,MAAM,2BAA2B,CAAC,GAC9H,2BAA2B,GAC3B,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=update-vector-with-custom-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-vector-with-custom-state.js","sourceRoot":"","sources":["../../../src/types/update-vector-with-custom-state.ts"],"names":[],"mappings":""}
@@ -1,21 +1,25 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('subscribable-things'), require('timing-object'), require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/defineProperty')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'subscribable-things', 'timing-object', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/defineProperty'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.timingsrc = {}, global.subscribableThings, global.timingObject, global._slicedToArray, global._defineProperty));
5
- })(this, (function (exports, subscribableThings, timingObject, _slicedToArray, _defineProperty) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('subscribable-things'), require('timing-object'), require('@babel/runtime/helpers/slicedToArray')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'subscribable-things', 'timing-object', '@babel/runtime/helpers/slicedToArray'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.timingsrc = {}, global.subscribableThings, global.timingObject, global._slicedToArray));
5
+ })(this, (function (exports, subscribableThings, timingObject, _slicedToArray) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
10
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
10
+
11
+ var createComputeVelocity = function createComputeVelocity(timeConstant) {
12
+ return function (delta, minValue, maxValue, velocity) {
13
+ return Math.max(minValue, Math.min(maxValue, (timeConstant - delta) / timeConstant * velocity));
14
+ };
15
+ };
11
16
 
12
17
  var DEFAULT_THRESHOLD = 1;
13
18
  var DEFAULT_TIME_CONSTANT = 0.5;
14
19
  var DEFAULT_TOLERANCE = 0.025;
15
- var createDefaultSetTimingsrc = function createDefaultSetTimingsrc(createSetTimingsrc, createUpdateGradually, createUpdateStepwise, determineSupportedPlaybackRateValues, setTimingsrcWithCustomUpdateFunction, window) {
16
- return window !== null && window.navigator.userAgent.includes('Safari') && !window.navigator.userAgent.includes('Chrome') ? function () {
17
- return createSetTimingsrc(setTimingsrcWithCustomUpdateFunction, createUpdateStepwise(DEFAULT_TOLERANCE)).apply(void 0, arguments);
18
- } : createSetTimingsrc(setTimingsrcWithCustomUpdateFunction, createUpdateGradually(determineSupportedPlaybackRateValues(window), DEFAULT_TIME_CONSTANT, DEFAULT_THRESHOLD, DEFAULT_TOLERANCE));
20
+ var createDefaultSetTimingsrc = function createDefaultSetTimingsrc(createComputeVelocity, createSetTimingsrc, createUpdateGradually, createUpdateStepwise, determineSupportedPlaybackRateValues, setTimingsrcWithCustomUpdateFunction, updateVectorWithNewPosition, window) {
21
+ var update = window !== null && window.navigator.userAgent.includes('Safari') && !window.navigator.userAgent.includes('Chrome') ? createUpdateStepwise(DEFAULT_TOLERANCE) : createUpdateGradually(createComputeVelocity(DEFAULT_TIME_CONSTANT), determineSupportedPlaybackRateValues(window), DEFAULT_THRESHOLD, DEFAULT_TOLERANCE, updateVectorWithNewPosition);
22
+ return createSetTimingsrc(setTimingsrcWithCustomUpdateFunction, update);
19
23
  };
20
24
 
21
25
  var createSetCurrentTime = function createSetCurrentTime(currentTimeAssignments) {
@@ -52,18 +56,18 @@
52
56
  var createSetTimingsrcWithCustomUpdateFunction = function createSetTimingsrcWithCustomUpdateFunction(animationFrame, document, on, updateMediaElement) {
53
57
  return function (mediaElement, timingObject, updateFunction) {
54
58
  var prepareTimingStateVector = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
59
+ var previousUpdateVectorWithCustomState = null;
55
60
 
56
61
  var update = function update() {
57
62
  var currentTime = mediaElement.currentTime,
58
63
  duration = mediaElement.duration,
59
64
  playbackRate = mediaElement.playbackRate;
60
65
  var timingStateVector = timingObject.query();
61
-
62
- var _updateFunction = updateFunction(prepareTimingStateVector === null ? timingStateVector : prepareTimingStateVector(timingStateVector), currentTime),
63
- position = _updateFunction.position,
64
- velocity = _updateFunction.velocity;
65
-
66
+ previousUpdateVectorWithCustomState = updateFunction(prepareTimingStateVector === null ? timingStateVector : prepareTimingStateVector(timingStateVector), currentTime, previousUpdateVectorWithCustomState);
66
67
  var sanitizedDuration = typeof duration === 'number' && !isNaN(duration) ? duration : 0;
68
+ var _previousUpdateVector = previousUpdateVectorWithCustomState,
69
+ position = _previousUpdateVector.position,
70
+ velocity = _previousUpdateVector.velocity;
67
71
  updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
68
72
  };
69
73
 
@@ -82,17 +86,23 @@
82
86
  };
83
87
  };
84
88
 
85
- var createUpdateGradually = function createUpdateGradually(_ref, timeConstant, threshold, tolerance) {
89
+ var createUpdateGradually = function createUpdateGradually(computeVelocity, _ref, threshold, tolerance, updateVectorWithNewPosition) {
86
90
  var _ref2 = _slicedToArray__default["default"](_ref, 2),
87
91
  minValue = _ref2[0],
88
92
  maxValue = _ref2[1];
89
93
 
90
- return function (_ref3, currentTime) {
94
+ return function (_ref3, currentTime, previousUpdateVectorWithCustomState) {
91
95
  var position = _ref3.position,
92
96
  velocity = _ref3.velocity;
93
97
 
98
+ var _ref4 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
99
+ mediaElementDelay: 0
100
+ },
101
+ mediaElementDelay = _ref4.mediaElementDelay;
102
+
94
103
  if (velocity < minValue || velocity > maxValue) {
95
104
  return {
105
+ mediaElementDelay: mediaElementDelay,
96
106
  position: position,
97
107
  velocity: 0
98
108
  };
@@ -100,6 +110,7 @@
100
110
 
101
111
  if (position < 0 || velocity === 0) {
102
112
  return {
113
+ mediaElementDelay: mediaElementDelay,
103
114
  position: position,
104
115
  velocity: velocity
105
116
  };
@@ -109,20 +120,38 @@
109
120
  var absolutePositionDifference = Math.abs(positionDifference);
110
121
 
111
122
  if (absolutePositionDifference > threshold) {
112
- return {
113
- position: position,
114
- velocity: velocity
115
- };
123
+ var _ref5 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
124
+ position: null
125
+ },
126
+ lastPosition = _ref5.position;
127
+
128
+ if (positionDifference < 0 || positionDifference > mediaElementDelay) {
129
+ if (lastPosition === currentTime) {
130
+ mediaElementDelay += absolutePositionDifference;
131
+ }
132
+
133
+ return updateVectorWithNewPosition(mediaElementDelay, position, function (nextPosition) {
134
+ return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
135
+ });
136
+ }
137
+
138
+ if (lastPosition !== currentTime) {
139
+ return updateVectorWithNewPosition(mediaElementDelay - absolutePositionDifference, position, function (nextPosition) {
140
+ return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
141
+ });
142
+ }
116
143
  }
117
144
 
118
145
  if (absolutePositionDifference > tolerance) {
119
146
  return {
147
+ mediaElementDelay: mediaElementDelay,
120
148
  position: currentTime,
121
- velocity: Math.max(minValue, Math.min(maxValue, (timeConstant - positionDifference) / timeConstant * velocity))
149
+ velocity: computeVelocity(positionDifference, minValue, maxValue, velocity)
122
150
  };
123
151
  }
124
152
 
125
153
  return {
154
+ mediaElementDelay: mediaElementDelay,
126
155
  position: currentTime,
127
156
  velocity: velocity
128
157
  };
@@ -166,67 +195,133 @@
166
195
  };
167
196
  };
168
197
 
169
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
170
-
171
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
172
-
198
+ var MAXIMUM_PLAYHEAD_DIFFERENCE = 0.5;
173
199
  var createUpdateStepwiseFactory = function createUpdateStepwiseFactory(translateTimingStateVector) {
174
200
  return function (tolerance) {
175
- var lastMotionUpdate = null;
176
- var lastPlayheadDifference = 0;
177
- var mediaElementDelay = 0;
178
- return function (timingStateVector, currentTime) {
201
+ return function (timingStateVector, currentTime, previousUpdateVectorWithCustomState) {
202
+ var _ref = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
203
+ lastAppliedPostion: 0,
204
+ lastAppliedTimestamp: 0,
205
+ lastAppliedVelocity: 0,
206
+ lastPlayheadDifference: 0,
207
+ mediaElementDelay: 0,
208
+ numberOfDetectedResets: 0,
209
+ numberOfExpectedResets: 1
210
+ },
211
+ lastAppliedPostion = _ref.lastAppliedPostion,
212
+ lastAppliedTimestamp = _ref.lastAppliedTimestamp,
213
+ lastAppliedVelocity = _ref.lastAppliedVelocity,
214
+ lastPlayheadDifference = _ref.lastPlayheadDifference,
215
+ mediaElementDelay = _ref.mediaElementDelay,
216
+ numberOfDetectedResets = _ref.numberOfDetectedResets,
217
+ numberOfExpectedResets = _ref.numberOfExpectedResets;
218
+
179
219
  if (timingStateVector.position < 0 || timingStateVector.velocity === 0) {
180
- lastMotionUpdate = null;
220
+ lastAppliedPostion = timingStateVector.position;
221
+ lastAppliedVelocity = timingStateVector.velocity;
181
222
  return {
182
- position: timingStateVector.position,
183
- velocity: timingStateVector.velocity
223
+ lastAppliedPostion: lastAppliedPostion,
224
+ lastAppliedTimestamp: 0,
225
+ lastAppliedVelocity: lastAppliedVelocity,
226
+ lastPlayheadDifference: lastPlayheadDifference,
227
+ mediaElementDelay: mediaElementDelay,
228
+ numberOfDetectedResets: numberOfDetectedResets,
229
+ numberOfExpectedResets: numberOfExpectedResets,
230
+ position: lastAppliedPostion,
231
+ velocity: lastAppliedVelocity
184
232
  };
185
- }
186
-
187
- if (lastMotionUpdate !== null) {
188
- var playheadDifference = Math.abs(currentTime - lastMotionUpdate.position); // Bug #4: Safari decreases currentTime after playing for about 200 milliseconds.
189
-
190
- if (lastPlayheadDifference - 0.01 < playheadDifference && lastPlayheadDifference < 0.5) {
233
+ } // Bug #4: Safari decreases currentTime after playing for about 200 milliseconds.
234
+
235
+
236
+ if (lastAppliedVelocity === timingStateVector.velocity && lastPlayheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
237
+ var playheadDifference = Math.abs(currentTime - lastAppliedPostion) * lastAppliedVelocity;
238
+
239
+ if (playheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
240
+ if (playheadDifference + 0.001 > lastPlayheadDifference) {
241
+ lastPlayheadDifference = playheadDifference;
242
+
243
+ if (numberOfDetectedResets < numberOfExpectedResets) {
244
+ return {
245
+ lastAppliedPostion: lastAppliedPostion,
246
+ lastAppliedTimestamp: lastAppliedTimestamp,
247
+ lastAppliedVelocity: lastAppliedVelocity,
248
+ lastPlayheadDifference: lastPlayheadDifference,
249
+ mediaElementDelay: mediaElementDelay,
250
+ numberOfDetectedResets: numberOfDetectedResets,
251
+ numberOfExpectedResets: numberOfExpectedResets,
252
+ position: currentTime,
253
+ velocity: lastAppliedVelocity
254
+ };
255
+ }
256
+ } else {
257
+ lastPlayheadDifference = playheadDifference;
258
+ numberOfDetectedResets += 1;
259
+
260
+ if (numberOfDetectedResets <= numberOfExpectedResets) {
261
+ return {
262
+ lastAppliedPostion: lastAppliedPostion,
263
+ lastAppliedTimestamp: lastAppliedTimestamp,
264
+ lastAppliedVelocity: lastAppliedVelocity,
265
+ lastPlayheadDifference: lastPlayheadDifference,
266
+ mediaElementDelay: mediaElementDelay,
267
+ numberOfDetectedResets: numberOfDetectedResets,
268
+ numberOfExpectedResets: numberOfExpectedResets,
269
+ position: currentTime,
270
+ velocity: lastAppliedVelocity
271
+ };
272
+ }
273
+
274
+ numberOfExpectedResets += 1;
275
+ }
276
+ } else {
191
277
  lastPlayheadDifference = playheadDifference;
192
- return {
193
- position: currentTime,
194
- velocity: lastMotionUpdate.velocity
195
- };
278
+ numberOfExpectedResets = Math.max(numberOfDetectedResets, 1);
196
279
  }
197
-
198
- lastPlayheadDifference = Number.POSITIVE_INFINITY;
280
+ } else {
281
+ lastAppliedTimestamp = 0;
199
282
  }
200
283
 
201
284
  var positionDifference = Math.abs(currentTime - timingStateVector.position);
202
-
203
- if (positionDifference > tolerance) {
204
- if (lastMotionUpdate !== null) {
205
- var elapsedTime = timingStateVector.timestamp - lastMotionUpdate.timestamp;
206
-
207
- var _translateTimingState = translateTimingStateVector(_objectSpread({
208
- acceleration: 0
209
- }, lastMotionUpdate), elapsedTime),
285
+ var velocityHasChanged = lastAppliedVelocity === 0 || lastAppliedVelocity < 0 && timingStateVector.velocity > 0 || lastAppliedVelocity > 0 && timingStateVector.velocity < 0;
286
+
287
+ if (positionDifference > tolerance || velocityHasChanged) {
288
+ if (lastAppliedTimestamp > 0) {
289
+ var elapsedTime = timingStateVector.timestamp - lastAppliedTimestamp;
290
+
291
+ var _translateTimingState = translateTimingStateVector({
292
+ acceleration: 0,
293
+ position: lastAppliedPostion,
294
+ timestamp: lastAppliedTimestamp,
295
+ velocity: lastAppliedVelocity
296
+ }, elapsedTime),
210
297
  position = _translateTimingState.position;
211
298
 
212
299
  mediaElementDelay = position - currentTime;
213
300
  }
214
301
 
215
- var positioWithDelay = timingStateVector.position + mediaElementDelay;
216
- lastMotionUpdate = {
217
- position: positioWithDelay,
218
- timestamp: timingStateVector.timestamp,
219
- velocity: timingStateVector.velocity
220
- };
221
- lastPlayheadDifference = 0;
302
+ lastAppliedPostion = timingStateVector.position + mediaElementDelay;
303
+ lastAppliedVelocity = timingStateVector.velocity;
222
304
  return {
223
- position: positioWithDelay,
224
- velocity: timingStateVector.velocity
305
+ lastAppliedPostion: lastAppliedPostion,
306
+ lastAppliedTimestamp: timingStateVector.timestamp,
307
+ lastAppliedVelocity: lastAppliedVelocity,
308
+ lastPlayheadDifference: 0,
309
+ mediaElementDelay: mediaElementDelay,
310
+ numberOfDetectedResets: 0,
311
+ numberOfExpectedResets: numberOfExpectedResets,
312
+ position: lastAppliedPostion,
313
+ velocity: lastAppliedVelocity
225
314
  };
226
315
  }
227
316
 
228
- lastMotionUpdate = null;
229
317
  return {
318
+ lastAppliedPostion: lastAppliedPostion,
319
+ lastAppliedTimestamp: lastAppliedTimestamp,
320
+ lastAppliedVelocity: lastAppliedVelocity,
321
+ lastPlayheadDifference: lastPlayheadDifference,
322
+ mediaElementDelay: mediaElementDelay,
323
+ numberOfDetectedResets: numberOfDetectedResets,
324
+ numberOfExpectedResets: numberOfExpectedResets,
230
325
  position: currentTime,
231
326
  velocity: timingStateVector.velocity
232
327
  };
@@ -278,10 +373,19 @@
278
373
  }
279
374
  };
280
375
 
376
+ var updateVectorWithNewPosition = function updateVectorWithNewPosition(mediaElementDelay, position, updateVelocity) {
377
+ var nextPosition = position + mediaElementDelay;
378
+ return {
379
+ mediaElementDelay: mediaElementDelay,
380
+ position: nextPosition,
381
+ velocity: updateVelocity(nextPosition)
382
+ };
383
+ };
384
+
281
385
  var createUpdateStepwise = createUpdateStepwiseFactory(timingObject.translateTimingStateVector);
282
386
  var updateMediaElement = createUpdateMediaElement(pause, play, createSetCurrentTime(new WeakMap()), createSetPlaybackRate(new WeakMap()));
283
387
  var setTimingsrcWithCustomUpdateFunction = createSetTimingsrcWithCustomUpdateFunction(subscribableThings.animationFrame, document, subscribableThings.on, updateMediaElement);
284
- var setTimingsrc = createDefaultSetTimingsrc(createSetTimingsrc, createUpdateGradually, createUpdateStepwise, determineSupportedPlaybackRateValues, setTimingsrcWithCustomUpdateFunction, createWindow());
388
+ var setTimingsrc = createDefaultSetTimingsrc(createComputeVelocity, createSetTimingsrc, createUpdateGradually, createUpdateStepwise, determineSupportedPlaybackRateValues, setTimingsrcWithCustomUpdateFunction, updateVectorWithNewPosition, createWindow());
285
389
 
286
390
  exports.createSetTimingsrc = createSetTimingsrc;
287
391
  exports.createUpdateGradually = createUpdateGradually;
package/package.json CHANGED
@@ -9,30 +9,30 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@babel/runtime": "^7.18.9",
13
- "subscribable-things": "^2.1.6",
14
- "timing-object": "^3.1.47",
12
+ "@babel/runtime": "^7.19.0",
13
+ "subscribable-things": "^2.1.7",
14
+ "timing-object": "^3.1.48",
15
15
  "tslib": "^2.4.0"
16
16
  },
17
17
  "description": "A library to synchronize a MediaElement with a TimingObject.",
18
18
  "devDependencies": {
19
- "@babel/core": "^7.18.13",
19
+ "@babel/core": "^7.19.1",
20
20
  "@babel/plugin-external-helpers": "^7.18.6",
21
- "@babel/plugin-transform-runtime": "^7.18.10",
22
- "@babel/preset-env": "^7.18.10",
23
- "@commitlint/cli": "^17.1.1",
21
+ "@babel/plugin-transform-runtime": "^7.19.1",
22
+ "@babel/preset-env": "^7.19.1",
23
+ "@commitlint/cli": "^17.1.2",
24
24
  "@commitlint/config-angular": "^17.1.0",
25
25
  "@rollup/plugin-babel": "^5.3.1",
26
26
  "chai": "^4.3.6",
27
27
  "commitizen": "^4.2.5",
28
28
  "cz-conventional-changelog": "^3.3.0",
29
- "eslint": "^8.23.0",
30
- "eslint-config-holy-grail": "^52.0.29",
29
+ "eslint": "^8.23.1",
30
+ "eslint-config-holy-grail": "^52.0.33",
31
31
  "grunt": "^1.5.3",
32
32
  "grunt-cli": "^1.4.3",
33
33
  "grunt-sh": "^0.2.0",
34
34
  "husky": "^8.0.1",
35
- "karma": "^6.4.0",
35
+ "karma": "^6.4.1",
36
36
  "karma-browserstack-launcher": "^1.6.0",
37
37
  "karma-chrome-launcher": "^3.1.1",
38
38
  "karma-firefox-launcher": "^2.1.2",
@@ -45,14 +45,14 @@
45
45
  "prettier": "^2.7.1",
46
46
  "pretty-quick": "^3.1.3",
47
47
  "rimraf": "^3.0.2",
48
- "rollup": "^2.78.1",
48
+ "rollup": "^2.79.1",
49
49
  "sinon": "^14.0.0",
50
50
  "sinon-chai": "^3.7.0",
51
- "ts-loader": "^9.3.1",
52
- "tsconfig-holy-grail": "^11.1.34",
51
+ "ts-loader": "^9.4.1",
52
+ "tsconfig-holy-grail": "^11.1.36",
53
53
  "tslint": "^6.1.3",
54
- "tslint-config-holy-grail": "^53.2.31",
55
- "typescript": "^4.8.2",
54
+ "tslint-config-holy-grail": "^53.2.33",
55
+ "typescript": "^4.8.3",
56
56
  "webpack": "^5.74.0"
57
57
  },
58
58
  "files": [
@@ -75,5 +75,5 @@
75
75
  "test": "grunt lint && grunt test"
76
76
  },
77
77
  "types": "build/es2019/module.d.ts",
78
- "version": "1.2.5"
78
+ "version": "1.2.7"
79
79
  }
@@ -0,0 +1,2 @@
1
+ export const createComputeVelocity = (timeConstant: number) => (delta: number, minValue: number, maxValue: number, velocity: number) =>
2
+ Math.max(minValue, Math.min(maxValue, ((timeConstant - delta) / timeConstant) * velocity));
@@ -1,26 +1,37 @@
1
- import { TDefaultSetTimingsrcFactory, TSetTimingsrcFunction } from '../types';
1
+ import type { determineSupportedPlaybackRateValues as determineSupportedPlaybackRateValuesFunction } from '../functions/determine-supported-playback-rate-values';
2
+ import type { updateVectorWithNewPosition as updateVectorWithNewPositionFunction } from '../functions/update-vector-with-new-position';
3
+ import { TUpdateFunction, TUpdateVectorWithCustomState } from '../types';
4
+ import type { createComputeVelocity as createComputeVelocityFunction } from './compute-velocity';
5
+ import type { createSetTimingsrc as createSetTimingsrcFunction } from './set-timingsrc';
6
+ import type { createSetTimingsrcWithCustomUpdateFunction } from './set-timingsrc-with-custom-update-function';
7
+ import type { createUpdateGradually as createUpdateGraduallyFunction } from './update-gradually';
8
+ import type { createUpdateStepwiseFactory } from './update-stepwise-factory';
9
+ import type { createWindow } from './window';
2
10
 
3
11
  const DEFAULT_THRESHOLD = 1;
4
12
  const DEFAULT_TIME_CONSTANT = 0.5;
5
13
  const DEFAULT_TOLERANCE = 0.025;
6
14
 
7
- export const createDefaultSetTimingsrc: TDefaultSetTimingsrcFactory = (
8
- createSetTimingsrc,
9
- createUpdateGradually,
10
- createUpdateStepwise,
11
- determineSupportedPlaybackRateValues,
12
- setTimingsrcWithCustomUpdateFunction,
13
- window
14
- ) =>
15
- window !== null && window.navigator.userAgent.includes('Safari') && !window.navigator.userAgent.includes('Chrome')
16
- ? (...args: Parameters<TSetTimingsrcFunction>) =>
17
- createSetTimingsrc(setTimingsrcWithCustomUpdateFunction, createUpdateStepwise(DEFAULT_TOLERANCE))(...args)
18
- : createSetTimingsrc(
19
- setTimingsrcWithCustomUpdateFunction,
20
- createUpdateGradually(
15
+ export const createDefaultSetTimingsrc = (
16
+ createComputeVelocity: typeof createComputeVelocityFunction,
17
+ createSetTimingsrc: typeof createSetTimingsrcFunction,
18
+ createUpdateGradually: typeof createUpdateGraduallyFunction,
19
+ createUpdateStepwise: ReturnType<typeof createUpdateStepwiseFactory>,
20
+ determineSupportedPlaybackRateValues: typeof determineSupportedPlaybackRateValuesFunction,
21
+ setTimingsrcWithCustomUpdateFunction: ReturnType<typeof createSetTimingsrcWithCustomUpdateFunction>,
22
+ updateVectorWithNewPosition: typeof updateVectorWithNewPositionFunction,
23
+ window: ReturnType<typeof createWindow>
24
+ ) => {
25
+ const update =
26
+ window !== null && window.navigator.userAgent.includes('Safari') && !window.navigator.userAgent.includes('Chrome')
27
+ ? createUpdateStepwise(DEFAULT_TOLERANCE)
28
+ : createUpdateGradually(
29
+ createComputeVelocity(DEFAULT_TIME_CONSTANT),
21
30
  determineSupportedPlaybackRateValues(window),
22
- DEFAULT_TIME_CONSTANT,
23
31
  DEFAULT_THRESHOLD,
24
- DEFAULT_TOLERANCE
25
- )
26
- );
32
+ DEFAULT_TOLERANCE,
33
+ updateVectorWithNewPosition
34
+ );
35
+
36
+ return createSetTimingsrc(setTimingsrcWithCustomUpdateFunction, <TUpdateFunction<TUpdateVectorWithCustomState<typeof update>>>update);
37
+ };
@@ -1,7 +1,5 @@
1
- import { TSetCurrentTimeFactory } from '../types';
2
-
3
- export const createSetCurrentTime: TSetCurrentTimeFactory = (currentTimeAssignments) => {
4
- return (mediaElement, previousValue, nextValue) => {
1
+ export const createSetCurrentTime = (currentTimeAssignments: WeakMap<HTMLMediaElement, [number, number]>) => {
2
+ return (mediaElement: HTMLMediaElement, previousValue: number, nextValue: number) => {
5
3
  const currentTimeAssignment = currentTimeAssignments.get(mediaElement);
6
4
 
7
5
  if (
@@ -1,7 +1,5 @@
1
- import { TSetPlaybackRateFactory } from '../types';
2
-
3
- export const createSetPlaybackRate: TSetPlaybackRateFactory = (playbackRateAssignments) => {
4
- return (mediaElement, previousValue, nextValue) => {
1
+ export const createSetPlaybackRate = (playbackRateAssignments: WeakMap<HTMLMediaElement, [number, number]>) => {
2
+ return (mediaElement: HTMLMediaElement, previousValue: number, nextValue: number) => {
5
3
  const playbackRateAssignment = playbackRateAssignments.get(mediaElement);
6
4
 
7
5
  if (
@@ -1,20 +1,35 @@
1
- import { TSetTimingsrcWithCustomUpdateFunctionFactory } from '../types';
1
+ import type { TAnimationFrameFunction, TOnFunction } from 'subscribable-things';
2
+ import type { ITimingObject } from 'timing-object';
3
+ import { IUpdateVector } from '../interfaces';
4
+ import { TPrepareTimingStateVectorFunction, TUpdateFunction } from '../types';
5
+ import type { createUpdateMediaElement } from './update-media-element';
2
6
 
3
- export const createSetTimingsrcWithCustomUpdateFunction: TSetTimingsrcWithCustomUpdateFunctionFactory = (
4
- animationFrame,
5
- document,
6
- on,
7
- updateMediaElement
7
+ export const createSetTimingsrcWithCustomUpdateFunction = (
8
+ animationFrame: TAnimationFrameFunction,
9
+ document: Document,
10
+ on: TOnFunction,
11
+ updateMediaElement: ReturnType<typeof createUpdateMediaElement>
8
12
  ) => {
9
- return (mediaElement, timingObject, updateFunction, prepareTimingStateVector = null) => {
13
+ return <UpdateVectorWithCustomState extends IUpdateVector>(
14
+ mediaElement: HTMLMediaElement,
15
+ timingObject: ITimingObject,
16
+ updateFunction: TUpdateFunction<UpdateVectorWithCustomState>,
17
+ prepareTimingStateVector: null | TPrepareTimingStateVectorFunction = null
18
+ ) => {
19
+ let previousUpdateVectorWithCustomState: null | UpdateVectorWithCustomState = null;
20
+
10
21
  const update = () => {
11
22
  const { currentTime, duration, playbackRate } = mediaElement;
12
23
  const timingStateVector = timingObject.query();
13
- const { position, velocity } = updateFunction(
24
+
25
+ previousUpdateVectorWithCustomState = updateFunction(
14
26
  prepareTimingStateVector === null ? timingStateVector : prepareTimingStateVector(timingStateVector),
15
- currentTime
27
+ currentTime,
28
+ previousUpdateVectorWithCustomState
16
29
  );
30
+
17
31
  const sanitizedDuration = typeof duration === 'number' && !isNaN(duration) ? duration : 0;
32
+ const { position, velocity } = previousUpdateVectorWithCustomState;
18
33
 
19
34
  updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
20
35
  };