0.2.1 • Published 6 months ago

img-butler v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

img-butler

A React-based image manipulator, allowing users to examine a source image using a mouse, trackpad, or touch screen.

useImgButler()

Produces an tag. This contains a canvas to display and interact with your image.

Options:

NameTypeDefaultDescriptionNotes
srcstringpipa-fria.pngThe image's source URI.
titlestringundefinedA title to be drawn above the image as an <h2> element.
descstringundefinedA description to be drawn underneath the image as a <caption> element.
defaultPositionobject[x:0,y:0]Default position values for this image.A position value of {x:0,y:0} is centered.
positionBoundsobject[left:-100, right:100, top:100, bottom:-100]The smallest and largest allowed values for this image's position.A value of undefined indicates no bounds. Note that as zoomState changes, these bounds will also change to maintain relatively consistent bounds within the frame.
defaultZoombool1Default zoom value for this image.A zoom value of 1 guarantees the image is fully visible.
zoomBoundsobject[min:0.5,max:5]The smallest and largest allowed values for this image's zoom.A value of undefined indicates no bounds.
canDragbooltrueCan the user move the image using the drag gesture?
canPinchbooltrueCan the user zoom the image using the pinch gesture?
pointsArray<Point>[]A list of points to display on the map. See <Point/> below
onGesturefunction() => {}Function callback for responding to Gesture events. See GestureEvent below

\

This is a point that can be displayed on the map. It contains an optional tag, which may be toggled when the point is clicked.

Options:

NameTypeDefaultDescriptionNotes
xPercentagenumberundefineddescribes how far along the image's x axis the point should be placed0 is the left edge. 100 is the right edge
yPercentagenumberundefineddescribes how far along the image's y axis the point should be placed0 is the top edge. 100 is the bottom edge
popup<Popup/>undefinedoptional popup to open when the point is clicked. See <Popup/> below
sizenumber4describes the size of the point
sizeUnitsstring%describes the units for size, relative to image widthsize={4} sizeUnits={%} means the point is 4% of image width
backroundColorstringtransparentthe background color for the point. generally will be transparent
iconSrcstringstar_PNG41474.pngThe point's source URI, or text to display
iconTypestringimgThe point's source URIone of img, text. text allows you to use unicode
startOpenbooltrueIf it has a popup, whether that popup should open when the point is first created
closeEventsArray<DRAWABLE_EVENT>[POPUP_OPEN, CREATE, ESCAPE, ENTER, CLICK, DRAWING_END, DRAWING_START]The events that should cause the popup to closeSee DrawableEvent below
onPopupOpenfunction() => {}Optional callback that will be triggered when the popup opens
onPopupClosefunction() => {}Optional callback that will be triggered when the popup closes

\

A popup that a \ can accept. It can be used to encase other React tags.

Example

<Popup>
  <h1> hello! </h1>
  <input
    type="text"
    value={inputText}
    onChange={(e) => setInputText(e.target.value)}
  />
  <p> have a nice day! </p>
</Popup>

GestureEvent

Fired when a user-iput gesture detected on the image.

Fields:

NameTypeDescriptionNotes
eventTypeMOTIONThe type of event triggeredSee MOTION Event Types options below
xnumberwhere on the image's x axis the gesture occurs
ynumberwhere on the image's y axis the gesture occurs
targetnumberwhere on the image's y axis the gesture occurs

MOTION Event Types:

NameDescription
ZOOM_INFired when a user zooms in on the image
ZOOM_OUTFired when a user zooms out on the image
ZOOM_RESETFired when a user resets the image's zoom level
MOVE_UPFired when a user translates the images towards the top of the screen
MOVE_DOWNFired when a user translates the images towards the bottom of the screen
MOVE_LEFTFired when a user translates the images towards the left side of the screen
MOVE_RIGHTFired when a user translates the images towards the right side of the screen
MOVE_RESETFired when a user resets the x, y position of the image

DrawableEvent

NameTypeDescriptionNotes
eventTypeDRAWABLE_EVENTThe type of event triggeredSee DRAWABLE_EVENT Event Types options below
idstringthe id of the Drawable object firing this event

DRAWABLE_EVENT Event Types:

NameDescription
POPUP_OPENFired when a drawable's popup opens
POPUP_CLOSEFired when a drawables's popup closes
CREATEFired when a drawable is created
ESCAPEFired when the escape key is input by user
ENTERFired when the enter key is input by user
CLICKFired when the user clicks on a Drawable
DRAWING_ENDFired when isDrawing becomes false
DRAWING_STARTFired when isDrawing becomes true

External Control

The high-level concept is to call useImgButler() to create a \ tag, and populate it with the fields and/or objects you want.

Example:

const title = "My Cool Map";
const desc = "A map that is super cool";
const popup = <Popup>
  <p> popping up! </p>
</Popup>;
const points = [
  <Point
    xPercentage={50}
    yPercentage={50}
    popup={popup}
    startOpen={true}
  />
];
const src = require("../assets/my-map.png");
const onGesture = (e) => console.log(e);
const imgButler = useImgButler({ title, desc, points, src, onGesture });
...
<div className="app-scene">
  {imgButler}
</div>

Exports

The following items are exports of the img-butler package: | Name |Description | |-------------------|----------------------------------------------------| | MOTION | See above | | DRAWABLE_EVENT | See above | | GestureEvent | See above | | DrawableEvent | See above | | useImgButler | See above | | Point | See above | | Popup | See above |

0.2.1

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago