@jsb188/schedule 1.1.2

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.
Files changed (60) hide show
  1. package/package.json +62 -0
  2. package/src/constants/schedule.ts +549 -0
  3. package/src/css.d.ts +7 -0
  4. package/src/libs/gantt-geometry.ts +771 -0
  5. package/src/libs/gantt-histogram.ts +124 -0
  6. package/src/libs/gantt-keyboard.ts +113 -0
  7. package/src/libs/gantt-state.ts +57 -0
  8. package/src/libs/gantt-url.ts +63 -0
  9. package/src/modules/Gantt.helpers.ts +119 -0
  10. package/src/modules/Gantt.tsx +584 -0
  11. package/src/types/schedule.d.ts +1149 -0
  12. package/src/ui/ActivityFormUI.tsx +133 -0
  13. package/src/ui/GanttEditorsUI.tsx +102 -0
  14. package/src/ui/GanttHistogramUI.tsx +236 -0
  15. package/src/ui/GanttUI.tsx +792 -0
  16. package/src/ui/ProjectFormUI.tsx +250 -0
  17. package/src/ui/ProjectMobileListUI.tsx +80 -0
  18. package/src/ui/ProjectToolbarUI.tsx +54 -0
  19. package/src/ui/RelationshipListUI.tsx +176 -0
  20. package/src/ui/ScheduleRunUI.tsx +173 -0
  21. package/src/ui/ScheduleSettingsUI.tsx +420 -0
  22. package/src/utils/coverage.helpers.ts +679 -0
  23. package/src/utils/coverage.ts +630 -0
  24. package/src/utils/cpm.helpers.ts +674 -0
  25. package/src/utils/cpm.ts +907 -0
  26. package/src/utils/cpmLeveling.helpers.ts +564 -0
  27. package/src/utils/cpmLeveling.ts +367 -0
  28. package/src/utils/defaults.ts +8 -0
  29. package/src/utils/eligibility.ts +457 -0
  30. package/src/utils/planCsv.ts +344 -0
  31. package/src/utils/predecessorText.ts +96 -0
  32. package/src/utils/recurrence.ts +616 -0
  33. package/src/utils/request.ts +153 -0
  34. package/src/utils/resource.ts +182 -0
  35. package/src/utils/rule.ts +216 -0
  36. package/src/utils/run.ts +43 -0
  37. package/src/utils/series.ts +161 -0
  38. package/src/utils/slot.ts +208 -0
  39. package/src/utils/workTime.ts +1382 -0
  40. package/tests/coverage.fixtures.ts +111 -0
  41. package/tests/coverage.test.ts +503 -0
  42. package/tests/cpm.bench.test.ts +154 -0
  43. package/tests/cpm.test.ts +354 -0
  44. package/tests/cpmCorrectness.test.ts +327 -0
  45. package/tests/cpmLeveling.test.ts +471 -0
  46. package/tests/eligibility.test.ts +320 -0
  47. package/tests/gantt-geometry.test.ts +367 -0
  48. package/tests/gantt-histogram.test.ts +78 -0
  49. package/tests/gantt-keyboard.test.ts +69 -0
  50. package/tests/helpers/cpmFixtures.ts +101 -0
  51. package/tests/projectInputs.test.ts +165 -0
  52. package/tests/recurrence.test.ts +68 -0
  53. package/tests/request.test.ts +99 -0
  54. package/tests/resource.test.ts +95 -0
  55. package/tests/rule.test.ts +98 -0
  56. package/tests/series.test.ts +120 -0
  57. package/tests/workTime.test.ts +1007 -0
  58. package/tests/workTimeContracts.test.ts +111 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +8 -0
@@ -0,0 +1,124 @@
1
+ import { DateTime } from 'luxon';
2
+ import { getGanttX, type GanttScaleObj } from './gantt-geometry.ts';
3
+
4
+ export interface GanttUsageDay {
5
+ resourceId: string;
6
+ date: string;
7
+ demandUnits: number;
8
+ externalUnits: number;
9
+ availableUnits: number | null;
10
+ overallocated?: boolean;
11
+ }
12
+
13
+ export interface GanttHistogramBar {
14
+ date: string;
15
+ x: number;
16
+ width: number;
17
+ demandHeight: number;
18
+ externalHeight: number;
19
+ availableY: number;
20
+ overallocated: boolean;
21
+ demandUnits: number;
22
+ externalUnits: number;
23
+ availableUnits: number | null;
24
+ }
25
+
26
+ /* Restrict the usage query to at most 1,100 local days around the project data date. */
27
+ export function clampGanttHistogramRange(
28
+ scale: GanttScaleObj,
29
+ dataDateAt: Date | string,
30
+ ) {
31
+ const anchor = DateTime.fromJSDate(new Date(dataDateAt), {
32
+ zone: scale.timeZone,
33
+ }).startOf('day');
34
+ const axisStart = DateTime.fromJSDate(scale.startAt, {
35
+ zone: scale.timeZone,
36
+ }).startOf('day');
37
+ const axisEnd = DateTime.fromJSDate(scale.endAt, {
38
+ zone: scale.timeZone,
39
+ }).startOf('day');
40
+ const floor = anchor.minus({ days: 30 });
41
+ const ceiling = anchor.plus({ days: 1070 });
42
+ const from = DateTime.max(axisStart, floor);
43
+ const to = DateTime.min(axisEnd, ceiling);
44
+ return {
45
+ from: from.toISODate()!,
46
+ to: DateTime.max(from, to).toISODate()!,
47
+ clamped: from > axisStart || to < axisEnd,
48
+ };
49
+ }
50
+
51
+ /* Convert one resource's daily demand into a bounded stacked lane using local-day coordinates. */
52
+ export function buildGanttHistogram(
53
+ rows: GanttUsageDay[],
54
+ scale: GanttScaleObj,
55
+ resourceId: string,
56
+ laneHeight = 24,
57
+ ): GanttHistogramBar[] {
58
+ const bars: GanttHistogramBar[] = [];
59
+ for (const row of rows) {
60
+ if (row.resourceId !== resourceId) continue;
61
+ const date = DateTime.fromISO(row.date, { zone: scale.timeZone }).startOf(
62
+ 'day',
63
+ );
64
+ if (
65
+ !date.isValid ||
66
+ date.toMillis() < scale.startAt.getTime() ||
67
+ date.toMillis() >= scale.endAt.getTime()
68
+ )
69
+ continue;
70
+ const demand = Math.max(0, Number(row.demandUnits) || 0);
71
+ const external = Math.max(0, Number(row.externalUnits) || 0);
72
+ const available =
73
+ row.availableUnits === null
74
+ ? demand + external
75
+ : Math.max(0, Number(row.availableUnits) || 0);
76
+ const denominator = Math.max(available, demand + external, 1e-9);
77
+ bars.push({
78
+ date: row.date,
79
+ x: getGanttX(scale, date.toJSDate()),
80
+ width: scale.dayWidth,
81
+ demandHeight: (laneHeight * demand) / denominator,
82
+ externalHeight: (laneHeight * external) / denominator,
83
+ availableY: laneHeight * (1 - available / denominator),
84
+ overallocated: demand + external > available + 1e-9,
85
+ demandUnits: demand,
86
+ externalUnits: external,
87
+ availableUnits: row.availableUnits === null ? null : available,
88
+ });
89
+ }
90
+ return bars;
91
+ }
92
+
93
+ /* Build a local-day axis when the histogram is displayed without a Gantt viewport. */
94
+ export function buildGanttHistogramScale(
95
+ fromDate: string,
96
+ toDate: string,
97
+ timeZone: string,
98
+ ): GanttScaleObj {
99
+ const start = DateTime.fromISO(fromDate, { zone: timeZone }).startOf('day');
100
+ const end = DateTime.max(
101
+ start.plus({ days: 1 }),
102
+ DateTime.fromISO(toDate, { zone: timeZone }).startOf('day'),
103
+ );
104
+ const dayWidth = 14;
105
+ const majorTicks: GanttScaleObj['majorTicks'] = [];
106
+ for (let cursor = start; cursor < end; cursor = cursor.plus({ days: 7 })) {
107
+ const next = DateTime.min(end, cursor.plus({ days: 7 }));
108
+ majorTicks.push({
109
+ x: cursor.diff(start, 'days').days * dayWidth,
110
+ width: next.diff(cursor, 'days').days * dayWidth,
111
+ label: cursor.toLocaleString({ month: 'short', day: 'numeric' }),
112
+ });
113
+ }
114
+ return {
115
+ zoom: 'WEEK',
116
+ timeZone,
117
+ startAt: start.toJSDate(),
118
+ endAt: end.toJSDate(),
119
+ dayWidth,
120
+ totalWidth: end.diff(start, 'days').days * dayWidth,
121
+ majorTicks,
122
+ minorTicks: [],
123
+ };
124
+ }
@@ -0,0 +1,113 @@
1
+ import type { GanttZoomEnum } from './gantt-geometry.ts';
2
+
3
+ export interface GanttKeyboardContext {
4
+ rowIndex: number;
5
+ rowCount: number;
6
+ columnIndex: number;
7
+ columnCount: number;
8
+ pageSize: number;
9
+ isWbs: boolean;
10
+ editable: boolean;
11
+ zoom: GanttZoomEnum;
12
+ }
13
+
14
+ export type GanttKeyAction =
15
+ | { kind: 'MOVE'; rowIndex: number; columnIndex: number; extend: boolean }
16
+ | { kind: 'EDIT'; initialText?: string }
17
+ | { kind: 'COLLAPSE'; collapsed?: boolean }
18
+ | { kind: 'INSERT'; wbs: boolean }
19
+ | { kind: 'INDENT'; outdent: boolean }
20
+ | { kind: 'ZOOM'; zoom: GanttZoomEnum }
21
+ | { kind: 'DELETE' | 'ESCAPE' | 'SEARCH' };
22
+
23
+ /* Translate grid keys into intents without touching DOM, selection stores, or server data. */
24
+ export function handleGanttKeyboardEvent(
25
+ event: Pick<
26
+ KeyboardEvent,
27
+ 'key' | 'ctrlKey' | 'metaKey' | 'altKey' | 'shiftKey'
28
+ >,
29
+ context: GanttKeyboardContext,
30
+ ): GanttKeyAction | null {
31
+ const command = event.ctrlKey || event.metaKey;
32
+ if (command && event.key.toLowerCase() === 'f') return { kind: 'SEARCH' };
33
+ if (event.key === 'Escape') return { kind: 'ESCAPE' };
34
+ if (
35
+ context.editable &&
36
+ (event.key === 'Insert' || (command && event.key === 'Enter'))
37
+ )
38
+ return { kind: 'INSERT', wbs: command && event.shiftKey };
39
+ if (context.editable && ['Delete', 'Backspace'].includes(event.key))
40
+ return { kind: 'DELETE' };
41
+ if (event.altKey && ['ArrowLeft', 'ArrowRight'].includes(event.key))
42
+ return context.editable
43
+ ? { kind: 'INDENT', outdent: event.key === 'ArrowLeft' }
44
+ : null;
45
+ if (!command && !event.altKey && (event.key === '+' || event.key === '-')) {
46
+ const zooms: GanttZoomEnum[] = ['DAY', 'WEEK', 'MONTH'];
47
+ return {
48
+ kind: 'ZOOM',
49
+ zoom: zooms[
50
+ Math.max(
51
+ 0,
52
+ Math.min(
53
+ 2,
54
+ zooms.indexOf(context.zoom) + (event.key === '+' ? -1 : 1),
55
+ ),
56
+ )
57
+ ],
58
+ };
59
+ }
60
+ if (!context.rowCount || command || event.altKey) return null;
61
+ if (event.key === ' ') return context.isWbs ? { kind: 'COLLAPSE' } : null;
62
+ if (context.editable && (event.key === 'Enter' || event.key === 'F2'))
63
+ return { kind: 'EDIT' };
64
+ let rowIndex = context.rowIndex;
65
+ let columnIndex = context.columnIndex;
66
+ switch (event.key) {
67
+ case 'ArrowUp':
68
+ rowIndex -= 1;
69
+ break;
70
+ case 'ArrowDown':
71
+ rowIndex += 1;
72
+ break;
73
+ case 'Home':
74
+ rowIndex = 0;
75
+ break;
76
+ case 'End':
77
+ rowIndex = context.rowCount - 1;
78
+ break;
79
+ case 'PageUp':
80
+ rowIndex -= context.pageSize;
81
+ break;
82
+ case 'PageDown':
83
+ rowIndex += context.pageSize;
84
+ break;
85
+ case 'ArrowLeft':
86
+ columnIndex -= 1;
87
+ break;
88
+ case 'ArrowRight':
89
+ columnIndex += 1;
90
+ break;
91
+ case 'Tab':
92
+ columnIndex += event.shiftKey ? -1 : 1;
93
+ if (columnIndex < 0) {
94
+ columnIndex = context.columnCount - 1;
95
+ rowIndex -= 1;
96
+ }
97
+ if (columnIndex >= context.columnCount) {
98
+ columnIndex = 0;
99
+ rowIndex += 1;
100
+ }
101
+ break;
102
+ default:
103
+ return context.editable && event.key.length === 1
104
+ ? { kind: 'EDIT', initialText: event.key }
105
+ : null;
106
+ }
107
+ return {
108
+ kind: 'MOVE',
109
+ rowIndex: Math.max(0, Math.min(context.rowCount - 1, rowIndex)),
110
+ columnIndex: Math.max(0, Math.min(context.columnCount - 1, columnIndex)),
111
+ extend: event.shiftKey && event.key !== 'Tab',
112
+ };
113
+ }
@@ -0,0 +1,57 @@
1
+ import { atom, type PrimitiveAtom, useAtomValue } from 'jotai';
2
+ import { selectAtom } from 'jotai/utils';
3
+ import { useMemo } from 'react';
4
+
5
+ export type GanttSelectionAtom = PrimitiveAtom<Set<string>>;
6
+
7
+ /* Create a selection store per mounted chart so simultaneous projects do not share selection. */
8
+ export function createGanttSelectionAtom(): GanttSelectionAtom {
9
+ return atom(new Set<string>());
10
+ }
11
+
12
+ /* Subscribe one row to its selected flag, avoiding a rerender of every visible row on each click. */
13
+ export function useGanttRowSelected(
14
+ selection: GanttSelectionAtom,
15
+ id: string,
16
+ ): boolean {
17
+ const selected = useMemo(
18
+ () => selectAtom(selection, (ids) => ids.has(id)),
19
+ [selection, id],
20
+ );
21
+ return useAtomValue(selected);
22
+ }
23
+
24
+ /* Apply pointer selection with standard range and additive modifiers. */
25
+ export function getGanttSelection(
26
+ current: Set<string>,
27
+ rows: Array<{ id: string }>,
28
+ id: string,
29
+ anchorId: string | null,
30
+ additive: boolean,
31
+ range: boolean,
32
+ ): Set<string> {
33
+ if (range && anchorId) {
34
+ let from = -1;
35
+ let to = -1;
36
+ for (
37
+ let index = 0;
38
+ index < rows.length && (from < 0 || to < 0);
39
+ index += 1
40
+ ) {
41
+ if (rows[index].id === anchorId) from = index;
42
+ if (rows[index].id === id) to = index;
43
+ }
44
+ if (from >= 0 && to >= 0) {
45
+ const next = additive ? new Set(current) : new Set<string>();
46
+ const end = Math.max(from, to);
47
+ for (let index = Math.min(from, to); index <= end; index += 1)
48
+ next.add(rows[index].id);
49
+ return next;
50
+ }
51
+ }
52
+ if (!additive) return new Set([id]);
53
+ const next = new Set(current);
54
+ if (next.has(id)) next.delete(id);
55
+ else next.add(id);
56
+ return next;
57
+ }
@@ -0,0 +1,63 @@
1
+ import type { GanttZoomEnum } from './gantt-geometry.ts';
2
+
3
+ export interface GanttUrlState {
4
+ zoom: GanttZoomEnum;
5
+ criticalOnly: boolean;
6
+ showBaseline: boolean;
7
+ histogramResourceIds: string[];
8
+ wbsId: string | null;
9
+ search: string;
10
+ reviewFilter: 'unreviewed' | null;
11
+ selectedActivityId: string | null;
12
+ }
13
+ export const GANTT_SEARCH_PARAMS = {
14
+ zoom: 'z',
15
+ criticalOnly: 'crit',
16
+ showBaseline: 'bl',
17
+ histogramResourceIds: 'hist',
18
+ wbsId: 'wbs',
19
+ search: 'q',
20
+ reviewFilter: 'rv',
21
+ selectedActivityId: 'sel',
22
+ } as const;
23
+ /* Parse shareable project filters while rejecting unknown zoom values. */
24
+ export function readGanttUrlState(params: URLSearchParams): GanttUrlState {
25
+ const zoom = params.get('z')?.toUpperCase();
26
+ return {
27
+ zoom: zoom === 'DAY' || zoom === 'MONTH' ? zoom : 'WEEK',
28
+ criticalOnly: params.get('crit') === '1',
29
+ showBaseline: params.get('bl') === '1',
30
+ histogramResourceIds: [
31
+ ...new Set((params.get('hist') || '').split(',').filter(Boolean)),
32
+ ].slice(0, 8),
33
+ wbsId: params.get('wbs') || null,
34
+ search: params.get('q') || '',
35
+ reviewFilter: params.get('rv') === 'unreviewed' ? 'unreviewed' : null,
36
+ selectedActivityId: params.get('sel') || null,
37
+ };
38
+ }
39
+ /* Write only explicit changes and preserve unrelated route search parameters. */
40
+ export function writeGanttUrlState(
41
+ current: URLSearchParams,
42
+ next: Partial<GanttUrlState>,
43
+ ): URLSearchParams {
44
+ const result = new URLSearchParams(current);
45
+ for (const key of Object.keys(next) as Array<keyof GanttUrlState>) {
46
+ const value = next[key];
47
+ const text =
48
+ key === 'zoom'
49
+ ? value === 'WEEK'
50
+ ? ''
51
+ : String(value).toLowerCase()
52
+ : Array.isArray(value)
53
+ ? value.slice(0, 8).join(',')
54
+ : typeof value === 'boolean'
55
+ ? value
56
+ ? '1'
57
+ : ''
58
+ : value || '';
59
+ if (text) result.set(GANTT_SEARCH_PARAMS[key], String(text));
60
+ else result.delete(GANTT_SEARCH_PARAMS[key]);
61
+ }
62
+ return result;
63
+ }
@@ -0,0 +1,119 @@
1
+ import { createGridEdgeAutoScroller } from '@jsb188/sheet/libs/grid-touch';
2
+ import { getGanttDate, GANTT_ROW_HEIGHT, type GanttBarObj, type GanttRowObj, type GanttScaleObj } from '../libs/gantt-geometry.ts';
3
+ import type { ScheduleRelationshipTypeEnum } from '../types/schedule.d.ts';
4
+
5
+ export interface GanttMoveIntent {
6
+ kind: 'MOVE' | 'RESIZE_START' | 'RESIZE_FINISH';
7
+ date: Date;
8
+ deltaDays: number;
9
+ }
10
+
11
+ /* Track one pointer gesture with edge scrolling; commit only an intentional completed move or link. */
12
+ export function startGanttPointerInteraction(p: {
13
+ isKeyboardLayerActive: (event: KeyboardEvent) => boolean;
14
+ event: React.PointerEvent<HTMLDivElement>;
15
+ row: GanttRowObj;
16
+ bar: GanttBarObj;
17
+ kind: GanttMoveIntent['kind'] | 'LINK_START' | 'LINK_FINISH';
18
+ body: HTMLElement;
19
+ scale: GanttScaleObj;
20
+ tableWidth: number;
21
+ onMove?: (row: GanttRowObj, intent: GanttMoveIntent) => void;
22
+ onLink?: (predecessorId: string, successorId: string, type: ScheduleRelationshipTypeEnum) => void;
23
+ }): () => void {
24
+ p.event.preventDefault();
25
+ const element = p.event.currentTarget.closest<HTMLElement>('[data-gantt-activity]') || p.event.currentTarget;
26
+ const initialX = p.event.clientX;
27
+ const initialScroll = p.body.scrollLeft;
28
+ let clientX = initialX;
29
+ let clientY = p.event.clientY;
30
+ let distance = 0;
31
+ let finished = false;
32
+ const original = {
33
+ left: element.style.left,
34
+ width: element.style.width,
35
+ transform: element.style.transform,
36
+ };
37
+ const link = p.kind.startsWith('LINK');
38
+ const svg = p.body.querySelector('svg');
39
+ const preview = link && svg ? document.createElementNS('http://www.w3.org/2000/svg', 'path') : null;
40
+ if (preview) {
41
+ preview.setAttribute('stroke', 'currentColor');
42
+ preview.setAttribute('fill', 'none');
43
+ preview.setAttribute('stroke-dasharray', '4 3');
44
+ svg!.appendChild(preview);
45
+ }
46
+ /* Draw feedback directly on the active bar without rebuilding the schedule network. */
47
+ const draw = (x: number, y: number) => {
48
+ clientX = x;
49
+ clientY = y;
50
+ distance = x - initialX + p.body.scrollLeft - initialScroll;
51
+ if (link && preview) {
52
+ const bounds = p.body.getBoundingClientRect();
53
+ const x1 = p.kind === 'LINK_START' ? p.bar.x : p.bar.x + p.bar.width;
54
+ const y1 = p.bar.rowIndex * GANTT_ROW_HEIGHT + GANTT_ROW_HEIGHT / 2;
55
+ const x2 = x - bounds.left + p.body.scrollLeft - p.tableWidth;
56
+ const y2 = y - bounds.top + p.body.scrollTop;
57
+ preview.setAttribute('d', `M ${x1} ${y1} L ${x2} ${y2}`);
58
+ } else if (p.kind === 'MOVE') element.style.transform = `${original.transform} translateX(${distance}px)`;
59
+ else if (p.kind === 'RESIZE_START') {
60
+ element.style.left = `${p.bar.x + Math.min(distance, p.bar.width - 2)}px`;
61
+ element.style.width = `${Math.max(2, p.bar.width - distance)}px`;
62
+ } else if (p.kind === 'RESIZE_FINISH') element.style.width = `${Math.max(2, p.bar.width + distance)}px`;
63
+ };
64
+ const scroller = createGridEdgeAutoScroller({
65
+ getScrollNode: () => p.body,
66
+ onScrollFrame: draw,
67
+ });
68
+ /* Remove every listener and temporary pixel adjustment on completion, cancellation or unmount. */
69
+ const cleanup = () => {
70
+ if (finished) return;
71
+ finished = true;
72
+ scroller.stop();
73
+ preview?.remove();
74
+ Object.assign(element.style, original);
75
+ window.removeEventListener('pointermove', move);
76
+ window.removeEventListener('pointerup', up);
77
+ window.removeEventListener('pointercancel', cancel);
78
+ window.removeEventListener('keydown', key);
79
+ };
80
+ /* Update the active pointer and let the shared grid helper advance edge scrolling. */
81
+ const move = (event: PointerEvent) => {
82
+ draw(event.clientX, event.clientY);
83
+ scroller.update(event.clientX, event.clientY);
84
+ };
85
+ /* Commit the target after removing temporary geometry so the server remains authoritative. */
86
+ const up = (event: PointerEvent) => {
87
+ const deltaDays = Math.round(distance / p.scale.dayWidth);
88
+ const target = link
89
+ ? document.elementFromPoint(event.clientX, event.clientY)?.closest<HTMLElement>('[data-gantt-activity]')
90
+ : null;
91
+ cleanup();
92
+ if (link && target && target.dataset.ganttActivity !== p.row.id) {
93
+ const bounds = target.getBoundingClientRect();
94
+ const toFinish = event.clientX >= bounds.left + bounds.width / 2;
95
+ const type = `${p.kind === 'LINK_START' ? 'S' : 'F'}${toFinish ? 'F' : 'S'}` as ScheduleRelationshipTypeEnum;
96
+ p.onLink?.(p.row.id, target.dataset.ganttActivity!, type);
97
+ } else if (!link && Math.abs(distance) >= 3 && deltaDays) {
98
+ const endpoint = p.kind === 'RESIZE_FINISH' ? p.bar.x + p.bar.width : p.bar.x;
99
+ p.onMove?.(p.row, {
100
+ kind: p.kind as GanttMoveIntent['kind'],
101
+ date: getGanttDate(p.scale, endpoint + deltaDays * p.scale.dayWidth),
102
+ deltaDays,
103
+ });
104
+ }
105
+ };
106
+ /* Cancel without issuing a mutation when capture is interrupted. */
107
+ const cancel = () => cleanup();
108
+ /* Escape always cancels the current gesture. */
109
+ const key = (event: KeyboardEvent) => {
110
+ if (!p.isKeyboardLayerActive(event)) return;
111
+ if (event.key === 'Escape') cleanup();
112
+ };
113
+ window.addEventListener('pointermove', move);
114
+ window.addEventListener('pointerup', up);
115
+ window.addEventListener('pointercancel', cancel);
116
+ window.addEventListener('keydown', key);
117
+ draw(clientX, clientY);
118
+ return cleanup;
119
+ }