@tiennm99/aboutme 0.0.0-stage → 1.0.1

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,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @tiennm99/aboutme
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A floating bubble that shows links about a site's author. Drag it onto the target at
4
+ the bottom of the screen, or press "Hide", and it stays hidden for a period you choose.
5
+
6
+ ```html
7
+ <script
8
+ src="https://cdn.jsdelivr.net/npm/@tiennm99/aboutme@1"
9
+ data-profile="https://<your-worker>.workers.dev/profile.json"
10
+ data-hide="7d"
11
+ defer
12
+ ></script>
13
+ ```
14
+
15
+ The profile format is in [`profile.schema.json`](profile.schema.json). Options, the
16
+ profile Worker and anonymous counts: [github.com/tiennm99/aboutme](https://github.com/tiennm99/aboutme).
17
+
18
+ MIT licensed.
@@ -0,0 +1,50 @@
1
+ (()=>{var P="aboutme:hiddenUntil";var q=["home","blog","github","facebook","linkedin","x","youtube","email","link"],Q={m:6e4,h:36e5,d:864e5,w:6048e5},ee={m:"minute",h:"hour",d:"day",w:"week"},F=/^(\d{1,4})\s*([mhdw])$/i,te=/^[a-z0-9-]{1,32}$/;function H(t){let n=F.exec(String(t??"").trim());return!n||Number(n[1])===0?H("7d"):Number(n[1])*Q[n[2].toLowerCase()]}function N(t){let n=F.exec(String(t??"").trim());if(!n||Number(n[1])===0)return N("7d");let i=Number(n[1]),a=ee[n[2].toLowerCase()];return`${i} ${a}${i===1?"":"s"}`}function W(t,n){try{let i=Number(t?.getItem(P));return Number.isFinite(i)&&i>n}catch{return!1}}function X(t,n,i){try{t?.setItem(P,String(n+i))}catch{}}function I(t,n){if(typeof t!="string")return null;try{let i=new URL(t);return n.includes(i.protocol)?i.href:null}catch{return null}}function D(t,n){return typeof t=="string"?t.trim().slice(0,n):""}function j(t,n){if(!t||typeof t!="object"||t.schemaVersion!==1)return null;let i=D(t.name,60);if(!i)return null;let a=[],f=new Set;for(let s of Array.isArray(t.links)?t.links.slice(0,12):[]){let p=typeof s?.id=="string"&&te.test(s.id)?s.id:null,y=D(s?.label,40),o=I(s?.url,["https:","http:","mailto:"]);!p||!y||!o||f.has(p)||(f.add(p),a.push({id:p,label:y,url:o,icon:q.includes(s.icon)?s.icon:"link"}))}if(a.length===0)return null;let u=null;if(typeof t.events=="string")try{u=I(new URL(t.events,n).href,["https:","http:"])}catch{u=null}return{name:i,tagline:D(t.tagline,120),avatar:I(t.avatar,["https:"]),links:a,events:u}}var m=52,l=16,ne=6,oe=72,B={person:'<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-7 8-7s8 3 8 7"/>',close:'<path d="M6 6l12 12M18 6L6 18"/>',home:'<path d="M3 11l9-7 9 7v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"/>',blog:'<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M14 6l4 4"/>',github:'<path d="M8 8l-4 4 4 4M16 8l4 4-4 4"/>',facebook:'<circle cx="9" cy="8" r="3"/><path d="M3 20c0-3 3-5 6-5s6 2 6 5"/><circle cx="17" cy="9" r="2.5"/><path d="M15 15c3 0 6 1.5 6 4.5"/>',linkedin:'<rect x="3" y="7" width="18" height="13" rx="2"/><path d="M9 7V5h6v2"/>',x:'<path d="M4 5h16v11H9l-5 4z"/>',youtube:'<rect x="3" y="6" width="18" height="12" rx="3"/><path d="M10 9l5 3-5 3z"/>',email:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/>',link:'<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>'},ie=`
2
+ :host { all: initial; }
3
+ * { box-sizing: border-box; }
4
+ .root {
5
+ --bg: #ffffff; --fg: #1f2328; --muted: #59636e; --line: #d1d9e0; --hover: #f2f4f6;
6
+ --accent: #2563eb; --accent-fg: #ffffff; --danger: #dc2626;
7
+ font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
8
+ color: var(--fg);
9
+ }
10
+ @media (prefers-color-scheme: dark) {
11
+ .root { --bg: #1c2128; --fg: #e6edf3; --muted: #9198a1; --line: #3d444d; --hover: #262c36; --accent: #4493f8; }
12
+ }
13
+ svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
14
+ .bubble {
15
+ position: fixed; left: 0; top: 0; width: ${m}px; height: ${m}px; z-index: 2147483001;
16
+ border: 0; border-radius: 50%; padding: 0; cursor: grab; touch-action: none; user-select: none;
17
+ background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; overflow: hidden;
18
+ box-shadow: 0 4px 14px rgb(0 0 0 / 25%); transition: transform .2s ease;
19
+ }
20
+ .bubble svg { width: 26px; height: 26px; }
21
+ .bubble img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
22
+ .bubble:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
23
+ .bubble.dragging { cursor: grabbing; transition: none; }
24
+ .panel {
25
+ position: fixed; z-index: 2147483000; width: min(280px, calc(100vw - ${l*2}px));
26
+ background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
27
+ box-shadow: 0 8px 30px rgb(0 0 0 / 20%);
28
+ }
29
+ .panel[hidden] { display: none; }
30
+ .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
31
+ .head img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
32
+ .who { flex: 1; min-width: 0; }
33
+ .name { font-weight: 600; }
34
+ .tagline { color: var(--muted); font-size: 13px; }
35
+ .icon-btn { border: 0; background: none; color: var(--muted); padding: 4px; border-radius: 6px; cursor: pointer; display: grid; }
36
+ .icon-btn:hover { background: var(--hover); color: var(--fg); }
37
+ ul { list-style: none; margin: 0; padding: 0; }
38
+ a { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; color: var(--fg); text-decoration: none; }
39
+ a:hover { background: var(--hover); }
40
+ .hide { width: 100%; margin-top: 8px; padding: 6px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
41
+ .hide:hover { color: var(--fg); }
42
+ .target {
43
+ position: fixed; left: 50%; bottom: 32px; width: 64px; height: 64px; margin-left: -32px; z-index: 2147483000;
44
+ border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgb(0 0 0 / 55%);
45
+ border: 2px solid rgb(255 255 255 / 70%); transition: transform .15s ease, background .15s ease; pointer-events: none;
46
+ }
47
+ .target[hidden] { display: none; }
48
+ .target.active { transform: scale(1.25); background: var(--danger); }
49
+ @media (prefers-reduced-motion: reduce) { .bubble, .target { transition: none; } }
50
+ `;function k(t){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("aria-hidden","true"),n.innerHTML=B[t]??B.link,n}function r(t,n,i){let a=document.createElement(t);return n&&(a.className=n),i&&(a.textContent=i),a}function G({profile:t,position:n,hide:i,track:a,onDismiss:f}){let u=document.createElement("aboutme-widget"),s=u.attachShadow({mode:"open"}),p=r("div","root"),y=r("style");y.textContent=ie;let o=r("button","bubble");if(o.type="button",o.setAttribute("aria-label",`About ${t.name}`),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-controls","aboutme-panel"),o.title="Drag to the bottom to hide",t.avatar){let e=r("img");e.alt="",e.src=t.avatar,e.addEventListener("error",()=>e.replaceWith(k("person")),{once:!0}),o.append(e)}else o.append(k("person"));let d=r("div","panel");d.id="aboutme-panel",d.setAttribute("role","dialog"),d.setAttribute("aria-label",`About ${t.name}`),d.hidden=!0;let A=r("div","head");if(t.avatar){let e=r("img");e.alt="",e.src=t.avatar,A.append(e)}let S=r("div","who");S.append(r("div","name",t.name)),t.tagline&&S.append(r("div","tagline",t.tagline));let L=r("button","icon-btn");L.type="button",L.setAttribute("aria-label","Close"),L.append(k("close")),A.append(S,L);let R=r("ul");for(let e of t.links){let b=r("li"),h=r("a");h.href=e.url,h.target="_blank",h.rel="noopener noreferrer",h.append(k(e.icon),r("span","",e.label)),h.addEventListener("click",()=>a("click",e.id)),b.append(h),R.append(b)}let _=r("button","hide",`Hide for ${N(i)}`);_.type="button",d.append(A,R,_);let x=r("div","target");x.hidden=!0,x.append(k("close")),p.append(y,d,x,o),s.append(p),document.body.append(u);let v=0,g=0,E=n;function T(){o.style.transform=`translate(${v}px, ${g}px)`}function M(){let e=window.innerHeight-m-l;E=v+m/2<window.innerWidth/2?"left":"right",v=E==="left"?l:window.innerWidth-m-l,g=Math.min(Math.max(g,l),Math.max(e,l)),T()}function J(){let e=d.offsetWidth,b=d.offsetHeight,h=E==="left"?l:window.innerWidth-e-l,Y=g-b-8,Z=Y>=l?Y:Math.min(g+m+8,window.innerHeight-b-l);d.style.left=`${Math.max(h,l)}px`,d.style.top=`${Math.max(Z,l)}px`}function w(e){e!==!d.hidden&&(d.hidden=!e,o.setAttribute("aria-expanded",String(e)),e&&(J(),a("open")))}function U(){a("dismiss"),u.remove(),window.removeEventListener("resize",M),document.removeEventListener("pointerdown",$,!0),document.removeEventListener("keydown",C),f()}function $(e){e.composedPath().includes(u)||w(!1)}function C(e){e.key==="Escape"&&!d.hidden&&(w(!1),o.focus())}function z(){let e=x.getBoundingClientRect(),b=v+m/2-(e.left+e.width/2),h=g+m/2-(e.top+e.height/2);return Math.hypot(b,h)<oe}let c=null;o.addEventListener("pointerdown",e=>{e.button===0&&(c={id:e.pointerId,startX:e.clientX,startY:e.clientY,dx:e.clientX-v,dy:e.clientY-g,moved:!1},o.setPointerCapture(e.pointerId))}),o.addEventListener("pointermove",e=>{!c||e.pointerId!==c.id||!c.moved&&Math.hypot(e.clientX-c.startX,e.clientY-c.startY)<ne||(c.moved||(c.moved=!0,o.classList.add("dragging"),x.hidden=!1,w(!1)),v=e.clientX-c.dx,g=e.clientY-c.dy,T(),x.classList.toggle("active",z()))});function O(e){if(!c||e.pointerId!==c.id)return;let{moved:b}=c;if(c=null,!b){e.type==="pointerup"&&w(d.hidden);return}o.classList.remove("dragging");let h=e.type==="pointerup"&&z();x.hidden=!0,x.classList.remove("active"),h?U():M()}return o.addEventListener("pointerup",O),o.addEventListener("pointercancel",O),o.addEventListener("click",e=>{e.detail===0&&w(d.hidden)}),L.addEventListener("click",()=>{w(!1),o.focus()}),_.addEventListener("click",U),window.addEventListener("resize",M),document.addEventListener("pointerdown",$,!0),document.addEventListener("keydown",C),o.classList.add("dragging"),v=E==="left"?0:window.innerWidth,g=window.innerHeight-m-l*2,M(),o.getBoundingClientRect(),o.classList.remove("dragging"),u}function V(){try{return window.localStorage}catch{return null}}function re(t,n,i){if(t)try{fetch(t,{method:"POST",mode:"cors",credentials:"omit",keepalive:!0,headers:{"content-type":"text/plain"},body:JSON.stringify(i?{event:n,target:i}:{event:n})}).catch(()=>{})}catch{}}async function ae(t){let n=t.dataset.profile,i=t.dataset.hide,a=t.dataset.position==="left"?"left":"right";if(!n||W(V(),Date.now()))return;let f;try{let s=new URL(n,document.baseURI).href,p=await fetch(s,{credentials:"omit"});if(!p.ok)return;f=j(await p.json(),s)}catch{return}if(!f)return;let u=()=>G({profile:f,position:a,hide:i??"",track:(s,p)=>re(f.events,s,p),onDismiss:()=>X(V(),Date.now(),H(i))});document.body?u():document.addEventListener("DOMContentLoaded",u,{once:!0})}var K=document.currentScript;K instanceof HTMLScriptElement&&!window.__aboutmeLoaded&&(window.__aboutmeLoaded=!0,ae(K));})();
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@tiennm99/aboutme",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "A draggable floating bubble that shows links about the site's author, loaded from a profile JSON.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "tiennm99",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/tiennm99/aboutme.git",
11
+ "directory": "widget"
12
+ },
13
+ "homepage": "https://github.com/tiennm99/aboutme#readme",
14
+ "keywords": [
15
+ "about-me",
16
+ "widget",
17
+ "floating-button",
18
+ "profile",
19
+ "links"
20
+ ],
21
+ "main": "dist/aboutme.js",
22
+ "jsdelivr": "dist/aboutme.js",
23
+ "unpkg": "dist/aboutme.js",
24
+ "files": [
25
+ "dist",
26
+ "profile.schema.json"
27
+ ],
28
+ "exports": {
29
+ ".": "./dist/aboutme.js",
30
+ "./profile.schema.json": "./profile.schema.json"
31
+ },
32
+ "scripts": {
33
+ "build": "node build.js",
34
+ "test": "vitest run",
35
+ "test:e2e": "npm run build && playwright test",
36
+ "prepublishOnly": "npm run build && npm test"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "devDependencies": {
42
+ "@playwright/test": "^1.50.0",
43
+ "esbuild": "^0.28.0",
44
+ "vitest": "^5.0.0"
45
+ }
46
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/tiennm99/aboutme/blob/main/widget/profile.schema.json",
4
+ "title": "aboutme profile, schema version 1",
5
+ "description": "Data the widget shows. Unknown fields are ignored, so new optional fields do not need a new schema version.",
6
+ "type": "object",
7
+ "required": ["schemaVersion", "name", "links"],
8
+ "properties": {
9
+ "schemaVersion": { "const": 1 },
10
+ "name": { "type": "string", "minLength": 1, "maxLength": 60 },
11
+ "tagline": { "type": "string", "maxLength": 120 },
12
+ "avatar": { "type": "string", "format": "uri", "pattern": "^https://" },
13
+ "events": {
14
+ "type": "string",
15
+ "description": "Count endpoint, absolute or relative to the profile URL. Leave it out to send no counts."
16
+ },
17
+ "links": {
18
+ "type": "array",
19
+ "minItems": 1,
20
+ "maxItems": 12,
21
+ "items": {
22
+ "type": "object",
23
+ "required": ["id", "label", "url"],
24
+ "properties": {
25
+ "id": { "type": "string", "pattern": "^[a-z0-9-]{1,32}$" },
26
+ "label": { "type": "string", "minLength": 1, "maxLength": 40 },
27
+ "url": { "type": "string", "pattern": "^(https?:|mailto:)" },
28
+ "icon": {
29
+ "enum": ["home", "blog", "github", "facebook", "linkedin", "x", "youtube", "email", "link"]
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }