MCPcopy Create free account
hub / github.com/pacexy/flow / updateCustomStyle

Function updateCustomStyle

apps/reader/src/styles.ts:39–72  ·  view source on GitHub ↗
(
  contents: Contents | undefined,
  settings: Settings | undefined,
)

Source from the content-addressed store, hash-verified

37}
38
39export 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
74export function lock(l: number, r: number, unit = 'px') {
75 const minw = 400

Callers 1

BookPaneFunction · 0.90

Calls 3

mapToCssFunction · 0.85
addStylesheetCssMethod · 0.80
scaleFunction · 0.70

Tested by

no test coverage detected