@robert-stackflow/oneui 0.6.45 → 0.6.47

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.6.47
2
+
3
+ - Segmented 的服务端首屏按 aria-pressed 显示选中背景,不再等客户端测量后才出现;测量完成后无缝接回滑动指示器。合并重复的控件样式规则。
4
+
5
+ ## 0.6.46
6
+
7
+ - TableOfContents 修复快速滚动跨过多个标题、或处在长章节之间时高亮停留旧章节的问题;滚动事件按动画帧合并,与章节观察器共用同步逻辑。
8
+
1
9
  ## 0.6.45
2
10
 
3
11
  - TableOfContents 在外层容器管理滚动时,将当前章节自动滚动到容器可见范围;窗口尺寸变化时重新检查,保留焦点并避免滚动正文,支持减少动态效果偏好。
@@ -6,9 +6,11 @@
6
6
  align-self: flex-start;
7
7
  gap: 3px;
8
8
  padding: 3px;
9
- background: var(--soft);
9
+ max-width: 100%;
10
+ overflow: auto;
11
+ background: var(--segment-background);
10
12
  border: 1px solid var(--line);
11
- border-radius: calc(var(--radius) - 2px);
13
+ border-radius: var(--segment-radius);
12
14
  }
13
15
  .count {
14
16
  font-size: 0.85em;
@@ -24,11 +26,14 @@
24
26
  height: var(--segment-height, 0px);
25
27
  transform: translate(var(--segment-x, 0px), var(--segment-y, 0px));
26
28
  border-radius: calc(var(--radius) - 5px);
27
- background: var(--surface);
28
- box-shadow: 0 1px 3px #0000000d;
29
29
  pointer-events: none;
30
30
  z-index: 0;
31
31
  }
32
+ .indicator,
33
+ .segmented:not([data-ready="true"]) button[aria-pressed="true"] {
34
+ background: var(--surface);
35
+ box-shadow: 0 1px 3px #0000000d;
36
+ }
32
37
  .segmented[data-ready="true"] .indicator {
33
38
  transition:
34
39
  transform var(--motion-segment) var(--ease),
@@ -42,38 +47,25 @@
42
47
  align-items: center;
43
48
  justify-content: center;
44
49
  gap: 6px;
45
- min-height: 26px;
50
+ min-height: var(--segment-height-min);
46
51
  border: 0;
47
52
  padding: 4px 12px;
48
53
  border-radius: calc(var(--radius) - 5px);
49
54
  background: transparent;
50
55
  color: var(--muted);
51
- font-size: 12px;
56
+ font-size: var(--field-font-size);
57
+ white-space: nowrap;
58
+ cursor: pointer;
52
59
  transition:
53
60
  color var(--motion-hover) var(--ease),
54
61
  scale var(--motion-press) var(--ease);
55
62
  }
56
63
  .segmented button[aria-pressed="true"] {
57
- color: var(--fg);
64
+ color: var(--segment-selected-color);
58
65
  }
59
66
  .segmented button:active:not(:disabled) {
60
67
  scale: 0.97;
61
68
  }
62
- .segmented {
63
- max-width: 100%;
64
- overflow: auto;
65
- border-radius: var(--segment-radius);
66
- background: var(--segment-background);
67
- }
68
- .segmented button {
69
- min-height: var(--segment-height-min);
70
- font-size: var(--field-font-size);
71
- white-space: nowrap;
72
- cursor: pointer;
73
- }
74
- .segmented button[aria-pressed="true"] {
75
- color: var(--segment-selected-color);
76
- }
77
69
  .segmented button:disabled {
78
70
  opacity: 0.45;
79
71
  cursor: not-allowed;
@@ -86,5 +78,11 @@
86
78
  outline-offset: -2px;
87
79
  }
88
80
 
89
- .segmented[data-full-width] { width: 100%; align-self: stretch; }
90
- .segmented[data-full-width] button { flex: 1; min-width: 0; }
81
+ .segmented[data-full-width] {
82
+ width: 100%;
83
+ align-self: stretch;
84
+ }
85
+ .segmented[data-full-width] button {
86
+ flex: 1;
87
+ min-width: 0;
88
+ }
@@ -116,46 +116,60 @@ function TableOfContents({
116
116
  const headings = entries.map((entry) => document.getElementById(entry.id)).filter((node) => Boolean(node));
117
117
  if (!headings.length) return;
118
118
  const root = scrollParent(headings[0]);
119
- const intersections = /* @__PURE__ */ new Set();
120
119
  let previous = { first: 0, last: 0, up: false };
121
- const observer = new IntersectionObserver(
122
- (changes) => {
123
- for (const entry of changes) {
124
- if (entry.isIntersecting) intersections.add(entry.target.id);
125
- else intersections.delete(entry.target.id);
126
- }
127
- let ids = headings.filter((heading) => intersections.has(heading.id)).map((heading) => heading.id);
128
- if (!ids.length) {
129
- const top = (root?.getBoundingClientRect().top ?? 0) + scrollOffset;
130
- const nearest = headings.reduce(
131
- (best, heading) => Math.abs(heading.getBoundingClientRect().top - top) < Math.abs(best.getBoundingClientRect().top - top) ? heading : best
132
- );
133
- ids = [nearest.id];
134
- }
135
- const first2 = entries.findIndex((entry) => entry.id === ids[0]);
136
- const last2 = entries.findIndex((entry) => entry.id === ids.at(-1));
137
- const isUp = first2 < previous.first || last2 < previous.last || first2 === previous.first && last2 === previous.last && previous.up;
138
- previous = { first: first2, last: last2, up: isUp };
139
- setUp(isUp);
140
- setVisible((old) => old.join("\0") === ids.join("\0") ? old : ids);
141
- const viewTop = (root?.getBoundingClientRect().top ?? 0) + scrollOffset + 2;
142
- let primary = headings[0].id;
143
- for (const heading of headings) {
144
- if (heading.getBoundingClientRect().top <= viewTop)
145
- primary = heading.id;
146
- }
147
- if (root && root.scrollHeight > root.clientHeight + 1 && root.scrollTop + root.clientHeight >= root.scrollHeight - 2)
148
- primary = headings.at(-1).id;
149
- setInternal(primary);
150
- if (lastActive.current !== primary) {
151
- lastActive.current = primary;
152
- change.current?.(primary);
153
- }
154
- },
155
- { root, rootMargin: `-${scrollOffset}px 0px -12px 0px`, threshold: 0 }
156
- );
120
+ let frame = 0;
121
+ const sync = () => {
122
+ const bounds = root?.getBoundingClientRect();
123
+ const viewTop = (bounds?.top ?? 0) + scrollOffset + 2;
124
+ const viewBottom = bounds ? bounds.top + root.clientHeight - 12 : innerHeight - 12;
125
+ const positions = headings.map((heading) => ({
126
+ heading,
127
+ bounds: heading.getBoundingClientRect()
128
+ }));
129
+ let primary = headings[0].id;
130
+ for (const position of positions)
131
+ if (position.bounds.top <= viewTop) primary = position.heading.id;
132
+ if (root && root.scrollHeight > root.clientHeight + 1 && root.scrollTop + root.clientHeight >= root.scrollHeight - 2)
133
+ primary = headings.at(-1).id;
134
+ const visible2 = positions.filter(
135
+ (position) => position.bounds.bottom > viewTop && position.bounds.top < viewBottom
136
+ ).map((position) => position.heading.id);
137
+ const ids = visible2.length ? visible2 : [primary];
138
+ const first2 = entries.findIndex((entry) => entry.id === ids[0]);
139
+ const last2 = entries.findIndex((entry) => entry.id === ids.at(-1));
140
+ const isUp = first2 < previous.first || last2 < previous.last || first2 === previous.first && last2 === previous.last && previous.up;
141
+ previous = { first: first2, last: last2, up: isUp };
142
+ setUp(isUp);
143
+ setVisible((old) => old.join("\0") === ids.join("\0") ? old : ids);
144
+ setInternal(primary);
145
+ if (lastActive.current !== primary) {
146
+ lastActive.current = primary;
147
+ change.current?.(primary);
148
+ }
149
+ };
150
+ const schedule = () => {
151
+ if (frame) return;
152
+ frame = requestAnimationFrame(() => {
153
+ frame = 0;
154
+ sync();
155
+ });
156
+ };
157
+ const observer = new IntersectionObserver(schedule, {
158
+ root,
159
+ rootMargin: `-${scrollOffset}px 0px -12px 0px`,
160
+ threshold: 0
161
+ });
157
162
  headings.forEach((heading) => observer.observe(heading));
158
- return () => observer.disconnect();
163
+ const source = root ?? window;
164
+ source.addEventListener("scroll", schedule, { passive: true });
165
+ window.addEventListener("resize", schedule);
166
+ sync();
167
+ return () => {
168
+ observer.disconnect();
169
+ source.removeEventListener("scroll", schedule);
170
+ window.removeEventListener("resize", schedule);
171
+ cancelAnimationFrame(frame);
172
+ };
159
173
  }, [entries, scrollOffset]);
160
174
  useLayoutEffect(() => {
161
175
  const node = list.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.45",
3
+ "version": "0.6.47",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [