vue-pointing-bubble 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +68 -2
- package/dist/index.d.ts +3 -0
- package/dist/pointing-bubble/PointingBubble.vue.d.ts +45 -0
- package/dist/pointing-bubble/core.d.ts +13 -0
- package/dist/pointing-bubble/createBubbleController.d.ts +31 -0
- package/dist/pointing-bubble/ease.d.ts +9 -0
- package/dist/pointing-bubble/geometry.d.ts +14 -0
- package/dist/pointing-bubble/index.d.ts +11 -0
- package/dist/pointing-bubble/measure.d.ts +5 -0
- package/dist/pointing-bubble/resolveTarget.d.ts +7 -0
- package/dist/pointing-bubble/styles.d.ts +3 -0
- package/dist/pointing-bubble/tail.d.ts +12 -0
- package/dist/pointing-bubble/types.d.ts +66 -0
- package/dist/vue-pointing-bubble.cjs +9 -0
- package/dist/vue-pointing-bubble.js +505 -0
- package/package.json +59 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexey Murz Korepov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vue-pointing-bubble
|
|
2
|
+
|
|
3
|
+
Vue 3 callout / speech bubble whose SVG tail points exactly at coordinates or a DOM element.
|
|
4
|
+
|
|
5
|
+
Repository: [github.com/MurzNN/js-pointing-bubble](https://github.com/MurzNN/js-pointing-bubble) · Demo: [https://murznn.github.io/js-pointing-bubble/vue/](https://murznn.github.io/js-pointing-bubble/vue/)
|
|
6
|
+
|
|
7
|
+
- Point at `{ x, y }` or a DOM element / CSS selector
|
|
8
|
+
- Auto / fixed / manual placement with a seamless SVG tail
|
|
9
|
+
- Edge or center target anchors, resize + scroll tracking, optional glide
|
|
10
|
+
- Style with `class` / `style` (Tailwind / UnoCSS welcome); no CSS import required
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add vue-pointing-bubble
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Install via shadcn-vue
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm dlx shadcn-vue@latest add MurzNN/js-pointing-bubble/vue-pointing-bubble
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { PointingBubble } from '@/components/ui/pointing-bubble'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```vue
|
|
31
|
+
<script setup lang="ts">
|
|
32
|
+
import { ref } from 'vue'
|
|
33
|
+
import { PointingBubble } from 'vue-pointing-bubble'
|
|
34
|
+
|
|
35
|
+
const btn = ref<HTMLElement | null>(null)
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<button ref="btn">Hint</button>
|
|
40
|
+
<PointingBubble :target="btn" :max-width="240">
|
|
41
|
+
Precise callout content
|
|
42
|
+
</PointingBubble>
|
|
43
|
+
</template>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Props
|
|
47
|
+
|
|
48
|
+
| Prop | Default | Notes |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `target` | `null` | `{x,y}`, `Element`, CSS selector, or `null` (in-flow box only) |
|
|
51
|
+
| `placement` | `'auto'` | `'auto'` \| quadrant \| `'manual'` (CSS positions the box) |
|
|
52
|
+
| `targetAnchor` | `'center'` | `'center'` \| `'edge'` for element targets |
|
|
53
|
+
| `maxWidth` | — | Wrap width (px) unless CSS sets width/max-width |
|
|
54
|
+
| `tailLength` | `45` | Tip → box offset (px) |
|
|
55
|
+
| `tailBaseWidth` | `24` | Tail width at the box (px) |
|
|
56
|
+
| `padding` | `8` | Via `--pb-padding` unless CSS sets padding |
|
|
57
|
+
| `shadow` | `true` | Shared drop-shadow on overlay/box |
|
|
58
|
+
| `transitionDuration` | `200` | Glide ms (`0` off; respects reduced motion) |
|
|
59
|
+
|
|
60
|
+
Expose / ref: `update()` after non-reactive layout changes.
|
|
61
|
+
|
|
62
|
+
CSS hooks: `.pointing-bubble`, `.pointing-bubble__inner`, `.pointing-bubble__svg`, `.pointing-bubble__path`. Vars: `--pb-padding`, `--pb-max-width`, `--pb-width`.
|
|
63
|
+
|
|
64
|
+
**Breaking (v0.2):** class prefix renamed from `.vue-pointing-bubble*` / `--vpb-*` to `.pointing-bubble*` / `--pb-*`.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
2
69
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { PointingBubble, PointingBubble as Callout, PointingBubble as default, PointingBubblePlugin, type PointingBubblePluginOptions, } from './pointing-bubble';
|
|
2
|
+
export type { Placement, ResolvedPlacement, TargetAnchor, Point, BubbleTarget, BubbleConfig, BubbleController, BubbleRenderState, } from './pointing-bubble';
|
|
3
|
+
export { DEFAULT_BUBBLE_CONFIG, createBubbleController, resolveElement, isPoint, computeGeometry, buildTailPaths, } from './pointing-bubble';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ComponentPublicInstance } from 'vue';
|
|
2
|
+
import { BubbleTarget, Placement, TargetAnchor } from './core';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
target?: BubbleTarget | ComponentPublicInstance | null;
|
|
5
|
+
placement?: Placement;
|
|
6
|
+
targetAnchor?: TargetAnchor;
|
|
7
|
+
maxWidth?: number;
|
|
8
|
+
tailLength?: number;
|
|
9
|
+
tailBaseWidth?: number;
|
|
10
|
+
padding?: number | string;
|
|
11
|
+
shadow?: boolean;
|
|
12
|
+
transitionDuration?: number;
|
|
13
|
+
};
|
|
14
|
+
declare function update(): void;
|
|
15
|
+
declare var __VLS_1: {
|
|
16
|
+
placement: "none";
|
|
17
|
+
tip: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
} | null;
|
|
21
|
+
};
|
|
22
|
+
type __VLS_Slots = {} & {
|
|
23
|
+
default?: (props: typeof __VLS_1) => any;
|
|
24
|
+
};
|
|
25
|
+
declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
|
|
26
|
+
update: typeof update;
|
|
27
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
28
|
+
placement: Placement;
|
|
29
|
+
tailLength: number;
|
|
30
|
+
tailBaseWidth: number;
|
|
31
|
+
target: BubbleTarget | ComponentPublicInstance;
|
|
32
|
+
targetAnchor: TargetAnchor;
|
|
33
|
+
maxWidth: number;
|
|
34
|
+
padding: string | number;
|
|
35
|
+
shadow: boolean;
|
|
36
|
+
transitionDuration: number;
|
|
37
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
38
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
39
|
+
declare const _default: typeof __VLS_export;
|
|
40
|
+
export default _default;
|
|
41
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
42
|
+
new (): {
|
|
43
|
+
$slots: S;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { Placement, ResolvedPlacement, TargetAnchor, Point, BubbleTarget, FrameRect, LocalRect, BoxMeasure, Geometry, Room, TailPaths, BubbleConfig, StyleMap, } from './types';
|
|
2
|
+
export { DEFAULT_BUBBLE_CONFIG } from './types';
|
|
3
|
+
export { injectBubbleStyles, SHADOW } from './styles';
|
|
4
|
+
export { isPoint, resolveElement } from './resolveTarget';
|
|
5
|
+
export { sameKeys, measureFrame, measureBox } from './measure';
|
|
6
|
+
export { computeRoom, roomierSide, computeGeometry } from './geometry';
|
|
7
|
+
export type { ComputeGeometryOptions } from './geometry';
|
|
8
|
+
export { easeGeometry } from './ease';
|
|
9
|
+
export type { EaseHandle } from './ease';
|
|
10
|
+
export { buildTailPaths } from './tail';
|
|
11
|
+
export type { BuildTailOptions } from './tail';
|
|
12
|
+
export { createBubbleController } from './createBubbleController';
|
|
13
|
+
export type { BubbleRenderState, BubbleControllerOptions, BubbleController, } from './createBubbleController';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BubbleConfig, BubbleTarget, Point, ResolvedPlacement, StyleMap, TailPaths } from './types';
|
|
2
|
+
export interface BubbleRenderState {
|
|
3
|
+
hasTarget: boolean;
|
|
4
|
+
placement: ResolvedPlacement;
|
|
5
|
+
tip: Point | null;
|
|
6
|
+
/** Tip passed to slot/children (resolved geometry tip when available). */
|
|
7
|
+
slotTip: Point | null;
|
|
8
|
+
overlayStyle: StyleMap;
|
|
9
|
+
boxStyle: StyleMap;
|
|
10
|
+
/** When no target, root element is the box. */
|
|
11
|
+
rootIsBox: boolean;
|
|
12
|
+
tail: TailPaths | null;
|
|
13
|
+
boxFill: string;
|
|
14
|
+
boxStroke: string;
|
|
15
|
+
boxStrokeWidth: number;
|
|
16
|
+
boxZIndex: string;
|
|
17
|
+
}
|
|
18
|
+
export interface BubbleControllerOptions {
|
|
19
|
+
getRootEl: () => HTMLElement | null;
|
|
20
|
+
getBoxEl: () => HTMLElement | null;
|
|
21
|
+
onChange?: (state: BubbleRenderState) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface BubbleController {
|
|
24
|
+
update: () => void;
|
|
25
|
+
setConfig: (partial: Partial<BubbleConfig>) => void;
|
|
26
|
+
getConfig: () => BubbleConfig;
|
|
27
|
+
getState: () => BubbleRenderState;
|
|
28
|
+
destroy: () => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createBubbleController(options: BubbleControllerOptions): BubbleController;
|
|
31
|
+
export type { BubbleTarget };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Geometry } from './types';
|
|
2
|
+
export interface EaseHandle {
|
|
3
|
+
cancel: () => void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Ease `from` → `to` with ease-out cubic. Calls `onFrame` each tick.
|
|
7
|
+
* Manual placement only animates tip coords (CSS owns the box).
|
|
8
|
+
*/
|
|
9
|
+
export declare function easeGeometry(from: Geometry | null, to: Geometry | null, durationMs: number, onFrame: (value: Geometry | null) => void): EaseHandle;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BoxMeasure, FrameRect, Geometry, LocalRect, Placement, Point, Room, TargetAnchor } from './types';
|
|
2
|
+
export declare function computeRoom(tip: Point, frame: FrameRect, tailLength: number): Room;
|
|
3
|
+
export declare function roomierSide(room: Room): 'left' | 'right';
|
|
4
|
+
export interface ComputeGeometryOptions {
|
|
5
|
+
tip: Point;
|
|
6
|
+
box: BoxMeasure;
|
|
7
|
+
frame: FrameRect;
|
|
8
|
+
placement: Placement;
|
|
9
|
+
targetAnchor: TargetAnchor;
|
|
10
|
+
targetRect: LocalRect | null;
|
|
11
|
+
room: Room;
|
|
12
|
+
tailLength: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function computeGeometry(opts: ComputeGeometryOptions): Geometry | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from 'vue';
|
|
2
|
+
import { default as PointingBubble } from './PointingBubble.vue';
|
|
3
|
+
export type { Placement, ResolvedPlacement, TargetAnchor, Point, BubbleTarget, BubbleConfig, BubbleController, BubbleRenderState, } from './core';
|
|
4
|
+
export { DEFAULT_BUBBLE_CONFIG, createBubbleController, resolveElement, isPoint, computeGeometry, buildTailPaths, } from './core';
|
|
5
|
+
export { PointingBubble };
|
|
6
|
+
export { PointingBubble as Callout };
|
|
7
|
+
export { PointingBubble as default };
|
|
8
|
+
export interface PointingBubblePluginOptions {
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const PointingBubblePlugin: Plugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BoxMeasure, FrameRect } from './types';
|
|
2
|
+
export declare function sameKeys(a: Record<string, unknown> | null | undefined, b: Record<string, unknown> | null | undefined): boolean;
|
|
3
|
+
/** Measure root frame including ancestor CSS scale (e.g. Slidev). */
|
|
4
|
+
export declare function measureFrame(root: HTMLElement): FrameRect;
|
|
5
|
+
export declare function measureBox(boxEl: HTMLElement, rootEl: HTMLElement, frame: FrameRect, manual: boolean): BoxMeasure;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BubbleTarget, Point } from './types';
|
|
2
|
+
export declare function isPoint(value: unknown): value is Point;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a CSS selector or Element. Adapters unwrap framework component
|
|
5
|
+
* instances / refs before calling this.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveElement(target: BubbleTarget): Element | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Geometry, TailPaths } from './types';
|
|
2
|
+
export interface BuildTailOptions {
|
|
3
|
+
geometry: Geometry;
|
|
4
|
+
strokeWidth: number;
|
|
5
|
+
radius: string;
|
|
6
|
+
tailBaseWidth: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Build fill + stroke SVG path `d` for the tail from the box wall facing the tip.
|
|
10
|
+
* Fill extends 1px past the border inner edge to cover zoom snapping seams.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildTailPaths(opts: BuildTailOptions): TailPaths | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type Placement = 'auto' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'manual';
|
|
2
|
+
export type ResolvedPlacement = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'manual' | 'none';
|
|
3
|
+
export type TargetAnchor = 'center' | 'edge';
|
|
4
|
+
export interface Point {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
/** Core target: coords, DOM element, CSS selector, or null (box-only / in-flow). */
|
|
9
|
+
export type BubbleTarget = Point | Element | string | null;
|
|
10
|
+
export interface FrameRect {
|
|
11
|
+
left: number;
|
|
12
|
+
top: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
scaleX: number;
|
|
16
|
+
scaleY: number;
|
|
17
|
+
viewportWidth: number;
|
|
18
|
+
viewportHeight: number;
|
|
19
|
+
}
|
|
20
|
+
export interface LocalRect {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
right: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
}
|
|
26
|
+
export interface BoxMeasure {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
fill: string;
|
|
32
|
+
stroke: string;
|
|
33
|
+
strokeWidth: number;
|
|
34
|
+
radius: string;
|
|
35
|
+
zIndex: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Geometry {
|
|
38
|
+
placement: ResolvedPlacement;
|
|
39
|
+
tx: number;
|
|
40
|
+
ty: number;
|
|
41
|
+
bx: number;
|
|
42
|
+
by: number;
|
|
43
|
+
w: number;
|
|
44
|
+
h: number;
|
|
45
|
+
}
|
|
46
|
+
export interface Room {
|
|
47
|
+
left: number;
|
|
48
|
+
right: number;
|
|
49
|
+
}
|
|
50
|
+
export interface TailPaths {
|
|
51
|
+
fill: string;
|
|
52
|
+
stroke: string | null;
|
|
53
|
+
}
|
|
54
|
+
export interface BubbleConfig {
|
|
55
|
+
target: BubbleTarget;
|
|
56
|
+
placement: Placement;
|
|
57
|
+
targetAnchor: TargetAnchor;
|
|
58
|
+
maxWidth?: number;
|
|
59
|
+
tailLength: number;
|
|
60
|
+
tailBaseWidth: number;
|
|
61
|
+
padding: number | string;
|
|
62
|
+
shadow: boolean;
|
|
63
|
+
transitionDuration: number;
|
|
64
|
+
}
|
|
65
|
+
export declare const DEFAULT_BUBBLE_CONFIG: BubbleConfig;
|
|
66
|
+
export type StyleMap = Record<string, string | number | undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("vue"),T={target:null,placement:"auto",targetAnchor:"center",tailLength:45,tailBaseWidth:24,padding:8,shadow:!0,transitionDuration:200},I="pointing-bubble-styles",U=`:where(.pointing-bubble__inner) {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
width: var(--pb-width, max-content);
|
|
4
|
+
max-width: var(--pb-max-width, none);
|
|
5
|
+
padding: var(--pb-padding);
|
|
6
|
+
background: white;
|
|
7
|
+
border: 2px solid gray;
|
|
8
|
+
border-radius: 8px;
|
|
9
|
+
}`,_="drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25))";function H(n=document){if(n.getElementById(I))return;const e=n.createElement("style");e.id=I,e.textContent=U,n.head.prepend(e)}function P(n){return typeof n=="object"&&n!==null&&typeof n.x=="number"&&typeof n.y=="number"&&n.nodeType!==1}function D(n){return typeof Element>"u"||n==null?null:typeof n=="string"?document.querySelector(n):n instanceof Element?n:null}function z(n,e){return!n||!e?!1:Object.keys(n).every(t=>n[t]===e[t])}function X(n){const e=n.getBoundingClientRect(),t=getComputedStyle(n),a=parseFloat(t.width)||0,l=parseFloat(t.height)||0;return{left:e.left,top:e.top,width:a,height:l,scaleX:a?e.width/a:1,scaleY:l?e.height/l:1,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight}}function G(n,e,t,a){const l=getComputedStyle(n),{scaleX:r,scaleY:u}=t,i=n.getBoundingClientRect(),d=e.getBoundingClientRect();return{x:a?(i.left-d.left)/r:0,y:a?(i.top-d.top)/u:0,width:i.width/r,height:i.height/u,fill:l.backgroundColor,stroke:l.borderTopColor,strokeWidth:parseFloat(l.borderTopWidth)||0,radius:l.borderTopLeftRadius,zIndex:l.zIndex}}function F(n,e,t){const a=n.x-t;let l=a,r=e.width?e.width-n.x-t:1/0;return e.viewportWidth&&(l=Math.min(l,e.left/e.scaleX+a),r=Math.min(r,(e.viewportWidth-e.left)/e.scaleX-n.x-t)),{left:Math.max(0,l),right:Math.max(0,r)}}function O(n){return n.left>n.right?"left":"right"}function j(n){const{tip:e,box:t,frame:a,placement:l,targetRect:r,room:u,tailLength:i}=n;if(!t.width||!t.height)return null;const{width:d,height:f}=t,{x,y}=e,E=l==="manual",o=n.targetAnchor==="edge"?r:null;if(E){if(o){const v=t.x+d/2,w=t.y+f/2;if(!(v>=o.left&&v<=o.right&&w>=o.top&&w<=o.bottom)){const g=Math.min(o.right,Math.max(o.left,v)),b=Math.min(o.bottom,Math.max(o.top,w));return{placement:"manual",tx:g,ty:b,bx:t.x,by:t.y,w:d,h:f}}}return{placement:"manual",tx:x,ty:y,bx:t.x,by:t.y,w:d,h:f}}const k=v=>o?v==="top"?o.top:o.bottom:y;let S=l;if(l==="auto"){let v=y>(a.height||600)/2?"top":"bottom",w=O(u);const{scaleX:p,scaleY:g}=a;if(a.viewportHeight){const b=a.top+(k("top")-f-i)*g>=0,B=a.top+(k("bottom")+f+i)*g<=a.viewportHeight;v==="top"&&!b&&B?v="bottom":v==="bottom"&&!B&&b&&(v="top")}if(a.viewportWidth){const b=a.left+(x-d-i)*p>=0,B=a.left+(x+d+i)*p<=a.viewportWidth;w==="left"&&!b&&B?w="right":w==="right"&&!B&&b&&(w="left")}S=`${v}-${w}`}const[W,C]=S.split("-"),$=k(W);return{placement:S,tx:x,ty:$,bx:C==="left"?x-d-i:x+i,by:W==="top"?$-f-i:$+i,w:d,h:f}}const q=["tx","ty","bx","by"],V=["tx","ty"];function Z(){return typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function K(n,e,t,a){let l=0;const r=()=>{typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(l)};if(!e||!n||t<=0||typeof requestAnimationFrame>"u"||Z())return a(e),{cancel:r};const u=performance.now(),i=d=>{const f=Math.min(1,(d-u)/t),x=1-Math.pow(1-f,3),y={...e},E=e.placement==="manual"?V:q;for(const o of E)y[o]=n[o]+(e[o]-n[o])*x;a(y),f<1&&(l=requestAnimationFrame(i))};return l=requestAnimationFrame(i),{cancel:r}}function N(n){const{geometry:e,strokeWidth:t,radius:a,tailBaseWidth:l}=n,{placement:r,tx:u,ty:i,bx:d,by:f,w:x,h:y}=e,E=parseFloat(a)*(a.endsWith("%")?Math.min(x,y)/100:1)||0,o=l/2,k=(s,c,h)=>c>h?(c+h)/2:Math.min(h,Math.max(c,s));let S=null,W=0;if(r==="manual"){const s=Math.max(d-u,u-(d+x),0),c=Math.max(f-i,i-(f+y),0);if(s>0&&s>=c)S=u<d?"left":"right",W=i;else if(c>0)S=i<f?"top":"bottom",W=u;else return null}else if(r!=="none"){const[s,c]=r.split("-");S=c==="left"?"right":"left",W=f+y*(s==="top"?.65:.35)}else return null;const C=1,$=S==="top"||S==="bottom",v={left:(s,c)=>[d-c,s],right:(s,c)=>[d+x+c,s],top:(s,c)=>[s,f-c],bottom:(s,c)=>[s,f+y+c]}[S],w={left:d-u,right:u-d-x,top:f-i,bottom:i-f-y}[S],p=$?k(W,d+E+o+t/2,d+x-E-o-t/2):k(W,f+E+o+t/2,f+y-E-o-t/2),g=Math.max(0,Math.min(t,w/2)),b=([s,c])=>`${s} ${c}`,B=(s,c)=>{const h=v(s,g),L=Math.hypot(u-h[0],i-h[1])||1,R=[h[0]+(u-h[0])*g/L,h[1]+(i-h[1])*g/L];return{inner:b(v(s,c)),outer:b(v(s,0)),ctrl:b(h),end:b(R)}},M=s=>{const c=B(p-o,s),h=B(p+o,s);return`M ${c.inner} L ${c.outer} Q ${c.ctrl} ${c.end} L ${u} ${i} L ${h.end} Q ${h.ctrl} ${h.outer} L ${h.inner}`};return{fill:`${M(-t-C)} Z`,stroke:t?M(-t):null}}function Q(n){return{hasTarget:n,placement:"none",tip:null,slotTip:null,overlayStyle:{},boxStyle:{},rootIsBox:!n,tail:null,boxFill:"",boxStroke:"",boxStrokeWidth:0,boxZIndex:"auto"}}function Y(n){H();let e={...T},t=null,a=null,l=null,r={left:0,top:0,width:0,height:0,scaleX:1,scaleY:1,viewportWidth:0,viewportHeight:0},u=null,i=null,d=null,f=null,x=Q(!1);const y=()=>{x=E(),n.onChange?.(x)};function E(){const p=e.target!=null,g=e.placement==="manual",b=p?u?.placement??"none":"none",B={position:"absolute",inset:"0",pointerEvents:"none",filter:e.shadow?_:void 0},M=l?.zIndex;M&&M!=="auto"&&(B.zIndex=M);const s={"--pb-padding":typeof e.padding=="number"?`${e.padding}px`:e.padding};if(e.maxWidth!=null&&(s["--pb-max-width"]=`${e.maxWidth}px`),!p)s["--pb-width"]="fit-content",e.shadow&&(s.filter=_);else if(Object.assign(s,{position:"absolute",pointerEvents:"auto",visibility:u?"visible":"hidden"}),g)s["--pb-width"]="fit-content";else if(Object.assign(s,{left:`${u?.bx??0}px`,top:`${u?.by??0}px`,margin:"0"}),e.maxWidth==null&&t){const h=F(t,r,e.tailLength),L=i?.placement??e.placement,R=L==="auto"?O(h):L.split("-")[1];s["--pb-max-width"]=`${h[R]}px`}const c=p&&u&&l?N({geometry:u,strokeWidth:l.strokeWidth,radius:l.radius,tailBaseWidth:e.tailBaseWidth}):null;return{hasTarget:p,placement:b,tip:t,slotTip:i?{x:i.tx,y:i.ty}:t,overlayStyle:B,boxStyle:s,rootIsBox:!p,tail:c,boxFill:l?.fill??"",boxStroke:l?.stroke??"",boxStrokeWidth:l?.strokeWidth??0,boxZIndex:l?.zIndex??"auto"}}function o(){if(!t||!l){i=null,k(null);return}const p=F(t,r,e.tailLength);i=j({tip:t,box:l,frame:r,placement:e.placement,targetAnchor:e.targetAnchor,targetRect:a,room:p,tailLength:e.tailLength}),k(i)}function k(p){d?.cancel(),d=K(u,p,e.transitionDuration,g=>{u=g,y()})}function S(){const p=n.getRootEl(),g=n.getBoxEl();if(!g||e.target==null||!p)return;const b=G(g,p,r,e.placement==="manual");z(b,l)||(l=b)}function W(){const p=n.getRootEl();if(e.target==null||!p){t=null,a=null,l=null,i=null,u=null,y();return}r=X(p);const g=D(e.target);if(g){const b=g.getBoundingClientRect(),{scaleX:B,scaleY:M,left:s,top:c}=r,h={left:(b.left-s)/B,top:(b.top-c)/M,right:(b.right-s)/B,bottom:(b.bottom-c)/M};z(h,a)||(a=h),t={x:(h.left+h.right)/2,y:(h.top+h.bottom)/2}}else if(P(e.target))a=null,t={x:e.target.x,y:e.target.y};else{a=null,t=null,l=null,i=null,u=null,y();return}S(),o()}function C(){W()}typeof window<"u"&&(window.addEventListener("resize",C),window.addEventListener("scroll",C,!0));function $(){if(typeof ResizeObserver>"u")return;f?.disconnect(),f=new ResizeObserver(()=>W());const p=n.getRootEl(),g=n.getBoxEl();p&&f.observe(p),g&&f.observe(g)}const v=W;function w(){$(),v()}return{update:w,setConfig(p){e={...e,...p},w()},getConfig:()=>e,getState:()=>x,destroy(){d?.cancel(),f?.disconnect(),typeof window<"u"&&(window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0))}}}const J=["data-placement"],tt=["d","fill"],et=["d","stroke","stroke-width"],A=m.defineComponent({name:"PointingBubble",inheritAttrs:!1,__name:"PointingBubble",props:{target:{default:null},placement:{default:"auto"},targetAnchor:{default:"center"},maxWidth:{default:void 0},tailLength:{default:45},tailBaseWidth:{default:24},padding:{default:8},shadow:{type:Boolean,default:!0},transitionDuration:{default:200}},setup(n,{expose:e}){const t=n,a=m.ref(null),l=m.ref(null),r=m.ref({hasTarget:!1,placement:"none",tip:null,slotTip:null,overlayStyle:{},boxStyle:{},rootIsBox:!0,tail:null,boxFill:"",boxStroke:"",boxStrokeWidth:0,boxZIndex:"auto"});function u(o){return o==null?null:typeof o=="string"||typeof Element<"u"&&o instanceof Element?o:typeof o=="object"&&"$el"in o&&o.$el instanceof Element?o.$el:typeof o=="object"&&typeof o.x=="number"&&typeof o.y=="number"?o:null}const i=Y({getRootEl:()=>a.value,getBoxEl:()=>l.value,onChange:o=>{r.value=o}});function d(){i.setConfig({target:u(t.target),placement:t.placement,targetAnchor:t.targetAnchor,maxWidth:t.maxWidth,tailLength:t.tailLength,tailBaseWidth:t.tailBaseWidth,padding:t.padding,shadow:t.shadow,transitionDuration:t.transitionDuration})}m.watch(()=>[t.target,typeof t.target=="object"&&t.target&&"x"in t.target?t.target.x:null,typeof t.target=="object"&&t.target&&"y"in t.target?t.target.y:null,t.placement,t.targetAnchor,t.maxWidth,t.tailLength,t.tailBaseWidth,t.padding,t.shadow,t.transitionDuration],d,{flush:"post"}),m.onMounted(()=>{d()}),m.onUpdated(()=>{i.update()}),m.onBeforeUnmount(()=>{i.destroy()});function f(){i.update()}e({update:f});const x=m.computed(()=>r.value.rootIsBox?r.value.boxStyle:r.value.overlayStyle),y=m.computed(()=>r.value.rootIsBox?{display:"contents"}:r.value.boxStyle),E=m.computed(()=>({position:"absolute",inset:"0",width:"100%",height:"100%",overflow:"visible",zIndex:r.value.boxZIndex}));return(o,k)=>(m.openBlock(),m.createElementBlock("div",m.mergeProps({ref_key:"rootRef",ref:a,class:["pointing-bubble",{"pointing-bubble__inner":!n.target}],"data-placement":r.value.placement},n.target?{}:o.$attrs,{style:x.value}),[m.createElementVNode("div",m.mergeProps({ref_key:"boxRef",ref:l,class:{"pointing-bubble__inner":!!n.target}},n.target?o.$attrs:{},{style:y.value}),[m.renderSlot(o.$slots,"default",{placement:r.value.placement,tip:r.value.slotTip},()=>[k[0]||(k[0]=m.createElementVNode("p",{style:{margin:0,fontSize:"14px",fontWeight:600,color:"#1e293b"}}," Callout content ",-1))])],16),n.target&&r.value.tail?(m.openBlock(),m.createElementBlock("svg",{key:0,class:"pointing-bubble__svg",style:m.normalizeStyle(E.value)},[m.createElementVNode("path",{class:"pointing-bubble__path",d:r.value.tail.fill,fill:r.value.boxFill},null,8,tt),r.value.tail.stroke?(m.openBlock(),m.createElementBlock("path",{key:0,class:"pointing-bubble__path",d:r.value.tail.stroke,fill:"none",stroke:r.value.boxStroke,"stroke-width":r.value.boxStrokeWidth,"stroke-linejoin":"round","stroke-linecap":"butt"},null,8,et)):m.createCommentVNode("",!0)],4)):m.createCommentVNode("",!0)],16,J))}}),nt={install(n,e={}){const t=e.name??"PointingBubble";n.component(t,A),n.component("Callout",A)}};exports.Callout=A;exports.DEFAULT_BUBBLE_CONFIG=T;exports.PointingBubble=A;exports.PointingBubblePlugin=nt;exports.buildTailPaths=N;exports.computeGeometry=j;exports.createBubbleController=Y;exports.default=A;exports.isPoint=P;exports.resolveElement=D;
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { defineComponent as U, ref as L, watch as X, onMounted as N, onUpdated as Z, onBeforeUnmount as q, computed as R, openBlock as I, createElementBlock as z, mergeProps as F, createElementVNode as _, renderSlot as G, normalizeStyle as K, createCommentVNode as T } from "vue";
|
|
2
|
+
const Q = {
|
|
3
|
+
target: null,
|
|
4
|
+
placement: "auto",
|
|
5
|
+
targetAnchor: "center",
|
|
6
|
+
tailLength: 45,
|
|
7
|
+
tailBaseWidth: 24,
|
|
8
|
+
padding: 8,
|
|
9
|
+
shadow: !0,
|
|
10
|
+
transitionDuration: 200
|
|
11
|
+
}, D = "pointing-bubble-styles", V = `:where(.pointing-bubble__inner) {
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
width: var(--pb-width, max-content);
|
|
14
|
+
max-width: var(--pb-max-width, none);
|
|
15
|
+
padding: var(--pb-padding);
|
|
16
|
+
background: white;
|
|
17
|
+
border: 2px solid gray;
|
|
18
|
+
border-radius: 8px;
|
|
19
|
+
}`, j = "drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25))";
|
|
20
|
+
function J(n = document) {
|
|
21
|
+
if (n.getElementById(D)) return;
|
|
22
|
+
const e = n.createElement("style");
|
|
23
|
+
e.id = D, e.textContent = V, n.head.prepend(e);
|
|
24
|
+
}
|
|
25
|
+
function tt(n) {
|
|
26
|
+
return typeof n == "object" && n !== null && typeof n.x == "number" && typeof n.y == "number" && n.nodeType !== 1;
|
|
27
|
+
}
|
|
28
|
+
function et(n) {
|
|
29
|
+
return typeof Element > "u" || n == null ? null : typeof n == "string" ? document.querySelector(n) : n instanceof Element ? n : null;
|
|
30
|
+
}
|
|
31
|
+
function O(n, e) {
|
|
32
|
+
return !n || !e ? !1 : Object.keys(n).every((t) => n[t] === e[t]);
|
|
33
|
+
}
|
|
34
|
+
function nt(n) {
|
|
35
|
+
const e = n.getBoundingClientRect(), t = getComputedStyle(n), a = parseFloat(t.width) || 0, l = parseFloat(t.height) || 0;
|
|
36
|
+
return {
|
|
37
|
+
left: e.left,
|
|
38
|
+
top: e.top,
|
|
39
|
+
width: a,
|
|
40
|
+
height: l,
|
|
41
|
+
scaleX: a ? e.width / a : 1,
|
|
42
|
+
scaleY: l ? e.height / l : 1,
|
|
43
|
+
viewportWidth: window.innerWidth,
|
|
44
|
+
viewportHeight: window.innerHeight
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function ot(n, e, t, a) {
|
|
48
|
+
const l = getComputedStyle(n), { scaleX: r, scaleY: u } = t, i = n.getBoundingClientRect(), d = e.getBoundingClientRect();
|
|
49
|
+
return {
|
|
50
|
+
x: a ? (i.left - d.left) / r : 0,
|
|
51
|
+
y: a ? (i.top - d.top) / u : 0,
|
|
52
|
+
width: i.width / r,
|
|
53
|
+
height: i.height / u,
|
|
54
|
+
fill: l.backgroundColor,
|
|
55
|
+
stroke: l.borderTopColor,
|
|
56
|
+
strokeWidth: parseFloat(l.borderTopWidth) || 0,
|
|
57
|
+
radius: l.borderTopLeftRadius,
|
|
58
|
+
zIndex: l.zIndex
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function P(n, e, t) {
|
|
62
|
+
const a = n.x - t;
|
|
63
|
+
let l = a, r = e.width ? e.width - n.x - t : 1 / 0;
|
|
64
|
+
return e.viewportWidth && (l = Math.min(l, e.left / e.scaleX + a), r = Math.min(
|
|
65
|
+
r,
|
|
66
|
+
(e.viewportWidth - e.left) / e.scaleX - n.x - t
|
|
67
|
+
)), { left: Math.max(0, l), right: Math.max(0, r) };
|
|
68
|
+
}
|
|
69
|
+
function H(n) {
|
|
70
|
+
return n.left > n.right ? "left" : "right";
|
|
71
|
+
}
|
|
72
|
+
function lt(n) {
|
|
73
|
+
const { tip: e, box: t, frame: a, placement: l, targetRect: r, room: u, tailLength: i } = n;
|
|
74
|
+
if (!t.width || !t.height) return null;
|
|
75
|
+
const { width: d, height: f } = t, { x: g, y: x } = e, W = l === "manual", o = n.targetAnchor === "edge" ? r : null;
|
|
76
|
+
if (W) {
|
|
77
|
+
if (o) {
|
|
78
|
+
const y = t.x + d / 2, v = t.y + f / 2;
|
|
79
|
+
if (!(y >= o.left && y <= o.right && v >= o.top && v <= o.bottom)) {
|
|
80
|
+
const b = Math.min(o.right, Math.max(o.left, y)), m = Math.min(o.bottom, Math.max(o.top, v));
|
|
81
|
+
return { placement: "manual", tx: b, ty: m, bx: t.x, by: t.y, w: d, h: f };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { placement: "manual", tx: g, ty: x, bx: t.x, by: t.y, w: d, h: f };
|
|
85
|
+
}
|
|
86
|
+
const B = (y) => o ? y === "top" ? o.top : o.bottom : x;
|
|
87
|
+
let S = l;
|
|
88
|
+
if (l === "auto") {
|
|
89
|
+
let y = x > (a.height || 600) / 2 ? "top" : "bottom", v = H(u);
|
|
90
|
+
const { scaleX: p, scaleY: b } = a;
|
|
91
|
+
if (a.viewportHeight) {
|
|
92
|
+
const m = a.top + (B("top") - f - i) * b >= 0, w = a.top + (B("bottom") + f + i) * b <= a.viewportHeight;
|
|
93
|
+
y === "top" && !m && w ? y = "bottom" : y === "bottom" && !w && m && (y = "top");
|
|
94
|
+
}
|
|
95
|
+
if (a.viewportWidth) {
|
|
96
|
+
const m = a.left + (g - d - i) * p >= 0, w = a.left + (g + d + i) * p <= a.viewportWidth;
|
|
97
|
+
v === "left" && !m && w ? v = "right" : v === "right" && !w && m && (v = "left");
|
|
98
|
+
}
|
|
99
|
+
S = `${y}-${v}`;
|
|
100
|
+
}
|
|
101
|
+
const [k, $] = S.split("-"), M = B(k);
|
|
102
|
+
return {
|
|
103
|
+
placement: S,
|
|
104
|
+
tx: g,
|
|
105
|
+
ty: M,
|
|
106
|
+
bx: $ === "left" ? g - d - i : g + i,
|
|
107
|
+
by: k === "top" ? M - f - i : M + i,
|
|
108
|
+
w: d,
|
|
109
|
+
h: f
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const it = ["tx", "ty", "bx", "by"], rt = ["tx", "ty"];
|
|
113
|
+
function at() {
|
|
114
|
+
return typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
115
|
+
}
|
|
116
|
+
function st(n, e, t, a) {
|
|
117
|
+
let l = 0;
|
|
118
|
+
const r = () => {
|
|
119
|
+
typeof cancelAnimationFrame < "u" && cancelAnimationFrame(l);
|
|
120
|
+
};
|
|
121
|
+
if (!e || !n || t <= 0 || typeof requestAnimationFrame > "u" || at())
|
|
122
|
+
return a(e), { cancel: r };
|
|
123
|
+
const u = performance.now(), i = (d) => {
|
|
124
|
+
const f = Math.min(1, (d - u) / t), g = 1 - Math.pow(1 - f, 3), x = { ...e }, W = e.placement === "manual" ? rt : it;
|
|
125
|
+
for (const o of W)
|
|
126
|
+
x[o] = n[o] + (e[o] - n[o]) * g;
|
|
127
|
+
a(x), f < 1 && (l = requestAnimationFrame(i));
|
|
128
|
+
};
|
|
129
|
+
return l = requestAnimationFrame(i), { cancel: r };
|
|
130
|
+
}
|
|
131
|
+
function ct(n) {
|
|
132
|
+
const { geometry: e, strokeWidth: t, radius: a, tailBaseWidth: l } = n, { placement: r, tx: u, ty: i, bx: d, by: f, w: g, h: x } = e, W = parseFloat(a) * (a.endsWith("%") ? Math.min(g, x) / 100 : 1) || 0, o = l / 2, B = (s, c, h) => c > h ? (c + h) / 2 : Math.min(h, Math.max(c, s));
|
|
133
|
+
let S = null, k = 0;
|
|
134
|
+
if (r === "manual") {
|
|
135
|
+
const s = Math.max(d - u, u - (d + g), 0), c = Math.max(f - i, i - (f + x), 0);
|
|
136
|
+
if (s > 0 && s >= c)
|
|
137
|
+
S = u < d ? "left" : "right", k = i;
|
|
138
|
+
else if (c > 0)
|
|
139
|
+
S = i < f ? "top" : "bottom", k = u;
|
|
140
|
+
else
|
|
141
|
+
return null;
|
|
142
|
+
} else if (r !== "none") {
|
|
143
|
+
const [s, c] = r.split("-");
|
|
144
|
+
S = c === "left" ? "right" : "left", k = f + x * (s === "top" ? 0.65 : 0.35);
|
|
145
|
+
} else
|
|
146
|
+
return null;
|
|
147
|
+
const $ = 1, M = S === "top" || S === "bottom", y = {
|
|
148
|
+
left: (s, c) => [d - c, s],
|
|
149
|
+
right: (s, c) => [d + g + c, s],
|
|
150
|
+
top: (s, c) => [s, f - c],
|
|
151
|
+
bottom: (s, c) => [s, f + x + c]
|
|
152
|
+
}[S], v = {
|
|
153
|
+
left: d - u,
|
|
154
|
+
right: u - d - g,
|
|
155
|
+
top: f - i,
|
|
156
|
+
bottom: i - f - x
|
|
157
|
+
}[S], p = M ? B(k, d + W + o + t / 2, d + g - W - o - t / 2) : B(k, f + W + o + t / 2, f + x - W - o - t / 2), b = Math.max(0, Math.min(t, v / 2)), m = ([s, c]) => `${s} ${c}`, w = (s, c) => {
|
|
158
|
+
const h = y(s, b), A = Math.hypot(u - h[0], i - h[1]) || 1, C = [
|
|
159
|
+
h[0] + (u - h[0]) * b / A,
|
|
160
|
+
h[1] + (i - h[1]) * b / A
|
|
161
|
+
];
|
|
162
|
+
return {
|
|
163
|
+
inner: m(y(s, c)),
|
|
164
|
+
outer: m(y(s, 0)),
|
|
165
|
+
ctrl: m(h),
|
|
166
|
+
end: m(C)
|
|
167
|
+
};
|
|
168
|
+
}, E = (s) => {
|
|
169
|
+
const c = w(p - o, s), h = w(p + o, s);
|
|
170
|
+
return `M ${c.inner} L ${c.outer} Q ${c.ctrl} ${c.end} L ${u} ${i} L ${h.end} Q ${h.ctrl} ${h.outer} L ${h.inner}`;
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
fill: `${E(-t - $)} Z`,
|
|
174
|
+
stroke: t ? E(-t) : null
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function ut(n) {
|
|
178
|
+
return {
|
|
179
|
+
hasTarget: n,
|
|
180
|
+
placement: "none",
|
|
181
|
+
tip: null,
|
|
182
|
+
slotTip: null,
|
|
183
|
+
overlayStyle: {},
|
|
184
|
+
boxStyle: {},
|
|
185
|
+
rootIsBox: !n,
|
|
186
|
+
tail: null,
|
|
187
|
+
boxFill: "",
|
|
188
|
+
boxStroke: "",
|
|
189
|
+
boxStrokeWidth: 0,
|
|
190
|
+
boxZIndex: "auto"
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function dt(n) {
|
|
194
|
+
J();
|
|
195
|
+
let e = { ...Q }, t = null, a = null, l = null, r = {
|
|
196
|
+
left: 0,
|
|
197
|
+
top: 0,
|
|
198
|
+
width: 0,
|
|
199
|
+
height: 0,
|
|
200
|
+
scaleX: 1,
|
|
201
|
+
scaleY: 1,
|
|
202
|
+
viewportWidth: 0,
|
|
203
|
+
viewportHeight: 0
|
|
204
|
+
}, u = null, i = null, d = null, f = null, g = ut(!1);
|
|
205
|
+
const x = () => {
|
|
206
|
+
g = W(), n.onChange?.(g);
|
|
207
|
+
};
|
|
208
|
+
function W() {
|
|
209
|
+
const p = e.target != null, b = e.placement === "manual", m = p ? u?.placement ?? "none" : "none", w = {
|
|
210
|
+
position: "absolute",
|
|
211
|
+
inset: "0",
|
|
212
|
+
pointerEvents: "none",
|
|
213
|
+
filter: e.shadow ? j : void 0
|
|
214
|
+
}, E = l?.zIndex;
|
|
215
|
+
E && E !== "auto" && (w.zIndex = E);
|
|
216
|
+
const s = {
|
|
217
|
+
"--pb-padding": typeof e.padding == "number" ? `${e.padding}px` : e.padding
|
|
218
|
+
};
|
|
219
|
+
if (e.maxWidth != null && (s["--pb-max-width"] = `${e.maxWidth}px`), !p)
|
|
220
|
+
s["--pb-width"] = "fit-content", e.shadow && (s.filter = j);
|
|
221
|
+
else if (Object.assign(s, {
|
|
222
|
+
position: "absolute",
|
|
223
|
+
pointerEvents: "auto",
|
|
224
|
+
visibility: u ? "visible" : "hidden"
|
|
225
|
+
}), b)
|
|
226
|
+
s["--pb-width"] = "fit-content";
|
|
227
|
+
else if (Object.assign(s, {
|
|
228
|
+
left: `${u?.bx ?? 0}px`,
|
|
229
|
+
top: `${u?.by ?? 0}px`,
|
|
230
|
+
margin: "0"
|
|
231
|
+
}), e.maxWidth == null && t) {
|
|
232
|
+
const h = P(t, r, e.tailLength), A = i?.placement ?? e.placement, C = A === "auto" ? H(h) : A.split("-")[1];
|
|
233
|
+
s["--pb-max-width"] = `${h[C]}px`;
|
|
234
|
+
}
|
|
235
|
+
const c = p && u && l ? ct({
|
|
236
|
+
geometry: u,
|
|
237
|
+
strokeWidth: l.strokeWidth,
|
|
238
|
+
radius: l.radius,
|
|
239
|
+
tailBaseWidth: e.tailBaseWidth
|
|
240
|
+
}) : null;
|
|
241
|
+
return {
|
|
242
|
+
hasTarget: p,
|
|
243
|
+
placement: m,
|
|
244
|
+
tip: t,
|
|
245
|
+
slotTip: i ? { x: i.tx, y: i.ty } : t,
|
|
246
|
+
overlayStyle: w,
|
|
247
|
+
boxStyle: s,
|
|
248
|
+
rootIsBox: !p,
|
|
249
|
+
tail: c,
|
|
250
|
+
boxFill: l?.fill ?? "",
|
|
251
|
+
boxStroke: l?.stroke ?? "",
|
|
252
|
+
boxStrokeWidth: l?.strokeWidth ?? 0,
|
|
253
|
+
boxZIndex: l?.zIndex ?? "auto"
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function o() {
|
|
257
|
+
if (!t || !l) {
|
|
258
|
+
i = null, B(null);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const p = P(t, r, e.tailLength);
|
|
262
|
+
i = lt({
|
|
263
|
+
tip: t,
|
|
264
|
+
box: l,
|
|
265
|
+
frame: r,
|
|
266
|
+
placement: e.placement,
|
|
267
|
+
targetAnchor: e.targetAnchor,
|
|
268
|
+
targetRect: a,
|
|
269
|
+
room: p,
|
|
270
|
+
tailLength: e.tailLength
|
|
271
|
+
}), B(i);
|
|
272
|
+
}
|
|
273
|
+
function B(p) {
|
|
274
|
+
d?.cancel(), d = st(
|
|
275
|
+
u,
|
|
276
|
+
p,
|
|
277
|
+
e.transitionDuration,
|
|
278
|
+
(b) => {
|
|
279
|
+
u = b, x();
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
function S() {
|
|
284
|
+
const p = n.getRootEl(), b = n.getBoxEl();
|
|
285
|
+
if (!b || e.target == null || !p) return;
|
|
286
|
+
const m = ot(
|
|
287
|
+
b,
|
|
288
|
+
p,
|
|
289
|
+
r,
|
|
290
|
+
e.placement === "manual"
|
|
291
|
+
);
|
|
292
|
+
O(
|
|
293
|
+
m,
|
|
294
|
+
l
|
|
295
|
+
) || (l = m);
|
|
296
|
+
}
|
|
297
|
+
function k() {
|
|
298
|
+
const p = n.getRootEl();
|
|
299
|
+
if (e.target == null || !p) {
|
|
300
|
+
t = null, a = null, l = null, i = null, u = null, x();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
r = nt(p);
|
|
304
|
+
const b = et(e.target);
|
|
305
|
+
if (b) {
|
|
306
|
+
const m = b.getBoundingClientRect(), { scaleX: w, scaleY: E, left: s, top: c } = r, h = {
|
|
307
|
+
left: (m.left - s) / w,
|
|
308
|
+
top: (m.top - c) / E,
|
|
309
|
+
right: (m.right - s) / w,
|
|
310
|
+
bottom: (m.bottom - c) / E
|
|
311
|
+
};
|
|
312
|
+
O(h, a) || (a = h), t = {
|
|
313
|
+
x: (h.left + h.right) / 2,
|
|
314
|
+
y: (h.top + h.bottom) / 2
|
|
315
|
+
};
|
|
316
|
+
} else if (tt(e.target))
|
|
317
|
+
a = null, t = { x: e.target.x, y: e.target.y };
|
|
318
|
+
else {
|
|
319
|
+
a = null, t = null, l = null, i = null, u = null, x();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
S(), o();
|
|
323
|
+
}
|
|
324
|
+
function $() {
|
|
325
|
+
k();
|
|
326
|
+
}
|
|
327
|
+
typeof window < "u" && (window.addEventListener("resize", $), window.addEventListener("scroll", $, !0));
|
|
328
|
+
function M() {
|
|
329
|
+
if (typeof ResizeObserver > "u") return;
|
|
330
|
+
f?.disconnect(), f = new ResizeObserver(() => k());
|
|
331
|
+
const p = n.getRootEl(), b = n.getBoxEl();
|
|
332
|
+
p && f.observe(p), b && f.observe(b);
|
|
333
|
+
}
|
|
334
|
+
const y = k;
|
|
335
|
+
function v() {
|
|
336
|
+
M(), y();
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
update: v,
|
|
340
|
+
setConfig(p) {
|
|
341
|
+
e = { ...e, ...p }, v();
|
|
342
|
+
},
|
|
343
|
+
getConfig: () => e,
|
|
344
|
+
getState: () => g,
|
|
345
|
+
destroy() {
|
|
346
|
+
d?.cancel(), f?.disconnect(), typeof window < "u" && (window.removeEventListener("resize", $), window.removeEventListener("scroll", $, !0));
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const ft = ["data-placement"], pt = ["d", "fill"], ht = ["d", "stroke", "stroke-width"], Y = /* @__PURE__ */ U({
|
|
351
|
+
name: "PointingBubble",
|
|
352
|
+
inheritAttrs: !1,
|
|
353
|
+
__name: "PointingBubble",
|
|
354
|
+
props: {
|
|
355
|
+
target: { default: null },
|
|
356
|
+
placement: { default: "auto" },
|
|
357
|
+
targetAnchor: { default: "center" },
|
|
358
|
+
maxWidth: { default: void 0 },
|
|
359
|
+
tailLength: { default: 45 },
|
|
360
|
+
tailBaseWidth: { default: 24 },
|
|
361
|
+
padding: { default: 8 },
|
|
362
|
+
shadow: { type: Boolean, default: !0 },
|
|
363
|
+
transitionDuration: { default: 200 }
|
|
364
|
+
},
|
|
365
|
+
setup(n, { expose: e }) {
|
|
366
|
+
const t = n, a = L(null), l = L(null), r = L({
|
|
367
|
+
hasTarget: !1,
|
|
368
|
+
placement: "none",
|
|
369
|
+
tip: null,
|
|
370
|
+
slotTip: null,
|
|
371
|
+
overlayStyle: {},
|
|
372
|
+
boxStyle: {},
|
|
373
|
+
rootIsBox: !0,
|
|
374
|
+
tail: null,
|
|
375
|
+
boxFill: "",
|
|
376
|
+
boxStroke: "",
|
|
377
|
+
boxStrokeWidth: 0,
|
|
378
|
+
boxZIndex: "auto"
|
|
379
|
+
});
|
|
380
|
+
function u(o) {
|
|
381
|
+
return o == null ? null : typeof o == "string" || typeof Element < "u" && o instanceof Element ? o : typeof o == "object" && "$el" in o && o.$el instanceof Element ? o.$el : typeof o == "object" && typeof o.x == "number" && typeof o.y == "number" ? o : null;
|
|
382
|
+
}
|
|
383
|
+
const i = dt({
|
|
384
|
+
getRootEl: () => a.value,
|
|
385
|
+
getBoxEl: () => l.value,
|
|
386
|
+
onChange: (o) => {
|
|
387
|
+
r.value = o;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
function d() {
|
|
391
|
+
i.setConfig({
|
|
392
|
+
target: u(t.target),
|
|
393
|
+
placement: t.placement,
|
|
394
|
+
targetAnchor: t.targetAnchor,
|
|
395
|
+
maxWidth: t.maxWidth,
|
|
396
|
+
tailLength: t.tailLength,
|
|
397
|
+
tailBaseWidth: t.tailBaseWidth,
|
|
398
|
+
padding: t.padding,
|
|
399
|
+
shadow: t.shadow,
|
|
400
|
+
transitionDuration: t.transitionDuration
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
X(
|
|
404
|
+
() => [
|
|
405
|
+
t.target,
|
|
406
|
+
typeof t.target == "object" && t.target && "x" in t.target ? t.target.x : null,
|
|
407
|
+
typeof t.target == "object" && t.target && "y" in t.target ? t.target.y : null,
|
|
408
|
+
t.placement,
|
|
409
|
+
t.targetAnchor,
|
|
410
|
+
t.maxWidth,
|
|
411
|
+
t.tailLength,
|
|
412
|
+
t.tailBaseWidth,
|
|
413
|
+
t.padding,
|
|
414
|
+
t.shadow,
|
|
415
|
+
t.transitionDuration
|
|
416
|
+
],
|
|
417
|
+
d,
|
|
418
|
+
{ flush: "post" }
|
|
419
|
+
), N(() => {
|
|
420
|
+
d();
|
|
421
|
+
}), Z(() => {
|
|
422
|
+
i.update();
|
|
423
|
+
}), q(() => {
|
|
424
|
+
i.destroy();
|
|
425
|
+
});
|
|
426
|
+
function f() {
|
|
427
|
+
i.update();
|
|
428
|
+
}
|
|
429
|
+
e({ update: f });
|
|
430
|
+
const g = R(
|
|
431
|
+
() => r.value.rootIsBox ? r.value.boxStyle : r.value.overlayStyle
|
|
432
|
+
), x = R(() => r.value.rootIsBox ? { display: "contents" } : r.value.boxStyle), W = R(
|
|
433
|
+
() => ({
|
|
434
|
+
position: "absolute",
|
|
435
|
+
inset: "0",
|
|
436
|
+
width: "100%",
|
|
437
|
+
height: "100%",
|
|
438
|
+
overflow: "visible",
|
|
439
|
+
zIndex: r.value.boxZIndex
|
|
440
|
+
})
|
|
441
|
+
);
|
|
442
|
+
return (o, B) => (I(), z("div", F({
|
|
443
|
+
ref_key: "rootRef",
|
|
444
|
+
ref: a,
|
|
445
|
+
class: ["pointing-bubble", { "pointing-bubble__inner": !n.target }],
|
|
446
|
+
"data-placement": r.value.placement
|
|
447
|
+
}, n.target ? {} : o.$attrs, { style: g.value }), [
|
|
448
|
+
_("div", F({
|
|
449
|
+
ref_key: "boxRef",
|
|
450
|
+
ref: l,
|
|
451
|
+
class: { "pointing-bubble__inner": !!n.target }
|
|
452
|
+
}, n.target ? o.$attrs : {}, { style: x.value }), [
|
|
453
|
+
G(o.$slots, "default", {
|
|
454
|
+
placement: r.value.placement,
|
|
455
|
+
tip: r.value.slotTip
|
|
456
|
+
}, () => [
|
|
457
|
+
B[0] || (B[0] = _("p", { style: {
|
|
458
|
+
margin: 0,
|
|
459
|
+
fontSize: "14px",
|
|
460
|
+
fontWeight: 600,
|
|
461
|
+
color: "#1e293b"
|
|
462
|
+
} }, " Callout content ", -1))
|
|
463
|
+
])
|
|
464
|
+
], 16),
|
|
465
|
+
n.target && r.value.tail ? (I(), z("svg", {
|
|
466
|
+
key: 0,
|
|
467
|
+
class: "pointing-bubble__svg",
|
|
468
|
+
style: K(W.value)
|
|
469
|
+
}, [
|
|
470
|
+
_("path", {
|
|
471
|
+
class: "pointing-bubble__path",
|
|
472
|
+
d: r.value.tail.fill,
|
|
473
|
+
fill: r.value.boxFill
|
|
474
|
+
}, null, 8, pt),
|
|
475
|
+
r.value.tail.stroke ? (I(), z("path", {
|
|
476
|
+
key: 0,
|
|
477
|
+
class: "pointing-bubble__path",
|
|
478
|
+
d: r.value.tail.stroke,
|
|
479
|
+
fill: "none",
|
|
480
|
+
stroke: r.value.boxStroke,
|
|
481
|
+
"stroke-width": r.value.boxStrokeWidth,
|
|
482
|
+
"stroke-linejoin": "round",
|
|
483
|
+
"stroke-linecap": "butt"
|
|
484
|
+
}, null, 8, ht)) : T("", !0)
|
|
485
|
+
], 4)) : T("", !0)
|
|
486
|
+
], 16, ft));
|
|
487
|
+
}
|
|
488
|
+
}), bt = {
|
|
489
|
+
install(n, e = {}) {
|
|
490
|
+
const t = e.name ?? "PointingBubble";
|
|
491
|
+
n.component(t, Y), n.component("Callout", Y);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
export {
|
|
495
|
+
Y as Callout,
|
|
496
|
+
Q as DEFAULT_BUBBLE_CONFIG,
|
|
497
|
+
Y as PointingBubble,
|
|
498
|
+
bt as PointingBubblePlugin,
|
|
499
|
+
ct as buildTailPaths,
|
|
500
|
+
lt as computeGeometry,
|
|
501
|
+
dt as createBubbleController,
|
|
502
|
+
Y as default,
|
|
503
|
+
tt as isPoint,
|
|
504
|
+
et as resolveElement
|
|
505
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-pointing-bubble",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vue 3 callout / speech bubble whose SVG tail points exactly at coordinates or a DOM element.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/vue-pointing-bubble.cjs",
|
|
11
|
+
"module": "./dist/vue-pointing-bubble.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/vue-pointing-bubble.js",
|
|
17
|
+
"require": "./dist/vue-pointing-bubble.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"vue": "^3.5.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@microsoft/api-extractor": "^7.59.4",
|
|
25
|
+
"@types/node": "^22.18.0",
|
|
26
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
27
|
+
"@vue/test-utils": "^2.4.6",
|
|
28
|
+
"@vue/tsconfig": "^0.7.0",
|
|
29
|
+
"jsdom": "^26.1.0",
|
|
30
|
+
"typescript": "~5.9.2",
|
|
31
|
+
"unplugin-dts": "^1.0.0-beta.6",
|
|
32
|
+
"vite": "^7.1.7",
|
|
33
|
+
"vitest": "^3.2.4",
|
|
34
|
+
"vue": "^3.5.21",
|
|
35
|
+
"vue-tsc": "^3.0.7"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"homepage": "https://murznn.github.io/js-pointing-bubble/",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/MurzNN/js-pointing-bubble.git",
|
|
46
|
+
"directory": "packages/vue"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"vue",
|
|
50
|
+
"vue3",
|
|
51
|
+
"callout",
|
|
52
|
+
"speech-bubble",
|
|
53
|
+
"tooltip",
|
|
54
|
+
"popover",
|
|
55
|
+
"shadcn-vue"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "vite build",
|
|
59
|
+
"typecheck": "vue-tsc --noEmit -p tsconfig.json",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
6
62
|
}
|