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