lilact 0.26.1 → 0.26.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.
@@ -4981,123 +4981,144 @@ var SplitPane = forwardRef(function SplitPane2({
4981
4981
  }, ref) {
4982
4982
  const containerRef = useRef(null);
4983
4983
  const sizeRef = useRef({ w: 0, h: 0 });
4984
- const initialMode = mode === "vertical" ? "vertical" : "horizontal";
4985
- const [internalMode, setInternalMode] = useState(initialMode);
4986
- const [internalPos, setInternalPos] = useState(clamp(
4987
- defaultPosition,
4988
- min,
4989
- max,
4990
- mode === "verical" ? sizeRef.current.h : sizeRef.current.w,
4991
- splitterSize
4992
- ));
4993
- let posResolved = position2 == null ? internalPos : position2;
4994
- posResolved = clamp(
4995
- posResolved,
4996
- min,
4997
- max,
4998
- mode === "verical" ? sizeRef.current.h : sizeRef.current.w,
4999
- splitterSize
5000
- );
4984
+ const [internalMode, setInternalMode] = useState(mode === "vertical" ? "vertical" : "horizontal");
4985
+ const internalModeRef = useRef(internalMode);
4986
+ const [internalPos, setInternalPos] = useState(defaultPosition);
4987
+ const internalPosRef = useRef(internalPos);
4988
+ const effectivePosRef = useRef(void 0);
4989
+ const resizePolicyRef = useRef(resizePolicy);
5001
4990
  useEffect(() => {
5002
- if (position2 == null) return;
5003
- setInternalPos(clamp(
5004
- position2,
5005
- min,
5006
- max,
5007
- mode === "verical" ? sizeRef.current.h : sizeRef.current.w,
5008
- splitterSize
5009
- ));
5010
- }, [position2, min, max]);
4991
+ resizePolicyRef.current = resizePolicy;
4992
+ }, [resizePolicy]);
4993
+ internalModeRef.current = internalMode;
5011
4994
  useEffect(() => {
4995
+ internalPosRef.current = internalPos;
4996
+ }, [internalPos]);
4997
+ useLayoutEffect(() => {
5012
4998
  setInternalMode(mode === "vertical" ? "vertical" : "horizontal");
5013
4999
  }, [mode]);
5000
+ const clampWithSize = (v, modeNow, w2, h2) => {
5001
+ const size = modeNow === "vertical" ? h2 : w2;
5002
+ return clamp(v, min, max, size, splitterSize);
5003
+ };
5004
+ const posResolved = useMemo(() => {
5005
+ const raw = position2 == null ? internalPos : position2;
5006
+ const { w: w2, h: h2 } = sizeRef.current;
5007
+ const hasSize = mode === "vertical" ? h2 > 0 : w2 > 0;
5008
+ if (!hasSize) return raw;
5009
+ return clampWithSize(raw, internalModeRef.current, w2, h2);
5010
+ }, [position2, internalPos, min, max, splitterSize, mode]);
5011
+ useEffect(() => {
5012
+ effectivePosRef.current = posResolved;
5013
+ }, [posResolved]);
5014
5014
  const setPosition = (next2) => {
5015
- const clamped = clamp(
5016
- next2,
5017
- min,
5018
- max,
5019
- mode === "verical" ? sizeRef.current.h : sizeRef.current.w,
5020
- splitterSize
5021
- );
5015
+ const modeNow = internalModeRef.current;
5016
+ const { w: w2, h: h2 } = sizeRef.current;
5017
+ if (modeNow === "vertical" ? h2 <= 0 : w2 <= 0) {
5018
+ if (position2 == null) setInternalPos(next2);
5019
+ onSizeChange == null ? void 0 : onSizeChange(next2);
5020
+ return;
5021
+ }
5022
+ const clamped = clampWithSize(next2, modeNow, w2, h2);
5022
5023
  if (position2 == null) setInternalPos(clamped);
5024
+ effectivePosRef.current = clamped;
5023
5025
  onSizeChange == null ? void 0 : onSizeChange(clamped);
5024
5026
  };
5025
5027
  useImperativeHandle(ref, () => ({
5026
5028
  setPosition,
5027
5029
  setMode: (nextMode) => setInternalMode(nextMode === "vertical" ? "vertical" : "horizontal"),
5028
- getPosition: () => posResolved,
5029
- getMode: () => internalMode
5030
+ getPosition: () => {
5031
+ var _a;
5032
+ return (_a = effectivePosRef.current) != null ? _a : posResolved;
5033
+ },
5034
+ getMode: () => internalModeRef.current
5030
5035
  }));
5036
+ const didInitRef = useRef(false);
5031
5037
  useLayoutEffect(() => {
5032
5038
  const el = containerRef.current;
5033
5039
  if (!el) return;
5034
- const ro = new ResizeObserver(() => {
5040
+ const ro = new ResizeObserver((entries) => {
5035
5041
  var _a;
5036
- const rect2 = el.getBoundingClientRect();
5037
- const o = sizeRef.current;
5038
- sizeRef.current = { w: rect2.width, h: rect2.height };
5039
- const EPS = 1e-6;
5040
- function clamp01(x) {
5041
- return Math.min(1, Math.max(0, x));
5042
- }
5043
- if ((_a = ref.current) == null ? void 0 : _a.getPosition) {
5044
- const p2 = ref.current.getPosition();
5045
- if (resizePolicy === "fixFirst") {
5046
- if (internalMode === "vertical") {
5047
- const availOld = o.h - splitterSize;
5048
- const availNew = sizeRef.current.h - splitterSize;
5049
- if (availOld > 0 && availNew > 0) {
5050
- const firstPx = p2 * availOld;
5051
- const nextP = firstPx / availNew;
5052
- if (Math.abs(nextP - p2) > EPS) setPosition(clamp01(nextP));
5053
- }
5054
- } else {
5055
- const availOld = o.w - splitterSize;
5056
- const availNew = sizeRef.current.w - splitterSize;
5057
- if (availOld > 0 && availNew > 0) {
5058
- const firstPx = p2 * availOld;
5059
- const nextP = firstPx / availNew;
5060
- if (Math.abs(nextP - p2) > EPS) setPosition(clamp01(nextP));
5061
- }
5042
+ const rect = el.getBoundingClientRect();
5043
+ const prev2 = sizeRef.current;
5044
+ const nextSize = { w: rect.width, h: rect.height };
5045
+ sizeRef.current = nextSize;
5046
+ const modeNow = internalModeRef.current;
5047
+ const hadSize = modeNow === "vertical" ? prev2.h > 0 : prev2.w > 0;
5048
+ const hasSizeNow = modeNow === "vertical" ? nextSize.h > 0 : nextSize.w > 0;
5049
+ if (!didInitRef.current && hasSizeNow) {
5050
+ didInitRef.current = true;
5051
+ const raw = position2 == null ? internalPosRef.current : position2;
5052
+ const clamped = clampWithSize(raw, modeNow, nextSize.w, nextSize.h);
5053
+ if (position2 == null) setInternalPos(clamped);
5054
+ effectivePosRef.current = clamped;
5055
+ onSizeChange == null ? void 0 : onSizeChange(clamped);
5056
+ return;
5057
+ }
5058
+ if (!hadSize || !hasSizeNow) return;
5059
+ const p2 = (_a = effectivePosRef.current) != null ? _a : posResolved;
5060
+ const rp = resizePolicyRef.current;
5061
+ const s = splitterSize;
5062
+ if (rp === "fixFirst") {
5063
+ if (modeNow === "vertical") {
5064
+ const availOld = prev2.h - s;
5065
+ const availNew = nextSize.h - s;
5066
+ if (availOld > 0 && availNew > 0) {
5067
+ const firstPx = p2 * availOld;
5068
+ const nextP = firstPx / availNew;
5069
+ if (Math.abs(nextP - p2) > EPS) setPosition(nextP);
5062
5070
  }
5063
- } else if (resizePolicy === "fixSecond") {
5064
- if (internalMode === "vertical") {
5065
- const availOld = o.h - splitterSize;
5066
- const availNew = sizeRef.current.h - splitterSize;
5067
- if (availOld > 0 && availNew > 0) {
5068
- const secondPx = (1 - p2) * availOld;
5069
- const nextP = 1 - secondPx / availNew;
5070
- if (Math.abs(nextP - p2) > EPS) setPosition(clamp01(nextP));
5071
- }
5072
- } else {
5073
- const availOld = o.w - splitterSize;
5074
- const availNew = sizeRef.current.w - splitterSize;
5075
- if (availOld > 0 && availNew > 0) {
5076
- const secondPx = (1 - p2) * availOld;
5077
- const nextP = 1 - secondPx / availNew;
5078
- if (Math.abs(nextP - p2) > EPS) setPosition(clamp01(nextP));
5079
- }
5071
+ } else {
5072
+ const availOld = prev2.w - s;
5073
+ const availNew = nextSize.w - s;
5074
+ if (availOld > 0 && availNew > 0) {
5075
+ const firstPx = p2 * availOld;
5076
+ const nextP = firstPx / availNew;
5077
+ if (Math.abs(nextP - p2) > EPS) setPosition(nextP);
5078
+ }
5079
+ }
5080
+ } else if (rp === "fixSecond") {
5081
+ if (modeNow === "vertical") {
5082
+ const availOld = prev2.h - s;
5083
+ const availNew = nextSize.h - s;
5084
+ if (availOld > 0 && availNew > 0) {
5085
+ const secondPx = (1 - p2) * availOld;
5086
+ const nextP = 1 - secondPx / availNew;
5087
+ if (Math.abs(nextP - p2) > EPS) setPosition(nextP);
5088
+ }
5089
+ } else {
5090
+ const availOld = prev2.w - s;
5091
+ const availNew = nextSize.w - s;
5092
+ if (availOld > 0 && availNew > 0) {
5093
+ const secondPx = (1 - p2) * availOld;
5094
+ const nextP = 1 - secondPx / availNew;
5095
+ if (Math.abs(nextP - p2) > EPS) setPosition(nextP);
5080
5096
  }
5081
5097
  }
5082
5098
  }
5083
5099
  });
5084
5100
  ro.observe(el);
5085
- const rect = el.getBoundingClientRect();
5086
- sizeRef.current = { w: rect.width, h: rect.height };
5087
5101
  return () => ro.disconnect();
5088
- }, [resizePolicy, internalMode]);
5102
+ }, [min, max, splitterSize, onSizeChange, position2]);
5089
5103
  const startPosRef = useRef(posResolved);
5090
5104
  const [dragging, setDragging] = useState(false);
5105
+ useEffect(() => {
5106
+ if (!dragging) startPosRef.current = posResolved;
5107
+ }, [posResolved, dragging]);
5091
5108
  const handleStart = () => {
5109
+ var _a;
5092
5110
  setDragging(true);
5093
- startPosRef.current = posResolved;
5111
+ startPosRef.current = (_a = effectivePosRef.current) != null ? _a : posResolved;
5094
5112
  };
5095
- const handleDelta = (x, y, _data) => {
5113
+ const handleDelta = (x, y) => {
5114
+ const modeNow = internalModeRef.current;
5096
5115
  const { w: w2, h: h2 } = sizeRef.current;
5097
- if (internalMode === "horizontal") {
5098
- setPosition(startPosRef.current + x / (w2 || 1));
5116
+ if (modeNow === "horizontal") {
5117
+ const denom = w2 > 0 ? w2 : 1;
5118
+ setPosition(startPosRef.current + x / denom);
5099
5119
  } else {
5100
- setPosition(startPosRef.current + y / (h2 || 1));
5120
+ const denom = h2 > 0 ? h2 : 1;
5121
+ setPosition(startPosRef.current + y / denom);
5101
5122
  }
5102
5123
  };
5103
5124
  const handleEnd = () => setDragging(false);
@@ -5134,21 +5155,25 @@ var SplitPane = forwardRef(function SplitPane2({
5134
5155
  computedPane1Style.bottom = 0;
5135
5156
  computedPane2Style.top = 0;
5136
5157
  if (resizePolicy === "fixFirst") {
5137
- computedPane1Style.width = p * (w - splitterSize);
5138
- computedPane2Style.left = computedPane1Style.width + splitterSize;
5158
+ const ww = w - splitterSize;
5159
+ const pane1W = ww > 0 ? p * ww : 0;
5160
+ computedPane1Style.width = pane1W;
5161
+ computedPane2Style.left = pane1W + splitterSize;
5139
5162
  Object.assign(computedSplitterStyle, {
5140
5163
  top: 0,
5141
5164
  bottom: 0,
5142
- left: computedPane1Style.width,
5165
+ left: pane1W,
5143
5166
  width: splitterSize
5144
5167
  });
5145
5168
  } else if (resizePolicy === "fixSecond") {
5146
- computedPane2Style.width = (1 - p) * (w - splitterSize);
5147
- computedPane1Style.right = computedPane2Style.width + splitterSize;
5169
+ const ww = w - splitterSize;
5170
+ const pane2W = ww > 0 ? (1 - p) * ww : 0;
5171
+ computedPane2Style.width = pane2W;
5172
+ computedPane1Style.right = pane2W + splitterSize;
5148
5173
  Object.assign(computedSplitterStyle, {
5149
5174
  top: 0,
5150
5175
  bottom: 0,
5151
- right: computedPane2Style.width,
5176
+ right: pane2W,
5152
5177
  width: splitterSize
5153
5178
  });
5154
5179
  } else {
@@ -5165,21 +5190,25 @@ var SplitPane = forwardRef(function SplitPane2({
5165
5190
  computedPane1Style.right = 0;
5166
5191
  computedPane2Style.left = 0;
5167
5192
  if (resizePolicy === "fixFirst") {
5168
- computedPane1Style.height = p * (h - splitterSize);
5169
- computedPane2Style.top = computedPane1Style.height + splitterSize;
5193
+ const hh = h - splitterSize;
5194
+ const pane1H = hh > 0 ? p * hh : 0;
5195
+ computedPane1Style.height = pane1H;
5196
+ computedPane2Style.top = pane1H + splitterSize;
5170
5197
  Object.assign(computedSplitterStyle, {
5171
5198
  left: 0,
5172
5199
  right: 0,
5173
- top: computedPane1Style.height,
5200
+ top: pane1H,
5174
5201
  height: splitterSize
5175
5202
  });
5176
5203
  } else if (resizePolicy === "fixSecond") {
5177
- computedPane2Style.height = (1 - p) * (h - splitterSize);
5178
- computedPane1Style.bottom = computedPane2Style.height + splitterSize;
5204
+ const hh = h - splitterSize;
5205
+ const pane2H = hh > 0 ? (1 - p) * hh : 0;
5206
+ computedPane2Style.height = pane2H;
5207
+ computedPane1Style.bottom = pane2H + splitterSize;
5179
5208
  Object.assign(computedSplitterStyle, {
5180
5209
  left: 0,
5181
5210
  right: 0,
5182
- bottom: computedPane2Style.height,
5211
+ bottom: pane2H,
5183
5212
  height: splitterSize
5184
5213
  });
5185
5214
  } else {
@@ -5199,18 +5228,23 @@ var SplitPane = forwardRef(function SplitPane2({
5199
5228
  height: "100%",
5200
5229
  overflow: "hidden",
5201
5230
  ...style || {}
5202
- } }, createComponent("div", { "style": computedPane1Style }, firstChild), createComponent("div", { "style": computedPane2Style }, secondChild), createComponent(DragHandle, { "onStart": handleStart, "onDelta": handleDelta, "onEnd": handleEnd, "style": computedSplitterStyle, "className": "splitter" }, splitterChild));
5231
+ } }, createComponent("div", { "style": computedPane1Style }, firstChild), createComponent("div", { "style": computedPane2Style }, secondChild), createComponent(DragHandle, { "key": internalMode, "onStart": handleStart, "onDelta": handleDelta, "onEnd": handleEnd, "style": computedSplitterStyle, "className": "splitter" }, splitterChild));
5203
5232
  });
5233
+ var EPS = 1e-6;
5204
5234
  var clamp = function(v, min, max, size, splitterSize) {
5205
- if (typeof min === "function") {
5206
- if (size > 0) min = min(size, splitterSize);
5207
- else min = 0;
5208
- }
5209
- if (typeof max === "function") {
5210
- if (size > 0) max = max(size, splitterSize);
5211
- else max = 1;
5212
- }
5213
- return Math.max(min, Math.min(max, v));
5235
+ let _min = min;
5236
+ let _max = max;
5237
+ if (typeof _min === "function") {
5238
+ if (size > 0) _min = _min(size, splitterSize);
5239
+ else _min = 0;
5240
+ }
5241
+ if (typeof _max === "function") {
5242
+ if (size > 0) _max = _max(size, splitterSize);
5243
+ else _max = 1;
5244
+ }
5245
+ _min = Math.max(0, Math.min(_min, 1));
5246
+ _max = Math.max(0, Math.min(_max, 1));
5247
+ return Math.max(_min, Math.min(_max, v));
5214
5248
  };
5215
5249
 
5216
5250
  // .tmp/src/vlq.js