@stacksjs/components 0.2.662 → 0.2.663

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.
@@ -2,8 +2,9 @@
2
2
  export declare function measureTooltipPosition(trigger: HTMLElement | NativeTooltipView, panel: HTMLElement | NativeTooltipView, preferred?: TooltipSide, viewportPresentation?: boolean): Promise<unknown>;
3
3
  /**
4
4
  * Craft presents a non-modal Modal in viewport coordinates while retaining its
5
- * logical parent. There is no host layout-change subscription yet: sample only
6
- * while open, serially, and ignore replies after close/removal. Never reparent.
5
+ * logical parent. Observe layout changes as invalidations, not coordinates:
6
+ * onLayout is parent-relative and omits scrolling/transforms. Keep serial
7
+ * polling for those changes and older runtimes. Never reparent.
7
8
  */
8
9
  export declare function trackNativePopup(trigger: NativeTooltipView, panel: NativeTooltipView, preferred: TooltipSide, apply: (style: Record<string, unknown>) => void, warn?: (message: string) => void): () => void;
9
10
  /** Position in viewport coordinates; flip when possible, then keep every edge readable. */
@@ -27,6 +28,7 @@ declare interface NativeTooltipBounds {
27
28
  }
28
29
  declare interface NativeTooltipView {
29
30
  measure: () => Promise<NativeTooltipBounds>
31
+ observeLayout?: (callback: () => void) => (() => void)
30
32
  parentElement?: NativeTooltipView | null
31
33
  }
32
34
  export type TooltipSide = 'top' | 'bottom' | 'left' | 'right';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.662",
4
+ "version": "0.2.663",
5
5
  "description": "A modern component library built with STX, featuring headwind utility classes and TypeScript syntax highlighting.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -77,8 +77,8 @@
77
77
  "dependencies": {
78
78
  "@iconify-json/f7": "^1.2.2",
79
79
  "@stacksjs/ts-css": "^0.3.11",
80
- "@stacksjs/stx": "0.2.662",
81
- "bun-plugin-stx": "0.2.662",
80
+ "@stacksjs/stx": "0.2.663",
81
+ "bun-plugin-stx": "0.2.663",
82
82
  "ts-syntax-highlighter": "^0.2.17",
83
83
  "ts-video-player": "^0.1.9"
84
84
  },
@@ -13,6 +13,7 @@ interface NativeTooltipBounds {
13
13
  }
14
14
  interface NativeTooltipView {
15
15
  measure: () => Promise<NativeTooltipBounds>
16
+ observeLayout?: (callback: () => void) => (() => void)
16
17
  parentElement?: NativeTooltipView | null
17
18
  }
18
19
 
@@ -43,8 +44,9 @@ export async function measureTooltipPosition(trigger: HTMLElement | NativeToolti
43
44
 
44
45
  /**
45
46
  * Craft presents a non-modal Modal in viewport coordinates while retaining its
46
- * logical parent. There is no host layout-change subscription yet: sample only
47
- * while open, serially, and ignore replies after close/removal. Never reparent.
47
+ * logical parent. Observe layout changes as invalidations, not coordinates:
48
+ * onLayout is parent-relative and omits scrolling/transforms. Keep serial
49
+ * polling for those changes and older runtimes. Never reparent.
48
50
  */
49
51
  export function trackNativePopup(
50
52
  trigger: NativeTooltipView,
@@ -57,11 +59,23 @@ export function trackNativePopup(
57
59
  let timer: ReturnType<typeof setTimeout> | undefined
58
60
  let previous = ''
59
61
  let reported = false
62
+ let inFlight = false
63
+ let dirty = false
64
+ const subscriptions: Array<() => void> = []
65
+ function invalidate(): void {
66
+ if (!active) return
67
+ dirty = true
68
+ clearTimeout(timer)
69
+ if (!inFlight) void update()
70
+ }
60
71
  async function update(): Promise<void> {
72
+ if (!active) return
73
+ inFlight = true
74
+ dirty = false
61
75
  try {
62
76
  const point = await measureTooltipPosition(trigger, panel, preferred, true)
63
77
  if (!active) return
64
- if (point) {
78
+ if (point && !dirty) {
65
79
  const style = { position: 'absolute', left: point.left, top: point.top, right: 'auto', bottom: 'auto', margin: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, transform: [] }
66
80
  const signature = JSON.stringify(style)
67
81
  if (signature !== previous) { apply(style); previous = signature }
@@ -73,10 +87,27 @@ export function trackNativePopup(
73
87
  warn('[stx:popup] Could not measure native popup: ' + (error instanceof Error ? error.message : String(error)))
74
88
  }
75
89
  }
76
- if (active) timer = setTimeout(update, 250)
90
+ finally {
91
+ inFlight = false
92
+ // Coalesce layout bursts during a measurement into one fresh read.
93
+ // Defer it so a synchronous layout callback cannot recurse forever.
94
+ if (active) timer = setTimeout(update, dirty ? 0 : 250)
95
+ }
96
+ }
97
+ const observed = new Set<NativeTooltipView>()
98
+ for (const root of [trigger, panel]) {
99
+ for (let node: NativeTooltipView | null | undefined = root; node && !observed.has(node); node = node.parentElement) {
100
+ observed.add(node)
101
+ if (node.observeLayout) subscriptions.push(node.observeLayout(invalidate))
102
+ }
103
+ }
104
+ invalidate()
105
+ return () => {
106
+ if (!active) return
107
+ active = false
108
+ clearTimeout(timer)
109
+ for (const unsubscribe of subscriptions) unsubscribe()
77
110
  }
78
- void update()
79
- return () => { active = false; clearTimeout(timer) }
80
111
  }
81
112
 
82
113
  /** Position in viewport coordinates; flip when possible, then keep every edge readable. */