{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/post-processes/post-process-stage-collection/index.ts"],"sourcesContent":["/*\n * @Author: zouyaoji@https://github.com/zouyaoji\n * @Date: 2021-09-16 09:28:13\n * @LastEditTime: 2022-03-30 13:39:37\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\vue-cesium@next\\packages\\components\\post-processes\\post-process-stage-collection\\index.ts\n */\nimport type { WatchStopHandle, PropType, VNode } from 'vue'\nimport { createCommentVNode, defineComponent, getCurrentInstance, h, onUnmounted, watch } from 'vue'\nimport type { VcComponentInternalInstance, VcComponentPublicInstance, VcReadyObject } from '@vue-cesium/utils/types'\nimport { useCommon } from '@vue-cesium/composables/index'\nimport { kebabCase } from '@vue-cesium/utils/util'\nimport { hSlot } from '@vue-cesium/utils/private/render'\nimport { commonEmits } from '@vue-cesium/utils/emits'\nimport type { VcPostProcessStageProps } from '../post-process-stage'\n\nexport const postProcessStageCollectionProps = {\n  postProcesses: {\n    type: Array as PropType<Array<VcPostProcessStageProps>>,\n    default: () => []\n  }\n}\nexport default defineComponent({\n  name: 'VcPostProcessStageCollection',\n  props: postProcessStageCollectionProps,\n  emits: commonEmits,\n  setup(props, ctx) {\n    // state\n    const instance = getCurrentInstance() as VcComponentInternalInstance\n    instance.cesiumClass = 'PostProcessStageCollection'\n    instance.cesiumEvents = []\n    const commonState = useCommon(props, ctx, instance)\n    if (commonState === void 0) {\n      return\n    }\n    const { $services } = commonState\n    const stages: Array<Cesium.PostProcessStage | Cesium.PostProcessStageComposite> = []\n    let unwatchFns: Array<WatchStopHandle> = []\n    // watch\n    unwatchFns.push(\n      watch(\n        () => props.postProcesses,\n        val => {\n          if (instance.mounted) {\n            ;(instance.proxy as VcComponentPublicInstance).reload?.()\n          }\n        },\n        { deep: true }\n      )\n    )\n\n    // methods\n    instance.createCesiumObject = async () => {\n      return stages\n    }\n\n    instance.mount = async () => {\n      const { postProcessStages } = $services\n      props.postProcesses.forEach(postProcess => {\n        const opts = commonState.transformProps(postProcess)\n        stages.push(postProcessStages.add(new Cesium.PostProcessStage(opts as any)))\n      })\n      return true\n    }\n\n    instance.unmount = async () => {\n      const { postProcessStages } = $services\n      stages.forEach(stage => {\n        postProcessStages.remove(stage)\n      })\n      stages.length = 0\n      return true\n    }\n\n    // life cycle\n    onUnmounted(() => {\n      unwatchFns.forEach(item => item())\n      unwatchFns = []\n    })\n\n    return () =>\n      ctx.slots.default\n        ? h(\n            'i',\n            {\n              class: kebabCase(instance.proxy?.$options.name || ''),\n              style: { display: 'none !important' }\n            },\n            hSlot(ctx.slots.default)\n          )\n        : createCommentVNode(kebabCase(instance.proxy?.$options.name || ''))\n  }\n})\n\nexport type VcPostProcessStageCollectionProps = {\n  /**\n   * Specify the post-processing collection. The props are consistent with [`vc-post-process-stage`](https://zouyaoji.top/vue-cesium/#/en-US/component/post-processes/vc-post-process-stage#props).\n   */\n  postProcesses?: Array<VcPostProcessStageProps>\n  /**\n   * Triggers before the component is loaded.\n   */\n  onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the component is successfully loaded.\n   */\n  onReady?: (readyObject: VcReadyObject) => void\n  /**\n   * Triggers when the component load failed.\n   */\n  onUnready?: (e: any) => void\n  /**\n   * Triggers when the component is destroyed.\n   */\n  onDestroyed?: (instance: VcComponentInternalInstance) => void\n}\n\nexport type VcPostProcessStageCollectionRef = VcComponentPublicInstance<VcPostProcessStageCollectionProps>\n\nexport type VcPostProcessStageCollectionSlots = {\n  /**\n   * Slot for vc-post-process-stage-scan, vc-post-process-stage\n   */\n  default: () => VNode[]\n}\n"],"names":[],"mappings":";;;;;;;;AAiBO,MAAM,+BAAkC,GAAA;AAAA,EAC7C,aAAe,EAAA;AAAA,IACb,IAAM,EAAA,KAAA;AAAA,IACN,OAAA,EAAS,MAAM,EAAC;AAAA,GAClB;AACF,EAAA;AACA,iCAAe,eAAgB,CAAA;AAAA,EAC7B,IAAM,EAAA,8BAAA;AAAA,EACN,KAAO,EAAA,+BA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