ywana-core8 0.2.14 → 0.2.16

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
@@ -22635,26 +22635,38 @@ const rows = [
22635
22635
  const SCROLL_SENSITIVITY = 5e-4;
22636
22636
  const MAX_ZOOM = 5;
22637
22637
  const MIN_ZOOM = 0.1;
22638
- const ImageViewer = ({ image }) => {
22638
+ const ImageViewer = React.forwardRef(({ image }, ref2) => {
22639
22639
  const [offset2, setOffset] = React.useState({ x: 0, y: 0 });
22640
22640
  const [zoom, setZoom] = React.useState(1);
22641
- const [draggind, setDragging] = React.useState(false);
22641
+ const [dragging, setDragging] = React.useState(false);
22642
22642
  const touch = React.useRef({ x: 0, y: 0 });
22643
22643
  const canvasRef = React.useRef(null);
22644
22644
  const containerRef = React.useRef(null);
22645
22645
  const observer = React.useRef(null);
22646
22646
  const background = React.useMemo(() => new Image(), [image]);
22647
22647
  const clamp = (num, min2, max2) => Math.min(Math.max(num, min2), max2);
22648
+ React.useImperativeHandle(ref2, () => ({
22649
+ zoomIn: () => {
22650
+ setZoom((prevZoom) => clamp(prevZoom + 0.2, MIN_ZOOM, MAX_ZOOM));
22651
+ },
22652
+ zoomOut: () => {
22653
+ setZoom((prevZoom) => clamp(prevZoom - 0.2, MIN_ZOOM, MAX_ZOOM));
22654
+ },
22655
+ resetZoom: () => {
22656
+ setZoom(1);
22657
+ setOffset({ x: 0, y: 0 });
22658
+ }
22659
+ }), []);
22648
22660
  const handleWheel = (event) => {
22649
22661
  const { deltaY } = event;
22650
- if (!draggind) {
22662
+ if (!dragging) {
22651
22663
  setZoom(
22652
22664
  (zoom2) => clamp(zoom2 + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM)
22653
22665
  );
22654
22666
  }
22655
22667
  };
22656
22668
  const handleMouseMove = (event) => {
22657
- if (draggind) {
22669
+ if (dragging) {
22658
22670
  const { x, y } = touch.current;
22659
22671
  const { clientX, clientY } = event;
22660
22672
  setOffset({
@@ -22671,24 +22683,34 @@ const rows = [
22671
22683
  };
22672
22684
  const handleMouseUp = () => setDragging(false);
22673
22685
  const draw = () => {
22674
- if (canvasRef.current) {
22675
- const { width, height } = canvasRef.current;
22676
- const context = canvasRef.current.getContext("2d");
22677
- canvasRef.current.width = width;
22678
- canvasRef.current.height = height;
22686
+ if (!canvasRef.current || !background.complete || !background.naturalWidth) {
22687
+ return;
22688
+ }
22689
+ try {
22690
+ const canvas = canvasRef.current;
22691
+ const { width, height } = canvas;
22692
+ const context = canvas.getContext("2d");
22693
+ canvas.width = width;
22694
+ canvas.height = height;
22695
+ context.save();
22679
22696
  context.translate(-offset2.x, -offset2.y);
22680
22697
  context.scale(zoom, zoom);
22681
22698
  context.clearRect(0, 0, width, height);
22682
- const x = (context.canvas.width / zoom - background.width) / 2;
22683
- const y = (context.canvas.height / zoom - background.height) / 2;
22699
+ const x = (canvas.width / zoom - background.width) / 2;
22700
+ const y = (canvas.height / zoom - background.height) / 2;
22684
22701
  context.drawImage(background, x, y);
22702
+ context.restore();
22703
+ } catch (error) {
22704
+ console.warn("Error drawing image:", error);
22685
22705
  }
22686
22706
  };
22687
22707
  React.useEffect(() => {
22708
+ const container = containerRef.current;
22709
+ if (!container) return;
22688
22710
  observer.current = new ResizeObserver((entries) => {
22689
22711
  entries.forEach(({ target }) => {
22690
22712
  const { width, height } = background;
22691
- if (target.clientWidth < width) {
22713
+ if (target.clientWidth < width && canvasRef.current) {
22692
22714
  const scale = target.clientWidth / width;
22693
22715
  canvasRef.current.width = width * scale;
22694
22716
  canvasRef.current.height = height * scale;
@@ -22696,23 +22718,37 @@ const rows = [
22696
22718
  }
22697
22719
  });
22698
22720
  });
22699
- observer.current.observe(containerRef.current);
22700
- return () => observer.current.unobserve(containerRef.current);
22721
+ observer.current.observe(container);
22722
+ return () => {
22723
+ if (observer.current && container) {
22724
+ observer.current.unobserve(container);
22725
+ }
22726
+ };
22701
22727
  }, []);
22702
22728
  React.useEffect(() => {
22729
+ if (!image) return;
22703
22730
  background.src = image;
22704
- if (canvasRef.current) {
22705
- background.onload = () => {
22731
+ const handleImageLoad = () => {
22732
+ if (canvasRef.current) {
22706
22733
  const { width, height } = background;
22707
22734
  canvasRef.current.width = width;
22708
22735
  canvasRef.current.height = height;
22709
22736
  canvasRef.current.getContext("2d").drawImage(background, 0, 0);
22710
- };
22711
- }
22712
- }, [background]);
22737
+ }
22738
+ };
22739
+ const handleImageError = () => {
22740
+ console.warn("Failed to load image:", image);
22741
+ };
22742
+ background.onload = handleImageLoad;
22743
+ background.onerror = handleImageError;
22744
+ return () => {
22745
+ background.onload = null;
22746
+ background.onerror = null;
22747
+ };
22748
+ }, [image, background]);
22713
22749
  React.useEffect(() => {
22714
22750
  draw();
22715
- }, [zoom, offset2]);
22751
+ }, [zoom, offset2, background.src]);
22716
22752
  return /* @__PURE__ */ React.createElement("div", { className: "image-viewer", ref: containerRef }, /* @__PURE__ */ React.createElement(
22717
22753
  "canvas",
22718
22754
  {
@@ -22723,14 +22759,55 @@ const rows = [
22723
22759
  ref: canvasRef
22724
22760
  }
22725
22761
  ));
22762
+ });
22763
+ const ViewerTest = () => {
22764
+ const [showViewer, setShowViewer] = React.useState(false);
22765
+ const sampleInfo = /* @__PURE__ */ React.createElement("div", { style: { padding: "1rem" } }, /* @__PURE__ */ React.createElement("h3", null, "Sample Image"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Size:"), " 1920x1080"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Format:"), " PNG"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Created:"), " 2024-01-15"));
22766
+ const sampleActions = [
22767
+ /* @__PURE__ */ React.createElement(Icon, { key: "download", icon: "download", clickable: true, title: "Download" }),
22768
+ /* @__PURE__ */ React.createElement(Icon, { key: "share", icon: "share", clickable: true, title: "Share" })
22769
+ ];
22770
+ return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("button", { onClick: () => setShowViewer(true) }, "Open Viewer Test"), showViewer && /* @__PURE__ */ React.createElement(
22771
+ Viewer,
22772
+ {
22773
+ title: "Sample Image",
22774
+ src: "https://concepto.de/wp-content/uploads/2015/03/paisaje-800x409.jpg",
22775
+ info: sampleInfo,
22776
+ actions: sampleActions,
22777
+ tools: true,
22778
+ onClose: () => setShowViewer(false)
22779
+ }
22780
+ ));
22726
22781
  };
22727
22782
  const Viewer = ({ title, src, info, actions = [], tools = false, onClose }) => {
22728
22783
  const [showDetails, setShowDetails] = React.useState(false);
22784
+ const [imageViewerRef, setImageViewerRef] = React.useState(null);
22729
22785
  function toggleDetails() {
22730
22786
  setShowDetails(!showDetails);
22731
22787
  }
22788
+ function handleZoomIn() {
22789
+ if (imageViewerRef && imageViewerRef.zoomIn) {
22790
+ imageViewerRef.zoomIn();
22791
+ }
22792
+ }
22793
+ function handleZoomOut() {
22794
+ if (imageViewerRef && imageViewerRef.zoomOut) {
22795
+ imageViewerRef.zoomOut();
22796
+ }
22797
+ }
22798
+ function handleZoomReset() {
22799
+ if (imageViewerRef && imageViewerRef.resetZoom) {
22800
+ imageViewerRef.resetZoom();
22801
+ }
22802
+ }
22732
22803
  const headerTitle = /* @__PURE__ */ React.createElement(Text, { use: "headline6" }, title);
22733
- return /* @__PURE__ */ React.createElement("div", { className: "viewer" }, /* @__PURE__ */ React.createElement(Header, { icon: "view", title: headerTitle }, onClose ? /* @__PURE__ */ React.createElement(Icon, { icon: "close", clickable: true, action: onClose }) : null, showDetails ? "" : /* @__PURE__ */ React.createElement(Icon, { icon: "info", clickable: true, action: toggleDetails }), actions), /* @__PURE__ */ React.createElement("main", null, /* @__PURE__ */ React.createElement("div", { className: "resizer" }, /* @__PURE__ */ React.createElement("picture", null, /* @__PURE__ */ React.createElement(ImageViewer, { image: src })))), /* @__PURE__ */ React.createElement("aside", { className: `${showDetails ? "open" : ""}` }, /* @__PURE__ */ React.createElement(Header, { title: "Detalles" }, /* @__PURE__ */ React.createElement(Icon, { icon: "close", clickable: true, action: toggleDetails })), /* @__PURE__ */ React.createElement("main", null, info)), tools ? /* @__PURE__ */ React.createElement("footer", null, /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_out" }), /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_out_map" }), /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_in" })) : null);
22804
+ return /* @__PURE__ */ React.createElement("div", { className: "viewer" }, /* @__PURE__ */ React.createElement(Header, { icon: "view", title: headerTitle }, actions, !showDetails && /* @__PURE__ */ React.createElement(Icon, { icon: "info", clickable: true, action: toggleDetails }), onClose && /* @__PURE__ */ React.createElement(Icon, { icon: "close", clickable: true, action: onClose })), /* @__PURE__ */ React.createElement("main", null, /* @__PURE__ */ React.createElement("div", { className: "resizer" }, /* @__PURE__ */ React.createElement("picture", null, /* @__PURE__ */ React.createElement(
22805
+ ImageViewer,
22806
+ {
22807
+ image: src,
22808
+ ref: setImageViewerRef
22809
+ }
22810
+ )))), /* @__PURE__ */ React.createElement("aside", { className: `${showDetails ? "open" : ""}` }, /* @__PURE__ */ React.createElement(Header, { title: "Detalles" }, /* @__PURE__ */ React.createElement(Icon, { icon: "close", clickable: true, action: toggleDetails })), /* @__PURE__ */ React.createElement("main", null, info)), tools && /* @__PURE__ */ React.createElement("footer", null, /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_out", action: handleZoomOut }), /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_out_map", action: handleZoomReset }), /* @__PURE__ */ React.createElement(Icon, { clickable: true, icon: "zoom_in", action: handleZoomIn })));
22734
22811
  };
22735
22812
  const Kanban = ({ children }) => {
22736
22813
  const hasSwimlanes = React.useMemo(() => {
@@ -43034,6 +43111,7 @@ Middle click: Close`
43034
43111
  exports2.MenuItem = MenuItem;
43035
43112
  exports2.MenuSeparator = MenuSeparator;
43036
43113
  exports2.MonthCalendar = MonthCalendar;
43114
+ exports2.MultiProgress = MultiProgress;
43037
43115
  exports2.MultiSelector = MultiSelector;
43038
43116
  exports2.Page = Page;
43039
43117
  exports2.PageContext = PageContext;
@@ -43047,6 +43125,7 @@ Middle click: Close`
43047
43125
  exports2.ProgressExamples = ProgressExamples;
43048
43126
  exports2.Property = Property;
43049
43127
  exports2.PropertyExamples = PropertyExamples;
43128
+ exports2.RadialProgress = RadialProgress;
43050
43129
  exports2.RadioButton = RadioButton;
43051
43130
  exports2.RadioExamples = RadioExamples;
43052
43131
  exports2.RadioGroup = RadioGroup;
@@ -43058,6 +43137,7 @@ Middle click: Close`
43058
43137
  exports2.SiteContext = SiteContext;
43059
43138
  exports2.SiteProvider = SiteProvider;
43060
43139
  exports2.Stack = Stack;
43140
+ exports2.StepProgress = StepProgress;
43061
43141
  exports2.Switch = Switch;
43062
43142
  exports2.SwitchExamples = SwitchExamples;
43063
43143
  exports2.TASK_STATES = TASK_STATES;
@@ -43102,6 +43182,7 @@ Middle click: Close`
43102
43182
  exports2.Uploader = Uploader;
43103
43183
  exports2.View = View;
43104
43184
  exports2.Viewer = Viewer;
43185
+ exports2.ViewerTest = ViewerTest;
43105
43186
  exports2.WaitScreen = WaitScreen;
43106
43187
  exports2.Window = Window;
43107
43188
  exports2.WindowManager = WindowManager;