solely 0.4.10 → 0.4.11

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
@@ -7,6 +7,8 @@
7
7
  **一个轻量级、现代化的 Web 组件开发框架**
8
8
 
9
9
  [![npm version](https://img.shields.io/npm/v/solely.svg)](https://www.npmjs.com/package/solely)
10
+ [![codecov](https://codecov.io/gh/solelyjs/solely/branch/main/graph/badge.svg)](https://codecov.io/gh/solelyjs/solely)
11
+ [![VS Code Extension](https://img.shields.io/badge/VS%20Code-Solely-blue?logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=solely.solely-vscode)
10
12
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
11
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
12
14
 
@@ -29,6 +31,7 @@
29
31
  - [快速开始指南](./docs/guide.md) - 从零开始学习 Solely
30
32
  - [API 文档](./docs/api.md) - 完整的 API 参考
31
33
  - [示例项目](./examples/) - 实际应用示例
34
+ - [VS Code 扩展](./vscode-extension/) - 语法高亮、智能跳转、错误诊断
32
35
  - [插件系统](#插件系统) - 了解 Vite 插件的使用方法
33
36
  - [安全机制说明](#安全机制) - 了解框架的 XSS 防护机制
34
37
  - [安全演示](./examples/security-demo/) - 查看 XSS 防护实际效果
@@ -46,6 +49,38 @@ yarn add solely
46
49
  pnpm add solely
47
50
  ```
48
51
 
52
+ ## 🛠️ VS Code 扩展
53
+
54
+ Solely 提供了官方 VS Code 扩展,为 `.html` 模板文件提供语法高亮、智能跳转、悬停提示和错误诊断。
55
+
56
+ ### 安装
57
+
58
+ **方式一:通过 VS Code 扩展面板安装(推荐)**
59
+
60
+ 按 `Ctrl+Shift+X` 打开扩展面板,搜索 **"Solely Framework Support"** 即可安装。
61
+
62
+ **方式二:通过命令行安装**
63
+
64
+ 需确保 `code` 命令已在系统 PATH 中(可通过 `Shell Command: Install 'code' command in PATH` 命令添加):
65
+
66
+ ```bash
67
+ code --install-extension solely.solely-vscode
68
+ ```
69
+
70
+ ### 功能
71
+
72
+ | 功能 | 说明 |
73
+ | ------------ | --------------------------------------------------------------------------------- |
74
+ | **语法高亮** | `$data.xxx`、`this.xxx()`、`<If>`/`<For>`、`@click`、`ref="xxx"` 等均有独立配色 |
75
+ | **定义跳转** | Ctrl+点击模板中的方法名/属性名/引用,跳转到 TS 文件中对应定义 |
76
+ | **悬停提示** | 鼠标悬停显示方法签名、属性信息和跳转提示 |
77
+ | **错误诊断** | `<If>`/`<ElseIf>`/`<Else>`/`<For>` 标签配对检查和嵌套错误提示 |
78
+ | **模板关联** | 自动识别 `import template from './xxx.html?raw'` / `?solely`,正确关联 HTML 与 TS |
79
+
80
+ ### 版本要求
81
+
82
+ - VS Code `>= 1.85.0`
83
+
49
84
  ## 🎯 快速开始
50
85
 
51
86
  ### 1. 创建一个简单的组件
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={placement:"top",trigger:"hover",duration:3e3},o=[],l=new WeakSet;let i=null;async function s(t,n){const l=o.findIndex(e=>e.id===t);if(-1===l)return;const i=o[l],s=i.element.querySelector(".tooltip");s&&s.classList.add("is-closing"),await e.addClosingAnimation(i.element,e.ANIMATION_DURATION.FAST),i.element.remove(),o.splice(l,1),null==n||n()}function r(l,r){var a;const c=e.generateId();e.injectStyle("solely-tooltip-styles",t.default);const d=r.placement??n.placement,u=e.createElement("div",{className:"tooltip-overlay"}),m=(p=u,(()=>{const e=document.documentElement.getAttribute("data-theme");e?p.setAttribute("data-theme",e):p.removeAttribute("data-theme")})(),i||(i=new MutationObserver(()=>{o.forEach(e=>{const t=document.documentElement.getAttribute("data-theme");t?e.element.setAttribute("data-theme",t):e.element.removeAttribute("data-theme")})}),i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]})),()=>{i&&0===o.length&&(i.disconnect(),i=null)});var p;const v=e.createElement("div",{className:`tooltip tooltip--${d}${r.className?` ${r.className}`:""}`,styles:{...r.style,...r.color?{backgroundColor:r.color}:{}}}),h=e.createElement("div",{className:"tooltip__content"});r.content&&("string"==typeof r.content?h.textContent=r.content:r.content instanceof HTMLElement&&h.appendChild(r.content.cloneNode(!0))),v.appendChild(h);const g=e.createElement("div",{className:"tooltip__arrow"});r.color&&(g.style.backgroundColor=r.color),v.appendChild(g),u.appendChild(v),document.body.appendChild(u);const f=e.calculatePosition(l,v,d);return v.style.top=`${f.top}px`,v.style.left=`${f.left}px`,void 0!==f.arrowLeft&&(g.style.left=`${f.arrowLeft}px`),void 0!==f.arrowTop&&(g.style.top=`${f.arrowTop}px`),o.push({id:c,element:u,target:l,destroy:()=>{m(),s(c)}}),null==(a=r.onVisibleChange)||a.call(r,!0),c}const a={bind:function(e,t){if(l.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};l.add(e);const o=t.trigger??n.trigger;let i=t.visible??t.defaultVisible??!1,a=null;const c=()=>{i||(i=!0,a=r(e,t))},d=()=>{if(!i||null===a)return;i=!1;const e=a;a=null,s(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},u=e=>{e.stopPropagation(),i?d():c()},m=t=>{i&&(e.contains(t.target)||d())};return"hover"===o?(e.addEventListener("mouseenter",c),e.addEventListener("mouseleave",d)):"click"===o?(e.addEventListener("click",u),document.addEventListener("click",m)):"focus"===o&&(e.addEventListener("focus",c),e.addEventListener("blur",d)),i&&(a=r(e,t)),{show:c,hide:d,destroy:()=>{d(),l.delete(e),"hover"===o?(e.removeEventListener("mouseenter",c),e.removeEventListener("mouseleave",d)):"click"===o?(e.removeEventListener("click",u),document.removeEventListener("click",m)):"focus"===o&&(e.removeEventListener("focus",c),e.removeEventListener("blur",d))}}},show:function(e,t){const o=r(e,t),l=t.duration??n.duration;l>0&&setTimeout(()=>{s(o)},l)},hide:async function(t){0!==o.length?(await Promise.all(o.map(async t=>{const n=t.element.querySelector(".tooltip");n&&n.classList.add("is-closing"),await e.addClosingAnimation(t.element,e.ANIMATION_DURATION.FAST),t.element.remove()})),o.length=0,null==t||t()):null==t||t()},config:function(e){Object.assign(n,e)}};exports.Tooltip=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),o={placement:"top",trigger:"hover",duration:3e3,singleton:!0},n=[],r=new WeakSet;let l=null;function s(e,t,o,n=8){const r=e.getBoundingClientRect(),l=t.offsetWidth||250,s=t.offsetHeight||100;let i,a,c=0,d=0;switch(o){case"top":c=r.top-s-n,d=r.left+(r.width-l)/2,i=l/2-4;break;case"topLeft":c=r.top-s-n,d=r.left,i=16;break;case"topRight":c=r.top-s-n,d=r.right-l,i=l-24;break;case"bottom":c=r.bottom+n,d=r.left+(r.width-l)/2,i=l/2-4;break;case"bottomLeft":c=r.bottom+n,d=r.left,i=16;break;case"bottomRight":c=r.bottom+n,d=r.right-l,i=l-24;break;case"left":c=r.top+(r.height-s)/2,d=r.left-l-n,a=s/2-4;break;case"leftTop":c=r.top,d=r.left-l-n,a=16;break;case"leftBottom":c=r.bottom-s,d=r.left-l-n,a=s-24;break;case"right":c=r.top+(r.height-s)/2,d=r.right+n,a=s/2-4;break;case"rightTop":c=r.top,d=r.right+n,a=16;break;case"rightBottom":c=r.bottom-s,d=r.right+n,a=s-24}return c=Math.max(8,Math.min(c,window.innerHeight-s-8)),d=Math.max(8,Math.min(d,window.innerWidth-l-8)),{top:c,left:d,arrowLeft:i,arrowTop:a}}let i=null,a=!1;function c(){i||(i=requestAnimationFrame(()=>{i=null,n.forEach(e=>{const t=e.element;if(!t||!e.target)return;const o=t.querySelector(".tooltip__arrow"),n=s(e.target,t,e.placement);t.style.top=`${n.top}px`,t.style.left=`${n.left}px`,o&&(void 0!==n.arrowLeft&&(o.style.left=`${n.arrowLeft}px`,o.style.top=""),void 0!==n.arrowTop&&(o.style.top=`${n.arrowTop}px`,o.style.left=""))})}))}function d(){a&&(a=!1,window.removeEventListener("resize",c),i&&(cancelAnimationFrame(i),i=null))}async function m(e,t){const o=n.findIndex(t=>t.id===e);if(-1===o)return;const r=n[o];r.element.classList.add("is-closing"),r.element.remove(),r.scrollParents.forEach(e=>e.removeEventListener("scroll",c)),n.splice(o,1),0===n.length&&d(),null==t||t()}function u(){if(0===n.length)return;const e=new Set;n.forEach(t=>{t.scrollParents.forEach(t=>e.add(t)),t.element.classList.add("is-closing"),t.element.remove()}),e.forEach(e=>e.removeEventListener("scroll",c)),n.length=0,d()}function f(r,i){var d;const m=e.generateId();e.injectStyle("solely-tooltip-styles",t.default);const f=i.placement??o.placement,p=n.findIndex(e=>e.target===r);if(-1!==p){const e=n[p];e.element.remove(),e.scrollParents.forEach(e=>e.removeEventListener("scroll",c)),n.splice(p,1)}o.singleton&&n.length>0&&u();const h=e.createElement("div",{className:`tooltip tooltip--${f}${i.className?` ${i.className}`:""}`,styles:{...i.style,...i.color?{backgroundColor:i.color}:{}}});var v;v=h,(()=>{const e=document.documentElement.getAttribute("data-theme");e?v.setAttribute("data-theme",e):v.removeAttribute("data-theme")})(),l||(l=new MutationObserver(()=>{const e=document.documentElement.getAttribute("data-theme");n.forEach(t=>{e?t.element.setAttribute("data-theme",e):t.element.removeAttribute("data-theme")})}),l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}));const g=e.createElement("div",{className:"tooltip__content"});i.content&&("string"==typeof i.content?g.textContent=i.content:i.content instanceof HTMLElement&&g.appendChild(i.content.cloneNode(!0))),h.appendChild(g);const b=e.createElement("div",{className:"tooltip__arrow"});i.color&&(b.style.backgroundColor=i.color),h.appendChild(b),document.body.appendChild(h),requestAnimationFrame(()=>{const e=s(r,h,f);h.style.top=`${e.top}px`,h.style.left=`${e.left}px`,void 0!==e.arrowLeft&&(b.style.left=`${e.arrowLeft}px`),void 0!==e.arrowTop&&(b.style.top=`${e.arrowTop}px`)});const E=function(e){const t=[];let o=e.parentElement;for(;o&&o!==document.body;){const e=getComputedStyle(o);"auto"!==e.overflow&&"scroll"!==e.overflow&&"auto"!==e.overflowY&&"scroll"!==e.overflowY||t.push(o),o=o.parentElement}return t}(r);return E.forEach(e=>e.addEventListener("scroll",c)),a||0===n.length||(a=!0,window.addEventListener("resize",c)),n.push({id:m,element:h,target:r,placement:f,scrollParents:E}),null==(d=i.onVisibleChange)||d.call(i,!0),m}const p={bind:function(e,t){if(r.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};r.add(e);const n=t.trigger??o.trigger;let l=t.visible??t.defaultVisible??!1,s=null;const i=()=>{l||(l=!0,s=f(e,t))},a=()=>{if(!l||null===s)return;l=!1;const e=s;s=null,m(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},c=e=>{e.stopPropagation(),l?a():i()},d=t=>{l&&(e.contains(t.target)||a())};return"hover"===n?(e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",a)):"click"===n?(e.addEventListener("click",c),document.addEventListener("click",d)):"focus"===n&&(e.addEventListener("focus",i),e.addEventListener("blur",a)),l&&(s=f(e,t)),{show:i,hide:a,destroy:()=>{a(),r.delete(e),"hover"===n?(e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",a)):"click"===n?(e.removeEventListener("click",c),document.removeEventListener("click",d)):"focus"===n&&(e.removeEventListener("focus",i),e.removeEventListener("blur",a))}}},show:function(e,t){const n=f(e,t),r=t.duration??o.duration;r>0&&setTimeout(()=>m(n),r)},hide:async function(e){u(),null==e||e()},config:function(e){Object.assign(o,e)}};exports.Tooltip=p;
@@ -1 +1 @@
1
- import{addClosingAnimation as e,ANIMATION_DURATION as t,generateId as n,createElement as o,calculatePosition as l,injectStyle as s}from"../utils.js";import r from"./style.css.js";const i={placement:"top",trigger:"hover",duration:3e3},a=[],c=new WeakSet;let d=null;async function u(n,o){const l=a.findIndex(e=>e.id===n);if(-1===l)return;const s=a[l],r=s.element.querySelector(".tooltip");r&&r.classList.add("is-closing"),await e(s.element,t.FAST),s.element.remove(),a.splice(l,1),null==o||o()}function m(e,t){var c;const m=n();s("solely-tooltip-styles",r);const p=t.placement??i.placement,v=o("div",{className:"tooltip-overlay"}),h=(f=v,(()=>{const e=document.documentElement.getAttribute("data-theme");e?f.setAttribute("data-theme",e):f.removeAttribute("data-theme")})(),d||(d=new MutationObserver(()=>{a.forEach(e=>{const t=document.documentElement.getAttribute("data-theme");t?e.element.setAttribute("data-theme",t):e.element.removeAttribute("data-theme")})}),d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]})),()=>{d&&0===a.length&&(d.disconnect(),d=null)});var f;const g=o("div",{className:`tooltip tooltip--${p}${t.className?` ${t.className}`:""}`,styles:{...t.style,...t.color?{backgroundColor:t.color}:{}}}),b=o("div",{className:"tooltip__content"});t.content&&("string"==typeof t.content?b.textContent=t.content:t.content instanceof HTMLElement&&b.appendChild(t.content.cloneNode(!0))),g.appendChild(b);const y=o("div",{className:"tooltip__arrow"});t.color&&(y.style.backgroundColor=t.color),g.appendChild(y),v.appendChild(g),document.body.appendChild(v);const E=l(e,g,p);return g.style.top=`${E.top}px`,g.style.left=`${E.left}px`,void 0!==E.arrowLeft&&(y.style.left=`${E.arrowLeft}px`),void 0!==E.arrowTop&&(y.style.top=`${E.arrowTop}px`),a.push({id:m,element:v,target:e,destroy:()=>{h(),u(m)}}),null==(c=t.onVisibleChange)||c.call(t,!0),m}const p={bind:function(e,t){if(c.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};c.add(e);const n=t.trigger??i.trigger;let o=t.visible??t.defaultVisible??!1,l=null;const s=()=>{o||(o=!0,l=m(e,t))},r=()=>{if(!o||null===l)return;o=!1;const e=l;l=null,u(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},a=e=>{e.stopPropagation(),o?r():s()},d=t=>{o&&(e.contains(t.target)||r())};return"hover"===n?(e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",r)):"click"===n?(e.addEventListener("click",a),document.addEventListener("click",d)):"focus"===n&&(e.addEventListener("focus",s),e.addEventListener("blur",r)),o&&(l=m(e,t)),{show:s,hide:r,destroy:()=>{r(),c.delete(e),"hover"===n?(e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",r)):"click"===n?(e.removeEventListener("click",a),document.removeEventListener("click",d)):"focus"===n&&(e.removeEventListener("focus",s),e.removeEventListener("blur",r))}}},show:function(e,t){const n=m(e,t),o=t.duration??i.duration;o>0&&setTimeout(()=>{u(n)},o)},hide:async function(n){0!==a.length?(await Promise.all(a.map(async n=>{const o=n.element.querySelector(".tooltip");o&&o.classList.add("is-closing"),await e(n.element,t.FAST),n.element.remove()})),a.length=0,null==n||n()):null==n||n()},config:function(e){Object.assign(i,e)}};export{p as Tooltip};
1
+ import{generateId as e,createElement as t,injectStyle as o}from"../utils.js";import n from"./style.css.js";const r={placement:"top",trigger:"hover",duration:3e3,singleton:!0},l=[],s=new WeakSet;let i=null;function a(e,t,o,n=8){const r=e.getBoundingClientRect(),l=t.offsetWidth||250,s=t.offsetHeight||100;let i,a,c=0,d=0;switch(o){case"top":c=r.top-s-n,d=r.left+(r.width-l)/2,i=l/2-4;break;case"topLeft":c=r.top-s-n,d=r.left,i=16;break;case"topRight":c=r.top-s-n,d=r.right-l,i=l-24;break;case"bottom":c=r.bottom+n,d=r.left+(r.width-l)/2,i=l/2-4;break;case"bottomLeft":c=r.bottom+n,d=r.left,i=16;break;case"bottomRight":c=r.bottom+n,d=r.right-l,i=l-24;break;case"left":c=r.top+(r.height-s)/2,d=r.left-l-n,a=s/2-4;break;case"leftTop":c=r.top,d=r.left-l-n,a=16;break;case"leftBottom":c=r.bottom-s,d=r.left-l-n,a=s-24;break;case"right":c=r.top+(r.height-s)/2,d=r.right+n,a=s/2-4;break;case"rightTop":c=r.top,d=r.right+n,a=16;break;case"rightBottom":c=r.bottom-s,d=r.right+n,a=s-24}return c=Math.max(8,Math.min(c,window.innerHeight-s-8)),d=Math.max(8,Math.min(d,window.innerWidth-l-8)),{top:c,left:d,arrowLeft:i,arrowTop:a}}let c=null,d=!1;function m(){c||(c=requestAnimationFrame(()=>{c=null,l.forEach(e=>{const t=e.element;if(!t||!e.target)return;const o=t.querySelector(".tooltip__arrow"),n=a(e.target,t,e.placement);t.style.top=`${n.top}px`,t.style.left=`${n.left}px`,o&&(void 0!==n.arrowLeft&&(o.style.left=`${n.arrowLeft}px`,o.style.top=""),void 0!==n.arrowTop&&(o.style.top=`${n.arrowTop}px`,o.style.left=""))})}))}function u(){d&&(d=!1,window.removeEventListener("resize",m),c&&(cancelAnimationFrame(c),c=null))}async function f(e,t){const o=l.findIndex(t=>t.id===e);if(-1===o)return;const n=l[o];n.element.classList.add("is-closing"),n.element.remove(),n.scrollParents.forEach(e=>e.removeEventListener("scroll",m)),l.splice(o,1),0===l.length&&u(),null==t||t()}function p(){if(0===l.length)return;const e=new Set;l.forEach(t=>{t.scrollParents.forEach(t=>e.add(t)),t.element.classList.add("is-closing"),t.element.remove()}),e.forEach(e=>e.removeEventListener("scroll",m)),l.length=0,u()}function h(s,c){var u;const f=e();o("solely-tooltip-styles",n);const h=c.placement??r.placement,v=l.findIndex(e=>e.target===s);if(-1!==v){const e=l[v];e.element.remove(),e.scrollParents.forEach(e=>e.removeEventListener("scroll",m)),l.splice(v,1)}r.singleton&&l.length>0&&p();const g=t("div",{className:`tooltip tooltip--${h}${c.className?` ${c.className}`:""}`,styles:{...c.style,...c.color?{backgroundColor:c.color}:{}}});var b;b=g,(()=>{const e=document.documentElement.getAttribute("data-theme");e?b.setAttribute("data-theme",e):b.removeAttribute("data-theme")})(),i||(i=new MutationObserver(()=>{const e=document.documentElement.getAttribute("data-theme");l.forEach(t=>{e?t.element.setAttribute("data-theme",e):t.element.removeAttribute("data-theme")})}),i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}));const w=t("div",{className:"tooltip__content"});c.content&&("string"==typeof c.content?w.textContent=c.content:c.content instanceof HTMLElement&&w.appendChild(c.content.cloneNode(!0))),g.appendChild(w);const E=t("div",{className:"tooltip__arrow"});c.color&&(E.style.backgroundColor=c.color),g.appendChild(E),document.body.appendChild(g),requestAnimationFrame(()=>{const e=a(s,g,h);g.style.top=`${e.top}px`,g.style.left=`${e.left}px`,void 0!==e.arrowLeft&&(E.style.left=`${e.arrowLeft}px`),void 0!==e.arrowTop&&(E.style.top=`${e.arrowTop}px`)});const L=function(e){const t=[];let o=e.parentElement;for(;o&&o!==document.body;){const e=getComputedStyle(o);"auto"!==e.overflow&&"scroll"!==e.overflow&&"auto"!==e.overflowY&&"scroll"!==e.overflowY||t.push(o),o=o.parentElement}return t}(s);return L.forEach(e=>e.addEventListener("scroll",m)),d||0===l.length||(d=!0,window.addEventListener("resize",m)),l.push({id:f,element:g,target:s,placement:h,scrollParents:L}),null==(u=c.onVisibleChange)||u.call(c,!0),f}const v={bind:function(e,t){if(s.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};s.add(e);const o=t.trigger??r.trigger;let n=t.visible??t.defaultVisible??!1,l=null;const i=()=>{n||(n=!0,l=h(e,t))},a=()=>{if(!n||null===l)return;n=!1;const e=l;l=null,f(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},c=e=>{e.stopPropagation(),n?a():i()},d=t=>{n&&(e.contains(t.target)||a())};return"hover"===o?(e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",a)):"click"===o?(e.addEventListener("click",c),document.addEventListener("click",d)):"focus"===o&&(e.addEventListener("focus",i),e.addEventListener("blur",a)),n&&(l=h(e,t)),{show:i,hide:a,destroy:()=>{a(),s.delete(e),"hover"===o?(e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",a)):"click"===o?(e.removeEventListener("click",c),document.removeEventListener("click",d)):"focus"===o&&(e.removeEventListener("focus",i),e.removeEventListener("blur",a))}}},show:function(e,t){const o=h(e,t),n=t.duration??r.duration;n>0&&setTimeout(()=>f(o),n)},hide:async function(e){p(),null==e||e()},config:function(e){Object.assign(r,e)}};export{v as Tooltip};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),exports.default="*,*:before,*:after{box-sizing:border-box}.tooltip-overlay{position:absolute;top:0;left:0;width:100%;min-height:100%;z-index:var(--solely-z-index-tooltip);pointer-events:none}.tooltip{position:absolute;background-color:var(--solely-inverted-bg);border-radius:var(--solely-border-radius-md);box-shadow:var(--solely-shadow-md);padding:var(--solely-spacing-sm) var(--solely-spacing-md);min-width:30px;max-width:250px;font-family:var(--solely-font-family);font-size:var(--solely-font-size-md);font-weight:400;line-height:var(--solely-line-height-md);color:var(--solely-inverted-text);text-align:left;text-decoration:none;word-wrap:break-word;z-index:var(--solely-z-index-tooltip);animation:tooltip-fade-in var(--solely-transition-duration) var(--solely-transition-timing)}.tooltip.is-closing{animation:tooltip-fade-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.tooltip__content{position:relative;z-index:1}.tooltip__arrow{position:absolute;width:var(--solely-tooltip-arrow-size, 8px);height:var(--solely-tooltip-arrow-size, 8px);background-color:var(--solely-inverted-bg);transform:rotate(45deg);z-index:0}.tooltip--top .tooltip__arrow,.tooltip--topLeft .tooltip__arrow,.tooltip--topRight .tooltip__arrow{bottom:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--bottom .tooltip__arrow,.tooltip--bottomLeft .tooltip__arrow,.tooltip--bottomRight .tooltip__arrow{top:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--left .tooltip__arrow,.tooltip--leftTop .tooltip__arrow,.tooltip--leftBottom .tooltip__arrow{right:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--right .tooltip__arrow,.tooltip--rightTop .tooltip__arrow,.tooltip--rightBottom .tooltip__arrow{left:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}@keyframes tooltip-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes tooltip-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}";
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),exports.default=".tooltip{position:fixed;background-color:var(--solely-inverted-bg);border-radius:var(--solely-border-radius-md);box-shadow:var(--solely-shadow-md);padding:var(--solely-spacing-sm) var(--solely-spacing-md);width:max-content;max-width:250px;font-family:var(--solely-font-family);font-size:var(--solely-font-size-md);font-weight:400;line-height:var(--solely-line-height-md);color:var(--solely-inverted-text);text-align:left;text-decoration:none;z-index:var(--solely-z-index-tooltip);pointer-events:auto;animation:tooltip-fade-in var(--solely-transition-duration) var(--solely-transition-timing)}.tooltip.is-closing{animation:tooltip-fade-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.tooltip__content{position:relative;z-index:1;word-wrap:break-word;overflow-wrap:break-word}.tooltip__arrow{position:absolute;width:var(--solely-tooltip-arrow-size, 8px);height:var(--solely-tooltip-arrow-size, 8px);background-color:var(--solely-inverted-bg);transform:rotate(45deg);z-index:0}.tooltip--top .tooltip__arrow,.tooltip--topLeft .tooltip__arrow,.tooltip--topRight .tooltip__arrow{bottom:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--bottom .tooltip__arrow,.tooltip--bottomLeft .tooltip__arrow,.tooltip--bottomRight .tooltip__arrow{top:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--left .tooltip__arrow,.tooltip--leftTop .tooltip__arrow,.tooltip--leftBottom .tooltip__arrow{right:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--right .tooltip__arrow,.tooltip--rightTop .tooltip__arrow,.tooltip--rightBottom .tooltip__arrow{left:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}@keyframes tooltip-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes tooltip-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}";
@@ -1 +1 @@
1
- const o="*,*:before,*:after{box-sizing:border-box}.tooltip-overlay{position:absolute;top:0;left:0;width:100%;min-height:100%;z-index:var(--solely-z-index-tooltip);pointer-events:none}.tooltip{position:absolute;background-color:var(--solely-inverted-bg);border-radius:var(--solely-border-radius-md);box-shadow:var(--solely-shadow-md);padding:var(--solely-spacing-sm) var(--solely-spacing-md);min-width:30px;max-width:250px;font-family:var(--solely-font-family);font-size:var(--solely-font-size-md);font-weight:400;line-height:var(--solely-line-height-md);color:var(--solely-inverted-text);text-align:left;text-decoration:none;word-wrap:break-word;z-index:var(--solely-z-index-tooltip);animation:tooltip-fade-in var(--solely-transition-duration) var(--solely-transition-timing)}.tooltip.is-closing{animation:tooltip-fade-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.tooltip__content{position:relative;z-index:1}.tooltip__arrow{position:absolute;width:var(--solely-tooltip-arrow-size, 8px);height:var(--solely-tooltip-arrow-size, 8px);background-color:var(--solely-inverted-bg);transform:rotate(45deg);z-index:0}.tooltip--top .tooltip__arrow,.tooltip--topLeft .tooltip__arrow,.tooltip--topRight .tooltip__arrow{bottom:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--bottom .tooltip__arrow,.tooltip--bottomLeft .tooltip__arrow,.tooltip--bottomRight .tooltip__arrow{top:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--left .tooltip__arrow,.tooltip--leftTop .tooltip__arrow,.tooltip--leftBottom .tooltip__arrow{right:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--right .tooltip__arrow,.tooltip--rightTop .tooltip__arrow,.tooltip--rightBottom .tooltip__arrow{left:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}@keyframes tooltip-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes tooltip-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}";export{o as default};
1
+ const o=".tooltip{position:fixed;background-color:var(--solely-inverted-bg);border-radius:var(--solely-border-radius-md);box-shadow:var(--solely-shadow-md);padding:var(--solely-spacing-sm) var(--solely-spacing-md);width:max-content;max-width:250px;font-family:var(--solely-font-family);font-size:var(--solely-font-size-md);font-weight:400;line-height:var(--solely-line-height-md);color:var(--solely-inverted-text);text-align:left;text-decoration:none;z-index:var(--solely-z-index-tooltip);pointer-events:auto;animation:tooltip-fade-in var(--solely-transition-duration) var(--solely-transition-timing)}.tooltip.is-closing{animation:tooltip-fade-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.tooltip__content{position:relative;z-index:1;word-wrap:break-word;overflow-wrap:break-word}.tooltip__arrow{position:absolute;width:var(--solely-tooltip-arrow-size, 8px);height:var(--solely-tooltip-arrow-size, 8px);background-color:var(--solely-inverted-bg);transform:rotate(45deg);z-index:0}.tooltip--top .tooltip__arrow,.tooltip--topLeft .tooltip__arrow,.tooltip--topRight .tooltip__arrow{bottom:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--bottom .tooltip__arrow,.tooltip--bottomLeft .tooltip__arrow,.tooltip--bottomRight .tooltip__arrow{top:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--left .tooltip__arrow,.tooltip--leftTop .tooltip__arrow,.tooltip--leftBottom .tooltip__arrow{right:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}.tooltip--right .tooltip__arrow,.tooltip--rightTop .tooltip__arrow,.tooltip--rightBottom .tooltip__arrow{left:calc(var(--solely-tooltip-arrow-size, 8px) / -2)}@keyframes tooltip-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes tooltip-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}";export{o as default};
@@ -40,4 +40,6 @@ export interface TooltipConfig {
40
40
  trigger: TooltipTrigger;
41
41
  /** 默认显示时长(show 方法使用) */
42
42
  duration: number;
43
+ /** 是否单例模式(新 tooltip 显示时自动关闭其他) */
44
+ singleton?: boolean;
43
45
  }
@@ -0,0 +1,59 @@
1
+ import { BaseElement } from '../../../runtime/component';
2
+ import { TooltipProps } from './types';
3
+ declare class SolelyTooltip extends BaseElement<TooltipProps> {
4
+ private _clickOutsideHandler?;
5
+ /**
6
+ * 获取 tooltip class 对象
7
+ */
8
+ getTooltipClasses(): Record<string, boolean>;
9
+ /**
10
+ * 显示 tooltip
11
+ */
12
+ show(): void;
13
+ /**
14
+ * 隐藏 tooltip
15
+ */
16
+ hide(): void;
17
+ /**
18
+ * 鼠标移入处理
19
+ */
20
+ handleMouseEnter(event: Event): void;
21
+ /**
22
+ * 鼠标移出处理
23
+ */
24
+ handleMouseLeave(event: Event): void;
25
+ /**
26
+ * 聚焦处理
27
+ */
28
+ handleFocus(event: Event): void;
29
+ /**
30
+ * 失焦处理
31
+ */
32
+ handleBlur(event: Event): void;
33
+ /**
34
+ * 绑定事件到 slot 内容元素
35
+ */
36
+ private bindSlotEvents;
37
+ /**
38
+ * 点击处理
39
+ */
40
+ handleClick(event: Event): void;
41
+ /**
42
+ * 绑定点击外部关闭
43
+ */
44
+ private bindClickOutside;
45
+ /**
46
+ * 解绑点击外部关闭
47
+ */
48
+ private unbindClickOutside;
49
+ /**
50
+ * 组件挂载后初始化
51
+ */
52
+ mounted(): void;
53
+ /**
54
+ * 组件销毁时清理
55
+ */
56
+ unmounted(): void;
57
+ }
58
+ export default SolelyTooltip;
59
+ export { SolelyTooltip };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Tooltip 组件类型定义
3
+ */
4
+ export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
5
+ export type TooltipTrigger = 'hover' | 'click' | 'focus';
6
+ export interface TooltipProps {
7
+ /** 提示内容 */
8
+ content: string;
9
+ /** 气泡框位置 */
10
+ placement: TooltipPlacement;
11
+ /** 触发方式 */
12
+ trigger: TooltipTrigger;
13
+ /** 是否显示 */
14
+ visible: boolean;
15
+ /** 背景颜色 */
16
+ color: string;
17
+ /** 最大宽度 */
18
+ maxWidth: number;
19
+ }
20
+ export interface TooltipRefs extends Record<string, Element> {
21
+ tooltipRef: HTMLElement;
22
+ arrowRef: HTMLElement;
23
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.4.10",
4
+ "version": "0.4.11",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
7
  "sideEffects": false,