@popcorn245/cornfield 0.46.1 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/explorer/capped.js +3 -2
- package/explorer/engine/feedback.js +49 -0
- package/explorer/engine/flow-ui.js +39 -0
- package/explorer/engine/fly.js +54 -0
- package/explorer/engine/hint.js +98 -0
- package/explorer/engine/keyboard.js +156 -0
- package/explorer/engine/layers.js +280 -0
- package/explorer/engine/layout.js +378 -0
- package/explorer/engine/map-style.js +552 -0
- package/explorer/engine/piece.js +142 -0
- package/explorer/engine/render.js +331 -0
- package/explorer/engine/search-status.js +59 -0
- package/explorer/engine/selection.js +42 -0
- package/explorer/engine/sheets.js +417 -0
- package/explorer/engine/strings.js +63 -0
- package/explorer/feedback.js +11 -45
- package/explorer/flow-build.js +88 -0
- package/explorer/flow-style.js +28 -0
- package/explorer/flows.js +11 -132
- package/explorer/fly.js +11 -43
- package/explorer/hint.js +15 -88
- package/explorer/index.html +40 -82
- package/explorer/input.js +197 -177
- package/explorer/instance-state.js +172 -0
- package/explorer/instance.js +267 -0
- package/explorer/keyboard.js +14 -206
- package/explorer/labels.js +3 -3
- package/explorer/layers.js +34 -445
- package/explorer/layout.js +14 -372
- package/explorer/main.js +4 -226
- package/explorer/map-style.js +27 -525
- package/explorer/mockups-model.js +3 -3
- package/explorer/page-pieces.js +66 -0
- package/explorer/page.js +223 -0
- package/explorer/panels.js +29 -409
- package/explorer/pieces/adopt-tokens.js +38 -0
- package/explorer/pieces/layers.js +325 -0
- package/explorer/pieces/map-stage.css +14 -0
- package/explorer/pieces/map.js +332 -0
- package/explorer/pieces/node-panel.js +536 -0
- package/explorer/pieces/search.js +454 -0
- package/explorer/proposal-model.js +1 -1
- package/explorer/proposal.js +1 -0
- package/explorer/render.js +37 -267
- package/explorer/renderer-canvas2d.js +4 -4
- package/explorer/renderer-webgl.js +21 -8
- package/explorer/renderer.js +12 -9
- package/explorer/scene.js +3 -2
- package/explorer/search-status.js +8 -47
- package/explorer/search.js +26 -324
- package/explorer/selection-view.js +17 -19
- package/explorer/sheets.js +31 -379
- package/explorer/state.js +38 -173
- package/explorer/strings.js +17 -60
- package/explorer/view.js +4 -5
- package/package.json +1 -1
package/explorer/page.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/page
|
|
3
|
+
*
|
|
4
|
+
* cornfield's own page: the shell that mounts the engine in the document (spec 0011 D1, D2). explorer/main.js (which index.html loads) only
|
|
5
|
+
* calls `startPage()`. It makes exactly one instance (instance.js) with the document as its root, starts the map on it, and wires the header,
|
|
6
|
+
* the Layers menu and the side panel to the modules that do the work (some are on the instance already, some still reach it through
|
|
7
|
+
* state.js), loads topology.json, then the sources the repo's config names (plugins.js).
|
|
8
|
+
*
|
|
9
|
+
* This is the one module that may read `location`, write `history` and listen on `document`: the address bar, the click on any
|
|
10
|
+
* `data-action` and the deep links belong to the page, not to a piece. (test/explorer/instance-tripwires.test.js exempts it.)
|
|
11
|
+
*
|
|
12
|
+
* instance.js the instance (state, root, base) engine/layout.js where nodes sit (orbit, lanes, freeform)
|
|
13
|
+
* engine/render.js the camera and the loop flows.js flow styling, legend, the data-flow preset
|
|
14
|
+
* scene.js what is drawn (contract) renderer.js how it is drawn: renderer-webgl.js or renderer-canvas2d.js
|
|
15
|
+
* pieces/ the node panel, the Layers menu and the search: pieces mounted where index.html has their places (page-pieces.js)
|
|
16
|
+
* view.js loading and view switching input.js mouse and touch
|
|
17
|
+
* proposal.js the proposal overlay (picker, Before / Diff / After); proposal-model.js its pure half
|
|
18
|
+
* whatif.js what-if edits on an open proposal (add, remove, draw, steps, undo); whatif-model.js its pure half
|
|
19
|
+
* review.js approve a proposal or send it back with a note and the edits; review-model.js its pure half
|
|
20
|
+
* deep-link.js ?run=, ?issue= and ?proposal=…&start=1 land on a run, an issue and a Start dialog
|
|
21
|
+
* scenario.js the player's pure core scenario-ui.js its bar, keys and camera
|
|
22
|
+
* bench.js /?bench=1 stopwatch and /?fixture=5k (the generated topology, from the server)
|
|
23
|
+
* keyboard.js the map by keyboard and the screen reader's announcer; keyboard-model.js its pure half
|
|
24
|
+
* live.js the live layer: the chip, polling, laying a live source's answer over the map; live-model.js its pure half
|
|
25
|
+
* review-tokens.js review tokens for the review API, when somebody is signed in: make one (shown once), list, revoke; review-tokens-model.js its pure half
|
|
26
|
+
* forge-panel.js the issues and PRs panel, when the config names a forge: a PR lights the nodes it changes; forge-panel-model.js its pure half
|
|
27
|
+
* theme.js light or dark: the system setting and the header toggle; theme-model.js the colours (theme-boot.js before the first paint)
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { state, startPageInstance } from './state.js';
|
|
31
|
+
import { createMap } from './engine/render.js';
|
|
32
|
+
import { rendererPreference } from './renderer.js';
|
|
33
|
+
import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './engine/layout.js';
|
|
34
|
+
import { measureCovered } from './sheets.js';
|
|
35
|
+
import { setProjectLayers } from './layers.js';
|
|
36
|
+
import { closeDrawer } from './panels.js';
|
|
37
|
+
import { ensurePagePieces, pieceSlots } from './page-pieces.js';
|
|
38
|
+
import { initScenarioUi, maybeStartDemo, playOutage } from './scenario-ui.js';
|
|
39
|
+
import { initSheets } from './sheets.js';
|
|
40
|
+
import { initReviewColumn } from './review-column.js';
|
|
41
|
+
import { loadTopology, setView, syncViewUi } from './view.js';
|
|
42
|
+
import { mount as mountMap, KEYS_HELP_WITH_PANEL } from './pieces/map.js';
|
|
43
|
+
import { initProposals } from './proposal.js';
|
|
44
|
+
import { followDeepLink } from './deep-link.js';
|
|
45
|
+
import { initWhatIf } from './whatif.js';
|
|
46
|
+
import { initReview } from './review.js';
|
|
47
|
+
import { initMockups } from './mockups.js';
|
|
48
|
+
import { benchMeta, measureParams, readoutLines, resultLine, runBench, showReadout } from './bench.js';
|
|
49
|
+
import { initLive } from './live.js';
|
|
50
|
+
import { initHouse } from './house.js';
|
|
51
|
+
import { houseOffered } from './house-model.js';
|
|
52
|
+
import { initChecks } from './check.js';
|
|
53
|
+
import { initKeyboard } from './keyboard.js';
|
|
54
|
+
import { initForgePanel } from './forge-panel.js';
|
|
55
|
+
import { initReviewTokens } from './review-tokens.js';
|
|
56
|
+
import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
|
|
57
|
+
import { initTheme, setThemeChoice } from './theme.js';
|
|
58
|
+
import { initAccountMenu } from './account-menu.js';
|
|
59
|
+
import { watchHeaderFit } from './header-fit.js';
|
|
60
|
+
import { watchHint } from './hint.js';
|
|
61
|
+
import { watchFocusRoom } from './focus-room.js';
|
|
62
|
+
import { mapStyleOf } from './engine/map-style.js';
|
|
63
|
+
|
|
64
|
+
/** The instance and its map: made by `startPage`, the one of this document */
|
|
65
|
+
let inst;
|
|
66
|
+
let map;
|
|
67
|
+
|
|
68
|
+
const $ = (id) => inst.el(id);
|
|
69
|
+
const render = () => map.render();
|
|
70
|
+
const fitGraphToViewport = (...a) => map.fitGraphToViewport(...a);
|
|
71
|
+
const fitPadding = () => map.fitPadding();
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Freeform mode: orbit clustering (locked) or dragging nodes anywhere
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
function updateFreeformUI() {
|
|
77
|
+
const on = state.isFreeform;
|
|
78
|
+
$('freeform-toggle-btn').setAttribute('aria-checked', String(on));
|
|
79
|
+
$('reset-positions-btn').hidden = !on;
|
|
80
|
+
syncViewUi();
|
|
81
|
+
state.canvas.style.cursor = on ? 'default' : 'grab';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toggleFreeformMode() {
|
|
85
|
+
setView('orbit'); // positions are only draggable on the full map
|
|
86
|
+
state.isFreeform = !state.isFreeform;
|
|
87
|
+
layoutOrbit(inst);
|
|
88
|
+
updateFreeformUI();
|
|
89
|
+
render();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resetFreeformPositions() {
|
|
93
|
+
clearFreeformPositions(inst);
|
|
94
|
+
layoutOrbit(inst);
|
|
95
|
+
updateFreeformUI();
|
|
96
|
+
render();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// One click handler for everything with a data-action
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
const ACTIONS = {
|
|
103
|
+
'reset-view': () => fitGraphToViewport(fitPadding()),
|
|
104
|
+
'fit': () => fitGraphToViewport(fitPadding()),
|
|
105
|
+
'toggle-freeform': () => toggleFreeformMode(),
|
|
106
|
+
'reset-positions': () => resetFreeformPositions(),
|
|
107
|
+
'preset-map': () => {
|
|
108
|
+
closeDrawer();
|
|
109
|
+
setView('orbit');
|
|
110
|
+
},
|
|
111
|
+
'preset-dataflow': () => {
|
|
112
|
+
closeDrawer();
|
|
113
|
+
setView(state.view === 'dataflow' ? 'orbit' : 'dataflow');
|
|
114
|
+
},
|
|
115
|
+
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
116
|
+
'retry': () => loadTopology(),
|
|
117
|
+
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// The click on a control the page owns (the header's View switch, Fit, Retry, the theme and the Freeform layout). The pieces' controls are their own:
|
|
121
|
+
// the node panel's, the Layers menu's and the search's (explorer/pieces/), which also close the Layers menu on a click outside it
|
|
122
|
+
document.addEventListener('click', (e) => {
|
|
123
|
+
const target = e.target.closest('[data-action]');
|
|
124
|
+
if (target) {
|
|
125
|
+
const action = ACTIONS[target.dataset.action];
|
|
126
|
+
if (action) action(target);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// /?bench=1: the scripted pan-and-zoom of bench.js on the map as loaded
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
async function runPageBench(frames, zoomFactor, sync) {
|
|
134
|
+
fitGraphToViewport(fitPadding());
|
|
135
|
+
const { camera, width, height } = state;
|
|
136
|
+
const base = { zoom: camera.zoom, cx: (width / 2 - camera.x) / camera.zoom, cy: (height / 2 - camera.y) / camera.zoom, width, height, zoomFactor };
|
|
137
|
+
const result = await runBench({
|
|
138
|
+
frames,
|
|
139
|
+
base,
|
|
140
|
+
setCamera: (c) => { camera.x = c.x; camera.y = c.y; camera.zoom = c.zoom; },
|
|
141
|
+
// renderNow draws this instant (and the labels with it), so a measured frame is a whole one
|
|
142
|
+
draw: () => {
|
|
143
|
+
map.renderNow();
|
|
144
|
+
// ?sync=1: wait for the GPU, so the time in draw is the whole frame's and not just the hand-over
|
|
145
|
+
if (sync) { const gl = state.canvas.getContext('webgl2'); if (gl) gl.finish(); }
|
|
146
|
+
},
|
|
147
|
+
// The page's own frames (a packet loop, a pending draw) would add draws the script does not count:
|
|
148
|
+
// hold them while the run lasts, then let go, so the run draws what a viewer sees
|
|
149
|
+
before: () => map.holdFrames(true),
|
|
150
|
+
after: () => { map.holdFrames(false); fitGraphToViewport(fitPadding()); map.ensureFlowLoop(); },
|
|
151
|
+
});
|
|
152
|
+
const meta = benchMeta({
|
|
153
|
+
nodes: state.nodes.length, edges: state.edges.length, view: state.view, renderer: map.getRenderer().kind,
|
|
154
|
+
zoomFactor, width, height, dpr: window.devicePixelRatio, search: window.location.search,
|
|
155
|
+
});
|
|
156
|
+
const line = resultLine(result, meta);
|
|
157
|
+
console.log(line);
|
|
158
|
+
window.__bench = { result, meta, line };
|
|
159
|
+
showReadout(document, readoutLines(result, meta));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Start
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
/**
|
|
166
|
+
* Starts cornfield's page: the one instance of this document, its map, and everything the page shows. Called once, by main.js.
|
|
167
|
+
* @returns {ReturnType<typeof startPageInstance>} the page's instance
|
|
168
|
+
*/
|
|
169
|
+
export function startPage() {
|
|
170
|
+
inst = startPageInstance({ root: document }); // the one instance of this document, the document its root; state.js hands the modules that are not yet on an instance its state
|
|
171
|
+
map = createMap(inst, { measureCovered }); // the camera, the scene and the frame loop of this instance (engine/render.js)
|
|
172
|
+
const mapStyle = mapStyleOf(inst);
|
|
173
|
+
initTheme(); // light or dark, before the first scene is built (theme.js)
|
|
174
|
+
// The map piece (pieces/map.js, also what <corn-map> mounts) makes the map's canvases, their keys' help and the announcer where index.html keeps
|
|
175
|
+
// `<!--corn-piece:map/stage-->`. It watches the theme's tokens (the map reads --corn-map-* from the theme, and again when it changes), makes the
|
|
176
|
+
// renderer (WebGL2, or Canvas 2D when it is missing or the address says ?renderer=canvas2d: the address is read here, not by the renderer), binds
|
|
177
|
+
// the canvas and its keys (engine/keyboard.js), follows the box's size, and answers a tap (a node's panel, the normal view, the end of a flight)
|
|
178
|
+
mountMap(document.body, inst, {
|
|
179
|
+
slots: pieceSlots('map'), measureCovered, keysHelp: KEYS_HELP_WITH_PANEL,
|
|
180
|
+
renderer: rendererPreference(window.location.search) === 'canvas2d' ? 'canvas2d' : 'auto',
|
|
181
|
+
});
|
|
182
|
+
loadFreeformPositions(inst);
|
|
183
|
+
ensurePagePieces(); // the node panel, the Layers menu and the search, mounted where index.html has their places (page-pieces.js)
|
|
184
|
+
initKeyboard(); // the map by keyboard (the panel's, the Layers menu's and the search's keys are their pieces') (engine/keyboard.js)
|
|
185
|
+
initAccountMenu(); // the one menu at the right of the header (account-menu.js)
|
|
186
|
+
initSheets();
|
|
187
|
+
initScenarioUi();
|
|
188
|
+
initReviewColumn(); // the review column: the changes, and the personas with their scenarios (review-column.js)
|
|
189
|
+
|
|
190
|
+
map.resize();
|
|
191
|
+
syncViewUi();
|
|
192
|
+
// /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
|
|
193
|
+
const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); mapStyle.applyTheme(config.theme); setProjectLayers(config.layers); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
|
|
194
|
+
loadTopology().then(async (ok) => {
|
|
195
|
+
if (!ok) return;
|
|
196
|
+
// The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
|
|
197
|
+
const config = await configReady;
|
|
198
|
+
state.forge = config.forge || null;
|
|
199
|
+
const { liveSource, floorRenderer, checker, houseSource } = await loadSources(config);
|
|
200
|
+
const forgeOn = initForgePanel(config); // issues and PRs: only when the config names a forge (forge-panel.js)
|
|
201
|
+
initReviewTokens(config); // review tokens for the review API: only for somebody signed in (review-tokens.js)
|
|
202
|
+
initWhatIf(); // before a proposal can open, so its edits come with it
|
|
203
|
+
initReview(); // after it: the review controls sit under the edit controls on the bar
|
|
204
|
+
initMockups(); // a proposal's screens open from the node they name
|
|
205
|
+
const proposalOpened = await initProposals();
|
|
206
|
+
// The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
|
|
207
|
+
initLive({ source: liveSource, onSelectionGone: closeDrawer });
|
|
208
|
+
// The House view (house.js): a source's floor renderer draws the plan under the map (plain room boxes without one); /?view=house opens it
|
|
209
|
+
initHouse({ floor: floorRenderer, offered: houseOffered(houseSource, state.nodes) }); // no house source and no house in the map: no House button
|
|
210
|
+
initChecks({ checker }); // scenarios ask the source's checker, when there is one (check.js)
|
|
211
|
+
if (new URLSearchParams(window.location.search).get("view") === "dataflow") setView("dataflow");
|
|
212
|
+
// /?run=, /?issue= and /?proposal=…&start=1 land on a run, an issue's Start button and a proposal's Start dialog (deep-link.js)
|
|
213
|
+
followDeepLink({ proposalOpened, forgeOn }).catch((err) => console.error('Following the link failed', err));
|
|
214
|
+
// /?scenario-demo=1 plays a small scenario over real nodes, to look at the player
|
|
215
|
+
maybeStartDemo();
|
|
216
|
+
// /?bench=1 runs the stopwatch (bench.js) once the map is up
|
|
217
|
+
const { benchFrames, benchZoom, benchSync } = measureParams(window.location.search);
|
|
218
|
+
if (benchFrames) {
|
|
219
|
+
try { await runPageBench(benchFrames, benchZoom, benchSync); } catch (err) { console.error("The bench failed", err); }
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return inst;
|
|
223
|
+
}
|