import "../styles/reset.css";
import "./overflow-title.less";
import { PropTypes as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__, debounce as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_debounce__, hasOverflowEllipsis as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_hasOverflowEllipsis__, withInstall as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__ } from "../shared";
import { computed as __WEBPACK_EXTERNAL_MODULE_vue_computed__, createVNode as __WEBPACK_EXTERNAL_MODULE_vue_createVNode__, defineComponent as __WEBPACK_EXTERNAL_MODULE_vue_defineComponent__, mergeProps as __WEBPACK_EXTERNAL_MODULE_vue_mergeProps__, onBeforeUnmount as __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__, onMounted as __WEBPACK_EXTERNAL_MODULE_vue_onMounted__, ref as __WEBPACK_EXTERNAL_MODULE_vue_ref__, shallowRef as __WEBPACK_EXTERNAL_MODULE_vue_shallowRef__ } from "vue";
import { default as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_popover_9b03f19d_default__ } from "../popover";
import "../popover/popover.less";
import { default as __WEBPACK_EXTERNAL_MODULE_lodash_merge_cf99375a_default__ } from "lodash/merge";
import { string as __WEBPACK_EXTERNAL_MODULE_vue_types_22de060a_string__ } from "vue-types";

;// external "../shared"

;// external "vue"

;// external "../popover"

;// external "../popover/popover.less"

;// external "lodash/merge"

;// external "vue-types"

;// ../../packages/overflow-title/src/props.ts
/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */


var PlacementEnum;
(function (PlacementEnum) {
  PlacementEnum["AUTO"] = "auto";
  PlacementEnum["AUTO_END"] = "auto-end";
  PlacementEnum["AUTO_START"] = "auto-start";
  PlacementEnum["BOTTOM"] = "bottom";
  PlacementEnum["BOTTOM_END"] = "bottom-end";
  PlacementEnum["BOTTOM_START"] = "bottom-start";
  PlacementEnum["LEFT"] = "left";
  PlacementEnum["LEFT_END"] = "left-end";
  PlacementEnum["LEFT_START"] = "left-start";
  PlacementEnum["RIGHT"] = "right";
  PlacementEnum["RIGHT_END"] = "right-end";
  PlacementEnum["RIGHT_START"] = "right-start";
  PlacementEnum["TOP"] = "top";
  PlacementEnum["TOP_END"] = "top-end";
  PlacementEnum["TOP_START"] = "top-start";
})(PlacementEnum || (PlacementEnum = {}));
function placementType() {
  return __WEBPACK_EXTERNAL_MODULE_vue_types_22de060a_string__().def(PlacementEnum.BOTTOM);
}
/* harmony default export */ const props = ({
  content: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string,
  type: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOf(['tips', 'title']).def('title'),
  boundary: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string.def('parent'), __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.instanceOf(HTMLElement)]).def(document.body),
  placement: placementType().def(PlacementEnum.TOP_START),
  resizeable: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
  popoverOptions: Object // popover属性
});
;// ../../packages/overflow-title/src/components/overflow-title.tsx
/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */






// import getActualWidthByCanvas from '../utils/getActualWidthByCanvas';
// import getActualWidthByDom from '../utils/getActualWidthByDom';
/* harmony default export */ const overflow_title = (__WEBPACK_EXTERNAL_MODULE_vue_defineComponent__({
  name: 'OverflowTitle',
  props: props,
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var boxRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var textRef = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var isShowTips = __WEBPACK_EXTERNAL_MODULE_vue_ref__(false);
    var textProps = __WEBPACK_EXTERNAL_MODULE_vue_shallowRef__();
    var contentText = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      var _slots$default;
      if (props.content) {
        return props.content;
      }
      return slots === null || slots === void 0 || (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
    });
    __WEBPACK_EXTERNAL_MODULE_vue_onMounted__(function () {
      // const { clientWidth } = boxRef.value;
      var resizeHandler = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_debounce__(500, function () {
        isShowTips.value = false;
        textProps.value = {};
        // let textWidth = 0;
        // if (props.calType === 'dom') {
        //   textWidth = getActualWidthByDom(textRef.value?.textContent, null, boxRef.value);
        // } else {
        //   const { fontSize, fontFamily } = getComputedStyle(boxRef.value);
        //   textWidth = getActualWidthByCanvas(contentText.value as string, { fontSize, fontFamily });
        // }
        if (__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_hasOverflowEllipsis__(textRef.value)) {
          isShowTips.value = true;
          if (props.type === 'title') {
            var _textRef$value$innerT, _textRef$value;
            textProps.value = {
              title: (_textRef$value$innerT = textRef === null || textRef === void 0 || (_textRef$value = textRef.value) === null || _textRef$value === void 0 ? void 0 : _textRef$value.innerText) !== null && _textRef$value$innerT !== void 0 ? _textRef$value$innerT : props.content
            };
          }
        }
      });
      resizeHandler();
      if (props.resizeable) {
        var observer = new ResizeObserver(resizeHandler);
        observer.observe(boxRef.value);
        __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__(function () {
          boxRef.value && (observer === null || observer === void 0 ? void 0 : observer.unobserve(boxRef.value));
          observer === null || observer === void 0 || observer.disconnect();
        });
      }
    });
    return {
      boxRef: boxRef,
      textRef: textRef,
      isShowTips: isShowTips,
      contentText: contentText,
      textProps: textProps
    };
  },
  render: function render() {
    var _this = this;
    /** popover 基础配置 */
    var basePopoverOptions = {
      boundary: this.boundary || document.body,
      placement: this.placement,
      popoverDelay: [200, 0],
      disabled: this.type === 'title' || !this.isShowTips,
      referenceCls: 'overflow-popover-reference'
    };
    var popoverOptions = __WEBPACK_EXTERNAL_MODULE_lodash_merge_cf99375a_default__(basePopoverOptions, this.popoverOptions);
    return __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
      "ref": "boxRef",
      "class": "position-relative"
    }, [__WEBPACK_EXTERNAL_MODULE_vue_createVNode__(__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_popover_9b03f19d_default__, popoverOptions, {
      "default": function _default() {
        return __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", __WEBPACK_EXTERNAL_MODULE_vue_mergeProps__({
          "ref": "textRef",
          "class": "text-ov"
        }, _this.textProps), [_this.contentText]);
      },
      content: function content() {
        return _this.contentText;
      }
    })]);
  }
}));
;// ../../packages/overflow-title/src/utils/getActualWidthByCanvas.ts
function getActualWidthByCanvas(text, options) {
  var _options$fontSize = options.fontSize,
    fontSize = _options$fontSize === void 0 ? 14 : _options$fontSize,
    _options$fontFamily = options.fontFamily,
    fontFamily = _options$fontFamily === void 0 ? 'Microsoft YaHei' : _options$fontFamily;
  var canvas = document.createElement('canvas');
  var ctx = canvas.getContext('2d');
  ctx.font = "".concat(fontSize, "px ").concat(fontFamily);
  var metrics = ctx.measureText(text);
  var actual = Math.abs(metrics.actualBoundingBoxLeft) + Math.abs(metrics.actualBoundingBoxRight);
  return Math.max(metrics.width, actual);
}
/* harmony default export */ const utils_getActualWidthByCanvas = (getActualWidthByCanvas);
;// ../../packages/overflow-title/src/utils/getActualWidthByDom.ts
function getActualWidthByDom(text, options) {
  var dom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.body;
  if (!dom) {
    return 0;
  }
  var _ref = options || {},
    fontSize = _ref.fontSize,
    fontFamily = _ref.fontFamily;
  var tempDom = document.createElement('div');
  tempDom.style.cssText = "position: absolute;left: -999em;top:-999em;z-index: -1;text-overflow: initial;\n    ".concat(fontSize ? "font-size:".concat(fontSize, " ;") : '', "\n    ").concat(fontFamily ? "font-family:".concat(fontFamily, " ") : '', "\n  ");
  tempDom.innerText = text;
  dom.append(tempDom);
  var clientWidth = tempDom.clientWidth;
  dom.removeChild(tempDom);
  return clientWidth;
}
/* harmony default export */ const utils_getActualWidthByDom = (getActualWidthByDom);
;// ../../packages/overflow-title/src/directive/overflow-title.ts


var overflowTitle = {
  mounted: function mounted(el, _ref) {
    var _ref$value = _ref.value,
      value = _ref$value === void 0 ? {} : _ref$value;
    var clientWidth = el.parentElement.clientWidth;
    if (!clientWidth) {
      return;
    }
    var content = value.content,
      _value$calType = value.calType,
      calType = _value$calType === void 0 ? 'dom' : _value$calType;
    var text = content || el.innerText;
    var textWidth = 0;
    if (calType === 'dom') {
      textWidth = utils_getActualWidthByDom(el.textContent, null, el.parentElement);
    } else {
      var _getComputedStyle = getComputedStyle(el),
        fontSize = _getComputedStyle.fontSize,
        fontFamily = _getComputedStyle.fontFamily;
      textWidth = utils_getActualWidthByCanvas(text, {
        fontSize: fontSize,
        fontFamily: fontFamily
      });
    }
    if (textWidth > clientWidth) {
      el.setAttribute('title', text);
    }
  }
};
/* harmony default export */ const directive_overflow_title = (overflowTitle);
;// ../../packages/overflow-title/src/index.ts
/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */





var BkOverflowTitle = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__(overflow_title);

/* harmony default export */ const src = (BkOverflowTitle);
export { overflow_title as OverflowTitle, src as default, utils_getActualWidthByCanvas as getActualWidthByCanvas, utils_getActualWidthByDom as getActualWidthByDom, directive_overflow_title as overflowTitle };
