This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import Anchor from './src/anchor.vue';
import AnchorLink from './src/anchor-link.vue';
import type { SFCWithInstall } from 'element-plus/es/utils';
export declare const ElAnchor: SFCWithInstall<typeof Anchor> & {
AnchorLink: typeof AnchorLink;
};
export declare const ElAnchorLink: SFCWithInstall<typeof AnchorLink>;
export default ElAnchor;
export * from './src/anchor';

View File

@@ -0,0 +1,20 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var anchor$1 = require('./src/anchor2.js');
var anchorLink = require('./src/anchor-link2.js');
var anchor = require('./src/anchor.js');
var install = require('../../utils/vue/install.js');
const ElAnchor = install.withInstall(anchor$1["default"], {
AnchorLink: anchorLink["default"]
});
const ElAnchorLink = install.withNoopInstall(anchorLink["default"]);
exports.anchorEmits = anchor.anchorEmits;
exports.anchorProps = anchor.anchorProps;
exports.ElAnchor = ElAnchor;
exports.ElAnchorLink = ElAnchorLink;
exports["default"] = ElAnchor;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../../packages/components/anchor/index.ts"],"sourcesContent":["import { withInstall, withNoopInstall } from '@element-plus/utils'\nimport Anchor from './src/anchor.vue'\nimport AnchorLink from './src/anchor-link.vue'\n\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nexport const ElAnchor: SFCWithInstall<typeof Anchor> & {\n AnchorLink: typeof AnchorLink\n} = withInstall(Anchor, {\n AnchorLink,\n})\nexport const ElAnchorLink: SFCWithInstall<typeof AnchorLink> =\n withNoopInstall(AnchorLink)\nexport default ElAnchor\n\nexport * from './src/anchor'\n"],"names":["withInstall","Anchor","AnchorLink","withNoopInstall"],"mappings":";;;;;;;;;AAGY,MAAC,QAAQ,GAAGA,mBAAW,CAACC,mBAAM,EAAE;AAC5C,cAAEC,qBAAU;AACZ,CAAC,EAAE;AACS,MAAC,YAAY,GAAGC,uBAAe,CAACD,qBAAU;;;;;;;;"}

View File

@@ -0,0 +1,7 @@
import type { ExtractPropTypes, __ExtractPublicPropTypes } from 'vue';
export declare const anchorLinkProps: {
title: StringConstructor;
href: StringConstructor;
};
export type AnchorLinkProps = ExtractPropTypes<typeof anchorLinkProps>;
export type AnchorLinkPropsPublic = __ExtractPublicPropTypes<typeof anchorLinkProps>;

View File

@@ -0,0 +1,13 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var runtime = require('../../../utils/vue/props/runtime.js');
const anchorLinkProps = runtime.buildProps({
title: String,
href: String
});
exports.anchorLinkProps = anchorLinkProps;
//# sourceMappingURL=anchor-link.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"anchor-link.js","sources":["../../../../../../packages/components/anchor/src/anchor-link.ts"],"sourcesContent":["import { buildProps } from '@element-plus/utils'\n\nimport type { ExtractPropTypes, __ExtractPublicPropTypes } from 'vue'\n\nexport const anchorLinkProps = buildProps({\n /**\n * @description the text content of the anchor link\n */\n title: String,\n /**\n * @description The address of the anchor link\n */\n href: String,\n})\n\nexport type AnchorLinkProps = ExtractPropTypes<typeof anchorLinkProps>\nexport type AnchorLinkPropsPublic = __ExtractPublicPropTypes<\n typeof anchorLinkProps\n>\n"],"names":["buildProps"],"mappings":";;;;;;AACY,MAAC,eAAe,GAAGA,kBAAU,CAAC;AAC1C,EAAE,KAAK,EAAE,MAAM;AACf,EAAE,IAAI,EAAE,MAAM;AACd,CAAC;;;;"}

View File

@@ -0,0 +1,18 @@
declare function __VLS_template(): {
default?(_: {}): any;
"sub-link"?(_: {}): any;
};
declare const __VLS_component: import("vue").DefineComponent<{
title: StringConstructor;
href: StringConstructor;
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
title: StringConstructor;
href: StringConstructor;
}>>, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};

View File

@@ -0,0 +1,89 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var anchorLink = require('./anchor-link.js');
var constants = require('./constants.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
const __default__ = vue.defineComponent({
name: "ElAnchorLink"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: anchorLink.anchorLinkProps,
setup(__props) {
const props = __props;
const linkRef = vue.ref(null);
const {
ns,
direction,
currentAnchor,
addLink,
removeLink,
handleClick: contextHandleClick
} = vue.inject(constants.anchorKey);
const cls = vue.computed(() => [
ns.e("link"),
ns.is("active", currentAnchor.value === props.href)
]);
const handleClick = (e) => {
contextHandleClick(e, props.href);
};
vue.watch(() => props.href, (val, oldVal) => {
vue.nextTick(() => {
if (oldVal)
removeLink(oldVal);
if (val) {
addLink({
href: val,
el: linkRef.value
});
}
});
});
vue.onMounted(() => {
const { href } = props;
if (href) {
addLink({
href,
el: linkRef.value
});
}
});
vue.onBeforeUnmount(() => {
const { href } = props;
if (href) {
removeLink(href);
}
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass(vue.unref(ns).e("item"))
}, [
vue.createElementVNode("a", {
ref_key: "linkRef",
ref: linkRef,
class: vue.normalizeClass(vue.unref(cls)),
href: _ctx.href,
onClick: handleClick
}, [
vue.renderSlot(_ctx.$slots, "default", {}, () => [
vue.createTextVNode(vue.toDisplayString(_ctx.title), 1)
])
], 10, ["href"]),
_ctx.$slots["sub-link"] && vue.unref(direction) === "vertical" ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: vue.normalizeClass(vue.unref(ns).e("list"))
}, [
vue.renderSlot(_ctx.$slots, "sub-link")
], 2)) : vue.createCommentVNode("v-if", true)
], 2);
};
}
});
var AnchorLink = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "anchor-link.vue"]]);
exports["default"] = AnchorLink;
//# sourceMappingURL=anchor-link2.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"anchor-link2.js","sources":["../../../../../../packages/components/anchor/src/anchor-link.vue"],"sourcesContent":["<template>\n <div :class=\"ns.e('item')\">\n <a ref=\"linkRef\" :class=\"cls\" :href=\"href\" @click=\"handleClick\">\n <slot>{{ title }}</slot>\n </a>\n <div\n v-if=\"$slots['sub-link'] && direction === 'vertical'\"\n :class=\"ns.e('list')\"\n >\n <slot name=\"sub-link\" />\n </div>\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n computed,\n inject,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n} from 'vue'\nimport { anchorLinkProps } from './anchor-link'\nimport { anchorKey } from './constants'\n\ndefineOptions({\n name: 'ElAnchorLink',\n})\n\nconst props = defineProps(anchorLinkProps)\n\nconst linkRef = ref<HTMLElement | null>(null)\n\nconst {\n ns,\n direction,\n currentAnchor,\n addLink,\n removeLink,\n handleClick: contextHandleClick,\n} = inject(anchorKey)!\n\nconst cls = computed(() => [\n ns.e('link'),\n ns.is('active', currentAnchor.value === props.href),\n])\n\nconst handleClick = (e: MouseEvent) => {\n contextHandleClick(e, props.href)\n}\n\nwatch(\n () => props.href,\n (val, oldVal) => {\n nextTick(() => {\n if (oldVal) removeLink(oldVal)\n if (val) {\n addLink({\n href: val,\n el: linkRef.value!,\n })\n }\n })\n }\n)\n\nonMounted(() => {\n const { href } = props\n if (href) {\n addLink({\n href,\n el: linkRef.value!,\n })\n }\n})\n\nonBeforeUnmount(() => {\n const { href } = props\n if (href) {\n removeLink(href)\n }\n})\n</script>\n"],"names":["ref","inject","anchorKey","computed","watch","nextTick","onMounted","onBeforeUnmount","_openBlock","_createElementBlock"],"mappings":";;;;;;;;;uCA2Bc,CAAA;AAAA,EACZ,IAAM,EAAA,cAAA;AACR,CAAA,CAAA,CAAA;;;;;;AAIA,IAAM,MAAA,OAAA,GAAUA,QAAwB,IAAI,CAAA,CAAA;AAE5C,IAAM,MAAA;AAAA,MACJ,EAAA;AAAA,MACA,SAAA;AAAA,MACA,aAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAa,EAAA,kBAAA;AAAA,KACf,GAAIC,WAAOC,mBAAS,CAAA,CAAA;AAEpB,IAAM,MAAA,GAAA,GAAMC,aAAS,MAAM;AAAA,MACzB,EAAA,CAAG,EAAE,MAAM,CAAA;AAAA,MACX,GAAG,EAAG,CAAA,QAAA,EAAU,aAAc,CAAA,KAAA,KAAU,MAAM,IAAI,CAAA;AAAA,KACnD,CAAA,CAAA;AAED,IAAM,MAAA,WAAA,GAAc,CAAC,CAAkB,KAAA;AACrC,MAAmB,kBAAA,CAAA,CAAA,EAAG,MAAM,IAAI,CAAA,CAAA;AAAA,KAClC,CAAA;AAEA,IAAAC,SAAA,CAAA,MAAA,KAAA,CAAA,IAAA,EAAA,CAAA,GAAA,EAAA,MAAA,KAAA;AAAA,MACEC,YAAY,CAAA,MAAA;AAAA,YACN,MAAW;AACf,UAAA,UAAe,CAAA,MAAA,CAAA,CAAA;AACb,QAAI,IAAA,GAAA,EAAA;AACJ,UAAA,OAAS,CAAA;AACP,YAAQ,IAAA,EAAA,GAAA;AAAA,YAAA,EACN,EAAM,OAAA,CAAA,KAAA;AAAA,WAAA,CAAA,CAAA;AACM,SAAA;AACb,OACH,CAAA,CAAA;AAAA,KAAA,CAAA,CAAA;AACD,IACHC,aAAA,CAAA,MAAA;AAAA,MACF,MAAA,EAAA,IAAA,EAAA,GAAA,KAAA,CAAA;AAEA,MAAA,IAAA,IAAU,EAAM;AACd,QAAM;AACN,UAAI,IAAM;AACR,UAAQ,EAAA,EAAA,OAAA,CAAA,KAAA;AAAA,SACN,CAAA,CAAA;AAAA,OAAA;AACY,KAAA,CAAA,CAAA;AACb,IACHC,mBAAA,CAAA,MAAA;AAAA,MACD,MAAA,EAAA,IAAA,EAAA,GAAA,KAAA,CAAA;AAED,MAAA,IAAA,IAAA,EAAA;AACE,QAAM,WAAO,IAAI,CAAA,CAAA;AACjB,OAAA;AACE,KAAA,CAAA,CAAA;AAAe,IACjB,OAAA,CAAA,IAAA,EAAA,MAAA,KAAA;AAAA,MACD,OAAAC,aAAA,EAAA,EAAAC,sBAAA,CAAA,KAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}

View File

@@ -0,0 +1,25 @@
import type { ExtractPropTypes, __ExtractPublicPropTypes } from 'vue';
import type Anchor from './anchor.vue';
export declare const anchorProps: {
container: {
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null) | ((new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
bound: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
marker: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
type: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "default" | "underline") | (() => "default" | "underline") | ((new (...args: any[]) => "default" | "underline") | (() => "default" | "underline"))[], unknown, unknown, string, boolean>;
direction: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical") | ((new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical"))[], unknown, unknown, string, boolean>;
selectScrollTop: BooleanConstructor;
};
export type AnchorProps = ExtractPropTypes<typeof anchorProps>;
export type AnchorPropsPublic = __ExtractPublicPropTypes<typeof anchorProps>;
export type AnchorInstance = InstanceType<typeof Anchor> & unknown;
export declare const anchorEmits: {
change: (href: string) => boolean;
click: (e: MouseEvent, href?: string) => boolean;
};
export type AnchorEmits = typeof anchorEmits;

View File

@@ -0,0 +1,49 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var runtime = require('../../../utils/vue/props/runtime.js');
var shared = require('@vue/shared');
var types = require('../../../utils/types.js');
const anchorProps = runtime.buildProps({
container: {
type: runtime.definePropType([
String,
Object
])
},
offset: {
type: Number,
default: 0
},
bound: {
type: Number,
default: 15
},
duration: {
type: Number,
default: 300
},
marker: {
type: Boolean,
default: true
},
type: {
type: runtime.definePropType(String),
default: "default"
},
direction: {
type: runtime.definePropType(String),
default: "vertical"
},
selectScrollTop: Boolean
});
const anchorEmits = {
change: (href) => shared.isString(href),
click: (e, href) => e instanceof MouseEvent && (shared.isString(href) || types.isUndefined(href))
};
exports.anchorEmits = anchorEmits;
exports.anchorProps = anchorProps;
//# sourceMappingURL=anchor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"anchor.js","sources":["../../../../../../packages/components/anchor/src/anchor.ts"],"sourcesContent":["import {\n buildProps,\n definePropType,\n isString,\n isUndefined,\n} from '@element-plus/utils'\n\nimport type { ExtractPropTypes, __ExtractPublicPropTypes } from 'vue'\nimport type Anchor from './anchor.vue'\n\nexport const anchorProps = buildProps({\n /**\n * @description scroll container\n */\n container: {\n type: definePropType<string | HTMLElement | Window | null>([\n String,\n Object,\n ]),\n },\n /**\n * @description Set the offset of the anchor scroll\n */\n offset: {\n type: Number,\n default: 0,\n },\n /**\n * @description The offset of the element starting to trigger the anchor\n */\n bound: {\n type: Number,\n default: 15,\n },\n /**\n * @description Set the scroll duration of the container when the anchor is clicked, in milliseconds\n */\n duration: {\n type: Number,\n default: 300,\n },\n /**\n * @description Whether to show the marker\n */\n marker: {\n type: Boolean,\n default: true,\n },\n /**\n * @description Set Anchor type\n */\n type: {\n type: definePropType<'default' | 'underline'>(String),\n default: 'default',\n },\n /**\n * @description Set Anchor direction\n */\n direction: {\n type: definePropType<'vertical' | 'horizontal'>(String),\n default: 'vertical',\n },\n /**\n * @description Scroll whether link is selected at the top\n */\n selectScrollTop: Boolean,\n})\n\nexport type AnchorProps = ExtractPropTypes<typeof anchorProps>\nexport type AnchorPropsPublic = __ExtractPublicPropTypes<typeof anchorProps>\nexport type AnchorInstance = InstanceType<typeof Anchor> & unknown\n\nexport const anchorEmits = {\n change: (href: string) => isString(href),\n click: (e: MouseEvent, href?: string) =>\n e instanceof MouseEvent && (isString(href) || isUndefined(href)),\n}\nexport type AnchorEmits = typeof anchorEmits\n"],"names":["buildProps","definePropType","isString","isUndefined"],"mappings":";;;;;;;;AAMY,MAAC,WAAW,GAAGA,kBAAU,CAAC;AACtC,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAEC,sBAAc,CAAC;AACzB,MAAM,MAAM;AACZ,MAAM,MAAM;AACZ,KAAK,CAAC;AACN,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,EAAE;AACf,GAAG;AACH,EAAE,QAAQ,EAAE;AACZ,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,GAAG;AAChB,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,OAAO;AACjB,IAAI,OAAO,EAAE,IAAI;AACjB,GAAG;AACH,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAEA,sBAAc,CAAC,MAAM,CAAC;AAChC,IAAI,OAAO,EAAE,SAAS;AACtB,GAAG;AACH,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAEA,sBAAc,CAAC,MAAM,CAAC;AAChC,IAAI,OAAO,EAAE,UAAU;AACvB,GAAG;AACH,EAAE,eAAe,EAAE,OAAO;AAC1B,CAAC,EAAE;AACS,MAAC,WAAW,GAAG;AAC3B,EAAE,MAAM,EAAE,CAAC,IAAI,KAAKC,eAAQ,CAAC,IAAI,CAAC;AAClC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,YAAY,UAAU,KAAKA,eAAQ,CAAC,IAAI,CAAC,IAAIC,iBAAW,CAAC,IAAI,CAAC,CAAC;AACtF;;;;;"}

View File

@@ -0,0 +1,55 @@
declare function __VLS_template(): {
default?(_: {}): any;
};
declare const __VLS_component: import("vue").DefineComponent<{
container: {
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null) | ((new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
bound: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
marker: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
type: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "default" | "underline") | (() => "default" | "underline") | ((new (...args: any[]) => "default" | "underline") | (() => "default" | "underline"))[], unknown, unknown, string, boolean>;
direction: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical") | ((new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical"))[], unknown, unknown, string, boolean>;
selectScrollTop: BooleanConstructor;
}, {
scrollTo: (href?: string) => void;
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
click: (e: MouseEvent, href?: string | undefined) => void;
change: (href: string) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
container: {
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null) | ((new (...args: any[]) => string | HTMLElement | Window) | (() => string | HTMLElement | Window | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
bound: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, number, boolean>;
marker: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
type: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "default" | "underline") | (() => "default" | "underline") | ((new (...args: any[]) => "default" | "underline") | (() => "default" | "underline"))[], unknown, unknown, string, boolean>;
direction: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical") | ((new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical"))[], unknown, unknown, string, boolean>;
selectScrollTop: BooleanConstructor;
}>> & {
onChange?: ((href: string) => any) | undefined;
onClick?: ((e: MouseEvent, href?: string | undefined) => any) | undefined;
}, {
marker: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
direction: import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical") | ((new (...args: any[]) => "horizontal" | "vertical") | (() => "horizontal" | "vertical"))[], unknown, unknown>;
offset: number;
type: import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => "default" | "underline") | (() => "default" | "underline") | ((new (...args: any[]) => "default" | "underline") | (() => "default" | "underline"))[], unknown, unknown>;
duration: number;
bound: number;
selectScrollTop: boolean;
}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};

View File

@@ -0,0 +1,215 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
var anchor = require('./anchor.js');
var constants = require('./constants.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var element = require('../../../utils/dom/element.js');
var throttleByRaf = require('../../../utils/throttleByRaf.js');
var scroll = require('../../../utils/dom/scroll.js');
var position = require('../../../utils/dom/position.js');
var index = require('../../../hooks/use-namespace/index.js');
var types = require('../../../utils/types.js');
var event = require('../../../constants/event.js');
const __default__ = vue.defineComponent({
name: "ElAnchor"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: anchor.anchorProps,
emits: anchor.anchorEmits,
setup(__props, { expose, emit }) {
const props = __props;
const slots = vue.useSlots();
const currentAnchor = vue.ref("");
const markerStyle = vue.ref({});
const anchorRef = vue.ref(null);
const markerRef = vue.ref(null);
const containerEl = vue.ref();
const links = {};
let isScrolling = false;
let currentScrollTop = 0;
const ns = index.useNamespace("anchor");
const cls = vue.computed(() => [
ns.b(),
props.type === "underline" ? ns.m("underline") : "",
ns.m(props.direction)
]);
const addLink = (state) => {
links[state.href] = state.el;
};
const removeLink = (href) => {
delete links[href];
};
const setCurrentAnchor = (href) => {
const activeHref = currentAnchor.value;
if (activeHref !== href) {
currentAnchor.value = href;
emit(event.CHANGE_EVENT, href);
}
};
let clearAnimate = null;
const scrollToAnchor = (href) => {
if (!containerEl.value)
return;
const target = element.getElement(href);
if (!target)
return;
if (clearAnimate)
clearAnimate();
isScrolling = true;
const scrollEle = scroll.getScrollElement(target, containerEl.value);
const distance = position.getOffsetTopDistance(target, scrollEle);
const max = scrollEle.scrollHeight - scrollEle.clientHeight;
const to = Math.min(distance - props.offset, max);
clearAnimate = scroll.animateScrollTo(containerEl.value, currentScrollTop, to, props.duration, () => {
setTimeout(() => {
isScrolling = false;
}, 20);
});
};
const scrollTo = (href) => {
if (href) {
setCurrentAnchor(href);
scrollToAnchor(href);
}
};
const handleClick = (e, href) => {
emit("click", e, href);
scrollTo(href);
};
const handleScroll = throttleByRaf.throttleByRaf(() => {
if (containerEl.value) {
currentScrollTop = scroll.getScrollTop(containerEl.value);
}
const currentHref = getCurrentHref();
if (isScrolling || types.isUndefined(currentHref))
return;
setCurrentAnchor(currentHref);
});
const getCurrentHref = () => {
if (!containerEl.value)
return;
const scrollTop = scroll.getScrollTop(containerEl.value);
const anchorTopList = [];
for (const href of Object.keys(links)) {
const target = element.getElement(href);
if (!target)
continue;
const scrollEle = scroll.getScrollElement(target, containerEl.value);
const distance = position.getOffsetTopDistance(target, scrollEle);
anchorTopList.push({
top: distance - props.offset - props.bound,
href
});
}
anchorTopList.sort((prev, next) => prev.top - next.top);
for (let i = 0; i < anchorTopList.length; i++) {
const item = anchorTopList[i];
const next = anchorTopList[i + 1];
if (i === 0 && scrollTop === 0) {
return props.selectScrollTop ? item.href : "";
}
if (item.top <= scrollTop && (!next || next.top > scrollTop)) {
return item.href;
}
}
};
const getContainer = () => {
const el = element.getElement(props.container);
if (!el || types.isWindow(el)) {
containerEl.value = window;
} else {
containerEl.value = el;
}
};
core.useEventListener(containerEl, "scroll", handleScroll);
const updateMarkerStyle = () => {
vue.nextTick(() => {
if (!anchorRef.value || !markerRef.value || !currentAnchor.value) {
markerStyle.value = {};
return;
}
const currentLinkEl = links[currentAnchor.value];
if (!currentLinkEl) {
markerStyle.value = {};
return;
}
const anchorRect = anchorRef.value.getBoundingClientRect();
const markerRect = markerRef.value.getBoundingClientRect();
const linkRect = currentLinkEl.getBoundingClientRect();
if (props.direction === "horizontal") {
const left = linkRect.left - anchorRect.left;
markerStyle.value = {
left: `${left}px`,
width: `${linkRect.width}px`,
opacity: 1
};
} else {
const top = linkRect.top - anchorRect.top + (linkRect.height - markerRect.height) / 2;
markerStyle.value = {
top: `${top}px`,
opacity: 1
};
}
});
};
vue.watch(currentAnchor, updateMarkerStyle);
vue.watch(() => {
var _a;
return (_a = slots.default) == null ? void 0 : _a.call(slots);
}, updateMarkerStyle);
vue.onMounted(() => {
getContainer();
const hash = decodeURIComponent(window.location.hash);
const target = element.getElement(hash);
if (target) {
scrollTo(hash);
} else {
handleScroll();
}
});
vue.watch(() => props.container, () => {
getContainer();
});
vue.provide(constants.anchorKey, {
ns,
direction: props.direction,
currentAnchor,
addLink,
removeLink,
handleClick
});
expose({
scrollTo
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
ref_key: "anchorRef",
ref: anchorRef,
class: vue.normalizeClass(vue.unref(cls))
}, [
_ctx.marker ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
ref_key: "markerRef",
ref: markerRef,
class: vue.normalizeClass(vue.unref(ns).e("marker")),
style: vue.normalizeStyle(markerStyle.value)
}, null, 6)) : vue.createCommentVNode("v-if", true),
vue.createElementVNode("div", {
class: vue.normalizeClass(vue.unref(ns).e("list"))
}, [
vue.renderSlot(_ctx.$slots, "default")
], 2)
], 2);
};
}
});
var Anchor = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "anchor.vue"]]);
exports["default"] = Anchor;
//# sourceMappingURL=anchor2.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
import type { InjectionKey, Ref } from 'vue';
import type { UseNamespaceReturn } from 'element-plus/es/hooks';
export interface AnchorLinkState {
el: HTMLElement;
href: string;
}
export interface AnchorContext {
ns: UseNamespaceReturn;
direction: string;
currentAnchor: Ref<string>;
addLink(state: AnchorLinkState): void;
removeLink(href: string): void;
handleClick(e: MouseEvent, href?: string): void;
}
export declare const anchorKey: InjectionKey<AnchorContext>;

View File

@@ -0,0 +1,8 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const anchorKey = Symbol("anchor");
exports.anchorKey = anchorKey;
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sources":["../../../../../../packages/components/anchor/src/constants.ts"],"sourcesContent":["import type { InjectionKey, Ref } from 'vue'\nimport type { UseNamespaceReturn } from '@element-plus/hooks'\n\nexport interface AnchorLinkState {\n el: HTMLElement\n href: string\n}\n\nexport interface AnchorContext {\n ns: UseNamespaceReturn\n direction: string\n currentAnchor: Ref<string>\n addLink(state: AnchorLinkState): void\n removeLink(href: string): void\n handleClick(e: MouseEvent, href?: string): void\n}\n\nexport const anchorKey: InjectionKey<AnchorContext> = Symbol('anchor')\n"],"names":[],"mappings":";;;;AAAY,MAAC,SAAS,GAAG,MAAM,CAAC,QAAQ;;;;"}

View File

@@ -0,0 +1,2 @@
import 'element-plus/es/components/base/style/css';
import 'element-plus/theme-chalk/el-anchor.css';

View File

@@ -0,0 +1,6 @@
'use strict';
require('../../base/style/css.js');
require('element-plus/theme-chalk/el-anchor.css');
//# sourceMappingURL=css.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}

View File

@@ -0,0 +1,2 @@
import 'element-plus/es/components/base/style';
import 'element-plus/theme-chalk/src/anchor.scss';

View File

@@ -0,0 +1,6 @@
'use strict';
require('../../base/style/index.js');
require('element-plus/theme-chalk/src/anchor.scss');
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}