@greypan/web-ui 2.1.8 → 3.0.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/README.CN.md +44 -6
- package/README.md +46 -7
- package/dist/assets/menu-portal.js +1 -1
- package/dist/assets/menu-portal.js.map +1 -1
- package/dist/components/autocomplete/index.d.ts +121 -0
- package/dist/components/autocomplete/index.js +414 -0
- package/dist/components/autocomplete/index.js.map +1 -0
- package/dist/components/autocomplete/style.js +6 -0
- package/dist/components/autocomplete/style.js.map +1 -0
- package/dist/components/avatar/index.d.ts +0 -1
- package/dist/components/avatar/index.js +9 -9
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/back-top/index.d.ts +0 -1
- package/dist/components/back-top/index.js.map +1 -1
- package/dist/components/badge/index.d.ts +0 -1
- package/dist/components/badge/index.js +5 -5
- package/dist/components/badge/index.js.map +1 -1
- package/dist/components/button/index.d.ts +0 -1
- package/dist/components/button/index.js +8 -8
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button/style.js +1 -1
- package/dist/components/button/style.js.map +1 -1
- package/dist/components/button-group/index.d.ts +0 -1
- package/dist/components/button-group/index.js.map +1 -1
- package/dist/components/checkbox/index.js +7 -5
- package/dist/components/checkbox/index.js.map +1 -1
- package/dist/components/checkbox-group/index.js +2 -2
- package/dist/components/checkbox-group/index.js.map +1 -1
- package/dist/components/context-menu/index.js +25 -25
- package/dist/components/context-menu/index.js.map +1 -1
- package/dist/components/dialog/index.js +3 -3
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/drawer/index.js +7 -7
- package/dist/components/drawer/index.js.map +1 -1
- package/dist/components/dropdown/index.js +31 -30
- package/dist/components/dropdown/index.js.map +1 -1
- package/dist/components/dropdown-divider/index.d.ts +0 -1
- package/dist/components/dropdown-divider/index.js.map +1 -1
- package/dist/components/dropdown-header/index.d.ts +0 -1
- package/dist/components/dropdown-header/index.js.map +1 -1
- package/dist/components/dropdown-item/index.d.ts +0 -1
- package/dist/components/dropdown-item/index.js.map +1 -1
- package/dist/components/dropdown-item/style.js +1 -1
- package/dist/components/dropdown-item/style.js.map +1 -1
- package/dist/components/empty/index.d.ts +0 -1
- package/dist/components/empty/index.js +6 -6
- package/dist/components/empty/index.js.map +1 -1
- package/dist/components/icon/index.d.ts +0 -1
- package/dist/components/icon/index.js.map +1 -1
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +36 -35
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.js +24 -13
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/style.js +1 -1
- package/dist/components/input/style.js.map +1 -1
- package/dist/components/input-number/index.d.ts +2 -0
- package/dist/components/input-number/index.js +25 -12
- package/dist/components/input-number/index.js.map +1 -1
- package/dist/components/input-number/style.js +1 -1
- package/dist/components/input-number/style.js.map +1 -1
- package/dist/components/layout/index.d.ts +0 -1
- package/dist/components/layout/index.js +4 -4
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/option/index.d.ts +0 -11
- package/dist/components/option/index.js.map +1 -1
- package/dist/components/option/style.js +1 -1
- package/dist/components/option/style.js.map +1 -1
- package/dist/components/popover/index.js +12 -12
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/radio/index.js +8 -5
- package/dist/components/radio/index.js.map +1 -1
- package/dist/components/radio-group/index.js +2 -2
- package/dist/components/radio-group/index.js.map +1 -1
- package/dist/components/segmented/index.js +2 -2
- package/dist/components/segmented/index.js.map +1 -1
- package/dist/components/segmented-trigger/index.d.ts +1 -0
- package/dist/components/segmented-trigger/index.js +11 -2
- package/dist/components/segmented-trigger/index.js.map +1 -1
- package/dist/components/select/index.d.ts +0 -1
- package/dist/components/select/index.js +19 -30
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/select/style.js +1 -1
- package/dist/components/select/style.js.map +1 -1
- package/dist/components/spinner/index.d.ts +0 -1
- package/dist/components/spinner/index.js.map +1 -1
- package/dist/components/svg-draw-lines/index.d.ts +0 -1
- package/dist/components/svg-draw-lines/index.js.map +1 -1
- package/dist/components/switch/index.js +6 -6
- package/dist/components/textarea/index.js +18 -15
- package/dist/components/textarea/index.js.map +1 -1
- package/dist/components/textarea/style.js +1 -1
- package/dist/components/textarea/style.js.map +1 -1
- package/dist/components/theme/index.d.ts +0 -1
- package/dist/components/theme/index.js.map +1 -1
- package/dist/components/toast/toast.js +13 -13
- package/dist/components/tooltip/index.js +13 -13
- package/dist/components/tooltip/index.js.map +1 -1
- package/dist/shared/menu-portal/menu-portal.js +10 -11
- package/dist/shared/menu-portal/menu-portal.js.map +1 -1
- package/dist/shared/overlay/anchored-panel.js +12 -12
- package/dist/shared/overlay/overlay.js +55 -33
- package/dist/shared/overlay/overlay.js.map +1 -1
- package/dist/shared/overlay/portal.js +25 -13
- package/dist/shared/overlay/portal.js.map +1 -1
- package/dist/shared/scroll-lock/scroll-lock.js +13 -12
- package/dist/shared/scroll-lock/scroll-lock.js.map +1 -1
- package/dist/shared/theme/overlay-root.js +3 -3
- package/dist/types/react.d.ts +15 -41
- package/dist/types/utils.d.ts +33 -4
- package/dist/types/vue.d.ts +17 -49
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/theme/index.ts"],"sourcesContent":["import { html, LitElement, nothing, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { normalizeLiteral } from '@/shared/normalize'\nimport { applyOverlayRootStyles } from '@/shared/theme/overlay-root'\n\nimport style from './style.css?inline'\n\nexport type ThemeAppearance = 'light' | 'dark' | 'system'\nexport type ThemeMotion = 'full' | 'reduced' | 'system'\n\nconst APPEARANCES = ['light', 'dark', 'system'] as const\nconst MOTIONS = ['full', 'reduced', 'system'] as const\n\n@customElement('web-ui-theme')\nexport class WebUiTheme extends LitElement {\n static override styles = unsafeCSS(style)\n\n @property({ type: String, reflect: true })\n get appearance(): ThemeAppearance | undefined {\n return this._appearance\n }\n set appearance(v: string | undefined) {\n const old = this._appearance\n this._appearance = v !== undefined ? (normalizeLiteral(v, APPEARANCES, 'light') as ThemeAppearance) : undefined\n this.requestUpdate('appearance', old)\n }\n private _appearance?: ThemeAppearance\n\n @property({ type: String, reflect: true })\n get motion(): ThemeMotion {\n return this._motion\n }\n set motion(v: string) {\n const old = this._motion\n this._motion = normalizeLiteral(v, MOTIONS, 'system') as ThemeMotion\n this.requestUpdate('motion', old)\n }\n private _motion: ThemeMotion = 'system'\n\n private _warned = false\n\n override connectedCallback() {\n super.connectedCallback()\n this._warnWhenAppearanceIsMissing()\n }\n\n protected override updated() {\n this._warnWhenAppearanceIsMissing()\n }\n\n // 返回此主题范围内的浮层挂载点;未设置 appearance 时不创建。\n getOverlayRoot(): HTMLElement | undefined {\n if (!this._hasAppearance()) return undefined\n return this.renderRoot.querySelector<HTMLElement>('[data-wui-overlay-container]') ?? undefined\n }\n\n // 当前范围是否应减少动效;`system` 跟随用户的系统偏好。\n isReducedMotion(): boolean {\n if (this.motion === 'reduced') return true\n if (this.motion === 'full') return false\n\n try {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches\n } catch {\n return false\n }\n }\n\n override render() {\n return html`<slot></slot>${this._hasAppearance() ? html`<div data-wui-overlay-container></div>` : nothing}`\n }\n\n override firstUpdated() {\n if (this.renderRoot instanceof ShadowRoot) {\n applyOverlayRootStyles(this.renderRoot)\n }\n }\n\n private _hasAppearance(): this is this & { appearance: ThemeAppearance } {\n return this.appearance !== undefined && (APPEARANCES as readonly string[]).includes(this.appearance)\n }\n\n private _warnWhenAppearanceIsMissing() {\n if (this._hasAppearance() || this._warned || !import.meta.env.DEV) return\n this._warned = true\n console.warn('[web-ui-theme] appearance is required; this theme scope is inactive until it is set.')\n }\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/theme/index.ts"],"sourcesContent":["import { html, LitElement, nothing, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { normalizeLiteral } from '@/shared/normalize'\nimport { applyOverlayRootStyles } from '@/shared/theme/overlay-root'\n\nimport style from './style.css?inline'\n\nexport type ThemeAppearance = 'light' | 'dark' | 'system'\nexport type ThemeMotion = 'full' | 'reduced' | 'system'\n\nconst APPEARANCES = ['light', 'dark', 'system'] as const\nconst MOTIONS = ['full', 'reduced', 'system'] as const\n\n@customElement('web-ui-theme')\nexport class WebUiTheme extends LitElement {\n static override styles = unsafeCSS(style)\n\n @property({ type: String, reflect: true })\n get appearance(): ThemeAppearance | undefined {\n return this._appearance\n }\n set appearance(v: string | undefined) {\n const old = this._appearance\n this._appearance = v !== undefined ? (normalizeLiteral(v, APPEARANCES, 'light') as ThemeAppearance) : undefined\n this.requestUpdate('appearance', old)\n }\n private _appearance?: ThemeAppearance\n\n @property({ type: String, reflect: true })\n get motion(): ThemeMotion {\n return this._motion\n }\n set motion(v: string) {\n const old = this._motion\n this._motion = normalizeLiteral(v, MOTIONS, 'system') as ThemeMotion\n this.requestUpdate('motion', old)\n }\n private _motion: ThemeMotion = 'system'\n\n private _warned = false\n\n override connectedCallback() {\n super.connectedCallback()\n this._warnWhenAppearanceIsMissing()\n }\n\n protected override updated() {\n this._warnWhenAppearanceIsMissing()\n }\n\n // 返回此主题范围内的浮层挂载点;未设置 appearance 时不创建。\n getOverlayRoot(): HTMLElement | undefined {\n if (!this._hasAppearance()) return undefined\n return this.renderRoot.querySelector<HTMLElement>('[data-wui-overlay-container]') ?? undefined\n }\n\n // 当前范围是否应减少动效;`system` 跟随用户的系统偏好。\n isReducedMotion(): boolean {\n if (this.motion === 'reduced') return true\n if (this.motion === 'full') return false\n\n try {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches\n } catch {\n return false\n }\n }\n\n override render() {\n return html`<slot></slot>${this._hasAppearance() ? html`<div data-wui-overlay-container></div>` : nothing}`\n }\n\n override firstUpdated() {\n if (this.renderRoot instanceof ShadowRoot) {\n applyOverlayRootStyles(this.renderRoot)\n }\n }\n\n private _hasAppearance(): this is this & { appearance: ThemeAppearance } {\n return this.appearance !== undefined && (APPEARANCES as readonly string[]).includes(this.appearance)\n }\n\n private _warnWhenAppearanceIsMissing() {\n if (this._hasAppearance() || this._warned || !import.meta.env.DEV) return\n this._warned = true\n console.warn('[web-ui-theme] appearance is required; this theme scope is inactive until it is set.')\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-theme': WebUiTheme\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAM,IAAc;CAAC;CAAS;CAAQ;AAAQ,GACxC,IAAU;CAAC;CAAQ;CAAW;AAAQ,GAG/B,IAAN,cAAyB,EAAW;;EAyBvB,aAFa,KAAA,UAAA,UAEb,KAAA,UAAA;;;EAxBO,KAAA,SAAA,EAAU,CAAK;;CAExC,IACI,aAA0C;EAC5C,OAAO,KAAK;CACd;CACA,IAAI,WAAW,GAAuB;EACpC,IAAM,IAAM,KAAK;EAEjB,AADA,KAAK,cAAc,MAAM,KAAA,IAA6E,KAAA,IAAhE,EAAiB,GAAG,GAAa,OAAO,GAC9E,KAAK,cAAc,cAAc,CAAG;CACtC;CAGA,IACI,SAAsB;EACxB,OAAO,KAAK;CACd;CACA,IAAI,OAAO,GAAW;EACpB,IAAM,IAAM,KAAK;EAEjB,AADA,KAAK,UAAU,EAAiB,GAAG,GAAS,QAAQ,GACpD,KAAK,cAAc,UAAU,CAAG;CAClC;CAKA,oBAA6B;EAE3B,AADA,MAAM,kBAAkB,GACxB,KAAK,6BAA6B;CACpC;CAEA,UAA6B;EAC3B,KAAK,6BAA6B;CACpC;CAGA,iBAA0C;EACnC,SAAK,eAAe,GACzB,OAAO,KAAK,WAAW,cAA2B,8BAA8B,KAAK,KAAA;CACvF;CAGA,kBAA2B;EACzB,IAAI,KAAK,WAAW,WAAW,OAAO;EACtC,IAAI,KAAK,WAAW,QAAQ,OAAO;EAEnC,IAAI;GACF,OAAO,OAAO,WAAW,kCAAkC,CAAC,CAAC;EAC/D,QAAQ;GACN,OAAO;EACT;CACF;CAEA,SAAkB;EAChB,OAAO,CAAI,gBAAgB,KAAK,eAAe,IAAI,CAAI,2CAA2C;CACpG;CAEA,eAAwB;EACtB,AAAI,KAAK,sBAAsB,cAC7B,EAAuB,KAAK,UAAU;CAE1C;CAEA,iBAAyE;EACvE,OAAO,KAAK,eAAe,KAAA,KAAc,EAAkC,SAAS,KAAK,UAAU;CACrG;CAEA,+BAAuC;EACjC,KAAK,eAAe,KAAK,KAAK;CAGpC;AACF;AAtEG,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,cAAA,IAAA,GAWxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,UAAA,IAAA,GAf1C,IAAA,EAAA,CAAA,EAAc,cAAc,CAAA,GAAA,CAAA"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import e from "../../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate.js";
|
|
2
2
|
import "../icon/index.js";
|
|
3
|
-
import t from "../../
|
|
4
|
-
import n from "../../icons/generated/lucide-
|
|
5
|
-
import r from "../../icons/generated/lucide-
|
|
6
|
-
import i from "../../icons/generated/lucide-
|
|
7
|
-
import a from "../../icons/generated/
|
|
8
|
-
import o from "../../
|
|
9
|
-
import "../button/index.js";
|
|
3
|
+
import t from "../../icons/generated/lucide-check.js";
|
|
4
|
+
import n from "../../icons/generated/lucide-info.js";
|
|
5
|
+
import r from "../../icons/generated/lucide-triangle-alert.js";
|
|
6
|
+
import i from "../../icons/generated/lucide-circle-alert.js";
|
|
7
|
+
import a from "../../icons/generated/heroicons-x-mark-16-solid.js";
|
|
8
|
+
import o from "../../assets/glass.js";
|
|
10
9
|
import { getTransitionDuration as s } from "../../shared/overlay/presence.js";
|
|
10
|
+
import "../button/index.js";
|
|
11
11
|
import c from "./style.js";
|
|
12
12
|
import { LitElement as l, html as u, nothing as d, unsafeCSS as f } from "lit";
|
|
13
13
|
import { customElement as p, property as m } from "lit/decorators.js";
|
|
14
14
|
//#region src/components/toast/toast.ts
|
|
15
15
|
var h = {
|
|
16
|
-
success:
|
|
17
|
-
info:
|
|
18
|
-
warning:
|
|
19
|
-
error:
|
|
16
|
+
success: t,
|
|
17
|
+
info: n,
|
|
18
|
+
warning: r,
|
|
19
|
+
error: i
|
|
20
20
|
};
|
|
21
21
|
function g() {
|
|
22
22
|
let e = /* @__PURE__ */ new Date();
|
|
@@ -33,7 +33,7 @@ var _ = class extends l {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
static {
|
|
36
|
-
this.styles = [f(
|
|
36
|
+
this.styles = [f(o), f(c)];
|
|
37
37
|
}
|
|
38
38
|
connectedCallback() {
|
|
39
39
|
super.connectedCallback(), this.addEventListener("pointerenter", this._onPointerEnter), this.addEventListener("pointerleave", this._onPointerLeave);
|
|
@@ -100,7 +100,7 @@ var _ = class extends l {
|
|
|
100
100
|
aria-label="关闭"
|
|
101
101
|
@click=${this._onCloseClick}
|
|
102
102
|
>
|
|
103
|
-
<web-ui-icon .icon=${
|
|
103
|
+
<web-ui-icon .icon=${a} size="16"></web-ui-icon>
|
|
104
104
|
</web-ui-button>
|
|
105
105
|
`}
|
|
106
106
|
</div>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import e from "../../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate.js";
|
|
2
2
|
import t from "../../assets/glass.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import a from "../../
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import n from "../../assets/overlay-motion.js";
|
|
4
|
+
import { normalizeLiteral as r, normalizeNumber as i } from "../../shared/normalize/index.js";
|
|
5
|
+
import { defineAnchoredPanel as a } from "../../shared/overlay/anchored-panel.js";
|
|
6
|
+
import { defineOverlayPortal as o } from "../../shared/overlay/portal.js";
|
|
7
|
+
import { UserChangeController as s } from "../../shared/events/user-change.js";
|
|
8
8
|
import c from "./style.js";
|
|
9
9
|
import { LitElement as l, html as u, unsafeCSS as d } from "lit";
|
|
10
10
|
import { customElement as f, property as p } from "lit/decorators.js";
|
|
@@ -24,7 +24,7 @@ var m = [
|
|
|
24
24
|
"right-end"
|
|
25
25
|
], h = 0, g = class extends l {
|
|
26
26
|
constructor(...e) {
|
|
27
|
-
super(...e), this._placement = "top", this._showDelay = 200, this._hideDelay = 100, this.disabled = !1, this._offset = 6, this.content = "", this.open = !1, this.portal = !1, this._isCountedVisible = !1, this._userOpenChange = new
|
|
27
|
+
super(...e), this._placement = "top", this._showDelay = 200, this._hideDelay = 100, this.disabled = !1, this._offset = 6, this.content = "", this.open = !1, this.portal = !1, this._isCountedVisible = !1, this._userOpenChange = new s(), this._shouldOpenInstantly = !0, this._panel = a().make({
|
|
28
28
|
getAnchor: () => this.shadowRoot?.querySelector(".tooltip-trigger") ?? null,
|
|
29
29
|
getLocalPanel: () => this.shadowRoot?.querySelector(".tooltip-panel") ?? null,
|
|
30
30
|
getPositioning: () => ({
|
|
@@ -47,7 +47,7 @@ var m = [
|
|
|
47
47
|
static {
|
|
48
48
|
this.styles = [
|
|
49
49
|
d(t),
|
|
50
|
-
d(
|
|
50
|
+
d(n),
|
|
51
51
|
d(c)
|
|
52
52
|
];
|
|
53
53
|
}
|
|
@@ -56,28 +56,28 @@ var m = [
|
|
|
56
56
|
}
|
|
57
57
|
set placement(e) {
|
|
58
58
|
let t = this._placement;
|
|
59
|
-
this._placement =
|
|
59
|
+
this._placement = r(e, m, "top"), this.requestUpdate("placement", t);
|
|
60
60
|
}
|
|
61
61
|
get showDelay() {
|
|
62
62
|
return this._showDelay;
|
|
63
63
|
}
|
|
64
64
|
set showDelay(e) {
|
|
65
65
|
let t = this._showDelay;
|
|
66
|
-
this._showDelay =
|
|
66
|
+
this._showDelay = i(e, 0, 5e3, 200), this.requestUpdate("showDelay", t);
|
|
67
67
|
}
|
|
68
68
|
get hideDelay() {
|
|
69
69
|
return this._hideDelay;
|
|
70
70
|
}
|
|
71
71
|
set hideDelay(e) {
|
|
72
72
|
let t = this._hideDelay;
|
|
73
|
-
this._hideDelay =
|
|
73
|
+
this._hideDelay = i(e, 0, 5e3, 100), this.requestUpdate("hideDelay", t);
|
|
74
74
|
}
|
|
75
75
|
get offset() {
|
|
76
76
|
return this._offset;
|
|
77
77
|
}
|
|
78
78
|
set offset(e) {
|
|
79
79
|
let t = this._offset;
|
|
80
|
-
this._offset =
|
|
80
|
+
this._offset = i(e, 0, 100, 6), this.requestUpdate("offset", t);
|
|
81
81
|
}
|
|
82
82
|
get isOpen() {
|
|
83
83
|
return this.open;
|
|
@@ -104,10 +104,10 @@ var m = [
|
|
|
104
104
|
this._panel.open(e);
|
|
105
105
|
}
|
|
106
106
|
_createPortal() {
|
|
107
|
-
let e =
|
|
107
|
+
let e = o().make({
|
|
108
108
|
container: this.overlayContainer,
|
|
109
109
|
target: this,
|
|
110
|
-
style: `${t}\n${
|
|
110
|
+
style: `${t}\n${n}\n${c}`,
|
|
111
111
|
className: "tooltip-panel portal wui-glass wui-floating-panel"
|
|
112
112
|
});
|
|
113
113
|
if (this.content) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/tooltip/index.ts"],"sourcesContent":["import type { Placement } from '@floating-ui/dom'\nimport { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport overlayMotion from '@/assets/overlay-motion.css?inline'\nimport { UserChangeController } from '@/shared/events/user-change'\nimport { normalizeLiteral, normalizeNumber } from '@/shared/normalize'\nimport { defineAnchoredPanel } from '@/shared/overlay/anchored-panel'\nimport { createOverlayPortal } from '@/shared/overlay/portal'\nimport type { OverlayContainer, OverlayPortal } from '@/shared/overlay/portal'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_PLACEMENTS = [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end'\n] as const\n\nlet visibleTooltipCount = 0\n\n@customElement('web-ui-tooltip')\nexport class WebUiTooltip extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(overlayMotion), unsafeCSS(style)]\n\n @property({ type: String, reflect: true })\n get placement(): Placement {\n return this._placement\n }\n set placement(v: string) {\n const old = this._placement\n this._placement = normalizeLiteral(v, ALLOWED_PLACEMENTS, 'top')\n this.requestUpdate('placement', old)\n }\n private _placement: Placement = 'top'\n\n @property({ type: Number, attribute: 'show-delay' })\n get showDelay(): number {\n return this._showDelay\n }\n set showDelay(v: number) {\n const old = this._showDelay\n this._showDelay = normalizeNumber(v, 0, 5000, 200)\n this.requestUpdate('showDelay', old)\n }\n private _showDelay = 200\n\n @property({ type: Number, attribute: 'hide-delay' })\n get hideDelay(): number {\n return this._hideDelay\n }\n set hideDelay(v: number) {\n const old = this._hideDelay\n this._hideDelay = normalizeNumber(v, 0, 5000, 100)\n this.requestUpdate('hideDelay', old)\n }\n private _hideDelay = 100\n\n @property({ type: Boolean, reflect: true }) disabled = false\n\n @property({ type: Number })\n get offset(): number {\n return this._offset\n }\n set offset(v: number) {\n const old = this._offset\n this._offset = normalizeNumber(v, 0, 100, 6)\n this.requestUpdate('offset', old)\n }\n private _offset = 6\n\n @property({ type: String }) content = ''\n\n @property({ type: Boolean, reflect: true }) open = false\n @property({ type: Boolean, reflect: true }) portal = false\n @property({ attribute: false }) overlayContainer?: OverlayContainer\n\n private _showTimer?: ReturnType<typeof setTimeout>\n private _hideTimer?: ReturnType<typeof setTimeout>\n private _isCountedVisible = false\n private readonly _userOpenChange = new UserChangeController()\n private _shouldOpenInstantly = true\n private readonly _panel = defineAnchoredPanel().make({\n getAnchor: () => this.shadowRoot?.querySelector<HTMLElement>('.tooltip-trigger') ?? null,\n getLocalPanel: () => this.shadowRoot?.querySelector<HTMLElement>('.tooltip-panel') ?? null,\n getPositioning: () => ({\n placement: this.placement,\n offset: this.offset,\n strategy: this.portal ? 'fixed' : 'absolute'\n }),\n isPortal: () => this.portal,\n createPortal: () => this._createPortal()\n })\n\n get isOpen(): boolean {\n return this.open\n }\n\n override connectedCallback() {\n super.connectedCallback()\n this.addEventListener('pointerenter', this._onPointerEnter)\n this.addEventListener('pointerleave', this._onPointerLeave)\n this.addEventListener('focusin', this._onFocusIn)\n this.addEventListener('focusout', this._onFocusOut)\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n this.removeEventListener('focusin', this._onFocusIn)\n this.removeEventListener('focusout', this._onFocusOut)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._syncVisibleTooltipCount(false)\n this._panel.dispose()\n }\n\n override firstUpdated() {\n if (this.open) {\n this._openOverlay(this._shouldOpenInstantly)\n this._shouldOpenInstantly = true\n }\n }\n\n protected override updated(changed: Map<string, unknown>) {\n if (changed.has('portal') || changed.has('overlayContainer')) {\n requestAnimationFrame(() => this._reconfigureOverlay())\n } else if (changed.has('placement') || changed.has('offset'))\n requestAnimationFrame(() => this._panel.updatePosition())\n\n if (changed.has('open')) {\n this._syncVisibleTooltipCount(this.open)\n if (this.open) {\n this._openOverlay(this._shouldOpenInstantly)\n this._shouldOpenInstantly = true\n } else {\n void this._closeOverlay()\n }\n if (this._userOpenChange.consume()) this._dispatchChange(this.open)\n }\n if (changed.has('content')) this._syncPortalContent()\n }\n\n private _onPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled) return\n clearTimeout(this._hideTimer)\n this._showTimer = setTimeout(() => this._show(), visibleTooltipCount > 0 ? 0 : this.showDelay)\n }\n\n private _onPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled) return\n clearTimeout(this._showTimer)\n this._hideTimer = setTimeout(() => this._hide(), this.hideDelay)\n }\n\n private _onFocusIn = () => {\n if (this.disabled) return\n clearTimeout(this._hideTimer)\n this._show(true)\n }\n\n private _onFocusOut = () => {\n if (this.disabled) return\n clearTimeout(this._showTimer)\n this._hide()\n }\n\n private _show(isInstant = false) {\n if (this.open) return\n this._shouldOpenInstantly = isInstant\n this._userOpenChange.mark()\n this.open = true\n }\n\n private _hide() {\n if (!this.open) return\n this._userOpenChange.mark()\n this.open = false\n }\n\n private _openOverlay(isInstant = false) {\n this._panel.open(isInstant)\n }\n\n private _createPortal(): OverlayPortal {\n const portal = createOverlayPortal({\n container: this.overlayContainer,\n target: this,\n style: `${glass}\\n${overlayMotion}\\n${style}`,\n className: 'tooltip-panel portal wui-glass wui-floating-panel'\n })\n if (this.content) {\n const text = document.createElement('span')\n text.className = 'tooltip-text'\n text.textContent = this.content\n portal.panel.append(text)\n } else portal.moveContent(Array.from(this.querySelectorAll('[slot=\"content\"]')))\n portal.panel.setAttribute('role', 'tooltip')\n return portal\n }\n\n private async _closeOverlay() {\n await this._panel.close(() => this.open)\n }\n\n private _reconfigureOverlay() {\n this._panel.reconfigure(this.open)\n }\n\n private _syncPortalContent() {\n if (!this.portal || !this.open) return\n const panel = this._panel.getPanel()\n if (!panel) return\n const text = panel.querySelector<HTMLElement>('.tooltip-text')\n if (text) {\n text.textContent = this.content\n return\n }\n if (!this.content) return\n panel.replaceChildren()\n const nextText = document.createElement('span')\n nextText.className = 'tooltip-text'\n nextText.textContent = this.content\n panel.append(nextText)\n }\n\n private _dispatchChange(open: boolean) {\n this.dispatchEvent(\n new CustomEvent('open-change', {\n detail: { open },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private _syncVisibleTooltipCount(isVisible: boolean) {\n if (isVisible && !this._isCountedVisible) {\n visibleTooltipCount += 1\n this._isCountedVisible = true\n } else if (!isVisible && this._isCountedVisible) {\n visibleTooltipCount = Math.max(0, visibleTooltipCount - 1)\n this._isCountedVisible = false\n }\n }\n\n override render() {\n return html`\n <div class=\"tooltip-anchor\">\n <div class=\"tooltip-trigger\"><slot></slot></div>\n <div class=\"tooltip-panel wui-glass wui-floating-panel\" hidden role=\"tooltip\">\n ${this.content ? html`<span class=\"tooltip-text\">${this.content}</span>` : html`<slot name=\"content\"></slot>`}\n </div>\n </div>\n `\n }\n\n declare readonly $events: {\n 'open-change': CustomEvent<{ open: boolean }>\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-tooltip': WebUiTooltip\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAM,IAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEI,IAAsB,GAGb,IAAN,cAA2B,EAAW;;EA8If,aAlII,KAAA,aAAA,OAWX,KAAA,aAAA,KAWA,KAAA,aAAA,KAEkC,KAAA,WAAA,IAWrC,KAAA,UAAA,GAEoB,KAAA,UAAA,IAEa,KAAA,OAAA,IACE,KAAA,SAAA,IAKzB,KAAA,oBAAA,IACO,KAAA,kBAAA,IAAI,EAAqB,GAC7B,KAAA,uBAAA,IACL,KAAA,SAAA,EAAoB,CAAC,CAAC,KAAK;GACnD,iBAAiB,KAAK,YAAY,cAA2B,kBAAkB,KAAK;GACpF,qBAAqB,KAAK,YAAY,cAA2B,gBAAgB,KAAK;GACtF,uBAAuB;IACrB,WAAW,KAAK;IAChB,QAAQ,KAAK;IACb,UAAU,KAAK,SAAS,UAAU;GACpC;GACA,gBAAgB,KAAK;GACrB,oBAAoB,KAAK,cAAc;EACzC,CAAC,GAoD0B,KAAA,mBAAA,MAAoB;GACzC,EAAE,gBAAgB,YAClB,KAAK,aACT,aAAa,KAAK,UAAU,GAC5B,KAAK,aAAa,iBAAiB,KAAK,MAAM,GAAG,IAAsB,IAAI,IAAI,KAAK,SAAS;EAC/F,GAE2B,KAAA,mBAAA,MAAoB;GACzC,EAAE,gBAAgB,YAClB,KAAK,aACT,aAAa,KAAK,UAAU,GAC5B,KAAK,aAAa,iBAAiB,KAAK,MAAM,GAAG,KAAK,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CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,aAAA,IAAA,GAWxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,WAAW;AAAa,CAAC,CAAA,GAAA,EAAA,WAAA,aAAA,IAAA,GAWlD,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,WAAW;AAAa,CAAC,CAAA,GAAA,EAAA,WAAA,aAAA,IAAA,GAWlD,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GAEzC,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,EAAA,WAAA,UAAA,IAAA,GAWzB,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,EAAA,WAAA,WAAA,KAAA,CAAA,GAEzB,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,QAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,UAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS,EAAE,WAAW,GAAM,CAAC,CAAA,GAAA,EAAA,WAAA,oBAAA,KAAA,CAAA,GAtD/B,IAAA,EAAA,CAAA,EAAc,gBAAgB,CAAA,GAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/tooltip/index.ts"],"sourcesContent":["import type { Placement } from '@floating-ui/dom'\nimport { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport overlayMotion from '@/assets/overlay-motion.css?inline'\nimport { UserChangeController } from '@/shared/events/user-change'\nimport { normalizeLiteral, normalizeNumber } from '@/shared/normalize'\nimport { defineAnchoredPanel } from '@/shared/overlay/anchored-panel'\nimport { defineOverlayPortal } from '@/shared/overlay/portal'\nimport type { OverlayContainer, OverlayPortal } from '@/shared/overlay/portal'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_PLACEMENTS = [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end'\n] as const\n\nlet visibleTooltipCount = 0\n\n@customElement('web-ui-tooltip')\nexport class WebUiTooltip extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(overlayMotion), unsafeCSS(style)]\n\n @property({ type: String, reflect: true })\n get placement(): Placement {\n return this._placement\n }\n set placement(v: string) {\n const old = this._placement\n this._placement = normalizeLiteral(v, ALLOWED_PLACEMENTS, 'top')\n this.requestUpdate('placement', old)\n }\n private _placement: Placement = 'top'\n\n @property({ type: Number, attribute: 'show-delay' })\n get showDelay(): number {\n return this._showDelay\n }\n set showDelay(v: number) {\n const old = this._showDelay\n this._showDelay = normalizeNumber(v, 0, 5000, 200)\n this.requestUpdate('showDelay', old)\n }\n private _showDelay = 200\n\n @property({ type: Number, attribute: 'hide-delay' })\n get hideDelay(): number {\n return this._hideDelay\n }\n set hideDelay(v: number) {\n const old = this._hideDelay\n this._hideDelay = normalizeNumber(v, 0, 5000, 100)\n this.requestUpdate('hideDelay', old)\n }\n private _hideDelay = 100\n\n @property({ type: Boolean, reflect: true }) disabled = false\n\n @property({ type: Number })\n get offset(): number {\n return this._offset\n }\n set offset(v: number) {\n const old = this._offset\n this._offset = normalizeNumber(v, 0, 100, 6)\n this.requestUpdate('offset', old)\n }\n private _offset = 6\n\n @property({ type: String }) content = ''\n\n @property({ type: Boolean, reflect: true }) open = false\n @property({ type: Boolean, reflect: true }) portal = false\n @property({ attribute: false }) overlayContainer?: OverlayContainer\n\n private _showTimer?: ReturnType<typeof setTimeout>\n private _hideTimer?: ReturnType<typeof setTimeout>\n private _isCountedVisible = false\n private readonly _userOpenChange = new UserChangeController()\n private _shouldOpenInstantly = true\n private readonly _panel = defineAnchoredPanel().make({\n getAnchor: () => this.shadowRoot?.querySelector<HTMLElement>('.tooltip-trigger') ?? null,\n getLocalPanel: () => this.shadowRoot?.querySelector<HTMLElement>('.tooltip-panel') ?? null,\n getPositioning: () => ({\n placement: this.placement,\n offset: this.offset,\n strategy: this.portal ? 'fixed' : 'absolute'\n }),\n isPortal: () => this.portal,\n createPortal: () => this._createPortal()\n })\n\n get isOpen(): boolean {\n return this.open\n }\n\n override connectedCallback() {\n super.connectedCallback()\n this.addEventListener('pointerenter', this._onPointerEnter)\n this.addEventListener('pointerleave', this._onPointerLeave)\n this.addEventListener('focusin', this._onFocusIn)\n this.addEventListener('focusout', this._onFocusOut)\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n this.removeEventListener('focusin', this._onFocusIn)\n this.removeEventListener('focusout', this._onFocusOut)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._syncVisibleTooltipCount(false)\n this._panel.dispose()\n }\n\n override firstUpdated() {\n if (this.open) {\n this._openOverlay(this._shouldOpenInstantly)\n this._shouldOpenInstantly = true\n }\n }\n\n protected override updated(changed: Map<string, unknown>) {\n if (changed.has('portal') || changed.has('overlayContainer')) {\n requestAnimationFrame(() => this._reconfigureOverlay())\n } else if (changed.has('placement') || changed.has('offset'))\n requestAnimationFrame(() => this._panel.updatePosition())\n\n if (changed.has('open')) {\n this._syncVisibleTooltipCount(this.open)\n if (this.open) {\n this._openOverlay(this._shouldOpenInstantly)\n this._shouldOpenInstantly = true\n } else {\n void this._closeOverlay()\n }\n if (this._userOpenChange.consume()) this._dispatchChange(this.open)\n }\n if (changed.has('content')) this._syncPortalContent()\n }\n\n private _onPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled) return\n clearTimeout(this._hideTimer)\n this._showTimer = setTimeout(() => this._show(), visibleTooltipCount > 0 ? 0 : this.showDelay)\n }\n\n private _onPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled) return\n clearTimeout(this._showTimer)\n this._hideTimer = setTimeout(() => this._hide(), this.hideDelay)\n }\n\n private _onFocusIn = () => {\n if (this.disabled) return\n clearTimeout(this._hideTimer)\n this._show(true)\n }\n\n private _onFocusOut = () => {\n if (this.disabled) return\n clearTimeout(this._showTimer)\n this._hide()\n }\n\n private _show(isInstant = false) {\n if (this.open) return\n this._shouldOpenInstantly = isInstant\n this._userOpenChange.mark()\n this.open = true\n }\n\n private _hide() {\n if (!this.open) return\n this._userOpenChange.mark()\n this.open = false\n }\n\n private _openOverlay(isInstant = false) {\n this._panel.open(isInstant)\n }\n\n private _createPortal(): OverlayPortal {\n const portal = defineOverlayPortal().make({\n container: this.overlayContainer,\n target: this,\n style: `${glass}\\n${overlayMotion}\\n${style}`,\n className: 'tooltip-panel portal wui-glass wui-floating-panel'\n })\n if (this.content) {\n const text = document.createElement('span')\n text.className = 'tooltip-text'\n text.textContent = this.content\n portal.panel.append(text)\n } else portal.moveContent(Array.from(this.querySelectorAll('[slot=\"content\"]')))\n portal.panel.setAttribute('role', 'tooltip')\n return portal\n }\n\n private async _closeOverlay() {\n await this._panel.close(() => this.open)\n }\n\n private _reconfigureOverlay() {\n this._panel.reconfigure(this.open)\n }\n\n private _syncPortalContent() {\n if (!this.portal || !this.open) return\n const panel = this._panel.getPanel()\n if (!panel) return\n const text = panel.querySelector<HTMLElement>('.tooltip-text')\n if (text) {\n text.textContent = this.content\n return\n }\n if (!this.content) return\n panel.replaceChildren()\n const nextText = document.createElement('span')\n nextText.className = 'tooltip-text'\n nextText.textContent = this.content\n panel.append(nextText)\n }\n\n private _dispatchChange(open: boolean) {\n this.dispatchEvent(\n new CustomEvent('open-change', {\n detail: { open },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private _syncVisibleTooltipCount(isVisible: boolean) {\n if (isVisible && !this._isCountedVisible) {\n visibleTooltipCount += 1\n this._isCountedVisible = true\n } else if (!isVisible && this._isCountedVisible) {\n visibleTooltipCount = Math.max(0, visibleTooltipCount - 1)\n this._isCountedVisible = false\n }\n }\n\n override render() {\n return html`\n <div class=\"tooltip-anchor\">\n <div class=\"tooltip-trigger\"><slot></slot></div>\n <div class=\"tooltip-panel wui-glass wui-floating-panel\" hidden role=\"tooltip\">\n ${this.content ? html`<span class=\"tooltip-text\">${this.content}</span>` : html`<slot name=\"content\"></slot>`}\n </div>\n </div>\n `\n }\n\n declare readonly $events: {\n 'open-change': CustomEvent<{ open: boolean }>\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-tooltip': WebUiTooltip\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAM,IAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEI,IAAsB,GAGb,IAAN,cAA2B,EAAW;;EA8If,aAlII,KAAA,aAAA,OAWX,KAAA,aAAA,KAWA,KAAA,aAAA,KAEkC,KAAA,WAAA,IAWrC,KAAA,UAAA,GAEoB,KAAA,UAAA,IAEa,KAAA,OAAA,IACE,KAAA,SAAA,IAKzB,KAAA,oBAAA,IACO,KAAA,kBAAA,IAAI,EAAqB,GAC7B,KAAA,uBAAA,IACL,KAAA,SAAA,EAAoB,CAAC,CAAC,KAAK;GACnD,iBAAiB,KAAK,YAAY,cAA2B,kBAAkB,KAAK;GACpF,qBAAqB,KAAK,YAAY,cAA2B,gBAAgB,KAAK;GACtF,uBAAuB;IACrB,WAAW,KAAK;IAChB,QAAQ,KAAK;IACb,UAAU,KAAK,SAAS,UAAU;GACpC;GACA,gBAAgB,KAAK;GACrB,oBAAoB,KAAK,cAAc;EACzC,CAAC,GAoD0B,KAAA,mBAAA,MAAoB;GACzC,EAAE,gBAAgB,YAClB,KAAK,aACT,aAAa,KAAK,UAAU,GAC5B,KAAK,aAAa,iBAAiB,KAAK,MAAM,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e } from "../overlay/portal.js";
|
|
3
2
|
//#region src/shared/menu-portal/menu-portal.ts
|
|
4
|
-
function
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let r = document.createElement("div");
|
|
5
|
+
r.className = `wui-menu-portal-overlay wui-floating-panel wui-glass ${t}`, r.dataset.wuiPresence = "entering";
|
|
6
|
+
let i = document.createElement("div");
|
|
7
|
+
i.className = "wui-menu-scroll";
|
|
5
8
|
let a = document.createElement("div");
|
|
6
|
-
a.className =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let s = document.createElement("div");
|
|
10
|
-
return s.className = "wui-menu-content", o.append(s), a.append(o), ((i ? t(i) : n())?.getOverlayRoot() ?? e()).appendChild(a), {
|
|
11
|
-
panel: a,
|
|
12
|
-
content: s
|
|
9
|
+
return a.className = "wui-menu-content", i.append(a), r.append(i), e(void 0, n ?? document.body, { preferRootTheme: n === void 0 }).appendChild(r), {
|
|
10
|
+
panel: r,
|
|
11
|
+
content: a
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
//#endregion
|
|
16
|
-
export {
|
|
15
|
+
export { t as createMenuPortalOverlay };
|
|
17
16
|
|
|
18
17
|
//# sourceMappingURL=menu-portal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-portal.js","names":[],"sources":["../../../src/shared/menu-portal/menu-portal.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"menu-portal.js","names":[],"sources":["../../../src/shared/menu-portal/menu-portal.ts"],"sourcesContent":["import { resolveOverlayContainer } from '@/shared/overlay/portal'\n\nexport interface MenuPortalOverlay {\n readonly panel: HTMLElement\n readonly content: HTMLElement\n}\n\n/**\n * 菜单浮层面板:面板直接挂到 overlay 容器(与普通 Overlay Portal 共用容器解析),\n * 样式复用容器内已注入的共享菜单样式(glass/menu-portal/overlay-motion),\n * 因此无需自建 shadow。菜单内容由 dropdown/context-menu 自行构建(menu-tree),\n * 这里只提供 panel 与 content 挂载点。\n */\nexport function createMenuPortalOverlay(className: string, target?: Element): MenuPortalOverlay {\n const panel = document.createElement('div')\n panel.className = `wui-menu-portal-overlay wui-floating-panel wui-glass ${className}`\n panel.dataset.wuiPresence = 'entering'\n const scroll = document.createElement('div')\n scroll.className = 'wui-menu-scroll'\n const content = document.createElement('div')\n content.className = 'wui-menu-content'\n scroll.append(content)\n panel.append(scroll)\n\n const container = resolveOverlayContainer(undefined, target ?? document.body, {\n preferRootTheme: target === undefined\n })\n container.appendChild(panel)\n\n return { panel, content }\n}\n"],"mappings":";;AAaA,SAAgB,EAAwB,GAAmB,GAAqC;CAC9F,IAAM,IAAQ,SAAS,cAAc,KAAK;CAE1C,AADA,EAAM,YAAY,wDAAwD,KAC1E,EAAM,QAAQ,cAAc;CAC5B,IAAM,IAAS,SAAS,cAAc,KAAK;CAC3C,EAAO,YAAY;CACnB,IAAM,IAAU,SAAS,cAAc,KAAK;CAU5C,OATA,EAAQ,YAAY,oBACpB,EAAO,OAAO,CAAO,GACrB,EAAM,OAAO,CAAM,GAKnB,EAH0C,KAAA,GAAW,KAAU,SAAS,MAAM,EAC5E,iBAAiB,MAAW,KAAA,EAC9B,CACA,CAAA,CAAU,YAAY,CAAK,GAEpB;EAAE;EAAO;CAAQ;AAC1B"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { defineOverlay as e } from "./overlay.js";
|
|
2
|
+
import { hideOverlayPresence as t, showOverlayPresence as n } from "./presence.js";
|
|
3
3
|
import { definePlugin as r } from "@greypan/js-kit";
|
|
4
4
|
//#region src/shared/overlay/anchored-panel.ts
|
|
5
5
|
var i = () => r((r) => {
|
|
6
6
|
let i, a, o = () => a?.panel ?? r.getLocalPanel(), s = () => {
|
|
7
7
|
a && (a.restoreContent(), a.remove(), a = void 0, i = void 0);
|
|
8
|
-
}, c = () => r.isPortal() ? (a ??= r.createPortal(), a.panel) : r.getLocalPanel(), l = (
|
|
8
|
+
}, c = () => r.isPortal() ? (a ??= r.createPortal(), a.panel) : r.getLocalPanel(), l = (t, n) => {
|
|
9
9
|
if (i) {
|
|
10
|
-
i.updateAnchor(
|
|
10
|
+
i.updateAnchor(t), i.update(r.getPositioning());
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
i =
|
|
14
|
-
anchor:
|
|
15
|
-
overlay:
|
|
13
|
+
i = e().make({
|
|
14
|
+
anchor: t,
|
|
15
|
+
overlay: n,
|
|
16
16
|
...r.getPositioning()
|
|
17
17
|
});
|
|
18
18
|
}, u = (e = !1) => {
|
|
19
|
-
let
|
|
20
|
-
if (!
|
|
19
|
+
let t = r.getAnchor();
|
|
20
|
+
if (!t) return;
|
|
21
21
|
let a = c();
|
|
22
|
-
a && (l(
|
|
22
|
+
a && (l(t, a), i?.open(), n(a, { isInstant: e }));
|
|
23
23
|
}, d = () => {
|
|
24
24
|
i?.dispose(), i = void 0, s();
|
|
25
25
|
};
|
|
@@ -28,10 +28,10 @@ var i = () => r((r) => {
|
|
|
28
28
|
return o();
|
|
29
29
|
},
|
|
30
30
|
open: u,
|
|
31
|
-
async close(
|
|
31
|
+
async close(e) {
|
|
32
32
|
i?.close();
|
|
33
33
|
let n = o();
|
|
34
|
-
return n && !await
|
|
34
|
+
return n && !await t(n) || e() ? !1 : (s(), !0);
|
|
35
35
|
},
|
|
36
36
|
updatePosition() {
|
|
37
37
|
i?.update(r.getPositioning());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { autoUpdate as e, computePosition as t, flip as n, offset as r, shift as i, size as a } from "../../node_modules/.pnpm/@floating-ui_dom@1.8.0/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
|
|
2
2
|
import { definePlugin as o } from "@greypan/js-kit";
|
|
3
3
|
//#region src/shared/overlay/overlay.ts
|
|
4
|
-
var s = {
|
|
4
|
+
var s = 120, c = "--wui-overlay-min-width", l = {
|
|
5
5
|
placement: "bottom-start",
|
|
6
6
|
offset: 4,
|
|
7
7
|
flip: !0,
|
|
@@ -10,55 +10,77 @@ var s = {
|
|
|
10
10
|
minAnchorWidth: !1,
|
|
11
11
|
strategy: "absolute"
|
|
12
12
|
};
|
|
13
|
-
function
|
|
13
|
+
function u(e) {
|
|
14
|
+
if (typeof getComputedStyle != "function") return s;
|
|
15
|
+
let t = Number.parseFloat(getComputedStyle(e).getPropertyValue(c));
|
|
16
|
+
return Number.isFinite(t) ? t : s;
|
|
17
|
+
}
|
|
18
|
+
function d(e) {
|
|
19
|
+
e.style.removeProperty("width"), e.style.removeProperty("min-width");
|
|
20
|
+
}
|
|
21
|
+
function f(e, t, n) {
|
|
22
|
+
if (t.matchWidth) return e.style.removeProperty("min-width"), n.hasManagedStyles = !0, a({ apply({ rects: t }) {
|
|
23
|
+
e.style.width = `${t.reference.width}px`;
|
|
24
|
+
} });
|
|
25
|
+
if (t.minAnchorWidth) {
|
|
26
|
+
let t = u(e);
|
|
27
|
+
return n.hasManagedStyles = !0, a({ apply({ rects: n }) {
|
|
28
|
+
e.style.width = "max-content", e.style.minWidth = `${Math.max(n.reference.width, t)}px`;
|
|
29
|
+
} });
|
|
30
|
+
}
|
|
31
|
+
n.hasManagedStyles &&= (d(e), !1);
|
|
32
|
+
}
|
|
33
|
+
function p(e, t, a) {
|
|
34
|
+
let o = [r(t.offset)];
|
|
35
|
+
t.flip && o.push(n()), t.shift && o.push(i({ padding: 8 }));
|
|
36
|
+
let s = f(e, t, a);
|
|
37
|
+
return s && o.push(s), o;
|
|
38
|
+
}
|
|
39
|
+
function m(e) {
|
|
14
40
|
let [t, n] = e.split("-"), r = n === "start" ? "left" : n === "end" ? "right" : "center", i = n === "start" ? "top" : n === "end" ? "bottom" : "center";
|
|
15
41
|
return t === "top" ? `bottom ${r}` : t === "bottom" ? `top ${r}` : t === "left" ? `right ${i}` : `left ${i}`;
|
|
16
42
|
}
|
|
17
|
-
var
|
|
18
|
-
let
|
|
19
|
-
placement:
|
|
20
|
-
offset:
|
|
21
|
-
flip:
|
|
22
|
-
shift:
|
|
23
|
-
matchWidth:
|
|
24
|
-
minAnchorWidth:
|
|
25
|
-
strategy:
|
|
26
|
-
},
|
|
27
|
-
function
|
|
28
|
-
let o =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} })), f?.(), f = e(p, u, () => {
|
|
34
|
-
t(p, u, {
|
|
35
|
-
placement: l.placement,
|
|
36
|
-
strategy: l.strategy,
|
|
37
|
-
middleware: o
|
|
43
|
+
var h = () => o((n) => {
|
|
44
|
+
let r = {
|
|
45
|
+
placement: n.placement ?? l.placement,
|
|
46
|
+
offset: n.offset ?? l.offset,
|
|
47
|
+
flip: n.flip ?? l.flip,
|
|
48
|
+
shift: n.shift ?? l.shift,
|
|
49
|
+
matchWidth: n.matchWidth ?? l.matchWidth,
|
|
50
|
+
minAnchorWidth: n.minAnchorWidth ?? l.minAnchorWidth,
|
|
51
|
+
strategy: n.strategy ?? l.strategy
|
|
52
|
+
}, i = n.overlay, a = { hasManagedStyles: !1 }, o = !1, s = null, c = n.anchor;
|
|
53
|
+
function u() {
|
|
54
|
+
let n = p(i, r, a), o = () => {
|
|
55
|
+
t(c, i, {
|
|
56
|
+
placement: r.placement,
|
|
57
|
+
strategy: r.strategy,
|
|
58
|
+
middleware: n
|
|
38
59
|
}).then(({ x: e, y: t, placement: n }) => {
|
|
39
|
-
|
|
60
|
+
i.style.left = `${e}px`, i.style.top = `${t}px`, i.style.setProperty("--wui-overlay-transform-origin", m(n));
|
|
40
61
|
});
|
|
41
|
-
}
|
|
62
|
+
};
|
|
63
|
+
o(), s?.(), s = e(c, i, o);
|
|
42
64
|
}
|
|
43
65
|
return {
|
|
44
66
|
isOpen() {
|
|
45
|
-
return
|
|
67
|
+
return o;
|
|
46
68
|
},
|
|
47
|
-
options:
|
|
69
|
+
options: r,
|
|
48
70
|
open() {
|
|
49
|
-
|
|
71
|
+
o || (o = !0, i.style.display = "", u());
|
|
50
72
|
},
|
|
51
73
|
close() {
|
|
52
|
-
|
|
74
|
+
o && (o = !1, s?.(), s = null);
|
|
53
75
|
},
|
|
54
76
|
toggle() {
|
|
55
|
-
|
|
77
|
+
o ? this.close() : this.open();
|
|
56
78
|
},
|
|
57
79
|
update(e) {
|
|
58
|
-
Object.assign(
|
|
80
|
+
Object.assign(r, e), o && u();
|
|
59
81
|
},
|
|
60
82
|
updateAnchor(e) {
|
|
61
|
-
|
|
83
|
+
c = e, o && u();
|
|
62
84
|
},
|
|
63
85
|
dispose() {
|
|
64
86
|
this.close();
|
|
@@ -66,6 +88,6 @@ var l = () => o((o) => {
|
|
|
66
88
|
};
|
|
67
89
|
});
|
|
68
90
|
//#endregion
|
|
69
|
-
export {
|
|
91
|
+
export { h as defineOverlay };
|
|
70
92
|
|
|
71
93
|
//# sourceMappingURL=overlay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.js","names":[],"sources":["../../../src/shared/overlay/overlay.ts"],"sourcesContent":["import {\n autoUpdate,\n computePosition,\n flip,\n offset,\n shift,\n size,\n type Middleware,\n type Placement,\n type Strategy\n} from '@floating-ui/dom'\nimport { definePlugin } from '@greypan/js-kit'\n\nexport interface OverlayOptions {\n placement?: Placement\n offset?: number\n flip?: boolean\n shift?: boolean\n
|
|
1
|
+
{"version":3,"file":"overlay.js","names":[],"sources":["../../../src/shared/overlay/overlay.ts"],"sourcesContent":["import {\n autoUpdate,\n computePosition,\n flip,\n offset,\n shift,\n size,\n type Middleware,\n type Placement,\n type Strategy\n} from '@floating-ui/dom'\nimport { definePlugin } from '@greypan/js-kit'\n\nexport interface OverlayOptions {\n placement?: Placement\n offset?: number\n flip?: boolean\n shift?: boolean\n /** 面板宽度与锚点宽度保持一致。 */\n matchWidth?: boolean\n /** 面板至少与锚点同宽,同时允许内容将面板撑宽。 */\n minAnchorWidth?: boolean\n strategy?: Strategy\n}\n\n/** 虚拟锚点:无对应 DOM 元素的定位基准(如右键菜单的鼠标坐标)。 */\nexport interface OverlayVirtualAnchor {\n getBoundingClientRect(): DOMRect\n}\n\nexport type OverlayAnchor = HTMLElement | OverlayVirtualAnchor\n\nexport interface OverlayApi {\n isOpen(): boolean\n readonly options: Required<OverlayOptions>\n open(): void\n close(): void\n toggle(): void\n update(options: Partial<OverlayOptions>): void\n updateAnchor(anchor: OverlayAnchor): void\n dispose(): void\n}\n\nconst DEFAULT_OVERLAY_MIN_WIDTH = 120\nconst OVERLAY_MIN_WIDTH_VARIABLE = '--wui-overlay-min-width'\n\nconst DEFAULT_OPTIONS: Required<OverlayOptions> = {\n placement: 'bottom-start',\n offset: 4,\n flip: true,\n shift: true,\n matchWidth: false,\n minAnchorWidth: false,\n strategy: 'absolute'\n}\n\ninterface WidthStyleState {\n hasManagedStyles: boolean\n}\n\nfunction readOverlayMinWidth(overlay: HTMLElement): number {\n if (typeof getComputedStyle !== 'function') return DEFAULT_OVERLAY_MIN_WIDTH\n\n const minWidth = Number.parseFloat(getComputedStyle(overlay).getPropertyValue(OVERLAY_MIN_WIDTH_VARIABLE))\n return Number.isFinite(minWidth) ? minWidth : DEFAULT_OVERLAY_MIN_WIDTH\n}\n\nfunction clearManagedWidthStyles(overlay: HTMLElement) {\n overlay.style.removeProperty('width')\n overlay.style.removeProperty('min-width')\n}\n\nfunction createWidthMiddleware(\n overlay: HTMLElement,\n options: Required<OverlayOptions>,\n widthStyles: WidthStyleState\n): Middleware | undefined {\n if (options.matchWidth) {\n // matchWidth 必须移除之前 minAnchorWidth 写入的 min-width,才能精确跟随 trigger。\n overlay.style.removeProperty('min-width')\n widthStyles.hasManagedStyles = true\n return size({\n apply({ rects }) {\n overlay.style.width = `${rects.reference.width}px`\n }\n })\n }\n\n if (options.minAnchorWidth) {\n const minWidth = readOverlayMinWidth(overlay)\n widthStyles.hasManagedStyles = true\n return size({\n apply({ rects }) {\n // max-content 让内容决定宽度,min-width 再提供 trigger 与 floor 两个下限。\n overlay.style.width = 'max-content'\n overlay.style.minWidth = `${Math.max(rects.reference.width, minWidth)}px`\n }\n })\n }\n\n if (widthStyles.hasManagedStyles) {\n clearManagedWidthStyles(overlay)\n widthStyles.hasManagedStyles = false\n }\n\n return undefined\n}\n\nfunction createPositioningMiddleware(\n overlay: HTMLElement,\n options: Required<OverlayOptions>,\n widthStyles: WidthStyleState\n): Middleware[] {\n const middleware: Middleware[] = [offset(options.offset)]\n if (options.flip) middleware.push(flip())\n if (options.shift) middleware.push(shift({ padding: 8 }))\n\n const widthMiddleware = createWidthMiddleware(overlay, options, widthStyles)\n if (widthMiddleware) middleware.push(widthMiddleware)\n\n return middleware\n}\n\nfunction getTransformOrigin(placement: Placement): string {\n const [side, alignment] = placement.split('-')\n const horizontalOrigin = alignment === 'start' ? 'left' : alignment === 'end' ? 'right' : 'center'\n const verticalOrigin = alignment === 'start' ? 'top' : alignment === 'end' ? 'bottom' : 'center'\n\n if (side === 'top') return `bottom ${horizontalOrigin}`\n if (side === 'bottom') return `top ${horizontalOrigin}`\n if (side === 'left') return `right ${verticalOrigin}`\n return `left ${verticalOrigin}`\n}\n\nexport const defineOverlay = () =>\n definePlugin<OverlayApi, { anchor: OverlayAnchor; overlay: HTMLElement } & OverlayOptions>(ctx => {\n const options: Required<OverlayOptions> = {\n placement: ctx.placement ?? DEFAULT_OPTIONS.placement,\n offset: ctx.offset ?? DEFAULT_OPTIONS.offset,\n flip: ctx.flip ?? DEFAULT_OPTIONS.flip,\n shift: ctx.shift ?? DEFAULT_OPTIONS.shift,\n matchWidth: ctx.matchWidth ?? DEFAULT_OPTIONS.matchWidth,\n minAnchorWidth: ctx.minAnchorWidth ?? DEFAULT_OPTIONS.minAnchorWidth,\n strategy: ctx.strategy ?? DEFAULT_OPTIONS.strategy\n }\n\n const overlay = ctx.overlay\n const widthStyles: WidthStyleState = { hasManagedStyles: false }\n let isOpen = false\n let cleanupAutoUpdate: (() => void) | null = null\n let currentAnchor = ctx.anchor\n\n function updatePosition() {\n const middleware = createPositioningMiddleware(overlay, options, widthStyles)\n\n const applyPosition = () => {\n void computePosition(currentAnchor, overlay, {\n placement: options.placement,\n strategy: options.strategy,\n middleware\n }).then(({ x, y, placement }) => {\n overlay.style.left = `${x}px`\n overlay.style.top = `${y}px`\n overlay.style.setProperty('--wui-overlay-transform-origin', getTransformOrigin(placement))\n })\n }\n\n // 立即定位一次,避免浮层首帧出现在左上角;autoUpdate 负责后续滚动/尺寸变化。\n applyPosition()\n cleanupAutoUpdate?.()\n cleanupAutoUpdate = autoUpdate(currentAnchor, overlay, applyPosition)\n }\n\n return {\n isOpen() {\n return isOpen\n },\n options,\n\n open() {\n if (isOpen) return\n isOpen = true\n overlay.style.display = ''\n updatePosition()\n },\n\n close() {\n if (!isOpen) return\n isOpen = false\n cleanupAutoUpdate?.()\n cleanupAutoUpdate = null\n },\n\n toggle() {\n if (isOpen) this.close()\n else this.open()\n },\n\n update(nextOptions) {\n Object.assign(options, nextOptions)\n if (isOpen) updatePosition()\n },\n\n updateAnchor(newAnchor: OverlayAnchor) {\n currentAnchor = newAnchor\n if (isOpen) updatePosition()\n },\n\n dispose() {\n this.close()\n }\n }\n })\n"],"mappings":";;;AA2CA,IAAM,IAA4B,KAC5B,IAA6B,2BAE7B,IAA4C;CAChD,WAAW;CACX,QAAQ;CACR,MAAM;CACN,OAAO;CACP,YAAY;CACZ,gBAAgB;CAChB,UAAU;AACZ;AAMA,SAAS,EAAoB,GAA8B;CACzD,IAAI,OAAO,oBAAqB,YAAY,OAAO;CAEnD,IAAM,IAAW,OAAO,WAAW,iBAAiB,CAAO,CAAC,CAAC,iBAAiB,CAA0B,CAAC;CACzG,OAAO,OAAO,SAAS,CAAQ,IAAI,IAAW;AAChD;AAEA,SAAS,EAAwB,GAAsB;CAErD,AADA,EAAQ,MAAM,eAAe,OAAO,GACpC,EAAQ,MAAM,eAAe,WAAW;AAC1C;AAEA,SAAS,EACP,GACA,GACA,GACwB;CACxB,IAAI,EAAQ,YAIV,OAFA,EAAQ,MAAM,eAAe,WAAW,GACxC,EAAY,mBAAmB,IACxB,EAAK,EACV,MAAM,EAAE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IAAU,EAAI,SACd,IAA+B,EAAE,kBAAkB,GAAM,GAC3D,IAAS,IACT,IAAyC,MACzC,IAAgB,EAAI;CAExB,SAAS,IAAiB;EACxB,IAAM,IAAa,EAA4B,GAAS,GAAS,CAAW,GAEtE,UAAsB;GAC1B,EAAqB,GAAe,GAAS;IAC3C,WAAW,EAAQ;IACnB,UAAU,EAAQ;IAClB;GACF,CAAC,CAAC,CAAC,MAAM,EAAE,MAAG,MAAG,mBAAgB;IAG/B,AAFA,EAAQ,MAAM,OAAO,GAAG,EAAE,KAC1B,EAAQ,MAAM,MAAM,GAAG,EAAE,KACzB,EAAQ,MAAM,YAAY,kCAAkC,EAAmB,CAAS,CAAC;GAC3F,CAAC;EACH;EAKA,AAFA,EAAc,GACd,IAAoB,GACpB,IAAoB,EAAW,GAAe,GAAS,CAAa;CACtE;CAEA,OAAO;EACL,SAAS;GACP,OAAO;EACT;EACA;EAEA,OAAO;GACD,MACJ,IAAS,IACT,EAAQ,MAAM,UAAU,IACxB,EAAe;EACjB;EAEA,QAAQ;GACD,MACL,IAAS,IACT,IAAoB,GACpB,IAAoB;EACtB;EAEA,SAAS;GACP,AAAI,IAAQ,KAAK,MAAM,IAClB,KAAK,KAAK;EACjB;EAEA,OAAO,GAAa;GAElB,AADA,OAAO,OAAO,GAAS,CAAW,GAC9B,KAAQ,EAAe;EAC7B;EAEA,aAAa,GAA0B;GAErC,AADA,IAAgB,GACZ,KAAQ,EAAe;EAC7B;EAEA,UAAU;GACR,KAAK,MAAM;EACb;CACF;AACF,CAAC"}
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { getFallbackOverlayRoot as e } from "../theme/overlay-root.js";
|
|
2
|
-
import { findNearestTheme as t } from "../theme/theme-scope.js";
|
|
2
|
+
import { findNearestTheme as t, findRootTheme as n } from "../theme/theme-scope.js";
|
|
3
|
+
import { definePlugin as r } from "@greypan/js-kit";
|
|
3
4
|
//#region src/shared/overlay/portal.ts
|
|
4
|
-
|
|
5
|
+
var i = () => r((e) => {
|
|
5
6
|
let t = document.createElement("div");
|
|
6
7
|
t.style.display = "contents";
|
|
7
|
-
let n = t.attachShadow({ mode: "open" }),
|
|
8
|
-
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
let o = []
|
|
8
|
+
let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
|
|
9
|
+
r.textContent = e.style;
|
|
10
|
+
let i = document.createElement("div");
|
|
11
|
+
i.className = e.className, i.dataset.wuiPresence = "entering", n.append(r, i), a(e.container, e.target).appendChild(t);
|
|
12
|
+
let o = [], s = (e) => {
|
|
13
|
+
e.forEach((e) => {
|
|
14
|
+
let t = o.indexOf(e);
|
|
15
|
+
t >= 0 && o.splice(t, 1);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
12
18
|
return {
|
|
13
|
-
panel:
|
|
14
|
-
moveContent(e, t =
|
|
19
|
+
panel: i,
|
|
20
|
+
moveContent(e, t = i) {
|
|
15
21
|
o.splice(0, o.length, ...e), t.append(...o);
|
|
16
22
|
},
|
|
23
|
+
appendContent(e, t = i) {
|
|
24
|
+
s(e), o.push(...e), t.append(...e);
|
|
25
|
+
},
|
|
26
|
+
removeContent(e) {
|
|
27
|
+
s(e);
|
|
28
|
+
},
|
|
17
29
|
restoreContent() {
|
|
18
30
|
e.target.append(...o), o.length = 0;
|
|
19
31
|
},
|
|
@@ -21,11 +33,11 @@ function n(e) {
|
|
|
21
33
|
t.remove();
|
|
22
34
|
}
|
|
23
35
|
};
|
|
24
|
-
}
|
|
25
|
-
function r
|
|
26
|
-
return (typeof
|
|
36
|
+
});
|
|
37
|
+
function a(r, i, a = {}) {
|
|
38
|
+
return (typeof r == "function" ? r() : r) || ((a.preferRootTheme ? n() : t(i))?.getOverlayRoot() ?? e());
|
|
27
39
|
}
|
|
28
40
|
//#endregion
|
|
29
|
-
export {
|
|
41
|
+
export { i as defineOverlayPortal, a as resolveOverlayContainer };
|
|
30
42
|
|
|
31
43
|
//# sourceMappingURL=portal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","names":[],"sources":["../../../src/shared/overlay/portal.ts"],"sourcesContent":["import { getFallbackOverlayRoot } from '@/shared/theme/overlay-root'\nimport { findNearestTheme } from '@/shared/theme/theme-scope'\n\nexport type OverlayContainer = HTMLElement | (() => HTMLElement | undefined)\n\
|
|
1
|
+
{"version":3,"file":"portal.js","names":[],"sources":["../../../src/shared/overlay/portal.ts"],"sourcesContent":["import { definePlugin } from '@greypan/js-kit'\n\nimport { getFallbackOverlayRoot } from '@/shared/theme/overlay-root'\nimport { findNearestTheme, findRootTheme } from '@/shared/theme/theme-scope'\n\nexport type OverlayContainer = HTMLElement | (() => HTMLElement | undefined)\n\nexport interface OverlayContainerResolutionOptions {\n /** 无 target 时优先使用文档中的 root theme。 */\n preferRootTheme?: boolean\n}\n\nexport interface OverlayPortalOptions {\n container?: OverlayContainer\n target: Element\n style: string\n className: string\n}\n\nexport interface OverlayPortal {\n readonly panel: HTMLElement\n restoreContent(): void\n moveContent(nodes: Node[], target?: HTMLElement): void\n appendContent(nodes: Node[], target?: HTMLElement): void\n removeContent(nodes: Node[]): void\n remove(): void\n}\n\n/**\n * 构建带 Shadow DOM 样式边界的 Portal 面板,并追踪被迁移的内容节点以便恢复。\n */\nexport const defineOverlayPortal = () =>\n definePlugin<OverlayPortal, OverlayPortalOptions>(ctx => {\n const host = document.createElement('div')\n // :host 规则可能让宿主在 overlay 容器中生成行盒;display: contents 保留面板定位而不参与布局。\n host.style.display = 'contents'\n\n const root = host.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = ctx.style\n const panel = document.createElement('div')\n panel.className = ctx.className\n panel.dataset.wuiPresence = 'entering'\n root.append(style, panel)\n\n resolveOverlayContainer(ctx.container, ctx.target).appendChild(host)\n\n const trackedNodes: Node[] = []\n const untrackNodes = (nodes: Node[]) => {\n nodes.forEach(node => {\n const index = trackedNodes.indexOf(node)\n if (index >= 0) trackedNodes.splice(index, 1)\n })\n }\n\n return {\n panel,\n\n moveContent(nodes, target = panel) {\n trackedNodes.splice(0, trackedNodes.length, ...nodes)\n target.append(...trackedNodes)\n },\n\n appendContent(nodes, target = panel) {\n untrackNodes(nodes)\n trackedNodes.push(...nodes)\n target.append(...nodes)\n },\n\n removeContent(nodes) {\n untrackNodes(nodes)\n },\n\n restoreContent() {\n ctx.target.append(...trackedNodes)\n trackedNodes.length = 0\n },\n\n remove() {\n host.remove()\n }\n }\n })\n\nexport function resolveOverlayContainer(\n container: OverlayContainer | undefined,\n target: Element,\n options: OverlayContainerResolutionOptions = {}\n): HTMLElement {\n const explicit = typeof container === 'function' ? container() : container\n if (explicit) return explicit\n\n // 无 target 的调用(如菜单)优先使用 root theme;有 target 时使用最近的 theme。\n const theme = options.preferRootTheme ? findRootTheme() : findNearestTheme(target)\n return theme?.getOverlayRoot() ?? getFallbackOverlayRoot()\n}\n"],"mappings":";;;;AA+BA,IAAa,UACX,GAAkD,MAAO;CACvD,IAAM,IAAO,SAAS,cAAc,KAAK;CAEzC,EAAK,MAAM,UAAU;CAErB,IAAM,IAAO,EAAK,aAAa,EAAE,MAAM,OAAO,CAAC,GACzC,IAAQ,SAAS,cAAc,OAAO;CAC5C,EAAM,cAAc,EAAI;CACxB,IAAM,IAAQ,SAAS,cAAc,KAAK;CAK1C,AAJA,EAAM,YAAY,EAAI,WACtB,EAAM,QAAQ,cAAc,YAC5B,EAAK,OAAO,GAAO,CAAK,GAExB,EAAwB,EAAI,WAAW,EAAI,MAAM,CAAC,CAAC,YAAY,CAAI;CAEnE,IAAM,IAAuB,CAAC,GACxB,KAAgB,MAAkB;EACtC,EAAM,SAAQ,MAAQ;GACpB,IAAM,IAAQ,EAAa,QAAQ,CAAI;GACvC,AAAI,KAAS,KAAG,EAAa,OAAO,GAAO,CAAC;EAC9C,CAAC;CACH;CAEA,OAAO;EACL;EAEA,YAAY,GAAO,IAAS,GAAO;GAEjC,AADA,EAAa,OAAO,GAAG,EAAa,QAAQ,GAAG,CAAK,GACpD,EAAO,OAAO,GAAG,CAAY;EAC/B;EAEA,cAAc,GAAO,IAAS,GAAO;GAGnC,AAFA,EAAa,CAAK,GAClB,EAAa,KAAK,GAAG,CAAK,GAC1B,EAAO,OAAO,GAAG,CAAK;EACxB;EAEA,cAAc,GAAO;GACnB,EAAa,CAAK;EACpB;EAEA,iBAAiB;GAEf,AADA,EAAI,OAAO,OAAO,GAAG,CAAY,GACjC,EAAa,SAAS;EACxB;EAEA,SAAS;GACP,EAAK,OAAO;EACd;CACF;AACF,CAAC;AAEH,SAAgB,EACd,GACA,GACA,IAA6C,CAAC,GACjC;CAMb,QALiB,OAAO,KAAc,aAAa,EAAU,IAAI,QAInD,EAAQ,kBAAkB,EAAc,IAAI,EAAiB,CAAM,EAAA,EACnE,eAAe,KAAK,EAAuB;AAC3D"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
+
import { definePlugin as e } from "@greypan/js-kit";
|
|
1
2
|
//#region src/shared/scroll-lock/scroll-lock.ts
|
|
2
|
-
var
|
|
3
|
-
function r() {
|
|
4
|
-
e === 0 && (n = window.scrollY, t = document.documentElement.style.overflow, document.documentElement.style.overflow = "hidden", document.body.style.position = "fixed", document.body.style.top = `-${n}px`, document.body.style.width = "100%"), e++;
|
|
5
|
-
}
|
|
3
|
+
var t = 0, n = "", r = 0;
|
|
6
4
|
function i() {
|
|
7
|
-
|
|
5
|
+
t === 0 && (r = window.scrollY, n = document.documentElement.style.overflow, document.documentElement.style.overflow = "hidden", document.body.style.position = "fixed", document.body.style.top = `-${r}px`, document.body.style.width = "100%"), t++;
|
|
8
6
|
}
|
|
9
7
|
function a() {
|
|
10
|
-
|
|
8
|
+
t = Math.max(0, t - 1), t === 0 && (document.documentElement.style.overflow = n, document.body.style.position = "", document.body.style.top = "", document.body.style.width = "", window.scrollTo(0, r));
|
|
9
|
+
}
|
|
10
|
+
var o = () => e(() => {
|
|
11
|
+
let e = !1, t = (t) => {
|
|
12
|
+
t !== e && (t ? i() : a(), e = t);
|
|
13
|
+
};
|
|
11
14
|
return {
|
|
12
15
|
get isLocked() {
|
|
13
16
|
return e;
|
|
14
17
|
},
|
|
15
|
-
sync
|
|
16
|
-
t !== e && (t ? r() : i(), e = t);
|
|
17
|
-
},
|
|
18
|
+
sync: t,
|
|
18
19
|
release() {
|
|
19
|
-
|
|
20
|
+
t(!1);
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
|
-
}
|
|
23
|
+
});
|
|
23
24
|
//#endregion
|
|
24
|
-
export {
|
|
25
|
+
export { o as defineScrollLockLease, i as lockScroll, a as unlockScroll };
|
|
25
26
|
|
|
26
27
|
//# sourceMappingURL=scroll-lock.js.map
|