@react-fabric/draw 1.0.0-beta.9 → 1.0.2

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.
Files changed (57) hide show
  1. package/dist/cjs/index.js +32 -0
  2. package/dist/esm/index.js +31 -0
  3. package/dist/types/index.d.ts +26 -1
  4. package/package.json +15 -17
  5. package/src/index.ts +21 -18
  6. package/dist/cjs/_virtual/_commonjsHelpers.js +0 -7
  7. package/dist/cjs/_virtual/dom-to-image.js +0 -5
  8. package/dist/cjs/node_modules/dom-to-image/src/dom-to-image.js +0 -777
  9. package/dist/cjs/packages/draw/src/canvas/DrawCanvas.js +0 -326
  10. package/dist/cjs/packages/draw/src/canvas/DrawContext.js +0 -22
  11. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/AvatarShapeTool.js +0 -271
  12. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/IdleState.js +0 -59
  13. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/PointingState.js +0 -84
  14. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/type.js +0 -36
  15. package/dist/cjs/packages/draw/src/canvas/shapes/custom/AudioShape.js +0 -152
  16. package/dist/cjs/packages/draw/src/canvas/shapes/custom/CardShape.js +0 -115
  17. package/dist/cjs/packages/draw/src/canvas/shapes/custom/FileShape.js +0 -128
  18. package/dist/cjs/packages/draw/src/canvas/shapes/custom/ImageShape.js +0 -137
  19. package/dist/cjs/packages/draw/src/canvas/shapes/custom/VideoShape.js +0 -160
  20. package/dist/cjs/packages/draw/src/index.js +0 -7
  21. package/dist/esm/_virtual/_commonjsHelpers.js +0 -7
  22. package/dist/esm/_virtual/dom-to-image.js +0 -5
  23. package/dist/esm/node_modules/dom-to-image/src/dom-to-image.js +0 -777
  24. package/dist/esm/packages/draw/src/canvas/DrawCanvas.js +0 -325
  25. package/dist/esm/packages/draw/src/canvas/DrawContext.js +0 -21
  26. package/dist/esm/packages/draw/src/canvas/shapes/avatar/AvatarShapeTool.js +0 -270
  27. package/dist/esm/packages/draw/src/canvas/shapes/avatar/IdleState.js +0 -59
  28. package/dist/esm/packages/draw/src/canvas/shapes/avatar/PointingState.js +0 -84
  29. package/dist/esm/packages/draw/src/canvas/shapes/avatar/type.js +0 -36
  30. package/dist/esm/packages/draw/src/canvas/shapes/custom/AudioShape.js +0 -152
  31. package/dist/esm/packages/draw/src/canvas/shapes/custom/CardShape.js +0 -115
  32. package/dist/esm/packages/draw/src/canvas/shapes/custom/FileShape.js +0 -128
  33. package/dist/esm/packages/draw/src/canvas/shapes/custom/ImageShape.js +0 -137
  34. package/dist/esm/packages/draw/src/canvas/shapes/custom/VideoShape.js +0 -160
  35. package/dist/esm/packages/draw/src/index.js +0 -3
  36. package/dist/types/canvas/DrawCanvas.d.ts +0 -13
  37. package/dist/types/canvas/DrawContext.d.ts +0 -6
  38. package/dist/types/canvas/shapes/avatar/AvatarShapeTool.d.ts +0 -37
  39. package/dist/types/canvas/shapes/avatar/IdleState.d.ts +0 -8
  40. package/dist/types/canvas/shapes/avatar/PointingState.d.ts +0 -13
  41. package/dist/types/canvas/shapes/avatar/type.d.ts +0 -9
  42. package/dist/types/canvas/shapes/custom/AudioShape.d.ts +0 -18
  43. package/dist/types/canvas/shapes/custom/CardShape.d.ts +0 -23
  44. package/dist/types/canvas/shapes/custom/FileShape.d.ts +0 -18
  45. package/dist/types/canvas/shapes/custom/ImageShape.d.ts +0 -29
  46. package/dist/types/canvas/shapes/custom/VideoShape.d.ts +0 -32
  47. package/src/canvas/DrawCanvas.tsx +0 -291
  48. package/src/canvas/DrawContext.tsx +0 -36
  49. package/src/canvas/shapes/avatar/AvatarShapeTool.tsx +0 -234
  50. package/src/canvas/shapes/avatar/IdleState.ts +0 -61
  51. package/src/canvas/shapes/avatar/PointingState.ts +0 -97
  52. package/src/canvas/shapes/avatar/type.ts +0 -41
  53. package/src/canvas/shapes/custom/AudioShape.tsx +0 -134
  54. package/src/canvas/shapes/custom/CardShape.tsx +0 -106
  55. package/src/canvas/shapes/custom/FileShape.tsx +0 -101
  56. package/src/canvas/shapes/custom/ImageShape.tsx +0 -138
  57. package/src/canvas/shapes/custom/VideoShape.tsx +0 -170
@@ -1,326 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
5
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
6
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
8
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
9
- var core = require('@react-fabric/core');
10
- var utilities = require('@react-fabric/utilities');
11
- var tldraw = require('@tldraw/tldraw');
12
- require('@tldraw/tldraw/tldraw.css');
13
- var react = require('react');
14
- var DrawContext = require('./DrawContext.js');
15
- var AvatarShapeTool = require('./shapes/avatar/AvatarShapeTool.js');
16
- var AudioShape = require('./shapes/custom/AudioShape.js');
17
- var CardShape = require('./shapes/custom/CardShape.js');
18
- var FileShape = require('./shapes/custom/FileShape.js');
19
- var ImageShape = require('./shapes/custom/ImageShape.js');
20
- var VideoShape = require('./shapes/custom/VideoShape.js');
21
- var jsxRuntime = require('react/jsx-runtime');
22
-
23
- var _excluded = ["type"];
24
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
26
- var customAssetUrls = {
27
- icons: {
28
- avatar: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPgo8cGF0aCBkPSJNMjIuOCAyMi44di0yLjRjMC0xLjY1Ni0wLjY3My0zLjE1OC0xLjc1Ny00LjI0M3MtMi41ODctMS43NTctNC4yNDMtMS43NTdoLTkuNmMtMS42NTYgMC0zLjE1OCAwLjY3My00LjI0MyAxLjc1N3MtMS43NTcgMi41ODctMS43NTcgNC4yNDN2Mi40YzAgMC42NjIgMC41MzggMS4yIDEuMiAxLjJzMS4yLTAuNTM4IDEuMi0xLjJ2LTIuNGMwLTAuOTk1IDAuNDAyLTEuODkyIDEuMDU1LTIuNTQ1czEuNTUtMS4wNTUgMi41NDUtMS4wNTVoOS42YzAuOTk1IDAgMS44OTIgMC40MDIgMi41NDUgMS4wNTVzMS4wNTUgMS41NSAxLjA1NSAyLjU0NXYyLjRjMCAwLjY2MiAwLjUzOCAxLjIgMS4yIDEuMnMxLjItMC41MzggMS4yLTEuMnpNMTggNmMwLTEuNjU2LTAuNjczLTMuMTU4LTEuNzU3LTQuMjQzcy0yLjU4Ny0xLjc1Ny00LjI0My0xLjc1Ny0zLjE1OCAwLjY3My00LjI0MyAxLjc1Ny0xLjc1NyAyLjU4Ny0xLjc1NyA0LjI0MyAwLjY3MyAzLjE1OCAxLjc1NyA0LjI0MyAyLjU4NyAxLjc1NyA0LjI0MyAxLjc1NyAzLjE1OC0wLjY3MyA0LjI0My0xLjc1NyAxLjc1Ny0yLjU4NyAxLjc1Ny00LjI0M3pNMTUuNiA2YzAgMC45OTUtMC40MDIgMS44OTItMS4wNTUgMi41NDVzLTEuNTUgMS4wNTUtMi41NDUgMS4wNTUtMS44OTItMC40MDItMi41NDUtMS4wNTUtMS4wNTUtMS41NS0xLjA1NS0yLjU0NSAwLjQwMi0xLjg5MiAxLjA1NS0yLjU0NSAxLjU1LTEuMDU1IDIuNTQ1LTEuMDU1IDEuODkyIDAuNDAyIDIuNTQ1IDEuMDU1IDEuMDU1IDEuNTUgMS4wNTUgMi41NDV6Ij48L3BhdGg+Cjwvc3ZnPgo="
29
- }
30
- };
31
- function getSvgAsDataUrl(_x) {
32
- return _getSvgAsDataUrl.apply(this, arguments);
33
- }
34
- function _getSvgAsDataUrl() {
35
- _getSvgAsDataUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(svg) {
36
- var clone, fileReader, imgs, _loop2, _i, _imgs, svgStr, base64SVG;
37
- return _regeneratorRuntime.wrap(function _callee2$(_context4) {
38
- while (1) switch (_context4.prev = _context4.next) {
39
- case 0:
40
- clone = svg.cloneNode(true);
41
- clone.setAttribute("encoding", 'UTF-8"');
42
- fileReader = new FileReader();
43
- imgs = Array.from(clone.querySelectorAll("image"));
44
- _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
45
- var img, src, blob, base64;
46
- return _regeneratorRuntime.wrap(function _loop2$(_context3) {
47
- while (1) switch (_context3.prev = _context3.next) {
48
- case 0:
49
- img = _imgs[_i];
50
- src = img.getAttribute("xlink:href");
51
- if (!src) {
52
- _context3.next = 13;
53
- break;
54
- }
55
- if (src.startsWith("data:")) {
56
- _context3.next = 13;
57
- break;
58
- }
59
- _context3.next = 6;
60
- return fetch(src);
61
- case 6:
62
- _context3.next = 8;
63
- return _context3.sent.blob();
64
- case 8:
65
- blob = _context3.sent;
66
- _context3.next = 11;
67
- return new Promise(function (resolve, reject) {
68
- fileReader.onload = function () {
69
- return resolve(fileReader.result);
70
- };
71
- fileReader.onerror = function () {
72
- return reject(fileReader.error);
73
- };
74
- fileReader.readAsDataURL(blob);
75
- });
76
- case 11:
77
- base64 = _context3.sent;
78
- img.setAttribute("xlink:href", base64);
79
- case 13:
80
- case "end":
81
- return _context3.stop();
82
- }
83
- }, _loop2);
84
- });
85
- _i = 0, _imgs = imgs;
86
- case 6:
87
- if (!(_i < _imgs.length)) {
88
- _context4.next = 11;
89
- break;
90
- }
91
- return _context4.delegateYield(_loop2(), "t0", 8);
92
- case 8:
93
- _i++;
94
- _context4.next = 6;
95
- break;
96
- case 11:
97
- svgStr = new XMLSerializer().serializeToString(clone); // NOTE: `unescape` works everywhere although deprecated
98
- base64SVG = typeof window !== "undefined" ? window.btoa(unescape(encodeURIComponent(svgStr))) : "";
99
- return _context4.abrupt("return", "data:image/svg+xml;base64,".concat(base64SVG));
100
- case 14:
101
- case "end":
102
- return _context4.stop();
103
- }
104
- }, _callee2);
105
- }));
106
- return _getSvgAsDataUrl.apply(this, arguments);
107
- }
108
- var TypeMap = {
109
- image: "image-card",
110
- video: "video-card",
111
- audio: "audio-card",
112
- file: "file-card",
113
- card: "data-card"
114
- };
115
- var DrawCanvas = function DrawCanvas(_ref) {
116
- var snapshot = _ref.snapshot,
117
- renderer = _ref.renderer,
118
- onUpdate = _ref.onUpdate,
119
- canvasRef = _ref.canvasRef;
120
- var _useState = react.useState(),
121
- _useState2 = _slicedToArray(_useState, 2),
122
- editorRef = _useState2[0],
123
- setEditor = _useState2[1];
124
- var isDark = core.useIsDark();
125
- react.useEffect(function () {
126
- editorRef === null || editorRef === void 0 || editorRef.user.updateUserPreferences({
127
- colorScheme: isDark ? "dark" : "light"
128
- });
129
- }, [editorRef, isDark]);
130
- react.useEffect(function () {
131
- var handler = utilities.debounce(function () {
132
- editorRef && (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(tldraw.getSnapshot(editorRef.store)));
133
- }, 500);
134
- editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterChangeHandler("shape", handler);
135
- editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterCreateHandler("shape", handler);
136
- editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterDeleteHandler("shape", handler);
137
- return function () {
138
- //
139
- };
140
- }, [editorRef]);
141
- react.useLayoutEffect(function () {
142
- setTimeout(function () {
143
- (editorRef === null || editorRef === void 0 ? void 0 : editorRef.store) && snapshot && tldraw.loadSnapshot(editorRef.store, snapshot);
144
- }, 500);
145
- }, [editorRef, snapshot]);
146
- var handleDragOver = react.useCallback(function (e) {
147
- if (!e.dataTransfer.getData("react-fabric/canvas")) {
148
- e.preventDefault();
149
- return false;
150
- }
151
- return true;
152
- }, []);
153
- var handleDrop = react.useCallback(function (e) {
154
- var data = e.dataTransfer.getData("react-fabric/canvas");
155
- if (!data) {
156
- e.preventDefault();
157
- return false;
158
- }
159
- var _JSON$parse = JSON.parse(data),
160
- type = _JSON$parse.type,
161
- props = _objectWithoutProperties(_JSON$parse, _excluded);
162
- if (type in TypeMap) {
163
- var _editorRef$getContain;
164
- var _ref2 = (_editorRef$getContain = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getContainer().getBoundingClientRect()) !== null && _editorRef$getContain !== void 0 ? _editorRef$getContain : {},
165
- _ref2$x = _ref2.x,
166
- x = _ref2$x === void 0 ? 0 : _ref2$x,
167
- _ref2$y = _ref2.y,
168
- y = _ref2$y === void 0 ? 0 : _ref2$y;
169
- editorRef === null || editorRef === void 0 || editorRef.createShape({
170
- type: TypeMap[type],
171
- x: e.clientX - x,
172
- y: e.clientY - y,
173
- props: props
174
- });
175
- }
176
- return true;
177
- }, [editorRef]);
178
- react.useImperativeHandle(canvasRef, function () {
179
- return {
180
- exportPages: function () {
181
- var _exportPages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
182
- var _editorRef$store$getS;
183
- var currentPage, pages, pageSnapshots, _loop;
184
- return _regeneratorRuntime.wrap(function _callee$(_context2) {
185
- while (1) switch (_context2.prev = _context2.next) {
186
- case 0:
187
- currentPage = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageId();
188
- pages = Object.keys((_editorRef$store$getS = editorRef === null || editorRef === void 0 ? void 0 : editorRef.store.getSnapshot().store) !== null && _editorRef$store$getS !== void 0 ? _editorRef$store$getS : {}).filter(function (key) {
189
- return key.startsWith("page:");
190
- });
191
- pageSnapshots = [];
192
- _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
193
- var pg, shapes, svg;
194
- return _regeneratorRuntime.wrap(function _loop$(_context) {
195
- while (1) switch (_context.prev = _context.next) {
196
- case 0:
197
- pg = pages.shift();
198
- _context.next = 3;
199
- return new Promise(function (resolve) {
200
- editorRef === null || editorRef === void 0 || editorRef.addListener("change", function () {
201
- if (editorRef.getCurrentPageId() === pg) {
202
- editorRef.removeListener("change");
203
- resolve(0);
204
- }
205
- });
206
- editorRef === null || editorRef === void 0 || editorRef.setCurrentPage(pg);
207
- });
208
- case 3:
209
- shapes = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageShapeIds();
210
- _context.next = 6;
211
- return editorRef === null || editorRef === void 0 ? void 0 : editorRef.getSvg(_toConsumableArray(shapes), {
212
- scale: 1,
213
- background: true
214
- });
215
- case 6:
216
- svg = _context.sent;
217
- if (!svg) {
218
- _context.next = 17;
219
- break;
220
- }
221
- _context.t0 = pageSnapshots;
222
- _context.t1 = pg;
223
- _context.t2 = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPage().name;
224
- _context.next = 13;
225
- return getSvgAsDataUrl(svg);
226
- case 13:
227
- _context.t3 = _context.sent;
228
- _context.t4 = {
229
- image: _context.t3
230
- };
231
- _context.t5 = {
232
- id: _context.t1,
233
- name: _context.t2,
234
- content: _context.t4
235
- };
236
- _context.t0.push.call(_context.t0, _context.t5);
237
- case 17:
238
- case "end":
239
- return _context.stop();
240
- }
241
- }, _loop);
242
- });
243
- case 4:
244
- if (!pages.length) {
245
- _context2.next = 8;
246
- break;
247
- }
248
- return _context2.delegateYield(_loop(), "t0", 6);
249
- case 6:
250
- _context2.next = 4;
251
- break;
252
- case 8:
253
- currentPage && (editorRef === null || editorRef === void 0 ? void 0 : editorRef.setCurrentPage(currentPage));
254
- return _context2.abrupt("return", pageSnapshots);
255
- case 10:
256
- case "end":
257
- return _context2.stop();
258
- }
259
- }, _callee);
260
- }));
261
- function exportPages() {
262
- return _exportPages.apply(this, arguments);
263
- }
264
- return exportPages;
265
- }()
266
- };
267
- }, [editorRef]);
268
- var TLDraw = react.useMemo(function () {
269
- return /*#__PURE__*/jsxRuntime.jsx(tldraw.Tldraw, {
270
- assetUrls: customAssetUrls,
271
- shapeUtils: [AvatarShapeTool.AvatarShapeUtil, AudioShape.AudioShapeUtil, ImageShape.ImageShapeUtil, VideoShape.VideoShapeUtil, CardShape.CardShapeUtil, FileShape.FileShapeUtil],
272
- tools: [AvatarShapeTool.AvatarShapeTool],
273
- onMount: setEditor,
274
- components: {
275
- Toolbar: function Toolbar(props) {
276
- var tools = tldraw.useTools();
277
- var isAvatarSelected = tldraw.useIsToolSelected(tools.avatar);
278
- return /*#__PURE__*/jsxRuntime.jsxs(tldraw.DefaultToolbar, _objectSpread(_objectSpread({}, props), {}, {
279
- children: [/*#__PURE__*/jsxRuntime.jsx(tldraw.DefaultToolbarContent, {}), /*#__PURE__*/jsxRuntime.jsx(tldraw.TldrawUiMenuItem, _objectSpread(_objectSpread({}, tools.avatar), {}, {
280
- isSelected: isAvatarSelected
281
- }))]
282
- }));
283
- }
284
- },
285
- overrides: {
286
- translations: {
287
- en: {
288
- "tool.avatar": "Avatar"
289
- }
290
- },
291
- tools: function tools(editor, schema) {
292
- schema.avatar = {
293
- id: "avatar",
294
- label: "tool.avatar",
295
- readonlyOk: false,
296
- icon: "avatar",
297
- onSelect: function onSelect() {
298
- editor.setCurrentTool("avatar");
299
- }
300
- };
301
- return _objectSpread({}, schema);
302
- },
303
- actions: function actions(editor, schema) {
304
- delete schema["insert-embed"];
305
- delete schema["insert-media"];
306
- return schema;
307
- }
308
- }
309
- });
310
- }, []);
311
- return /*#__PURE__*/jsxRuntime.jsx(DrawContext.DrawContextProvider, {
312
- renderer: renderer,
313
- children: /*#__PURE__*/jsxRuntime.jsx(core.Section, {
314
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
315
- className: "absolute inset-0",
316
- onDragOver: handleDragOver,
317
- onDrop: handleDrop,
318
- "data-testid": "draw-canvas",
319
- children: TLDraw
320
- })
321
- })
322
- });
323
- };
324
-
325
- exports.DrawCanvas = DrawCanvas;
326
- exports.getSvgAsDataUrl = getSvgAsDataUrl;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
4
- var react = require('react');
5
- var jsxRuntime = require('react/jsx-runtime');
6
-
7
- var _excluded = ["children"];
8
- var DrawContext = /*#__PURE__*/react.createContext({});
9
- var DrawContextProvider = function DrawContextProvider(_ref) {
10
- var children = _ref.children,
11
- props = _objectWithoutProperties(_ref, _excluded);
12
- return /*#__PURE__*/jsxRuntime.jsx(DrawContext.Provider, {
13
- value: props,
14
- children: children
15
- });
16
- };
17
- var useDrawContext = function useDrawContext() {
18
- return react.useContext(DrawContext);
19
- };
20
-
21
- exports.DrawContextProvider = DrawContextProvider;
22
- exports.useDrawContext = useDrawContext;
@@ -1,271 +0,0 @@
1
- 'use strict';
2
-
3
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
4
- var _createClass = require('@babel/runtime/helpers/createClass');
5
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
6
- var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
7
- var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
8
- var _inherits = require('@babel/runtime/helpers/inherits');
9
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
- var core = require('@react-fabric/core');
12
- var editor = require('@tldraw/editor');
13
- var tldraw = require('@tldraw/tldraw');
14
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
15
- var react = require('react');
16
- var IdleState = require('./IdleState.js');
17
- var PointingState = require('./PointingState.js');
18
- var type = require('./type.js');
19
- var jsxRuntime = require('react/jsx-runtime');
20
-
21
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
22
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
23
- var AvatarShapeTool = /*#__PURE__*/function (_StateNode) {
24
- function AvatarShapeTool() {
25
- var _this;
26
- _classCallCheck(this, AvatarShapeTool);
27
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
28
- args[_key] = arguments[_key];
29
- }
30
- _this = _callSuper(this, AvatarShapeTool, [].concat(args));
31
- _defineProperty(_this, "shapeType", "avatar");
32
- return _this;
33
- }
34
- _inherits(AvatarShapeTool, _StateNode);
35
- return _createClass(AvatarShapeTool);
36
- }(editor.StateNode);
37
- _defineProperty(AvatarShapeTool, "id", "avatar");
38
- _defineProperty(AvatarShapeTool, "initial", "idle");
39
- _defineProperty(AvatarShapeTool, "children", function () {
40
- return [IdleState.Idle, PointingState.Pointing];
41
- });
42
- var SIZE_MAP = {
43
- s: 48,
44
- m: 72,
45
- l: 96,
46
- xl: 128
47
- };
48
- var FONT_SIZE_MAP = {
49
- s: 12,
50
- m: 16,
51
- l: 18,
52
- xl: 22
53
- };
54
- var AvatarShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
55
- function AvatarShapeUtil(editor) {
56
- var _this2;
57
- _classCallCheck(this, AvatarShapeUtil);
58
- _this2 = _callSuper(this, AvatarShapeUtil, [editor]);
59
- _defineProperty(_this2, "el", document.createElement("div"));
60
- _defineProperty(_this2, "canEdit", function () {
61
- return true;
62
- });
63
- _defineProperty(_this2, "canResize", function () {
64
- return true;
65
- });
66
- _defineProperty(_this2, "hideRotateHandle", function () {
67
- return true;
68
- });
69
- _defineProperty(_this2, "onChange", function (shape, newText) {
70
- var _ref = shape,
71
- id = _ref.id,
72
- type = _ref.type,
73
- text = _ref.props.text;
74
- if (newText && text.trim() !== newText.trim()) {
75
- _this2.editor.updateShapes([{
76
- id: id,
77
- type: type,
78
- props: {
79
- text: newText.trim()
80
- }
81
- }]);
82
- }
83
- });
84
- _this2.el.style.position = "absolute";
85
- editor.getContainer().appendChild(_this2.el);
86
- return _this2;
87
- }
88
- _inherits(AvatarShapeUtil, _ShapeUtil);
89
- return _createClass(AvatarShapeUtil, [{
90
- key: "getDefaultProps",
91
- value: function getDefaultProps() {
92
- return {
93
- color: "black",
94
- fill: "none",
95
- size: "s",
96
- font: "draw",
97
- text: "person"
98
- };
99
- }
100
- }, {
101
- key: "getSize",
102
- value: function getSize(shape) {
103
- var size = SIZE_MAP[shape.props.size];
104
- this.el.innerHTML = "<div class=\"tl-text-label\" data-font=\"".concat(shape.props.font, "\" style=\"position:relative;align-items:end;font-size:").concat(FONT_SIZE_MAP[shape.props.size], "px;\">\n<div class=\"tl-text-label__inner\">\n <div class=\"tl-text tl-text-content\" style=\"white-space:nowrap;padding:4px;\">\n ").concat(shape.props.text, "\n </div></div></div>");
105
- return {
106
- width: Math.max(size, this.el.offsetWidth),
107
- height: +size + this.el.offsetHeight
108
- };
109
- }
110
- }, {
111
- key: "getGeometry",
112
- value: function getGeometry(shape) {
113
- var _this$getSize = this.getSize(shape),
114
- width = _this$getSize.width,
115
- height = _this$getSize.height;
116
- return new tldraw.Rectangle2d({
117
- width: width,
118
- height: height,
119
- isFilled: true
120
- });
121
- }
122
- }, {
123
- key: "indicator",
124
- value: function indicator(shape) {
125
- var _this$getSize2 = this.getSize(shape),
126
- width = _this$getSize2.width,
127
- height = _this$getSize2.height;
128
- return /*#__PURE__*/jsxRuntime.jsx("rect", {
129
- width: width,
130
- height: height
131
- });
132
- }
133
- }, {
134
- key: "component",
135
- value: function component(shape) {
136
- var _this3 = this,
137
- _theme,
138
- _theme2;
139
- var isDark = core.useIsDark();
140
- var isEditing = tldraw.useIsEditing(shape.id);
141
- var size = SIZE_MAP[shape.props.size];
142
- var theme = tldraw.getDefaultColorTheme({
143
- isDarkMode: isDark
144
- });
145
- var inputRef = react.useRef("");
146
- var _this$getSize3 = this.getSize(shape),
147
- width = _this$getSize3.width,
148
- height = _this$getSize3.height;
149
- react.useEffect(function () {
150
- !isEditing && inputRef.current && _this3.onChange(shape, inputRef.current);
151
- }, [isEditing]);
152
- var bg = "transparent";
153
- if (shape.props.fill === "solid" || shape.props.fill === "pattern") bg = (_theme = theme[shape.props.color]) === null || _theme === void 0 ? void 0 : _theme.semi;
154
- if (shape.props.fill === "semi") bg = isDark ? "#28292e" : "#fcfffe";
155
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
156
- "data-shape-id": shape.id,
157
- style: {
158
- position: "relative",
159
- textAlign: "center",
160
- width: width,
161
- height: height
162
- },
163
- children: [/*#__PURE__*/jsxRuntime.jsx("svg", {
164
- id: "svg-" + shape.id,
165
- viewBox: "0 0 30 30",
166
- width: size,
167
- height: size,
168
- children: /*#__PURE__*/jsxRuntime.jsx("path", {
169
- fill: bg,
170
- stroke: (_theme2 = theme[shape.props.color]) === null || _theme2 === void 0 ? void 0 : _theme2.solid,
171
- d: "M5 27.4996C5 20.2996 8.79988 17.0996 14.9999 17.0996C21.1999 17.0996 25.0001 20.2996 25 27.4996M14.9997 15.6001C18.4792 15.6001 21.2998 12.7794 21.2998 9.30003C21.2998 5.82062 18.4792 3 14.9997 3C11.5203 3 8.69971 5.82062 8.69971 9.30003C8.69971 12.7794 11.5203 15.6001 14.9997 15.6001Z"
172
- })
173
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
174
- id: "label-" + shape.id,
175
- className: "tl-text-label",
176
- "data-isediting": isEditing,
177
- "data-font": shape.props.font,
178
- style: {
179
- alignItems: "end",
180
- fontSize: FONT_SIZE_MAP[shape.props.size],
181
- color: theme[shape.props.color].solid
182
- },
183
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
184
- className: "tl-text-label__inner",
185
- style: {
186
- minWidth: "100%"
187
- },
188
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
189
- className: "tl-text tl-text-content",
190
- style: {
191
- whiteSpace: "nowrap",
192
- padding: 4
193
- },
194
- children: "".concat(shape.props.text)
195
- }), isEditing && /*#__PURE__*/jsxRuntime.jsx("textarea", {
196
- className: "tl-text tl-text-input",
197
- style: {
198
- whiteSpace: "nowrap",
199
- padding: 4,
200
- minWidth: "100%"
201
- },
202
- name: "text",
203
- tabIndex: -1,
204
- autoComplete: "false",
205
- autoCapitalize: "false",
206
- autoCorrect: "false",
207
- autoSave: "false",
208
- placeholder: "",
209
- spellCheck: "true",
210
- wrap: "off",
211
- dir: "auto",
212
- ref: function ref(el) {
213
- return [el === null || el === void 0 ? void 0 : el.select(), el === null || el === void 0 ? void 0 : el.focus()];
214
- },
215
- onKeyDown: function onKeyDown(e) {
216
- return e.key === "Enter" && (e.stopPropagation(), _this3.onChange(shape, inputRef.current), _this3.editor.setEditingShape(null));
217
- },
218
- onChange: function onChange(e) {
219
- return inputRef.current = e.target.value;
220
- },
221
- defaultValue: shape.props.text
222
- })]
223
- })
224
- })]
225
- });
226
- }
227
- }, {
228
- key: "toSvg",
229
- value: function () {
230
- var _toSvg = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(shape) {
231
- var el;
232
- return _regeneratorRuntime.wrap(function _callee$(_context) {
233
- while (1) switch (_context.prev = _context.next) {
234
- case 0:
235
- el = document.querySelector("div[data-shape-id=\"".concat(shape.id, "\"]"));
236
- if (el) {
237
- _context.next = 3;
238
- break;
239
- }
240
- return _context.abrupt("return", /*#__PURE__*/jsxRuntime.jsx("img", {
241
- src: "",
242
- alt: "svg"
243
- }));
244
- case 3:
245
- _context.next = 5;
246
- return domToImage.toPng(el).then(function (dataUrl) {
247
- return /*#__PURE__*/jsxRuntime.jsx("img", {
248
- src: dataUrl,
249
- alt: "svg"
250
- });
251
- });
252
- case 5:
253
- return _context.abrupt("return", _context.sent);
254
- case 6:
255
- case "end":
256
- return _context.stop();
257
- }
258
- }, _callee);
259
- }));
260
- function toSvg(_x) {
261
- return _toSvg.apply(this, arguments);
262
- }
263
- return toSvg;
264
- }()
265
- }]);
266
- }(tldraw.ShapeUtil);
267
- _defineProperty(AvatarShapeUtil, "type", "avatar");
268
- _defineProperty(AvatarShapeUtil, "props", type.AvatarShapeProps);
269
-
270
- exports.AvatarShapeTool = AvatarShapeTool;
271
- exports.AvatarShapeUtil = AvatarShapeUtil;
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- var _createClass = require('@babel/runtime/helpers/createClass');
4
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
- var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
6
- var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
7
- var _inherits = require('@babel/runtime/helpers/inherits');
8
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
9
- var editor = require('@tldraw/editor');
10
-
11
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
14
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
- var Idle = /*#__PURE__*/function (_StateNode) {
16
- function Idle() {
17
- var _this;
18
- _classCallCheck(this, Idle);
19
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
20
- args[_key] = arguments[_key];
21
- }
22
- _this = _callSuper(this, Idle, [].concat(args));
23
- _defineProperty(_this, "onPointerDown", function (info) {
24
- _this.parent.transition("pointing", info);
25
- });
26
- _defineProperty(_this, "onEnter", function () {
27
- _this.editor.setCursor({
28
- type: "cross",
29
- rotation: 0
30
- });
31
- });
32
- _defineProperty(_this, "onCancel", function () {
33
- _this.editor.setCurrentTool("select");
34
- });
35
- _defineProperty(_this, "onKeyUp", function (info) {
36
- if (info.key === "Enter") {
37
- if (_this.editor.getInstanceState().isReadonly) return null;
38
- var onlySelectedShape = _this.editor.getOnlySelectedShape();
39
- // If the only selected shape is editable, start editing it
40
- if (onlySelectedShape && _this.editor.getShapeUtil(onlySelectedShape).canEdit(onlySelectedShape)) {
41
- var _this$editor$root$val;
42
- _this.editor.setCurrentTool("select");
43
- _this.editor.setEditingShape(onlySelectedShape.id);
44
- // @ts-expect-error ignore
45
- (_this$editor$root$val = _this.editor.root.value) === null || _this$editor$root$val === void 0 || _this$editor$root$val.transition("editing_shape", _objectSpread(_objectSpread({}, info), {}, {
46
- target: "shape",
47
- shape: onlySelectedShape
48
- }));
49
- }
50
- }
51
- });
52
- return _this;
53
- }
54
- _inherits(Idle, _StateNode);
55
- return _createClass(Idle);
56
- }(editor.StateNode);
57
- _defineProperty(Idle, "id", "idle");
58
-
59
- exports.Idle = Idle;