@startside/swa 1.0.2 → 1.0.3
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/LICENSE +7 -6
- package/README.md +15 -4
- package/bin/swa.mjs +2 -2
- package/package.json +2 -2
- package/swa/1.0/agents.md +87 -2
- package/swa/1.0/frame.css +245 -0
- package/swa/1.0/frame.js +4 -0
- package/swa/1.0/host.md +126 -0
- package/swa/1.0/quickstart.md +2 -0
- package/swa/1.0/runtime.js +3 -3
- package/swa/1.0/spec.md +193 -37
- package/swa/1.0/swa.d.ts +81 -2
package/LICENSE
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
This package holds two kinds of files, under two licences:
|
|
2
2
|
|
|
3
|
-
- The
|
|
4
|
-
below, which covers them only, not the texts. bin/swa.mjs also
|
|
5
|
-
licences, at the end of this file.
|
|
6
|
-
- The texts (swa/1.0/spec.md, swa/1.0/quickstart.md, swa/1.0/agents.md): the Startside Widget API
|
|
7
|
-
specification, SWA in 60 lines and the guide for
|
|
8
|
-
Attribution 4.0 International licence (CC BY 4.0):
|
|
3
|
+
- The runtimes, their styles, the types and the command (swa/1.0/runtime.js, swa/1.0/frame.js, swa/1.0/frame.css,
|
|
4
|
+
swa/1.0/swa.d.ts, bin/swa.mjs): the MIT License, below, which covers them only, not the texts. bin/swa.mjs also
|
|
5
|
+
holds Acorn and acorn-jsx, under their own MIT licences, at the end of this file.
|
|
6
|
+
- The texts (swa/1.0/spec.md, swa/1.0/quickstart.md, swa/1.0/agents.md, swa/1.0/host.md): the Startside Widget API
|
|
7
|
+
(SWA) 1.0 specification, SWA in 60 lines, the guide for agents and the guide for hosts, © 2026 François Hodierne,
|
|
8
|
+
under the Creative Commons Attribution 4.0 International licence (CC BY 4.0):
|
|
9
|
+
https://creativecommons.org/licenses/by/4.0/
|
|
9
10
|
Their current versions: https://startside.app/swa/1.0/
|
|
10
11
|
|
|
11
12
|
MIT License
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @startside/swa
|
|
2
2
|
|
|
3
|
-
The runtime of the **Startside Widget API (SWA) 1.0**, its TypeScript types, its specification in Markdown,
|
|
4
|
-
command that checks a widget file and inlines its runtime.
|
|
3
|
+
The runtime of the **Startside Widget API (SWA) 1.0**, its TypeScript types, its specification in Markdown, a
|
|
4
|
+
command that checks a widget file and inlines its runtime, and what another host needs to run widgets in its own page.
|
|
5
5
|
|
|
6
6
|
An SWA widget is a single HTML file: its head names it and loads this runtime, a hidden form declares its settings, and
|
|
7
7
|
its scripts draw it through one object, `widget`. Opened on its own, the file runs on a standalone page with the
|
|
@@ -83,6 +83,17 @@ that loads the runtime by its address as the widget's own, and inline again afte
|
|
|
83
83
|
|
|
84
84
|
Or next to a widget's code, with the file copied beside it: `/// <reference path="./swa.d.ts" />`.
|
|
85
85
|
|
|
86
|
+
## Running widgets in your own page
|
|
87
|
+
|
|
88
|
+
Since 1.0.3, for a page that runs SWA widget files the way Startside's dashboard does, each in a sandboxed frame:
|
|
89
|
+
|
|
90
|
+
- `swa/1.0/frame.js`: the runtime a host writes into a widget's frame (not `runtime.js`, which runs a file on its own
|
|
91
|
+
page);
|
|
92
|
+
- `swa/1.0/frame.css`: its base styles, for the frame's host layer;
|
|
93
|
+
- `swa/1.0/host.md`: how: the frame, its document, the config the runtime reads, and the messages a host must answer.
|
|
94
|
+
|
|
95
|
+
RWA files need RWA's runtime, which isn't in this package.
|
|
96
|
+
|
|
86
97
|
## Versions
|
|
87
98
|
|
|
88
99
|
The package has its own version. A patch is a runtime fix, the texts brought up to date, or the command's changes; a
|
|
@@ -91,5 +102,5 @@ remove one. The API's version is the one in the path.
|
|
|
91
102
|
|
|
92
103
|
## Licence
|
|
93
104
|
|
|
94
|
-
The
|
|
95
|
-
`quickstart.md`, `agents.md`): CC BY 4.0, © François Hodierne. `LICENSE` says which is which.
|
|
105
|
+
The runtimes, their styles, the types and the command: MIT; the command holds Acorn and acorn-jsx, MIT too. The texts (`spec.md`,
|
|
106
|
+
`quickstart.md`, `agents.md`, `host.md`): CC BY 4.0, © François Hodierne. `LICENSE` says which is which.
|
package/bin/swa.mjs
CHANGED
|
@@ -20,7 +20,7 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
|
|
|
20
20
|
`:`\r
|
|
21
21
|
`):n=String.fromCharCode(t),this.options.locations&&(++this.curLine,this.lineStart=this.pos),n}jsx_readString(e){let t=``,n=++this.pos;for(;;){this.pos>=this.input.length&&this.raise(this.start,`Unterminated string constant`);let r=this.input.charCodeAt(this.pos);if(r===e)break;r===38?(t+=this.input.slice(n,this.pos),t+=this.jsx_readEntity(),n=this.pos):h(r)?(t+=this.input.slice(n,this.pos),t+=this.jsx_readNewLine(!1),n=this.pos):++this.pos}return t+=this.input.slice(n,this.pos++),this.finishToken(l.string,t)}jsx_readEntity(){let e=``,t=0,a,o=this.input[this.pos];o!==`&`&&this.raise(this.pos,`Entity must start with an ampersand`);let s=++this.pos;for(;this.pos<this.input.length&&t++<10;){if(o=this.input[this.pos++],o===`;`){e[0]===`#`?e[1]===`x`?(e=e.substr(2),r.test(e)&&(a=String.fromCharCode(parseInt(e,16)))):(e=e.substr(1),i.test(e)&&(a=String.fromCharCode(parseInt(e,10)))):a=n[e];break}e+=o}return a||(this.pos=s,`&`)}jsx_readWord(){let e,t=this.pos;do e=this.input.charCodeAt(++this.pos);while(_(e)||e===45);return this.finishToken(u.jsxName,this.input.slice(t,this.pos))}jsx_parseIdentifier(){let e=this.startNode();return this.type===u.jsxName?e.name=this.value:this.type.keyword?e.name=this.type.keyword:this.unexpected(),this.next(),this.finishNode(e,`JSXIdentifier`)}jsx_parseNamespacedName(){let t=this.start,n=this.startLoc,r=this.jsx_parseIdentifier();if(!e.allowNamespaces||!this.eat(l.colon))return r;var i=this.startNodeAt(t,n);return i.namespace=r,i.name=this.jsx_parseIdentifier(),this.finishNode(i,`JSXNamespacedName`)}jsx_parseElementName(){if(this.type===u.jsxTagEnd)return``;let t=this.start,n=this.startLoc,r=this.jsx_parseNamespacedName();for(this.type===l.dot&&r.type===`JSXNamespacedName`&&!e.allowNamespacedObjects&&this.unexpected();this.eat(l.dot);){let e=this.startNodeAt(t,n);e.object=r,e.property=this.jsx_parseIdentifier(),r=this.finishNode(e,`JSXMemberExpression`)}return r}jsx_parseAttributeValue(){switch(this.type){case l.braceL:let e=this.jsx_parseExpressionContainer();return e.expression.type===`JSXEmptyExpression`&&this.raise(e.start,`JSX attributes must only be assigned a non-empty expression`),e;case u.jsxTagStart:case l.string:return this.parseExprAtom();default:this.raise(this.start,`JSX value should be either an expression or a quoted JSX text`)}}jsx_parseEmptyExpression(){let e=this.startNodeAt(this.lastTokEnd,this.lastTokEndLoc);return this.finishNodeAt(e,`JSXEmptyExpression`,this.start,this.startLoc)}jsx_parseExpressionContainer(){let e=this.startNode();return this.next(),e.expression=this.type===l.braceR?this.jsx_parseEmptyExpression():this.parseExpression(),this.expect(l.braceR),this.finishNode(e,`JSXExpressionContainer`)}jsx_parseAttribute(){let e=this.startNode();return this.eat(l.braceL)?(this.expect(l.ellipsis),e.argument=this.parseMaybeAssign(),this.expect(l.braceR),this.finishNode(e,`JSXSpreadAttribute`)):(e.name=this.jsx_parseNamespacedName(),e.value=this.eat(l.eq)?this.jsx_parseAttributeValue():null,this.finishNode(e,`JSXAttribute`))}jsx_parseOpeningElementAt(e,t){let n=this.startNodeAt(e,t);n.attributes=[];let r=this.jsx_parseElementName();for(r&&(n.name=r);this.type!==l.slash&&this.type!==u.jsxTagEnd;)n.attributes.push(this.jsx_parseAttribute());return n.selfClosing=this.eat(l.slash),this.expect(u.jsxTagEnd),this.finishNode(n,r?`JSXOpeningElement`:`JSXOpeningFragment`)}jsx_parseClosingElementAt(e,t){let n=this.startNodeAt(e,t),r=this.jsx_parseElementName();return r&&(n.name=r),this.expect(u.jsxTagEnd),this.finishNode(n,r?`JSXClosingElement`:`JSXClosingFragment`)}jsx_parseElementAt(e,t){let n=this.startNodeAt(e,t),r=[],i=this.jsx_parseOpeningElementAt(e,t),a=null;if(!i.selfClosing){contents:for(;;)switch(this.type){case u.jsxTagStart:if(e=this.start,t=this.startLoc,this.next(),this.eat(l.slash)){a=this.jsx_parseClosingElementAt(e,t);break contents}r.push(this.jsx_parseElementAt(e,t));break;case u.jsxText:r.push(this.parseExprAtom());break;case l.braceL:r.push(this.jsx_parseExpressionContainer());break;default:this.unexpected()}s(a.name)!==s(i.name)&&this.raise(a.start,`Expected corresponding JSX closing tag for <`+s(i.name)+`>`)}let o=i.name?`Element`:`Fragment`;return n[`opening`+o]=i,n[`closing`+o]=a,n.children=r,this.type===l.relational&&this.value===`<`&&this.raise(this.start,`Adjacent JSX elements must be wrapped in an enclosing tag`),this.finishNode(n,`JSX`+o)}jsx_parseText(){let e=this.parseLiteral(this.value);return e.type=`JSXText`,e}jsx_parseElement(){let e=this.start,t=this.startLoc;return this.next(),this.jsx_parseElementAt(e,t)}parseExprAtom(e){return this.type===u.jsxText?this.jsx_parseText():this.type===u.jsxTagStart?this.jsx_parseElement():super.parseExprAtom(e)}readToken(e){let t=this.curContext();if(t===m)return this.jsx_readToken();if(t===f||t===p){if(g(e))return this.jsx_readWord();if(e==62)return++this.pos,this.finishToken(u.jsxTagEnd);if((e===34||e===39)&&t==f)return this.jsx_readString(e)}return e===60&&this.exprAllowed&&this.input.charCodeAt(this.pos+1)!==33?(++this.pos,this.finishToken(u.jsxTagStart)):super.readToken(e)}updateContext(e){if(this.type==l.braceL){var t=this.curContext();t==f?this.context.push(d.b_expr):t==m?this.context.push(d.b_tmpl):super.updateContext(e),this.exprAllowed=!0}else if(this.type===l.slash&&e===u.jsxTagStart)this.context.length-=2,this.context.push(p),this.exprAllowed=!1;else return super.updateContext(e)}}}})))(),1);R.extend((0,Zt.default)());function Qt(e,t){let n=e.slice(0,t);return{line:n.split(`
|
|
22
22
|
`).length,col:t-n.lastIndexOf(`
|
|
23
|
-
`)}}function $t(e){let t=[],n=/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi;for(let r;r=n.exec(e);){let e=/\btype\s*=\s*["']?([^"'\s>]+)/i.exec(r[1])?.[1]?.toLowerCase()??``;t.push({type:e,attrs:r[1],code:r[2],at:r.index+r[0].indexOf(`>`)+1})}return t}function en(e,t,n=[]){if(e&&typeof e.type==`string`){t(e,n);for(let[r,i]of Object.entries(e)){if(r===`loc`||r===`start`||r===`end`)continue;let a=Array.isArray(i)?i:[i];for(let r of a)r&&typeof r==`object`&&typeof r.type==`string`&&en(r,t,[...n,e])}}}function tn(e,t){let n=(e,t)=>{let n=Array.from({length:e.length+1},(e,n)=>[n,...Array(t.length).fill(0)]);for(let e=1;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=e.length;r++)for(let i=1;i<=t.length;i++)n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+(e[r-1]===t[i-1]?0:1));return n[e.length][t.length]},r=t.map(t=>[t,n(e.toLowerCase(),t.toLowerCase())]).sort((e,t)=>e[1]-t[1])[0];return r&&r[1]<=Math.max(2,e.length/3)?r[0]:null}const nn=(e,t)=>{let n=tn(e,t);return n?` (did you mean "${n}"?)`:``},rn=[`load`,`loadcomplete`,`refresh`,`resize`,`updatebody`,`updatepreferences`,`hideedit`,`readall`,`audiostate`,`audioresume`,`videostate`,`fullsize`,`fullscreen`,`settingschange`,`action`],an={description:null,author:null,email:null,website:null,version:null,apiVersion:e=>e===`1.0`||`apiVersion is "1.0" for SWA 1.0`,keywords:null,category:null,unlisted:e=>e===`true`||`unlisted is "true", or absent`,addButton:e=>e===`false`||`addButton is "false", or absent`,chromeColor:null,chromeColorDark:null,background:null,backgroundDark:null,accentColor:null,looks:e=>[`own`,`page`,`both`].includes(e)||`looks is "own", "page" or "both"`,maximize:e=>[`column`,`fill`,`fit`].includes(e)||`maximize is "column", "fill" or "fit"`,maximizeWidth:e=>/^\d+$/.test(e)&&+e>=360&&+e<=1600||`maximizeWidth is a whole number of pixels, 360 to 1600`,autoRefresh:e=>/^\d+$/.test(e)&&+e>0||`autoRefresh is a positive whole number of minutes`,livePreferences:e=>[`false`,`instant`].includes(e)||`livePreferences is "false" or "instant"`,feed:e=>/^https?:\/\//i.test(e)||/^\{[\w-]+\}$/.test(e)||`feed is an http(s) URL template ({setting} for a value, or the whole of it)`,accountService:null,accountScope:null,debugMode:e=>[`true`,`false`].includes(e)||`debugMode is "true", or absent`,export:e=>e===`false`||`export is "false", or absent`},on=[`viewport`,`color-scheme`,`theme-color`,`robots`,`generator`,`referrer`,`application-name`],sn=[`text`,`password`,`hidden`,`checkbox`,`range`,`number`,`url`],cn=[`submit`,`button`,`reset`,`image`],ln={getValue:`widget.settings.get(name)`,getInt:`widget.settings.get(name) (a number for a range)`,getBool:`widget.settings.get(name) (a boolean for a checkbox)`,setValue:`widget.settings.set(name, value)`,deleteValue:`widget.settings.reset(name)`,remember:`widget.storage.memory.set(key, value)`,recall:`await widget.storage.memory.get(key)`,setStored:`widget.storage.local.set(key, value)`,getStored:`await widget.storage.local.get(key)`,loadContent:`widget.fetchFeed(url) (it keeps the feed)`,keptContent:`widget.fetchFeed(url)`,keepContent:`widget.fetchFeed(url)`,callback:`widget.addEventListener(type, listener)`,setCallback:`widget.addEventListener(type, listener)`},un={UWA:`widget.fetch / widget.fetchFeed (8)`,$:`document.getElementById`,$A:`Array.from`,Class:`a class`,Environment:`widget.settings`},dn={setText:`el.textContent = text`,appendText:`el.append(text)`,addClassName:`el.classList.add(name)`,removeClassName:`el.classList.remove(name)`,hasClassName:`el.classList.contains(name)`,getElements:`el.querySelectorAll(selector)`,getElement:`el.querySelector(selector)`,getParent:`el.parentElement`,getChildren:`el.children`,addEvent:`el.addEventListener(type, fn)`,addEvents:`el.addEventListener, once per type`,addListener:`el.addEventListener(type, fn)`,removeListener:`el.removeEventListener(type, fn)`,inject:`parent.append(el)`,setStyles:`Object.assign(el.style, styles)`,setOpacity:`el.style.opacity = value`,setContent:`el.replaceChildren(content)`,addContent:`el.append(content)`,getDimensions:`el.getBoundingClientRect()`,setAttributes:`el.setAttribute, once per attribute`,stripTags:`the text of a parsed document (new DOMParser().parseFromString(html, 'text/html').body.textContent)`,bindAsEventListener:`fn.bind(object)`},fn=[`localStorage`,`sessionStorage`,`indexedDB`],pn=[`content`,`uwa-feeds`],$=(e,t)=>RegExp(`(?:^|\\s)${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,`i`).exec(e)?.slice(1).find(e=>e!==void 0),mn={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`},hn=e=>e.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi,(e,t,n,r)=>{if(r)return mn[r.toLowerCase()];let i=t?Number(t):parseInt(n,16);return i>0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):`�`}),gn=(e,t)=>RegExp(`\\s${t}(\\s|=|/?>|$)`,`i`).test(e),_n=[`.cook`,`.txt`,`.md`,`.csv`,`.json`,`.ics`,`.opml`],vn=[`reset`,`refresh`,`undo`,`redo`,`copy`,`download`,`upload`,`share`,`add`,`remove`,`clear`,`edit`,`search`,`print`,`play`,`pause`,`stop`,`check`,`star`,`info`,`settings`];function yn(e){let t=[...e.matchAll(/<menu\b([^>]*)>([\s\S]*?)<\/menu\s*>/gi)].find(e=>$(e[1],`id`)===`actions`);if(!t)return null;let n=t.index+t[0].indexOf(`>`)+1,r=[...t[2].matchAll(/<button\b([^>]*)>([\s\S]*?)<\/button\s*>/gi)].map(e=>({tag:e[1],inner:e[2],at:n+e.index})),i=t[2].replace(/<button\b[^>]*>[\s\S]*?<\/button\s*>/gi,``).replace(/<!--[\s\S]*?-->/g,``).trim();return{tag:t[1],at:t.index,buttons:r,rest:i}}function bn(e){let t=/<form\b([^>]*\bid\s*=\s*["']?preferences["']?[^>]*)>([\s\S]*?)<\/form\s*>/i.exec(e);if(!t)return null;let n=t.index+t[0].indexOf(`>`)+1,r=[];for(let e of t[2].matchAll(/<(select|input|textarea)\b([^>]*)>/gi)){let i=e[2],a=e[1].toLowerCase(),o=a===`select`?`list`:a===`textarea`?`text`:($(i,`type`)??`text`).toLowerCase(),s=n+e.index,c=[];if(a===`select`){let r=t[2].indexOf(`</select`,e.index);c=[...t[2].slice(e.index,r<0?void 0:r).matchAll(/<option\b([^>]*)>([^<]*)/gi)].map(t=>({value:$(t[1],`value`)??t[2].trim(),tag:t[1],at:n+e.index+t.index}))}r.push({kind:a,type:o,tag:i,at:s,name:$(i,`name`),options:c})}return{tag:t[1],at:t.index,controls:r}}function xn(e,t=``){let n=[],i=(t,r,i)=>n.push({...Qt(e,Math.max(0,r)),level:t,message:i});t&&!/^[a-z0-9-]+\.swa\.html$/.test(r(t))&&i(`error`,0,`An SWA file is named <name>.swa.html, <name> lowercase letters, digits and "-" (4.1): "${r(t)}".`),/^\s*(<!--[\s\S]*?-->\s*)*<!doctype html>/i.test(e)||i(`error`,0,`An SWA file begins with <!doctype html> (4.2).`),/<\?xml\b/i.test(e)&&i(`error`,e.search(/<\?xml\b/i),`No XML declaration: an SWA file is HTML (4.2). UWA files are XHTML.`);let a=e.replace(/(<script\b[^>]*\bdata-runtime\b[^>]*>)([\s\S]*?)(<\/script)/gi,(e,t,n,r)=>t+n.replace(/[^\n]/g,` `)+r),o=a.replace(/(<(style|script)\b[^>]*>)([\s\S]*?)(<\/\2)/gi,(e,t,n,r,i)=>t+r.replace(/[^\n]/g,` `)+i).replace(/"data:[^"]*"|'data:[^']*'/gi,e=>e.replace(/[^\n]/g,` `));/\sxmlns(:\w+)?\s*=/.test(o)&&i(`warning`,o.search(/\sxmlns(:\w+)?\s*=/),`No namespaces needed: an SWA file is HTML (4.2).`),/<!\[CDATA\[/.test(a)&&i(`warning`,a.indexOf(`<![CDATA[`),`No CDATA sections needed: an SWA file is HTML (4.2).`);for(let e of a.matchAll(/\buwa-dark\b/g))i(`warning`,e.index,`uwa-dark is UWA's (4.7): colors by light-dark(light, dark), the rest under :root[data-color-scheme="dark"].`);for(let e of a.matchAll(/prefers-color-scheme/g))i(`warning`,e.index,`prefers-color-scheme is the system's preference, not the page's mode (4.7): light-dark() and data-color-scheme.`);let s=$t(e),c=s.map(e=>({...e,src:$(e.attrs,`src`)})).filter(e=>e.src),l=c.filter(e=>/\/swa\/[^/]+\/runtime\.js(\?|$)/i.test(e.src)),u=c.find(e=>/\/rwa\/[^/]+\/runtime\.js/i.test(e.src)),d=c.filter(e=>/\/js\/UWA\/load\.js\.php/i.test(e.src)),f=s.filter(e=>!$(e.attrs,`src`)&&$(e.attrs,`data-runtime`)!==void 0);for(let e of f){let t=$(e.attrs,`data-runtime`);t!==`swa/1.0`&&i(`error`,e.at,`An inlined runtime is data-runtime="swa/1.0" for SWA 1.0 (4.3), not "${t}".`);let n=$(e.attrs,`data-host`);n!==void 0&&!/^https:\/\/[^/]+\/?$/i.test(n)&&i(`error`,e.at,`data-host is the runtime's host, an https origin (4.3): "${n}".`),/^\s*\/\* SWA \d/.test(e.code)||i(`warning`,e.at,`An inlined runtime holds the text of https://startside.app/swa/1.0/runtime.js, unchanged (4.3).`)}f.length&&(l.length||d.length)&&i(`error`,f[0].at,`One runtime only (4.3): its address or its inlined text, not both.`),f.length>1&&i(`error`,f[1].at,`One runtime script only (4.3).`);let p=/<\/head\s*>/i.exec(e);for(let e of f.slice(0,1))p&&e.at>p.index&&i(`error`,e.at,`The runtime script is in the head (4.3).`);u&&i(`error`,u.at,`This loads RWA's runtime: an RWA file is named .rwa.html and checked by check:rwa.`),l.length||d.length||f.length||i(`error`,0,`No runtime: the head loads https://…/swa/1.0/runtime.js (4.3).`),!l.length&&!f.length&&d.length&&(i(`warning`,d[0].at,`UWA's platform tags are accepted (4.3), but an SWA file loads /swa/1.0/runtime.js.`),/<link\b[^>]*href\s*=\s*["']?[^"'\s>]*\/themes\/uwa\/style\.css/i.test(e)||i(`error`,d[0].at,`UWA's platform tags go together (4.3): the script and the stylesheet /themes/uwa/style.css.`)),l.length>1&&i(`error`,l[1].at,`One runtime script only (4.3).`);for(let t of l.slice(0,1)){let n=/\/swa\/([^/]+)\/runtime\.js/i.exec(t.src)[1];n!==`1.0`&&i(`error`,t.at,`The runtime of SWA 1.0 is /swa/1.0/runtime.js, not /swa/${n}/ (4.3).`),/^https?:\/\//i.test(t.src)?/^http:/i.test(t.src)&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])[:/]/i.test(t.src)&&i(`warning`,t.at,`The runtime's URL SHOULD use https (4.3).`):i(`error`,t.at,`The runtime's URL is absolute (4.3): https://startside.app/swa/1.0/runtime.js (from disk, a relative address finds nothing).`);let r=/<\/head\s*>/i.exec(e);r&&t.at>r.index&&i(`error`,t.at,`The runtime script is in the head (4.3).`);let a=$(t.attrs,`data-host`);a!==void 0&&!/^https:\/\/[^/]+\/?$/i.test(a)&&i(`error`,t.at,`data-host is the runtime's host, an https origin (4.3): "${a}".`);let o=/\/@startside\/swa(@[^/]*)?\//i.exec(t.src);o&&(!o[1]||/^@latest$/i.test(o[1]))&&i(`warning`,t.at,`Name the package's version in the address, @1: ${o[1]?`@latest`:`no version`} can move the file to a release that breaks it (4.3).`)}let m=/<title\b[^>]*>([\s\S]*?)<\/title\s*>/i.exec(e);m?m[1].trim()||i(`error`,m.index,`The <title> is empty: it is the widget's name (4.4).`):i(`error`,0,`The head has a <title>: the widget's name (4.4).`);let h=/* @__PURE__ */ new Set;for(let t of e.matchAll(/<meta\b([^>]*)>/gi)){let e=$(t[1],`name`);if(!e||on.includes(e.toLowerCase()))continue;if(e===`inline`){i(`warning`,t.index,`SWA has no inline mode (10.2): an SWA widget runs framed or on its own page; "inline" is ignored.`);continue}if(!Object.hasOwn(an,e)){i(`warning`,t.index,`"${e}" isn't SWA metadata, and is ignored (4.5)${nn(e,Object.keys(an))}.`);continue}h.has(e)&&i(`warning`,t.index,`"${e}" twice: one is ignored (4.5).`),h.add(e);let n=$(t[1],`content`)??``,r=an[e],a=!r||r(n);a!==!0&&i(`error`,t.index,`${a} (4.5): "${n}".`)}h.has(`description`)||i(`warning`,0,`No description: one line saying what the widget does, in the host's lists (4.5).`);let g=bn(e),_=/* @__PURE__ */ new Map;if(g){gn(g.tag,`hidden`)||i(`error`,g.at,`The settings form carries the hidden attribute (5.1): <form id="preferences" hidden>.`);for(let e of g.controls){if(cn.includes(e.type))continue;if(!e.name){i(`warning`,e.at,`A control without a name declares no setting (5.1).`);continue}_.has(e.name)&&i(`error`,e.at,`"${e.name}" is declared twice: names are unique in the form (5.1).`),_.set(e.name,e),e.kind===`input`&&!sn.includes(e.type)&&i(`warning`,e.at,`An input of type "${e.type}" is read as text (5.2): ${sn.join(`, `)}.`);let t=$(e.tag,`data-commit`);if(t!==void 0&&t!==`ok`&&i(`error`,e.at,`data-commit is "ok" (5.3): "${t}".`),gn(e.tag,`data-load`)){let t=$(e.tag,`data-load`)??``;e.type===`hidden`&&gn(e.tag,`data-share`)||i(`error`,e.at,`data-load goes on a hidden input with data-share (5.3).`),t.length>40&&i(`error`,e.at,`data-load's label is 40 characters at most (5.3): ${t.length}.`)}for(let t of e.options){let e=$(t.tag,`data-feed`);e!==void 0&&e!==`none`&&!/^https?:\/\//i.test(e)&&i(`error`,t.at,`data-feed is an http(s) URL, or "none" (5.3): "${e}".`)}}for(let e of _.values()){let t=$(e.tag,`data-when`);if(!t)continue;let n=/^\s*([\w-]+)\s*(!?=)\s*(.*)$/.exec(t);if(!n){i(`error`,e.at,`data-when is "name=value", "name=a|b" or "name!=value" (5.3): "${t}".`);continue}let r=_.get(n[1]);if(!r)i(`error`,e.at,`data-when names "${n[1]}", which the form doesn't declare${nn(n[1],[..._.keys()])}.`);else if(r.type===`list`)for(let t of n[3].split(`|`))r.options.some(e=>e.value===t.trim())||i(`warning`,e.at,`data-when: "${t.trim()}" isn't one of ${n[1]}'s options.`)}}let ee=yn(e),v=/* @__PURE__ */ new Set,y=!1;if(ee){gn(ee.tag,`hidden`)||i(`error`,ee.at,`The actions' declaration carries the hidden attribute (7.13): <menu id="actions" hidden>.`),ee.rest&&i(`error`,ee.at,`The actions' declaration holds buttons only, its own children (7.13): <button type="button" name="…">Label</button>.`);let e=0;for(let t of ee.buttons){let r=n.length,a=hn($(t.tag,`name`)??``),o=hn(t.inner).replace(/\s+/g,` `).trim();/^[A-Za-z0-9_.-]{1,40}$/.test(a)?v.has(a)?i(`error`,t.at,`The action "${a}" is declared twice: names are unique (7.13).`):v.add(a):i(`error`,t.at,`An action's name is its id: 1 to 40 letters, digits, "-", "_" or "." (7.13)${a?`, not "${a.slice(0,50)}"`:``}.`),/</.test(t.inner)?i(`error`,t.at,`An action's label is text, never markup (7.13).`):o?o.length>40&&i(`error`,t.at,`An action's label is 40 characters at most (7.13): this one has ${o.length}.`):i(`error`,t.at,`An action needs a label: its button's text (7.13).`);let s=$(t.tag,`data-confirm`);s&&hn(s).replace(/\s+/g,` `).trim().length>200&&i(`error`,t.at,`An action's question (data-confirm) is 200 characters at most (7.13).`),n.length===r&&++e===6&&i(`error`,t.at,`Five actions at most (7.13): a host leaves the others out.`);let c=$(t.tag,`data-icon`);c&&!vn.includes(c.trim().toLowerCase())&&!/\p{Extended_Pictographic}/u.test(c)&&i(`warning`,t.at,`data-icon "${c.slice(0,20)}" is neither a generic name (${vn.slice(0,4).join(`, `)}…) nor an emoji (7.13): no picture is shown${nn(c,vn)}.`),$(t.tag,`type`)!==`button`&&i(`warning`,t.at,`An action is <button type="button"> (7.13).`);let l=$(t.tag,`data-save`);if(l!==void 0){y=!0;let e=hn(l).trim().split(/\s+/).filter(Boolean);e.length||i(`error`,t.at,`data-save lists the extensions the action may save, space-separated (7.13): data-save=".cook".`);for(let n of e)/^\.[A-Za-z0-9]{1,10}$/.test(n)?_n.includes(n.toLowerCase())||i(`error`,t.at,`A host saves no "${n}" file (7.13): the data formats ${_n.join(` `)} only${nn(n.toLowerCase(),_n)}.`):i(`error`,t.at,`data-save lists extensions, each a dot and 1 to 10 letters or digits (7.13), not "${n.slice(0,20)}".`)}}}for(let t of e.matchAll(/\bwidget\.setActions\s*\(/g))i(`error`,t.index,`SWA has no widget.setActions: actions are declared in <menu id="actions"> (7.13), and widget.setActionStates changes their state.`);if(!y)for(let e of a.matchAll(/\bwidget\.saveFile\s*\(/g))i(`error`,e.index,`widget.saveFile answers a choice of an action that declares data-save (7.13): the file declares none.`);for(let t of e.matchAll(/\bwidget\.setActionStates\s*\(\s*\{/g)){if(!ee){i(`error`,t.index,`widget.setActionStates changes the state of declared actions: the file declares none (<menu id="actions" hidden>, 7.13).`);continue}let n=/^\s*((?:['"]?[\w.-]+['"]?\s*:\s*\{[^{}]*\}\s*,?\s*)+)\}/.exec(e.slice(t.index+t[0].length));for(let e of n?n[1].matchAll(/['"]?([\w.-]+)['"]?\s*:\s*\{/g):[])v.has(e[1])||i(`error`,t.index,`widget.setActionStates names "${e[1]}", which the file doesn't declare (7.13: a TypeError)${nn(e[1],[...v])}.`)}for(let e of s.filter(e=>!f.includes(e))){if(/^text\/(jsx|babel)$/.test(e.type)){i(`warning`,e.at,`A JSX script (text/jsx) isn't run in an SWA file: JSX templates are RWA's (.rwa.html).`);continue}if(![``,`text/javascript`,`application/javascript`,`module`].includes(e.type)||$(e.attrs,`src`))continue;let t;try{t=R.parse(e.code,{ecmaVersion:`latest`,sourceType:e.type===`module`?`module`:`script`,allowReturnOutsideFunction:!1})}catch(t){i(`error`,e.at+(t.pos??0),`Syntax error: ${String(t.message).replace(/\s*\(\d+:\d+\)$/,``)}.`);continue}let n=t=>e.at+t.start,r=/* @__PURE__ */ new Set;en(t,e=>{e.type===`VariableDeclarator`&&e.id.type===`Identifier`&&r.add(e.id.name),(e.type===`FunctionDeclaration`||e.type===`ClassDeclaration`)&&e.id&&r.add(e.id.name)});let a=c.some(e=>!l.includes(e)&&!d.includes(e)),o=e=>e?.type===`Identifier`?e.name:e?.type===`Literal`?String(e.value):null,s=e=>e?.type===`Identifier`&&e.name===`widget`,u=e=>e[0]?.type===`Literal`&&typeof e[0].value==`string`?e[0].value:null,f=e=>e?.type===`Literal`||e?.type===`TemplateLiteral`&&!e.expressions.length||e?.type===`BinaryExpression`&&e.operator===`+`&&f(e.left)&&f(e.right),p=e=>e?.type===`Literal`&&typeof e.value==`string`||e?.type===`TemplateLiteral`||e?.type===`BinaryExpression`&&e.operator===`+`&&(p(e.left)||p(e.right)),m=e=>e?.type===`TemplateLiteral`&&e.expressions.length>0||e?.type===`BinaryExpression`&&e.operator===`+`&&p(e)&&!f(e),h=`a value in markup becomes markup: fill a template's or an element's textContent instead, and pass the node (7.3, 7.3.1)`;en(t,(e,t)=>{if(e.type===`AssignmentExpression`&&e.left.type===`MemberExpression`&&[`innerHTML`,`outerHTML`].includes(o(e.left.property)??``)&&m(e.right)&&i(`warning`,n(e.right),`${o(e.left.property)} built from values: ${h}.`),e.type===`AssignmentExpression`&&e.left.type===`MemberExpression`&&s(e.left.object)&&/^on[A-Z]/.test(o(e.left.property)??``)&&i(`error`,n(e),`widget.${o(e.left.property)} is UWA's: an SWA widget listens with widget.addEventListener('${o(e.left.property).slice(2).toLowerCase()}', …) (7.6).`),e.type===`MemberExpression`&&!e.computed){let r=o(e.property);s(e.object)&&Object.hasOwn(ln,r)&&i(`error`,n(e),`widget.${r} is UWA's: in SWA, ${ln[r]}.`),!s(e.object)&&Object.hasOwn(dn,r)&&t.at(-1)?.type===`CallExpression`&&t.at(-1).callee===e&&i(a?`warning`:`error`,n(e.property),`.${r}() is UWA's element extension, absent in SWA (9): ${dn[r]}.`),e.object.type===`Identifier`&&e.object.name===`document`&&r===`cookie`&&i(`error`,n(e),`No cookies: a framed widget has no storage of its own; widget.storage instead (4.8, 7.8).`)}if(e.type===`Identifier`&&!r.has(e.name)){let r=t.at(-1),o=r?.type===`MemberExpression`&&r.property===e&&!r.computed,s=r?.type===`Property`&&r.key===e&&!r.computed;!o&&!s&&(Object.hasOwn(un,e.name)&&!(e.name===`$`&&a)&&i(`error`,n(e),e.name===`UWA`?`There's no UWA in an SWA widget (8, 9): ${un.UWA}.`:`${e.name} is UWA's, absent in SWA (9): ${un[e.name]}.`),fn.includes(e.name)&&i(`error`,n(e),`No ${e.name}: a framed widget has no storage of its own; widget.storage instead (4.8, 7.8).`))}if(e.type===`CallExpression`){let t=e.callee,a=t.type===`Identifier`&&!r.has(t.name)?t.name:t.type===`MemberExpression`&&t.object.type===`Identifier`&&[`window`,`self`,`globalThis`].includes(t.object.name)?o(t.property):null;[`alert`,`confirm`,`prompt`].includes(a)&&i(`warning`,n(e),`${a}() does nothing in a frame (10.1: ${a===`confirm`?`it answers false`:a===`prompt`?`it answers null`:`nothing shows`}): ask in the widget's own box.`)}if(e.type===`CallExpression`&&e.callee.type===`MemberExpression`){let t=e.callee,r=o(t.property),a=u(e.arguments);if(t.object.type===`MemberExpression`&&s(t.object.object)&&o(t.object.property)===`settings`&&[`get`,`set`,`reset`].includes(r)&&a!==null){if(!_.has(a)&&a!==`title`)i(r===`get`?`warning`:`error`,n(e.arguments[0]),`widget.settings.${r}('${a}'): the form declares no "${a}" (7.5: ${r===`get`?`it gives undefined`:`a TypeError`})${nn(a,[..._.keys()])}.`);else if(r===`set`&&_.has(a)){let t=_.get(a),r=e.arguments[1],o=r?.type===`Literal`?typeof r.value:null;t.type===`checkbox`&&o&&o!==`boolean`&&i(`error`,n(r),`"${a}" is a checkbox: set it to true or false (7.5).`),(t.type===`range`||t.type===`number`)&&o&&o!==`number`&&i(`error`,n(r),`"${a}" is a number: set it to a number (7.5).`)}}t.object.type===`MemberExpression`&&o(t.object.property)===`memory`&&t.object.object.type===`MemberExpression`&&s(t.object.object.object)&&a&&pn.includes(a)&&i(`error`,n(e.arguments[0]),`"${a}" is a key the runtime keeps its own data under (7.8): another name.`),(s(t.object)&&[`setBody`,`addBody`].includes(r)||r===`insertAdjacentHTML`)&&m(e.arguments[+(r===`insertAdjacentHTML`)])&&i(`warning`,n(e.arguments[+(r===`insertAdjacentHTML`)]),`${r}() given markup built from values: ${h}.`),s(t.object)&&r===`addEventListener`&&a!==null&&!rn.includes(a)&&i(`warning`,n(e.arguments[0]),`SWA fires no "${a}" event (7.6.1)${nn(a,rn)}.`)}})}return n.sort((e,t)=>e.line-t.line||e.col-t.col)}const Sn=c(new URL(`../swa/1.0/runtime.js`,import.meta.url)),Cn=c(new URL(`../package.json`,import.meta.url)),wn=`Usage: npx @startside/swa <command>
|
|
23
|
+
`)}}function $t(e){let t=[],n=/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi;for(let r;r=n.exec(e);){let e=/\btype\s*=\s*["']?([^"'\s>]+)/i.exec(r[1])?.[1]?.toLowerCase()??``;t.push({type:e,attrs:r[1],code:r[2],at:r.index+r[0].indexOf(`>`)+1})}return t}function en(e,t,n=[]){if(e&&typeof e.type==`string`){t(e,n);for(let[r,i]of Object.entries(e)){if(r===`loc`||r===`start`||r===`end`)continue;let a=Array.isArray(i)?i:[i];for(let r of a)r&&typeof r==`object`&&typeof r.type==`string`&&en(r,t,[...n,e])}}}function tn(e,t){let n=(e,t)=>{let n=Array.from({length:e.length+1},(e,n)=>[n,...Array(t.length).fill(0)]);for(let e=1;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=e.length;r++)for(let i=1;i<=t.length;i++)n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+(e[r-1]===t[i-1]?0:1));return n[e.length][t.length]},r=t.map(t=>[t,n(e.toLowerCase(),t.toLowerCase())]).sort((e,t)=>e[1]-t[1])[0];return r&&r[1]<=Math.max(2,e.length/3)?r[0]:null}const nn=(e,t)=>{let n=tn(e,t);return n?` (did you mean "${n}"?)`:``},rn=[`load`,`loadcomplete`,`refresh`,`resize`,`updatebody`,`updatepreferences`,`hideedit`,`readall`,`audiostate`,`audioresume`,`videostate`,`fullsize`,`fullscreen`,`settingschange`,`action`,`photodelete`,`storagechange`,`fileschange`],an={description:null,author:null,email:null,website:null,version:null,apiVersion:e=>e===`1.0`||`apiVersion is "1.0" for SWA 1.0`,keywords:null,category:null,unlisted:e=>e===`true`||`unlisted is "true", or absent`,addButton:e=>e===`false`||`addButton is "false", or absent`,chromeColor:null,chromeColorDark:null,background:null,backgroundDark:null,accentColor:null,looks:e=>[`own`,`page`,`both`].includes(e)||`looks is "own", "page" or "both"`,maximize:e=>[`column`,`fill`,`fit`].includes(e)||`maximize is "column", "fill" or "fit"`,maximizeWidth:e=>/^\d+$/.test(e)&&+e>=360&&+e<=1600||`maximizeWidth is a whole number of pixels, 360 to 1600`,autoRefresh:e=>/^\d+$/.test(e)&&+e>0||`autoRefresh is a positive whole number of minutes`,livePreferences:e=>[`false`,`instant`].includes(e)||`livePreferences is "false" or "instant"`,feed:e=>/^https?:\/\//i.test(e)||/^\{[\w-]+\}$/.test(e)||`feed is an http(s) URL template ({setting} for a value, or the whole of it)`,accountService:null,accountScope:null,debugMode:e=>[`true`,`false`].includes(e)||`debugMode is "true", or absent`,export:e=>e===`false`||`export is "false", or absent`,acceptFiles:e=>/^\s*\.[A-Za-z0-9]{1,10}(\s+\.[A-Za-z0-9]{1,10})*\s*$/.test(e)||`acceptFiles lists the file extensions the widget takes when dropped on it, space-separated: ".gpx"`},on=[`viewport`,`color-scheme`,`theme-color`,`robots`,`generator`,`referrer`,`application-name`],sn=[`text`,`password`,`hidden`,`checkbox`,`range`,`number`,`url`],cn=[`submit`,`button`,`reset`,`image`],ln={getValue:`widget.settings.get(name)`,getInt:`widget.settings.get(name) (a number for a range)`,getBool:`widget.settings.get(name) (a boolean for a checkbox)`,setValue:`widget.settings.set(name, value)`,deleteValue:`widget.settings.reset(name)`,remember:`widget.storage.memory.set(key, value)`,recall:`await widget.storage.memory.get(key)`,setStored:`widget.storage.local.set(key, value)`,getStored:`await widget.storage.local.get(key)`,loadContent:`widget.fetchFeed(url) (it keeps the feed)`,keptContent:`widget.fetchFeed(url)`,keepContent:`widget.fetchFeed(url)`,callback:`widget.addEventListener(type, listener)`,setCallback:`widget.addEventListener(type, listener)`},un={UWA:`widget.fetch / widget.fetchFeed (8)`,$:`document.getElementById`,$A:`Array.from`,Class:`a class`,Environment:`widget.settings`},dn={setText:`el.textContent = text`,appendText:`el.append(text)`,addClassName:`el.classList.add(name)`,removeClassName:`el.classList.remove(name)`,hasClassName:`el.classList.contains(name)`,getElements:`el.querySelectorAll(selector)`,getElement:`el.querySelector(selector)`,getParent:`el.parentElement`,getChildren:`el.children`,addEvent:`el.addEventListener(type, fn)`,addEvents:`el.addEventListener, once per type`,addListener:`el.addEventListener(type, fn)`,removeListener:`el.removeEventListener(type, fn)`,inject:`parent.append(el)`,setStyles:`Object.assign(el.style, styles)`,setOpacity:`el.style.opacity = value`,setContent:`el.replaceChildren(content)`,addContent:`el.append(content)`,getDimensions:`el.getBoundingClientRect()`,setAttributes:`el.setAttribute, once per attribute`,stripTags:`the text of a parsed document (new DOMParser().parseFromString(html, 'text/html').body.textContent)`,bindAsEventListener:`fn.bind(object)`},fn=[`localStorage`,`sessionStorage`,`indexedDB`],pn=[`content`,`uwa-feeds`],$=(e,t)=>RegExp(`(?:^|\\s)${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,`i`).exec(e)?.slice(1).find(e=>e!==void 0),mn={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`},hn=e=>e.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi,(e,t,n,r)=>{if(r)return mn[r.toLowerCase()];let i=t?Number(t):parseInt(n,16);return i>0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):`�`}),gn=(e,t)=>RegExp(`\\s${t}(\\s|=|/?>|$)`,`i`).test(e),_n=[`.cook`,`.txt`,`.md`,`.csv`,`.json`,`.ics`,`.opml`,`.gpx`],vn=[`reset`,`refresh`,`undo`,`redo`,`copy`,`download`,`upload`,`share`,`add`,`remove`,`clear`,`edit`,`search`,`print`,`play`,`pause`,`stop`,`check`,`star`,`info`,`settings`];function yn(e){let t=[...e.matchAll(/<menu\b([^>]*)>([\s\S]*?)<\/menu\s*>/gi)].find(e=>$(e[1],`id`)===`actions`);if(!t)return null;let n=t.index+t[0].indexOf(`>`)+1,r=[...t[2].matchAll(/<button\b([^>]*)>([\s\S]*?)<\/button\s*>/gi)].map(e=>({tag:e[1],inner:e[2],at:n+e.index})),i=t[2].replace(/<button\b[^>]*>[\s\S]*?<\/button\s*>/gi,``).replace(/<!--[\s\S]*?-->/g,``).trim();return{tag:t[1],at:t.index,buttons:r,rest:i}}function bn(e){let t=/<form\b([^>]*\bid\s*=\s*["']?preferences["']?[^>]*)>([\s\S]*?)<\/form\s*>/i.exec(e);if(!t)return null;let n=t.index+t[0].indexOf(`>`)+1,r=[];for(let e of t[2].matchAll(/<(select|input|textarea)\b([^>]*)>/gi)){let i=e[2],a=e[1].toLowerCase(),o=a===`select`?`list`:a===`textarea`?`text`:($(i,`type`)??`text`).toLowerCase(),s=n+e.index,c=[];if(a===`select`){let r=t[2].indexOf(`</select`,e.index);c=[...t[2].slice(e.index,r<0?void 0:r).matchAll(/<option\b([^>]*)>([^<]*)/gi)].map(t=>({value:$(t[1],`value`)??t[2].trim(),tag:t[1],at:n+e.index+t.index}))}r.push({kind:a,type:o,tag:i,at:s,name:$(i,`name`),options:c})}let i=[...t[2].matchAll(/<label\b[^>]*>([\s\S]*?)<\/label\s*>/gi)].map(e=>({at:n+e.index,text:e[1].replace(/<(select|textarea)\b[\s\S]*?<\/\1\s*>/gi,``).replace(/<[^>]*>/g,``).replace(/\s+/g,` `).trim()}));return{tag:t[1],at:t.index,controls:r,labels:i}}function xn(e,t=``){let n=[],i=(t,r,i)=>n.push({...Qt(e,Math.max(0,r)),level:t,message:i});t&&!/^[a-z0-9-]+\.swa\.html$/.test(r(t))&&i(`error`,0,`An SWA file is named <name>.swa.html, <name> lowercase letters, digits and "-" (4.1): "${r(t)}".`),/^\s*(<!--[\s\S]*?-->\s*)*<!doctype html>/i.test(e)||i(`error`,0,`An SWA file begins with <!doctype html> (4.2).`),/<\?xml\b/i.test(e)&&i(`error`,e.search(/<\?xml\b/i),`No XML declaration: an SWA file is HTML (4.2). UWA files are XHTML.`);let a=e.replace(/(<script\b[^>]*\bdata-runtime\b[^>]*>)([\s\S]*?)(<\/script)/gi,(e,t,n,r)=>t+n.replace(/[^\n]/g,` `)+r),o=a.replace(/(<(style|script)\b[^>]*>)([\s\S]*?)(<\/\2)/gi,(e,t,n,r,i)=>t+r.replace(/[^\n]/g,` `)+i).replace(/"data:[^"]*"|'data:[^']*'/gi,e=>e.replace(/[^\n]/g,` `));/\sxmlns(:\w+)?\s*=/.test(o)&&i(`warning`,o.search(/\sxmlns(:\w+)?\s*=/),`No namespaces needed: an SWA file is HTML (4.2).`),/<!\[CDATA\[/.test(a)&&i(`warning`,a.indexOf(`<![CDATA[`),`No CDATA sections needed: an SWA file is HTML (4.2).`);for(let e of a.matchAll(/\buwa-dark\b/g))i(`warning`,e.index,`uwa-dark is UWA's (4.7): colors by light-dark(light, dark), the rest under :root[data-color-scheme="dark"].`);for(let e of a.matchAll(/prefers-color-scheme/g))i(`warning`,e.index,`prefers-color-scheme is the system's preference, not the page's mode (4.7): light-dark() and data-color-scheme.`);let s=$t(e),c=s.map(e=>({...e,src:$(e.attrs,`src`)})).filter(e=>e.src),l=c.filter(e=>/\/swa\/[^/]+\/runtime\.js(\?|$)/i.test(e.src)),u=c.find(e=>/\/rwa\/[^/]+\/runtime\.js/i.test(e.src)),d=c.filter(e=>/\/js\/UWA\/load\.js\.php/i.test(e.src)),f=s.filter(e=>!$(e.attrs,`src`)&&$(e.attrs,`data-runtime`)!==void 0);for(let e of f){let t=$(e.attrs,`data-runtime`);t!==`swa/1.0`&&i(`error`,e.at,`An inlined runtime is data-runtime="swa/1.0" for SWA 1.0 (4.3), not "${t}".`);let n=$(e.attrs,`data-host`);n!==void 0&&!/^https:\/\/[^/]+\/?$/i.test(n)&&i(`error`,e.at,`data-host is the runtime's host, an https origin (4.3): "${n}".`),/^\s*\/\* SWA \d/.test(e.code)||i(`warning`,e.at,`An inlined runtime holds the text of https://startside.app/swa/1.0/runtime.js, unchanged (4.3).`)}f.length&&(l.length||d.length)&&i(`error`,f[0].at,`One runtime only (4.3): its address or its inlined text, not both.`),f.length>1&&i(`error`,f[1].at,`One runtime script only (4.3).`);let p=/<\/head\s*>/i.exec(e);for(let e of f.slice(0,1))p&&e.at>p.index&&i(`error`,e.at,`The runtime script is in the head (4.3).`);u&&i(`error`,u.at,`This loads RWA's runtime: an RWA file is named .rwa.html and checked by check:rwa.`),l.length||d.length||f.length||i(`error`,0,`No runtime: the head loads https://…/swa/1.0/runtime.js (4.3).`),!l.length&&!f.length&&d.length&&(i(`warning`,d[0].at,`UWA's platform tags are accepted (4.3), but an SWA file loads /swa/1.0/runtime.js.`),/<link\b[^>]*href\s*=\s*["']?[^"'\s>]*\/themes\/uwa\/style\.css/i.test(e)||i(`error`,d[0].at,`UWA's platform tags go together (4.3): the script and the stylesheet /themes/uwa/style.css.`)),l.length>1&&i(`error`,l[1].at,`One runtime script only (4.3).`);for(let t of l.slice(0,1)){let n=/\/swa\/([^/]+)\/runtime\.js/i.exec(t.src)[1];n!==`1.0`&&i(`error`,t.at,`The runtime of SWA 1.0 is /swa/1.0/runtime.js, not /swa/${n}/ (4.3).`),/^https?:\/\//i.test(t.src)?/^http:/i.test(t.src)&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])[:/]/i.test(t.src)&&i(`warning`,t.at,`The runtime's URL SHOULD use https (4.3).`):i(`error`,t.at,`The runtime's URL is absolute (4.3): https://startside.app/swa/1.0/runtime.js (from disk, a relative address finds nothing).`);let r=/<\/head\s*>/i.exec(e);r&&t.at>r.index&&i(`error`,t.at,`The runtime script is in the head (4.3).`);let a=$(t.attrs,`data-host`);a!==void 0&&!/^https:\/\/[^/]+\/?$/i.test(a)&&i(`error`,t.at,`data-host is the runtime's host, an https origin (4.3): "${a}".`);let o=/\/@startside\/swa(@[^/]*)?\//i.exec(t.src);o&&(!o[1]||/^@latest$/i.test(o[1]))&&i(`warning`,t.at,`Name the package's version in the address, @1: ${o[1]?`@latest`:`no version`} can move the file to a release that breaks it (4.3).`)}let m=/<title\b[^>]*>([\s\S]*?)<\/title\s*>/i.exec(e);m?m[1].trim()||i(`error`,m.index,`The <title> is empty: it is the widget's name (4.4).`):i(`error`,0,`The head has a <title>: the widget's name (4.4).`);let h=/* @__PURE__ */ new Set;for(let t of e.matchAll(/<meta\b([^>]*)>/gi)){let e=$(t[1],`name`);if(!e||on.includes(e.toLowerCase()))continue;if(e===`inline`){i(`warning`,t.index,`SWA has no inline mode (10.2): an SWA widget runs framed or on its own page; "inline" is ignored.`);continue}if(!Object.hasOwn(an,e)){i(`warning`,t.index,`"${e}" isn't SWA metadata, and is ignored (4.5)${nn(e,Object.keys(an))}.`);continue}h.has(e)&&i(`warning`,t.index,`"${e}" twice: one is ignored (4.5).`),h.add(e);let n=$(t[1],`content`)??``,r=an[e],a=!r||r(n);a!==!0&&i(`error`,t.index,`${a} (4.5): "${n}".`)}h.has(`description`)||i(`warning`,0,`No description: one line saying what the widget does, in the host's lists (4.5).`);let g=bn(e),_=/* @__PURE__ */ new Map;if(g){gn(g.tag,`hidden`)||i(`error`,g.at,`The settings form carries the hidden attribute (5.1): <form id="preferences" hidden>.`);for(let e of g.labels)/[::]$/.test(e.text)&&i(`warning`,e.at,`A label without its colon (5.2): the host adds one ("${e.text}").`);for(let e of g.controls){if(cn.includes(e.type))continue;if(!e.name){i(`warning`,e.at,`A control without a name declares no setting (5.1).`);continue}_.has(e.name)&&i(`error`,e.at,`"${e.name}" is declared twice: names are unique in the form (5.1).`),_.set(e.name,e),e.kind===`input`&&!sn.includes(e.type)&&i(`warning`,e.at,`An input of type "${e.type}" is read as text (5.2): ${sn.join(`, `)}.`);let t=$(e.tag,`data-commit`);if(t!==void 0&&t!==`ok`&&i(`error`,e.at,`data-commit is "ok" (5.3): "${t}".`),e.name===`countInTab`&&(e.type===`checkbox`?gn(e.tag,`checked`)||i(`error`,e.at,`countInTab is declared checked (7.5): the count adds up until the person unticks it.`):i(`error`,e.at,`countInTab is a checkbox (7.5).`)),gn(e.tag,`data-load`)){let t=$(e.tag,`data-load`)??``;e.type===`hidden`&&gn(e.tag,`data-share`)||i(`error`,e.at,`data-load goes on a hidden input with data-share (5.3).`),t.length>40&&i(`error`,e.at,`data-load's label is 40 characters at most (5.3): ${t.length}.`)}gn(e.tag,`data-key-for`)&&(e.type===`password`?Sn($(e.tag,`data-key-for`))||i(`error`,e.at,`data-key-for is an https origin, no path (5.3): "${$(e.tag,`data-key-for`)??``}".`):i(`error`,e.at,`data-key-for goes on a password input (5.3).`),e.type===`password`&&$(e.tag,`value`)&&i(`error`,e.at,`A key for a site has no value in the file: the person adds their own (5.3).`));for(let t of e.options){let e=$(t.tag,`data-feed`);e!==void 0&&e!==`none`&&!/^https?:\/\//i.test(e)&&i(`error`,t.at,`data-feed is an http(s) URL, or "none" (5.3): "${e}".`)}}for(let e of _.values()){let t=$(e.tag,`data-when`);if(!t)continue;let n=/^\s*([\w-]+)\s*(!?=)\s*(.*)$/.exec(t);if(!n){i(`error`,e.at,`data-when is "name=value", "name=a|b" or "name!=value" (5.3): "${t}".`);continue}let r=_.get(n[1]);if(!r)i(`error`,e.at,`data-when names "${n[1]}", which the form doesn't declare${nn(n[1],[..._.keys()])}.`);else if(r.type===`list`)for(let t of n[3].split(`|`))r.options.some(e=>e.value===t.trim())||i(`warning`,e.at,`data-when: "${t.trim()}" isn't one of ${n[1]}'s options.`)}}let ee=yn(e),v=/* @__PURE__ */ new Set,y=!1;if(ee){gn(ee.tag,`hidden`)||i(`error`,ee.at,`The actions' declaration carries the hidden attribute (7.13): <menu id="actions" hidden>.`),ee.rest&&i(`error`,ee.at,`The actions' declaration holds buttons only, its own children (7.13): <button type="button" name="…">Label</button>.`);let e=0;for(let t of ee.buttons){let r=n.length,a=hn($(t.tag,`name`)??``),o=hn(t.inner).replace(/\s+/g,` `).trim();/^[A-Za-z0-9_.-]{1,40}$/.test(a)?v.has(a)?i(`error`,t.at,`The action "${a}" is declared twice: names are unique (7.13).`):v.add(a):i(`error`,t.at,`An action's name is its id: 1 to 40 letters, digits, "-", "_" or "." (7.13)${a?`, not "${a.slice(0,50)}"`:``}.`),/</.test(t.inner)?i(`error`,t.at,`An action's label is text, never markup (7.13).`):o?o.length>40&&i(`error`,t.at,`An action's label is 40 characters at most (7.13): this one has ${o.length}.`):i(`error`,t.at,`An action needs a label: its button's text (7.13).`);let s=$(t.tag,`data-confirm`);s&&hn(s).replace(/\s+/g,` `).trim().length>200&&i(`error`,t.at,`An action's question (data-confirm) is 200 characters at most (7.13).`),n.length===r&&++e===6&&i(`error`,t.at,`Five actions at most (7.13): a host leaves the others out.`);let c=$(t.tag,`data-icon`);c&&!vn.includes(c.trim().toLowerCase())&&!/\p{Extended_Pictographic}/u.test(c)&&i(`warning`,t.at,`data-icon "${c.slice(0,20)}" is neither a generic name (${vn.slice(0,4).join(`, `)}…) nor an emoji (7.13): no picture is shown${nn(c,vn)}.`),$(t.tag,`type`)!==`button`&&i(`warning`,t.at,`An action is <button type="button"> (7.13).`);let l=$(t.tag,`data-save`);if(l!==void 0){y=!0;let e=hn(l).trim().split(/\s+/).filter(Boolean);e.length||i(`error`,t.at,`data-save lists the extensions the action may save, space-separated (7.13): data-save=".cook".`);for(let n of e)/^\.[A-Za-z0-9]{1,10}$/.test(n)?_n.includes(n.toLowerCase())||i(`error`,t.at,`A host saves no "${n}" file (7.13): the data formats ${_n.join(` `)} only${nn(n.toLowerCase(),_n)}.`):i(`error`,t.at,`data-save lists extensions, each a dot and 1 to 10 letters or digits (7.13), not "${n.slice(0,20)}".`)}}}for(let t of e.matchAll(/\bwidget\.setActions\s*\(/g))i(`error`,t.index,`SWA has no widget.setActions: actions are declared in <menu id="actions"> (7.13), and widget.setActionStates changes their state.`);if(!y)for(let e of a.matchAll(/\bwidget\.saveFile\s*\(/g))i(`error`,e.index,`widget.saveFile answers a choice of an action that declares data-save (7.13): the file declares none.`);for(let t of e.matchAll(/\bwidget\.setActionStates\s*\(\s*\{/g)){if(!ee){i(`error`,t.index,`widget.setActionStates changes the state of declared actions: the file declares none (<menu id="actions" hidden>, 7.13).`);continue}let n=/^\s*((?:['"]?[\w.-]+['"]?\s*:\s*\{[^{}]*\}\s*,?\s*)+)\}/.exec(e.slice(t.index+t[0].length));for(let e of n?n[1].matchAll(/['"]?([\w.-]+)['"]?\s*:\s*\{/g):[])v.has(e[1])||i(`error`,t.index,`widget.setActionStates names "${e[1]}", which the file doesn't declare (7.13: a TypeError)${nn(e[1],[...v])}.`)}for(let e of s.filter(e=>!f.includes(e))){if(/^text\/(jsx|babel)$/.test(e.type)){i(`warning`,e.at,`A JSX script (text/jsx) isn't run in an SWA file: JSX templates are RWA's (.rwa.html).`);continue}if(![``,`text/javascript`,`application/javascript`,`module`].includes(e.type)||$(e.attrs,`src`))continue;let t;try{t=R.parse(e.code,{ecmaVersion:`latest`,sourceType:e.type===`module`?`module`:`script`,allowReturnOutsideFunction:!1})}catch(t){i(`error`,e.at+(t.pos??0),`Syntax error: ${String(t.message).replace(/\s*\(\d+:\d+\)$/,``)}.`);continue}let n=t=>e.at+t.start,r=/* @__PURE__ */ new Set;en(t,e=>{e.type===`VariableDeclarator`&&e.id.type===`Identifier`&&r.add(e.id.name),(e.type===`FunctionDeclaration`||e.type===`ClassDeclaration`)&&e.id&&r.add(e.id.name)});let a=c.some(e=>!l.includes(e)&&!d.includes(e)),o=e=>e?.type===`Identifier`?e.name:e?.type===`Literal`?String(e.value):null,s=e=>e?.type===`Identifier`&&e.name===`widget`,u=e=>e[0]?.type===`Literal`&&typeof e[0].value==`string`?e[0].value:null,f=e=>e?.type===`Literal`||e?.type===`TemplateLiteral`&&!e.expressions.length||e?.type===`BinaryExpression`&&e.operator===`+`&&f(e.left)&&f(e.right),p=e=>e?.type===`Literal`&&typeof e.value==`string`||e?.type===`TemplateLiteral`||e?.type===`BinaryExpression`&&e.operator===`+`&&(p(e.left)||p(e.right)),m=e=>e?.type===`TemplateLiteral`&&e.expressions.length>0||e?.type===`BinaryExpression`&&e.operator===`+`&&p(e)&&!f(e),h=`a value in markup becomes markup: fill a template's or an element's textContent instead, and pass the node (7.3, 7.3.1)`;en(t,(e,t)=>{if(e.type===`AssignmentExpression`&&e.left.type===`MemberExpression`&&[`innerHTML`,`outerHTML`].includes(o(e.left.property)??``)&&m(e.right)&&i(`warning`,n(e.right),`${o(e.left.property)} built from values: ${h}.`),e.type===`AssignmentExpression`&&e.left.type===`MemberExpression`&&s(e.left.object)&&/^on[A-Z]/.test(o(e.left.property)??``)&&i(`error`,n(e),`widget.${o(e.left.property)} is UWA's: an SWA widget listens with widget.addEventListener('${o(e.left.property).slice(2).toLowerCase()}', …) (7.6).`),e.type===`MemberExpression`&&!e.computed){let r=o(e.property);s(e.object)&&Object.hasOwn(ln,r)&&i(`error`,n(e),`widget.${r} is UWA's: in SWA, ${ln[r]}.`),!s(e.object)&&Object.hasOwn(dn,r)&&t.at(-1)?.type===`CallExpression`&&t.at(-1).callee===e&&i(a?`warning`:`error`,n(e.property),`.${r}() is UWA's element extension, absent in SWA (9): ${dn[r]}.`),e.object.type===`Identifier`&&e.object.name===`document`&&r===`cookie`&&i(`error`,n(e),`No cookies: a framed widget has no storage of its own; widget.storage instead (4.8, 7.8).`)}if(e.type===`Identifier`&&!r.has(e.name)){let r=t.at(-1),o=r?.type===`MemberExpression`&&r.property===e&&!r.computed,s=r?.type===`Property`&&r.key===e&&!r.computed;!o&&!s&&(Object.hasOwn(un,e.name)&&!(e.name===`$`&&a)&&i(`error`,n(e),e.name===`UWA`?`There's no UWA in an SWA widget (8, 9): ${un.UWA}.`:`${e.name} is UWA's, absent in SWA (9): ${un[e.name]}.`),fn.includes(e.name)&&i(`error`,n(e),`No ${e.name}: a framed widget has no storage of its own; widget.storage instead (4.8, 7.8).`))}if(e.type===`CallExpression`){let t=e.callee,a=t.type===`Identifier`&&!r.has(t.name)?t.name:t.type===`MemberExpression`&&t.object.type===`Identifier`&&[`window`,`self`,`globalThis`].includes(t.object.name)?o(t.property):null;[`alert`,`confirm`,`prompt`].includes(a)&&i(`warning`,n(e),`${a}() does nothing in a frame (10.1: ${a===`confirm`?`it answers false`:a===`prompt`?`it answers null`:`nothing shows`}): ask in the widget's own box.`)}if(e.type===`CallExpression`&&e.callee.type===`MemberExpression`){let t=e.callee,r=o(t.property),a=u(e.arguments);if(t.object.type===`MemberExpression`&&s(t.object.object)&&o(t.object.property)===`settings`&&[`get`,`set`,`reset`].includes(r)&&a!==null){if(!_.has(a)&&a!==`title`)i(r===`get`?`warning`:`error`,n(e.arguments[0]),`widget.settings.${r}('${a}'): the form declares no "${a}" (7.5: ${r===`get`?`it gives undefined`:`a TypeError`})${nn(a,[..._.keys()])}.`);else if(r===`set`&&_.has(a)){let t=_.get(a),r=e.arguments[1],o=r?.type===`Literal`?typeof r.value:null;t.type===`checkbox`&&o&&o!==`boolean`&&i(`error`,n(r),`"${a}" is a checkbox: set it to true or false (7.5).`),(t.type===`range`||t.type===`number`)&&o&&o!==`number`&&i(`error`,n(r),`"${a}" is a number: set it to a number (7.5).`)}}t.object.type===`MemberExpression`&&o(t.object.property)===`memory`&&t.object.object.type===`MemberExpression`&&s(t.object.object.object)&&a&&pn.includes(a)&&i(`error`,n(e.arguments[0]),`"${a}" is a key the runtime keeps its own data under (7.8): another name.`),(s(t.object)&&[`setBody`,`addBody`].includes(r)||r===`insertAdjacentHTML`)&&m(e.arguments[+(r===`insertAdjacentHTML`)])&&i(`warning`,n(e.arguments[+(r===`insertAdjacentHTML`)]),`${r}() given markup built from values: ${h}.`),s(t.object)&&r===`addEventListener`&&a!==null&&!rn.includes(a)&&i(`warning`,n(e.arguments[0]),`SWA fires no "${a}" event (7.6.1)${nn(a,rn)}.`)}})}return n.sort((e,t)=>e.line-t.line||e.col-t.col)}function Sn(e){let t=typeof e==`string`?e.trim():``;if(!/^https:\/\/[^\s/?#@\\]+\/?$/i.test(t))return null;try{let e=new URL(t);return e.protocol===`https:`&&!e.username&&!e.password&&!e.search&&!e.hash&&e.pathname===`/`?e.origin:null}catch{return null}}const Cn=c(new URL(`../swa/1.0/runtime.js`,import.meta.url)),wn=c(new URL(`../package.json`,import.meta.url)),Tn=`Usage: npx @startside/swa <command>
|
|
24
24
|
|
|
25
25
|
validate <files…> [--json] Check SWA widget files (.swa.html) without running them:
|
|
26
26
|
file:line:col: error|warning: message, each citing SWA 1.0's section.
|
|
@@ -30,4 +30,4 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
|
|
|
30
30
|
Default output: <name>-inline.swa.html beside it, never over the file.
|
|
31
31
|
--version The package's version.
|
|
32
32
|
|
|
33
|
-
The specification: https://startside.app/swa/1.0/ (in this package: swa/1.0/spec.md).`,
|
|
33
|
+
The specification: https://startside.app/swa/1.0/ (in this package: swa/1.0/spec.md).`,En=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Dn(e){let n=[];for(let i of e){let e;try{e=t(i,`utf8`)}catch(e){n.push({file:i,line:1,col:1,level:`error`,message:`Can't read it: ${e.message}`});continue}for(let t of xn(e,i))n.push({file:o(process.cwd(),s(i))||r(i),...t})}return n}function On(e,t,n){let r=e.filter(e=>e.level===`error`).length;if(n)console.log(JSON.stringify(e,null,2));else{for(let t of e)console.log(`${t.file}:${t.line}:${t.col}: ${t.level}: ${t.message}`);console.log(`${En(t.length,`SWA file`)}: ${En(r,`error`)}, ${En(e.length-r,`warning`)}.`)}return r}function kn(e,t){let n=/<\/head\s*>/i.exec(e),r=/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi;for(let i;(i=r.exec(e))&&!(n&&i.index>n.index);){let n=i[1],r=/\bsrc\s*=\s*["']?([^"'\s>]+)/i.exec(n)?.[1];if(!(r?/\/swa\/1\.0\/runtime\.js(\?|#|$)/i.test(r):/\bdata-runtime\b/i.test(n)))continue;let a=/\bdata-host\s*=\s*["']([^"']*)["']/i.exec(n)?.[1],o=`<script data-runtime="swa/1.0"${a===void 0?``:` data-host="${a}"`}>${t}<\/script>`;return e.slice(0,i.index)+o+e.slice(i.index+i[0].length)}return null}function An(o){let[c,...l]=o;if(!c||c===`help`||c===`--help`||c===`-h`)return console.log(Tn),0;if(c===`--version`||c===`-v`)return console.log(JSON.parse(t(wn,`utf8`)).version),0;if(c===`validate`){let e=l.filter(e=>!e.startsWith(`--`)),t=l.filter(e=>e.startsWith(`--`)&&e!==`--json`);return t.length?jn(`unknown option ${t[0]}.`):e.length?+!!On(Dn(e),e,l.includes(`--json`)):jn(`validate needs one file at least: npx @startside/swa validate my-widget.swa.html`)}if(c===`inline`){let o,c=[];for(let e=0;e<l.length;e++)if(l[e]===`-o`||l[e]===`--output`)o=l[++e];else if(l[e].startsWith(`-`))return jn(`unknown option ${l[e]}.`);else c.push(l[e]);if(c.length!==1)return jn(`inline takes one file: npx @startside/swa inline my-widget.swa.html [-o out.swa.html]`);if(l.includes(`-o`)&&!o)return jn(`-o needs a file name.`);let u=c[0];if(!e(u))return jn(`${u}: no such file.`);let d=r(u).replace(/(-inline)?\.swa\.html$/i,``).replace(/\.html?$/i,``);if(o??=a(i(u),`${d}-inline.swa.html`),s(o)===s(u))return jn(`${o} is the file itself: the output is a new file (-o).`);let f=t(Cn,`utf8`).trimEnd(),p=/<\/script|<!--|<script/i.exec(f);if(p)return jn(`the runtime holds "${p[0]}": it can't be inlined.`);let m=kn(t(u,`utf8`),f);return m===null?jn(`${u}: no runtime script in its head (…/swa/1.0/runtime.js, or an inlined one) to replace (SWA 1.0, 4.3).`):(n(o,m),console.log(`Wrote ${o}, the runtime inlined (${Math.round(f.length/1024)} KB).`),+!!On(Dn([o]),[o],!1))}return jn(`unknown command "${c}".\n\n${Tn}`)}function jn(e){return console.error(`swa: ${e}`),2}process.exitCode=An(process.argv.slice(2));export{kn as inline};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startside/swa",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "The Startside Widget API (SWA): the runtime a widget file loads, its TypeScript types, its specification in Markdown, and a command to check a widget file and inline its runtime.",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "The Startside Widget API (SWA): the runtime a widget file loads, its TypeScript types, its specification in Markdown, and a command to check a widget file and inline its runtime, and what another host needs to run a widget in a frame.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"swa",
|
|
7
7
|
"startside",
|
package/swa/1.0/agents.md
CHANGED
|
@@ -133,8 +133,10 @@ What it shows, in order:
|
|
|
133
133
|
| SHOULD | Follow its width with a `ResizeObserver` on its own element when its layout depends on it | 7.3.2 |
|
|
134
134
|
| SHOULD | Meet WCAG 2.2 AA: keyboard alone, names on controls, 4.5:1 text, `prefers-reduced-motion` | 14 |
|
|
135
135
|
| MUST | Show only pictures it may show (public domain, or a licence or permission that allows it), their required credits kept; a picture opened large carries its own: `widget.openPhoto({ src, alt, credit })` | 7.12 |
|
|
136
|
+
| MAY | Read an API that wants the person's own key: `<input type="password" name="key" data-key-for="https://api.example">` in the settings, then `widget.fetch` to that origin. The host keeps the key and adds `Authorization: Bearer`; the widget never sees it (`widget.settings.get('key')` is `''`), and a 401 or 403 means no key yet: say to add one in the settings | 5.3, 8.2 |
|
|
136
137
|
| MAY | Declare actions of its own for its options menu, in the file: `<menu id="actions" hidden>` with one `<button type="button" name="reset">Reset</button>` each, five at most (`disabled` or `hidden` as it starts, `data-confirm="…?"` for a question the host asks first). Answer the `action` event (`event.detail.id`), and change their state as the widget's does with `widget.setActionStates({ reset: { disabled: false } })` | 7.13 |
|
|
137
138
|
| MAY | Hand the person a file it makes, from one of those actions only: `data-save=".cook"` on its button, then `widget.saveFile({ name, type, data }, { action: event })` in its `action` listener | 7.13 |
|
|
139
|
+
| MAY | Take a file dragged from the computer onto it: `<meta name="acceptFiles" content=".gpx">` (the extensions it takes), then its own `dragover` (`preventDefault()`) and `drop` listeners; a file it doesn't take, left uncancelled, is refused, never opened. A file input (`<input type="file" accept=".gpx">`) beside it, for the keyboard and a phone | 4.5, 10.1 |
|
|
138
140
|
| MAY | Carry its icon in the file: `<link rel="icon" href="data:image/svg+xml,…">`, kept when the file is shared by itself (best: an SVG drawn for 16 pixels, or a 64 × 64 PNG) | 4.6 |
|
|
139
141
|
|
|
140
142
|
## Checklist
|
|
@@ -184,6 +186,9 @@ licence (CC BY 4.0).*
|
|
|
184
186
|
(`https://cdn.jsdelivr.net/npm/@startside/swa@1/swa/1.0/agents.md`). Served by jsDelivr and unpkg (4.3), installed
|
|
185
187
|
with `npm install @startside/swa`. Since 1.0.1 too, a command, for Node 20 or later, with nothing else to install:
|
|
186
188
|
`validate` and `inline`, below.
|
|
189
|
+
- **Running widgets in another page.** Since 1.0.3, `@startside/swa` also carries the runtime a host writes into a
|
|
190
|
+
widget's frame (`swa/1.0/frame.js`, SWA files only), its base styles (`frame.css`), and `host.md`: how a host runs a
|
|
191
|
+
frame (10.1), the configuration that runtime reads and the messages a host answers.
|
|
187
192
|
- **Checking a file.** `npx @startside/swa validate my-widget.swa.html` reads a widget file without running it, with no
|
|
188
193
|
network: the file's name and document, its runtime tag, metadata and settings form, and its scripts against this
|
|
189
194
|
API, UWA's members and globals named with what replaces them. Each finding is `file:line:col: error|warning:
|
|
@@ -253,12 +258,16 @@ declare global {
|
|
|
253
258
|
settingschange: WidgetEvent<{ names: string[] }>;
|
|
254
259
|
/** One of the widget's own actions (declared in `<menu id="actions">`, 7.13) chosen in its options menu. */
|
|
255
260
|
action: WidgetEvent<{ id: string }>;
|
|
261
|
+
/** A picture opened with `openPhoto({ deletable: true, id })`, deleted by the person in the host's window. */
|
|
262
|
+
photodelete: WidgetEvent<{ id: string }>;
|
|
263
|
+
/** Its pictures (`storage.files`) changed: Sync, another copy of the page, or its own call. List them again. */
|
|
264
|
+
fileschange: WidgetEvent<null>;
|
|
256
265
|
}
|
|
257
266
|
|
|
258
267
|
interface Widget extends EventTarget {
|
|
259
268
|
// 7.2 Identity and environment
|
|
260
269
|
readonly id: string;
|
|
261
|
-
/** The title shown: the
|
|
270
|
+
/** The title shown: the widget's own, its file's `<title>` until it sets another (7.3). */
|
|
262
271
|
readonly title: string;
|
|
263
272
|
/** The widget file's address. */
|
|
264
273
|
readonly uwaUrl: string;
|
|
@@ -328,6 +337,11 @@ declare global {
|
|
|
328
337
|
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
329
338
|
/** RSS, Atom or JSON Feed as a JSON Feed 1.1, kept by the host: a kept copy answers at once. */
|
|
330
339
|
fetchFeed(url: string, options?: FetchFeedOptions): Promise<ContentFeed>;
|
|
340
|
+
/**
|
|
341
|
+
* A picture fetched by the host as itself (with its Referer; 8.6): an address to show in an `img`, the same for the
|
|
342
|
+
* same picture. https, a raster picture of 2 MB at most; rejects with a TypeError otherwise.
|
|
343
|
+
*/
|
|
344
|
+
fetchImage(url: string, options?: { signal?: AbortSignal | null }): Promise<string>;
|
|
331
345
|
|
|
332
346
|
// 7.10 Read state and counts
|
|
333
347
|
readItems(box: Element, itemSelector: string, options?: { key?: (item: Element) => string }): void;
|
|
@@ -356,6 +370,8 @@ declare global {
|
|
|
356
370
|
// 7.13 The page
|
|
357
371
|
shareUrl(): string | null;
|
|
358
372
|
share(data?: { text?: string; url?: string }): unknown;
|
|
373
|
+
/** Startside's extension: the page's Send to… for this widget; nothing where environment.people is null. */
|
|
374
|
+
sendTo(): void;
|
|
359
375
|
/** Absent where no widget can be added (a preview, a widget on its own page): `if (widget.addWidget)`. */
|
|
360
376
|
addWidget?(spec: AddWidgetSpec): unknown;
|
|
361
377
|
/** `spec`, or a function giving it as the drag starts, given the drag's event; nothing given, the drag doesn't start. */
|
|
@@ -413,6 +429,31 @@ declare global {
|
|
|
413
429
|
readonly memory: WidgetStorageArea;
|
|
414
430
|
/** Across reloads, shared by every widget of the same file: scores. */
|
|
415
431
|
readonly local: WidgetStorageArea;
|
|
432
|
+
/** Its own pictures, kept for good and the same on the person's other devices (synced): photos it took. */
|
|
433
|
+
readonly files: WidgetFiles;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** A widget's pictures (7.8): JPEG, PNG, WebP or GIF, 10 MB each at most. */
|
|
437
|
+
interface WidgetFiles {
|
|
438
|
+
/** Every one, oldest first, from this device at once. */
|
|
439
|
+
list(): Promise<WidgetFile[]>;
|
|
440
|
+
/** Its bytes, from this device or the server; rejects `NotFoundError`, or `NetworkError` offline without them. */
|
|
441
|
+
get(id: string): Promise<Blob>;
|
|
442
|
+
/** Kept here at once, sent when the host can; its id. Rejects `TypeError` (not a picture, a meta not JSON or over 1,024 bytes), `RangeError` (over 10 MB). */
|
|
443
|
+
add(file: Blob, meta?: unknown): Promise<string>;
|
|
444
|
+
/** Deleted here and on the person's other devices. */
|
|
445
|
+
delete(id: string): Promise<void>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
interface WidgetFile {
|
|
449
|
+
readonly id: string;
|
|
450
|
+
/** `image/jpeg`, `image/png`, `image/webp` or `image/gif`, told by its bytes. */
|
|
451
|
+
readonly type: string;
|
|
452
|
+
readonly size: number;
|
|
453
|
+
/** When it was added, in milliseconds. */
|
|
454
|
+
readonly at: number;
|
|
455
|
+
/** What the widget gave `add`. */
|
|
456
|
+
readonly meta: unknown;
|
|
416
457
|
}
|
|
417
458
|
|
|
418
459
|
interface WidgetStorageArea {
|
|
@@ -428,6 +469,11 @@ declare global {
|
|
|
428
469
|
readonly inline: boolean;
|
|
429
470
|
/** The page's style, or "" standalone. */
|
|
430
471
|
readonly style: string;
|
|
472
|
+
/**
|
|
473
|
+
* Startside's extension: who plays, in the beta's conversations (this person's name, and who sent this copy,
|
|
474
|
+
* null on their own page); null elsewhere.
|
|
475
|
+
*/
|
|
476
|
+
readonly people: Readonly<{ me: string; from: string | null; to: string | null }> | null;
|
|
431
477
|
}
|
|
432
478
|
|
|
433
479
|
/** A setting as the file declares it: frozen, as `preferences` and `getPreference` give it. */
|
|
@@ -530,6 +576,20 @@ declare global {
|
|
|
530
576
|
/** Played without a Referer, through the host's relay. */
|
|
531
577
|
relay?: boolean;
|
|
532
578
|
live?: boolean;
|
|
579
|
+
/**
|
|
580
|
+
* For a file (`live: false`): the files the host plays after it, each as the one before ends, with no further click,
|
|
581
|
+
* until a pause (7.12). `audioState.url` says which plays. 100 at most.
|
|
582
|
+
*/
|
|
583
|
+
next?: NextAudio[];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
interface NextAudio {
|
|
587
|
+
/** https */
|
|
588
|
+
url: string;
|
|
589
|
+
relay?: boolean;
|
|
590
|
+
/** What the host says plays as it starts (`audioInfo`'s title and artist). */
|
|
591
|
+
title?: string;
|
|
592
|
+
artist?: string;
|
|
533
593
|
}
|
|
534
594
|
|
|
535
595
|
interface AudioState {
|
|
@@ -540,6 +600,21 @@ declare global {
|
|
|
540
600
|
/** Seconds, for a file. */
|
|
541
601
|
time?: number | null;
|
|
542
602
|
duration?: number | null;
|
|
603
|
+
/**
|
|
604
|
+
* A file (`live: false`) another widget of the page plays, playing or loading, else null. While this widget plays
|
|
605
|
+
* nothing itself, `pauseAudio` and `seekAudio` act on it; `playAudio` of a file another widget holds goes on there.
|
|
606
|
+
*/
|
|
607
|
+
elsewhere?: ElsewhereAudio | null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
interface ElsewhereAudio {
|
|
611
|
+
url: string;
|
|
612
|
+
playing: boolean;
|
|
613
|
+
loading: boolean;
|
|
614
|
+
time: number | null;
|
|
615
|
+
duration: number | null;
|
|
616
|
+
/** Its `audioInfo`'s source. */
|
|
617
|
+
source: string | null;
|
|
543
618
|
}
|
|
544
619
|
|
|
545
620
|
interface AudioControls {
|
|
@@ -577,7 +652,12 @@ declare global {
|
|
|
577
652
|
}
|
|
578
653
|
|
|
579
654
|
interface PhotoSpec {
|
|
580
|
-
|
|
655
|
+
/** An `https` picture or one of the host's; `file` instead for one of the widget's own files. */
|
|
656
|
+
src?: string;
|
|
657
|
+
/** One of its own pictures (`storage.files`), by id: the host reads it, `src` aside. */
|
|
658
|
+
file?: string;
|
|
659
|
+
/** Its own pictures to step through from `file` (their ids, in order, 5,000 at most): ‹ › and the arrow keys. */
|
|
660
|
+
files?: string[];
|
|
581
661
|
alt?: string;
|
|
582
662
|
title?: string;
|
|
583
663
|
preview?: string;
|
|
@@ -587,6 +667,10 @@ declare global {
|
|
|
587
667
|
height?: number;
|
|
588
668
|
/** What the picture's licence asks to go with it. A plain string is its credit text. */
|
|
589
669
|
credit?: PhotoCredit | string;
|
|
670
|
+
/** The window offers Delete, which asks the person first; the widget hears it as `photodelete`. */
|
|
671
|
+
deletable?: boolean;
|
|
672
|
+
/** Given back in `photodelete`'s detail: which picture (100 characters at most). With `file`, the file's id instead. */
|
|
673
|
+
id?: string;
|
|
590
674
|
}
|
|
591
675
|
|
|
592
676
|
/**
|
|
@@ -688,6 +772,7 @@ The full text: https://startside.app/swa/1.0/ (Markdown: https://startside.app/s
|
|
|
688
772
|
- [8.3 `widget.fetchFeed`](https://startside.app/swa/1.0/#83-widgetfetchfeed)
|
|
689
773
|
- [8.4 Freshness](https://startside.app/swa/1.0/#84-freshness)
|
|
690
774
|
- [8.5 Content feeds](https://startside.app/swa/1.0/#85-content-feeds)
|
|
775
|
+
- [8.6 `widget.fetchImage`](https://startside.app/swa/1.0/#86-widgetfetchimage)
|
|
691
776
|
- [9. Built-in objects](https://startside.app/swa/1.0/#9-built-in-objects)
|
|
692
777
|
- [10. Execution environments](https://startside.app/swa/1.0/#10-execution-environments)
|
|
693
778
|
- [10.1 Framed](https://startside.app/swa/1.0/#101-framed)
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/* Base styles for every widget, UWA, SWA and RWA, in its frame, inline and on its own page (the shared runtime, XWA:
|
|
2
|
+
docs/plans/xwa-rename.md), in the spirit of Netvibes' uwa-iframe.css,
|
|
3
|
+
using the dashboard skin's colors (the --variables are injected per frame). */
|
|
4
|
+
html,
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
background: transparent;
|
|
9
|
+
}
|
|
10
|
+
body {
|
|
11
|
+
color: var(--text, #333);
|
|
12
|
+
font: 11px/1.45 var(--font-body, Verdana, Tahoma, Geneva, sans-serif);
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
.moduleContent {
|
|
16
|
+
padding: 6px 8px;
|
|
17
|
+
}
|
|
18
|
+
/* A widget with viewport-fit=cover in its viewport meta draws to its edges (srcdoc.ts, runtime.js: uwa-cover; SWA 7.3.2). */
|
|
19
|
+
:root.uwa-cover .moduleContent {
|
|
20
|
+
padding: 0;
|
|
21
|
+
}
|
|
22
|
+
a {
|
|
23
|
+
color: var(--link, #1e5bb8);
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
}
|
|
26
|
+
a:hover {
|
|
27
|
+
text-decoration: underline;
|
|
28
|
+
}
|
|
29
|
+
p {
|
|
30
|
+
margin: 0 0 6px;
|
|
31
|
+
}
|
|
32
|
+
ul {
|
|
33
|
+
margin: 0;
|
|
34
|
+
padding: 0;
|
|
35
|
+
list-style: none;
|
|
36
|
+
}
|
|
37
|
+
li {
|
|
38
|
+
padding: 2px 0 2px 12px;
|
|
39
|
+
position: relative;
|
|
40
|
+
}
|
|
41
|
+
li::before {
|
|
42
|
+
content: '';
|
|
43
|
+
position: absolute;
|
|
44
|
+
left: 2px;
|
|
45
|
+
top: 7px;
|
|
46
|
+
width: 4px;
|
|
47
|
+
height: 4px;
|
|
48
|
+
background: var(--link, #1e5bb8);
|
|
49
|
+
}
|
|
50
|
+
input,
|
|
51
|
+
select,
|
|
52
|
+
textarea,
|
|
53
|
+
button {
|
|
54
|
+
font: inherit;
|
|
55
|
+
}
|
|
56
|
+
table {
|
|
57
|
+
border-collapse: collapse;
|
|
58
|
+
font: inherit;
|
|
59
|
+
}
|
|
60
|
+
.buttonClean,
|
|
61
|
+
button {
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
padding: 2px 10px;
|
|
64
|
+
border: 1px solid #8e99a6;
|
|
65
|
+
border-radius: 3px;
|
|
66
|
+
color: #222;
|
|
67
|
+
background: linear-gradient(#ffffff, #e8ecf1 50%, #d6dde5 51%, #e9edf2);
|
|
68
|
+
}
|
|
69
|
+
/* On a dark page the same glossy button, dark: unstyled buttons stayed pale grey with dark text there (found by an
|
|
70
|
+
agent's screenshot, November 2026). data-color-scheme is set on a frame's and the standalone page's root. It weighs
|
|
71
|
+
more than a widget's `.x`, which still wins: this file sits under the widget's rules everywhere, in a cascade layer
|
|
72
|
+
in a frame (srcdoc.ts) and on the widget's own page (server/widgetRuntime.ts), the widget's rules scoped by a doubled
|
|
73
|
+
id inline (inline.ts; issue #87). */
|
|
74
|
+
:root[data-color-scheme='dark'] .buttonClean,
|
|
75
|
+
:root[data-color-scheme='dark'] button {
|
|
76
|
+
border-color: #5c6672;
|
|
77
|
+
color: #e6e9ed;
|
|
78
|
+
background: linear-gradient(#3e4650, #313841 50%, #2a3038 51%, #323941);
|
|
79
|
+
}
|
|
80
|
+
.uwa-error {
|
|
81
|
+
margin: 0 0 6px;
|
|
82
|
+
padding: 4px 8px;
|
|
83
|
+
color: #b3261e;
|
|
84
|
+
background: #fdecea;
|
|
85
|
+
border-bottom: 1px solid #f3c1bc;
|
|
86
|
+
}
|
|
87
|
+
.nv-pager {
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: baseline;
|
|
90
|
+
gap: 10px;
|
|
91
|
+
margin-top: 6px;
|
|
92
|
+
padding-top: 5px;
|
|
93
|
+
border-top: 1px dotted var(--border, #ccc);
|
|
94
|
+
}
|
|
95
|
+
.nv-pager .status {
|
|
96
|
+
color: var(--muted, #888);
|
|
97
|
+
font-size: 10px;
|
|
98
|
+
}
|
|
99
|
+
.nv-pager .next {
|
|
100
|
+
margin-left: auto;
|
|
101
|
+
}
|
|
102
|
+
/* Keep images in proportion when a widget sets only their width. */
|
|
103
|
+
img {
|
|
104
|
+
max-width: 100%;
|
|
105
|
+
height: auto;
|
|
106
|
+
}
|
|
107
|
+
/* The dashboard's loading indicator (src/widgetBox/Loading.tsx and base.css), so a widget
|
|
108
|
+
can show the same one:
|
|
109
|
+
<div class="loading"><span class="spinner"><i/><i/><i/><i/><i/><i/><i/><i/></span>Loading…</div> */
|
|
110
|
+
.loading {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: 6px;
|
|
114
|
+
padding: 10px 8px;
|
|
115
|
+
color: var(--muted, #888);
|
|
116
|
+
}
|
|
117
|
+
.spinner {
|
|
118
|
+
position: relative;
|
|
119
|
+
width: 16px;
|
|
120
|
+
height: 16px;
|
|
121
|
+
}
|
|
122
|
+
.spinner i {
|
|
123
|
+
position: absolute;
|
|
124
|
+
left: 7px;
|
|
125
|
+
top: 0;
|
|
126
|
+
width: 2px;
|
|
127
|
+
height: 5px;
|
|
128
|
+
border-radius: 1px;
|
|
129
|
+
background: var(--muted, #888);
|
|
130
|
+
transform-origin: 1px 8px;
|
|
131
|
+
animation: spin-fade 0.8s steps(1) infinite;
|
|
132
|
+
}
|
|
133
|
+
.spinner i:nth-child(1) {
|
|
134
|
+
transform: rotate(0deg);
|
|
135
|
+
animation-delay: -0.8s;
|
|
136
|
+
}
|
|
137
|
+
.spinner i:nth-child(2) {
|
|
138
|
+
transform: rotate(45deg);
|
|
139
|
+
animation-delay: -0.7s;
|
|
140
|
+
}
|
|
141
|
+
.spinner i:nth-child(3) {
|
|
142
|
+
transform: rotate(90deg);
|
|
143
|
+
animation-delay: -0.6s;
|
|
144
|
+
}
|
|
145
|
+
.spinner i:nth-child(4) {
|
|
146
|
+
transform: rotate(135deg);
|
|
147
|
+
animation-delay: -0.5s;
|
|
148
|
+
}
|
|
149
|
+
.spinner i:nth-child(5) {
|
|
150
|
+
transform: rotate(180deg);
|
|
151
|
+
animation-delay: -0.4s;
|
|
152
|
+
}
|
|
153
|
+
.spinner i:nth-child(6) {
|
|
154
|
+
transform: rotate(225deg);
|
|
155
|
+
animation-delay: -0.3s;
|
|
156
|
+
}
|
|
157
|
+
.spinner i:nth-child(7) {
|
|
158
|
+
transform: rotate(270deg);
|
|
159
|
+
animation-delay: -0.2s;
|
|
160
|
+
}
|
|
161
|
+
.spinner i:nth-child(8) {
|
|
162
|
+
transform: rotate(315deg);
|
|
163
|
+
animation-delay: -0.1s;
|
|
164
|
+
}
|
|
165
|
+
@keyframes spin-fade {
|
|
166
|
+
0% {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
}
|
|
169
|
+
12.5% {
|
|
170
|
+
opacity: 0.8;
|
|
171
|
+
}
|
|
172
|
+
25% {
|
|
173
|
+
opacity: 0.6;
|
|
174
|
+
}
|
|
175
|
+
37.5% {
|
|
176
|
+
opacity: 0.45;
|
|
177
|
+
}
|
|
178
|
+
50% {
|
|
179
|
+
opacity: 0.3;
|
|
180
|
+
}
|
|
181
|
+
62.5%,
|
|
182
|
+
100% {
|
|
183
|
+
opacity: 0.15;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* A link that leaves the dashboard (a new tab on another site, not the reader): a small "open
|
|
188
|
+
in new" icon after its text, in its own color, faded. Widgets put it on their headlines. */
|
|
189
|
+
/* The icon takes no room of its own (margin-right cancels it) and the link's end padding holds
|
|
190
|
+
its place: the padding sticks to the last word, so the icon never wraps onto a line alone. */
|
|
191
|
+
.ext-link {
|
|
192
|
+
padding-right: 1.02em;
|
|
193
|
+
}
|
|
194
|
+
.ext-link::after {
|
|
195
|
+
content: '';
|
|
196
|
+
display: inline-block;
|
|
197
|
+
flex: none;
|
|
198
|
+
width: 0.72em;
|
|
199
|
+
height: 0.72em;
|
|
200
|
+
margin: 0 -1.02em 0 0.3em;
|
|
201
|
+
vertical-align: 0;
|
|
202
|
+
background: currentColor;
|
|
203
|
+
opacity: 0.45;
|
|
204
|
+
-webkit-mask: var(--ext-icon) no-repeat center / contain;
|
|
205
|
+
mask: var(--ext-icon) no-repeat center / contain;
|
|
206
|
+
--ext-icon: url('data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27%3E%3Cpath d=%27M14 3h7v7h-2V6.41l-9.29 9.3-1.42-1.42L17.59 5H14V3zM5 5h6v2H5v12h12v-6h2v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2z%27/%3E%3C/svg%3E');
|
|
207
|
+
}
|
|
208
|
+
.ext-link:hover::after {
|
|
209
|
+
opacity: 0.8;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* The corner grip of list widgets (widget.countGrip): drag it down for more items, up for fewer. */
|
|
213
|
+
.count-grip {
|
|
214
|
+
position: absolute;
|
|
215
|
+
right: 0;
|
|
216
|
+
bottom: 0;
|
|
217
|
+
width: 20px;
|
|
218
|
+
height: 20px;
|
|
219
|
+
display: grid;
|
|
220
|
+
place-items: center;
|
|
221
|
+
cursor: ns-resize;
|
|
222
|
+
touch-action: none;
|
|
223
|
+
color: currentColor;
|
|
224
|
+
opacity: 0.35;
|
|
225
|
+
}
|
|
226
|
+
.count-grip:hover,
|
|
227
|
+
.count-grip-dragging .count-grip {
|
|
228
|
+
opacity: 0.9;
|
|
229
|
+
}
|
|
230
|
+
/* Focused from the keyboard (↑ ↓, Home, End): the grip at full strength in a ring of the text's colour. */
|
|
231
|
+
.count-grip:focus-visible {
|
|
232
|
+
opacity: 1;
|
|
233
|
+
outline: 2px solid currentColor;
|
|
234
|
+
outline-offset: -2px;
|
|
235
|
+
border-radius: 3px;
|
|
236
|
+
}
|
|
237
|
+
.count-grip svg {
|
|
238
|
+
width: 10px;
|
|
239
|
+
height: 10px;
|
|
240
|
+
}
|
|
241
|
+
.count-grip-dragging,
|
|
242
|
+
.count-grip-dragging * {
|
|
243
|
+
cursor: ns-resize !important;
|
|
244
|
+
user-select: none;
|
|
245
|
+
}
|