@littlefriend/feedback 0.1.1 → 0.1.2
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/dist/index.js +21 -4
- package/dist/lf-feedback.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -28,8 +28,11 @@ var LIMITS = {
|
|
|
28
28
|
var RETENTION_DAYS = {
|
|
29
29
|
events: { min: 1, max: 365, default: 7 },
|
|
30
30
|
aggregates: { min: 30, max: 395, default: 395 },
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Server log lines, a separate add-on with its own store. The default, null, keeps them for
|
|
33
|
+
* good: past LOG_LIMITS.hotDays they move to the archive and stay searchable.
|
|
34
|
+
*/
|
|
35
|
+
logs: { min: 1, max: 3650, default: null },
|
|
33
36
|
feedback: { min: 1, max: 365, default: 90 }
|
|
34
37
|
};
|
|
35
38
|
var SESSION_ID_RE = /^[A-Za-z0-9_-]{16,32}$/;
|
|
@@ -57,8 +60,22 @@ function looksLikePII(input) {
|
|
|
57
60
|
return true;
|
|
58
61
|
if ((HEXISH_RE.test(value) || UUID_RE.test(value)) && HEX_LETTER_RE.test(value))
|
|
59
62
|
return false;
|
|
60
|
-
return LONG_DIGITS_RE.test(value);
|
|
63
|
+
return LONG_DIGITS_RE.test(value) || announcesCredential(value);
|
|
61
64
|
}
|
|
65
|
+
var CREDENTIAL_RES = [
|
|
66
|
+
// Slack: xoxb-, xoxp-, xoxa-, xoxe-, xoxr-, xoxs- and a digit.
|
|
67
|
+
/(?:^|[^A-Za-z0-9])xox[abeprs]-\d/,
|
|
68
|
+
// GitHub tokens: ghp_, gho_, ghu_, ghs_, ghr_ and 36 letters and digits; fine-grained ones.
|
|
69
|
+
/(?:^|[^A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{36}/,
|
|
70
|
+
/(?:^|[^A-Za-z0-9])github_pat_[A-Za-z0-9_]{22,}/,
|
|
71
|
+
// AWS access key ids: AKIA or ASIA and 16 capitals and digits.
|
|
72
|
+
/(?:^|[^A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Za-z0-9])/,
|
|
73
|
+
// Stripe secret and restricted keys.
|
|
74
|
+
/(?:^|[^A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/,
|
|
75
|
+
// A JWT, or its header on its own: `{"alg"` always encodes to `eyJ`.
|
|
76
|
+
/(?:^|[^A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{16,}/
|
|
77
|
+
];
|
|
78
|
+
var announcesCredential = (value) => CREDENTIAL_RES.some((re) => re.test(value));
|
|
62
79
|
function sanitizeRoute(input) {
|
|
63
80
|
return cleanPath(input, false);
|
|
64
81
|
}
|
|
@@ -226,7 +243,7 @@ function routeOf(loc, templates) {
|
|
|
226
243
|
}
|
|
227
244
|
|
|
228
245
|
// src/version.ts
|
|
229
|
-
var VERSION = "0.1.
|
|
246
|
+
var VERSION = "0.1.2";
|
|
230
247
|
|
|
231
248
|
// src/styles.ts
|
|
232
249
|
var CSS = `:host{all:initial}
|
package/dist/lf-feedback.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=/^[A-Za-z0-9_-]{16,32}$/,t=new RegExp("[^\\s@/]{1,64}@[^\\s@/]{1,253}\\.\\p{L}{2,24}","iu"),n=/\d[\d\s().-]{7,}\d/,r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,a=/^[0-9a-f]{16,}$/i,i=/[a-f]/i,o=/^\d+$/,l=/^(?=.*\d)(?=.*[a-zA-Z])[A-Za-z0-9_-]{20,}$/,s=/^(?:eyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*){1,4}|(?=.*\d)(?=.*[A-Z])[A-Za-z0-9_-]{16,}(?:\.[A-Za-z0-9_-]{16,}){2})$/,d=/^:[a-z_][a-z0-9_]{0,31}$/,c=/[\u0000-\u001f\u007f]/g,u=/[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;function f(e){let o=e.length>2048?e.slice(0,2048):e;return!(!o.includes("@")||!t.test(o))||(!a.test(o)&&!r.test(o)||!i.test(o))&&n.test(o)}function p(e){return(e=>{if("string"!=typeof e||e.length>2048)return null;let t=e,n=t.search(/[?#]/);n>=0&&(t=t.slice(0,n)),t.startsWith("/")||(t=`/${t}`);let i=t;try{i=decodeURIComponent(t)}catch{}i=(e=>e.replace(c,"").replace(u,e=>2===e.length?e:""))(i);let p=i.search(/[?#]/);p>=0&&(i=i.slice(0,p));let m=i.split("/").map(e=>{if(e.includes("="))return":redacted";if(""===e)return e;if(e.startsWith(":")){let t=e.slice(1);return b.test(t)?e:g(t)?":id":f(t)?":redacted":e}if(d.test(e))return e;let t=e.startsWith(":")?e.slice(1):e;return o.test(t)||r.test(t)||a.test(t)||l.test(t)||s.test(t)?":id":f(t)?":redacted":e}).join("/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m.length>256?null:m})(e)}var b=/^[A-Za-z_][A-Za-z0-9_]*$/,g=e=>o.test(e)||r.test(e)||a.test(e)||s.test(e),m=["confusing","bug","idea","other"];function h(e){return"string"==typeof e&&m.includes(e)}var y={confusing:"Confusing",bug:"Something broke",idea:"Idea",other:"Other"},x=["bottom_right","bottom_left","right_edge","manual"];function v(e){return"string"==typeof e&&x.includes(e)}var k=2e3;function w(e,t){let n=e.pathname,r="file:"===e.protocol?n.slice(n.lastIndexOf("/")):n;for(let[e,n]of t)if(n.test(r))return p(e)??"/";return p(r)??"/"}function $(e){return"empty"===e?"Write a note first.":"rate_limited"===e||"quota_exceeded"===e?"Too many notes right now. Please try again in a minute.":"network"===e?"Your note was not sent. Check your connection and try again.":"feedback_off"===e?"Feedback is turned off for this site.":"Your note was not sent. Please try again."}function A(e){let t=e;if(!0!==t?.on)return null;let n="string"==typeof t.label?t.label.trim().slice(0,24):"",r="string"==typeof t.prompt?t.prompt.trim().slice(0,140):"",a=t.days;return{v:1,on:!0,label:n||"Feedback",placement:v(t.placement)?t.placement:"bottom_right",prompt:r||null,days:"number"==typeof a&&Number.isInteger(a)&&a>=1?a:90}}var _,S=Symbol.for("littlefriend.feedback"),E=document,z=E.currentScript,L=z?.hasAttribute("data-site")?z:E.querySelector("script[data-site][data-feedback]"),C=e=>L?.getAttribute(`data-${e}`)||void 0,j=C("site");try{_=JSON.parse(C("routes")||E.querySelector("script[data-site][data-routes]")?.getAttribute("data-routes")||"[]")}catch{}j&&((t,n)=>{let r=t,a=r[S];if(a)return a;let i=function(t,n){let r,a,i=t.document,o=(n.api||"https://in.littlefriend.io").replace(/\/+$/,""),l=(e=>Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.startsWith("/")).map(e=>[e,RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/:\w+/g,"[^/]+").replace(/\*/g,".*")}/?$`)]):[])(n.routes),s=!1,d=new Promise(e=>i.prerendering?i.addEventListener("prerenderingchange",()=>e(),{once:!0}):e()).then(()=>t.fetch(`${o}/v1/f/config?k=${encodeURIComponent(n.site)}`,{credentials:"omit"})).then(e=>e.ok?e.json():null).then(A,()=>null),c=()=>{let n=null,r=t.lf;if(r?.v)try{r("session",t=>{n="string"==typeof t&&e.test(t)?t:null})}catch{}return n},u=async e=>{let r=await d;if(s||!r)return{ok:!1,error:"feedback_off"};let a=e??{},i="string"==typeof a.text?a.text.trim():"";if(!i)return{ok:!1,error:"empty"};if(null!=a.category&&!h(a.category))return{ok:!1,error:"bad_category"};let u=c();return(async e=>{for(let n=0;;n++){e.s&&c()!==e.s&&(delete e.s,e.m="a");let r=JSON.stringify(e),a=0,i="network",l=1e3*2**n;try{let e=await t.fetch(`${o}/v1/f`,{method:"POST",body:r,credentials:"omit",keepalive:!0});if(a=e.status,a>=200&&a<300)return{ok:!0};let n=Number(e.headers.get("retry-after"));n>0&&(l=1e3*n);try{let t=await e.json();i="string"==typeof t?.error&&/^[a-z_]{1,40}$/.test(t.error)?t.error:"refused"}catch{i="refused"}if(429!==a&&a<500)return{ok:!1,error:i}}catch{}if(n>=3||l>1e4||s)return{ok:!1,error:i};await new Promise(e=>setTimeout(e,l))}})({v:1,k:n.site,i:[...crypto.getRandomValues(new Uint8Array(20))].map(e=>(31&e).toString(32)).join(""),t:[...i].slice(0,k).join(""),...h(a.category)?{c:a.category}:{},u:w(t.location,l),m:u?"j":"a",...u?{s:u}:{},sv:"feedback-0.1.1"})},f=e=>r||=(e=>{let{w:t,config:n}=e,r=t.document,a=r.createElement("div");a.setAttribute("data-lf-block",""),a.setAttribute("data-lf-feedback","");let i=a.attachShadow({mode:"open"});i.innerHTML='<style>:host{all:initial}\n*{box-sizing:border-box;font:14px/1.45 system-ui,sans-serif;color:inherit}\n.w{--b:#fff;--f:#1d1d22;--m:#55555f;--l:#cfcfd8;--a:#3346c4;--o:#fff;--e:#b42318;color:var(--f)}\n@media (prefers-color-scheme:dark){.w{--b:#1d1d23;--f:#f2f2f5;--m:#b0b0bc;--l:#45454f;--a:#9aa5ff;--o:#11131f;--e:#ff9b91}}\nbutton{border:1px solid var(--l);border-radius:8px;background:none;cursor:pointer;padding:8px 16px}\n.f{position:fixed;z-index:2147483000;right:16px;bottom:16px;border-radius:99px;background:var(--b);box-shadow:0 2px 10px #0003}\n.f.l{right:auto;left:16px}\n.f.e{right:0;bottom:auto;top:50%;transform:translateY(-50%) rotate(180deg);writing-mode:vertical-rl;padding:14px 8px}\n:focus-visible{outline:3px solid var(--a);outline-offset:2px}\n.b{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:flex-end;justify-content:flex-end;padding:16px;background:#0004}\n.b.l{justify-content:flex-start}\n[hidden]{display:none!important}\n.d{position:relative;width:min(380px,100%);max-height:calc(100vh - 32px);overflow:auto;padding:20px;border:1px solid var(--l);border-radius:12px;background:var(--b);box-shadow:0 12px 40px #0005}\n@media (max-width:480px){.b{padding:0;justify-content:center}.d{width:100%;border-radius:12px 12px 0 0}}\nh2{margin:0 36px 12px 0;font-size:17px;font-weight:600}\nlabel,legend{display:block;margin:0 0 6px;font-weight:500}\ntextarea{display:block;width:100%;min-height:112px;resize:vertical;padding:8px 10px;border:1px solid var(--l);border-radius:8px;background:none}\n.n,.c{margin:4px 0 12px;color:var(--m);font-size:12.5px}\nfieldset{margin:0;padding:0;border:0}\n.r label{display:inline-flex;gap:4px;align-items:center;margin:0 12px 6px 0;font-weight:400}\ninput{margin:0;accent-color:var(--a)}\n.a{display:flex;justify-content:flex-end;gap:8px}\n.s{border-color:var(--a);background:var(--a);color:var(--o);font-weight:600}\n.s:disabled{opacity:.6}\n.x{position:absolute;top:10px;right:10px;width:34px;height:34px;padding:0;border:0;font-size:22px;line-height:1}\n.t{min-height:1.45em;margin:10px 0 0}\n.t.e{color:var(--e)}\n@media (prefers-reduced-motion:no-preference){.d{animation:i .16s ease-out}@keyframes i{from{opacity:0;transform:translateY(8px)}}}</style><div class="w"><button type="button" class="f" aria-haspopup="dialog"></button><div class="b" hidden><div class="d" role="dialog" aria-modal="true" aria-labelledby="h" aria-describedby="c"><button type="button" class="x" aria-label="Close">×</button><h2 id="h">Send feedback</h2><form novalidate><label for="m"></label><textarea id="m" aria-describedby="n"></textarea><p class="n" id="n"></p><fieldset><legend>Kind of note (optional)</legend><div class="r"></div></fieldset><p class="c" id="c"></p><div class="a"><button type="button" class="k">Cancel</button><button type="submit" class="s">Send</button></div></form><p class="t" role="status" aria-live="polite"></p></div></div></div>';let o=e=>i.querySelector(e),l=o(".f"),s=o(".b"),d=o(".d"),c=o("form"),u=o("textarea"),f=o(".n"),p=o(".c"),b=o(".t"),g=o(".s"),h=o(".x");l.textContent=n.label,"manual"===n.placement?l.remove():"bottom_left"===n.placement?(l.classList.add("l"),s.classList.add("l")):"right_edge"===n.placement&&l.classList.add("e"),o("label").textContent=n.prompt||"What could be better on this page?",u.maxLength=k;let x=o(".r");for(let e of m){let t=r.createElement("label"),n=r.createElement("input");n.type="radio",n.name="k",n.value=e,t.append(n,y[e]),x.append(t)}let v=null,w=!1,A=()=>{let e=k-u.value.length;f.textContent=`${e.toLocaleString("en-US")} ${1===e?"character":"characters"} left`};u.addEventListener("input",A);let _=(e,t=!1)=>{b.textContent=e,b.classList.toggle("e",t)},S=()=>{if(s.hidden)return;s.hidden=!0;let e=v&&v.isConnected?v:l.isConnected?l:null;v=null,e?.focus?.()},E=t=>{a.isConnected||(r.body||r.documentElement).append(a),v=t??null,c.hidden&&(c.hidden=!1,c.reset(),_("")),p.textContent=e.consent(),A(),s.hidden=!1,u.focus()},z=async()=>{if(w)return;if(!u.value.trim())return _($("empty"),!0),void u.focus();let t=e.consent();if(t!==p.textContent)return p.textContent=t,void _("The line above changed. Read it, then press Send again.",!0);w=!0,g.disabled=!0,_("Sending");let n=x.querySelector(":checked")?.value,r=await e.submit({text:u.value,...n?{category:n}:{}});w=!1,g.disabled=!1,r.ok?(c.hidden=!0,_("Thanks. Your note was sent."),h.focus()):_($(r.error),!0)};return l.addEventListener("click",()=>E(l)),h.addEventListener("click",S),o(".k").addEventListener("click",S),s.addEventListener("click",e=>{e.target===s&&S()}),c.addEventListener("submit",e=>{e.preventDefault(),z()}),u.addEventListener("keydown",e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),z())}),d.addEventListener("keydown",e=>{if("Escape"===e.key)e.preventDefault(),S();else if("Tab"===e.key){let t=[...d.querySelectorAll("button,textarea,input")].filter(e=>!e.disabled&&!e.closest("[hidden]")&&("INPUT"!==e.tagName||e.checked||!x.querySelector(":checked"))),n=t[0],r=t[t.length-1],a=i.activeElement;if(!n||!r)return;(e.shiftKey?a===n||!a:a===r||!a)&&(e.preventDefault(),(e.shiftKey?r:n).focus())}}),"manual"!==n.placement&&(r.body||r.documentElement).append(a),{open:E,close:S,destroy:()=>{s.hidden=!0,a.remove()},root:i}})({w:t,config:e,consent:()=>(e=>`${e.visit?"Your note, this page's address, the time, your device type and a link to this visit":"Your note, this page's address, the time and your device type"} go to the team behind ${e.site.replace(/^www\./,"")||"this site"} when you press Send, and are kept for ${1===e.days?"1 day":`${e.days} days`}. Please leave out passwords and card numbers.`)({site:t.location.hostname,days:e.days,visit:null!==c()}),submit:u}),p=async e=>{let t=await d;!s&&t&&f(t).open(e??null)};d.then(e=>{!s&&e&&"manual"!==e.placement&&f(e)});let b,g,x=e=>{let t=e[1],n=e[2];t&&"object"==typeof t?u(t).then(e=>{"function"==typeof n&&n(e)}):p(i.activeElement)},v=1e3,_=()=>{if(clearTimeout(a),s)return;let e=t.lf;if(!e){let n=(...e)=>n.q.push(e);n.q=[],t.lf=e=n}(!e.q||e.q!==b)&&(b=((e,t,n)=>{let r=e.q;(!r||"function"!=typeof r.push)&&(r=[],e.q=r);let a=e=>{try{n(e)}catch(e){setTimeout(()=>{throw e})}};if(Array.isArray(r))for(let e=0;e<r.length;)r[e]?.[0]===t?a(r.splice(e,1)[0]):e++;let i=r,o=i.push;return i.push=e=>e?.[0]===t?a(e):o.call(i,e),i})(e,"feedback",x)),e.v||(a=setTimeout(_,v),v=Math.min(2*v,3e4))},S=Object.getOwnPropertyDescriptor(t,"lf"),E=!!S&&!("value"in S),z=t.lf;if(!S||S.configurable){g={configurable:!0,enumerable:!S||S.enumerable,get:E?()=>S.get?.call(t):()=>z,set:e=>{E?S.set?.call(t,e):z=e,e?.v&&_()}};try{Object.defineProperty(t,"lf",g)}catch{g=void 0}}return _(),{ready:d,open:p,send:u,stop:()=>{if(s=!0,clearTimeout(a),g&&Object.getOwnPropertyDescriptor(t,"lf")?.get===g.get)try{Object.defineProperty(t,"lf",E&&S?S:{configurable:!0,enumerable:g.enumerable,writable:!0,value:z})}catch{}r?.destroy(),r=void 0},widget:()=>r}}(t,n);r[S]=i;let o=i.stop;i.stop=()=>{o(),r[S]===i&&delete r[S]}})(window,{site:j,api:C("api"),routes:Array.isArray(_)?_:[]})})();
|
|
1
|
+
(()=>{var e=/^[A-Za-z0-9_-]{16,32}$/,t=new RegExp("[^\\s@/]{1,64}@[^\\s@/]{1,253}\\.\\p{L}{2,24}","iu"),n=/\d[\d\s().-]{7,}\d/,r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,a=/^[0-9a-f]{16,}$/i,i=/[a-f]/i,o=/^\d+$/,l=/^(?=.*\d)(?=.*[a-zA-Z])[A-Za-z0-9_-]{20,}$/,s=/^(?:eyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*){1,4}|(?=.*\d)(?=.*[A-Z])[A-Za-z0-9_-]{16,}(?:\.[A-Za-z0-9_-]{16,}){2})$/,d=/^:[a-z_][a-z0-9_]{0,31}$/,c=/[\u0000-\u001f\u007f]/g,u=/[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;function f(e){let o=e.length>2048?e.slice(0,2048):e;return!(!o.includes("@")||!t.test(o))||(!a.test(o)&&!r.test(o)||!i.test(o))&&(n.test(o)||b(o))}var p=[/(?:^|[^A-Za-z0-9])xox[abeprs]-\d/,/(?:^|[^A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{36}/,/(?:^|[^A-Za-z0-9])github_pat_[A-Za-z0-9_]{22,}/,/(?:^|[^A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Za-z0-9])/,/(?:^|[^A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/,/(?:^|[^A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{16,}/],b=e=>p.some(t=>t.test(e));function g(e){return(e=>{if("string"!=typeof e||e.length>2048)return null;let t=e,n=t.search(/[?#]/);n>=0&&(t=t.slice(0,n)),t.startsWith("/")||(t=`/${t}`);let i=t;try{i=decodeURIComponent(t)}catch{}i=(e=>e.replace(c,"").replace(u,e=>2===e.length?e:""))(i);let p=i.search(/[?#]/);p>=0&&(i=i.slice(0,p));let b=i.split("/").map(e=>{if(e.includes("="))return":redacted";if(""===e)return e;if(e.startsWith(":")){let t=e.slice(1);return m.test(t)?e:h(t)?":id":f(t)?":redacted":e}if(d.test(e))return e;let t=e.startsWith(":")?e.slice(1):e;return o.test(t)||r.test(t)||a.test(t)||l.test(t)||s.test(t)?":id":f(t)?":redacted":e}).join("/");return b.length>1&&b.endsWith("/")&&(b=b.slice(0,-1)),b.length>256?null:b})(e)}var m=/^[A-Za-z_][A-Za-z0-9_]*$/,h=e=>o.test(e)||r.test(e)||a.test(e)||s.test(e),y=["confusing","bug","idea","other"];function x(e){return"string"==typeof e&&y.includes(e)}var v={confusing:"Confusing",bug:"Something broke",idea:"Idea",other:"Other"},k=["bottom_right","bottom_left","right_edge","manual"];function w(e){return"string"==typeof e&&k.includes(e)}var A=2e3;function z(e,t){let n=e.pathname,r="file:"===e.protocol?n.slice(n.lastIndexOf("/")):n;for(let[e,n]of t)if(n.test(r))return g(e)??"/";return g(r)??"/"}function _(e){return"empty"===e?"Write a note first.":"rate_limited"===e||"quota_exceeded"===e?"Too many notes right now. Please try again in a minute.":"network"===e?"Your note was not sent. Check your connection and try again.":"feedback_off"===e?"Feedback is turned off for this site.":"Your note was not sent. Please try again."}function $(e){let t=e;if(!0!==t?.on)return null;let n="string"==typeof t.label?t.label.trim().slice(0,24):"",r="string"==typeof t.prompt?t.prompt.trim().slice(0,140):"",a=t.days;return{v:1,on:!0,label:n||"Feedback",placement:w(t.placement)?t.placement:"bottom_right",prompt:r||null,days:"number"==typeof a&&Number.isInteger(a)&&a>=1?a:90}}var S,Z=Symbol.for("littlefriend.feedback"),E=document,L=E.currentScript,C=L?.hasAttribute("data-site")?L:E.querySelector("script[data-site][data-feedback]"),j=e=>C?.getAttribute(`data-${e}`)||void 0,q=j("site");try{S=JSON.parse(j("routes")||E.querySelector("script[data-site][data-routes]")?.getAttribute("data-routes")||"[]")}catch{}q&&((t,n)=>{let r=t,a=r[Z];if(a)return a;let i=function(t,n){let r,a,i=t.document,o=(n.api||"https://in.littlefriend.io").replace(/\/+$/,""),l=(e=>Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.startsWith("/")).map(e=>[e,RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/:\w+/g,"[^/]+").replace(/\*/g,".*")}/?$`)]):[])(n.routes),s=!1,d=new Promise(e=>i.prerendering?i.addEventListener("prerenderingchange",()=>e(),{once:!0}):e()).then(()=>t.fetch(`${o}/v1/f/config?k=${encodeURIComponent(n.site)}`,{credentials:"omit"})).then(e=>e.ok?e.json():null).then($,()=>null),c=()=>{let n=null,r=t.lf;if(r?.v)try{r("session",t=>{n="string"==typeof t&&e.test(t)?t:null})}catch{}return n},u=async e=>{let r=await d;if(s||!r)return{ok:!1,error:"feedback_off"};let a=e??{},i="string"==typeof a.text?a.text.trim():"";if(!i)return{ok:!1,error:"empty"};if(null!=a.category&&!x(a.category))return{ok:!1,error:"bad_category"};let u=c();return(async e=>{for(let n=0;;n++){e.s&&c()!==e.s&&(delete e.s,e.m="a");let r=JSON.stringify(e),a=0,i="network",l=1e3*2**n;try{let e=await t.fetch(`${o}/v1/f`,{method:"POST",body:r,credentials:"omit",keepalive:!0});if(a=e.status,a>=200&&a<300)return{ok:!0};let n=Number(e.headers.get("retry-after"));n>0&&(l=1e3*n);try{let t=await e.json();i="string"==typeof t?.error&&/^[a-z_]{1,40}$/.test(t.error)?t.error:"refused"}catch{i="refused"}if(429!==a&&a<500)return{ok:!1,error:i}}catch{}if(n>=3||l>1e4||s)return{ok:!1,error:i};await new Promise(e=>setTimeout(e,l))}})({v:1,k:n.site,i:[...crypto.getRandomValues(new Uint8Array(20))].map(e=>(31&e).toString(32)).join(""),t:[...i].slice(0,A).join(""),...x(a.category)?{c:a.category}:{},u:z(t.location,l),m:u?"j":"a",...u?{s:u}:{},sv:"feedback-0.1.2"})},f=e=>r||=(e=>{let{w:t,config:n}=e,r=t.document,a=r.createElement("div");a.setAttribute("data-lf-block",""),a.setAttribute("data-lf-feedback","");let i=a.attachShadow({mode:"open"});i.innerHTML='<style>:host{all:initial}\n*{box-sizing:border-box;font:14px/1.45 system-ui,sans-serif;color:inherit}\n.w{--b:#fff;--f:#1d1d22;--m:#55555f;--l:#cfcfd8;--a:#3346c4;--o:#fff;--e:#b42318;color:var(--f)}\n@media (prefers-color-scheme:dark){.w{--b:#1d1d23;--f:#f2f2f5;--m:#b0b0bc;--l:#45454f;--a:#9aa5ff;--o:#11131f;--e:#ff9b91}}\nbutton{border:1px solid var(--l);border-radius:8px;background:none;cursor:pointer;padding:8px 16px}\n.f{position:fixed;z-index:2147483000;right:16px;bottom:16px;border-radius:99px;background:var(--b);box-shadow:0 2px 10px #0003}\n.f.l{right:auto;left:16px}\n.f.e{right:0;bottom:auto;top:50%;transform:translateY(-50%) rotate(180deg);writing-mode:vertical-rl;padding:14px 8px}\n:focus-visible{outline:3px solid var(--a);outline-offset:2px}\n.b{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:flex-end;justify-content:flex-end;padding:16px;background:#0004}\n.b.l{justify-content:flex-start}\n[hidden]{display:none!important}\n.d{position:relative;width:min(380px,100%);max-height:calc(100vh - 32px);overflow:auto;padding:20px;border:1px solid var(--l);border-radius:12px;background:var(--b);box-shadow:0 12px 40px #0005}\n@media (max-width:480px){.b{padding:0;justify-content:center}.d{width:100%;border-radius:12px 12px 0 0}}\nh2{margin:0 36px 12px 0;font-size:17px;font-weight:600}\nlabel,legend{display:block;margin:0 0 6px;font-weight:500}\ntextarea{display:block;width:100%;min-height:112px;resize:vertical;padding:8px 10px;border:1px solid var(--l);border-radius:8px;background:none}\n.n,.c{margin:4px 0 12px;color:var(--m);font-size:12.5px}\nfieldset{margin:0;padding:0;border:0}\n.r label{display:inline-flex;gap:4px;align-items:center;margin:0 12px 6px 0;font-weight:400}\ninput{margin:0;accent-color:var(--a)}\n.a{display:flex;justify-content:flex-end;gap:8px}\n.s{border-color:var(--a);background:var(--a);color:var(--o);font-weight:600}\n.s:disabled{opacity:.6}\n.x{position:absolute;top:10px;right:10px;width:34px;height:34px;padding:0;border:0;font-size:22px;line-height:1}\n.t{min-height:1.45em;margin:10px 0 0}\n.t.e{color:var(--e)}\n@media (prefers-reduced-motion:no-preference){.d{animation:i .16s ease-out}@keyframes i{from{opacity:0;transform:translateY(8px)}}}</style><div class="w"><button type="button" class="f" aria-haspopup="dialog"></button><div class="b" hidden><div class="d" role="dialog" aria-modal="true" aria-labelledby="h" aria-describedby="c"><button type="button" class="x" aria-label="Close">×</button><h2 id="h">Send feedback</h2><form novalidate><label for="m"></label><textarea id="m" aria-describedby="n"></textarea><p class="n" id="n"></p><fieldset><legend>Kind of note (optional)</legend><div class="r"></div></fieldset><p class="c" id="c"></p><div class="a"><button type="button" class="k">Cancel</button><button type="submit" class="s">Send</button></div></form><p class="t" role="status" aria-live="polite"></p></div></div></div>';let o=e=>i.querySelector(e),l=o(".f"),s=o(".b"),d=o(".d"),c=o("form"),u=o("textarea"),f=o(".n"),p=o(".c"),b=o(".t"),g=o(".s"),m=o(".x");l.textContent=n.label,"manual"===n.placement?l.remove():"bottom_left"===n.placement?(l.classList.add("l"),s.classList.add("l")):"right_edge"===n.placement&&l.classList.add("e"),o("label").textContent=n.prompt||"What could be better on this page?",u.maxLength=A;let h=o(".r");for(let e of y){let t=r.createElement("label"),n=r.createElement("input");n.type="radio",n.name="k",n.value=e,t.append(n,v[e]),h.append(t)}let x=null,k=!1,w=()=>{let e=A-u.value.length;f.textContent=`${e.toLocaleString("en-US")} ${1===e?"character":"characters"} left`};u.addEventListener("input",w);let z=(e,t=!1)=>{b.textContent=e,b.classList.toggle("e",t)},$=()=>{if(s.hidden)return;s.hidden=!0;let e=x&&x.isConnected?x:l.isConnected?l:null;x=null,e?.focus?.()},S=t=>{a.isConnected||(r.body||r.documentElement).append(a),x=t??null,c.hidden&&(c.hidden=!1,c.reset(),z("")),p.textContent=e.consent(),w(),s.hidden=!1,u.focus()},Z=async()=>{if(k)return;if(!u.value.trim())return z(_("empty"),!0),void u.focus();let t=e.consent();if(t!==p.textContent)return p.textContent=t,void z("The line above changed. Read it, then press Send again.",!0);k=!0,g.disabled=!0,z("Sending");let n=h.querySelector(":checked")?.value,r=await e.submit({text:u.value,...n?{category:n}:{}});k=!1,g.disabled=!1,r.ok?(c.hidden=!0,z("Thanks. Your note was sent."),m.focus()):z(_(r.error),!0)};return l.addEventListener("click",()=>S(l)),m.addEventListener("click",$),o(".k").addEventListener("click",$),s.addEventListener("click",e=>{e.target===s&&$()}),c.addEventListener("submit",e=>{e.preventDefault(),Z()}),u.addEventListener("keydown",e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),Z())}),d.addEventListener("keydown",e=>{if("Escape"===e.key)e.preventDefault(),$();else if("Tab"===e.key){let t=[...d.querySelectorAll("button,textarea,input")].filter(e=>!e.disabled&&!e.closest("[hidden]")&&("INPUT"!==e.tagName||e.checked||!h.querySelector(":checked"))),n=t[0],r=t[t.length-1],a=i.activeElement;if(!n||!r)return;(e.shiftKey?a===n||!a:a===r||!a)&&(e.preventDefault(),(e.shiftKey?r:n).focus())}}),"manual"!==n.placement&&(r.body||r.documentElement).append(a),{open:S,close:$,destroy:()=>{s.hidden=!0,a.remove()},root:i}})({w:t,config:e,consent:()=>(e=>`${e.visit?"Your note, this page's address, the time, your device type and a link to this visit":"Your note, this page's address, the time and your device type"} go to the team behind ${e.site.replace(/^www\./,"")||"this site"} when you press Send, and are kept for ${1===e.days?"1 day":`${e.days} days`}. Please leave out passwords and card numbers.`)({site:t.location.hostname,days:e.days,visit:null!==c()}),submit:u}),p=async e=>{let t=await d;!s&&t&&f(t).open(e??null)};d.then(e=>{!s&&e&&"manual"!==e.placement&&f(e)});let b,g,m=e=>{let t=e[1],n=e[2];t&&"object"==typeof t?u(t).then(e=>{"function"==typeof n&&n(e)}):p(i.activeElement)},h=1e3,k=()=>{if(clearTimeout(a),s)return;let e=t.lf;if(!e){let n=(...e)=>n.q.push(e);n.q=[],t.lf=e=n}(!e.q||e.q!==b)&&(b=((e,t,n)=>{let r=e.q;(!r||"function"!=typeof r.push)&&(r=[],e.q=r);let a=e=>{try{n(e)}catch(e){setTimeout(()=>{throw e})}};if(Array.isArray(r))for(let e=0;e<r.length;)r[e]?.[0]===t?a(r.splice(e,1)[0]):e++;let i=r,o=i.push;return i.push=e=>e?.[0]===t?a(e):o.call(i,e),i})(e,"feedback",m)),e.v||(a=setTimeout(k,h),h=Math.min(2*h,3e4))},w=Object.getOwnPropertyDescriptor(t,"lf"),S=!!w&&!("value"in w),Z=t.lf;if(!w||w.configurable){g={configurable:!0,enumerable:!w||w.enumerable,get:S?()=>w.get?.call(t):()=>Z,set:e=>{S?w.set?.call(t,e):Z=e,e?.v&&k()}};try{Object.defineProperty(t,"lf",g)}catch{g=void 0}}return k(),{ready:d,open:p,send:u,stop:()=>{if(s=!0,clearTimeout(a),g&&Object.getOwnPropertyDescriptor(t,"lf")?.get===g.get)try{Object.defineProperty(t,"lf",S&&w?w:{configurable:!0,enumerable:g.enumerable,writable:!0,value:Z})}catch{}r?.destroy(),r=void 0},widget:()=>r}}(t,n);r[Z]=i;let o=i.stop;i.stop=()=>{o(),r[Z]===i&&delete r[Z]}})(window,{site:q,api:j("api"),routes:Array.isArray(S)?S:[]})})();
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Kept in step with package.json by test/size.test.ts. */
|
|
2
|
-
export declare const VERSION = "0.1.
|
|
2
|
+
export declare const VERSION = "0.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@littlefriend/feedback",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Little Friend feedback button: a small, accessible widget where a person can tell you a page is confusing, at the moment it happens. Sent only when they press Send.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"happy-dom": "^20.0.0",
|
|
36
36
|
"terser": "^5.51.2",
|
|
37
37
|
"@littlefriend/contract": "0.1.0",
|
|
38
|
-
"@littlefriend/tracker": "0.1.
|
|
38
|
+
"@littlefriend/tracker": "0.1.8"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "node scripts/build.mjs",
|