@anlijiu/markmap 1.0.1 → 1.0.2

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.
package/dist/markmap.js CHANGED
@@ -7232,7 +7232,7 @@ a {
7232
7232
  }
7233
7233
  __name(_unsupportedIterableToArray, "_unsupportedIterableToArray");
7234
7234
  var _window = typeof window === "undefined" ? null : window;
7235
- var navigator = _window ? _window.navigator : null;
7235
+ var navigator2 = _window ? _window.navigator : null;
7236
7236
  _window ? _window.document : null;
7237
7237
  var typeofstr = _typeof("");
7238
7238
  var typeofobj = _typeof({});
@@ -7310,7 +7310,7 @@ a {
7310
7310
  return object(obj) && fn$6(obj.then);
7311
7311
  }, "promise");
7312
7312
  var ms = /* @__PURE__ */ __name(function ms2() {
7313
- return navigator && navigator.userAgent.match(/msie|trident|edge/i);
7313
+ return navigator2 && navigator2.userAgent.match(/msie|trident|edge/i);
7314
7314
  }, "ms");
7315
7315
  var memoize = /* @__PURE__ */ __name(function memoize2(fn3, keyFn) {
7316
7316
  if (!keyFn) {
@@ -39483,6 +39483,3757 @@ a {
39483
39483
  };
39484
39484
  }, "updateLows");
39485
39485
 
39486
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/generated/bidi-data.js
39487
+ var latin1BidiTypes = [
39488
+ "BN",
39489
+ "BN",
39490
+ "BN",
39491
+ "BN",
39492
+ "BN",
39493
+ "BN",
39494
+ "BN",
39495
+ "BN",
39496
+ "BN",
39497
+ "S",
39498
+ "B",
39499
+ "S",
39500
+ "WS",
39501
+ "B",
39502
+ "BN",
39503
+ "BN",
39504
+ "BN",
39505
+ "BN",
39506
+ "BN",
39507
+ "BN",
39508
+ "BN",
39509
+ "BN",
39510
+ "BN",
39511
+ "BN",
39512
+ "BN",
39513
+ "BN",
39514
+ "BN",
39515
+ "BN",
39516
+ "B",
39517
+ "B",
39518
+ "B",
39519
+ "S",
39520
+ "WS",
39521
+ "ON",
39522
+ "ON",
39523
+ "ET",
39524
+ "ET",
39525
+ "ET",
39526
+ "ON",
39527
+ "ON",
39528
+ "ON",
39529
+ "ON",
39530
+ "ON",
39531
+ "ES",
39532
+ "CS",
39533
+ "ES",
39534
+ "CS",
39535
+ "CS",
39536
+ "EN",
39537
+ "EN",
39538
+ "EN",
39539
+ "EN",
39540
+ "EN",
39541
+ "EN",
39542
+ "EN",
39543
+ "EN",
39544
+ "EN",
39545
+ "EN",
39546
+ "CS",
39547
+ "ON",
39548
+ "ON",
39549
+ "ON",
39550
+ "ON",
39551
+ "ON",
39552
+ "ON",
39553
+ "L",
39554
+ "L",
39555
+ "L",
39556
+ "L",
39557
+ "L",
39558
+ "L",
39559
+ "L",
39560
+ "L",
39561
+ "L",
39562
+ "L",
39563
+ "L",
39564
+ "L",
39565
+ "L",
39566
+ "L",
39567
+ "L",
39568
+ "L",
39569
+ "L",
39570
+ "L",
39571
+ "L",
39572
+ "L",
39573
+ "L",
39574
+ "L",
39575
+ "L",
39576
+ "L",
39577
+ "L",
39578
+ "L",
39579
+ "ON",
39580
+ "ON",
39581
+ "ON",
39582
+ "ON",
39583
+ "ON",
39584
+ "ON",
39585
+ "L",
39586
+ "L",
39587
+ "L",
39588
+ "L",
39589
+ "L",
39590
+ "L",
39591
+ "L",
39592
+ "L",
39593
+ "L",
39594
+ "L",
39595
+ "L",
39596
+ "L",
39597
+ "L",
39598
+ "L",
39599
+ "L",
39600
+ "L",
39601
+ "L",
39602
+ "L",
39603
+ "L",
39604
+ "L",
39605
+ "L",
39606
+ "L",
39607
+ "L",
39608
+ "L",
39609
+ "L",
39610
+ "L",
39611
+ "ON",
39612
+ "ON",
39613
+ "ON",
39614
+ "ON",
39615
+ "BN",
39616
+ "BN",
39617
+ "BN",
39618
+ "BN",
39619
+ "BN",
39620
+ "BN",
39621
+ "B",
39622
+ "BN",
39623
+ "BN",
39624
+ "BN",
39625
+ "BN",
39626
+ "BN",
39627
+ "BN",
39628
+ "BN",
39629
+ "BN",
39630
+ "BN",
39631
+ "BN",
39632
+ "BN",
39633
+ "BN",
39634
+ "BN",
39635
+ "BN",
39636
+ "BN",
39637
+ "BN",
39638
+ "BN",
39639
+ "BN",
39640
+ "BN",
39641
+ "BN",
39642
+ "BN",
39643
+ "BN",
39644
+ "BN",
39645
+ "BN",
39646
+ "BN",
39647
+ "BN",
39648
+ "CS",
39649
+ "ON",
39650
+ "ET",
39651
+ "ET",
39652
+ "ET",
39653
+ "ET",
39654
+ "ON",
39655
+ "ON",
39656
+ "ON",
39657
+ "ON",
39658
+ "L",
39659
+ "ON",
39660
+ "ON",
39661
+ "BN",
39662
+ "ON",
39663
+ "ON",
39664
+ "ET",
39665
+ "ET",
39666
+ "EN",
39667
+ "EN",
39668
+ "ON",
39669
+ "L",
39670
+ "ON",
39671
+ "ON",
39672
+ "ON",
39673
+ "EN",
39674
+ "L",
39675
+ "ON",
39676
+ "ON",
39677
+ "ON",
39678
+ "ON",
39679
+ "ON",
39680
+ "L",
39681
+ "L",
39682
+ "L",
39683
+ "L",
39684
+ "L",
39685
+ "L",
39686
+ "L",
39687
+ "L",
39688
+ "L",
39689
+ "L",
39690
+ "L",
39691
+ "L",
39692
+ "L",
39693
+ "L",
39694
+ "L",
39695
+ "L",
39696
+ "L",
39697
+ "L",
39698
+ "L",
39699
+ "L",
39700
+ "L",
39701
+ "L",
39702
+ "L",
39703
+ "ON",
39704
+ "L",
39705
+ "L",
39706
+ "L",
39707
+ "L",
39708
+ "L",
39709
+ "L",
39710
+ "L",
39711
+ "L",
39712
+ "L",
39713
+ "L",
39714
+ "L",
39715
+ "L",
39716
+ "L",
39717
+ "L",
39718
+ "L",
39719
+ "L",
39720
+ "L",
39721
+ "L",
39722
+ "L",
39723
+ "L",
39724
+ "L",
39725
+ "L",
39726
+ "L",
39727
+ "L",
39728
+ "L",
39729
+ "L",
39730
+ "L",
39731
+ "L",
39732
+ "L",
39733
+ "L",
39734
+ "L",
39735
+ "ON",
39736
+ "L",
39737
+ "L",
39738
+ "L",
39739
+ "L",
39740
+ "L",
39741
+ "L",
39742
+ "L",
39743
+ "L"
39744
+ ];
39745
+ var nonLatin1BidiRanges = [
39746
+ [697, 698, "ON"],
39747
+ [706, 719, "ON"],
39748
+ [722, 735, "ON"],
39749
+ [741, 749, "ON"],
39750
+ [751, 767, "ON"],
39751
+ [768, 879, "NSM"],
39752
+ [884, 885, "ON"],
39753
+ [894, 894, "ON"],
39754
+ [900, 901, "ON"],
39755
+ [903, 903, "ON"],
39756
+ [1014, 1014, "ON"],
39757
+ [1155, 1161, "NSM"],
39758
+ [1418, 1418, "ON"],
39759
+ [1421, 1422, "ON"],
39760
+ [1423, 1423, "ET"],
39761
+ [1424, 1424, "R"],
39762
+ [1425, 1469, "NSM"],
39763
+ [1470, 1470, "R"],
39764
+ [1471, 1471, "NSM"],
39765
+ [1472, 1472, "R"],
39766
+ [1473, 1474, "NSM"],
39767
+ [1475, 1475, "R"],
39768
+ [1476, 1477, "NSM"],
39769
+ [1478, 1478, "R"],
39770
+ [1479, 1479, "NSM"],
39771
+ [1480, 1535, "R"],
39772
+ [1536, 1541, "AN"],
39773
+ [1542, 1543, "ON"],
39774
+ [1544, 1544, "AL"],
39775
+ [1545, 1546, "ET"],
39776
+ [1547, 1547, "AL"],
39777
+ [1548, 1548, "CS"],
39778
+ [1549, 1549, "AL"],
39779
+ [1550, 1551, "ON"],
39780
+ [1552, 1562, "NSM"],
39781
+ [1563, 1610, "AL"],
39782
+ [1611, 1631, "NSM"],
39783
+ [1632, 1641, "AN"],
39784
+ [1642, 1642, "ET"],
39785
+ [1643, 1644, "AN"],
39786
+ [1645, 1647, "AL"],
39787
+ [1648, 1648, "NSM"],
39788
+ [1649, 1749, "AL"],
39789
+ [1750, 1756, "NSM"],
39790
+ [1757, 1757, "AN"],
39791
+ [1758, 1758, "ON"],
39792
+ [1759, 1764, "NSM"],
39793
+ [1765, 1766, "AL"],
39794
+ [1767, 1768, "NSM"],
39795
+ [1769, 1769, "ON"],
39796
+ [1770, 1773, "NSM"],
39797
+ [1774, 1775, "AL"],
39798
+ [1776, 1785, "EN"],
39799
+ [1786, 1808, "AL"],
39800
+ [1809, 1809, "NSM"],
39801
+ [1810, 1839, "AL"],
39802
+ [1840, 1866, "NSM"],
39803
+ [1867, 1957, "AL"],
39804
+ [1958, 1968, "NSM"],
39805
+ [1969, 1983, "AL"],
39806
+ [1984, 2026, "R"],
39807
+ [2027, 2035, "NSM"],
39808
+ [2036, 2037, "R"],
39809
+ [2038, 2041, "ON"],
39810
+ [2042, 2044, "R"],
39811
+ [2045, 2045, "NSM"],
39812
+ [2046, 2069, "R"],
39813
+ [2070, 2073, "NSM"],
39814
+ [2074, 2074, "R"],
39815
+ [2075, 2083, "NSM"],
39816
+ [2084, 2084, "R"],
39817
+ [2085, 2087, "NSM"],
39818
+ [2088, 2088, "R"],
39819
+ [2089, 2093, "NSM"],
39820
+ [2094, 2136, "R"],
39821
+ [2137, 2139, "NSM"],
39822
+ [2140, 2143, "R"],
39823
+ [2144, 2191, "AL"],
39824
+ [2192, 2193, "AN"],
39825
+ [2194, 2198, "AL"],
39826
+ [2199, 2207, "NSM"],
39827
+ [2208, 2249, "AL"],
39828
+ [2250, 2273, "NSM"],
39829
+ [2274, 2274, "AN"],
39830
+ [2275, 2306, "NSM"],
39831
+ [2362, 2362, "NSM"],
39832
+ [2364, 2364, "NSM"],
39833
+ [2369, 2376, "NSM"],
39834
+ [2381, 2381, "NSM"],
39835
+ [2385, 2391, "NSM"],
39836
+ [2402, 2403, "NSM"],
39837
+ [2433, 2433, "NSM"],
39838
+ [2492, 2492, "NSM"],
39839
+ [2497, 2500, "NSM"],
39840
+ [2509, 2509, "NSM"],
39841
+ [2530, 2531, "NSM"],
39842
+ [2546, 2547, "ET"],
39843
+ [2555, 2555, "ET"],
39844
+ [2558, 2558, "NSM"],
39845
+ [2561, 2562, "NSM"],
39846
+ [2620, 2620, "NSM"],
39847
+ [2625, 2626, "NSM"],
39848
+ [2631, 2632, "NSM"],
39849
+ [2635, 2637, "NSM"],
39850
+ [2641, 2641, "NSM"],
39851
+ [2672, 2673, "NSM"],
39852
+ [2677, 2677, "NSM"],
39853
+ [2689, 2690, "NSM"],
39854
+ [2748, 2748, "NSM"],
39855
+ [2753, 2757, "NSM"],
39856
+ [2759, 2760, "NSM"],
39857
+ [2765, 2765, "NSM"],
39858
+ [2786, 2787, "NSM"],
39859
+ [2801, 2801, "ET"],
39860
+ [2810, 2815, "NSM"],
39861
+ [2817, 2817, "NSM"],
39862
+ [2876, 2876, "NSM"],
39863
+ [2879, 2879, "NSM"],
39864
+ [2881, 2884, "NSM"],
39865
+ [2893, 2893, "NSM"],
39866
+ [2901, 2902, "NSM"],
39867
+ [2914, 2915, "NSM"],
39868
+ [2946, 2946, "NSM"],
39869
+ [3008, 3008, "NSM"],
39870
+ [3021, 3021, "NSM"],
39871
+ [3059, 3064, "ON"],
39872
+ [3065, 3065, "ET"],
39873
+ [3066, 3066, "ON"],
39874
+ [3072, 3072, "NSM"],
39875
+ [3076, 3076, "NSM"],
39876
+ [3132, 3132, "NSM"],
39877
+ [3134, 3136, "NSM"],
39878
+ [3142, 3144, "NSM"],
39879
+ [3146, 3149, "NSM"],
39880
+ [3157, 3158, "NSM"],
39881
+ [3170, 3171, "NSM"],
39882
+ [3192, 3198, "ON"],
39883
+ [3201, 3201, "NSM"],
39884
+ [3260, 3260, "NSM"],
39885
+ [3276, 3277, "NSM"],
39886
+ [3298, 3299, "NSM"],
39887
+ [3328, 3329, "NSM"],
39888
+ [3387, 3388, "NSM"],
39889
+ [3393, 3396, "NSM"],
39890
+ [3405, 3405, "NSM"],
39891
+ [3426, 3427, "NSM"],
39892
+ [3457, 3457, "NSM"],
39893
+ [3530, 3530, "NSM"],
39894
+ [3538, 3540, "NSM"],
39895
+ [3542, 3542, "NSM"],
39896
+ [3633, 3633, "NSM"],
39897
+ [3636, 3642, "NSM"],
39898
+ [3647, 3647, "ET"],
39899
+ [3655, 3662, "NSM"],
39900
+ [3761, 3761, "NSM"],
39901
+ [3764, 3772, "NSM"],
39902
+ [3784, 3790, "NSM"],
39903
+ [3864, 3865, "NSM"],
39904
+ [3893, 3893, "NSM"],
39905
+ [3895, 3895, "NSM"],
39906
+ [3897, 3897, "NSM"],
39907
+ [3898, 3901, "ON"],
39908
+ [3953, 3966, "NSM"],
39909
+ [3968, 3972, "NSM"],
39910
+ [3974, 3975, "NSM"],
39911
+ [3981, 3991, "NSM"],
39912
+ [3993, 4028, "NSM"],
39913
+ [4038, 4038, "NSM"],
39914
+ [4141, 4144, "NSM"],
39915
+ [4146, 4151, "NSM"],
39916
+ [4153, 4154, "NSM"],
39917
+ [4157, 4158, "NSM"],
39918
+ [4184, 4185, "NSM"],
39919
+ [4190, 4192, "NSM"],
39920
+ [4209, 4212, "NSM"],
39921
+ [4226, 4226, "NSM"],
39922
+ [4229, 4230, "NSM"],
39923
+ [4237, 4237, "NSM"],
39924
+ [4253, 4253, "NSM"],
39925
+ [4957, 4959, "NSM"],
39926
+ [5008, 5017, "ON"],
39927
+ [5120, 5120, "ON"],
39928
+ [5760, 5760, "WS"],
39929
+ [5787, 5788, "ON"],
39930
+ [5906, 5908, "NSM"],
39931
+ [5938, 5939, "NSM"],
39932
+ [5970, 5971, "NSM"],
39933
+ [6002, 6003, "NSM"],
39934
+ [6068, 6069, "NSM"],
39935
+ [6071, 6077, "NSM"],
39936
+ [6086, 6086, "NSM"],
39937
+ [6089, 6099, "NSM"],
39938
+ [6107, 6107, "ET"],
39939
+ [6109, 6109, "NSM"],
39940
+ [6128, 6137, "ON"],
39941
+ [6144, 6154, "ON"],
39942
+ [6155, 6157, "NSM"],
39943
+ [6158, 6158, "BN"],
39944
+ [6159, 6159, "NSM"],
39945
+ [6277, 6278, "NSM"],
39946
+ [6313, 6313, "NSM"],
39947
+ [6432, 6434, "NSM"],
39948
+ [6439, 6440, "NSM"],
39949
+ [6450, 6450, "NSM"],
39950
+ [6457, 6459, "NSM"],
39951
+ [6464, 6464, "ON"],
39952
+ [6468, 6469, "ON"],
39953
+ [6622, 6655, "ON"],
39954
+ [6679, 6680, "NSM"],
39955
+ [6683, 6683, "NSM"],
39956
+ [6742, 6742, "NSM"],
39957
+ [6744, 6750, "NSM"],
39958
+ [6752, 6752, "NSM"],
39959
+ [6754, 6754, "NSM"],
39960
+ [6757, 6764, "NSM"],
39961
+ [6771, 6780, "NSM"],
39962
+ [6783, 6783, "NSM"],
39963
+ [6832, 6877, "NSM"],
39964
+ [6880, 6891, "NSM"],
39965
+ [6912, 6915, "NSM"],
39966
+ [6964, 6964, "NSM"],
39967
+ [6966, 6970, "NSM"],
39968
+ [6972, 6972, "NSM"],
39969
+ [6978, 6978, "NSM"],
39970
+ [7019, 7027, "NSM"],
39971
+ [7040, 7041, "NSM"],
39972
+ [7074, 7077, "NSM"],
39973
+ [7080, 7081, "NSM"],
39974
+ [7083, 7085, "NSM"],
39975
+ [7142, 7142, "NSM"],
39976
+ [7144, 7145, "NSM"],
39977
+ [7149, 7149, "NSM"],
39978
+ [7151, 7153, "NSM"],
39979
+ [7212, 7219, "NSM"],
39980
+ [7222, 7223, "NSM"],
39981
+ [7376, 7378, "NSM"],
39982
+ [7380, 7392, "NSM"],
39983
+ [7394, 7400, "NSM"],
39984
+ [7405, 7405, "NSM"],
39985
+ [7412, 7412, "NSM"],
39986
+ [7416, 7417, "NSM"],
39987
+ [7616, 7679, "NSM"],
39988
+ [8125, 8125, "ON"],
39989
+ [8127, 8129, "ON"],
39990
+ [8141, 8143, "ON"],
39991
+ [8157, 8159, "ON"],
39992
+ [8173, 8175, "ON"],
39993
+ [8189, 8190, "ON"],
39994
+ [8192, 8202, "WS"],
39995
+ [8203, 8205, "BN"],
39996
+ [8207, 8207, "R"],
39997
+ [8208, 8231, "ON"],
39998
+ [8232, 8232, "WS"],
39999
+ [8233, 8233, "B"],
40000
+ [8234, 8238, "BN"],
40001
+ [8239, 8239, "CS"],
40002
+ [8240, 8244, "ET"],
40003
+ [8245, 8259, "ON"],
40004
+ [8260, 8260, "CS"],
40005
+ [8261, 8286, "ON"],
40006
+ [8287, 8287, "WS"],
40007
+ [8288, 8303, "BN"],
40008
+ [8304, 8304, "EN"],
40009
+ [8308, 8313, "EN"],
40010
+ [8314, 8315, "ES"],
40011
+ [8316, 8318, "ON"],
40012
+ [8320, 8329, "EN"],
40013
+ [8330, 8331, "ES"],
40014
+ [8332, 8334, "ON"],
40015
+ [8352, 8399, "ET"],
40016
+ [8400, 8432, "NSM"],
40017
+ [8448, 8449, "ON"],
40018
+ [8451, 8454, "ON"],
40019
+ [8456, 8457, "ON"],
40020
+ [8468, 8468, "ON"],
40021
+ [8470, 8472, "ON"],
40022
+ [8478, 8483, "ON"],
40023
+ [8485, 8485, "ON"],
40024
+ [8487, 8487, "ON"],
40025
+ [8489, 8489, "ON"],
40026
+ [8494, 8494, "ET"],
40027
+ [8506, 8507, "ON"],
40028
+ [8512, 8516, "ON"],
40029
+ [8522, 8525, "ON"],
40030
+ [8528, 8543, "ON"],
40031
+ [8585, 8587, "ON"],
40032
+ [8592, 8721, "ON"],
40033
+ [8722, 8722, "ES"],
40034
+ [8723, 8723, "ET"],
40035
+ [8724, 9013, "ON"],
40036
+ [9083, 9108, "ON"],
40037
+ [9110, 9257, "ON"],
40038
+ [9280, 9290, "ON"],
40039
+ [9312, 9351, "ON"],
40040
+ [9352, 9371, "EN"],
40041
+ [9450, 9899, "ON"],
40042
+ [9901, 10239, "ON"],
40043
+ [10496, 11123, "ON"],
40044
+ [11126, 11263, "ON"],
40045
+ [11493, 11498, "ON"],
40046
+ [11503, 11505, "NSM"],
40047
+ [11513, 11519, "ON"],
40048
+ [11647, 11647, "NSM"],
40049
+ [11744, 11775, "NSM"],
40050
+ [11776, 11869, "ON"],
40051
+ [11904, 11929, "ON"],
40052
+ [11931, 12019, "ON"],
40053
+ [12032, 12245, "ON"],
40054
+ [12272, 12287, "ON"],
40055
+ [12288, 12288, "WS"],
40056
+ [12289, 12292, "ON"],
40057
+ [12296, 12320, "ON"],
40058
+ [12330, 12333, "NSM"],
40059
+ [12336, 12336, "ON"],
40060
+ [12342, 12343, "ON"],
40061
+ [12349, 12351, "ON"],
40062
+ [12441, 12442, "NSM"],
40063
+ [12443, 12444, "ON"],
40064
+ [12448, 12448, "ON"],
40065
+ [12539, 12539, "ON"],
40066
+ [12736, 12773, "ON"],
40067
+ [12783, 12783, "ON"],
40068
+ [12829, 12830, "ON"],
40069
+ [12880, 12895, "ON"],
40070
+ [12924, 12926, "ON"],
40071
+ [12977, 12991, "ON"],
40072
+ [13004, 13007, "ON"],
40073
+ [13175, 13178, "ON"],
40074
+ [13278, 13279, "ON"],
40075
+ [13311, 13311, "ON"],
40076
+ [19904, 19967, "ON"],
40077
+ [42128, 42182, "ON"],
40078
+ [42509, 42511, "ON"],
40079
+ [42607, 42610, "NSM"],
40080
+ [42611, 42611, "ON"],
40081
+ [42612, 42621, "NSM"],
40082
+ [42622, 42623, "ON"],
40083
+ [42654, 42655, "NSM"],
40084
+ [42736, 42737, "NSM"],
40085
+ [42752, 42785, "ON"],
40086
+ [42888, 42888, "ON"],
40087
+ [43010, 43010, "NSM"],
40088
+ [43014, 43014, "NSM"],
40089
+ [43019, 43019, "NSM"],
40090
+ [43045, 43046, "NSM"],
40091
+ [43048, 43051, "ON"],
40092
+ [43052, 43052, "NSM"],
40093
+ [43064, 43065, "ET"],
40094
+ [43124, 43127, "ON"],
40095
+ [43204, 43205, "NSM"],
40096
+ [43232, 43249, "NSM"],
40097
+ [43263, 43263, "NSM"],
40098
+ [43302, 43309, "NSM"],
40099
+ [43335, 43345, "NSM"],
40100
+ [43392, 43394, "NSM"],
40101
+ [43443, 43443, "NSM"],
40102
+ [43446, 43449, "NSM"],
40103
+ [43452, 43453, "NSM"],
40104
+ [43493, 43493, "NSM"],
40105
+ [43561, 43566, "NSM"],
40106
+ [43569, 43570, "NSM"],
40107
+ [43573, 43574, "NSM"],
40108
+ [43587, 43587, "NSM"],
40109
+ [43596, 43596, "NSM"],
40110
+ [43644, 43644, "NSM"],
40111
+ [43696, 43696, "NSM"],
40112
+ [43698, 43700, "NSM"],
40113
+ [43703, 43704, "NSM"],
40114
+ [43710, 43711, "NSM"],
40115
+ [43713, 43713, "NSM"],
40116
+ [43756, 43757, "NSM"],
40117
+ [43766, 43766, "NSM"],
40118
+ [43882, 43883, "ON"],
40119
+ [44005, 44005, "NSM"],
40120
+ [44008, 44008, "NSM"],
40121
+ [44013, 44013, "NSM"],
40122
+ [64285, 64285, "R"],
40123
+ [64286, 64286, "NSM"],
40124
+ [64287, 64296, "R"],
40125
+ [64297, 64297, "ES"],
40126
+ [64298, 64335, "R"],
40127
+ [64336, 64450, "AL"],
40128
+ [64451, 64466, "ON"],
40129
+ [64467, 64829, "AL"],
40130
+ [64830, 64847, "ON"],
40131
+ [64848, 64911, "AL"],
40132
+ [64912, 64913, "ON"],
40133
+ [64914, 64967, "AL"],
40134
+ [64968, 64975, "ON"],
40135
+ [64976, 65007, "BN"],
40136
+ [65008, 65020, "AL"],
40137
+ [65021, 65023, "ON"],
40138
+ [65024, 65039, "NSM"],
40139
+ [65040, 65049, "ON"],
40140
+ [65056, 65071, "NSM"],
40141
+ [65072, 65103, "ON"],
40142
+ [65104, 65104, "CS"],
40143
+ [65105, 65105, "ON"],
40144
+ [65106, 65106, "CS"],
40145
+ [65108, 65108, "ON"],
40146
+ [65109, 65109, "CS"],
40147
+ [65110, 65118, "ON"],
40148
+ [65119, 65119, "ET"],
40149
+ [65120, 65121, "ON"],
40150
+ [65122, 65123, "ES"],
40151
+ [65124, 65126, "ON"],
40152
+ [65128, 65128, "ON"],
40153
+ [65129, 65130, "ET"],
40154
+ [65131, 65131, "ON"],
40155
+ [65136, 65278, "AL"],
40156
+ [65279, 65279, "BN"],
40157
+ [65281, 65282, "ON"],
40158
+ [65283, 65285, "ET"],
40159
+ [65286, 65290, "ON"],
40160
+ [65291, 65291, "ES"],
40161
+ [65292, 65292, "CS"],
40162
+ [65293, 65293, "ES"],
40163
+ [65294, 65295, "CS"],
40164
+ [65296, 65305, "EN"],
40165
+ [65306, 65306, "CS"],
40166
+ [65307, 65312, "ON"],
40167
+ [65339, 65344, "ON"],
40168
+ [65371, 65381, "ON"],
40169
+ [65504, 65505, "ET"],
40170
+ [65506, 65508, "ON"],
40171
+ [65509, 65510, "ET"],
40172
+ [65512, 65518, "ON"],
40173
+ [65520, 65528, "BN"],
40174
+ [65529, 65533, "ON"],
40175
+ [65534, 65535, "BN"],
40176
+ [65793, 65793, "ON"],
40177
+ [65856, 65932, "ON"],
40178
+ [65936, 65948, "ON"],
40179
+ [65952, 65952, "ON"],
40180
+ [66045, 66045, "NSM"],
40181
+ [66272, 66272, "NSM"],
40182
+ [66273, 66299, "EN"],
40183
+ [66422, 66426, "NSM"],
40184
+ [67584, 67870, "R"],
40185
+ [67871, 67871, "ON"],
40186
+ [67872, 68096, "R"],
40187
+ [68097, 68099, "NSM"],
40188
+ [68100, 68100, "R"],
40189
+ [68101, 68102, "NSM"],
40190
+ [68103, 68107, "R"],
40191
+ [68108, 68111, "NSM"],
40192
+ [68112, 68151, "R"],
40193
+ [68152, 68154, "NSM"],
40194
+ [68155, 68158, "R"],
40195
+ [68159, 68159, "NSM"],
40196
+ [68160, 68324, "R"],
40197
+ [68325, 68326, "NSM"],
40198
+ [68327, 68408, "R"],
40199
+ [68409, 68415, "ON"],
40200
+ [68416, 68863, "R"],
40201
+ [68864, 68899, "AL"],
40202
+ [68900, 68903, "NSM"],
40203
+ [68904, 68911, "AL"],
40204
+ [68912, 68921, "AN"],
40205
+ [68922, 68927, "AL"],
40206
+ [68928, 68937, "AN"],
40207
+ [68938, 68968, "R"],
40208
+ [68969, 68973, "NSM"],
40209
+ [68974, 68974, "ON"],
40210
+ [68975, 69215, "R"],
40211
+ [69216, 69246, "AN"],
40212
+ [69247, 69290, "R"],
40213
+ [69291, 69292, "NSM"],
40214
+ [69293, 69311, "R"],
40215
+ [69312, 69327, "AL"],
40216
+ [69328, 69336, "ON"],
40217
+ [69337, 69369, "AL"],
40218
+ [69370, 69375, "NSM"],
40219
+ [69376, 69423, "R"],
40220
+ [69424, 69445, "AL"],
40221
+ [69446, 69456, "NSM"],
40222
+ [69457, 69487, "AL"],
40223
+ [69488, 69505, "R"],
40224
+ [69506, 69509, "NSM"],
40225
+ [69510, 69631, "R"],
40226
+ [69633, 69633, "NSM"],
40227
+ [69688, 69702, "NSM"],
40228
+ [69714, 69733, "ON"],
40229
+ [69744, 69744, "NSM"],
40230
+ [69747, 69748, "NSM"],
40231
+ [69759, 69761, "NSM"],
40232
+ [69811, 69814, "NSM"],
40233
+ [69817, 69818, "NSM"],
40234
+ [69826, 69826, "NSM"],
40235
+ [69888, 69890, "NSM"],
40236
+ [69927, 69931, "NSM"],
40237
+ [69933, 69940, "NSM"],
40238
+ [70003, 70003, "NSM"],
40239
+ [70016, 70017, "NSM"],
40240
+ [70070, 70078, "NSM"],
40241
+ [70089, 70092, "NSM"],
40242
+ [70095, 70095, "NSM"],
40243
+ [70191, 70193, "NSM"],
40244
+ [70196, 70196, "NSM"],
40245
+ [70198, 70199, "NSM"],
40246
+ [70206, 70206, "NSM"],
40247
+ [70209, 70209, "NSM"],
40248
+ [70367, 70367, "NSM"],
40249
+ [70371, 70378, "NSM"],
40250
+ [70400, 70401, "NSM"],
40251
+ [70459, 70460, "NSM"],
40252
+ [70464, 70464, "NSM"],
40253
+ [70502, 70508, "NSM"],
40254
+ [70512, 70516, "NSM"],
40255
+ [70587, 70592, "NSM"],
40256
+ [70606, 70606, "NSM"],
40257
+ [70608, 70608, "NSM"],
40258
+ [70610, 70610, "NSM"],
40259
+ [70625, 70626, "NSM"],
40260
+ [70712, 70719, "NSM"],
40261
+ [70722, 70724, "NSM"],
40262
+ [70726, 70726, "NSM"],
40263
+ [70750, 70750, "NSM"],
40264
+ [70835, 70840, "NSM"],
40265
+ [70842, 70842, "NSM"],
40266
+ [70847, 70848, "NSM"],
40267
+ [70850, 70851, "NSM"],
40268
+ [71090, 71093, "NSM"],
40269
+ [71100, 71101, "NSM"],
40270
+ [71103, 71104, "NSM"],
40271
+ [71132, 71133, "NSM"],
40272
+ [71219, 71226, "NSM"],
40273
+ [71229, 71229, "NSM"],
40274
+ [71231, 71232, "NSM"],
40275
+ [71264, 71276, "ON"],
40276
+ [71339, 71339, "NSM"],
40277
+ [71341, 71341, "NSM"],
40278
+ [71344, 71349, "NSM"],
40279
+ [71351, 71351, "NSM"],
40280
+ [71453, 71453, "NSM"],
40281
+ [71455, 71455, "NSM"],
40282
+ [71458, 71461, "NSM"],
40283
+ [71463, 71467, "NSM"],
40284
+ [71727, 71735, "NSM"],
40285
+ [71737, 71738, "NSM"],
40286
+ [71995, 71996, "NSM"],
40287
+ [71998, 71998, "NSM"],
40288
+ [72003, 72003, "NSM"],
40289
+ [72148, 72151, "NSM"],
40290
+ [72154, 72155, "NSM"],
40291
+ [72160, 72160, "NSM"],
40292
+ [72193, 72198, "NSM"],
40293
+ [72201, 72202, "NSM"],
40294
+ [72243, 72248, "NSM"],
40295
+ [72251, 72254, "NSM"],
40296
+ [72263, 72263, "NSM"],
40297
+ [72273, 72278, "NSM"],
40298
+ [72281, 72283, "NSM"],
40299
+ [72330, 72342, "NSM"],
40300
+ [72344, 72345, "NSM"],
40301
+ [72544, 72544, "NSM"],
40302
+ [72546, 72548, "NSM"],
40303
+ [72550, 72550, "NSM"],
40304
+ [72752, 72758, "NSM"],
40305
+ [72760, 72765, "NSM"],
40306
+ [72850, 72871, "NSM"],
40307
+ [72874, 72880, "NSM"],
40308
+ [72882, 72883, "NSM"],
40309
+ [72885, 72886, "NSM"],
40310
+ [73009, 73014, "NSM"],
40311
+ [73018, 73018, "NSM"],
40312
+ [73020, 73021, "NSM"],
40313
+ [73023, 73029, "NSM"],
40314
+ [73031, 73031, "NSM"],
40315
+ [73104, 73105, "NSM"],
40316
+ [73109, 73109, "NSM"],
40317
+ [73111, 73111, "NSM"],
40318
+ [73459, 73460, "NSM"],
40319
+ [73472, 73473, "NSM"],
40320
+ [73526, 73530, "NSM"],
40321
+ [73536, 73536, "NSM"],
40322
+ [73538, 73538, "NSM"],
40323
+ [73562, 73562, "NSM"],
40324
+ [73685, 73692, "ON"],
40325
+ [73693, 73696, "ET"],
40326
+ [73697, 73713, "ON"],
40327
+ [78912, 78912, "NSM"],
40328
+ [78919, 78933, "NSM"],
40329
+ [90398, 90409, "NSM"],
40330
+ [90413, 90415, "NSM"],
40331
+ [92912, 92916, "NSM"],
40332
+ [92976, 92982, "NSM"],
40333
+ [94031, 94031, "NSM"],
40334
+ [94095, 94098, "NSM"],
40335
+ [94178, 94178, "ON"],
40336
+ [94180, 94180, "NSM"],
40337
+ [113821, 113822, "NSM"],
40338
+ [113824, 113827, "BN"],
40339
+ [117760, 117973, "ON"],
40340
+ [118e3, 118009, "EN"],
40341
+ [118010, 118012, "ON"],
40342
+ [118016, 118451, "ON"],
40343
+ [118458, 118480, "ON"],
40344
+ [118496, 118512, "ON"],
40345
+ [118528, 118573, "NSM"],
40346
+ [118576, 118598, "NSM"],
40347
+ [119143, 119145, "NSM"],
40348
+ [119155, 119162, "BN"],
40349
+ [119163, 119170, "NSM"],
40350
+ [119173, 119179, "NSM"],
40351
+ [119210, 119213, "NSM"],
40352
+ [119273, 119274, "ON"],
40353
+ [119296, 119361, "ON"],
40354
+ [119362, 119364, "NSM"],
40355
+ [119365, 119365, "ON"],
40356
+ [119552, 119638, "ON"],
40357
+ [120513, 120513, "ON"],
40358
+ [120539, 120539, "ON"],
40359
+ [120571, 120571, "ON"],
40360
+ [120597, 120597, "ON"],
40361
+ [120629, 120629, "ON"],
40362
+ [120655, 120655, "ON"],
40363
+ [120687, 120687, "ON"],
40364
+ [120713, 120713, "ON"],
40365
+ [120745, 120745, "ON"],
40366
+ [120771, 120771, "ON"],
40367
+ [120782, 120831, "EN"],
40368
+ [121344, 121398, "NSM"],
40369
+ [121403, 121452, "NSM"],
40370
+ [121461, 121461, "NSM"],
40371
+ [121476, 121476, "NSM"],
40372
+ [121499, 121503, "NSM"],
40373
+ [121505, 121519, "NSM"],
40374
+ [122880, 122886, "NSM"],
40375
+ [122888, 122904, "NSM"],
40376
+ [122907, 122913, "NSM"],
40377
+ [122915, 122916, "NSM"],
40378
+ [122918, 122922, "NSM"],
40379
+ [123023, 123023, "NSM"],
40380
+ [123184, 123190, "NSM"],
40381
+ [123566, 123566, "NSM"],
40382
+ [123628, 123631, "NSM"],
40383
+ [123647, 123647, "ET"],
40384
+ [124140, 124143, "NSM"],
40385
+ [124398, 124399, "NSM"],
40386
+ [124643, 124643, "NSM"],
40387
+ [124646, 124646, "NSM"],
40388
+ [124654, 124655, "NSM"],
40389
+ [124661, 124661, "NSM"],
40390
+ [124928, 125135, "R"],
40391
+ [125136, 125142, "NSM"],
40392
+ [125143, 125251, "R"],
40393
+ [125252, 125258, "NSM"],
40394
+ [125259, 126063, "R"],
40395
+ [126064, 126143, "AL"],
40396
+ [126144, 126207, "R"],
40397
+ [126208, 126287, "AL"],
40398
+ [126288, 126463, "R"],
40399
+ [126464, 126703, "AL"],
40400
+ [126704, 126705, "ON"],
40401
+ [126706, 126719, "AL"],
40402
+ [126720, 126975, "R"],
40403
+ [126976, 127019, "ON"],
40404
+ [127024, 127123, "ON"],
40405
+ [127136, 127150, "ON"],
40406
+ [127153, 127167, "ON"],
40407
+ [127169, 127183, "ON"],
40408
+ [127185, 127221, "ON"],
40409
+ [127232, 127242, "EN"],
40410
+ [127243, 127247, "ON"],
40411
+ [127279, 127279, "ON"],
40412
+ [127338, 127343, "ON"],
40413
+ [127405, 127405, "ON"],
40414
+ [127584, 127589, "ON"],
40415
+ [127744, 128728, "ON"],
40416
+ [128732, 128748, "ON"],
40417
+ [128752, 128764, "ON"],
40418
+ [128768, 128985, "ON"],
40419
+ [128992, 129003, "ON"],
40420
+ [129008, 129008, "ON"],
40421
+ [129024, 129035, "ON"],
40422
+ [129040, 129095, "ON"],
40423
+ [129104, 129113, "ON"],
40424
+ [129120, 129159, "ON"],
40425
+ [129168, 129197, "ON"],
40426
+ [129200, 129211, "ON"],
40427
+ [129216, 129217, "ON"],
40428
+ [129232, 129240, "ON"],
40429
+ [129280, 129623, "ON"],
40430
+ [129632, 129645, "ON"],
40431
+ [129648, 129660, "ON"],
40432
+ [129664, 129674, "ON"],
40433
+ [129678, 129734, "ON"],
40434
+ [129736, 129736, "ON"],
40435
+ [129741, 129756, "ON"],
40436
+ [129759, 129770, "ON"],
40437
+ [129775, 129784, "ON"],
40438
+ [129792, 129938, "ON"],
40439
+ [129940, 130031, "ON"],
40440
+ [130032, 130041, "EN"],
40441
+ [130042, 130042, "ON"],
40442
+ [131070, 131071, "BN"],
40443
+ [196606, 196607, "BN"],
40444
+ [262142, 262143, "BN"],
40445
+ [327678, 327679, "BN"],
40446
+ [393214, 393215, "BN"],
40447
+ [458750, 458751, "BN"],
40448
+ [524286, 524287, "BN"],
40449
+ [589822, 589823, "BN"],
40450
+ [655358, 655359, "BN"],
40451
+ [720894, 720895, "BN"],
40452
+ [786430, 786431, "BN"],
40453
+ [851966, 851967, "BN"],
40454
+ [917502, 917759, "BN"],
40455
+ [917760, 917999, "NSM"],
40456
+ [918e3, 921599, "BN"],
40457
+ [983038, 983039, "BN"],
40458
+ [1048574, 1048575, "BN"],
40459
+ [1114110, 1114111, "BN"]
40460
+ ];
40461
+
40462
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/bidi.js
40463
+ function classifyCodePoint(codePoint) {
40464
+ if (codePoint <= 255)
40465
+ return latin1BidiTypes[codePoint];
40466
+ let lo = 0;
40467
+ let hi = nonLatin1BidiRanges.length - 1;
40468
+ while (lo <= hi) {
40469
+ const mid = lo + hi >> 1;
40470
+ const range = nonLatin1BidiRanges[mid];
40471
+ if (codePoint < range[0]) {
40472
+ hi = mid - 1;
40473
+ continue;
40474
+ }
40475
+ if (codePoint > range[1]) {
40476
+ lo = mid + 1;
40477
+ continue;
40478
+ }
40479
+ return range[2];
40480
+ }
40481
+ return "L";
40482
+ }
40483
+ __name(classifyCodePoint, "classifyCodePoint");
40484
+ function computeBidiLevels(str) {
40485
+ const len = str.length;
40486
+ if (len === 0)
40487
+ return null;
40488
+ const types = new Array(len);
40489
+ let sawBidi = false;
40490
+ for (let i = 0; i < len; ) {
40491
+ const first2 = str.charCodeAt(i);
40492
+ let codePoint = first2;
40493
+ let codeUnitLength = 1;
40494
+ if (first2 >= 55296 && first2 <= 56319 && i + 1 < len) {
40495
+ const second = str.charCodeAt(i + 1);
40496
+ if (second >= 56320 && second <= 57343) {
40497
+ codePoint = (first2 - 55296 << 10) + (second - 56320) + 65536;
40498
+ codeUnitLength = 2;
40499
+ }
40500
+ }
40501
+ const t2 = classifyCodePoint(codePoint);
40502
+ if (t2 === "R" || t2 === "AL" || t2 === "AN")
40503
+ sawBidi = true;
40504
+ for (let j = 0; j < codeUnitLength; j++) {
40505
+ types[i + j] = t2;
40506
+ }
40507
+ i += codeUnitLength;
40508
+ }
40509
+ if (!sawBidi)
40510
+ return null;
40511
+ let startLevel = 0;
40512
+ for (let i = 0; i < len; i++) {
40513
+ const t2 = types[i];
40514
+ if (t2 === "L") {
40515
+ startLevel = 0;
40516
+ break;
40517
+ }
40518
+ if (t2 === "R" || t2 === "AL") {
40519
+ startLevel = 1;
40520
+ break;
40521
+ }
40522
+ }
40523
+ const levels = new Int8Array(len);
40524
+ for (let i = 0; i < len; i++)
40525
+ levels[i] = startLevel;
40526
+ const e = startLevel & 1 ? "R" : "L";
40527
+ const sor = e;
40528
+ let lastType = sor;
40529
+ for (let i = 0; i < len; i++) {
40530
+ if (types[i] === "NSM")
40531
+ types[i] = lastType;
40532
+ else
40533
+ lastType = types[i];
40534
+ }
40535
+ lastType = sor;
40536
+ for (let i = 0; i < len; i++) {
40537
+ const t2 = types[i];
40538
+ if (t2 === "EN")
40539
+ types[i] = lastType === "AL" ? "AN" : "EN";
40540
+ else if (t2 === "R" || t2 === "L" || t2 === "AL")
40541
+ lastType = t2;
40542
+ }
40543
+ for (let i = 0; i < len; i++) {
40544
+ if (types[i] === "AL")
40545
+ types[i] = "R";
40546
+ }
40547
+ for (let i = 1; i < len - 1; i++) {
40548
+ if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
40549
+ types[i] = "EN";
40550
+ }
40551
+ if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
40552
+ types[i] = types[i - 1];
40553
+ }
40554
+ }
40555
+ for (let i = 0; i < len; i++) {
40556
+ if (types[i] !== "EN")
40557
+ continue;
40558
+ let j;
40559
+ for (j = i - 1; j >= 0 && types[j] === "ET"; j--)
40560
+ types[j] = "EN";
40561
+ for (j = i + 1; j < len && types[j] === "ET"; j++)
40562
+ types[j] = "EN";
40563
+ }
40564
+ for (let i = 0; i < len; i++) {
40565
+ const t2 = types[i];
40566
+ if (t2 === "WS" || t2 === "ES" || t2 === "ET" || t2 === "CS")
40567
+ types[i] = "ON";
40568
+ }
40569
+ lastType = sor;
40570
+ for (let i = 0; i < len; i++) {
40571
+ const t2 = types[i];
40572
+ if (t2 === "EN")
40573
+ types[i] = lastType === "L" ? "L" : "EN";
40574
+ else if (t2 === "R" || t2 === "L")
40575
+ lastType = t2;
40576
+ }
40577
+ for (let i = 0; i < len; i++) {
40578
+ if (types[i] !== "ON")
40579
+ continue;
40580
+ let end = i + 1;
40581
+ while (end < len && types[end] === "ON")
40582
+ end++;
40583
+ const before = i > 0 ? types[i - 1] : sor;
40584
+ const after = end < len ? types[end] : sor;
40585
+ const bDir = before !== "L" ? "R" : "L";
40586
+ const aDir = after !== "L" ? "R" : "L";
40587
+ if (bDir === aDir) {
40588
+ for (let j = i; j < end; j++)
40589
+ types[j] = bDir;
40590
+ }
40591
+ i = end - 1;
40592
+ }
40593
+ for (let i = 0; i < len; i++) {
40594
+ if (types[i] === "ON")
40595
+ types[i] = e;
40596
+ }
40597
+ for (let i = 0; i < len; i++) {
40598
+ const t2 = types[i];
40599
+ if ((levels[i] & 1) === 0) {
40600
+ if (t2 === "R")
40601
+ levels[i]++;
40602
+ else if (t2 === "AN" || t2 === "EN")
40603
+ levels[i] += 2;
40604
+ } else if (t2 === "L" || t2 === "AN" || t2 === "EN") {
40605
+ levels[i]++;
40606
+ }
40607
+ }
40608
+ return levels;
40609
+ }
40610
+ __name(computeBidiLevels, "computeBidiLevels");
40611
+ function computeSegmentLevels(normalized, segStarts) {
40612
+ const bidiLevels = computeBidiLevels(normalized);
40613
+ if (bidiLevels === null)
40614
+ return null;
40615
+ const segLevels = new Int8Array(segStarts.length);
40616
+ for (let i = 0; i < segStarts.length; i++) {
40617
+ segLevels[i] = bidiLevels[segStarts[i]];
40618
+ }
40619
+ return segLevels;
40620
+ }
40621
+ __name(computeSegmentLevels, "computeSegmentLevels");
40622
+
40623
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/analysis.js
40624
+ var collapsibleWhitespaceRunRe = /[ \t\n\r\f]+/g;
40625
+ var needsWhitespaceNormalizationRe = /[\t\n\r\f]| {2,}|^ | $/;
40626
+ function getWhiteSpaceProfile(whiteSpace) {
40627
+ const mode = whiteSpace ?? "normal";
40628
+ return mode === "pre-wrap" ? { mode, preserveOrdinarySpaces: true, preserveHardBreaks: true } : { mode, preserveOrdinarySpaces: false, preserveHardBreaks: false };
40629
+ }
40630
+ __name(getWhiteSpaceProfile, "getWhiteSpaceProfile");
40631
+ function normalizeWhitespaceNormal(text2) {
40632
+ if (!needsWhitespaceNormalizationRe.test(text2))
40633
+ return text2;
40634
+ let normalized = text2.replace(collapsibleWhitespaceRunRe, " ");
40635
+ if (normalized.charCodeAt(0) === 32) {
40636
+ normalized = normalized.slice(1);
40637
+ }
40638
+ if (normalized.length > 0 && normalized.charCodeAt(normalized.length - 1) === 32) {
40639
+ normalized = normalized.slice(0, -1);
40640
+ }
40641
+ return normalized;
40642
+ }
40643
+ __name(normalizeWhitespaceNormal, "normalizeWhitespaceNormal");
40644
+ function normalizeWhitespacePreWrap(text2) {
40645
+ if (!/[\r\f]/.test(text2))
40646
+ return text2.replace(/\r\n/g, "\n");
40647
+ return text2.replace(/\r\n/g, "\n").replace(/[\r\f]/g, "\n");
40648
+ }
40649
+ __name(normalizeWhitespacePreWrap, "normalizeWhitespacePreWrap");
40650
+ var sharedWordSegmenter = null;
40651
+ var segmenterLocale;
40652
+ function getSharedWordSegmenter() {
40653
+ if (sharedWordSegmenter === null) {
40654
+ sharedWordSegmenter = new Intl.Segmenter(segmenterLocale, { granularity: "word" });
40655
+ }
40656
+ return sharedWordSegmenter;
40657
+ }
40658
+ __name(getSharedWordSegmenter, "getSharedWordSegmenter");
40659
+ var arabicScriptRe = /\p{Script=Arabic}/u;
40660
+ var combiningMarkRe = /\p{M}/u;
40661
+ var decimalDigitRe = /\p{Nd}/u;
40662
+ function containsArabicScript(text2) {
40663
+ return arabicScriptRe.test(text2);
40664
+ }
40665
+ __name(containsArabicScript, "containsArabicScript");
40666
+ function isCJKCodePoint(codePoint) {
40667
+ return codePoint >= 19968 && codePoint <= 40959 || codePoint >= 13312 && codePoint <= 19903 || codePoint >= 131072 && codePoint <= 173791 || codePoint >= 173824 && codePoint <= 177983 || codePoint >= 177984 && codePoint <= 178207 || codePoint >= 178208 && codePoint <= 183983 || codePoint >= 183984 && codePoint <= 191471 || codePoint >= 191472 && codePoint <= 192093 || codePoint >= 194560 && codePoint <= 195103 || codePoint >= 196608 && codePoint <= 201551 || codePoint >= 201552 && codePoint <= 205743 || codePoint >= 205744 && codePoint <= 210041 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 12288 && codePoint <= 12351 || codePoint >= 12352 && codePoint <= 12447 || codePoint >= 12448 && codePoint <= 12543 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 65280 && codePoint <= 65519;
40668
+ }
40669
+ __name(isCJKCodePoint, "isCJKCodePoint");
40670
+ function isCJK(s) {
40671
+ for (let i = 0; i < s.length; i++) {
40672
+ const first2 = s.charCodeAt(i);
40673
+ if (first2 < 12288)
40674
+ continue;
40675
+ if (first2 >= 55296 && first2 <= 56319 && i + 1 < s.length) {
40676
+ const second = s.charCodeAt(i + 1);
40677
+ if (second >= 56320 && second <= 57343) {
40678
+ const codePoint = (first2 - 55296 << 10) + (second - 56320) + 65536;
40679
+ if (isCJKCodePoint(codePoint))
40680
+ return true;
40681
+ i++;
40682
+ continue;
40683
+ }
40684
+ }
40685
+ if (isCJKCodePoint(first2))
40686
+ return true;
40687
+ }
40688
+ return false;
40689
+ }
40690
+ __name(isCJK, "isCJK");
40691
+ function endsWithLineStartProhibitedText(text2) {
40692
+ const last2 = getLastCodePoint(text2);
40693
+ return last2 !== null && (kinsokuStart.has(last2) || leftStickyPunctuation.has(last2));
40694
+ }
40695
+ __name(endsWithLineStartProhibitedText, "endsWithLineStartProhibitedText");
40696
+ var keepAllGlueChars = /* @__PURE__ */ new Set([
40697
+ "\xA0",
40698
+ "\u202F",
40699
+ "\u2060",
40700
+ "\uFEFF"
40701
+ ]);
40702
+ function containsCJKText(text2) {
40703
+ return isCJK(text2);
40704
+ }
40705
+ __name(containsCJKText, "containsCJKText");
40706
+ function endsWithKeepAllGlueText(text2) {
40707
+ const last2 = getLastCodePoint(text2);
40708
+ return last2 !== null && keepAllGlueChars.has(last2);
40709
+ }
40710
+ __name(endsWithKeepAllGlueText, "endsWithKeepAllGlueText");
40711
+ function canContinueKeepAllTextRun(previousText) {
40712
+ return !endsWithLineStartProhibitedText(previousText) && !endsWithKeepAllGlueText(previousText);
40713
+ }
40714
+ __name(canContinueKeepAllTextRun, "canContinueKeepAllTextRun");
40715
+ var kinsokuStart = /* @__PURE__ */ new Set([
40716
+ "\uFF0C",
40717
+ "\uFF0E",
40718
+ "\uFF01",
40719
+ "\uFF1A",
40720
+ "\uFF1B",
40721
+ "\uFF1F",
40722
+ "\u3001",
40723
+ "\u3002",
40724
+ "\u30FB",
40725
+ "\uFF09",
40726
+ "\u3015",
40727
+ "\u3009",
40728
+ "\u300B",
40729
+ "\u300D",
40730
+ "\u300F",
40731
+ "\u3011",
40732
+ "\u3017",
40733
+ "\u3019",
40734
+ "\u301B",
40735
+ "\u30FC",
40736
+ "\u3005",
40737
+ "\u303B",
40738
+ "\u309D",
40739
+ "\u309E",
40740
+ "\u30FD",
40741
+ "\u30FE"
40742
+ ]);
40743
+ var kinsokuEnd = /* @__PURE__ */ new Set([
40744
+ '"',
40745
+ "(",
40746
+ "[",
40747
+ "{",
40748
+ "\u201C",
40749
+ "\u2018",
40750
+ "\xAB",
40751
+ "\u2039",
40752
+ "\uFF08",
40753
+ "\u3014",
40754
+ "\u3008",
40755
+ "\u300A",
40756
+ "\u300C",
40757
+ "\u300E",
40758
+ "\u3010",
40759
+ "\u3016",
40760
+ "\u3018",
40761
+ "\u301A"
40762
+ ]);
40763
+ var forwardStickyGlue = /* @__PURE__ */ new Set([
40764
+ "'",
40765
+ "\u2019"
40766
+ ]);
40767
+ var leftStickyPunctuation = /* @__PURE__ */ new Set([
40768
+ ".",
40769
+ ",",
40770
+ "!",
40771
+ "?",
40772
+ ":",
40773
+ ";",
40774
+ "\u060C",
40775
+ "\u061B",
40776
+ "\u061F",
40777
+ "\u0964",
40778
+ "\u0965",
40779
+ "\u104A",
40780
+ "\u104B",
40781
+ "\u104C",
40782
+ "\u104D",
40783
+ "\u104F",
40784
+ ")",
40785
+ "]",
40786
+ "}",
40787
+ "%",
40788
+ '"',
40789
+ "\u201D",
40790
+ "\u2019",
40791
+ "\xBB",
40792
+ "\u203A",
40793
+ "\u2026"
40794
+ ]);
40795
+ var arabicNoSpaceTrailingPunctuation = /* @__PURE__ */ new Set([
40796
+ ":",
40797
+ ".",
40798
+ "\u060C",
40799
+ "\u061B"
40800
+ ]);
40801
+ var myanmarMedialGlue = /* @__PURE__ */ new Set([
40802
+ "\u104F"
40803
+ ]);
40804
+ var closingQuoteChars = /* @__PURE__ */ new Set([
40805
+ "\u201D",
40806
+ "\u2019",
40807
+ "\xBB",
40808
+ "\u203A",
40809
+ "\u300D",
40810
+ "\u300F",
40811
+ "\u3011",
40812
+ "\u300B",
40813
+ "\u3009",
40814
+ "\u3015",
40815
+ "\uFF09"
40816
+ ]);
40817
+ function isLeftStickyPunctuationSegment(segment) {
40818
+ if (isEscapedQuoteClusterSegment(segment))
40819
+ return true;
40820
+ let sawPunctuation = false;
40821
+ for (const ch of segment) {
40822
+ if (leftStickyPunctuation.has(ch)) {
40823
+ sawPunctuation = true;
40824
+ continue;
40825
+ }
40826
+ if (sawPunctuation && combiningMarkRe.test(ch))
40827
+ continue;
40828
+ return false;
40829
+ }
40830
+ return sawPunctuation;
40831
+ }
40832
+ __name(isLeftStickyPunctuationSegment, "isLeftStickyPunctuationSegment");
40833
+ function isCJKLineStartProhibitedSegment(segment) {
40834
+ for (const ch of segment) {
40835
+ if (!kinsokuStart.has(ch) && !leftStickyPunctuation.has(ch))
40836
+ return false;
40837
+ }
40838
+ return segment.length > 0;
40839
+ }
40840
+ __name(isCJKLineStartProhibitedSegment, "isCJKLineStartProhibitedSegment");
40841
+ function isForwardStickyClusterSegment(segment) {
40842
+ if (isEscapedQuoteClusterSegment(segment))
40843
+ return true;
40844
+ for (const ch of segment) {
40845
+ if (!kinsokuEnd.has(ch) && !forwardStickyGlue.has(ch) && !combiningMarkRe.test(ch))
40846
+ return false;
40847
+ }
40848
+ return segment.length > 0;
40849
+ }
40850
+ __name(isForwardStickyClusterSegment, "isForwardStickyClusterSegment");
40851
+ function isEscapedQuoteClusterSegment(segment) {
40852
+ let sawQuote = false;
40853
+ for (const ch of segment) {
40854
+ if (ch === "\\" || combiningMarkRe.test(ch))
40855
+ continue;
40856
+ if (kinsokuEnd.has(ch) || leftStickyPunctuation.has(ch) || forwardStickyGlue.has(ch)) {
40857
+ sawQuote = true;
40858
+ continue;
40859
+ }
40860
+ return false;
40861
+ }
40862
+ return sawQuote;
40863
+ }
40864
+ __name(isEscapedQuoteClusterSegment, "isEscapedQuoteClusterSegment");
40865
+ function previousCodePointStart(text2, end) {
40866
+ const last2 = end - 1;
40867
+ if (last2 <= 0)
40868
+ return Math.max(last2, 0);
40869
+ const lastCodeUnit = text2.charCodeAt(last2);
40870
+ if (lastCodeUnit < 56320 || lastCodeUnit > 57343)
40871
+ return last2;
40872
+ const maybeHigh = last2 - 1;
40873
+ if (maybeHigh < 0)
40874
+ return last2;
40875
+ const highCodeUnit = text2.charCodeAt(maybeHigh);
40876
+ return highCodeUnit >= 55296 && highCodeUnit <= 56319 ? maybeHigh : last2;
40877
+ }
40878
+ __name(previousCodePointStart, "previousCodePointStart");
40879
+ function getLastCodePoint(text2) {
40880
+ if (text2.length === 0)
40881
+ return null;
40882
+ const start = previousCodePointStart(text2, text2.length);
40883
+ return text2.slice(start);
40884
+ }
40885
+ __name(getLastCodePoint, "getLastCodePoint");
40886
+ function splitTrailingForwardStickyCluster(text2) {
40887
+ const chars = Array.from(text2);
40888
+ let splitIndex = chars.length;
40889
+ while (splitIndex > 0) {
40890
+ const ch = chars[splitIndex - 1];
40891
+ if (combiningMarkRe.test(ch)) {
40892
+ splitIndex--;
40893
+ continue;
40894
+ }
40895
+ if (kinsokuEnd.has(ch) || forwardStickyGlue.has(ch)) {
40896
+ splitIndex--;
40897
+ continue;
40898
+ }
40899
+ break;
40900
+ }
40901
+ if (splitIndex <= 0 || splitIndex === chars.length)
40902
+ return null;
40903
+ return {
40904
+ head: chars.slice(0, splitIndex).join(""),
40905
+ tail: chars.slice(splitIndex).join("")
40906
+ };
40907
+ }
40908
+ __name(splitTrailingForwardStickyCluster, "splitTrailingForwardStickyCluster");
40909
+ function getRepeatableSingleCharRunChar(text2, isWordLike, kind) {
40910
+ return kind === "text" && !isWordLike && text2.length === 1 && text2 !== "-" && text2 !== "\u2014" ? text2 : null;
40911
+ }
40912
+ __name(getRepeatableSingleCharRunChar, "getRepeatableSingleCharRunChar");
40913
+ function materializeDeferredSingleCharRun(texts, chars, lengths, index) {
40914
+ const ch = chars[index];
40915
+ const text2 = texts[index];
40916
+ if (ch == null)
40917
+ return text2;
40918
+ const length2 = lengths[index];
40919
+ if (text2.length === length2)
40920
+ return text2;
40921
+ const materialized = ch.repeat(length2);
40922
+ texts[index] = materialized;
40923
+ return materialized;
40924
+ }
40925
+ __name(materializeDeferredSingleCharRun, "materializeDeferredSingleCharRun");
40926
+ function hasArabicNoSpacePunctuation(containsArabic, lastCodePoint) {
40927
+ return containsArabic && lastCodePoint !== null && arabicNoSpaceTrailingPunctuation.has(lastCodePoint);
40928
+ }
40929
+ __name(hasArabicNoSpacePunctuation, "hasArabicNoSpacePunctuation");
40930
+ function endsWithMyanmarMedialGlue(segment) {
40931
+ const lastCodePoint = getLastCodePoint(segment);
40932
+ return lastCodePoint !== null && myanmarMedialGlue.has(lastCodePoint);
40933
+ }
40934
+ __name(endsWithMyanmarMedialGlue, "endsWithMyanmarMedialGlue");
40935
+ function splitLeadingSpaceAndMarks(segment) {
40936
+ if (segment.length < 2 || segment[0] !== " ")
40937
+ return null;
40938
+ const marks = segment.slice(1);
40939
+ if (/^\p{M}+$/u.test(marks)) {
40940
+ return { space: " ", marks };
40941
+ }
40942
+ return null;
40943
+ }
40944
+ __name(splitLeadingSpaceAndMarks, "splitLeadingSpaceAndMarks");
40945
+ function endsWithClosingQuote(text2) {
40946
+ let end = text2.length;
40947
+ while (end > 0) {
40948
+ const start = previousCodePointStart(text2, end);
40949
+ const ch = text2.slice(start, end);
40950
+ if (closingQuoteChars.has(ch))
40951
+ return true;
40952
+ if (!leftStickyPunctuation.has(ch))
40953
+ return false;
40954
+ end = start;
40955
+ }
40956
+ return false;
40957
+ }
40958
+ __name(endsWithClosingQuote, "endsWithClosingQuote");
40959
+ function classifySegmentBreakChar(ch, whiteSpaceProfile) {
40960
+ if (whiteSpaceProfile.preserveOrdinarySpaces || whiteSpaceProfile.preserveHardBreaks) {
40961
+ if (ch === " ")
40962
+ return "preserved-space";
40963
+ if (ch === " ")
40964
+ return "tab";
40965
+ if (whiteSpaceProfile.preserveHardBreaks && ch === "\n")
40966
+ return "hard-break";
40967
+ }
40968
+ if (ch === " ")
40969
+ return "space";
40970
+ if (ch === "\xA0" || ch === "\u202F" || ch === "\u2060" || ch === "\uFEFF") {
40971
+ return "glue";
40972
+ }
40973
+ if (ch === "\u200B")
40974
+ return "zero-width-break";
40975
+ if (ch === "\xAD")
40976
+ return "soft-hyphen";
40977
+ return "text";
40978
+ }
40979
+ __name(classifySegmentBreakChar, "classifySegmentBreakChar");
40980
+ var breakCharRe = /[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;
40981
+ function joinTextParts(parts) {
40982
+ return parts.length === 1 ? parts[0] : parts.join("");
40983
+ }
40984
+ __name(joinTextParts, "joinTextParts");
40985
+ function joinReversedPrefixParts(prefixParts, tail) {
40986
+ const parts = [];
40987
+ for (let i = prefixParts.length - 1; i >= 0; i--) {
40988
+ parts.push(prefixParts[i]);
40989
+ }
40990
+ parts.push(tail);
40991
+ return joinTextParts(parts);
40992
+ }
40993
+ __name(joinReversedPrefixParts, "joinReversedPrefixParts");
40994
+ function splitSegmentByBreakKind(segment, isWordLike, start, whiteSpaceProfile) {
40995
+ if (!breakCharRe.test(segment)) {
40996
+ return [{ text: segment, isWordLike, kind: "text", start }];
40997
+ }
40998
+ const pieces = [];
40999
+ let currentKind = null;
41000
+ let currentTextParts = [];
41001
+ let currentStart = start;
41002
+ let currentWordLike = false;
41003
+ let offset = 0;
41004
+ for (const ch of segment) {
41005
+ const kind = classifySegmentBreakChar(ch, whiteSpaceProfile);
41006
+ const wordLike = kind === "text" && isWordLike;
41007
+ if (currentKind !== null && kind === currentKind && wordLike === currentWordLike) {
41008
+ currentTextParts.push(ch);
41009
+ offset += ch.length;
41010
+ continue;
41011
+ }
41012
+ if (currentKind !== null) {
41013
+ pieces.push({
41014
+ text: joinTextParts(currentTextParts),
41015
+ isWordLike: currentWordLike,
41016
+ kind: currentKind,
41017
+ start: currentStart
41018
+ });
41019
+ }
41020
+ currentKind = kind;
41021
+ currentTextParts = [ch];
41022
+ currentStart = start + offset;
41023
+ currentWordLike = wordLike;
41024
+ offset += ch.length;
41025
+ }
41026
+ if (currentKind !== null) {
41027
+ pieces.push({
41028
+ text: joinTextParts(currentTextParts),
41029
+ isWordLike: currentWordLike,
41030
+ kind: currentKind,
41031
+ start: currentStart
41032
+ });
41033
+ }
41034
+ return pieces;
41035
+ }
41036
+ __name(splitSegmentByBreakKind, "splitSegmentByBreakKind");
41037
+ function isTextRunBoundary(kind) {
41038
+ return kind === "space" || kind === "preserved-space" || kind === "zero-width-break" || kind === "hard-break";
41039
+ }
41040
+ __name(isTextRunBoundary, "isTextRunBoundary");
41041
+ var urlSchemeSegmentRe = /^[A-Za-z][A-Za-z0-9+.-]*:$/;
41042
+ function isUrlLikeRunStart(segmentation, index) {
41043
+ const text2 = segmentation.texts[index];
41044
+ if (text2.startsWith("www."))
41045
+ return true;
41046
+ return urlSchemeSegmentRe.test(text2) && index + 1 < segmentation.len && segmentation.kinds[index + 1] === "text" && segmentation.texts[index + 1] === "//";
41047
+ }
41048
+ __name(isUrlLikeRunStart, "isUrlLikeRunStart");
41049
+ function isUrlQueryBoundarySegment(text2) {
41050
+ return text2.includes("?") && (text2.includes("://") || text2.startsWith("www."));
41051
+ }
41052
+ __name(isUrlQueryBoundarySegment, "isUrlQueryBoundarySegment");
41053
+ function mergeUrlLikeRuns(segmentation) {
41054
+ const texts = segmentation.texts.slice();
41055
+ const isWordLike = segmentation.isWordLike.slice();
41056
+ const kinds = segmentation.kinds.slice();
41057
+ const starts = segmentation.starts.slice();
41058
+ for (let i = 0; i < segmentation.len; i++) {
41059
+ if (kinds[i] !== "text" || !isUrlLikeRunStart(segmentation, i))
41060
+ continue;
41061
+ const mergedParts = [texts[i]];
41062
+ let j = i + 1;
41063
+ while (j < segmentation.len && !isTextRunBoundary(kinds[j])) {
41064
+ mergedParts.push(texts[j]);
41065
+ isWordLike[i] = true;
41066
+ const endsQueryPrefix = texts[j].includes("?");
41067
+ kinds[j] = "text";
41068
+ texts[j] = "";
41069
+ j++;
41070
+ if (endsQueryPrefix)
41071
+ break;
41072
+ }
41073
+ texts[i] = joinTextParts(mergedParts);
41074
+ }
41075
+ let compactLen = 0;
41076
+ for (let read = 0; read < texts.length; read++) {
41077
+ const text2 = texts[read];
41078
+ if (text2.length === 0)
41079
+ continue;
41080
+ if (compactLen !== read) {
41081
+ texts[compactLen] = text2;
41082
+ isWordLike[compactLen] = isWordLike[read];
41083
+ kinds[compactLen] = kinds[read];
41084
+ starts[compactLen] = starts[read];
41085
+ }
41086
+ compactLen++;
41087
+ }
41088
+ texts.length = compactLen;
41089
+ isWordLike.length = compactLen;
41090
+ kinds.length = compactLen;
41091
+ starts.length = compactLen;
41092
+ return {
41093
+ len: compactLen,
41094
+ texts,
41095
+ isWordLike,
41096
+ kinds,
41097
+ starts
41098
+ };
41099
+ }
41100
+ __name(mergeUrlLikeRuns, "mergeUrlLikeRuns");
41101
+ function mergeUrlQueryRuns(segmentation) {
41102
+ const texts = [];
41103
+ const isWordLike = [];
41104
+ const kinds = [];
41105
+ const starts = [];
41106
+ for (let i = 0; i < segmentation.len; i++) {
41107
+ const text2 = segmentation.texts[i];
41108
+ texts.push(text2);
41109
+ isWordLike.push(segmentation.isWordLike[i]);
41110
+ kinds.push(segmentation.kinds[i]);
41111
+ starts.push(segmentation.starts[i]);
41112
+ if (!isUrlQueryBoundarySegment(text2))
41113
+ continue;
41114
+ const nextIndex = i + 1;
41115
+ if (nextIndex >= segmentation.len || isTextRunBoundary(segmentation.kinds[nextIndex])) {
41116
+ continue;
41117
+ }
41118
+ const queryParts = [];
41119
+ const queryStart = segmentation.starts[nextIndex];
41120
+ let j = nextIndex;
41121
+ while (j < segmentation.len && !isTextRunBoundary(segmentation.kinds[j])) {
41122
+ queryParts.push(segmentation.texts[j]);
41123
+ j++;
41124
+ }
41125
+ if (queryParts.length > 0) {
41126
+ texts.push(joinTextParts(queryParts));
41127
+ isWordLike.push(true);
41128
+ kinds.push("text");
41129
+ starts.push(queryStart);
41130
+ i = j - 1;
41131
+ }
41132
+ }
41133
+ return {
41134
+ len: texts.length,
41135
+ texts,
41136
+ isWordLike,
41137
+ kinds,
41138
+ starts
41139
+ };
41140
+ }
41141
+ __name(mergeUrlQueryRuns, "mergeUrlQueryRuns");
41142
+ var numericJoinerChars = /* @__PURE__ */ new Set([
41143
+ ":",
41144
+ "-",
41145
+ "/",
41146
+ "\xD7",
41147
+ ",",
41148
+ ".",
41149
+ "+",
41150
+ "\u2013",
41151
+ "\u2014"
41152
+ ]);
41153
+ var asciiPunctuationChainSegmentRe = /^[A-Za-z0-9_]+[,:;]*$/;
41154
+ var asciiPunctuationChainTrailingJoinersRe = /[,:;]+$/;
41155
+ function segmentContainsDecimalDigit(text2) {
41156
+ for (const ch of text2) {
41157
+ if (decimalDigitRe.test(ch))
41158
+ return true;
41159
+ }
41160
+ return false;
41161
+ }
41162
+ __name(segmentContainsDecimalDigit, "segmentContainsDecimalDigit");
41163
+ function isNumericRunSegment(text2) {
41164
+ if (text2.length === 0)
41165
+ return false;
41166
+ for (const ch of text2) {
41167
+ if (decimalDigitRe.test(ch) || numericJoinerChars.has(ch))
41168
+ continue;
41169
+ return false;
41170
+ }
41171
+ return true;
41172
+ }
41173
+ __name(isNumericRunSegment, "isNumericRunSegment");
41174
+ function mergeNumericRuns(segmentation) {
41175
+ const texts = [];
41176
+ const isWordLike = [];
41177
+ const kinds = [];
41178
+ const starts = [];
41179
+ for (let i = 0; i < segmentation.len; i++) {
41180
+ const text2 = segmentation.texts[i];
41181
+ const kind = segmentation.kinds[i];
41182
+ if (kind === "text" && isNumericRunSegment(text2) && segmentContainsDecimalDigit(text2)) {
41183
+ const mergedParts = [text2];
41184
+ let j = i + 1;
41185
+ while (j < segmentation.len && segmentation.kinds[j] === "text" && isNumericRunSegment(segmentation.texts[j])) {
41186
+ mergedParts.push(segmentation.texts[j]);
41187
+ j++;
41188
+ }
41189
+ texts.push(joinTextParts(mergedParts));
41190
+ isWordLike.push(true);
41191
+ kinds.push("text");
41192
+ starts.push(segmentation.starts[i]);
41193
+ i = j - 1;
41194
+ continue;
41195
+ }
41196
+ texts.push(text2);
41197
+ isWordLike.push(segmentation.isWordLike[i]);
41198
+ kinds.push(kind);
41199
+ starts.push(segmentation.starts[i]);
41200
+ }
41201
+ return {
41202
+ len: texts.length,
41203
+ texts,
41204
+ isWordLike,
41205
+ kinds,
41206
+ starts
41207
+ };
41208
+ }
41209
+ __name(mergeNumericRuns, "mergeNumericRuns");
41210
+ function mergeAsciiPunctuationChains(segmentation) {
41211
+ const texts = [];
41212
+ const isWordLike = [];
41213
+ const kinds = [];
41214
+ const starts = [];
41215
+ for (let i = 0; i < segmentation.len; i++) {
41216
+ const text2 = segmentation.texts[i];
41217
+ const kind = segmentation.kinds[i];
41218
+ const wordLike = segmentation.isWordLike[i];
41219
+ if (kind === "text" && wordLike && asciiPunctuationChainSegmentRe.test(text2)) {
41220
+ const mergedParts = [text2];
41221
+ let endsWithJoiners = asciiPunctuationChainTrailingJoinersRe.test(text2);
41222
+ let j = i + 1;
41223
+ while (endsWithJoiners && j < segmentation.len && segmentation.kinds[j] === "text" && segmentation.isWordLike[j] && asciiPunctuationChainSegmentRe.test(segmentation.texts[j])) {
41224
+ const nextText = segmentation.texts[j];
41225
+ mergedParts.push(nextText);
41226
+ endsWithJoiners = asciiPunctuationChainTrailingJoinersRe.test(nextText);
41227
+ j++;
41228
+ }
41229
+ texts.push(joinTextParts(mergedParts));
41230
+ isWordLike.push(true);
41231
+ kinds.push("text");
41232
+ starts.push(segmentation.starts[i]);
41233
+ i = j - 1;
41234
+ continue;
41235
+ }
41236
+ texts.push(text2);
41237
+ isWordLike.push(wordLike);
41238
+ kinds.push(kind);
41239
+ starts.push(segmentation.starts[i]);
41240
+ }
41241
+ return {
41242
+ len: texts.length,
41243
+ texts,
41244
+ isWordLike,
41245
+ kinds,
41246
+ starts
41247
+ };
41248
+ }
41249
+ __name(mergeAsciiPunctuationChains, "mergeAsciiPunctuationChains");
41250
+ function splitHyphenatedNumericRuns(segmentation) {
41251
+ const texts = [];
41252
+ const isWordLike = [];
41253
+ const kinds = [];
41254
+ const starts = [];
41255
+ for (let i = 0; i < segmentation.len; i++) {
41256
+ const text2 = segmentation.texts[i];
41257
+ if (segmentation.kinds[i] === "text" && text2.includes("-")) {
41258
+ const parts = text2.split("-");
41259
+ let shouldSplit = parts.length > 1;
41260
+ for (let j = 0; j < parts.length; j++) {
41261
+ const part = parts[j];
41262
+ if (!shouldSplit)
41263
+ break;
41264
+ if (part.length === 0 || !segmentContainsDecimalDigit(part) || !isNumericRunSegment(part)) {
41265
+ shouldSplit = false;
41266
+ }
41267
+ }
41268
+ if (shouldSplit) {
41269
+ let offset = 0;
41270
+ for (let j = 0; j < parts.length; j++) {
41271
+ const part = parts[j];
41272
+ const splitText = j < parts.length - 1 ? `${part}-` : part;
41273
+ texts.push(splitText);
41274
+ isWordLike.push(true);
41275
+ kinds.push("text");
41276
+ starts.push(segmentation.starts[i] + offset);
41277
+ offset += splitText.length;
41278
+ }
41279
+ continue;
41280
+ }
41281
+ }
41282
+ texts.push(text2);
41283
+ isWordLike.push(segmentation.isWordLike[i]);
41284
+ kinds.push(segmentation.kinds[i]);
41285
+ starts.push(segmentation.starts[i]);
41286
+ }
41287
+ return {
41288
+ len: texts.length,
41289
+ texts,
41290
+ isWordLike,
41291
+ kinds,
41292
+ starts
41293
+ };
41294
+ }
41295
+ __name(splitHyphenatedNumericRuns, "splitHyphenatedNumericRuns");
41296
+ function mergeGlueConnectedTextRuns(segmentation) {
41297
+ const texts = [];
41298
+ const isWordLike = [];
41299
+ const kinds = [];
41300
+ const starts = [];
41301
+ let read = 0;
41302
+ while (read < segmentation.len) {
41303
+ const textParts = [segmentation.texts[read]];
41304
+ let wordLike = segmentation.isWordLike[read];
41305
+ let kind = segmentation.kinds[read];
41306
+ let start = segmentation.starts[read];
41307
+ if (kind === "glue") {
41308
+ const glueParts = [textParts[0]];
41309
+ const glueStart = start;
41310
+ read++;
41311
+ while (read < segmentation.len && segmentation.kinds[read] === "glue") {
41312
+ glueParts.push(segmentation.texts[read]);
41313
+ read++;
41314
+ }
41315
+ const glueText = joinTextParts(glueParts);
41316
+ if (read < segmentation.len && segmentation.kinds[read] === "text") {
41317
+ textParts[0] = glueText;
41318
+ textParts.push(segmentation.texts[read]);
41319
+ wordLike = segmentation.isWordLike[read];
41320
+ kind = "text";
41321
+ start = glueStart;
41322
+ read++;
41323
+ } else {
41324
+ texts.push(glueText);
41325
+ isWordLike.push(false);
41326
+ kinds.push("glue");
41327
+ starts.push(glueStart);
41328
+ continue;
41329
+ }
41330
+ } else {
41331
+ read++;
41332
+ }
41333
+ if (kind === "text") {
41334
+ while (read < segmentation.len && segmentation.kinds[read] === "glue") {
41335
+ const glueParts = [];
41336
+ while (read < segmentation.len && segmentation.kinds[read] === "glue") {
41337
+ glueParts.push(segmentation.texts[read]);
41338
+ read++;
41339
+ }
41340
+ const glueText = joinTextParts(glueParts);
41341
+ if (read < segmentation.len && segmentation.kinds[read] === "text") {
41342
+ textParts.push(glueText, segmentation.texts[read]);
41343
+ wordLike = wordLike || segmentation.isWordLike[read];
41344
+ read++;
41345
+ continue;
41346
+ }
41347
+ textParts.push(glueText);
41348
+ }
41349
+ }
41350
+ texts.push(joinTextParts(textParts));
41351
+ isWordLike.push(wordLike);
41352
+ kinds.push(kind);
41353
+ starts.push(start);
41354
+ }
41355
+ return {
41356
+ len: texts.length,
41357
+ texts,
41358
+ isWordLike,
41359
+ kinds,
41360
+ starts
41361
+ };
41362
+ }
41363
+ __name(mergeGlueConnectedTextRuns, "mergeGlueConnectedTextRuns");
41364
+ function carryTrailingForwardStickyAcrossCJKBoundary(segmentation) {
41365
+ const texts = segmentation.texts.slice();
41366
+ const isWordLike = segmentation.isWordLike.slice();
41367
+ const kinds = segmentation.kinds.slice();
41368
+ const starts = segmentation.starts.slice();
41369
+ for (let i = 0; i < texts.length - 1; i++) {
41370
+ if (kinds[i] !== "text" || kinds[i + 1] !== "text")
41371
+ continue;
41372
+ if (!isCJK(texts[i]) || !isCJK(texts[i + 1]))
41373
+ continue;
41374
+ const split = splitTrailingForwardStickyCluster(texts[i]);
41375
+ if (split === null)
41376
+ continue;
41377
+ texts[i] = split.head;
41378
+ texts[i + 1] = split.tail + texts[i + 1];
41379
+ starts[i + 1] = starts[i] + split.head.length;
41380
+ }
41381
+ return {
41382
+ len: texts.length,
41383
+ texts,
41384
+ isWordLike,
41385
+ kinds,
41386
+ starts
41387
+ };
41388
+ }
41389
+ __name(carryTrailingForwardStickyAcrossCJKBoundary, "carryTrailingForwardStickyAcrossCJKBoundary");
41390
+ function buildMergedSegmentation(normalized, profile, whiteSpaceProfile) {
41391
+ const wordSegmenter = getSharedWordSegmenter();
41392
+ let mergedLen = 0;
41393
+ const mergedTexts = [];
41394
+ const mergedTextParts = [];
41395
+ const mergedWordLike = [];
41396
+ const mergedKinds = [];
41397
+ const mergedStarts = [];
41398
+ const mergedSingleCharRunChars = [];
41399
+ const mergedSingleCharRunLengths = [];
41400
+ const mergedContainsCJK = [];
41401
+ const mergedContainsArabicScript = [];
41402
+ const mergedEndsWithClosingQuote = [];
41403
+ const mergedEndsWithMyanmarMedialGlue = [];
41404
+ const mergedHasArabicNoSpacePunctuation = [];
41405
+ for (const s of wordSegmenter.segment(normalized)) {
41406
+ for (const piece of splitSegmentByBreakKind(s.segment, s.isWordLike ?? false, s.index, whiteSpaceProfile)) {
41407
+ let appendPieceToPrevious2 = function() {
41408
+ if (mergedSingleCharRunChars[prevIndex] !== null) {
41409
+ mergedTextParts[prevIndex] = [
41410
+ materializeDeferredSingleCharRun(mergedTexts, mergedSingleCharRunChars, mergedSingleCharRunLengths, prevIndex)
41411
+ ];
41412
+ mergedSingleCharRunChars[prevIndex] = null;
41413
+ }
41414
+ mergedTextParts[prevIndex].push(piece.text);
41415
+ mergedWordLike[prevIndex] = mergedWordLike[prevIndex] || piece.isWordLike;
41416
+ mergedContainsCJK[prevIndex] = mergedContainsCJK[prevIndex] || pieceContainsCJK;
41417
+ mergedContainsArabicScript[prevIndex] = mergedContainsArabicScript[prevIndex] || pieceContainsArabicScript;
41418
+ mergedEndsWithClosingQuote[prevIndex] = pieceEndsWithClosingQuote;
41419
+ mergedEndsWithMyanmarMedialGlue[prevIndex] = pieceEndsWithMyanmarMedialGlue;
41420
+ mergedHasArabicNoSpacePunctuation[prevIndex] = hasArabicNoSpacePunctuation(mergedContainsArabicScript[prevIndex], pieceLastCodePoint);
41421
+ };
41422
+ var appendPieceToPrevious = appendPieceToPrevious2;
41423
+ __name(appendPieceToPrevious2, "appendPieceToPrevious");
41424
+ const isText = piece.kind === "text";
41425
+ const repeatableSingleCharRunChar = getRepeatableSingleCharRunChar(piece.text, piece.isWordLike, piece.kind);
41426
+ const pieceContainsCJK = isCJK(piece.text);
41427
+ const pieceContainsArabicScript = containsArabicScript(piece.text);
41428
+ const pieceLastCodePoint = getLastCodePoint(piece.text);
41429
+ const pieceEndsWithClosingQuote = endsWithClosingQuote(piece.text);
41430
+ const pieceEndsWithMyanmarMedialGlue = endsWithMyanmarMedialGlue(piece.text);
41431
+ const prevIndex = mergedLen - 1;
41432
+ if (profile.carryCJKAfterClosingQuote && isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && pieceContainsCJK && mergedContainsCJK[prevIndex] && mergedEndsWithClosingQuote[prevIndex]) {
41433
+ appendPieceToPrevious2();
41434
+ } else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && isCJKLineStartProhibitedSegment(piece.text) && mergedContainsCJK[prevIndex]) {
41435
+ appendPieceToPrevious2();
41436
+ } else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && mergedEndsWithMyanmarMedialGlue[prevIndex]) {
41437
+ appendPieceToPrevious2();
41438
+ } else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && piece.isWordLike && pieceContainsArabicScript && mergedHasArabicNoSpacePunctuation[prevIndex]) {
41439
+ appendPieceToPrevious2();
41440
+ mergedWordLike[prevIndex] = true;
41441
+ } else if (repeatableSingleCharRunChar !== null && mergedLen > 0 && mergedKinds[prevIndex] === "text" && mergedSingleCharRunChars[prevIndex] === repeatableSingleCharRunChar) {
41442
+ mergedSingleCharRunLengths[prevIndex] = (mergedSingleCharRunLengths[prevIndex] ?? 1) + 1;
41443
+ } else if (isText && !piece.isWordLike && mergedLen > 0 && mergedKinds[prevIndex] === "text" && (isLeftStickyPunctuationSegment(piece.text) || piece.text === "-" && mergedWordLike[prevIndex])) {
41444
+ appendPieceToPrevious2();
41445
+ } else {
41446
+ mergedTexts[mergedLen] = piece.text;
41447
+ mergedTextParts[mergedLen] = [piece.text];
41448
+ mergedWordLike[mergedLen] = piece.isWordLike;
41449
+ mergedKinds[mergedLen] = piece.kind;
41450
+ mergedStarts[mergedLen] = piece.start;
41451
+ mergedSingleCharRunChars[mergedLen] = repeatableSingleCharRunChar;
41452
+ mergedSingleCharRunLengths[mergedLen] = repeatableSingleCharRunChar === null ? 0 : 1;
41453
+ mergedContainsCJK[mergedLen] = pieceContainsCJK;
41454
+ mergedContainsArabicScript[mergedLen] = pieceContainsArabicScript;
41455
+ mergedEndsWithClosingQuote[mergedLen] = pieceEndsWithClosingQuote;
41456
+ mergedEndsWithMyanmarMedialGlue[mergedLen] = pieceEndsWithMyanmarMedialGlue;
41457
+ mergedHasArabicNoSpacePunctuation[mergedLen] = hasArabicNoSpacePunctuation(pieceContainsArabicScript, pieceLastCodePoint);
41458
+ mergedLen++;
41459
+ }
41460
+ }
41461
+ }
41462
+ for (let i = 0; i < mergedLen; i++) {
41463
+ if (mergedSingleCharRunChars[i] !== null) {
41464
+ mergedTexts[i] = materializeDeferredSingleCharRun(mergedTexts, mergedSingleCharRunChars, mergedSingleCharRunLengths, i);
41465
+ continue;
41466
+ }
41467
+ mergedTexts[i] = joinTextParts(mergedTextParts[i]);
41468
+ }
41469
+ for (let i = 1; i < mergedLen; i++) {
41470
+ if (mergedKinds[i] === "text" && !mergedWordLike[i] && isEscapedQuoteClusterSegment(mergedTexts[i]) && mergedKinds[i - 1] === "text") {
41471
+ mergedTexts[i - 1] += mergedTexts[i];
41472
+ mergedWordLike[i - 1] = mergedWordLike[i - 1] || mergedWordLike[i];
41473
+ mergedTexts[i] = "";
41474
+ }
41475
+ }
41476
+ const forwardStickyPrefixParts = Array.from({ length: mergedLen }, () => null);
41477
+ let nextLiveIndex = -1;
41478
+ for (let i = mergedLen - 1; i >= 0; i--) {
41479
+ const text2 = mergedTexts[i];
41480
+ if (text2.length === 0)
41481
+ continue;
41482
+ if (mergedKinds[i] === "text" && !mergedWordLike[i] && isForwardStickyClusterSegment(text2) && nextLiveIndex >= 0 && mergedKinds[nextLiveIndex] === "text") {
41483
+ const prefixParts = forwardStickyPrefixParts[nextLiveIndex] ?? [];
41484
+ prefixParts.push(text2);
41485
+ forwardStickyPrefixParts[nextLiveIndex] = prefixParts;
41486
+ mergedStarts[nextLiveIndex] = mergedStarts[i];
41487
+ mergedTexts[i] = "";
41488
+ continue;
41489
+ }
41490
+ nextLiveIndex = i;
41491
+ }
41492
+ for (let i = 0; i < mergedLen; i++) {
41493
+ const prefixParts = forwardStickyPrefixParts[i];
41494
+ if (prefixParts == null)
41495
+ continue;
41496
+ mergedTexts[i] = joinReversedPrefixParts(prefixParts, mergedTexts[i]);
41497
+ }
41498
+ let compactLen = 0;
41499
+ for (let read = 0; read < mergedLen; read++) {
41500
+ const text2 = mergedTexts[read];
41501
+ if (text2.length === 0)
41502
+ continue;
41503
+ if (compactLen !== read) {
41504
+ mergedTexts[compactLen] = text2;
41505
+ mergedWordLike[compactLen] = mergedWordLike[read];
41506
+ mergedKinds[compactLen] = mergedKinds[read];
41507
+ mergedStarts[compactLen] = mergedStarts[read];
41508
+ }
41509
+ compactLen++;
41510
+ }
41511
+ mergedTexts.length = compactLen;
41512
+ mergedWordLike.length = compactLen;
41513
+ mergedKinds.length = compactLen;
41514
+ mergedStarts.length = compactLen;
41515
+ const compacted = mergeGlueConnectedTextRuns({
41516
+ len: compactLen,
41517
+ texts: mergedTexts,
41518
+ isWordLike: mergedWordLike,
41519
+ kinds: mergedKinds,
41520
+ starts: mergedStarts
41521
+ });
41522
+ const withMergedUrls = carryTrailingForwardStickyAcrossCJKBoundary(mergeAsciiPunctuationChains(splitHyphenatedNumericRuns(mergeNumericRuns(mergeUrlQueryRuns(mergeUrlLikeRuns(compacted))))));
41523
+ for (let i = 0; i < withMergedUrls.len - 1; i++) {
41524
+ const split = splitLeadingSpaceAndMarks(withMergedUrls.texts[i]);
41525
+ if (split === null)
41526
+ continue;
41527
+ if (withMergedUrls.kinds[i] !== "space" && withMergedUrls.kinds[i] !== "preserved-space" || withMergedUrls.kinds[i + 1] !== "text" || !containsArabicScript(withMergedUrls.texts[i + 1])) {
41528
+ continue;
41529
+ }
41530
+ withMergedUrls.texts[i] = split.space;
41531
+ withMergedUrls.isWordLike[i] = false;
41532
+ withMergedUrls.kinds[i] = withMergedUrls.kinds[i] === "preserved-space" ? "preserved-space" : "space";
41533
+ withMergedUrls.texts[i + 1] = split.marks + withMergedUrls.texts[i + 1];
41534
+ withMergedUrls.starts[i + 1] = withMergedUrls.starts[i] + split.space.length;
41535
+ }
41536
+ return withMergedUrls;
41537
+ }
41538
+ __name(buildMergedSegmentation, "buildMergedSegmentation");
41539
+ function compileAnalysisChunks(segmentation, whiteSpaceProfile) {
41540
+ if (segmentation.len === 0)
41541
+ return [];
41542
+ if (!whiteSpaceProfile.preserveHardBreaks) {
41543
+ return [{
41544
+ startSegmentIndex: 0,
41545
+ endSegmentIndex: segmentation.len,
41546
+ consumedEndSegmentIndex: segmentation.len
41547
+ }];
41548
+ }
41549
+ const chunks = [];
41550
+ let startSegmentIndex = 0;
41551
+ for (let i = 0; i < segmentation.len; i++) {
41552
+ if (segmentation.kinds[i] !== "hard-break")
41553
+ continue;
41554
+ chunks.push({
41555
+ startSegmentIndex,
41556
+ endSegmentIndex: i,
41557
+ consumedEndSegmentIndex: i + 1
41558
+ });
41559
+ startSegmentIndex = i + 1;
41560
+ }
41561
+ if (startSegmentIndex < segmentation.len) {
41562
+ chunks.push({
41563
+ startSegmentIndex,
41564
+ endSegmentIndex: segmentation.len,
41565
+ consumedEndSegmentIndex: segmentation.len
41566
+ });
41567
+ }
41568
+ return chunks;
41569
+ }
41570
+ __name(compileAnalysisChunks, "compileAnalysisChunks");
41571
+ function mergeKeepAllTextSegments(segmentation) {
41572
+ if (segmentation.len <= 1)
41573
+ return segmentation;
41574
+ const texts = [];
41575
+ const isWordLike = [];
41576
+ const kinds = [];
41577
+ const starts = [];
41578
+ let pendingTextParts = null;
41579
+ let pendingWordLike = false;
41580
+ let pendingStart = 0;
41581
+ let pendingContainsCJK = false;
41582
+ let pendingCanContinue = false;
41583
+ function flushPendingText() {
41584
+ if (pendingTextParts === null)
41585
+ return;
41586
+ texts.push(joinTextParts(pendingTextParts));
41587
+ isWordLike.push(pendingWordLike);
41588
+ kinds.push("text");
41589
+ starts.push(pendingStart);
41590
+ pendingTextParts = null;
41591
+ }
41592
+ __name(flushPendingText, "flushPendingText");
41593
+ for (let i = 0; i < segmentation.len; i++) {
41594
+ const text2 = segmentation.texts[i];
41595
+ const kind = segmentation.kinds[i];
41596
+ const wordLike = segmentation.isWordLike[i];
41597
+ const start = segmentation.starts[i];
41598
+ if (kind === "text") {
41599
+ const textContainsCJK = containsCJKText(text2);
41600
+ const textCanContinue = canContinueKeepAllTextRun(text2);
41601
+ if (pendingTextParts !== null && pendingContainsCJK && pendingCanContinue) {
41602
+ pendingTextParts.push(text2);
41603
+ pendingWordLike = pendingWordLike || wordLike;
41604
+ pendingContainsCJK = pendingContainsCJK || textContainsCJK;
41605
+ pendingCanContinue = textCanContinue;
41606
+ continue;
41607
+ }
41608
+ flushPendingText();
41609
+ pendingTextParts = [text2];
41610
+ pendingWordLike = wordLike;
41611
+ pendingStart = start;
41612
+ pendingContainsCJK = textContainsCJK;
41613
+ pendingCanContinue = textCanContinue;
41614
+ continue;
41615
+ }
41616
+ flushPendingText();
41617
+ texts.push(text2);
41618
+ isWordLike.push(wordLike);
41619
+ kinds.push(kind);
41620
+ starts.push(start);
41621
+ }
41622
+ flushPendingText();
41623
+ return {
41624
+ len: texts.length,
41625
+ texts,
41626
+ isWordLike,
41627
+ kinds,
41628
+ starts
41629
+ };
41630
+ }
41631
+ __name(mergeKeepAllTextSegments, "mergeKeepAllTextSegments");
41632
+ function analyzeText(text2, profile, whiteSpace = "normal", wordBreak = "normal") {
41633
+ const whiteSpaceProfile = getWhiteSpaceProfile(whiteSpace);
41634
+ const normalized = whiteSpaceProfile.mode === "pre-wrap" ? normalizeWhitespacePreWrap(text2) : normalizeWhitespaceNormal(text2);
41635
+ if (normalized.length === 0) {
41636
+ return {
41637
+ normalized,
41638
+ chunks: [],
41639
+ len: 0,
41640
+ texts: [],
41641
+ isWordLike: [],
41642
+ kinds: [],
41643
+ starts: []
41644
+ };
41645
+ }
41646
+ const segmentation = wordBreak === "keep-all" ? mergeKeepAllTextSegments(buildMergedSegmentation(normalized, profile, whiteSpaceProfile)) : buildMergedSegmentation(normalized, profile, whiteSpaceProfile);
41647
+ return {
41648
+ normalized,
41649
+ chunks: compileAnalysisChunks(segmentation, whiteSpaceProfile),
41650
+ ...segmentation
41651
+ };
41652
+ }
41653
+ __name(analyzeText, "analyzeText");
41654
+
41655
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/measurement.js
41656
+ var measureContext = null;
41657
+ var segmentMetricCaches = /* @__PURE__ */ new Map();
41658
+ var cachedEngineProfile = null;
41659
+ var MAX_PREFIX_FIT_GRAPHEMES = 96;
41660
+ var emojiPresentationRe = /\p{Emoji_Presentation}/u;
41661
+ var maybeEmojiRe = /[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;
41662
+ var sharedGraphemeSegmenter = null;
41663
+ var emojiCorrectionCache = /* @__PURE__ */ new Map();
41664
+ function getMeasureContext() {
41665
+ if (measureContext !== null)
41666
+ return measureContext;
41667
+ if (typeof OffscreenCanvas !== "undefined") {
41668
+ measureContext = new OffscreenCanvas(1, 1).getContext("2d");
41669
+ return measureContext;
41670
+ }
41671
+ if (typeof document !== "undefined") {
41672
+ measureContext = document.createElement("canvas").getContext("2d");
41673
+ return measureContext;
41674
+ }
41675
+ throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.");
41676
+ }
41677
+ __name(getMeasureContext, "getMeasureContext");
41678
+ function getSegmentMetricCache(font) {
41679
+ let cache3 = segmentMetricCaches.get(font);
41680
+ if (!cache3) {
41681
+ cache3 = /* @__PURE__ */ new Map();
41682
+ segmentMetricCaches.set(font, cache3);
41683
+ }
41684
+ return cache3;
41685
+ }
41686
+ __name(getSegmentMetricCache, "getSegmentMetricCache");
41687
+ function getSegmentMetrics(seg, cache3) {
41688
+ let metrics = cache3.get(seg);
41689
+ if (metrics === void 0) {
41690
+ const ctx = getMeasureContext();
41691
+ metrics = {
41692
+ width: ctx.measureText(seg).width,
41693
+ containsCJK: isCJK(seg)
41694
+ };
41695
+ cache3.set(seg, metrics);
41696
+ }
41697
+ return metrics;
41698
+ }
41699
+ __name(getSegmentMetrics, "getSegmentMetrics");
41700
+ function getEngineProfile() {
41701
+ if (cachedEngineProfile !== null)
41702
+ return cachedEngineProfile;
41703
+ if (typeof navigator === "undefined") {
41704
+ cachedEngineProfile = {
41705
+ lineFitEpsilon: 5e-3,
41706
+ carryCJKAfterClosingQuote: false,
41707
+ preferPrefixWidthsForBreakableRuns: false,
41708
+ preferEarlySoftHyphenBreak: false
41709
+ };
41710
+ return cachedEngineProfile;
41711
+ }
41712
+ const ua = navigator.userAgent;
41713
+ const vendor = navigator.vendor;
41714
+ const isSafari = vendor === "Apple Computer, Inc." && ua.includes("Safari/") && !ua.includes("Chrome/") && !ua.includes("Chromium/") && !ua.includes("CriOS/") && !ua.includes("FxiOS/") && !ua.includes("EdgiOS/");
41715
+ const isChromium = ua.includes("Chrome/") || ua.includes("Chromium/") || ua.includes("CriOS/") || ua.includes("Edg/");
41716
+ cachedEngineProfile = {
41717
+ lineFitEpsilon: isSafari ? 1 / 64 : 5e-3,
41718
+ carryCJKAfterClosingQuote: isChromium,
41719
+ preferPrefixWidthsForBreakableRuns: isSafari,
41720
+ preferEarlySoftHyphenBreak: isSafari
41721
+ };
41722
+ return cachedEngineProfile;
41723
+ }
41724
+ __name(getEngineProfile, "getEngineProfile");
41725
+ function parseFontSize(font) {
41726
+ const m = font.match(/(\d+(?:\.\d+)?)\s*px/);
41727
+ return m ? parseFloat(m[1]) : 16;
41728
+ }
41729
+ __name(parseFontSize, "parseFontSize");
41730
+ function getSharedGraphemeSegmenter() {
41731
+ if (sharedGraphemeSegmenter === null) {
41732
+ sharedGraphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
41733
+ }
41734
+ return sharedGraphemeSegmenter;
41735
+ }
41736
+ __name(getSharedGraphemeSegmenter, "getSharedGraphemeSegmenter");
41737
+ function isEmojiGrapheme(g) {
41738
+ return emojiPresentationRe.test(g) || g.includes("\uFE0F");
41739
+ }
41740
+ __name(isEmojiGrapheme, "isEmojiGrapheme");
41741
+ function textMayContainEmoji(text2) {
41742
+ return maybeEmojiRe.test(text2);
41743
+ }
41744
+ __name(textMayContainEmoji, "textMayContainEmoji");
41745
+ function getEmojiCorrection(font, fontSize) {
41746
+ let correction = emojiCorrectionCache.get(font);
41747
+ if (correction !== void 0)
41748
+ return correction;
41749
+ const ctx = getMeasureContext();
41750
+ ctx.font = font;
41751
+ const canvasW = ctx.measureText("\u{1F600}").width;
41752
+ correction = 0;
41753
+ if (canvasW > fontSize + 0.5 && typeof document !== "undefined" && document.body !== null) {
41754
+ const span = document.createElement("span");
41755
+ span.style.font = font;
41756
+ span.style.display = "inline-block";
41757
+ span.style.visibility = "hidden";
41758
+ span.style.position = "absolute";
41759
+ span.textContent = "\u{1F600}";
41760
+ document.body.appendChild(span);
41761
+ const domW = span.getBoundingClientRect().width;
41762
+ document.body.removeChild(span);
41763
+ if (canvasW - domW > 0.5) {
41764
+ correction = canvasW - domW;
41765
+ }
41766
+ }
41767
+ emojiCorrectionCache.set(font, correction);
41768
+ return correction;
41769
+ }
41770
+ __name(getEmojiCorrection, "getEmojiCorrection");
41771
+ function countEmojiGraphemes(text2) {
41772
+ let count2 = 0;
41773
+ const graphemeSegmenter = getSharedGraphemeSegmenter();
41774
+ for (const g of graphemeSegmenter.segment(text2)) {
41775
+ if (isEmojiGrapheme(g.segment))
41776
+ count2++;
41777
+ }
41778
+ return count2;
41779
+ }
41780
+ __name(countEmojiGraphemes, "countEmojiGraphemes");
41781
+ function getEmojiCount(seg, metrics) {
41782
+ if (metrics.emojiCount === void 0) {
41783
+ metrics.emojiCount = countEmojiGraphemes(seg);
41784
+ }
41785
+ return metrics.emojiCount;
41786
+ }
41787
+ __name(getEmojiCount, "getEmojiCount");
41788
+ function getCorrectedSegmentWidth(seg, metrics, emojiCorrection) {
41789
+ if (emojiCorrection === 0)
41790
+ return metrics.width;
41791
+ return metrics.width - getEmojiCount(seg, metrics) * emojiCorrection;
41792
+ }
41793
+ __name(getCorrectedSegmentWidth, "getCorrectedSegmentWidth");
41794
+ function getSegmentBreakableFitAdvances(seg, metrics, cache3, emojiCorrection, mode) {
41795
+ if (metrics.breakableFitAdvances !== void 0)
41796
+ return metrics.breakableFitAdvances;
41797
+ const graphemeSegmenter = getSharedGraphemeSegmenter();
41798
+ const graphemes = [];
41799
+ for (const gs of graphemeSegmenter.segment(seg)) {
41800
+ graphemes.push(gs.segment);
41801
+ }
41802
+ if (graphemes.length <= 1) {
41803
+ metrics.breakableFitAdvances = null;
41804
+ return metrics.breakableFitAdvances;
41805
+ }
41806
+ if (mode === "sum-graphemes") {
41807
+ const advances2 = [];
41808
+ for (const grapheme of graphemes) {
41809
+ const graphemeMetrics = getSegmentMetrics(grapheme, cache3);
41810
+ advances2.push(getCorrectedSegmentWidth(grapheme, graphemeMetrics, emojiCorrection));
41811
+ }
41812
+ metrics.breakableFitAdvances = advances2;
41813
+ return metrics.breakableFitAdvances;
41814
+ }
41815
+ if (mode === "pair-context" || graphemes.length > MAX_PREFIX_FIT_GRAPHEMES) {
41816
+ const advances2 = [];
41817
+ let previousGrapheme = null;
41818
+ let previousWidth = 0;
41819
+ for (const grapheme of graphemes) {
41820
+ const graphemeMetrics = getSegmentMetrics(grapheme, cache3);
41821
+ const currentWidth = getCorrectedSegmentWidth(grapheme, graphemeMetrics, emojiCorrection);
41822
+ if (previousGrapheme === null) {
41823
+ advances2.push(currentWidth);
41824
+ } else {
41825
+ const pair = previousGrapheme + grapheme;
41826
+ const pairMetrics = getSegmentMetrics(pair, cache3);
41827
+ advances2.push(getCorrectedSegmentWidth(pair, pairMetrics, emojiCorrection) - previousWidth);
41828
+ }
41829
+ previousGrapheme = grapheme;
41830
+ previousWidth = currentWidth;
41831
+ }
41832
+ metrics.breakableFitAdvances = advances2;
41833
+ return metrics.breakableFitAdvances;
41834
+ }
41835
+ const advances = [];
41836
+ let prefix = "";
41837
+ let prefixWidth = 0;
41838
+ for (const grapheme of graphemes) {
41839
+ prefix += grapheme;
41840
+ const prefixMetrics = getSegmentMetrics(prefix, cache3);
41841
+ const nextPrefixWidth = getCorrectedSegmentWidth(prefix, prefixMetrics, emojiCorrection);
41842
+ advances.push(nextPrefixWidth - prefixWidth);
41843
+ prefixWidth = nextPrefixWidth;
41844
+ }
41845
+ metrics.breakableFitAdvances = advances;
41846
+ return metrics.breakableFitAdvances;
41847
+ }
41848
+ __name(getSegmentBreakableFitAdvances, "getSegmentBreakableFitAdvances");
41849
+ function getFontMeasurementState(font, needsEmojiCorrection) {
41850
+ const ctx = getMeasureContext();
41851
+ ctx.font = font;
41852
+ const cache3 = getSegmentMetricCache(font);
41853
+ const fontSize = parseFontSize(font);
41854
+ const emojiCorrection = needsEmojiCorrection ? getEmojiCorrection(font, fontSize) : 0;
41855
+ return { cache: cache3, fontSize, emojiCorrection };
41856
+ }
41857
+ __name(getFontMeasurementState, "getFontMeasurementState");
41858
+
41859
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/line-break.js
41860
+ function normalizeSimpleLineStartSegmentIndex(prepared, segmentIndex) {
41861
+ while (segmentIndex < prepared.widths.length) {
41862
+ const kind = prepared.kinds[segmentIndex];
41863
+ if (kind !== "space" && kind !== "zero-width-break" && kind !== "soft-hyphen")
41864
+ break;
41865
+ segmentIndex++;
41866
+ }
41867
+ return segmentIndex;
41868
+ }
41869
+ __name(normalizeSimpleLineStartSegmentIndex, "normalizeSimpleLineStartSegmentIndex");
41870
+ function getTabAdvance(lineWidth, tabStopAdvance) {
41871
+ if (tabStopAdvance <= 0)
41872
+ return 0;
41873
+ const remainder = lineWidth % tabStopAdvance;
41874
+ if (Math.abs(remainder) <= 1e-6)
41875
+ return tabStopAdvance;
41876
+ return tabStopAdvance - remainder;
41877
+ }
41878
+ __name(getTabAdvance, "getTabAdvance");
41879
+ function fitSoftHyphenBreak(graphemeFitAdvances, initialWidth, maxWidth, lineFitEpsilon, discretionaryHyphenWidth) {
41880
+ let fitCount = 0;
41881
+ let fittedWidth = initialWidth;
41882
+ while (fitCount < graphemeFitAdvances.length) {
41883
+ const nextWidth = fittedWidth + graphemeFitAdvances[fitCount];
41884
+ const nextLineWidth = fitCount + 1 < graphemeFitAdvances.length ? nextWidth + discretionaryHyphenWidth : nextWidth;
41885
+ if (nextLineWidth > maxWidth + lineFitEpsilon)
41886
+ break;
41887
+ fittedWidth = nextWidth;
41888
+ fitCount++;
41889
+ }
41890
+ return { fitCount, fittedWidth };
41891
+ }
41892
+ __name(fitSoftHyphenBreak, "fitSoftHyphenBreak");
41893
+ function findChunkIndexForStart(prepared, segmentIndex) {
41894
+ let lo = 0;
41895
+ let hi = prepared.chunks.length;
41896
+ while (lo < hi) {
41897
+ const mid = Math.floor((lo + hi) / 2);
41898
+ if (segmentIndex < prepared.chunks[mid].consumedEndSegmentIndex) {
41899
+ hi = mid;
41900
+ } else {
41901
+ lo = mid + 1;
41902
+ }
41903
+ }
41904
+ return lo < prepared.chunks.length ? lo : -1;
41905
+ }
41906
+ __name(findChunkIndexForStart, "findChunkIndexForStart");
41907
+ function normalizeLineStartInChunk(prepared, chunkIndex, cursor) {
41908
+ let segmentIndex = cursor.segmentIndex;
41909
+ if (cursor.graphemeIndex > 0)
41910
+ return chunkIndex;
41911
+ const chunk = prepared.chunks[chunkIndex];
41912
+ if (chunk.startSegmentIndex === chunk.endSegmentIndex && segmentIndex === chunk.startSegmentIndex) {
41913
+ cursor.segmentIndex = segmentIndex;
41914
+ cursor.graphemeIndex = 0;
41915
+ return chunkIndex;
41916
+ }
41917
+ if (segmentIndex < chunk.startSegmentIndex)
41918
+ segmentIndex = chunk.startSegmentIndex;
41919
+ while (segmentIndex < chunk.endSegmentIndex) {
41920
+ const kind = prepared.kinds[segmentIndex];
41921
+ if (kind !== "space" && kind !== "zero-width-break" && kind !== "soft-hyphen") {
41922
+ cursor.segmentIndex = segmentIndex;
41923
+ cursor.graphemeIndex = 0;
41924
+ return chunkIndex;
41925
+ }
41926
+ segmentIndex++;
41927
+ }
41928
+ if (chunk.consumedEndSegmentIndex >= prepared.widths.length)
41929
+ return -1;
41930
+ cursor.segmentIndex = chunk.consumedEndSegmentIndex;
41931
+ cursor.graphemeIndex = 0;
41932
+ return chunkIndex + 1;
41933
+ }
41934
+ __name(normalizeLineStartInChunk, "normalizeLineStartInChunk");
41935
+ function normalizeLineStartChunkIndex(prepared, cursor) {
41936
+ if (cursor.segmentIndex >= prepared.widths.length)
41937
+ return -1;
41938
+ const chunkIndex = findChunkIndexForStart(prepared, cursor.segmentIndex);
41939
+ if (chunkIndex < 0)
41940
+ return -1;
41941
+ return normalizeLineStartInChunk(prepared, chunkIndex, cursor);
41942
+ }
41943
+ __name(normalizeLineStartChunkIndex, "normalizeLineStartChunkIndex");
41944
+ function walkPreparedLinesSimple(prepared, maxWidth, onLine) {
41945
+ const { widths, kinds, breakableFitAdvances } = prepared;
41946
+ if (widths.length === 0)
41947
+ return 0;
41948
+ const engineProfile = getEngineProfile();
41949
+ const lineFitEpsilon = engineProfile.lineFitEpsilon;
41950
+ const fitLimit = maxWidth + lineFitEpsilon;
41951
+ let lineCount = 0;
41952
+ let lineW = 0;
41953
+ let hasContent = false;
41954
+ let lineStartSegmentIndex = 0;
41955
+ let lineStartGraphemeIndex = 0;
41956
+ let lineEndSegmentIndex = 0;
41957
+ let lineEndGraphemeIndex = 0;
41958
+ let pendingBreakSegmentIndex = -1;
41959
+ let pendingBreakPaintWidth = 0;
41960
+ function clearPendingBreak() {
41961
+ pendingBreakSegmentIndex = -1;
41962
+ pendingBreakPaintWidth = 0;
41963
+ }
41964
+ __name(clearPendingBreak, "clearPendingBreak");
41965
+ function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width2 = lineW) {
41966
+ lineCount++;
41967
+ onLine?.({
41968
+ startSegmentIndex: lineStartSegmentIndex,
41969
+ startGraphemeIndex: lineStartGraphemeIndex,
41970
+ endSegmentIndex,
41971
+ endGraphemeIndex,
41972
+ width: width2
41973
+ });
41974
+ lineW = 0;
41975
+ hasContent = false;
41976
+ clearPendingBreak();
41977
+ }
41978
+ __name(emitCurrentLine, "emitCurrentLine");
41979
+ function startLineAtSegment(segmentIndex, width2) {
41980
+ hasContent = true;
41981
+ lineStartSegmentIndex = segmentIndex;
41982
+ lineStartGraphemeIndex = 0;
41983
+ lineEndSegmentIndex = segmentIndex + 1;
41984
+ lineEndGraphemeIndex = 0;
41985
+ lineW = width2;
41986
+ }
41987
+ __name(startLineAtSegment, "startLineAtSegment");
41988
+ function startLineAtGrapheme(segmentIndex, graphemeIndex, width2) {
41989
+ hasContent = true;
41990
+ lineStartSegmentIndex = segmentIndex;
41991
+ lineStartGraphemeIndex = graphemeIndex;
41992
+ lineEndSegmentIndex = segmentIndex;
41993
+ lineEndGraphemeIndex = graphemeIndex + 1;
41994
+ lineW = width2;
41995
+ }
41996
+ __name(startLineAtGrapheme, "startLineAtGrapheme");
41997
+ function appendWholeSegment(segmentIndex, width2) {
41998
+ if (!hasContent) {
41999
+ startLineAtSegment(segmentIndex, width2);
42000
+ return;
42001
+ }
42002
+ lineW += width2;
42003
+ lineEndSegmentIndex = segmentIndex + 1;
42004
+ lineEndGraphemeIndex = 0;
42005
+ }
42006
+ __name(appendWholeSegment, "appendWholeSegment");
42007
+ function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
42008
+ const fitAdvances = breakableFitAdvances[segmentIndex];
42009
+ for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
42010
+ const gw = fitAdvances[g];
42011
+ if (!hasContent) {
42012
+ startLineAtGrapheme(segmentIndex, g, gw);
42013
+ } else if (lineW + gw > fitLimit) {
42014
+ emitCurrentLine();
42015
+ startLineAtGrapheme(segmentIndex, g, gw);
42016
+ } else {
42017
+ lineW += gw;
42018
+ lineEndSegmentIndex = segmentIndex;
42019
+ lineEndGraphemeIndex = g + 1;
42020
+ }
42021
+ }
42022
+ if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
42023
+ lineEndSegmentIndex = segmentIndex + 1;
42024
+ lineEndGraphemeIndex = 0;
42025
+ }
42026
+ }
42027
+ __name(appendBreakableSegmentFrom, "appendBreakableSegmentFrom");
42028
+ let i = 0;
42029
+ while (i < widths.length) {
42030
+ if (!hasContent) {
42031
+ i = normalizeSimpleLineStartSegmentIndex(prepared, i);
42032
+ if (i >= widths.length)
42033
+ break;
42034
+ }
42035
+ const w = widths[i];
42036
+ const kind = kinds[i];
42037
+ const breakAfter = kind === "space" || kind === "preserved-space" || kind === "tab" || kind === "zero-width-break" || kind === "soft-hyphen";
42038
+ if (!hasContent) {
42039
+ if (w > maxWidth && breakableFitAdvances[i] !== null) {
42040
+ appendBreakableSegmentFrom(i, 0);
42041
+ } else {
42042
+ startLineAtSegment(i, w);
42043
+ }
42044
+ if (breakAfter) {
42045
+ pendingBreakSegmentIndex = i + 1;
42046
+ pendingBreakPaintWidth = lineW - w;
42047
+ }
42048
+ i++;
42049
+ continue;
42050
+ }
42051
+ const newW = lineW + w;
42052
+ if (newW > fitLimit) {
42053
+ if (breakAfter) {
42054
+ appendWholeSegment(i, w);
42055
+ emitCurrentLine(i + 1, 0, lineW - w);
42056
+ i++;
42057
+ continue;
42058
+ }
42059
+ if (pendingBreakSegmentIndex >= 0) {
42060
+ if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
42061
+ emitCurrentLine();
42062
+ continue;
42063
+ }
42064
+ emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
42065
+ continue;
42066
+ }
42067
+ if (w > maxWidth && breakableFitAdvances[i] !== null) {
42068
+ emitCurrentLine();
42069
+ appendBreakableSegmentFrom(i, 0);
42070
+ i++;
42071
+ continue;
42072
+ }
42073
+ emitCurrentLine();
42074
+ continue;
42075
+ }
42076
+ appendWholeSegment(i, w);
42077
+ if (breakAfter) {
42078
+ pendingBreakSegmentIndex = i + 1;
42079
+ pendingBreakPaintWidth = lineW - w;
42080
+ }
42081
+ i++;
42082
+ }
42083
+ if (hasContent)
42084
+ emitCurrentLine();
42085
+ return lineCount;
42086
+ }
42087
+ __name(walkPreparedLinesSimple, "walkPreparedLinesSimple");
42088
+ function walkPreparedLines(prepared, maxWidth, onLine) {
42089
+ if (prepared.simpleLineWalkFastPath) {
42090
+ return walkPreparedLinesSimple(prepared, maxWidth, onLine);
42091
+ }
42092
+ const { widths, lineEndFitAdvances, lineEndPaintAdvances, kinds, breakableFitAdvances, discretionaryHyphenWidth, tabStopAdvance, chunks } = prepared;
42093
+ if (widths.length === 0 || chunks.length === 0)
42094
+ return 0;
42095
+ const engineProfile = getEngineProfile();
42096
+ const lineFitEpsilon = engineProfile.lineFitEpsilon;
42097
+ const fitLimit = maxWidth + lineFitEpsilon;
42098
+ let lineCount = 0;
42099
+ let lineW = 0;
42100
+ let hasContent = false;
42101
+ let lineStartSegmentIndex = 0;
42102
+ let lineStartGraphemeIndex = 0;
42103
+ let lineEndSegmentIndex = 0;
42104
+ let lineEndGraphemeIndex = 0;
42105
+ let pendingBreakSegmentIndex = -1;
42106
+ let pendingBreakFitWidth = 0;
42107
+ let pendingBreakPaintWidth = 0;
42108
+ let pendingBreakKind = null;
42109
+ function clearPendingBreak() {
42110
+ pendingBreakSegmentIndex = -1;
42111
+ pendingBreakFitWidth = 0;
42112
+ pendingBreakPaintWidth = 0;
42113
+ pendingBreakKind = null;
42114
+ }
42115
+ __name(clearPendingBreak, "clearPendingBreak");
42116
+ function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width2 = lineW) {
42117
+ lineCount++;
42118
+ onLine?.({
42119
+ startSegmentIndex: lineStartSegmentIndex,
42120
+ startGraphemeIndex: lineStartGraphemeIndex,
42121
+ endSegmentIndex,
42122
+ endGraphemeIndex,
42123
+ width: width2
42124
+ });
42125
+ lineW = 0;
42126
+ hasContent = false;
42127
+ clearPendingBreak();
42128
+ }
42129
+ __name(emitCurrentLine, "emitCurrentLine");
42130
+ function startLineAtSegment(segmentIndex, width2) {
42131
+ hasContent = true;
42132
+ lineStartSegmentIndex = segmentIndex;
42133
+ lineStartGraphemeIndex = 0;
42134
+ lineEndSegmentIndex = segmentIndex + 1;
42135
+ lineEndGraphemeIndex = 0;
42136
+ lineW = width2;
42137
+ }
42138
+ __name(startLineAtSegment, "startLineAtSegment");
42139
+ function startLineAtGrapheme(segmentIndex, graphemeIndex, width2) {
42140
+ hasContent = true;
42141
+ lineStartSegmentIndex = segmentIndex;
42142
+ lineStartGraphemeIndex = graphemeIndex;
42143
+ lineEndSegmentIndex = segmentIndex;
42144
+ lineEndGraphemeIndex = graphemeIndex + 1;
42145
+ lineW = width2;
42146
+ }
42147
+ __name(startLineAtGrapheme, "startLineAtGrapheme");
42148
+ function appendWholeSegment(segmentIndex, width2) {
42149
+ if (!hasContent) {
42150
+ startLineAtSegment(segmentIndex, width2);
42151
+ return;
42152
+ }
42153
+ lineW += width2;
42154
+ lineEndSegmentIndex = segmentIndex + 1;
42155
+ lineEndGraphemeIndex = 0;
42156
+ }
42157
+ __name(appendWholeSegment, "appendWholeSegment");
42158
+ function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth) {
42159
+ if (!breakAfter)
42160
+ return;
42161
+ const fitAdvance = kind === "tab" ? 0 : lineEndFitAdvances[segmentIndex];
42162
+ const paintAdvance = kind === "tab" ? segmentWidth : lineEndPaintAdvances[segmentIndex];
42163
+ pendingBreakSegmentIndex = segmentIndex + 1;
42164
+ pendingBreakFitWidth = lineW - segmentWidth + fitAdvance;
42165
+ pendingBreakPaintWidth = lineW - segmentWidth + paintAdvance;
42166
+ pendingBreakKind = kind;
42167
+ }
42168
+ __name(updatePendingBreakForWholeSegment, "updatePendingBreakForWholeSegment");
42169
+ function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
42170
+ const fitAdvances = breakableFitAdvances[segmentIndex];
42171
+ for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
42172
+ const gw = fitAdvances[g];
42173
+ if (!hasContent) {
42174
+ startLineAtGrapheme(segmentIndex, g, gw);
42175
+ } else if (lineW + gw > fitLimit) {
42176
+ emitCurrentLine();
42177
+ startLineAtGrapheme(segmentIndex, g, gw);
42178
+ } else {
42179
+ lineW += gw;
42180
+ lineEndSegmentIndex = segmentIndex;
42181
+ lineEndGraphemeIndex = g + 1;
42182
+ }
42183
+ }
42184
+ if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
42185
+ lineEndSegmentIndex = segmentIndex + 1;
42186
+ lineEndGraphemeIndex = 0;
42187
+ }
42188
+ }
42189
+ __name(appendBreakableSegmentFrom, "appendBreakableSegmentFrom");
42190
+ function continueSoftHyphenBreakableSegment(segmentIndex) {
42191
+ if (pendingBreakKind !== "soft-hyphen")
42192
+ return false;
42193
+ const fitWidths = breakableFitAdvances[segmentIndex];
42194
+ if (fitWidths == null)
42195
+ return false;
42196
+ const { fitCount, fittedWidth } = fitSoftHyphenBreak(fitWidths, lineW, maxWidth, lineFitEpsilon, discretionaryHyphenWidth);
42197
+ if (fitCount === 0)
42198
+ return false;
42199
+ lineW = fittedWidth;
42200
+ lineEndSegmentIndex = segmentIndex;
42201
+ lineEndGraphemeIndex = fitCount;
42202
+ clearPendingBreak();
42203
+ if (fitCount === fitWidths.length) {
42204
+ lineEndSegmentIndex = segmentIndex + 1;
42205
+ lineEndGraphemeIndex = 0;
42206
+ return true;
42207
+ }
42208
+ emitCurrentLine(segmentIndex, fitCount, fittedWidth + discretionaryHyphenWidth);
42209
+ appendBreakableSegmentFrom(segmentIndex, fitCount);
42210
+ return true;
42211
+ }
42212
+ __name(continueSoftHyphenBreakableSegment, "continueSoftHyphenBreakableSegment");
42213
+ function emitEmptyChunk(chunk) {
42214
+ lineCount++;
42215
+ onLine?.({
42216
+ startSegmentIndex: chunk.startSegmentIndex,
42217
+ startGraphemeIndex: 0,
42218
+ endSegmentIndex: chunk.consumedEndSegmentIndex,
42219
+ endGraphemeIndex: 0,
42220
+ width: 0
42221
+ });
42222
+ clearPendingBreak();
42223
+ }
42224
+ __name(emitEmptyChunk, "emitEmptyChunk");
42225
+ for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
42226
+ const chunk = chunks[chunkIndex];
42227
+ if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
42228
+ emitEmptyChunk(chunk);
42229
+ continue;
42230
+ }
42231
+ hasContent = false;
42232
+ lineW = 0;
42233
+ lineStartSegmentIndex = chunk.startSegmentIndex;
42234
+ lineStartGraphemeIndex = 0;
42235
+ lineEndSegmentIndex = chunk.startSegmentIndex;
42236
+ lineEndGraphemeIndex = 0;
42237
+ clearPendingBreak();
42238
+ let i = chunk.startSegmentIndex;
42239
+ while (i < chunk.endSegmentIndex) {
42240
+ const kind = kinds[i];
42241
+ const breakAfter = kind === "space" || kind === "preserved-space" || kind === "tab" || kind === "zero-width-break" || kind === "soft-hyphen";
42242
+ const w = kind === "tab" ? getTabAdvance(lineW, tabStopAdvance) : widths[i];
42243
+ if (kind === "soft-hyphen") {
42244
+ if (hasContent) {
42245
+ lineEndSegmentIndex = i + 1;
42246
+ lineEndGraphemeIndex = 0;
42247
+ pendingBreakSegmentIndex = i + 1;
42248
+ pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
42249
+ pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
42250
+ pendingBreakKind = kind;
42251
+ }
42252
+ i++;
42253
+ continue;
42254
+ }
42255
+ if (!hasContent) {
42256
+ if (w > maxWidth && breakableFitAdvances[i] !== null) {
42257
+ appendBreakableSegmentFrom(i, 0);
42258
+ } else {
42259
+ startLineAtSegment(i, w);
42260
+ }
42261
+ updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
42262
+ i++;
42263
+ continue;
42264
+ }
42265
+ const newW = lineW + w;
42266
+ if (newW > fitLimit) {
42267
+ const currentBreakFitWidth = lineW + (kind === "tab" ? 0 : lineEndFitAdvances[i]);
42268
+ const currentBreakPaintWidth = lineW + (kind === "tab" ? w : lineEndPaintAdvances[i]);
42269
+ if (pendingBreakKind === "soft-hyphen" && engineProfile.preferEarlySoftHyphenBreak && pendingBreakFitWidth <= fitLimit) {
42270
+ emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
42271
+ continue;
42272
+ }
42273
+ if (pendingBreakKind === "soft-hyphen" && continueSoftHyphenBreakableSegment(i)) {
42274
+ i++;
42275
+ continue;
42276
+ }
42277
+ if (breakAfter && currentBreakFitWidth <= fitLimit) {
42278
+ appendWholeSegment(i, w);
42279
+ emitCurrentLine(i + 1, 0, currentBreakPaintWidth);
42280
+ i++;
42281
+ continue;
42282
+ }
42283
+ if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
42284
+ if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
42285
+ emitCurrentLine();
42286
+ continue;
42287
+ }
42288
+ const nextSegmentIndex = pendingBreakSegmentIndex;
42289
+ emitCurrentLine(nextSegmentIndex, 0, pendingBreakPaintWidth);
42290
+ i = nextSegmentIndex;
42291
+ continue;
42292
+ }
42293
+ if (w > maxWidth && breakableFitAdvances[i] !== null) {
42294
+ emitCurrentLine();
42295
+ appendBreakableSegmentFrom(i, 0);
42296
+ i++;
42297
+ continue;
42298
+ }
42299
+ emitCurrentLine();
42300
+ continue;
42301
+ }
42302
+ appendWholeSegment(i, w);
42303
+ updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
42304
+ i++;
42305
+ }
42306
+ if (hasContent) {
42307
+ const finalPaintWidth = pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex ? pendingBreakPaintWidth : lineW;
42308
+ emitCurrentLine(chunk.consumedEndSegmentIndex, 0, finalPaintWidth);
42309
+ }
42310
+ }
42311
+ return lineCount;
42312
+ }
42313
+ __name(walkPreparedLines, "walkPreparedLines");
42314
+ function stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth) {
42315
+ const chunk = prepared.chunks[chunkIndex];
42316
+ if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
42317
+ cursor.segmentIndex = chunk.consumedEndSegmentIndex;
42318
+ cursor.graphemeIndex = 0;
42319
+ return 0;
42320
+ }
42321
+ const { widths, lineEndFitAdvances, lineEndPaintAdvances, kinds, breakableFitAdvances, discretionaryHyphenWidth, tabStopAdvance } = prepared;
42322
+ const engineProfile = getEngineProfile();
42323
+ const lineFitEpsilon = engineProfile.lineFitEpsilon;
42324
+ const fitLimit = maxWidth + lineFitEpsilon;
42325
+ let lineW = 0;
42326
+ let hasContent = false;
42327
+ let lineEndSegmentIndex = cursor.segmentIndex;
42328
+ let lineEndGraphemeIndex = cursor.graphemeIndex;
42329
+ let pendingBreakSegmentIndex = -1;
42330
+ let pendingBreakFitWidth = 0;
42331
+ let pendingBreakPaintWidth = 0;
42332
+ let pendingBreakKind = null;
42333
+ function clearPendingBreak() {
42334
+ pendingBreakSegmentIndex = -1;
42335
+ pendingBreakFitWidth = 0;
42336
+ pendingBreakPaintWidth = 0;
42337
+ pendingBreakKind = null;
42338
+ }
42339
+ __name(clearPendingBreak, "clearPendingBreak");
42340
+ function finishLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width2 = lineW) {
42341
+ if (!hasContent)
42342
+ return null;
42343
+ cursor.segmentIndex = endSegmentIndex;
42344
+ cursor.graphemeIndex = endGraphemeIndex;
42345
+ return width2;
42346
+ }
42347
+ __name(finishLine, "finishLine");
42348
+ function startLineAtSegment(segmentIndex, width2) {
42349
+ hasContent = true;
42350
+ lineEndSegmentIndex = segmentIndex + 1;
42351
+ lineEndGraphemeIndex = 0;
42352
+ lineW = width2;
42353
+ }
42354
+ __name(startLineAtSegment, "startLineAtSegment");
42355
+ function startLineAtGrapheme(segmentIndex, graphemeIndex, width2) {
42356
+ hasContent = true;
42357
+ lineEndSegmentIndex = segmentIndex;
42358
+ lineEndGraphemeIndex = graphemeIndex + 1;
42359
+ lineW = width2;
42360
+ }
42361
+ __name(startLineAtGrapheme, "startLineAtGrapheme");
42362
+ function appendWholeSegment(segmentIndex, width2) {
42363
+ if (!hasContent) {
42364
+ startLineAtSegment(segmentIndex, width2);
42365
+ return;
42366
+ }
42367
+ lineW += width2;
42368
+ lineEndSegmentIndex = segmentIndex + 1;
42369
+ lineEndGraphemeIndex = 0;
42370
+ }
42371
+ __name(appendWholeSegment, "appendWholeSegment");
42372
+ function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth) {
42373
+ if (!breakAfter)
42374
+ return;
42375
+ const fitAdvance = kind === "tab" ? 0 : lineEndFitAdvances[segmentIndex];
42376
+ const paintAdvance = kind === "tab" ? segmentWidth : lineEndPaintAdvances[segmentIndex];
42377
+ pendingBreakSegmentIndex = segmentIndex + 1;
42378
+ pendingBreakFitWidth = lineW - segmentWidth + fitAdvance;
42379
+ pendingBreakPaintWidth = lineW - segmentWidth + paintAdvance;
42380
+ pendingBreakKind = kind;
42381
+ }
42382
+ __name(updatePendingBreakForWholeSegment, "updatePendingBreakForWholeSegment");
42383
+ function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
42384
+ const fitAdvances = breakableFitAdvances[segmentIndex];
42385
+ for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
42386
+ const gw = fitAdvances[g];
42387
+ if (!hasContent) {
42388
+ startLineAtGrapheme(segmentIndex, g, gw);
42389
+ } else {
42390
+ if (lineW + gw > fitLimit) {
42391
+ return finishLine();
42392
+ }
42393
+ lineW += gw;
42394
+ lineEndSegmentIndex = segmentIndex;
42395
+ lineEndGraphemeIndex = g + 1;
42396
+ }
42397
+ }
42398
+ if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
42399
+ lineEndSegmentIndex = segmentIndex + 1;
42400
+ lineEndGraphemeIndex = 0;
42401
+ }
42402
+ return null;
42403
+ }
42404
+ __name(appendBreakableSegmentFrom, "appendBreakableSegmentFrom");
42405
+ function maybeFinishAtSoftHyphen(segmentIndex) {
42406
+ if (pendingBreakKind !== "soft-hyphen" || pendingBreakSegmentIndex < 0)
42407
+ return null;
42408
+ const fitWidths = breakableFitAdvances[segmentIndex] ?? null;
42409
+ if (fitWidths !== null) {
42410
+ const { fitCount, fittedWidth } = fitSoftHyphenBreak(fitWidths, lineW, maxWidth, lineFitEpsilon, discretionaryHyphenWidth);
42411
+ if (fitCount === fitWidths.length) {
42412
+ lineW = fittedWidth;
42413
+ lineEndSegmentIndex = segmentIndex + 1;
42414
+ lineEndGraphemeIndex = 0;
42415
+ clearPendingBreak();
42416
+ return null;
42417
+ }
42418
+ if (fitCount > 0) {
42419
+ return finishLine(segmentIndex, fitCount, fittedWidth + discretionaryHyphenWidth);
42420
+ }
42421
+ }
42422
+ if (pendingBreakFitWidth <= fitLimit) {
42423
+ return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
42424
+ }
42425
+ return null;
42426
+ }
42427
+ __name(maybeFinishAtSoftHyphen, "maybeFinishAtSoftHyphen");
42428
+ for (let i = cursor.segmentIndex; i < chunk.endSegmentIndex; i++) {
42429
+ const kind = kinds[i];
42430
+ const breakAfter = kind === "space" || kind === "preserved-space" || kind === "tab" || kind === "zero-width-break" || kind === "soft-hyphen";
42431
+ const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
42432
+ const w = kind === "tab" ? getTabAdvance(lineW, tabStopAdvance) : widths[i];
42433
+ if (kind === "soft-hyphen" && startGraphemeIndex === 0) {
42434
+ if (hasContent) {
42435
+ lineEndSegmentIndex = i + 1;
42436
+ lineEndGraphemeIndex = 0;
42437
+ pendingBreakSegmentIndex = i + 1;
42438
+ pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
42439
+ pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
42440
+ pendingBreakKind = kind;
42441
+ }
42442
+ continue;
42443
+ }
42444
+ if (!hasContent) {
42445
+ if (startGraphemeIndex > 0) {
42446
+ const line2 = appendBreakableSegmentFrom(i, startGraphemeIndex);
42447
+ if (line2 !== null)
42448
+ return line2;
42449
+ } else if (w > maxWidth && breakableFitAdvances[i] !== null) {
42450
+ const line2 = appendBreakableSegmentFrom(i, 0);
42451
+ if (line2 !== null)
42452
+ return line2;
42453
+ } else {
42454
+ startLineAtSegment(i, w);
42455
+ }
42456
+ updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
42457
+ continue;
42458
+ }
42459
+ const newW = lineW + w;
42460
+ if (newW > fitLimit) {
42461
+ const currentBreakFitWidth = lineW + (kind === "tab" ? 0 : lineEndFitAdvances[i]);
42462
+ const currentBreakPaintWidth = lineW + (kind === "tab" ? w : lineEndPaintAdvances[i]);
42463
+ if (pendingBreakKind === "soft-hyphen" && engineProfile.preferEarlySoftHyphenBreak && pendingBreakFitWidth <= fitLimit) {
42464
+ return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
42465
+ }
42466
+ const softBreakLine = maybeFinishAtSoftHyphen(i);
42467
+ if (softBreakLine !== null)
42468
+ return softBreakLine;
42469
+ if (breakAfter && currentBreakFitWidth <= fitLimit) {
42470
+ appendWholeSegment(i, w);
42471
+ return finishLine(i + 1, 0, currentBreakPaintWidth);
42472
+ }
42473
+ if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
42474
+ if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
42475
+ return finishLine();
42476
+ }
42477
+ return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
42478
+ }
42479
+ if (w > maxWidth && breakableFitAdvances[i] !== null) {
42480
+ const currentLine = finishLine();
42481
+ if (currentLine !== null)
42482
+ return currentLine;
42483
+ const line2 = appendBreakableSegmentFrom(i, 0);
42484
+ if (line2 !== null)
42485
+ return line2;
42486
+ }
42487
+ return finishLine();
42488
+ }
42489
+ appendWholeSegment(i, w);
42490
+ updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
42491
+ }
42492
+ if (pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex && lineEndGraphemeIndex === 0) {
42493
+ return finishLine(chunk.consumedEndSegmentIndex, 0, pendingBreakPaintWidth);
42494
+ }
42495
+ return finishLine(chunk.consumedEndSegmentIndex, 0, lineW);
42496
+ }
42497
+ __name(stepPreparedChunkLineGeometry, "stepPreparedChunkLineGeometry");
42498
+ function stepPreparedSimpleLineGeometry(prepared, cursor, maxWidth) {
42499
+ const { widths, kinds, breakableFitAdvances } = prepared;
42500
+ const engineProfile = getEngineProfile();
42501
+ const lineFitEpsilon = engineProfile.lineFitEpsilon;
42502
+ const fitLimit = maxWidth + lineFitEpsilon;
42503
+ let lineW = 0;
42504
+ let hasContent = false;
42505
+ let lineEndSegmentIndex = cursor.segmentIndex;
42506
+ let lineEndGraphemeIndex = cursor.graphemeIndex;
42507
+ let pendingBreakSegmentIndex = -1;
42508
+ let pendingBreakPaintWidth = 0;
42509
+ for (let i = cursor.segmentIndex; i < widths.length; i++) {
42510
+ const w = widths[i];
42511
+ const kind = kinds[i];
42512
+ const breakAfter = kind === "space" || kind === "preserved-space" || kind === "tab" || kind === "zero-width-break" || kind === "soft-hyphen";
42513
+ const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
42514
+ const breakableFitAdvance = breakableFitAdvances[i];
42515
+ if (!hasContent) {
42516
+ if (startGraphemeIndex > 0 || w > maxWidth && breakableFitAdvance !== null) {
42517
+ const fitAdvances = breakableFitAdvance;
42518
+ const firstGraphemeWidth = fitAdvances[startGraphemeIndex];
42519
+ hasContent = true;
42520
+ lineW = firstGraphemeWidth;
42521
+ lineEndSegmentIndex = i;
42522
+ lineEndGraphemeIndex = startGraphemeIndex + 1;
42523
+ for (let g = startGraphemeIndex + 1; g < fitAdvances.length; g++) {
42524
+ const gw = fitAdvances[g];
42525
+ if (lineW + gw > fitLimit) {
42526
+ cursor.segmentIndex = lineEndSegmentIndex;
42527
+ cursor.graphemeIndex = lineEndGraphemeIndex;
42528
+ return lineW;
42529
+ }
42530
+ lineW += gw;
42531
+ lineEndSegmentIndex = i;
42532
+ lineEndGraphemeIndex = g + 1;
42533
+ }
42534
+ if (lineEndSegmentIndex === i && lineEndGraphemeIndex === fitAdvances.length) {
42535
+ lineEndSegmentIndex = i + 1;
42536
+ lineEndGraphemeIndex = 0;
42537
+ }
42538
+ } else {
42539
+ hasContent = true;
42540
+ lineW = w;
42541
+ lineEndSegmentIndex = i + 1;
42542
+ lineEndGraphemeIndex = 0;
42543
+ }
42544
+ if (breakAfter) {
42545
+ pendingBreakSegmentIndex = i + 1;
42546
+ pendingBreakPaintWidth = lineW - w;
42547
+ }
42548
+ continue;
42549
+ }
42550
+ if (lineW + w > fitLimit) {
42551
+ if (breakAfter) {
42552
+ cursor.segmentIndex = i + 1;
42553
+ cursor.graphemeIndex = 0;
42554
+ return lineW;
42555
+ }
42556
+ if (pendingBreakSegmentIndex >= 0) {
42557
+ if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
42558
+ cursor.segmentIndex = lineEndSegmentIndex;
42559
+ cursor.graphemeIndex = lineEndGraphemeIndex;
42560
+ return lineW;
42561
+ }
42562
+ cursor.segmentIndex = pendingBreakSegmentIndex;
42563
+ cursor.graphemeIndex = 0;
42564
+ return pendingBreakPaintWidth;
42565
+ }
42566
+ cursor.segmentIndex = lineEndSegmentIndex;
42567
+ cursor.graphemeIndex = lineEndGraphemeIndex;
42568
+ return lineW;
42569
+ }
42570
+ lineW += w;
42571
+ lineEndSegmentIndex = i + 1;
42572
+ lineEndGraphemeIndex = 0;
42573
+ if (breakAfter) {
42574
+ pendingBreakSegmentIndex = i + 1;
42575
+ pendingBreakPaintWidth = lineW - w;
42576
+ }
42577
+ }
42578
+ if (!hasContent)
42579
+ return null;
42580
+ cursor.segmentIndex = lineEndSegmentIndex;
42581
+ cursor.graphemeIndex = lineEndGraphemeIndex;
42582
+ return lineW;
42583
+ }
42584
+ __name(stepPreparedSimpleLineGeometry, "stepPreparedSimpleLineGeometry");
42585
+ function layoutNextLineRange(prepared, start, maxWidth) {
42586
+ const end = {
42587
+ segmentIndex: start.segmentIndex,
42588
+ graphemeIndex: start.graphemeIndex
42589
+ };
42590
+ const chunkIndex = normalizeLineStartChunkIndex(prepared, end);
42591
+ if (chunkIndex < 0)
42592
+ return null;
42593
+ const lineStartSegmentIndex = end.segmentIndex;
42594
+ const lineStartGraphemeIndex = end.graphemeIndex;
42595
+ const width2 = prepared.simpleLineWalkFastPath ? stepPreparedSimpleLineGeometry(prepared, end, maxWidth) : stepPreparedChunkLineGeometry(prepared, end, chunkIndex, maxWidth);
42596
+ if (width2 === null)
42597
+ return null;
42598
+ return {
42599
+ startSegmentIndex: lineStartSegmentIndex,
42600
+ startGraphemeIndex: lineStartGraphemeIndex,
42601
+ endSegmentIndex: end.segmentIndex,
42602
+ endGraphemeIndex: end.graphemeIndex,
42603
+ width: width2
42604
+ };
42605
+ }
42606
+ __name(layoutNextLineRange, "layoutNextLineRange");
42607
+
42608
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/layout.js
42609
+ var sharedGraphemeSegmenter2 = null;
42610
+ var sharedLineTextCaches = /* @__PURE__ */ new WeakMap();
42611
+ function getSharedGraphemeSegmenter2() {
42612
+ if (sharedGraphemeSegmenter2 === null) {
42613
+ sharedGraphemeSegmenter2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
42614
+ }
42615
+ return sharedGraphemeSegmenter2;
42616
+ }
42617
+ __name(getSharedGraphemeSegmenter2, "getSharedGraphemeSegmenter");
42618
+ function createEmptyPrepared(includeSegments) {
42619
+ if (includeSegments) {
42620
+ return {
42621
+ widths: [],
42622
+ lineEndFitAdvances: [],
42623
+ lineEndPaintAdvances: [],
42624
+ kinds: [],
42625
+ simpleLineWalkFastPath: true,
42626
+ segLevels: null,
42627
+ breakableFitAdvances: [],
42628
+ discretionaryHyphenWidth: 0,
42629
+ tabStopAdvance: 0,
42630
+ chunks: [],
42631
+ segments: []
42632
+ };
42633
+ }
42634
+ return {
42635
+ widths: [],
42636
+ lineEndFitAdvances: [],
42637
+ lineEndPaintAdvances: [],
42638
+ kinds: [],
42639
+ simpleLineWalkFastPath: true,
42640
+ segLevels: null,
42641
+ breakableFitAdvances: [],
42642
+ discretionaryHyphenWidth: 0,
42643
+ tabStopAdvance: 0,
42644
+ chunks: []
42645
+ };
42646
+ }
42647
+ __name(createEmptyPrepared, "createEmptyPrepared");
42648
+ function buildBaseCjkUnits(segText, engineProfile) {
42649
+ const units = [];
42650
+ let unitParts = [];
42651
+ let unitStart = 0;
42652
+ let unitContainsCJK = false;
42653
+ let unitEndsWithClosingQuote = false;
42654
+ let unitIsSingleKinsokuEnd = false;
42655
+ function pushUnit() {
42656
+ if (unitParts.length === 0)
42657
+ return;
42658
+ units.push({
42659
+ text: unitParts.length === 1 ? unitParts[0] : unitParts.join(""),
42660
+ start: unitStart
42661
+ });
42662
+ unitParts = [];
42663
+ unitContainsCJK = false;
42664
+ unitEndsWithClosingQuote = false;
42665
+ unitIsSingleKinsokuEnd = false;
42666
+ }
42667
+ __name(pushUnit, "pushUnit");
42668
+ function startUnit(grapheme, start, graphemeContainsCJK) {
42669
+ unitParts = [grapheme];
42670
+ unitStart = start;
42671
+ unitContainsCJK = graphemeContainsCJK;
42672
+ unitEndsWithClosingQuote = endsWithClosingQuote(grapheme);
42673
+ unitIsSingleKinsokuEnd = kinsokuEnd.has(grapheme);
42674
+ }
42675
+ __name(startUnit, "startUnit");
42676
+ function appendToUnit(grapheme, graphemeContainsCJK) {
42677
+ unitParts.push(grapheme);
42678
+ unitContainsCJK = unitContainsCJK || graphemeContainsCJK;
42679
+ const graphemeEndsWithClosingQuote = endsWithClosingQuote(grapheme);
42680
+ if (grapheme.length === 1 && leftStickyPunctuation.has(grapheme)) {
42681
+ unitEndsWithClosingQuote = unitEndsWithClosingQuote || graphemeEndsWithClosingQuote;
42682
+ } else {
42683
+ unitEndsWithClosingQuote = graphemeEndsWithClosingQuote;
42684
+ }
42685
+ unitIsSingleKinsokuEnd = false;
42686
+ }
42687
+ __name(appendToUnit, "appendToUnit");
42688
+ for (const gs of getSharedGraphemeSegmenter2().segment(segText)) {
42689
+ const grapheme = gs.segment;
42690
+ const graphemeContainsCJK = isCJK(grapheme);
42691
+ if (unitParts.length === 0) {
42692
+ startUnit(grapheme, gs.index, graphemeContainsCJK);
42693
+ continue;
42694
+ }
42695
+ if (unitIsSingleKinsokuEnd || kinsokuStart.has(grapheme) || leftStickyPunctuation.has(grapheme) || engineProfile.carryCJKAfterClosingQuote && graphemeContainsCJK && unitEndsWithClosingQuote) {
42696
+ appendToUnit(grapheme, graphemeContainsCJK);
42697
+ continue;
42698
+ }
42699
+ if (!unitContainsCJK && !graphemeContainsCJK) {
42700
+ appendToUnit(grapheme, graphemeContainsCJK);
42701
+ continue;
42702
+ }
42703
+ pushUnit();
42704
+ startUnit(grapheme, gs.index, graphemeContainsCJK);
42705
+ }
42706
+ pushUnit();
42707
+ return units;
42708
+ }
42709
+ __name(buildBaseCjkUnits, "buildBaseCjkUnits");
42710
+ function mergeKeepAllTextUnits(units) {
42711
+ if (units.length <= 1)
42712
+ return units;
42713
+ const merged = [];
42714
+ let currentTextParts = [units[0].text];
42715
+ let currentStart = units[0].start;
42716
+ let currentContainsCJK = isCJK(units[0].text);
42717
+ let currentCanContinue = canContinueKeepAllTextRun(units[0].text);
42718
+ function flushCurrent() {
42719
+ merged.push({
42720
+ text: currentTextParts.length === 1 ? currentTextParts[0] : currentTextParts.join(""),
42721
+ start: currentStart
42722
+ });
42723
+ }
42724
+ __name(flushCurrent, "flushCurrent");
42725
+ for (let i = 1; i < units.length; i++) {
42726
+ const next3 = units[i];
42727
+ const nextContainsCJK = isCJK(next3.text);
42728
+ const nextCanContinue = canContinueKeepAllTextRun(next3.text);
42729
+ if (currentContainsCJK && currentCanContinue) {
42730
+ currentTextParts.push(next3.text);
42731
+ currentContainsCJK = currentContainsCJK || nextContainsCJK;
42732
+ currentCanContinue = nextCanContinue;
42733
+ continue;
42734
+ }
42735
+ flushCurrent();
42736
+ currentTextParts = [next3.text];
42737
+ currentStart = next3.start;
42738
+ currentContainsCJK = nextContainsCJK;
42739
+ currentCanContinue = nextCanContinue;
42740
+ }
42741
+ flushCurrent();
42742
+ return merged;
42743
+ }
42744
+ __name(mergeKeepAllTextUnits, "mergeKeepAllTextUnits");
42745
+ function measureAnalysis(analysis, font, includeSegments, wordBreak) {
42746
+ const engineProfile = getEngineProfile();
42747
+ const { cache: cache3, emojiCorrection } = getFontMeasurementState(font, textMayContainEmoji(analysis.normalized));
42748
+ const discretionaryHyphenWidth = getCorrectedSegmentWidth("-", getSegmentMetrics("-", cache3), emojiCorrection);
42749
+ const spaceWidth = getCorrectedSegmentWidth(" ", getSegmentMetrics(" ", cache3), emojiCorrection);
42750
+ const tabStopAdvance = spaceWidth * 8;
42751
+ if (analysis.len === 0)
42752
+ return createEmptyPrepared(includeSegments);
42753
+ const widths = [];
42754
+ const lineEndFitAdvances = [];
42755
+ const lineEndPaintAdvances = [];
42756
+ const kinds = [];
42757
+ let simpleLineWalkFastPath = analysis.chunks.length <= 1;
42758
+ const segStarts = includeSegments ? [] : null;
42759
+ const breakableFitAdvances = [];
42760
+ const segments = includeSegments ? [] : null;
42761
+ const preparedStartByAnalysisIndex = Array.from({ length: analysis.len });
42762
+ function pushMeasuredSegment(text2, width2, lineEndFitAdvance, lineEndPaintAdvance, kind, start, breakableFitAdvance) {
42763
+ if (kind !== "text" && kind !== "space" && kind !== "zero-width-break") {
42764
+ simpleLineWalkFastPath = false;
42765
+ }
42766
+ widths.push(width2);
42767
+ lineEndFitAdvances.push(lineEndFitAdvance);
42768
+ lineEndPaintAdvances.push(lineEndPaintAdvance);
42769
+ kinds.push(kind);
42770
+ segStarts?.push(start);
42771
+ breakableFitAdvances.push(breakableFitAdvance);
42772
+ if (segments !== null)
42773
+ segments.push(text2);
42774
+ }
42775
+ __name(pushMeasuredSegment, "pushMeasuredSegment");
42776
+ function pushMeasuredTextSegment(text2, kind, start, wordLike, allowOverflowBreaks) {
42777
+ const textMetrics = getSegmentMetrics(text2, cache3);
42778
+ const width2 = getCorrectedSegmentWidth(text2, textMetrics, emojiCorrection);
42779
+ const lineEndFitAdvance = kind === "space" || kind === "preserved-space" || kind === "zero-width-break" ? 0 : width2;
42780
+ const lineEndPaintAdvance = kind === "space" || kind === "zero-width-break" ? 0 : width2;
42781
+ if (allowOverflowBreaks && wordLike && text2.length > 1) {
42782
+ let fitMode = "sum-graphemes";
42783
+ if (isNumericRunSegment(text2)) {
42784
+ fitMode = "pair-context";
42785
+ } else if (engineProfile.preferPrefixWidthsForBreakableRuns) {
42786
+ fitMode = "segment-prefixes";
42787
+ }
42788
+ const fitAdvances = getSegmentBreakableFitAdvances(text2, textMetrics, cache3, emojiCorrection, fitMode);
42789
+ pushMeasuredSegment(text2, width2, lineEndFitAdvance, lineEndPaintAdvance, kind, start, fitAdvances);
42790
+ return;
42791
+ }
42792
+ pushMeasuredSegment(text2, width2, lineEndFitAdvance, lineEndPaintAdvance, kind, start, null);
42793
+ }
42794
+ __name(pushMeasuredTextSegment, "pushMeasuredTextSegment");
42795
+ for (let mi = 0; mi < analysis.len; mi++) {
42796
+ preparedStartByAnalysisIndex[mi] = widths.length;
42797
+ const segText = analysis.texts[mi];
42798
+ const segWordLike = analysis.isWordLike[mi];
42799
+ const segKind = analysis.kinds[mi];
42800
+ const segStart = analysis.starts[mi];
42801
+ if (segKind === "soft-hyphen") {
42802
+ pushMeasuredSegment(segText, 0, discretionaryHyphenWidth, discretionaryHyphenWidth, segKind, segStart, null);
42803
+ continue;
42804
+ }
42805
+ if (segKind === "hard-break") {
42806
+ pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null);
42807
+ continue;
42808
+ }
42809
+ if (segKind === "tab") {
42810
+ pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null);
42811
+ continue;
42812
+ }
42813
+ const segMetrics = getSegmentMetrics(segText, cache3);
42814
+ if (segKind === "text" && segMetrics.containsCJK) {
42815
+ const baseUnits = buildBaseCjkUnits(segText, engineProfile);
42816
+ const measuredUnits = wordBreak === "keep-all" ? mergeKeepAllTextUnits(baseUnits) : baseUnits;
42817
+ for (let i = 0; i < measuredUnits.length; i++) {
42818
+ const unit = measuredUnits[i];
42819
+ pushMeasuredTextSegment(unit.text, "text", segStart + unit.start, segWordLike, wordBreak === "keep-all" || !isCJK(unit.text));
42820
+ }
42821
+ continue;
42822
+ }
42823
+ pushMeasuredTextSegment(segText, segKind, segStart, segWordLike, true);
42824
+ }
42825
+ const chunks = mapAnalysisChunksToPreparedChunks(analysis.chunks, preparedStartByAnalysisIndex, widths.length);
42826
+ const segLevels = segStarts === null ? null : computeSegmentLevels(analysis.normalized, segStarts);
42827
+ if (segments !== null) {
42828
+ return {
42829
+ widths,
42830
+ lineEndFitAdvances,
42831
+ lineEndPaintAdvances,
42832
+ kinds,
42833
+ simpleLineWalkFastPath,
42834
+ segLevels,
42835
+ breakableFitAdvances,
42836
+ discretionaryHyphenWidth,
42837
+ tabStopAdvance,
42838
+ chunks,
42839
+ segments
42840
+ };
42841
+ }
42842
+ return {
42843
+ widths,
42844
+ lineEndFitAdvances,
42845
+ lineEndPaintAdvances,
42846
+ kinds,
42847
+ simpleLineWalkFastPath,
42848
+ segLevels,
42849
+ breakableFitAdvances,
42850
+ discretionaryHyphenWidth,
42851
+ tabStopAdvance,
42852
+ chunks
42853
+ };
42854
+ }
42855
+ __name(measureAnalysis, "measureAnalysis");
42856
+ function mapAnalysisChunksToPreparedChunks(chunks, preparedStartByAnalysisIndex, preparedEndSegmentIndex) {
42857
+ const preparedChunks = [];
42858
+ for (let i = 0; i < chunks.length; i++) {
42859
+ const chunk = chunks[i];
42860
+ const startSegmentIndex = chunk.startSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.startSegmentIndex] : preparedEndSegmentIndex;
42861
+ const endSegmentIndex = chunk.endSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.endSegmentIndex] : preparedEndSegmentIndex;
42862
+ const consumedEndSegmentIndex = chunk.consumedEndSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.consumedEndSegmentIndex] : preparedEndSegmentIndex;
42863
+ preparedChunks.push({
42864
+ startSegmentIndex,
42865
+ endSegmentIndex,
42866
+ consumedEndSegmentIndex
42867
+ });
42868
+ }
42869
+ return preparedChunks;
42870
+ }
42871
+ __name(mapAnalysisChunksToPreparedChunks, "mapAnalysisChunksToPreparedChunks");
42872
+ function prepareInternal(text2, font, includeSegments, options2) {
42873
+ const wordBreak = options2?.wordBreak ?? "normal";
42874
+ const analysis = analyzeText(text2, getEngineProfile(), options2?.whiteSpace, wordBreak);
42875
+ return measureAnalysis(analysis, font, includeSegments, wordBreak);
42876
+ }
42877
+ __name(prepareInternal, "prepareInternal");
42878
+ function prepareWithSegments(text2, font, options2) {
42879
+ return prepareInternal(text2, font, true, options2);
42880
+ }
42881
+ __name(prepareWithSegments, "prepareWithSegments");
42882
+ function getInternalPrepared(prepared) {
42883
+ return prepared;
42884
+ }
42885
+ __name(getInternalPrepared, "getInternalPrepared");
42886
+ function getSegmentGraphemes(segmentIndex, segments, cache3) {
42887
+ let graphemes = cache3.get(segmentIndex);
42888
+ if (graphemes !== void 0)
42889
+ return graphemes;
42890
+ graphemes = [];
42891
+ const graphemeSegmenter = getSharedGraphemeSegmenter2();
42892
+ for (const gs of graphemeSegmenter.segment(segments[segmentIndex])) {
42893
+ graphemes.push(gs.segment);
42894
+ }
42895
+ cache3.set(segmentIndex, graphemes);
42896
+ return graphemes;
42897
+ }
42898
+ __name(getSegmentGraphemes, "getSegmentGraphemes");
42899
+ function getLineTextCache(prepared) {
42900
+ let cache3 = sharedLineTextCaches.get(prepared);
42901
+ if (cache3 !== void 0)
42902
+ return cache3;
42903
+ cache3 = /* @__PURE__ */ new Map();
42904
+ sharedLineTextCaches.set(prepared, cache3);
42905
+ return cache3;
42906
+ }
42907
+ __name(getLineTextCache, "getLineTextCache");
42908
+ function lineHasDiscretionaryHyphen(kinds, startSegmentIndex, startGraphemeIndex, endSegmentIndex) {
42909
+ return endSegmentIndex > 0 && kinds[endSegmentIndex - 1] === "soft-hyphen" && !(startSegmentIndex === endSegmentIndex && startGraphemeIndex > 0);
42910
+ }
42911
+ __name(lineHasDiscretionaryHyphen, "lineHasDiscretionaryHyphen");
42912
+ function buildLineTextFromRange(segments, kinds, cache3, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
42913
+ let text2 = "";
42914
+ const endsWithDiscretionaryHyphen = lineHasDiscretionaryHyphen(kinds, startSegmentIndex, startGraphemeIndex, endSegmentIndex);
42915
+ for (let i = startSegmentIndex; i < endSegmentIndex; i++) {
42916
+ if (kinds[i] === "soft-hyphen" || kinds[i] === "hard-break")
42917
+ continue;
42918
+ if (i === startSegmentIndex && startGraphemeIndex > 0) {
42919
+ text2 += getSegmentGraphemes(i, segments, cache3).slice(startGraphemeIndex).join("");
42920
+ } else {
42921
+ text2 += segments[i];
42922
+ }
42923
+ }
42924
+ if (endGraphemeIndex > 0) {
42925
+ if (endsWithDiscretionaryHyphen)
42926
+ text2 += "-";
42927
+ text2 += getSegmentGraphemes(endSegmentIndex, segments, cache3).slice(startSegmentIndex === endSegmentIndex ? startGraphemeIndex : 0, endGraphemeIndex).join("");
42928
+ } else if (endsWithDiscretionaryHyphen) {
42929
+ text2 += "-";
42930
+ }
42931
+ return text2;
42932
+ }
42933
+ __name(buildLineTextFromRange, "buildLineTextFromRange");
42934
+ function createLayoutLine(prepared, cache3, width2, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
42935
+ return {
42936
+ text: buildLineTextFromRange(prepared.segments, prepared.kinds, cache3, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex),
42937
+ width: width2,
42938
+ start: {
42939
+ segmentIndex: startSegmentIndex,
42940
+ graphemeIndex: startGraphemeIndex
42941
+ },
42942
+ end: {
42943
+ segmentIndex: endSegmentIndex,
42944
+ graphemeIndex: endGraphemeIndex
42945
+ }
42946
+ };
42947
+ }
42948
+ __name(createLayoutLine, "createLayoutLine");
42949
+ function toLayoutLineRange(line2) {
42950
+ return {
42951
+ width: line2.width,
42952
+ start: {
42953
+ segmentIndex: line2.startSegmentIndex,
42954
+ graphemeIndex: line2.startGraphemeIndex
42955
+ },
42956
+ end: {
42957
+ segmentIndex: line2.endSegmentIndex,
42958
+ graphemeIndex: line2.endGraphemeIndex
42959
+ }
42960
+ };
42961
+ }
42962
+ __name(toLayoutLineRange, "toLayoutLineRange");
42963
+ function materializeLineRange(prepared, line2) {
42964
+ return createLayoutLine(prepared, getLineTextCache(prepared), line2.width, line2.start.segmentIndex, line2.start.graphemeIndex, line2.end.segmentIndex, line2.end.graphemeIndex);
42965
+ }
42966
+ __name(materializeLineRange, "materializeLineRange");
42967
+ function walkLineRanges(prepared, maxWidth, onLine) {
42968
+ if (prepared.widths.length === 0)
42969
+ return 0;
42970
+ return walkPreparedLines(getInternalPrepared(prepared), maxWidth, (line2) => {
42971
+ onLine(toLayoutLineRange(line2));
42972
+ });
42973
+ }
42974
+ __name(walkLineRanges, "walkLineRanges");
42975
+ function measureNaturalWidth(prepared) {
42976
+ let maxWidth = 0;
42977
+ walkLineRanges(prepared, Number.POSITIVE_INFINITY, (line2) => {
42978
+ if (line2.width > maxWidth)
42979
+ maxWidth = line2.width;
42980
+ });
42981
+ return maxWidth;
42982
+ }
42983
+ __name(measureNaturalWidth, "measureNaturalWidth");
42984
+
42985
+ // ../../node_modules/.pnpm/@chenglou+pretext@0.0.5/node_modules/@chenglou/pretext/dist/rich-inline.js
42986
+ var COLLAPSIBLE_BOUNDARY_RE = /[ \t\n\f\r]+/;
42987
+ var LEADING_COLLAPSIBLE_BOUNDARY_RE = /^[ \t\n\f\r]+/;
42988
+ var TRAILING_COLLAPSIBLE_BOUNDARY_RE = /[ \t\n\f\r]+$/;
42989
+ var EMPTY_LAYOUT_CURSOR = { segmentIndex: 0, graphemeIndex: 0 };
42990
+ var RICH_INLINE_START_CURSOR = {
42991
+ itemIndex: 0,
42992
+ segmentIndex: 0,
42993
+ graphemeIndex: 0
42994
+ };
42995
+ function getInternalPreparedRichInline(prepared) {
42996
+ return prepared;
42997
+ }
42998
+ __name(getInternalPreparedRichInline, "getInternalPreparedRichInline");
42999
+ function cloneCursor(cursor) {
43000
+ return {
43001
+ segmentIndex: cursor.segmentIndex,
43002
+ graphemeIndex: cursor.graphemeIndex
43003
+ };
43004
+ }
43005
+ __name(cloneCursor, "cloneCursor");
43006
+ function isLineStartCursor(cursor) {
43007
+ return cursor.segmentIndex === 0 && cursor.graphemeIndex === 0;
43008
+ }
43009
+ __name(isLineStartCursor, "isLineStartCursor");
43010
+ function getCollapsedSpaceWidth(font, cache3) {
43011
+ const cached = cache3.get(font);
43012
+ if (cached !== void 0)
43013
+ return cached;
43014
+ const joinedWidth = measureNaturalWidth(prepareWithSegments("A A", font));
43015
+ const compactWidth = measureNaturalWidth(prepareWithSegments("AA", font));
43016
+ const collapsedWidth = Math.max(0, joinedWidth - compactWidth);
43017
+ cache3.set(font, collapsedWidth);
43018
+ return collapsedWidth;
43019
+ }
43020
+ __name(getCollapsedSpaceWidth, "getCollapsedSpaceWidth");
43021
+ function prepareWholeItemLine(prepared) {
43022
+ const line2 = layoutNextLineRange(prepared, EMPTY_LAYOUT_CURSOR, Number.POSITIVE_INFINITY);
43023
+ if (line2 === null)
43024
+ return null;
43025
+ return {
43026
+ endGraphemeIndex: line2.endGraphemeIndex,
43027
+ endSegmentIndex: line2.endSegmentIndex,
43028
+ width: line2.width
43029
+ };
43030
+ }
43031
+ __name(prepareWholeItemLine, "prepareWholeItemLine");
43032
+ function endsInsideFirstSegment(segmentIndex, graphemeIndex) {
43033
+ return segmentIndex === 0 && graphemeIndex > 0;
43034
+ }
43035
+ __name(endsInsideFirstSegment, "endsInsideFirstSegment");
43036
+ function prepareRichInline(items) {
43037
+ const preparedItems = [];
43038
+ const itemsBySourceItemIndex = Array.from({ length: items.length });
43039
+ const collapsedSpaceWidthCache = /* @__PURE__ */ new Map();
43040
+ let pendingGapWidth = 0;
43041
+ for (let index = 0; index < items.length; index++) {
43042
+ const item = items[index];
43043
+ const hasLeadingWhitespace = LEADING_COLLAPSIBLE_BOUNDARY_RE.test(item.text);
43044
+ const hasTrailingWhitespace = TRAILING_COLLAPSIBLE_BOUNDARY_RE.test(item.text);
43045
+ const trimmedText = item.text.replace(LEADING_COLLAPSIBLE_BOUNDARY_RE, "").replace(TRAILING_COLLAPSIBLE_BOUNDARY_RE, "");
43046
+ if (trimmedText.length === 0) {
43047
+ if (COLLAPSIBLE_BOUNDARY_RE.test(item.text) && pendingGapWidth === 0) {
43048
+ pendingGapWidth = getCollapsedSpaceWidth(item.font, collapsedSpaceWidthCache);
43049
+ }
43050
+ continue;
43051
+ }
43052
+ const gapBefore = pendingGapWidth > 0 ? pendingGapWidth : hasLeadingWhitespace ? getCollapsedSpaceWidth(item.font, collapsedSpaceWidthCache) : 0;
43053
+ const prepared = prepareWithSegments(trimmedText, item.font);
43054
+ const wholeLine = prepareWholeItemLine(prepared);
43055
+ if (wholeLine === null) {
43056
+ pendingGapWidth = hasTrailingWhitespace ? getCollapsedSpaceWidth(item.font, collapsedSpaceWidthCache) : 0;
43057
+ continue;
43058
+ }
43059
+ const preparedItem = {
43060
+ break: item.break ?? "normal",
43061
+ endGraphemeIndex: wholeLine.endGraphemeIndex,
43062
+ endSegmentIndex: wholeLine.endSegmentIndex,
43063
+ extraWidth: item.extraWidth ?? 0,
43064
+ gapBefore,
43065
+ naturalWidth: wholeLine.width,
43066
+ prepared,
43067
+ sourceItemIndex: index
43068
+ };
43069
+ preparedItems.push(preparedItem);
43070
+ itemsBySourceItemIndex[index] = preparedItem;
43071
+ pendingGapWidth = hasTrailingWhitespace ? getCollapsedSpaceWidth(item.font, collapsedSpaceWidthCache) : 0;
43072
+ }
43073
+ return {
43074
+ items: preparedItems,
43075
+ itemsBySourceItemIndex
43076
+ };
43077
+ }
43078
+ __name(prepareRichInline, "prepareRichInline");
43079
+ function stepRichInlineLine(flow, maxWidth, cursor, collectFragment) {
43080
+ if (flow.items.length === 0 || cursor.itemIndex >= flow.items.length)
43081
+ return null;
43082
+ const safeWidth = Math.max(1, maxWidth);
43083
+ let lineWidth = 0;
43084
+ let remainingWidth = safeWidth;
43085
+ let itemIndex = cursor.itemIndex;
43086
+ const textCursor = {
43087
+ segmentIndex: cursor.segmentIndex,
43088
+ graphemeIndex: cursor.graphemeIndex
43089
+ };
43090
+ lineLoop: while (itemIndex < flow.items.length) {
43091
+ const item = flow.items[itemIndex];
43092
+ if (!isLineStartCursor(textCursor) && textCursor.segmentIndex === item.endSegmentIndex && textCursor.graphemeIndex === item.endGraphemeIndex) {
43093
+ itemIndex++;
43094
+ textCursor.segmentIndex = 0;
43095
+ textCursor.graphemeIndex = 0;
43096
+ continue;
43097
+ }
43098
+ const gapBefore = lineWidth === 0 ? 0 : item.gapBefore;
43099
+ const atItemStart = isLineStartCursor(textCursor);
43100
+ if (item.break === "never") {
43101
+ if (!atItemStart) {
43102
+ itemIndex++;
43103
+ textCursor.segmentIndex = 0;
43104
+ textCursor.graphemeIndex = 0;
43105
+ continue;
43106
+ }
43107
+ const occupiedWidth = item.naturalWidth + item.extraWidth;
43108
+ const totalWidth = gapBefore + occupiedWidth;
43109
+ if (lineWidth > 0 && totalWidth > remainingWidth)
43110
+ break lineLoop;
43111
+ collectFragment?.(item, gapBefore, occupiedWidth, cloneCursor(EMPTY_LAYOUT_CURSOR), {
43112
+ segmentIndex: item.endSegmentIndex,
43113
+ graphemeIndex: item.endGraphemeIndex
43114
+ });
43115
+ lineWidth += totalWidth;
43116
+ remainingWidth = Math.max(0, safeWidth - lineWidth);
43117
+ itemIndex++;
43118
+ textCursor.segmentIndex = 0;
43119
+ textCursor.graphemeIndex = 0;
43120
+ continue;
43121
+ }
43122
+ const reservedWidth = gapBefore + item.extraWidth;
43123
+ if (lineWidth > 0 && reservedWidth >= remainingWidth)
43124
+ break lineLoop;
43125
+ if (atItemStart) {
43126
+ const totalWidth = reservedWidth + item.naturalWidth;
43127
+ if (totalWidth <= remainingWidth) {
43128
+ collectFragment?.(item, gapBefore, item.naturalWidth + item.extraWidth, cloneCursor(EMPTY_LAYOUT_CURSOR), {
43129
+ segmentIndex: item.endSegmentIndex,
43130
+ graphemeIndex: item.endGraphemeIndex
43131
+ });
43132
+ lineWidth += totalWidth;
43133
+ remainingWidth = Math.max(0, safeWidth - lineWidth);
43134
+ itemIndex++;
43135
+ textCursor.segmentIndex = 0;
43136
+ textCursor.graphemeIndex = 0;
43137
+ continue;
43138
+ }
43139
+ }
43140
+ const availableWidth = Math.max(1, remainingWidth - reservedWidth);
43141
+ const line2 = layoutNextLineRange(item.prepared, textCursor, availableWidth);
43142
+ if (line2 === null) {
43143
+ itemIndex++;
43144
+ textCursor.segmentIndex = 0;
43145
+ textCursor.graphemeIndex = 0;
43146
+ continue;
43147
+ }
43148
+ if (textCursor.segmentIndex === line2.endSegmentIndex && textCursor.graphemeIndex === line2.endGraphemeIndex) {
43149
+ itemIndex++;
43150
+ textCursor.segmentIndex = 0;
43151
+ textCursor.graphemeIndex = 0;
43152
+ continue;
43153
+ }
43154
+ if (lineWidth > 0 && atItemStart && gapBefore > 0 && endsInsideFirstSegment(line2.endSegmentIndex, line2.endGraphemeIndex)) {
43155
+ const freshLine = layoutNextLineRange(item.prepared, EMPTY_LAYOUT_CURSOR, Math.max(1, safeWidth - item.extraWidth));
43156
+ if (freshLine !== null && (freshLine.endSegmentIndex > line2.endSegmentIndex || freshLine.endSegmentIndex === line2.endSegmentIndex && freshLine.endGraphemeIndex > line2.endGraphemeIndex)) {
43157
+ break lineLoop;
43158
+ }
43159
+ }
43160
+ collectFragment?.(item, gapBefore, line2.width + item.extraWidth, cloneCursor(textCursor), {
43161
+ segmentIndex: line2.endSegmentIndex,
43162
+ graphemeIndex: line2.endGraphemeIndex
43163
+ });
43164
+ lineWidth += gapBefore + line2.width + item.extraWidth;
43165
+ remainingWidth = Math.max(0, safeWidth - lineWidth);
43166
+ if (line2.endSegmentIndex === item.endSegmentIndex && line2.endGraphemeIndex === item.endGraphemeIndex) {
43167
+ itemIndex++;
43168
+ textCursor.segmentIndex = 0;
43169
+ textCursor.graphemeIndex = 0;
43170
+ continue;
43171
+ }
43172
+ textCursor.segmentIndex = line2.endSegmentIndex;
43173
+ textCursor.graphemeIndex = line2.endGraphemeIndex;
43174
+ break;
43175
+ }
43176
+ if (lineWidth === 0)
43177
+ return null;
43178
+ cursor.itemIndex = itemIndex;
43179
+ cursor.segmentIndex = textCursor.segmentIndex;
43180
+ cursor.graphemeIndex = textCursor.graphemeIndex;
43181
+ return lineWidth;
43182
+ }
43183
+ __name(stepRichInlineLine, "stepRichInlineLine");
43184
+ function layoutNextRichInlineLineRange(prepared, maxWidth, start = RICH_INLINE_START_CURSOR) {
43185
+ const flow = getInternalPreparedRichInline(prepared);
43186
+ const end = {
43187
+ itemIndex: start.itemIndex,
43188
+ segmentIndex: start.segmentIndex,
43189
+ graphemeIndex: start.graphemeIndex
43190
+ };
43191
+ const fragments = [];
43192
+ const width2 = stepRichInlineLine(flow, maxWidth, end, (item, gapBefore, occupiedWidth, fragmentStart, fragmentEnd) => {
43193
+ fragments.push({
43194
+ itemIndex: item.sourceItemIndex,
43195
+ gapBefore,
43196
+ occupiedWidth,
43197
+ start: fragmentStart,
43198
+ end: fragmentEnd
43199
+ });
43200
+ });
43201
+ if (width2 === null)
43202
+ return null;
43203
+ return {
43204
+ fragments,
43205
+ width: width2,
43206
+ end
43207
+ };
43208
+ }
43209
+ __name(layoutNextRichInlineLineRange, "layoutNextRichInlineLineRange");
43210
+ function materializeFragmentText(item, fragment) {
43211
+ const line2 = materializeLineRange(item.prepared, {
43212
+ width: fragment.occupiedWidth - item.extraWidth,
43213
+ start: fragment.start,
43214
+ end: fragment.end
43215
+ });
43216
+ return line2.text;
43217
+ }
43218
+ __name(materializeFragmentText, "materializeFragmentText");
43219
+ function materializeRichInlineLineRange(prepared, line2) {
43220
+ const flow = getInternalPreparedRichInline(prepared);
43221
+ return {
43222
+ fragments: line2.fragments.map((fragment) => {
43223
+ const item = flow.itemsBySourceItemIndex[fragment.itemIndex];
43224
+ if (item === void 0)
43225
+ throw new Error("Missing rich-text inline item for fragment");
43226
+ return {
43227
+ ...fragment,
43228
+ text: materializeFragmentText(item, fragment)
43229
+ };
43230
+ }),
43231
+ width: line2.width,
43232
+ end: line2.end
43233
+ };
43234
+ }
43235
+ __name(materializeRichInlineLineRange, "materializeRichInlineLineRange");
43236
+
39486
43237
  // ../../node_modules/.pnpm/html-void-elements@3.0.0/node_modules/html-void-elements/index.js
39487
43238
  var htmlVoidElements = [
39488
43239
  "area",
@@ -42295,99 +46046,6 @@ a {
42295
46046
  }
42296
46047
  __name(closedDialog, "closedDialog");
42297
46048
 
42298
- // src/splitText.ts
42299
- function splitTextToChars(text2) {
42300
- if (Intl.Segmenter) {
42301
- return [...new Intl.Segmenter().segment(text2)].map((s) => s.segment);
42302
- }
42303
- return [...text2];
42304
- }
42305
- __name(splitTextToChars, "splitTextToChars");
42306
- function splitWordToFitWidth(checkFit, word) {
42307
- const characters3 = splitTextToChars(word.content);
42308
- return splitWordToFitWidthRecursion(checkFit, [], characters3, word.type);
42309
- }
42310
- __name(splitWordToFitWidth, "splitWordToFitWidth");
42311
- function splitWordToFitWidthRecursion(checkFit, usedChars, remainingChars, type) {
42312
- if (remainingChars.length === 0) {
42313
- return [
42314
- { content: usedChars.join(""), type },
42315
- { content: "", type }
42316
- ];
42317
- }
42318
- const [nextChar, ...rest] = remainingChars;
42319
- const newWord = [...usedChars, nextChar];
42320
- if (checkFit({
42321
- type: "text_line",
42322
- words: [{ content: newWord.join(""), type }]
42323
- })) {
42324
- return splitWordToFitWidthRecursion(checkFit, newWord, rest, type);
42325
- }
42326
- if (usedChars.length === 0 && nextChar) {
42327
- usedChars.push(nextChar);
42328
- remainingChars.shift();
42329
- }
42330
- return [
42331
- { content: usedChars.join(""), type },
42332
- { content: remainingChars.join(""), type }
42333
- ];
42334
- }
42335
- __name(splitWordToFitWidthRecursion, "splitWordToFitWidthRecursion");
42336
- function splitLineToFitWidth(line2, checkFit) {
42337
- if (line2.words.some(({ content }) => content.includes("\n"))) {
42338
- throw new Error("splitLineToFitWidth does not support newlines in the line");
42339
- }
42340
- return splitLineToFitWidthRecursion(line2, checkFit);
42341
- }
42342
- __name(splitLineToFitWidth, "splitLineToFitWidth");
42343
- function splitLineToFitWidthRecursion(line2, checkFit, lines = [], newLine = []) {
42344
- let words = line2.words;
42345
- if (words.length === 0) {
42346
- if (newLine.length > 0) {
42347
- lines.push({
42348
- type: "text_line",
42349
- words: newLine
42350
- });
42351
- }
42352
- return lines.length > 0 ? lines : [];
42353
- }
42354
- let joiner = "";
42355
- if (words[0].content === " ") {
42356
- joiner = " ";
42357
- words.shift();
42358
- }
42359
- const nextWord = words.shift() ?? { content: " ", type: "normal" };
42360
- const lineWithNextWord = {
42361
- type: "text_line",
42362
- words: [...newLine]
42363
- };
42364
- if (joiner !== "") {
42365
- lineWithNextWord.words.push({ content: joiner, type: "normal" });
42366
- }
42367
- lineWithNextWord.words.push(nextWord);
42368
- if (checkFit(lineWithNextWord)) {
42369
- return splitLineToFitWidthRecursion(line2, checkFit, lines, lineWithNextWord.words);
42370
- }
42371
- if (newLine.length > 0) {
42372
- lines.push({
42373
- type: "text_line",
42374
- words: [...newLine]
42375
- });
42376
- line2.words.unshift(nextWord);
42377
- } else if (nextWord.content) {
42378
- const [word, rest] = splitWordToFitWidth(checkFit, nextWord);
42379
- lines.push({
42380
- type: "text_line",
42381
- words: [word]
42382
- });
42383
- if (rest.content) {
42384
- line2.words.unshift(rest);
42385
- }
42386
- }
42387
- return splitLineToFitWidthRecursion(line2, checkFit, lines);
42388
- }
42389
- __name(splitLineToFitWidthRecursion, "splitLineToFitWidthRecursion");
42390
-
42391
46049
  // src/utils.ts
42392
46050
  var decodeEntities = /* @__PURE__ */ __name(function(text2) {
42393
46051
  return text2.replace(/fl°°/g, "&#").replace(/fl°/g, "&").replace(/¶ß/g, ";");
@@ -42589,19 +46247,130 @@ a {
42589
46247
  }, "walkTree");
42590
46248
 
42591
46249
  // src/text.ts
46250
+ var DEFAULT_FONT_FAMILY = '"trebuchet ms", verdana, arial, sans-serif';
46251
+ var DEFAULT_LINE_HEIGHT_EM = 1.1;
46252
+ function getWordFontStyle(wordType) {
46253
+ return {
46254
+ fontStyle: wordType === "emphasis" ? "italic" : "normal",
46255
+ fontWeight: wordType === "strong" ? "bold" : "normal"
46256
+ };
46257
+ }
46258
+ __name(getWordFontStyle, "getWordFontStyle");
46259
+ function createCanvasFont(word, fontSize, fontFamily) {
46260
+ const { fontStyle, fontWeight } = getWordFontStyle(word.type);
46261
+ return [fontStyle, fontWeight, `${fontSize}px`, fontFamily].join(" ");
46262
+ }
46263
+ __name(createCanvasFont, "createCanvasFont");
46264
+ function splitTextToGraphemes(text2) {
46265
+ if (Intl.Segmenter) {
46266
+ return [...new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(text2)].map(
46267
+ (segment) => segment.segment
46268
+ );
46269
+ }
46270
+ return [...text2];
46271
+ }
46272
+ __name(splitTextToGraphemes, "splitTextToGraphemes");
46273
+ function measureWordWidth(word, fontSize, fontFamily, content = word.content) {
46274
+ return measureNaturalWidth(prepareWithSegments(content, createCanvasFont(word, fontSize, fontFamily)));
46275
+ }
46276
+ __name(measureWordWidth, "measureWordWidth");
46277
+ function splitOversizedWordWithPretext(word, width2, fontSize, fontFamily) {
46278
+ const graphemes = splitTextToGraphemes(word.content);
46279
+ if (graphemes.length === 0) return [];
46280
+ const lines = [];
46281
+ let current = "";
46282
+ for (const grapheme of graphemes) {
46283
+ const candidate = `${current}${grapheme}`;
46284
+ const candidateWidth = measureWordWidth(word, fontSize, fontFamily, candidate);
46285
+ if (candidateWidth <= width2 || current.length === 0) {
46286
+ current = candidate;
46287
+ continue;
46288
+ }
46289
+ lines.push({
46290
+ fragments: [{
46291
+ gapBefore: 0,
46292
+ text: current,
46293
+ word
46294
+ }],
46295
+ width: measureWordWidth(word, fontSize, fontFamily, current)
46296
+ });
46297
+ current = grapheme;
46298
+ }
46299
+ if (current.length > 0) {
46300
+ lines.push({
46301
+ fragments: [{
46302
+ gapBefore: 0,
46303
+ text: current,
46304
+ word
46305
+ }],
46306
+ width: measureWordWidth(word, fontSize, fontFamily, current)
46307
+ });
46308
+ }
46309
+ return lines;
46310
+ }
46311
+ __name(splitOversizedWordWithPretext, "splitOversizedWordWithPretext");
46312
+ function createRichInlineItems(line2, fontSize, fontFamily) {
46313
+ return line2.words.map((word, index) => ({
46314
+ break: "never",
46315
+ font: createCanvasFont(word, fontSize, fontFamily),
46316
+ text: index === 0 ? word.content : ` ${word.content}`
46317
+ }));
46318
+ }
46319
+ __name(createRichInlineItems, "createRichInlineItems");
46320
+ function layoutTextLineWithPretext(line2, width2, fontSize, fontFamily) {
46321
+ const items = createRichInlineItems(line2, fontSize, fontFamily);
46322
+ if (items.length === 0) return [];
46323
+ const prepared = prepareRichInline(items);
46324
+ const wrappedLines = [];
46325
+ let cursor;
46326
+ while (true) {
46327
+ const lineRange = layoutNextRichInlineLineRange(prepared, width2, cursor);
46328
+ if (!lineRange) break;
46329
+ const materializedLine = materializeRichInlineLineRange(prepared, lineRange);
46330
+ const nextLine = {
46331
+ fragments: materializedLine.fragments.map((fragment) => ({
46332
+ gapBefore: fragment.gapBefore,
46333
+ text: fragment.text,
46334
+ word: line2.words[fragment.itemIndex]
46335
+ })),
46336
+ width: materializedLine.width
46337
+ };
46338
+ if (nextLine.width > width2 && nextLine.fragments.length === 1) {
46339
+ wrappedLines.push(
46340
+ ...splitOversizedWordWithPretext(
46341
+ nextLine.fragments[0].word,
46342
+ width2,
46343
+ fontSize,
46344
+ fontFamily
46345
+ )
46346
+ );
46347
+ } else {
46348
+ wrappedLines.push(nextLine);
46349
+ }
46350
+ cursor = lineRange.end;
46351
+ }
46352
+ return wrappedLines;
46353
+ }
46354
+ __name(layoutTextLineWithPretext, "layoutTextLineWithPretext");
46355
+ function measureTextLineWithPretext(line2, width2, fontSize, fontFamily = DEFAULT_FONT_FAMILY) {
46356
+ const lines = layoutTextLineWithPretext(line2, width2, fontSize, fontFamily);
46357
+ const measuredWidth = lines.reduce((currentWidth, wrappedLine) => {
46358
+ return Math.max(currentWidth, wrappedLine.width);
46359
+ }, 0);
46360
+ return {
46361
+ height: Math.max(
46362
+ DEFAULT_LINE_HEIGHT_EM * fontSize,
46363
+ lines.length * DEFAULT_LINE_HEIGHT_EM * fontSize
46364
+ ),
46365
+ lines,
46366
+ width: measuredWidth
46367
+ };
46368
+ }
46369
+ __name(measureTextLineWithPretext, "measureTextLineWithPretext");
42592
46370
  function createTspan(textElement, lineIndex, lineHeight) {
42593
46371
  return textElement.append("tspan").attr("class", "text-outer-tspan").attr("x", 0).attr("y", lineIndex * lineHeight - 0.1 + "em").attr("dy", lineHeight + "em");
42594
46372
  }
42595
46373
  __name(createTspan, "createTspan");
42596
- function computeWidthOfText(parentNode, lineHeight, line2) {
42597
- const testElement = parentNode.append("text");
42598
- const testSpan = createTspan(testElement, 1, lineHeight);
42599
- updateTextContentAndStyles(testSpan, line2.words);
42600
- const textLength = testSpan.node().getComputedTextLength();
42601
- testElement.remove();
42602
- return textLength;
42603
- }
42604
- __name(computeWidthOfText, "computeWidthOfText");
42605
46374
  function updateTextContentAndStyles(tspan, wrappedLine) {
42606
46375
  tspan.text("");
42607
46376
  wrappedLine.forEach((word, index) => {
@@ -42615,6 +46384,17 @@ a {
42615
46384
  });
42616
46385
  }
42617
46386
  __name(updateTextContentAndStyles, "updateTextContentAndStyles");
46387
+ function updateTextContentAndStylesFromFragments(tspan, wrappedLine) {
46388
+ tspan.text("");
46389
+ wrappedLine.forEach((fragment) => {
46390
+ const { fontStyle, fontWeight } = getWordFontStyle(fragment.word.type);
46391
+ const innerTspan = tspan.append("tspan").attr("font-style", fontStyle).attr("class", "text-inner-tspan").attr("font-weight", fontWeight);
46392
+ if (fragment.word.type === "delete") innerTspan.attr("text-decoration", "line-through");
46393
+ if (fragment.gapBefore > 0) innerTspan.attr("dx", fragment.gapBefore);
46394
+ innerTspan.text(fragment.text);
46395
+ });
46396
+ }
46397
+ __name(updateTextContentAndStylesFromFragments, "updateTextContentAndStylesFromFragments");
42618
46398
  function addImageObject(element5, node2, width2, y2) {
42619
46399
  const img = element5.append("image");
42620
46400
  img.attr("href", node2.src);
@@ -42632,6 +46412,11 @@ a {
42632
46412
  let desc = img.append("desc");
42633
46413
  desc.text(node2.alt);
42634
46414
  }
46415
+ return {
46416
+ h: node2.height,
46417
+ node: img.node(),
46418
+ w: node2.width
46419
+ };
42635
46420
  }
42636
46421
  __name(addImageObject, "addImageObject");
42637
46422
  function addHtmlSpan(element5, node2, width2, classes2, y2, addBackground = false) {
@@ -42797,30 +46582,20 @@ a {
42797
46582
  });
42798
46583
  return lines;
42799
46584
  }, "hastToLines");
42800
- function createFormattedText(width2, g, structuredBlocks, addBackground = false, txtColor = "currentColor") {
46585
+ function createFormattedText(width2, g, structuredBlocks, addBackground = false, txtColor = "currentColor", fontSize = 16, fontFamily = DEFAULT_FONT_FAMILY) {
42801
46586
  const labelGroup = g.append("g");
42802
- const lineHeight = 1.1;
46587
+ const lineHeight = DEFAULT_LINE_HEIGHT_EM;
42803
46588
  const bkg = labelGroup.insert("rect").attr("class", "background");
42804
- let textElement = void 0;
42805
- let y2 = -10;
42806
- let maxWidth = width2;
42807
- let i = 0;
46589
+ let y2 = 0;
46590
+ let maxWidth = 0;
46591
+ let usedPretext = true;
42808
46592
  for (const line2 of structuredBlocks) {
42809
46593
  if (line2.type === "image") {
42810
- if (textElement) {
42811
- y2 += 1.5 * textElement.node().getBBox().height;
42812
- } else if (i === 0) {
42813
- y2 = 0;
42814
- }
42815
46594
  const result = addImageObject(labelGroup, line2, width2, y2);
42816
46595
  addBackground = true;
46596
+ maxWidth = Math.max(maxWidth, result.w);
46597
+ y2 += result.h;
42817
46598
  } else if (line2.type === "raw_html") {
42818
- if (textElement) {
42819
- y2 += 1.5 * textElement.node().getBBox().height;
42820
- } else if (i === 0) {
42821
- y2 = 0;
42822
- }
42823
- textElement = void 0;
42824
46599
  const decodedReplacedText = line2.raw;
42825
46600
  const htmlnode = {
42826
46601
  isNode: true,
@@ -42830,29 +46605,41 @@ a {
42830
46605
  const result = addHtmlSpan(labelGroup, htmlnode, width2, "", y2, false);
42831
46606
  log.debug("addHtmlSpan result w: ", result.w, ", h:", result.h);
42832
46607
  const { w, h } = result;
42833
- if (w > maxWidth) maxWidth = w;
46608
+ maxWidth = Math.max(maxWidth, w);
46609
+ y2 += h;
42834
46610
  } else {
42835
- if (textElement === void 0) {
42836
- textElement = labelGroup.append("text").attr("y", y2).attr("fill", txtColor);
42837
- }
42838
- ;
42839
- let lineIndex = 0;
42840
- const checkWidth = /* @__PURE__ */ __name((line3) => computeWidthOfText(labelGroup, lineHeight, line3) <= width2, "checkWidth");
42841
- const linesUnderWidth = checkWidth(line2) ? [line2] : splitLineToFitWidth(line2, checkWidth);
42842
- for (const preparedLine of linesUnderWidth) {
42843
- const tspan = createTspan(textElement, lineIndex, lineHeight);
42844
- updateTextContentAndStyles(tspan, preparedLine.words);
42845
- lineIndex++;
46611
+ const textElement = labelGroup.append("text").attr("y", y2).attr("fill", txtColor);
46612
+ try {
46613
+ const measuredText = measureTextLineWithPretext(line2, width2, fontSize, fontFamily);
46614
+ for (const [lineIndex, preparedLine] of measuredText.lines.entries()) {
46615
+ const tspan = createTspan(textElement, lineIndex, lineHeight);
46616
+ updateTextContentAndStylesFromFragments(tspan, preparedLine.fragments);
46617
+ maxWidth = Math.max(maxWidth, preparedLine.width);
46618
+ }
46619
+ y2 += measuredText.height;
46620
+ } catch (error3) {
46621
+ log.warn("pretext layout failed, falling back to DOM text rendering", error3);
46622
+ usedPretext = false;
46623
+ const tspan = createTspan(textElement, 0, lineHeight);
46624
+ updateTextContentAndStyles(tspan, line2.words);
46625
+ const bbox = textElement.node().getBBox();
46626
+ maxWidth = Math.max(maxWidth, bbox.width);
46627
+ y2 += bbox.height;
42846
46628
  }
42847
46629
  }
42848
- ++i;
42849
46630
  }
42850
46631
  if (addBackground) {
42851
- const bbox = labelGroup.node().getBBox();
42852
46632
  const padding = 2;
42853
- bkg.attr("x", -padding).attr("y", -padding).attr("width", bbox.width + 2 * padding).attr("height", bbox.height + 2 * padding);
46633
+ bkg.attr("x", -padding).attr("y", -padding).attr("width", maxWidth + 2 * padding).attr("height", y2 + 2 * padding);
42854
46634
  }
42855
- return labelGroup.node();
46635
+ return {
46636
+ measurement: {
46637
+ height: y2,
46638
+ usedPretext,
46639
+ width: maxWidth
46640
+ },
46641
+ node: labelGroup.node()
46642
+ };
42856
46643
  }
42857
46644
  __name(createFormattedText, "createFormattedText");
42858
46645
  var createText = /* @__PURE__ */ __name((el, text2 = "", contents = [], {
@@ -42863,12 +46650,22 @@ a {
42863
46650
  useHtmlLabels = true,
42864
46651
  isNode: isNode2 = true,
42865
46652
  width: width2 = 300,
42866
- addSvgBackground = false
46653
+ addSvgBackground = false,
46654
+ fontFamily = DEFAULT_FONT_FAMILY,
46655
+ fontSize = 16
42867
46656
  } = {}) => {
42868
46657
  log.info("createText", text2, JSON.stringify(contents, void 0, 2), style3, isTitle, classes2, useHtmlLabels, isNode2, addSvgBackground);
42869
46658
  if (!Array.isArray(contents) || contents.length == 0) return;
42870
46659
  const structuredBlocks = hastToLines(contents);
42871
- const svgLabel = createFormattedText(width2, el, structuredBlocks, addSvgBackground, txtColor);
46660
+ const svgLabel = createFormattedText(
46661
+ width2,
46662
+ el,
46663
+ structuredBlocks,
46664
+ addSvgBackground,
46665
+ txtColor,
46666
+ fontSize,
46667
+ fontFamily
46668
+ );
42872
46669
  log.info("structuredBlocks ", JSON.stringify(structuredBlocks, void 0, 2));
42873
46670
  return svgLabel;
42874
46671
  }, "createText");
@@ -43090,16 +46887,19 @@ a {
43090
46887
  nodeElem.attr("class", (node2.class ? node2.class + " " : "") + "mindmap-node " + sectionClass + ` node-level-${node2.level}`);
43091
46888
  const bkgElem = nodeElem.append("g");
43092
46889
  const textElem = nodeElem.append("g");
46890
+ const fontSize = theme_default.fontSize(node2.level);
43093
46891
  const description = node2.descr?.replace(/(<br\/*>)/g, "\n") ?? "";
43094
46892
  const contents = node2.contents;
43095
- const newEl = createText(
46893
+ const textResult = createText(
43096
46894
  textElem,
43097
46895
  description,
43098
46896
  contents,
43099
46897
  {
43100
46898
  useHtmlLabels: htmlLabels,
43101
46899
  width: node2.width,
43102
- classes: "mindmap-node-label"
46900
+ classes: "mindmap-node-label",
46901
+ fontFamily: theme_default.defaultFontFamily,
46902
+ fontSize
43103
46903
  }
43104
46904
  );
43105
46905
  const hasCodeTag = textElem.selectAll("code").size() > 0;
@@ -43109,14 +46909,13 @@ a {
43109
46909
  }
43110
46910
  if (hasCodeTag) {
43111
46911
  }
43112
- const fontSize = theme_default.fontSize(node2.level);
43113
46912
  log.debug("fffffffffffffontsize : ", fontSize);
43114
46913
  if (!htmlLabels) {
43115
46914
  textElem.attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle");
43116
46915
  }
43117
46916
  let tt = textElem.selectAll("text");
43118
46917
  tt.attr("font-size", `${fontSize}px`);
43119
- const bbox = textElem.node().getBBox();
46918
+ const bbox = textResult?.measurement ?? textElem.node().getBBox();
43120
46919
  if (hasImage) {
43121
46920
  node2.height = bbox.height;
43122
46921
  node2.width = bbox.width;