util.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import slide from 'assets/json/slideSettings/slide.json'
  21. import { ISlideParams } from 'containers/Viz/types'
  22. import { ILayerParams } from './types'
  23. export { computeEditorBaselines } from './Container/Slide/util'
  24. export { setLayersAlignment } from './Setting/Alignment/util'
  25. import { GraphTypes, SecondaryGraphTypes, slideSettings } from './constants'
  26. export function getDefaultSlideParams() {
  27. const params = (slide as any).params
  28. const defaultSlideParams = {}
  29. params.forEach((param) => {
  30. param.items.forEach((item) => {
  31. defaultSlideParams[item.name] = item.default || null
  32. })
  33. })
  34. return defaultSlideParams as ISlideParams
  35. }
  36. export function getDefaultLayerSetting(
  37. graphType: GraphTypes,
  38. secondaryGraphType?: SecondaryGraphTypes
  39. ) {
  40. const defaultSetting = {}
  41. const type = secondaryGraphType || graphType
  42. const setting = slideSettings[type]
  43. if (!setting) {
  44. return defaultSetting as ILayerParams
  45. }
  46. setting.params.forEach((param) => {
  47. param.items.forEach((item) => {
  48. defaultSetting[item.name] = item.default || null
  49. })
  50. })
  51. return defaultSetting as ILayerParams
  52. }
  53. export const captureVideosWithImages = (canvasDom) => {
  54. const canvas = canvasDom || document.createElement('canvas')
  55. const ctx = canvas.getContext('2d')
  56. const videos = document.querySelectorAll('video')
  57. Array.prototype.forEach.call(videos, (v) => {
  58. if (!v.src) {
  59. return
  60. }
  61. try {
  62. const { videoWidth, videoHeight } = v
  63. canvas.width = videoWidth
  64. canvas.height = videoHeight
  65. ctx.fillRect(0, 0, videoWidth, videoHeight)
  66. ctx.drawImage(v, 0, 0, videoWidth, videoHeight)
  67. v.style.backgroundImage = `url(${canvas.toDataURL()})`
  68. v.style.backgroundSize = 'cover'
  69. console.log('v.style: ', v.style)
  70. ctx.clearRect(0, 0, videoWidth, videoHeight)
  71. } catch (e) {
  72. console.log('e: ', e)
  73. return
  74. }
  75. })
  76. }