@excalidraw/excalidraw 0.18.0-3bdaafe → 0.18.0-414182f
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/dev/{chunk-WQARCR2O.js → chunk-WWDIUJ2Q.js} +45 -776
- package/dist/dev/chunk-WWDIUJ2Q.js.map +7 -0
- package/dist/dev/data/{image-6EX7CJAB.js → image-VTYIFRQE.js} +2 -2
- package/dist/dev/index.js +1470 -708
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/chunk-VTWWEYSQ.js +4 -0
- package/dist/prod/data/{image-I65E4LM3.js → image-YQ6UXXDA.js} +1 -1
- package/dist/prod/index.js +20 -17
- package/dist/types/common/src/constants.d.ts +10 -3
- package/dist/types/excalidraw/clipboard.d.ts +61 -1
- package/dist/types/excalidraw/data/blob.d.ts +0 -7
- package/package.json +4 -4
- package/dist/dev/chunk-WQARCR2O.js.map +0 -7
- package/dist/prod/chunk-K6SESUPD.js +0 -7
- /package/dist/dev/data/{image-6EX7CJAB.js.map → image-VTYIFRQE.js.map} +0 -0
|
@@ -9,15 +9,15 @@ import {
|
|
|
9
9
|
import tEXt from "png-chunk-text";
|
|
10
10
|
import encodePng from "png-chunks-encode";
|
|
11
11
|
import decodePng from "png-chunks-extract";
|
|
12
|
-
import { EXPORT_DATA_TYPES as
|
|
12
|
+
import { EXPORT_DATA_TYPES as EXPORT_DATA_TYPES3, MIME_TYPES as MIME_TYPES7 } from "@excalidraw/common";
|
|
13
13
|
|
|
14
14
|
// data/blob.ts
|
|
15
15
|
import { nanoid } from "nanoid";
|
|
16
16
|
import {
|
|
17
17
|
IMAGE_MIME_TYPES,
|
|
18
|
-
MIME_TYPES as
|
|
18
|
+
MIME_TYPES as MIME_TYPES6,
|
|
19
19
|
bytesToHexString,
|
|
20
|
-
isPromiseLike
|
|
20
|
+
isPromiseLike
|
|
21
21
|
} from "@excalidraw/common";
|
|
22
22
|
import { clearElementsForExport as clearElementsForExport2 } from "@excalidraw/element";
|
|
23
23
|
|
|
@@ -4677,709 +4677,10 @@ var getExportSize = (elements, exportPadding, scale) => {
|
|
|
4677
4677
|
return [width, height];
|
|
4678
4678
|
};
|
|
4679
4679
|
|
|
4680
|
-
// clipboard.ts
|
|
4681
|
-
import {
|
|
4682
|
-
ALLOWED_PASTE_MIME_TYPES,
|
|
4683
|
-
EXPORT_DATA_TYPES as EXPORT_DATA_TYPES3,
|
|
4684
|
-
MIME_TYPES as MIME_TYPES6,
|
|
4685
|
-
arrayToMap as arrayToMap2,
|
|
4686
|
-
isMemberOf,
|
|
4687
|
-
isPromiseLike,
|
|
4688
|
-
EVENT as EVENT2
|
|
4689
|
-
} from "@excalidraw/common";
|
|
4690
|
-
import { mutateElement } from "@excalidraw/element";
|
|
4691
|
-
import { deepCopyElement } from "@excalidraw/element";
|
|
4692
|
-
import {
|
|
4693
|
-
isFrameLikeElement as isFrameLikeElement2,
|
|
4694
|
-
isInitializedImageElement as isInitializedImageElement2
|
|
4695
|
-
} from "@excalidraw/element";
|
|
4696
|
-
import { getContainingFrame as getContainingFrame2 } from "@excalidraw/element";
|
|
4697
|
-
|
|
4698
|
-
// charts.ts
|
|
4699
|
-
import { pointFrom as pointFrom3 } from "@excalidraw/math";
|
|
4700
|
-
import {
|
|
4701
|
-
COLOR_PALETTE as COLOR_PALETTE2,
|
|
4702
|
-
DEFAULT_CHART_COLOR_INDEX,
|
|
4703
|
-
getAllColorsSpecificShade,
|
|
4704
|
-
DEFAULT_FONT_FAMILY as DEFAULT_FONT_FAMILY2,
|
|
4705
|
-
DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE2,
|
|
4706
|
-
VERTICAL_ALIGN,
|
|
4707
|
-
randomId,
|
|
4708
|
-
isDevEnv
|
|
4709
|
-
} from "@excalidraw/common";
|
|
4710
|
-
import {
|
|
4711
|
-
newTextElement as newTextElement2,
|
|
4712
|
-
newLinearElement,
|
|
4713
|
-
newElement
|
|
4714
|
-
} from "@excalidraw/element";
|
|
4715
|
-
var BAR_WIDTH = 32;
|
|
4716
|
-
var BAR_GAP = 12;
|
|
4717
|
-
var BAR_HEIGHT = 256;
|
|
4718
|
-
var GRID_OPACITY = 50;
|
|
4719
|
-
var NOT_SPREADSHEET = "NOT_SPREADSHEET";
|
|
4720
|
-
var VALID_SPREADSHEET = "VALID_SPREADSHEET";
|
|
4721
|
-
var tryParseNumber = (s) => {
|
|
4722
|
-
const match = /^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(s);
|
|
4723
|
-
if (!match) {
|
|
4724
|
-
return null;
|
|
4725
|
-
}
|
|
4726
|
-
return parseFloat(`${(match[1] || match[2]) + match[3]}`.replace(/,/g, ""));
|
|
4727
|
-
};
|
|
4728
|
-
var isNumericColumn = (lines, columnIndex) => lines.slice(1).every((line) => tryParseNumber(line[columnIndex]) !== null);
|
|
4729
|
-
var tryParseCells = (cells) => {
|
|
4730
|
-
const numCols = cells[0].length;
|
|
4731
|
-
if (numCols > 2) {
|
|
4732
|
-
return { type: NOT_SPREADSHEET, reason: "More than 2 columns" };
|
|
4733
|
-
}
|
|
4734
|
-
if (numCols === 1) {
|
|
4735
|
-
if (!isNumericColumn(cells, 0)) {
|
|
4736
|
-
return { type: NOT_SPREADSHEET, reason: "Value is not numeric" };
|
|
4737
|
-
}
|
|
4738
|
-
const hasHeader2 = tryParseNumber(cells[0][0]) === null;
|
|
4739
|
-
const values = (hasHeader2 ? cells.slice(1) : cells).map(
|
|
4740
|
-
(line) => tryParseNumber(line[0])
|
|
4741
|
-
);
|
|
4742
|
-
if (values.length < 2) {
|
|
4743
|
-
return { type: NOT_SPREADSHEET, reason: "Less than two rows" };
|
|
4744
|
-
}
|
|
4745
|
-
return {
|
|
4746
|
-
type: VALID_SPREADSHEET,
|
|
4747
|
-
spreadsheet: {
|
|
4748
|
-
title: hasHeader2 ? cells[0][0] : null,
|
|
4749
|
-
labels: null,
|
|
4750
|
-
values
|
|
4751
|
-
}
|
|
4752
|
-
};
|
|
4753
|
-
}
|
|
4754
|
-
const labelColumnNumeric = isNumericColumn(cells, 0);
|
|
4755
|
-
const valueColumnNumeric = isNumericColumn(cells, 1);
|
|
4756
|
-
if (!labelColumnNumeric && !valueColumnNumeric) {
|
|
4757
|
-
return { type: NOT_SPREADSHEET, reason: "Value is not numeric" };
|
|
4758
|
-
}
|
|
4759
|
-
const [labelColumnIndex, valueColumnIndex] = valueColumnNumeric ? [0, 1] : [1, 0];
|
|
4760
|
-
const hasHeader = tryParseNumber(cells[0][valueColumnIndex]) === null;
|
|
4761
|
-
const rows = hasHeader ? cells.slice(1) : cells;
|
|
4762
|
-
if (rows.length < 2) {
|
|
4763
|
-
return { type: NOT_SPREADSHEET, reason: "Less than 2 rows" };
|
|
4764
|
-
}
|
|
4765
|
-
return {
|
|
4766
|
-
type: VALID_SPREADSHEET,
|
|
4767
|
-
spreadsheet: {
|
|
4768
|
-
title: hasHeader ? cells[0][valueColumnIndex] : null,
|
|
4769
|
-
labels: rows.map((row) => row[labelColumnIndex]),
|
|
4770
|
-
values: rows.map((row) => tryParseNumber(row[valueColumnIndex]))
|
|
4771
|
-
}
|
|
4772
|
-
};
|
|
4773
|
-
};
|
|
4774
|
-
var transposeCells = (cells) => {
|
|
4775
|
-
const nextCells = [];
|
|
4776
|
-
for (let col = 0; col < cells[0].length; col++) {
|
|
4777
|
-
const nextCellRow = [];
|
|
4778
|
-
for (let row = 0; row < cells.length; row++) {
|
|
4779
|
-
nextCellRow.push(cells[row][col]);
|
|
4780
|
-
}
|
|
4781
|
-
nextCells.push(nextCellRow);
|
|
4782
|
-
}
|
|
4783
|
-
return nextCells;
|
|
4784
|
-
};
|
|
4785
|
-
var tryParseSpreadsheet = (text) => {
|
|
4786
|
-
let lines = text.trim().split("\n").map((line) => line.trim().split(" "));
|
|
4787
|
-
if (lines.length && lines[0].length !== 2) {
|
|
4788
|
-
lines = text.trim().split("\n").map((line) => line.trim().split(","));
|
|
4789
|
-
}
|
|
4790
|
-
if (lines.length === 0) {
|
|
4791
|
-
return { type: NOT_SPREADSHEET, reason: "No values" };
|
|
4792
|
-
}
|
|
4793
|
-
const numColsFirstLine = lines[0].length;
|
|
4794
|
-
const isSpreadsheet = lines.every((line) => line.length === numColsFirstLine);
|
|
4795
|
-
if (!isSpreadsheet) {
|
|
4796
|
-
return {
|
|
4797
|
-
type: NOT_SPREADSHEET,
|
|
4798
|
-
reason: "All rows don't have same number of columns"
|
|
4799
|
-
};
|
|
4800
|
-
}
|
|
4801
|
-
const result = tryParseCells(lines);
|
|
4802
|
-
if (result.type !== VALID_SPREADSHEET) {
|
|
4803
|
-
const transposedResults = tryParseCells(transposeCells(lines));
|
|
4804
|
-
if (transposedResults.type === VALID_SPREADSHEET) {
|
|
4805
|
-
return transposedResults;
|
|
4806
|
-
}
|
|
4807
|
-
}
|
|
4808
|
-
return result;
|
|
4809
|
-
};
|
|
4810
|
-
var bgColors = getAllColorsSpecificShade(DEFAULT_CHART_COLOR_INDEX);
|
|
4811
|
-
var commonProps = {
|
|
4812
|
-
fillStyle: "hachure",
|
|
4813
|
-
fontFamily: DEFAULT_FONT_FAMILY2,
|
|
4814
|
-
fontSize: DEFAULT_FONT_SIZE2,
|
|
4815
|
-
opacity: 100,
|
|
4816
|
-
roughness: 1,
|
|
4817
|
-
strokeColor: COLOR_PALETTE2.black,
|
|
4818
|
-
roundness: null,
|
|
4819
|
-
strokeStyle: "solid",
|
|
4820
|
-
strokeWidth: 1,
|
|
4821
|
-
verticalAlign: VERTICAL_ALIGN.MIDDLE,
|
|
4822
|
-
locked: false
|
|
4823
|
-
};
|
|
4824
|
-
var getChartDimensions = (spreadsheet) => {
|
|
4825
|
-
const chartWidth = (BAR_WIDTH + BAR_GAP) * spreadsheet.values.length + BAR_GAP;
|
|
4826
|
-
const chartHeight = BAR_HEIGHT + BAR_GAP * 2;
|
|
4827
|
-
return { chartWidth, chartHeight };
|
|
4828
|
-
};
|
|
4829
|
-
var chartXLabels = (spreadsheet, x, y, groupId, backgroundColor) => {
|
|
4830
|
-
return spreadsheet.labels?.map((label, index) => {
|
|
4831
|
-
return newTextElement2({
|
|
4832
|
-
groupIds: [groupId],
|
|
4833
|
-
backgroundColor,
|
|
4834
|
-
...commonProps,
|
|
4835
|
-
text: label.length > 8 ? `${label.slice(0, 5)}...` : label,
|
|
4836
|
-
x: x + index * (BAR_WIDTH + BAR_GAP) + BAR_GAP * 2,
|
|
4837
|
-
y: y + BAR_GAP / 2,
|
|
4838
|
-
width: BAR_WIDTH,
|
|
4839
|
-
angle: 5.87,
|
|
4840
|
-
fontSize: 16,
|
|
4841
|
-
textAlign: "center",
|
|
4842
|
-
verticalAlign: "top"
|
|
4843
|
-
});
|
|
4844
|
-
}) || [];
|
|
4845
|
-
};
|
|
4846
|
-
var chartYLabels = (spreadsheet, x, y, groupId, backgroundColor) => {
|
|
4847
|
-
const minYLabel = newTextElement2({
|
|
4848
|
-
groupIds: [groupId],
|
|
4849
|
-
backgroundColor,
|
|
4850
|
-
...commonProps,
|
|
4851
|
-
x: x - BAR_GAP,
|
|
4852
|
-
y: y - BAR_GAP,
|
|
4853
|
-
text: "0",
|
|
4854
|
-
textAlign: "right"
|
|
4855
|
-
});
|
|
4856
|
-
const maxYLabel = newTextElement2({
|
|
4857
|
-
groupIds: [groupId],
|
|
4858
|
-
backgroundColor,
|
|
4859
|
-
...commonProps,
|
|
4860
|
-
x: x - BAR_GAP,
|
|
4861
|
-
y: y - BAR_HEIGHT - minYLabel.height / 2,
|
|
4862
|
-
text: Math.max(...spreadsheet.values).toLocaleString(),
|
|
4863
|
-
textAlign: "right"
|
|
4864
|
-
});
|
|
4865
|
-
return [minYLabel, maxYLabel];
|
|
4866
|
-
};
|
|
4867
|
-
var chartLines = (spreadsheet, x, y, groupId, backgroundColor) => {
|
|
4868
|
-
const { chartWidth, chartHeight } = getChartDimensions(spreadsheet);
|
|
4869
|
-
const xLine = newLinearElement({
|
|
4870
|
-
backgroundColor,
|
|
4871
|
-
groupIds: [groupId],
|
|
4872
|
-
...commonProps,
|
|
4873
|
-
type: "line",
|
|
4874
|
-
x,
|
|
4875
|
-
y,
|
|
4876
|
-
width: chartWidth,
|
|
4877
|
-
points: [pointFrom3(0, 0), pointFrom3(chartWidth, 0)]
|
|
4878
|
-
});
|
|
4879
|
-
const yLine = newLinearElement({
|
|
4880
|
-
backgroundColor,
|
|
4881
|
-
groupIds: [groupId],
|
|
4882
|
-
...commonProps,
|
|
4883
|
-
type: "line",
|
|
4884
|
-
x,
|
|
4885
|
-
y,
|
|
4886
|
-
height: chartHeight,
|
|
4887
|
-
points: [pointFrom3(0, 0), pointFrom3(0, -chartHeight)]
|
|
4888
|
-
});
|
|
4889
|
-
const maxLine = newLinearElement({
|
|
4890
|
-
backgroundColor,
|
|
4891
|
-
groupIds: [groupId],
|
|
4892
|
-
...commonProps,
|
|
4893
|
-
type: "line",
|
|
4894
|
-
x,
|
|
4895
|
-
y: y - BAR_HEIGHT - BAR_GAP,
|
|
4896
|
-
strokeStyle: "dotted",
|
|
4897
|
-
width: chartWidth,
|
|
4898
|
-
opacity: GRID_OPACITY,
|
|
4899
|
-
points: [pointFrom3(0, 0), pointFrom3(chartWidth, 0)]
|
|
4900
|
-
});
|
|
4901
|
-
return [xLine, yLine, maxLine];
|
|
4902
|
-
};
|
|
4903
|
-
var chartBaseElements = (spreadsheet, x, y, groupId, backgroundColor, debug) => {
|
|
4904
|
-
const { chartWidth, chartHeight } = getChartDimensions(spreadsheet);
|
|
4905
|
-
const title = spreadsheet.title ? newTextElement2({
|
|
4906
|
-
backgroundColor,
|
|
4907
|
-
groupIds: [groupId],
|
|
4908
|
-
...commonProps,
|
|
4909
|
-
text: spreadsheet.title,
|
|
4910
|
-
x: x + chartWidth / 2,
|
|
4911
|
-
y: y - BAR_HEIGHT - BAR_GAP * 2 - DEFAULT_FONT_SIZE2,
|
|
4912
|
-
roundness: null,
|
|
4913
|
-
textAlign: "center"
|
|
4914
|
-
}) : null;
|
|
4915
|
-
const debugRect = debug ? newElement({
|
|
4916
|
-
backgroundColor,
|
|
4917
|
-
groupIds: [groupId],
|
|
4918
|
-
...commonProps,
|
|
4919
|
-
type: "rectangle",
|
|
4920
|
-
x,
|
|
4921
|
-
y: y - chartHeight,
|
|
4922
|
-
width: chartWidth,
|
|
4923
|
-
height: chartHeight,
|
|
4924
|
-
strokeColor: COLOR_PALETTE2.black,
|
|
4925
|
-
fillStyle: "solid",
|
|
4926
|
-
opacity: 6
|
|
4927
|
-
}) : null;
|
|
4928
|
-
return [
|
|
4929
|
-
...debugRect ? [debugRect] : [],
|
|
4930
|
-
...title ? [title] : [],
|
|
4931
|
-
...chartXLabels(spreadsheet, x, y, groupId, backgroundColor),
|
|
4932
|
-
...chartYLabels(spreadsheet, x, y, groupId, backgroundColor),
|
|
4933
|
-
...chartLines(spreadsheet, x, y, groupId, backgroundColor)
|
|
4934
|
-
];
|
|
4935
|
-
};
|
|
4936
|
-
var chartTypeBar = (spreadsheet, x, y) => {
|
|
4937
|
-
const max = Math.max(...spreadsheet.values);
|
|
4938
|
-
const groupId = randomId();
|
|
4939
|
-
const backgroundColor = bgColors[Math.floor(Math.random() * bgColors.length)];
|
|
4940
|
-
const bars = spreadsheet.values.map((value, index) => {
|
|
4941
|
-
const barHeight = value / max * BAR_HEIGHT;
|
|
4942
|
-
return newElement({
|
|
4943
|
-
backgroundColor,
|
|
4944
|
-
groupIds: [groupId],
|
|
4945
|
-
...commonProps,
|
|
4946
|
-
type: "rectangle",
|
|
4947
|
-
x: x + index * (BAR_WIDTH + BAR_GAP) + BAR_GAP,
|
|
4948
|
-
y: y - barHeight - BAR_GAP,
|
|
4949
|
-
width: BAR_WIDTH,
|
|
4950
|
-
height: barHeight
|
|
4951
|
-
});
|
|
4952
|
-
});
|
|
4953
|
-
return [
|
|
4954
|
-
...bars,
|
|
4955
|
-
...chartBaseElements(
|
|
4956
|
-
spreadsheet,
|
|
4957
|
-
x,
|
|
4958
|
-
y,
|
|
4959
|
-
groupId,
|
|
4960
|
-
backgroundColor,
|
|
4961
|
-
isDevEnv()
|
|
4962
|
-
)
|
|
4963
|
-
];
|
|
4964
|
-
};
|
|
4965
|
-
var chartTypeLine = (spreadsheet, x, y) => {
|
|
4966
|
-
const max = Math.max(...spreadsheet.values);
|
|
4967
|
-
const groupId = randomId();
|
|
4968
|
-
const backgroundColor = bgColors[Math.floor(Math.random() * bgColors.length)];
|
|
4969
|
-
let index = 0;
|
|
4970
|
-
const points = [];
|
|
4971
|
-
for (const value of spreadsheet.values) {
|
|
4972
|
-
const cx = index * (BAR_WIDTH + BAR_GAP);
|
|
4973
|
-
const cy = -(value / max) * BAR_HEIGHT;
|
|
4974
|
-
points.push([cx, cy]);
|
|
4975
|
-
index++;
|
|
4976
|
-
}
|
|
4977
|
-
const maxX = Math.max(...points.map((element) => element[0]));
|
|
4978
|
-
const maxY = Math.max(...points.map((element) => element[1]));
|
|
4979
|
-
const minX = Math.min(...points.map((element) => element[0]));
|
|
4980
|
-
const minY = Math.min(...points.map((element) => element[1]));
|
|
4981
|
-
const line = newLinearElement({
|
|
4982
|
-
backgroundColor,
|
|
4983
|
-
groupIds: [groupId],
|
|
4984
|
-
...commonProps,
|
|
4985
|
-
type: "line",
|
|
4986
|
-
x: x + BAR_GAP + BAR_WIDTH / 2,
|
|
4987
|
-
y: y - BAR_GAP,
|
|
4988
|
-
height: maxY - minY,
|
|
4989
|
-
width: maxX - minX,
|
|
4990
|
-
strokeWidth: 2,
|
|
4991
|
-
points
|
|
4992
|
-
});
|
|
4993
|
-
const dots = spreadsheet.values.map((value, index2) => {
|
|
4994
|
-
const cx = index2 * (BAR_WIDTH + BAR_GAP) + BAR_GAP / 2;
|
|
4995
|
-
const cy = -(value / max) * BAR_HEIGHT + BAR_GAP / 2;
|
|
4996
|
-
return newElement({
|
|
4997
|
-
backgroundColor,
|
|
4998
|
-
groupIds: [groupId],
|
|
4999
|
-
...commonProps,
|
|
5000
|
-
fillStyle: "solid",
|
|
5001
|
-
strokeWidth: 2,
|
|
5002
|
-
type: "ellipse",
|
|
5003
|
-
x: x + cx + BAR_WIDTH / 2,
|
|
5004
|
-
y: y + cy - BAR_GAP * 2,
|
|
5005
|
-
width: BAR_GAP,
|
|
5006
|
-
height: BAR_GAP
|
|
5007
|
-
});
|
|
5008
|
-
});
|
|
5009
|
-
const lines = spreadsheet.values.map((value, index2) => {
|
|
5010
|
-
const cx = index2 * (BAR_WIDTH + BAR_GAP) + BAR_GAP / 2;
|
|
5011
|
-
const cy = value / max * BAR_HEIGHT + BAR_GAP / 2 + BAR_GAP;
|
|
5012
|
-
return newLinearElement({
|
|
5013
|
-
backgroundColor,
|
|
5014
|
-
groupIds: [groupId],
|
|
5015
|
-
...commonProps,
|
|
5016
|
-
type: "line",
|
|
5017
|
-
x: x + cx + BAR_WIDTH / 2 + BAR_GAP / 2,
|
|
5018
|
-
y: y - cy,
|
|
5019
|
-
height: cy,
|
|
5020
|
-
strokeStyle: "dotted",
|
|
5021
|
-
opacity: GRID_OPACITY,
|
|
5022
|
-
points: [pointFrom3(0, 0), pointFrom3(0, cy)]
|
|
5023
|
-
});
|
|
5024
|
-
});
|
|
5025
|
-
return [
|
|
5026
|
-
...chartBaseElements(
|
|
5027
|
-
spreadsheet,
|
|
5028
|
-
x,
|
|
5029
|
-
y,
|
|
5030
|
-
groupId,
|
|
5031
|
-
backgroundColor,
|
|
5032
|
-
isDevEnv()
|
|
5033
|
-
),
|
|
5034
|
-
line,
|
|
5035
|
-
...lines,
|
|
5036
|
-
...dots
|
|
5037
|
-
];
|
|
5038
|
-
};
|
|
5039
|
-
var renderSpreadsheet = (chartType, spreadsheet, x, y) => {
|
|
5040
|
-
if (chartType === "line") {
|
|
5041
|
-
return chartTypeLine(spreadsheet, x, y);
|
|
5042
|
-
}
|
|
5043
|
-
return chartTypeBar(spreadsheet, x, y);
|
|
5044
|
-
};
|
|
5045
|
-
|
|
5046
|
-
// clipboard.ts
|
|
5047
|
-
var probablySupportsClipboardReadText = "clipboard" in navigator && "readText" in navigator.clipboard;
|
|
5048
|
-
var probablySupportsClipboardWriteText = "clipboard" in navigator && "writeText" in navigator.clipboard;
|
|
5049
|
-
var probablySupportsClipboardBlob = "clipboard" in navigator && "write" in navigator.clipboard && "ClipboardItem" in window && "toBlob" in HTMLCanvasElement.prototype;
|
|
5050
|
-
var clipboardContainsElements = (contents) => {
|
|
5051
|
-
if ([
|
|
5052
|
-
EXPORT_DATA_TYPES3.excalidraw,
|
|
5053
|
-
EXPORT_DATA_TYPES3.excalidrawClipboard,
|
|
5054
|
-
EXPORT_DATA_TYPES3.excalidrawClipboardWithAPI
|
|
5055
|
-
].includes(contents?.type) && Array.isArray(contents.elements)) {
|
|
5056
|
-
return true;
|
|
5057
|
-
}
|
|
5058
|
-
return false;
|
|
5059
|
-
};
|
|
5060
|
-
var createPasteEvent = ({
|
|
5061
|
-
types,
|
|
5062
|
-
files
|
|
5063
|
-
}) => {
|
|
5064
|
-
if (!types && !files) {
|
|
5065
|
-
console.warn("createPasteEvent: no types or files provided");
|
|
5066
|
-
}
|
|
5067
|
-
const event = new ClipboardEvent(EVENT2.PASTE, {
|
|
5068
|
-
clipboardData: new DataTransfer()
|
|
5069
|
-
});
|
|
5070
|
-
if (types) {
|
|
5071
|
-
for (const [type, value] of Object.entries(types)) {
|
|
5072
|
-
if (typeof value !== "string") {
|
|
5073
|
-
files = files || [];
|
|
5074
|
-
files.push(value);
|
|
5075
|
-
continue;
|
|
5076
|
-
}
|
|
5077
|
-
try {
|
|
5078
|
-
event.clipboardData?.setData(type, value);
|
|
5079
|
-
if (event.clipboardData?.getData(type) !== value) {
|
|
5080
|
-
throw new Error(`Failed to set "${type}" as clipboardData item`);
|
|
5081
|
-
}
|
|
5082
|
-
} catch (error) {
|
|
5083
|
-
throw new Error(error.message);
|
|
5084
|
-
}
|
|
5085
|
-
}
|
|
5086
|
-
}
|
|
5087
|
-
if (files) {
|
|
5088
|
-
let idx = -1;
|
|
5089
|
-
for (const file of files) {
|
|
5090
|
-
idx++;
|
|
5091
|
-
try {
|
|
5092
|
-
event.clipboardData?.items.add(file);
|
|
5093
|
-
if (event.clipboardData?.files[idx] !== file) {
|
|
5094
|
-
throw new Error(
|
|
5095
|
-
`Failed to set file "${file.name}" as clipboardData item`
|
|
5096
|
-
);
|
|
5097
|
-
}
|
|
5098
|
-
} catch (error) {
|
|
5099
|
-
throw new Error(error.message);
|
|
5100
|
-
}
|
|
5101
|
-
}
|
|
5102
|
-
}
|
|
5103
|
-
return event;
|
|
5104
|
-
};
|
|
5105
|
-
var serializeAsClipboardJSON = ({
|
|
5106
|
-
elements,
|
|
5107
|
-
files
|
|
5108
|
-
}) => {
|
|
5109
|
-
const elementsMap = arrayToMap2(elements);
|
|
5110
|
-
const framesToCopy = new Set(
|
|
5111
|
-
elements.filter((element) => isFrameLikeElement2(element))
|
|
5112
|
-
);
|
|
5113
|
-
let foundFile = false;
|
|
5114
|
-
const _files = elements.reduce((acc, element) => {
|
|
5115
|
-
if (isInitializedImageElement2(element)) {
|
|
5116
|
-
foundFile = true;
|
|
5117
|
-
if (files && files[element.fileId]) {
|
|
5118
|
-
acc[element.fileId] = files[element.fileId];
|
|
5119
|
-
}
|
|
5120
|
-
}
|
|
5121
|
-
return acc;
|
|
5122
|
-
}, {});
|
|
5123
|
-
if (foundFile && !files) {
|
|
5124
|
-
console.warn(
|
|
5125
|
-
"copyToClipboard: attempting to file element(s) without providing associated `files` object."
|
|
5126
|
-
);
|
|
5127
|
-
}
|
|
5128
|
-
const contents = {
|
|
5129
|
-
type: EXPORT_DATA_TYPES3.excalidrawClipboard,
|
|
5130
|
-
elements: elements.map((element) => {
|
|
5131
|
-
if (getContainingFrame2(element, elementsMap) && !framesToCopy.has(getContainingFrame2(element, elementsMap))) {
|
|
5132
|
-
const copiedElement = deepCopyElement(element);
|
|
5133
|
-
mutateElement(copiedElement, elementsMap, {
|
|
5134
|
-
frameId: null
|
|
5135
|
-
});
|
|
5136
|
-
return copiedElement;
|
|
5137
|
-
}
|
|
5138
|
-
return element;
|
|
5139
|
-
}),
|
|
5140
|
-
files: files ? _files : void 0
|
|
5141
|
-
};
|
|
5142
|
-
return JSON.stringify(contents);
|
|
5143
|
-
};
|
|
5144
|
-
var copyToClipboard = async (elements, files, clipboardEvent) => {
|
|
5145
|
-
await copyTextToSystemClipboard(
|
|
5146
|
-
serializeAsClipboardJSON({ elements, files }),
|
|
5147
|
-
clipboardEvent
|
|
5148
|
-
);
|
|
5149
|
-
};
|
|
5150
|
-
var parsePotentialSpreadsheet = (text) => {
|
|
5151
|
-
const result = tryParseSpreadsheet(text);
|
|
5152
|
-
if (result.type === VALID_SPREADSHEET) {
|
|
5153
|
-
return { spreadsheet: result.spreadsheet };
|
|
5154
|
-
}
|
|
5155
|
-
return null;
|
|
5156
|
-
};
|
|
5157
|
-
function parseHTMLTree(el) {
|
|
5158
|
-
let result = [];
|
|
5159
|
-
for (const node of el.childNodes) {
|
|
5160
|
-
if (node.nodeType === 3) {
|
|
5161
|
-
const text = node.textContent?.trim();
|
|
5162
|
-
if (text) {
|
|
5163
|
-
result.push({ type: "text", value: text });
|
|
5164
|
-
}
|
|
5165
|
-
} else if (node instanceof HTMLImageElement) {
|
|
5166
|
-
const url = node.getAttribute("src");
|
|
5167
|
-
if (url && url.startsWith("http")) {
|
|
5168
|
-
result.push({ type: "imageUrl", value: url });
|
|
5169
|
-
}
|
|
5170
|
-
} else {
|
|
5171
|
-
result = result.concat(parseHTMLTree(node));
|
|
5172
|
-
}
|
|
5173
|
-
}
|
|
5174
|
-
return result;
|
|
5175
|
-
}
|
|
5176
|
-
var maybeParseHTMLPaste = (event) => {
|
|
5177
|
-
const html = event.clipboardData?.getData(MIME_TYPES6.html);
|
|
5178
|
-
if (!html) {
|
|
5179
|
-
return null;
|
|
5180
|
-
}
|
|
5181
|
-
try {
|
|
5182
|
-
const doc = new DOMParser().parseFromString(html, MIME_TYPES6.html);
|
|
5183
|
-
const content = parseHTMLTree(doc.body);
|
|
5184
|
-
if (content.length) {
|
|
5185
|
-
return { type: "mixedContent", value: content };
|
|
5186
|
-
}
|
|
5187
|
-
} catch (error) {
|
|
5188
|
-
console.error(`error in parseHTMLFromPaste: ${error.message}`);
|
|
5189
|
-
}
|
|
5190
|
-
return null;
|
|
5191
|
-
};
|
|
5192
|
-
var readSystemClipboard = async () => {
|
|
5193
|
-
const types = {};
|
|
5194
|
-
let clipboardItems;
|
|
5195
|
-
try {
|
|
5196
|
-
clipboardItems = await navigator.clipboard?.read();
|
|
5197
|
-
} catch (error) {
|
|
5198
|
-
try {
|
|
5199
|
-
if (navigator.clipboard?.readText) {
|
|
5200
|
-
console.warn(
|
|
5201
|
-
`navigator.clipboard.readText() failed (${error.message}). Failling back to navigator.clipboard.read()`
|
|
5202
|
-
);
|
|
5203
|
-
const readText = await navigator.clipboard?.readText();
|
|
5204
|
-
if (readText) {
|
|
5205
|
-
return { [MIME_TYPES6.text]: readText };
|
|
5206
|
-
}
|
|
5207
|
-
}
|
|
5208
|
-
} catch (error2) {
|
|
5209
|
-
if (navigator.clipboard?.read) {
|
|
5210
|
-
console.warn(
|
|
5211
|
-
`navigator.clipboard.readText() failed (${error2.message}). Failling back to navigator.clipboard.read()`
|
|
5212
|
-
);
|
|
5213
|
-
} else {
|
|
5214
|
-
if (error2.name === "DataError") {
|
|
5215
|
-
console.warn(
|
|
5216
|
-
`navigator.clipboard.read() error, clipboard is probably empty: ${error2.message}`
|
|
5217
|
-
);
|
|
5218
|
-
return types;
|
|
5219
|
-
}
|
|
5220
|
-
throw error2;
|
|
5221
|
-
}
|
|
5222
|
-
}
|
|
5223
|
-
throw error;
|
|
5224
|
-
}
|
|
5225
|
-
for (const item of clipboardItems) {
|
|
5226
|
-
for (const type of item.types) {
|
|
5227
|
-
if (!isMemberOf(ALLOWED_PASTE_MIME_TYPES, type)) {
|
|
5228
|
-
continue;
|
|
5229
|
-
}
|
|
5230
|
-
try {
|
|
5231
|
-
if (type === MIME_TYPES6.text || type === MIME_TYPES6.html) {
|
|
5232
|
-
types[type] = await (await item.getType(type)).text();
|
|
5233
|
-
} else if (isSupportedImageFileType(type)) {
|
|
5234
|
-
const imageBlob = await item.getType(type);
|
|
5235
|
-
const file = createFile(imageBlob, type, void 0);
|
|
5236
|
-
types[type] = file;
|
|
5237
|
-
} else {
|
|
5238
|
-
throw new ExcalidrawError(`Unsupported clipboard type: ${type}`);
|
|
5239
|
-
}
|
|
5240
|
-
} catch (error) {
|
|
5241
|
-
console.warn(
|
|
5242
|
-
error instanceof ExcalidrawError ? error.message : `Cannot retrieve ${type} from clipboardItem: ${error.message}`
|
|
5243
|
-
);
|
|
5244
|
-
}
|
|
5245
|
-
}
|
|
5246
|
-
}
|
|
5247
|
-
if (Object.keys(types).length === 0) {
|
|
5248
|
-
console.warn("No clipboard data found from clipboard.read().");
|
|
5249
|
-
return types;
|
|
5250
|
-
}
|
|
5251
|
-
return types;
|
|
5252
|
-
};
|
|
5253
|
-
var parseClipboardEventTextData = async (event, isPlainPaste = false) => {
|
|
5254
|
-
try {
|
|
5255
|
-
const mixedContent = !isPlainPaste && event && maybeParseHTMLPaste(event);
|
|
5256
|
-
if (mixedContent) {
|
|
5257
|
-
if (mixedContent.value.every((item) => item.type === "text")) {
|
|
5258
|
-
return {
|
|
5259
|
-
type: "text",
|
|
5260
|
-
value: event.clipboardData?.getData(MIME_TYPES6.text) || mixedContent.value.map((item) => item.value).join("\n").trim()
|
|
5261
|
-
};
|
|
5262
|
-
}
|
|
5263
|
-
return mixedContent;
|
|
5264
|
-
}
|
|
5265
|
-
const text = event.clipboardData?.getData(MIME_TYPES6.text);
|
|
5266
|
-
return { type: "text", value: (text || "").trim() };
|
|
5267
|
-
} catch {
|
|
5268
|
-
return { type: "text", value: "" };
|
|
5269
|
-
}
|
|
5270
|
-
};
|
|
5271
|
-
var parseClipboard = async (event, isPlainPaste = false) => {
|
|
5272
|
-
const parsedEventData = await parseClipboardEventTextData(
|
|
5273
|
-
event,
|
|
5274
|
-
isPlainPaste
|
|
5275
|
-
);
|
|
5276
|
-
if (parsedEventData.type === "mixedContent") {
|
|
5277
|
-
return {
|
|
5278
|
-
mixedContent: parsedEventData.value
|
|
5279
|
-
};
|
|
5280
|
-
}
|
|
5281
|
-
try {
|
|
5282
|
-
const spreadsheetResult = !isPlainPaste && parsePotentialSpreadsheet(parsedEventData.value);
|
|
5283
|
-
if (spreadsheetResult) {
|
|
5284
|
-
return spreadsheetResult;
|
|
5285
|
-
}
|
|
5286
|
-
} catch (error) {
|
|
5287
|
-
console.error(error);
|
|
5288
|
-
}
|
|
5289
|
-
try {
|
|
5290
|
-
const systemClipboardData = JSON.parse(parsedEventData.value);
|
|
5291
|
-
const programmaticAPI = systemClipboardData.type === EXPORT_DATA_TYPES3.excalidrawClipboardWithAPI;
|
|
5292
|
-
if (clipboardContainsElements(systemClipboardData)) {
|
|
5293
|
-
return {
|
|
5294
|
-
elements: systemClipboardData.elements,
|
|
5295
|
-
files: systemClipboardData.files,
|
|
5296
|
-
text: isPlainPaste ? JSON.stringify(systemClipboardData.elements, null, 2) : void 0,
|
|
5297
|
-
programmaticAPI
|
|
5298
|
-
};
|
|
5299
|
-
}
|
|
5300
|
-
} catch {
|
|
5301
|
-
}
|
|
5302
|
-
return { text: parsedEventData.value };
|
|
5303
|
-
};
|
|
5304
|
-
var copyBlobToClipboardAsPng = async (blob) => {
|
|
5305
|
-
try {
|
|
5306
|
-
await navigator.clipboard.write([
|
|
5307
|
-
new window.ClipboardItem({
|
|
5308
|
-
[MIME_TYPES6.png]: blob
|
|
5309
|
-
})
|
|
5310
|
-
]);
|
|
5311
|
-
} catch (error) {
|
|
5312
|
-
if (isPromiseLike(blob)) {
|
|
5313
|
-
await navigator.clipboard.write([
|
|
5314
|
-
new window.ClipboardItem({
|
|
5315
|
-
[MIME_TYPES6.png]: await blob
|
|
5316
|
-
})
|
|
5317
|
-
]);
|
|
5318
|
-
} else {
|
|
5319
|
-
throw error;
|
|
5320
|
-
}
|
|
5321
|
-
}
|
|
5322
|
-
};
|
|
5323
|
-
var copyTextToSystemClipboard = async (text, clipboardEvent) => {
|
|
5324
|
-
if (probablySupportsClipboardWriteText) {
|
|
5325
|
-
try {
|
|
5326
|
-
await navigator.clipboard.writeText(text || "");
|
|
5327
|
-
return;
|
|
5328
|
-
} catch (error) {
|
|
5329
|
-
console.error(error);
|
|
5330
|
-
}
|
|
5331
|
-
}
|
|
5332
|
-
try {
|
|
5333
|
-
if (clipboardEvent) {
|
|
5334
|
-
clipboardEvent.clipboardData?.setData(MIME_TYPES6.text, text || "");
|
|
5335
|
-
if (clipboardEvent.clipboardData?.getData(MIME_TYPES6.text) !== text) {
|
|
5336
|
-
throw new Error("Failed to setData on clipboardEvent");
|
|
5337
|
-
}
|
|
5338
|
-
return;
|
|
5339
|
-
}
|
|
5340
|
-
} catch (error) {
|
|
5341
|
-
console.error(error);
|
|
5342
|
-
}
|
|
5343
|
-
if (!copyTextViaExecCommand(text)) {
|
|
5344
|
-
throw new Error("Error copying to clipboard.");
|
|
5345
|
-
}
|
|
5346
|
-
};
|
|
5347
|
-
var copyTextViaExecCommand = (text) => {
|
|
5348
|
-
if (!text) {
|
|
5349
|
-
text = " ";
|
|
5350
|
-
}
|
|
5351
|
-
const isRTL2 = document.documentElement.getAttribute("dir") === "rtl";
|
|
5352
|
-
const textarea = document.createElement("textarea");
|
|
5353
|
-
textarea.style.border = "0";
|
|
5354
|
-
textarea.style.padding = "0";
|
|
5355
|
-
textarea.style.margin = "0";
|
|
5356
|
-
textarea.style.position = "absolute";
|
|
5357
|
-
textarea.style[isRTL2 ? "right" : "left"] = "-9999px";
|
|
5358
|
-
const yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
|
5359
|
-
textarea.style.top = `${yPosition}px`;
|
|
5360
|
-
textarea.style.fontSize = "12pt";
|
|
5361
|
-
textarea.setAttribute("readonly", "");
|
|
5362
|
-
textarea.value = text;
|
|
5363
|
-
document.body.appendChild(textarea);
|
|
5364
|
-
let success = false;
|
|
5365
|
-
try {
|
|
5366
|
-
textarea.select();
|
|
5367
|
-
textarea.setSelectionRange(0, textarea.value.length);
|
|
5368
|
-
success = document.execCommand("copy");
|
|
5369
|
-
} catch (error) {
|
|
5370
|
-
console.error(error);
|
|
5371
|
-
}
|
|
5372
|
-
textarea.remove();
|
|
5373
|
-
return success;
|
|
5374
|
-
};
|
|
5375
|
-
var isClipboardEvent = (event) => {
|
|
5376
|
-
return event.type === EVENT2.PASTE || event.type === EVENT2.COPY || event.type === EVENT2.CUT;
|
|
5377
|
-
};
|
|
5378
|
-
|
|
5379
4680
|
// data/restore.ts
|
|
5380
|
-
import { isFiniteNumber, pointFrom as
|
|
4681
|
+
import { isFiniteNumber, pointFrom as pointFrom3 } from "@excalidraw/math";
|
|
5381
4682
|
import {
|
|
5382
|
-
DEFAULT_FONT_FAMILY as
|
|
4683
|
+
DEFAULT_FONT_FAMILY as DEFAULT_FONT_FAMILY2,
|
|
5383
4684
|
DEFAULT_TEXT_ALIGN as DEFAULT_TEXT_ALIGN2,
|
|
5384
4685
|
DEFAULT_VERTICAL_ALIGN,
|
|
5385
4686
|
FONT_FAMILY as FONT_FAMILY3,
|
|
@@ -5388,10 +4689,10 @@ import {
|
|
|
5388
4689
|
DEFAULT_ELEMENT_PROPS as DEFAULT_ELEMENT_PROPS2,
|
|
5389
4690
|
DEFAULT_GRID_SIZE as DEFAULT_GRID_SIZE2,
|
|
5390
4691
|
DEFAULT_GRID_STEP as DEFAULT_GRID_STEP2,
|
|
5391
|
-
randomId
|
|
4692
|
+
randomId,
|
|
5392
4693
|
getUpdatedTimestamp,
|
|
5393
4694
|
updateActiveTool,
|
|
5394
|
-
arrayToMap as
|
|
4695
|
+
arrayToMap as arrayToMap2,
|
|
5395
4696
|
getSizeFromPoints,
|
|
5396
4697
|
normalizeLink as normalizeLink2,
|
|
5397
4698
|
getLineHeight
|
|
@@ -5443,7 +4744,7 @@ var getFontFamilyByName = (fontFamilyName) => {
|
|
|
5443
4744
|
if (Object.keys(FONT_FAMILY3).includes(fontFamilyName)) {
|
|
5444
4745
|
return FONT_FAMILY3[fontFamilyName];
|
|
5445
4746
|
}
|
|
5446
|
-
return
|
|
4747
|
+
return DEFAULT_FONT_FAMILY2;
|
|
5447
4748
|
};
|
|
5448
4749
|
var repairBinding = (element, binding) => {
|
|
5449
4750
|
if (!binding) {
|
|
@@ -5472,7 +4773,7 @@ var restoreElementWithProperties = (element, extra) => {
|
|
|
5472
4773
|
versionNonce: element.versionNonce ?? 0,
|
|
5473
4774
|
index: element.index ?? null,
|
|
5474
4775
|
isDeleted: element.isDeleted ?? false,
|
|
5475
|
-
id: element.id ||
|
|
4776
|
+
id: element.id || randomId(),
|
|
5476
4777
|
fillStyle: element.fillStyle || DEFAULT_ELEMENT_PROPS2.fillStyle,
|
|
5477
4778
|
strokeWidth: element.strokeWidth || DEFAULT_ELEMENT_PROPS2.strokeWidth,
|
|
5478
4779
|
strokeStyle: element.strokeStyle ?? DEFAULT_ELEMENT_PROPS2.strokeStyle,
|
|
@@ -5573,7 +4874,7 @@ var restoreElement = (element, opts) => {
|
|
|
5573
4874
|
let y = element.y;
|
|
5574
4875
|
let points = (
|
|
5575
4876
|
// migrate old arrow model to new one
|
|
5576
|
-
!Array.isArray(element.points) || element.points.length < 2 ? [
|
|
4877
|
+
!Array.isArray(element.points) || element.points.length < 2 ? [pointFrom3(0, 0), pointFrom3(element.width, element.height)] : element.points
|
|
5577
4878
|
);
|
|
5578
4879
|
if (points[0][0] !== 0 || points[0][1] !== 0) {
|
|
5579
4880
|
({ points, x, y } = LinearElementEditor2.getNormalizeElementPointsAndCoords(element));
|
|
@@ -5599,7 +4900,7 @@ var restoreElement = (element, opts) => {
|
|
|
5599
4900
|
let y2 = element.y;
|
|
5600
4901
|
let points2 = (
|
|
5601
4902
|
// migrate old arrow model to new one
|
|
5602
|
-
!Array.isArray(element.points) || element.points.length < 2 ? [
|
|
4903
|
+
!Array.isArray(element.points) || element.points.length < 2 ? [pointFrom3(0, 0), pointFrom3(element.width, element.height)] : element.points
|
|
5603
4904
|
);
|
|
5604
4905
|
if (points2[0][0] !== 0 || points2[0][1] !== 0) {
|
|
5605
4906
|
({ points: points2, x: x2, y: y2 } = LinearElementEditor2.getNormalizeElementPointsAndCoords(element));
|
|
@@ -5692,7 +4993,7 @@ var repairFrameMembership = (element, elementsMap) => {
|
|
|
5692
4993
|
};
|
|
5693
4994
|
var restoreElements = (elements, localElements, opts) => {
|
|
5694
4995
|
const existingIds = /* @__PURE__ */ new Set();
|
|
5695
|
-
const localElementsMap = localElements ?
|
|
4996
|
+
const localElementsMap = localElements ? arrayToMap2(localElements) : null;
|
|
5696
4997
|
const restoredElements = syncInvalidIndices2(
|
|
5697
4998
|
(elements || []).reduce((elements2, element) => {
|
|
5698
4999
|
if (element.type === "selection") {
|
|
@@ -5711,7 +5012,7 @@ var restoreElements = (elements, localElements, opts) => {
|
|
|
5711
5012
|
migratedElement = { ...migratedElement, isDeleted: true };
|
|
5712
5013
|
}
|
|
5713
5014
|
if (existingIds.has(migratedElement.id)) {
|
|
5714
|
-
migratedElement = { ...migratedElement, id:
|
|
5015
|
+
migratedElement = { ...migratedElement, id: randomId() };
|
|
5715
5016
|
}
|
|
5716
5017
|
existingIds.add(migratedElement.id);
|
|
5717
5018
|
elements2.push(migratedElement);
|
|
@@ -5722,7 +5023,7 @@ var restoreElements = (elements, localElements, opts) => {
|
|
|
5722
5023
|
if (!opts?.repairBindings) {
|
|
5723
5024
|
return restoredElements;
|
|
5724
5025
|
}
|
|
5725
|
-
const restoredElementsMap =
|
|
5026
|
+
const restoredElementsMap = arrayToMap2(restoredElements);
|
|
5726
5027
|
for (const element of restoredElements) {
|
|
5727
5028
|
if (element.frameId) {
|
|
5728
5029
|
repairFrameMembership(element, restoredElementsMap);
|
|
@@ -5760,7 +5061,7 @@ var restoreElements = (elements, localElements, opts) => {
|
|
|
5760
5061
|
restoredElementsMap,
|
|
5761
5062
|
{
|
|
5762
5063
|
points: [
|
|
5763
|
-
|
|
5064
|
+
pointFrom3(0, 0),
|
|
5764
5065
|
element.points[element.points.length - 1]
|
|
5765
5066
|
]
|
|
5766
5067
|
}
|
|
@@ -5789,10 +5090,10 @@ var restoreElements = (elements, localElements, opts) => {
|
|
|
5789
5090
|
width: boundElement.width,
|
|
5790
5091
|
height: boundElement.height,
|
|
5791
5092
|
points: [
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5093
|
+
pointFrom3(0, 0),
|
|
5094
|
+
pointFrom3(0, -10),
|
|
5095
|
+
pointFrom3(boundElement.width / 2 + 5, -10),
|
|
5096
|
+
pointFrom3(
|
|
5796
5097
|
boundElement.width / 2 + 5,
|
|
5797
5098
|
boundElement.height / 2 + 5
|
|
5798
5099
|
)
|
|
@@ -5891,7 +5192,7 @@ var restoreLibraryItems = (libraryItems = [], defaultStatus) => {
|
|
|
5891
5192
|
const restoredItem = restoreLibraryItem({
|
|
5892
5193
|
status: defaultStatus,
|
|
5893
5194
|
elements: item,
|
|
5894
|
-
id:
|
|
5195
|
+
id: randomId(),
|
|
5895
5196
|
created: Date.now()
|
|
5896
5197
|
});
|
|
5897
5198
|
if (restoredItem) {
|
|
@@ -5901,7 +5202,7 @@ var restoreLibraryItems = (libraryItems = [], defaultStatus) => {
|
|
|
5901
5202
|
const _item = item;
|
|
5902
5203
|
const restoredItem = restoreLibraryItem({
|
|
5903
5204
|
..._item,
|
|
5904
|
-
id: _item.id ||
|
|
5205
|
+
id: _item.id || randomId(),
|
|
5905
5206
|
status: _item.status || defaultStatus,
|
|
5906
5207
|
created: _item.created || Date.now()
|
|
5907
5208
|
});
|
|
@@ -5916,9 +5217,9 @@ var restoreLibraryItems = (libraryItems = [], defaultStatus) => {
|
|
|
5916
5217
|
// data/blob.ts
|
|
5917
5218
|
var parseFileContents = async (blob) => {
|
|
5918
5219
|
let contents;
|
|
5919
|
-
if (blob.type ===
|
|
5220
|
+
if (blob.type === MIME_TYPES6.png) {
|
|
5920
5221
|
try {
|
|
5921
|
-
return await (await import("./data/image-
|
|
5222
|
+
return await (await import("./data/image-VTYIFRQE.js")).decodePngMetadata(blob);
|
|
5922
5223
|
} catch (error) {
|
|
5923
5224
|
if (error.message === "INVALID") {
|
|
5924
5225
|
throw new ImageSceneDataError(
|
|
@@ -5943,7 +5244,7 @@ var parseFileContents = async (blob) => {
|
|
|
5943
5244
|
};
|
|
5944
5245
|
});
|
|
5945
5246
|
}
|
|
5946
|
-
if (blob.type ===
|
|
5247
|
+
if (blob.type === MIME_TYPES6.svg) {
|
|
5947
5248
|
try {
|
|
5948
5249
|
return decodeSvgBase64Payload({
|
|
5949
5250
|
svg: contents
|
|
@@ -5999,7 +5300,7 @@ var loadSceneOrLibraryFromBlob = async (blob, localAppState, localElements, file
|
|
|
5999
5300
|
}
|
|
6000
5301
|
if (isValidExcalidrawData(data)) {
|
|
6001
5302
|
return {
|
|
6002
|
-
type:
|
|
5303
|
+
type: MIME_TYPES6.excalidraw,
|
|
6003
5304
|
data: restore(
|
|
6004
5305
|
{
|
|
6005
5306
|
elements: clearElementsForExport2(data.elements || []),
|
|
@@ -6022,7 +5323,7 @@ var loadSceneOrLibraryFromBlob = async (blob, localAppState, localElements, file
|
|
|
6022
5323
|
};
|
|
6023
5324
|
} else if (isValidLibrary(data)) {
|
|
6024
5325
|
return {
|
|
6025
|
-
type:
|
|
5326
|
+
type: MIME_TYPES6.excalidrawlib,
|
|
6026
5327
|
data
|
|
6027
5328
|
};
|
|
6028
5329
|
}
|
|
@@ -6041,7 +5342,7 @@ var loadFromBlob = async (blob, localAppState, localElements, fileHandle) => {
|
|
|
6041
5342
|
localElements,
|
|
6042
5343
|
fileHandle
|
|
6043
5344
|
);
|
|
6044
|
-
if (ret.type !==
|
|
5345
|
+
if (ret.type !== MIME_TYPES6.excalidraw) {
|
|
6045
5346
|
throw new Error("Error: invalid file");
|
|
6046
5347
|
}
|
|
6047
5348
|
return ret.data;
|
|
@@ -6060,7 +5361,7 @@ var loadLibraryFromBlob = async (blob, defaultStatus = "unpublished") => {
|
|
|
6060
5361
|
var canvasToBlob = async (canvas) => {
|
|
6061
5362
|
return new Promise(async (resolve, reject) => {
|
|
6062
5363
|
try {
|
|
6063
|
-
if (
|
|
5364
|
+
if (isPromiseLike(canvas)) {
|
|
6064
5365
|
canvas = await canvas;
|
|
6065
5366
|
}
|
|
6066
5367
|
canvas.toBlob((blob) => {
|
|
@@ -6109,7 +5410,7 @@ var dataURLToString = (dataURL) => {
|
|
|
6109
5410
|
return base64ToString(dataURL.slice(dataURL.indexOf(",") + 1));
|
|
6110
5411
|
};
|
|
6111
5412
|
var resizeImageFile = async (file, opts) => {
|
|
6112
|
-
if (file.type ===
|
|
5413
|
+
if (file.type === MIME_TYPES6.svg) {
|
|
6113
5414
|
return file;
|
|
6114
5415
|
}
|
|
6115
5416
|
const [pica, imageBlobReduce] = await Promise.all([
|
|
@@ -6142,7 +5443,7 @@ var resizeImageFile = async (file, opts) => {
|
|
|
6142
5443
|
};
|
|
6143
5444
|
var SVGStringToFile = (SVGString, filename = "") => {
|
|
6144
5445
|
return new File([new TextEncoder().encode(SVGString)], filename, {
|
|
6145
|
-
type:
|
|
5446
|
+
type: MIME_TYPES6.svg
|
|
6146
5447
|
});
|
|
6147
5448
|
};
|
|
6148
5449
|
var ImageURLToFile = async (imageUrl, filename = "") => {
|
|
@@ -6162,32 +5463,6 @@ var ImageURLToFile = async (imageUrl, filename = "") => {
|
|
|
6162
5463
|
}
|
|
6163
5464
|
throw new Error("Error: unsupported file type", { cause: "UNSUPPORTED" });
|
|
6164
5465
|
};
|
|
6165
|
-
var getFilesFromEvent = async (event) => {
|
|
6166
|
-
let fileList = void 0;
|
|
6167
|
-
let items = void 0;
|
|
6168
|
-
if (isClipboardEvent(event)) {
|
|
6169
|
-
fileList = event.clipboardData?.files;
|
|
6170
|
-
items = event.clipboardData?.items;
|
|
6171
|
-
} else {
|
|
6172
|
-
const dragEvent = event;
|
|
6173
|
-
fileList = dragEvent.dataTransfer?.files;
|
|
6174
|
-
items = dragEvent.dataTransfer?.items;
|
|
6175
|
-
}
|
|
6176
|
-
const files = Array.from(fileList || []);
|
|
6177
|
-
return await Promise.all(
|
|
6178
|
-
files.map(async (file, idx) => {
|
|
6179
|
-
const dataTransferItem = items?.[idx];
|
|
6180
|
-
const fileHandle = dataTransferItem ? getFileHandle(dataTransferItem) : null;
|
|
6181
|
-
return file ? {
|
|
6182
|
-
file: await normalizeFile(file),
|
|
6183
|
-
fileHandle: await fileHandle
|
|
6184
|
-
} : {
|
|
6185
|
-
file: null,
|
|
6186
|
-
fileHandle: null
|
|
6187
|
-
};
|
|
6188
|
-
})
|
|
6189
|
-
);
|
|
6190
|
-
};
|
|
6191
5466
|
var getFileHandle = async (event) => {
|
|
6192
5467
|
if (nativeFileSystemSupported) {
|
|
6193
5468
|
try {
|
|
@@ -6215,11 +5490,11 @@ var getActualMimeTypeFromImage = (buffer) => {
|
|
|
6215
5490
|
gif: "71 73 70 56 57 97 "
|
|
6216
5491
|
};
|
|
6217
5492
|
if (first8Bytes === headerBytes.png) {
|
|
6218
|
-
mimeType =
|
|
5493
|
+
mimeType = MIME_TYPES6.png;
|
|
6219
5494
|
} else if (first8Bytes.startsWith(headerBytes.jpg)) {
|
|
6220
|
-
mimeType =
|
|
5495
|
+
mimeType = MIME_TYPES6.jpg;
|
|
6221
5496
|
} else if (first8Bytes.startsWith(headerBytes.gif)) {
|
|
6222
|
-
mimeType =
|
|
5497
|
+
mimeType = MIME_TYPES6.gif;
|
|
6223
5498
|
}
|
|
6224
5499
|
return mimeType;
|
|
6225
5500
|
};
|
|
@@ -6233,13 +5508,13 @@ var normalizeFile = async (file) => {
|
|
|
6233
5508
|
if (file?.name?.endsWith(".excalidrawlib")) {
|
|
6234
5509
|
file = createFile(
|
|
6235
5510
|
await blobToArrayBuffer(file),
|
|
6236
|
-
|
|
5511
|
+
MIME_TYPES6.excalidrawlib,
|
|
6237
5512
|
file.name
|
|
6238
5513
|
);
|
|
6239
5514
|
} else if (file?.name?.endsWith(".excalidraw")) {
|
|
6240
5515
|
file = createFile(
|
|
6241
5516
|
await blobToArrayBuffer(file),
|
|
6242
|
-
|
|
5517
|
+
MIME_TYPES6.excalidraw,
|
|
6243
5518
|
file.name
|
|
6244
5519
|
);
|
|
6245
5520
|
} else {
|
|
@@ -6289,7 +5564,7 @@ var encodePngMetadata = async ({
|
|
|
6289
5564
|
}) => {
|
|
6290
5565
|
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
|
6291
5566
|
const metadataChunk = tEXt.encode(
|
|
6292
|
-
|
|
5567
|
+
MIME_TYPES7.excalidraw,
|
|
6293
5568
|
JSON.stringify(
|
|
6294
5569
|
encode({
|
|
6295
5570
|
text: metadata,
|
|
@@ -6298,15 +5573,15 @@ var encodePngMetadata = async ({
|
|
|
6298
5573
|
)
|
|
6299
5574
|
);
|
|
6300
5575
|
chunks.splice(-1, 0, metadataChunk);
|
|
6301
|
-
return new Blob([encodePng(chunks)], { type:
|
|
5576
|
+
return new Blob([encodePng(chunks)], { type: MIME_TYPES7.png });
|
|
6302
5577
|
};
|
|
6303
5578
|
var decodePngMetadata = async (blob) => {
|
|
6304
5579
|
const metadata = await getTEXtChunk(blob);
|
|
6305
|
-
if (metadata?.keyword ===
|
|
5580
|
+
if (metadata?.keyword === MIME_TYPES7.excalidraw) {
|
|
6306
5581
|
try {
|
|
6307
5582
|
const encodedData = JSON.parse(metadata.text);
|
|
6308
5583
|
if (!("encoded" in encodedData)) {
|
|
6309
|
-
if ("type" in encodedData && encodedData.type ===
|
|
5584
|
+
if ("type" in encodedData && encodedData.type === EXPORT_DATA_TYPES3.excalidraw) {
|
|
6310
5585
|
return metadata.text;
|
|
6311
5586
|
}
|
|
6312
5587
|
throw new Error("FAILED");
|
|
@@ -6336,6 +5611,7 @@ export {
|
|
|
6336
5611
|
canChangeRoundness,
|
|
6337
5612
|
AbortError,
|
|
6338
5613
|
ImageSceneDataError,
|
|
5614
|
+
ExcalidrawError,
|
|
6339
5615
|
Fonts,
|
|
6340
5616
|
getDefaultAppState,
|
|
6341
5617
|
isEraserActive,
|
|
@@ -6375,6 +5651,7 @@ export {
|
|
|
6375
5651
|
getFileHandleType,
|
|
6376
5652
|
isImageFileHandleType,
|
|
6377
5653
|
isImageFileHandle,
|
|
5654
|
+
isSupportedImageFileType,
|
|
6378
5655
|
isSupportedImageFile,
|
|
6379
5656
|
loadSceneOrLibraryFromBlob,
|
|
6380
5657
|
loadFromBlob,
|
|
@@ -6388,16 +5665,8 @@ export {
|
|
|
6388
5665
|
resizeImageFile,
|
|
6389
5666
|
SVGStringToFile,
|
|
6390
5667
|
ImageURLToFile,
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
probablySupportsClipboardWriteText,
|
|
6395
|
-
probablySupportsClipboardBlob,
|
|
6396
|
-
createPasteEvent,
|
|
6397
|
-
copyToClipboard,
|
|
6398
|
-
readSystemClipboard,
|
|
6399
|
-
parseClipboard,
|
|
6400
|
-
copyBlobToClipboardAsPng,
|
|
6401
|
-
copyTextToSystemClipboard
|
|
5668
|
+
getFileHandle,
|
|
5669
|
+
createFile,
|
|
5670
|
+
normalizeFile
|
|
6402
5671
|
};
|
|
6403
|
-
//# sourceMappingURL=chunk-
|
|
5672
|
+
//# sourceMappingURL=chunk-WWDIUJ2Q.js.map
|