@lvce-editor/find-widget-worker 3.16.2 → 3.18.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.
@@ -508,6 +508,9 @@ const restoreExistingError = (error, currentStack) => {
508
508
  };
509
509
  const restoreMethodNotFoundError = (error, currentStack) => {
510
510
  const restoredError = new JsonRpcError(error.message);
511
+ Object.assign(restoredError, {
512
+ code: error.code
513
+ });
511
514
  const parentStack = getParentStack(error);
512
515
  setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
513
516
  return restoredError;
@@ -527,9 +530,13 @@ const applyDataProperties = (restoredError, error) => {
527
530
  // @ts-ignore
528
531
  restoredError.codeFrame = error.data.codeFrame;
529
532
  }
530
- if (error.data.code) {
533
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
531
534
  // @ts-ignore
532
- restoredError.code = error.data.code;
535
+ Object.defineProperty(restoredError, 'code', {
536
+ configurable: true,
537
+ value: error.data.code,
538
+ writable: true
539
+ });
533
540
  }
534
541
  if (error.data.type) {
535
542
  // @ts-ignore
@@ -550,7 +557,14 @@ const applyDirectProperties = (restoredError, error) => {
550
557
  }
551
558
  };
552
559
  const restoreMessageError = (error, _currentStack) => {
553
- const restoredError = constructError(error.message, error.type, error.name);
560
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
561
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
562
+ Object.defineProperty(restoredError, 'code', {
563
+ configurable: true,
564
+ value: error.code,
565
+ writable: true
566
+ });
567
+ }
554
568
  if (error.data) {
555
569
  applyDataProperties(restoredError, error);
556
570
  } else {
@@ -558,6 +572,23 @@ const restoreMessageError = (error, _currentStack) => {
558
572
  }
559
573
  return restoredError;
560
574
  };
575
+ const getFallbackMessage = error => {
576
+ if (error && typeof error.message === 'string' && error.message) {
577
+ return error.message;
578
+ }
579
+ if (error && error.data) {
580
+ return getFallbackMessage(error.data);
581
+ }
582
+ const stringified = String(error);
583
+ if (stringified !== '[object Object]') {
584
+ return stringified;
585
+ }
586
+ try {
587
+ return JSON.stringify(error);
588
+ } catch {
589
+ return stringified;
590
+ }
591
+ };
561
592
  const restoreJsonRpcError = error => {
562
593
  const currentStack = getCurrentStack();
563
594
  if (error && error instanceof Error) {
@@ -566,13 +597,13 @@ const restoreJsonRpcError = error => {
566
597
  if (error && error.code && error.code === MethodNotFound) {
567
598
  return restoreMethodNotFoundError(error, currentStack);
568
599
  }
600
+ if (error && error.error) {
601
+ return restoreJsonRpcError(error.error);
602
+ }
569
603
  if (error && error.message) {
570
604
  return restoreMessageError(error);
571
605
  }
572
- if (typeof error === 'string') {
573
- return new Error(`JsonRpc Error: ${error}`);
574
- }
575
- return new Error(`JsonRpc Error: ${error}`);
606
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
576
607
  };
577
608
  const unwrapJsonRpcResult = responseMessage => {
578
609
  if ('error' in responseMessage) {
@@ -629,9 +660,9 @@ const getErrorProperty = (error, prettyError) => {
629
660
  return {
630
661
  code: Custom,
631
662
  data: {
632
- code: prettyError.code,
663
+ code: prettyError.code ?? error?.code,
633
664
  codeFrame: prettyError.codeFrame,
634
- name: prettyError.name,
665
+ name: prettyError.name ?? error?.name,
635
666
  stack: getStack(prettyError),
636
667
  type: getErrorType(prettyError)
637
668
  },
@@ -666,7 +697,12 @@ const getErrorResponseSimple = (id, error) => {
666
697
  return {
667
698
  error: {
668
699
  code: Custom,
669
- data: error,
700
+ data: error instanceof Error ? {
701
+ ...error,
702
+ code: 'code' in error ? error.code : undefined,
703
+ stack: error.stack,
704
+ type: error.name
705
+ } : error,
670
706
  // @ts-ignore
671
707
  message: error.message
672
708
  },
@@ -955,174 +991,10 @@ const CheckBox = 'checkbox';
955
991
  const Group = 'group';
956
992
  const None = 'none';
957
993
 
958
- const Audio = 0;
959
994
  const Button = 1;
960
- const Col = 2;
961
- const ColGroup = 3;
962
995
  const Div = 4;
963
- const H1 = 5;
964
- const Input = 6;
965
- const Kbd = 7;
966
- const Span = 8;
967
- const Table = 9;
968
- const TBody = 10;
969
- const Td = 11;
970
996
  const Text = 12;
971
- const Th = 13;
972
- const THead = 14;
973
- const Tr = 15;
974
- const I = 16;
975
- const Img = 17;
976
- const Root = 0;
977
- const Ins = 20;
978
- const Del = 21;
979
- const H2 = 22;
980
- const H3 = 23;
981
- const H4 = 24;
982
- const H5 = 25;
983
- const H6 = 26;
984
- const Article = 27;
985
- const Aside = 28;
986
- const Footer = 29;
987
- const Header = 30;
988
- const Nav = 40;
989
- const Section = 41;
990
- const Search = 42;
991
- const Dd = 43;
992
- const Dl = 44;
993
- const Figcaption = 45;
994
- const Figure = 46;
995
- const Hr = 47;
996
- const Li = 48;
997
- const Ol = 49;
998
- const P = 50;
999
- const Pre = 51;
1000
- const A = 53;
1001
- const Abbr = 54;
1002
- const Br = 55;
1003
- const Cite = 56;
1004
- const Data = 57;
1005
- const Time = 58;
1006
- const Tfoot = 59;
1007
- const Ul = 60;
1008
- const Video = 61;
1009
997
  const TextArea = 62;
1010
- const Select = 63;
1011
- const Option = 64;
1012
- const Code = 65;
1013
- const Label = 66;
1014
- const Dt = 67;
1015
- const Iframe = 68;
1016
- const Main = 69;
1017
- const Strong = 70;
1018
- const Em = 71;
1019
- const Style = 72;
1020
- const Html = 73;
1021
- const Head = 74;
1022
- const Title = 75;
1023
- const Meta = 76;
1024
- const Canvas = 77;
1025
- const Form = 78;
1026
- const BlockQuote = 79;
1027
- const Quote = 80;
1028
- const Circle = 81;
1029
- const Defs = 82;
1030
- const Ellipse = 83;
1031
- const G = 84;
1032
- const Line = 85;
1033
- const Path = 86;
1034
- const Polygon = 87;
1035
- const Polyline = 88;
1036
- const Rect = 89;
1037
- const Svg = 90;
1038
- const Use = 91;
1039
- const Reference = 100;
1040
-
1041
- const VirtualDomElements = {
1042
- __proto__: null,
1043
- A,
1044
- Abbr,
1045
- Article,
1046
- Aside,
1047
- Audio,
1048
- BlockQuote,
1049
- Br,
1050
- Button,
1051
- Canvas,
1052
- Circle,
1053
- Cite,
1054
- Code,
1055
- Col,
1056
- ColGroup,
1057
- Data,
1058
- Dd,
1059
- Defs,
1060
- Del,
1061
- Div,
1062
- Dl,
1063
- Dt,
1064
- Ellipse,
1065
- Em,
1066
- Figcaption,
1067
- Figure,
1068
- Footer,
1069
- Form,
1070
- G,
1071
- H1,
1072
- H2,
1073
- H3,
1074
- H4,
1075
- H5,
1076
- H6,
1077
- Head,
1078
- Header,
1079
- Hr,
1080
- Html,
1081
- I,
1082
- Iframe,
1083
- Img,
1084
- Input,
1085
- Ins,
1086
- Kbd,
1087
- Label,
1088
- Li,
1089
- Line,
1090
- Main,
1091
- Meta,
1092
- Nav,
1093
- Ol,
1094
- Option,
1095
- P,
1096
- Path,
1097
- Polygon,
1098
- Polyline,
1099
- Pre,
1100
- Quote,
1101
- Rect,
1102
- Reference,
1103
- Root,
1104
- Search,
1105
- Section,
1106
- Select,
1107
- Span,
1108
- Strong,
1109
- Style,
1110
- Svg,
1111
- TBody,
1112
- THead,
1113
- Table,
1114
- Td,
1115
- Text,
1116
- TextArea,
1117
- Tfoot,
1118
- Th,
1119
- Time,
1120
- Title,
1121
- Tr,
1122
- Ul,
1123
- Use,
1124
- Video
1125
- };
1126
998
 
1127
999
  const ClientX = 'event.clientX';
1128
1000
  const ClientY = 'event.clientY';
@@ -1192,7 +1064,8 @@ const create$1 = () => {
1192
1064
  const commandQueues = new Map();
1193
1065
  const generations = Object.create(null);
1194
1066
  const states = Object.create(null);
1195
- const commandMapRef = {};
1067
+ const commandMapRef = Object.create(null);
1068
+ const commandsById = Object.create(null);
1196
1069
  const getGeneration = uid => generations[uid] || 0;
1197
1070
  const isCurrentGeneration = (uid, generation) => {
1198
1071
  return states[uid] !== undefined && getGeneration(uid) === generation;
@@ -1254,6 +1127,18 @@ const create$1 = () => {
1254
1127
  delete states[key];
1255
1128
  }
1256
1129
  },
1130
+ createDirectEventCommandMap(requestRender) {
1131
+ return {
1132
+ async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
1133
+ const fn = commandsById[command];
1134
+ if (!fn) {
1135
+ throw new Error(`Viewlet command not found: ${command}`);
1136
+ }
1137
+ await fn(uid, ...args);
1138
+ await requestRender(uid);
1139
+ }
1140
+ };
1141
+ },
1257
1142
  diff(uid, modules, numbers) {
1258
1143
  const {
1259
1144
  oldState,
@@ -1285,6 +1170,9 @@ const create$1 = () => {
1285
1170
  },
1286
1171
  registerCommands(commandMap) {
1287
1172
  Object.assign(commandMapRef, commandMap);
1173
+ for (const [key, fn] of Object.entries(commandMap)) {
1174
+ commandsById[toCommandId(key)] = fn;
1175
+ }
1288
1176
  },
1289
1177
  set(uid, oldState, newState, scheduledState) {
1290
1178
  const current = states[uid];
@@ -1529,6 +1417,7 @@ const createState = (uid, x, y, width, height, parentUid, instanceId) => {
1529
1417
  focused: false,
1530
1418
  focusSource: Unknown,
1531
1419
  focusVersion: 0,
1420
+ fontSize: 'inherit',
1532
1421
  height: 0,
1533
1422
  history: [],
1534
1423
  inputBorderWidth: 1,
@@ -1580,7 +1469,7 @@ const isEqual$8 = (oldState, newState) => {
1580
1469
  };
1581
1470
 
1582
1471
  const isEqual$7 = (oldState, newState) => {
1583
- return oldState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.searchInputHeight === newState.searchInputHeight;
1472
+ return oldState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.searchInputHeight === newState.searchInputHeight && oldState.fontSize === newState.fontSize;
1584
1473
  };
1585
1474
 
1586
1475
  const isEqual$6 = (oldState, newState) => {
@@ -1815,6 +1704,14 @@ const buildRegex = (searchString, options) => {
1815
1704
  }
1816
1705
  };
1817
1706
 
1707
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Appends matches to the shared output array.
1708
+ const collectMatchesForLineInternal = (matches, line, lineIndex, regex) => {
1709
+ let lastMatch = regex.exec(line);
1710
+ while (lastMatch) {
1711
+ matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
1712
+ lastMatch = regex.exec(line);
1713
+ }
1714
+ };
1818
1715
  const findRegexMatches = (lines, regex) => {
1819
1716
  if (!regex.global) {
1820
1717
  throw new Error('regex must be global');
@@ -1823,15 +1720,8 @@ const findRegexMatches = (lines, regex) => {
1823
1720
  length
1824
1721
  } = lines;
1825
1722
  const matches = [];
1826
- const collectMatchesForLine = (line, lineIndex) => {
1827
- let lastMatch = regex.exec(line);
1828
- while (lastMatch) {
1829
- matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
1830
- lastMatch = regex.exec(line);
1831
- }
1832
- };
1833
1723
  for (let i = 0; i < length; i++) {
1834
- collectMatchesForLine(lines[i], i);
1724
+ collectMatchesForLineInternal(matches, lines[i], i, regex);
1835
1725
  }
1836
1726
  return new Uint32Array(matches);
1837
1727
  };
@@ -1875,8 +1765,9 @@ const measureTextHeight = (value, lineHeight) => {
1875
1765
  return lines.length * lineHeight;
1876
1766
  };
1877
1767
 
1878
- const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded) => {
1879
- const textHeight = measureTextHeight(value, inputLineHeight);
1768
+ const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize = 'inherit') => {
1769
+ const effectiveLineHeight = typeof fontSize === 'number' ? Math.max(inputLineHeight, fontSize) : inputLineHeight;
1770
+ const textHeight = measureTextHeight(value, effectiveLineHeight);
1880
1771
  const inputHeight = textHeight + inputPaddingBottom + inputPaddingTop + inputBorderWidth * 2;
1881
1772
  const replaceInputHeight = replaceExpanded ? inputHeight : 0; // TODO should be independent of input
1882
1773
  const actualGap = replaceExpanded ? inputGap : 0;
@@ -1891,6 +1782,7 @@ const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPad
1891
1782
 
1892
1783
  const refresh$1 = (state, value, inputSource) => {
1893
1784
  const {
1785
+ fontSize,
1894
1786
  inputBorderWidth,
1895
1787
  inputGap,
1896
1788
  inputLineHeight,
@@ -1914,7 +1806,7 @@ const refresh$1 = (state, value, inputSource) => {
1914
1806
  const {
1915
1807
  height,
1916
1808
  inputHeight
1917
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
1809
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
1918
1810
  if (error) {
1919
1811
  return {
1920
1812
  ...state,
@@ -1971,11 +1863,11 @@ const togglePreserveCase = state => {
1971
1863
  const {
1972
1864
  preserveCase
1973
1865
  } = state;
1974
- // TODO update search results
1975
- return {
1866
+ const newState = {
1976
1867
  ...state,
1977
1868
  preserveCase: !preserveCase
1978
1869
  };
1870
+ return refresh(newState, newState.value, User$1);
1979
1871
  };
1980
1872
 
1981
1873
  const toggleUseRegularExpression = state => {
@@ -2376,6 +2268,7 @@ const handleToggleReplaceFocus = state => {
2376
2268
 
2377
2269
  const toggleReplace$1 = state => {
2378
2270
  const {
2271
+ fontSize,
2379
2272
  inputBorderWidth,
2380
2273
  inputGap,
2381
2274
  inputLineHeight,
@@ -2387,7 +2280,7 @@ const toggleReplace$1 = state => {
2387
2280
  const newExpanded = !replaceExpanded;
2388
2281
  const {
2389
2282
  height
2390
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, newExpanded);
2283
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, newExpanded, fontSize);
2391
2284
  return {
2392
2285
  ...state,
2393
2286
  height,
@@ -2598,6 +2491,57 @@ const handleReplaceInput = (state, value, inputSource = User$1) => {
2598
2491
  };
2599
2492
  };
2600
2493
 
2494
+ const MIN_FONT_SIZE = 10;
2495
+ const MAX_FONT_SIZE = 100;
2496
+ const EMPTY_VALUES = [undefined, null, '', 0];
2497
+ const normalizeFontSize = value => {
2498
+ let result = 'inherit';
2499
+ if (!EMPTY_VALUES.includes(value)) {
2500
+ let numericValue = NaN;
2501
+ if (typeof value === 'number') {
2502
+ numericValue = value;
2503
+ } else if (typeof value === 'string' && value.trim()) {
2504
+ numericValue = Number(value);
2505
+ }
2506
+ if (Number.isFinite(numericValue)) {
2507
+ result = Math.min(MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, numericValue));
2508
+ }
2509
+ }
2510
+ return result;
2511
+ };
2512
+
2513
+ const getFontSize = async () => {
2514
+ try {
2515
+ const value = await invoke('Editor.getFindWidgetFontSize');
2516
+ return normalizeFontSize(value);
2517
+ } catch {
2518
+ return 'inherit';
2519
+ }
2520
+ };
2521
+
2522
+ const handleSettingsChanged = async state => {
2523
+ const {
2524
+ inputBorderWidth,
2525
+ inputGap,
2526
+ inputLineHeight,
2527
+ inputPaddingBottom,
2528
+ inputPaddingTop,
2529
+ replaceExpanded,
2530
+ value
2531
+ } = state;
2532
+ const fontSize = await getFontSize();
2533
+ const {
2534
+ height,
2535
+ inputHeight
2536
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
2537
+ return {
2538
+ ...state,
2539
+ fontSize,
2540
+ height,
2541
+ searchInputHeight: inputHeight
2542
+ };
2543
+ };
2544
+
2601
2545
  const regexFlags = 'gi';
2602
2546
  const getSearchRegex = searchString => {
2603
2547
  const escaped = escapeRegExpCharacters(searchString);
@@ -2677,6 +2621,7 @@ const loadContent = async (state, savedState) => {
2677
2621
  inputPaddingTop,
2678
2622
  replaceExpanded
2679
2623
  } = state;
2624
+ const fontSize = await getFontSize();
2680
2625
  const {
2681
2626
  replacement,
2682
2627
  value
@@ -2697,11 +2642,12 @@ const loadContent = async (state, savedState) => {
2697
2642
  const {
2698
2643
  height,
2699
2644
  inputHeight
2700
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
2645
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
2701
2646
  return {
2702
2647
  ...state,
2703
2648
  focus: FocusSearchInput,
2704
2649
  focused: true,
2650
+ fontSize,
2705
2651
  height,
2706
2652
  inputSource: Script$1,
2707
2653
  lines,
@@ -2924,8 +2870,6 @@ const text = data => {
2924
2870
  };
2925
2871
  };
2926
2872
 
2927
- new Set(Object.values(VirtualDomElements));
2928
-
2929
2873
  const FindWidget = 'FindWidget';
2930
2874
  const FindWidgetFind = 'FindWidgetFind';
2931
2875
  const FindWidgetMatchCount = 'FindWidgetMatchCount';
@@ -3192,6 +3136,7 @@ const renderContent = (oldState, newState) => {
3192
3136
 
3193
3137
  const renderCss = (oldState, newState) => {
3194
3138
  const {
3139
+ fontSize,
3195
3140
  height,
3196
3141
  searchInputHeight: inputHeight,
3197
3142
  uid,
@@ -3199,12 +3144,14 @@ const renderCss = (oldState, newState) => {
3199
3144
  x,
3200
3145
  y
3201
3146
  } = newState;
3147
+ const cssFontSize = fontSize === 'inherit' ? 'inherit' : `${fontSize}px`;
3202
3148
  const css = `:root {
3203
3149
  --FindWidgetWidth: ${width}px;
3204
3150
  --FindWidgetHeight: ${height}px;
3205
3151
  --FindWidgetX: ${x}px;
3206
3152
  --FindWidgetY: ${y}px;
3207
3153
  --FindWidgetInputHeight: ${inputHeight}px;
3154
+ --FindWidgetFontSize: ${cssFontSize};
3208
3155
  }`;
3209
3156
  return [SetCss, uid, css];
3210
3157
  };
@@ -3500,6 +3447,7 @@ const commandMap = {
3500
3447
  'FindWidget.handleResizerPointerDown': wrapCommand(handleResizerPointerDown),
3501
3448
  'FindWidget.handleResizerPointerMove': wrapCommand(handleResizerPointerMove),
3502
3449
  'FindWidget.handleResizerPointerUp': wrapCommand(handleResizerPointerUp),
3450
+ 'FindWidget.handleSettingsChanged': wrapCommand(handleSettingsChanged),
3503
3451
  'FindWidget.handleToggleReplaceFocus': wrapCommand(handleToggleReplaceFocus),
3504
3452
  'FindWidget.loadContent': wrapCommand(loadContent),
3505
3453
  'FindWidget.loadContentInstance': wrapInstanceCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "3.16.2",
3
+ "version": "3.18.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",