@94ai/nf-text-overflow 3.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.cjs ADDED
@@ -0,0 +1,49 @@
1
+ module.exports = {
2
+ "root": true,
3
+ "env": {
4
+ "node": true
5
+ },
6
+ "extends": [
7
+ "plugin:vue/essential"
8
+ ],
9
+ "parser": "vue-eslint-parser",
10
+ "parserOptions": {
11
+ "parser": "@typescript-eslint/parser",
12
+ "ecmaVersion": 2020,
13
+ "sourceType": "module"
14
+ },
15
+ "rules": {
16
+ "@typescript-eslint/ban-ts-ignore": "off",
17
+ "@typescript-eslint/explicit-function-return-type": "off",
18
+ "@typescript-eslint/no-explicit-any": "off",
19
+ "@typescript-eslint/no-var-requires": "off",
20
+ "@typescript-eslint/no-empty-function": "off",
21
+ "vue/custom-event-name-casing": "off",
22
+ "no-use-before-define": "off",
23
+ "@typescript-eslint/no-use-before-define": "off",
24
+ "@typescript-eslint/ban-ts-comment": "off",
25
+ "@typescript-eslint/ban-types": "off",
26
+ "@typescript-eslint/no-non-null-assertion": "off",
27
+ "@typescript-eslint/explicit-module-boundary-types": "off",
28
+ "@typescript-eslint/no-unused-vars": "off",
29
+ "vue/multi-word-component-names": [
30
+ "error",
31
+ {
32
+ "ignores": [
33
+ "index"
34
+ ]
35
+ }
36
+ ],
37
+ "no-console": "warn",
38
+ "no-debugger": "warn",
39
+ "prettier/prettier": [
40
+ "error",
41
+ {
42
+ "tabWidth": 2,
43
+ "singleQuote": true,
44
+ "semi": false,
45
+ "endOfLine": "auto"
46
+ }
47
+ ]
48
+ }
49
+ }
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # `@94ai/nf-text-overflow`
2
+
3
+ 文本溢出组件
4
+
5
+ ## HomePage
6
+
7
+ 官网地址: https://oss.xccjh.top/common-ui/#/ai-index
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ const NfTextOverflow = import('@94ai/nf-text-overflow'); // or const NfMessage = require('@94ai/nf-text-overflow');
13
+
14
+ Vue.use(NfTextOverflow)
15
+ ```
@@ -0,0 +1,8 @@
1
+ export {}
2
+
3
+ declare module 'vue' {
4
+ export interface GlobalComponents {
5
+ NfTextOverflow: typeof import('@94ai/nf-text-overflow/lib/nf-text-overflow.vue')['default']
6
+
7
+ }
8
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import { PluginObject } from 'vue-demi';
2
+ declare const _default: import("vue/types/v3-component-public-instance").ComponentPublicInstanceConstructor<import("vue/types/v3-component-public-instance").Vue3Instance<{}, Readonly<import("vue-demi").ExtractPropTypes<{
3
+ content: {
4
+ type: import("vue-demi").PropType<string>;
5
+ default: string;
6
+ };
7
+ expandText: {
8
+ type: import("vue-demi").PropType<string>;
9
+ default: string;
10
+ };
11
+ collapseText: {
12
+ type: import("vue-demi").PropType<string>;
13
+ default: string;
14
+ };
15
+ rows: {
16
+ type: import("vue-demi").PropType<string | number>;
17
+ default: number;
18
+ };
19
+ rowHeight: {
20
+ type: import("vue-demi").PropType<string | number>;
21
+ default: number;
22
+ };
23
+ }>>, Readonly<import("vue-demi").ExtractPropTypes<{
24
+ content: {
25
+ type: import("vue-demi").PropType<string>;
26
+ default: string;
27
+ };
28
+ expandText: {
29
+ type: import("vue-demi").PropType<string>;
30
+ default: string;
31
+ };
32
+ collapseText: {
33
+ type: import("vue-demi").PropType<string>;
34
+ default: string;
35
+ };
36
+ rows: {
37
+ type: import("vue-demi").PropType<string | number>;
38
+ default: number;
39
+ };
40
+ rowHeight: {
41
+ type: import("vue-demi").PropType<string | number>;
42
+ default: number;
43
+ };
44
+ }>>, {
45
+ clickAction: (param: {
46
+ event: Event;
47
+ expanded: boolean;
48
+ }) => void;
49
+ }, {
50
+ content: string;
51
+ expandText: string;
52
+ collapseText: string;
53
+ rows: string | number;
54
+ rowHeight: string | number;
55
+ }, true, import("vue/types/v3-component-options").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, any>> & Readonly<Readonly<import("vue-demi").ExtractPropTypes<{
56
+ content: {
57
+ type: import("vue-demi").PropType<string>;
58
+ default: string;
59
+ };
60
+ expandText: {
61
+ type: import("vue-demi").PropType<string>;
62
+ default: string;
63
+ };
64
+ collapseText: {
65
+ type: import("vue-demi").PropType<string>;
66
+ default: string;
67
+ };
68
+ rows: {
69
+ type: import("vue-demi").PropType<string | number>;
70
+ default: number;
71
+ };
72
+ rowHeight: {
73
+ type: import("vue-demi").PropType<string | number>;
74
+ default: number;
75
+ };
76
+ }>>> & import("vue-demi").ShallowUnwrapRef<{
77
+ init: () => void;
78
+ }> & import("vue/types/v3-component-options").ExtractComputedReturns<{}> & import("vue-demi").ComponentCustomProperties & Readonly<import("vue-demi").ExtractPropTypes<{
79
+ content: {
80
+ type: import("vue-demi").PropType<string>;
81
+ default: string;
82
+ };
83
+ expandText: {
84
+ type: import("vue-demi").PropType<string>;
85
+ default: string;
86
+ };
87
+ collapseText: {
88
+ type: import("vue-demi").PropType<string>;
89
+ default: string;
90
+ };
91
+ rows: {
92
+ type: import("vue-demi").PropType<string | number>;
93
+ default: number;
94
+ };
95
+ rowHeight: {
96
+ type: import("vue-demi").PropType<string | number>;
97
+ default: number;
98
+ };
99
+ }>>, any, any, any, import("vue-demi").ComponentComputedOptions, import("vue-demi").ComponentMethodOptions> & import("vue/types/v3-component-options").ComponentOptionsBase<Readonly<import("vue-demi").ExtractPropTypes<{
100
+ content: {
101
+ type: import("vue-demi").PropType<string>;
102
+ default: string;
103
+ };
104
+ expandText: {
105
+ type: import("vue-demi").PropType<string>;
106
+ default: string;
107
+ };
108
+ collapseText: {
109
+ type: import("vue-demi").PropType<string>;
110
+ default: string;
111
+ };
112
+ rows: {
113
+ type: import("vue-demi").PropType<string | number>;
114
+ default: number;
115
+ };
116
+ rowHeight: {
117
+ type: import("vue-demi").PropType<string | number>;
118
+ default: number;
119
+ };
120
+ }>>, {
121
+ init: () => void;
122
+ }, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
123
+ clickAction: (param: {
124
+ event: Event;
125
+ expanded: boolean;
126
+ }) => void;
127
+ }, string, {
128
+ content: string;
129
+ expandText: string;
130
+ collapseText: string;
131
+ rows: string | number;
132
+ rowHeight: string | number;
133
+ }> & {
134
+ props: {
135
+ content: {
136
+ type: import("vue-demi").PropType<string>;
137
+ default: string;
138
+ };
139
+ expandText: {
140
+ type: import("vue-demi").PropType<string>;
141
+ default: string;
142
+ };
143
+ collapseText: {
144
+ type: import("vue-demi").PropType<string>;
145
+ default: string;
146
+ };
147
+ rows: {
148
+ type: import("vue-demi").PropType<string | number>;
149
+ default: number;
150
+ };
151
+ rowHeight: {
152
+ type: import("vue-demi").PropType<string | number>;
153
+ default: number;
154
+ };
155
+ };
156
+ } & (new () => {
157
+ $scopedSlots: {
158
+ default?(_: {}): any;
159
+ };
160
+ }) & PluginObject<undefined>;
161
+ export default _default;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const vueDemi = require("vue-demi");
4
+ const vue2RuntimeHelpers = require("@94ai/vue2-runtime-helpers");
5
+ const __sfc_main = vueDemi.defineComponent({
6
+ name: "nf-text-overflow"
7
+ });
8
+ __sfc_main.props = {
9
+ content: {
10
+ key: "content",
11
+ required: false,
12
+ type: String,
13
+ default: ""
14
+ },
15
+ expandText: {
16
+ key: "expandText",
17
+ required: false,
18
+ type: String,
19
+ default: "展开"
20
+ },
21
+ collapseText: {
22
+ key: "collapseText",
23
+ required: false,
24
+ type: String,
25
+ default: "收起"
26
+ },
27
+ rows: {
28
+ key: "rows",
29
+ required: false,
30
+ type: [String, Number],
31
+ default: 1
32
+ },
33
+ rowHeight: {
34
+ key: "rowHeight",
35
+ required: false,
36
+ type: [String, Number],
37
+ default: 20
38
+ }
39
+ };
40
+ __sfc_main.setup = (__props, __ctx) => {
41
+ const props = __props;
42
+ const emit = __ctx.emit;
43
+ const text = vueDemi.ref("");
44
+ const expanded = vueDemi.ref(false);
45
+ const hasAction = vueDemi.ref(false);
46
+ const textbox = vueDemi.ref();
47
+ const contentHeight = vueDemi.ref();
48
+ const hasDefaultSlot = vueDemi.computed(() => !!vueDemi.useSlots().default);
49
+ const maxContentHeight = vueDemi.computed(() => Number(props.rows) * Number(props.rowHeight));
50
+ const pxToNum = (value) => {
51
+ if (!value)
52
+ return 0;
53
+ const match = value.match(/^\d*(\.\d*)?/);
54
+ return match ? Number(match[0]) : 0;
55
+ };
56
+ const calcEllipsised = () => {
57
+ const cloneContainer = () => {
58
+ if (!textbox.value)
59
+ return;
60
+ const originStyle = window.getComputedStyle(textbox.value);
61
+ const container2 = document.createElement("div");
62
+ const styleNames = Array.prototype.slice.apply(originStyle);
63
+ styleNames.forEach((name) => {
64
+ container2.style.setProperty(name, originStyle.getPropertyValue(name));
65
+ });
66
+ container2.style.position = "fixed";
67
+ container2.style.zIndex = "-9999";
68
+ container2.style.top = "-9999px";
69
+ container2.style.height = "auto";
70
+ container2.style.minHeight = "auto";
71
+ container2.style.maxHeight = "auto";
72
+ container2.innerText = props.content;
73
+ document.body.appendChild(container2);
74
+ return container2;
75
+ };
76
+ const calcEllipsisText = (container2, maxHeight2) => {
77
+ const {
78
+ content
79
+ } = props;
80
+ let left = 0;
81
+ let right = content.length;
82
+ let res = -1;
83
+ while (left <= right) {
84
+ const mid = Math.floor((left + right) / 2);
85
+ container2.innerText = content.slice(0, mid);
86
+ if (container2.offsetHeight <= maxHeight2) {
87
+ left = mid + 1;
88
+ res = mid;
89
+ } else {
90
+ right = mid - 1;
91
+ }
92
+ }
93
+ return content.slice(0, res);
94
+ };
95
+ const container = cloneContainer();
96
+ if (!container)
97
+ return;
98
+ const {
99
+ paddingBottom,
100
+ paddingTop,
101
+ lineHeight
102
+ } = container.style;
103
+ const maxHeight = (Number(props.rows) + 0.5) * pxToNum(lineHeight) + pxToNum(paddingTop) + pxToNum(paddingBottom);
104
+ if (maxHeight < container.offsetHeight) {
105
+ hasAction.value = true;
106
+ text.value = calcEllipsisText(container, maxHeight);
107
+ } else {
108
+ hasAction.value = false;
109
+ text.value = props.content;
110
+ }
111
+ document.body.removeChild(container);
112
+ };
113
+ const calcContentHeight = () => {
114
+ if (!textbox.value)
115
+ return;
116
+ const height = textbox.value.offsetHeight;
117
+ if (height > maxContentHeight.value) {
118
+ hasAction.value = true;
119
+ contentHeight.value = `${maxContentHeight.value}px`;
120
+ }
121
+ };
122
+ const init = hasDefaultSlot.value ? calcContentHeight : calcEllipsised;
123
+ const onClickAction = (event) => {
124
+ expanded.value = !expanded.value;
125
+ if (hasDefaultSlot.value) {
126
+ contentHeight.value = expanded.value ? "auto" : `${maxContentHeight.value}px`;
127
+ }
128
+ emit("clickAction", {
129
+ event,
130
+ expanded: expanded.value
131
+ });
132
+ };
133
+ vueDemi.onMounted(() => {
134
+ init();
135
+ window.addEventListener("resize", init);
136
+ });
137
+ vueDemi.onUnmounted(() => {
138
+ window.removeEventListener("resize", init);
139
+ });
140
+ vueDemi.watch(() => [props.content, props.rows], init);
141
+ return Object.assign({
142
+ text,
143
+ expanded,
144
+ hasAction,
145
+ textbox,
146
+ contentHeight,
147
+ onClickAction
148
+ }, {
149
+ init
150
+ });
151
+ };
152
+ var _sfc_render = function render() {
153
+ var _vm = this, _c = _vm._self._c;
154
+ _vm._self._setupProxy;
155
+ return _c("div", {
156
+ staticClass: "nf-text-overflow"
157
+ }, [_c("div", {
158
+ ref: "textbox",
159
+ staticClass: "nf-text-overflow__content",
160
+ style: {
161
+ height: _vm.contentHeight,
162
+ lineHeight: `${_vm.rowHeight}px`
163
+ }
164
+ }, [_vm._t("default", function() {
165
+ return [_vm._v(_vm._s(_vm.expanded ? _vm.content : _vm.text))];
166
+ })], 2), _vm.hasAction ? _c("div", {
167
+ staticClass: "nf-text-overflow__action",
168
+ on: {
169
+ "click": _vm.onClickAction
170
+ }
171
+ }, [_vm._v(" " + _vm._s(_vm.expanded ? _vm.collapseText : _vm.expandText) + " "), _c("i", {
172
+ staticClass: "nf-text-overflow__icon",
173
+ class: [_vm.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"]
174
+ })]) : _vm._e()]);
175
+ };
176
+ var _sfc_staticRenderFns = [];
177
+ var __component__ = /* @__PURE__ */ vue2RuntimeHelpers.normalizeComponent(__sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null, null, null);
178
+ const NfTextOverflow = __component__.exports;
179
+ NfTextOverflow.install = (app) => {
180
+ app.component("nf-text-overflow", NfTextOverflow);
181
+ };
182
+ exports.default = NfTextOverflow;
@@ -0,0 +1,182 @@
1
+ import { defineComponent, ref, computed, useSlots, onMounted, onUnmounted, watch } from "vue-demi";
2
+ import { normalizeComponent } from "@94ai/vue2-runtime-helpers";
3
+ const __sfc_main = defineComponent({
4
+ name: "nf-text-overflow"
5
+ });
6
+ __sfc_main.props = {
7
+ content: {
8
+ key: "content",
9
+ required: false,
10
+ type: String,
11
+ default: ""
12
+ },
13
+ expandText: {
14
+ key: "expandText",
15
+ required: false,
16
+ type: String,
17
+ default: "展开"
18
+ },
19
+ collapseText: {
20
+ key: "collapseText",
21
+ required: false,
22
+ type: String,
23
+ default: "收起"
24
+ },
25
+ rows: {
26
+ key: "rows",
27
+ required: false,
28
+ type: [String, Number],
29
+ default: 1
30
+ },
31
+ rowHeight: {
32
+ key: "rowHeight",
33
+ required: false,
34
+ type: [String, Number],
35
+ default: 20
36
+ }
37
+ };
38
+ __sfc_main.setup = (__props, __ctx) => {
39
+ const props = __props;
40
+ const emit = __ctx.emit;
41
+ const text = ref("");
42
+ const expanded = ref(false);
43
+ const hasAction = ref(false);
44
+ const textbox = ref();
45
+ const contentHeight = ref();
46
+ const hasDefaultSlot = computed(() => !!useSlots().default);
47
+ const maxContentHeight = computed(() => Number(props.rows) * Number(props.rowHeight));
48
+ const pxToNum = (value) => {
49
+ if (!value)
50
+ return 0;
51
+ const match = value.match(/^\d*(\.\d*)?/);
52
+ return match ? Number(match[0]) : 0;
53
+ };
54
+ const calcEllipsised = () => {
55
+ const cloneContainer = () => {
56
+ if (!textbox.value)
57
+ return;
58
+ const originStyle = window.getComputedStyle(textbox.value);
59
+ const container2 = document.createElement("div");
60
+ const styleNames = Array.prototype.slice.apply(originStyle);
61
+ styleNames.forEach((name) => {
62
+ container2.style.setProperty(name, originStyle.getPropertyValue(name));
63
+ });
64
+ container2.style.position = "fixed";
65
+ container2.style.zIndex = "-9999";
66
+ container2.style.top = "-9999px";
67
+ container2.style.height = "auto";
68
+ container2.style.minHeight = "auto";
69
+ container2.style.maxHeight = "auto";
70
+ container2.innerText = props.content;
71
+ document.body.appendChild(container2);
72
+ return container2;
73
+ };
74
+ const calcEllipsisText = (container2, maxHeight2) => {
75
+ const {
76
+ content
77
+ } = props;
78
+ let left = 0;
79
+ let right = content.length;
80
+ let res = -1;
81
+ while (left <= right) {
82
+ const mid = Math.floor((left + right) / 2);
83
+ container2.innerText = content.slice(0, mid);
84
+ if (container2.offsetHeight <= maxHeight2) {
85
+ left = mid + 1;
86
+ res = mid;
87
+ } else {
88
+ right = mid - 1;
89
+ }
90
+ }
91
+ return content.slice(0, res);
92
+ };
93
+ const container = cloneContainer();
94
+ if (!container)
95
+ return;
96
+ const {
97
+ paddingBottom,
98
+ paddingTop,
99
+ lineHeight
100
+ } = container.style;
101
+ const maxHeight = (Number(props.rows) + 0.5) * pxToNum(lineHeight) + pxToNum(paddingTop) + pxToNum(paddingBottom);
102
+ if (maxHeight < container.offsetHeight) {
103
+ hasAction.value = true;
104
+ text.value = calcEllipsisText(container, maxHeight);
105
+ } else {
106
+ hasAction.value = false;
107
+ text.value = props.content;
108
+ }
109
+ document.body.removeChild(container);
110
+ };
111
+ const calcContentHeight = () => {
112
+ if (!textbox.value)
113
+ return;
114
+ const height = textbox.value.offsetHeight;
115
+ if (height > maxContentHeight.value) {
116
+ hasAction.value = true;
117
+ contentHeight.value = `${maxContentHeight.value}px`;
118
+ }
119
+ };
120
+ const init = hasDefaultSlot.value ? calcContentHeight : calcEllipsised;
121
+ const onClickAction = (event) => {
122
+ expanded.value = !expanded.value;
123
+ if (hasDefaultSlot.value) {
124
+ contentHeight.value = expanded.value ? "auto" : `${maxContentHeight.value}px`;
125
+ }
126
+ emit("clickAction", {
127
+ event,
128
+ expanded: expanded.value
129
+ });
130
+ };
131
+ onMounted(() => {
132
+ init();
133
+ window.addEventListener("resize", init);
134
+ });
135
+ onUnmounted(() => {
136
+ window.removeEventListener("resize", init);
137
+ });
138
+ watch(() => [props.content, props.rows], init);
139
+ return Object.assign({
140
+ text,
141
+ expanded,
142
+ hasAction,
143
+ textbox,
144
+ contentHeight,
145
+ onClickAction
146
+ }, {
147
+ init
148
+ });
149
+ };
150
+ var _sfc_render = function render() {
151
+ var _vm = this, _c = _vm._self._c;
152
+ _vm._self._setupProxy;
153
+ return _c("div", {
154
+ staticClass: "nf-text-overflow"
155
+ }, [_c("div", {
156
+ ref: "textbox",
157
+ staticClass: "nf-text-overflow__content",
158
+ style: {
159
+ height: _vm.contentHeight,
160
+ lineHeight: `${_vm.rowHeight}px`
161
+ }
162
+ }, [_vm._t("default", function() {
163
+ return [_vm._v(_vm._s(_vm.expanded ? _vm.content : _vm.text))];
164
+ })], 2), _vm.hasAction ? _c("div", {
165
+ staticClass: "nf-text-overflow__action",
166
+ on: {
167
+ "click": _vm.onClickAction
168
+ }
169
+ }, [_vm._v(" " + _vm._s(_vm.expanded ? _vm.collapseText : _vm.expandText) + " "), _c("i", {
170
+ staticClass: "nf-text-overflow__icon",
171
+ class: [_vm.expanded ? "el-icon-arrow-up" : "el-icon-arrow-down"]
172
+ })]) : _vm._e()]);
173
+ };
174
+ var _sfc_staticRenderFns = [];
175
+ var __component__ = /* @__PURE__ */ normalizeComponent(__sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null, null, null);
176
+ const NfTextOverflow = __component__.exports;
177
+ NfTextOverflow.install = (app) => {
178
+ app.component("nf-text-overflow", NfTextOverflow);
179
+ };
180
+ export {
181
+ NfTextOverflow as default
182
+ };
@@ -0,0 +1,63 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
2
+ content?: string | undefined;
3
+ expandText?: string | undefined;
4
+ collapseText?: string | undefined;
5
+ rows?: string | number | undefined;
6
+ rowHeight?: string | number | undefined;
7
+ }>, {
8
+ content: string;
9
+ expandText: string;
10
+ collapseText: string;
11
+ rows: number;
12
+ rowHeight: number;
13
+ }>, {
14
+ init: () => void;
15
+ }, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
16
+ clickAction: (param: {
17
+ event: Event;
18
+ expanded: boolean;
19
+ }) => void;
20
+ }, string, Readonly<import("vue-demi").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
21
+ content?: string | undefined;
22
+ expandText?: string | undefined;
23
+ collapseText?: string | undefined;
24
+ rows?: string | number | undefined;
25
+ rowHeight?: string | number | undefined;
26
+ }>, {
27
+ content: string;
28
+ expandText: string;
29
+ collapseText: string;
30
+ rows: number;
31
+ rowHeight: number;
32
+ }>>>, {
33
+ content: string;
34
+ expandText: string;
35
+ collapseText: string;
36
+ rows: string | number;
37
+ rowHeight: string | number;
38
+ }>, {
39
+ default?(_: {}): any;
40
+ }>;
41
+ export default _default;
42
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
43
+ type __VLS_TypePropsToRuntimeProps<T> = {
44
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
45
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
46
+ } : {
47
+ type: import('vue').PropType<T[K]>;
48
+ required: true;
49
+ };
50
+ };
51
+ type __VLS_WithDefaults<P, D> = {
52
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
53
+ default: D[K];
54
+ }> : P[K];
55
+ };
56
+ type __VLS_Prettify<T> = {
57
+ [K in keyof T]: T[K];
58
+ } & {};
59
+ type __VLS_WithTemplateSlots<T, S> = T & {
60
+ new (): {
61
+ $scopedSlots: S;
62
+ };
63
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-text-overflow.css'
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-text-overflow.scss'
@@ -0,0 +1,8 @@
1
+ import NfTextOverflow from './nf-text-overflow.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+
4
+ NfTextOverflow.install = (app: typeof Vue2) => {
5
+ app!.component('nf-text-overflow', NfTextOverflow)
6
+ }
7
+
8
+ export default NfTextOverflow as typeof NfTextOverflow & PluginObject<undefined>
@@ -0,0 +1,161 @@
1
+ <template>
2
+ <div class="nf-text-overflow">
3
+ <div class="nf-text-overflow__content" ref="textbox" :style="{ height: contentHeight, lineHeight: `${rowHeight}px` }">
4
+ <slot>{{ expanded ? content : text }}</slot>
5
+ </div>
6
+ <div class="nf-text-overflow__action" v-if="hasAction" @click="onClickAction">
7
+ {{ expanded ? collapseText : expandText }}
8
+ <i class="nf-text-overflow__icon" :class="[expanded ? 'el-icon-arrow-up' : 'el-icon-arrow-down']"></i>
9
+ </div>
10
+ </div>
11
+ </template>
12
+
13
+ <script lang="ts">
14
+ import { defineComponent } from 'vue-demi'
15
+
16
+ export default defineComponent({
17
+ name: "nf-text-overflow",
18
+ })
19
+ </script>
20
+
21
+ <script lang="ts" setup>
22
+ import { ref, onMounted, onUnmounted, watch, useSlots, computed } from 'vue-demi'
23
+
24
+ const props = withDefaults(defineProps<{
25
+ content?: string
26
+ expandText?: string
27
+ collapseText?: string
28
+ rows?: string | number
29
+ rowHeight?: string | number
30
+ }>(), {
31
+ content: '',
32
+ expandText: '展开',
33
+ collapseText: '收起',
34
+ rows: 1,
35
+ rowHeight: 20
36
+ })
37
+
38
+ const emit = defineEmits<{
39
+ (e: 'clickAction', param: {
40
+ event: Event,
41
+ expanded: boolean,
42
+ }): void
43
+ }>()
44
+
45
+
46
+ const text = ref('');
47
+ const expanded = ref(false);
48
+ const hasAction = ref(false);
49
+ const textbox = ref<HTMLElement>();
50
+ const contentHeight = ref()
51
+
52
+ const hasDefaultSlot = computed(() => !!useSlots().default)
53
+ const maxContentHeight = computed(() => Number(props.rows) * Number(props.rowHeight))
54
+
55
+ const pxToNum = (value: string | null) => {
56
+ if (!value) return 0;
57
+ const match = value.match(/^\d*(\.\d*)?/);
58
+ return match ? Number(match[0]) : 0;
59
+ };
60
+
61
+ const calcEllipsised = () => {
62
+ const cloneContainer = () => {
63
+ if (!textbox.value) return;
64
+
65
+ const originStyle = window.getComputedStyle(textbox.value);
66
+ const container = document.createElement('div');
67
+ const styleNames: string[] = Array.prototype.slice.apply(originStyle);
68
+ styleNames.forEach((name) => {
69
+ container.style.setProperty(name, originStyle.getPropertyValue(name));
70
+ });
71
+
72
+ container.style.position = 'fixed';
73
+ container.style.zIndex = '-9999';
74
+ container.style.top = '-9999px';
75
+ container.style.height = 'auto';
76
+ container.style.minHeight = 'auto';
77
+ container.style.maxHeight = 'auto';
78
+
79
+ container.innerText = props.content;
80
+ document.body.appendChild(container);
81
+ return container;
82
+ };
83
+
84
+ const calcEllipsisText = (
85
+ container: HTMLDivElement,
86
+ maxHeight: number
87
+ ) => {
88
+ const { content } = props;
89
+ let left = 0;
90
+ let right = content.length;
91
+ let res = -1;
92
+
93
+ while (left <= right) {
94
+ const mid = Math.floor((left + right) / 2);
95
+ container.innerText = content.slice(0, mid);
96
+ if (container.offsetHeight <= maxHeight) {
97
+ left = mid + 1;
98
+ res = mid;
99
+ } else {
100
+ right = mid - 1;
101
+ }
102
+ }
103
+ return content.slice(0, res);
104
+ };
105
+
106
+ const container = cloneContainer();
107
+ if (!container) return;
108
+
109
+ const { paddingBottom, paddingTop, lineHeight } = container.style;
110
+ const maxHeight =
111
+ (Number(props.rows) + 0.5) * pxToNum(lineHeight) +
112
+ pxToNum(paddingTop) +
113
+ pxToNum(paddingBottom);
114
+ if (maxHeight < container.offsetHeight) {
115
+ hasAction.value = true;
116
+ text.value = calcEllipsisText(container, maxHeight);
117
+ } else {
118
+ hasAction.value = false;
119
+ text.value = props.content;
120
+ }
121
+
122
+ document.body.removeChild(container);
123
+ };
124
+
125
+ const calcContentHeight = () => {
126
+ if (!textbox.value) return;
127
+ const height = textbox.value.offsetHeight
128
+ if (height > maxContentHeight.value) {
129
+ hasAction.value = true;
130
+ contentHeight.value = `${maxContentHeight.value}px`
131
+ }
132
+ }
133
+
134
+ const init = hasDefaultSlot.value ? calcContentHeight : calcEllipsised
135
+
136
+ const onClickAction = (event: MouseEvent) => {
137
+ expanded.value = !expanded.value;
138
+ if (hasDefaultSlot.value) {
139
+ contentHeight.value = expanded.value ? 'auto' : `${maxContentHeight.value}px`
140
+ }
141
+ emit('clickAction', {
142
+ event,
143
+ expanded: expanded.value
144
+ });
145
+ };
146
+
147
+ onMounted(() => {
148
+ init()
149
+ window.addEventListener('resize', init)
150
+ });
151
+
152
+ onUnmounted(() => {
153
+ window.removeEventListener('resize', init)
154
+ })
155
+
156
+ watch(() => [props.content, props.rows], init);
157
+
158
+ defineExpose({
159
+ init
160
+ })
161
+ </script>
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-text-overflow.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-text-overflow.scss'
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@94ai/nf-text-overflow",
3
+ "version": "3.1.13",
4
+ "description": "> TODO: description",
5
+ "keywords": [],
6
+ "author": "zhongzhenjie <1476686104@qq.com>",
7
+ "homepage": "https://oss.xccjh.top/common-ui/#/ai-index",
8
+ "license": "ISC",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
+ },
16
+ "dependencies": {
17
+ "@94ai/nf-theme-chalk": "^3.1.13",
18
+ "vue-demi": "^0.14.5"
19
+ },
20
+ "peerDependenciesMeta": {
21
+ "@vue/composition-api": {
22
+ "optional": true
23
+ }
24
+ },
25
+ "peerDependencies": {
26
+ "@vue/composition-api": "^1.0.0-rc.1",
27
+ "element-ui": ">=2.13.2",
28
+ "vue": "^2.0.0 || >=3.0.0"
29
+ },
30
+ "types": "lib/index.d.ts",
31
+ "main": "lib/nf-text-overflow.cjs.js",
32
+ "module": "lib/nf-text-overflow.esm-bundler.js",
33
+ "gitHead": "a8c56183ccc8e979008e2d38bfde2d7d1448654c"
34
+ }
@@ -0,0 +1,8 @@
1
+ export default {
2
+ plugins: {
3
+ // 这个工具可以实现自动添加CSS3前缀
4
+ autoprefixer: {
5
+ overrideBrowserslist: ['last 5 version', '>1%', 'ie >=8']
6
+ },
7
+ },
8
+ }