-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
479 lines (425 loc) · 18.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!doctype html>
<html>
<head>
<title>cdcraft</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="./styles/katex.min.css">
<link rel="stylesheet" href="./styles/bootstrap.css">
<link rel="stylesheet" href="./styles/graphics.css">
<link rel="stylesheet" href="./styles/toolbars.css">
<script src="./libraries/glm-js.min.js"></script>
<script src="./libraries/katex.min.js"></script>
<script src="./libraries/auto-render.min.js"></script>
<script src="./scripts/typecheck.js"></script>
<script src="./scripts/coordinates/ScreenStateStorage.js"></script>
<script src="./scripts/coordinates/ScreenStateStore.js"></script>
<script src="./scripts/coordinates/CoordinateSystems.js"></script>
<script src="./scripts/models/positions/DiagramIds.js"></script>
<script src="./scripts/models/positions/CellHashing.js"></script>
<script src="./scripts/models/positions/PositionMetricBundle.js"></script>
<script src="./scripts/models/nodes/Node.js"></script>
<script src="./scripts/models/nodes/NodeHashing.js"></script>
<script src="./scripts/models/nodes/NodePointIndicationCurried.js"></script>
<script src="./scripts/models/nodes/NodeMetricBundle.js"></script>
<script src="./scripts/models/arcs/StoredArc.js"></script>
<script src="./scripts/models/arcs/UserArc.js"></script>
<script src="./scripts/models/arcs/PointArc.js"></script>
<script src="./scripts/models/arcs/SamplerArc.js"></script>
<script src="./scripts/models/arcs/SvgArc.js"></script>
<script src="./scripts/models/arcs/SamplerArcRendering.js"></script>
<script src="./scripts/models/arcs/SamplerArcTransforms.js"></script>
<script src="./scripts/models/arcs/SamplerArcProperties.js"></script>
<script src="./scripts/models/arcs/SamplerArcMapping.js"></script>
<script src="./scripts/models/arcs/UserArcsAndStoredArcsCurried.js"></script>
<script src="./scripts/models/arcs/StoredArcsAndPointArcsCurried.js"></script>
<script src="./scripts/models/arcs/StoredArcPropertiesCurried.js"></script>
<script src="./scripts/models/arcs/StoredArcPointIndicationCurried.js"></script>
<script src="./scripts/models/arcs/PointArcsAndSamplerArcs.js"></script>
<script src="./scripts/models/arcs/PointArcsAndSvgArcs.js"></script>
<script src="./scripts/models/arcs/PointArcProperties.js"></script>
<script src="./scripts/models/arcs/PointArcMapping.js"></script>
<script src="./scripts/models/arcs/PointArcPointIndication.js"></script>
<script src="./scripts/models/arrows/Arrow.js"></script>
<script src="./scripts/models/arrows/DiagramArrow.js"></script>
<script src="./scripts/models/objects/DiagramObject.js"></script>
<script src="./scripts/models/objects/DiagramObjectSetOperations.js"></script>
<script src="./scripts/models/diagrams/Diagram.js"></script>
<script src="./scripts/models/diagrams/DiagramMetrics.js"></script>
<script src="./scripts/models/app/AppState.js"></script>
<script src="./scripts/models/app/AppHistoryTraversal.js"></script>
<script src="./scripts/models/app/AppDragOperations.js"></script>
<script src="./scripts/views/ViewEventDeferralCurried.js"></script>
<script src="./scripts/views/SvgObjectView.js"></script>
<script src="./scripts/views/SvgObjectSelectionView.js"></script>
<script src="./scripts/views/SvgArrowAttributes.js"></script>
<script src="./scripts/views/SvgArrowView.js"></script>
<script src="./scripts/views/SvgArrowSelectionView.js"></script>
<script src="./scripts/views/SvgArrowMidpointView.js"></script>
<script src="./scripts/views/HtmlObjectToolbarView.js"></script>
<script src="./scripts/views/HtmlArrowToolbarView.js"></script>
<script src="./scripts/views/HtmlMultientityToolbarView.js"></script>
<script src="./scripts/views/SvgGridView.js"></script>
<script src="./scripts/views/SvgAppView.js"></script>
<script src="./scripts/dom/Html.js"></script>
<script src="./scripts/dom/Svg.js"></script>
<script src="./scripts/updaters/drags/AbstractArrowDragCurried.js"></script>
<script src="./scripts/updaters/drags/ViewDrags.js"></script>
<script src="./scripts/updaters/drags/SelectionDrags.js"></script>
<script src="./scripts/updaters/drags/ArrowDrags.js"></script>
<script src="./scripts/updaters/drags/DragState.js"></script>
<script src="./scripts/updaters/AppUpdater.js"></script>
<script src="./scripts/resources/ArrayResource.js"></script>
<script src="./scripts/resources/ArrowPositionsResource.js"></script>
<script src="./scripts/resources/ArrowReferenceResource.js"></script>
<script src="./scripts/resources/ObjectPositionResource.js"></script>
<script src="./scripts/resources/DiagramObjectResource.js"></script>
<script src="./scripts/resources/DiagramArrowResource.js"></script>
<script src="./scripts/resources/ResourceOperations.js"></script>
<script src="./scripts/resources/PositionMapOperations.js"></script>
<script src="./scripts/serializers/url/UrlNumbersCurried.js"></script>
<script src="./scripts/serializers/url/UrlVectorsCurried.js"></script>
<script src="./scripts/serializers/url/UrlUintArraysCurried.js"></script>
<script src="./scripts/serializers/url/UrlStrings.js"></script>
<script src="./scripts/serializers/url/UrlArrays.js"></script>
<script src="./scripts/serializers/url/UrlColors.js"></script>
<script src="./scripts/serializers/url/UrlObjects.js"></script>
<script src="./scripts/serializers/url/UrlArrows.js"></script>
<script src="./scripts/serializers/url/UrlScreenState.js"></script>
<script src="./scripts/serializers/url/UrlDiagrams.js"></script>
<script src="./scripts/serializers/svg/SvgDiagramExport.js"></script>
</head>
<body>
<svg id="graphics">
<g id="transformation">
<g id="cell-borders"></g>
<g id="arrow-midpoint-hitboxes"></g>
<g id="object-selections"></g>
<g id="arrow-selections"></g>
<g id="object-selection-hitboxes" class="hitbox"></g>
<g id="arrow-selection-hitboxes" class="hitbox"></g>
<g id="objects"></g>
<g id="arrows"></g>
</g>
</svg>
<div id="toolbar" class="top left short-axis-group control">
<div class="banner">
<div class="logo">∙⇆∙<div class="title">cdcraft</div></div>
<div class="subtitle">A workspace of commutative diagrams</div>
</div>
<div class="short-axis-group group-joined">
<button id="save-url" type="button" class="btn btn-dark">
<div>URL</div>
<img id="save-url-image" src="icons/link.svg"/>
<img id="saved-url-image" src="icons/clipboard-check.svg"/>
<div id="save-url-hotkey" class="instructions">ctrl+S</div>
</button>
<button id="save-svg" type="button" class="btn btn-dark">
<div>SVG</div>
<img id="save-svg-image" src="icons/code-angles.svg"/>
<img id="saved-svg-image" src="icons/clipboard-check.svg"/>
</button>
<!--
<button id="copy" type="button" class="btn btn-dark">
<div>LaTeX</div>
<img id="save-latex-image" src="icons/code-braces.svg"/>
<img id="saved-latex-image" src="icons/clipboard-check.svg"/>
<div class="instructions">ctrl+S</div>
</button>
<button id="copy" type="button" class="btn btn-dark">
<div>Copy</div>
<img src="icons/copy.svg"/>
<div class="instructions">ctrl+C</div>
</button>
-->
<button id="undo" type="button" class="btn btn-dark" disabled>
<div>Undo</div>
<img src="icons/undo.svg"/>
<div class="instructions">ctrl+Z</div>
</button>
<button id="redo" type="button" class="btn btn-dark" disabled>
<div>Redo</div>
<img src="icons/redo.svg"/>
<div class="instructions">ctrl+Y</div>
</button>
<!--
<button id="paste" type="button" class="btn btn-dark">
<div>Paste</div>
<img src="icons/paste.svg"/>
<div class="instructions">ctrl+V</div>
</button>
<button id="link" type="button" class="btn btn-dark">
<div>Url</div>
<img src="icons/link.svg"/>
</button>
<button id="svg" type="button" class="btn btn-dark">
<div>SVG</div>
<img src="icons/code-angles.svg"/>
</button>
<button id="latex" type="button" class="btn btn-dark">
<div>TikZ</div>
<img src="icons/code-LaTeX.svg"/>
</button>
-->
<button id="toggle-grid" type="button" class="btn btn-dark active">
<div>Grid</div>
<img src="icons/grid.svg"/>
</button>
</div>
</div>
<div class="bottom right mobile-logo">∙⇆∙</div>
<div class="bottom right short-axis-group group-dark group-round control">
<div id="object-toolbar" class="hidden"></div>
<div id="arrow-toolbar" class="hidden"></div>
<div id="multientity-toolbar" class="hidden"></div>
</div>
<script type="text/javascript">
'use strict';
const diagram_ids = DiagramIds(UnboundedCellHashing(PositiveCellHashing(), Math), Math);
const node_metric_bundle = NodeMetricBundle(PositionMetricBundle(diagram_ids, glm));
const point_arc_properties = PointArcProperties(glm, Math);
const stored_curried_arc_properties =
StoredArcPropertiesCurried(
point_arc_properties,
LinearMapping,
ZoomRotateMapping,
0.08 // target offset distance for 2-arrows
);
const point_arcs_and_sampler_arcs =
PointArcsAndSamplerArcs(
point_arc_properties,
Math);
const sampler_arc_properties = SamplerArcProperties();
const stored_arcs_and_point_arcs_curried =
StoredArcsAndPointArcsCurried(
NodePointIndicationCurried(
StoredArcPointIndicationCurried(
PointArcPointIndication(
point_arcs_and_sampler_arcs,
sampler_arc_properties,
0.5))),
stored_curried_arc_properties,
);
const user_arcs_curried_and_stored_arcs =
UserArcsAndStoredArcsCurried(
stored_arcs_and_point_arcs_curried,
stored_curried_arc_properties,
node_metric_bundle, diagram_ids, glm,
0.025, 0.5, 0.25, 0.25, // min loop, max loop, loop snap, nonloop snap
);
const screen_state_storage = ScreenStateStorage();
const svg = Svg();
const html = Html();
const svg_grid_view =
SvgGridView({
svg : svg,
screen_state_storage : screen_state_storage,
diagram_ids : diagram_ids,
PanZoomMapping : PanZoomMapping,
});
const sampler_arc_transforms = SamplerArcTransforms(sampler_arc_properties);
const svg_arrow_attributes =
SvgArrowAttributes({
PanZoomMapping : PanZoomMapping,
AffineMapping : AffineMapping,
AffineRemapping : AffineRemapping,
screen_state_storage : screen_state_storage,
sampler_arc_properties : sampler_arc_properties,
sampler_arc_transforms : sampler_arc_transforms,
sampler_arc_rendering : SamplerArcRendering(sampler_arc_properties),
point_arcs_and_sampler_arcs: point_arcs_and_sampler_arcs,
});
const svg_arrow_view = SvgArrowView({
PanZoomMapping : PanZoomMapping,
AffineMapping : AffineMapping,
AffineRemapping : AffineRemapping,
SamplerArcMapping : SamplerArcMapping,
svg : svg,
html : html,
sampler_arc_properties : sampler_arc_properties,
sampler_arc_transforms : sampler_arc_transforms,
svg_arrow_attributes : svg_arrow_attributes,
screen_state_storage : screen_state_storage,
render : renderMathInElement,
point_arcs_and_sampler_arcs: point_arcs_and_sampler_arcs,
stored_arcs_and_point_arcs_curried: stored_arcs_and_point_arcs_curried,
},
{
source_trim_length: 0.13,
target_trim_length: 0.13,
arrow_line_spacing: 3,
arrow_head_slope: 1,
arrow_line_width: 2,
highlight_width: 0.2,
});
const svg_arrow_selection_view =
SvgArrowSelectionView({
PanZoomMapping : PanZoomMapping,
SamplerArcMapping : SamplerArcMapping,
svg : svg,
screen_state_storage : screen_state_storage,
svg_arrow_attributes : svg_arrow_attributes,
stored_arcs_and_point_arcs_curried: stored_arcs_and_point_arcs_curried,
},
{
source_trim_length: 0.13,
target_trim_length: 0.13,
highlight_width: 0.2,
});
const svg_arrow_midpoint_view =
SvgArrowMidpointView({
PanZoomMapping : PanZoomMapping,
svg : svg,
screen_state_storage : screen_state_storage,
svg_arrow_attributes : svg_arrow_attributes,
sampler_arc_properties : sampler_arc_properties,
sampler_arc_transforms : sampler_arc_transforms,
point_arcs_and_sampler_arcs: point_arcs_and_sampler_arcs,
stored_arcs_and_point_arcs_curried: stored_arcs_and_point_arcs_curried,
},
{
source_trim_length: 0.13,
target_trim_length: 0.13,
midpoint_width: 0.5,
});
const svg_object_view =
SvgObjectView({
PanZoomMapping : PanZoomMapping,
svg : svg,
html : html,
render : renderMathInElement,
screen_state_storage : screen_state_storage,
svg_object_attributes : SvgObjectAttributes(Math),
}, 0.5);
const svg_object_selection_view =
SvgObjectSelectionView({
PanZoomMapping : PanZoomMapping,
svg : svg,
screen_state_storage : screen_state_storage,
}, 0.5);
const node_hashing = NodeHashing(UnboundedCellHashing(PositiveCellHashing(), Math));
const arrow_reference_resource =
ArrowReferenceResource(user_arcs_curried_and_stored_arcs, node_hashing);
const arrow_positions_resource =
ArrowPositionsResource(
arrow_reference_resource,
user_arcs_curried_and_stored_arcs,
node_hashing);
const object_position_resource =
ObjectPositionResource(diagram_ids);
const resource_operations = ResourceOperations();
const selection_drags =
SelectionDrags(
PanZoomMapping,
arrow_positions_resource,
object_position_resource,
resource_operations,
PositionMapOperations(diagram_ids),
DiagramObjectSetOperations(diagram_ids),
);
const arrow_drags =
ArrowDrags(
diagram_ids,
node_hashing,
node_metric_bundle,
AbstractArrowDragCurried(
user_arcs_curried_and_stored_arcs,
stored_arcs_and_point_arcs_curried,
Math,
0.001 // min_length_clockwise_change_per_scroll
),
arrow_reference_resource,
user_arcs_curried_and_stored_arcs,
1.0, // default_min_length_clockwise
);
const view_drags =
ViewDrags(
PanZoomMapping,
screen_state_storage,
-0.001, // log2_cell_width_change_per_scroll
Math.log2(50), // log2_cell_width_min
Math.log2(500) // log2_cell_width_max
);
const app_history_traversal =
AppHistoryTraversal(DiagramMetrics(), Infinity);
const array_resource = ArrayResource();
// svg serializers
const svg_diagram_export = SvgDiagramExport({
screen_state_storage : screen_state_storage,
arrow_positions_resource : arrow_positions_resource,
object_position_resource : object_position_resource,
resource_operations : resource_operations,
svg_arrow_view : svg_arrow_view,
svg_object_view : svg_object_view,
});
// url serializers
const url_floats_curried = UrlNumbersCurried(parseFloat, 10);
const url_ints_curried = UrlNumbersCurried(parseInt, 10);
const url_dependencies = {
url_uint_arrays_curried: UrlUintArraysCurried(UrlNumbersCurried(parseInt, 36)(0,1)),
url_vec2s_curried: UrlVectorsCurried(glm.vec2, url_floats_curried, UrlArrays('_')),
url_ivec2s_curried: UrlVectorsCurried(glm.ivec2, url_ints_curried, UrlArrays('_')),
url_floats_curried: url_floats_curried,
url_ints_curried: url_ints_curried,
url_arrays: UrlArrays(',', ':'),
url_strings: UrlStrings('*'),
url_colors: UrlColors([
['contrast', 0],
['red', 1],
['green', 2],
['yellow', 3],
['blue', 4],
]),
};
const url_diagrams = UrlDiagrams(
UrlArrays('&='),
UrlArrays(';'),
UrlArrows(url_dependencies),
UrlObjects(url_dependencies),
UrlScreenState(url_dependencies),
new ScreenStateStore(glm.vec2(), 8),
0
);
const app_updater =
AppUpdater({
PanZoomMapping : PanZoomMapping,
selection_drags : selection_drags,
arrow_drags : arrow_drags,
view_drags : view_drags,
url_diagrams : url_diagrams,
svg_diagram_export : svg_diagram_export,
screen_state_storage : screen_state_storage,
diagram_object_resources : DiagramObjectResource(array_resource),
diagram_arrow_resources : DiagramArrowResource(array_resource),
drag_state_ops : AppDragOperations(PanZoomMapping, screen_state_storage, app_history_traversal),
app_history_traversal : app_history_traversal,
});
const app_view =
SvgAppView({
screen_state_storage : screen_state_storage,
arrow_positions_resource : arrow_positions_resource,
object_position_resource : object_position_resource,
resource_operations : resource_operations,
svg_grid_view : svg_grid_view,
svg_arrow_view : svg_arrow_view,
svg_object_view : svg_object_view,
svg_object_selection_view : svg_object_selection_view,
svg_arrow_selection_view : svg_arrow_selection_view,
svg_arrow_midpoint_view : svg_arrow_midpoint_view,
view_event_deferal : ViewEventDeferralCurried(),
html_object_toolbar_view : HtmlObjectToolbarView({html:html}),
html_arrow_toolbar_view : HtmlArrowToolbarView({html:html}),
html_multientity_toolbar_view : HtmlMultientityToolbarView({html:html}),
}, app_updater);
const initial_diagram = url_diagrams.import(window.location.search);
const disengaged_drag = view_drags.release(initial_diagram.screen_frame_store);
const app_state =
new AppState(
initial_diagram,
disengaged_drag,
disengaged_drag.initialize(),
);
app_view.wire(app_state, document);
</script>
</body>
</html>