PageSourceSearch

https://pupwife.com/scripts/daw/dawPage.js

js pupwife.com collected 2026-09-30 15:06:36 UTC 3,189 bytes, 107 lines download raw bytes

1/**
2 * Virtual Keyboard page boot — shared by CitrusOS window and standalone daw.html.
3 */
4(function (global) {
5    'use strict';
6
7    global.__dawDeferBoot = true;
8
9    var activeMount = null;
10    var bootPromise = null;
11
12    function getMount(scopeEl) {
13        if (global.CitrusToolContract && typeof global.CitrusToolContract.getMount === 'function') {
14            return global.CitrusToolContract.getMount(scopeEl);
15        }
16        if (!scopeEl) return null;
17        return scopeEl.querySelector('[data-citrus-mount]') ||
18            scopeEl.querySelector('#content') ||
19            scopeEl;
20    }
21
22    function renderMarkup(mount) {
23        if (!mount || !global.DawDesktopMarkup) return;
24        mount.innerHTML = global.DawDesktopMarkup;
25        var root = mount.querySelector('#daw-app-root');
26        if (root) {
27            root.classList.add('daw-citrus');
28        }
29    }
30
31    function waitForDawModule() {
32        if (global.DAW) return Promise.resolve(global.DAW);
33        if (global.__dawBootPromise) return global.__dawBootPromise;
34        return new Promise(function (resolve, reject) {
35            var attempts = 0;
36            var timer = global.setInterval(function () {
37                attempts++;
38                if (global.DAW) {
39                    global.clearInterval(timer);
40                    resolve(global.DAW);
41                } else if (attempts > 200) {
42                    global.clearInterval(timer);
43                    reject(new Error('Virtual Keyboard module failed to load'));
44                }
45            }, 50);
46        });
47    }
48
49    function ensureBooted() {
50        if (bootPromise) return bootPromise;
51
52        bootPromise = waitForDawModule().then(function (daw) {
53            if (global.DawEngine) global.DawEngine.bind(daw);
54            if (!daw.isInitialized) {
55                return daw.init().then(function () { return daw; });
56            }
57            return daw;
58        });
59
60        return bootPromise;
61    }
62
63    function init(scopeEl) {
64        var mount = getMount(scopeEl);
65        if (!mount) return Promise.resolve();
66
67        activeMount = mount;
68        renderMarkup(mount);
69
70        if (typeof global.initializeDAW === 'function' && !global.DAW) {
71            global.initializeDAW();
72        }
73
74        return ensureBooted();
75    }
76
77    function destroy(scopeEl) {
78        var mount = getMount(scopeEl) || activeMount;
79        activeMount = null;
80        bootPromise = null;
81
82        if (global.DawEngine) {
83            global.DawEngine.allNotesOff();
84            global.DawEngine.setPhysicalMidiEnabled(false);
85            global.DawEngine.suspendAudio();
86            global.DawEngine.unbind();
87        }
88
89        if (global.DAW && typeof global.DAW.destroy === 'function') {
90            try {
91                global.DAW.destroy();
92            } catch (e) {
93                console.warn('[DawPage] destroy failed', e);
94            }
95        }
96        global.DAW = null;
97
98        if (mount) mount.innerHTML = '';
99        return Promise.resolve();
100    }
101
102    global.DawPage = {
103        init: init,
104        destroy: destroy,
105        renderMarkup: renderMarkup
106    };
107})(typeof window !== 'undefined' ? window : this);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.