x-star-editor 0.6.3 → 0.6.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.
@@ -1787,6 +1787,9 @@ body {
1787
1787
  .x-star-editor-md-editor > :last-child {
1788
1788
  margin-bottom: 0.5em;
1789
1789
  }
1790
+ .x-star-editor-md-editor.x-star-editor-empty {
1791
+ /* 文本为空时显示提示 */
1792
+ }
1790
1793
  .x-star-editor-md-editor.x-star-editor-empty::before {
1791
1794
  content: attr(placeholder);
1792
1795
  position: absolute;
@@ -1830,11 +1833,13 @@ body {
1830
1833
  .x-star-editor-md-viewer tr:nth-child(even) td {
1831
1834
  background-color: rgba(0, 0, 0, 0.04);
1832
1835
  }
1836
+ .x-star-editor-md-viewer img {
1837
+ max-width: 100%;
1838
+ }
1833
1839
 
1834
1840
  .x-star-editor-slide-viewer {
1835
1841
  position: relative;
1836
1842
  color: rgba(0, 0, 0, 0.88);
1837
- position: relative;
1838
1843
  overflow: hidden;
1839
1844
  aspect-ratio: 16/9;
1840
1845
  }
@@ -1849,19 +1854,14 @@ body {
1849
1854
  .x-star-editor-slide-viewer .x-star-editor-slide {
1850
1855
  width: 1280px;
1851
1856
  height: 720px;
1852
- padding: 0 32px;
1857
+ padding: 78.5px;
1853
1858
  display: flex;
1854
1859
  flex-direction: column;
1855
1860
  justify-content: center;
1861
+ font-size: 29px;
1856
1862
  background-color: #fff;
1857
1863
  transform-origin: top left;
1858
1864
  }
1859
- .x-star-editor-slide-viewer .x-star-editor-slide > :first-child {
1860
- margin-top: 0;
1861
- }
1862
- .x-star-editor-slide-viewer .x-star-editor-slide > :last-child {
1863
- margin-bottom: 0;
1864
- }
1865
1865
  .x-star-editor-slide-viewer .x-star-editor-slide h1,
1866
1866
  .x-star-editor-slide-viewer .x-star-editor-slide h2,
1867
1867
  .x-star-editor-slide-viewer .x-star-editor-slide h3,
@@ -1871,12 +1871,12 @@ body {
1871
1871
  font-weight: bold;
1872
1872
  }
1873
1873
  .x-star-editor-slide-viewer .x-star-editor-slide table {
1874
- margin: 16px 0;
1874
+ margin: 1em 0;
1875
1875
  border-collapse: collapse;
1876
1876
  }
1877
1877
  .x-star-editor-slide-viewer .x-star-editor-slide th,
1878
1878
  .x-star-editor-slide-viewer .x-star-editor-slide td {
1879
- padding: 8px;
1879
+ padding: 0.5em;
1880
1880
  border: 1px solid #dedede;
1881
1881
  }
1882
1882
  .x-star-editor-slide-viewer .x-star-editor-slide th {
@@ -1886,18 +1886,25 @@ body {
1886
1886
  .x-star-editor-slide-viewer .x-star-editor-slide tr:nth-child(even) td {
1887
1887
  background-color: rgba(0, 0, 0, 0.04);
1888
1888
  }
1889
- .x-star-editor-slide-viewer .x-star-editor-slide pre {
1890
- width: max-content;
1889
+ .x-star-editor-slide-viewer .x-star-editor-slide img {
1891
1890
  max-width: 100%;
1892
1891
  }
1893
- .x-star-editor-slide-viewer .x-star-editor-slide img[id^=user-content-mermaid] {
1894
- max-width: 100%;
1892
+ .x-star-editor-slide-viewer .x-star-editor-slide > :first-child {
1893
+ margin-top: 0; /* 防止垂直居中时出现视觉上不居中的现象 */
1894
+ }
1895
+ .x-star-editor-slide-viewer .x-star-editor-slide > :last-child {
1896
+ margin-bottom: 0; /* 防止垂直居中时出现视觉上不居中的现象 */
1897
+ }
1898
+ .x-star-editor-slide-viewer .x-star-editor-pad {
1899
+ position: absolute;
1900
+ top: 0;
1901
+ left: 0;
1895
1902
  }
1896
1903
  .x-star-editor-slide-viewer .x-star-editor-custom-cursor-pencil {
1897
1904
  cursor: url("./cursor/pencil.png"), auto;
1898
1905
  }
1899
1906
  .x-star-editor-slide-viewer .x-star-editor-custom-cursor-eraser {
1900
- cursor: url("./cursor/editor-eraser.png"), auto;
1907
+ cursor: url("./cursor/eraser.png"), auto;
1901
1908
  }
1902
1909
  .x-star-editor-slide-viewer .x-star-editor-btn-container {
1903
1910
  position: absolute;
@@ -1906,7 +1913,7 @@ body {
1906
1913
  height: 32px;
1907
1914
  display: flex;
1908
1915
  flex-direction: row-reverse;
1909
- z-index: 10000;
1916
+ z-index: 1;
1910
1917
  }
1911
1918
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-common-btn {
1912
1919
  position: relative;
@@ -1922,13 +1929,14 @@ body {
1922
1929
  cursor: pointer;
1923
1930
  }
1924
1931
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-common-btn:hover {
1925
- color: #f8f8f8;
1932
+ color: rgb(132, 174, 241);
1926
1933
  background-color: #f0f0f0;
1927
1934
  }
1928
1935
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-popover {
1929
1936
  position: absolute;
1930
1937
  width: 150px;
1931
1938
  height: 0;
1939
+ margin: 5px;
1932
1940
  display: flex;
1933
1941
  flex-direction: column;
1934
1942
  align-items: center;
@@ -1937,40 +1945,51 @@ body {
1937
1945
  border-radius: 6px;
1938
1946
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
1939
1947
  overflow: hidden;
1940
- z-index: 10000;
1948
+ z-index: 1;
1941
1949
  transition: all 0.3s cubic-bezier(0.51, 0.3, 0.06, 0.98);
1950
+ user-select: none;
1942
1951
  }
1943
1952
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-popover > * {
1944
1953
  margin: 8px 0;
1945
1954
  }
1955
+ .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-popover-label {
1956
+ margin-right: 15px;
1957
+ font-size: 12px;
1958
+ }
1959
+ .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-tooltip {
1960
+ position: absolute;
1961
+ height: 0;
1962
+ margin-top: 36px;
1963
+ margin-left: 10px;
1964
+ padding: 10px;
1965
+ display: flex;
1966
+ flex-direction: column;
1967
+ align-items: center;
1968
+ justify-content: center;
1969
+ line-height: 30px;
1970
+ white-space: nowrap;
1971
+ font-size: 12px;
1972
+ background-color: #fff;
1973
+ border-radius: 6px;
1974
+ box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
1975
+ z-index: 1;
1976
+ transform: scale(0);
1977
+ transition: all 0.25s cubic-bezier(0.51, 0.3, 0.06, 0.98);
1978
+ user-select: none;
1979
+ }
1980
+ .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-common-btn:hover + .x-star-editor-tooltip {
1981
+ height: 30px;
1982
+ transform: scale(1);
1983
+ }
1946
1984
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-common-btn:hover + .x-star-editor-popover,
1947
1985
  .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-popover:hover {
1948
1986
  height: 100px;
1949
1987
  }
1950
- .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-draw-popover {
1988
+ .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-pencil-popover {
1951
1989
  top: 33px;
1952
1990
  left: 120px;
1953
1991
  }
1954
- .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-erase-popover {
1992
+ .x-star-editor-slide-viewer .x-star-editor-btn-container .x-star-editor-eraser-popover {
1955
1993
  top: 33px;
1956
1994
  left: 75px;
1957
1995
  }
1958
- .x-star-editor-slide-viewer .x-star-editor-pad {
1959
- position: absolute;
1960
- top: 0;
1961
- left: 0;
1962
- width: 960px;
1963
- height: 540px;
1964
- }
1965
- .x-star-editor-slide-viewer .x-star-editor-ring {
1966
- position: absolute;
1967
- top: 50%;
1968
- left: 50%;
1969
- width: 100px;
1970
- height: 100px;
1971
- border: 2px solid black;
1972
- border-radius: 50%;
1973
- opacity: 0.5; /* 圆环内部透明 */
1974
- transform: translate(-50%, -50%);
1975
- pointer-events: none; /* 防止圆环遮挡鼠标事件 */
1976
- }
@@ -1,7 +1,15 @@
1
1
  import type { Root as HastRoot } from 'hast';
2
+ import type { Root as MdastRoot } from 'mdast';
2
3
  import type { Options as ToStringOptions } from 'mdast-util-to-string';
3
4
  import { defaultSchema } from 'rehype-sanitize';
4
5
  import type { ViewerOptions } from '../x-star-md-viewer';
6
+ /**
7
+ * 带缓存的解析函数
8
+ *
9
+ * @param sourceCode Markdown 文本
10
+ * @returns Mdast 树
11
+ */
12
+ export declare const cachedParse: (sourceCode: string) => MdastRoot;
5
13
  /**
6
14
  * 将 Markdown 文本映射到 DOM 树,第一层为 `<div>` 块元素,第二层为 `<div>` 行元素,之后均为 `<span>` 元素
7
15
  *
@@ -41,7 +41,7 @@ var toMdastProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath)
41
41
  * @param sourceCode Markdown 文本
42
42
  * @returns Mdast 树
43
43
  */
44
- var cachedParse = function () {
44
+ export var cachedParse = function () {
45
45
  var cache = {};
46
46
  return function (sourceCode) {
47
47
  var _cache$sourceCode;
@@ -139,9 +139,7 @@ var rehypeMath = function rehypeMath() {
139
139
  }, function (node, index, parent) {
140
140
  var _node$properties3;
141
141
  if (typeof ((_node$properties3 = node.properties) === null || _node$properties3 === void 0 ? void 0 : _node$properties3.value) === 'string') {
142
- rawPositions = node.properties.value.split(' ').map(function (offset) {
143
- return parseInt(offset);
144
- });
142
+ rawPositions = node.properties.value.split(' ').map(Number);
145
143
  }
146
144
  if (index !== null && parent) {
147
145
  parent.children.splice(index);
@@ -0,0 +1,26 @@
1
+ import type { PointGroup } from 'signature_pad';
2
+ export interface PadValue {
3
+ data: PointGroup[];
4
+ scale: number;
5
+ }
6
+ /**
7
+ * 计算缩放后点的坐标值
8
+ *
9
+ * @param padValue 画板数据
10
+ * @param parentWidth 父元素宽度
11
+ * @returns 新坐标值
12
+ */
13
+ export declare const getScaledData: ({ data, scale }: PadValue, parentWidth: number) => {
14
+ points: {
15
+ x: number;
16
+ y: number;
17
+ pressure: number;
18
+ time: number;
19
+ }[];
20
+ dotSize: number;
21
+ minWidth: number;
22
+ maxWidth: number;
23
+ penColor: string;
24
+ velocityFilterWeight: number;
25
+ compositeOperation: GlobalCompositeOperation;
26
+ }[];
@@ -0,0 +1,22 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ /**
3
+ * 计算缩放后点的坐标值
4
+ *
5
+ * @param padValue 画板数据
6
+ * @param parentWidth 父元素宽度
7
+ * @returns 新坐标值
8
+ */
9
+ export var getScaledData = function getScaledData(_ref, parentWidth) {
10
+ var data = _ref.data,
11
+ scale = _ref.scale;
12
+ return data.map(function (group) {
13
+ return _objectSpread(_objectSpread({}, group), {}, {
14
+ points: group.points.map(function (point) {
15
+ return _objectSpread(_objectSpread({}, point), {}, {
16
+ x: point.x / scale * (parentWidth / 1280),
17
+ y: point.y / scale * (parentWidth / 1280)
18
+ });
19
+ })
20
+ });
21
+ });
22
+ };
@@ -50,7 +50,7 @@ export interface XStarEditorProps {
50
50
  */
51
51
  viewerRender?: (value: string) => React.ReactNode;
52
52
  /**
53
- * 文本变化回调函数
53
+ * 文本改变回调函数
54
54
  */
55
55
  onChange?: XStarMdEditorProps['onChange'];
56
56
  /**
@@ -64,12 +64,8 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
64
64
 
65
65
  // 同步滚动
66
66
  useEffect(function () {
67
- var _editorRef$current, _viewerRef$current;
68
- var editor = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getEditorContainer();
69
- var viewer = (_viewerRef$current = viewerRef.current) === null || _viewerRef$current === void 0 ? void 0 : _viewerRef$current.getViewerContainer();
70
- if (!editor || !viewer) {
71
- return;
72
- }
67
+ var editor = editorRef.current.getEditorContainer();
68
+ var viewer = viewerRef.current.getViewerContainer();
73
69
 
74
70
  /**
75
71
  * 获取两个父元素的子元素到各自父元素顶部的距离
@@ -92,9 +88,8 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
92
88
  } else if (!(toChild instanceof HTMLElement)) {
93
89
  j++;
94
90
  } else {
95
- var _fromChild$dataset$li, _toChild$dataset$line;
96
- var fromLine = parseInt((_fromChild$dataset$li = fromChild.dataset.line) !== null && _fromChild$dataset$li !== void 0 ? _fromChild$dataset$li : '');
97
- var toLine = parseInt((_toChild$dataset$line = toChild.dataset.line) !== null && _toChild$dataset$line !== void 0 ? _toChild$dataset$line : '');
91
+ var fromLine = Number(fromChild.dataset.line);
92
+ var toLine = Number(toChild.dataset.line);
98
93
  if (!fromLine) {
99
94
  i++;
100
95
  } else if (!toLine) {
@@ -70,7 +70,7 @@ export interface XStarMdEditorProps {
70
70
  */
71
71
  plugins?: XStarMdEditorPlugin[];
72
72
  /**
73
- * 文本变化回调函数
73
+ * 文本改变回调函数
74
74
  */
75
75
  onChange?: (value: string) => void;
76
76
  /**