@gantfdt/semiword 1.0.1 → 1.1.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 (47) hide show
  1. package/README.md +20 -0
  2. package/dist-lib/{FlowchartEditor-S3WKMPDU.mjs → FlowchartEditor-LT6T7ZQV.mjs} +4 -4
  3. package/dist-lib/{FlowchartEditor-S3WKMPDU.mjs.map → FlowchartEditor-LT6T7ZQV.mjs.map} +1 -1
  4. package/dist-lib/{MindmapEditor-KXVEAEQ5.mjs → MindmapEditor-TMXT2VG3.mjs} +4 -4
  5. package/dist-lib/{MindmapEditor-KXVEAEQ5.mjs.map → MindmapEditor-TMXT2VG3.mjs.map} +1 -1
  6. package/dist-lib/{WhiteboardEditor-HZFL4ZPY.mjs → WhiteboardEditor-FSYK6RVN.mjs} +4 -4
  7. package/dist-lib/{WhiteboardEditor-HZFL4ZPY.mjs.map → WhiteboardEditor-FSYK6RVN.mjs.map} +1 -1
  8. package/dist-lib/ai.mjs +7 -7
  9. package/dist-lib/{chunk-N3YIYJWU.mjs → chunk-3K44CBQF.mjs} +1000 -97
  10. package/dist-lib/chunk-3K44CBQF.mjs.map +1 -0
  11. package/dist-lib/{chunk-KS6IR3BG.mjs → chunk-6XGJMUU3.mjs} +1142 -168
  12. package/dist-lib/chunk-6XGJMUU3.mjs.map +1 -0
  13. package/dist-lib/{chunk-4W6PPBHQ.mjs → chunk-7D6NMYFG.mjs} +32 -6
  14. package/dist-lib/chunk-7D6NMYFG.mjs.map +1 -0
  15. package/dist-lib/{chunk-SYHECPDJ.mjs → chunk-DRZQC4T6.mjs} +5 -5
  16. package/dist-lib/{chunk-SYHECPDJ.mjs.map → chunk-DRZQC4T6.mjs.map} +1 -1
  17. package/dist-lib/{chunk-Y2RC2UZD.mjs → chunk-KD56TONW.mjs} +4 -4
  18. package/dist-lib/{chunk-Y2RC2UZD.mjs.map → chunk-KD56TONW.mjs.map} +1 -1
  19. package/dist-lib/{chunk-4JNPZORJ.mjs → chunk-MC3JHNMW.mjs} +8 -8
  20. package/dist-lib/{chunk-4JNPZORJ.mjs.map → chunk-MC3JHNMW.mjs.map} +1 -1
  21. package/dist-lib/{chunk-QWDJU3H7.mjs → chunk-NRQTMBH3.mjs} +3 -3
  22. package/dist-lib/{chunk-QWDJU3H7.mjs.map → chunk-NRQTMBH3.mjs.map} +1 -1
  23. package/dist-lib/{chunk-G4OJCQKQ.mjs → chunk-SG6KJKDX.mjs} +28 -5
  24. package/dist-lib/chunk-SG6KJKDX.mjs.map +1 -0
  25. package/dist-lib/{chunk-766SMPYW.mjs → chunk-THKKUOIF.mjs} +9 -9
  26. package/dist-lib/chunk-THKKUOIF.mjs.map +1 -0
  27. package/dist-lib/{chunk-ZM3WULHX.mjs → chunk-WT7ZJINB.mjs} +288 -4
  28. package/dist-lib/chunk-WT7ZJINB.mjs.map +1 -0
  29. package/dist-lib/designer.mjs +8 -8
  30. package/dist-lib/document.mjs +2 -2
  31. package/dist-lib/editor.d.mts +3 -3
  32. package/dist-lib/editor.mjs +9 -9
  33. package/dist-lib/gant-ai.mjs +7 -7
  34. package/dist-lib/index.d.mts +2 -2
  35. package/dist-lib/index.mjs +9 -9
  36. package/dist-lib/io.mjs +4 -4
  37. package/dist-lib/sdk.mjs +6 -6
  38. package/dist-lib/storage.d.mts +3 -3
  39. package/dist-lib/{types-vl8k8NDK.d.mts → types-D7kCE5Mu.d.mts} +18 -2
  40. package/dist-lib/{useDocumentPersistence-DOpnQsZQ.d.mts → useDocumentPersistence-CDUT0u5S.d.mts} +1 -1
  41. package/package.json +1 -1
  42. package/dist-lib/chunk-4W6PPBHQ.mjs.map +0 -1
  43. package/dist-lib/chunk-766SMPYW.mjs.map +0 -1
  44. package/dist-lib/chunk-G4OJCQKQ.mjs.map +0 -1
  45. package/dist-lib/chunk-KS6IR3BG.mjs.map +0 -1
  46. package/dist-lib/chunk-N3YIYJWU.mjs.map +0 -1
  47. package/dist-lib/chunk-ZM3WULHX.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
- import { useEditorRefApi, isTemplateTableEl, useTableActions, useTableRowColActions } from './chunk-SYHECPDJ.mjs';
2
- import { glassSurfaceCss, createCssScope, templateCss, typographyCss, codeBlockCss, tableCss, fixedTableCss, getDefaultPlaceholder, PluginRegistry, BUILTIN_PLUGINS, MINIMAL_PLUGINS, isSafeCssColor, sanitizeJsonContent, findAncestor } from './chunk-KS6IR3BG.mjs';
3
- import { createStyles, Button, Tooltip, Tag, Dropdown, Divider } from './chunk-ZM3WULHX.mjs';
4
- import { sanitizeHtml } from './chunk-4W6PPBHQ.mjs';
1
+ import { useEditorRefApi, isTemplateTableEl, useTableActions, useTableRowColActions } from './chunk-DRZQC4T6.mjs';
2
+ import { glassSurfaceCss, createCssScope, templateCss, typographyCss, codeBlockCss, tableCss, fixedTableCss, getDefaultPlaceholder, PluginRegistry, BUILTIN_PLUGINS, MINIMAL_PLUGINS, isSafeCssColor, sanitizeJsonContent, findAncestor } from './chunk-6XGJMUU3.mjs';
3
+ import { createStyles, Button, IconChevronDown, Tooltip, Tag, Dropdown, Divider, Input, InputNumber } from './chunk-WT7ZJINB.mjs';
4
+ import { sanitizeHtml } from './chunk-7D6NMYFG.mjs';
5
5
  import { tr } from './chunk-W627LLF4.mjs';
6
6
  import { createContext, forwardRef, memo, useMemo, useRef, useEffect, useState, useCallback, useImperativeHandle, useContext, Fragment, createElement, useReducer } from 'react';
7
7
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
@@ -12,7 +12,7 @@ import { HocuspocusProvider } from '@hocuspocus/provider';
12
12
  import { IndexeddbPersistence } from 'y-indexeddb';
13
13
  import { EditorContent, useEditor } from '@tiptap/react';
14
14
  import { getSchema } from '@tiptap/core';
15
- import { DownOutlined, InsertRowAboveOutlined, InsertRowBelowOutlined, DeleteRowOutlined, InsertRowLeftOutlined, InsertRowRightOutlined, DeleteColumnOutlined, MergeCellsOutlined, SplitCellsOutlined, BorderOutlined, DeleteOutlined } from '@ant-design/icons';
15
+ import { InsertRowAboveOutlined, InsertRowBelowOutlined, DeleteRowOutlined, InsertRowLeftOutlined, InsertRowRightOutlined, DeleteColumnOutlined, MergeCellsOutlined, SplitCellsOutlined, BorderOutlined, DeleteOutlined } from '@ant-design/icons';
16
16
 
17
17
  var registrationIdentities = /* @__PURE__ */ new WeakMap();
18
18
  var registrationIdentitySeq = 0;
@@ -913,7 +913,8 @@ function EditorStatusBar({ editor, collaborationEnabled }) {
913
913
  const { styles } = useStyles();
914
914
  const { reconnect, connectionStatus: collabStatus, onlineUsers, error: collabError } = useCollaboration();
915
915
  const onlineCount = onlineUsers.length;
916
- useEditorRerenderOn(editor, STATUS_BAR_RERENDER_EVENTS);
916
+ const showCharacterCount = !!editor?.extensionManager.extensions.some((ext) => ext.name === "characterCount");
917
+ useEditorRerenderOn(showCharacterCount ? editor : null, STATUS_BAR_RERENDER_EVENTS);
917
918
  const characterCount = editor?.storage?.characterCount;
918
919
  const characters = characterCount?.characters?.() ?? 0;
919
920
  const words = characterCount?.words?.() ?? 0;
@@ -925,8 +926,9 @@ function EditorStatusBar({ editor, collaborationEnabled }) {
925
926
  error: { label: tr(CONNECTION_STATUS_LABEL.error), dotClass: styles.statusDotError }
926
927
  };
927
928
  const statusMeta = STATUS_META[status] ?? STATUS_META.disconnected;
929
+ if (!showCharacterCount && !collaborationEnabled) return null;
928
930
  return /* @__PURE__ */ jsxs("div", { className: styles.statusBar, children: [
929
- /* @__PURE__ */ jsx("div", { className: styles.leftSection, children: /* @__PURE__ */ jsxs("div", { className: styles.charCount, children: [
931
+ showCharacterCount && /* @__PURE__ */ jsx("div", { className: styles.leftSection, children: /* @__PURE__ */ jsxs("div", { className: styles.charCount, children: [
930
932
  /* @__PURE__ */ jsxs("span", { children: [
931
933
  tr("\u5B57\u6570"),
932
934
  ": ",
@@ -1059,7 +1061,7 @@ var useToolbarStyles = createStyles(({ css, token, sizeToken, glassEffect, getAl
1059
1061
  toolbar: css`
1060
1062
  display: flex;
1061
1063
  align-items: center;
1062
- padding: 4px ${paddingContentHorizontal}px;
1064
+ padding: 8px ${paddingContentHorizontal}px;
1063
1065
  /* 毛玻璃表面走共享工厂的 strip 变体(贴顶条带:底边框 + container 背景 + -sm 模糊) */
1064
1066
  ${glassSurfaceCss({ token, glassEffect, getAlphaColor, borderRadius }, { variant: "strip" })}
1065
1067
  overflow-x: auto;
@@ -1074,25 +1076,159 @@ var useToolbarStyles = createStyles(({ css, token, sizeToken, glassEffect, getAl
1074
1076
  toolbarGroup: css`
1075
1077
  display: flex;
1076
1078
  align-items: center;
1077
- gap: 2px;
1079
+ gap: 4px;
1078
1080
  flex-wrap: nowrap;
1079
1081
 
1080
1082
  .ant-divider-vertical {
1081
- margin: 0 4px;
1082
- height: ${controlHeight - 8}px;
1083
+ margin: 0 8px;
1084
+ height: ${controlHeight - 12}px;
1083
1085
  }
1084
1086
  `,
1085
1087
  activeBtn: css`
1086
1088
  background: ${getAlphaColor(token.colorPrimary, 0.1)} !important;
1087
1089
  color: ${token.colorPrimary} !important;
1088
- border-radius: ${borderRadius}px;
1090
+ border-radius: ${borderRadius + 2}px;
1089
1091
  `,
1090
1092
  /* ---- 颜色选择器 ---- */
1093
+ colorPanel: css`
1094
+ display: flex;
1095
+ align-items: flex-start;
1096
+ `,
1091
1097
  colorPaletteWrapper: css`
1092
1098
  padding: 8px;
1093
- /* 宽度由色板行内容撑开,不写死,避免与 COLOR_GRID_COLS(每行格子数)耦合 */
1099
+ /* 宽度由色板行内容撑开,不写死,避免与色板列数耦合 */
1094
1100
  width: fit-content;
1095
1101
  `,
1102
+ /* ---- 颜色触发器(左侧应用区 + 右侧下拉区) ---- */
1103
+ colorTrigger: css`
1104
+ display: inline-flex;
1105
+ align-items: center;
1106
+ height: ${controlHeight}px;
1107
+ border-radius: ${borderRadius}px;
1108
+ color: ${token.colorText};
1109
+ `,
1110
+ colorTriggerMain: css`
1111
+ display: inline-flex;
1112
+ align-items: center;
1113
+ justify-content: center;
1114
+ width: 30px;
1115
+ height: 100%;
1116
+ padding: 0;
1117
+ border: none;
1118
+ border-radius: ${borderRadius}px 0 0 ${borderRadius}px;
1119
+ background: transparent;
1120
+ color: inherit;
1121
+ cursor: pointer;
1122
+
1123
+ &:hover {
1124
+ background: ${getAlphaColor(token.colorText, 0.06)};
1125
+ }
1126
+
1127
+ &:focus-visible {
1128
+ outline: 2px solid ${token.colorPrimary};
1129
+ outline-offset: -2px;
1130
+ }
1131
+ `,
1132
+ colorTriggerIcon: css`
1133
+ position: relative;
1134
+ display: inline-flex;
1135
+ align-items: center;
1136
+ justify-content: center;
1137
+ width: 20px;
1138
+ height: 20px;
1139
+
1140
+ /* 颜色图标统一 20px 渲染,给马克笔与色条留出更多垂直空间 */
1141
+ > svg {
1142
+ width: 20px;
1143
+ height: 20px;
1144
+ display: block;
1145
+ }
1146
+ `,
1147
+ colorTriggerBar: css`
1148
+ position: absolute;
1149
+ bottom: 1px;
1150
+ left: 50%;
1151
+ width: 12px;
1152
+ height: 2.5px;
1153
+ border-radius: 1px;
1154
+ transform: translateX(-50%);
1155
+ pointer-events: none;
1156
+ box-shadow: inset 0 0 0 1px ${getAlphaColor(token.colorText, 0.08)};
1157
+ `,
1158
+ colorTriggerBarEmpty: css`
1159
+ /* 透明色用棋盘格表示(与调色板透明度色块一致) */
1160
+ background-color: ${token.colorBgContainer};
1161
+ background-image:
1162
+ linear-gradient(45deg, ${getAlphaColor(token.colorText, 0.16)} 25%, transparent 25%),
1163
+ linear-gradient(-45deg, ${getAlphaColor(token.colorText, 0.16)} 25%, transparent 25%),
1164
+ linear-gradient(45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.16)} 75%),
1165
+ linear-gradient(-45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.16)} 75%);
1166
+ background-size: 4px 4px;
1167
+ background-position:
1168
+ 0 0,
1169
+ 0 2px,
1170
+ 2px -2px,
1171
+ -2px 0;
1172
+ box-shadow: inset 0 0 0 1px ${getAlphaColor(token.colorText, 0.12)};
1173
+ `,
1174
+ colorTriggerArrow: css`
1175
+ display: inline-flex;
1176
+ align-items: center;
1177
+ justify-content: center;
1178
+ width: 18px;
1179
+ height: 100%;
1180
+ padding: 0;
1181
+ border: none;
1182
+ border-radius: 0 ${borderRadius}px ${borderRadius}px 0;
1183
+ background: transparent;
1184
+ color: ${token.colorTextTertiary};
1185
+ cursor: pointer;
1186
+
1187
+ &:hover {
1188
+ background: ${getAlphaColor(token.colorText, 0.06)};
1189
+ color: ${token.colorText};
1190
+ }
1191
+
1192
+ &:focus-visible {
1193
+ outline: 2px solid ${token.colorPrimary};
1194
+ outline-offset: -2px;
1195
+ }
1196
+ `,
1197
+ colorTriggerArrowOpen: css`
1198
+ background: ${getAlphaColor(token.colorPrimary, 0.1)};
1199
+ color: ${token.colorPrimary};
1200
+ `,
1201
+ colorDefaultRow: css`
1202
+ display: flex;
1203
+ align-items: center;
1204
+ gap: 8px;
1205
+ width: 100%;
1206
+ margin-bottom: 6px;
1207
+ padding: 4px 6px;
1208
+ border: none;
1209
+ border-radius: ${borderRadius}px;
1210
+ background: transparent;
1211
+ color: ${token.colorText};
1212
+ font-size: ${token.fontSize}px;
1213
+ text-align: left;
1214
+ cursor: pointer;
1215
+
1216
+ &:hover {
1217
+ background: ${getAlphaColor(token.colorPrimary, 0.06)};
1218
+ }
1219
+ `,
1220
+ colorDefaultSwatch: css`
1221
+ display: inline-flex;
1222
+ align-items: center;
1223
+ justify-content: center;
1224
+ width: 22px;
1225
+ height: 22px;
1226
+ border: 1px solid ${token.colorBorderSecondary};
1227
+ border-radius: ${borderRadius}px;
1228
+ `,
1229
+ colorDefaultLabel: css`
1230
+ flex: 1;
1231
+ `,
1096
1232
  colorPalette: css`
1097
1233
  display: flex;
1098
1234
  flex-direction: column;
@@ -1103,20 +1239,277 @@ var useToolbarStyles = createStyles(({ css, token, sizeToken, glassEffect, getAl
1103
1239
  gap: 4px;
1104
1240
  `,
1105
1241
  colorCell: css`
1106
- width: 20px;
1107
- height: 20px;
1242
+ position: relative;
1243
+ width: 22px;
1244
+ height: 22px;
1108
1245
  border-radius: ${borderRadius}px;
1109
1246
  cursor: pointer;
1110
1247
  border: 1px solid ${token.colorBorderSecondary};
1111
1248
  transition: transform 0.15s ease;
1112
1249
 
1113
1250
  &:hover {
1114
- transform: scale(1.15);
1251
+ transform: scale(1.12);
1115
1252
  border-color: ${token.colorPrimary};
1116
1253
  }
1254
+
1255
+ &:focus-visible {
1256
+ outline: 2px solid ${token.colorPrimary};
1257
+ outline-offset: 1px;
1258
+ }
1259
+ `,
1260
+ colorCheck: css`
1261
+ position: absolute;
1262
+ inset: 0;
1263
+ display: flex;
1264
+ align-items: center;
1265
+ justify-content: center;
1266
+ pointer-events: none;
1267
+ filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.35));
1268
+ `,
1269
+ colorSectionTitle: css`
1270
+ margin: 10px 0 6px;
1271
+ color: ${token.colorTextSecondary};
1272
+ font-size: 12px;
1273
+ line-height: 18px;
1274
+ `,
1275
+ gradientRow: css`
1276
+ display: flex;
1277
+ gap: 6px;
1278
+ `,
1279
+ gradientCell: css`
1280
+ position: relative;
1281
+ width: 34px;
1282
+ height: 22px;
1283
+ border: 1px solid ${token.colorBorderSecondary};
1284
+ border-radius: ${borderRadius}px;
1285
+ cursor: pointer;
1286
+
1287
+ &:focus-visible {
1288
+ outline: 2px solid ${token.colorPrimary};
1289
+ outline-offset: 1px;
1290
+ }
1291
+ `,
1292
+ recentRow: css`
1293
+ display: flex;
1294
+ flex-wrap: wrap;
1295
+ gap: 4px;
1296
+ `,
1297
+ recentEmpty: css`
1298
+ color: ${token.colorTextQuaternary};
1299
+ font-size: 12px;
1300
+ line-height: 22px;
1301
+ `,
1302
+ alphaSwatch: css`
1303
+ position: relative;
1304
+ width: 22px;
1305
+ height: 22px;
1306
+ overflow: hidden;
1307
+ border: 1px solid ${token.colorBorderSecondary};
1308
+ border-radius: ${borderRadius}px;
1309
+ cursor: pointer;
1310
+ /* 棋盘格提示透明度,叠在内层色块下方 */
1311
+ background-color: ${token.colorBgContainer};
1312
+ background-image:
1313
+ linear-gradient(45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1314
+ linear-gradient(-45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1315
+ linear-gradient(45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%),
1316
+ linear-gradient(-45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%);
1317
+ background-size: 8px 8px;
1318
+ background-position:
1319
+ 0 0,
1320
+ 0 4px,
1321
+ 4px -4px,
1322
+ -4px 0;
1323
+
1324
+ &:focus-visible {
1325
+ outline: 2px solid ${token.colorPrimary};
1326
+ outline-offset: 1px;
1327
+ }
1328
+ `,
1329
+ alphaSwatchFill: css`
1330
+ position: absolute;
1331
+ inset: 0;
1332
+ `,
1333
+ moreColorRow: css`
1334
+ display: flex;
1335
+ align-items: center;
1336
+ gap: 8px;
1337
+ width: 100%;
1338
+ margin-top: 10px;
1339
+ padding: 6px;
1340
+ border: none;
1341
+ border-top: 1px solid ${token.colorBorderSecondary};
1342
+ border-radius: 0 0 ${borderRadius}px ${borderRadius}px;
1343
+ background: transparent;
1344
+ color: ${token.colorText};
1345
+ font-size: ${token.fontSize}px;
1346
+ text-align: left;
1347
+ cursor: pointer;
1348
+
1349
+ &:hover {
1350
+ background: ${getAlphaColor(token.colorPrimary, 0.06)};
1351
+ }
1352
+ `,
1353
+ moreColorDot: css`
1354
+ width: 18px;
1355
+ height: 18px;
1356
+ border-radius: 50%;
1357
+ background: conic-gradient(#ff4d4f, #faad14, #52c41a, #13c2c2, #1677ff, #722ed1, #eb2f96, #ff4d4f);
1358
+ `,
1359
+ moreColorLabel: css`
1360
+ flex: 1;
1361
+ `,
1362
+ moreColorChevron: css`
1363
+ display: inline-flex;
1364
+ color: ${token.colorTextTertiary};
1365
+ transform: rotate(-90deg);
1366
+ transition: transform 0.2s ease;
1367
+ `,
1368
+ moreColorChevronOpen: css`
1369
+ transform: rotate(0deg);
1370
+ `,
1371
+ /* ---- 更多颜色(自定义取色器) ---- */
1372
+ colorCustomPanel: css`
1373
+ width: 248px;
1374
+ margin-left: 4px;
1375
+ padding: 8px 10px 10px;
1376
+ border-left: 1px solid ${token.colorBorderSecondary};
1377
+ `,
1378
+ svPanel: css`
1379
+ position: relative;
1380
+ width: 100%;
1381
+ height: 150px;
1382
+ overflow: hidden;
1383
+ border-radius: ${borderRadius}px;
1384
+ cursor: crosshair;
1385
+ touch-action: none;
1386
+ `,
1387
+ svWhite: css`
1388
+ position: absolute;
1389
+ inset: 0;
1390
+ background: linear-gradient(to right, #ffffff, rgba(255, 255, 255, 0));
1391
+ `,
1392
+ svBlack: css`
1393
+ position: absolute;
1394
+ inset: 0;
1395
+ background: linear-gradient(to top, #000000, rgba(0, 0, 0, 0));
1396
+ `,
1397
+ svHandle: css`
1398
+ position: absolute;
1399
+ width: 12px;
1400
+ height: 12px;
1401
+ border: 2px solid #ffffff;
1402
+ border-radius: 50%;
1403
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
1404
+ transform: translate(-50%, -50%);
1405
+ pointer-events: none;
1406
+ `,
1407
+ sliderTrack: css`
1408
+ position: relative;
1409
+ height: 10px;
1410
+ margin-top: 12px;
1411
+ border-radius: 5px;
1412
+ cursor: pointer;
1413
+ touch-action: none;
1414
+ `,
1415
+ hueTrack: css`
1416
+ background: linear-gradient(
1417
+ to right,
1418
+ #ff0000 0%,
1419
+ #ffff00 17%,
1420
+ #00ff00 33%,
1421
+ #00ffff 50%,
1422
+ #0000ff 67%,
1423
+ #ff00ff 83%,
1424
+ #ff0000 100%
1425
+ );
1426
+ `,
1427
+ alphaRow: css`
1428
+ display: flex;
1429
+ align-items: center;
1430
+ gap: 8px;
1431
+ `,
1432
+ alphaTrack: css`
1433
+ flex: 1;
1434
+ margin-top: 0;
1435
+ background-color: ${token.colorBgContainer};
1436
+ background-image:
1437
+ linear-gradient(45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1438
+ linear-gradient(-45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1439
+ linear-gradient(45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%),
1440
+ linear-gradient(-45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%);
1441
+ background-size: 8px 8px;
1442
+ background-position:
1443
+ 0 0,
1444
+ 0 4px,
1445
+ 4px -4px,
1446
+ -4px 0;
1447
+ `,
1448
+ alphaTrackFill: css`
1449
+ position: absolute;
1450
+ inset: 0;
1451
+ border-radius: inherit;
1452
+ pointer-events: none;
1453
+ `,
1454
+ sliderHandle: css`
1455
+ position: absolute;
1456
+ top: 50%;
1457
+ width: 14px;
1458
+ height: 14px;
1459
+ border: 2px solid #ffffff;
1460
+ border-radius: 50%;
1461
+ background: transparent;
1462
+ box-shadow:
1463
+ 0 0 0 1px rgba(0, 0, 0, 0.25),
1464
+ 0 1px 2px rgba(0, 0, 0, 0.2);
1465
+ transform: translate(-50%, -50%);
1466
+ pointer-events: none;
1467
+ `,
1468
+ colorPreview: css`
1469
+ position: relative;
1470
+ flex-shrink: 0;
1471
+ width: 24px;
1472
+ height: 24px;
1473
+ overflow: hidden;
1474
+ border: 1px solid ${token.colorBorderSecondary};
1475
+ border-radius: 50%;
1476
+ background-color: ${token.colorBgContainer};
1477
+ background-image:
1478
+ linear-gradient(45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1479
+ linear-gradient(-45deg, ${getAlphaColor(token.colorText, 0.08)} 25%, transparent 25%),
1480
+ linear-gradient(45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%),
1481
+ linear-gradient(-45deg, transparent 75%, ${getAlphaColor(token.colorText, 0.08)} 75%);
1482
+ background-size: 8px 8px;
1483
+ background-position:
1484
+ 0 0,
1485
+ 0 4px,
1486
+ 4px -4px,
1487
+ -4px 0;
1488
+ `,
1489
+ colorPreviewFill: css`
1490
+ position: absolute;
1491
+ inset: 0;
1492
+ `,
1493
+ colorInputs: css`
1494
+ display: flex;
1495
+ gap: 4px;
1496
+ margin-top: 12px;
1497
+ `,
1498
+ colorInputField: css`
1499
+ display: flex;
1500
+ flex: 1;
1501
+ flex-direction: column;
1502
+ gap: 2px;
1503
+ min-width: 0;
1504
+
1505
+ &:first-of-type {
1506
+ flex: 2.2;
1507
+ }
1117
1508
  `,
1118
- clearColorBtn: css`
1119
- margin-top: 4px;
1509
+ colorInputLabel: css`
1510
+ color: ${token.colorTextTertiary};
1511
+ font-size: 11px;
1512
+ line-height: 14px;
1120
1513
  text-align: center;
1121
1514
  `,
1122
1515
  /* ---- 表格插入网格 ---- */
@@ -1159,34 +1552,371 @@ var useToolbarStyles = createStyles(({ css, token, sizeToken, glassEffect, getAl
1159
1552
  dropdownTrigger: css`
1160
1553
  display: inline-flex;
1161
1554
  align-items: center;
1162
- gap: 2px;
1163
- `,
1164
- /* 触发器右侧下拉箭头(10px 小号图标) */
1165
- dropdownTriggerIcon: css`
1166
- font-size: 10px;
1555
+ gap: 4px;
1556
+ font-size: ${token.fontSizeLG}px;
1167
1557
  `
1168
1558
  };
1169
1559
  });
1170
- var ToolbarDropdownTrigger = forwardRef(
1171
- ({ children, className, ...rest }, ref) => {
1172
- const { styles, cx } = useToolbarStyles();
1173
- return /* @__PURE__ */ jsxs(
1174
- Button,
1560
+
1561
+ // src/editor/toolbar/colorPalette.ts
1562
+ var COLOR_PALETTE_COLUMNS = 10;
1563
+ var GRAYSCALE_COLORS = [
1564
+ "#000000",
1565
+ "#262626",
1566
+ "#595959",
1567
+ "#8C8C8C",
1568
+ "#BFBFBF",
1569
+ "#D9D9D9",
1570
+ "#F0F0F0",
1571
+ "#F5F5F5",
1572
+ "#FAFAFA",
1573
+ "#FFFFFF"
1574
+ ];
1575
+ var HUE_COLUMNS = [
1576
+ ["#FFCCC7", "#FFA39E", "#FF7875", "#FF4D4F", "#F5222D", "#CF1322"],
1577
+ ["#FFE7BA", "#FFD591", "#FFC069", "#FFA940", "#FA8C16", "#D46B08"],
1578
+ ["#FFF1B8", "#FFE58F", "#FFD666", "#FFC53D", "#FAAD14", "#D48806"],
1579
+ ["#F4FFB8", "#EAFF8F", "#D3F261", "#BAE637", "#A0D911", "#7CB305"],
1580
+ ["#D9F7BE", "#B7EB8F", "#95DE64", "#73D13D", "#52C41A", "#389E0D"],
1581
+ ["#B5F5EC", "#87E8DE", "#5CDBD3", "#36CFC9", "#13C2C2", "#08979C"],
1582
+ ["#BAE0FF", "#91CAFF", "#69B1FF", "#4096FF", "#1677FF", "#0958D9"],
1583
+ ["#D6E4FF", "#ADC6FF", "#85A5FF", "#597EF7", "#2F54EB", "#1D39C4"],
1584
+ ["#EFDBFF", "#D3ADF7", "#B37FEB", "#9254DE", "#722ED1", "#531DAB"],
1585
+ ["#FFD6E7", "#FFADD2", "#FF85C0", "#F759AB", "#EB2F96", "#C41D7F"]
1586
+ ];
1587
+ var COLOR_PALETTE_ROWS = HUE_COLUMNS[0].map(
1588
+ (_, level) => HUE_COLUMNS.map((column) => column[level])
1589
+ );
1590
+ var GRADIENT_PRESETS = [
1591
+ "linear-gradient(135deg, #5B8FF9 0%, #7048E8 100%)",
1592
+ "linear-gradient(135deg, #B37FEB 0%, #F759AB 100%)",
1593
+ "linear-gradient(135deg, #9254DE 0%, #FF7A45 100%)",
1594
+ "linear-gradient(135deg, #FF85C0 0%, #FFC53D 100%)"
1595
+ ];
1596
+ var RECENT_COLORS_STORAGE_KEY = "semiword.editor.recentColors";
1597
+ var MAX_RECENT_COLORS = 8;
1598
+ function clamp(value, min, max) {
1599
+ return Math.min(max, Math.max(min, value));
1600
+ }
1601
+ function toHexPair(value) {
1602
+ return clamp(Math.round(value), 0, 255).toString(16).padStart(2, "0");
1603
+ }
1604
+ function rgbToHex(r, g, b) {
1605
+ return `#${toHexPair(r)}${toHexPair(g)}${toHexPair(b)}`.toUpperCase();
1606
+ }
1607
+ function parseCssColor(value) {
1608
+ const color = value.trim();
1609
+ const hex = color.match(/^#([\da-f]{3,8})$/i)?.[1];
1610
+ if (hex) {
1611
+ if (![3, 4, 6, 8].includes(hex.length)) return null;
1612
+ const full = hex.length <= 4 ? hex.replace(/./g, (char) => char + char) : hex;
1613
+ return {
1614
+ r: Number.parseInt(full.slice(0, 2), 16),
1615
+ g: Number.parseInt(full.slice(2, 4), 16),
1616
+ b: Number.parseInt(full.slice(4, 6), 16),
1617
+ a: full.length === 8 ? Number.parseInt(full.slice(6, 8), 16) / 255 : 1
1618
+ };
1619
+ }
1620
+ const fn = color.match(/^rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*(?:[,/]\s*([\d.]+%?))?\s*\)$/i);
1621
+ if (!fn) return null;
1622
+ const alphaRaw = fn[4];
1623
+ const alpha = alphaRaw ? alphaRaw.endsWith("%") ? Number.parseFloat(alphaRaw) / 100 : Number.parseFloat(alphaRaw) : 1;
1624
+ return {
1625
+ r: clamp(Number.parseFloat(fn[1]), 0, 255),
1626
+ g: clamp(Number.parseFloat(fn[2]), 0, 255),
1627
+ b: clamp(Number.parseFloat(fn[3]), 0, 255),
1628
+ a: clamp(alpha, 0, 1)
1629
+ };
1630
+ }
1631
+ function hsvToRgb(h, s, v) {
1632
+ const saturation = clamp(s, 0, 100) / 100;
1633
+ const value = clamp(v, 0, 100) / 100;
1634
+ const chroma = value * saturation;
1635
+ const hue = (h % 360 + 360) % 360 / 60;
1636
+ const x = chroma * (1 - Math.abs(hue % 2 - 1));
1637
+ const base = value - chroma;
1638
+ const [r, g, b] = hue < 1 ? [chroma, x, 0] : hue < 2 ? [x, chroma, 0] : hue < 3 ? [0, chroma, x] : hue < 4 ? [0, x, chroma] : hue < 5 ? [x, 0, chroma] : [chroma, 0, x];
1639
+ return {
1640
+ r: Math.round((r + base) * 255),
1641
+ g: Math.round((g + base) * 255),
1642
+ b: Math.round((b + base) * 255)
1643
+ };
1644
+ }
1645
+ function rgbToHsv(r, g, b) {
1646
+ const red = clamp(r, 0, 255) / 255;
1647
+ const green = clamp(g, 0, 255) / 255;
1648
+ const blue = clamp(b, 0, 255) / 255;
1649
+ const max = Math.max(red, green, blue);
1650
+ const min = Math.min(red, green, blue);
1651
+ const delta = max - min;
1652
+ let hue = 0;
1653
+ if (delta !== 0) {
1654
+ if (max === red) hue = (green - blue) / delta % 6;
1655
+ else if (max === green) hue = (blue - red) / delta + 2;
1656
+ else hue = (red - green) / delta + 4;
1657
+ hue = (hue * 60 + 360) % 360;
1658
+ }
1659
+ return {
1660
+ h: hue,
1661
+ s: max === 0 ? 0 : delta / max * 100,
1662
+ v: max * 100
1663
+ };
1664
+ }
1665
+ function formatHsvColor(hsv, alphaPercent) {
1666
+ const { r, g, b } = hsvToRgb(hsv.h, hsv.s, hsv.v);
1667
+ const alpha = Math.round(clamp(alphaPercent, 0, 100)) / 100;
1668
+ if (alpha >= 1) return rgbToHex(r, g, b);
1669
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
1670
+ }
1671
+ function isGradientColor(value) {
1672
+ return typeof value === "string" && /^linear-gradient\(/i.test(value.trim());
1673
+ }
1674
+ function isSameColor(a, b) {
1675
+ if (!a || !b) return false;
1676
+ const colorA = parseCssColor(a);
1677
+ const colorB = parseCssColor(b);
1678
+ if (colorA && colorB) {
1679
+ return colorA.r === colorB.r && colorA.g === colorB.g && colorA.b === colorB.b && Math.abs(colorA.a - colorB.a) < 0.01;
1680
+ }
1681
+ const normalize = (value) => value.replace(/\s+/g, "").toLowerCase();
1682
+ return normalize(a) === normalize(b);
1683
+ }
1684
+ function getReadableCheckColor(background) {
1685
+ const color = parseCssColor(background);
1686
+ if (!color) return "#FFFFFF";
1687
+ const luminance = 0.299 * color.r + 0.587 * color.g + 0.114 * color.b;
1688
+ return luminance > 170 ? "#262626" : "#FFFFFF";
1689
+ }
1690
+ function readRecentColors() {
1691
+ if (typeof window === "undefined") return [];
1692
+ try {
1693
+ const parsed = JSON.parse(window.localStorage.getItem(RECENT_COLORS_STORAGE_KEY) ?? "[]");
1694
+ if (!Array.isArray(parsed)) return [];
1695
+ return parsed.filter((value) => typeof value === "string" && parseCssColor(value) !== null).slice(0, MAX_RECENT_COLORS);
1696
+ } catch {
1697
+ return [];
1698
+ }
1699
+ }
1700
+ function rememberRecentColor(color) {
1701
+ if (typeof window === "undefined" || parseCssColor(color) === null) return;
1702
+ try {
1703
+ const next = [color, ...readRecentColors().filter((item) => !isSameColor(item, color))].slice(0, MAX_RECENT_COLORS);
1704
+ window.localStorage.setItem(RECENT_COLORS_STORAGE_KEY, JSON.stringify(next));
1705
+ } catch {
1706
+ }
1707
+ }
1708
+ function clampValue(value, min, max) {
1709
+ return Math.min(max, Math.max(min, value));
1710
+ }
1711
+ function ColorCustomPicker({ initialColor, onChange, onRemember }) {
1712
+ const { styles, cx } = useToolbarStyles();
1713
+ const initialRgba = useMemo(() => parseCssColor(initialColor ?? "") ?? { r: 0, g: 0, b: 0, a: 1 }, [initialColor]);
1714
+ const [hsv, setHsv] = useState(() => rgbToHsv(initialRgba.r, initialRgba.g, initialRgba.b));
1715
+ const [alpha, setAlpha] = useState(() => Math.round(initialRgba.a * 100));
1716
+ const hsvRef = useRef(hsv);
1717
+ const alphaRef = useRef(alpha);
1718
+ const appliedRef = useRef(null);
1719
+ const rememberRef = useRef(onRemember);
1720
+ const [hexDraft, setHexDraft] = useState(null);
1721
+ useEffect(() => {
1722
+ rememberRef.current = onRemember;
1723
+ }, [onRemember]);
1724
+ useEffect(
1725
+ () => () => {
1726
+ if (appliedRef.current) rememberRef.current?.(appliedRef.current);
1727
+ },
1728
+ []
1729
+ );
1730
+ const rgb = hsvToRgb(hsv.h, hsv.s, hsv.v);
1731
+ const hexValue = rgbToHex(rgb.r, rgb.g, rgb.b);
1732
+ const colorValue = formatHsvColor(hsv, alpha);
1733
+ const updateHsv = (patch) => {
1734
+ const next = { ...hsvRef.current, ...patch };
1735
+ hsvRef.current = next;
1736
+ setHsv(next);
1737
+ return next;
1738
+ };
1739
+ const updateAlpha = (value) => {
1740
+ const next = Math.round(clampValue(value, 0, 100));
1741
+ alphaRef.current = next;
1742
+ setAlpha(next);
1743
+ return next;
1744
+ };
1745
+ const apply = () => {
1746
+ const color = formatHsvColor(hsvRef.current, alphaRef.current);
1747
+ appliedRef.current = color;
1748
+ onChange(color);
1749
+ };
1750
+ const bindDrag = (compute) => ({
1751
+ onPointerDown: (event) => {
1752
+ event.currentTarget.setPointerCapture(event.pointerId);
1753
+ compute(event);
1754
+ },
1755
+ onPointerMove: (event) => {
1756
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) compute(event);
1757
+ },
1758
+ onPointerUp: (event) => {
1759
+ if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;
1760
+ event.currentTarget.releasePointerCapture(event.pointerId);
1761
+ apply();
1762
+ }
1763
+ });
1764
+ const horizontalRatio = (event) => {
1765
+ const rect = event.currentTarget.getBoundingClientRect();
1766
+ return rect.width > 0 ? clampValue((event.clientX - rect.left) / rect.width, 0, 1) : 0;
1767
+ };
1768
+ const svDrag = bindDrag((event) => {
1769
+ const rect = event.currentTarget.getBoundingClientRect();
1770
+ const saturation = rect.width > 0 ? (event.clientX - rect.left) / rect.width * 100 : 0;
1771
+ const brightness = rect.height > 0 ? (1 - (event.clientY - rect.top) / rect.height) * 100 : 0;
1772
+ updateHsv({ s: clampValue(saturation, 0, 100), v: clampValue(brightness, 0, 100) });
1773
+ });
1774
+ const hueDrag = bindDrag((event) => {
1775
+ updateHsv({ h: horizontalRatio(event) * 360 });
1776
+ });
1777
+ const alphaDrag = bindDrag((event) => {
1778
+ updateAlpha(horizontalRatio(event) * 100);
1779
+ });
1780
+ const handleSliderKeyDown = (event, step) => {
1781
+ if (event.key === "ArrowLeft" || event.key === "ArrowDown") {
1782
+ event.preventDefault();
1783
+ step(-1);
1784
+ } else if (event.key === "ArrowRight" || event.key === "ArrowUp") {
1785
+ event.preventDefault();
1786
+ step(1);
1787
+ }
1788
+ };
1789
+ const setChannel = (channel, value) => {
1790
+ const nextRgb = { ...rgb, [channel]: Math.round(clampValue(value ?? 0, 0, 255)) };
1791
+ updateHsv(rgbToHsv(nextRgb.r, nextRgb.g, nextRgb.b));
1792
+ };
1793
+ const commitHex = () => {
1794
+ if (hexDraft) {
1795
+ const parsed = parseCssColor(hexDraft);
1796
+ if (parsed) {
1797
+ const nextHsv = rgbToHsv(parsed.r, parsed.g, parsed.b);
1798
+ updateHsv(nextHsv);
1799
+ updateAlpha(parsed.a * 100);
1800
+ apply();
1801
+ }
1802
+ }
1803
+ setHexDraft(null);
1804
+ };
1805
+ return /* @__PURE__ */ jsxs("div", { className: styles.colorCustomPanel, children: [
1806
+ /* @__PURE__ */ jsxs(
1807
+ "div",
1175
1808
  {
1176
- ref,
1177
- type: "text",
1178
- size: "small",
1179
- ...rest,
1180
- className: cx(styles.dropdownTrigger, className),
1809
+ className: styles.svPanel,
1810
+ style: { backgroundColor: `hsl(${hsv.h}, 100%, 50%)` },
1811
+ "aria-label": tr("\u9971\u548C\u5EA6\u4E0E\u660E\u5EA6"),
1812
+ ...svDrag,
1181
1813
  children: [
1182
- children,
1183
- /* @__PURE__ */ jsx(DownOutlined, { className: styles.dropdownTriggerIcon })
1814
+ /* @__PURE__ */ jsx("div", { className: styles.svWhite }),
1815
+ /* @__PURE__ */ jsx("div", { className: styles.svBlack }),
1816
+ /* @__PURE__ */ jsx("div", { className: styles.svHandle, style: { left: `${hsv.s}%`, top: `${100 - hsv.v}%` } })
1184
1817
  ]
1185
1818
  }
1186
- );
1187
- }
1188
- );
1189
- ToolbarDropdownTrigger.displayName = "ToolbarDropdownTrigger";
1819
+ ),
1820
+ /* @__PURE__ */ jsx(
1821
+ "div",
1822
+ {
1823
+ className: cx(styles.sliderTrack, styles.hueTrack),
1824
+ role: "slider",
1825
+ tabIndex: 0,
1826
+ "aria-label": tr("\u8272\u76F8"),
1827
+ "aria-valuemin": 0,
1828
+ "aria-valuemax": 360,
1829
+ "aria-valuenow": Math.round(hsv.h),
1830
+ onKeyDown: (event) => handleSliderKeyDown(event, (delta) => {
1831
+ updateHsv({ h: (hsvRef.current.h + delta + 360) % 360 });
1832
+ apply();
1833
+ }),
1834
+ ...hueDrag,
1835
+ children: /* @__PURE__ */ jsx("div", { className: styles.sliderHandle, style: { left: `${hsv.h / 360 * 100}%` } })
1836
+ }
1837
+ ),
1838
+ /* @__PURE__ */ jsxs("div", { className: styles.alphaRow, children: [
1839
+ /* @__PURE__ */ jsxs(
1840
+ "div",
1841
+ {
1842
+ className: cx(styles.sliderTrack, styles.alphaTrack),
1843
+ role: "slider",
1844
+ tabIndex: 0,
1845
+ "aria-label": tr("\u900F\u660E\u5EA6"),
1846
+ "aria-valuemin": 0,
1847
+ "aria-valuemax": 100,
1848
+ "aria-valuenow": alpha,
1849
+ onKeyDown: (event) => handleSliderKeyDown(event, (delta) => {
1850
+ updateAlpha(alphaRef.current + delta);
1851
+ apply();
1852
+ }),
1853
+ ...alphaDrag,
1854
+ children: [
1855
+ /* @__PURE__ */ jsx(
1856
+ "div",
1857
+ {
1858
+ className: styles.alphaTrackFill,
1859
+ style: { background: `linear-gradient(to right, transparent, ${hexValue})` }
1860
+ }
1861
+ ),
1862
+ /* @__PURE__ */ jsx("div", { className: styles.sliderHandle, style: { left: `${alpha}%` } })
1863
+ ]
1864
+ }
1865
+ ),
1866
+ /* @__PURE__ */ jsx("span", { className: styles.colorPreview, "aria-hidden": "true", children: /* @__PURE__ */ jsx("span", { className: styles.colorPreviewFill, style: { backgroundColor: colorValue } }) })
1867
+ ] }),
1868
+ /* @__PURE__ */ jsxs("div", { className: styles.colorInputs, children: [
1869
+ /* @__PURE__ */ jsxs("div", { className: styles.colorInputField, children: [
1870
+ /* @__PURE__ */ jsx(
1871
+ Input,
1872
+ {
1873
+ size: "small",
1874
+ allowClear: false,
1875
+ value: hexDraft ?? hexValue,
1876
+ "aria-label": tr("HEX \u989C\u8272\u503C"),
1877
+ onFocus: () => setHexDraft(hexValue),
1878
+ onChange: (value) => setHexDraft(value),
1879
+ onBlur: commitHex,
1880
+ onPressEnter: commitHex
1881
+ }
1882
+ ),
1883
+ /* @__PURE__ */ jsx("span", { className: styles.colorInputLabel, children: "HEX" })
1884
+ ] }),
1885
+ ["r", "g", "b"].map((channel) => /* @__PURE__ */ jsxs("div", { className: styles.colorInputField, children: [
1886
+ /* @__PURE__ */ jsx(
1887
+ InputNumber,
1888
+ {
1889
+ size: "small",
1890
+ controls: false,
1891
+ min: 0,
1892
+ max: 255,
1893
+ value: rgb[channel],
1894
+ "aria-label": channel.toUpperCase(),
1895
+ onChange: (value) => setChannel(channel, value),
1896
+ onBlur: apply
1897
+ }
1898
+ ),
1899
+ /* @__PURE__ */ jsx("span", { className: styles.colorInputLabel, children: channel.toUpperCase() })
1900
+ ] }, channel)),
1901
+ /* @__PURE__ */ jsxs("div", { className: styles.colorInputField, children: [
1902
+ /* @__PURE__ */ jsx(
1903
+ InputNumber,
1904
+ {
1905
+ size: "small",
1906
+ controls: false,
1907
+ min: 0,
1908
+ max: 100,
1909
+ value: alpha,
1910
+ "aria-label": "A",
1911
+ onChange: (value) => updateAlpha(value ?? 0),
1912
+ onBlur: apply
1913
+ }
1914
+ ),
1915
+ /* @__PURE__ */ jsx("span", { className: styles.colorInputLabel, children: "A" })
1916
+ ] })
1917
+ ] })
1918
+ ] });
1919
+ }
1190
1920
  function useRovingFocus({
1191
1921
  containerRef,
1192
1922
  count,
@@ -1243,76 +1973,246 @@ function useRovingFocus({
1243
1973
  );
1244
1974
  return { handleKeyDown, focusCell };
1245
1975
  }
1246
- var PRESET_COLORS = [
1247
- "#000000",
1248
- "#434343",
1249
- "#666666",
1250
- "#999999",
1251
- "#E74C3C",
1252
- "#E67E22",
1253
- "#F1C40F",
1254
- "#27AE60",
1255
- "#1ABC9C",
1256
- "#3498DB",
1257
- "#9B59B6",
1258
- "#95A5A6",
1259
- "#FF6B6B",
1260
- "#FFA500",
1261
- "#00BFFF",
1262
- "#9C27B0"
1263
- ];
1264
- var COLOR_GRID_COLS = 8;
1976
+ var PALETTE_ROWS = [GRAYSCALE_COLORS, ...COLOR_PALETTE_ROWS];
1977
+ var SOLID_COLORS = PALETTE_ROWS.flat();
1978
+ function CheckIcon({ color }) {
1979
+ return /* @__PURE__ */ jsx(
1980
+ "svg",
1981
+ {
1982
+ width: "12",
1983
+ height: "12",
1984
+ viewBox: "0 0 12 12",
1985
+ fill: "none",
1986
+ stroke: color,
1987
+ strokeWidth: "1.8",
1988
+ strokeLinecap: "round",
1989
+ strokeLinejoin: "round",
1990
+ "aria-hidden": "true",
1991
+ children: /* @__PURE__ */ jsx("path", { d: "M2.5 6.2 4.9 8.6 9.5 3.4" })
1992
+ }
1993
+ );
1994
+ }
1995
+ function handleActivateKey(event, action) {
1996
+ if (event.key !== "Enter" && event.key !== " ") return;
1997
+ event.preventDefault();
1998
+ action();
1999
+ }
1265
2000
  function ColorPickerButton({ item, editor }) {
1266
- const { styles } = useToolbarStyles();
2001
+ const { styles, cx } = useToolbarStyles();
1267
2002
  const [open, setOpen] = useState(false);
2003
+ const [moreOpen, setMoreOpen] = useState(false);
2004
+ const [recentColors, setRecentColors] = useState([]);
2005
+ const [lastUsedColor, setLastUsedColor] = useState(item.initialColor ?? item.defaultSwatch ?? null);
1268
2006
  const paletteRef = useRef(null);
1269
- const handleColorSelect = (color) => {
1270
- item.onColorSelect?.(editor, color);
2007
+ const activeValue = item.getActiveValue?.(editor) ?? null;
2008
+ const displayValue = lastUsedColor;
2009
+ const checkedValue = activeValue ?? lastUsedColor;
2010
+ useEffect(() => {
2011
+ if (!open) return;
2012
+ const handlePointerDown = (event) => {
2013
+ const target = event.target;
2014
+ const owner = target?.closest?.("[data-color-picker-owner]");
2015
+ if (owner?.getAttribute("data-color-picker-owner") === item.id) return;
2016
+ setOpen(false);
2017
+ setMoreOpen(false);
2018
+ };
2019
+ const handleKeyDown2 = (event) => {
2020
+ if (event.key !== "Escape") return;
2021
+ setOpen(false);
2022
+ setMoreOpen(false);
2023
+ };
2024
+ document.addEventListener("pointerdown", handlePointerDown, true);
2025
+ document.addEventListener("keydown", handleKeyDown2);
2026
+ return () => {
2027
+ document.removeEventListener("pointerdown", handlePointerDown, true);
2028
+ document.removeEventListener("keydown", handleKeyDown2);
2029
+ };
2030
+ }, [open, item.id]);
2031
+ const handleOpenChange = (next) => {
2032
+ setOpen(next);
2033
+ if (next) {
2034
+ setRecentColors(readRecentColors());
2035
+ } else {
2036
+ setMoreOpen(false);
2037
+ }
2038
+ };
2039
+ const applyColor = (color, options) => {
2040
+ item.onColorSelect?.(editor, color, options);
2041
+ setLastUsedColor(color);
2042
+ setOpen(false);
2043
+ };
2044
+ const applyGradient = (gradient) => {
2045
+ item.onGradientSelect?.(editor, gradient);
2046
+ setLastUsedColor(gradient);
1271
2047
  setOpen(false);
1272
2048
  };
1273
- const { handleKeyDown } = useRovingFocus({
1274
- containerRef: paletteRef,
1275
- count: PRESET_COLORS.length,
1276
- cols: COLOR_GRID_COLS,
1277
- navigation: "linear",
1278
- cellSelector: (index) => `[data-idocs-color-index="${index}"]`,
1279
- onSelect: (index) => handleColorSelect(PRESET_COLORS[index])
1280
- });
1281
2049
  const handleClear = () => {
1282
2050
  if (item.onClear) {
1283
2051
  item.onClear(editor);
1284
2052
  } else if (item.onColorSelect) {
1285
2053
  item.onColorSelect(editor, "");
1286
2054
  }
2055
+ setLastUsedColor(item.defaultSwatch ?? null);
1287
2056
  setOpen(false);
1288
2057
  };
1289
- const colorRows = [];
1290
- for (let i = 0; i < PRESET_COLORS.length; i += COLOR_GRID_COLS) {
1291
- colorRows.push(PRESET_COLORS.slice(i, i + COLOR_GRID_COLS));
1292
- }
1293
- const palette = /* @__PURE__ */ jsxs("div", { ref: paletteRef, className: styles.colorPaletteWrapper, children: [
1294
- /* @__PURE__ */ jsx("div", { className: styles.colorPalette, role: "grid", "aria-label": item.label ?? tr("\u989C\u8272"), children: colorRows.map((row, rowIndex) => /* @__PURE__ */ jsx("div", { role: "row", className: styles.colorRow, children: row.map((color, colIndex) => {
1295
- const index = rowIndex * COLOR_GRID_COLS + colIndex;
1296
- return /* @__PURE__ */ jsx(
1297
- "div",
2058
+ const { handleKeyDown } = useRovingFocus({
2059
+ containerRef: paletteRef,
2060
+ count: SOLID_COLORS.length,
2061
+ cols: COLOR_PALETTE_COLUMNS,
2062
+ navigation: "linear",
2063
+ cellSelector: (index) => `[data-idocs-color-index="${index}"]`,
2064
+ onSelect: (index) => applyColor(SOLID_COLORS[index])
2065
+ });
2066
+ const handleCustomChange = (color) => {
2067
+ item.onColorSelect?.(editor, color, { focus: false });
2068
+ setLastUsedColor(color);
2069
+ };
2070
+ const handleCustomRemember = (color) => {
2071
+ rememberRecentColor(color);
2072
+ setRecentColors(readRecentColors());
2073
+ };
2074
+ const handleApplyLastUsed = () => {
2075
+ if (!displayValue) {
2076
+ handleClear();
2077
+ return;
2078
+ }
2079
+ if (isGradientColor(displayValue)) {
2080
+ applyGradient(displayValue);
2081
+ } else {
2082
+ applyColor(displayValue);
2083
+ }
2084
+ };
2085
+ const defaultSwatch = item.defaultSwatch;
2086
+ const isDefaultActive = !checkedValue;
2087
+ const solidInitialColor = lastUsedColor && !isGradientColor(lastUsedColor) ? lastUsedColor : recentColors[0];
2088
+ const barStyle = displayValue ? isGradientColor(displayValue) ? { backgroundImage: displayValue } : { backgroundColor: displayValue } : void 0;
2089
+ const palette = /* @__PURE__ */ jsxs("div", { className: styles.colorPanel, "data-color-picker-owner": item.id, children: [
2090
+ /* @__PURE__ */ jsxs("div", { className: styles.colorPaletteWrapper, children: [
2091
+ /* @__PURE__ */ jsxs("button", { type: "button", className: styles.colorDefaultRow, onClick: handleClear, children: [
2092
+ /* @__PURE__ */ jsx("span", { className: styles.colorDefaultSwatch, style: { backgroundColor: defaultSwatch ?? "transparent" }, children: isDefaultActive && /* @__PURE__ */ jsx(CheckIcon, { color: defaultSwatch ? getReadableCheckColor(defaultSwatch) : "#262626" }) }),
2093
+ /* @__PURE__ */ jsx("span", { className: styles.colorDefaultLabel, children: tr("\u9ED8\u8BA4") })
2094
+ ] }),
2095
+ /* @__PURE__ */ jsx("div", { ref: paletteRef, className: styles.colorPalette, role: "grid", "aria-label": item.label ?? tr("\u989C\u8272"), children: PALETTE_ROWS.map((row, rowIndex) => /* @__PURE__ */ jsx("div", { role: "row", className: styles.colorRow, children: row.map((color, colIndex) => {
2096
+ const index = rowIndex * COLOR_PALETTE_COLUMNS + colIndex;
2097
+ const active = isSameColor(checkedValue, color);
2098
+ return /* @__PURE__ */ jsx(
2099
+ "div",
2100
+ {
2101
+ role: "gridcell",
2102
+ "aria-label": tr("\u9009\u62E9\u989C\u8272 ${0}", [color]),
2103
+ "aria-selected": active,
2104
+ tabIndex: index === 0 ? 0 : -1,
2105
+ "data-idocs-color-index": index,
2106
+ className: styles.colorCell,
2107
+ style: { backgroundColor: color },
2108
+ onClick: () => applyColor(color),
2109
+ onKeyDown: (event) => handleKeyDown(event, index),
2110
+ children: active && /* @__PURE__ */ jsx("span", { className: styles.colorCheck, children: /* @__PURE__ */ jsx(CheckIcon, { color: getReadableCheckColor(color) }) })
2111
+ },
2112
+ `${rowIndex}-${colIndex}`
2113
+ );
2114
+ }) }, rowIndex)) }),
2115
+ /* @__PURE__ */ jsx("div", { className: styles.colorSectionTitle, children: tr("\u6E10\u53D8\u8272") }),
2116
+ /* @__PURE__ */ jsx("div", { className: styles.gradientRow, children: GRADIENT_PRESETS.map((gradient, index) => {
2117
+ const active = isGradientColor(checkedValue) && isSameColor(checkedValue, gradient);
2118
+ return /* @__PURE__ */ jsx(
2119
+ "div",
2120
+ {
2121
+ role: "button",
2122
+ tabIndex: 0,
2123
+ "aria-label": tr("\u6E10\u53D8 ${0}", [index + 1]),
2124
+ className: styles.gradientCell,
2125
+ style: { backgroundImage: gradient },
2126
+ onClick: () => applyGradient(gradient),
2127
+ onKeyDown: (event) => handleActivateKey(event, () => applyGradient(gradient)),
2128
+ children: active && /* @__PURE__ */ jsx("span", { className: styles.colorCheck, children: /* @__PURE__ */ jsx(CheckIcon, { color: "#FFFFFF" }) })
2129
+ },
2130
+ gradient
2131
+ );
2132
+ }) }),
2133
+ /* @__PURE__ */ jsx("div", { className: styles.colorSectionTitle, children: tr("\u6700\u8FD1\u4F7F\u7528\u81EA\u5B9A\u4E49\u989C\u8272") }),
2134
+ recentColors.length === 0 ? /* @__PURE__ */ jsx("div", { className: styles.recentEmpty, children: tr("\u6682\u65E0") }) : /* @__PURE__ */ jsx("div", { className: styles.recentRow, children: recentColors.map((color) => {
2135
+ const active = isSameColor(checkedValue, color);
2136
+ return /* @__PURE__ */ jsxs(
2137
+ "span",
2138
+ {
2139
+ role: "button",
2140
+ tabIndex: 0,
2141
+ "aria-label": tr("\u4F7F\u7528\u989C\u8272 ${0}", [color]),
2142
+ className: styles.alphaSwatch,
2143
+ onClick: () => applyColor(color),
2144
+ onKeyDown: (event) => handleActivateKey(event, () => applyColor(color)),
2145
+ children: [
2146
+ /* @__PURE__ */ jsx("span", { className: styles.alphaSwatchFill, style: { backgroundColor: color } }),
2147
+ active && /* @__PURE__ */ jsx("span", { className: styles.colorCheck, children: /* @__PURE__ */ jsx(CheckIcon, { color: getReadableCheckColor(color) }) })
2148
+ ]
2149
+ },
2150
+ color
2151
+ );
2152
+ }) }),
2153
+ /* @__PURE__ */ jsxs(
2154
+ "button",
1298
2155
  {
1299
- role: "gridcell",
1300
- "aria-label": tr("\u9009\u62E9\u989C\u8272 ${0}", [color]),
1301
- tabIndex: index === 0 ? 0 : -1,
1302
- "data-idocs-color-index": index,
1303
- className: styles.colorCell,
1304
- style: { backgroundColor: color },
1305
- onClick: () => handleColorSelect(color),
1306
- onKeyDown: (event) => handleKeyDown(event, index)
1307
- },
1308
- color
1309
- );
1310
- }) }, rowIndex)) }),
1311
- /* @__PURE__ */ jsx("div", { className: styles.clearColorBtn, children: /* @__PURE__ */ jsx(Button, { type: "text", size: "small", block: true, onClick: handleClear, children: tr("\u6E05\u9664\u989C\u8272") }) })
2156
+ type: "button",
2157
+ className: styles.moreColorRow,
2158
+ "aria-expanded": moreOpen,
2159
+ onClick: () => setMoreOpen((value) => !value),
2160
+ children: [
2161
+ /* @__PURE__ */ jsx("span", { className: styles.moreColorDot, "aria-hidden": "true" }),
2162
+ /* @__PURE__ */ jsx("span", { className: styles.moreColorLabel, children: tr("\u66F4\u591A\u989C\u8272") }),
2163
+ /* @__PURE__ */ jsx("span", { className: cx(styles.moreColorChevron, moreOpen && styles.moreColorChevronOpen), children: /* @__PURE__ */ jsx(IconChevronDown, { size: 12 }) })
2164
+ ]
2165
+ }
2166
+ )
2167
+ ] }),
2168
+ moreOpen && /* @__PURE__ */ jsx(
2169
+ ColorCustomPicker,
2170
+ {
2171
+ initialColor: solidInitialColor,
2172
+ onChange: handleCustomChange,
2173
+ onRemember: handleCustomRemember
2174
+ }
2175
+ )
2176
+ ] });
2177
+ const trigger = /* @__PURE__ */ jsxs("span", { className: styles.colorTrigger, "data-color-picker-owner": item.id, children: [
2178
+ /* @__PURE__ */ jsx("button", { type: "button", className: styles.colorTriggerMain, "aria-label": item.label, onClick: handleApplyLastUsed, children: /* @__PURE__ */ jsxs("span", { className: styles.colorTriggerIcon, children: [
2179
+ item.icon,
2180
+ /* @__PURE__ */ jsx("span", { className: cx(styles.colorTriggerBar, !displayValue && styles.colorTriggerBarEmpty), style: barStyle })
2181
+ ] }) }),
2182
+ /* @__PURE__ */ jsx(
2183
+ "button",
2184
+ {
2185
+ type: "button",
2186
+ className: cx(styles.colorTriggerArrow, open && styles.colorTriggerArrowOpen),
2187
+ "aria-label": tr("\u9009\u62E9\u989C\u8272"),
2188
+ "aria-expanded": open,
2189
+ onClick: () => setOpen((value) => !value),
2190
+ children: /* @__PURE__ */ jsx(IconChevronDown, { size: 14 })
2191
+ }
2192
+ )
1312
2193
  ] });
1313
- const triggerBtn = /* @__PURE__ */ jsx(ToolbarDropdownTrigger, { children: item.icon });
1314
- return /* @__PURE__ */ jsx(Dropdown, { trigger: ["click"], open, onOpenChange: setOpen, popupRender: () => palette, children: item.label ? /* @__PURE__ */ jsx(Tooltip, { title: item.label, children: triggerBtn }) : triggerBtn });
2194
+ return /* @__PURE__ */ jsx(Dropdown, { trigger: [], open, onOpenChange: handleOpenChange, popupRender: () => palette, children: item.label ? /* @__PURE__ */ jsx(Tooltip, { title: item.label, children: trigger }) : trigger });
1315
2195
  }
2196
+ var ToolbarDropdownTrigger = forwardRef(
2197
+ ({ children, className, ...rest }, ref) => {
2198
+ const { styles, cx } = useToolbarStyles();
2199
+ return /* @__PURE__ */ jsxs(
2200
+ Button,
2201
+ {
2202
+ ref,
2203
+ type: "text",
2204
+ size: "middle",
2205
+ ...rest,
2206
+ className: cx(styles.dropdownTrigger, className),
2207
+ children: [
2208
+ children,
2209
+ /* @__PURE__ */ jsx(IconChevronDown, { size: 14 })
2210
+ ]
2211
+ }
2212
+ );
2213
+ }
2214
+ );
2215
+ ToolbarDropdownTrigger.displayName = "ToolbarDropdownTrigger";
1316
2216
  var MAX_ROWS = 5;
1317
2217
  var MAX_COLS = 5;
1318
2218
  function TableInsertMenu({ item, editor }) {
@@ -1380,7 +2280,7 @@ function ToolbarButton({ item, editor }) {
1380
2280
  Button,
1381
2281
  {
1382
2282
  type: "text",
1383
- size: "small",
2283
+ size: "middle",
1384
2284
  icon: item.icon,
1385
2285
  disabled,
1386
2286
  className: active ? styles.activeBtn : void 0,
@@ -1422,7 +2322,10 @@ function ToolbarDropdown({ item, editor }) {
1422
2322
  opt?.onClick(editor);
1423
2323
  }
1424
2324
  },
1425
- children: /* @__PURE__ */ jsx(ToolbarDropdownTrigger, { children: triggerLabel })
2325
+ children: /* @__PURE__ */ jsxs(ToolbarDropdownTrigger, { children: [
2326
+ item.icon,
2327
+ triggerLabel
2328
+ ] })
1426
2329
  }
1427
2330
  );
1428
2331
  }
@@ -2438,5 +3341,5 @@ var RichEditor = forwardRef(function RichEditor2(props, ref) {
2438
3341
  });
2439
3342
 
2440
3343
  export { CollaborationProvider, EditorContext, RichEditor, useCollaboration, useEditorContext, usePluginRegistry };
2441
- //# sourceMappingURL=chunk-N3YIYJWU.mjs.map
2442
- //# sourceMappingURL=chunk-N3YIYJWU.mjs.map
3344
+ //# sourceMappingURL=chunk-3K44CBQF.mjs.map
3345
+ //# sourceMappingURL=chunk-3K44CBQF.mjs.map