@lemonppt/view-model 0.1.0
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/LICENSE +21 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +92 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lemonforme
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DeckGoal, Slide } from '@lemonppt/core';
|
|
2
|
+
export interface NormalizeOptions {
|
|
3
|
+
/** 标题最大长度,默认 80 */
|
|
4
|
+
maxTitleLength?: number;
|
|
5
|
+
/** 单条要点最大长度,默认 120 */
|
|
6
|
+
maxPointLength?: number;
|
|
7
|
+
/** 要点最大条数,默认 6 */
|
|
8
|
+
maxPoints?: number;
|
|
9
|
+
/** 摘要/描述最大长度,默认 200 */
|
|
10
|
+
maxDescriptionLength?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 截断文本,超出部分显示省略号。
|
|
14
|
+
*/
|
|
15
|
+
export declare function truncateText(text: string, maxLength: number): string;
|
|
16
|
+
/**
|
|
17
|
+
* 规范化单个 slide 的 props:注入页码、截断文本、确保数组存在。
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeSlide(slide: Slide, index: number, pageCount: number, options?: NormalizeOptions): Slide;
|
|
20
|
+
/**
|
|
21
|
+
* 规范化整个 DeckGoal:同步 pageCount、逐页规范化 props。
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeDeck(goal: DeckGoal, options?: NormalizeOptions): DeckGoal;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
|
+
maxTitleLength: 80,
|
|
3
|
+
maxPointLength: 120,
|
|
4
|
+
maxPoints: 6,
|
|
5
|
+
maxDescriptionLength: 200,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 截断文本,超出部分显示省略号。
|
|
9
|
+
*/
|
|
10
|
+
export function truncateText(text, maxLength) {
|
|
11
|
+
if (text.length <= maxLength)
|
|
12
|
+
return text;
|
|
13
|
+
return text.slice(0, maxLength - 1) + '…';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 确保字段是数组,并截断每条内容。
|
|
17
|
+
*/
|
|
18
|
+
function normalizeArrayField(props, key, maxItems, maxItemLength) {
|
|
19
|
+
const value = props[key];
|
|
20
|
+
if (value === undefined || value === null) {
|
|
21
|
+
props[key] = [];
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!Array.isArray(value)) {
|
|
25
|
+
props[key] = [];
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
props[key] = value
|
|
29
|
+
.slice(0, maxItems)
|
|
30
|
+
.map((item) => (typeof item === 'string' ? truncateText(item, maxItemLength) : item));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 规范化单个 slide 的 props:注入页码、截断文本、确保数组存在。
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeSlide(slide, index, pageCount, options = {}) {
|
|
36
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
37
|
+
const props = { ...slide.props };
|
|
38
|
+
// 注入页码信息,供版式组件使用
|
|
39
|
+
props._slideIdx = index + 1;
|
|
40
|
+
props._pageCount = pageCount;
|
|
41
|
+
// 截断常见文本字段
|
|
42
|
+
if (typeof props.title === 'string') {
|
|
43
|
+
props.title = truncateText(props.title, opts.maxTitleLength);
|
|
44
|
+
}
|
|
45
|
+
if (typeof props.kicker === 'string') {
|
|
46
|
+
props.kicker = truncateText(props.kicker, opts.maxTitleLength);
|
|
47
|
+
}
|
|
48
|
+
if (typeof props.subtitle === 'string') {
|
|
49
|
+
props.subtitle = truncateText(props.subtitle, opts.maxDescriptionLength);
|
|
50
|
+
}
|
|
51
|
+
if (typeof props.description === 'string') {
|
|
52
|
+
props.description = truncateText(props.description, opts.maxDescriptionLength);
|
|
53
|
+
}
|
|
54
|
+
if (typeof props.quote === 'string') {
|
|
55
|
+
props.quote = truncateText(props.quote, opts.maxPointLength * 2);
|
|
56
|
+
}
|
|
57
|
+
if (typeof props.content === 'string') {
|
|
58
|
+
props.content = truncateText(props.content, opts.maxDescriptionLength);
|
|
59
|
+
}
|
|
60
|
+
// 确保常见数组字段存在且长度受控
|
|
61
|
+
const arrayFields = [
|
|
62
|
+
'points',
|
|
63
|
+
'leftPoints',
|
|
64
|
+
'rightPoints',
|
|
65
|
+
'items',
|
|
66
|
+
'steps',
|
|
67
|
+
'features',
|
|
68
|
+
'milestones',
|
|
69
|
+
'phases',
|
|
70
|
+
'tiers',
|
|
71
|
+
'images',
|
|
72
|
+
'partners',
|
|
73
|
+
'stats',
|
|
74
|
+
'members',
|
|
75
|
+
];
|
|
76
|
+
for (const key of arrayFields) {
|
|
77
|
+
normalizeArrayField(props, key, opts.maxPoints, opts.maxPointLength);
|
|
78
|
+
}
|
|
79
|
+
return { ...slide, props };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 规范化整个 DeckGoal:同步 pageCount、逐页规范化 props。
|
|
83
|
+
*/
|
|
84
|
+
export function normalizeDeck(goal, options) {
|
|
85
|
+
const pageCount = goal.slides.length;
|
|
86
|
+
const slides = goal.slides.map((slide, index) => normalizeSlide(slide, index, pageCount, options));
|
|
87
|
+
return {
|
|
88
|
+
...goal,
|
|
89
|
+
pageCount,
|
|
90
|
+
slides,
|
|
91
|
+
};
|
|
92
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lemonppt/view-model",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/lemonforme/lemonPPT.git",
|
|
22
|
+
"directory": "packages/view-model"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/lemonforme/lemonPPT/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/lemonforme/lemonPPT#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@lemonppt/core": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"typescript": "^5.5.0"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"typecheck": "tsc --noEmit"
|
|
38
|
+
}
|
|
39
|
+
}
|