( contents: Contents | undefined, settings: Settings | undefined, )
| 37 | } |
| 38 | |
| 39 | export function updateCustomStyle( |
| 40 | contents: Contents | undefined, |
| 41 | settings: Settings | undefined, |
| 42 | ) { |
| 43 | if (!contents || !settings) return |
| 44 | |
| 45 | const { zoom, ...other } = settings |
| 46 | let css = `a, article, cite, div, li, p, pre, span, table, body { |
| 47 | ${mapToCss(other)} |
| 48 | }` |
| 49 | |
| 50 | if (zoom) { |
| 51 | const body = contents.content as HTMLBodyElement |
| 52 | const scale = (p: keyof CSSStyleDeclaration) => ({ |
| 53 | [p]: `${parseInt(body.style[p] as string) / zoom}px`, |
| 54 | }) |
| 55 | css += `body { |
| 56 | ${mapToCss({ |
| 57 | transformOrigin: 'top left', |
| 58 | transform: `scale(${zoom})`, |
| 59 | ...scale('width'), |
| 60 | ...scale('height'), |
| 61 | ...scale('columnWidth'), |
| 62 | ...scale('columnGap'), |
| 63 | ...scale('paddingTop'), |
| 64 | ...scale('paddingBottom'), |
| 65 | ...scale('paddingLeft'), |
| 66 | ...scale('paddingRight'), |
| 67 | })} |
| 68 | }` |
| 69 | } |
| 70 | |
| 71 | return contents.addStylesheetCss(css, Style.Custom) |
| 72 | } |
| 73 | |
| 74 | export function lock(l: number, r: number, unit = 'px') { |
| 75 | const minw = 400 |
no test coverage detected