import "../styles/reset.css";
import "./affix.less";
import { PropTypes as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__, classes as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_classes__, 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__, getCurrentInstance as __WEBPACK_EXTERNAL_MODULE_vue_getCurrentInstance__, nextTick as __WEBPACK_EXTERNAL_MODULE_vue_nextTick__, onBeforeUnmount as __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__, onMounted as __WEBPACK_EXTERNAL_MODULE_vue_onMounted__, ref as __WEBPACK_EXTERNAL_MODULE_vue_ref__ } from "vue";
import { usePrefix as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__ } from "../config-provider";
import { default as __WEBPACK_EXTERNAL_MODULE_lodash_throttle_a7b7506a_default__ } from "lodash/throttle";

;// external "../shared"

;// external "vue"

;// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
function _typeof(o) {
  "@babel/helpers - typeof";

  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
    return typeof o;
  } : function (o) {
    return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  }, _typeof(o);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js

function toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js


function toPropertyKey(t) {
  var i = toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}

;// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js

function _defineProperty(e, r, t) {
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[r] = t, e;
}

;// external "../config-provider"

;// external "lodash/throttle"

;// ../../packages/affix/src/affix.tsx


function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/*
 * 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 on = function () {
  if (document.addEventListener) {
    return function (element, event, handler) {
      if (element && event && handler) {
        element.addEventListener(event, handler, true);
      }
    };
  }
  return function (element, event, handler) {
    if (element && event && handler) {
      element.attachEvent("on".concat(event), handler);
    }
  };
}();
// 兼容浏览器，移除事件监听器
var off = function () {
  if (document.removeEventListener) {
    return function (element, event, handler) {
      if (element && event) {
        element.removeEventListener(event, handler, true);
      }
    };
  }
  return function (element, event, handler) {
    if (element && event) {
      element.detachEvent("on".concat(event), handler);
    }
  };
}();
/* harmony default export */ const affix = (__WEBPACK_EXTERNAL_MODULE_vue_defineComponent__({
  name: 'Affix',
  props: {
    offsetTop: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(0),
    offsetBottom: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number,
    target: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string.def(''),
    zIndex: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number.def(1000)
  },
  emits: ['change'],
  setup: function setup(props, _ref) {
    var emit = _ref.emit,
      slots = _ref.slots;
    var point = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var root = __WEBPACK_EXTERNAL_MODULE_vue_ref__(null);
    var targetEl = __WEBPACK_EXTERNAL_MODULE_vue_ref__();
    var styles = __WEBPACK_EXTERNAL_MODULE_vue_ref__({});
    var _getCurrentInstance = __WEBPACK_EXTERNAL_MODULE_vue_getCurrentInstance__(),
      proxy = _getCurrentInstance.proxy;
    var affixWidth = __WEBPACK_EXTERNAL_MODULE_vue_ref__(0);
    var offsetStyles = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return _objectSpread(_objectSpread({}, styles.value), {}, {
        'z-index': props.zIndex
      });
    });
    __WEBPACK_EXTERNAL_MODULE_vue_onMounted__(function () {
      affixWidth.value = proxy.$el.offsetWidth;
      targetEl.value = props.target ? document.querySelector(props.target) : window;
      on(targetEl.value, 'scroll', listenScroll);
      on(targetEl.value, 'resize', listenScroll);
      __WEBPACK_EXTERNAL_MODULE_vue_nextTick__(function () {
        handleScroll();
      });
    });
    var _usePrefix = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__(),
      resolveClassName = _usePrefix.resolveClassName;
    var affix = __WEBPACK_EXTERNAL_MODULE_vue_ref__(false);
    var pointClass = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_classes__(_defineProperty({}, "".concat(resolveClassName('affix')), affix.value));
    });
    var offsetType = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return props.offsetBottom >= 0 ? 'bottom' : 'top';
    });
    var setTargetLoop = function setTargetLoop() {
      if (offsetType.value === 'top') {
        styles.value = {
          top: "".concat(targetEl.value.getBoundingClientRect().top + props.offsetTop, "px")
        };
      } else {
        styles.value = {
          bottom: "".concat(window.innerHeight - targetEl.value.getBoundingClientRect().bottom + props.offsetBottom, "px")
        };
      }
    };
    var listenScroll = __WEBPACK_EXTERNAL_MODULE_lodash_throttle_a7b7506a_default__(function () {
      handleScroll();
    }, 100);
    // 获取元素到浏览器边缘的距离
    var getOffset = function getOffset(element) {
      var rect = element.value.getBoundingClientRect();
      var rect2 = targetEl.value === window ? {
        top: 0,
        left: 0
      } : targetEl.value.getBoundingClientRect();
      var clientTop = targetEl.value.clientTop || 0;
      var clientLeft = targetEl.value.clientLeft || 0;
      return {
        top: rect.top - rect2.top - clientTop,
        left: rect.left - rect2.left - clientLeft
      };
    };
    var handleScroll = function handleScroll() {
      var rect = targetEl.value === window ? {
        top: 0,
        left: 0,
        bottom: window.innerHeight
      } : targetEl.value.getBoundingClientRect();
      var elOffset = getOffset(root);
      var windowHeight = targetEl.value === window ? targetEl.value.innerHeight : targetEl.value.clientHeight;
      var elHeight = point.value.offsetHeight;
      // Fixed Top
      if (elOffset.top < props.offsetTop && offsetType.value === 'top' && !affix.value) {
        affix.value = true;
        styles.value = {
          position: 'fixed',
          top: "".concat(rect.top + props.offsetTop, "px"),
          left: "".concat(rect.left + elOffset.left, "px"),
          width: "".concat(affixWidth.value, "px")
        };
        if (targetEl.value !== window) {
          on(window, 'scroll', setTargetLoop);
        }
        emit('change', true);
      } else if (elOffset.top > props.offsetTop && offsetType.value === 'top' && affix.value) {
        affix.value = false;
        styles.value = null;
        emit('change', false);
      }
      // Fixed Bottom
      if (elOffset.top + props.offsetBottom + elHeight > windowHeight && offsetType.value === 'bottom' && !affix.value) {
        affix.value = true;
        styles.value = {
          bottom: "".concat(window.innerHeight - rect.bottom + props.offsetBottom, "px"),
          left: "".concat(rect.left + elOffset.left, "px"),
          width: "".concat(affixWidth.value, "px")
        };
        if (targetEl.value !== window) {
          on(window, 'scroll', setTargetLoop);
        }
        emit('change', true);
      } else if (elOffset.top + props.offsetBottom + elHeight < windowHeight && offsetType.value === 'bottom' && affix.value) {
        affix.value = false;
        styles.value = null;
        emit('change', false);
      }
    };
    __WEBPACK_EXTERNAL_MODULE_vue_onBeforeUnmount__(function () {
      off(targetEl.value, 'scroll', listenScroll);
      off(targetEl.value, 'resize', listenScroll);
      off(window, 'scroll', setTargetLoop);
    });
    return function () {
      var _slots$default;
      return __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
        "ref": root
      }, [__WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
        "ref": point,
        "style": offsetStyles.value,
        "class": pointClass.value
      }, [(_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)])]);
    };
  }
}));
;// ../../packages/affix/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 BkAffix = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__(affix);
/* harmony default export */ const src = (BkAffix);
export { src as default };
