Skip to content

Commit

Permalink
feat: add scale arg for image export (#1263) (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Feb 6, 2024
1 parent d3e5cf8 commit 1eaf92a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/slidev/node/cli.ts
Expand Up @@ -534,6 +534,10 @@ function exportOptions<T>(args: Argv<T>) {
type: 'boolean',
describe: 'slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF',
})
.option('scale', {
type: 'number',
describe: 'scale factor for image export',
})
}

function printInfo(
Expand Down
6 changes: 5 additions & 1 deletion packages/slidev/node/export.ts
Expand Up @@ -33,6 +33,7 @@ export interface ExportOptions {
* @default false
*/
perSlide?: boolean
scale?: number
}

function addToTree(tree: TocItem[], info: SlideInfo, slideIndexes: Record<number, number>, level = 1) {
Expand Down Expand Up @@ -161,6 +162,7 @@ export async function exportSlides({
executablePath = undefined,
withToc = false,
perSlide = false,
scale = 1,
}: ExportOptions) {
const pages: number[] = parseRangeString(total, range)

Expand All @@ -174,7 +176,7 @@ export async function exportSlides({
// Calculate height for every slides to be in the viewport to trigger the rendering of iframes (twitter, youtube...)
height: perSlide ? height : height * pages.length,
},
deviceScaleFactor: 1,
deviceScaleFactor: scale,
})
const page = await context.newPage()
const progress = createSlidevProgress(!perSlide)
Expand Down Expand Up @@ -449,6 +451,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption
executablePath,
withToc,
perSlide,
scale,
} = config
outFilename = output || options.data.config.exportFilename || outFilename || `${path.basename(entry, '.md')}-export`
if (outDir)
Expand All @@ -468,6 +471,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption
executablePath,
withToc: withToc || false,
perSlide: perSlide || false,
scale: scale || 1,
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/cli.ts
Expand Up @@ -13,6 +13,7 @@ export interface ExportArgs extends CommonArgs {
'executable-path'?: string
'with-toc'?: boolean
'per-slide'?: boolean
scale?: number
}

export interface BuildArgs extends ExportArgs {
Expand Down

0 comments on commit 1eaf92a

Please sign in to comment.