1
0
Fork 0
forked from jan/psslides
psslides/src/slides/worker-globals.ts
navi 97ae327415 feat: compiled-style thumbnails and Less compilation in a worker
- thumbnails: compile the project stylesheet once per rebuild and feed it
  into the layout sandbox, compose each tile like the runtime does
  (<section data-ps-slide> around the slide), and show example HTML on
  the global tile instead of another real slide's content.
- worker: less compiles off the main thread in less-worker; a side-effect
  module shims window/document and disables the browser build's page
  auto-init, and compilation falls back inline if the worker can't start.
- code-to-element: wrap styles[] entries in <style> blocks - raw CSS text
  in the iframe head fell into <body> and rendered as literal garbage.
2026-09-28 13:05:42 +02:00

14 lines
820 B
TypeScript

// less' browser build runs a page auto-init while its module loads: it
// reaches for `window`, copies any `window.less` config, then — unless told
// otherwise — hides `<body>` and rescans the document's stylesheets. A worker
// has none of that, so bind `window` to the worker scope, stub the single
// `document` probe the init makes (null-safe downstream), and pre-set
// `onReady: false` so init stops right after building the compiler.
// The worker imports this for side effects before `less`, so ESM evaluation
// order guarantees the shim exists by the time the auto-init runs.
if (typeof window === 'undefined') {
const worker = globalThis as unknown as Record<string, unknown>
worker.window = worker
worker.document = { getElementsByTagName: () => [] }
worker.less = { onReady: false }
}