@netless/fastboard 0.0.4 → 0.0.5

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.es.js CHANGED
@@ -17,12 +17,24 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __publicField = (obj, key, value) => {
21
33
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
34
  return value;
23
35
  };
24
36
  import { WindowManager } from "@netless/window-manager";
25
- import { WhiteWebSdk, DefaultHotKeys, ApplianceNames, ShapeType } from "white-web-sdk";
37
+ import { WhiteWebSdk, DefaultHotKeys, ApplianceNames, ShapeType, PlayerPhase } from "white-web-sdk";
26
38
  import i18next from "i18next";
27
39
  import require$$0, { memo, forwardRef, useContext, useCallback, useState, useEffect, useRef, createContext } from "react";
28
40
  import ReactDOM from "react-dom";
@@ -580,7 +592,7 @@ const Up = (props) => {
580
592
  })
581
593
  });
582
594
  };
583
- const Icons = {
595
+ const Icons$1 = {
584
596
  Clicker: memo(Clicker),
585
597
  Collapse: memo(Collapse),
586
598
  Eraser: memo(Eraser),
@@ -601,7 +613,7 @@ const Icons = {
601
613
  Up: memo(Up),
602
614
  Down: memo(Down)
603
615
  };
604
- const Button = forwardRef((props, ref) => {
616
+ const Button$1 = forwardRef((props, ref) => {
605
617
  const {
606
618
  content,
607
619
  disabled,
@@ -640,7 +652,7 @@ function CutLine() {
640
652
  theme
641
653
  } = useContext(ToolbarContext);
642
654
  return /* @__PURE__ */ jsx("span", {
643
- className: clsx(`${name$3}-cut-line`, theme)
655
+ className: clsx(`${name$4}-cut-line`, theme)
644
656
  });
645
657
  }
646
658
  function useWritable(room) {
@@ -714,14 +726,14 @@ const EmptyToolbarHook = {
714
726
  setStrokeColor: noop
715
727
  };
716
728
  const ShapesMap = {
717
- [ApplianceNames.rectangle]: Icons.Rectangle,
718
- [ApplianceNames.ellipse]: Icons.Circle,
719
- [ApplianceNames.straight]: Icons.Line,
720
- [ApplianceNames.arrow]: Icons.Arrow,
721
- [ShapeType.Pentagram]: Icons.Star,
722
- [ShapeType.Rhombus]: Icons.Diamond,
723
- [ShapeType.Triangle]: Icons.Triangle,
724
- [ShapeType.SpeechBalloon]: Icons.SpeechBalloon
729
+ [ApplianceNames.rectangle]: Icons$1.Rectangle,
730
+ [ApplianceNames.ellipse]: Icons$1.Circle,
731
+ [ApplianceNames.straight]: Icons$1.Line,
732
+ [ApplianceNames.arrow]: Icons$1.Arrow,
733
+ [ShapeType.Pentagram]: Icons$1.Star,
734
+ [ShapeType.Rhombus]: Icons$1.Diamond,
735
+ [ShapeType.Triangle]: Icons$1.Triangle,
736
+ [ShapeType.SpeechBalloon]: Icons$1.SpeechBalloon
725
737
  };
726
738
  const ApplianceShapes = [
727
739
  ApplianceNames.rectangle,
@@ -749,12 +761,12 @@ function UpButton({
749
761
  } = useContext(ToolbarContext);
750
762
  const scrollUp = useCallback(() => scrollTo(-ItemHeight), [scrollTo]);
751
763
  return /* @__PURE__ */ jsxs(Fragment, {
752
- children: [/* @__PURE__ */ jsx(Button, {
764
+ children: [/* @__PURE__ */ jsx(Button$1, {
753
765
  content: "Up",
754
766
  disabled,
755
767
  onClick: scrollUp,
756
768
  children: /* @__PURE__ */ jsx(Icon, {
757
- fallback: /* @__PURE__ */ jsx(Icons.Up, {
769
+ fallback: /* @__PURE__ */ jsx(Icons$1.Up, {
758
770
  theme
759
771
  }),
760
772
  src: disabled ? icons == null ? void 0 : icons.upIconDisable : icons == null ? void 0 : icons.upIcon,
@@ -773,12 +785,12 @@ function DownButton({
773
785
  } = useContext(ToolbarContext);
774
786
  const scrollDown = useCallback(() => scrollTo(ItemHeight), [scrollTo]);
775
787
  return /* @__PURE__ */ jsxs(Fragment, {
776
- children: [/* @__PURE__ */ jsx(CutLine, {}), /* @__PURE__ */ jsx(Button, {
788
+ children: [/* @__PURE__ */ jsx(CutLine, {}), /* @__PURE__ */ jsx(Button$1, {
777
789
  content: "Down",
778
790
  disabled,
779
791
  onClick: scrollDown,
780
792
  children: /* @__PURE__ */ jsx(Icon, {
781
- fallback: /* @__PURE__ */ jsx(Icons.Down, {
793
+ fallback: /* @__PURE__ */ jsx(Icons$1.Down, {
782
794
  theme
783
795
  }),
784
796
  src: disabled ? icons == null ? void 0 : icons.downIconDisable : icons == null ? void 0 : icons.downIcon,
@@ -816,12 +828,12 @@ function ClickerButton() {
816
828
  const appliance = memberState == null ? void 0 : memberState.currentApplianceName;
817
829
  const active = appliance === ApplianceNames.clicker;
818
830
  const disabled = !writable;
819
- return /* @__PURE__ */ jsx(Button, {
831
+ return /* @__PURE__ */ jsx(Button$1, {
820
832
  content: renderToolTip(i18n == null ? void 0 : i18n.t("clicker"), shortcut),
821
833
  onClick: changeAppliance,
822
834
  active,
823
835
  children: /* @__PURE__ */ jsx(Icon, {
824
- fallback: /* @__PURE__ */ jsx(Icons.Clicker, {
836
+ fallback: /* @__PURE__ */ jsx(Icons$1.Clicker, {
825
837
  theme,
826
838
  active
827
839
  }),
@@ -845,12 +857,12 @@ function SelectorButton() {
845
857
  const active = appliance === ApplianceNames.selector;
846
858
  const disabled = !writable;
847
859
  const shortcut = ((app == null ? void 0 : app.config.joinRoom.hotKeys) || defaultHotKeys).changeToSelector;
848
- return /* @__PURE__ */ jsx(Button, {
860
+ return /* @__PURE__ */ jsx(Button$1, {
849
861
  content: renderToolTip(i18n == null ? void 0 : i18n.t("selector"), shortcut),
850
862
  onClick: changeAppliance,
851
863
  active,
852
864
  children: /* @__PURE__ */ jsx(Icon, {
853
- fallback: /* @__PURE__ */ jsx(Icons.Selector, {
865
+ fallback: /* @__PURE__ */ jsx(Icons$1.Selector, {
854
866
  theme,
855
867
  active
856
868
  }),
@@ -874,12 +886,12 @@ function EraserButton() {
874
886
  const active = appliance === ApplianceNames.eraser;
875
887
  const disabled = !writable;
876
888
  const shortcut = ((app == null ? void 0 : app.config.joinRoom.hotKeys) || defaultHotKeys).changeToEraser;
877
- return /* @__PURE__ */ jsx(Button, {
889
+ return /* @__PURE__ */ jsx(Button$1, {
878
890
  content: renderToolTip(i18n == null ? void 0 : i18n.t("eraser"), shortcut),
879
891
  onClick: changeAppliance,
880
892
  active,
881
893
  children: /* @__PURE__ */ jsx(Icon, {
882
- fallback: /* @__PURE__ */ jsx(Icons.Eraser, {
894
+ fallback: /* @__PURE__ */ jsx(Icons$1.Eraser, {
883
895
  theme,
884
896
  active
885
897
  }),
@@ -897,11 +909,11 @@ function CleanButton() {
897
909
  i18n
898
910
  } = useContext(ToolbarContext);
899
911
  const disabled = !writable;
900
- return /* @__PURE__ */ jsx(Button, {
912
+ return /* @__PURE__ */ jsx(Button$1, {
901
913
  content: i18n == null ? void 0 : i18n.t("clean"),
902
914
  onClick: cleanCurrentScene,
903
915
  children: /* @__PURE__ */ jsx(Icon, {
904
- fallback: /* @__PURE__ */ jsx(Icons.Clean, {
916
+ fallback: /* @__PURE__ */ jsx(Icons$1.Clean, {
905
917
  theme
906
918
  }),
907
919
  src: disabled ? icons == null ? void 0 : icons.cleanIconDisable : icons == null ? void 0 : icons.cleanIcon,
@@ -922,11 +934,11 @@ function AppsButton({
922
934
  writable
923
935
  } = useContext(ToolbarContext);
924
936
  const disabled = !writable;
925
- const button = /* @__PURE__ */ jsx(Button, {
937
+ const button = /* @__PURE__ */ jsx(Button$1, {
926
938
  content: "Apps",
927
939
  onClick,
928
940
  children: /* @__PURE__ */ jsx(Icon, {
929
- fallback: /* @__PURE__ */ jsx(Icons.Apps, {
941
+ fallback: /* @__PURE__ */ jsx(Icons$1.Apps, {
930
942
  theme
931
943
  }),
932
944
  src: disabled ? icons == null ? void 0 : icons.appsIconDisable : icons == null ? void 0 : icons.appsIcon,
@@ -986,7 +998,7 @@ function AppIcon({
986
998
  }) {
987
999
  return /* @__PURE__ */ jsxs("span", {
988
1000
  className: "fastboard-toolbar-app-icon",
989
- children: [/* @__PURE__ */ jsx(Button, {
1001
+ children: [/* @__PURE__ */ jsx(Button$1, {
990
1002
  placement: "top",
991
1003
  content: title,
992
1004
  onClick,
@@ -1099,12 +1111,12 @@ function PencilButton() {
1099
1111
  offset: RightOffset,
1100
1112
  arrow: false,
1101
1113
  interactive: true,
1102
- children: /* @__PURE__ */ jsxs(Button, {
1114
+ children: /* @__PURE__ */ jsxs(Button$1, {
1103
1115
  content: renderToolTip(i18n == null ? void 0 : i18n.t("pencil"), shortcut),
1104
1116
  active,
1105
1117
  onClick: changeAppliance,
1106
1118
  children: [/* @__PURE__ */ jsx(Icon, {
1107
- fallback: /* @__PURE__ */ jsx(Icons.Pencil, {
1119
+ fallback: /* @__PURE__ */ jsx(Icons$1.Pencil, {
1108
1120
  theme,
1109
1121
  active
1110
1122
  }),
@@ -1151,12 +1163,12 @@ function TextButton() {
1151
1163
  offset: RightOffset,
1152
1164
  arrow: false,
1153
1165
  interactive: true,
1154
- children: /* @__PURE__ */ jsxs(Button, {
1166
+ children: /* @__PURE__ */ jsxs(Button$1, {
1155
1167
  content: renderToolTip(i18n == null ? void 0 : i18n.t("text"), shortcut),
1156
1168
  active,
1157
1169
  onClick: changeAppliance,
1158
1170
  children: [/* @__PURE__ */ jsx(Icon, {
1159
- fallback: /* @__PURE__ */ jsx(Icons.Text, {
1171
+ fallback: /* @__PURE__ */ jsx(Icons$1.Text, {
1160
1172
  theme,
1161
1173
  active
1162
1174
  }),
@@ -1186,7 +1198,7 @@ function ShapesButton() {
1186
1198
  const shape = memberState == null ? void 0 : memberState.shapeType;
1187
1199
  const key = appliance === ApplianceNames.shape ? shape : appliance;
1188
1200
  const active = ShapeTypes.has(key);
1189
- const CurrentIcon = ShapesMap[key] || Icons.Rectangle;
1201
+ const CurrentIcon = ShapesMap[key] || Icons$1.Rectangle;
1190
1202
  return /* @__PURE__ */ jsx("span", {
1191
1203
  className: "fastboard-toolbar-btn-interactive",
1192
1204
  children: /* @__PURE__ */ jsx(Tippy, {
@@ -1198,7 +1210,7 @@ function ShapesButton() {
1198
1210
  offset: RightOffset,
1199
1211
  arrow: false,
1200
1212
  interactive: true,
1201
- children: /* @__PURE__ */ jsxs(Button, {
1213
+ children: /* @__PURE__ */ jsxs(Button$1, {
1202
1214
  content: i18n == null ? void 0 : i18n.t("shape"),
1203
1215
  active,
1204
1216
  children: [/* @__PURE__ */ jsx(CurrentIcon, {
@@ -1247,7 +1259,7 @@ function ApplianceShapeButton({
1247
1259
  } = useContext(ToolbarContext);
1248
1260
  const current = memberState == null ? void 0 : memberState.currentApplianceName;
1249
1261
  const disabled = !writable;
1250
- return /* @__PURE__ */ jsx(Button, {
1262
+ return /* @__PURE__ */ jsx(Button$1, {
1251
1263
  content,
1252
1264
  disabled,
1253
1265
  placement: "top",
@@ -1272,7 +1284,7 @@ function ShapeShapeButton({
1272
1284
  const appliance = memberState == null ? void 0 : memberState.currentApplianceName;
1273
1285
  const current = appliance === ApplianceNames.shape && (memberState == null ? void 0 : memberState.shapeType);
1274
1286
  const disabled = !writable;
1275
- return /* @__PURE__ */ jsx(Button, {
1287
+ return /* @__PURE__ */ jsx(Button$1, {
1276
1288
  content,
1277
1289
  disabled,
1278
1290
  placement: "top",
@@ -1325,7 +1337,7 @@ function Content() {
1325
1337
  disabled: disableScrollUp
1326
1338
  }), /* @__PURE__ */ jsxs("div", {
1327
1339
  ref,
1328
- className: `${name$3}-section`,
1340
+ className: `${name$4}-section`,
1329
1341
  style: {
1330
1342
  height: `${sectionHeight}px`,
1331
1343
  overflow: needScroll ? "hidden" : "visible"
@@ -1343,7 +1355,7 @@ function Content() {
1343
1355
  const ToolbarContext = createContext(__spreadValues({
1344
1356
  theme: "light"
1345
1357
  }, EmptyToolbarHook));
1346
- const name$3 = "fastboard-toolbar";
1358
+ const name$4 = "fastboard-toolbar";
1347
1359
  const Toolbar = ({
1348
1360
  theme = "light",
1349
1361
  icons,
@@ -1362,21 +1374,21 @@ const Toolbar = ({
1362
1374
  i18n
1363
1375
  }),
1364
1376
  children: /* @__PURE__ */ jsxs("div", {
1365
- className: clsx(name$3, theme),
1366
- children: [expanded ? /* @__PURE__ */ jsx(Button, {
1377
+ className: clsx(name$4, theme),
1378
+ children: [expanded ? /* @__PURE__ */ jsx(Button$1, {
1367
1379
  content: i18n == null ? void 0 : i18n.t("collapse"),
1368
1380
  onClick: toggle,
1369
1381
  children: /* @__PURE__ */ jsx(Icon, {
1370
- fallback: /* @__PURE__ */ jsx(Icons.Collapse, {
1382
+ fallback: /* @__PURE__ */ jsx(Icons$1.Collapse, {
1371
1383
  theme
1372
1384
  }),
1373
1385
  src: disabled ? icons == null ? void 0 : icons.collapseIconDisable : icons == null ? void 0 : icons.collapseIcon
1374
1386
  })
1375
- }) : /* @__PURE__ */ jsx(Button, {
1387
+ }) : /* @__PURE__ */ jsx(Button$1, {
1376
1388
  content: i18n == null ? void 0 : i18n.t("expand"),
1377
1389
  onClick: toggle,
1378
1390
  children: /* @__PURE__ */ jsx(Icon, {
1379
- fallback: /* @__PURE__ */ jsx(Icons.Expand, {
1391
+ fallback: /* @__PURE__ */ jsx(Icons$1.Expand, {
1380
1392
  theme
1381
1393
  }),
1382
1394
  src: disabled ? icons == null ? void 0 : icons.expandIconDisable : icons == null ? void 0 : icons.expandIcon
@@ -1431,7 +1443,7 @@ function Redo({
1431
1443
  })
1432
1444
  });
1433
1445
  }
1434
- const name$2 = "fastboard-redo-undo";
1446
+ const name$3 = "fastboard-redo-undo";
1435
1447
  function RedoUndo({
1436
1448
  room,
1437
1449
  theme = "light",
@@ -1461,7 +1473,7 @@ function RedoUndo({
1461
1473
  }, [room]);
1462
1474
  const disabled = !writable;
1463
1475
  return /* @__PURE__ */ jsxs("div", {
1464
- className: clsx(name$2, theme),
1476
+ className: clsx(name$3, theme),
1465
1477
  children: [/* @__PURE__ */ jsx(Tippy, {
1466
1478
  className: "fastboard-tip",
1467
1479
  content: i18n == null ? void 0 : i18n.t("undo"),
@@ -1471,7 +1483,7 @@ function RedoUndo({
1471
1483
  duration: 300,
1472
1484
  offset: TopOffset,
1473
1485
  children: /* @__PURE__ */ jsx("button", {
1474
- className: clsx(`${name$2}-btn`, "undo", theme),
1486
+ className: clsx(`${name$3}-btn`, "undo", theme),
1475
1487
  disabled: disabled || undoSteps === 0,
1476
1488
  onClick: useCallback(() => room && room.undo(), [room]),
1477
1489
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1491,7 +1503,7 @@ function RedoUndo({
1491
1503
  duration: 300,
1492
1504
  offset: TopOffset,
1493
1505
  children: /* @__PURE__ */ jsx("button", {
1494
- className: clsx(`${name$2}-btn`, "redo", theme),
1506
+ className: clsx(`${name$3}-btn`, "redo", theme),
1495
1507
  disabled: disabled || redoSteps === 0,
1496
1508
  onClick: useCallback(() => room && room.redo(), [room]),
1497
1509
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1569,7 +1581,7 @@ function Reset({
1569
1581
  })
1570
1582
  });
1571
1583
  }
1572
- const name$1 = "fastboard-zoom-control";
1584
+ const name$2 = "fastboard-zoom-control";
1573
1585
  const ScalePoints = [0.10737418240000011, 0.13421772800000012, 0.16777216000000014, 0.20971520000000016, 0.26214400000000015, 0.3276800000000002, 0.4096000000000002, 0.5120000000000001, 0.6400000000000001, 0.8, 1, 1.26, 1.5876000000000001, 2.000376, 2.5204737600000002, 3.1757969376000004, 4.001504141376, 5.041895218133761, 6.352787974848539, 8.00451284830916, 10];
1574
1586
  function nextScale(scale, delta) {
1575
1587
  const {
@@ -1697,7 +1709,7 @@ function ZoomControl({
1697
1709
  }, [room, manager]);
1698
1710
  const disabled = !writable;
1699
1711
  return /* @__PURE__ */ jsxs("div", {
1700
- className: clsx(name$1, theme),
1712
+ className: clsx(name$2, theme),
1701
1713
  children: [/* @__PURE__ */ jsx(Tippy, {
1702
1714
  className: "fastboard-tip",
1703
1715
  content: i18n == null ? void 0 : i18n.t("zoomOut"),
@@ -1707,7 +1719,7 @@ function ZoomControl({
1707
1719
  duration: 300,
1708
1720
  offset: TopOffset,
1709
1721
  children: /* @__PURE__ */ jsx("button", {
1710
- className: clsx(`${name$1}-btn`, "minus", theme),
1722
+ className: clsx(`${name$2}-btn`, "minus", theme),
1711
1723
  disabled,
1712
1724
  onClick: zoomOut,
1713
1725
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1719,10 +1731,10 @@ function ZoomControl({
1719
1731
  })
1720
1732
  })
1721
1733
  }), /* @__PURE__ */ jsx("span", {
1722
- className: clsx(`${name$1}-scale`, theme),
1734
+ className: clsx(`${name$2}-scale`, theme),
1723
1735
  children: Math.ceil(scale * 100)
1724
1736
  }), /* @__PURE__ */ jsx("span", {
1725
- className: clsx(`${name$1}-percent`, theme),
1737
+ className: clsx(`${name$2}-percent`, theme),
1726
1738
  children: "%"
1727
1739
  }), /* @__PURE__ */ jsx(Tippy, {
1728
1740
  className: "fastboard-tip",
@@ -1733,7 +1745,7 @@ function ZoomControl({
1733
1745
  duration: 300,
1734
1746
  offset: TopOffset,
1735
1747
  children: /* @__PURE__ */ jsx("button", {
1736
- className: clsx(`${name$1}-btn`, "plus", theme),
1748
+ className: clsx(`${name$2}-btn`, "plus", theme),
1737
1749
  disabled,
1738
1750
  onClick: zoomIn,
1739
1751
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1753,7 +1765,7 @@ function ZoomControl({
1753
1765
  duration: 300,
1754
1766
  offset: TopOffset,
1755
1767
  children: /* @__PURE__ */ jsx("button", {
1756
- className: clsx(`${name$1}-btn`, "reset", theme),
1768
+ className: clsx(`${name$2}-btn`, "reset", theme),
1757
1769
  disabled,
1758
1770
  onClick: resetCamera,
1759
1771
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1815,7 +1827,7 @@ function ChevronRight({
1815
1827
  })
1816
1828
  });
1817
1829
  }
1818
- const name = "fastboard-page-control";
1830
+ const name$1 = "fastboard-page-control";
1819
1831
  function PageControl({
1820
1832
  room,
1821
1833
  manager,
@@ -1895,7 +1907,7 @@ function PageControl({
1895
1907
  }, [room, manager]);
1896
1908
  const disabled = !writable;
1897
1909
  return /* @__PURE__ */ jsxs("div", {
1898
- className: clsx(name, theme),
1910
+ className: clsx(name$1, theme),
1899
1911
  children: [/* @__PURE__ */ jsx(Tippy, {
1900
1912
  className: "fastboard-tip",
1901
1913
  content: i18n == null ? void 0 : i18n.t("prevPage"),
@@ -1905,7 +1917,7 @@ function PageControl({
1905
1917
  duration: 300,
1906
1918
  offset: TopOffset,
1907
1919
  children: /* @__PURE__ */ jsx("button", {
1908
- className: clsx(`${name}-btn`, "prev", theme),
1920
+ className: clsx(`${name$1}-btn`, "prev", theme),
1909
1921
  disabled: disabled || pageIndex === 0,
1910
1922
  onClick: prevPage,
1911
1923
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1917,13 +1929,13 @@ function PageControl({
1917
1929
  })
1918
1930
  })
1919
1931
  }), /* @__PURE__ */ jsx("span", {
1920
- className: clsx(`${name}-page`, theme),
1932
+ className: clsx(`${name$1}-page`, theme),
1921
1933
  children: pageCount === 0 ? "\u2026" : pageIndex + 1
1922
1934
  }), /* @__PURE__ */ jsx("span", {
1923
- className: clsx(`${name}-slash`, theme),
1935
+ className: clsx(`${name$1}-slash`, theme),
1924
1936
  children: "/"
1925
1937
  }), /* @__PURE__ */ jsx("span", {
1926
- className: clsx(`${name}-page-count`, theme),
1938
+ className: clsx(`${name$1}-page-count`, theme),
1927
1939
  children: pageCount
1928
1940
  }), /* @__PURE__ */ jsx(Tippy, {
1929
1941
  className: "fastboard-tip",
@@ -1934,7 +1946,7 @@ function PageControl({
1934
1946
  duration: 300,
1935
1947
  offset: TopOffset,
1936
1948
  children: /* @__PURE__ */ jsx("button", {
1937
- className: clsx(`${name}-btn`, "next", theme),
1949
+ className: clsx(`${name$1}-btn`, "next", theme),
1938
1950
  disabled: disabled || pageIndex === pageCount - 1,
1939
1951
  onClick: nextPage,
1940
1952
  children: /* @__PURE__ */ jsx(Icon, {
@@ -1954,7 +1966,7 @@ function PageControl({
1954
1966
  duration: 300,
1955
1967
  offset: TopOffset,
1956
1968
  children: /* @__PURE__ */ jsx("button", {
1957
- className: clsx(`${name}-btn`, "add", theme),
1969
+ className: clsx(`${name$1}-btn`, "add", theme),
1958
1970
  disabled,
1959
1971
  onClick: addPage,
1960
1972
  children: /* @__PURE__ */ jsx(Icon, {
@@ -2180,15 +2192,41 @@ applyStyles(style);
2180
2192
  class WhiteboardApp {
2181
2193
  constructor(config) {
2182
2194
  __publicField(this, "_instance");
2195
+ __publicField(this, "_target", null);
2183
2196
  this.config = config;
2184
2197
  this._instance = new Instance(config);
2185
2198
  }
2199
+ get target() {
2200
+ return this._target;
2201
+ }
2202
+ get room() {
2203
+ return this._instance.room;
2204
+ }
2205
+ get manager() {
2206
+ return this._instance.manager;
2207
+ }
2208
+ get sdk() {
2209
+ return this._instance.sdk;
2210
+ }
2211
+ get i18n() {
2212
+ return this._instance.i18n;
2213
+ }
2186
2214
  bindElement(target) {
2215
+ this._target = target || null;
2187
2216
  this._instance.target = target || null;
2188
2217
  }
2189
2218
  insertDocs(params) {
2190
2219
  return this._instance.insertDocs(params);
2191
2220
  }
2221
+ insertCodeEditor() {
2222
+ return this._instance.insertCodeEditor();
2223
+ }
2224
+ insertGeoGebra() {
2225
+ return this._instance.insertGeoGebra();
2226
+ }
2227
+ insertCountdown() {
2228
+ return this._instance.insertCountdown();
2229
+ }
2192
2230
  changeLanguage(language) {
2193
2231
  return this._instance.changeLanguage(language);
2194
2232
  }
@@ -2196,7 +2234,264 @@ class WhiteboardApp {
2196
2234
  return this._instance.dispose();
2197
2235
  }
2198
2236
  }
2199
- const version = "0.0.4";
2237
+ const version = "0.0.5";
2238
+ const EMPTY_ARRAY = [];
2239
+ function useForceUpdate() {
2240
+ const [, forceUpdate_] = useState({});
2241
+ return useCallback(() => forceUpdate_({}), EMPTY_ARRAY);
2242
+ }
2243
+ function useLastValue(value) {
2244
+ const ref = useRef(value);
2245
+ useEffect(() => {
2246
+ ref.current = value;
2247
+ }, [value]);
2248
+ return ref.current;
2249
+ }
2250
+ function usePlayer(player) {
2251
+ const togglePlay = useCallback(() => {
2252
+ if (player) {
2253
+ switch (player.phase) {
2254
+ case PlayerPhase.WaitingFirstFrame:
2255
+ case PlayerPhase.Pause:
2256
+ case PlayerPhase.Ended: {
2257
+ player.play();
2258
+ break;
2259
+ }
2260
+ case PlayerPhase.Playing: {
2261
+ player.pause();
2262
+ break;
2263
+ }
2264
+ }
2265
+ }
2266
+ }, [player]);
2267
+ const seekToProgressTime = useCallback((time) => {
2268
+ if (player) {
2269
+ player.seekToProgressTime(time);
2270
+ }
2271
+ }, [player]);
2272
+ const lastPlayer = useLastValue(player);
2273
+ const forceUpdate = useForceUpdate();
2274
+ const setSpeed = useCallback((speed2) => {
2275
+ if (player) {
2276
+ player.playbackSpeed = speed2;
2277
+ forceUpdate();
2278
+ }
2279
+ }, [forceUpdate, player]);
2280
+ useEffect(() => {
2281
+ if (!lastPlayer && player) {
2282
+ forceUpdate();
2283
+ }
2284
+ }, [forceUpdate, lastPlayer, player]);
2285
+ useEffect(() => {
2286
+ if (player) {
2287
+ player.callbacks.on("onPhaseChanged", forceUpdate);
2288
+ player.callbacks.on("onProgressTimeChanged", forceUpdate);
2289
+ return () => {
2290
+ player.callbacks.off("onPhaseChanged", forceUpdate);
2291
+ player.callbacks.off("onProgressTimeChanged", forceUpdate);
2292
+ };
2293
+ }
2294
+ }, [forceUpdate, player]);
2295
+ const phase = player ? player.phase : PlayerPhase.WaitingFirstFrame;
2296
+ const currentTime = player ? player.progressTime : 0;
2297
+ const totalTime = player ? player.timeDuration : 0;
2298
+ const speed = player ? player.playbackSpeed : 1;
2299
+ return {
2300
+ phase,
2301
+ currentTime,
2302
+ totalTime,
2303
+ speed,
2304
+ setSpeed,
2305
+ togglePlay,
2306
+ seekToProgressTime
2307
+ };
2308
+ }
2309
+ const Loading = (props) => {
2310
+ const stroke = getStroke(props);
2311
+ return /* @__PURE__ */ jsx("svg", {
2312
+ viewBox: "0 0 24 24",
2313
+ children: /* @__PURE__ */ jsx("path", {
2314
+ d: "M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8z",
2315
+ fill: stroke
2316
+ })
2317
+ });
2318
+ };
2319
+ const Pause = (props) => {
2320
+ const stroke = getStroke(props);
2321
+ return /* @__PURE__ */ jsx("svg", {
2322
+ viewBox: "0 0 24 24",
2323
+ children: /* @__PURE__ */ jsx("path", {
2324
+ d: "M14 19h4V5h-4M6 19h4V5H6v14z",
2325
+ fill: stroke
2326
+ })
2327
+ });
2328
+ };
2329
+ const Play = (props) => {
2330
+ const stroke = getStroke(props);
2331
+ return /* @__PURE__ */ jsx("svg", {
2332
+ viewBox: "0 0 24 24",
2333
+ children: /* @__PURE__ */ jsx("path", {
2334
+ d: "M8 5.14v14l11-7l-11-7z",
2335
+ fill: stroke
2336
+ })
2337
+ });
2338
+ };
2339
+ const Icons = {
2340
+ Play: memo(Play),
2341
+ Pause: memo(Pause),
2342
+ Loading: memo(Loading)
2343
+ };
2344
+ const Button = forwardRef((props, ref) => {
2345
+ const {
2346
+ theme,
2347
+ content,
2348
+ disabled,
2349
+ active,
2350
+ onClick,
2351
+ interactive,
2352
+ placement = "top",
2353
+ children
2354
+ } = props;
2355
+ return /* @__PURE__ */ jsx(Tippy, {
2356
+ className: "fastboard-tip",
2357
+ content,
2358
+ interactive,
2359
+ theme,
2360
+ disabled,
2361
+ placement,
2362
+ offset: TopOffset,
2363
+ duration: 300,
2364
+ children: /* @__PURE__ */ jsx("button", {
2365
+ ref,
2366
+ className: clsx("fastboard-player-control-btn", theme, {
2367
+ active
2368
+ }),
2369
+ onClick,
2370
+ disabled,
2371
+ children
2372
+ })
2373
+ });
2374
+ });
2375
+ const name = "fastboard-player-control";
2376
+ function PlayerControl(_a) {
2377
+ var _b = _a, {
2378
+ autoHide = false,
2379
+ player: player_,
2380
+ theme = "light",
2381
+ i18n
2382
+ } = _b, icons = __objRest(_b, [
2383
+ "autoHide",
2384
+ "player",
2385
+ "theme",
2386
+ "i18n"
2387
+ ]);
2388
+ const [currentTime, setCurrentTime] = useState(0);
2389
+ const player = usePlayer(player_);
2390
+ useEffect(() => {
2391
+ setCurrentTime(player.currentTime);
2392
+ }, [player.currentTime]);
2393
+ useEffect(() => {
2394
+ if (player.currentTime !== currentTime) {
2395
+ player.seekToProgressTime(currentTime);
2396
+ }
2397
+ }, [currentTime]);
2398
+ const isLoading = player.phase === PlayerPhase.WaitingFirstFrame || player.phase === PlayerPhase.Buffering;
2399
+ const isPlaying = player.phase === PlayerPhase.Playing;
2400
+ const {
2401
+ activeColor
2402
+ } = themes[theme];
2403
+ return /* @__PURE__ */ jsxs("div", {
2404
+ className: clsx(name, theme, {
2405
+ "auto-hide": autoHide
2406
+ }),
2407
+ children: [/* @__PURE__ */ jsx("button", {
2408
+ className: clsx(`${name}-btn`, isLoading ? "loading" : isPlaying ? "pause" : "play", theme),
2409
+ disabled: isLoading,
2410
+ onClick: player.togglePlay,
2411
+ children: /* @__PURE__ */ jsx(Icon, {
2412
+ fallback: isLoading ? /* @__PURE__ */ jsx(Icons.Loading, {
2413
+ theme
2414
+ }) : isPlaying ? /* @__PURE__ */ jsx(Icons.Pause, {
2415
+ theme
2416
+ }) : /* @__PURE__ */ jsx(Icons.Play, {
2417
+ theme
2418
+ }),
2419
+ src: isLoading ? icons.loadingIcon : isPlaying ? icons.pauseIcon : icons.playIcon,
2420
+ alt: isLoading ? "[loading]" : isPlaying ? "[pause]" : "[play]"
2421
+ })
2422
+ }), /* @__PURE__ */ jsx("span", {
2423
+ className: clsx(`${name}-slider`, {
2424
+ loading: isLoading
2425
+ }, theme),
2426
+ children: /* @__PURE__ */ jsx(RcSlider, {
2427
+ disabled: isLoading,
2428
+ trackStyle: {
2429
+ background: activeColor
2430
+ },
2431
+ handleStyle: {
2432
+ border: `1px solid ${activeColor}`
2433
+ },
2434
+ value: currentTime,
2435
+ onChange: setCurrentTime,
2436
+ min: 0,
2437
+ max: player.totalTime,
2438
+ step: 100
2439
+ })
2440
+ }), /* @__PURE__ */ jsx("span", {
2441
+ className: clsx(`${name}-current`, theme),
2442
+ children: renderTime(player.currentTime)
2443
+ }), /* @__PURE__ */ jsx("span", {
2444
+ className: clsx(`${name}-slash`, theme),
2445
+ children: "/"
2446
+ }), /* @__PURE__ */ jsx("span", {
2447
+ className: clsx(`${name}-total`, theme),
2448
+ children: renderTime(player.totalTime)
2449
+ }), /* @__PURE__ */ jsx("span", {
2450
+ className: `${name}-btn-interactive`,
2451
+ children: /* @__PURE__ */ jsx(Tippy, {
2452
+ className: "fastboard-tip",
2453
+ content: renderSpeeds(player),
2454
+ theme,
2455
+ placement: "top-end",
2456
+ trigger: "click",
2457
+ offset: TopOffset,
2458
+ arrow: false,
2459
+ interactive: true,
2460
+ children: /* @__PURE__ */ jsx(Button, {
2461
+ content: i18n == null ? void 0 : i18n.t("speed"),
2462
+ theme,
2463
+ disabled: isLoading,
2464
+ children: /* @__PURE__ */ jsxs("span", {
2465
+ className: clsx(`${name}-speed-text`, theme),
2466
+ children: [player.speed, "x"]
2467
+ })
2468
+ })
2469
+ })
2470
+ })]
2471
+ });
2472
+ }
2473
+ function renderTime(ms) {
2474
+ let seconds = ms / 1e3;
2475
+ const minutes = Math.floor(seconds / 60);
2476
+ seconds = Math.floor(seconds) % 60;
2477
+ return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
2478
+ }
2479
+ const Speeds = [2, 1.5, 1.25, 1, 0.75, 0.5];
2480
+ function renderSpeeds({
2481
+ speed: current,
2482
+ setSpeed
2483
+ }) {
2484
+ return /* @__PURE__ */ jsx("div", {
2485
+ className: clsx(`${name}-panel`, "speed"),
2486
+ children: Speeds.map((speed) => /* @__PURE__ */ jsxs("button", {
2487
+ className: clsx(`${name}-btn`, "speed", {
2488
+ active: speed === current
2489
+ }),
2490
+ onClick: () => setSpeed(speed),
2491
+ children: [speed, "x"]
2492
+ }, speed))
2493
+ });
2494
+ }
2200
2495
  function useFastboard(config) {
2201
2496
  const [app, setApp] = useState(null);
2202
2497
  const [currentTarget, ref] = useState(null);
@@ -2224,5 +2519,5 @@ async function createWhiteboardApp(config) {
2224
2519
  await app._instance.readyPromise;
2225
2520
  return app;
2226
2521
  }
2227
- export { PageControl, RedoUndo, Toolbar, WhiteboardApp, ZoomControl, createWhiteboardApp, register, useFastboard, version };
2522
+ export { PageControl, PlayerControl, RedoUndo, Toolbar, WhiteboardApp, ZoomControl, createWhiteboardApp, register, useFastboard, version };
2228
2523
  //# sourceMappingURL=index.es.js.map