@lvce-editor/find-widget-worker 3.16.1 → 3.17.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.
@@ -1529,6 +1529,7 @@ const createState = (uid, x, y, width, height, parentUid, instanceId) => {
1529
1529
  focused: false,
1530
1530
  focusSource: Unknown,
1531
1531
  focusVersion: 0,
1532
+ fontSize: 'inherit',
1532
1533
  height: 0,
1533
1534
  history: [],
1534
1535
  inputBorderWidth: 1,
@@ -1580,7 +1581,7 @@ const isEqual$8 = (oldState, newState) => {
1580
1581
  };
1581
1582
 
1582
1583
  const isEqual$7 = (oldState, newState) => {
1583
- return oldState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.searchInputHeight === newState.searchInputHeight;
1584
+ return oldState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.searchInputHeight === newState.searchInputHeight && oldState.fontSize === newState.fontSize;
1584
1585
  };
1585
1586
 
1586
1587
  const isEqual$6 = (oldState, newState) => {
@@ -1875,8 +1876,9 @@ const measureTextHeight = (value, lineHeight) => {
1875
1876
  return lines.length * lineHeight;
1876
1877
  };
1877
1878
 
1878
- const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded) => {
1879
- const textHeight = measureTextHeight(value, inputLineHeight);
1879
+ const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize = 'inherit') => {
1880
+ const effectiveLineHeight = typeof fontSize === 'number' ? Math.max(inputLineHeight, fontSize) : inputLineHeight;
1881
+ const textHeight = measureTextHeight(value, effectiveLineHeight);
1880
1882
  const inputHeight = textHeight + inputPaddingBottom + inputPaddingTop + inputBorderWidth * 2;
1881
1883
  const replaceInputHeight = replaceExpanded ? inputHeight : 0; // TODO should be independent of input
1882
1884
  const actualGap = replaceExpanded ? inputGap : 0;
@@ -1891,6 +1893,7 @@ const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPad
1891
1893
 
1892
1894
  const refresh$1 = (state, value, inputSource) => {
1893
1895
  const {
1896
+ fontSize,
1894
1897
  inputBorderWidth,
1895
1898
  inputGap,
1896
1899
  inputLineHeight,
@@ -1914,7 +1917,7 @@ const refresh$1 = (state, value, inputSource) => {
1914
1917
  const {
1915
1918
  height,
1916
1919
  inputHeight
1917
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
1920
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
1918
1921
  if (error) {
1919
1922
  return {
1920
1923
  ...state,
@@ -2376,6 +2379,7 @@ const handleToggleReplaceFocus = state => {
2376
2379
 
2377
2380
  const toggleReplace$1 = state => {
2378
2381
  const {
2382
+ fontSize,
2379
2383
  inputBorderWidth,
2380
2384
  inputGap,
2381
2385
  inputLineHeight,
@@ -2387,7 +2391,7 @@ const toggleReplace$1 = state => {
2387
2391
  const newExpanded = !replaceExpanded;
2388
2392
  const {
2389
2393
  height
2390
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, newExpanded);
2394
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, newExpanded, fontSize);
2391
2395
  return {
2392
2396
  ...state,
2393
2397
  height,
@@ -2598,6 +2602,57 @@ const handleReplaceInput = (state, value, inputSource = User$1) => {
2598
2602
  };
2599
2603
  };
2600
2604
 
2605
+ const MIN_FONT_SIZE = 10;
2606
+ const MAX_FONT_SIZE = 100;
2607
+ const EMPTY_VALUES = [undefined, null, '', 0];
2608
+ const normalizeFontSize = value => {
2609
+ let result = 'inherit';
2610
+ if (!EMPTY_VALUES.includes(value)) {
2611
+ let numericValue = NaN;
2612
+ if (typeof value === 'number') {
2613
+ numericValue = value;
2614
+ } else if (typeof value === 'string' && value.trim()) {
2615
+ numericValue = Number(value);
2616
+ }
2617
+ if (Number.isFinite(numericValue)) {
2618
+ result = Math.min(MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, numericValue));
2619
+ }
2620
+ }
2621
+ return result;
2622
+ };
2623
+
2624
+ const getFontSize = async () => {
2625
+ try {
2626
+ const value = await invoke('Editor.getFindWidgetFontSize');
2627
+ return normalizeFontSize(value);
2628
+ } catch {
2629
+ return 'inherit';
2630
+ }
2631
+ };
2632
+
2633
+ const handleSettingsChanged = async state => {
2634
+ const {
2635
+ inputBorderWidth,
2636
+ inputGap,
2637
+ inputLineHeight,
2638
+ inputPaddingBottom,
2639
+ inputPaddingTop,
2640
+ replaceExpanded,
2641
+ value
2642
+ } = state;
2643
+ const fontSize = await getFontSize();
2644
+ const {
2645
+ height,
2646
+ inputHeight
2647
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
2648
+ return {
2649
+ ...state,
2650
+ fontSize,
2651
+ height,
2652
+ searchInputHeight: inputHeight
2653
+ };
2654
+ };
2655
+
2601
2656
  const regexFlags = 'gi';
2602
2657
  const getSearchRegex = searchString => {
2603
2658
  const escaped = escapeRegExpCharacters(searchString);
@@ -2612,8 +2667,7 @@ const findMatchesCaseInsensitive = (lines, searchString) => {
2612
2667
  return findRegexMatches(lines, regex);
2613
2668
  };
2614
2669
 
2615
- const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
2616
- const width = 300;
2670
+ const getFindWidgetPosition = (editorX, editorY, editorWidth, width = 300) => {
2617
2671
  const height = 30;
2618
2672
  const paddingTop = 10;
2619
2673
  const paddingRight = 20;
@@ -2678,6 +2732,7 @@ const loadContent = async (state, savedState) => {
2678
2732
  inputPaddingTop,
2679
2733
  replaceExpanded
2680
2734
  } = state;
2735
+ const fontSize = await getFontSize();
2681
2736
  const {
2682
2737
  replacement,
2683
2738
  value
@@ -2698,11 +2753,12 @@ const loadContent = async (state, savedState) => {
2698
2753
  const {
2699
2754
  height,
2700
2755
  inputHeight
2701
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
2756
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
2702
2757
  return {
2703
2758
  ...state,
2704
2759
  focus: FocusSearchInput,
2705
2760
  focused: true,
2761
+ fontSize,
2706
2762
  height,
2707
2763
  inputSource: Script$1,
2708
2764
  lines,
@@ -3193,6 +3249,7 @@ const renderContent = (oldState, newState) => {
3193
3249
 
3194
3250
  const renderCss = (oldState, newState) => {
3195
3251
  const {
3252
+ fontSize,
3196
3253
  height,
3197
3254
  searchInputHeight: inputHeight,
3198
3255
  uid,
@@ -3200,12 +3257,14 @@ const renderCss = (oldState, newState) => {
3200
3257
  x,
3201
3258
  y
3202
3259
  } = newState;
3260
+ const cssFontSize = fontSize === 'inherit' ? 'inherit' : `${fontSize}px`;
3203
3261
  const css = `:root {
3204
3262
  --FindWidgetWidth: ${width}px;
3205
3263
  --FindWidgetHeight: ${height}px;
3206
3264
  --FindWidgetX: ${x}px;
3207
3265
  --FindWidgetY: ${y}px;
3208
3266
  --FindWidgetInputHeight: ${inputHeight}px;
3267
+ --FindWidgetFontSize: ${cssFontSize};
3209
3268
  }`;
3210
3269
  return [SetCss, uid, css];
3211
3270
  };
@@ -3423,7 +3482,25 @@ const renderInstance = (instanceId, diffResult) => {
3423
3482
  };
3424
3483
 
3425
3484
  const resize = async (state, dimensions) => {
3426
- return state;
3485
+ const {
3486
+ height: editorHeight,
3487
+ width: editorWidth,
3488
+ x: editorX,
3489
+ y: editorY
3490
+ } = dimensions;
3491
+ const {
3492
+ width: widgetWidth
3493
+ } = state;
3494
+ const position = getFindWidgetPosition(editorX, editorY, editorWidth, widgetWidth);
3495
+ return {
3496
+ ...state,
3497
+ editorHeight,
3498
+ editorWidth,
3499
+ editorX,
3500
+ editorY,
3501
+ x: position.x,
3502
+ y: position.y
3503
+ };
3427
3504
  };
3428
3505
 
3429
3506
  const saveState = state => {
@@ -3483,6 +3560,7 @@ const commandMap = {
3483
3560
  'FindWidget.handleResizerPointerDown': wrapCommand(handleResizerPointerDown),
3484
3561
  'FindWidget.handleResizerPointerMove': wrapCommand(handleResizerPointerMove),
3485
3562
  'FindWidget.handleResizerPointerUp': wrapCommand(handleResizerPointerUp),
3563
+ 'FindWidget.handleSettingsChanged': wrapCommand(handleSettingsChanged),
3486
3564
  'FindWidget.handleToggleReplaceFocus': wrapCommand(handleToggleReplaceFocus),
3487
3565
  'FindWidget.loadContent': wrapCommand(loadContent),
3488
3566
  '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.1",
3
+ "version": "3.17.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",