react-screenshots 0.5.21 → 0.6.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.
Files changed (139) hide show
  1. package/README.md +145 -145
  2. package/dist/electron.html +1 -0
  3. package/dist/index.html +1 -0
  4. package/dist/static/css/electron.7eee95c8.css +1 -0
  5. package/dist/static/css/index.7eee95c8.css +1 -0
  6. package/dist/static/image/image.1ca17a04.jpg +0 -0
  7. package/dist/static/js/589.5602a0fa.js +12 -0
  8. package/dist/static/js/electron.1c6ab61b.js +1 -0
  9. package/dist/static/js/index.fbe72af7.js +1 -0
  10. package/dist/static/js/lib-react.6d1aa3cf.js +2 -0
  11. package/dist/static/js/lib-react.6d1aa3cf.js.LICENSE.txt +39 -0
  12. package/lib/{types → Screenshots}/ScreenshotsBackground/getBoundsByPoints.d.ts +1 -1
  13. package/lib/Screenshots/ScreenshotsBackground/getBoundsByPoints.js +21 -0
  14. package/lib/Screenshots/ScreenshotsBackground/index.d.ts +3 -0
  15. package/lib/Screenshots/ScreenshotsBackground/index.js +100 -0
  16. package/lib/{types → Screenshots}/ScreenshotsButton/index.d.ts +2 -2
  17. package/lib/Screenshots/ScreenshotsButton/index.js +31 -0
  18. package/lib/{types → Screenshots}/ScreenshotsCanvas/getBoundsByPoints.d.ts +1 -1
  19. package/lib/Screenshots/ScreenshotsCanvas/getBoundsByPoints.js +33 -0
  20. package/lib/{types → Screenshots}/ScreenshotsCanvas/getPoints.d.ts +1 -1
  21. package/lib/Screenshots/ScreenshotsCanvas/getPoints.js +57 -0
  22. package/lib/{types → Screenshots}/ScreenshotsCanvas/index.d.ts +1 -2
  23. package/lib/Screenshots/ScreenshotsCanvas/index.js +199 -0
  24. package/lib/{types → Screenshots}/ScreenshotsCanvas/isPointInDraw.d.ts +1 -1
  25. package/lib/Screenshots/ScreenshotsCanvas/isPointInDraw.js +24 -0
  26. package/lib/{types → Screenshots}/ScreenshotsColor/index.d.ts +1 -2
  27. package/lib/Screenshots/ScreenshotsColor/index.js +30 -0
  28. package/lib/{types → Screenshots}/ScreenshotsContext.d.ts +4 -3
  29. package/lib/Screenshots/ScreenshotsContext.js +32 -0
  30. package/lib/{types → Screenshots}/ScreenshotsMagnifier/index.d.ts +1 -2
  31. package/lib/Screenshots/ScreenshotsMagnifier/index.js +99 -0
  32. package/lib/{types → Screenshots}/ScreenshotsOperations/index.d.ts +1 -1
  33. package/lib/Screenshots/ScreenshotsOperations/index.js +64 -0
  34. package/lib/{types → Screenshots}/ScreenshotsOption/index.d.ts +3 -3
  35. package/lib/Screenshots/ScreenshotsOption/index.js +94 -0
  36. package/lib/{types → Screenshots}/ScreenshotsSize/index.d.ts +1 -2
  37. package/lib/Screenshots/ScreenshotsSize/index.js +31 -0
  38. package/lib/{types → Screenshots}/ScreenshotsSizeColor/index.d.ts +2 -3
  39. package/lib/Screenshots/ScreenshotsSizeColor/index.js +21 -0
  40. package/lib/Screenshots/ScreenshotsTextarea/calculateNodeSize.js +69 -0
  41. package/lib/{types → Screenshots}/ScreenshotsTextarea/index.d.ts +2 -2
  42. package/lib/Screenshots/ScreenshotsTextarea/index.js +54 -0
  43. package/lib/{types → Screenshots}/composeImage.d.ts +1 -1
  44. package/lib/Screenshots/composeImage.js +27 -0
  45. package/lib/Screenshots/exports.d.ts +4 -0
  46. package/lib/Screenshots/exports.js +2 -0
  47. package/lib/{types → Screenshots}/hooks/useBounds.d.ts +1 -1
  48. package/lib/Screenshots/hooks/useBounds.js +25 -0
  49. package/lib/Screenshots/hooks/useCall.js +12 -0
  50. package/lib/{types → Screenshots}/hooks/useCanvasContextRef.d.ts +1 -1
  51. package/lib/Screenshots/hooks/useCanvasContextRef.js +6 -0
  52. package/lib/Screenshots/hooks/useCanvasMousedown.js +15 -0
  53. package/lib/Screenshots/hooks/useCanvasMousemove.js +15 -0
  54. package/lib/Screenshots/hooks/useCanvasMouseup.js +15 -0
  55. package/lib/Screenshots/hooks/useCursor.js +25 -0
  56. package/lib/Screenshots/hooks/useDispatcher.d.ts +2 -0
  57. package/lib/Screenshots/hooks/useDispatcher.js +7 -0
  58. package/lib/{types → Screenshots}/hooks/useDrawSelect.d.ts +1 -1
  59. package/lib/Screenshots/hooks/useDrawSelect.js +15 -0
  60. package/lib/{types → Screenshots}/hooks/useEmiter.d.ts +1 -1
  61. package/lib/Screenshots/hooks/useEmiter.js +41 -0
  62. package/lib/{types → Screenshots}/hooks/useHistory.d.ts +1 -1
  63. package/lib/Screenshots/hooks/useHistory.js +122 -0
  64. package/lib/{types → Screenshots}/hooks/useLang.d.ts +1 -1
  65. package/lib/Screenshots/hooks/useLang.js +6 -0
  66. package/lib/Screenshots/hooks/useOperation.js +25 -0
  67. package/lib/Screenshots/hooks/useReset.js +28 -0
  68. package/lib/Screenshots/hooks/useStore.d.ts +2 -0
  69. package/lib/Screenshots/hooks/useStore.js +7 -0
  70. package/lib/{types → Screenshots}/index.d.ts +2 -2
  71. package/lib/Screenshots/index.js +140 -0
  72. package/lib/{types → Screenshots}/operations/Arrow/draw.d.ts +2 -2
  73. package/lib/Screenshots/operations/Arrow/draw.js +51 -0
  74. package/lib/{types → Screenshots}/operations/Arrow/index.d.ts +1 -1
  75. package/lib/Screenshots/operations/Arrow/index.js +153 -0
  76. package/lib/{types → Screenshots}/operations/Brush/draw.d.ts +2 -2
  77. package/lib/Screenshots/operations/Brush/draw.js +31 -0
  78. package/lib/{types → Screenshots}/operations/Brush/index.d.ts +2 -2
  79. package/lib/Screenshots/operations/Brush/index.js +138 -0
  80. package/lib/{types → Screenshots}/operations/Cancel/index.d.ts +1 -1
  81. package/lib/Screenshots/operations/Cancel/index.js +24 -0
  82. package/lib/{types → Screenshots}/operations/Ellipse/draw.d.ts +2 -2
  83. package/lib/Screenshots/operations/Ellipse/draw.js +81 -0
  84. package/lib/{types → Screenshots}/operations/Ellipse/index.d.ts +1 -1
  85. package/lib/Screenshots/operations/Ellipse/index.js +185 -0
  86. package/lib/{types → Screenshots}/operations/Mosaic/index.d.ts +1 -1
  87. package/lib/Screenshots/operations/Mosaic/index.js +174 -0
  88. package/lib/{types → Screenshots}/operations/Ok/index.d.ts +1 -1
  89. package/lib/Screenshots/operations/Ok/index.js +48 -0
  90. package/lib/{types → Screenshots}/operations/Rectangle/draw.d.ts +2 -2
  91. package/lib/Screenshots/operations/Rectangle/draw.js +66 -0
  92. package/lib/{types → Screenshots}/operations/Rectangle/index.d.ts +1 -1
  93. package/lib/Screenshots/operations/Rectangle/index.js +186 -0
  94. package/lib/{types → Screenshots}/operations/Redo/index.d.ts +1 -1
  95. package/lib/Screenshots/operations/Redo/index.js +21 -0
  96. package/lib/{types → Screenshots}/operations/Save/index.d.ts +1 -1
  97. package/lib/Screenshots/operations/Save/index.js +48 -0
  98. package/lib/{types → Screenshots}/operations/Text/index.d.ts +1 -1
  99. package/lib/Screenshots/operations/Text/index.js +220 -0
  100. package/lib/{types → Screenshots}/operations/Undo/index.d.ts +1 -1
  101. package/lib/Screenshots/operations/Undo/index.js +21 -0
  102. package/lib/Screenshots/operations/index.js +27 -0
  103. package/lib/{types → Screenshots}/operations/utils.d.ts +1 -1
  104. package/lib/Screenshots/operations/utils.js +23 -0
  105. package/lib/{types → Screenshots}/types.d.ts +1 -1
  106. package/lib/Screenshots/types.js +6 -0
  107. package/lib/Screenshots/useGetLoadedImage.js +22 -0
  108. package/lib/Screenshots/zh_CN.js +16 -0
  109. package/lib/electron/app.d.ts +10 -0
  110. package/lib/electron/app.js +80 -0
  111. package/lib/electron/index.d.ts +1 -0
  112. package/lib/electron/index.js +7 -0
  113. package/lib/web/app.d.ts +3 -0
  114. package/lib/web/app.js +41 -0
  115. package/lib/web/index.d.ts +1 -0
  116. package/lib/web/index.js +7 -0
  117. package/package.json +35 -41
  118. package/LICENSE +0 -21
  119. package/electron/assets/electron-ed141e06.css +0 -1
  120. package/electron/assets/index-73f470f6.js +0 -53
  121. package/electron/electron.html +0 -14
  122. package/lib/react-screenshots.cjs.js +0 -14
  123. package/lib/react-screenshots.es.js +0 -1716
  124. package/lib/style.css +0 -1
  125. package/lib/types/ScreenshotsBackground/index.d.ts +0 -4
  126. package/lib/types/exports.d.ts +0 -3
  127. package/lib/types/hooks/useDispatcher.d.ts +0 -2
  128. package/lib/types/hooks/useStore.d.ts +0 -2
  129. /package/lib/{types → Screenshots}/ScreenshotsTextarea/calculateNodeSize.d.ts +0 -0
  130. /package/lib/{types → Screenshots}/hooks/useCall.d.ts +0 -0
  131. /package/lib/{types → Screenshots}/hooks/useCanvasMousedown.d.ts +0 -0
  132. /package/lib/{types → Screenshots}/hooks/useCanvasMousemove.d.ts +0 -0
  133. /package/lib/{types → Screenshots}/hooks/useCanvasMouseup.d.ts +0 -0
  134. /package/lib/{types → Screenshots}/hooks/useCursor.d.ts +0 -0
  135. /package/lib/{types → Screenshots}/hooks/useOperation.d.ts +0 -0
  136. /package/lib/{types → Screenshots}/hooks/useReset.d.ts +0 -0
  137. /package/lib/{types → Screenshots}/operations/index.d.ts +0 -0
  138. /package/lib/{types → Screenshots}/useGetLoadedImage.d.ts +0 -0
  139. /package/lib/{types → Screenshots}/zh_CN.d.ts +0 -0
@@ -0,0 +1,94 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { cloneElement, memo, useContext, useEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { ScreenshotsOperationsCtx } from "../ScreenshotsOperations/index.js";
5
+ import "./index.css";
6
+ var ScreenshotsOption_Placement = /*#__PURE__*/ function(Placement) {
7
+ Placement["Bottom"] = "bottom";
8
+ Placement["Top"] = "top";
9
+ return Placement;
10
+ }({});
11
+ const Screenshots_ScreenshotsOption = /*#__PURE__*/ memo(function({ open, content, children }) {
12
+ const childrenRef = useRef(null);
13
+ const popoverRef = useRef(null);
14
+ const contentRef = useRef(null);
15
+ const operationsRect = useContext(ScreenshotsOperationsCtx);
16
+ const [placement, setPlacement] = useState("bottom");
17
+ const [position, setPosition] = useState(null);
18
+ const [offsetX, setOffsetX] = useState(0);
19
+ const getPopoverEl = ()=>{
20
+ if (!popoverRef.current) popoverRef.current = document.createElement('div');
21
+ return popoverRef.current;
22
+ };
23
+ useEffect(()=>{
24
+ const $el = getPopoverEl();
25
+ if (open) document.body.appendChild($el);
26
+ return ()=>{
27
+ $el.remove();
28
+ };
29
+ }, [
30
+ open
31
+ ]);
32
+ useEffect(()=>{
33
+ if (!open || !operationsRect || !childrenRef.current || !contentRef.current) return;
34
+ const childrenRect = childrenRef.current.getBoundingClientRect();
35
+ const contentRect = contentRef.current.getBoundingClientRect();
36
+ let currentPlacement = placement;
37
+ let x = childrenRect.left + childrenRect.width / 2;
38
+ let y = childrenRect.top + childrenRect.height;
39
+ let currentOffsetX = offsetX;
40
+ if (x + contentRect.width / 2 > operationsRect.x + operationsRect.width) {
41
+ const ox = x;
42
+ x = operationsRect.x + operationsRect.width - contentRect.width / 2;
43
+ currentOffsetX = ox - x;
44
+ }
45
+ if (x < operationsRect.x + contentRect.width / 2) {
46
+ const ox = x;
47
+ x = operationsRect.x + contentRect.width / 2;
48
+ currentOffsetX = ox - x;
49
+ }
50
+ if (y > window.innerHeight - contentRect.height) {
51
+ if ("bottom" === currentPlacement) currentPlacement = "top";
52
+ y = childrenRect.top - contentRect.height;
53
+ }
54
+ if (y < 0) {
55
+ if ("top" === currentPlacement) currentPlacement = "bottom";
56
+ y = childrenRect.top + childrenRect.height;
57
+ }
58
+ if (currentPlacement !== placement) setPlacement(currentPlacement);
59
+ if (position?.x !== x || position.y !== y) setPosition({
60
+ x,
61
+ y
62
+ });
63
+ if (currentOffsetX !== offsetX) setOffsetX(currentOffsetX);
64
+ });
65
+ return /*#__PURE__*/ jsxs(Fragment, {
66
+ children: [
67
+ /*#__PURE__*/ cloneElement(children, {
68
+ ref: childrenRef
69
+ }),
70
+ open && content && /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs("div", {
71
+ ref: contentRef,
72
+ className: "screenshots-option",
73
+ style: {
74
+ visibility: position ? 'visible' : 'hidden',
75
+ transform: `translate(${position?.x ?? 0}px, ${position?.y ?? 0}px)`
76
+ },
77
+ "data-placement": placement,
78
+ children: [
79
+ /*#__PURE__*/ jsx("div", {
80
+ className: "screenshots-option-container",
81
+ children: content
82
+ }),
83
+ /*#__PURE__*/ jsx("div", {
84
+ className: "screenshots-option-arrow",
85
+ style: {
86
+ marginLeft: offsetX
87
+ }
88
+ })
89
+ ]
90
+ }), getPopoverEl())
91
+ ]
92
+ });
93
+ });
94
+ export { ScreenshotsOption_Placement as Placement, Screenshots_ScreenshotsOption as default };
@@ -1,8 +1,7 @@
1
- import React from 'react';
2
1
  import './index.less';
3
2
  export interface SizeProps {
4
3
  value: number;
5
4
  onChange: (value: number) => void;
6
5
  }
7
- declare const _default: React.NamedExoticComponent<SizeProps>;
6
+ declare const _default: import("react").NamedExoticComponent<SizeProps>;
8
7
  export default _default;
@@ -0,0 +1,31 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { memo } from "react";
3
+ import "./index.css";
4
+ const Screenshots_ScreenshotsSize = /*#__PURE__*/ memo(function({ value, onChange }) {
5
+ const sizes = [
6
+ 3,
7
+ 6,
8
+ 9
9
+ ];
10
+ return /*#__PURE__*/ jsx("div", {
11
+ className: "screenshots-size",
12
+ children: sizes.map((size)=>{
13
+ const classNames = [
14
+ 'screenshots-size-item'
15
+ ];
16
+ if (size === value) classNames.push('screenshots-size-active');
17
+ return /*#__PURE__*/ jsx("div", {
18
+ className: classNames.join(' '),
19
+ onClick: ()=>onChange && onChange(size),
20
+ children: /*#__PURE__*/ jsx("div", {
21
+ className: "screenshots-size-pointer",
22
+ style: {
23
+ width: 1.8 * size,
24
+ height: 1.8 * size
25
+ }
26
+ })
27
+ }, size);
28
+ })
29
+ });
30
+ });
31
+ export { Screenshots_ScreenshotsSize as default };
@@ -1,10 +1,9 @@
1
- import React from 'react';
2
- import './index.less';
1
+ import "./index.less";
3
2
  export interface SizeColorProps {
4
3
  size: number;
5
4
  color: string;
6
5
  onSizeChange: (value: number) => void;
7
6
  onColorChange: (value: string) => void;
8
7
  }
9
- declare const _default: React.NamedExoticComponent<SizeColorProps>;
8
+ declare const _default: import("react").NamedExoticComponent<SizeColorProps>;
10
9
  export default _default;
@@ -0,0 +1,21 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { memo } from "react";
3
+ import ScreenshotsSize from "../ScreenshotsSize/index.js";
4
+ import ScreenshotsColor from "../ScreenshotsColor/index.js";
5
+ import "./index.css";
6
+ const Screenshots_ScreenshotsSizeColor = /*#__PURE__*/ memo(function({ size, color, onSizeChange, onColorChange }) {
7
+ return /*#__PURE__*/ jsxs("div", {
8
+ className: "screenshots-sizecolor",
9
+ children: [
10
+ /*#__PURE__*/ jsx(ScreenshotsSize, {
11
+ value: size,
12
+ onChange: onSizeChange
13
+ }),
14
+ /*#__PURE__*/ jsx(ScreenshotsColor, {
15
+ value: color,
16
+ onChange: onColorChange
17
+ })
18
+ ]
19
+ });
20
+ });
21
+ export { Screenshots_ScreenshotsSizeColor as default };
@@ -0,0 +1,69 @@
1
+ const hiddenTextareaStyle = `
2
+ min-width: 0 !important;
3
+ width: 0 !important;
4
+ min-height: 0 !important;
5
+ height:0 !important;
6
+ visibility: hidden !important;
7
+ overflow: hidden !important;
8
+ position: absolute !important;
9
+ z-index: -1000 !important;
10
+ top:0 !important;
11
+ right:0 !important;
12
+ `;
13
+ const sizeStyle = [
14
+ 'letter-spacing',
15
+ 'line-height',
16
+ 'padding-top',
17
+ 'padding-bottom',
18
+ 'font-family',
19
+ 'font-weight',
20
+ 'font-size',
21
+ 'font-variant',
22
+ 'text-rendering',
23
+ 'text-transform',
24
+ 'text-indent',
25
+ 'padding-left',
26
+ 'padding-right',
27
+ 'border-width',
28
+ 'box-sizing',
29
+ 'white-space',
30
+ 'word-break'
31
+ ];
32
+ let hiddenTextarea;
33
+ function getComputedSizeInfo(node) {
34
+ const style = window.getComputedStyle(node);
35
+ const boxSizing = style.getPropertyValue('box-sizing') || style.getPropertyValue('-moz-box-sizing') || style.getPropertyValue('-webkit-box-sizing');
36
+ const paddingSize = parseFloat(style.getPropertyValue('padding-bottom')) + parseFloat(style.getPropertyValue('padding-top'));
37
+ const borderSize = parseFloat(style.getPropertyValue('border-bottom-width')) + parseFloat(style.getPropertyValue('border-top-width'));
38
+ const sizingStyle = sizeStyle.map((name)=>`${name}:${style.getPropertyValue(name)}`).join(';');
39
+ return {
40
+ sizingStyle,
41
+ paddingSize,
42
+ borderSize,
43
+ boxSizing
44
+ };
45
+ }
46
+ function calculateNodeSize(textarea, value, maxWidth, maxHeight) {
47
+ if (!hiddenTextarea) {
48
+ hiddenTextarea = document.createElement('textarea');
49
+ hiddenTextarea.setAttribute('tab-index', '-1');
50
+ document.body.appendChild(hiddenTextarea);
51
+ }
52
+ const { paddingSize, borderSize, boxSizing, sizingStyle } = getComputedSizeInfo(textarea);
53
+ hiddenTextarea.setAttribute('style', `${sizingStyle};${hiddenTextareaStyle};max-width:${maxWidth}px;max-height:${maxHeight}px`);
54
+ hiddenTextarea.value = value || ' ';
55
+ let width = hiddenTextarea.scrollWidth;
56
+ let height = hiddenTextarea.scrollHeight;
57
+ if ('border-box' === boxSizing) {
58
+ width += borderSize;
59
+ height += borderSize;
60
+ } else if ('content-box' === boxSizing) {
61
+ width -= paddingSize;
62
+ height -= paddingSize;
63
+ }
64
+ return {
65
+ width: Math.min(width, maxWidth),
66
+ height: Math.min(height, maxHeight)
67
+ };
68
+ }
69
+ export { calculateNodeSize as default, getComputedSizeInfo };
@@ -1,4 +1,4 @@
1
- import React, { FocusEvent } from 'react';
1
+ import type { FocusEvent } from 'react';
2
2
  import './index.less';
3
3
  export interface TextInputProps {
4
4
  x: number;
@@ -11,5 +11,5 @@ export interface TextInputProps {
11
11
  onChange: (value: string) => unknown;
12
12
  onBlur: (e: FocusEvent<HTMLTextAreaElement>) => unknown;
13
13
  }
14
- declare const _default: React.NamedExoticComponent<TextInputProps>;
14
+ declare const _default: import("react").NamedExoticComponent<TextInputProps>;
15
15
  export default _default;
@@ -0,0 +1,54 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { memo, useLayoutEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import calculateNodeSize from "./calculateNodeSize.js";
5
+ import "./index.css";
6
+ const Screenshots_ScreenshotsTextarea = /*#__PURE__*/ memo(function({ x, y, maxWidth, maxHeight, size, color, value, onChange, onBlur }) {
7
+ const popoverRef = useRef(null);
8
+ const textareaRef = useRef(null);
9
+ const [width, setWidth] = useState(0);
10
+ const [height, setHeight] = useState(0);
11
+ const getPopoverEl = ()=>{
12
+ if (!popoverRef.current) popoverRef.current = document.createElement('div');
13
+ return popoverRef.current;
14
+ };
15
+ useLayoutEffect(()=>{
16
+ if (popoverRef.current) {
17
+ document.body.appendChild(popoverRef.current);
18
+ requestAnimationFrame(()=>{
19
+ textareaRef.current?.focus();
20
+ });
21
+ }
22
+ return ()=>{
23
+ popoverRef.current?.remove();
24
+ };
25
+ }, []);
26
+ useLayoutEffect(()=>{
27
+ if (!textareaRef.current) return;
28
+ const { width, height } = calculateNodeSize(textareaRef.current, value, maxWidth, maxHeight);
29
+ setWidth(width);
30
+ setHeight(height);
31
+ }, [
32
+ value,
33
+ maxWidth,
34
+ maxHeight
35
+ ]);
36
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("textarea", {
37
+ ref: textareaRef,
38
+ className: "screenshots-textarea",
39
+ style: {
40
+ color,
41
+ width,
42
+ height,
43
+ maxWidth,
44
+ maxHeight,
45
+ fontSize: size,
46
+ lineHeight: `${size}px`,
47
+ transform: `translate(${x}px, ${y}px)`
48
+ },
49
+ value: value,
50
+ onChange: (e)=>onChange && onChange(e.target.value),
51
+ onBlur: (e)=>onBlur && onBlur(e)
52
+ }), getPopoverEl());
53
+ });
54
+ export { Screenshots_ScreenshotsTextarea as default };
@@ -1,4 +1,4 @@
1
- import { Bounds, History } from './types';
1
+ import type { Bounds, History } from './types';
2
2
  interface ComposeImageOpts {
3
3
  image: HTMLImageElement;
4
4
  width: number;
@@ -0,0 +1,27 @@
1
+ import { HistoryItemType } from "./types.js";
2
+ function composeImage({ image, width, height, history, bounds }) {
3
+ return new Promise((resolve, reject)=>{
4
+ const $canvas = document.createElement('canvas');
5
+ const targetWidth = bounds.width * window.devicePixelRatio;
6
+ const targetHeight = bounds.height * window.devicePixelRatio;
7
+ $canvas.width = targetWidth;
8
+ $canvas.height = targetHeight;
9
+ const ctx = $canvas.getContext('2d');
10
+ if (!ctx) return reject(new Error('convert image to blob fail'));
11
+ const rx = image.naturalWidth / width;
12
+ const ry = image.naturalHeight / height;
13
+ ctx.imageSmoothingEnabled = true;
14
+ ctx.imageSmoothingQuality = 'low';
15
+ ctx.setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0);
16
+ ctx.clearRect(0, 0, bounds.width, bounds.height);
17
+ ctx.drawImage(image, bounds.x * rx, bounds.y * ry, bounds.width * rx, bounds.height * ry, 0, 0, bounds.width, bounds.height);
18
+ history.stack.slice(0, history.index + 1).forEach((item)=>{
19
+ if (item.type === HistoryItemType.Source) item.draw(ctx, item);
20
+ });
21
+ $canvas.toBlob((blob)=>{
22
+ if (!blob) return reject(new Error('canvas toBlob fail'));
23
+ resolve(blob);
24
+ }, 'image/png');
25
+ });
26
+ }
27
+ export { composeImage as default };
@@ -0,0 +1,4 @@
1
+ export type { Bounds } from './types';
2
+ export type { Lang } from './zh_CN';
3
+ export { default } from './';
4
+ export type { ScreenshotsProps } from './';
@@ -0,0 +1,2 @@
1
+ import index from "./index.js";
2
+ export { index as default };
@@ -1,4 +1,4 @@
1
- import { Bounds } from '../types';
1
+ import type { Bounds } from '../types';
2
2
  export interface BoundsDispatcher {
3
3
  set: (bounds: Bounds) => void;
4
4
  reset: () => void;
@@ -0,0 +1,25 @@
1
+ import { useCallback } from "react";
2
+ import useDispatcher from "./useDispatcher.js";
3
+ import useStore from "./useStore.js";
4
+ function useBounds() {
5
+ const { bounds } = useStore();
6
+ const { setBounds } = useDispatcher();
7
+ const set = useCallback((bounds)=>{
8
+ setBounds?.(bounds);
9
+ }, [
10
+ setBounds
11
+ ]);
12
+ const reset = useCallback(()=>{
13
+ setBounds?.(null);
14
+ }, [
15
+ setBounds
16
+ ]);
17
+ return [
18
+ bounds,
19
+ {
20
+ set,
21
+ reset
22
+ }
23
+ ];
24
+ }
25
+ export { useBounds as default };
@@ -0,0 +1,12 @@
1
+ import { useCallback } from "react";
2
+ import useDispatcher from "./useDispatcher.js";
3
+ function useCall() {
4
+ const dispatcher = useDispatcher();
5
+ const call = useCallback((funcName, ...args)=>{
6
+ dispatcher.call?.(funcName, ...args);
7
+ }, [
8
+ dispatcher
9
+ ]);
10
+ return call;
11
+ }
12
+ export { useCall as default };
@@ -1,2 +1,2 @@
1
- import { CanvasContextRef } from '../types';
1
+ import type { CanvasContextRef } from '../types';
2
2
  export default function useCanvasContextRef(): CanvasContextRef;
@@ -0,0 +1,6 @@
1
+ import useStore from "./useStore.js";
2
+ function useCanvasContextRef() {
3
+ const { canvasContextRef } = useStore();
4
+ return canvasContextRef;
5
+ }
6
+ export { useCanvasContextRef as default };
@@ -0,0 +1,15 @@
1
+ import { useEffect } from "react";
2
+ import useEmiter from "./useEmiter.js";
3
+ function useCanvasMousedown(onMousedown) {
4
+ const emiter = useEmiter();
5
+ useEffect(()=>{
6
+ emiter.on('mousedown', onMousedown);
7
+ return ()=>{
8
+ emiter.off('mousedown', onMousedown);
9
+ };
10
+ }, [
11
+ onMousedown,
12
+ emiter
13
+ ]);
14
+ }
15
+ export { useCanvasMousedown as default };
@@ -0,0 +1,15 @@
1
+ import { useEffect } from "react";
2
+ import useEmiter from "./useEmiter.js";
3
+ function useCanvasMousemove(onMousemove) {
4
+ const emiter = useEmiter();
5
+ useEffect(()=>{
6
+ emiter.on('mousemove', onMousemove);
7
+ return ()=>{
8
+ emiter.off('mousemove', onMousemove);
9
+ };
10
+ }, [
11
+ onMousemove,
12
+ emiter
13
+ ]);
14
+ }
15
+ export { useCanvasMousemove as default };
@@ -0,0 +1,15 @@
1
+ import { useEffect } from "react";
2
+ import useEmiter from "./useEmiter.js";
3
+ function useCanvasMouseup(onMouseup) {
4
+ const emiter = useEmiter();
5
+ useEffect(()=>{
6
+ emiter.on('mouseup', onMouseup);
7
+ return ()=>{
8
+ emiter.off('mouseup', onMouseup);
9
+ };
10
+ }, [
11
+ onMouseup,
12
+ emiter
13
+ ]);
14
+ }
15
+ export { useCanvasMouseup as default };
@@ -0,0 +1,25 @@
1
+ import { useCallback } from "react";
2
+ import useDispatcher from "./useDispatcher.js";
3
+ import useStore from "./useStore.js";
4
+ function useCursor() {
5
+ const { cursor } = useStore();
6
+ const { setCursor } = useDispatcher();
7
+ const set = useCallback((cursor)=>{
8
+ setCursor?.(cursor);
9
+ }, [
10
+ setCursor
11
+ ]);
12
+ const reset = useCallback(()=>{
13
+ setCursor?.('move');
14
+ }, [
15
+ setCursor
16
+ ]);
17
+ return [
18
+ cursor,
19
+ {
20
+ set,
21
+ reset
22
+ }
23
+ ];
24
+ }
25
+ export { useCursor as default };
@@ -0,0 +1,2 @@
1
+ import type { ScreenshotsContextDispatcher } from '../ScreenshotsContext';
2
+ export default function useDispatcher(): ScreenshotsContextDispatcher;
@@ -0,0 +1,7 @@
1
+ import { useContext } from "react";
2
+ import ScreenshotsContext from "../ScreenshotsContext.js";
3
+ function useDispatcher() {
4
+ const { dispatcher } = useContext(ScreenshotsContext);
5
+ return dispatcher;
6
+ }
7
+ export { useDispatcher as default };
@@ -1,2 +1,2 @@
1
- import { HistoryItemSource } from '../types';
1
+ import type { HistoryItemSource } from '../types';
2
2
  export default function useDrawSelect(onDrawSelect: (action: HistoryItemSource<unknown, unknown>, e: MouseEvent) => unknown): void;
@@ -0,0 +1,15 @@
1
+ import { useEffect } from "react";
2
+ import useEmiter from "./useEmiter.js";
3
+ function useDrawSelect(onDrawSelect) {
4
+ const emiter = useEmiter();
5
+ useEffect(()=>{
6
+ emiter.on('drawselect', onDrawSelect);
7
+ return ()=>{
8
+ emiter.off('drawselect', onDrawSelect);
9
+ };
10
+ }, [
11
+ onDrawSelect,
12
+ emiter
13
+ ]);
14
+ }
15
+ export { useDrawSelect as default };
@@ -1,4 +1,4 @@
1
- import { EmiterListener } from '../types';
1
+ import type { EmiterListener } from '../types';
2
2
  export interface EmiterDispatcher {
3
3
  on: (event: string, listener: EmiterListener) => void;
4
4
  off: (event: string, listener: EmiterListener) => void;
@@ -0,0 +1,41 @@
1
+ import { useCallback } from "react";
2
+ import useStore from "./useStore.js";
3
+ function useEmiter() {
4
+ const { emiterRef } = useStore();
5
+ const on = useCallback((event, listener)=>{
6
+ const emiter = emiterRef.current;
7
+ if (Array.isArray(emiter[event])) emiter[event].push(listener);
8
+ else emiter[event] = [
9
+ listener
10
+ ];
11
+ }, [
12
+ emiterRef
13
+ ]);
14
+ const off = useCallback((event, listener)=>{
15
+ const emiter = emiterRef.current;
16
+ if (Array.isArray(emiter[event])) {
17
+ const index = emiter[event].findIndex((item)=>item === listener);
18
+ if (-1 !== index) emiter[event].splice(index, 1);
19
+ }
20
+ }, [
21
+ emiterRef
22
+ ]);
23
+ const emit = useCallback((event, ...args)=>{
24
+ const emiter = emiterRef.current;
25
+ if (Array.isArray(emiter[event])) emiter[event].forEach((listener)=>listener(...args));
26
+ }, [
27
+ emiterRef
28
+ ]);
29
+ const reset = useCallback(()=>{
30
+ emiterRef.current = {};
31
+ }, [
32
+ emiterRef
33
+ ]);
34
+ return {
35
+ on,
36
+ off,
37
+ emit,
38
+ reset
39
+ };
40
+ }
41
+ export { useEmiter as default };
@@ -1,4 +1,4 @@
1
- import { History, HistoryItem } from '../types';
1
+ import type { History, HistoryItem } from '../types';
2
2
  export interface HistoryValue extends History {
3
3
  top?: HistoryItem<unknown, unknown>;
4
4
  }