react-cheminfo 0.127.0 → 0.129.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 +79 -43
- package/lib/drawing/core/camera.d.ts +22 -0
- package/lib/drawing/core/camera.d.ts.map +1 -1
- package/lib/drawing/core/camera.js +37 -0
- package/lib/drawing/core/camera.js.map +1 -1
- package/lib/drawing/core/graphics.d.ts.map +1 -1
- package/lib/drawing/core/graphics.js +2 -10
- package/lib/drawing/core/graphics.js.map +1 -1
- package/lib/drawing/core/groupFiles.d.ts +22 -0
- package/lib/drawing/core/groupFiles.d.ts.map +1 -0
- package/lib/drawing/core/groupFiles.js +51 -0
- package/lib/drawing/core/groupFiles.js.map +1 -0
- package/lib/drawing/core/groups.d.ts +76 -0
- package/lib/drawing/core/groups.d.ts.map +1 -0
- package/lib/drawing/core/groups.js +190 -0
- package/lib/drawing/core/groups.js.map +1 -0
- package/lib/drawing/core/index.d.ts +7 -2
- package/lib/drawing/core/index.d.ts.map +1 -1
- package/lib/drawing/core/index.js +5 -2
- package/lib/drawing/core/index.js.map +1 -1
- package/lib/drawing/core/selectionFrame.d.ts +70 -0
- package/lib/drawing/core/selectionFrame.d.ts.map +1 -0
- package/lib/drawing/core/selectionFrame.js +156 -0
- package/lib/drawing/core/selectionFrame.js.map +1 -0
- package/lib/drawing/core/transform.d.ts +30 -0
- package/lib/drawing/core/transform.d.ts.map +1 -1
- package/lib/drawing/core/transform.js +59 -0
- package/lib/drawing/core/transform.js.map +1 -1
- package/lib/drawing/ui/FrameMarks.d.ts +30 -0
- package/lib/drawing/ui/FrameMarks.d.ts.map +1 -0
- package/lib/drawing/ui/FrameMarks.js +19 -0
- package/lib/drawing/ui/FrameMarks.js.map +1 -0
- package/lib/drawing/ui/curveHandleMarks.d.ts +10 -0
- package/lib/drawing/ui/curveHandleMarks.d.ts.map +1 -1
- package/lib/drawing/ui/curveHandleMarks.js +20 -2
- package/lib/drawing/ui/curveHandleMarks.js.map +1 -1
- package/lib/drawing/ui/index.d.ts +5 -1
- package/lib/drawing/ui/index.d.ts.map +1 -1
- package/lib/drawing/ui/index.js +3 -1
- package/lib/drawing/ui/index.js.map +1 -1
- package/lib/drawing/ui/useCanvasNavigation.d.ts +35 -0
- package/lib/drawing/ui/useCanvasNavigation.d.ts.map +1 -0
- package/lib/drawing/ui/useCanvasNavigation.js +95 -0
- package/lib/drawing/ui/useCanvasNavigation.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/ir/ui/BandsPanel.d.ts +3 -3
- package/lib/ir/ui/BandsPanel.d.ts.map +1 -1
- package/lib/ir/ui/BandsPanel.js +7 -7
- package/lib/ir/ui/BandsPanel.js.map +1 -1
- package/lib/ir/ui/BandsToolbar.d.ts.map +1 -1
- package/lib/ir/ui/BandsToolbar.js +2 -4
- package/lib/ir/ui/BandsToolbar.js.map +1 -1
- package/lib/ir/ui/IrEditor.d.ts +7 -0
- package/lib/ir/ui/IrEditor.d.ts.map +1 -1
- package/lib/ir/ui/IrEditor.js.map +1 -1
- package/lib/ir/ui/IrShell.d.ts.map +1 -1
- package/lib/ir/ui/IrShell.js +3 -2
- package/lib/ir/ui/IrShell.js.map +1 -1
- package/lib/ir/ui/IrStatusBar.js +2 -2
- package/lib/ir/ui/IrStatusBar.js.map +1 -1
- package/lib/ir/ui/IrToolbar.js +2 -2
- package/lib/ir/ui/IrToolbar.js.map +1 -1
- package/lib/ir/ui/VibrationalEditor.d.ts +7 -0
- package/lib/ir/ui/VibrationalEditor.d.ts.map +1 -1
- package/lib/ir/ui/VibrationalEditor.js +2 -1
- package/lib/ir/ui/VibrationalEditor.js.map +1 -1
- package/lib/ir/ui/useIrEditor.d.ts +12 -0
- package/lib/ir/ui/useIrEditor.d.ts.map +1 -1
- package/lib/ir/ui/useIrEditor.js +10 -3
- package/lib/ir/ui/useIrEditor.js.map +1 -1
- package/lib/locales/de.json +9 -0
- package/lib/locales/en.json +9 -0
- package/lib/locales/es.json +9 -0
- package/lib/locales/fr.json +9 -0
- package/lib/locales/it.json +9 -0
- package/lib/pedagogy/ui/ExerciseActions.d.ts +10 -2
- package/lib/pedagogy/ui/ExerciseActions.d.ts.map +1 -1
- package/lib/pedagogy/ui/ExerciseActions.js +7 -5
- package/lib/pedagogy/ui/ExerciseActions.js.map +1 -1
- package/lib/share/core/exampleMark.d.ts +31 -0
- package/lib/share/core/exampleMark.d.ts.map +1 -0
- package/lib/share/core/exampleMark.js +31 -0
- package/lib/share/core/exampleMark.js.map +1 -0
- package/lib/share/core/index.d.ts +5 -0
- package/lib/share/core/index.d.ts.map +1 -1
- package/lib/share/core/index.js +3 -0
- package/lib/share/core/index.js.map +1 -1
- package/lib/share/core/linkBytes.d.ts +29 -0
- package/lib/share/core/linkBytes.d.ts.map +1 -0
- package/lib/share/core/linkBytes.js +70 -0
- package/lib/share/core/linkBytes.js.map +1 -0
- package/lib/share/core/linkValue.d.ts +34 -0
- package/lib/share/core/linkValue.d.ts.map +1 -0
- package/lib/share/core/linkValue.js +58 -0
- package/lib/share/core/linkValue.js.map +1 -0
- package/lib/share/core/opensOn.d.ts +133 -0
- package/lib/share/core/opensOn.d.ts.map +1 -0
- package/lib/share/core/opensOn.js +82 -0
- package/lib/share/core/opensOn.js.map +1 -0
- package/lib/share/core/seal.d.ts.map +1 -1
- package/lib/share/core/seal.js +3 -32
- package/lib/share/core/seal.js.map +1 -1
- package/lib/share/ui/ShareOpensOn.d.ts +32 -0
- package/lib/share/ui/ShareOpensOn.d.ts.map +1 -0
- package/lib/share/ui/ShareOpensOn.js +49 -0
- package/lib/share/ui/ShareOpensOn.js.map +1 -0
- package/lib/share/ui/index.d.ts +4 -0
- package/lib/share/ui/index.d.ts.map +1 -1
- package/lib/share/ui/index.js +2 -0
- package/lib/share/ui/index.js.map +1 -1
- package/lib/share/ui/useOpensOnShare.d.ts +65 -0
- package/lib/share/ui/useOpensOnShare.d.ts.map +1 -0
- package/lib/share/ui/useOpensOnShare.js +60 -0
- package/lib/share/ui/useOpensOnShare.js.map +1 -0
- package/package.json +1 -1
- package/src/drawing/core/camera.ts +45 -0
- package/src/drawing/core/graphics.ts +2 -12
- package/src/drawing/core/groupFiles.ts +55 -0
- package/src/drawing/core/groups.ts +221 -0
- package/src/drawing/core/index.ts +29 -1
- package/src/drawing/core/selectionFrame.ts +192 -0
- package/src/drawing/core/transform.ts +80 -0
- package/src/drawing/ui/FrameMarks.tsx +57 -0
- package/src/drawing/ui/curveHandleMarks.tsx +43 -10
- package/src/drawing/ui/index.ts +8 -1
- package/src/drawing/ui/useCanvasNavigation.ts +120 -0
- package/src/ir/ui/BandsPanel.tsx +15 -10
- package/src/ir/ui/BandsToolbar.tsx +2 -4
- package/src/ir/ui/IrEditor.tsx +7 -0
- package/src/ir/ui/IrShell.tsx +4 -2
- package/src/ir/ui/IrStatusBar.tsx +2 -2
- package/src/ir/ui/IrToolbar.tsx +2 -2
- package/src/ir/ui/VibrationalEditor.tsx +9 -0
- package/src/ir/ui/useIrEditor.ts +23 -4
- package/src/locales/de.json +9 -0
- package/src/locales/en.json +9 -0
- package/src/locales/es.json +9 -0
- package/src/locales/fr.json +9 -0
- package/src/locales/it.json +9 -0
- package/src/pedagogy/ui/ExerciseActions.tsx +22 -7
- package/src/share/core/exampleMark.ts +52 -0
- package/src/share/core/index.ts +25 -0
- package/src/share/core/linkBytes.ts +75 -0
- package/src/share/core/linkValue.ts +66 -0
- package/src/share/core/opensOn.ts +203 -0
- package/src/share/core/seal.ts +3 -36
- package/src/share/ui/ShareOpensOn.tsx +169 -0
- package/src/share/ui/index.ts +7 -0
- package/src/share/ui/useOpensOnShare.tsx +152 -0
- package/styles/chrome.css +18 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { OpensOnChoice, OpensOnLinks, ShareExample } from '../core/opensOn.ts';
|
|
3
|
+
/** Props of {@link ShareOpensOn}. */
|
|
4
|
+
export interface ShareOpensOnProps {
|
|
5
|
+
/** What the dialog can hand out for the page on screen. */
|
|
6
|
+
links: OpensOnLinks;
|
|
7
|
+
/** What the link opens on. */
|
|
8
|
+
choice: OpensOnChoice;
|
|
9
|
+
/** Called with the choice the reader makes. */
|
|
10
|
+
onChange: (choice: OpensOnChoice) => void;
|
|
11
|
+
/** The examples a link can open on, in the order they are listed. */
|
|
12
|
+
examples: readonly ShareExample[];
|
|
13
|
+
/**
|
|
14
|
+
* What the site calls what is on screen: "This circuit", "This drawing".
|
|
15
|
+
* @default the chrome's own words
|
|
16
|
+
*/
|
|
17
|
+
screenLabel?: string;
|
|
18
|
+
/**
|
|
19
|
+
* What a site adds under the choice: the style a link sets, say.
|
|
20
|
+
* @default undefined — nothing
|
|
21
|
+
*/
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The section of the Share dialog saying what the link opens on: what is on
|
|
26
|
+
* screen, when a link can carry it; any of the examples, whatever is on
|
|
27
|
+
* screen; or the page alone.
|
|
28
|
+
* @param props - See {@link ShareOpensOnProps}.
|
|
29
|
+
* @returns The section's content.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ShareOpensOn(props: ShareOpensOnProps): ReactElement;
|
|
32
|
+
//# sourceMappingURL=ShareOpensOn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShareOpensOn.d.ts","sourceRoot":"","sources":["../../../src/share/ui/ShareOpensOn.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIrD,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EAEZ,YAAY,EACb,MAAM,oBAAoB,CAAC;AAE5B,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,KAAK,EAAE,YAAY,CAAC;IACpB,8BAA8B;IAC9B,MAAM,EAAE,aAAa,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAkFnE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { H6, HTMLSelect, Radio } from '@blueprintjs/core';
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { useChromeT } from "../../i18n/ui/useT.js";
|
|
5
|
+
/**
|
|
6
|
+
* The section of the Share dialog saying what the link opens on: what is on
|
|
7
|
+
* screen, when a link can carry it; any of the examples, whatever is on
|
|
8
|
+
* screen; or the page alone.
|
|
9
|
+
* @param props - See {@link ShareOpensOnProps}.
|
|
10
|
+
* @returns The section's content.
|
|
11
|
+
*/
|
|
12
|
+
export function ShareOpensOn(props) {
|
|
13
|
+
const { links, choice, onChange, examples, screenLabel, children } = props;
|
|
14
|
+
const t = useChromeT();
|
|
15
|
+
const group = useId();
|
|
16
|
+
const select = (opensOn) => () => {
|
|
17
|
+
onChange({ ...choice, opensOn });
|
|
18
|
+
};
|
|
19
|
+
const tooLarge = links.screen === 'too-large';
|
|
20
|
+
const shown = examples.find((example) => example.id === choice.example);
|
|
21
|
+
const changed = links.changed && choice.example === links.example;
|
|
22
|
+
return (_jsxs("div", { role: "radiogroup", "aria-label": t('share.opensOn'), className: "share-opens-on", children: [_jsx(H6, { children: t('share.opensOn') }), links.screen === undefined ? null : (_jsx(Radio, { name: group, value: "screen", checked: choice.opensOn === 'screen', disabled: tooLarge, onChange: select('screen'), labelElement: _jsx(Option, { title: screenLabel ?? t('share.opensOnScreen'), note: tooLarge
|
|
23
|
+
? t('share.opensOnTooLarge')
|
|
24
|
+
: t('share.opensOnScreenNote') }) })), examples.length === 0 ? null : (_jsxs(_Fragment, { children: [_jsx(Radio, { name: group, value: "example", checked: choice.opensOn === 'example', onChange: select('example'), label: t('share.opensOnExample') }), _jsxs("div", { className: "share-opens-on__under", children: [_jsx(HTMLSelect, { fill: true, "aria-label": t('share.opensOnExampleLabel'), value: choice.example, onChange: (event) => {
|
|
25
|
+
onChange({ opensOn: 'example', example: event.target.value });
|
|
26
|
+
}, children: _jsx(ExampleOptions, { examples: examples }) }), shown?.description ? (_jsx("span", { className: "share-opens-on__note", children: shown.description })) : null, changed ? (_jsx("span", { className: "share-opens-on__note", children: t('share.opensOnChanged') })) : null] })] })), _jsx(Radio, { name: group, value: "none", checked: choice.opensOn === 'none', onChange: select('none'), labelElement: _jsx(Option, { title: t('share.opensOnNone'), note: t('share.opensOnNoneNote') }) }), children] }));
|
|
27
|
+
}
|
|
28
|
+
// The title in a span of its own, so it is what a click on the words finds.
|
|
29
|
+
function Option(props) {
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "share-opens-on__title", children: props.title }), _jsx("span", { className: "share-opens-on__note", children: props.note })] }));
|
|
31
|
+
}
|
|
32
|
+
// Listed under their groups when they have any, in the order they come.
|
|
33
|
+
function ExampleOptions(props) {
|
|
34
|
+
const groups = new Map();
|
|
35
|
+
const loose = [];
|
|
36
|
+
for (const example of props.examples) {
|
|
37
|
+
if (example.group === undefined) {
|
|
38
|
+
loose.push(example);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const group = groups.get(example.group);
|
|
42
|
+
if (group)
|
|
43
|
+
group.push(example);
|
|
44
|
+
else
|
|
45
|
+
groups.set(example.group, [example]);
|
|
46
|
+
}
|
|
47
|
+
return (_jsxs(_Fragment, { children: [loose.map((example) => (_jsx("option", { value: example.id, children: example.name }, example.id))), [...groups].map(([label, members]) => (_jsx("optgroup", { label: label, children: members.map((example) => (_jsx("option", { value: example.id, children: example.name }, example.id))) }, label)))] }));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ShareOpensOn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShareOpensOn.js","sourceRoot":"","sources":["../../../src/share/ui/ShareOpensOn.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA8BnD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3E,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;IACvB,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;IACtB,MAAM,MAAM,GAAG,CAAC,OAAsB,EAAE,EAAE,CAAC,GAAG,EAAE;QAC9C,QAAQ,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACnC,CAAC,CAAC;IACF,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC;IAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAAC;IAClE,OAAO,CACL,eACE,IAAI,EAAC,YAAY,gBACL,CAAC,CAAC,eAAe,CAAC,EAC9B,SAAS,EAAC,gBA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AO,CAAC,CAAC;;YAC1B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,CACL,8BACG,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACtB,iBAAyB,KAAK,EAAE,OAAO,CAAC,EAAE,YACvC,OAAO,CAAC,IAAI,IADF,OAAO,CAAC,EAAE,CAEd,CACV,CAAC,EACD,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CACrC,mBAAsB,KAAK,EAAE,KAAK,YAC/B,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACxB,iBAAyB,KAAK,EAAE,OAAO,CAAC,EAAE,YACvC,OAAO,CAAC,IAAI,IADF,OAAO,CAAC,EAAE,CAEd,CACV,CAAC,IALW,KAAK,CAMT,CACZ,CAAC,IACD,CACJ,CAAC;AACJ,CAAC"}
|
package/lib/share/ui/index.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export type { ShareButtonProps, ShareButtonVariant } from './ShareButton.tsx';
|
|
|
9
9
|
export { ShareButton } from './ShareButton.tsx';
|
|
10
10
|
export type { ShareDialogProps } from './ShareDialog.tsx';
|
|
11
11
|
export type { SharePartDescriptions } from './SharePartRow.tsx';
|
|
12
|
+
export type { ShareOpensOnProps } from './ShareOpensOn.tsx';
|
|
13
|
+
export { ShareOpensOn } from './ShareOpensOn.tsx';
|
|
12
14
|
export type { ShareQrCodeProps } from './ShareQrCode.tsx';
|
|
13
15
|
export { ShareQrCode } from './ShareQrCode.tsx';
|
|
14
16
|
export { ShareDialog } from './ShareDialog.tsx';
|
|
17
|
+
export type { OpensOnShareOptions, OpensOnShareProps, } from './useOpensOnShare.tsx';
|
|
18
|
+
export { useOpensOnShare } from './useOpensOnShare.tsx';
|
|
15
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/share/ui/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/share/ui/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/share/ui/index.js
CHANGED
|
@@ -3,6 +3,8 @@ export { useIsHidden } from "./hiddenParts.js";
|
|
|
3
3
|
export { PagePart } from "./PagePart.js";
|
|
4
4
|
export { SealedLinkRefused } from "./SealedLinkRefused.js";
|
|
5
5
|
export { ShareButton } from "./ShareButton.js";
|
|
6
|
+
export { ShareOpensOn } from "./ShareOpensOn.js";
|
|
6
7
|
export { ShareQrCode } from "./ShareQrCode.js";
|
|
7
8
|
export { ShareDialog } from "./ShareDialog.js";
|
|
9
|
+
export { useOpensOnShare } from "./useOpensOnShare.js";
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/share/ui/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAgB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/share/ui/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAgB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAoB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAKhD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAuB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ShareAddress, ShareExample, ShareOnScreen } from '../core/opensOn.ts';
|
|
3
|
+
/** What {@link useOpensOnShare} is told of the page. */
|
|
4
|
+
export interface OpensOnShareOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the page holding the document is the page on show. Any other page
|
|
7
|
+
* hands out its own address.
|
|
8
|
+
*/
|
|
9
|
+
active: boolean;
|
|
10
|
+
/** The examples a link can open on, in the order the folder lists them. */
|
|
11
|
+
examples: readonly ShareExample[];
|
|
12
|
+
/**
|
|
13
|
+
* What is on screen, read as the dialog opens. A promise when writing it
|
|
14
|
+
* into a link takes a moment: the dialog then opens once it is written.
|
|
15
|
+
*/
|
|
16
|
+
onScreen: () => ShareOnScreen | Promise<ShareOnScreen>;
|
|
17
|
+
/**
|
|
18
|
+
* The parameters naming what a page opens on, besides `example`, which a
|
|
19
|
+
* link replaces: the one carrying a document, say.
|
|
20
|
+
* @default [] — `example` alone
|
|
21
|
+
*/
|
|
22
|
+
openedOn?: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* The link to an example.
|
|
25
|
+
* @default `?example=<id>` on the page on screen
|
|
26
|
+
*/
|
|
27
|
+
exampleAddress?: (id: string) => ShareAddress;
|
|
28
|
+
/**
|
|
29
|
+
* The link to the page alone.
|
|
30
|
+
* @default the page on screen, with nothing added
|
|
31
|
+
*/
|
|
32
|
+
aloneAddress?: ShareAddress;
|
|
33
|
+
/**
|
|
34
|
+
* What the site calls what is on screen: "This circuit", "This drawing".
|
|
35
|
+
* @default the chrome's own words
|
|
36
|
+
*/
|
|
37
|
+
screenLabel?: string;
|
|
38
|
+
/**
|
|
39
|
+
* What a site adds under the choice: the style a link sets, say.
|
|
40
|
+
* @default undefined — nothing
|
|
41
|
+
*/
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
}
|
|
44
|
+
/** What the header's Share control is told, beyond what every page shares. */
|
|
45
|
+
export interface OpensOnShareProps {
|
|
46
|
+
/** Whether the dialog is open. */
|
|
47
|
+
open: boolean;
|
|
48
|
+
/** Called when the dialog opens or closes. */
|
|
49
|
+
onOpenChange: (open: boolean) => void;
|
|
50
|
+
/** The query string the link is built from. */
|
|
51
|
+
search: string | undefined;
|
|
52
|
+
/** The page the link opens, when it is not the page on screen. */
|
|
53
|
+
baseUrl: string | undefined;
|
|
54
|
+
/** The section saying what the link opens on. */
|
|
55
|
+
children: ReactNode;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Share dialog of a page holding a document says what the link opens on:
|
|
59
|
+
* what is on screen, any of the examples the site comes with, or the page
|
|
60
|
+
* alone. Spread it into the header's `share` prop.
|
|
61
|
+
* @param options - See {@link OpensOnShareOptions}.
|
|
62
|
+
* @returns What the header's Share control is told.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useOpensOnShare(options: OpensOnShareOptions): OpensOnShareProps;
|
|
65
|
+
//# sourceMappingURL=useOpensOnShare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpensOnShare.d.ts","sourceRoot":"","sources":["../../../src/share/ui/useOpensOnShare.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAGV,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAU5B,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB,2EAA2E;IAC3E,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAClC;;;OAGG;IACH,QAAQ,EAAE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,YAAY,CAAC;IAC9C;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,8CAA8C;IAC9C,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,+CAA+C;IAC/C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,kEAAkE;IAClE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,mBAAmB,GAC3B,iBAAiB,CAmEnB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { EXAMPLE_PARAM, defaultOpensOn, opensOnAddress, opensOnLinks, } from "../core/opensOn.js";
|
|
4
|
+
import { ShareOpensOn } from "./ShareOpensOn.js";
|
|
5
|
+
/**
|
|
6
|
+
* The Share dialog of a page holding a document says what the link opens on:
|
|
7
|
+
* what is on screen, any of the examples the site comes with, or the page
|
|
8
|
+
* alone. Spread it into the header's `share` prop.
|
|
9
|
+
* @param options - See {@link OpensOnShareOptions}.
|
|
10
|
+
* @returns What the header's Share control is told.
|
|
11
|
+
*/
|
|
12
|
+
export function useOpensOnShare(options) {
|
|
13
|
+
const { active, examples, onScreen, exampleAddress, aloneAddress, screenLabel, children, } = options;
|
|
14
|
+
const openedOn = [EXAMPLE_PARAM, ...(options.openedOn ?? [])];
|
|
15
|
+
const [shared, setShared] = useState(null);
|
|
16
|
+
const [choice, setChoice] = useState(null);
|
|
17
|
+
// A dialog closed before what is on screen was written stays closed.
|
|
18
|
+
const asked = useRef(0);
|
|
19
|
+
function onOpenChange(open) {
|
|
20
|
+
const request = ++asked.current;
|
|
21
|
+
if (!open) {
|
|
22
|
+
setShared(null);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const { search } = globalThis.location;
|
|
26
|
+
if (!active) {
|
|
27
|
+
setShared(search);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const show = (screen) => {
|
|
31
|
+
if (request !== asked.current)
|
|
32
|
+
return;
|
|
33
|
+
const links = opensOnLinks(search, openedOn, screen);
|
|
34
|
+
setChoice(defaultOpensOn(links, examples));
|
|
35
|
+
setShared(links);
|
|
36
|
+
};
|
|
37
|
+
const read = onScreen();
|
|
38
|
+
if (read instanceof Promise)
|
|
39
|
+
void read.then(show);
|
|
40
|
+
else
|
|
41
|
+
show(read);
|
|
42
|
+
}
|
|
43
|
+
const links = typeof shared === 'string' ? null : shared;
|
|
44
|
+
const address = links === null || choice === null
|
|
45
|
+
? undefined
|
|
46
|
+
: opensOnAddress(links, choice, {
|
|
47
|
+
example: exampleAddress,
|
|
48
|
+
alone: aloneAddress,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
open: shared !== null,
|
|
52
|
+
onOpenChange,
|
|
53
|
+
search: typeof shared === 'string' ? shared : address?.search,
|
|
54
|
+
baseUrl: address?.path === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: new URL(address.path, globalThis.location.href).href,
|
|
57
|
+
children: links === null || choice === null ? undefined : (_jsx(ShareOpensOn, { links: links, choice: choice, onChange: setChoice, examples: examples, screenLabel: screenLabel, children: children })),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=useOpensOnShare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpensOnShare.js","sourceRoot":"","sources":["../../../src/share/ui/useOpensOnShare.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AASzC,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAoB,CAAC;AA0DlD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,OAA4B;IAE5B,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,GAAG,OAAO,CA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,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,OAAO,GACX,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI;QAC/B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;YAC5B,OAAO,EAAE,cAAc;YACvB,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;IACT,OAAO;QACL,IAAI,EAAE,MAAM,KAAK,IAAI;QACrB,YAAY;QACZ,MAAM,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM;QAC7D,OAAO,EACL,OAAO,EAAE,IAAI,KAAK,SAAS;YACzB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI;QAC1D,QAAQ,EACN,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAC9C,KAAC,YAAY,IACX,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,YAEvB,QAAQ,GACI,CAChB;KACJ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cheminfo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.129.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
|
|
6
6
|
"author": "Luc Patiny",
|
|
@@ -135,6 +135,51 @@ export function zoomAround(
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* How much a turn of the wheel zooms: a smooth exponential of the distance it
|
|
140
|
+
* scrolls, so a trackpad's many small steps and a mouse's few large ones zoom
|
|
141
|
+
* alike. A wheel that counts in lines or in pages is turned into pixels first.
|
|
142
|
+
* @param wheel - The wheel's `deltaY` and `deltaMode`.
|
|
143
|
+
* @param wheel.deltaY - How far it scrolls down, in its unit.
|
|
144
|
+
* @param wheel.deltaMode - Its unit: 0 pixels, 1 lines, 2 pages.
|
|
145
|
+
* @param pageHeight - The height of the view, in pixels: a page's worth.
|
|
146
|
+
* @returns The factor: above 1 zooms in.
|
|
147
|
+
*/
|
|
148
|
+
export function wheelZoomFactor(
|
|
149
|
+
wheel: { deltaY: number; deltaMode: number },
|
|
150
|
+
pageHeight: number,
|
|
151
|
+
): number {
|
|
152
|
+
const { deltaY, deltaMode } = wheel;
|
|
153
|
+
const pixels =
|
|
154
|
+
deltaMode === 1
|
|
155
|
+
? deltaY * WHEEL_LINE
|
|
156
|
+
: deltaMode === 2
|
|
157
|
+
? deltaY * pageHeight
|
|
158
|
+
: deltaY;
|
|
159
|
+
return Math.exp(-pixels * WHEEL_ZOOM_RATE);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The camera dragged by the pointer: the drawing follows the pointer.
|
|
164
|
+
* @param camera - The camera.
|
|
165
|
+
* @param dx - How far the pointer went right, in screen pixels.
|
|
166
|
+
* @param dy - How far it went down, in screen pixels.
|
|
167
|
+
* @returns The camera, moved.
|
|
168
|
+
*/
|
|
169
|
+
export function pannedCamera(camera: Camera, dx: number, dy: number): Camera {
|
|
170
|
+
return {
|
|
171
|
+
...camera,
|
|
172
|
+
x: camera.x - dx / camera.zoom,
|
|
173
|
+
y: camera.y - dy / camera.zoom,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Pixels per line of a wheel that counts in lines, as Firefox's does. */
|
|
178
|
+
const WHEEL_LINE = 16;
|
|
179
|
+
|
|
180
|
+
/** How much closer each pixel the wheel scrolls up brings the view. */
|
|
181
|
+
const WHEEL_ZOOM_RATE = 0.002;
|
|
182
|
+
|
|
138
183
|
function clampZoom(zoom: number): number {
|
|
139
184
|
return Math.min(
|
|
140
185
|
ZOOM_RANGE.max * PIXELS_PER_POINT,
|
|
@@ -11,6 +11,7 @@ import { curveOutline } from './curves.ts';
|
|
|
11
11
|
import type { LineDash } from './dashes.ts';
|
|
12
12
|
import { boxCorners } from './geometry.ts';
|
|
13
13
|
import type { GraphicGradient } from './graphicGradients.ts';
|
|
14
|
+
import { mapCurve } from './transform.ts';
|
|
14
15
|
import type { Box, Point } from './types.ts';
|
|
15
16
|
import { turnAbout } from './vectors.ts';
|
|
16
17
|
|
|
@@ -201,16 +202,5 @@ export function mapPath(
|
|
|
201
202
|
graphic: DrawPathGraphic,
|
|
202
203
|
map: (point: Point) => Point,
|
|
203
204
|
): DrawPathGraphic {
|
|
204
|
-
|
|
205
|
-
...graphic,
|
|
206
|
-
points: graphic.points.map(map),
|
|
207
|
-
};
|
|
208
|
-
if (graphic.controls) {
|
|
209
|
-
moved.controls = graphic.controls.map((control) =>
|
|
210
|
-
control
|
|
211
|
-
? { before: map(control.before), after: map(control.after) }
|
|
212
|
-
: null,
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
return moved;
|
|
205
|
+
return mapCurve(graphic, map);
|
|
216
206
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups going in and out of a figure: read from a file, and renamed for a
|
|
3
|
+
* paste. See `groups.ts` for what a group is.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { DrawGroup } from './groups.ts';
|
|
7
|
+
import { isRecord } from './values.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The groups of a figure read from a file; `reconcileGroups` then drops
|
|
11
|
+
* what they name that is not there.
|
|
12
|
+
* @param value - The parsed `groups` of the file.
|
|
13
|
+
* @returns The groups, or undefined when there are none.
|
|
14
|
+
*/
|
|
15
|
+
export function parseGroups(value: unknown): DrawGroup[] | undefined {
|
|
16
|
+
if (!Array.isArray(value)) return undefined;
|
|
17
|
+
const seen = new Set<string>();
|
|
18
|
+
const groups: DrawGroup[] = [];
|
|
19
|
+
for (const item of value) {
|
|
20
|
+
if (!isRecord(item) || !Array.isArray(item.members)) continue;
|
|
21
|
+
const { id } = item;
|
|
22
|
+
if (typeof id !== 'string' || id === '' || seen.has(id)) continue;
|
|
23
|
+
seen.add(id);
|
|
24
|
+
const members = item.members.filter(
|
|
25
|
+
(member): member is string => typeof member === 'string' && member !== '',
|
|
26
|
+
);
|
|
27
|
+
groups.push({ id, members });
|
|
28
|
+
}
|
|
29
|
+
return groups.length > 0 ? groups : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The groups of pasted items, under the identifiers the items took in the
|
|
34
|
+
* figure pasted into; a member that was not pasted is left out.
|
|
35
|
+
* @param groups - The groups of what was copied.
|
|
36
|
+
* @param renamed - The new identifier of each pasted item.
|
|
37
|
+
* @param nextGroupId - Gives a free identifier for each group.
|
|
38
|
+
* @returns The groups.
|
|
39
|
+
*/
|
|
40
|
+
export function renumberGroups(
|
|
41
|
+
groups: readonly DrawGroup[] | undefined,
|
|
42
|
+
renamed: ReadonlyMap<string, string>,
|
|
43
|
+
nextGroupId: () => string,
|
|
44
|
+
): DrawGroup[] {
|
|
45
|
+
if (!groups?.length) return [];
|
|
46
|
+
const groupIds = new Map(groups.map((group) => [group.id, nextGroupId()]));
|
|
47
|
+
return groups.map((group) => {
|
|
48
|
+
const members: string[] = [];
|
|
49
|
+
for (const id of group.members) {
|
|
50
|
+
const next = groupIds.get(id) ?? renamed.get(id);
|
|
51
|
+
if (next !== undefined) members.push(next);
|
|
52
|
+
}
|
|
53
|
+
return { id: groupIds.get(group.id) as string, members };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups: items of a figure selected, moved, scaled and turned as one, the
|
|
3
|
+
* same on every canvas of the family. A group names its members by their
|
|
4
|
+
* identifiers — the site's items, or other groups, so that grouping two groups
|
|
5
|
+
* and ungrouping the result gives the two back. What a member stands for (a
|
|
6
|
+
* molecule's atoms on draw, a membrane on cell) is the site's to say; this
|
|
7
|
+
* module knows only identifiers.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** A group of items. */
|
|
11
|
+
export interface DrawGroup {
|
|
12
|
+
/** Identifier, unique in the figure. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** What it holds, two members at least: items and groups, by identifier. */
|
|
15
|
+
members: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The group each member is held in.
|
|
20
|
+
* @param groups - The groups of a figure.
|
|
21
|
+
* @returns The identifier of the group holding each member, by the member's.
|
|
22
|
+
*/
|
|
23
|
+
export function parentsOf(
|
|
24
|
+
groups: readonly DrawGroup[] | undefined,
|
|
25
|
+
): Map<string, string> {
|
|
26
|
+
const parents = new Map<string, string>();
|
|
27
|
+
for (const group of groups ?? []) {
|
|
28
|
+
for (const id of group.members) parents.set(id, group.id);
|
|
29
|
+
}
|
|
30
|
+
return parents;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The outermost things some members belong to: the outermost group of a
|
|
35
|
+
* grouped member, or the member itself.
|
|
36
|
+
* @param groups - The groups of a figure.
|
|
37
|
+
* @param members - The members, by identifier.
|
|
38
|
+
* @returns The outermost units, each once.
|
|
39
|
+
*/
|
|
40
|
+
export function outermostUnits(
|
|
41
|
+
groups: readonly DrawGroup[] | undefined,
|
|
42
|
+
members: Iterable<string>,
|
|
43
|
+
): Set<string> {
|
|
44
|
+
const parents = parentsOf(groups);
|
|
45
|
+
const units = new Set<string>();
|
|
46
|
+
for (const member of members) {
|
|
47
|
+
let top = member;
|
|
48
|
+
const seen = new Set<string>();
|
|
49
|
+
for (let parent = parents.get(top); parent; parent = parents.get(top)) {
|
|
50
|
+
if (seen.has(parent)) break;
|
|
51
|
+
seen.add(parent);
|
|
52
|
+
top = parent;
|
|
53
|
+
}
|
|
54
|
+
units.add(top);
|
|
55
|
+
}
|
|
56
|
+
return units;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The items some units stand for: a group's members in turn, at any depth,
|
|
61
|
+
* and an item itself.
|
|
62
|
+
* @param groups - The groups of a figure.
|
|
63
|
+
* @param units - Items and groups, by identifier.
|
|
64
|
+
* @returns The items, each once, groups left out.
|
|
65
|
+
*/
|
|
66
|
+
export function leafMembers(
|
|
67
|
+
groups: readonly DrawGroup[] | undefined,
|
|
68
|
+
units: Iterable<string>,
|
|
69
|
+
): string[] {
|
|
70
|
+
const byId = new Map((groups ?? []).map((group) => [group.id, group]));
|
|
71
|
+
const leaves = new Set<string>();
|
|
72
|
+
const seen = new Set<string>();
|
|
73
|
+
const visit = (ids: Iterable<string>) => {
|
|
74
|
+
for (const id of ids) {
|
|
75
|
+
const group = byId.get(id);
|
|
76
|
+
if (!group) {
|
|
77
|
+
leaves.add(id);
|
|
78
|
+
} else if (!seen.has(id)) {
|
|
79
|
+
seen.add(id);
|
|
80
|
+
visit(group.members);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
visit(units);
|
|
85
|
+
return [...leaves];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Some items grown to the whole of every group they belong to, which is what
|
|
90
|
+
* a click or a box with the selection tool picks.
|
|
91
|
+
* @param groups - The groups of a figure.
|
|
92
|
+
* @param items - The items, by identifier.
|
|
93
|
+
* @returns The items and every item grouped with them.
|
|
94
|
+
*/
|
|
95
|
+
export function expandToGroups(
|
|
96
|
+
groups: readonly DrawGroup[] | undefined,
|
|
97
|
+
items: Iterable<string>,
|
|
98
|
+
): string[] {
|
|
99
|
+
if (!groups?.length) return [...items];
|
|
100
|
+
return leafMembers(groups, outermostUnits(groups, items));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Group the outermost things some items belong to.
|
|
105
|
+
* @param groups - The groups of a figure.
|
|
106
|
+
* @param items - What to group, by identifier.
|
|
107
|
+
* @param id - The new group's identifier.
|
|
108
|
+
* @returns The groups with the new one, or undefined when the items belong
|
|
109
|
+
* to fewer than two things to group.
|
|
110
|
+
*/
|
|
111
|
+
export function withGroup(
|
|
112
|
+
groups: readonly DrawGroup[] | undefined,
|
|
113
|
+
items: Iterable<string>,
|
|
114
|
+
id: string,
|
|
115
|
+
): DrawGroup[] | undefined {
|
|
116
|
+
const units = outermostUnits(groups, items);
|
|
117
|
+
if (units.size < 2) return undefined;
|
|
118
|
+
return [...(groups ?? []), { id, members: [...units] }];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Take apart, one level, the outermost groups some items belong to: a group
|
|
123
|
+
* of groups gives its groups back.
|
|
124
|
+
* @param groups - The groups of a figure.
|
|
125
|
+
* @param items - The items, by identifier.
|
|
126
|
+
* @returns The groups left, or undefined when the items belong to none.
|
|
127
|
+
*/
|
|
128
|
+
export function withoutGroups(
|
|
129
|
+
groups: readonly DrawGroup[] | undefined,
|
|
130
|
+
items: Iterable<string>,
|
|
131
|
+
): DrawGroup[] | undefined {
|
|
132
|
+
if (!groups?.length) return undefined;
|
|
133
|
+
const ids = new Set(groups.map((group) => group.id));
|
|
134
|
+
const top = new Set(
|
|
135
|
+
[...outermostUnits(groups, items)].filter((unit) => ids.has(unit)),
|
|
136
|
+
);
|
|
137
|
+
if (top.size === 0) return undefined;
|
|
138
|
+
return groups.filter((group) => !top.has(group.id));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Groups brought in step with what a figure holds: a member gone leaves its
|
|
143
|
+
* group, a member named twice stays in the first group naming it, a group
|
|
144
|
+
* never holds itself, and a group left with one member gives it back to the
|
|
145
|
+
* group above.
|
|
146
|
+
* @param groups - The groups.
|
|
147
|
+
* @param existing - The items the figure holds, by identifier; groups need not
|
|
148
|
+
* be listed.
|
|
149
|
+
* @param rejoining - A group to put an item back in, when the site knows the
|
|
150
|
+
* item replaced one that was grouped (a molecule split in two on draw).
|
|
151
|
+
* @returns The groups, the same array when nothing changed.
|
|
152
|
+
*/
|
|
153
|
+
export function reconcileGroups(
|
|
154
|
+
groups: readonly DrawGroup[],
|
|
155
|
+
existing: ReadonlySet<string>,
|
|
156
|
+
rejoining?: ReadonlyMap<string, string>,
|
|
157
|
+
): readonly DrawGroup[] {
|
|
158
|
+
const groupIds = new Set(groups.map((group) => group.id));
|
|
159
|
+
const parents = new Map<string, string>();
|
|
160
|
+
let next: DrawGroup[] = groups.map((group) => {
|
|
161
|
+
const members: string[] = [];
|
|
162
|
+
for (const id of group.members) {
|
|
163
|
+
if (!(existing.has(id) || groupIds.has(id)) || parents.has(id)) continue;
|
|
164
|
+
if (encloses(parents, id, group.id)) continue;
|
|
165
|
+
parents.set(id, group.id);
|
|
166
|
+
members.push(id);
|
|
167
|
+
}
|
|
168
|
+
return { id: group.id, members };
|
|
169
|
+
});
|
|
170
|
+
for (const [item, groupId] of rejoining ?? []) {
|
|
171
|
+
if (parents.has(item)) continue;
|
|
172
|
+
const group = next.find((candidate) => candidate.id === groupId);
|
|
173
|
+
if (!group) continue;
|
|
174
|
+
group.members.push(item);
|
|
175
|
+
parents.set(item, groupId);
|
|
176
|
+
}
|
|
177
|
+
next = dissolveSmall(next, parents);
|
|
178
|
+
return JSON.stringify(next) === JSON.stringify(groups) ? groups : next;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Whether a member is the group itself, or a group holding it at some depth.
|
|
182
|
+
function encloses(
|
|
183
|
+
parents: ReadonlyMap<string, string>,
|
|
184
|
+
candidate: string,
|
|
185
|
+
groupId: string,
|
|
186
|
+
): boolean {
|
|
187
|
+
if (candidate === groupId) return true;
|
|
188
|
+
const seen = new Set<string>();
|
|
189
|
+
for (let at = parents.get(groupId); at;) {
|
|
190
|
+
if (at === candidate || seen.has(at)) return true;
|
|
191
|
+
seen.add(at);
|
|
192
|
+
at = parents.get(at);
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Groups left with fewer than two members dissolved: an empty one goes, and
|
|
198
|
+
// the one member of another moves up to the group above it.
|
|
199
|
+
function dissolveSmall(
|
|
200
|
+
groups: DrawGroup[],
|
|
201
|
+
parents: Map<string, string>,
|
|
202
|
+
): DrawGroup[] {
|
|
203
|
+
let current = groups;
|
|
204
|
+
for (;;) {
|
|
205
|
+
const small = current.find((group) => group.members.length < 2);
|
|
206
|
+
if (!small) return current;
|
|
207
|
+
const kept = current.filter((group) => group !== small);
|
|
208
|
+
const parent = kept.find((group) => group.id === parents.get(small.id));
|
|
209
|
+
if (parent) {
|
|
210
|
+
parent.members = parent.members.filter((id) => id !== small.id);
|
|
211
|
+
for (const id of small.members) {
|
|
212
|
+
parent.members.push(id);
|
|
213
|
+
parents.set(id, parent.id);
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
for (const id of small.members) parents.delete(id);
|
|
217
|
+
}
|
|
218
|
+
parents.delete(small.id);
|
|
219
|
+
current = kept;
|
|
220
|
+
}
|
|
221
|
+
}
|