Skip to content

Commit 7078cd3

Browse files
committed
Docs: Add docs for dimensions, isInView rename
1 parent 97777c5 commit 7078cd3

File tree

6 files changed

+213
-39
lines changed

6 files changed

+213
-39
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Please note after `1.0` Semver will be followed using normal protocols.
2828
* **Feature** - Added [`position()`](https://next.semantic-ui.com/api/query/dimensions#position) method that replaces `containerPosition()` with enhanced API supporting multiple coordinate systems (global, local, relative) and proper empty selection handling.
2929
* **Feature** - Added [`pagePosition()`](https://next.semantic-ui.com/api/query/dimensions#pageposition) method for getting/setting element position relative to the document.
3030
* **Feature** - Added [`dimensions()`](https://next.semantic-ui.com/api/query/dimensions#dimensions) method returning comprehensive dimension information including content, padding, border, margin, and scroll dimensions.
31-
* **Feature** - Added [`isInViewport()`](https://next.semantic-ui.com/api/query/visibility#isinviewport) method for detecting viewport intersection with optional threshold and fully visible options.
31+
* **Feature** - Added [`intersects()`](https://next.semantic-ui.com/api/query/dimensions#intersects) method for checking element intersection with configurable threshold, side detection, and detailed intersection data.
32+
* **Feature** - Added [`isInView()`](https://next.semantic-ui.com/api/query/visibility#isinview) method for detecting viewport intersection with optional threshold and fully visible options.
3233
* **Feature** - Added [`positioningParent()`](https://next.semantic-ui.com/api/query/visibility#positioningparent) method that correctly identifies positioning contexts for both absolute and fixed elements, including modern CSS properties like transform, filter, perspective, contain, and will-change.
3334
* **Feature** - Added [`show()`](https://next.semantic-ui.com/api/query/visibility#show) method for showing hidden elements with optional `calculate` parameter to determine natural display values.
3435
* **Feature** - Added [`hide()`](https://next.semantic-ui.com/api/query/visibility#hide) method for hiding elements by setting display to 'none'.

ai/packages/query.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ The Query class provides a comprehensive set of methods organized into logical c
167167
- `pagePosition(options)` - Get document-relative position (viewport + scroll)
168168
- `dimensions()` - Get comprehensive dimension info (position, size, box model)
169169
- `bounds()` - Get DOMRect bounding box information
170+
- `intersects(target, options)` - Check if elements intersect with target (with threshold, sides, details)
170171
- `offsetParent(options)` - Get offset parent for positioning
171172
- `naturalWidth()`, `naturalHeight()` - Get natural dimensions
172173
- `naturalDisplay(options)` - Get natural display value (ignoring display: none)
@@ -179,7 +180,7 @@ The Query class provides a comprehensive set of methods organized into logical c
179180
- `hide()` - Hide elements by setting display: none
180181
- `toggle(options)` - Toggle visibility state
181182
- `isVisible(options)` - Check if elements are visible (with opacity/visibility checks)
182-
- `isInViewport(options)` - Check if elements are within viewport bounds (defaults to clipping parent)
183+
- `isInView(options)` - Check if elements are within viewport bounds (defaults to clipping parent)
183184

184185
### Component Integration (Semantic UI specific)
185186
- `settings(newSettings)` - Configure component settings

docs/src/pages/api/query/dimensions.mdx

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -367,40 +367,38 @@ const precisePos = $('#element').pagePosition({ precision: 'subpixel' });
367367

368368
## dimensions
369369

370-
Gets comprehensive dimension information for elements.
370+
Gets dimension information for elements.
371371

372372
### Syntax
373373

374-
#### Get
375374
```javascript
376375
$('selector').dimensions()
377376
```
378377

379378
### Returns
380379

381-
#### Get
382-
Returns a detailed dimensions object:
383-
- **Single Element** - Dimension object with all measurements
380+
- **Single Element** - Dimension object
384381
- **Multiple Elements** - Array of dimension objects
385382
- **Empty Selection** - `undefined`
386383

387-
#### Dimension Object Properties
388-
| Property | Description |
389-
|---------------|------------------------------------------------|
390-
| top, left | Position relative to viewport |
391-
| right, bottom | Right and bottom edges relative to viewport |
392-
| pageTop, pageLeft | Position relative to document |
393-
| width | Content width |
394-
| innerWidth | Content + padding width |
395-
| outerWidth | Content + padding + border width |
396-
| marginWidth | Content + padding + border + margin width |
397-
| height | Content height |
398-
| innerHeight | Content + padding height |
399-
| outerHeight | Content + padding + border height |
400-
| marginHeight | Content + padding + border + margin height |
401-
| scrollTop, scrollLeft | Current scroll position |
402-
| scrollHeight, scrollWidth | Total scrollable dimensions |
403-
| box | Detailed box model measurements |
384+
#### Properties
385+
| Property | Description |
386+
|---------------|-----------------------------------------|
387+
| top, left | Viewport position |
388+
| right, bottom | Viewport edges |
389+
| pageTop, pageLeft | Document position |
390+
| width | Content width |
391+
| innerWidth | Content + padding |
392+
| outerWidth | Content + padding + border |
393+
| marginWidth | Content + padding + border + margin |
394+
| height | Content height |
395+
| innerHeight | Content + padding |
396+
| outerHeight | Content + padding + border |
397+
| marginHeight | Content + padding + border + margin |
398+
| scrollTop, scrollLeft | Scroll position |
399+
| scrollHeight, scrollWidth | Scrollable dimensions |
400+
| box | Box model details |
401+
| bounds | DOMRect bounding box |
404402

405403
### Usage
406404

@@ -420,3 +418,92 @@ console.log(`Margin: ${dims.box.margin.bottom}px`);
420418

421419
### Example
422420
<PlaygroundExample id="query-dimensions" direction="horizontal"></PlaygroundExample>
421+
422+
## intersects
423+
424+
Checks if elements intersect with a target.
425+
426+
### Syntax
427+
428+
```javascript
429+
$('selector').intersects(target)
430+
$('selector').intersects(target, options)
431+
```
432+
433+
### Parameters
434+
| Name | Type | Description |
435+
|---------|------------------------|------------------------|
436+
| target | string/Element/Query | Target element(s) |
437+
| options | object | Options (optional) |
438+
439+
#### Options
440+
| Name | Type | Description | Default |
441+
|---------------|--------------|---------------------------------------------------------------------|---------|
442+
| sides | string/array | Which sides must intersect ('all', 'top', 'bottom', 'left', 'right') | 'all' |
443+
| threshold | number | Minimum intersection ratio (0-1) | 0 |
444+
| fully | boolean | Source must be fully contained | false |
445+
| returnDetails | boolean | Return detailed intersection data | false |
446+
447+
### Returns
448+
449+
- **Basic** - `true` if intersects, `false` otherwise
450+
- **With returnDetails** - Details object (single element) or array (multiple elements)
451+
452+
#### Details Object
453+
| Property | Type | Description |
454+
|------------|---------|--------------------------------------|
455+
| intersects | boolean | Elements intersect |
456+
| top | boolean | Top edge within target |
457+
| bottom | boolean | Bottom edge within target |
458+
| left | boolean | Left edge within target |
459+
| right | boolean | Right edge within target |
460+
| ratio | number | Intersection/source area ratio |
461+
| rect | object | Intersection rectangle (or null) |
462+
463+
### Usage
464+
465+
```javascript
466+
// Check intersection
467+
if ($('#trigger').intersects('#popup')) {
468+
console.log('Overlapping');
469+
}
470+
471+
// Multiple targets
472+
if ($('.item').intersects('.dropzone')) {
473+
console.log('Over dropzone');
474+
}
475+
476+
// 50% overlap required
477+
$('#draggable').intersects('#target', { threshold: 0.5 });
478+
479+
// Must be fully contained
480+
$('#child').intersects('#container', { fully: true });
481+
482+
// Check specific sides
483+
$('#element').intersects('#boundary', { sides: 'top' });
484+
$('#element').intersects('#boundary', { sides: ['left', 'right'] });
485+
486+
// Get detailed data
487+
const details = $('#source').intersects('#target', { returnDetails: true });
488+
if (details.intersects) {
489+
console.log(`Overlap: ${details.ratio * 100}%`);
490+
console.log(`Area: ${details.rect.width * details.rect.height}px²`);
491+
}
492+
493+
// Multiple elements
494+
$('.item').intersects('#container', { returnDetails: true })
495+
.forEach((details, i) => {
496+
if (details.intersects) {
497+
console.log(`Item ${i}: ${details.ratio * 100}%`);
498+
}
499+
});
500+
```
501+
502+
### Notes
503+
- Uses `outerWidth` and `outerHeight` for box-model accuracy
504+
- Coordinates relative to target element
505+
- `fully` overrides `threshold` when true
506+
- With `sides`, at least one specified side must intersect
507+
508+
### Example
509+
<PlaygroundExample id="query-intersects" direction="horizontal"></PlaygroundExample>

docs/src/pages/api/query/visibility.mdx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,36 +349,34 @@ This method detects elements that create containing blocks through:
349349
### Example
350350
<PlaygroundExample id="query-positioningparent" direction="horizontal"></PlaygroundExample>
351351

352-
## isInViewport
352+
## isInView
353353

354-
Checks if all elements in the selection are within the viewport bounds.
355-
356-
> **Note** By default, this method checks visibility within the clipping parent (scrollable container). If no clipping parent exists, it falls back to the browser viewport. You can also specify a custom viewport element.
354+
Checks if all elements are within the viewport bounds.
357355

358356
### Syntax
359357

360358
```javascript
361-
$('selector').isInViewport()
362-
$('selector').isInViewport(options)
359+
$('selector').isInView()
360+
$('selector').isInView(options)
363361
```
364362

365363
### Parameters
366364

367365
| Name | Type | Description |
368366
|-----------|---------|-------------|
369-
| threshold | number | Minimum percentage (0-1) of element that must be visible. Defaults to `0` (any part visible). |
370-
| fully | boolean | Whether element must be fully within viewport. Overrides threshold. Defaults to `false`. |
371-
| viewport | Element\|Query | The viewport element to check against. Defaults to clipping parent, falls back to browser viewport. |
367+
| threshold | number | Minimum percentage (0-1) visible. Defaults to `0`. |
368+
| fully | boolean | Element must be fully within viewport. Defaults to `false`. |
369+
| viewport | Element\|Query | Viewport element to check against. Defaults to clipping parent. |
372370

373371
### Returns
374372

375-
`boolean` - `true` if **ALL** elements meet the visibility criteria, `false` if **ANY** element doesn't meet criteria.
373+
`boolean` - `true` if ALL elements meet criteria, `false` otherwise.
376374

377375
### Usage
378376

379377
```javascript
380378
// Check if any part is visible in clipping parent (default)
381-
if ($('#element').isInViewport()) {
379+
if ($('#element').isInView()) {
382380
console.log('Element is at least partially visible in container');
383381
}
384382

@@ -398,7 +396,7 @@ if ($('#tooltip').isInViewport({ viewport: $('#modal') })) {
398396
}
399397

400398
// Check multiple elements (all must meet criteria)
401-
if ($('.items').isInViewport()) {
399+
if ($('.items').isInView()) {
402400
console.log('All items are at least partially visible');
403401
}
404402
```

packages/query/src/query.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,16 @@ export class Query {
19961996
scrollHeight: document.documentElement.scrollHeight,
19971997
scrollWidth: document.documentElement.scrollWidth,
19981998
box: { padding: boxValues, border: boxValues, margin: boxValues },
1999+
bounds: {
2000+
top: 0,
2001+
left: 0,
2002+
right: window.innerWidth,
2003+
bottom: window.innerHeight,
2004+
width: window.innerWidth,
2005+
height: window.innerHeight,
2006+
x: 0,
2007+
y: 0,
2008+
},
19992009
};
20002010
}
20012011

packages/query/types/query.d.ts

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ export class Query {
10661066
border: { top: number; right: number; bottom: number; left: number; };
10671067
margin: { top: number; right: number; bottom: number; left: number; };
10681068
};
1069+
bounds: DOMRect;
10691070
}
10701071
| Array<{
10711072
top: number;
@@ -1091,19 +1092,95 @@ export class Query {
10911092
border: { top: number; right: number; bottom: number; left: number; };
10921093
margin: { top: number; right: number; bottom: number; left: number; };
10931094
};
1095+
bounds: DOMRect;
10941096
}>
10951097
| undefined;
10961098

1099+
/**
1100+
* Checks if elements in the collection intersect with a target element or elements.
1101+
* @see https://next.semantic-ui.com/api/query/dimensions#intersects
1102+
* @param target - The target element(s) to check intersection with. Can be a selector string, DOM element, or Query object.
1103+
* @param options - Configuration options for intersection detection.
1104+
* @returns Boolean indicating intersection, or detailed intersection data if returnDetails is true.
1105+
*/
1106+
intersects(
1107+
target: string | Element | Query,
1108+
options?: {
1109+
/** Which sides must intersect ('all' or specific sides). Defaults to 'all'. */
1110+
sides?: 'all' | 'top' | 'bottom' | 'left' | 'right' | Array<'top' | 'bottom' | 'left' | 'right'>;
1111+
/** Minimum intersection ratio (0-1). Defaults to 0. */
1112+
threshold?: number;
1113+
/** Whether source must be fully contained in target. Defaults to false. */
1114+
fully?: boolean;
1115+
/** Whether to return detailed intersection data. Defaults to false. */
1116+
returnDetails?: false;
1117+
},
1118+
): boolean;
1119+
1120+
/**
1121+
* Checks if elements in the collection intersect with a target element or elements, returning detailed information.
1122+
* @see https://next.semantic-ui.com/api/query/dimensions#intersects
1123+
* @param target - The target element(s) to check intersection with.
1124+
* @param options - Configuration options with returnDetails set to true.
1125+
* @returns Detailed intersection data object or array of objects.
1126+
*/
1127+
intersects(
1128+
target: string | Element | Query,
1129+
options: {
1130+
/** Which sides must intersect ('all' or specific sides). Defaults to 'all'. */
1131+
sides?: 'all' | 'top' | 'bottom' | 'left' | 'right' | Array<'top' | 'bottom' | 'left' | 'right'>;
1132+
/** Minimum intersection ratio (0-1). Defaults to 0. */
1133+
threshold?: number;
1134+
/** Whether source must be fully contained in target. Defaults to false. */
1135+
fully?: boolean;
1136+
/** Must be true to get detailed intersection data. */
1137+
returnDetails: true;
1138+
},
1139+
):
1140+
| {
1141+
intersects: boolean;
1142+
top: boolean;
1143+
bottom: boolean;
1144+
left: boolean;
1145+
right: boolean;
1146+
ratio: number;
1147+
rect: {
1148+
left: number;
1149+
top: number;
1150+
right: number;
1151+
bottom: number;
1152+
width: number;
1153+
height: number;
1154+
} | null;
1155+
}
1156+
| Array<{
1157+
intersects: boolean;
1158+
top: boolean;
1159+
bottom: boolean;
1160+
left: boolean;
1161+
right: boolean;
1162+
ratio: number;
1163+
rect: {
1164+
left: number;
1165+
top: number;
1166+
right: number;
1167+
bottom: number;
1168+
width: number;
1169+
height: number;
1170+
} | null;
1171+
}>
1172+
| null;
1173+
10971174
/**
10981175
* Checks if ALL elements in the selection are within the viewport.
1099-
* @see https://next.semantic-ui.com/api/query/visibility#isinviewport
1176+
* @see https://next.semantic-ui.com/api/query/visibility#isinview
11001177
* @param options - Configuration options.
11011178
* @param options.threshold - Minimum percentage (0-1) of element that must be visible. Defaults to 0.
1102-
* @param options.fully - Whether element must be fully within viewport. Overrides threshold. Defaults to false.
1179+
* @param options.fully - Whether element must be fully within viewport. Defaults to false.
11031180
* @param options.viewport - The viewport element to check against. Defaults to clipping parent if not specified.
11041181
* @returns true if ALL elements meet criteria, false otherwise.
11051182
*/
1106-
isInViewport(options?: { threshold?: number; fully?: boolean; viewport?: Element | Query; }): boolean;
1183+
isInView(options?: { threshold?: number; fully?: boolean; viewport?: Element | Query; }): boolean;
11071184

11081185
/**
11091186
* Shows hidden elements by setting their display to the natural display value.

0 commit comments

Comments
 (0)