@plait/core 0.48.0 → 0.50.0

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 (36) hide show
  1. package/constants/index.d.ts +0 -1
  2. package/esm2022/board/board.component.mjs +8 -7
  3. package/esm2022/constants/index.mjs +1 -2
  4. package/esm2022/interfaces/board.mjs +1 -1
  5. package/esm2022/plugins/create-board.mjs +5 -2
  6. package/esm2022/plugins/with-moving.mjs +6 -9
  7. package/esm2022/plugins/with-selection.mjs +7 -8
  8. package/esm2022/transforms/board.mjs +4 -5
  9. package/esm2022/utils/board.mjs +1 -15
  10. package/esm2022/utils/clipboard/clipboard.mjs +36 -0
  11. package/esm2022/utils/clipboard/common.mjs +64 -0
  12. package/esm2022/utils/clipboard/data-transfer.mjs +21 -0
  13. package/esm2022/utils/clipboard/index.mjs +3 -0
  14. package/esm2022/utils/clipboard/navigator-clipboard.mjs +73 -0
  15. package/esm2022/utils/clipboard/types.mjs +6 -0
  16. package/esm2022/utils/dom/common.mjs +1 -23
  17. package/esm2022/utils/index.mjs +5 -1
  18. package/esm2022/utils/to-point.mjs +49 -0
  19. package/esm2022/utils/viewport.mjs +8 -20
  20. package/fesm2022/plait-core.mjs +257 -107
  21. package/fesm2022/plait-core.mjs.map +1 -1
  22. package/interfaces/board.d.ts +3 -2
  23. package/package.json +1 -1
  24. package/utils/board.d.ts +0 -3
  25. package/utils/clipboard/clipboard.d.ts +3 -0
  26. package/utils/clipboard/common.d.ts +8 -0
  27. package/utils/clipboard/data-transfer.d.ts +5 -0
  28. package/utils/clipboard/index.d.ts +2 -0
  29. package/utils/clipboard/navigator-clipboard.d.ts +3 -0
  30. package/utils/clipboard/types.d.ts +17 -0
  31. package/utils/dom/common.d.ts +1 -16
  32. package/utils/index.d.ts +4 -0
  33. package/utils/to-point.d.ts +21 -0
  34. package/utils/viewport.d.ts +2 -7
  35. package/esm2022/utils/clipboard.mjs +0 -45
  36. package/utils/clipboard.d.ts +0 -8
@@ -321,7 +321,6 @@ const ATTACHED_ELEMENT_CLASS_NAME = 'plait-board-attached';
321
321
  const ACTIVE_STROKE_WIDTH = 1;
322
322
  const SELECTION_RECTANGLE_CLASS_NAME = 'selection-rectangle';
323
323
 
324
- const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
325
324
  const HOST_CLASS_NAME = 'plait-board-container';
326
325
  const ACTIVE_MOVING_CLASS_NAME = 'active-with-moving';
327
326
  const SCROLL_BAR_WIDTH = 20;
@@ -335,27 +334,6 @@ const POINTER_BUTTON = {
335
334
  const PRESS_AND_MOVE_BUFFER = 3;
336
335
 
337
336
  const NS = 'http://www.w3.org/2000/svg';
338
- /**
339
- * Get the screen coordinates starting from the upper left corner of the svg element (based on the svg screen coordinate system)
340
- * @param x screen x
341
- * @param y screen x
342
- * @returns
343
- */
344
- function toPoint(x, y, svg) {
345
- const rect = svg.getBoundingClientRect();
346
- return [x - rect.x, y - rect.y];
347
- }
348
- /**
349
- * `toPoint` reverse processing
350
- * Get the screen coordinate starting from the upper left corner of the browser window (based on the screen coordinate system)
351
- * @param point screen coordinates based on the upper left corner of the svg
352
- * @returns
353
- */
354
- function toScreenPoint(board, point) {
355
- const host = PlaitBoard.getHost(board);
356
- const rect = host.getBoundingClientRect();
357
- return [point[0] + rect.x, point[1] + rect.y];
358
- }
359
337
  function createG() {
360
338
  const newG = document.createElementNS(NS, 'g');
361
339
  return newG;
@@ -838,20 +816,6 @@ const catmullRomFitting = function (points) {
838
816
  return result;
839
817
  };
840
818
 
841
- function transformPoints(board, points) {
842
- const newPoints = points.map(point => {
843
- return transformPoint(board, point);
844
- });
845
- return newPoints;
846
- }
847
- function transformPoint(board, point) {
848
- const { width, height } = PlaitBoard.getHost(board).getBoundingClientRect();
849
- const viewBox = PlaitBoard.getHost(board).viewBox.baseVal;
850
- const x = (point[0] / width) * viewBox.width + viewBox.x;
851
- const y = (point[1] / height) * viewBox.height + viewBox.y;
852
- const newPoint = [x, y];
853
- return newPoint;
854
- }
855
819
  function isInPlaitBoard(board, x, y) {
856
820
  const plaitBoardElement = PlaitBoard.getBoardContainer(board);
857
821
  const plaitBoardRect = plaitBoardElement.getBoundingClientRect();
@@ -1246,13 +1210,13 @@ const updatePointerType = (board, pointer) => {
1246
1210
  };
1247
1211
  function updateZoom(board, newZoom, isCenter = true) {
1248
1212
  newZoom = clampZoomLevel(newZoom);
1249
- const mousePoint = PlaitBoard.getMovingPointInBoard(board);
1213
+ const movingPoint = PlaitBoard.getMovingPointInBoard(board);
1250
1214
  const nativeElement = PlaitBoard.getBoardContainer(board);
1251
1215
  const nativeElementRect = nativeElement.getBoundingClientRect();
1252
1216
  const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
1253
1217
  let focusPoint = [boardContainerRect.width / 2, boardContainerRect.height / 2];
1254
- if (!isCenter && mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], nativeElementRect) === 0) {
1255
- focusPoint = toPoint(mousePoint[0], mousePoint[1], nativeElement);
1218
+ if (!isCenter && movingPoint && distanceBetweenPointAndRectangle(movingPoint[0], movingPoint[1], nativeElementRect) === 0) {
1219
+ focusPoint = [movingPoint[0] - nativeElementRect.x, movingPoint[1] - nativeElementRect.y];
1256
1220
  }
1257
1221
  const zoom = board.viewport.zoom;
1258
1222
  const origination = getViewportOrigination(board);
@@ -1340,15 +1304,56 @@ const BoardTransforms = {
1340
1304
  fitViewportWidth
1341
1305
  };
1342
1306
 
1343
- const IS_FROM_SCROLLING = new WeakMap();
1344
- const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
1345
- function toSVGScreenPoint(board, point) {
1307
+ const getViewBox = (board) => {
1308
+ return PlaitBoard.getHost(board).viewBox.baseVal;
1309
+ };
1310
+ /**
1311
+ * Get the screen point starting from the upper left corner of the svg element (based on the svg screen coordinate system)
1312
+ */
1313
+ function toHostPoint(board, x, y) {
1314
+ const host = PlaitBoard.getHost(board);
1315
+ const rect = host.getBoundingClientRect();
1316
+ return [x - rect.x, y - rect.y];
1317
+ }
1318
+ /**
1319
+ * Get the point in the coordinate system of the svg viewBox
1320
+ */
1321
+ function toViewBoxPoint(board, hostPoint) {
1322
+ const viewBox = getViewBox(board);
1323
+ const { zoom } = board.viewport;
1324
+ const x = hostPoint[0] / zoom + viewBox.x;
1325
+ const y = hostPoint[1] / zoom + viewBox.y;
1326
+ const newPoint = [x, y];
1327
+ return newPoint;
1328
+ }
1329
+ function toViewBoxPoints(board, hostPoints) {
1330
+ const newPoints = hostPoints.map(point => {
1331
+ return toViewBoxPoint(board, point);
1332
+ });
1333
+ return newPoints;
1334
+ }
1335
+ /**
1336
+ * `toHostPoint` reverse processing
1337
+ * Get the screen point starting from the upper left corner of the browser window or the viewport (based on the screen coordinate system)
1338
+ */
1339
+ function toScreenPointFromHostPoint(board, hostPoint) {
1340
+ const host = PlaitBoard.getHost(board);
1341
+ const rect = host.getBoundingClientRect();
1342
+ return [hostPoint[0] + rect.x, hostPoint[1] + rect.y];
1343
+ }
1344
+ /**
1345
+ * `toViewBoxPoint` reverse processing
1346
+ */
1347
+ function toHostPointFromViewBoxPoint(board, viewBoxPoint) {
1346
1348
  const { zoom } = board.viewport;
1347
- const viewBox = getViewBox(board, zoom);
1348
- const x = (point[0] - viewBox[0]) * zoom;
1349
- const y = (point[1] - viewBox[1]) * zoom;
1349
+ const viewBox = getViewBox(board);
1350
+ const x = (viewBoxPoint[0] - viewBox.x) * zoom;
1351
+ const y = (viewBoxPoint[1] - viewBox.y) * zoom;
1350
1352
  return [x, y];
1351
1353
  }
1354
+
1355
+ const IS_FROM_SCROLLING = new WeakMap();
1356
+ const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
1352
1357
  function getViewportContainerRect(board) {
1353
1358
  const { hideScrollbar } = board.options;
1354
1359
  const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
@@ -1395,16 +1400,12 @@ function getElementHostBBox(board, zoom) {
1395
1400
  };
1396
1401
  }
1397
1402
  /**
1398
- * 验证缩放比是否符合限制,如果超出限制,则返回合适的缩放比
1399
- * @param zoom 缩放比
1400
- * @param minZoom 最小缩放比
1401
- * @param maxZoom 最大缩放比
1402
- * @returns 正确的缩放比
1403
+ * Normalize the scaling ratio, or return the corrected scaling ratio if the limit is exceeded
1403
1404
  */
1404
1405
  function clampZoomLevel(zoom, minZoom = MIN_ZOOM, maxZoom = MAX_ZOOM) {
1405
1406
  return zoom < minZoom ? minZoom : zoom > maxZoom ? maxZoom : zoom;
1406
1407
  }
1407
- function getViewBox(board, zoom) {
1408
+ function calcNewViewBox(board, zoom) {
1408
1409
  const boardContainerRectangle = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
1409
1410
  const elementHostBBox = getElementHostBBox(board, zoom);
1410
1411
  const horizontalPadding = boardContainerRectangle.width / 2;
@@ -1436,7 +1437,7 @@ function updateViewportOffset(board) {
1436
1437
  if (!origination) {
1437
1438
  return;
1438
1439
  }
1439
- const [scrollLeft, scrollTop] = toSVGScreenPoint(board, origination);
1440
+ const [scrollLeft, scrollTop] = toHostPointFromViewBoxPoint(board, origination);
1440
1441
  updateViewportContainerScroll(board, scrollLeft, scrollTop);
1441
1442
  }
1442
1443
  function updateViewportContainerScroll(board, left, top, isFromViewportChange = true) {
@@ -1467,9 +1468,7 @@ function updateViewportContainerScroll(board, left, top, isFromViewportChange =
1467
1468
  }
1468
1469
  }
1469
1470
  function updateViewportByScrolling(board, scrollLeft, scrollTop) {
1470
- const zoom = board.viewport.zoom;
1471
- const viewBox = getViewBox(board, zoom);
1472
- const origination = [scrollLeft / zoom + viewBox[0], scrollTop / zoom + viewBox[1]];
1471
+ const origination = toViewBoxPoint(board, [scrollLeft, scrollTop]);
1473
1472
  if (Point.isEquals(origination, getViewportOrigination(board))) {
1474
1473
  return;
1475
1474
  }
@@ -1484,14 +1483,14 @@ function initializeViewportContainer(board) {
1484
1483
  }
1485
1484
  function initializeViewBox(board) {
1486
1485
  const zoom = board.viewport.zoom;
1487
- const viewBox = getViewBox(board, zoom);
1486
+ const viewBox = calcNewViewBox(board, zoom);
1488
1487
  setSVGViewBox(board, viewBox);
1489
1488
  }
1490
1489
  function initializeViewportOffset(board) {
1491
1490
  if (!board.viewport?.origination) {
1492
1491
  const zoom = board.viewport.zoom;
1493
1492
  const viewportContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
1494
- const viewBox = getViewBox(board, zoom);
1493
+ const viewBox = calcNewViewBox(board, zoom);
1495
1494
  const centerX = viewBox[0] + viewBox[2] / 2;
1496
1495
  const centerY = viewBox[1] + viewBox[3] / 2;
1497
1496
  const origination = [centerX - viewportContainerRect.width / 2 / zoom, centerY - viewportContainerRect.height / 2 / zoom];
@@ -1789,48 +1788,198 @@ function downloadImage(url, name) {
1789
1788
  a.remove();
1790
1789
  }
1791
1790
 
1792
- const getClipboardByKey = (key) => {
1793
- return `application/x-plait-${key}-fragment`;
1791
+ var WritableClipboardType;
1792
+ (function (WritableClipboardType) {
1793
+ WritableClipboardType["medias"] = "medias";
1794
+ WritableClipboardType["elements"] = "elements";
1795
+ })(WritableClipboardType || (WritableClipboardType = {}));
1796
+
1797
+ const buildPlaitHtml = (type, data) => {
1798
+ const stringifiedClipboard = JSON.stringify({
1799
+ type,
1800
+ data
1801
+ });
1802
+ return `<plait>${stringifiedClipboard}</plait>`;
1794
1803
  };
1795
- const setClipboardData = (data, elements) => {
1796
- const result = [...elements];
1797
- const pluginContextResult = getDataFromClipboard(data);
1798
- if (pluginContextResult) {
1799
- result.push(...pluginContextResult);
1800
- }
1801
- const stringObj = JSON.stringify(result);
1802
- const encoded = window.btoa(encodeURIComponent(stringObj));
1803
- data?.setData(`application/${CLIP_BOARD_FORMAT_KEY}`, encoded);
1804
+ const getClipboardFromHtml = (html) => {
1805
+ const plaitString = html?.match(/<plait[^>]*>(.*)<\/plait>/)?.[1];
1806
+ if (plaitString) {
1807
+ try {
1808
+ const plaitJson = JSON.parse(plaitString);
1809
+ if (plaitJson) {
1810
+ if (plaitJson.type === WritableClipboardType.elements) {
1811
+ return {
1812
+ elements: plaitJson.data
1813
+ };
1814
+ }
1815
+ else if (plaitJson.type === WritableClipboardType.medias) {
1816
+ return {
1817
+ medias: plaitJson.data
1818
+ };
1819
+ }
1820
+ }
1821
+ }
1822
+ catch (error) {
1823
+ console.error(error);
1824
+ return null;
1825
+ }
1826
+ }
1827
+ return null;
1828
+ };
1829
+ const stripHtml = (html) => {
1830
+ // See <https://github.com/developit/preact-markup/blob/4788b8d61b4e24f83688710746ee36e7464f7bbc/src/parse-markup.js#L60-L69>
1831
+ const doc = document.implementation.createHTMLDocument('');
1832
+ doc.documentElement.innerHTML = html.trim();
1833
+ return doc.body.textContent || doc.body.innerText || '';
1834
+ };
1835
+ const getProbablySupportsClipboardWrite = () => {
1836
+ return 'clipboard' in navigator && 'write' in navigator.clipboard;
1837
+ };
1838
+ const getProbablySupportsClipboardRead = () => {
1839
+ return 'clipboard' in navigator && 'read' in navigator.clipboard;
1840
+ };
1841
+ const createClipboardContext = (type, data, text) => {
1842
+ return {
1843
+ type,
1844
+ data,
1845
+ text
1846
+ };
1847
+ };
1848
+ const addClipboardContext = (clipboardContext, addition) => {
1849
+ const { type, data, text } = clipboardContext;
1850
+ if (type === addition.type) {
1851
+ return {
1852
+ type,
1853
+ data: data.concat(addition.data),
1854
+ text: text + ' ' + addition.text
1855
+ };
1856
+ }
1857
+ return clipboardContext;
1804
1858
  };
1805
- const setClipboardDataByText = (data, text) => {
1806
- const pluginContextResult = getTextFromClipboard(data);
1807
- data?.setData(`text/plain`, text + '\n' + pluginContextResult);
1859
+
1860
+ const setDataTransferClipboard = (dataTransfer, type, data) => {
1861
+ dataTransfer?.setData(`text/html`, buildPlaitHtml(type, data));
1808
1862
  };
1809
- const setClipboardDataByMedia = (data, media, key) => {
1810
- const stringObj = JSON.stringify(media);
1811
- const encoded = window.btoa(encodeURIComponent(stringObj));
1812
- data?.setData(getClipboardByKey(key), encoded);
1863
+ const setDataTransferClipboardText = (data, text) => {
1864
+ data?.setData(`text/plain`, text);
1813
1865
  };
1814
- const getDataFromClipboard = (data) => {
1815
- const encoded = data?.getData(`application/${CLIP_BOARD_FORMAT_KEY}`);
1816
- let nodesData = [];
1817
- if (encoded) {
1818
- const decoded = decodeURIComponent(window.atob(encoded));
1819
- nodesData = JSON.parse(decoded);
1820
- }
1821
- return nodesData;
1866
+ const getDataTransferClipboard = (data) => {
1867
+ const html = data?.getData(`text/html`);
1868
+ if (html) {
1869
+ const htmlClipboardData = getClipboardFromHtml(html);
1870
+ if (htmlClipboardData) {
1871
+ return htmlClipboardData;
1872
+ }
1873
+ }
1874
+ return {};
1822
1875
  };
1823
- const getTextFromClipboard = (data) => {
1876
+ const getDataTransferClipboardText = (data) => {
1824
1877
  return (data ? data.getData(`text/plain`) : '');
1825
1878
  };
1826
- const getClipboardDataByMedia = (data, key) => {
1827
- const encoded = data?.getData(getClipboardByKey(key));
1828
- let imageItem = null;
1829
- if (encoded) {
1830
- const decoded = decodeURIComponent(window.atob(encoded));
1831
- imageItem = JSON.parse(decoded);
1832
- }
1833
- return imageItem;
1879
+
1880
+ const setNavigatorClipboard = async (type, data, text = '') => {
1881
+ let textClipboard = text;
1882
+ if ('clipboard' in navigator && 'write' in navigator.clipboard) {
1883
+ if (navigator.clipboard && typeof navigator.clipboard.write === 'function') {
1884
+ await navigator.clipboard.write([
1885
+ new ClipboardItem({
1886
+ 'text/html': new Blob([buildPlaitHtml(type, data)], {
1887
+ type: 'text/html'
1888
+ }),
1889
+ 'text/plain': new Blob([JSON.stringify(textClipboard ?? data)], { type: 'text/plain' })
1890
+ })
1891
+ ]);
1892
+ }
1893
+ }
1894
+ };
1895
+ const getNavigatorClipboard = async () => {
1896
+ if (!('clipboard' in navigator && 'read' in navigator.clipboard)) {
1897
+ return {};
1898
+ }
1899
+ const clipboardItems = await navigator.clipboard.read();
1900
+ let clipboardData = {};
1901
+ if (Array.isArray(clipboardItems) && clipboardItems[0] instanceof ClipboardItem) {
1902
+ for (const item of clipboardItems) {
1903
+ if (isFile(item)) {
1904
+ const clipboardFiles = item.types.filter(type => type.match(/^image\//));
1905
+ const fileBlobs = await Promise.all(clipboardFiles.map(type => item.getType(type)));
1906
+ const urls = fileBlobs.filter(Boolean).map(blob => URL.createObjectURL(blob));
1907
+ const files = await Promise.all(urls.map(async (url) => {
1908
+ const blob = await (await fetch(url)).blob();
1909
+ return new File([blob], 'plait-file', { type: blob.type });
1910
+ }));
1911
+ return {
1912
+ files
1913
+ };
1914
+ }
1915
+ if (item.types.includes('text/html')) {
1916
+ const htmlContent = await blobAsString(await item.getType('text/html'));
1917
+ const htmlClipboardData = getClipboardFromHtml(htmlContent);
1918
+ if (htmlClipboardData) {
1919
+ return htmlClipboardData;
1920
+ }
1921
+ if (htmlContent && htmlContent.trim()) {
1922
+ clipboardData = { text: stripHtml(htmlContent) };
1923
+ }
1924
+ }
1925
+ if (item.types.includes('text/plain')) {
1926
+ const textContent = await blobAsString(await item.getType('text/plain'));
1927
+ clipboardData = {
1928
+ text: stripHtml(textContent)
1929
+ };
1930
+ }
1931
+ }
1932
+ }
1933
+ return clipboardData;
1934
+ };
1935
+ const isFile = (item) => {
1936
+ return item.types.find(i => i.match(/^image\//));
1937
+ };
1938
+ const blobAsString = (blob) => {
1939
+ return new Promise((resolve, reject) => {
1940
+ const reader = new FileReader();
1941
+ reader.addEventListener('loadend', () => {
1942
+ const text = reader.result;
1943
+ resolve(text);
1944
+ });
1945
+ reader.addEventListener('error', () => {
1946
+ reject(reader.error);
1947
+ });
1948
+ reader.readAsText(blob);
1949
+ });
1950
+ };
1951
+
1952
+ const getClipboardData = async (dataTransfer) => {
1953
+ let clipboardData = {};
1954
+ if (dataTransfer) {
1955
+ if (dataTransfer.files.length) {
1956
+ return { files: Array.from(dataTransfer.files) };
1957
+ }
1958
+ clipboardData = getDataTransferClipboard(dataTransfer);
1959
+ if (Object.keys(clipboardData).length === 0) {
1960
+ clipboardData = {
1961
+ text: getDataTransferClipboardText(dataTransfer)
1962
+ };
1963
+ }
1964
+ return clipboardData;
1965
+ }
1966
+ if (getProbablySupportsClipboardRead()) {
1967
+ return await getNavigatorClipboard();
1968
+ }
1969
+ return clipboardData;
1970
+ };
1971
+ const setClipboardData = async (dataTransfer, clipboardContext) => {
1972
+ if (!clipboardContext) {
1973
+ return;
1974
+ }
1975
+ const { type, data, text } = clipboardContext;
1976
+ if (getProbablySupportsClipboardWrite()) {
1977
+ return await setNavigatorClipboard(type, data, text);
1978
+ }
1979
+ if (dataTransfer) {
1980
+ setDataTransferClipboard(dataTransfer, type, data);
1981
+ setDataTransferClipboardText(dataTransfer, text);
1982
+ }
1834
1983
  };
1835
1984
 
1836
1985
  const BOARD_TO_TOUCH_REF = new WeakMap();
@@ -2637,13 +2786,13 @@ function withSelection(board) {
2637
2786
  if (event.shiftKey && !isTextSelection) {
2638
2787
  event.preventDefault();
2639
2788
  }
2640
- const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
2789
+ const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
2641
2790
  const hitElement = getHitElementByPoint(board, point);
2642
2791
  const options = board.getPluginOptions(PlaitPluginKey.withSelection);
2643
2792
  if (PlaitBoard.isPointer(board, PlaitPointerType.selection) && !hitElement && options.isMultiple && !options.isDisabledSelect) {
2644
2793
  preventTouchMove(board, event, true);
2645
2794
  // start rectangle selection
2646
- start = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
2795
+ start = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
2647
2796
  }
2648
2797
  pointerDown(event);
2649
2798
  };
@@ -2653,7 +2802,7 @@ function withSelection(board) {
2653
2802
  event.preventDefault();
2654
2803
  }
2655
2804
  if (start && PlaitBoard.isPointer(board, PlaitPointerType.selection)) {
2656
- const movedTarget = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
2805
+ const movedTarget = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
2657
2806
  const rectangle = RectangleClient.toRectangleClient([start, movedTarget]);
2658
2807
  selectionMovingG?.remove();
2659
2808
  if (Math.hypot(rectangle.width, rectangle.height) > PRESS_AND_MOVE_BUFFER || isSelectionMoving(board)) {
@@ -2683,7 +2832,7 @@ function withSelection(board) {
2683
2832
  pointerDown(event);
2684
2833
  return;
2685
2834
  }
2686
- const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
2835
+ const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
2687
2836
  const selection = { anchor: point, focus: point };
2688
2837
  Transforms.setSelection(board, selection);
2689
2838
  pointerUp(event);
@@ -2975,7 +3124,9 @@ function createBoard(children, options) {
2975
3124
  globalKeydown: (event) => { },
2976
3125
  keyup: (event) => { },
2977
3126
  dblclick: (event) => { },
2978
- setFragment: (data) => { },
3127
+ setFragment: (data, clipboardContext) => {
3128
+ setClipboardData(data, clipboardContext);
3129
+ },
2979
3130
  insertFragment: (data) => { },
2980
3131
  deleteFragment: (data) => {
2981
3132
  const elements = board.getDeletedFragment([]);
@@ -3569,8 +3720,7 @@ function withMoving(board) {
3569
3720
  let alignG = null;
3570
3721
  let activeElementsRectangle = null;
3571
3722
  board.pointerDown = (event) => {
3572
- const host = BOARD_TO_HOST.get(board);
3573
- const point = transformPoint(board, toPoint(event.x, event.y, host));
3723
+ const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
3574
3724
  let movableElements = board.children.filter(item => board.isMovable(item));
3575
3725
  if (!PlaitBoard.isReadonly(board) &&
3576
3726
  PlaitBoard.isPointer(board, PlaitPointerType.selection) &&
@@ -3602,8 +3752,7 @@ function withMoving(board) {
3602
3752
  isPreventDefault = true;
3603
3753
  }
3604
3754
  alignG?.remove();
3605
- const host = BOARD_TO_HOST.get(board);
3606
- const endPoint = transformPoint(board, toPoint(event.x, event.y, host));
3755
+ const endPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
3607
3756
  offsetX = endPoint[0] - startPoint[0];
3608
3757
  offsetY = endPoint[1] - startPoint[1];
3609
3758
  const distance = distanceBetweenPointAndPoint(...endPoint, ...startPoint);
@@ -4267,15 +4416,16 @@ class PlaitBoardComponent {
4267
4416
  const selectedElements = getSelectedElements(this.board);
4268
4417
  event.preventDefault();
4269
4418
  const rectangle = getRectangleByElements(this.board, selectedElements, false);
4270
- this.board.setFragment(event.clipboardData, rectangle, 'copy');
4419
+ this.board.setFragment(event.clipboardData, null, rectangle, 'copy');
4271
4420
  });
4272
4421
  fromEvent(document, 'paste')
4273
4422
  .pipe(takeUntil(this.destroy$), filter(() => this.isFocused && !PlaitBoard.isReadonly(this.board) && !PlaitBoard.hasBeenTextEditing(this.board)))
4274
- .subscribe((clipboardEvent) => {
4423
+ .subscribe(async (clipboardEvent) => {
4275
4424
  const mousePoint = PlaitBoard.getMovingPointInBoard(this.board);
4276
4425
  if (mousePoint) {
4277
- const targetPoint = transformPoint(this.board, toPoint(mousePoint[0], mousePoint[1], this.host));
4278
- this.board.insertFragment(clipboardEvent.clipboardData, targetPoint);
4426
+ const targetPoint = toViewBoxPoint(this.board, toHostPoint(this.board, mousePoint[0], mousePoint[1]));
4427
+ const clipboardData = await getClipboardData(clipboardEvent.clipboardData);
4428
+ this.board.insertFragment(clipboardEvent.clipboardData, clipboardData, targetPoint);
4279
4429
  }
4280
4430
  });
4281
4431
  fromEvent(document, 'cut')
@@ -4284,7 +4434,7 @@ class PlaitBoardComponent {
4284
4434
  const selectedElements = getSelectedElements(this.board);
4285
4435
  event.preventDefault();
4286
4436
  const rectangle = getRectangleByElements(this.board, selectedElements, false);
4287
- this.board.setFragment(event.clipboardData, rectangle, 'cut');
4437
+ this.board.setFragment(event.clipboardData, null, rectangle, 'cut');
4288
4438
  this.board.deleteFragment(event.clipboardData);
4289
4439
  });
4290
4440
  }
@@ -4613,5 +4763,5 @@ function createModModifierKeys() {
4613
4763
  * Generated bundle index. Do not edit.
4614
4764
  */
4615
4765
 
4616
- export { A, ACTIVE_MOVING_CLASS_NAME, ACTIVE_STROKE_WIDTH, ALT, APOSTROPHE, ATTACHED_ELEMENT_CLASS_NAME, AT_SIGN, B, BACKSLASH, BACKSPACE, BOARD_TO_AFTER_CHANGE, BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_TOUCH_REF, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLIP_BOARD_FORMAT_KEY, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, CoreTransforms, CursorClass, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, Direction, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRESS_AND_MOVE_BUFFER, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElementComponent, PlaitContextService, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, ResizeCursorClass, RetroThemeColor, RgbaToHEX, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SELECTION_RECTANGLE_CLASS_NAME, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, X, Y, Z, ZERO, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, catmullRomFitting, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createMask, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createRect, createSVG, createSelectionRectangleG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, distanceBetweenPointAndSegments, downScale, downloadImage, drawArrow, drawBezierPath, drawCircle, drawLine, drawLinearPath, drawRectangle, drawRoundRectangle, fakeNodeWeakMap, findElements, getBoardRectangle, getClipboardByKey, getClipboardDataByMedia, getDataFromClipboard, getElementById, getElementHostBBox, getHitElementByPoint, getHitElementsBySelection, getIsRecursionFunc, getMovingElements, getNearestPointBetweenPointAndSegment, getNearestPointBetweenPointAndSegments, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getTemporaryRef, getTextFromClipboard, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, handleTouchTarget, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isDragging, isFromScrolling, isFromViewportChange, isHandleSelection, isInPlaitBoard, isLineHitLine, isMainPointer, isMovingElements, isNullOrUndefined, isPointInEllipse, isPointInPolygon, isPointInRoundRectangle, isPolylineHitRectangle, isPreventTouchMove, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetSelectionOperation, isSetViewportOperation, normalizePoint, preventTouchMove, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setClipboardData, setClipboardDataByMedia, setClipboardDataByText, setDragging, setIsFromScrolling, setIsFromViewportChange, setPathStrokeLinecap, setSVGViewBox, setSelectionMoving, setStrokeLinecap, shouldClear, shouldMerge, shouldSave, temporaryDisableSelection, throttleRAF, toImage, toPoint, toSVGScreenPoint, toScreenPoint, transformPoint, transformPoints, updateForeignObject, updateForeignObjectWidth, updateViewportByScrolling, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
4766
+ export { A, ACTIVE_MOVING_CLASS_NAME, ACTIVE_STROKE_WIDTH, ALT, APOSTROPHE, ATTACHED_ELEMENT_CLASS_NAME, AT_SIGN, B, BACKSLASH, BACKSPACE, BOARD_TO_AFTER_CHANGE, BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_TOUCH_REF, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, CoreTransforms, CursorClass, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, Direction, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRESS_AND_MOVE_BUFFER, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElementComponent, PlaitContextService, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, ResizeCursorClass, RetroThemeColor, RgbaToHEX, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SELECTION_RECTANGLE_CLASS_NAME, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, WritableClipboardType, X, Y, Z, ZERO, addClipboardContext, addMovingElements, addSelectedElement, arrowPoints, buildPlaitHtml, cacheMovingElements, cacheSelectedElements, calcNewViewBox, catmullRomFitting, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createClipboardContext, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createMask, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createRect, createSVG, createSelectionRectangleG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, distanceBetweenPointAndSegments, downScale, downloadImage, drawArrow, drawBezierPath, drawCircle, drawLine, drawLinearPath, drawRectangle, drawRoundRectangle, fakeNodeWeakMap, findElements, getBoardRectangle, getClipboardData, getClipboardFromHtml, getDataTransferClipboard, getDataTransferClipboardText, getElementById, getElementHostBBox, getHitElementByPoint, getHitElementsBySelection, getIsRecursionFunc, getMovingElements, getNearestPointBetweenPointAndSegment, getNearestPointBetweenPointAndSegments, getProbablySupportsClipboardRead, getProbablySupportsClipboardWrite, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getTemporaryRef, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, handleTouchTarget, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isDragging, isFromScrolling, isFromViewportChange, isHandleSelection, isInPlaitBoard, isLineHitLine, isMainPointer, isMovingElements, isNullOrUndefined, isPointInEllipse, isPointInPolygon, isPointInRoundRectangle, isPolylineHitRectangle, isPreventTouchMove, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetSelectionOperation, isSetViewportOperation, normalizePoint, preventTouchMove, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setDragging, setIsFromScrolling, setIsFromViewportChange, setPathStrokeLinecap, setSVGViewBox, setSelectionMoving, setStrokeLinecap, shouldClear, shouldMerge, shouldSave, stripHtml, temporaryDisableSelection, throttleRAF, toHostPoint, toHostPointFromViewBoxPoint, toImage, toScreenPointFromHostPoint, toViewBoxPoint, toViewBoxPoints, updateForeignObject, updateForeignObjectWidth, updateViewportByScrolling, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
4617
4767
  //# sourceMappingURL=plait-core.mjs.map