@redvars/peacock 4.0.0 → 4.1.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/dist/{BaseField-CAog9TIc.js → BaseField-BMumJpkW.js} +6 -3
- package/dist/BaseField-BMumJpkW.js.map +1 -0
- package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-mWdyYv27.js} +6 -3
- package/dist/BaseInput-mWdyYv27.js.map +1 -0
- package/dist/accordion.js.map +1 -1
- package/dist/ai-badge.js +2 -2
- package/dist/ai-summary.js +2 -2
- package/dist/alert.js +2 -2
- package/dist/anchor-nav.js +2 -2
- package/dist/app-shell.js +2 -2
- package/dist/assistant-panel.js +2 -2
- package/dist/assistant-step.js +2 -2
- package/dist/assistant-steps.js +2 -2
- package/dist/avatar-group.js +2 -2
- package/dist/banner.js +2 -2
- package/dist/{base-button-Do2TUy8M.js → base-button-BJMGMcMv.js} +3 -1
- package/dist/base-button-BJMGMcMv.js.map +1 -0
- package/dist/{base-progress-BiLlZVHJ.js → base-progress-CvLVSjuy.js} +4 -2
- package/dist/base-progress-CvLVSjuy.js.map +1 -0
- package/dist/bottom-sheet.js +2 -2
- package/dist/breadcrumb.js +2 -2
- package/dist/button-group.js +4 -4
- package/dist/button.js +3 -3
- package/dist/calendar.js +2 -2
- package/dist/canvas-base-BTQMEVn_.js +788 -0
- package/dist/canvas-base-BTQMEVn_.js.map +1 -0
- package/dist/canvas-link-CtgsALq4.js +54 -0
- package/dist/canvas-link-CtgsALq4.js.map +1 -0
- package/dist/{cartesian-chart-C-f1frt0.js → cartesian-chart-DM1FC_XT.js} +3 -2
- package/dist/cartesian-chart-DM1FC_XT.js.map +1 -0
- package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-B6fa4Lll.js} +2 -2
- package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-B6fa4Lll.js.map} +1 -1
- package/dist/cb-group.js +3 -3
- package/dist/cb-rule.js +3 -3
- package/dist/chart-area.js +5 -4
- package/dist/chart-area.js.map +1 -1
- package/dist/chart-bar.js +5 -4
- package/dist/chart-bar.js.map +1 -1
- package/dist/chart-base-Dhxuw_Mw.js +833 -0
- package/dist/chart-base-Dhxuw_Mw.js.map +1 -0
- package/dist/chart-doughnut.js +4 -3
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +5 -4
- package/dist/chart-line.js.map +1 -1
- package/dist/chart-pie.js +4 -3
- package/dist/chart-pie.js.map +1 -1
- package/dist/chat-message.js +2 -2
- package/dist/chat-thread.js +2 -2
- package/dist/checkbox-group.js +4 -4
- package/dist/checkbox.js +4 -4
- package/dist/chip-set.js +3 -3
- package/dist/chip.js +4 -4
- package/dist/circular-progress.js +3 -3
- package/dist/citation.js +2 -2
- package/dist/code-editor.js +5 -4
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -2
- package/dist/color-field.js +5 -5
- package/dist/color-picker.js +2 -2
- package/dist/command-palette.js +2 -2
- package/dist/comment-composer.js +5 -5
- package/dist/condition-builder.js +3 -3
- package/dist/confirm-dialog.js +2 -2
- package/dist/copy-button.js +2 -2
- package/dist/currency-field.js +5 -5
- package/dist/custom-elements-jsdocs.json +2115 -336
- package/dist/custom-elements.json +19483 -615
- package/dist/date-field.js +6 -6
- package/dist/date-picker.js +4 -2
- package/dist/date-picker.js.map +1 -1
- package/dist/date-range-field.js +6 -6
- package/dist/datetime-field.js +6 -6
- package/dist/dependency-map-layout-5KUueabk.js +1390 -0
- package/dist/dependency-map-layout-5KUueabk.js.map +1 -0
- package/dist/dependency-map.js +1605 -0
- package/dist/dependency-map.js.map +1 -0
- package/dist/description-item.js +2 -2
- package/dist/description-list.js +2 -2
- package/dist/diagram-2r11KySs.js +2029 -0
- package/dist/diagram-2r11KySs.js.map +1 -0
- package/dist/diagram-controls.js +345 -0
- package/dist/diagram-controls.js.map +1 -0
- package/dist/diagram-minimap.js +216 -0
- package/dist/diagram-minimap.js.map +1 -0
- package/dist/diagram.js +20 -0
- package/dist/diagram.js.map +1 -0
- package/dist/diff-viewer.js +2 -2
- package/dist/discussion-activity.js +2 -2
- package/dist/discussion-comment.js +2 -2
- package/dist/discussion.js +5 -5
- package/dist/{document-editor-BO7QPbO5.js → document-editor-BnEugM3E.js} +2 -2
- package/dist/{document-editor-BO7QPbO5.js.map → document-editor-BnEugM3E.js.map} +1 -1
- package/dist/document-editor.js +3 -3
- package/dist/draft-card.js +2 -2
- package/dist/erd.js +2021 -0
- package/dist/erd.js.map +1 -0
- package/dist/fab.js +4 -4
- package/dist/field.js +257 -43
- package/dist/field.js.map +1 -1
- package/dist/file-upload.js +37 -15
- package/dist/file-upload.js.map +1 -1
- package/dist/filter-bar.js +2 -2
- package/dist/flow.js +27 -970
- package/dist/flow.js.map +1 -1
- package/dist/focus-ring.js +2 -0
- package/dist/focus-ring.js.map +1 -1
- package/dist/{form-associated-D3Tn33s_.js → form-associated-BHbg72PG.js} +3 -1
- package/dist/{form-associated-D3Tn33s_.js.map → form-associated-BHbg72PG.js.map} +1 -1
- package/dist/{form-submitter-DWwv6K9-.js → form-submitter-beG1CXAn.js} +7 -1
- package/dist/{form-submitter-DWwv6K9-.js.map → form-submitter-beG1CXAn.js.map} +1 -1
- package/dist/form.js +2 -2
- package/dist/{generative-view-DmtpDobn.js → generative-view-BgOcLRXr.js} +13 -13
- package/dist/generative-view-BgOcLRXr.js.map +1 -0
- package/dist/generative-view.js +3 -3
- package/dist/geometry-INg82Lxq.js +305 -0
- package/dist/geometry-INg82Lxq.js.map +1 -0
- package/dist/history-YbTSQZHj.js +45 -0
- package/dist/history-YbTSQZHj.js.map +1 -0
- package/dist/host-CZK7xhzh.js +40 -0
- package/dist/host-CZK7xhzh.js.map +1 -0
- package/dist/html-editor.js +5 -5
- package/dist/{hyperlink-DhE9RlVS.js → hyperlink-DycWPKwU.js} +10 -1
- package/dist/hyperlink-DycWPKwU.js.map +1 -0
- package/dist/{i18n-controller-urcQKYGe.js → i18n-controller-Cp43HjJl.js} +2 -2
- package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-Cp43HjJl.js.map} +1 -1
- package/dist/icon-button.js +4 -4
- package/dist/image.js +2 -2
- package/dist/index.js +37 -18
- package/dist/index.js.map +1 -1
- package/dist/inline-edit.js +2 -2
- package/dist/input.js +4 -4
- package/dist/json-viewer.js +2 -2
- package/dist/kanban.js +2 -2
- package/dist/kbd.js +2 -2
- package/dist/linear-progress.js +3 -3
- package/dist/link-button.js +2 -2
- package/dist/list-item.js +2 -2
- package/dist/list.js +2 -2
- package/dist/listbox.js +3 -3
- package/dist/loader-full.js +13 -13
- package/dist/loader.js +44 -15
- package/dist/loader.js.map +1 -1
- package/dist/markdown-editor.js +5 -5
- package/dist/markers-BFmh1OCz.js +46 -0
- package/dist/markers-BFmh1OCz.js.map +1 -0
- package/dist/measure-controller-Dmc5hZKg.js +89 -0
- package/dist/measure-controller-Dmc5hZKg.js.map +1 -0
- package/dist/mention-input.js +6 -5
- package/dist/mention-input.js.map +1 -1
- package/dist/menu-item.js +3 -2
- package/dist/menu-item.js.map +1 -1
- package/dist/menu.js +2 -2
- package/dist/modal.js +2 -2
- package/dist/navigation-bar.js +2 -2
- package/dist/navigation-drawer.js +2 -2
- package/dist/navigation-rail.js +2 -2
- package/dist/notification-center.js +2 -2
- package/dist/number-field.js +6 -5
- package/dist/number-field.js.map +1 -1
- package/dist/option.js +2 -2
- package/dist/page-header.js +2 -2
- package/dist/pagination.js +2 -2
- package/dist/password-field.js +5 -5
- package/dist/password-rules.js +2 -2
- package/dist/phone-field.js +5 -5
- package/dist/{picker-field-B4DtcJfL.js → picker-field-dTlIMAQn.js} +3 -3
- package/dist/{picker-field-B4DtcJfL.js.map → picker-field-dTlIMAQn.js.map} +1 -1
- package/dist/pin-input.js +5 -5
- package/dist/presence-indicator.js +2 -2
- package/dist/prompt-input.js +5 -5
- package/dist/radio-group.js +1 -0
- package/dist/radio-group.js.map +1 -1
- package/dist/radio.js +5 -5
- package/dist/radio.js.map +1 -1
- package/dist/rating.js +5 -4
- package/dist/rating.js.map +1 -1
- package/dist/redvars-loader.js +2 -2
- package/dist/relative-time.js +2 -2
- package/dist/resizable-panels.js +2 -2
- package/dist/{rich-text-input-DLICqof1.js → rich-text-input-DM_BOzgk.js} +3 -3
- package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-DM_BOzgk.js.map} +1 -1
- package/dist/ripple.js +2 -0
- package/dist/ripple.js.map +1 -1
- package/dist/{schema-hMt-NRLk.js → schema-B8g30A_n.js} +2 -2
- package/dist/{schema-hMt-NRLk.js.map → schema-B8g30A_n.js.map} +1 -1
- package/dist/search.js +4 -4
- package/dist/segmented-button-group.js +1 -1
- package/dist/select.js +7 -7
- package/dist/side-sheet.js +2 -2
- package/dist/signature-pad.js +5 -4
- package/dist/signature-pad.js.map +1 -1
- package/dist/slider.js +5 -4
- package/dist/slider.js.map +1 -1
- package/dist/snackbar.js +2 -2
- package/dist/sparkline.js +2 -2
- package/dist/split-button.js +2 -2
- package/dist/src/__internal/diagram/canvas-base.d.ts +105 -0
- package/dist/src/__internal/diagram/canvas-link.d.ts +21 -0
- package/dist/src/__internal/diagram/geometry.d.ts +49 -0
- package/dist/src/__internal/diagram/history.d.ts +17 -0
- package/dist/src/__internal/diagram/host.d.ts +45 -0
- package/dist/src/__internal/diagram/markers.d.ts +16 -0
- package/dist/src/__internal/diagram/measure-controller.d.ts +32 -0
- package/dist/src/__internal/diagram/motion.d.ts +22 -0
- package/dist/src/__internal/diagram/selection.d.ts +20 -0
- package/dist/src/__internal/diagram/types.d.ts +39 -0
- package/dist/src/__internal/diagram/viewport-controller.d.ts +89 -0
- package/dist/src/__internal/i18n/strings.d.ts +149 -0
- package/dist/src/__internal/toggle-base.d.ts +8 -0
- package/dist/src/__internal/utils/deprecate.d.ts +3 -3
- package/dist/src/accordion/accordion.d.ts +1 -0
- package/dist/src/code-editor/code-editor.d.ts +1 -0
- package/dist/src/date-picker/date-picker.d.ts +2 -0
- package/dist/src/dependency-map/dependency-map-layout.d.ts +48 -0
- package/dist/src/dependency-map/dependency-map.d.ts +241 -0
- package/dist/src/dependency-map/index.d.ts +2 -0
- package/dist/src/diagram/diagram.d.ts +300 -0
- package/dist/src/diagram/flow.d.ts +53 -0
- package/dist/src/diagram/index.d.ts +4 -0
- package/dist/src/diagram-controls/diagram-controls.d.ts +46 -0
- package/dist/src/diagram-controls/index.d.ts +1 -0
- package/dist/src/diagram-minimap/diagram-minimap.d.ts +39 -0
- package/dist/src/diagram-minimap/index.d.ts +1 -0
- package/dist/src/erd/erd-layout.d.ts +27 -0
- package/dist/src/erd/erd.d.ts +266 -0
- package/dist/src/erd/index.d.ts +2 -0
- package/dist/src/field/field.d.ts +38 -1
- package/dist/src/file-upload/file-upload.d.ts +3 -1
- package/dist/src/focus-ring/focus-ring.d.ts +2 -0
- package/dist/src/index.d.ts +15 -2
- package/dist/src/input/BaseField.d.ts +3 -0
- package/dist/src/input/BaseInput.d.ts +3 -0
- package/dist/src/menu/menu-item/menu-item.d.ts +1 -0
- package/dist/src/number-field/number-field.d.ts +4 -0
- package/dist/src/progress/base-progress.d.ts +3 -0
- package/dist/src/radio/radio-group.d.ts +1 -0
- package/dist/src/rating/rating.d.ts +1 -0
- package/dist/src/ripple/ripple.d.ts +2 -0
- package/dist/src/signature-pad/signature-pad.d.ts +1 -0
- package/dist/src/slider/slider.d.ts +1 -0
- package/dist/src/switch/switch.d.ts +1 -0
- package/dist/src/tabs/tab.d.ts +2 -0
- package/dist/src/tabs/tabs.d.ts +1 -0
- package/dist/src/textarea/textarea.d.ts +1 -0
- package/dist/src/time-picker/time-picker.d.ts +2 -0
- package/dist/src/transfer-list/transfer-list.d.ts +1 -0
- package/dist/src/tree-chart/index.d.ts +2 -0
- package/dist/src/tree-chart/tree-chart-layout.d.ts +49 -0
- package/dist/src/tree-chart/tree-chart.d.ts +221 -0
- package/dist/src/workflow/index.d.ts +2 -0
- package/dist/src/workflow/workflow-format.d.ts +5 -0
- package/dist/src/workflow/workflow-model.d.ts +194 -0
- package/dist/src/workflow/workflow.d.ts +313 -0
- package/dist/src/workflow-timeline/index.d.ts +1 -0
- package/dist/src/workflow-timeline/workflow-timeline.d.ts +41 -0
- package/dist/stat.js +2 -2
- package/dist/status-indicator.js +2 -2
- package/dist/step.js +2 -2
- package/dist/stepper.js +2 -2
- package/dist/{strings-DmbqMTfs.js → strings-BJPuhKJk.js} +163 -1
- package/dist/{strings-DmbqMTfs.js.map → strings-BJPuhKJk.js.map} +1 -1
- package/dist/sub-menu.js +2 -2
- package/dist/svg.js +2 -2
- package/dist/switch.js +5 -4
- package/dist/switch.js.map +1 -1
- package/dist/tab.js +1 -0
- package/dist/tab.js.map +1 -1
- package/dist/table.js +2 -2
- package/dist/tabs.js +1 -0
- package/dist/tabs.js.map +1 -1
- package/dist/test/diagram-controls.test.d.ts +1 -0
- package/dist/test/diagram-geometry.test.d.ts +1 -0
- package/dist/test/diagram.test.d.ts +1 -0
- package/dist/test/erd.test.d.ts +1 -0
- package/dist/test/toggle-label.test.d.ts +1 -0
- package/dist/test/tree-chart.test.d.ts +1 -0
- package/dist/test/workflow-debug.test.d.ts +1 -0
- package/dist/test/workflow.test.d.ts +1 -0
- package/dist/textarea.js +7 -5
- package/dist/textarea.js.map +1 -1
- package/dist/time-field.js +6 -6
- package/dist/time-picker.js +4 -2
- package/dist/time-picker.js.map +1 -1
- package/dist/timeline-item.js +2 -2
- package/dist/timeline.js +2 -2
- package/dist/{toggle-base-BQO5pjrU.js → toggle-base-BlaHalfS.js} +19 -3
- package/dist/toggle-base-BlaHalfS.js.map +1 -0
- package/dist/tour.js +2 -2
- package/dist/transfer-list.js +5 -4
- package/dist/transfer-list.js.map +1 -1
- package/dist/{chart-base-B-gOg2Di.js → transform-CxeQFXXB.js} +9 -839
- package/dist/transform-CxeQFXXB.js.map +1 -0
- package/dist/tree-chart.js +1986 -0
- package/dist/tree-chart.js.map +1 -0
- package/dist/tree-item.js +2 -2
- package/dist/tree.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/typing-indicator.js +2 -2
- package/dist/url-field.js +5 -5
- package/dist/user-menu.js +2 -2
- package/dist/virtual-list.js +2 -2
- package/dist/workflow-format-BsyveyeC.js +34 -0
- package/dist/workflow-format-BsyveyeC.js.map +1 -0
- package/dist/workflow-model-CauduOG2.js +330 -0
- package/dist/workflow-model-CauduOG2.js.map +1 -0
- package/dist/workflow-timeline.js +354 -0
- package/dist/workflow-timeline.js.map +1 -0
- package/dist/workflow.js +3337 -0
- package/dist/workflow.js.map +1 -0
- package/dist/workspace-switcher.js +2 -2
- package/package.json +1 -1
- package/readme.md +44 -2
- package/src/LoaderUtils.ts +9 -2
- package/src/__internal/diagram/canvas-base.ts +410 -0
- package/src/__internal/diagram/canvas-link.ts +66 -0
- package/src/__internal/diagram/geometry.ts +372 -0
- package/src/__internal/diagram/history.ts +49 -0
- package/src/__internal/diagram/host.ts +76 -0
- package/src/__internal/diagram/markers.ts +56 -0
- package/src/__internal/diagram/measure-controller.ts +104 -0
- package/src/__internal/diagram/motion.ts +89 -0
- package/src/__internal/diagram/selection.ts +69 -0
- package/src/__internal/diagram/types.ts +56 -0
- package/src/__internal/diagram/viewport-controller.ts +494 -0
- package/src/__internal/i18n/strings.ts +201 -0
- package/src/__internal/mixins/field.ts +3 -0
- package/src/__internal/mixins/form-associated.ts +2 -0
- package/src/__internal/mixins/form-submitter.ts +6 -0
- package/src/__internal/mixins/hyperlink.ts +10 -0
- package/src/__internal/toggle-base.ts +16 -0
- package/src/__internal/utils/deprecate.ts +5 -4
- package/src/accordion/accordion.ts +1 -0
- package/src/button/base-button/base-button.ts +2 -0
- package/src/code-editor/code-editor.ts +1 -0
- package/src/date-picker/date-picker.ts +2 -0
- package/src/dependency-map/dependency-map-layout.ts +505 -0
- package/src/dependency-map/dependency-map.scss +626 -0
- package/src/dependency-map/dependency-map.ts +1280 -0
- package/src/dependency-map/index.ts +16 -0
- package/src/diagram/diagram.scss +513 -0
- package/src/diagram/diagram.ts +1852 -0
- package/src/diagram/flow.ts +81 -0
- package/src/diagram/index.ts +44 -0
- package/src/diagram-controls/diagram-controls.scss +68 -0
- package/src/diagram-controls/diagram-controls.ts +255 -0
- package/src/diagram-controls/index.ts +1 -0
- package/src/diagram-minimap/diagram-minimap.scss +41 -0
- package/src/diagram-minimap/diagram-minimap.ts +149 -0
- package/src/diagram-minimap/index.ts +1 -0
- package/src/erd/erd-layout.ts +92 -0
- package/src/erd/erd.scss +636 -0
- package/src/erd/erd.ts +1728 -0
- package/src/erd/index.ts +17 -0
- package/src/field/field.scss +197 -23
- package/src/field/field.ts +109 -16
- package/src/file-upload/file-upload.scss +37 -10
- package/src/file-upload/file-upload.ts +3 -1
- package/src/focus-ring/focus-ring.ts +2 -0
- package/src/generative-view/catalog.generated.ts +12 -11
- package/src/index.ts +121 -2
- package/src/input/BaseField.ts +3 -0
- package/src/input/BaseInput.ts +3 -0
- package/src/loader.ts +25 -0
- package/src/mention-input/mention-input.scss +2 -0
- package/src/menu/menu-item/menu-item.ts +1 -0
- package/src/number-field/number-field.ts +4 -0
- package/src/progress/base-progress.ts +3 -0
- package/src/radio/radio-group.ts +1 -0
- package/src/radio/radio.ts +1 -1
- package/src/rating/rating.ts +1 -0
- package/src/ripple/ripple.ts +2 -0
- package/src/signature-pad/signature-pad.ts +1 -0
- package/src/slider/slider.ts +1 -0
- package/src/switch/switch.ts +1 -0
- package/src/tabs/tab.ts +2 -0
- package/src/tabs/tabs.ts +1 -0
- package/src/textarea/textarea.scss +2 -0
- package/src/textarea/textarea.ts +1 -0
- package/src/time-picker/time-picker.ts +2 -0
- package/src/transfer-list/transfer-list.ts +1 -0
- package/src/tree-chart/index.ts +13 -0
- package/src/tree-chart/tree-chart-layout.ts +185 -0
- package/src/tree-chart/tree-chart.scss +377 -0
- package/src/tree-chart/tree-chart.ts +1170 -0
- package/src/workflow/index.ts +35 -0
- package/src/workflow/workflow-format.ts +29 -0
- package/src/workflow/workflow-model.ts +583 -0
- package/src/workflow/workflow.scss +1164 -0
- package/src/workflow/workflow.ts +2674 -0
- package/src/workflow-timeline/index.ts +1 -0
- package/src/workflow-timeline/workflow-timeline.scss +128 -0
- package/src/workflow-timeline/workflow-timeline.ts +238 -0
- package/dist/BaseField-CAog9TIc.js.map +0 -1
- package/dist/BaseInput-CcMfg1Y2.js.map +0 -1
- package/dist/base-button-Do2TUy8M.js.map +0 -1
- package/dist/base-progress-BiLlZVHJ.js.map +0 -1
- package/dist/cartesian-chart-C-f1frt0.js.map +0 -1
- package/dist/chart-base-B-gOg2Di.js.map +0 -1
- package/dist/generative-view-DmtpDobn.js.map +0 -1
- package/dist/hyperlink-DhE9RlVS.js.map +0 -1
- package/dist/src/flow/flow.d.ts +0 -178
- package/dist/src/flow/index.d.ts +0 -2
- package/dist/toggle-base-BQO5pjrU.js.map +0 -1
- package/src/button/button-group/readme.md +0 -23
- package/src/flow/flow.scss +0 -215
- package/src/flow/flow.ts +0 -958
- package/src/flow/index.ts +0 -10
- /package/dist/test/{flow.test.d.ts → dependency-map.test.d.ts} +0 -0
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
import { _ as __decorate, a as i, A, b } from './IndividualComponent-BK7XZjE2.js';
|
|
2
|
+
import { n } from './property-B2TG3KEE.js';
|
|
3
|
+
import { I as I18nController } from './i18n-controller-Cp43HjJl.js';
|
|
4
|
+
import { b as boundsOf, i as inflateRect, a as rectsIntersect } from './geometry-INg82Lxq.js';
|
|
5
|
+
import { D as DiagramListeners } from './host-CZK7xhzh.js';
|
|
6
|
+
|
|
7
|
+
/** Whether the person asked for less motion. Diagram animations jump to their end state when true. */
|
|
8
|
+
function prefersReducedMotion() {
|
|
9
|
+
return (typeof matchMedia === 'function' &&
|
|
10
|
+
matchMedia('(prefers-reduced-motion: reduce)').matches);
|
|
11
|
+
}
|
|
12
|
+
const easeInOutCubic = (p) => p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2;
|
|
13
|
+
const easeOutCubic = (p) => 1 - (1 - p) ** 3;
|
|
14
|
+
/**
|
|
15
|
+
* Runs `onUpdate` every animation frame for `duration` milliseconds. Under reduced motion it
|
|
16
|
+
* calls `onUpdate(1)` and `onDone` straight away. Returns a function that stops the tween without
|
|
17
|
+
* calling `onDone`.
|
|
18
|
+
*/
|
|
19
|
+
function tween({ duration, easing = easeInOutCubic, onUpdate, onDone, }) {
|
|
20
|
+
if (duration <= 0 || prefersReducedMotion()) {
|
|
21
|
+
onUpdate(1);
|
|
22
|
+
onDone?.();
|
|
23
|
+
return () => { };
|
|
24
|
+
}
|
|
25
|
+
let frame = 0;
|
|
26
|
+
let stopped = false;
|
|
27
|
+
const start = performance.now();
|
|
28
|
+
const step = (now) => {
|
|
29
|
+
if (stopped)
|
|
30
|
+
return;
|
|
31
|
+
const p = Math.min(1, (now - start) / duration);
|
|
32
|
+
onUpdate(easing(p));
|
|
33
|
+
if (p < 1) {
|
|
34
|
+
frame = requestAnimationFrame(step);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
onDone?.();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
frame = requestAnimationFrame(step);
|
|
41
|
+
return () => {
|
|
42
|
+
stopped = true;
|
|
43
|
+
cancelAnimationFrame(frame);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fades and shrinks elements before they are removed, then calls `done`. Resolves at once under
|
|
48
|
+
* reduced motion or when the Web Animations API is missing.
|
|
49
|
+
*/
|
|
50
|
+
function animateOut(elements, done, duration = 160) {
|
|
51
|
+
if (elements.length === 0 || prefersReducedMotion()) {
|
|
52
|
+
done();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const animations = elements
|
|
56
|
+
.filter(el => typeof el.animate === 'function')
|
|
57
|
+
.map(el => el.animate([
|
|
58
|
+
{ opacity: 1, transform: 'scale(1)' },
|
|
59
|
+
{ opacity: 0, transform: 'scale(0.95)' },
|
|
60
|
+
], { duration, easing: 'ease-in', fill: 'forwards' }));
|
|
61
|
+
if (animations.length === 0) {
|
|
62
|
+
done();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
Promise.all(animations.map(a => a.finished.catch(() => undefined))).then(done);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Pointer travel, in screen pixels, before a press becomes a pan. */
|
|
69
|
+
const PAN_THRESHOLD = 3;
|
|
70
|
+
/** Milliseconds without wheel input before a wheel gesture counts as settled. */
|
|
71
|
+
const WHEEL_SETTLE_MS = 150;
|
|
72
|
+
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
|
|
73
|
+
/**
|
|
74
|
+
* The camera of an infinite canvas: pans with a background drag, Space + drag, the middle button,
|
|
75
|
+
* a trackpad or the wheel, and zooms around the pointer with Ctrl/⌘ + wheel or a pinch. There are
|
|
76
|
+
* no bounds, so content can sit anywhere, including at negative coordinates.
|
|
77
|
+
*
|
|
78
|
+
* A canvas point `c` is drawn at `c * zoom + (x, y)` relative to the element's top-left corner.
|
|
79
|
+
*/
|
|
80
|
+
class ViewportController {
|
|
81
|
+
constructor(host, options) {
|
|
82
|
+
this.view = { x: 0, y: 0, zoom: 1 };
|
|
83
|
+
/** Whether Space is held, so any drag pans. */
|
|
84
|
+
this.spaceHeld = false;
|
|
85
|
+
/** Whether a pan gesture is moving the view. */
|
|
86
|
+
this.panning = false;
|
|
87
|
+
this.touches = new Map();
|
|
88
|
+
this.onWheel = (event) => {
|
|
89
|
+
const zooming = event.ctrlKey || event.metaKey;
|
|
90
|
+
const inside = this.wheelBelongsInside(event);
|
|
91
|
+
if (inside === 'overlay' || (inside === 'scroll' && !zooming)) {
|
|
92
|
+
// Let the overlay or scroller have it; only stop the browser zooming the page.
|
|
93
|
+
if (zooming)
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
this.cancelAnimation();
|
|
99
|
+
let dx = event.deltaX;
|
|
100
|
+
let dy = event.deltaY;
|
|
101
|
+
if (event.deltaMode === 1) {
|
|
102
|
+
dx *= 16;
|
|
103
|
+
dy *= 16;
|
|
104
|
+
}
|
|
105
|
+
else if (event.deltaMode === 2) {
|
|
106
|
+
dx *= this.size().width;
|
|
107
|
+
dy *= this.size().height;
|
|
108
|
+
}
|
|
109
|
+
if (event.ctrlKey || event.metaKey) {
|
|
110
|
+
this.zoomBy(Math.exp(-clamp(dy, -60, 60) * 0.0125), event.clientX, event.clientY, false);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (event.shiftKey && dx === 0) {
|
|
114
|
+
dx = dy;
|
|
115
|
+
dy = 0;
|
|
116
|
+
}
|
|
117
|
+
this.panBy(-dx, -dy, false);
|
|
118
|
+
}
|
|
119
|
+
clearTimeout(this.wheelTimer);
|
|
120
|
+
this.wheelTimer = setTimeout(() => this.options.onChange(this.view, true), WHEEL_SETTLE_MS);
|
|
121
|
+
};
|
|
122
|
+
this.onPointerDown = (event) => {
|
|
123
|
+
if (event.pointerType === 'touch') {
|
|
124
|
+
this.touches.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
125
|
+
if (this.touches.size === 2) {
|
|
126
|
+
this.startPinch();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const primary = event.button === 0;
|
|
131
|
+
const middle = event.button === 1;
|
|
132
|
+
if (!primary && !middle)
|
|
133
|
+
return;
|
|
134
|
+
const background = this.options.isBackground(event.composedPath()[0] ?? event.target);
|
|
135
|
+
if (!middle && !this.spaceHeld && !background)
|
|
136
|
+
return;
|
|
137
|
+
if (primary &&
|
|
138
|
+
background &&
|
|
139
|
+
!this.spaceHeld &&
|
|
140
|
+
this.options.onBackgroundPointerDown?.(event)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (background) {
|
|
144
|
+
this.options.element()?.focus({ preventScroll: true });
|
|
145
|
+
}
|
|
146
|
+
this.beginPan(event, background && primary);
|
|
147
|
+
};
|
|
148
|
+
this.onPointerMove = (event) => {
|
|
149
|
+
if (this.touches.has(event.pointerId)) {
|
|
150
|
+
this.touches.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
151
|
+
if (this.pinch) {
|
|
152
|
+
this.movePinch();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const { pan } = this;
|
|
157
|
+
if (!pan || event.pointerId !== pan.pointerId)
|
|
158
|
+
return;
|
|
159
|
+
const dx = event.clientX - pan.startX;
|
|
160
|
+
const dy = event.clientY - pan.startY;
|
|
161
|
+
if (!pan.moved && Math.hypot(dx, dy) < PAN_THRESHOLD)
|
|
162
|
+
return;
|
|
163
|
+
if (!pan.moved) {
|
|
164
|
+
pan.moved = true;
|
|
165
|
+
this.panning = true;
|
|
166
|
+
this.host.requestUpdate();
|
|
167
|
+
}
|
|
168
|
+
this.apply({ ...pan.origin, x: pan.origin.x + dx, y: pan.origin.y + dy }, false);
|
|
169
|
+
};
|
|
170
|
+
this.onPointerUp = (event) => {
|
|
171
|
+
this.touches.delete(event.pointerId);
|
|
172
|
+
if (this.pinch && this.touches.size < 2) {
|
|
173
|
+
this.pinch = undefined;
|
|
174
|
+
this.options.onChange(this.view, true);
|
|
175
|
+
}
|
|
176
|
+
const { pan } = this;
|
|
177
|
+
if (!pan || event.pointerId !== pan.pointerId)
|
|
178
|
+
return;
|
|
179
|
+
this.pan = undefined;
|
|
180
|
+
try {
|
|
181
|
+
if (pan.element.hasPointerCapture(event.pointerId)) {
|
|
182
|
+
pan.element.releasePointerCapture(event.pointerId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// The pointer is already gone.
|
|
187
|
+
}
|
|
188
|
+
if (pan.moved) {
|
|
189
|
+
this.panning = false;
|
|
190
|
+
this.host.requestUpdate();
|
|
191
|
+
this.options.onChange(this.view, true);
|
|
192
|
+
}
|
|
193
|
+
else if (pan.background && event.type === 'pointerup') {
|
|
194
|
+
this.options.onBackgroundClick?.(event);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
this.onKeyDown = (event) => {
|
|
198
|
+
if (event.key === ' ' && event.target === this.attachedTo) {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
if (!this.spaceHeld) {
|
|
201
|
+
this.spaceHeld = true;
|
|
202
|
+
this.host.requestUpdate();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
this.onKeyUp = (event) => {
|
|
207
|
+
if (event.key === ' ' && this.spaceHeld) {
|
|
208
|
+
this.spaceHeld = false;
|
|
209
|
+
this.host.requestUpdate();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
this.onBlur = () => {
|
|
213
|
+
if (this.spaceHeld) {
|
|
214
|
+
this.spaceHeld = false;
|
|
215
|
+
this.host.requestUpdate();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
this.host = host;
|
|
219
|
+
this.options = options;
|
|
220
|
+
host.addController(this);
|
|
221
|
+
}
|
|
222
|
+
hostUpdated() {
|
|
223
|
+
const element = this.options.element();
|
|
224
|
+
if (element && element !== this.attachedTo) {
|
|
225
|
+
this.detach();
|
|
226
|
+
this.attach(element);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
hostDisconnected() {
|
|
230
|
+
this.detach();
|
|
231
|
+
this.cancelAnimation();
|
|
232
|
+
clearTimeout(this.wheelTimer);
|
|
233
|
+
}
|
|
234
|
+
// ── Geometry
|
|
235
|
+
/** The element's size in screen pixels. */
|
|
236
|
+
size() {
|
|
237
|
+
const el = this.options.element();
|
|
238
|
+
return { width: el?.clientWidth ?? 0, height: el?.clientHeight ?? 0 };
|
|
239
|
+
}
|
|
240
|
+
/** The part of the canvas in view, in canvas coordinates. */
|
|
241
|
+
visibleRect() {
|
|
242
|
+
const { width, height } = this.size();
|
|
243
|
+
const { x, y, zoom } = this.view;
|
|
244
|
+
return {
|
|
245
|
+
x: -x / zoom,
|
|
246
|
+
y: -y / zoom,
|
|
247
|
+
width: width / zoom,
|
|
248
|
+
height: height / zoom,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** Converts client (page viewport) coordinates to canvas coordinates. */
|
|
252
|
+
toCanvas(clientX, clientY) {
|
|
253
|
+
const rect = this.options.element()?.getBoundingClientRect();
|
|
254
|
+
const left = rect?.left ?? 0;
|
|
255
|
+
const top = rect?.top ?? 0;
|
|
256
|
+
return {
|
|
257
|
+
x: (clientX - left - this.view.x) / this.view.zoom,
|
|
258
|
+
y: (clientY - top - this.view.y) / this.view.zoom,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
clampZoom(zoom) {
|
|
262
|
+
return clamp(zoom, this.options.minZoom(), this.options.maxZoom());
|
|
263
|
+
}
|
|
264
|
+
/** The view that fits `rect` with `padding` screen pixels around it, never above `maxZoom`. */
|
|
265
|
+
viewForRect(rect, padding, maxZoom = 1) {
|
|
266
|
+
const { width, height } = this.size();
|
|
267
|
+
const fitW = (width - 2 * padding) / Math.max(rect.width, 1);
|
|
268
|
+
const fitH = (height - 2 * padding) / Math.max(rect.height, 1);
|
|
269
|
+
const zoom = this.clampZoom(Math.min(fitW, fitH, maxZoom, this.options.maxZoom()));
|
|
270
|
+
return {
|
|
271
|
+
zoom,
|
|
272
|
+
x: width / 2 - (rect.x + rect.width / 2) * zoom,
|
|
273
|
+
y: height / 2 - (rect.y + rect.height / 2) * zoom,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** The view that centres canvas `point` at `zoom`. */
|
|
277
|
+
viewCentering(point, zoom = this.view.zoom) {
|
|
278
|
+
const { width, height } = this.size();
|
|
279
|
+
const z = this.clampZoom(zoom);
|
|
280
|
+
return { zoom: z, x: width / 2 - point.x * z, y: height / 2 - point.y * z };
|
|
281
|
+
}
|
|
282
|
+
// ── Moving the camera
|
|
283
|
+
/** Moves the camera at once. */
|
|
284
|
+
setView(view, settled = true) {
|
|
285
|
+
this.cancelAnimation();
|
|
286
|
+
this.apply(view, settled);
|
|
287
|
+
}
|
|
288
|
+
panBy(dx, dy, settled = true) {
|
|
289
|
+
this.setView({ ...this.view, x: this.view.x + dx, y: this.view.y + dy }, settled);
|
|
290
|
+
}
|
|
291
|
+
/** Zooms by `factor` around a client point, or around the centre. */
|
|
292
|
+
zoomBy(factor, clientX, clientY, settled = true) {
|
|
293
|
+
this.zoomToValue(this.view.zoom * factor, clientX, clientY, settled);
|
|
294
|
+
}
|
|
295
|
+
zoomToValue(zoom, clientX, clientY, settled = true) {
|
|
296
|
+
const el = this.options.element();
|
|
297
|
+
const rect = el?.getBoundingClientRect();
|
|
298
|
+
const { width, height } = this.size();
|
|
299
|
+
const px = clientX !== undefined && rect ? clientX - rect.left : width / 2;
|
|
300
|
+
const py = clientY !== undefined && rect ? clientY - rect.top : height / 2;
|
|
301
|
+
const next = this.clampZoom(zoom);
|
|
302
|
+
const cx = (px - this.view.x) / this.view.zoom;
|
|
303
|
+
const cy = (py - this.view.y) / this.view.zoom;
|
|
304
|
+
this.setView({ zoom: next, x: px - cx * next, y: py - cy * next }, settled);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Flies the camera to `target`. Long trips zoom out on the way, like a map. Jumps at once under
|
|
308
|
+
* reduced motion.
|
|
309
|
+
*/
|
|
310
|
+
animateTo(target, duration = 500) {
|
|
311
|
+
this.cancelAnimation();
|
|
312
|
+
const goal = { ...target, zoom: this.clampZoom(target.zoom) };
|
|
313
|
+
const { width, height } = this.size();
|
|
314
|
+
if (prefersReducedMotion() || width === 0 || height === 0) {
|
|
315
|
+
this.apply(goal, true);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const from = { ...this.view };
|
|
319
|
+
const c0 = {
|
|
320
|
+
x: (width / 2 - from.x) / from.zoom,
|
|
321
|
+
y: (height / 2 - from.y) / from.zoom,
|
|
322
|
+
};
|
|
323
|
+
const c1 = {
|
|
324
|
+
x: (width / 2 - goal.x) / goal.zoom,
|
|
325
|
+
y: (height / 2 - goal.y) / goal.zoom,
|
|
326
|
+
};
|
|
327
|
+
const travel = Math.hypot(c1.x - c0.x, c1.y - c0.y) * Math.min(from.zoom, goal.zoom);
|
|
328
|
+
const far = travel > Math.max(width, height);
|
|
329
|
+
const lz0 = Math.log(from.zoom);
|
|
330
|
+
const lz1 = Math.log(goal.zoom);
|
|
331
|
+
this.stopAnimation = tween({
|
|
332
|
+
duration,
|
|
333
|
+
onUpdate: p => {
|
|
334
|
+
const dip = far ? 1 - 0.4 * Math.sin(Math.PI * p) : 1;
|
|
335
|
+
const zoom = Math.exp(lz0 + (lz1 - lz0) * p) * dip;
|
|
336
|
+
const cx = c0.x + (c1.x - c0.x) * p;
|
|
337
|
+
const cy = c0.y + (c1.y - c0.y) * p;
|
|
338
|
+
const view = p >= 1
|
|
339
|
+
? goal
|
|
340
|
+
: { zoom, x: width / 2 - cx * zoom, y: height / 2 - cy * zoom };
|
|
341
|
+
this.apply(view, false);
|
|
342
|
+
},
|
|
343
|
+
onDone: () => {
|
|
344
|
+
this.stopAnimation = undefined;
|
|
345
|
+
this.apply(goal, true);
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
cancelAnimation() {
|
|
350
|
+
this.stopAnimation?.();
|
|
351
|
+
this.stopAnimation = undefined;
|
|
352
|
+
}
|
|
353
|
+
apply(view, settled) {
|
|
354
|
+
this.view = { x: view.x, y: view.y, zoom: view.zoom };
|
|
355
|
+
this.options.onChange(this.view, settled);
|
|
356
|
+
}
|
|
357
|
+
/** Starts a pan from a pointer press anywhere, for Space + drag over content. */
|
|
358
|
+
beginPan(event, background = false) {
|
|
359
|
+
const element = this.options.element();
|
|
360
|
+
if (!element)
|
|
361
|
+
return;
|
|
362
|
+
this.cancelAnimation();
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
this.pan = {
|
|
365
|
+
pointerId: event.pointerId,
|
|
366
|
+
startX: event.clientX,
|
|
367
|
+
startY: event.clientY,
|
|
368
|
+
origin: { ...this.view },
|
|
369
|
+
moved: false,
|
|
370
|
+
background,
|
|
371
|
+
element,
|
|
372
|
+
};
|
|
373
|
+
try {
|
|
374
|
+
element.setPointerCapture(event.pointerId);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
// Synthetic pointers cannot be captured.
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// ── Input
|
|
381
|
+
attach(element) {
|
|
382
|
+
this.attachedTo = element;
|
|
383
|
+
element.addEventListener('wheel', this.onWheel, { passive: false });
|
|
384
|
+
element.addEventListener('pointerdown', this.onPointerDown);
|
|
385
|
+
element.addEventListener('pointermove', this.onPointerMove);
|
|
386
|
+
element.addEventListener('pointerup', this.onPointerUp);
|
|
387
|
+
element.addEventListener('pointercancel', this.onPointerUp);
|
|
388
|
+
element.addEventListener('keydown', this.onKeyDown);
|
|
389
|
+
element.addEventListener('keyup', this.onKeyUp);
|
|
390
|
+
element.addEventListener('blur', this.onBlur);
|
|
391
|
+
}
|
|
392
|
+
detach() {
|
|
393
|
+
const element = this.attachedTo;
|
|
394
|
+
if (!element)
|
|
395
|
+
return;
|
|
396
|
+
element.removeEventListener('wheel', this.onWheel);
|
|
397
|
+
element.removeEventListener('pointerdown', this.onPointerDown);
|
|
398
|
+
element.removeEventListener('pointermove', this.onPointerMove);
|
|
399
|
+
element.removeEventListener('pointerup', this.onPointerUp);
|
|
400
|
+
element.removeEventListener('pointercancel', this.onPointerUp);
|
|
401
|
+
element.removeEventListener('keydown', this.onKeyDown);
|
|
402
|
+
element.removeEventListener('keyup', this.onKeyUp);
|
|
403
|
+
element.removeEventListener('blur', this.onBlur);
|
|
404
|
+
this.attachedTo = undefined;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Whether a wheel event belongs to something inside the canvas: an overlay marked
|
|
408
|
+
* `data-diagram-overlay` (a palette, a popover), or an element that can scroll that way.
|
|
409
|
+
*/
|
|
410
|
+
wheelBelongsInside(event) {
|
|
411
|
+
for (const node of event.composedPath()) {
|
|
412
|
+
if (node === this.attachedTo)
|
|
413
|
+
break;
|
|
414
|
+
if (node instanceof HTMLElement) {
|
|
415
|
+
if (node.hasAttribute('data-diagram-overlay'))
|
|
416
|
+
return 'overlay';
|
|
417
|
+
const style = getComputedStyle(node);
|
|
418
|
+
const scrollsY = event.deltaY !== 0 &&
|
|
419
|
+
/(auto|scroll)/.test(style.overflowY) &&
|
|
420
|
+
node.scrollHeight > node.clientHeight;
|
|
421
|
+
const scrollsX = event.deltaX !== 0 &&
|
|
422
|
+
/(auto|scroll)/.test(style.overflowX) &&
|
|
423
|
+
node.scrollWidth > node.clientWidth;
|
|
424
|
+
if (scrollsY || scrollsX)
|
|
425
|
+
return 'scroll';
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return undefined;
|
|
429
|
+
}
|
|
430
|
+
startPinch() {
|
|
431
|
+
const [a, b] = [...this.touches.values()];
|
|
432
|
+
if (this.pan) {
|
|
433
|
+
this.pan = undefined;
|
|
434
|
+
this.panning = false;
|
|
435
|
+
}
|
|
436
|
+
const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
437
|
+
this.pinch = {
|
|
438
|
+
distance: Math.max(Math.hypot(a.x - b.x, a.y - b.y), 1),
|
|
439
|
+
zoom: this.view.zoom,
|
|
440
|
+
anchor: this.toCanvas(mid.x, mid.y),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
movePinch() {
|
|
444
|
+
const { pinch } = this;
|
|
445
|
+
if (!pinch)
|
|
446
|
+
return;
|
|
447
|
+
const [a, b] = [...this.touches.values()];
|
|
448
|
+
const rect = this.options.element()?.getBoundingClientRect();
|
|
449
|
+
const mid = {
|
|
450
|
+
x: (a.x + b.x) / 2 - (rect?.left ?? 0),
|
|
451
|
+
y: (a.y + b.y) / 2 - (rect?.top ?? 0),
|
|
452
|
+
};
|
|
453
|
+
const zoom = this.clampZoom(pinch.zoom * (Math.hypot(a.x - b.x, a.y - b.y) / pinch.distance));
|
|
454
|
+
this.apply({
|
|
455
|
+
zoom,
|
|
456
|
+
x: mid.x - pinch.anchor.x * zoom,
|
|
457
|
+
y: mid.y - pinch.anchor.y * zoom,
|
|
458
|
+
}, false);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Screen pixels arrow keys pan the empty canvas. */
|
|
463
|
+
const PAN_STEP = 60;
|
|
464
|
+
const ZOOM_STEP = 1.25;
|
|
465
|
+
/**
|
|
466
|
+
* The camera, start position and chrome hooks every diagram canvas shares: `wc-diagram`,
|
|
467
|
+
* `wc-workflow` and the later diagram components. Subclasses render their content inside the
|
|
468
|
+
* element returned by `viewportElement()` and describe it through the abstract hooks.
|
|
469
|
+
*/
|
|
470
|
+
class DiagramCanvasElement extends i {
|
|
471
|
+
constructor() {
|
|
472
|
+
// ── Properties
|
|
473
|
+
super(...arguments);
|
|
474
|
+
/** The camera's scale. Follows wheel and pinch zooming; set it to zoom around the centre. */
|
|
475
|
+
this.zoom = 1;
|
|
476
|
+
/** Screen pixels kept around content when fitting it. */
|
|
477
|
+
this.padding = 50;
|
|
478
|
+
/** Where the camera starts: fit all content, the canvas origin at 100%, or the first item at 100%. */
|
|
479
|
+
this.startPosition = 'fit';
|
|
480
|
+
/** Smallest zoom. */
|
|
481
|
+
this.minZoom = 0.1;
|
|
482
|
+
/** Largest zoom. */
|
|
483
|
+
this.maxZoom = 4;
|
|
484
|
+
/** Spacing of the background dots, in canvas pixels. */
|
|
485
|
+
this.gridSize = 20;
|
|
486
|
+
/** Turns on editing. */
|
|
487
|
+
this.editable = false;
|
|
488
|
+
/** Keeps content in place; the person can still pan, zoom and select. */
|
|
489
|
+
this.readonly = false;
|
|
490
|
+
/** The canvas's accessible name. */
|
|
491
|
+
this.label = '';
|
|
492
|
+
// ── Protected fields
|
|
493
|
+
this.i18n = new I18nController(this);
|
|
494
|
+
this.listeners = new DiagramListeners();
|
|
495
|
+
this.viewport = new ViewportController(this, {
|
|
496
|
+
element: () => this.viewportElement(),
|
|
497
|
+
minZoom: () => this.minZoom,
|
|
498
|
+
maxZoom: () => this.maxZoom,
|
|
499
|
+
onChange: (view, settled) => this.onViewChange(view, settled),
|
|
500
|
+
isBackground: target => this.isBackground(target),
|
|
501
|
+
onBackgroundPointerDown: event => this.onBackgroundPointerDown(event),
|
|
502
|
+
onBackgroundClick: event => this.onBackgroundClick(event),
|
|
503
|
+
});
|
|
504
|
+
/** Whether the camera has been placed at the start position. */
|
|
505
|
+
this.startApplied = false;
|
|
506
|
+
this.viewportFrame = 0;
|
|
507
|
+
}
|
|
508
|
+
/** Return true to take over a primary press on the background, for example for a marquee. */
|
|
509
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
510
|
+
onBackgroundPointerDown(_event) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
/** A background press released without moving. */
|
|
514
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
515
|
+
onBackgroundClick(_event) {
|
|
516
|
+
// Nothing by default.
|
|
517
|
+
}
|
|
518
|
+
// ── Lifecycle
|
|
519
|
+
connectedCallback() {
|
|
520
|
+
super.connectedCallback();
|
|
521
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
522
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
523
|
+
this.requestUpdate();
|
|
524
|
+
this.maybeApplyStart();
|
|
525
|
+
});
|
|
526
|
+
this.resizeObserver.observe(this);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
disconnectedCallback() {
|
|
530
|
+
super.disconnectedCallback();
|
|
531
|
+
this.resizeObserver?.disconnect();
|
|
532
|
+
cancelAnimationFrame(this.viewportFrame);
|
|
533
|
+
}
|
|
534
|
+
willUpdate(changed) {
|
|
535
|
+
if (changed.has('zoom') &&
|
|
536
|
+
Math.abs(this.zoom - this.viewport.view.zoom) > 1e-6) {
|
|
537
|
+
this.viewport.zoomToValue(this.zoom);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
updated(changed) {
|
|
541
|
+
super.updated(changed);
|
|
542
|
+
this.maybeApplyStart();
|
|
543
|
+
this.listeners.notify();
|
|
544
|
+
}
|
|
545
|
+
// ── Public API
|
|
546
|
+
/** The camera: canvas point `c` is drawn at `c * zoom + (x, y)`. Setting it moves the camera at once. */
|
|
547
|
+
get view() {
|
|
548
|
+
return { ...this.viewport.view };
|
|
549
|
+
}
|
|
550
|
+
set view(value) {
|
|
551
|
+
this.viewport.setView(value);
|
|
552
|
+
}
|
|
553
|
+
/** Fits all content in view, never zooming past 100%. */
|
|
554
|
+
fit() {
|
|
555
|
+
const bounds = this.contentBounds();
|
|
556
|
+
if (!bounds)
|
|
557
|
+
return;
|
|
558
|
+
this.viewport.animateTo(this.viewport.viewForRect(bounds, this.padding));
|
|
559
|
+
}
|
|
560
|
+
/** Flies back to the start position. */
|
|
561
|
+
home() {
|
|
562
|
+
this.viewport.animateTo(this.homeView ?? this.computeStartView());
|
|
563
|
+
}
|
|
564
|
+
zoomIn() {
|
|
565
|
+
this.animateZoom(this.viewport.view.zoom * ZOOM_STEP);
|
|
566
|
+
}
|
|
567
|
+
zoomOut() {
|
|
568
|
+
this.animateZoom(this.viewport.view.zoom / ZOOM_STEP);
|
|
569
|
+
}
|
|
570
|
+
/** Zooms to a level (`1` is 100%), or centres the item with that id at 100%. */
|
|
571
|
+
zoomTo(target) {
|
|
572
|
+
if (typeof target === 'number') {
|
|
573
|
+
this.animateZoom(target);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const r = this.itemRect(target);
|
|
577
|
+
if (!r)
|
|
578
|
+
return;
|
|
579
|
+
this.viewport.animateTo(this.viewport.viewCentering({ x: r.x + r.width / 2, y: r.y + r.height / 2 }, 1));
|
|
580
|
+
}
|
|
581
|
+
/** Fits the selection in view. */
|
|
582
|
+
zoomToSelection() {
|
|
583
|
+
const bounds = boundsOf(this.selectionRects());
|
|
584
|
+
if (!bounds)
|
|
585
|
+
return;
|
|
586
|
+
this.viewport.animateTo(this.viewport.viewForRect(bounds, this.padding));
|
|
587
|
+
}
|
|
588
|
+
/** Centres canvas point `x, y`; animated unless `instant`. */
|
|
589
|
+
centerOn(x, y, instant = false) {
|
|
590
|
+
const view = this.viewport.viewCentering({ x, y });
|
|
591
|
+
if (instant)
|
|
592
|
+
this.viewport.setView(view);
|
|
593
|
+
else
|
|
594
|
+
this.viewport.animateTo(view, 300);
|
|
595
|
+
}
|
|
596
|
+
_diagramSubscribe(listener) {
|
|
597
|
+
return this.listeners.add(listener);
|
|
598
|
+
}
|
|
599
|
+
_diagramOverview() {
|
|
600
|
+
return {
|
|
601
|
+
items: this.overviewItems(),
|
|
602
|
+
visible: this.viewport.visibleRect(),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
// ── Protected methods
|
|
606
|
+
emit(type, detail, cancelable = false) {
|
|
607
|
+
return this.dispatchEvent(new CustomEvent(type, {
|
|
608
|
+
detail,
|
|
609
|
+
bubbles: true,
|
|
610
|
+
composed: true,
|
|
611
|
+
cancelable,
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
/** The start view for the current `start-position`; subclasses may adjust `fit`. */
|
|
615
|
+
computeStartView() {
|
|
616
|
+
if (this.startView) {
|
|
617
|
+
return {
|
|
618
|
+
...this.startView,
|
|
619
|
+
zoom: this.viewport.clampZoom(this.startView.zoom),
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const { zoom } = this.viewport.view;
|
|
623
|
+
if (this.startPosition === 'origin')
|
|
624
|
+
return { x: 0, y: 0, zoom };
|
|
625
|
+
const first = this.firstItemRect();
|
|
626
|
+
if (this.startPosition === 'first' && first) {
|
|
627
|
+
return this.viewport.viewCentering({ x: first.x + first.width / 2, y: first.y + first.height / 2 }, 1);
|
|
628
|
+
}
|
|
629
|
+
const bounds = this.contentBounds();
|
|
630
|
+
return bounds
|
|
631
|
+
? this.viewport.viewForRect(bounds, this.padding)
|
|
632
|
+
: { x: 0, y: 0, zoom };
|
|
633
|
+
}
|
|
634
|
+
/** Whether there is anything to place the camera on yet. */
|
|
635
|
+
hasContent() {
|
|
636
|
+
return !!this.contentBounds();
|
|
637
|
+
}
|
|
638
|
+
/** Places the camera once, when the canvas has a size and something to show. */
|
|
639
|
+
maybeApplyStart() {
|
|
640
|
+
if (this.startApplied || !this.hasUpdated)
|
|
641
|
+
return;
|
|
642
|
+
const { width, height } = this.viewport.size();
|
|
643
|
+
if (!width || !height)
|
|
644
|
+
return;
|
|
645
|
+
if (!this.hasContent() &&
|
|
646
|
+
!this.startView &&
|
|
647
|
+
this.startPosition !== 'origin') {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
this.startApplied = true;
|
|
651
|
+
this.homeView = this.computeStartView();
|
|
652
|
+
this.viewport.setView(this.homeView);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Canvas-wide shortcuts: zoom (+, -, Ctrl/⌘+0), fit (Shift+1), selection (Shift+2), back to start
|
|
656
|
+
* (Home) and arrow keys on the empty canvas. Returns whether the key was handled.
|
|
657
|
+
*/
|
|
658
|
+
handleCanvasKey(event) {
|
|
659
|
+
const mod = event.ctrlKey || event.metaKey;
|
|
660
|
+
const key = event.key.toLowerCase();
|
|
661
|
+
const origin = event.composedPath()[0];
|
|
662
|
+
let action;
|
|
663
|
+
if (mod && key === '0')
|
|
664
|
+
action = () => this.zoomTo(1);
|
|
665
|
+
else if (!mod && (key === '+' || key === '='))
|
|
666
|
+
action = () => this.zoomIn();
|
|
667
|
+
else if (!mod && key === '-')
|
|
668
|
+
action = () => this.zoomOut();
|
|
669
|
+
else if (event.shiftKey && event.code === 'Digit1')
|
|
670
|
+
action = () => this.fit();
|
|
671
|
+
else if (event.shiftKey && event.code === 'Digit2') {
|
|
672
|
+
action = () => this.zoomToSelection();
|
|
673
|
+
}
|
|
674
|
+
else if (key === 'home')
|
|
675
|
+
action = () => this.home();
|
|
676
|
+
else if (origin === this.viewportElement() && key.startsWith('arrow')) {
|
|
677
|
+
const d = {
|
|
678
|
+
arrowleft: [PAN_STEP, 0],
|
|
679
|
+
arrowright: [-PAN_STEP, 0],
|
|
680
|
+
arrowup: [0, PAN_STEP],
|
|
681
|
+
arrowdown: [0, -PAN_STEP],
|
|
682
|
+
}[key];
|
|
683
|
+
if (d)
|
|
684
|
+
action = () => this.viewport.panBy(d[0], d[1]);
|
|
685
|
+
}
|
|
686
|
+
if (!action)
|
|
687
|
+
return false;
|
|
688
|
+
event.preventDefault();
|
|
689
|
+
action();
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
/** Inline style that scrolls and scales the background dots with the camera. */
|
|
693
|
+
gridStyle() {
|
|
694
|
+
const { x, y, zoom } = this.viewport.view;
|
|
695
|
+
let dot = this.gridSize * zoom;
|
|
696
|
+
while (dot < 12)
|
|
697
|
+
dot *= 2;
|
|
698
|
+
return `background-size: ${dot}px ${dot}px; background-position: ${x}px ${y}px;`;
|
|
699
|
+
}
|
|
700
|
+
/** Whether `rect` is near the view, for rendering only what can be seen. */
|
|
701
|
+
nearView(rect, margin = 200) {
|
|
702
|
+
const { width, height } = this.viewport.size();
|
|
703
|
+
if (!this.startApplied || !width || !height)
|
|
704
|
+
return true;
|
|
705
|
+
const visible = inflateRect(this.viewport.visibleRect(), margin / this.viewport.view.zoom);
|
|
706
|
+
return rectsIntersect(rect, visible);
|
|
707
|
+
}
|
|
708
|
+
/** The "Back to content" button, shown when nothing is in view. */
|
|
709
|
+
renderBackToContent() {
|
|
710
|
+
const bounds = this.contentBounds();
|
|
711
|
+
if (!this.startApplied || !bounds)
|
|
712
|
+
return A;
|
|
713
|
+
if (rectsIntersect(bounds, this.viewport.visibleRect()))
|
|
714
|
+
return A;
|
|
715
|
+
return b `<wc-button
|
|
716
|
+
class="back-to-content"
|
|
717
|
+
level="secondary"
|
|
718
|
+
size="sm"
|
|
719
|
+
@click=${() => this.fit()}
|
|
720
|
+
><wc-icon slot="icon" name="center_focus_strong"></wc-icon>${this.i18n.t('diagramBackToContent')}</wc-button
|
|
721
|
+
>`;
|
|
722
|
+
}
|
|
723
|
+
// ── Private methods
|
|
724
|
+
onViewChange(view, settled) {
|
|
725
|
+
if (this.zoom !== view.zoom)
|
|
726
|
+
this.zoom = view.zoom;
|
|
727
|
+
this.requestUpdate();
|
|
728
|
+
this.pendingViewport = { ...view, settled };
|
|
729
|
+
if (settled) {
|
|
730
|
+
cancelAnimationFrame(this.viewportFrame);
|
|
731
|
+
this.viewportFrame = 0;
|
|
732
|
+
this.flushViewport();
|
|
733
|
+
}
|
|
734
|
+
else if (!this.viewportFrame) {
|
|
735
|
+
this.viewportFrame = requestAnimationFrame(() => {
|
|
736
|
+
this.viewportFrame = 0;
|
|
737
|
+
this.flushViewport();
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
flushViewport() {
|
|
742
|
+
const detail = this.pendingViewport;
|
|
743
|
+
this.pendingViewport = undefined;
|
|
744
|
+
if (detail)
|
|
745
|
+
this.emit('viewport-change', detail);
|
|
746
|
+
}
|
|
747
|
+
animateZoom(zoom) {
|
|
748
|
+
const { width, height } = this.viewport.size();
|
|
749
|
+
const { x, y, zoom: current } = this.viewport.view;
|
|
750
|
+
const next = this.viewport.clampZoom(zoom);
|
|
751
|
+
const cx = (width / 2 - x) / current;
|
|
752
|
+
const cy = (height / 2 - y) / current;
|
|
753
|
+
this.viewport.animateTo({ zoom: next, x: width / 2 - cx * next, y: height / 2 - cy * next }, 200);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
__decorate([
|
|
757
|
+
n({ type: Number, reflect: true })
|
|
758
|
+
], DiagramCanvasElement.prototype, "zoom", void 0);
|
|
759
|
+
__decorate([
|
|
760
|
+
n({ type: Number, reflect: true })
|
|
761
|
+
], DiagramCanvasElement.prototype, "padding", void 0);
|
|
762
|
+
__decorate([
|
|
763
|
+
n({ type: String, attribute: 'start-position' })
|
|
764
|
+
], DiagramCanvasElement.prototype, "startPosition", void 0);
|
|
765
|
+
__decorate([
|
|
766
|
+
n({ type: Object, attribute: 'start-view' })
|
|
767
|
+
], DiagramCanvasElement.prototype, "startView", void 0);
|
|
768
|
+
__decorate([
|
|
769
|
+
n({ type: Number, attribute: 'min-zoom' })
|
|
770
|
+
], DiagramCanvasElement.prototype, "minZoom", void 0);
|
|
771
|
+
__decorate([
|
|
772
|
+
n({ type: Number, attribute: 'max-zoom' })
|
|
773
|
+
], DiagramCanvasElement.prototype, "maxZoom", void 0);
|
|
774
|
+
__decorate([
|
|
775
|
+
n({ type: Number, attribute: 'grid-size' })
|
|
776
|
+
], DiagramCanvasElement.prototype, "gridSize", void 0);
|
|
777
|
+
__decorate([
|
|
778
|
+
n({ type: Boolean, reflect: true })
|
|
779
|
+
], DiagramCanvasElement.prototype, "editable", void 0);
|
|
780
|
+
__decorate([
|
|
781
|
+
n({ type: Boolean, reflect: true })
|
|
782
|
+
], DiagramCanvasElement.prototype, "readonly", void 0);
|
|
783
|
+
__decorate([
|
|
784
|
+
n({ type: String })
|
|
785
|
+
], DiagramCanvasElement.prototype, "label", void 0);
|
|
786
|
+
|
|
787
|
+
export { DiagramCanvasElement as D, animateOut as a, easeOutCubic as b, easeInOutCubic as e, prefersReducedMotion as p, tween as t };
|
|
788
|
+
//# sourceMappingURL=canvas-base-BTQMEVn_.js.map
|