@pigmilcom/a11y 1.1.0 → 1.1.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.

Potentially problematic release.


This version of @pigmilcom/a11y might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -42,45 +42,86 @@ function _isLocalDev() {
42
42
  return true;
43
43
  }
44
44
  }
45
+ function _sign(domain) {
46
+ const seed = domain + "\0" + (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
47
+ let h = 2166136261 >>> 0;
48
+ for (let i = 0; i < seed.length; i++) {
49
+ h = Math.imul(h ^ seed.charCodeAt(i), 16777619) >>> 0;
50
+ }
51
+ return h.toString(36);
52
+ }
53
+ var _U = [66, 94, 94, 90, 89, 16, 5, 5, 75, 90, 67, 4, 90, 67, 69, 71, 67, 70, 4, 73, 69, 71, 5, 75, 27, 27, 83, 5, 92, 75, 70, 67, 78, 75, 94, 79];
54
+ function _ep(domain) {
55
+ const base = String.fromCharCode(..._U.map((n) => n ^ 42));
56
+ return base + "?d=" + encodeURIComponent(domain) + "&t=" + Date.now() + "&s=" + _sign(domain);
57
+ }
58
+ function _result(status, plan) {
59
+ return Object.freeze({ status, plan: plan || "free" });
60
+ }
45
61
  var _CK = "_pgm_lc";
62
+ var _TTL = 18e5;
46
63
  function _readCache() {
47
64
  try {
48
- const v = sessionStorage.getItem(_CK);
49
- if (!v) return null;
50
- const p = JSON.parse(v);
51
- return Date.now() - (p._ts || 0) < 18e5 ? p : null;
65
+ const raw = sessionStorage.getItem(_CK);
66
+ if (!raw) return null;
67
+ const p = JSON.parse(raw);
68
+ if (!p || typeof p.status !== "string") return null;
69
+ return Date.now() - (p._ts || 0) < _TTL ? p : null;
52
70
  } catch {
53
71
  return null;
54
72
  }
55
73
  }
56
- function _writeCache(result) {
74
+ function _writeCache(r) {
57
75
  try {
58
- sessionStorage.setItem(_CK, JSON.stringify({ ...result, _ts: Date.now() }));
76
+ sessionStorage.setItem(_CK, JSON.stringify({ status: r.status, plan: r.plan, _ts: Date.now() }));
59
77
  } catch {
60
78
  }
61
79
  }
62
- var _mock = () => Promise.resolve({ ok: true, plan: "free", blocked: false });
80
+ var MOCK_MODE = true;
81
+ async function _callApi(domain) {
82
+ if (MOCK_MODE) {
83
+ return { ok: true, plan: "free", blocked: false };
84
+ }
85
+ const ctrl = new AbortController();
86
+ const timer = setTimeout(() => ctrl.abort(), 5e3);
87
+ try {
88
+ const res = await fetch(_ep(domain), {
89
+ method: "GET",
90
+ mode: "cors",
91
+ credentials: "omit",
92
+ signal: ctrl.signal
93
+ });
94
+ clearTimeout(timer);
95
+ if (!res.ok) return null;
96
+ const data = await res.json();
97
+ return data && typeof data.ok === "boolean" ? data : null;
98
+ } catch {
99
+ clearTimeout(timer);
100
+ return null;
101
+ }
102
+ }
63
103
  async function validateLicense() {
64
104
  const cached = _readCache();
65
- if (cached) return { status: cached.status, plan: cached.plan };
105
+ if (cached) return _result(cached.status, cached.plan);
66
106
  if (_isLocalDev()) {
67
- const result2 = { status: "dev", plan: "free" };
68
- _writeCache(result2);
69
- return result2;
107
+ const r2 = _result("dev", "free");
108
+ _writeCache(r2);
109
+ return r2;
70
110
  }
71
111
  const domain = typeof location !== "undefined" ? location.hostname.toLowerCase().replace(/^www\./, "") : "";
72
- if (!domain) return { status: "error", plan: "free" };
73
- let result;
112
+ if (!domain) return _result("error", "free");
113
+ let r;
74
114
  try {
75
- const data = await _mock();
76
- if (!(data == null ? void 0 : data.ok)) result = { status: "error", plan: "free" };
77
- else if (data.blocked) result = { status: "blocked", plan: data.plan || "free" };
78
- else result = { status: "valid", plan: data.plan || "free" };
115
+ const data = await _callApi(domain);
116
+ if (!data) r = _result("error", "free");
117
+ else if (!data.ok) r = _result("error", data.plan || "free");
118
+ else if (data.blocked) r = _result("blocked", data.plan || "free");
119
+ else r = _result("valid", data.plan || "free");
79
120
  } catch {
80
- result = { status: "error", plan: "free" };
121
+ r = _result("error", "free");
81
122
  }
82
- _writeCache(result);
83
- return result;
123
+ _writeCache(r);
124
+ return r;
84
125
  }
85
126
 
86
127
  // src/widget.jsx
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- var f=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var R=(t,a)=>{for(var s in a)f(t,s,{get:a[s],enumerable:!0})},$=(t,a,s,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of O(a))!D.call(t,r)&&r!==s&&f(t,r,{get:()=>a[r],enumerable:!(o=E(a,r))||o.enumerable});return t};var P=t=>$(f({},"__esModule",{value:!0}),t);var K={};R(K,{A11yWidget:()=>p,a11y:()=>p,default:()=>p});module.exports=P(K);var i=require("react"),S=require("react-dom");var T=/^(localhost|127\.\d+\.\d+\.\d+|::1|\[::1\]|0\.0\.0\.0)$/i;function G(){try{let{hostname:t,port:a}=location;return!!(T.test(t)||a&&a!=="80"&&a!=="443")}catch{return!0}}var N="_pgm_lc";function J(){try{let t=sessionStorage.getItem(N);if(!t)return null;let a=JSON.parse(t);return Date.now()-(a._ts||0)<18e5?a:null}catch{return null}}function x(t){try{sessionStorage.setItem(N,JSON.stringify({...t,_ts:Date.now()}))}catch{}}var H=()=>Promise.resolve({ok:!0,plan:"free",blocked:!1});async function C(){let t=J();if(t)return{status:t.status,plan:t.plan};if(G()){let o={status:"dev",plan:"free"};return x(o),o}if(!(typeof location<"u"?location.hostname.toLowerCase().replace(/^www\./,""):""))return{status:"error",plan:"free"};let s;try{let o=await H();o!=null&&o.ok?o.blocked?s={status:"blocked",plan:o.plan||"free"}:s={status:"valid",plan:o.plan||"free"}:s={status:"error",plan:"free"}}catch{s={status:"error",plan:"free"}}return x(s),s}var e=require("react/jsx-runtime"),L="pgm-a11y",c={textSize:0,highContrast:!1,invertColors:!1,grayscale:!1,reduceMotion:!1,highlightLinks:!1,textSpacing:!1,adhd:!1,dyslexia:!1};function v(t){let a=document.documentElement;a.classList.remove("a11y-text-lg","a11y-text-xl"),t.textSize===1&&a.classList.add("a11y-text-lg"),t.textSize===2&&a.classList.add("a11y-text-xl");let s={"a11y-high-contrast":t.highContrast,"a11y-invert":t.invertColors,"a11y-grayscale":t.grayscale,"a11y-reduce-motion":t.reduceMotion,"a11y-highlight-links":t.highlightLinks,"a11y-text-spacing":t.textSpacing,"a11y-adhd":t.adhd,"a11y-dyslexia":t.dyslexia};for(let[r,u]of Object.entries(s))a.classList.toggle(r,u);let o=[];t.invertColors&&o.push("invert(1) hue-rotate(180deg)"),t.highContrast&&o.push("contrast(1.6)"),t.grayscale&&o.push("grayscale(1)"),a.style.filter=o.join(" ")}function j(){try{let t=localStorage.getItem(L);return t?{...c,...JSON.parse(t)}:{...c}}catch{return{...c}}}function w(t){try{localStorage.setItem(L,JSON.stringify(t))}catch{}}var M=["Normal","Large","X-Large"],F=[{key:"highContrast",label:"High Contrast",desc:"Increase colour contrast for readability",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("path",{d:"M12 2v20"}),(0,e.jsx)("path",{d:"M12 2a10 10 0 0 1 0 20",fill:"currentColor",stroke:"none"})]})},{key:"invertColors",label:"Invert Colors",desc:"Invert all page colours",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M12 3v18M3 12h18"}),(0,e.jsx)("path",{d:"M12 3a9 9 0 0 1 0 18",fill:"currentColor",stroke:"none"})]})},{key:"grayscale",label:"Grayscale",desc:"Remove all colour from the page",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,e.jsx)("circle",{cx:"12",cy:"12",r:"4",fill:"currentColor",stroke:"none"})]})},{key:"reduceMotion",label:"Reduce Motion",desc:"Stop animations and transitions",icon:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M5 12h14M12 5l-7 7 7 7"})})},{key:"highlightLinks",label:"Highlight Links",desc:"Make all links visible at a glance",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),(0,e.jsx)("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})},{key:"textSpacing",label:"Text Spacing",desc:"Increase letter, word & line spacing",icon:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})},{key:"adhd",label:"ADHD Friendly",desc:"Remove distractions, add focus ring",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,e.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,e.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{key:"dyslexia",label:"Dyslexia Font",desc:"Switch to a high-readability typeface",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M4 7V4h16v3"}),(0,e.jsx)("path",{d:"M9 20h6"}),(0,e.jsx)("path",{d:"M12 4v16"})]})}];function p({className:t}){let[a,s]=(0,i.useState)(!1),[o,r]=(0,i.useState)(c),[u,_]=(0,i.useState)(!1),[h,z]=(0,i.useState)(!1),[m,A]=(0,i.useState)({status:"checking",plan:"free"}),B=(0,i.useRef)(null);if((0,i.useEffect)(()=>{_(!0)},[]),(0,i.useEffect)(()=>{C().then(A)},[]),(0,i.useEffect)(()=>{let n=j();r(n),v(n)},[]),(0,i.useEffect)(()=>{if(!a)return;let n=l=>{l.key==="Escape"&&s(!1)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[a]),m.status==="checking"||m.status==="error"||m.status==="blocked")return null;let y=m.plan==="pro",b=n=>{r(l=>{let g={...l,...n};return v(g),w(g),g})},I=()=>{r(c),v(c),w(c)},k=JSON.stringify(o)!==JSON.stringify(c);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{ref:B,type:"button","aria-label":"Accessibility options","aria-expanded":a,"aria-haspopup":"dialog",onClick:()=>s(n=>!n),className:`pgm-btn a11y-widget-btn${t?` ${t}`:""}`,children:[(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-lg",fill:"none",stroke:"currentColor",strokeWidth:1.8,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),(0,e.jsx)("path",{d:"M5 8.5h14M8 8.5l1 10 3-4 3 4 1-10",strokeLinecap:"round",strokeLinejoin:"round"})]}),k&&(0,e.jsx)("span",{className:"pgm-dot","aria-hidden":"true"})]}),a&&u&&(0,S.createPortal)((0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"pgm-backdrop",onClick:()=>s(!1),"aria-hidden":"true"}),(0,e.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Accessibility settings",className:"pgm-dialog a11y-widget-dialog",children:[(0,e.jsxs)("div",{className:"pgm-header",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"pgm-header-title",children:"Accessibility"}),(0,e.jsx)("p",{className:"pgm-header-subtitle",children:"WCAG 2.1 \xB7 Personalise your experience"})]}),(0,e.jsx)("button",{type:"button","aria-label":"Close accessibility panel",onClick:()=>s(!1),className:"pgm-close-btn",children:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M18 6 6 18M6 6l12 12",strokeLinecap:"round"})})})]}),(0,e.jsxs)("div",{className:"pgm-size-section",children:[(0,e.jsxs)("div",{className:"pgm-size-header",children:[(0,e.jsx)("span",{className:"pgm-size-label",children:"Text Size"}),(0,e.jsx)("span",{className:"pgm-size-value",children:M[o.textSize]})]}),(0,e.jsx)("div",{className:"pgm-size-btns",children:M.map((n,l)=>(0,e.jsx)("button",{type:"button","aria-pressed":o.textSize===l,onClick:()=>b({textSize:l}),className:`pgm-size-btn ${o.textSize===l?"pgm-size-btn--active":"pgm-size-btn--inactive"}`,children:n},n))})]}),(0,e.jsx)("div",{className:"pgm-toggle-list",children:F.map(({key:n,label:l,desc:g,icon:W})=>{let d=o[n];return(0,e.jsxs)("button",{type:"button",role:"switch","aria-checked":d,onClick:()=>b({[n]:!d}),className:`pgm-toggle-btn a11y-widget-toggle-btn${d?" pgm-toggle-btn--on":""}`,children:[(0,e.jsx)("span",{className:`pgm-toggle-icon${d?" pgm-toggle-icon--on":""}`,children:W}),(0,e.jsxs)("span",{className:"pgm-toggle-text",children:[(0,e.jsx)("span",{className:`pgm-toggle-label${d?" pgm-toggle-label--on":""}`,children:l}),(0,e.jsx)("span",{className:"pgm-toggle-desc",children:g})]}),(0,e.jsx)("span",{"aria-hidden":"true",className:`pgm-pill${d?" pgm-pill--on":" pgm-pill--off"}`,children:(0,e.jsx)("span",{className:`pgm-pill-knob${d?" pgm-pill-knob--on":" pgm-pill-knob--off"}`})})]},n)})}),(0,e.jsxs)("div",{className:"pgm-footer",children:[!y&&(0,e.jsxs)("button",{type:"button","aria-expanded":h,"aria-controls":"pgm-notice",onClick:()=>z(n=>!n),className:"pgm-notice-btn",children:[(0,e.jsx)("img",{src:"https://cdn.pigmil.com/shared/icon.png",alt:"Pigmil",className:"pgm-notice-logo"}),(0,e.jsx)("span",{children:"About this widget"}),(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-notice-chevron",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",style:{transform:h?"rotate(180deg)":"rotate(0deg)"},children:(0,e.jsx)("path",{d:"M6 9l6 6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(0,e.jsx)("button",{type:"button",onClick:I,disabled:!k,className:"pgm-reset-btn",children:"Reset all"})]}),!y&&h&&(0,e.jsxs)("div",{id:"pgm-notice",className:"pgm-notice",children:[(0,e.jsxs)("p",{className:"pgm-notice-text",children:["This accessibility widget is provided free of charge by"," ",(0,e.jsx)("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-link",children:"PIGMIL"})," ","as an open-source tool to help make the web more accessible. It stores your preferences locally in your browser and sends no data to any server."]}),(0,e.jsxs)("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-gh",children:[(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z"})}),"View on GitHub"]})]})]})]}),document.body)]})}0&&(module.exports={A11yWidget,a11y});
1
+ var y=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var R=(t,a)=>{for(var n in a)y(t,n,{get:a[n],enumerable:!0})},$=(t,a,n,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of W(a))!D.call(t,r)&&r!==n&&y(t,r,{get:()=>a[r],enumerable:!(o=I(a,r))||o.enumerable});return t};var G=t=>$(y({},"__esModule",{value:!0}),t);var Q={};R(Q,{A11yWidget:()=>u,a11y:()=>u,default:()=>u});module.exports=G(Q);var i=require("react"),L=require("react-dom");var P=/^(localhost|127\.\d+\.\d+\.\d+|::1|\[::1\]|0\.0\.0\.0)$/i;function J(){try{let{hostname:t,port:a}=location;return!!(P.test(t)||a&&a!=="80"&&a!=="443")}catch{return!0}}function j(t){let a=t+"\0"+new Date().toISOString().slice(0,10),n=2166136261;for(let o=0;o<a.length;o++)n=Math.imul(n^a.charCodeAt(o),16777619)>>>0;return n.toString(36)}var H=[66,94,94,90,89,16,5,5,75,90,67,4,90,67,69,71,67,70,4,73,69,71,5,75,27,27,83,5,92,75,70,67,78,75,94,79];function K(t){return String.fromCharCode(...H.map(n=>n^42))+"?d="+encodeURIComponent(t)+"&t="+Date.now()+"&s="+j(t)}function c(t,a){return Object.freeze({status:t,plan:a||"free"})}var C="_pgm_lc",F=18e5;function U(){try{let t=sessionStorage.getItem(C);if(!t)return null;let a=JSON.parse(t);return!a||typeof a.status!="string"?null:Date.now()-(a._ts||0)<F?a:null}catch{return null}}function N(t){try{sessionStorage.setItem(C,JSON.stringify({status:t.status,plan:t.plan,_ts:Date.now()}))}catch{}}var V=!0;async function X(t){if(V)return{ok:!0,plan:"free",blocked:!1};let a=new AbortController,n=setTimeout(()=>a.abort(),5e3);try{let o=await fetch(K(t),{method:"GET",mode:"cors",credentials:"omit",signal:a.signal});if(clearTimeout(n),!o.ok)return null;let r=await o.json();return r&&typeof r.ok=="boolean"?r:null}catch{return clearTimeout(n),null}}async function w(){let t=U();if(t)return c(t.status,t.plan);if(J()){let o=c("dev","free");return N(o),o}let a=typeof location<"u"?location.hostname.toLowerCase().replace(/^www\./,""):"";if(!a)return c("error","free");let n;try{let o=await X(a);o?o.ok?o.blocked?n=c("blocked",o.plan||"free"):n=c("valid",o.plan||"free"):n=c("error",o.plan||"free"):n=c("error","free")}catch{n=c("error","free")}return N(n),n}var e=require("react/jsx-runtime"),_="pgm-a11y",d={textSize:0,highContrast:!1,invertColors:!1,grayscale:!1,reduceMotion:!1,highlightLinks:!1,textSpacing:!1,adhd:!1,dyslexia:!1};function v(t){let a=document.documentElement;a.classList.remove("a11y-text-lg","a11y-text-xl"),t.textSize===1&&a.classList.add("a11y-text-lg"),t.textSize===2&&a.classList.add("a11y-text-xl");let n={"a11y-high-contrast":t.highContrast,"a11y-invert":t.invertColors,"a11y-grayscale":t.grayscale,"a11y-reduce-motion":t.reduceMotion,"a11y-highlight-links":t.highlightLinks,"a11y-text-spacing":t.textSpacing,"a11y-adhd":t.adhd,"a11y-dyslexia":t.dyslexia};for(let[r,h]of Object.entries(n))a.classList.toggle(r,h);let o=[];t.invertColors&&o.push("invert(1) hue-rotate(180deg)"),t.highContrast&&o.push("contrast(1.6)"),t.grayscale&&o.push("grayscale(1)"),a.style.filter=o.join(" ")}function Y(){try{let t=localStorage.getItem(_);return t?{...d,...JSON.parse(t)}:{...d}}catch{return{...d}}}function M(t){try{localStorage.setItem(_,JSON.stringify(t))}catch{}}var S=["Normal","Large","X-Large"],q=[{key:"highContrast",label:"High Contrast",desc:"Increase colour contrast for readability",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("path",{d:"M12 2v20"}),(0,e.jsx)("path",{d:"M12 2a10 10 0 0 1 0 20",fill:"currentColor",stroke:"none"})]})},{key:"invertColors",label:"Invert Colors",desc:"Invert all page colours",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M12 3v18M3 12h18"}),(0,e.jsx)("path",{d:"M12 3a9 9 0 0 1 0 18",fill:"currentColor",stroke:"none"})]})},{key:"grayscale",label:"Grayscale",desc:"Remove all colour from the page",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,e.jsx)("circle",{cx:"12",cy:"12",r:"4",fill:"currentColor",stroke:"none"})]})},{key:"reduceMotion",label:"Reduce Motion",desc:"Stop animations and transitions",icon:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M5 12h14M12 5l-7 7 7 7"})})},{key:"highlightLinks",label:"Highlight Links",desc:"Make all links visible at a glance",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),(0,e.jsx)("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})},{key:"textSpacing",label:"Text Spacing",desc:"Increase letter, word & line spacing",icon:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})},{key:"adhd",label:"ADHD Friendly",desc:"Remove distractions, add focus ring",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,e.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,e.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{key:"dyslexia",label:"Dyslexia Font",desc:"Switch to a high-readability typeface",icon:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[(0,e.jsx)("path",{d:"M4 7V4h16v3"}),(0,e.jsx)("path",{d:"M9 20h6"}),(0,e.jsx)("path",{d:"M12 4v16"})]})}];function u({className:t}){let[a,n]=(0,i.useState)(!1),[o,r]=(0,i.useState)(d),[h,z]=(0,i.useState)(!1),[f,A]=(0,i.useState)(!1),[m,E]=(0,i.useState)({status:"checking",plan:"free"}),O=(0,i.useRef)(null);if((0,i.useEffect)(()=>{z(!0)},[]),(0,i.useEffect)(()=>{w().then(E)},[]),(0,i.useEffect)(()=>{let s=Y();r(s),v(s)},[]),(0,i.useEffect)(()=>{if(!a)return;let s=l=>{l.key==="Escape"&&n(!1)};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[a]),m.status==="checking"||m.status==="error"||m.status==="blocked")return null;let b=m.plan==="pro",k=s=>{r(l=>{let p={...l,...s};return v(p),M(p),p})},T=()=>{r(d),v(d),M(d)},x=JSON.stringify(o)!==JSON.stringify(d);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{ref:O,type:"button","aria-label":"Accessibility options","aria-expanded":a,"aria-haspopup":"dialog",onClick:()=>n(s=>!s),className:`pgm-btn a11y-widget-btn${t?` ${t}`:""}`,children:[(0,e.jsxs)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-lg",fill:"none",stroke:"currentColor",strokeWidth:1.8,"aria-hidden":"true",children:[(0,e.jsx)("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),(0,e.jsx)("path",{d:"M5 8.5h14M8 8.5l1 10 3-4 3 4 1-10",strokeLinecap:"round",strokeLinejoin:"round"})]}),x&&(0,e.jsx)("span",{className:"pgm-dot","aria-hidden":"true"})]}),a&&h&&(0,L.createPortal)((0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"pgm-backdrop",onClick:()=>n(!1),"aria-hidden":"true"}),(0,e.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Accessibility settings",className:"pgm-dialog a11y-widget-dialog",children:[(0,e.jsxs)("div",{className:"pgm-header",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"pgm-header-title",children:"Accessibility"}),(0,e.jsx)("p",{className:"pgm-header-subtitle",children:"WCAG 2.1 \xB7 Personalise your experience"})]}),(0,e.jsx)("button",{type:"button","aria-label":"Close accessibility panel",onClick:()=>n(!1),className:"pgm-close-btn",children:(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,e.jsx)("path",{d:"M18 6 6 18M6 6l12 12",strokeLinecap:"round"})})})]}),(0,e.jsxs)("div",{className:"pgm-size-section",children:[(0,e.jsxs)("div",{className:"pgm-size-header",children:[(0,e.jsx)("span",{className:"pgm-size-label",children:"Text Size"}),(0,e.jsx)("span",{className:"pgm-size-value",children:S[o.textSize]})]}),(0,e.jsx)("div",{className:"pgm-size-btns",children:S.map((s,l)=>(0,e.jsx)("button",{type:"button","aria-pressed":o.textSize===l,onClick:()=>k({textSize:l}),className:`pgm-size-btn ${o.textSize===l?"pgm-size-btn--active":"pgm-size-btn--inactive"}`,children:s},s))})]}),(0,e.jsx)("div",{className:"pgm-toggle-list",children:q.map(({key:s,label:l,desc:p,icon:B})=>{let g=o[s];return(0,e.jsxs)("button",{type:"button",role:"switch","aria-checked":g,onClick:()=>k({[s]:!g}),className:`pgm-toggle-btn a11y-widget-toggle-btn${g?" pgm-toggle-btn--on":""}`,children:[(0,e.jsx)("span",{className:`pgm-toggle-icon${g?" pgm-toggle-icon--on":""}`,children:B}),(0,e.jsxs)("span",{className:"pgm-toggle-text",children:[(0,e.jsx)("span",{className:`pgm-toggle-label${g?" pgm-toggle-label--on":""}`,children:l}),(0,e.jsx)("span",{className:"pgm-toggle-desc",children:p})]}),(0,e.jsx)("span",{"aria-hidden":"true",className:`pgm-pill${g?" pgm-pill--on":" pgm-pill--off"}`,children:(0,e.jsx)("span",{className:`pgm-pill-knob${g?" pgm-pill-knob--on":" pgm-pill-knob--off"}`})})]},s)})}),(0,e.jsxs)("div",{className:"pgm-footer",children:[!b&&(0,e.jsxs)("button",{type:"button","aria-expanded":f,"aria-controls":"pgm-notice",onClick:()=>A(s=>!s),className:"pgm-notice-btn",children:[(0,e.jsx)("img",{src:"https://cdn.pigmil.com/shared/icon.png",alt:"Pigmil",className:"pgm-notice-logo"}),(0,e.jsx)("span",{children:"About this widget"}),(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-notice-chevron",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",style:{transform:f?"rotate(180deg)":"rotate(0deg)"},children:(0,e.jsx)("path",{d:"M6 9l6 6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(0,e.jsx)("button",{type:"button",onClick:T,disabled:!x,className:"pgm-reset-btn",children:"Reset all"})]}),!b&&f&&(0,e.jsxs)("div",{id:"pgm-notice",className:"pgm-notice",children:[(0,e.jsxs)("p",{className:"pgm-notice-text",children:["This accessibility widget is provided free of charge by"," ",(0,e.jsx)("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-link",children:"PIGMIL"})," ","as an open-source tool to help make the web more accessible. It stores your preferences locally in your browser and sends no data to any server."]}),(0,e.jsxs)("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-gh",children:[(0,e.jsx)("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z"})}),"View on GitHub"]})]})]})]}),document.body)]})}0&&(module.exports={A11yWidget,a11y});
@@ -1 +1 @@
1
- import{useEffect as u,useRef as P,useState as p}from"react";import{createPortal as T}from"react-dom";var O=/^(localhost|127\.\d+\.\d+\.\d+|::1|\[::1\]|0\.0\.0\.0)$/i;function D(){try{let{hostname:t,port:s}=location;return!!(O.test(t)||s&&s!=="80"&&s!=="443")}catch{return!0}}var C="_pgm_lc";function R(){try{let t=sessionStorage.getItem(C);if(!t)return null;let s=JSON.parse(t);return Date.now()-(s._ts||0)<18e5?s:null}catch{return null}}function N(t){try{sessionStorage.setItem(C,JSON.stringify({...t,_ts:Date.now()}))}catch{}}var $=()=>Promise.resolve({ok:!0,plan:"free",blocked:!1});async function w(){let t=R();if(t)return{status:t.status,plan:t.plan};if(D()){let o={status:"dev",plan:"free"};return N(o),o}if(!(typeof location<"u"?location.hostname.toLowerCase().replace(/^www\./,""):""))return{status:"error",plan:"free"};let i;try{let o=await $();o!=null&&o.ok?o.blocked?i={status:"blocked",plan:o.plan||"free"}:i={status:"valid",plan:o.plan||"free"}:i={status:"error",plan:"free"}}catch{i={status:"error",plan:"free"}}return N(i),i}import{Fragment as L,jsx as e,jsxs as a}from"react/jsx-runtime";var _="pgm-a11y",l={textSize:0,highContrast:!1,invertColors:!1,grayscale:!1,reduceMotion:!1,highlightLinks:!1,textSpacing:!1,adhd:!1,dyslexia:!1};function y(t){let s=document.documentElement;s.classList.remove("a11y-text-lg","a11y-text-xl"),t.textSize===1&&s.classList.add("a11y-text-lg"),t.textSize===2&&s.classList.add("a11y-text-xl");let i={"a11y-high-contrast":t.highContrast,"a11y-invert":t.invertColors,"a11y-grayscale":t.grayscale,"a11y-reduce-motion":t.reduceMotion,"a11y-highlight-links":t.highlightLinks,"a11y-text-spacing":t.textSpacing,"a11y-adhd":t.adhd,"a11y-dyslexia":t.dyslexia};for(let[d,f]of Object.entries(i))s.classList.toggle(d,f);let o=[];t.invertColors&&o.push("invert(1) hue-rotate(180deg)"),t.highContrast&&o.push("contrast(1.6)"),t.grayscale&&o.push("grayscale(1)"),s.style.filter=o.join(" ")}function G(){try{let t=localStorage.getItem(_);return t?{...l,...JSON.parse(t)}:{...l}}catch{return{...l}}}function M(t){try{localStorage.setItem(_,JSON.stringify(t))}catch{}}var S=["Normal","Large","X-Large"],J=[{key:"highContrast",label:"High Contrast",desc:"Increase colour contrast for readability",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 2v20"}),e("path",{d:"M12 2a10 10 0 0 1 0 20",fill:"currentColor",stroke:"none"})]})},{key:"invertColors",label:"Invert Colors",desc:"Invert all page colours",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M12 3v18M3 12h18"}),e("path",{d:"M12 3a9 9 0 0 1 0 18",fill:"currentColor",stroke:"none"})]})},{key:"grayscale",label:"Grayscale",desc:"Remove all colour from the page",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"12",r:"9"}),e("circle",{cx:"12",cy:"12",r:"4",fill:"currentColor",stroke:"none"})]})},{key:"reduceMotion",label:"Reduce Motion",desc:"Stop animations and transitions",icon:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M5 12h14M12 5l-7 7 7 7"})})},{key:"highlightLinks",label:"Highlight Links",desc:"Make all links visible at a glance",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),e("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})},{key:"textSpacing",label:"Text Spacing",desc:"Increase letter, word & line spacing",icon:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})},{key:"adhd",label:"ADHD Friendly",desc:"Remove distractions, add focus ring",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e("path",{d:"M2 17l10 5 10-5"}),e("path",{d:"M2 12l10 5 10-5"})]})},{key:"dyslexia",label:"Dyslexia Font",desc:"Switch to a high-readability typeface",icon:a("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M4 7V4h16v3"}),e("path",{d:"M9 20h6"}),e("path",{d:"M12 4v16"})]})}];function h({className:t}){let[s,i]=p(!1),[o,d]=p(l),[f,z]=p(!1),[v,A]=p(!1),[m,B]=p({status:"checking",plan:"free"}),I=P(null);if(u(()=>{z(!0)},[]),u(()=>{w().then(B)},[]),u(()=>{let n=G();d(n),y(n)},[]),u(()=>{if(!s)return;let n=r=>{r.key==="Escape"&&i(!1)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[s]),m.status==="checking"||m.status==="error"||m.status==="blocked")return null;let b=m.plan==="pro",k=n=>{d(r=>{let g={...r,...n};return y(g),M(g),g})},W=()=>{d(l),y(l),M(l)},x=JSON.stringify(o)!==JSON.stringify(l);return a(L,{children:[a("button",{ref:I,type:"button","aria-label":"Accessibility options","aria-expanded":s,"aria-haspopup":"dialog",onClick:()=>i(n=>!n),className:`pgm-btn a11y-widget-btn${t?` ${t}`:""}`,children:[a("svg",{viewBox:"0 0 24 24",className:"pgm-icon-lg",fill:"none",stroke:"currentColor",strokeWidth:1.8,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),e("path",{d:"M5 8.5h14M8 8.5l1 10 3-4 3 4 1-10",strokeLinecap:"round",strokeLinejoin:"round"})]}),x&&e("span",{className:"pgm-dot","aria-hidden":"true"})]}),s&&f&&T(a(L,{children:[e("div",{className:"pgm-backdrop",onClick:()=>i(!1),"aria-hidden":"true"}),a("div",{role:"dialog","aria-modal":"true","aria-label":"Accessibility settings",className:"pgm-dialog a11y-widget-dialog",children:[a("div",{className:"pgm-header",children:[a("div",{children:[e("p",{className:"pgm-header-title",children:"Accessibility"}),e("p",{className:"pgm-header-subtitle",children:"WCAG 2.1 \xB7 Personalise your experience"})]}),e("button",{type:"button","aria-label":"Close accessibility panel",onClick:()=>i(!1),className:"pgm-close-btn",children:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M18 6 6 18M6 6l12 12",strokeLinecap:"round"})})})]}),a("div",{className:"pgm-size-section",children:[a("div",{className:"pgm-size-header",children:[e("span",{className:"pgm-size-label",children:"Text Size"}),e("span",{className:"pgm-size-value",children:S[o.textSize]})]}),e("div",{className:"pgm-size-btns",children:S.map((n,r)=>e("button",{type:"button","aria-pressed":o.textSize===r,onClick:()=>k({textSize:r}),className:`pgm-size-btn ${o.textSize===r?"pgm-size-btn--active":"pgm-size-btn--inactive"}`,children:n},n))})]}),e("div",{className:"pgm-toggle-list",children:J.map(({key:n,label:r,desc:g,icon:E})=>{let c=o[n];return a("button",{type:"button",role:"switch","aria-checked":c,onClick:()=>k({[n]:!c}),className:`pgm-toggle-btn a11y-widget-toggle-btn${c?" pgm-toggle-btn--on":""}`,children:[e("span",{className:`pgm-toggle-icon${c?" pgm-toggle-icon--on":""}`,children:E}),a("span",{className:"pgm-toggle-text",children:[e("span",{className:`pgm-toggle-label${c?" pgm-toggle-label--on":""}`,children:r}),e("span",{className:"pgm-toggle-desc",children:g})]}),e("span",{"aria-hidden":"true",className:`pgm-pill${c?" pgm-pill--on":" pgm-pill--off"}`,children:e("span",{className:`pgm-pill-knob${c?" pgm-pill-knob--on":" pgm-pill-knob--off"}`})})]},n)})}),a("div",{className:"pgm-footer",children:[!b&&a("button",{type:"button","aria-expanded":v,"aria-controls":"pgm-notice",onClick:()=>A(n=>!n),className:"pgm-notice-btn",children:[e("img",{src:"https://cdn.pigmil.com/shared/icon.png",alt:"Pigmil",className:"pgm-notice-logo"}),e("span",{children:"About this widget"}),e("svg",{viewBox:"0 0 24 24",className:"pgm-notice-chevron",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",style:{transform:v?"rotate(180deg)":"rotate(0deg)"},children:e("path",{d:"M6 9l6 6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e("button",{type:"button",onClick:W,disabled:!x,className:"pgm-reset-btn",children:"Reset all"})]}),!b&&v&&a("div",{id:"pgm-notice",className:"pgm-notice",children:[a("p",{className:"pgm-notice-text",children:["This accessibility widget is provided free of charge by"," ",e("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-link",children:"PIGMIL"})," ","as an open-source tool to help make the web more accessible. It stores your preferences locally in your browser and sends no data to any server."]}),a("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-gh",children:[e("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"currentColor","aria-hidden":"true",children:e("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z"})}),"View on GitHub"]})]})]})]}),document.body)]})}export{h as A11yWidget,h as a11y,h as default};
1
+ import{useEffect as h,useRef as K,useState as u}from"react";import{createPortal as F}from"react-dom";var W=/^(localhost|127\.\d+\.\d+\.\d+|::1|\[::1\]|0\.0\.0\.0)$/i;function D(){try{let{hostname:t,port:a}=location;return!!(W.test(t)||a&&a!=="80"&&a!=="443")}catch{return!0}}function R(t){let a=t+"\0"+new Date().toISOString().slice(0,10),n=2166136261;for(let o=0;o<a.length;o++)n=Math.imul(n^a.charCodeAt(o),16777619)>>>0;return n.toString(36)}var $=[66,94,94,90,89,16,5,5,75,90,67,4,90,67,69,71,67,70,4,73,69,71,5,75,27,27,83,5,92,75,70,67,78,75,94,79];function G(t){return String.fromCharCode(...$.map(n=>n^42))+"?d="+encodeURIComponent(t)+"&t="+Date.now()+"&s="+R(t)}function c(t,a){return Object.freeze({status:t,plan:a||"free"})}var w="_pgm_lc",P=18e5;function J(){try{let t=sessionStorage.getItem(w);if(!t)return null;let a=JSON.parse(t);return!a||typeof a.status!="string"?null:Date.now()-(a._ts||0)<P?a:null}catch{return null}}function C(t){try{sessionStorage.setItem(w,JSON.stringify({status:t.status,plan:t.plan,_ts:Date.now()}))}catch{}}var j=!0;async function H(t){if(j)return{ok:!0,plan:"free",blocked:!1};let a=new AbortController,n=setTimeout(()=>a.abort(),5e3);try{let o=await fetch(G(t),{method:"GET",mode:"cors",credentials:"omit",signal:a.signal});if(clearTimeout(n),!o.ok)return null;let i=await o.json();return i&&typeof i.ok=="boolean"?i:null}catch{return clearTimeout(n),null}}async function M(){let t=J();if(t)return c(t.status,t.plan);if(D()){let o=c("dev","free");return C(o),o}let a=typeof location<"u"?location.hostname.toLowerCase().replace(/^www\./,""):"";if(!a)return c("error","free");let n;try{let o=await H(a);o?o.ok?o.blocked?n=c("blocked",o.plan||"free"):n=c("valid",o.plan||"free"):n=c("error",o.plan||"free"):n=c("error","free")}catch{n=c("error","free")}return C(n),n}import{Fragment as _,jsx as e,jsxs as s}from"react/jsx-runtime";var z="pgm-a11y",d={textSize:0,highContrast:!1,invertColors:!1,grayscale:!1,reduceMotion:!1,highlightLinks:!1,textSpacing:!1,adhd:!1,dyslexia:!1};function b(t){let a=document.documentElement;a.classList.remove("a11y-text-lg","a11y-text-xl"),t.textSize===1&&a.classList.add("a11y-text-lg"),t.textSize===2&&a.classList.add("a11y-text-xl");let n={"a11y-high-contrast":t.highContrast,"a11y-invert":t.invertColors,"a11y-grayscale":t.grayscale,"a11y-reduce-motion":t.reduceMotion,"a11y-highlight-links":t.highlightLinks,"a11y-text-spacing":t.textSpacing,"a11y-adhd":t.adhd,"a11y-dyslexia":t.dyslexia};for(let[i,y]of Object.entries(n))a.classList.toggle(i,y);let o=[];t.invertColors&&o.push("invert(1) hue-rotate(180deg)"),t.highContrast&&o.push("contrast(1.6)"),t.grayscale&&o.push("grayscale(1)"),a.style.filter=o.join(" ")}function U(){try{let t=localStorage.getItem(z);return t?{...d,...JSON.parse(t)}:{...d}}catch{return{...d}}}function S(t){try{localStorage.setItem(z,JSON.stringify(t))}catch{}}var L=["Normal","Large","X-Large"],V=[{key:"highContrast",label:"High Contrast",desc:"Increase colour contrast for readability",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 2v20"}),e("path",{d:"M12 2a10 10 0 0 1 0 20",fill:"currentColor",stroke:"none"})]})},{key:"invertColors",label:"Invert Colors",desc:"Invert all page colours",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M12 3v18M3 12h18"}),e("path",{d:"M12 3a9 9 0 0 1 0 18",fill:"currentColor",stroke:"none"})]})},{key:"grayscale",label:"Grayscale",desc:"Remove all colour from the page",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"12",r:"9"}),e("circle",{cx:"12",cy:"12",r:"4",fill:"currentColor",stroke:"none"})]})},{key:"reduceMotion",label:"Reduce Motion",desc:"Stop animations and transitions",icon:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M5 12h14M12 5l-7 7 7 7"})})},{key:"highlightLinks",label:"Highlight Links",desc:"Make all links visible at a glance",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),e("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})},{key:"textSpacing",label:"Text Spacing",desc:"Increase letter, word & line spacing",icon:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})},{key:"adhd",label:"ADHD Friendly",desc:"Remove distractions, add focus ring",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e("path",{d:"M2 17l10 5 10-5"}),e("path",{d:"M2 12l10 5 10-5"})]})},{key:"dyslexia",label:"Dyslexia Font",desc:"Switch to a high-readability typeface",icon:s("svg",{viewBox:"0 0 24 24",className:"pgm-icon",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e("path",{d:"M4 7V4h16v3"}),e("path",{d:"M9 20h6"}),e("path",{d:"M12 4v16"})]})}];function f({className:t}){let[a,n]=u(!1),[o,i]=u(d),[y,A]=u(!1),[v,E]=u(!1),[m,O]=u({status:"checking",plan:"free"}),T=K(null);if(h(()=>{A(!0)},[]),h(()=>{M().then(O)},[]),h(()=>{let r=U();i(r),b(r)},[]),h(()=>{if(!a)return;let r=l=>{l.key==="Escape"&&n(!1)};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[a]),m.status==="checking"||m.status==="error"||m.status==="blocked")return null;let k=m.plan==="pro",x=r=>{i(l=>{let p={...l,...r};return b(p),S(p),p})},B=()=>{i(d),b(d),S(d)},N=JSON.stringify(o)!==JSON.stringify(d);return s(_,{children:[s("button",{ref:T,type:"button","aria-label":"Accessibility options","aria-expanded":a,"aria-haspopup":"dialog",onClick:()=>n(r=>!r),className:`pgm-btn a11y-widget-btn${t?` ${t}`:""}`,children:[s("svg",{viewBox:"0 0 24 24",className:"pgm-icon-lg",fill:"none",stroke:"currentColor",strokeWidth:1.8,"aria-hidden":"true",children:[e("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),e("path",{d:"M5 8.5h14M8 8.5l1 10 3-4 3 4 1-10",strokeLinecap:"round",strokeLinejoin:"round"})]}),N&&e("span",{className:"pgm-dot","aria-hidden":"true"})]}),a&&y&&F(s(_,{children:[e("div",{className:"pgm-backdrop",onClick:()=>n(!1),"aria-hidden":"true"}),s("div",{role:"dialog","aria-modal":"true","aria-label":"Accessibility settings",className:"pgm-dialog a11y-widget-dialog",children:[s("div",{className:"pgm-header",children:[s("div",{children:[e("p",{className:"pgm-header-title",children:"Accessibility"}),e("p",{className:"pgm-header-subtitle",children:"WCAG 2.1 \xB7 Personalise your experience"})]}),e("button",{type:"button","aria-label":"Close accessibility panel",onClick:()=>n(!1),className:"pgm-close-btn",children:e("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e("path",{d:"M18 6 6 18M6 6l12 12",strokeLinecap:"round"})})})]}),s("div",{className:"pgm-size-section",children:[s("div",{className:"pgm-size-header",children:[e("span",{className:"pgm-size-label",children:"Text Size"}),e("span",{className:"pgm-size-value",children:L[o.textSize]})]}),e("div",{className:"pgm-size-btns",children:L.map((r,l)=>e("button",{type:"button","aria-pressed":o.textSize===l,onClick:()=>x({textSize:l}),className:`pgm-size-btn ${o.textSize===l?"pgm-size-btn--active":"pgm-size-btn--inactive"}`,children:r},r))})]}),e("div",{className:"pgm-toggle-list",children:V.map(({key:r,label:l,desc:p,icon:I})=>{let g=o[r];return s("button",{type:"button",role:"switch","aria-checked":g,onClick:()=>x({[r]:!g}),className:`pgm-toggle-btn a11y-widget-toggle-btn${g?" pgm-toggle-btn--on":""}`,children:[e("span",{className:`pgm-toggle-icon${g?" pgm-toggle-icon--on":""}`,children:I}),s("span",{className:"pgm-toggle-text",children:[e("span",{className:`pgm-toggle-label${g?" pgm-toggle-label--on":""}`,children:l}),e("span",{className:"pgm-toggle-desc",children:p})]}),e("span",{"aria-hidden":"true",className:`pgm-pill${g?" pgm-pill--on":" pgm-pill--off"}`,children:e("span",{className:`pgm-pill-knob${g?" pgm-pill-knob--on":" pgm-pill-knob--off"}`})})]},r)})}),s("div",{className:"pgm-footer",children:[!k&&s("button",{type:"button","aria-expanded":v,"aria-controls":"pgm-notice",onClick:()=>E(r=>!r),className:"pgm-notice-btn",children:[e("img",{src:"https://cdn.pigmil.com/shared/icon.png",alt:"Pigmil",className:"pgm-notice-logo"}),e("span",{children:"About this widget"}),e("svg",{viewBox:"0 0 24 24",className:"pgm-notice-chevron",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",style:{transform:v?"rotate(180deg)":"rotate(0deg)"},children:e("path",{d:"M6 9l6 6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e("button",{type:"button",onClick:B,disabled:!N,className:"pgm-reset-btn",children:"Reset all"})]}),!k&&v&&s("div",{id:"pgm-notice",className:"pgm-notice",children:[s("p",{className:"pgm-notice-text",children:["This accessibility widget is provided free of charge by"," ",e("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-link",children:"PIGMIL"})," ","as an open-source tool to help make the web more accessible. It stores your preferences locally in your browser and sends no data to any server."]}),s("a",{href:"https://github.com/pigmilcom/a11y",target:"_blank",rel:"noopener noreferrer",className:"pgm-notice-gh",children:[e("svg",{viewBox:"0 0 24 24",className:"pgm-icon-sm",fill:"currentColor","aria-hidden":"true",children:e("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z"})}),"View on GitHub"]})]})]})]}),document.body)]})}export{f as A11yWidget,f as a11y,f as default};
package/dist/index.mjs CHANGED
@@ -16,45 +16,86 @@ function _isLocalDev() {
16
16
  return true;
17
17
  }
18
18
  }
19
+ function _sign(domain) {
20
+ const seed = domain + "\0" + (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
21
+ let h = 2166136261 >>> 0;
22
+ for (let i = 0; i < seed.length; i++) {
23
+ h = Math.imul(h ^ seed.charCodeAt(i), 16777619) >>> 0;
24
+ }
25
+ return h.toString(36);
26
+ }
27
+ var _U = [66, 94, 94, 90, 89, 16, 5, 5, 75, 90, 67, 4, 90, 67, 69, 71, 67, 70, 4, 73, 69, 71, 5, 75, 27, 27, 83, 5, 92, 75, 70, 67, 78, 75, 94, 79];
28
+ function _ep(domain) {
29
+ const base = String.fromCharCode(..._U.map((n) => n ^ 42));
30
+ return base + "?d=" + encodeURIComponent(domain) + "&t=" + Date.now() + "&s=" + _sign(domain);
31
+ }
32
+ function _result(status, plan) {
33
+ return Object.freeze({ status, plan: plan || "free" });
34
+ }
19
35
  var _CK = "_pgm_lc";
36
+ var _TTL = 18e5;
20
37
  function _readCache() {
21
38
  try {
22
- const v = sessionStorage.getItem(_CK);
23
- if (!v) return null;
24
- const p = JSON.parse(v);
25
- return Date.now() - (p._ts || 0) < 18e5 ? p : null;
39
+ const raw = sessionStorage.getItem(_CK);
40
+ if (!raw) return null;
41
+ const p = JSON.parse(raw);
42
+ if (!p || typeof p.status !== "string") return null;
43
+ return Date.now() - (p._ts || 0) < _TTL ? p : null;
26
44
  } catch {
27
45
  return null;
28
46
  }
29
47
  }
30
- function _writeCache(result) {
48
+ function _writeCache(r) {
31
49
  try {
32
- sessionStorage.setItem(_CK, JSON.stringify({ ...result, _ts: Date.now() }));
50
+ sessionStorage.setItem(_CK, JSON.stringify({ status: r.status, plan: r.plan, _ts: Date.now() }));
33
51
  } catch {
34
52
  }
35
53
  }
36
- var _mock = () => Promise.resolve({ ok: true, plan: "free", blocked: false });
54
+ var MOCK_MODE = true;
55
+ async function _callApi(domain) {
56
+ if (MOCK_MODE) {
57
+ return { ok: true, plan: "free", blocked: false };
58
+ }
59
+ const ctrl = new AbortController();
60
+ const timer = setTimeout(() => ctrl.abort(), 5e3);
61
+ try {
62
+ const res = await fetch(_ep(domain), {
63
+ method: "GET",
64
+ mode: "cors",
65
+ credentials: "omit",
66
+ signal: ctrl.signal
67
+ });
68
+ clearTimeout(timer);
69
+ if (!res.ok) return null;
70
+ const data = await res.json();
71
+ return data && typeof data.ok === "boolean" ? data : null;
72
+ } catch {
73
+ clearTimeout(timer);
74
+ return null;
75
+ }
76
+ }
37
77
  async function validateLicense() {
38
78
  const cached = _readCache();
39
- if (cached) return { status: cached.status, plan: cached.plan };
79
+ if (cached) return _result(cached.status, cached.plan);
40
80
  if (_isLocalDev()) {
41
- const result2 = { status: "dev", plan: "free" };
42
- _writeCache(result2);
43
- return result2;
81
+ const r2 = _result("dev", "free");
82
+ _writeCache(r2);
83
+ return r2;
44
84
  }
45
85
  const domain = typeof location !== "undefined" ? location.hostname.toLowerCase().replace(/^www\./, "") : "";
46
- if (!domain) return { status: "error", plan: "free" };
47
- let result;
86
+ if (!domain) return _result("error", "free");
87
+ let r;
48
88
  try {
49
- const data = await _mock();
50
- if (!(data == null ? void 0 : data.ok)) result = { status: "error", plan: "free" };
51
- else if (data.blocked) result = { status: "blocked", plan: data.plan || "free" };
52
- else result = { status: "valid", plan: data.plan || "free" };
89
+ const data = await _callApi(domain);
90
+ if (!data) r = _result("error", "free");
91
+ else if (!data.ok) r = _result("error", data.plan || "free");
92
+ else if (data.blocked) r = _result("blocked", data.plan || "free");
93
+ else r = _result("valid", data.plan || "free");
53
94
  } catch {
54
- result = { status: "error", plan: "free" };
95
+ r = _result("error", "free");
55
96
  }
56
- _writeCache(result);
57
- return result;
97
+ _writeCache(r);
98
+ return r;
58
99
  }
59
100
 
60
101
  // src/widget.jsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pigmilcom/a11y",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "WCAG 2.1 accessibility widget for React — text size, contrast, dyslexia font, motion reduction, and more.",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -42,7 +42,7 @@
42
42
  "build:js:min": "tsup --config tsup.min.config.mjs",
43
43
  "build:css": "node scripts/build-css.js",
44
44
  "build:css:min": "node scripts/build-css.js",
45
- "build:cdn": "npm run build:css && tsup --config tsup.cdn.config.mjs && node -e \"const f='./dist/a11y.cdn.css'; require('fs').existsSync(f) && require('fs').unlinkSync(f)\"",
45
+ "build:cdn": "npm run build:css && node scripts/obfuscate-cdn.js && tsup --config tsup.cdn.config.mjs && node -e \"const fs=require('fs');const b='./src/license.js.bak';const o='./src/license.js';if(fs.existsSync(b)){if(fs.existsSync(o))fs.unlinkSync(o);fs.renameSync(b,o);}['./dist/a11y.cdn.css','./src/license.cdn.js'].forEach(f=>{try{fs.unlinkSync(f)}catch{}});\"",
46
46
  "build": "npm run build:js && npm run build:js:min && npm run build:css && npm run build:css:min && npm run build:cdn",
47
47
  "dev": "tsup --watch",
48
48
  "prepublishOnly": "npm run build"
@@ -52,6 +52,7 @@
52
52
  "react-dom": ">=17.0.0"
53
53
  },
54
54
  "devDependencies": {
55
+ "javascript-obfuscator": "^5.4.1",
55
56
  "react": "^18.3.1",
56
57
  "react-dom": "^18.3.1",
57
58
  "tsup": "^8.3.0",