diff --git a/README.md b/README.md index 87bb9e5..c0dfac2 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,10 @@ The component is the default export of `@opencor/plot`, and is also exported as | `PlotCsvExportFinishedEvent` | `{ type: 'finished'; success: boolean }` | An export to CSV has finished, whether successfully (and the file was downloaded) or not. | | `PlotImageExportEvent` | `{ action: 'copy' \| 'export'; format: 'jpeg' \| 'png' \| 'svg' \| 'webp'; success: boolean }` | The payload of the [`imageExport`](#events) event: whether the plot was copied to the clipboard (always as PNG) or exported to an image file, in which format, and whether it worked. | | `PlotContextMenuEvent` | `{ clientX: number; clientY: number; usingKeyboard: boolean; items: ContextMenuItem[] }` | The payload of the [`contextMenu`](#events) event: where the context menu was requested (in client coordinates), whether it was requested using the keyboard (in which case the custom menu should take the keyboard focus), and the items that our context menu would have shown. These items reflect the plot as it was when the context menu was requested and don't get updated if the data changes while the custom context menu is shown, but their commands always act on the plot as it is when they are chosen. | -| `ContextMenuItem` | `ContextMenuAction \| ContextMenuSeparator` | An item of a context menu. | +| `ContextMenuItem` | `ContextMenuAction \| ContextMenuSeparator \| ContextMenuHeader` | An item of a context menu. | | `ContextMenuAction` | `{ label: string; icon?: IconName; checked?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `label`, its `icon`, whether it is checked (only for a checkable action, e.g. to make an axis logarithmic), the `command` to call when it is chosen, and its submenu `items`, if any. | | `ContextMenuSeparator` | `{ separator: true }` | A separator. | +| `ContextMenuHeader` | `{ header: string }` | A header that can't be chosen, e.g. the full name of a trace when the context menu is requested from its legend item. It can contain a little HTML (see [Data](#data)). | | `IconName` | `'angle-right' \| 'arrows-h' \| 'arrows-v' \| 'chart-line' \| 'check' \| 'copy' \| 'download' \| 'eye' \| 'image' \| 'pencil' \| 'refresh' \| 'search-minus' \| 'search-plus'` | The name of an icon (from [PrimeIcons](https://primevue.org/icons/)). | | `PlotPointCounts` | `{ nbOfPoints: number; nbOfDrawnPoints: number }` | The value returned by the [`pointCounts()`](#methods) method. | | `PlotMemoryUsage` | `{ levelOfDetail: number; logValues: number }` | The value returned by the [`memoryUsage()`](#methods) method. | @@ -142,7 +143,7 @@ Also set the [`live`](#props) prop while the data is live, so that the last poin | Prop | Type | Default | Description | |---|---|---|---| | `data` | [`PlotData`](#types) | (required) | The data to plot. | -| `showLegend` | `boolean` | `true` | Whether to show the legend. The legend takes at most 40% of the width of the plot (with long trace names truncated, and shown in full when hovered), and is hidden if the plot is too narrow for it to be useful. | +| `showLegend` | `boolean` | `true` | Whether to show the legend. The legend takes at most 40% of the width of the plot (with long trace names truncated, and shown in full when hovered or in the context menu of their legend item), and is hidden if the plot is too narrow for it to be useful. | | `theme` | [`PlotTheme`](#types) | `'system'` | Whether to use light or dark mode, or whatever the system uses. | | `margins` | [`PlotMargins`](#types) | | Margins shared with other plots, so that their plotting areas line up (see [`marginsUpdated`](#events)). | | `appendTo` | `HTMLElement \| string` | `body` | Where to append our overlays (context menu, hover tooltip, etc.). | @@ -159,7 +160,7 @@ To draw traces without our level of detail, use `:levelOfDetail="false"`. Our pa | `marginsUpdated` | [`PlotMargins`](#types) | The margins that the plot needs have changed. To line up several plots, pass the largest left and right margins of all of them to each plot's [`margins`](#props) prop. | | `csvExport` | [`PlotCsvExportEvent`](#types) | An export to CSV has `'started'`, made `'progress'` (with a `percent`), or `'finished'` (with whether it was a `success`), so that its progress can be shown. | | `imageExport` | [`PlotImageExportEvent`](#types) | The plot has been copied to the clipboard or exported to an image (or has failed to be), so that the user can be told about it. | -| `contextMenu` | [`PlotContextMenuEvent`](#types) | Only with [`customContextMenu`](#props): the context menu was requested at `clientX`/`clientY`, with the `items` that our context menu would have shown. If `usingKeyboard` is true, the custom menu should take the keyboard focus. | +| `contextMenu` | [`PlotContextMenuEvent`](#types) | Only with [`customContextMenu`](#props): the context menu was requested at `clientX`/`clientY`, with the `items` that our context menu would have shown. If `usingKeyboard` is true, the custom menu should take the keyboard focus. The custom menu should call the `command` of the chosen item while handling the click (or tap, or key press) that chose it, and it shouldn't move the keyboard focus afterwards (calling [`contextMenuHidden()`](#methods) instead), since some commands (e.g., to edit the range of an axis) give the keyboard focus to an editor that closes when it loses it, and iOS only shows its virtual keyboard for such an editor while handling a user interaction. If it calls that `command` while handling a key press (e.g., Enter or Space), it should also prevent that key's default action (using `preventDefault()`), since the key would otherwise also be typed into such an editor, replacing its selected value. | ### Methods @@ -168,7 +169,7 @@ Available through a template ref: | Method | Description | |---|---| | `resetMargins()` | Emit [`marginsUpdated`](#events) again, e.g. after the shared margins have been reset. | -| `contextMenuHidden()` | Tell the plot that a custom context menu (see [`contextMenu`](#events)) has been hidden, so that it can get the keyboard focus back. | +| `contextMenuHidden()` | Tell the plot that a custom context menu (see [`contextMenu`](#events)) has been hidden, so that it can get the keyboard focus back (unless something else, e.g. an editor opened by the chosen item, has it). | | `pointCounts()` | The number of points of the visible traces (`nbOfPoints`), and how many of them were last drawn (`nbOfDrawnPoints`), as a [`PlotPointCounts`](#types). Meant for testing and benchmarking. | | `memoryUsage()` | The memory (in bytes) used by the component itself, not counting the data, as a [`PlotMemoryUsage`](#types): by its levels of detail (`levelOfDetail`) and by the logarithm of its values along logarithmic axes (`logValues`). Meant for testing and benchmarking. | @@ -179,7 +180,7 @@ Like with [Plotly](https://plotly.com/javascript/): - **Middle of an axis:** drag to pan along that axis, use the mouse wheel to zoom along it, and double-click to reset its zoom. - **Ends of an axis and bottom corners:** drag to move an end of the axis, or click an end of the axis to type its value. - **Legend:** click a trace to show or hide it, double-click it to only show that trace (or all the traces again), and hover it to highlight its trace. Its context menu (right-click, or Shift+F10 once it has the focus) can also show only that trace (or all the traces again), or show or hide it if it is the only trace. -- **Touch:** drag with one finger as with a mouse, or use two fingers to zoom and pan. +- **Touch** (or a pen): on the plotting area, swipe to scroll the page, use two fingers to zoom and pan, touch and hold, then drag to zoom (in browsers that don't turn a pen into touch events, e.g. Chrome on Windows, a pen doesn't scroll the page, but drags to zoom straight away, as a mouse does), and tap, then drag straight away to move the hover tooltip (which is shown above the finger). On the axes, drag with one finger as with a mouse. Tap and double-tap as you would click and double-click. Touch and hold, then release, to open the context menu (as with a right-click), including from a legend item. If a touchscreen is available, the axes can be dragged a bit further away from the plotting area, the ends of the axes are longer, and the legend items and context menu items are taller. - **Keyboard** (once the plot has the focus): `+` and `−` to zoom in and out, `0` to reset the zoom, the arrow keys to pan, and Shift+F10 (or the context menu key) to open the context menu (e.g., to type the value of an end of an axis). Each legend item can also get the focus: Enter or Space shows or hides its trace, and Shift+F10 opens its context menu. - **Escape**, or pressing another mouse button, cancels a drag. diff --git a/bun.lock b/bun.lock index d766d0d..c0f8f5c 100644 --- a/bun.lock +++ b/bun.lock @@ -13,12 +13,12 @@ "@types/bun": "^1.4.5", "@vitejs/plugin-vue": "^6.0.11", "@vue/tsconfig": "^0.9.1", - "puppeteer-core": "^25.18.1", + "puppeteer-core": "^25.19.0", "stylelint": "^18.1.0", "stylelint-config-standard": "^41.1.0", "typescript": "^7.0.2", "typescript-6": "npm:typescript@^6.0.3", - "vite": "^8.3.8", + "vite": "^8.4.0", "vue": "^3.5.46", "vue-tsc": "^3.3.14", }, @@ -72,61 +72,51 @@ "@csstools/selector-specificity": ["@csstools/selector-specificity@6.0.1", "", { "peerDependencies": { "postcss-selector-parser": "^7.1.1" } }, "sha512-MBuqFIIvqk4S593MGAskTkPpEUUzZNvGzh8mMxEwl3oHwjQlXmqHEDxNbN3Y0Tsh+xjmem4GZjeg7I0qkwBivg=="], - "@emnapi/core": ["@emnapi/core@2.0.0-beta.2", "", { "dependencies": { "@emnapi/wasi-threads": "2.2.0", "tslib": "^2.4.0" } }, "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A=="], - - "@emnapi/runtime": ["@emnapi/runtime@2.0.0-beta.2", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw=="], - - "@emnapi/wasi-threads": ["@emnapi/wasi-threads@2.2.0", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw=="], - "@happy-dom/global-registrator": ["@happy-dom/global-registrator@21.0.4", "", { "dependencies": { "@types/node": ">=20.0.0", "happy-dom": "^21.0.4" } }, "sha512-Bbr0hW9hhDhBf3Jp0EyDlkCbFgbr0z2jd3BMKYOYW+fOkPM4Nx195GMXyCtRCGEgoNn6i09FabXrSkNFm2ONzg=="], "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], - "@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@1.2.6", "", { "dependencies": { "@tybys/wasm-util": "^0.10.3" }, "peerDependencies": { "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" } }, "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw=="], - - "@oxc-project/types": ["@oxc-project/types@0.156.0", "", {}, "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw=="], + "@oxc-project/types": ["@oxc-project/types@0.160.0", "", {}, "sha512-gw4k9syEmnckbOgw2A2FU1TBDdX9hfwV9jEn/uio65pguPzwWiXQS3OIJDMEhv9m06tj9XiEe6RoD0YA+LgreA=="], - "@puppeteer/browsers": ["@puppeteer/browsers@3.2.7", "", { "dependencies": { "modern-tar": "^0.8.6", "yargs": "^18.0.0" }, "peerDependencies": { "proxy-agent": ">=8.0.1", "yauzl": "^2.10.0 || ^3.4.0" }, "optionalPeers": ["proxy-agent", "yauzl"], "bin": { "browsers": "lib/main-cli.js" } }, "sha512-B3C/v8OEEaJYcN1IzzgbPmt+GbFANr4Mf/NrqNuGk/dIchrv6quNqxgT+A6qE0Ge0MN95NjKUddcR1JMpYRMWA=="], + "@puppeteer/browsers": ["@puppeteer/browsers@3.3.0", "", { "dependencies": { "modern-tar": "^0.8.6", "yargs": "^18.0.0" }, "peerDependencies": { "proxy-agent": ">=8.0.1", "yauzl": "^2.10.0 || ^3.4.0" }, "optionalPeers": ["proxy-agent", "yauzl"], "bin": { "browsers": "lib/main-cli.js" } }, "sha512-ZiOVHQ5KmsinwZJMwRc/a3xsGHbi9dRuAyf2gq4i9J5vRaI4r7SSIaJUniF1JVClG+qNoVdtBBWfL08N9Oib6g=="], - "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.19", "", { "os": "android", "cpu": "arm" }, "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A=="], + "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.3.4", "", { "os": "android", "cpu": "arm" }, "sha512-xCW8CkL/ualx/SbYqeG9iK87lJCZGDQ0soE+kaORJ0Bd+pHALyE4qK7BStmEAyYWLEzZ3/biSIpA6/7GDFvzIg=="], - "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.19", "", { "os": "android", "cpu": "arm64" }, "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA=="], + "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.3.4", "", { "os": "android", "cpu": "arm64" }, "sha512-5lifIO+b/prcM9sx/bkPN4w6UEToEfQ3gjhx0+0neuL+dkYskI792CfAq03T51jc8JFcaYXs2hi3l8RjiH/VWQ=="], - "@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.2.19", "", { "os": "darwin", "cpu": "arm64" }, "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g=="], + "@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.3.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-RCgxTI4AJQxhVF//BI3ImQOsXTHrF4Eg+f99jBy8WoETA2kSEGFxpnrVmW0leQq/2aBR4R5AC6csmy3rc66e3Q=="], - "@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.2.19", "", { "os": "darwin", "cpu": "x64" }, "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg=="], + "@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.3.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-zNPJVVPUaDEj+L0lImoK3rFv2b+Z5gNijI6DWu/fcD3/1TfmRXKb9ZyxbSN+2AhlctqjbNzUvCsMa+EBhnEM4Q=="], - "@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.2.19", "", { "os": "freebsd", "cpu": "x64" }, "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA=="], + "@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.3.4", "", { "os": "freebsd", "cpu": "x64" }, "sha512-upP6g7ZIRy5by1RDQ/EphHIdJ5xK0eUD7sUgfZFWJ49s4XdbYsIvIlAPtrFpayR70Hhf9J22lb4Pm8/9FhrZmg=="], - "@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.2.19", "", { "os": "linux", "cpu": "arm" }, "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw=="], + "@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.3.4", "", { "os": "linux", "cpu": "arm" }, "sha512-SAX5C5+poMLCxu8dkPF6h5yst40rkzs+9Y3cbPn2OFSydmHjAEprrGi64zGgnYyPIVZfdGUFqJ2fJbfbnHI+mA=="], - "@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.2.19", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA=="], + "@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.3.4", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-nwHqdlRZS6GWBef3dG5/pMY6RNTBBUjj7s0Da+m6xsFpe7jx6IC46SLZcCu8f46JOfCovZmwnrz51EzGE+7Fyw=="], - "@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.2.19", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg=="], + "@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.3.4", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-Gr78X2ur/AgLCkmZgHffk/FerIX8S5zb/eII4bCcvJo0ANzeXhTShahdNbpnY6bpiszIAgIfiuKS9ziziWsamw=="], - "@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.2.19", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q=="], + "@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.3.4", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-o9Wcn8nWrsQasaBRYM4d//FwhlBsTJYWkPVlhlt6FwzpwEoovY4IopRZjk5Fq3+ntRuSDORJjF/nA8sFeF2q6w=="], - "@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.2.19", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw=="], + "@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.3.4", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-UDWu4jkVcx2kiBKm3Ec//4lVCbeTWj8gmJ9SyLWCdLWtTlyq7fQVeVV/14nXvRtSLErvJ2+yA/Ux5taS31Y17Q=="], - "@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.2.19", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q=="], + "@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.3.4", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-W9mGtTa0w4fWh8RLMNPyaEhhcuqUfO07Q4I1bBc4PDMNg7gQSw0yPQNQ3D0qwbkXwxbyL4YrIzc8n6k1vuFExQ=="], - "@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.2.19", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A=="], + "@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.3.4", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-8B+ofyQZ7/aCmkqnyMonPr5zKLqMVNczhRGFNtdIuItiwNn8iQWJawMq2E58r7bxD1XEbtRRsULY/eCWwZQ01Q=="], - "@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.2.19", "", { "os": "none", "cpu": "arm64" }, "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA=="], + "@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.3.4", "", { "os": "none", "cpu": "arm64" }, "sha512-TlD0FSZaC7o2B4NCe9V5N11ugTnhzTM9ksj4sgRLvrKosDzjEkvlsTX3ehkw4ZlPv8AADimZZTvJGEa16pfXug=="], - "@rolldown/binding-wasm32-wasi": ["@rolldown/binding-wasm32-wasi@1.2.19", "", { "dependencies": { "@emnapi/core": "2.0.0-beta.2", "@emnapi/runtime": "2.0.0-beta.2", "@napi-rs/wasm-runtime": "1.2.6" }, "cpu": "none" }, "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg=="], + "@rolldown/binding-wasm32-wasi": ["@rolldown/binding-wasm32-wasi@1.3.4", "", { "dependencies": { "@oxc-project/types": "0.160.0" }, "cpu": "none" }, "sha512-jwO8P3o53ygo7b5061B7BeaJ1BGv3BKZ6jroFdw/01qWry7Z+qNBlDvulzbTle5s/A0Fc1FRgsTxrke9DvsSbA=="], - "@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.2.19", "", { "os": "win32", "cpu": "arm64" }, "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ=="], + "@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.3.4", "", { "os": "win32", "cpu": "arm64" }, "sha512-8adGMrNtrdzi2WD1ozhYapER59gD8Q/DV6SCKJlyG2HqULPdeQUBvMa33lTsiEYwIqTZUaIU2MmvPp5f1wbtXA=="], - "@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.2.19", "", { "os": "win32", "cpu": "x64" }, "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag=="], + "@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.3.4", "", { "os": "win32", "cpu": "x64" }, "sha512-rIMjtESdXJCIoOiUTroQ1Y1rjVDZkuUVRUxs3APX2vNv175D7TDWvzdELiIhzGq9cUNUFat+co+PTmPHPqSREg=="], "@rolldown/pluginutils": ["@rolldown/pluginutils@1.1.1", "", {}, "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA=="], - "@tybys/wasm-util": ["@tybys/wasm-util@0.10.5", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA=="], - "@types/bun": ["@types/bun@1.4.5", "", { "dependencies": { "bun-types": "1.4.5" } }, "sha512-DpgwNI9z0L1S0gtb45QLCWgwCUcMLnsHYMJHQvpNj7erGiCGBvpggltAIeARrtobNMKMuy0UP7i56tKKgwFs/Q=="], - "@types/node": ["@types/node@26.6.9", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-MkLVXFazHKL5/3lkiYqaSti6Ohv0Vi6z2bPwUQAs/aXUuuY8go4hR3mz8Kvu0lBC2HH0Zn+ON2G9hTglqDD48A=="], + "@types/node": ["@types/node@26.6.11", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-uUyQ2XLEz+EXh34lmS3GhKrkqn/8FU7KUiKRpk347At2bmnMVWss45yz8b4FG/tUtmV1tV/+TVkITItPROyeeQ=="], "@types/whatwg-mimetype": ["@types/whatwg-mimetype@3.0.2", "", {}, "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA=="], @@ -220,7 +210,7 @@ "cliui": ["cliui@9.0.1", "", { "dependencies": { "string-width": "^7.2.0", "strip-ansi": "^7.1.0", "wrap-ansi": "^9.0.0" } }, "sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w=="], - "colord": ["colord@2.14.0", "", {}, "sha512-eSdMel9EBvdFxnchObp7gljRoqYQLr+zXhaxjkym7syVphw1FIhfQwgsA5Bv3jArflZPJEa1rmQtGpa7NRc7Rw=="], + "colord": ["colord@2.14.1", "", {}, "sha512-oAnRdUZtIoONz9y5JZEM/Ogg4m/eYIvpCvzFZIFOPfraLqVYTmevf61yeIhcLq/9EXztGOwF4O36pCu143BqGw=="], "cosmiconfig": ["cosmiconfig@10.0.1", "", { "dependencies": { "env-paths": "^2.2.1", "js-yaml": "^5.4.1" } }, "sha512-/zvGoYn0y27QTBmK+0B+oPdEPC4fKGUmJsMTQbDjqph00TrkqfVFW/M+C6ya54sYCgHC6QCwK/mI6djt8cEGHQ=="], @@ -230,7 +220,7 @@ "detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], - "devtools-protocol": ["devtools-protocol@0.0.1717327", "", {}, "sha512-3RDLDzyvv8XAYf1L+TL1og0EEk0eOW1Jn0yi88uG6Bj8fUKO1ZKfgNtwbJkqf5SWdPDS4VGEPxwdUWz78V6Xcg=="], + "devtools-protocol": ["devtools-protocol@0.0.1724436", "", {}, "sha512-GcO1782pvzpmY4pQO1zjr8WZ95Wv8GodOs0v5J9QWwLGulTzfYIYECEd9iUsnqJmcehu+VMKxZquvjY8T2jhAA=="], "emoji-regex": ["emoji-regex@10.6.0", "", {}, "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A=="], @@ -252,7 +242,7 @@ "happy-dom": ["happy-dom@21.0.4", "", { "dependencies": { "@types/node": ">=20.0.0", "@types/whatwg-mimetype": "^3.0.2", "@types/ws": "^8.18.1", "buffer-image-size": "^0.6.4", "entities": "^7.0.1", "whatwg-mimetype": "^3.0.0", "ws": "^8.21.0" } }, "sha512-tFm+GaLBgo6o0awHnvHaNoraVo27qJ+2tZEtZ+cIa08hXbeitrxAJajLI05hsUy/2/YTKcUjQYzHe5mCcraLBw=="], - "ignore": ["ignore@7.0.16", "", {}, "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A=="], + "ignore": ["ignore@7.0.17", "", {}, "sha512-0c3zcBRlWmcKhcIQWckzkYncJRv5HHB8O32wO/FcWL8DDXWDJgiEF6SX9ThbTv5h/eZ+xJK+VvDjjQ+cQJhp3Q=="], "import-meta-resolve": ["import-meta-resolve@4.2.0", "", {}, "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg=="], @@ -294,6 +284,8 @@ "nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="], + "napi-windows-process-start-time": ["napi-windows-process-start-time@0.1.0", "", { "os": "win32", "cpu": [ "x64", "arm64", ] }, "sha512-zHxhzKsIFu3elch3eFw69WEUGc79DFhbc3nD/WEOzWL/pFFLZRW13EHnuO0c+0YjncE5uCaS9ICHxOBXkb6vPw=="], + "path-browserify": ["path-browserify@1.0.1", "", {}, "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g=="], "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], @@ -308,9 +300,9 @@ "postcss-value-parser": ["postcss-value-parser@4.2.0", "", {}, "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="], - "puppeteer-core": ["puppeteer-core@25.18.1", "", { "dependencies": { "@puppeteer/browsers": "3.2.7", "chromium-bidi": "157.0.8090-0", "devtools-protocol": "0.0.1717327", "typed-query-selector": "^2.12.3", "webdriver-bidi-protocol": "1.0.2", "ws": "^8.22.1" } }, "sha512-C0wHOJHDfAggGBtN5uUfsJGpeSKtPL5jzhgQYDuz4XKeOG1FUkxeZI2M5yK7AUyrdHO+RgDuiCfjmOpcw3PYTA=="], + "puppeteer-core": ["puppeteer-core@25.19.0", "", { "dependencies": { "@puppeteer/browsers": "3.3.0", "chromium-bidi": "157.0.8090-0", "devtools-protocol": "0.0.1724436", "typed-query-selector": "^2.12.3", "webdriver-bidi-protocol": "1.0.2", "ws": "^8.23.0" } }, "sha512-F4pw8kpSczJS3TCHBw7/qskDxv4cMj09oOv7BwhHGYOerxLF1Sk2t4tpWlLvy6Vx/mM6TuqkDj4j0j3PRN1FiA=="], - "rolldown": ["rolldown@1.2.19", "", { "dependencies": { "@oxc-project/types": "=0.156.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.2.19", "@rolldown/binding-android-arm64": "1.2.19", "@rolldown/binding-darwin-arm64": "1.2.19", "@rolldown/binding-darwin-x64": "1.2.19", "@rolldown/binding-freebsd-x64": "1.2.19", "@rolldown/binding-linux-arm-gnueabihf": "1.2.19", "@rolldown/binding-linux-arm64-gnu": "1.2.19", "@rolldown/binding-linux-arm64-musl": "1.2.19", "@rolldown/binding-linux-ppc64-gnu": "1.2.19", "@rolldown/binding-linux-s390x-gnu": "1.2.19", "@rolldown/binding-linux-x64-gnu": "1.2.19", "@rolldown/binding-linux-x64-musl": "1.2.19", "@rolldown/binding-openharmony-arm64": "1.2.19", "@rolldown/binding-wasm32-wasi": "1.2.19", "@rolldown/binding-win32-arm64-msvc": "1.2.19", "@rolldown/binding-win32-x64-msvc": "1.2.19" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA=="], + "rolldown": ["rolldown@1.3.4", "", { "dependencies": { "@oxc-project/types": "=0.160.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.3.4", "@rolldown/binding-android-arm64": "1.3.4", "@rolldown/binding-darwin-arm64": "1.3.4", "@rolldown/binding-darwin-x64": "1.3.4", "@rolldown/binding-freebsd-x64": "1.3.4", "@rolldown/binding-linux-arm-gnueabihf": "1.3.4", "@rolldown/binding-linux-arm64-gnu": "1.3.4", "@rolldown/binding-linux-arm64-musl": "1.3.4", "@rolldown/binding-linux-ppc64-gnu": "1.3.4", "@rolldown/binding-linux-s390x-gnu": "1.3.4", "@rolldown/binding-linux-x64-gnu": "1.3.4", "@rolldown/binding-linux-x64-musl": "1.3.4", "@rolldown/binding-openharmony-arm64": "1.3.4", "@rolldown/binding-wasm32-wasi": "1.3.4", "@rolldown/binding-win32-arm64-msvc": "1.3.4", "@rolldown/binding-win32-x64-msvc": "1.3.4" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-p2rq4bfBmF0M6yaR8+A89fbkBQynZI2fxUW4G07eq9kpctAkpo7q5BZ4X4Mo4XZ7HHROu33cX9PeopUFN6u+2Q=="], "signal-exit": ["signal-exit@4.1.0", "", {}, "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw=="], @@ -328,8 +320,6 @@ "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], - "tslib": ["tslib@2.9.1", "", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], - "typed-query-selector": ["typed-query-selector@2.12.4", "", {}, "sha512-lF6/OY655DSWZeuNovde8TZhju6QyC0Xtav57b07oZQ1EQvfSowA3+WfLEhvFJOc9sVfAtW5hie1lGIppOqbpQ=="], "typescript": ["typescript@7.0.2", "", { "optionalDependencies": { "@typescript/typescript-aix-ppc64": "7.0.2", "@typescript/typescript-darwin-arm64": "7.0.2", "@typescript/typescript-darwin-x64": "7.0.2", "@typescript/typescript-freebsd-arm64": "7.0.2", "@typescript/typescript-freebsd-x64": "7.0.2", "@typescript/typescript-linux-arm": "7.0.2", "@typescript/typescript-linux-arm64": "7.0.2", "@typescript/typescript-linux-loong64": "7.0.2", "@typescript/typescript-linux-mips64el": "7.0.2", "@typescript/typescript-linux-ppc64": "7.0.2", "@typescript/typescript-linux-riscv64": "7.0.2", "@typescript/typescript-linux-s390x": "7.0.2", "@typescript/typescript-linux-x64": "7.0.2", "@typescript/typescript-netbsd-arm64": "7.0.2", "@typescript/typescript-netbsd-x64": "7.0.2", "@typescript/typescript-openbsd-arm64": "7.0.2", "@typescript/typescript-openbsd-x64": "7.0.2", "@typescript/typescript-sunos-x64": "7.0.2", "@typescript/typescript-win32-arm64": "7.0.2", "@typescript/typescript-win32-x64": "7.0.2" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="], @@ -342,11 +332,11 @@ "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="], - "vite": ["vite@8.3.8", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.32", "rolldown": "~1.2.18", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA=="], + "vite": ["vite@8.4.0", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.33", "rolldown": "~1.3.2", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3", "napi-windows-process-start-time": "^0.1.0" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-X2nUJg+9cutlz3hzqyO6p+WTwk9H257DjwAEf9EQYUFrQbDItmetadi9gYmb+l7VDy4r3VXLUnmLTwuPmzejDw=="], - "vscode-jsonrpc": ["vscode-jsonrpc@10.0.1", "", {}, "sha512-fGdu32Sp4GeSQ2twML46WPMB6cFfIJ4Vdx1K5s/WPzUYdShVPCGKscYltn5hiNz748xKNJdBHgocAvuN48tLGw=="], + "vscode-jsonrpc": ["vscode-jsonrpc@10.0.2", "", {}, "sha512-U6K7wa1t8jTZf7eoHJLKSNdHE0oi9r/+/4TSXWPSLQ2FSQVMYLR5TvzQHrYjwW/lLjq0eTm+pi8vWz4jSV7o4w=="], - "vscode-languageserver-protocol": ["vscode-languageserver-protocol@3.18.6", "", { "dependencies": { "vscode-jsonrpc": "10.0.1", "vscode-languageserver-types": "3.18.6" } }, "sha512-Ocoa4g/vyB66ZFkIKApV8/FTjQ+EYeOVDkq/nzw9SmfX+L6Ikl5KtL5AjmSAQ7nhqfud1ojiVuy+drHdvAlgUg=="], + "vscode-languageserver-protocol": ["vscode-languageserver-protocol@3.18.7", "", { "dependencies": { "vscode-jsonrpc": "10.0.2", "vscode-languageserver-types": "3.18.6" } }, "sha512-5oItSZDTTehe0zXzwJCFUMso6RfUb2FWVTFfQxAesV3nTbkY1hjW3O6q8872M9TACEXFcALaU5xU37sGudYI8g=="], "vscode-languageserver-textdocument": ["vscode-languageserver-textdocument@1.0.16", "", {}, "sha512-qeNEuOi9a3qkqRf7Gfez2WL2VwlBTLCNekHBGO9kxPVUp9XuY15yfTJ9jwvOwKI0I2MhUUfZq95NSp+LK1CLQg=="], diff --git a/demo/App.vue b/demo/App.vue index adade2c..ed384d6 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -151,7 +151,8 @@ @keydown.escape="hideCustomMenu" >
  • -
    + {{ item.label }} +
  • @@ -1088,18 +1089,36 @@ const statusRows = vue.computed(() => [ interface CustomMenuItem { label: string; + header?: boolean; command?: () => void; } const customMenuRef = vue.useTemplateRef('customMenuRef'); const customMenu = vue.ref<{ x: number; y: number; items: CustomMenuItem[]; instance: number } | null>(null); +const headerLabel = (header: string): string => { + // Return the text of the given header, with its line breaks replaced with spaces, so that its lines don't run + // together. + + const body = new DOMParser().parseFromString(header, 'text/html').body; + + for (const lineBreak of body.querySelectorAll('br')) { + lineBreak.replaceWith(' '); + } + + return body.textContent ?? ''; +}; + const flattenedItems = (items: ContextMenuItem[], prefix: string = ''): CustomMenuItem[] => { return items.flatMap((item: ContextMenuItem): CustomMenuItem[] => { if ('separator' in item) { return [{ label: '' }]; } + if ('header' in item) { + return [{ label: headerLabel(item.header), header: true }]; + } + const label = `${prefix}${item.label}${item.checked ? ' ✓' : ''}`; return item.items ? flattenedItems(item.items, `${label} › `) : [{ label, command: item.command }]; @@ -1320,6 +1339,11 @@ const onWindowPointerDown = (event: PointerEvent): void => { background-color: var(--demo-border); } + .demo-custom-menu strong { + display: block; + padding: 0.25rem 0.5rem; + } + .demo-custom-menu hr { margin: 0.25rem 0; border: none; diff --git a/index.ts b/index.ts index 5fdc20c..82ac990 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ export type { IconName } from './src/common/icons'; export type { ContextMenuAction, + ContextMenuHeader, ContextMenuItem, ContextMenuSeparator } from './src/widgets/ContextMenuWidget.vue'; diff --git a/package.json b/package.json index c256bb7..590adcc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ ], "type": "module", "types": "dist/index.d.ts", - "version": "0.20261125.6", + "version": "0.20261127.0", "exports": { ".": { "types": "./dist/index.d.ts", @@ -67,12 +67,12 @@ "@types/bun": "^1.4.5", "@vitejs/plugin-vue": "^6.0.11", "@vue/tsconfig": "^0.9.1", - "puppeteer-core": "^25.18.1", + "puppeteer-core": "^25.19.0", "stylelint": "^18.1.0", "stylelint-config-standard": "^41.1.0", "typescript": "^7.0.2", "typescript-6": "npm:typescript@^6.0.3", - "vite": "^8.3.8", + "vite": "^8.4.0", "vue": "^3.5.46", "vue-tsc": "^3.3.14" } diff --git a/src/common/pathLevelOfDetailUtils.ts b/src/common/pathLevelOfDetailUtils.ts index 56bee08..99a619b 100644 --- a/src/common/pathLevelOfDetailUtils.ts +++ b/src/common/pathLevelOfDetailUtils.ts @@ -406,10 +406,10 @@ const processLevel = ( // Process (up to the given number of) the points of our trace that the given level hasn't processed (see Note #5 and // Note #9 above), and return whether the level has no more than the given number of points, stopping as soon as it // has more (since it then gets dropped, see processedLevel()). - // Note: the points that we process again (i.e. from our snapshot or from our anchor, see below) don't count towards - // the given number of points, so that we always process at least one new point. - // Note: our state (see PathLevelState for what it means) is kept in local variables rather than in a PathLevelState - // object while we process our points, so that JavaScript engines can keep it in registers. + // Note #1: the points that we process again (i.e. from our snapshot or from our anchor, see below) don't count + // towards the given number of points, so that we always process at least one new point. + // Note #2: our state (see PathLevelState for what it means) is kept in local variables rather than in a + // PathLevelState object while we process our points, so that JavaScript engines can keep it in registers. const xOrigin = lod.xOrigin; const yOrigin = lod.yOrigin; diff --git a/src/common/touchUtils.test.ts b/src/common/touchUtils.test.ts new file mode 100644 index 0000000..bf6bcac --- /dev/null +++ b/src/common/touchUtils.test.ts @@ -0,0 +1,180 @@ +import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test'; + +import { + axisEndSize, + DOUBLE_TAP_DELAY, + isDirectPointer, + isDoubleTap, + LONG_PRESS_DURATION, + LongPress, + pinchShift, + TOUCH_TARGET_SIZE +} from './touchUtils'; + +afterEach(() => { + mock.restore(); +}); + +// isDirectPointer(). + +describe('isDirectPointer()', () => { + it('returns whether a pointer is a finger or a pen', () => { + expect(isDirectPointer('touch')).toBe(true); + expect(isDirectPointer('pen')).toBe(true); + expect(isDirectPointer('mouse')).toBe(false); + expect(isDirectPointer('')).toBe(false); + }); +}); + +// axisEndSize(). + +describe('axisEndSize()', () => { + it('returns 10% of the length of an axis if it is at least the minimum size', () => { + expect(axisEndSize(1000, TOUCH_TARGET_SIZE)).toBe(100); + expect(axisEndSize(300, 0)).toBe(30); + }); + + it('returns the minimum size if 10% of the length of an axis is smaller', () => { + expect(axisEndSize(300, TOUCH_TARGET_SIZE)).toBe(TOUCH_TARGET_SIZE); + }); + + it('returns at most 25% of the length of an axis', () => { + expect(axisEndSize(100, TOUCH_TARGET_SIZE)).toBe(25); + expect(axisEndSize(0, TOUCH_TARGET_SIZE)).toBe(0); + }); +}); + +// pinchShift(). + +describe('pinchShift()', () => { + it('returns 0 if nothing has moved', () => { + expect(pinchShift(600, 300, 300, 1)).toBe(0); + expect(pinchShift(600, 100, 100, 1)).toBe(0); + }); + + it('returns how far our center has moved if we have only panned', () => { + expect(pinchShift(600, 300, 305, 1)).toBe(5); + expect(pinchShift(600, 300, 295, 1)).toBe(5); + }); + + it('returns how far an end of our axis has moved if we have zoomed', () => { + expect(pinchShift(100, 50, 50, 0.5)).toBe(50); + expect(pinchShift(100, 50, 50, 2)).toBe(25); + expect(pinchShift(100, 0, 0, 0.5)).toBe(100); + expect(pinchShift(100, 100, 100, 0.5)).toBe(100); + }); + + it('returns a large distance for a small pinch whose fingers started close together', () => { + // Two fingers that start 40 pixels apart in the middle of a 600-pixel axis, and that each move 7 pixels outwards. + + expect(pinchShift(600, 300, 300, 40 / 54)).toBeCloseTo(105); + }); + + it('returns the largest distance by which something has moved if we have zoomed and panned', () => { + expect(pinchShift(100, 50, 60, 0.5)).toBe(60); + expect(pinchShift(100, 50, 40, 0.5)).toBe(60); + }); +}); + +// isDoubleTap(). + +describe('isDoubleTap()', () => { + const firstTap = { pressTime: 1000, releaseTime: 1100, x: 50, y: 60 }; + const secondTap = (delay: number, x: number = 50, y: number = 60) => ({ + pressTime: 1100 + delay, + releaseTime: 1100 + delay + 100, + x, + y + }); + + it('returns false if there is no first tap', () => { + expect(isDoubleTap(undefined, secondTap(100))).toBe(false); + }); + + it('returns whether the second tap was pressed soon enough after the first one was released', () => { + expect(isDoubleTap(firstTap, secondTap(0))).toBe(true); + expect(isDoubleTap(firstTap, secondTap(DOUBLE_TAP_DELAY))).toBe(true); + expect(isDoubleTap(firstTap, secondTap(DOUBLE_TAP_DELAY + 1))).toBe(false); + expect(isDoubleTap(firstTap, secondTap(-1))).toBe(false); + }); + + it('returns whether the second tap was pressed close enough to the first one', () => { + expect(isDoubleTap(firstTap, secondTap(100, 50 + TOUCH_TARGET_SIZE - 1, 60))).toBe(true); + expect(isDoubleTap(firstTap, secondTap(100, 50, 60 - TOUCH_TARGET_SIZE))).toBe(false); + expect(isDoubleTap(firstTap, secondTap(100, 50 + 0.8 * TOUCH_TARGET_SIZE, 60 + 0.8 * TOUCH_TARGET_SIZE))).toBe( + false + ); + }); +}); + +// LongPress. + +describe('LongPress', () => { + let timeouts: [callback: () => void, delay: number | undefined][]; + let clearedTimeouts: unknown[]; + + beforeEach(() => { + // Mock setTimeout() and clearTimeout(), so that we can run our long press callback when we want. + + timeouts = []; + clearedTimeouts = []; + + spyOn(globalThis, 'setTimeout').mockImplementation(((callback: () => void, delay?: number) => { + timeouts.push([callback, delay]); + + return timeouts.length; + }) as typeof setTimeout); + spyOn(globalThis, 'clearTimeout').mockImplementation(((id: unknown) => { + clearedTimeouts.push(id); + }) as typeof clearTimeout); + }); + + it('fires once the pointer has been held long enough', () => { + let nbOfCalls = 0; + const longPress = new LongPress(10, 20, 8, () => { + ++nbOfCalls; + }); + + expect(timeouts.length).toBe(1); + expect(timeouts[0]?.[1]).toBe(LONG_PRESS_DURATION); + expect(longPress.pending).toBe(true); + expect(longPress.fired).toBe(false); + + longPress.move(17, 13); + + expect(longPress.pending).toBe(true); + + timeouts[0]?.[0](); + + expect(nbOfCalls).toBe(1); + expect(longPress.pending).toBe(false); + expect(longPress.fired).toBe(true); + }); + + it("doesn't fire if the pointer has moved too far, along either axis", () => { + for (const [x, y] of [ + [18, 20], + [2, 20], + [10, 28], + [10, 12] + ] as const) { + const longPress = new LongPress(10, 20, 8, () => {}); + + longPress.move(x, y); + + expect(longPress.pending).toBe(false); + expect(longPress.fired).toBe(false); + expect(clearedTimeouts.at(-1)).toBe(timeouts.length); + } + }); + + it("doesn't fire once it has been cancelled", () => { + const longPress = new LongPress(10, 20, 8, () => {}); + + longPress.cancel(); + + expect(longPress.pending).toBe(false); + expect(longPress.fired).toBe(false); + expect(clearedTimeouts).toEqual([1]); + }); +}); diff --git a/src/common/touchUtils.ts b/src/common/touchUtils.ts new file mode 100644 index 0000000..9fa691f --- /dev/null +++ b/src/common/touchUtils.ts @@ -0,0 +1,109 @@ +// Some utilities for touch interaction (see the pointer interaction section of PlotWidget.vue). + +export const LONG_PRESS_DURATION = 500; // Like Android, the time (in milliseconds) after which a press is a long press. +export const DOUBLE_TAP_DELAY = 300; // Like Android, the maximum gap (in milliseconds) between two taps to double-tap. +export const TOUCH_TARGET_SIZE = 44; // Like Apple, the minimum size (in CSS pixels) of something to touch. + +export const isDirectPointer = (pointerType: string): boolean => { + // Return whether the given pointer type is that of a pointer that directly manipulates what it touches, i.e. a finger + // or a pen, which (unlike a mouse) the browser uses to scroll the page, unless touch-action says otherwise. + + return pointerType === 'touch' || pointerType === 'pen'; +}; + +export const axisEndSize = (axisLength: number, minSize: number): number => { + // Return the size of one end of an axis of the given length, i.e. 10% of that length (like Plotly), but at least the + // given minimum size (e.g., so that it can be touched), as long as the middle of that axis still takes at least half + // of it. + + return Math.min(Math.max(0.1 * axisLength, minSize), 0.25 * axisLength); +}; + +export const pinchShift = (length: number, startCenter: number, center: number, factor: number): number => { + // Return the largest distance by which a pinch moves something along an axis of the given length, i.e. once the given + // start center of that pinch has moved to the given center and everything around it has been scaled by the inverse + // of the given factor (see pinchedRange()). + // Note: that distance varies linearly along our axis, so it is largest at one of its ends. + + const shift = (position: number): number => Math.abs(center + (position - startCenter) / factor - position); + + return Math.max(shift(0), shift(length)); +}; + +export interface Tap { + /** When the tap was pressed (in milliseconds). */ + pressTime: number; + /** When the tap was released (in milliseconds). */ + releaseTime: number; + /** Where the tap was pressed (in CSS pixels). */ + x: number; + /** Where the tap was pressed (in CSS pixels). */ + y: number; +} + +export const isDoubleTap = (firstTap: Tap | undefined, secondTap: Tap): boolean => { + // Return whether the given taps make a double-tap, i.e. whether the second one was pressed at most DOUBLE_TAP_DELAY + // milliseconds after the first one was released, and less than TOUCH_TARGET_SIZE pixels away from it. + + if (!firstTap) { + return false; + } + + const delay = secondTap.pressTime - firstTap.releaseTime; + + return ( + delay >= 0 && + delay <= DOUBLE_TAP_DELAY && + Math.hypot(secondTap.x - firstTap.x, secondTap.y - firstTap.y) < TOUCH_TARGET_SIZE + ); +}; + +export class LongPress { + // A long press, i.e. a pointer that is held for LONG_PRESS_DURATION milliseconds without moving by the given + // tolerance (or more) along either axis, in which case the given callback gets called. + + private timeoutId: ReturnType | undefined; + private hasFired = false; + + constructor( + private readonly startX: number, + private readonly startY: number, + private readonly tolerance: number, + onLongPress: () => void + ) { + this.timeoutId = setTimeout(() => { + this.timeoutId = undefined; + this.hasFired = true; + + onLongPress(); + }, LONG_PRESS_DURATION); + } + + get fired(): boolean { + // Return whether our pointer has been held long enough. + + return this.hasFired; + } + + get pending(): boolean { + // Return whether our pointer may still become a long press. + + return this.timeoutId !== undefined; + } + + move(x: number, y: number): void { + // Our pointer has moved, so it can't become a long press anymore if it has moved too far from where it started. + + if (Math.max(Math.abs(x - this.startX), Math.abs(y - this.startY)) >= this.tolerance) { + this.cancel(); + } + } + + cancel(): void { + // Our pointer can't become a long press anymore (e.g., it has been released). + + clearTimeout(this.timeoutId); + + this.timeoutId = undefined; + } +} diff --git a/src/widgets/ContextMenuWidget.vue b/src/widgets/ContextMenuWidget.vue index 9c7f812..9911b3a 100644 --- a/src/widgets/ContextMenuWidget.vue +++ b/src/widgets/ContextMenuWidget.vue @@ -12,6 +12,7 @@ :class="{ 'context-menu-submenu': levelIndex > 0 }" role="menu" aria-orientation="vertical" + :aria-labelledby="headerIds(level, levelIndex)" tabindex="-1" :aria-activedescendant="level.focusedIndex >= 0 ? itemId(levelIndex, level.focusedIndex) : undefined" :style="{ left: `${level.left}px`, top: `${level.top}px` }" @@ -19,6 +20,7 @@ > +