ywana-core8 0.0.789 → 0.0.791

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.
@@ -2915,10 +2915,161 @@ var ResetPasswordBox = function ResetPasswordBox(_ref) {
2915
2915
  })));
2916
2916
  };
2917
2917
 
2918
+ var SCROLL_SENSITIVITY = 0.0005;
2919
+ var MAX_ZOOM = 5;
2920
+ var MIN_ZOOM = 0.1;
2921
+ var ImageViewer = function ImageViewer(_ref) {
2922
+ var image = _ref.image;
2923
+
2924
+ var _useState = useState({
2925
+ x: 0,
2926
+ y: 0
2927
+ }),
2928
+ offset = _useState[0],
2929
+ setOffset = _useState[1];
2930
+
2931
+ var _useState2 = useState(1),
2932
+ zoom = _useState2[0],
2933
+ setZoom = _useState2[1];
2934
+
2935
+ var _useState3 = useState(false),
2936
+ draggind = _useState3[0],
2937
+ setDragging = _useState3[1];
2938
+
2939
+ var touch = useRef({
2940
+ x: 0,
2941
+ y: 0
2942
+ });
2943
+ var canvasRef = useRef(null);
2944
+ var containerRef = useRef(null);
2945
+ var observer = useRef(null);
2946
+ var background = useMemo(function () {
2947
+ return new Image();
2948
+ }, [image]);
2949
+
2950
+ var clamp = function clamp(num, min, max) {
2951
+ return Math.min(Math.max(num, min), max);
2952
+ };
2953
+
2954
+ var handleWheel = function handleWheel(event) {
2955
+ var deltaY = event.deltaY;
2956
+
2957
+ if (!draggind) {
2958
+ setZoom(function (zoom) {
2959
+ return clamp(zoom + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM);
2960
+ });
2961
+ }
2962
+ };
2963
+
2964
+ var handleMouseMove = function handleMouseMove(event) {
2965
+ if (draggind) {
2966
+ var _touch$current = touch.current,
2967
+ x = _touch$current.x,
2968
+ y = _touch$current.y;
2969
+ var clientX = event.clientX,
2970
+ clientY = event.clientY;
2971
+ setOffset({
2972
+ x: offset.x + (x - clientX),
2973
+ y: offset.y + (y - clientY)
2974
+ });
2975
+ touch.current = {
2976
+ x: clientX,
2977
+ y: clientY
2978
+ };
2979
+ }
2980
+ };
2981
+
2982
+ var handleMouseDown = function handleMouseDown(event) {
2983
+ var clientX = event.clientX,
2984
+ clientY = event.clientY;
2985
+ touch.current = {
2986
+ x: clientX,
2987
+ y: clientY
2988
+ };
2989
+ setDragging(true);
2990
+ };
2991
+
2992
+ var handleMouseUp = function handleMouseUp() {
2993
+ return setDragging(false);
2994
+ };
2995
+
2996
+ var draw = function draw() {
2997
+ if (canvasRef.current) {
2998
+ var _canvasRef$current = canvasRef.current,
2999
+ width = _canvasRef$current.width,
3000
+ height = _canvasRef$current.height;
3001
+ var context = canvasRef.current.getContext("2d"); // Set canvas dimensions
3002
+
3003
+ canvasRef.current.width = width;
3004
+ canvasRef.current.height = height; // Clear canvas and scale it
3005
+
3006
+ context.translate(-offset.x, -offset.y);
3007
+ context.scale(zoom, zoom);
3008
+ context.clearRect(0, 0, width, height); // Make sure we're zooming to the center
3009
+
3010
+ var x = (context.canvas.width / zoom - background.width) / 2;
3011
+ var y = (context.canvas.height / zoom - background.height) / 2; // Draw image
3012
+
3013
+ context.drawImage(background, x, y);
3014
+ }
3015
+ };
3016
+
3017
+ useEffect(function () {
3018
+ observer.current = new ResizeObserver(function (entries) {
3019
+ entries.forEach(function (_ref2) {
3020
+ var target = _ref2.target;
3021
+ var width = background.width,
3022
+ height = background.height; // If width of the container is smaller than image, scale image down
3023
+
3024
+ if (target.clientWidth < width) {
3025
+ // Calculate scale
3026
+ var scale = target.clientWidth / width; // Redraw image
3027
+
3028
+ canvasRef.current.width = width * scale;
3029
+ canvasRef.current.height = height * scale;
3030
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0, width * scale, height * scale);
3031
+ }
3032
+ });
3033
+ });
3034
+ observer.current.observe(containerRef.current);
3035
+ return function () {
3036
+ return observer.current.unobserve(containerRef.current);
3037
+ };
3038
+ }, []);
3039
+ useEffect(function () {
3040
+ background.src = image;
3041
+
3042
+ if (canvasRef.current) {
3043
+ background.onload = function () {
3044
+ // Get the image dimensions
3045
+ var width = background.width,
3046
+ height = background.height;
3047
+ canvasRef.current.width = width;
3048
+ canvasRef.current.height = height; // Set image as background
3049
+
3050
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0);
3051
+ };
3052
+ }
3053
+ }, [background]);
3054
+ useEffect(function () {
3055
+ draw();
3056
+ }, [zoom, offset]);
3057
+ return /*#__PURE__*/React.createElement("div", {
3058
+ ref: containerRef
3059
+ }, /*#__PURE__*/React.createElement("canvas", {
3060
+ onMouseDown: handleMouseDown,
3061
+ onMouseUp: handleMouseUp,
3062
+ onWheel: handleWheel,
3063
+ onMouseMove: handleMouseMove,
3064
+ ref: canvasRef
3065
+ }));
3066
+ };
3067
+
2918
3068
  /**
2919
3069
  * Viewer
2920
3070
  */
2921
3071
 
3072
+
2922
3073
  var Viewer = function Viewer(_ref) {
2923
3074
  var title = _ref.title,
2924
3075
  src = _ref.src,
@@ -2955,8 +3106,8 @@ var Viewer = function Viewer(_ref) {
2955
3106
  action: toggleDetails
2956
3107
  }), actions), /*#__PURE__*/React.createElement("main", null, /*#__PURE__*/React.createElement("div", {
2957
3108
  className: "resizer"
2958
- }, /*#__PURE__*/React.createElement("picture", null, /*#__PURE__*/React.createElement("img", {
2959
- src: src
3109
+ }, /*#__PURE__*/React.createElement("picture", null, /*#__PURE__*/React.createElement(ImageViewer, {
3110
+ image: src
2960
3111
  })))), /*#__PURE__*/React.createElement("aside", {
2961
3112
  className: "" + (showDetails ? 'open' : '')
2962
3113
  }, /*#__PURE__*/React.createElement(Header, {
@@ -4374,7 +4525,7 @@ var UploadDialog = function UploadDialog(_ref) {
4374
4525
  action: function action() {
4375
4526
  return onAction("CLOSE");
4376
4527
  },
4377
- disabled: canClose()
4528
+ disabled: !canClose()
4378
4529
  }));
4379
4530
  var title = /*#__PURE__*/React.createElement(Text, {
4380
4531
  use: "headline6"
@@ -4492,156 +4643,6 @@ var EmptyMessage = function EmptyMessage(_ref) {
4492
4643
  }, text));
4493
4644
  };
4494
4645
 
4495
- var SCROLL_SENSITIVITY = 0.0005;
4496
- var MAX_ZOOM = 5;
4497
- var MIN_ZOOM = 0.1;
4498
- var ImageViewer = function ImageViewer(_ref) {
4499
- var image = _ref.image;
4500
-
4501
- var _useState = useState({
4502
- x: 0,
4503
- y: 0
4504
- }),
4505
- offset = _useState[0],
4506
- setOffset = _useState[1];
4507
-
4508
- var _useState2 = useState(1),
4509
- zoom = _useState2[0],
4510
- setZoom = _useState2[1];
4511
-
4512
- var _useState3 = useState(false),
4513
- draggind = _useState3[0],
4514
- setDragging = _useState3[1];
4515
-
4516
- var touch = useRef({
4517
- x: 0,
4518
- y: 0
4519
- });
4520
- var canvasRef = useRef(null);
4521
- var containerRef = useRef(null);
4522
- var observer = useRef(null);
4523
- var background = useMemo(function () {
4524
- return new Image();
4525
- }, [image]);
4526
-
4527
- var clamp = function clamp(num, min, max) {
4528
- return Math.min(Math.max(num, min), max);
4529
- };
4530
-
4531
- var handleWheel = function handleWheel(event) {
4532
- var deltaY = event.deltaY;
4533
-
4534
- if (!draggind) {
4535
- setZoom(function (zoom) {
4536
- return clamp(zoom + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM);
4537
- });
4538
- }
4539
- };
4540
-
4541
- var handleMouseMove = function handleMouseMove(event) {
4542
- if (draggind) {
4543
- var _touch$current = touch.current,
4544
- x = _touch$current.x,
4545
- y = _touch$current.y;
4546
- var clientX = event.clientX,
4547
- clientY = event.clientY;
4548
- setOffset({
4549
- x: offset.x + (x - clientX),
4550
- y: offset.y + (y - clientY)
4551
- });
4552
- touch.current = {
4553
- x: clientX,
4554
- y: clientY
4555
- };
4556
- }
4557
- };
4558
-
4559
- var handleMouseDown = function handleMouseDown(event) {
4560
- var clientX = event.clientX,
4561
- clientY = event.clientY;
4562
- touch.current = {
4563
- x: clientX,
4564
- y: clientY
4565
- };
4566
- setDragging(true);
4567
- };
4568
-
4569
- var handleMouseUp = function handleMouseUp() {
4570
- return setDragging(false);
4571
- };
4572
-
4573
- var draw = function draw() {
4574
- if (canvasRef.current) {
4575
- var _canvasRef$current = canvasRef.current,
4576
- width = _canvasRef$current.width,
4577
- height = _canvasRef$current.height;
4578
- var context = canvasRef.current.getContext("2d"); // Set canvas dimensions
4579
-
4580
- canvasRef.current.width = width;
4581
- canvasRef.current.height = height; // Clear canvas and scale it
4582
-
4583
- context.translate(-offset.x, -offset.y);
4584
- context.scale(zoom, zoom);
4585
- context.clearRect(0, 0, width, height); // Make sure we're zooming to the center
4586
-
4587
- var x = (context.canvas.width / zoom - background.width) / 2;
4588
- var y = (context.canvas.height / zoom - background.height) / 2; // Draw image
4589
-
4590
- context.drawImage(background, x, y);
4591
- }
4592
- };
4593
-
4594
- useEffect(function () {
4595
- observer.current = new ResizeObserver(function (entries) {
4596
- entries.forEach(function (_ref2) {
4597
- var target = _ref2.target;
4598
- var width = background.width,
4599
- height = background.height; // If width of the container is smaller than image, scale image down
4600
-
4601
- if (target.clientWidth < width) {
4602
- // Calculate scale
4603
- var scale = target.clientWidth / width; // Redraw image
4604
-
4605
- canvasRef.current.width = width * scale;
4606
- canvasRef.current.height = height * scale;
4607
- canvasRef.current.getContext("2d").drawImage(background, 0, 0, width * scale, height * scale);
4608
- }
4609
- });
4610
- });
4611
- observer.current.observe(containerRef.current);
4612
- return function () {
4613
- return observer.current.unobserve(containerRef.current);
4614
- };
4615
- }, []);
4616
- useEffect(function () {
4617
- background.src = image;
4618
-
4619
- if (canvasRef.current) {
4620
- background.onload = function () {
4621
- // Get the image dimensions
4622
- var width = background.width,
4623
- height = background.height;
4624
- canvasRef.current.width = width;
4625
- canvasRef.current.height = height; // Set image as background
4626
-
4627
- canvasRef.current.getContext("2d").drawImage(background, 0, 0);
4628
- };
4629
- }
4630
- }, [background]);
4631
- useEffect(function () {
4632
- draw();
4633
- }, [zoom, offset]);
4634
- return /*#__PURE__*/React.createElement("div", {
4635
- ref: containerRef
4636
- }, /*#__PURE__*/React.createElement("canvas", {
4637
- onMouseDown: handleMouseDown,
4638
- onMouseUp: handleMouseUp,
4639
- onWheel: handleWheel,
4640
- onMouseMove: handleMouseMove,
4641
- ref: canvasRef
4642
- }));
4643
- };
4644
-
4645
4646
  /**
4646
4647
  * Content Form
4647
4648
  */