react-cheminfo 0.49.0 → 0.51.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/README.md +23 -0
- package/bin/check-seo.mjs +27 -2
- package/lib/clipboard/core/index.d.ts +0 -1
- package/lib/clipboard/core/index.d.ts.map +1 -1
- package/lib/clipboard/core/index.js +0 -1
- package/lib/clipboard/core/index.js.map +1 -1
- package/lib/clipboard/ui/CopyButton.d.ts +6 -0
- package/lib/clipboard/ui/CopyButton.d.ts.map +1 -1
- package/lib/clipboard/ui/CopyButton.js +5 -2
- package/lib/clipboard/ui/CopyButton.js.map +1 -1
- package/lib/color/core/index.d.ts +3 -0
- package/lib/color/core/index.d.ts.map +1 -1
- package/lib/color/core/index.js +2 -0
- package/lib/color/core/index.js.map +1 -1
- package/lib/color/core/interpolate.d.ts +4 -2
- package/lib/color/core/interpolate.d.ts.map +1 -1
- package/lib/color/core/interpolate.js +34 -12
- package/lib/color/core/interpolate.js.map +1 -1
- package/lib/color/core/stops.d.ts +43 -0
- package/lib/color/core/stops.d.ts.map +1 -0
- package/lib/color/core/stops.js +66 -0
- package/lib/color/core/stops.js.map +1 -0
- package/lib/color/core/tone.d.ts +25 -0
- package/lib/color/core/tone.d.ts.map +1 -0
- package/lib/color/core/tone.js +67 -0
- package/lib/color/core/tone.js.map +1 -0
- package/lib/color/core/uniform.d.ts +36 -0
- package/lib/color/core/uniform.d.ts.map +1 -0
- package/lib/color/core/uniform.js +61 -0
- package/lib/color/core/uniform.js.map +1 -0
- package/lib/color/ui/ColorScaleEditor.d.ts +5 -6
- package/lib/color/ui/ColorScaleEditor.d.ts.map +1 -1
- package/lib/color/ui/ColorScaleEditor.js +74 -84
- package/lib/color/ui/ColorScaleEditor.js.map +1 -1
- package/lib/color/ui/ColorScaleSelect.d.ts +16 -0
- package/lib/color/ui/ColorScaleSelect.d.ts.map +1 -1
- package/lib/color/ui/ColorScaleSelect.js +69 -17
- package/lib/color/ui/ColorScaleSelect.js.map +1 -1
- package/lib/color/ui/ColorScaleTone.d.ts +17 -0
- package/lib/color/ui/ColorScaleTone.d.ts.map +1 -0
- package/lib/color/ui/ColorScaleTone.js +55 -0
- package/lib/color/ui/ColorScaleTone.js.map +1 -0
- package/lib/color/ui/ColorScaleTrack.d.ts +29 -0
- package/lib/color/ui/ColorScaleTrack.d.ts.map +1 -0
- package/lib/color/ui/ColorScaleTrack.js +143 -0
- package/lib/color/ui/ColorScaleTrack.js.map +1 -0
- package/lib/download/core/copyFigure.d.ts +14 -0
- package/lib/download/core/copyFigure.d.ts.map +1 -0
- package/lib/download/core/copyFigure.js +18 -0
- package/lib/download/core/copyFigure.js.map +1 -0
- package/lib/download/core/figureHtml.js +1 -0
- package/lib/download/core/figureHtml.js.map +1 -1
- package/lib/download/core/figureHtmlMarkup.d.ts +10 -0
- package/lib/download/core/figureHtmlMarkup.d.ts.map +1 -1
- package/lib/download/core/figureHtmlMarkup.js +7 -1
- package/lib/download/core/figureHtmlMarkup.js.map +1 -1
- package/lib/download/core/index.d.ts +2 -0
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +1 -0
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.d.ts +2 -3
- package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.js +1 -1
- package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
- package/lib/download/ui/figureDownloadHint.d.ts +1 -1
- package/lib/download/ui/figureDownloadHint.d.ts.map +1 -1
- package/lib/download/ui/figureDownloadHint.js.map +1 -1
- package/lib/download/ui/index.d.ts +0 -1
- package/lib/download/ui/index.d.ts.map +1 -1
- package/lib/download/ui/useFigureActions.d.ts +2 -11
- package/lib/download/ui/useFigureActions.d.ts.map +1 -1
- package/lib/download/ui/useFigureActions.js +4 -23
- package/lib/download/ui/useFigureActions.js.map +1 -1
- package/lib/download/ui/useFigureTask.d.ts +21 -0
- package/lib/download/ui/useFigureTask.d.ts.map +1 -0
- package/lib/download/ui/useFigureTask.js +27 -0
- package/lib/download/ui/useFigureTask.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +28 -2
- package/lib/locales/en.json +28 -2
- package/lib/locales/es.json +28 -2
- package/lib/locales/fr.json +28 -2
- package/lib/locales/it.json +28 -2
- package/lib/molecule3d/core/index.d.ts +1 -1
- package/lib/molecule3d/core/index.d.ts.map +1 -1
- package/lib/molecule3d/core/index.js +1 -1
- package/lib/molecule3d/core/index.js.map +1 -1
- package/lib/molecule3d/core/settings.d.ts +15 -0
- package/lib/molecule3d/core/settings.d.ts.map +1 -1
- package/lib/molecule3d/core/settings.js +25 -0
- package/lib/molecule3d/core/settings.js.map +1 -1
- package/lib/molecule3d/ui/Molecule3DExport.d.ts +3 -0
- package/lib/molecule3d/ui/Molecule3DExport.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DExport.js +10 -16
- package/lib/molecule3d/ui/Molecule3DExport.js.map +1 -1
- package/lib/molecule3d/ui/Molecule3DOptions.d.ts +3 -1
- package/lib/molecule3d/ui/Molecule3DOptions.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DOptions.js +22 -6
- package/lib/molecule3d/ui/Molecule3DOptions.js.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +4 -3
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molecule3d/ui/exportMoleculeImage.d.ts +9 -0
- package/lib/molecule3d/ui/exportMoleculeImage.d.ts.map +1 -1
- package/lib/molecule3d/ui/exportMoleculeImage.js +15 -0
- package/lib/molecule3d/ui/exportMoleculeImage.js.map +1 -1
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts +2 -1
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts.map +1 -1
- package/lib/molecule3d/ui/useImageExport.d.ts +7 -1
- package/lib/molecule3d/ui/useImageExport.d.ts.map +1 -1
- package/lib/molecule3d/ui/useImageExport.js +12 -3
- package/lib/molecule3d/ui/useImageExport.js.map +1 -1
- package/lib/overlay/ui/FigureBar.d.ts +41 -0
- package/lib/overlay/ui/FigureBar.d.ts.map +1 -0
- package/lib/overlay/ui/FigureBar.js +43 -0
- package/lib/overlay/ui/FigureBar.js.map +1 -0
- package/lib/overlay/ui/OverlayBar.d.ts +13 -4
- package/lib/overlay/ui/OverlayBar.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayBar.js +2 -2
- package/lib/overlay/ui/OverlayBar.js.map +1 -1
- package/lib/overlay/ui/OverlayBarStrip.d.ts +2 -1
- package/lib/overlay/ui/OverlayBarStrip.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayBarStrip.js +9 -5
- package/lib/overlay/ui/OverlayBarStrip.js.map +1 -1
- package/lib/overlay/ui/OverlayIconButton.d.ts +8 -2
- package/lib/overlay/ui/OverlayIconButton.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayIconButton.js +2 -1
- package/lib/overlay/ui/OverlayIconButton.js.map +1 -1
- package/lib/overlay/ui/index.d.ts +4 -0
- package/lib/overlay/ui/index.d.ts.map +1 -1
- package/lib/overlay/ui/index.js +2 -0
- package/lib/overlay/ui/index.js.map +1 -1
- package/lib/overlay/ui/overlayBarShape.d.ts +18 -0
- package/lib/overlay/ui/overlayBarShape.d.ts.map +1 -1
- package/lib/overlay/ui/overlayStyles.d.ts +30 -0
- package/lib/overlay/ui/overlayStyles.d.ts.map +1 -1
- package/lib/overlay/ui/overlayStyles.js +52 -0
- package/lib/overlay/ui/overlayStyles.js.map +1 -1
- package/lib/overlay/ui/useFigureBarAwake.d.ts +12 -0
- package/lib/overlay/ui/useFigureBarAwake.d.ts.map +1 -0
- package/lib/overlay/ui/useFigureBarAwake.js +51 -0
- package/lib/overlay/ui/useFigureBarAwake.js.map +1 -0
- package/lib/pages.d.ts +3 -0
- package/lib/pages.d.ts.map +1 -0
- package/lib/pages.js +2 -0
- package/lib/pages.js.map +1 -0
- package/lib/periodic/core/elements.d.ts +6 -3
- package/lib/periodic/core/elements.d.ts.map +1 -1
- package/lib/periodic/core/elements.js +9 -3
- package/lib/periodic/core/elements.js.map +1 -1
- package/lib/periodic/core/index.d.ts +2 -2
- package/lib/periodic/core/index.d.ts.map +1 -1
- package/lib/periodic/core/index.js +1 -1
- package/lib/periodic/core/index.js.map +1 -1
- package/lib/periodic/core/layout.d.ts +33 -3
- package/lib/periodic/core/layout.d.ts.map +1 -1
- package/lib/periodic/core/layout.js +14 -0
- package/lib/periodic/core/layout.js.map +1 -1
- package/lib/periodic/ui/BlockStrip.d.ts +20 -0
- package/lib/periodic/ui/BlockStrip.d.ts.map +1 -0
- package/lib/periodic/ui/BlockStrip.js +48 -0
- package/lib/periodic/ui/BlockStrip.js.map +1 -0
- package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
- package/lib/periodic/ui/ElementCell.js +9 -8
- package/lib/periodic/ui/ElementCell.js.map +1 -1
- package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
- package/lib/periodic/ui/PeriodicTable.js +3 -1
- package/lib/periodic/ui/PeriodicTable.js.map +1 -1
- package/lib/periodic/ui/PeriodicTableHelp.d.ts +33 -0
- package/lib/periodic/ui/PeriodicTableHelp.d.ts.map +1 -0
- package/lib/periodic/ui/PeriodicTableHelp.js +107 -0
- package/lib/periodic/ui/PeriodicTableHelp.js.map +1 -0
- package/lib/periodic/ui/cellStyles.d.ts +3 -2
- package/lib/periodic/ui/cellStyles.d.ts.map +1 -1
- package/lib/periodic/ui/cellStyles.js +3 -2
- package/lib/periodic/ui/cellStyles.js.map +1 -1
- package/lib/periodic/ui/index.d.ts +2 -0
- package/lib/periodic/ui/index.d.ts.map +1 -1
- package/lib/periodic/ui/index.js +1 -0
- package/lib/periodic/ui/index.js.map +1 -1
- package/lib/periodic/ui/periodicTableProps.d.ts +5 -4
- package/lib/periodic/ui/periodicTableProps.d.ts.map +1 -1
- package/lib/periodic/ui/tableLayout.d.ts +3 -1
- package/lib/periodic/ui/tableLayout.d.ts.map +1 -1
- package/lib/periodic/ui/tableLayout.js +8 -3
- package/lib/periodic/ui/tableLayout.js.map +1 -1
- package/lib/seo/core/trackingMiddleware.d.ts +27 -0
- package/lib/seo/core/trackingMiddleware.d.ts.map +1 -0
- package/lib/seo/core/trackingMiddleware.js +33 -0
- package/lib/seo/core/trackingMiddleware.js.map +1 -0
- package/lib/share/ui/ShareDialogContent.d.ts +3 -2
- package/lib/share/ui/ShareDialogContent.d.ts.map +1 -1
- package/lib/share/ui/ShareDialogContent.js +5 -6
- package/lib/share/ui/ShareDialogContent.js.map +1 -1
- package/lib/share/ui/ShareLinkBar.d.ts +8 -2
- package/lib/share/ui/ShareLinkBar.d.ts.map +1 -1
- package/lib/share/ui/ShareLinkBar.js +6 -5
- package/lib/share/ui/ShareLinkBar.js.map +1 -1
- package/lib/share/ui/SharePreview.d.ts.map +1 -1
- package/lib/share/ui/SharePreview.js +2 -2
- package/lib/share/ui/SharePreview.js.map +1 -1
- package/lib/structure/ui/StructurePicturePane.js +3 -3
- package/lib/structure/ui/StructurePicturePane.js.map +1 -1
- package/package.json +2 -1
- package/src/clipboard/core/index.ts +0 -1
- package/src/clipboard/ui/CopyButton.tsx +12 -1
- package/src/color/core/index.ts +9 -0
- package/src/color/core/interpolate.ts +51 -22
- package/src/color/core/stops.ts +98 -0
- package/src/color/core/tone.ts +79 -0
- package/src/color/core/uniform.ts +67 -0
- package/src/color/ui/ColorScaleEditor.tsx +115 -141
- package/src/color/ui/ColorScaleSelect.tsx +160 -36
- package/src/color/ui/ColorScaleTone.tsx +103 -0
- package/src/color/ui/ColorScaleTrack.tsx +239 -0
- package/src/download/core/copyFigure.ts +20 -0
- package/src/download/core/figureHtml.ts +1 -0
- package/src/download/core/figureHtmlMarkup.ts +14 -1
- package/src/download/core/index.ts +2 -0
- package/src/download/ui/FigureDownloadPanel.tsx +8 -11
- package/src/download/ui/figureDownloadHint.ts +1 -2
- package/src/download/ui/index.ts +0 -1
- package/src/download/ui/useFigureActions.ts +6 -42
- package/src/download/ui/useFigureTask.ts +46 -0
- package/src/locales/de.json +28 -2
- package/src/locales/en.json +28 -2
- package/src/locales/es.json +28 -2
- package/src/locales/fr.json +28 -2
- package/src/locales/it.json +28 -2
- package/src/molecule3d/core/index.ts +2 -0
- package/src/molecule3d/core/settings.ts +35 -0
- package/src/molecule3d/ui/Molecule3DExport.tsx +18 -17
- package/src/molecule3d/ui/Molecule3DOptions.tsx +51 -3
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +11 -3
- package/src/molecule3d/ui/exportMoleculeImage.ts +20 -0
- package/src/molecule3d/ui/moleculeViewer3DProps.ts +2 -1
- package/src/molecule3d/ui/useImageExport.ts +25 -3
- package/src/overlay/ui/FigureBar.tsx +96 -0
- package/src/overlay/ui/OverlayBar.tsx +15 -5
- package/src/overlay/ui/OverlayBarStrip.tsx +34 -22
- package/src/overlay/ui/OverlayIconButton.tsx +10 -2
- package/src/overlay/ui/index.ts +4 -0
- package/src/overlay/ui/overlayBarShape.ts +19 -0
- package/src/overlay/ui/overlayStyles.ts +61 -0
- package/src/overlay/ui/useFigureBarAwake.ts +56 -0
- package/src/pages.ts +2 -0
- package/src/periodic/core/elements.ts +8 -3
- package/src/periodic/core/index.ts +8 -1
- package/src/periodic/core/layout.ts +45 -3
- package/src/periodic/ui/BlockStrip.tsx +81 -0
- package/src/periodic/ui/ElementCell.tsx +9 -8
- package/src/periodic/ui/PeriodicTable.tsx +4 -1
- package/src/periodic/ui/PeriodicTableHelp.tsx +205 -0
- package/src/periodic/ui/cellStyles.ts +3 -2
- package/src/periodic/ui/index.ts +5 -0
- package/src/periodic/ui/periodicTableProps.ts +5 -4
- package/src/periodic/ui/tableLayout.ts +9 -3
- package/src/seo/core/trackingMiddleware.ts +48 -0
- package/src/share/ui/ShareDialogContent.tsx +9 -13
- package/src/share/ui/ShareLinkBar.tsx +16 -4
- package/src/share/ui/SharePreview.tsx +6 -2
- package/src/structure/ui/StructurePicturePane.tsx +3 -3
- package/styles/chrome.css +43 -32
- package/lib/clipboard/core/copyPng.d.ts +0 -13
- package/lib/clipboard/core/copyPng.d.ts.map +0 -1
- package/lib/clipboard/core/copyPng.js +0 -19
- package/lib/clipboard/core/copyPng.js.map +0 -1
- package/src/clipboard/core/copyPng.ts +0 -20
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ only when it drags a heavy dependency behind it.
|
|
|
35
35
|
| `react-cheminfo/core` | every framework-free helper — 140 value exports | nothing |
|
|
36
36
|
| `react-cheminfo/ui` | every React component and hook — 60 value exports | React |
|
|
37
37
|
| `react-cheminfo/vite` | the prerender plugin and the OG card | nothing; React on the card |
|
|
38
|
+
| `react-cheminfo/pages` | the Cloudflare Pages analytics middleware | nothing |
|
|
38
39
|
| `react-cheminfo/orbital` | the 3D atomic-orbital viewer | React, molstar |
|
|
39
40
|
| `react-cheminfo/molecule3d` | the 3D molecule viewer and its toolbar | React, molstar |
|
|
40
41
|
| `react-cheminfo/structure` | the structure editor and renderer | React, react-ocl, OCL |
|
|
@@ -1096,6 +1097,28 @@ disk. A server writing more into the same place composes it itself, with
|
|
|
1096
1097
|
`pageHeadTags` and `fill(page, PAGE_BODY_MARKER, noscriptIndex(…))`. All of that
|
|
1097
1098
|
is `react-cheminfo/core`, so a backend loads no React and no Vite.
|
|
1098
1099
|
|
|
1100
|
+
### On Cloudflare Pages
|
|
1101
|
+
|
|
1102
|
+
Pages serves the build as it is, so there is no server and no entrypoint to put
|
|
1103
|
+
the analytics snippet in a page. `onRequest` from `react-cheminfo/pages` adds it
|
|
1104
|
+
per request instead, from the project's `TRACKING_SCRIPT` variable, and returns
|
|
1105
|
+
everything that is not a page untouched:
|
|
1106
|
+
|
|
1107
|
+
```ts
|
|
1108
|
+
// functions/_middleware.ts
|
|
1109
|
+
export { onRequest } from 'react-cheminfo/pages';
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
It is a door of its own so the Functions bundler reads two small files and
|
|
1113
|
+
never the rest of `core`, whose JSON imports an older esbuild cannot parse.
|
|
1114
|
+
|
|
1115
|
+
Keep the bundles out of the function with a `public/_routes.json`, so a page
|
|
1116
|
+
view costs one invocation rather than one per asset:
|
|
1117
|
+
|
|
1118
|
+
```json
|
|
1119
|
+
{ "version": 1, "include": ["/*"], "exclude": ["/assets/*"] }
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1099
1122
|
## Saying which build is running
|
|
1100
1123
|
|
|
1101
1124
|
A report of something going wrong is worth answering only when we know what was
|
package/bin/check-seo.mjs
CHANGED
|
@@ -60,6 +60,7 @@ if (stats === undefined || !stats.isDirectory()) {
|
|
|
60
60
|
process.exit(usageError(TOOL, `no such build directory: ${root}`));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
const named = sitemapAddresses();
|
|
63
64
|
const pages = [];
|
|
64
65
|
collect(root, pages);
|
|
65
66
|
if (pages.length === 0) {
|
|
@@ -358,6 +359,11 @@ function exists(path) {
|
|
|
358
359
|
|
|
359
360
|
/**
|
|
360
361
|
* Add every built page under a path to the list, with the address it answers.
|
|
362
|
+
*
|
|
363
|
+
* A folder's `index.html` is always a page. Any other `.html` file is one only
|
|
364
|
+
* when the sitemap names its address, as every prerendered `<route>.html` is:
|
|
365
|
+
* a demo the build emits or a document copied from `public` is not a page of
|
|
366
|
+
* the site, and holding it to a page's head would report a correct build.
|
|
361
367
|
* @param {string} path - A directory of the build.
|
|
362
368
|
* @param {Array<{ file: string, address: string }>} pages - Collected so far.
|
|
363
369
|
*/
|
|
@@ -369,8 +375,27 @@ function collect(path, pages) {
|
|
|
369
375
|
collect(next, pages);
|
|
370
376
|
} else if (entry.name.endsWith('.html')) {
|
|
371
377
|
const page = relative(root, next).replace(/\.html$/, '');
|
|
372
|
-
const address = `/${page.replace(/(?:^|\/)index$/, '')}
|
|
373
|
-
|
|
378
|
+
const address = trimSlash(`/${page.replace(/(?:^|\/)index$/, '')}`);
|
|
379
|
+
if (entry.name === 'index.html' || named.has(address)) {
|
|
380
|
+
pages.push({ file: next, address });
|
|
381
|
+
}
|
|
374
382
|
}
|
|
375
383
|
}
|
|
376
384
|
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Read which addresses of this build the sitemap names.
|
|
388
|
+
* @returns {Set<string>} Every address of this build the sitemap names.
|
|
389
|
+
*/
|
|
390
|
+
function sitemapAddresses() {
|
|
391
|
+
const sitemap = join(root, 'sitemap.xml');
|
|
392
|
+
const addresses = new Set();
|
|
393
|
+
if (!exists(sitemap)) return addresses;
|
|
394
|
+
for (const match of readFileSync(sitemap, 'utf8').matchAll(
|
|
395
|
+
/<loc>(?<loc>[^<]+)<\/loc>/g,
|
|
396
|
+
)) {
|
|
397
|
+
const own = ownPath(match.groups?.loc ?? '');
|
|
398
|
+
if (own !== undefined) addresses.add(own === '' ? '/' : own);
|
|
399
|
+
}
|
|
400
|
+
return addresses;
|
|
401
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { writeImageToClipboard } from './copyPng.ts';
|
|
2
1
|
export type { WriteBlobToClipboardOptions } from './writeBlobToClipboard.ts';
|
|
3
2
|
export { writeBlobToClipboard } from './writeBlobToClipboard.ts';
|
|
4
3
|
export type { ClipboardContent, ClipboardText } from './writeToClipboard.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clipboard/core/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clipboard/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/clipboard/core/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/clipboard/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -61,6 +61,12 @@ export interface CopyButtonProps {
|
|
|
61
61
|
* @default undefined
|
|
62
62
|
*/
|
|
63
63
|
className?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Called once the clipboard has taken the content — never when it refused —
|
|
66
|
+
* for a dialog whose whole purpose was that copy and that closes on it.
|
|
67
|
+
* @default undefined
|
|
68
|
+
*/
|
|
69
|
+
onCopied?: () => void;
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* A button that puts a piece of text on the clipboard and says so — with a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyButton.d.ts","sourceRoot":"","sources":["../../../src/clipboard/ui/CopyButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAU,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAU1C,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OA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GAAG,YAAY,CA+C/D"}
|
|
@@ -10,7 +10,7 @@ import { DEFAULT_COPY_RESET_AFTER, useCopyToClipboard, } from "./useCopyToClipbo
|
|
|
10
10
|
* @returns The copy button.
|
|
11
11
|
*/
|
|
12
12
|
export function CopyButton(props) {
|
|
13
|
-
const { content, label, copiedLabel, failedLabel, minimal = false, small = false, icon = 'clipboard', disabled = false, resetAfter = DEFAULT_COPY_RESET_AFTER, title, className, } = props;
|
|
13
|
+
const { content, label, copiedLabel, failedLabel, minimal = false, small = false, icon = 'clipboard', disabled = false, resetAfter = DEFAULT_COPY_RESET_AFTER, title, className, onCopied, } = props;
|
|
14
14
|
const t = useChromeT();
|
|
15
15
|
const { copied, failed, copy } = useCopyToClipboard(resetAfter);
|
|
16
16
|
const hoverTitle = title ?? t('clipboard.copyToClipboard');
|
|
@@ -23,7 +23,10 @@ export function CopyButton(props) {
|
|
|
23
23
|
failedLabel: failedLabel ?? t('clipboard.failed'),
|
|
24
24
|
});
|
|
25
25
|
return (_jsx(Button, { className: joinClassNames('no-print', className), variant: minimal ? 'minimal' : 'solid', size: small ? 'small' : 'medium', icon: look.icon, intent: look.intent, text: look.text, disabled: disabled, title: hoverTitle, "aria-label": label ?? hoverTitle, onClick: () => {
|
|
26
|
-
void copy(typeof content === 'function' ? content() : content)
|
|
26
|
+
void copy(typeof content === 'function' ? content() : content).then((written) => {
|
|
27
|
+
if (written)
|
|
28
|
+
onCopied?.();
|
|
29
|
+
});
|
|
27
30
|
} }));
|
|
28
31
|
}
|
|
29
32
|
function buttonLook(input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyButton.js","sourceRoot":"","sources":["../../../src/clipboard/ui/CopyButton.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAE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@@ export type { PositionInRangeOptions } from './scale.ts';
|
|
|
11
11
|
export { positionInRange } from './scale.ts';
|
|
12
12
|
export type { ColorScaleKind, NamedColorScale } from './scales.ts';
|
|
13
13
|
export { COLOR_SCALES, COLOR_SCALE_KIND_LABELS, DEFAULT_COLOR_SCALE_ID, colorScaleById, } from './scales.ts';
|
|
14
|
+
export { UNIFORM_COLOR_SCALE_ID, UNIFORM_SWATCH, formatUniformColorScale, isUniformColorScale, uniformSwatch, } from './uniform.ts';
|
|
15
|
+
export type { ScaleTone } from './tone.ts';
|
|
16
|
+
export { scaleTone, setScaleTone } from './tone.ts';
|
|
14
17
|
export type { ResolvedColorScale } from './scaleText.ts';
|
|
15
18
|
export { MAXIMUM_CUSTOM_STOPS, formatColorScale, parseColorScale, resolveColorScale, } from './scaleText.ts';
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/color/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC9E,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACvD,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,MAAM,GACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,kBAAkB,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,CAAC;AACnE,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC"}
|
package/lib/color/core/index.js
CHANGED
|
@@ -5,5 +5,7 @@ export { hsvToRgb, rgbToHsv, wrapHue } from "./hsv.js";
|
|
|
5
5
|
export { colorAt, evenScale, sampleScale, swatchAt } from "./interpolate.js";
|
|
6
6
|
export { positionInRange } from "./scale.js";
|
|
7
7
|
export { COLOR_SCALES, COLOR_SCALE_KIND_LABELS, DEFAULT_COLOR_SCALE_ID, colorScaleById, } from "./scales.js";
|
|
8
|
+
export { UNIFORM_COLOR_SCALE_ID, UNIFORM_SWATCH, formatUniformColorScale, isUniformColorScale, uniformSwatch, } from "./uniform.js";
|
|
9
|
+
export { scaleTone, setScaleTone } from "./tone.js";
|
|
8
10
|
export { MAXIMUM_CUSTOM_STOPS, formatColorScale, parseColorScale, resolveColorScale, } from "./scaleText.js";
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/color/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAOvD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/color/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAOvD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC"}
|
|
@@ -21,8 +21,10 @@ export interface ColorStop {
|
|
|
21
21
|
* - `hsv` turns along the colour wheel the short way round, so two anchors
|
|
22
22
|
* already describe a ramp that keeps its saturation instead of fading
|
|
23
23
|
* through the grey in the middle of the straight line between them.
|
|
24
|
-
* - `hsv-long` turns the
|
|
25
|
-
*
|
|
24
|
+
* - `hsv-long` turns the whole scale one way round the wheel: the long way
|
|
25
|
+
* between its two ends, which is how two anchors draw a rainbow. Each anchor
|
|
26
|
+
* in between is reached by turning that same way, never by a turn of its own,
|
|
27
|
+
* so adding one where the scale already has its colour changes nothing.
|
|
26
28
|
*/
|
|
27
29
|
export type ColorInterpolation = 'rgb' | 'hsv' | 'hsv-long';
|
|
28
30
|
/** A colour scale: its anchors, and how it moves between them. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../../src/color/core/interpolate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../../src/color/core/interpolate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAUxD,uDAAuD;AACvD,MAAM,WAAW,MAAM;IACrB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,iEAAiE;AACjE,MAAM,WAAW,SAAS;IACxB,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC;AAE5D,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,gDAAgD;IAChD,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;IAC5B,gDAAgD;IAChD,aAAa,EAAE,kBAAkB,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,aAAa,GAAE,kBAA0B,GACxC,UAAU,CASZ;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA4BnE;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAStE"}
|
|
@@ -53,7 +53,11 @@ export function colorAt(scale, position) {
|
|
|
53
53
|
continue;
|
|
54
54
|
const span = end.position - start.position;
|
|
55
55
|
const ratio = span <= 0 ? 0 : (at - start.position) / span;
|
|
56
|
-
return mix(start.color, end.color, ratio,
|
|
56
|
+
return mix(start.color, end.color, ratio, {
|
|
57
|
+
interpolation,
|
|
58
|
+
turn: longTurn(first.color, last.color),
|
|
59
|
+
whole: stops.length === MINIMUM_SAMPLES,
|
|
60
|
+
});
|
|
57
61
|
}
|
|
58
62
|
return toHexColor(parseHexColor(last.color));
|
|
59
63
|
}
|
|
@@ -86,10 +90,10 @@ export function sampleScale(scale, count) {
|
|
|
86
90
|
}
|
|
87
91
|
return colors;
|
|
88
92
|
}
|
|
89
|
-
function mix(start, end, ratio,
|
|
93
|
+
function mix(start, end, ratio, path) {
|
|
90
94
|
const from = parseHexColor(start);
|
|
91
95
|
const to = parseHexColor(end);
|
|
92
|
-
if (interpolation === 'rgb') {
|
|
96
|
+
if (path.interpolation === 'rgb') {
|
|
93
97
|
return toHexColor({
|
|
94
98
|
red: from.red + (to.red - from.red) * ratio,
|
|
95
99
|
green: from.green + (to.green - from.green) * ratio,
|
|
@@ -98,20 +102,38 @@ function mix(start, end, ratio, interpolation) {
|
|
|
98
102
|
}
|
|
99
103
|
const one = rgbToHsv(from);
|
|
100
104
|
const other = rgbToHsv(to);
|
|
101
|
-
const
|
|
105
|
+
const [fromHue, toHue] = pairHues(one, other);
|
|
106
|
+
const hue = fromHue + hueStep(fromHue, toHue, path) * ratio;
|
|
102
107
|
return toHexColor(hsvToRgb({
|
|
103
108
|
hue: wrapHue(hue),
|
|
104
109
|
saturation: one.saturation + (other.saturation - one.saturation) * ratio,
|
|
105
110
|
value: one.value + (other.value - one.value) * ratio,
|
|
106
111
|
}));
|
|
107
112
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return
|
|
113
|
+
// A grey, black or white has no hue of its own, so it takes the other one's:
|
|
114
|
+
// the path then fades to it instead of sweeping through red on the way.
|
|
115
|
+
function pairHues(one, other) {
|
|
116
|
+
if (one.saturation === 0)
|
|
117
|
+
return [other.hue, other.hue];
|
|
118
|
+
if (other.saturation === 0)
|
|
119
|
+
return [one.hue, one.hue];
|
|
120
|
+
return [one.hue, other.hue];
|
|
121
|
+
}
|
|
122
|
+
function hueStep(from, to, path) {
|
|
123
|
+
if (path.interpolation !== 'hsv-long')
|
|
124
|
+
return shortestStep(from, to);
|
|
125
|
+
const step = path.turn > 0 ? upStep(from, to) : -upStep(to, from);
|
|
126
|
+
return step === 0 && path.whole ? path.turn * TURN : step;
|
|
127
|
+
}
|
|
128
|
+
function longTurn(first, last) {
|
|
129
|
+
const [from, to] = pairHues(rgbToHsv(parseHexColor(first)), rgbToHsv(parseHexColor(last)));
|
|
130
|
+
// Two ends of one hue are a full turn apart, taken up the wheel.
|
|
131
|
+
return shortestStep(from, to) > 0 ? -1 : 1;
|
|
132
|
+
}
|
|
133
|
+
function shortestStep(from, to) {
|
|
134
|
+
return ((((to - from) % TURN) + TURN + HALF_TURN) % TURN) - HALF_TURN;
|
|
135
|
+
}
|
|
136
|
+
function upStep(from, to) {
|
|
137
|
+
return (((to - from) % TURN) + TURN) % TURN;
|
|
116
138
|
}
|
|
117
139
|
//# sourceMappingURL=interpolate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/color/core/interpolate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/color/core/interpolate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,eAAe,GAAG,CAAC,CAAC;AAyC1B;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,MAAyB,EACzB,gBAAoC,KAAK;IAEzC,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE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AQ,CACzB,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAC9B,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAC9B,CAAC;IACF,iEAAiE;IACjE,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,EAAU;IAC5C,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;AACxE,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,EAAU;IACtC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ColorScale, ColorStop } from './interpolate.ts';
|
|
2
|
+
/** How few anchors a scale may have: one at each end of what it draws. */
|
|
3
|
+
export declare const MINIMUM_CUSTOM_STOPS = 2;
|
|
4
|
+
/** The anchors after an edit, and where the edited one now stands among them. */
|
|
5
|
+
export interface EditedStops {
|
|
6
|
+
/** The anchors, from the low end. */
|
|
7
|
+
stops: ColorStop[];
|
|
8
|
+
/** The index of the anchor that was added or moved. */
|
|
9
|
+
index: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Add an anchor where the reader clicked, in the colour the scale already has
|
|
13
|
+
* there — so adding one changes nothing until it is moved or recoloured.
|
|
14
|
+
* @param scale - The scale being edited.
|
|
15
|
+
* @param position - Where to add it, from 0 at the low end to 1 at the high end.
|
|
16
|
+
* @returns The anchors with the new one, or `null` when the scale already holds as many as a link may carry.
|
|
17
|
+
*/
|
|
18
|
+
export declare function addColorStop(scale: ColorScale, position: number): EditedStops | null;
|
|
19
|
+
/**
|
|
20
|
+
* Move an anchor. It may pass its neighbours: the anchors are kept in order,
|
|
21
|
+
* and the returned index follows the one that moved.
|
|
22
|
+
* @param stops - The anchors, from the low end.
|
|
23
|
+
* @param index - Which of them moves.
|
|
24
|
+
* @param position - Where to, clamped to the scale.
|
|
25
|
+
* @returns The anchors in their new order, and where the moved one landed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function moveColorStop(stops: readonly ColorStop[], index: number, position: number): EditedStops;
|
|
28
|
+
/**
|
|
29
|
+
* Remove an anchor, unless the scale would be left with fewer than two.
|
|
30
|
+
* @param stops - The anchors, from the low end.
|
|
31
|
+
* @param index - Which of them to remove.
|
|
32
|
+
* @returns The remaining anchors, or the same ones when none may go.
|
|
33
|
+
*/
|
|
34
|
+
export declare function removeColorStop(stops: readonly ColorStop[], index: number): ColorStop[];
|
|
35
|
+
/**
|
|
36
|
+
* Recolour an anchor.
|
|
37
|
+
* @param stops - The anchors, from the low end.
|
|
38
|
+
* @param index - Which of them to recolour.
|
|
39
|
+
* @param color - Its new colour.
|
|
40
|
+
* @returns The anchors, with that one recoloured.
|
|
41
|
+
*/
|
|
42
|
+
export declare function recolorColorStop(stops: readonly ColorStop[], index: number, color: string): ColorStop[];
|
|
43
|
+
//# sourceMappingURL=stops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stops.d.ts","sourceRoot":"","sources":["../../../src/color/core/stops.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI9D,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAKtC,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,WAAW,GAAG,IAAI,CAKpB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,WAAW,CAUb;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAGb;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAEb"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { clamp } from "../../format/core/clamp.js";
|
|
2
|
+
import { colorAt } from "./interpolate.js";
|
|
3
|
+
import { MAXIMUM_CUSTOM_STOPS } from "./scaleText.js";
|
|
4
|
+
/** How few anchors a scale may have: one at each end of what it draws. */
|
|
5
|
+
export const MINIMUM_CUSTOM_STOPS = 2;
|
|
6
|
+
// A link writes three decimals, so an anchor is held where the link puts it.
|
|
7
|
+
const POSITION_FACTOR = 1000;
|
|
8
|
+
/**
|
|
9
|
+
* Add an anchor where the reader clicked, in the colour the scale already has
|
|
10
|
+
* there — so adding one changes nothing until it is moved or recoloured.
|
|
11
|
+
* @param scale - The scale being edited.
|
|
12
|
+
* @param position - Where to add it, from 0 at the low end to 1 at the high end.
|
|
13
|
+
* @returns The anchors with the new one, or `null` when the scale already holds as many as a link may carry.
|
|
14
|
+
*/
|
|
15
|
+
export function addColorStop(scale, position) {
|
|
16
|
+
if (scale.stops.length >= MAXIMUM_CUSTOM_STOPS)
|
|
17
|
+
return null;
|
|
18
|
+
const at = roundPosition(position);
|
|
19
|
+
const added = { position: at, color: colorAt(scale, at) };
|
|
20
|
+
return sortAround([...scale.stops, added], added);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Move an anchor. It may pass its neighbours: the anchors are kept in order,
|
|
24
|
+
* and the returned index follows the one that moved.
|
|
25
|
+
* @param stops - The anchors, from the low end.
|
|
26
|
+
* @param index - Which of them moves.
|
|
27
|
+
* @param position - Where to, clamped to the scale.
|
|
28
|
+
* @returns The anchors in their new order, and where the moved one landed.
|
|
29
|
+
*/
|
|
30
|
+
export function moveColorStop(stops, index, position) {
|
|
31
|
+
const stop = stops[index];
|
|
32
|
+
if (stop === undefined || !Number.isFinite(position)) {
|
|
33
|
+
return { stops: [...stops], index };
|
|
34
|
+
}
|
|
35
|
+
const moved = { ...stop, position: roundPosition(position) };
|
|
36
|
+
return sortAround(stops.map((other, at) => (at === index ? moved : other)), moved);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Remove an anchor, unless the scale would be left with fewer than two.
|
|
40
|
+
* @param stops - The anchors, from the low end.
|
|
41
|
+
* @param index - Which of them to remove.
|
|
42
|
+
* @returns The remaining anchors, or the same ones when none may go.
|
|
43
|
+
*/
|
|
44
|
+
export function removeColorStop(stops, index) {
|
|
45
|
+
if (stops.length <= MINIMUM_CUSTOM_STOPS)
|
|
46
|
+
return [...stops];
|
|
47
|
+
return stops.filter((_, at) => at !== index);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Recolour an anchor.
|
|
51
|
+
* @param stops - The anchors, from the low end.
|
|
52
|
+
* @param index - Which of them to recolour.
|
|
53
|
+
* @param color - Its new colour.
|
|
54
|
+
* @returns The anchors, with that one recoloured.
|
|
55
|
+
*/
|
|
56
|
+
export function recolorColorStop(stops, index, color) {
|
|
57
|
+
return stops.map((stop, at) => (at === index ? { ...stop, color } : stop));
|
|
58
|
+
}
|
|
59
|
+
function roundPosition(position) {
|
|
60
|
+
return Math.round(clamp(position, 0, 1) * POSITION_FACTOR) / POSITION_FACTOR;
|
|
61
|
+
}
|
|
62
|
+
function sortAround(stops, edited) {
|
|
63
|
+
const sorted = stops.toSorted((one, other) => one.position - other.position);
|
|
64
|
+
return { stops: sorted, index: sorted.indexOf(edited) };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=stops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stops.js","sourceRoot":"","sources":["../../../src/color/core/stops.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC,6EAA6E;AAC7E,MAAM,eAAe,GAAG,IAAI,CAAC;AAU7B;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAiB,EACjB,QAAgB;IAEhB,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,oBAAoB;QAAE,OAAO,IAAI,CAAC;IAC5D,MAAM,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,KAAK,GAAc,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;IACrE,OAAO,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,KAA2B,EAC3B,KAAa,EACb,QAAgB;IAEhB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,OAAO,EAAE,KAAK,EAAE,CAAC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G,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ColorStop } from './interpolate.ts';
|
|
2
|
+
/** How strong and how bright a scale's colours are, taken over all its anchors. */
|
|
3
|
+
export interface ScaleTone {
|
|
4
|
+
/** How far the anchors are from grey, from 0 to 1. */
|
|
5
|
+
saturation: number;
|
|
6
|
+
/** How bright they are, from 0 for black to 1. */
|
|
7
|
+
value: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The saturation and the brightness of a scale's anchors, averaged: what a
|
|
11
|
+
* control setting both for the whole scale opens on.
|
|
12
|
+
* @param stops - The anchors.
|
|
13
|
+
* @returns Their mean saturation and mean value; both 0 when there is no anchor.
|
|
14
|
+
*/
|
|
15
|
+
export declare function scaleTone(stops: readonly ColorStop[]): ScaleTone;
|
|
16
|
+
/**
|
|
17
|
+
* Give every anchor the same saturation, the same brightness, or both, keeping
|
|
18
|
+
* each one's hue — so the scale then only turns round the wheel. A grey anchor
|
|
19
|
+
* has no hue of its own and takes the hue of the nearest one that has.
|
|
20
|
+
* @param stops - The anchors.
|
|
21
|
+
* @param tone - What to set; a field left out keeps each anchor's own.
|
|
22
|
+
* @returns The recoloured anchors, in the same order.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setScaleTone(stops: readonly ColorStop[], tone: Partial<ScaleTone>): ColorStop[];
|
|
25
|
+
//# sourceMappingURL=tone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tone.d.ts","sourceRoot":"","sources":["../../../src/color/core/tone.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,mFAAmF;AACnF,MAAM,WAAW,SAAS;IACxB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAahE;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GACvB,SAAS,EAAE,CAeb"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { clamp } from "../../format/core/clamp.js";
|
|
2
|
+
import { parseHexColor, toHexColor } from "./hex.js";
|
|
3
|
+
import { hsvToRgb, rgbToHsv } from "./hsv.js";
|
|
4
|
+
/**
|
|
5
|
+
* The saturation and the brightness of a scale's anchors, averaged: what a
|
|
6
|
+
* control setting both for the whole scale opens on.
|
|
7
|
+
* @param stops - The anchors.
|
|
8
|
+
* @returns Their mean saturation and mean value; both 0 when there is no anchor.
|
|
9
|
+
*/
|
|
10
|
+
export function scaleTone(stops) {
|
|
11
|
+
const colors = toHsv(stops);
|
|
12
|
+
if (colors.length === 0)
|
|
13
|
+
return { saturation: 0, value: 0 };
|
|
14
|
+
let saturation = 0;
|
|
15
|
+
let value = 0;
|
|
16
|
+
for (const color of colors) {
|
|
17
|
+
saturation += color.saturation;
|
|
18
|
+
value += color.value;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
saturation: saturation / colors.length,
|
|
22
|
+
value: value / colors.length,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Give every anchor the same saturation, the same brightness, or both, keeping
|
|
27
|
+
* each one's hue — so the scale then only turns round the wheel. A grey anchor
|
|
28
|
+
* has no hue of its own and takes the hue of the nearest one that has.
|
|
29
|
+
* @param stops - The anchors.
|
|
30
|
+
* @param tone - What to set; a field left out keeps each anchor's own.
|
|
31
|
+
* @returns The recoloured anchors, in the same order.
|
|
32
|
+
*/
|
|
33
|
+
export function setScaleTone(stops, tone) {
|
|
34
|
+
const colors = toHsv(stops);
|
|
35
|
+
const result = [];
|
|
36
|
+
for (let index = 0; index < stops.length; index++) {
|
|
37
|
+
const stop = stops[index];
|
|
38
|
+
const color = colors[index];
|
|
39
|
+
if (stop === undefined || color === undefined)
|
|
40
|
+
continue;
|
|
41
|
+
const toned = hsvToRgb({
|
|
42
|
+
hue: hueNear(colors, index),
|
|
43
|
+
saturation: clamp(tone.saturation ?? color.saturation, 0, 1),
|
|
44
|
+
value: clamp(tone.value ?? color.value, 0, 1),
|
|
45
|
+
});
|
|
46
|
+
result.push({ ...stop, color: toHexColor(toned) });
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function toHsv(stops) {
|
|
51
|
+
const colors = [];
|
|
52
|
+
for (const stop of stops)
|
|
53
|
+
colors.push(rgbToHsv(parseHexColor(stop.color)));
|
|
54
|
+
return colors;
|
|
55
|
+
}
|
|
56
|
+
function hueNear(colors, index) {
|
|
57
|
+
for (let distance = 0; distance < colors.length; distance++) {
|
|
58
|
+
const before = colors[index - distance];
|
|
59
|
+
if (before !== undefined && before.saturation > 0)
|
|
60
|
+
return before.hue;
|
|
61
|
+
const after = colors[index + distance];
|
|
62
|
+
if (after !== undefined && after.saturation > 0)
|
|
63
|
+
return after.hue;
|
|
64
|
+
}
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=tone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tone.js","sourceRoot":"","sources":["../../../src/color/core/tone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAW9C;;;;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IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;SAC9C,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,KAAK,CAAC,KAA2B;IACxC,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAC,MAA2B,EAAE,KAAa;IACzD,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC;QACxC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC;QACrE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC;IACpE,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Swatch } from './interpolate.ts';
|
|
2
|
+
/**
|
|
3
|
+
* What a colour-scale picker offering one colour writes for it, and a link
|
|
4
|
+
* carries: every value the same colour, so the figure needs no key. Followed by
|
|
5
|
+
* `-` and a hex colour, e.g. `uniform-1c6e42`, it names that colour.
|
|
6
|
+
*/
|
|
7
|
+
export declare const UNIFORM_COLOR_SCALE_ID = "uniform";
|
|
8
|
+
/**
|
|
9
|
+
* The one colour of a uniform scale that names none: the family's border grey
|
|
10
|
+
* rather than white, so a cell still stands out from a white page and from the
|
|
11
|
+
* white ground of a saved figure.
|
|
12
|
+
*/
|
|
13
|
+
export declare const UNIFORM_SWATCH: Swatch;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a scale text asks for one colour.
|
|
16
|
+
* @param text - A scale id or a custom scale, as a link carries it.
|
|
17
|
+
* @returns `true` for {@link UNIFORM_COLOR_SCALE_ID}, with or without a colour.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isUniformColorScale(text: string | undefined): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The colour a uniform scale text names, and the ink to write on it.
|
|
22
|
+
*
|
|
23
|
+
* A colour with a typo in it falls back to the grey rather than failing, so a
|
|
24
|
+
* link written by hand still opens the figure.
|
|
25
|
+
* @param text - A scale text, e.g. `uniform` or `uniform-1c6e42`.
|
|
26
|
+
* @returns The swatch it names, or {@link UNIFORM_SWATCH}.
|
|
27
|
+
*/
|
|
28
|
+
export declare function uniformSwatch(text: string | undefined): Swatch;
|
|
29
|
+
/**
|
|
30
|
+
* Write one colour as the scale text a link carries; the `#` is dropped, since
|
|
31
|
+
* a query string is cut in two at the first one.
|
|
32
|
+
* @param color - The colour, as `#rgb` or `#rrggbb`.
|
|
33
|
+
* @returns E.g. `uniform-1c6e42`, or {@link UNIFORM_COLOR_SCALE_ID} when the colour is not a hex colour.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatUniformColorScale(color: string): string;
|
|
36
|
+
//# sourceMappingURL=uniform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform.d.ts","sourceRoot":"","sources":["../../../src/color/core/uniform.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAG5B,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGrE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAI9D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK7D"}
|