text: /*
   * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
   * under one or more contributor license agreements. See the NOTICE file
   * distributed with this work for additional information regarding copyright
   * ownership. Camunda licenses this file to you under the Apache License,
   * Version 2.0; you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  import BaseRenderer from 'diagram-js/lib/draw/BaseRenderer';
  
  import {
    append as svgAppend,
    attr as svgAttr,
    create as svgCreate,
    remove as svgRemove
  } from 'tiny-svg';
  
  import {
    getRoundRectPath
  } from 'bpmn-js/lib/draw/BpmnRenderUtil';
  
  import { is } from 'bpmn-js/lib/util/ModelUtil';
  import { isAny } from 'bpmn-js/lib/features/modeling/util/ModelingUtil';
  
  const HIGH_PRIORITY = 1500,
        TASK_BORDER_RADIUS = 2;
  
  
  export default class CustomRenderer extends BaseRenderer {
    constructor(eventBus, bpmnRenderer) {
      super(eventBus, HIGH_PRIORITY);
  
      this.bpmnRenderer = bpmnRenderer;
    }
  
    canRender(element) {
  
      // only render tasks and events (ignore labels)
      return isAny(element, [ 'bpmn:Task', 'bpmn:Event' ]) && !element.labelTarget;
    }
  
    drawShape(parentNode, element) {
      const shape = this.bpmnRenderer.drawShape(parentNode, element);
  
      if (is(element, 'bpmn:Task')) {
        const rect = drawRect(parentNode, 100, 80, TASK_BORDER_RADIUS, '#52B415');
  
        prependTo(rect, parentNode);
  
        svgRemove(shape);
  
        return shape;
      }
  
      const rect = drawRect(parentNode, 30, 20, TASK_BORDER_RADIUS, '#cc0000');
  
      svgAttr(rect, {
        transform: 'translate(-20, -10)'
      });
  
      return shape;
    }
  
    getShapePath(shape) {
      if (is(shape, 'bpmn:Task')) {
        return getRoundRectPath(shape, TASK_BORDER_RADIUS);
      }
  
      return this.bpmnRenderer.getShapePath(shape);
    }
  }
  
  CustomRenderer.$inject = [ 'eventBus', 'bpmnRenderer' ];
  
  // helpers //////////
  
  // copied from https://github.com/bpmn-io/bpmn-js/blob/master/lib/draw/BpmnRenderer.js
  function drawRect(parentNode, width, height, borderRadius, strokeColor) {
    const rect = svgCreate('rect');
  
    svgAttr(rect, {
      width: width,
      height: height,
      rx: borderRadius,
      ry: borderRadius,
      stroke: strokeColor || '#000',
      strokeWidth: 2,
      fill: '#fff'
    });
  
    svgAppend(parentNode, rect);
  
    return rect;
  }
  
  // copied from https://github.com/bpmn-io/diagram-js/blob/master/lib/core/GraphicsFactory.js
  function prependTo(newNode, parentNode, siblingNode) {
    parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild);
  }
  