@kwiz/fluentui 1.0.40 → 1.0.41

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.
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ export interface iProps {
3
+ label?: string;
4
+ value: string;
5
+ onChange: (newValue: string) => void;
6
+ required?: boolean;
7
+ showValidationErrors?: boolean;
8
+ underlined?: boolean;
9
+ width?: number;
10
+ buttonOnly?: boolean;
11
+ placeholder?: string;
12
+ }
13
+ export declare const ColorPickerEx: React.FunctionComponent<iProps>;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Field } from "@fluentui/react-components";
3
+ import { ColorRegular } from "@fluentui/react-icons";
4
+ import { isFunction, isNullOrEmptyString, isNumber } from "@kwiz/common";
5
+ import * as React from "react";
6
+ import ColorPicker from 'react-pick-color';
7
+ import { useEffectOnlyOnMount, useStateEX } from "../helpers/hooks";
8
+ import { ButtonEX } from "./button";
9
+ import { InputEx } from "./input";
10
+ import { Prompter } from "./prompt";
11
+ export const ColorPickerEx = (props) => {
12
+ const [isOpen, setIsOpen] = useStateEX(false);
13
+ const [selectedColor, setSelectedColor] = useStateEX(props.value);
14
+ const getColorCells = React.useCallback(() => {
15
+ let cells = [
16
+ "white", "black"
17
+ ];
18
+ return cells;
19
+ }, useEffectOnlyOnMount);
20
+ return _jsxs(_Fragment, { children: [props.buttonOnly
21
+ ? _jsx(ButtonEX, { title: "Open color picker", icon: _jsx(ColorRegular, { color: selectedColor }), onClick: () => setIsOpen(true) })
22
+ : _jsx(Field, { label: props.label, required: props.required === true, validationMessage: props.showValidationErrors && props.required === true && isNullOrEmptyString(selectedColor) ? "You can't leave this blank." : undefined, children: _jsx(InputEx, { placeholder: props.placeholder || "Enter value here", style: isNumber(props.width) ? { width: props.width } : undefined, value: selectedColor, onChange: (e, data) => {
23
+ setSelectedColor(data.value);
24
+ if (isFunction(props.onChange)) {
25
+ props.onChange(data.value);
26
+ }
27
+ }, contentAfter: _jsx(ButtonEX, { title: "Open color picker", icon: _jsx(ColorRegular, { color: selectedColor }), onClick: () => setIsOpen(true) }) }) }), isOpen && _jsx(Prompter, { maxWidth: 332, hideOk: true, hideCancel: true, onCancel: () => {
28
+ if (isFunction(props.onChange)) {
29
+ props.onChange(selectedColor);
30
+ }
31
+ setIsOpen(false);
32
+ }, showCancelInTitle: true, title: props.label || "Choose a color", children: _jsx(ColorPicker, { color: selectedColor, onChange: color => setSelectedColor(color.hex), presets: getColorCells() }) })] });
33
+ };
34
+ //# sourceMappingURL=ColorPickerDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPickerDialog.js","sourceRoot":"","sources":["../../src/controls/ColorPickerDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,WAAsB,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAapC,MAAM,CAAC,MAAM,aAAa,GAAoC,CAAC,KAAK,EAAE,EAAE;IACpE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,CAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,UAAU,CAAS,KAAK,CAAC,KAAK,CAAC,CAAC;IAE1E,MAAM,aAA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,KAAC,YAAY,IACf,KAAK,EAAE,aAAa,GAAI,EAE5B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAI,GACxC,GACE,EACX,MAAM,IAAI,KAAC,QAAQ,IAAC,QAAQ,EAAE,GAAG,EAC9B,MAAM,QAAC,UAAU,QAAC,QAAQ,EAAE,GAAG,EAAE;oBAC7B,IAAI,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC7B,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;oBAClC,CAAC;oBACD,SAAS,CAAC,KAAK,CAAC,CAAC;gBACrB,CAAC,EAAE,iBAAiB,QACpB,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,gBAAgB,YAEtC,KAAC,WAAW,IAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAC7E,OAAO,EAAE,aAAa,EAAE,GAC1B,GACK,IACZ,CAAC;AACR,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare class CustomEventTargetBase implements EventTarget {
2
+ private _et;
3
+ constructor();
4
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
5
+ dispatchEvent(event: Event): boolean;
6
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
7
+ }
@@ -0,0 +1,22 @@
1
+ export class CustomEventTargetBase {
2
+ constructor() {
3
+ try {
4
+ this._et = new EventTarget();
5
+ }
6
+ catch (error) {
7
+ // Using document as EventTarget to support iOS 13 and older.
8
+ // Because EventTarget constructor just exists at iOS 14 and later.
9
+ this._et = document;
10
+ }
11
+ }
12
+ addEventListener(type, listener, options) {
13
+ this._et.addEventListener(type, listener, options);
14
+ }
15
+ dispatchEvent(event) {
16
+ return this._et.dispatchEvent(event);
17
+ }
18
+ removeEventListener(type, callback, options) {
19
+ this._et.removeEventListener(type, callback, options);
20
+ }
21
+ }
22
+ //# sourceMappingURL=CustomEventTargetBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomEventTargetBase.js","sourceRoot":"","sources":["../../../src/controls/canvas/CustomEventTargetBase.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAqB;IAG9B;QACI,IAAI,CAAC;YACD,IAAI,CAAC,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,6DAA6D;YAC7D,mEAAmE;YACnE,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC;QACxB,CAAC;IACL,CAAC;IAEM,gBAAgB,CACnB,IAAY,EACZ,QAAmD,EACnD,OAA2C;QAE3C,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAEM,aAAa,CAAC,KAAY;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAEM,mBAAmB,CACtB,IAAY,EACZ,QAAmD,EACnD,OAAwC;QAExC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;CACJ"}
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ interface iProps {
3
+ BackgroundColor?: string;
4
+ BorderColor?: string;
5
+ LineColor?: string;
6
+ Width?: number;
7
+ Height?: number;
8
+ Value?: string;
9
+ OnChange?: (newValue: string) => void;
10
+ ReadOnly?: boolean;
11
+ HideButtons?: boolean;
12
+ SignAsText?: string;
13
+ }
14
+ export declare const DrawPad: React.FunctionComponent<iProps>;
15
+ export {};
@@ -0,0 +1,151 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { tokens } from "@fluentui/react-components";
12
+ import { ArrowUploadRegular, CalligraphyPenRegular, DismissRegular } from "@fluentui/react-icons";
13
+ import { ImageFileTypes, debounce, isElement, isFunction, isNullOrEmptyArray, isNullOrEmptyString } from "@kwiz/common";
14
+ import * as React from "react";
15
+ import { useStateEX } from "../../helpers/hooks";
16
+ import { ButtonEX } from "../button";
17
+ import { ColorPickerEx } from "../ColorPickerDialog";
18
+ import { FileUpload } from "../file-upload";
19
+ import { Horizontal } from "../horizontal";
20
+ import { Vertical } from "../vertical";
21
+ import DrawPadManager from "./DrawPadManager";
22
+ export const DrawPad = (props) => {
23
+ const [LineColor, setLineColor] = useStateEX(props.LineColor || tokens.colorBrandForeground1);
24
+ const [manager, setmanager] = useStateEX(null);
25
+ const [canUndo, setcanUndo] = useStateEX(false);
26
+ const [loadedFontNames, setloadedFontNames] = useStateEX([]);
27
+ const canvasArea = React.useRef();
28
+ const containerEle = React.useRef();
29
+ //load font for sign as text
30
+ React.useEffect(() => {
31
+ if (props.SignAsText && isNullOrEmptyArray(loadedFontNames)) {
32
+ let DancingScriptFont = new FontFace("Dancing Script", "url(https://fonts.gstatic.com/s/dancingscript/v25/If2RXTr6YS-zF4S-kcSWSVi_szLgiuE.woff2) format('woff2')", {
33
+ style: "normal",
34
+ weight: "400 700",
35
+ display: "swap",
36
+ unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"
37
+ });
38
+ DancingScriptFont.load().then((loadedFont) => __awaiter(void 0, void 0, void 0, function* () {
39
+ document.fonts.add(loadedFont);
40
+ yield document.fonts.ready;
41
+ setloadedFontNames(["Dancing Script"]);
42
+ }));
43
+ }
44
+ }, [props.SignAsText, loadedFontNames]);
45
+ //setup manager
46
+ React.useEffect(() => {
47
+ if (!props.ReadOnly) {
48
+ //this gets called after each render...
49
+ if (!manager) {
50
+ if (canvasArea.current) {
51
+ let manager = new DrawPadManager(canvasArea.current);
52
+ setmanager(manager).then(() => UpdateCanvas());
53
+ if (isFunction(props.OnChange)) {
54
+ manager.addEventListener("endStroke", () => {
55
+ let value = "";
56
+ if (!manager.isEmpty()) {
57
+ value = manager.toDataURL("image/png");
58
+ }
59
+ if (!canUndo)
60
+ setcanUndo(true);
61
+ props.OnChange(value);
62
+ });
63
+ }
64
+ }
65
+ }
66
+ else {
67
+ UpdateCanvas();
68
+ }
69
+ }
70
+ }); //run every time after render
71
+ //set value to canvas
72
+ const UpdateCanvas = React.useCallback(debounce(() => {
73
+ if (manager) {
74
+ manager.penColor.value = LineColor;
75
+ if (!isNullOrEmptyString(props.Value))
76
+ manager.fromDataURL(props.Value, { clear: true });
77
+ else
78
+ manager.clear();
79
+ }
80
+ }, 200, this), [manager, props.Value, LineColor]);
81
+ const onSignAs = React.useCallback(() => {
82
+ let canvas = canvasArea.current;
83
+ if (!isElement(canvas)) {
84
+ return;
85
+ }
86
+ let height = canvas.clientHeight;
87
+ let width = canvas.clientWidth;
88
+ let fontName = loadedFontNames[0];
89
+ let signAs = props.SignAsText;
90
+ let ctx = canvas.getContext("2d");
91
+ ctx.fillStyle = LineColor || LineColor || tokens.colorBrandForeground1;
92
+ let fontSize = 0.6 * height;
93
+ ctx.font = `${fontSize}px ${fontName}`;
94
+ let textMeasurement = ctx.measureText(signAs);
95
+ let textWidth = textMeasurement.width;
96
+ let maxWidth = 0.9 * width;
97
+ while (textWidth > maxWidth && fontSize > 1) {
98
+ fontSize = fontSize - 1;
99
+ ctx.font = `${fontSize}px ${fontName}`;
100
+ textMeasurement = ctx.measureText(signAs);
101
+ textWidth = textMeasurement.width;
102
+ }
103
+ let x = (width - textWidth) / 2;
104
+ let y = 0.6 * height; //baseline not starting point
105
+ ctx.fillText(signAs, x, y, width);
106
+ let url = canvas.toDataURL("image/png");
107
+ props.OnChange(url);
108
+ }, [canvasArea, props.OnChange]);
109
+ let width = props.Width > 0 ? props.Width : 400;
110
+ let height = props.Height > 0 ? props.Height : 200;
111
+ return _jsx("div", { ref: containerEle, children: _jsxs(Horizontal, { children: [_jsx("div", { style: {
112
+ position: "relative",
113
+ width: width,
114
+ height: height,
115
+ backgroundColor: props.BackgroundColor,
116
+ border: `1px solid ${props.BorderColor || tokens.colorNeutralStroke1}`
117
+ }, children: props.ReadOnly
118
+ ? _jsx("img", { src: props.Value, style: { position: "absolute", left: 0, top: 0, width: width, height: height } })
119
+ :
120
+ _jsxs("div", { style: { position: "absolute", left: 0, top: 0, width: width, height: height }, children: [_jsx("canvas", { ref: canvasArea, style: {
121
+ touchAction: "none",
122
+ userSelect: "none",
123
+ position: "absolute",
124
+ left: 0,
125
+ top: 0,
126
+ width: width,
127
+ height: height,
128
+ border: tokens.colorBrandStroke1
129
+ } }), isNullOrEmptyString(props.Value)
130
+ && !isNullOrEmptyString(props.SignAsText)
131
+ && !isNullOrEmptyArray(loadedFontNames)
132
+ && _jsx(ButtonEX, { style: {
133
+ position: "absolute",
134
+ bottom: 0,
135
+ border: 0,
136
+ margin: 0,
137
+ right: 0,
138
+ height: 16
139
+ }, icon: _jsx(CalligraphyPenRegular, {}), title: `Sign as ${props.SignAsText}`, onClick: () => {
140
+ onSignAs();
141
+ } })] }) }), !props.ReadOnly && !props.HideButtons && _jsxs(Vertical, { nogap: true, children: [_jsx(ColorPickerEx, { buttonOnly: true, value: props.LineColor, onChange: newColor => {
142
+ setLineColor(newColor);
143
+ } }), _jsx(ButtonEX, { disabled: isNullOrEmptyString(props.Value), title: "Clear", icon: _jsx(DismissRegular, {}), onClick: () => {
144
+ //can call clear on the canvas, or can call the onchange which will cause a re-draw
145
+ props.OnChange("");
146
+ } }), _jsx(FileUpload, { title: "Load background image", icon: _jsx(ArrowUploadRegular, {}), limitFileTypes: ImageFileTypes, asBase64: base64 => {
147
+ props.OnChange(base64[0].base64); //this will trigger a change and state update
148
+ //self.state.manager.fromDataURL(base64);//this will just set the image to the canvas but won't trigger a change
149
+ } })] })] }) });
150
+ };
151
+ //# sourceMappingURL=DrawPad.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DrawPad.js","sourceRoot":"","sources":["../../../src/controls/canvas/DrawPad.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAc9C,MAAM,CAAC,MAAM,OAAO,GAAoC,CAAC,KAAK,EAAE,EAAE;IAC9D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,U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mF;gCACnF,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;4BACvB,CAAC,GAAI,EACL,KAAC,UAAU,IAAC,KAAK,EAAC,uBAAuB,EAAC,IAAI,EAAE,KAAC,kBAAkB,KAAG,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE;gCACvH,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA,6CAA6C;gCAC9E,gHAAgH;4BACpH,CAAC,GAAI,IACE,IACF,GACP,CAAC;AACX,CAAC,CAAA"}
@@ -0,0 +1,84 @@
1
+ import { CustomEventTargetBase } from './CustomEventTargetBase';
2
+ import { BasicPoint } from './point';
3
+ declare global {
4
+ interface CSSStyleDeclaration {
5
+ msTouchAction: string | null;
6
+ }
7
+ }
8
+ export type DrawPadEvent = MouseEvent | Touch | PointerEvent;
9
+ export interface FromDataOptions {
10
+ clear?: boolean;
11
+ }
12
+ export interface PointGroupOptions {
13
+ dotSize: number;
14
+ minWidth: number;
15
+ maxWidth: number;
16
+ penColor: string;
17
+ }
18
+ export interface Options extends Partial<PointGroupOptions> {
19
+ minDistance?: number;
20
+ velocityFilterWeight?: number;
21
+ backgroundColor?: string;
22
+ throttle?: number;
23
+ }
24
+ export interface PointGroup extends PointGroupOptions {
25
+ points: BasicPoint[];
26
+ }
27
+ export default class DrawPadManager extends CustomEventTargetBase {
28
+ private canvas;
29
+ dotSize: import("@kwiz/common").DefaultProp<number>;
30
+ minWidth: import("@kwiz/common").DefaultProp<number>;
31
+ maxWidth: import("@kwiz/common").DefaultProp<number>;
32
+ penColor: import("@kwiz/common").DefaultProp<string>;
33
+ minDistance: import("@kwiz/common").DefaultProp<number>;
34
+ velocityFilterWeight: import("@kwiz/common").DefaultProp<number>;
35
+ backgroundColor: import("@kwiz/common").DefaultProp<string>;
36
+ throttle: import("@kwiz/common").DefaultProp<number>;
37
+ private _ctx;
38
+ private _drawningStroke;
39
+ private _isEmpty;
40
+ private _lastPoints;
41
+ private _data;
42
+ private _lastVelocity;
43
+ private _lastWidth;
44
+ private _strokeMoveUpdate;
45
+ constructor(canvas: HTMLCanvasElement, options?: Options);
46
+ clear(): void;
47
+ fromDataURL(dataUrl: string, options?: {
48
+ clear?: boolean;
49
+ }): Promise<void>;
50
+ toDataURL(type?: 'image/png' | 'image/jpeg' | 'image/svg+xml', encoderOptions?: number): string;
51
+ on(): void;
52
+ off(): void;
53
+ isEmpty(): boolean;
54
+ canUndo(): boolean;
55
+ undoLast(): void;
56
+ resizeCanvas(): void;
57
+ fromData(pointGroups: PointGroup[], { clear }?: FromDataOptions): void;
58
+ toData(): PointGroup[];
59
+ private _handleMouseDown;
60
+ private _handleMouseMove;
61
+ private _handleMouseUp;
62
+ private _handleTouchStart;
63
+ private _handleTouchMove;
64
+ private _handleTouchEnd;
65
+ private _handlePointerStart;
66
+ private _handlePointerMove;
67
+ private _handlePointerEnd;
68
+ private _strokeBegin;
69
+ private _strokeUpdate;
70
+ private _strokeEnd;
71
+ private _handlePointerEvents;
72
+ private _handleMouseEvents;
73
+ private _handleTouchEvents;
74
+ private _reset;
75
+ private _createPoint;
76
+ private _addPoint;
77
+ private _calculateCurveWidths;
78
+ private _strokeWidth;
79
+ private _drawCurveSegment;
80
+ private _drawCurve;
81
+ private _drawDot;
82
+ private _fromData;
83
+ private _toSVG;
84
+ }