@inizioevoke/veeva-astroclm-core 1.2.5 → 1.3.1
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/dist/tasks/generate-thumbs.js +119 -70
- package/dist/types/config.d.ts +13 -8
- package/package.json +1 -1
- package/src/tasks/generate-thumbs.ts +124 -78
- package/src/types/config.d.ts +13 -8
|
@@ -16,48 +16,42 @@ export default async function ({ config, root, deployDir, server }) {
|
|
|
16
16
|
isLandscape: true,
|
|
17
17
|
isMobile: true
|
|
18
18
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
for (const settings of slide.thumbnails.settings) {
|
|
26
|
-
logger.info(`Generating /${settings.path ?? slide.path}/`);
|
|
27
|
-
const url = `${server.protocol ?? 'http'}://${server.host}:${server.port}/${settings.path ?? slide.path}/${settings.queryStringParams ? `?${objToQS(settings.queryStringParams)}` : ''}`;
|
|
28
|
-
try {
|
|
19
|
+
try {
|
|
20
|
+
for (const slide of config.presentation.slides) {
|
|
21
|
+
for (const settings of slide.thumbnails.settings) {
|
|
22
|
+
logger.info(`Generating /${settings.path ?? slide.path}/`);
|
|
23
|
+
const url = `${server.protocol ?? 'http'}://${server.host}:${server.port}/${settings.path ?? slide.path}/${settings.queryStringParams ? `?${objToQS(settings.queryStringParams)}` : ''}`;
|
|
29
24
|
await page.goto(url, {
|
|
30
25
|
waitUntil: 'networkidle0'
|
|
31
26
|
});
|
|
27
|
+
if (settings.delay && settings.delay > 0) {
|
|
28
|
+
logger.info(`Delaying thumbnail generation for ${settings.delay}ms`);
|
|
29
|
+
await sleep(settings.delay);
|
|
30
|
+
}
|
|
31
|
+
let screenshot = await page.screenshot();
|
|
32
|
+
let thumb = await (sharp(screenshot)
|
|
33
|
+
.resize({
|
|
34
|
+
width: settings.width,
|
|
35
|
+
height: settings.height
|
|
36
|
+
})
|
|
37
|
+
.png({
|
|
38
|
+
palette: settings.palette ?? true,
|
|
39
|
+
compressionLevel: settings.compression ?? 9,
|
|
40
|
+
quality: settings.quality ?? 80,
|
|
41
|
+
effort: settings.effort ?? 10
|
|
42
|
+
})).toBuffer();
|
|
43
|
+
const fileName = typeof settings.outFile == 'function' ? settings.outFile(config, slide, settings) : settings.outFile ?? 'thumb.png';
|
|
44
|
+
await writeFile(join(deployDir, slide.path, fileName), thumb);
|
|
32
45
|
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
if (settings.delay && settings.delay > 0) {
|
|
37
|
-
logger.info(`Delaying thumbnail generation for ${settings.delay}ms`);
|
|
38
|
-
await sleep(settings.delay);
|
|
39
|
-
}
|
|
40
|
-
let screenshot = await page.screenshot();
|
|
41
|
-
let thumb = await (sharp(screenshot)
|
|
42
|
-
.resize({
|
|
43
|
-
width: settings.width,
|
|
44
|
-
height: settings.height
|
|
45
|
-
})
|
|
46
|
-
.png({
|
|
47
|
-
palette: true,
|
|
48
|
-
compressionLevel: 9,
|
|
49
|
-
quality: 80,
|
|
50
|
-
effort: 10
|
|
51
|
-
})).toBuffer();
|
|
52
|
-
const fileName = typeof settings.outFile == 'function' ? settings.outFile(config, slide, settings) : settings.outFile ?? 'thumb.png';
|
|
53
|
-
await writeFile(join(deployDir, slide.path, fileName), thumb);
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
finally {
|
|
49
|
+
await page.close();
|
|
50
|
+
await browser.close();
|
|
51
|
+
}
|
|
58
52
|
}
|
|
59
53
|
async function generateSharedThumb(config, deployDir) {
|
|
60
|
-
let settings = config.thumbnails
|
|
54
|
+
let settings = config.thumbnails.find(s => s.outFile === 'thumb.png');
|
|
61
55
|
const width = settings?.width ?? 600;
|
|
62
56
|
const height = settings?.height ?? width / 4 * 3;
|
|
63
57
|
const svgImage = `
|
|
@@ -75,7 +69,7 @@ async function generateSharedThumb(config, deployDir) {
|
|
|
75
69
|
width,
|
|
76
70
|
height: height,
|
|
77
71
|
channels: 4,
|
|
78
|
-
background: { r: 0, g: 0, b: 0, alpha: 1 }
|
|
72
|
+
background: { r: 0, g: 0, b: 0, alpha: 1 }
|
|
79
73
|
}
|
|
80
74
|
})
|
|
81
75
|
.composite([{
|
|
@@ -94,56 +88,111 @@ function objToQS(data) {
|
|
|
94
88
|
.join('&');
|
|
95
89
|
}
|
|
96
90
|
function initThumbSettings(config) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
config.thumbnails.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!config.thumbnails.settings) {
|
|
113
|
-
config.thumbnails.settings = [];
|
|
91
|
+
const DEFAULT_WIDTH = 600;
|
|
92
|
+
let defaultThumb = undefined;
|
|
93
|
+
if (Array.isArray(config.thumbnails)) {
|
|
94
|
+
const thumbs = [];
|
|
95
|
+
for (let i = 0; i < config.thumbnails.length; i++) {
|
|
96
|
+
const ss = config.thumbnails[i];
|
|
97
|
+
const width = ss.width ?? DEFAULT_WIDTH;
|
|
98
|
+
thumbs.push({
|
|
99
|
+
...ss,
|
|
100
|
+
width,
|
|
101
|
+
height: ss.height ?? width / 4 * 3,
|
|
102
|
+
outFile: ss.outFile ?? (i === 0 ? 'thumb.png' : i === 1 ? 'poster.png' : `thumb-${i + 1}.png`),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
config.thumbnails = thumbs;
|
|
114
106
|
}
|
|
115
|
-
if (config.thumbnails.settings
|
|
116
|
-
|
|
107
|
+
else if (config.thumbnails?.default || config.thumbnails?.settings) {
|
|
108
|
+
const thumbs = [];
|
|
109
|
+
defaultThumb = config.thumbnails.default;
|
|
110
|
+
if (defaultThumb) {
|
|
111
|
+
const width = defaultThumb.width ?? DEFAULT_WIDTH;
|
|
112
|
+
thumbs.push({
|
|
113
|
+
...defaultThumb,
|
|
114
|
+
width,
|
|
115
|
+
height: defaultThumb.height ?? width / 4 * 3,
|
|
116
|
+
outFile: defaultThumb.outFile ?? 'thumb.png',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(config.thumbnails?.settings)) {
|
|
120
|
+
const settings = config.thumbnails.settings;
|
|
121
|
+
for (let i = 0; i < settings.length; i++) {
|
|
122
|
+
const sets = settings[i];
|
|
123
|
+
const width = sets.width ?? DEFAULT_WIDTH;
|
|
124
|
+
thumbs.push({
|
|
125
|
+
...defaultThumb,
|
|
126
|
+
...sets,
|
|
127
|
+
width,
|
|
128
|
+
height: sets.height ?? width / 4 * 3,
|
|
129
|
+
outFile: sets.outFile ?? `thumb-${i + 1}.png`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
config.thumbnails = thumbs;
|
|
117
134
|
}
|
|
118
135
|
else {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
config.thumbnails = [{
|
|
137
|
+
width: DEFAULT_WIDTH,
|
|
138
|
+
height: DEFAULT_WIDTH / 4 * 3,
|
|
139
|
+
outFile: 'thumb.png'
|
|
140
|
+
}];
|
|
122
141
|
}
|
|
142
|
+
// if (!config.thumbnails) {
|
|
143
|
+
// config.thumbnails = {};
|
|
144
|
+
// }
|
|
145
|
+
// if (!config.thumbnails.default) {
|
|
146
|
+
// config.thumbnails.default = {};
|
|
147
|
+
// }
|
|
148
|
+
// if (!config.thumbnails.default.width) {
|
|
149
|
+
// config.thumbnails.default.width = 600;
|
|
150
|
+
// }
|
|
151
|
+
// if (!config.thumbnails.default.height) {
|
|
152
|
+
// config.thumbnails.default.height = config.thumbnails.default.width / 4 * 3;
|
|
153
|
+
// }
|
|
154
|
+
// if (!config.thumbnails.default.outFile) {
|
|
155
|
+
// config.thumbnails.default.outFile = 'thumb.png';
|
|
156
|
+
// }
|
|
157
|
+
// if (!config.thumbnails.settings) {
|
|
158
|
+
// config.thumbnails.settings = [];
|
|
159
|
+
// }
|
|
160
|
+
// if (config.thumbnails.settings.length === 0) {
|
|
161
|
+
// config.thumbnails.settings.push(config.thumbnails.default);
|
|
162
|
+
// } else {
|
|
163
|
+
// for (let i=0; i<config.thumbnails.settings.length; i++) {
|
|
164
|
+
// config.thumbnails.settings[i] = {...config.thumbnails.default, ...config.thumbnails.settings[i]};
|
|
165
|
+
// }
|
|
166
|
+
// }
|
|
123
167
|
for (const slide of config.presentation.slides) {
|
|
124
168
|
if (!slide.thumbnails) {
|
|
125
|
-
slide.thumbnails =
|
|
169
|
+
slide.thumbnails = {};
|
|
126
170
|
}
|
|
127
171
|
if (!slide.thumbnails.settings) {
|
|
128
|
-
slide.thumbnails.settings = config.thumbnails
|
|
172
|
+
slide.thumbnails.settings = config.thumbnails;
|
|
129
173
|
}
|
|
130
174
|
else {
|
|
131
175
|
switch (slide.thumbnails.strategy) {
|
|
132
176
|
case 'append':
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
177
|
+
if (defaultThumb) {
|
|
178
|
+
slide.thumbnails.settings = config.thumbnails.concat(slide.thumbnails.settings.map((sets) => {
|
|
179
|
+
return { ...defaultThumb, ...sets }; // {...config.thumbnails!.default, ...slide.thumbnails?.default ?? {}, ...sets}
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
slide.thumbnails.settings = config.thumbnails.concat(slide.thumbnails.settings);
|
|
184
|
+
}
|
|
138
185
|
break;
|
|
139
186
|
case 'merge':
|
|
140
|
-
default:
|
|
141
187
|
for (let i = 0; i < slide.thumbnails.settings.length; i++) {
|
|
142
|
-
slide.thumbnails.settings[i]
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
188
|
+
const sets = slide.thumbnails.settings[i];
|
|
189
|
+
const mergeWith = config.thumbnails.find(t => sets.outFile && sets.outFile === t.outFile) ?? defaultThumb;
|
|
190
|
+
if (mergeWith) {
|
|
191
|
+
slide.thumbnails.settings[i] = {
|
|
192
|
+
...mergeWith,
|
|
193
|
+
...slide.thumbnails.settings[i]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
147
196
|
}
|
|
148
197
|
break;
|
|
149
198
|
}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -7,12 +7,17 @@ export interface IDimensions {
|
|
|
7
7
|
height?: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
type VeevaScreenshotName = 'thumb.png' | 'poster.png' | (string & {});
|
|
10
11
|
export interface IScreenshotSettings extends IDimensions {
|
|
11
12
|
path?: string;
|
|
12
13
|
queryStringParams?: Record<string, boolean | number | string>;
|
|
13
14
|
delay?: number;
|
|
14
|
-
outFile?:
|
|
15
|
+
outFile?: VeevaScreenshotName | ThumbnailNameHandler;
|
|
15
16
|
outDir?: string | string[] | ThumbnailNameHandler;
|
|
17
|
+
palette?: boolean;
|
|
18
|
+
compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
19
|
+
quality?: 70 | 75 | 80 | 85 | 90 | 95 | 100 | (number & {});
|
|
20
|
+
effort?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
16
21
|
}
|
|
17
22
|
export interface IThumbnailSettings {
|
|
18
23
|
default?: IScreenshotSettings;
|
|
@@ -20,12 +25,12 @@ export interface IThumbnailSettings {
|
|
|
20
25
|
}
|
|
21
26
|
export interface ISlideThumbnailSettings {
|
|
22
27
|
strategy?: 'append' | 'merge' | 'replace';
|
|
23
|
-
thumbFile?: IDimensions & {
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
posterFile?: IDimensions & {
|
|
27
|
-
|
|
28
|
-
};
|
|
28
|
+
// thumbFile?: IDimensions & {
|
|
29
|
+
// filepath: string;
|
|
30
|
+
// };
|
|
31
|
+
// posterFile?: IDimensions & {
|
|
32
|
+
// filepath: string;
|
|
33
|
+
// };
|
|
29
34
|
settings?: IScreenshotSettings[];
|
|
30
35
|
}
|
|
31
36
|
|
|
@@ -47,7 +52,7 @@ export interface IVeevaConfigPresentation extends IVeevaClmPresentation {
|
|
|
47
52
|
export interface IVeevaConfig {
|
|
48
53
|
dimensions: { width: number, height: number };
|
|
49
54
|
slideSettings?: IVeevaClmSlideSettings; // legacy support
|
|
50
|
-
thumbnails?: IThumbnailSettings;
|
|
55
|
+
thumbnails?: IThumbnailSettings | IScreenshotSettings | IScreenshotSettings[];
|
|
51
56
|
|
|
52
57
|
presentation: IVeevaConfigPresentation & {
|
|
53
58
|
name: string;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import puppeteer, { type Viewport } from "puppeteer";
|
|
|
4
4
|
import sharp from 'sharp';
|
|
5
5
|
|
|
6
6
|
import logger from '../lib/logger.js';
|
|
7
|
-
import type { IVeevaConfig } from "../types";
|
|
7
|
+
import type { IVeevaConfig, IThumbnailSettings, IScreenshotSettings } from "../types";
|
|
8
8
|
|
|
9
9
|
interface Params {
|
|
10
10
|
config: IVeevaConfig;
|
|
@@ -32,54 +32,46 @@ export default async function({ config, root, deployDir, server }: Params) {
|
|
|
32
32
|
isMobile: true
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
for (const settings of slide.thumbnails!.settings!) {
|
|
43
|
-
logger.info(`Generating /${settings.path ?? slide.path}/`);
|
|
44
|
-
const url = `${server.protocol ?? 'http'}://${server.host}:${server.port}/${settings.path ?? slide.path}/${settings.queryStringParams ? `?${objToQS(settings.queryStringParams)}` : ''}`
|
|
35
|
+
try {
|
|
36
|
+
for (const slide of config.presentation.slides) {
|
|
37
|
+
for (const settings of slide.thumbnails!.settings!) {
|
|
38
|
+
logger.info(`Generating /${settings.path ?? slide.path}/`);
|
|
39
|
+
const url = `${server.protocol ?? 'http'}://${server.host}:${server.port}/${settings.path ?? slide.path}/${settings.queryStringParams ? `?${objToQS(settings.queryStringParams)}` : ''}`
|
|
45
40
|
|
|
46
|
-
try {
|
|
47
41
|
await page.goto(url, {
|
|
48
42
|
waitUntil: 'networkidle0'
|
|
49
43
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
await
|
|
44
|
+
if (settings.delay && settings.delay > 0) {
|
|
45
|
+
logger.info(`Delaying thumbnail generation for ${settings.delay}ms`);
|
|
46
|
+
await sleep(settings.delay);
|
|
47
|
+
}
|
|
48
|
+
let screenshot = await page.screenshot();
|
|
49
|
+
let thumb = await (
|
|
50
|
+
sharp(screenshot)
|
|
51
|
+
.resize({
|
|
52
|
+
width: settings.width,
|
|
53
|
+
height: settings.height
|
|
54
|
+
})
|
|
55
|
+
.png({
|
|
56
|
+
palette: settings.palette ?? true,
|
|
57
|
+
compressionLevel: settings.compression ?? 9,
|
|
58
|
+
quality: settings.quality ?? 80,
|
|
59
|
+
effort: settings.effort ?? 10
|
|
60
|
+
})
|
|
61
|
+
).toBuffer();
|
|
62
|
+
|
|
63
|
+
const fileName = typeof settings.outFile == 'function' ? settings.outFile(config, slide, settings) : settings.outFile ?? 'thumb.png';
|
|
64
|
+
await writeFile(join(deployDir, slide.path, fileName), thumb);
|
|
56
65
|
}
|
|
57
|
-
let screenshot = await page.screenshot();
|
|
58
|
-
let thumb = await (
|
|
59
|
-
sharp(screenshot)
|
|
60
|
-
.resize({
|
|
61
|
-
width: settings.width,
|
|
62
|
-
height: settings.height
|
|
63
|
-
})
|
|
64
|
-
.png({
|
|
65
|
-
palette: true,
|
|
66
|
-
compressionLevel: 9,
|
|
67
|
-
quality: 80,
|
|
68
|
-
effort: 10
|
|
69
|
-
})
|
|
70
|
-
).toBuffer();
|
|
71
|
-
|
|
72
|
-
const fileName = typeof settings.outFile == 'function' ? settings.outFile(config, slide, settings) : settings.outFile ?? 'thumb.png';
|
|
73
|
-
await writeFile(join(deployDir, slide.path, fileName), thumb);
|
|
74
66
|
}
|
|
67
|
+
} finally {
|
|
68
|
+
await page.close();
|
|
69
|
+
await browser.close();
|
|
75
70
|
}
|
|
76
|
-
|
|
77
|
-
await page.close();
|
|
78
|
-
await browser.close();
|
|
79
71
|
}
|
|
80
72
|
|
|
81
73
|
async function generateSharedThumb(config: IVeevaConfig, deployDir: string) {
|
|
82
|
-
let settings = config.thumbnails
|
|
74
|
+
let settings = (config.thumbnails as IScreenshotSettings[]).find(s => s.outFile === 'thumb.png');
|
|
83
75
|
const width = settings?.width ?? 600;
|
|
84
76
|
const height = settings?.height ?? width / 4 * 3;
|
|
85
77
|
const svgImage = `
|
|
@@ -98,7 +90,7 @@ async function generateSharedThumb(config: IVeevaConfig, deployDir: string) {
|
|
|
98
90
|
width,
|
|
99
91
|
height: height,
|
|
100
92
|
channels: 4,
|
|
101
|
-
background: { r: 0, g: 0, b: 0, alpha: 1 }
|
|
93
|
+
background: { r: 0, g: 0, b: 0, alpha: 1 }
|
|
102
94
|
}
|
|
103
95
|
})
|
|
104
96
|
.composite([{
|
|
@@ -120,57 +112,111 @@ function objToQS(data: Record<string, any>) {
|
|
|
120
112
|
}
|
|
121
113
|
|
|
122
114
|
function initThumbSettings(config: IVeevaConfig) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
config.thumbnails.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
115
|
+
const DEFAULT_WIDTH = 600;
|
|
116
|
+
let defaultThumb: IScreenshotSettings | undefined = undefined;
|
|
117
|
+
if (Array.isArray(config.thumbnails)) {
|
|
118
|
+
const thumbs: IScreenshotSettings[] = [];
|
|
119
|
+
for (let i=0; i<config.thumbnails.length; i++) {
|
|
120
|
+
const ss = config.thumbnails[i];
|
|
121
|
+
const width = ss.width ?? DEFAULT_WIDTH;
|
|
122
|
+
thumbs.push({
|
|
123
|
+
...ss,
|
|
124
|
+
width,
|
|
125
|
+
height: ss.height ?? width / 4 * 3,
|
|
126
|
+
outFile: ss.outFile ?? (i === 0 ? 'thumb.png' : i === 1 ? 'poster.png' : `thumb-${i+1}.png`),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
config.thumbnails = thumbs;
|
|
130
|
+
} else if ((config.thumbnails as IThumbnailSettings | undefined)?.default || (config.thumbnails as IThumbnailSettings | undefined)?.settings) {
|
|
131
|
+
const thumbs: IScreenshotSettings[] = [];
|
|
132
|
+
defaultThumb = (config.thumbnails as IThumbnailSettings).default;
|
|
133
|
+
if (defaultThumb) {
|
|
134
|
+
const width = defaultThumb.width ?? DEFAULT_WIDTH;
|
|
135
|
+
thumbs.push({
|
|
136
|
+
...defaultThumb,
|
|
137
|
+
width,
|
|
138
|
+
height: defaultThumb.height ?? width / 4 * 3,
|
|
139
|
+
outFile: defaultThumb.outFile ?? 'thumb.png',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray((config.thumbnails as IThumbnailSettings | undefined)?.settings)) {
|
|
143
|
+
const settings = (config.thumbnails as IThumbnailSettings).settings as IScreenshotSettings[];
|
|
144
|
+
for (let i=0; i<settings.length; i++) {
|
|
145
|
+
const sets = settings[i];
|
|
146
|
+
const width = sets.width ?? DEFAULT_WIDTH;
|
|
147
|
+
thumbs.push({
|
|
148
|
+
...defaultThumb,
|
|
149
|
+
...sets,
|
|
150
|
+
width,
|
|
151
|
+
height: sets.height ?? width / 4 * 3,
|
|
152
|
+
outFile: sets.outFile ?? `thumb-${i+1}.png`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
146
155
|
}
|
|
156
|
+
config.thumbnails = thumbs;
|
|
157
|
+
} else {
|
|
158
|
+
config.thumbnails = [{
|
|
159
|
+
width: DEFAULT_WIDTH,
|
|
160
|
+
height: DEFAULT_WIDTH / 4 * 3,
|
|
161
|
+
outFile: 'thumb.png'
|
|
162
|
+
}];
|
|
147
163
|
}
|
|
148
164
|
|
|
165
|
+
// if (!config.thumbnails) {
|
|
166
|
+
// config.thumbnails = {};
|
|
167
|
+
// }
|
|
168
|
+
// if (!config.thumbnails.default) {
|
|
169
|
+
// config.thumbnails.default = {};
|
|
170
|
+
// }
|
|
171
|
+
// if (!config.thumbnails.default.width) {
|
|
172
|
+
// config.thumbnails.default.width = 600;
|
|
173
|
+
// }
|
|
174
|
+
// if (!config.thumbnails.default.height) {
|
|
175
|
+
// config.thumbnails.default.height = config.thumbnails.default.width / 4 * 3;
|
|
176
|
+
// }
|
|
177
|
+
// if (!config.thumbnails.default.outFile) {
|
|
178
|
+
// config.thumbnails.default.outFile = 'thumb.png';
|
|
179
|
+
// }
|
|
180
|
+
// if (!config.thumbnails.settings) {
|
|
181
|
+
// config.thumbnails.settings = [];
|
|
182
|
+
// }
|
|
183
|
+
// if (config.thumbnails.settings.length === 0) {
|
|
184
|
+
// config.thumbnails.settings.push(config.thumbnails.default);
|
|
185
|
+
// } else {
|
|
186
|
+
// for (let i=0; i<config.thumbnails.settings.length; i++) {
|
|
187
|
+
// config.thumbnails.settings[i] = {...config.thumbnails.default, ...config.thumbnails.settings[i]};
|
|
188
|
+
// }
|
|
189
|
+
// }
|
|
190
|
+
|
|
149
191
|
for (const slide of config.presentation.slides) {
|
|
150
192
|
if (!slide.thumbnails) {
|
|
151
|
-
slide.thumbnails =
|
|
193
|
+
slide.thumbnails = {};
|
|
152
194
|
}
|
|
153
195
|
if (!slide.thumbnails.settings) {
|
|
154
|
-
slide.thumbnails.settings = config.thumbnails
|
|
196
|
+
slide.thumbnails.settings = config.thumbnails;
|
|
155
197
|
} else {
|
|
156
198
|
switch (slide.thumbnails.strategy) {
|
|
157
199
|
case 'append':
|
|
158
|
-
|
|
159
|
-
slide.thumbnails.settings.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
if (defaultThumb) {
|
|
201
|
+
slide.thumbnails.settings = config.thumbnails.concat(
|
|
202
|
+
slide.thumbnails.settings.map((sets) => {
|
|
203
|
+
return {...defaultThumb, ...sets}; // {...config.thumbnails!.default, ...slide.thumbnails?.default ?? {}, ...sets}
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
slide.thumbnails.settings = config.thumbnails.concat(slide.thumbnails.settings);
|
|
208
|
+
}
|
|
165
209
|
break;
|
|
166
210
|
case 'merge':
|
|
167
|
-
default:
|
|
168
211
|
for (let i=0; i<slide.thumbnails.settings.length; i++) {
|
|
169
|
-
slide.thumbnails
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
212
|
+
const sets = slide.thumbnails!.settings![i];
|
|
213
|
+
const mergeWith = config.thumbnails.find(t => sets.outFile && sets.outFile === t.outFile) ?? defaultThumb;
|
|
214
|
+
if (mergeWith) {
|
|
215
|
+
slide.thumbnails.settings[i] = {
|
|
216
|
+
...mergeWith,
|
|
217
|
+
...slide.thumbnails.settings[i]
|
|
218
|
+
};
|
|
219
|
+
}
|
|
174
220
|
}
|
|
175
221
|
break;
|
|
176
222
|
}
|
package/src/types/config.d.ts
CHANGED
|
@@ -7,12 +7,17 @@ export interface IDimensions {
|
|
|
7
7
|
height?: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
type VeevaScreenshotName = 'thumb.png' | 'poster.png' | (string & {});
|
|
10
11
|
export interface IScreenshotSettings extends IDimensions {
|
|
11
12
|
path?: string;
|
|
12
13
|
queryStringParams?: Record<string, boolean | number | string>;
|
|
13
14
|
delay?: number;
|
|
14
|
-
outFile?:
|
|
15
|
+
outFile?: VeevaScreenshotName | ThumbnailNameHandler;
|
|
15
16
|
outDir?: string | string[] | ThumbnailNameHandler;
|
|
17
|
+
palette?: boolean;
|
|
18
|
+
compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
19
|
+
quality?: 70 | 75 | 80 | 85 | 90 | 95 | 100 | (number & {});
|
|
20
|
+
effort?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
16
21
|
}
|
|
17
22
|
export interface IThumbnailSettings {
|
|
18
23
|
default?: IScreenshotSettings;
|
|
@@ -20,12 +25,12 @@ export interface IThumbnailSettings {
|
|
|
20
25
|
}
|
|
21
26
|
export interface ISlideThumbnailSettings {
|
|
22
27
|
strategy?: 'append' | 'merge' | 'replace';
|
|
23
|
-
thumbFile?: IDimensions & {
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
posterFile?: IDimensions & {
|
|
27
|
-
|
|
28
|
-
};
|
|
28
|
+
// thumbFile?: IDimensions & {
|
|
29
|
+
// filepath: string;
|
|
30
|
+
// };
|
|
31
|
+
// posterFile?: IDimensions & {
|
|
32
|
+
// filepath: string;
|
|
33
|
+
// };
|
|
29
34
|
settings?: IScreenshotSettings[];
|
|
30
35
|
}
|
|
31
36
|
|
|
@@ -47,7 +52,7 @@ export interface IVeevaConfigPresentation extends IVeevaClmPresentation {
|
|
|
47
52
|
export interface IVeevaConfig {
|
|
48
53
|
dimensions: { width: number, height: number };
|
|
49
54
|
slideSettings?: IVeevaClmSlideSettings; // legacy support
|
|
50
|
-
thumbnails?: IThumbnailSettings;
|
|
55
|
+
thumbnails?: IThumbnailSettings | IScreenshotSettings | IScreenshotSettings[];
|
|
51
56
|
|
|
52
57
|
presentation: IVeevaConfigPresentation & {
|
|
53
58
|
name: string;
|