|
| 1 | +import { |
| 2 | + buildStamp, |
| 3 | + makeTestComponentContext, |
| 4 | + makeTestEvent, |
| 5 | +} from 'butterfloat' |
| 6 | +import { JSDOM } from 'jsdom' |
| 7 | +import { |
| 8 | + FastForward, |
| 9 | + Github, |
| 10 | + Pause, |
| 11 | + Play, |
| 12 | + Plus, |
| 13 | + Rewind, |
| 14 | + SkipForward, |
| 15 | +} from 'lucide' |
| 16 | +import { writeFile } from 'node:fs/promises' |
| 17 | +import { Icon } from './icon.js' |
| 18 | +import { NEVER } from 'rxjs' |
| 19 | +import { Progress } from './progress.js' |
| 20 | +import { ProgVm } from './progvm.js' |
| 21 | + |
| 22 | +const dom = new JSDOM(` |
| 23 | + <!doctype html> |
| 24 | + <html> |
| 25 | + <head> |
| 26 | + <title>Composite Radial Progress Demo</title> |
| 27 | + <link rel="stylesheet" href="index.css" /> |
| 28 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 29 | + <script type="module" src="index-stamp.js"></script> |
| 30 | + </head> |
| 31 | +
|
| 32 | + <body id="container"></body> |
| 33 | + </html> |
| 34 | +`) |
| 35 | +const { window } = dom |
| 36 | +;(globalThis as any).window = window |
| 37 | +const { document } = window |
| 38 | +;(globalThis as any).document = document |
| 39 | +const jQuery: any = function () {} |
| 40 | +jQuery.fn = {} |
| 41 | +;(globalThis as any).jQuery = jQuery |
| 42 | +const container = document.getElementById('container')! |
| 43 | + |
| 44 | +// *** Main (prestamp) *** |
| 45 | + |
| 46 | +const { context: testMainContext } = makeTestComponentContext({ |
| 47 | + addItem: makeTestEvent<MouseEvent>(NEVER), |
| 48 | + toggleMenu: makeTestEvent<MouseEvent>(NEVER), |
| 49 | + attach: makeTestEvent<HTMLElement>(NEVER), |
| 50 | + pauseAll: makeTestEvent<MouseEvent>(NEVER), |
| 51 | + unpauseAll: makeTestEvent<MouseEvent>(NEVER), |
| 52 | +}) |
| 53 | +// imported late to set globalThis.window above |
| 54 | +const { Main } = await import('./main.js') |
| 55 | +const mainTree = Main({}, testMainContext) |
| 56 | +const mainStamp = buildStamp(mainTree, document) |
| 57 | +container.append(mainStamp.content) |
| 58 | + |
| 59 | +function appendStamp(stamp: HTMLTemplateElement) { |
| 60 | + container.append(stamp) |
| 61 | +} |
| 62 | + |
| 63 | +// *** Icon stamps *** |
| 64 | + |
| 65 | +const githubIconStamp = buildStamp(Icon({ icon: Github }), document) |
| 66 | +githubIconStamp.id = 'icon-github' |
| 67 | +appendStamp(githubIconStamp) |
| 68 | +const pauseIconStamp = buildStamp(Icon({ icon: Pause }), document) |
| 69 | +pauseIconStamp.id = 'icon-pause' |
| 70 | +appendStamp(pauseIconStamp) |
| 71 | +const playIconStamp = buildStamp(Icon({ icon: Play }), document) |
| 72 | +playIconStamp.id = 'icon-play' |
| 73 | +appendStamp(playIconStamp) |
| 74 | +const plusIconStamp = buildStamp(Icon({ icon: Plus }), document) |
| 75 | +plusIconStamp.id = 'icon-plus' |
| 76 | +appendStamp(plusIconStamp) |
| 77 | +const ffIconStamp = buildStamp(Icon({ icon: FastForward }), document) |
| 78 | +ffIconStamp.id = 'icon-fast-forward' |
| 79 | +appendStamp(ffIconStamp) |
| 80 | +const rwIconStamp = buildStamp(Icon({ icon: Rewind }), document) |
| 81 | +rwIconStamp.id = 'icon-rewind' |
| 82 | +appendStamp(rwIconStamp) |
| 83 | +const skipIconStamp = buildStamp(Icon({ icon: SkipForward }), document) |
| 84 | +skipIconStamp.id = 'icon-skip-forward' |
| 85 | +appendStamp(skipIconStamp) |
| 86 | + |
| 87 | +// *** Progress stamp *** |
| 88 | + |
| 89 | +const { context: testProgressContext } = makeTestComponentContext({ |
| 90 | + finish: makeTestEvent<MouseEvent>(NEVER), |
| 91 | + pause: makeTestEvent<MouseEvent>(NEVER), |
| 92 | + slowDown: makeTestEvent<MouseEvent>(NEVER), |
| 93 | + speedUp: makeTestEvent<MouseEvent>(NEVER), |
| 94 | + unpause: makeTestEvent<MouseEvent>(NEVER), |
| 95 | +}) |
| 96 | +const progressTree = Progress({ item: new ProgVm() }, testProgressContext) |
| 97 | +const progressStamp = buildStamp(progressTree, document) |
| 98 | +progressStamp.id = 'progress' |
| 99 | +appendStamp(progressStamp) |
| 100 | + |
| 101 | +// *** Serialize to HTML *** |
| 102 | + |
| 103 | +await writeFile('index.html', dom.serialize()) |
0 commit comments