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.css +59 -11
- package/dist/index.js +102 -21
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +103 -22
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +102 -21
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/index.js +1 -1
- package/src/widgets/image/ImageViewer.css +14 -1
- package/src/widgets/image/ImageViewer.js +72 -23
- package/src/widgets/viewer/Viewer.css +45 -10
- package/src/widgets/viewer/Viewer.js +71 -19
package/dist/index.modern.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useContext, useMemo, useCallback, useState, useEffect, useRef, Fragment, createContext } from "react";
|
1
|
+
import React, { useContext, useMemo, useCallback, useState, useEffect, useRef, Fragment, createContext, forwardRef, useImperativeHandle } from "react";
|
2
2
|
function isEmpty(obj) {
|
3
3
|
if (obj === null) {
|
4
4
|
return true;
|
@@ -22632,26 +22632,38 @@ const LOGIN_CONTEXT = {
|
|
22632
22632
|
const SCROLL_SENSITIVITY = 5e-4;
|
22633
22633
|
const MAX_ZOOM = 5;
|
22634
22634
|
const MIN_ZOOM = 0.1;
|
22635
|
-
const ImageViewer = ({ image }) => {
|
22635
|
+
const ImageViewer = forwardRef(({ image }, ref2) => {
|
22636
22636
|
const [offset2, setOffset] = useState({ x: 0, y: 0 });
|
22637
22637
|
const [zoom, setZoom] = useState(1);
|
22638
|
-
const [
|
22638
|
+
const [dragging, setDragging] = useState(false);
|
22639
22639
|
const touch = useRef({ x: 0, y: 0 });
|
22640
22640
|
const canvasRef = useRef(null);
|
22641
22641
|
const containerRef = useRef(null);
|
22642
22642
|
const observer = useRef(null);
|
22643
22643
|
const background = useMemo(() => new Image(), [image]);
|
22644
22644
|
const clamp = (num, min2, max2) => Math.min(Math.max(num, min2), max2);
|
22645
|
+
useImperativeHandle(ref2, () => ({
|
22646
|
+
zoomIn: () => {
|
22647
|
+
setZoom((prevZoom) => clamp(prevZoom + 0.2, MIN_ZOOM, MAX_ZOOM));
|
22648
|
+
},
|
22649
|
+
zoomOut: () => {
|
22650
|
+
setZoom((prevZoom) => clamp(prevZoom - 0.2, MIN_ZOOM, MAX_ZOOM));
|
22651
|
+
},
|
22652
|
+
resetZoom: () => {
|
22653
|
+
setZoom(1);
|
22654
|
+
setOffset({ x: 0, y: 0 });
|
22655
|
+
}
|
22656
|
+
}), []);
|
22645
22657
|
const handleWheel = (event) => {
|
22646
22658
|
const { deltaY } = event;
|
22647
|
-
if (!
|
22659
|
+
if (!dragging) {
|
22648
22660
|
setZoom(
|
22649
22661
|
(zoom2) => clamp(zoom2 + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM)
|
22650
22662
|
);
|
22651
22663
|
}
|
22652
22664
|
};
|
22653
22665
|
const handleMouseMove = (event) => {
|
22654
|
-
if (
|
22666
|
+
if (dragging) {
|
22655
22667
|
const { x, y } = touch.current;
|
22656
22668
|
const { clientX, clientY } = event;
|
22657
22669
|
setOffset({
|
@@ -22668,24 +22680,34 @@ const ImageViewer = ({ image }) => {
|
|
22668
22680
|
};
|
22669
22681
|
const handleMouseUp = () => setDragging(false);
|
22670
22682
|
const draw = () => {
|
22671
|
-
if (canvasRef.current) {
|
22672
|
-
|
22673
|
-
|
22674
|
-
|
22675
|
-
canvasRef.current
|
22683
|
+
if (!canvasRef.current || !background.complete || !background.naturalWidth) {
|
22684
|
+
return;
|
22685
|
+
}
|
22686
|
+
try {
|
22687
|
+
const canvas = canvasRef.current;
|
22688
|
+
const { width, height } = canvas;
|
22689
|
+
const context = canvas.getContext("2d");
|
22690
|
+
canvas.width = width;
|
22691
|
+
canvas.height = height;
|
22692
|
+
context.save();
|
22676
22693
|
context.translate(-offset2.x, -offset2.y);
|
22677
22694
|
context.scale(zoom, zoom);
|
22678
22695
|
context.clearRect(0, 0, width, height);
|
22679
|
-
const x = (
|
22680
|
-
const y = (
|
22696
|
+
const x = (canvas.width / zoom - background.width) / 2;
|
22697
|
+
const y = (canvas.height / zoom - background.height) / 2;
|
22681
22698
|
context.drawImage(background, x, y);
|
22699
|
+
context.restore();
|
22700
|
+
} catch (error) {
|
22701
|
+
console.warn("Error drawing image:", error);
|
22682
22702
|
}
|
22683
22703
|
};
|
22684
22704
|
useEffect(() => {
|
22705
|
+
const container = containerRef.current;
|
22706
|
+
if (!container) return;
|
22685
22707
|
observer.current = new ResizeObserver((entries) => {
|
22686
22708
|
entries.forEach(({ target }) => {
|
22687
22709
|
const { width, height } = background;
|
22688
|
-
if (target.clientWidth < width) {
|
22710
|
+
if (target.clientWidth < width && canvasRef.current) {
|
22689
22711
|
const scale = target.clientWidth / width;
|
22690
22712
|
canvasRef.current.width = width * scale;
|
22691
22713
|
canvasRef.current.height = height * scale;
|
@@ -22693,23 +22715,37 @@ const ImageViewer = ({ image }) => {
|
|
22693
22715
|
}
|
22694
22716
|
});
|
22695
22717
|
});
|
22696
|
-
observer.current.observe(
|
22697
|
-
return () =>
|
22718
|
+
observer.current.observe(container);
|
22719
|
+
return () => {
|
22720
|
+
if (observer.current && container) {
|
22721
|
+
observer.current.unobserve(container);
|
22722
|
+
}
|
22723
|
+
};
|
22698
22724
|
}, []);
|
22699
22725
|
useEffect(() => {
|
22726
|
+
if (!image) return;
|
22700
22727
|
background.src = image;
|
22701
|
-
|
22702
|
-
|
22728
|
+
const handleImageLoad = () => {
|
22729
|
+
if (canvasRef.current) {
|
22703
22730
|
const { width, height } = background;
|
22704
22731
|
canvasRef.current.width = width;
|
22705
22732
|
canvasRef.current.height = height;
|
22706
22733
|
canvasRef.current.getContext("2d").drawImage(background, 0, 0);
|
22707
|
-
}
|
22708
|
-
}
|
22709
|
-
|
22734
|
+
}
|
22735
|
+
};
|
22736
|
+
const handleImageError = () => {
|
22737
|
+
console.warn("Failed to load image:", image);
|
22738
|
+
};
|
22739
|
+
background.onload = handleImageLoad;
|
22740
|
+
background.onerror = handleImageError;
|
22741
|
+
return () => {
|
22742
|
+
background.onload = null;
|
22743
|
+
background.onerror = null;
|
22744
|
+
};
|
22745
|
+
}, [image, background]);
|
22710
22746
|
useEffect(() => {
|
22711
22747
|
draw();
|
22712
|
-
}, [zoom, offset2]);
|
22748
|
+
}, [zoom, offset2, background.src]);
|
22713
22749
|
return /* @__PURE__ */ React.createElement("div", { className: "image-viewer", ref: containerRef }, /* @__PURE__ */ React.createElement(
|
22714
22750
|
"canvas",
|
22715
22751
|
{
|
@@ -22720,14 +22756,55 @@ const ImageViewer = ({ image }) => {
|
|
22720
22756
|
ref: canvasRef
|
22721
22757
|
}
|
22722
22758
|
));
|
22759
|
+
});
|
22760
|
+
const ViewerTest = () => {
|
22761
|
+
const [showViewer, setShowViewer] = useState(false);
|
22762
|
+
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"));
|
22763
|
+
const sampleActions = [
|
22764
|
+
/* @__PURE__ */ React.createElement(Icon, { key: "download", icon: "download", clickable: true, title: "Download" }),
|
22765
|
+
/* @__PURE__ */ React.createElement(Icon, { key: "share", icon: "share", clickable: true, title: "Share" })
|
22766
|
+
];
|
22767
|
+
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("button", { onClick: () => setShowViewer(true) }, "Open Viewer Test"), showViewer && /* @__PURE__ */ React.createElement(
|
22768
|
+
Viewer,
|
22769
|
+
{
|
22770
|
+
title: "Sample Image",
|
22771
|
+
src: "https://concepto.de/wp-content/uploads/2015/03/paisaje-800x409.jpg",
|
22772
|
+
info: sampleInfo,
|
22773
|
+
actions: sampleActions,
|
22774
|
+
tools: true,
|
22775
|
+
onClose: () => setShowViewer(false)
|
22776
|
+
}
|
22777
|
+
));
|
22723
22778
|
};
|
22724
22779
|
const Viewer = ({ title, src, info, actions = [], tools = false, onClose }) => {
|
22725
22780
|
const [showDetails, setShowDetails] = useState(false);
|
22781
|
+
const [imageViewerRef, setImageViewerRef] = useState(null);
|
22726
22782
|
function toggleDetails() {
|
22727
22783
|
setShowDetails(!showDetails);
|
22728
22784
|
}
|
22785
|
+
function handleZoomIn() {
|
22786
|
+
if (imageViewerRef && imageViewerRef.zoomIn) {
|
22787
|
+
imageViewerRef.zoomIn();
|
22788
|
+
}
|
22789
|
+
}
|
22790
|
+
function handleZoomOut() {
|
22791
|
+
if (imageViewerRef && imageViewerRef.zoomOut) {
|
22792
|
+
imageViewerRef.zoomOut();
|
22793
|
+
}
|
22794
|
+
}
|
22795
|
+
function handleZoomReset() {
|
22796
|
+
if (imageViewerRef && imageViewerRef.resetZoom) {
|
22797
|
+
imageViewerRef.resetZoom();
|
22798
|
+
}
|
22799
|
+
}
|
22729
22800
|
const headerTitle = /* @__PURE__ */ React.createElement(Text, { use: "headline6" }, title);
|
22730
|
-
return /* @__PURE__ */ React.createElement("div", { className: "viewer" }, /* @__PURE__ */ React.createElement(Header, { icon: "view", title: headerTitle },
|
22801
|
+
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(
|
22802
|
+
ImageViewer,
|
22803
|
+
{
|
22804
|
+
image: src,
|
22805
|
+
ref: setImageViewerRef
|
22806
|
+
}
|
22807
|
+
)))), /* @__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 })));
|
22731
22808
|
};
|
22732
22809
|
const Kanban = ({ children }) => {
|
22733
22810
|
const hasSwimlanes = useMemo(() => {
|
@@ -43032,6 +43109,7 @@ export {
|
|
43032
43109
|
MenuItem,
|
43033
43110
|
MenuSeparator,
|
43034
43111
|
MonthCalendar,
|
43112
|
+
MultiProgress,
|
43035
43113
|
MultiSelector,
|
43036
43114
|
Page,
|
43037
43115
|
PageContext,
|
@@ -43045,6 +43123,7 @@ export {
|
|
43045
43123
|
ProgressExamples,
|
43046
43124
|
Property,
|
43047
43125
|
PropertyExamples,
|
43126
|
+
RadialProgress,
|
43048
43127
|
RadioButton,
|
43049
43128
|
RadioExamples,
|
43050
43129
|
RadioGroup,
|
@@ -43056,6 +43135,7 @@ export {
|
|
43056
43135
|
SiteContext,
|
43057
43136
|
SiteProvider,
|
43058
43137
|
Stack,
|
43138
|
+
StepProgress,
|
43059
43139
|
Switch,
|
43060
43140
|
SwitchExamples,
|
43061
43141
|
TASK_STATES,
|
@@ -43100,6 +43180,7 @@ export {
|
|
43100
43180
|
Uploader,
|
43101
43181
|
View,
|
43102
43182
|
Viewer,
|
43183
|
+
ViewerTest,
|
43103
43184
|
WaitScreen,
|
43104
43185
|
Window,
|
43105
43186
|
WindowManager,
|