@react-fabric/draw 1.0.0-beta.3

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/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/cjs/_virtual/_commonjsHelpers.js +7 -0
  4. package/dist/cjs/_virtual/dom-to-image.js +5 -0
  5. package/dist/cjs/node_modules/dom-to-image/src/dom-to-image.js +777 -0
  6. package/dist/cjs/packages/draw/src/canvas/DrawCanvas.js +299 -0
  7. package/dist/cjs/packages/draw/src/canvas/DrawContext.js +22 -0
  8. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/AvatarShapeTool.js +271 -0
  9. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/IdleState.js +59 -0
  10. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/PointingState.js +84 -0
  11. package/dist/cjs/packages/draw/src/canvas/shapes/avatar/type.js +36 -0
  12. package/dist/cjs/packages/draw/src/canvas/shapes/custom/AudioShape.js +152 -0
  13. package/dist/cjs/packages/draw/src/canvas/shapes/custom/CardShape.js +115 -0
  14. package/dist/cjs/packages/draw/src/canvas/shapes/custom/FileShape.js +128 -0
  15. package/dist/cjs/packages/draw/src/canvas/shapes/custom/ImageShape.js +137 -0
  16. package/dist/cjs/packages/draw/src/canvas/shapes/custom/VideoShape.js +160 -0
  17. package/dist/cjs/packages/draw/src/index.js +7 -0
  18. package/dist/esm/_virtual/_commonjsHelpers.js +7 -0
  19. package/dist/esm/_virtual/dom-to-image.js +5 -0
  20. package/dist/esm/node_modules/dom-to-image/src/dom-to-image.js +777 -0
  21. package/dist/esm/packages/draw/src/canvas/DrawCanvas.js +298 -0
  22. package/dist/esm/packages/draw/src/canvas/DrawContext.js +21 -0
  23. package/dist/esm/packages/draw/src/canvas/shapes/avatar/AvatarShapeTool.js +270 -0
  24. package/dist/esm/packages/draw/src/canvas/shapes/avatar/IdleState.js +59 -0
  25. package/dist/esm/packages/draw/src/canvas/shapes/avatar/PointingState.js +84 -0
  26. package/dist/esm/packages/draw/src/canvas/shapes/avatar/type.js +36 -0
  27. package/dist/esm/packages/draw/src/canvas/shapes/custom/AudioShape.js +152 -0
  28. package/dist/esm/packages/draw/src/canvas/shapes/custom/CardShape.js +115 -0
  29. package/dist/esm/packages/draw/src/canvas/shapes/custom/FileShape.js +128 -0
  30. package/dist/esm/packages/draw/src/canvas/shapes/custom/ImageShape.js +137 -0
  31. package/dist/esm/packages/draw/src/canvas/shapes/custom/VideoShape.js +160 -0
  32. package/dist/esm/packages/draw/src/index.js +3 -0
  33. package/dist/types/canvas/DrawCanvas.d.ts +13 -0
  34. package/dist/types/canvas/DrawContext.d.ts +6 -0
  35. package/dist/types/canvas/shapes/avatar/AvatarShapeTool.d.ts +37 -0
  36. package/dist/types/canvas/shapes/avatar/IdleState.d.ts +8 -0
  37. package/dist/types/canvas/shapes/avatar/PointingState.d.ts +13 -0
  38. package/dist/types/canvas/shapes/avatar/type.d.ts +9 -0
  39. package/dist/types/canvas/shapes/custom/AudioShape.d.ts +18 -0
  40. package/dist/types/canvas/shapes/custom/CardShape.d.ts +23 -0
  41. package/dist/types/canvas/shapes/custom/FileShape.d.ts +18 -0
  42. package/dist/types/canvas/shapes/custom/ImageShape.d.ts +29 -0
  43. package/dist/types/canvas/shapes/custom/VideoShape.d.ts +32 -0
  44. package/dist/types/index.d.ts +1 -0
  45. package/package.json +54 -0
  46. package/src/canvas/DrawCanvas.tsx +256 -0
  47. package/src/canvas/DrawContext.tsx +36 -0
  48. package/src/canvas/shapes/avatar/AvatarShapeTool.tsx +234 -0
  49. package/src/canvas/shapes/avatar/IdleState.ts +61 -0
  50. package/src/canvas/shapes/avatar/PointingState.ts +97 -0
  51. package/src/canvas/shapes/avatar/type.ts +41 -0
  52. package/src/canvas/shapes/custom/AudioShape.tsx +134 -0
  53. package/src/canvas/shapes/custom/CardShape.tsx +106 -0
  54. package/src/canvas/shapes/custom/FileShape.tsx +101 -0
  55. package/src/canvas/shapes/custom/ImageShape.tsx +138 -0
  56. package/src/canvas/shapes/custom/VideoShape.tsx +170 -0
  57. package/src/index.ts +24 -0
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
4
+ var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
+ var _createClass = require('@babel/runtime/helpers/createClass');
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 utilities = require('@react-fabric/utilities');
12
+ var tldraw = require('@tldraw/tldraw');
13
+ var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
14
+ var react = require('react');
15
+ var jsxRuntime = require('react/jsx-runtime');
16
+
17
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
18
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
19
+ var VideoShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
20
+ function VideoShapeUtil() {
21
+ _classCallCheck(this, VideoShapeUtil);
22
+ return _callSuper(this, VideoShapeUtil, arguments);
23
+ }
24
+ _inherits(VideoShapeUtil, _ShapeUtil);
25
+ return _createClass(VideoShapeUtil, [{
26
+ key: "onResize",
27
+ value: function onResize(shape, info) {
28
+ return {
29
+ props: {
30
+ w: Math.max(Math.min(info.initialBounds.w * info.scaleX, 1024), 128),
31
+ h: Math.max(Math.min(info.initialBounds.h * info.scaleY, 768), 128)
32
+ }
33
+ };
34
+ }
35
+ }, {
36
+ key: "getDefaultProps",
37
+ value: function getDefaultProps() {
38
+ return {
39
+ src: "",
40
+ poster: "",
41
+ fileName: "",
42
+ fileSize: 0,
43
+ w: 400,
44
+ h: 300
45
+ };
46
+ }
47
+ }, {
48
+ key: "getGeometry",
49
+ value: function getGeometry(shape) {
50
+ return new tldraw.Rectangle2d({
51
+ width: shape.props.w,
52
+ height: shape.props.h,
53
+ isFilled: true
54
+ });
55
+ }
56
+ }, {
57
+ key: "component",
58
+ value: function component(shape) {
59
+ var _shape$props$fileSize;
60
+ var videoRef = react.useRef(null);
61
+ react.useEffect(function () {
62
+ var _videoRef$current2;
63
+ var handler = function handler() {
64
+ var _videoRef$current;
65
+ (_videoRef$current = videoRef.current) === null || _videoRef$current === void 0 || (_videoRef$current = _videoRef$current.closest(".tl-container")) === null || _videoRef$current === void 0 || _videoRef$current.querySelectorAll("video,audio").forEach(function (el) {
66
+ if (el !== videoRef.current) el.pause();
67
+ });
68
+ };
69
+ (_videoRef$current2 = videoRef.current) === null || _videoRef$current2 === void 0 || _videoRef$current2.addEventListener("play", handler);
70
+ }, []);
71
+ return /*#__PURE__*/jsxRuntime.jsx(tldraw.HTMLContainer, {
72
+ className: "relative grid",
73
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
74
+ "data-shape-id": shape.id,
75
+ className: "bg-zinc-900 relative p-1 flex flex-col overflow-hidden",
76
+ children: [/*#__PURE__*/jsxRuntime.jsx("video", {
77
+ controls: true,
78
+ ref: videoRef,
79
+ src: shape.props.src,
80
+ poster: shape.props.poster,
81
+ className: "object-contain flex-1 pointer-events-auto overflow-hidden"
82
+ }), /*#__PURE__*/jsxRuntime.jsx("img", {
83
+ src: shape.props.poster,
84
+ alt: shape.props.fileName,
85
+ className: "object-contain flex-1 pointer-events-auto overflow-hidden hidden"
86
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
87
+ className: "bg-zinc-800/80 text-white items-center py-1 px-2 flex gap-1 text-sm",
88
+ children: [/*#__PURE__*/jsxRuntime.jsx("svg", {
89
+ xmlns: "http://www.w3.org/2000/svg",
90
+ viewBox: "0 0 24 24",
91
+ width: 16,
92
+ height: 16,
93
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
94
+ d: "M17,10.5V7A1,1 0 0,0 16,6H4A1,1 0 0,0 3,7V17A1,1 0 0,0 4,18H16A1,1 0 0,0 17,17V13.5L21,17.5V6.5L17,10.5Z"
95
+ })
96
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
97
+ className: "truncate flex-1",
98
+ children: shape.props.fileName
99
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
100
+ children: utilities.Format.bytes((_shape$props$fileSize = shape.props.fileSize) !== null && _shape$props$fileSize !== void 0 ? _shape$props$fileSize : 0)
101
+ })]
102
+ })]
103
+ })
104
+ });
105
+ }
106
+ }, {
107
+ key: "indicator",
108
+ value: function indicator(shape) {
109
+ return /*#__PURE__*/jsxRuntime.jsx("rect", {
110
+ width: shape.props.w,
111
+ height: shape.props.h
112
+ });
113
+ }
114
+ }, {
115
+ key: "toSvg",
116
+ value: function () {
117
+ var _toSvg = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(shape) {
118
+ var el;
119
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
120
+ while (1) switch (_context.prev = _context.next) {
121
+ case 0:
122
+ el = document.querySelector("div[data-shape-id=\"".concat(shape.id, "\"]"));
123
+ if (el) {
124
+ _context.next = 3;
125
+ break;
126
+ }
127
+ return _context.abrupt("return", /*#__PURE__*/jsxRuntime.jsx("img", {
128
+ src: "",
129
+ alt: "svg"
130
+ }));
131
+ case 3:
132
+ el.childNodes.item(0).style.display = "none";
133
+ el.childNodes.item(1).style.display = "block";
134
+ _context.next = 7;
135
+ return domToImage.toPng(el).then(function (dataUrl) {
136
+ el.childNodes.item(0).style.display = "block";
137
+ el.childNodes.item(1).style.display = "none";
138
+ return /*#__PURE__*/jsxRuntime.jsx("img", {
139
+ src: dataUrl,
140
+ alt: "svg"
141
+ });
142
+ });
143
+ case 7:
144
+ return _context.abrupt("return", _context.sent);
145
+ case 8:
146
+ case "end":
147
+ return _context.stop();
148
+ }
149
+ }, _callee);
150
+ }));
151
+ function toSvg(_x) {
152
+ return _toSvg.apply(this, arguments);
153
+ }
154
+ return toSvg;
155
+ }()
156
+ }]);
157
+ }(tldraw.ShapeUtil);
158
+ _defineProperty(VideoShapeUtil, "type", "video-card");
159
+
160
+ exports.VideoShapeUtil = VideoShapeUtil;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var DrawCanvas = require('./canvas/DrawCanvas.js');
4
+
5
+
6
+
7
+ exports.DrawCanvas = DrawCanvas.DrawCanvas;
@@ -0,0 +1,7 @@
1
+ 'use client';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ export { getDefaultExportFromCjs };
@@ -0,0 +1,5 @@
1
+ 'use client';
2
+
3
+ var domToImage = {exports: {}};
4
+
5
+ export { domToImage as __module };