@lvce-editor/find-widget-worker 3.16.2 → 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);
@@ -2677,6 +2732,7 @@ const loadContent = async (state, savedState) => {
2677
2732
  inputPaddingTop,
2678
2733
  replaceExpanded
2679
2734
  } = state;
2735
+ const fontSize = await getFontSize();
2680
2736
  const {
2681
2737
  replacement,
2682
2738
  value
@@ -2697,11 +2753,12 @@ const loadContent = async (state, savedState) => {
2697
2753
  const {
2698
2754
  height,
2699
2755
  inputHeight
2700
- } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
2756
+ } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded, fontSize);
2701
2757
  return {
2702
2758
  ...state,
2703
2759
  focus: FocusSearchInput,
2704
2760
  focused: true,
2761
+ fontSize,
2705
2762
  height,
2706
2763
  inputSource: Script$1,
2707
2764
  lines,
@@ -3192,6 +3249,7 @@ const renderContent = (oldState, newState) => {
3192
3249
 
3193
3250
  const renderCss = (oldState, newState) => {
3194
3251
  const {
3252
+ fontSize,
3195
3253
  height,
3196
3254
  searchInputHeight: inputHeight,
3197
3255
  uid,
@@ -3199,12 +3257,14 @@ const renderCss = (oldState, newState) => {
3199
3257
  x,
3200
3258
  y
3201
3259
  } = newState;
3260
+ const cssFontSize = fontSize === 'inherit' ? 'inherit' : `${fontSize}px`;
3202
3261
  const css = `:root {
3203
3262
  --FindWidgetWidth: ${width}px;
3204
3263
  --FindWidgetHeight: ${height}px;
3205
3264
  --FindWidgetX: ${x}px;
3206
3265
  --FindWidgetY: ${y}px;
3207
3266
  --FindWidgetInputHeight: ${inputHeight}px;
3267
+ --FindWidgetFontSize: ${cssFontSize};
3208
3268
  }`;
3209
3269
  return [SetCss, uid, css];
3210
3270
  };
@@ -3500,6 +3560,7 @@ const commandMap = {
3500
3560
  'FindWidget.handleResizerPointerDown': wrapCommand(handleResizerPointerDown),
3501
3561
  'FindWidget.handleResizerPointerMove': wrapCommand(handleResizerPointerMove),
3502
3562
  'FindWidget.handleResizerPointerUp': wrapCommand(handleResizerPointerUp),
3563
+ 'FindWidget.handleSettingsChanged': wrapCommand(handleSettingsChanged),
3503
3564
  'FindWidget.handleToggleReplaceFocus': wrapCommand(handleToggleReplaceFocus),
3504
3565
  'FindWidget.loadContent': wrapCommand(loadContent),
3505
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.2",
3
+ "version": "3.17.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",