@lanxuexing/vue2toast 0.0.7 → 1.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.md CHANGED
@@ -1,48 +1,167 @@
1
- ## vue2toast[![npm version](https://badge.fury.io/js/%40lanxuexing%2Fvue2toast.svg)](https://badge.fury.io/js/%40lanxuexing%2Fvue2toast)
1
+ <div align="center">
2
2
 
3
- ### Install
3
+ # vue2toast
4
4
 
5
- `npm i @lanxuexing/vue2toast --save`
5
+ A lightweight, high-performance Toast notification plugin for Vue 3, built with TypeScript and Vite.
6
6
 
7
+ [![NPM package](https://img.shields.io/npm/v/@lanxuexing/vue2toast.svg?style=flat-square)](https://npmjs.org/package/@lanxuexing/vue2toast)
8
+ [![GitHub Release Date](https://img.shields.io/github/release-date/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/releases)
9
+ [![GitHub repo size](https://img.shields.io/github/repo-size/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast)
10
+ [![GitHub Stars](https://img.shields.io/github/stars/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/stargazers)
11
+ [![NPM downloads](http://img.shields.io/npm/dm/@lanxuexing/vue2toast.svg?style=flat-square)](https://npmjs.org/package/@lanxuexing/vue2toast)
12
+ [![CI/CD](https://github.com/lanxuexing/vue2toast/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/lanxuexing/vue2toast/actions)
13
+ [![GitHub license](https://img.shields.io/github/license/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/blob/main/LICENSE)
14
+ [![Vue 3](https://img.shields.io/badge/vue-3.x-42b883.svg?style=flat-square&logo=vue.js&logoColor=white)](https://vuejs.org)
15
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
16
+ [![Code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
17
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
18
 
8
- ### Settings
19
+ [中文版](./README.zh-CN.md) | English
9
20
 
10
- Name | Default | Type | Description
11
- --------------------|--------------------------|----------|---------------------------
12
- duration | 200 | Number | The duration of the toast
13
- callback | null | Number | The callback of the toast
21
+ ## 🔗 Live Demo
22
+ Check out the component in action: **[https://lanxuexing.github.io/vue2toast/](https://lanxuexing.github.io/vue2toast/)**
14
23
 
15
- ### Usage
24
+ </div>
16
25
 
17
- There are two different ways to manage a Toast.
26
+ ---
18
27
 
19
- ##### **Calling api**
28
+ ## Features
20
29
 
21
- ```javascript
22
- // import plugin
23
- import Vue2Toast from '@lanxuexing/vue2toast';
30
+ - 🚀 **Vue 3 Optimized**: Built with `createVNode` and `render` for minimal overhead.
31
+ - 📐 **TypeScript Ready**: Full type definitions included.
32
+ - 🎨 **Modern Design**: Clean and accessible UI with smooth animations.
33
+ - 🔄 **Updateable Toasts**: Update message content programmatically (e.g., for progress bars).
34
+ - 📦 **Lightweight**: Zero dependencies, tiny bundle size.
35
+ - 🛠 **Customizable**: Control duration and styling easily.
36
+
37
+ ## 📦 Installation
38
+
39
+ ```bash
40
+ npm install @lanxuexing/vue2toast
41
+ ```
42
+
43
+ ## 🚀 Usage
44
+
45
+ ### 1. Register Plugin
46
+
47
+ Register the plugin in your main application file (`main.ts` or `main.js`).
24
48
 
25
- // register plugin on vue
26
- Vue.use(Vue2Toast)
49
+ ```typescript
50
+ import { createApp } from 'vue';
51
+ import App from './App.vue';
52
+ import Toast from '@lanxuexing/vue2toast';
53
+ import '@lanxuexing/vue2toast/style.css'; // Import styles
27
54
 
28
- // add a toast on screen
29
- this.$toast.show("Hello, Toast");
55
+ const app = createApp(App);
56
+ app.use(Toast); // Installs $toast globally and provides useToast
57
+ app.mount('#app');
58
+ ```
59
+
60
+ 3. **SSR Support**: Safe for Server-Side Rendering (Nuxt, Vite SSR).
61
+
62
+ ### 2. Usage in Components
63
+
64
+ You can access the toast instance via the `useToast` composable (Recommended) or the global `$toast` property.
30
65
 
31
- // you can manually hide the toast, or it will automatically disappear after a `duration` ms timeout.
32
- this.$toast.show("Hello, Toast", {
33
- duration: 500
34
- });
66
+ **Composition API (Recommended):**
35
67
 
36
- // you can add callback functions after toast display is complete
37
- this.$toast.show("Hello, Toast", function() {
38
- // do anything
39
- });
68
+ ```typescript
69
+ <script setup lang="ts">
70
+ import { useToast } from '@lanxuexing/vue2toast';
40
71
 
72
+ // Best practice: Typesafe & Clean
73
+ const toast = useToast();
74
+
75
+ const showToast = () => {
76
+ toast('Hello World');
77
+ };
78
+
79
+ const showLongToast = () => {
80
+ toast('This stays for 5 seconds', {
81
+ duration: 5000,
82
+ position: 'top',
83
+ style: { fontWeight: 'bold' }
84
+ });
85
+ };
86
+ </script>
41
87
  ```
42
88
 
43
- ### Run example:
89
+ **Options API:**
90
+
91
+ ```javascript
92
+ export default {
93
+ methods: {
94
+ showToast() {
95
+ // Fully typed via module augmentation
96
+ this.$toast('Hello World');
97
+ }
98
+ }
99
+ }
100
+ ```
44
101
 
102
+ ### 3. Updateable Toasts
103
+
104
+ You can update a toast message while it's still visible. This is perfect for loading states or countdowns.
105
+
106
+ ```typescript
107
+ const showDynamic = () => {
108
+ // Set duration to 0 to keep it open indefinitely (until closed manually)
109
+ const instance = toast('Loading... 0%', { duration: 0 });
110
+
111
+ let progress = 0;
112
+ const timer = setInterval(() => {
113
+ progress += 10;
114
+ instance.update(`Loading... ${progress}%`); // Update text
115
+
116
+ if (progress >= 100) {
117
+ clearInterval(timer);
118
+ instance.close(); // Close programmatically
119
+ toast('Done!');
120
+ }
121
+ }, 300);
122
+ };
45
123
  ```
46
- cd ./vue2toast
47
- npm install
124
+
125
+ ### 4. Manual Close (Persistent Toast)
126
+
127
+ Set `duration` to `0` to keep the toast open indefinitely until you call the `close()` method on the returned instance.
128
+
129
+ ```typescript
130
+ const showPersist = () => {
131
+ const instance = toast('I will not close automatically...', { duration: 0 });
132
+
133
+ // Close manually after some action
134
+ setTimeout(() => {
135
+ instance.close();
136
+ }, 5000);
137
+ };
48
138
  ```
139
+
140
+ ### 5. SSR & Best Practices
141
+
142
+ - **SSR Safe**: The plugin automatically detects the environment and returns a no-op instance on the server, preventing hydration mismatches or node errors.
143
+ - **Context Inheritance**: Toasts inherit the `appContext` of your application, meaning they can access global plugins (like `i18n`, `router`, `pinia`) and provided values.
144
+
145
+ ## ⚙️ Configuration
146
+
147
+ | Option | Type | Default | Description |
148
+ | :--- | :--- | :--- | :--- |
149
+ | `duration` | `number` | `3000` | Duration in ms. Set to `0` to persist indefinitely. |
150
+ | `pauseOnHover` | `boolean` | `true` | Pauses timer when hovering over the toast. |
151
+ | `position` | `'top' \| 'bottom' \| 'center'` | `'center'` | Vertical position of the toast. |
152
+ | `zIndex` | `number` | `9999` | Z-Index of the toast container. |
153
+ | `className` | `string` | `''` | Custom CSS class name for the toast content. |
154
+ | `style` | `CSSProperties` | `{}` | Custom inline styles (Vue CSS object). |
155
+ | `useHtml` | `boolean` | `false` | **Warning**: Enables HTML rendering (XSS Risk). |
156
+
157
+ ## 🛠 Development
158
+
159
+ This repository is powered by Vite.
160
+
161
+ - **Dev Server**: `npm run dev`
162
+ - **Build Lib**: `npm run build`
163
+ - **Build Demo**: `npm run build:demo`
164
+
165
+ ---
166
+
167
+ Built with ❤️ for the Vue Community.
@@ -0,0 +1,165 @@
1
+ <div align="center">
2
+
3
+ # vue2toast
4
+
5
+ 一个轻量、高性能的 Vue 3 Toast 提示插件,基于 TypeScript 和 Vite 构建。
6
+
7
+ [![NPM package](https://img.shields.io/npm/v/@lanxuexing/vue2toast.svg?style=flat-square)](https://npmjs.org/package/@lanxuexing/vue2toast)
8
+ [![GitHub Release Date](https://img.shields.io/github/release-date/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/releases)
9
+ [![GitHub repo size](https://img.shields.io/github/repo-size/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast)
10
+ [![GitHub Stars](https://img.shields.io/github/stars/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/stargazers)
11
+ [![NPM downloads](http://img.shields.io/npm/dm/@lanxuexing/vue2toast.svg?style=flat-square)](https://npmjs.org/package/@lanxuexing/vue2toast)
12
+ [![CI/CD](https://github.com/lanxuexing/vue2toast/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/lanxuexing/vue2toast/actions)
13
+ [![GitHub license](https://img.shields.io/github/license/lanxuexing/vue2toast.svg?style=flat-square)](https://github.com/lanxuexing/vue2toast/blob/main/LICENSE)
14
+ [![Vue 3](https://img.shields.io/badge/vue-3.x-42b883.svg?style=flat-square&logo=vue.js&logoColor=white)](https://vuejs.org)
15
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
16
+ [![Code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
17
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
18
+
19
+ [中文版](./README.zh-CN.md) | [English](./README.md)
20
+
21
+ ## 🔗 在线演示
22
+ 查看组件效果: **[https://lanxuexing.github.io/vue2toast/](https://lanxuexing.github.io/vue2toast/)**
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## ✨ 特性
29
+
30
+ - 🚀 **Vue 3 优化**: 使用 `createVNode` 和 `render` 函数构建,性能极致。
31
+ - 📐 **TypeScript 支持**: 内置完整的类型定义 (d.ts)。
32
+ - 🎨 **现代设计**: 简洁美观的 UI,流畅的动画。
33
+ - 🔄 **支持更新**: 可编程更新 Toast 内容 (适用于进度条、倒计时等)。
34
+ - 📦 **轻量级**: 零依赖,体积极小。
35
+ - 🛠 **易定制**: 轻松控制时长和样式。
36
+
37
+ ## 📦 安装
38
+
39
+ ```bash
40
+ npm install @lanxuexing/vue2toast
41
+ ```
42
+
43
+ ## 🚀 使用方法
44
+
45
+ ### 1. 注册插件
46
+
47
+ 在你的主入口文件 (`main.ts` 或 `main.js`) 中注册插件。
48
+
49
+ ```typescript
50
+ import { createApp } from 'vue';
51
+ import App from './App.vue';
52
+ import Toast from '@lanxuexing/vue2toast';
53
+ import '@lanxuexing/vue2toast/style.css'; // 记得引入样式文件
54
+
55
+ const app = createApp(App);
56
+ app.use(Toast); // 全局注册 $toast 并提供 useToast
57
+ app.mount('#app');
58
+ ```
59
+
60
+ ### 2. 在组件中使用
61
+
62
+ 推荐使用 `useToast` 组合式函数,也可以继续使用全局 `$toast`。
63
+
64
+ **Composition API (推荐):**
65
+
66
+ ```typescript
67
+ <script setup lang="ts">
68
+ import { useToast } from '@lanxuexing/vue2toast';
69
+
70
+ // 最佳实践:类型安全且简洁
71
+ const toast = useToast();
72
+
73
+ const showToast = () => {
74
+ toast('Hello World');
75
+ };
76
+
77
+ const showLongToast = () => {
78
+ toast('这条消息会显示 5 秒', {
79
+ duration: 5000,
80
+ position: 'top',
81
+ style: { fontWeight: 'bold' }
82
+ });
83
+ };
84
+ </script>
85
+ ```
86
+
87
+ **Options API:**
88
+
89
+ ```javascript
90
+ export default {
91
+ methods: {
92
+ showToast() {
93
+ // 这里的 this.$toast 现在有完善的类型提示
94
+ this.$toast('Hello World');
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ ### 3. 可更新的 Toast
101
+
102
+ 你可以在 Toast 显示期间更新其内容,这非常适合加载状态或倒计时场景。
103
+
104
+ ```typescript
105
+ const showDynamic = () => {
106
+ // 设置 duration 为 0,使其一直显示,直到手动关闭
107
+ const instance = toast('加载中... 0%', { duration: 0 });
108
+
109
+ let progress = 0;
110
+ const timer = setInterval(() => {
111
+ progress += 10;
112
+ instance.update(`加载中... ${progress}%`); // 更新内容
113
+
114
+ if (progress >= 100) {
115
+ clearInterval(timer);
116
+ instance.close(); // 手动关闭
117
+ toast('加载完成!');
118
+ }
119
+ }, 300);
120
+ };
121
+ ```
122
+
123
+ ### 4. 手动关闭 (持久化 Toast)
124
+
125
+ 将 `duration` 设置为 `0`,Toast 将不会自动消失,直到你调用返回实例的 `close()` 方法。
126
+
127
+ ```typescript
128
+ const showPersist = () => {
129
+ const instance = toast('我不会自动消失...', { duration: 0 });
130
+
131
+ // 模拟异步操作后关闭
132
+ setTimeout(() => {
133
+ instance.close();
134
+ }, 5000);
135
+ };
136
+ ```
137
+
138
+ ### 5. SSR 与最佳实践
139
+
140
+ - **SSR 安全**: 插件会自动检测环境,在服务端返回空实例,避免水合不匹配或 Node 报错。
141
+ - **上下文继承**: Toast 会自动继承应用的 `appContext`,这意味着你可以在 Toast 组件内部正常访问全局插件 (如 `i18n`, `router`, `pinia`)。
142
+
143
+ ## ⚙️ 配置选项
144
+
145
+ | 选项名 | 类型 | 默认值 | 描述 |
146
+ | :--- | :--- | :--- | :--- |
147
+ | `duration` | `number` | `3000` | 显示时长 (ms)。设置为 `0` 则永久显示。 |
148
+ | `pauseOnHover` | `boolean` | `true` | 鼠标悬停时是否暂停倒计时。 |
149
+ | `position` | `'top' \| 'bottom' \| 'center'` | `'center'` | Toast 的垂直显示位置。 |
150
+ | `zIndex` | `number` | `9999` | Toast 容器的层级 (z-index)。 |
151
+ | `className` | `string` | `''` | 自定义 CSS 类名。 |
152
+ | `style` | `CSSProperties` | `{}` | 自定义内联样式对象 (Vue CSS)。 |
153
+ | `useHtml` | `boolean` | `false` | **警告**: 是否解析 HTML (注意 XSS 风险)。 |
154
+
155
+ ## 🛠 本地开发
156
+
157
+ 本项目使用 Vite 构建。
158
+
159
+ - **启动开发服务器**: `npm run dev`
160
+ - **构建库**: `npm run build`
161
+ - **构建 Demo**: `npm run build:demo`
162
+
163
+ ---
164
+
165
+ Built with ❤️ for the Vue Community.
@@ -0,0 +1,64 @@
1
+ import { App } from 'vue';
2
+ import { CSSProperties } from 'vue';
3
+
4
+ export declare type ShowToast = (message: string, options?: ToastOptions | (() => void)) => ToastInstance;
5
+
6
+ declare const Toast: {
7
+ install(app: App, options?: ToastOptions): void;
8
+ };
9
+ export default Toast;
10
+
11
+ export declare interface ToastInstance {
12
+ close: () => void;
13
+ update: (message: string) => void;
14
+ }
15
+
16
+ export declare interface ToastOptions {
17
+ /**
18
+ * Duration in milliseconds before the toast automatically closes.
19
+ * Set to 0 to disable auto-close.
20
+ * @default 3000
21
+ */
22
+ duration?: number;
23
+ /**
24
+ * Whether to pause the auto-close timer when mouse hovers over the toast.
25
+ * @default true
26
+ */
27
+ pauseOnHover?: boolean;
28
+ /**
29
+ * Custom CSS class name(s) to apply to the toast element.
30
+ */
31
+ className?: string | object | string[];
32
+ /**
33
+ * Custom inline styles to apply to the toast element.
34
+ */
35
+ style?: CSSProperties;
36
+ /**
37
+ * Z-index of the toast container.
38
+ * @default 9999
39
+ */
40
+ zIndex?: number;
41
+ /**
42
+ * Position of the toast on the screen.
43
+ * @default 'center'
44
+ */
45
+ position?: 'top' | 'bottom' | 'center';
46
+ /**
47
+ * Whether to interpret the message property as HTML content.
48
+ * ⚠️ Be careful with XSS vulnerabilities when enabling this.
49
+ * @default false
50
+ */
51
+ useHtml?: boolean;
52
+ [key: string]: any;
53
+ }
54
+
55
+ export declare const useToast: () => ShowToast;
56
+
57
+ export { }
58
+
59
+
60
+ declare module '@vue/runtime-core' {
61
+ interface ComponentCustomProperties {
62
+ $toast: ShowToast;
63
+ }
64
+ }
@@ -0,0 +1 @@
1
+ .toast-container[data-v-00a26138]{position:fixed;left:0;top:0;bottom:0;right:0;display:flex;justify-content:center;pointer-events:none}.toast-container.is-center[data-v-00a26138]{align-items:center}.toast-container.is-top[data-v-00a26138]{align-items:flex-start;padding-top:60px}.toast-container.is-bottom[data-v-00a26138]{align-items:flex-end;padding-bottom:60px}.toast-container .toast[data-v-00a26138]{width:180px;height:60px;line-height:60px;text-align:center;background-color:#0000009c;border-radius:10px;color:#fff;pointer-events:auto;transition:transform .2s ease,box-shadow .2s ease;cursor:default}.toast-container .toast[data-v-00a26138]:hover{transform:scale(1.05);box-shadow:0 8px 20px #0003}.toast-container .message[data-v-00a26138]{font-size:14px;color:#fff}.fade-enter-active[data-v-00a26138],.fade-leave-active[data-v-00a26138]{transition:opacity .3s,transform .3s}.fade-enter-from[data-v-00a26138],.fade-leave-to[data-v-00a26138]{opacity:0;transform:scale(.7)}
@@ -0,0 +1,134 @@
1
+ import { defineComponent as _, ref as g, createBlock as h, openBlock as m, Transition as k, withCtx as z, createElementBlock as f, createCommentVNode as S, normalizeStyle as b, normalizeClass as x, createElementVNode as I, toDisplayString as N, inject as j, createVNode as M, render as C } from "vue";
2
+ const w = ["innerHTML"], B = {
3
+ key: 1,
4
+ class: "message"
5
+ }, E = /* @__PURE__ */ _({
6
+ __name: "Toast",
7
+ props: {
8
+ zIndex: {
9
+ type: Number,
10
+ default: 9999
11
+ },
12
+ position: {
13
+ type: String,
14
+ default: "center"
15
+ // 'top' | 'bottom' | 'center'
16
+ },
17
+ useHtml: {
18
+ type: Boolean,
19
+ default: !1
20
+ },
21
+ customClass: {
22
+ type: [String, Object, Array],
23
+ default: ""
24
+ },
25
+ customStyle: {
26
+ type: Object,
27
+ default: () => ({})
28
+ }
29
+ },
30
+ emits: ["mouseenter", "mouseleave"],
31
+ setup(e, { expose: c, emit: s }) {
32
+ const n = g(!1), a = g(""), l = s, t = () => l("mouseenter"), r = () => l("mouseleave");
33
+ return c({
34
+ visible: n,
35
+ message: a
36
+ }), (o, u) => (m(), h(k, { name: "fade" }, {
37
+ default: z(() => [
38
+ n.value ? (m(), f("section", {
39
+ key: 0,
40
+ class: x(["toast-container", [`is-${e.position}`]]),
41
+ style: b({ zIndex: e.zIndex })
42
+ }, [
43
+ I("div", {
44
+ class: x(["toast", e.customClass]),
45
+ style: b(e.customStyle),
46
+ onMouseenter: t,
47
+ onMouseleave: r
48
+ }, [
49
+ e.useHtml ? (m(), f("div", {
50
+ key: 0,
51
+ innerHTML: a.value,
52
+ class: "message-html"
53
+ }, null, 8, w)) : (m(), f("span", B, N(a.value), 1))
54
+ ], 38)
55
+ ], 6)) : S("", !0)
56
+ ]),
57
+ _: 1
58
+ }));
59
+ }
60
+ }), V = (e, c) => {
61
+ const s = e.__vccOpts || e;
62
+ for (const [n, a] of c)
63
+ s[n] = a;
64
+ return s;
65
+ }, L = /* @__PURE__ */ V(E, [["__scopeId", "data-v-00a26138"]]), H = Symbol("Toast"), A = {
66
+ install(e, c = {}) {
67
+ let s = {
68
+ duration: 3e3,
69
+ pauseOnHover: !0,
70
+ zIndex: 9999,
71
+ position: "center",
72
+ useHtml: !1
73
+ };
74
+ Object.assign(s, c);
75
+ const n = (a, l) => {
76
+ var T;
77
+ let t = { ...s }, r = null;
78
+ if (typeof l == "object" ? Object.assign(t, l) : typeof l == "function" && (r = l), typeof document > "u")
79
+ return {
80
+ close: () => {
81
+ },
82
+ update: () => {
83
+ }
84
+ };
85
+ const o = document.createElement("div");
86
+ document.body.appendChild(o);
87
+ let u = null;
88
+ const p = () => {
89
+ t.duration && t.duration > 0 && (u = setTimeout(() => {
90
+ y();
91
+ }, t.duration));
92
+ }, v = () => {
93
+ u && (clearTimeout(u), u = null);
94
+ };
95
+ let d = M(L, {
96
+ zIndex: t.zIndex,
97
+ position: t.position,
98
+ useHtml: t.useHtml,
99
+ customClass: t.className,
100
+ customStyle: t.style,
101
+ onMouseenter: () => {
102
+ t.pauseOnHover && v();
103
+ },
104
+ onMouseleave: () => {
105
+ t.pauseOnHover && p();
106
+ }
107
+ });
108
+ d.appContext = e._context, C(d, o);
109
+ const i = (T = d.component) == null ? void 0 : T.exposed;
110
+ i && (i.message.value = a, i.visible.value = !0);
111
+ const y = () => {
112
+ i && (i.visible.value = !1), v(), setTimeout(() => {
113
+ o && o.parentNode && (C(null, o), o.parentNode.removeChild(o)), r && r();
114
+ }, 300);
115
+ };
116
+ return p(), {
117
+ close: y,
118
+ update: (O) => {
119
+ i && (i.message.value = O);
120
+ }
121
+ };
122
+ };
123
+ e.config.globalProperties.$toast = n, e.provide(H, n);
124
+ }
125
+ }, D = () => {
126
+ const e = j(H);
127
+ if (!e)
128
+ throw new Error("Toast plugin not installed");
129
+ return e;
130
+ };
131
+ export {
132
+ A as default,
133
+ D as useToast
134
+ };
@@ -0,0 +1 @@
1
+ (function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.vue2toast={},n.Vue))})(this,(function(n,e){"use strict";const _=["innerHTML"],x={key:1,class:"message"},k=((t,u)=>{const l=t.__vccOpts||t;for(const[a,i]of u)l[a]=i;return l})(e.defineComponent({__name:"Toast",props:{zIndex:{type:Number,default:9999},position:{type:String,default:"center"},useHtml:{type:Boolean,default:!1},customClass:{type:[String,Object,Array],default:""},customStyle:{type:Object,default:()=>({})}},emits:["mouseenter","mouseleave"],setup(t,{expose:u,emit:l}){const a=e.ref(!1),i=e.ref(""),c=l,o=()=>c("mouseenter"),d=()=>c("mouseleave");return u({visible:a,message:i}),(s,m)=>(e.openBlock(),e.createBlock(e.Transition,{name:"fade"},{default:e.withCtx(()=>[a.value?(e.openBlock(),e.createElementBlock("section",{key:0,class:e.normalizeClass(["toast-container",[`is-${t.position}`]]),style:e.normalizeStyle({zIndex:t.zIndex})},[e.createElementVNode("div",{class:e.normalizeClass(["toast",t.customClass]),style:e.normalizeStyle(t.customStyle),onMouseenter:o,onMouseleave:d},[t.useHtml?(e.openBlock(),e.createElementBlock("div",{key:0,innerHTML:i.value,class:"message-html"},null,8,_)):(e.openBlock(),e.createElementBlock("span",x,e.toDisplayString(i.value),1))],38)],6)):e.createCommentVNode("",!0)]),_:1}))}}),[["__scopeId","data-v-00a26138"]]),p=Symbol("Toast"),h={install(t,u={}){let l={duration:3e3,pauseOnHover:!0,zIndex:9999,position:"center",useHtml:!1};Object.assign(l,u);const a=(i,c)=>{var g;let o={...l},d=null;if(typeof c=="object"?Object.assign(o,c):typeof c=="function"&&(d=c),typeof document>"u")return{close:()=>{},update:()=>{}};const s=document.createElement("div");document.body.appendChild(s);let m=null;const y=()=>{o.duration&&o.duration>0&&(m=setTimeout(()=>{b()},o.duration))},T=()=>{m&&(clearTimeout(m),m=null)};let f=e.createVNode(k,{zIndex:o.zIndex,position:o.position,useHtml:o.useHtml,customClass:o.className,customStyle:o.style,onMouseenter:()=>{o.pauseOnHover&&T()},onMouseleave:()=>{o.pauseOnHover&&y()}});f.appContext=t._context,e.render(f,s);const r=(g=f.component)==null?void 0:g.exposed;r&&(r.message.value=i,r.visible.value=!0);const b=()=>{r&&(r.visible.value=!1),T(),setTimeout(()=>{s&&s.parentNode&&(e.render(null,s),s.parentNode.removeChild(s)),d&&d()},300)};return y(),{close:b,update:O=>{r&&(r.message.value=O)}}};t.config.globalProperties.$toast=a,t.provide(p,a)}},C=()=>{const t=e.inject(p);if(!t)throw new Error("Toast plugin not installed");return t};n.default=h,n.useToast=C,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,35 +1,66 @@
1
1
  {
2
2
  "name": "@lanxuexing/vue2toast",
3
- "version": "0.0.7",
4
- "description": "this is an information prompt tool on vue",
5
- "main": "dist/vue2toast.js",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight, high-performance Toast notification plugin for Vue 3, built with TypeScript.",
5
+ "main": "dist/vue2toast.umd.js",
6
+ "module": "dist/vue2toast.es.js",
7
+ "types": "dist/index.d.ts",
6
8
  "author": "lanxuexing",
9
+ "license": "MIT",
10
+ "sideEffects": false,
7
11
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
12
+ "dev": "vite serve --config vite.config.demo.mjs",
13
+ "build": "vite build --config vite.config.js",
14
+ "build:demo": "vite build --config vite.config.demo.mjs",
15
+ "preview": "vite preview"
9
16
  },
10
17
  "keywords": [
11
- "toast",
18
+ "vue",
19
+ "vue3",
12
20
  "vue-toast",
13
- "vue2toast",
14
- "vue2-toast"
21
+ "toast",
22
+ "notification",
23
+ "message",
24
+ "alert",
25
+ "popup",
26
+ "component",
27
+ "plugin",
28
+ "typescript",
29
+ "ts"
15
30
  ],
16
- "dependencies": {
17
- "vue": "^2.3.4",
18
- "webpack": "^3.1.0"
31
+ "dependencies": {},
32
+ "peerDependencies": {
33
+ "vue": "^3.0.0"
19
34
  },
20
35
  "devDependencies": {
21
- "autoprefixer": "^7.1.2",
22
- "babel-core": "^6.25.0",
23
- "babel-loader": "^7.1.1",
24
- "babel-preset-env": "^1.6.0",
25
- "css-loader": "^0.28.4",
26
- "node-sass": "^4.5.3",
27
- "postcss-loader": "^2.0.6",
28
- "sass-loader": "^6.0.6",
29
- "style-loader": "^0.18.2",
30
- "uglifyjs-webpack-plugin": "^0.4.6",
31
- "vue-loader": "^13.0.1",
32
- "vue-template-compiler": "^2.3.4"
36
+ "@tailwindcss/vite": "^4.1.18",
37
+ "@types/node": "^22.10.2",
38
+ "@vitejs/plugin-vue": "^5.2.1",
39
+ "highlight.js": "^11.11.1",
40
+ "sass": "^1.83.0",
41
+ "tailwindcss": "^4.1.18",
42
+ "typescript": "^5.7.2",
43
+ "vite": "^6.0.5",
44
+ "vite-plugin-dts": "^4.3.0",
45
+ "vue": "^3.5.13",
46
+ "vue-tsc": "^2.1.10"
47
+ },
48
+ "overrides": {
49
+ "minimatch": "^9.0.5"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "README.md",
54
+ "README.zh-CN.md",
55
+ "LICENSE"
56
+ ],
57
+ "exports": {
58
+ ".": {
59
+ "types": "./dist/index.d.ts",
60
+ "import": "./dist/vue2toast.es.js",
61
+ "require": "./dist/vue2toast.umd.js"
62
+ },
63
+ "./style.css": "./dist/style.css"
33
64
  },
34
65
  "repository": {
35
66
  "type": "git",
@@ -40,5 +71,7 @@
40
71
  "email": "geziaihuahua@163.com"
41
72
  },
42
73
  "homepage": "https://github.com/lanxuexing/vue2toast#readme",
43
- "license": "MIT"
44
- }
74
+ "engines": {
75
+ "node": ">=24.0.0"
76
+ }
77
+ }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": []
3
- }