implemented reader mode
This commit is contained in:
1 parent
1704a4fa89
commit
3087bdbd8c
22 files changed
+6935
-20
No files matched your search
@@ -0,0 +1 @@
|
||||
../../js/readability/dist/readability.min.js.gz
|
||||
@@ -0,0 +1,25 @@
|
||||
# Node.js
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Logs
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids/
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Compiled output
|
||||
build/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm/
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReadabilityBundle=t():e.ReadabilityBundle=t()}(this,(()=>(()=>{var e={804:e=>{var t={unlikelyCandidates:/-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,okMaybeItsACandidate:/and|article|body|column|content|main|shadow/i};function i(e){return(!e.style||"none"!=e.style.display)&&!e.hasAttribute("hidden")&&(!e.hasAttribute("aria-hidden")||"true"!=e.getAttribute("aria-hidden")||e.className&&e.className.indexOf&&-1!==e.className.indexOf("fallback-image"))}e.exports=function(e,n={}){"function"==typeof n&&(n={visibilityChecker:n});var r={minScore:20,minContentLength:140,visibilityChecker:i};n=Object.assign(r,n);var a=e.querySelectorAll("p, pre, article"),o=e.querySelectorAll("div > br");if(o.length){var s=new Set(a);[].forEach.call(o,(function(e){s.add(e.parentNode)})),a=Array.from(s)}var l=0;return[].some.call(a,(function(e){if(!n.visibilityChecker(e))return!1;var i=e.className+" "+e.id;if(t.unlikelyCandidates.test(i)&&!t.okMaybeItsACandidate.test(i))return!1;if(e.matches("li p"))return!1;var r=e.textContent.trim().length;return!(r<n.minContentLength)&&(l+=Math.sqrt(r-n.minContentLength))>n.minScore}))}},238:e=>{function t(e,t){if(t&&t.documentElement)e=t,t=arguments[2];else if(!e||!e.documentElement)throw new Error("First argument to Readability constructor should be a document object.");if(t=t||{},this._doc=e,this._docJSDOMParser=this._doc.firstChild.__JSDOMParser__,this._articleTitle=null,this._articleByline=null,this._articleDir=null,this._articleSiteName=null,this._attempts=[],this._debug=!!t.debug,this._maxElemsToParse=t.maxElemsToParse||this.DEFAULT_MAX_ELEMS_TO_PARSE,this._nbTopCandidates=t.nbTopCandidates||this.DEFAULT_N_TOP_CANDIDATES,this._charThreshold=t.charThreshold||this.DEFAULT_CHAR_THRESHOLD,this._classesToPreserve=this.CLASSES_TO_PRESERVE.concat(t.classesToPreserve||[]),this._keepClasses=!!t.keepClasses,this._serializer=t.serializer||function(e){return e.innerHTML},this._disableJSONLD=!!t.disableJSONLD,this._allowedVideoRegex=t.allowedVideoRegex||this.REGEXPS.videos,this._flags=this.FLAG_STRIP_UNLIKELYS|this.FLAG_WEIGHT_CLASSES|this.FLAG_CLEAN_CONDITIONALLY,this._debug){let e=function(e){if(e.nodeType==e.TEXT_NODE)return`${e.nodeName} ("${e.textContent}")`;let t=Array.from(e.attributes||[],(function(e){return`${e.name}="${e.value}"`})).join(" ");return`<${e.localName} ${t}>`};this.log=function(){if("undefined"!=typeof console){let t=Array.from(arguments,(t=>t&&t.nodeType==this.ELEMENT_NODE?e(t):t));t.unshift("Reader: (Readability)"),console.log.apply(console,t)}else if("undefined"!=typeof dump){var t=Array.prototype.map.call(arguments,(function(t){return t&&t.nodeName?e(t):t})).join(" ");dump("Reader: (Readability) "+t+"\n")}}}else this.log=function(){}}t.prototype={FLAG_STRIP_UNLIKELYS:1,FLAG_WEIGHT_CLASSES:2,FLAG_CLEAN_CONDITIONALLY:4,ELEMENT_NODE:1,TEXT_NODE:3,DEFAULT_MAX_ELEMS_TO_PARSE:0,DEFAULT_N_TOP_CANDIDATES:5,DEFAULT_TAGS_TO_SCORE:"section,h2,h3,h4,h5,h6,p,td,pre".toUpperCase().split(","),DEFAULT_CHAR_THRESHOLD:500,REGEXPS:{unlikelyCandidates:/-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,okMaybeItsACandidate:/and|article|body|column|content|main|shadow/i,positive:/article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i,negative:/-ad-|hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i,extraneous:/print|archive|comment|discuss|e[\-]?mail|share|reply|all|login|sign|single|utility/i,byline:/byline|author|dateline|writtenby|p-author/i,replaceFonts:/<(\/?)font[^>]*>/gi,normalize:/\s{2,}/g,videos:/\/\/(www\.)?((dailymotion|youtube|youtube-nocookie|player\.vimeo|v\.qq)\.com|(archive|upload\.wikimedia)\.org|player\.twitch\.tv)/i,shareElements:/(\b|_)(share|sharedaddy)(\b|_)/i,nextLink:/(next|weiter|continue|>([^\|]|$)|»([^\|]|$))/i,prevLink:/(prev|earl|old|new|<|«)/i,tokenize:/\W+/g,whitespace:/^\s*$/,hasContent:/\S$/,hashUrl:/^#.+/,srcsetUrl:/(\S+)(\s+[\d.]+[xw])?(\s*(?:,|$))/g,b64DataUrl:/^data:\s*([^\s;,]+)\s*;\s*base64\s*,/i,commas:/\u002C|\u060C|\uFE50|\uFE10|\uFE11|\u2E41|\u2E34|\u2E32|\uFF0C/g,jsonLdArticleTypes:/^Article|AdvertiserContentArticle|NewsArticle|AnalysisNewsArticle|AskPublicNewsArticle|BackgroundNewsArticle|OpinionNewsArticle|ReportageNewsArticle|ReviewNewsArticle|Report|SatiricalArticle|ScholarlyArticle|MedicalScholarlyArticLine truncated
|
||||
/*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE */
|
||||
e.exports=function(){"use strict";const{entries:e,setPrototypeOf:t,isFrozen:i,getPrototypeOf:n,getOwnPropertyDescriptor:r}=Object;let{freeze:a,seal:o,create:s}=Object,{apply:l,construct:c}="undefined"!=typeof Reflect&&Reflect;a||(a=function(e){return e}),o||(o=function(e){return e}),l||(l=function(e,t,i){return e.apply(t,i)}),c||(c=function(e,t){return new e(...t)});const h=y(Array.prototype.forEach),d=y(Array.prototype.pop),u=y(Array.prototype.push),m=y(String.prototype.toLowerCase),g=y(String.prototype.toString),p=y(String.prototype.match),f=y(String.prototype.replace),_=y(String.prototype.indexOf),N=y(String.prototype.trim),E=y(Object.prototype.hasOwnProperty),T=y(RegExp.prototype.test),b=A(TypeError);function y(e){return function(t){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return l(e,t,n)}}function A(e){return function(){for(var t=arguments.length,i=new Array(t),n=0;n<t;n++)i[n]=arguments[n];return c(e,i)}}function v(e,n){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:m;t&&t(e,null);let a=n.length;for(;a--;){let t=n[a];if("string"==typeof t){const e=r(t);e!==t&&(i(n)||(n[a]=e),t=e)}e[t]=!0}return e}function S(e){for(let t=0;t<e.length;t++)E(e,t)||(e[t]=null);return e}function C(t){const i=s(null);for(const[n,r]of e(t))E(t,n)&&(Array.isArray(r)?i[n]=S(r):r&&"object"==typeof r&&r.constructor===Object?i[n]=C(r):i[n]=r);return i}function L(e,t){for(;null!==e;){const i=r(e,t);if(i){if(i.get)return y(i.get);if("function"==typeof i.value)return y(i.value)}e=n(e)}function i(){return null}return i}const x=a(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),R=a(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),D=a(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),I=a(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),O=a(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),w=a(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),P=a(["#text"]),M=a(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","Line truncated
|
||||
BIN
Binary file not shown.
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>readability [9 Jul 2024 at 10:42]</title>
|
||||
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
||||
|
||||
<script>
|
||||
window.enableWebSocket = false;
|
||||
</script>
|
||||
<!-- viewer.js -->
|
||||
<script>/*! For license information please see viewer.js.LICENSE.txt */
|
||||
(()=>{var e={184:(e,t)=>{var n;
|
||||
/*!
|
||||
Copyright (c) 2018 Jed Watson.
|
||||
Licensed under the MIT License (MIT), see
|
||||
http://jedwatson.github.io/classnames
|
||||
*/!function(){"use strict";var i={}.hasOwnProperty;function r(){for(var e=[],t=0;t<arguments.length;t++){var n=arguments[t];if(n){var o=typeof n;if("string"===o||"number"===o)e.push(n);else if(Array.isArray(n)){if(n.length){var a=r.apply(null,n);a&&e.push(a)}}else if("object"===o)if(n.toString===Object.prototype.toString)for(var s in n)i.call(n,s)&&n[s]&&e.push(s);else e.push(n.toString())}}return e.join(" ")}e.exports?(r.default=r,e.exports=r):void 0===(n=function(){return r}.apply(t,[]))||(e.exports=n)}()},908:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s});var i=n(15),r=n.n(i),o=n(645),a=n.n(o)()(r());a.push([e.id,".Button__button{background:#fff;border:1px solid #aaa;border-radius:4px;cursor:pointer;display:inline-block;font:var(--main-font);outline:none;padding:5px 7px;transition:background .3s ease;white-space:nowrap}.Button__button:focus,.Button__button:hover{background:#ffefd7}.Button__button.Button__active{background:orange;color:#000}.Button__button[disabled]{cursor:default}","",{version:3,sources:["webpack://./client/components/Button.css"],names:[],mappings:"AAAA,gBACE,eAAgB,CAChB,qBAAsB,CACtB,iBAAkB,CAClB,cAAe,CACf,oBAAqB,CACrB,qBAAsB,CACtB,YAAa,CACb,eAAgB,CAChB,8BAA+B,CAC/B,kBACF,CAEA,4CAEE,kBACF,CAEA,+BACE,iBAAmB,CACnB,UACF,CAEA,0BACE,cACF",sourcesContent:[".button {\n background: #fff;\n border: 1px solid #aaa;\n border-radius: 4px;\n cursor: pointer;\n display: inline-block;\n font: var(--main-font);\n outline: none;\n padding: 5px 7px;\n transition: background .3s ease;\n white-space: nowrap;\n}\n\n.button:focus,\n.button:hover {\n background: #ffefd7;\n}\n\n.button.active {\n background: #ffa500;\n color: #000;\n}\n\n.button[disabled] {\n cursor: default;\n}\n"],sourceRoot:""}]),a.locals={button:"Button__button",active:"Button__active"};const s=a},396:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s});var i=n(15),r=n.n(i),o=n(645),a=n.n(o)()(r());a.push([e.id,".Checkbox__label{display:inline-block}.Checkbox__checkbox,.Checkbox__label{cursor:pointer}.Checkbox__itemText{margin-left:3px;position:relative;top:-2px;vertical-align:middle}","",{version:3,sources:["webpack://./client/components/Checkbox.css"],names:[],mappings:"AAAA,iBAEE,oBACF,CAEA,qCAJE,cAMF,CAEA,oBACE,eAAgB,CAChB,iBAAkB,CAClB,QAAS,CACT,qBACF",sourcesContent:[".label {\n cursor: pointer;\n display: inline-block;\n}\n\n.checkbox {\n cursor: pointer;\n}\n\n.itemText {\n margin-left: 3px;\n position: relative;\n top: -2px;\n vertical-align: middle;\n}\n"],sourceRoot:""}]),a.locals={label:"Checkbox__label",checkbox:"Checkbox__checkbox",itemText:"Checkbox__itemText"};const s=a},213:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s});var i=n(15),r=n.n(i),o=n(645),a=n.n(o)()(r());a.push([e.id,".CheckboxList__container{font:var(--main-font);white-space:nowrap}.CheckboxList__label{font-size:11px;font-weight:700;margin-bottom:7px}.CheckboxList__item+.CheckboxList__item{margin-top:1px}","",{version:3,sources:["webpack://./client/components/CheckboxList.css"],names:[],mappings:"AAAA,yBACE,qBAAsB,CACtB,kBACF,CAEA,qBACE,cAAe,CACf,eAAiB,CACjB,iBACF,CAEA,wCACE,cACF",sourcesContent:[".container {\n font: var(--main-font);\n white-space: nowrap;\n}\n\n.label {\n font-size: 11px;\n font-weight: bold;\n margin-bottom: 7px;\n}\n\n.item + .item {\n margin-top: 1px;\n}\n"],sourceRoot:""}]),a.locals={container:"CheckboxList__container",label:"CheckboxList__label",item:"CheckboxList__item"};const s=a},580:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s});var i=n(15),r=n.n(i),o=n(645),a=n.n(o)()(r());a.push([e.id,".ContextMenu__container{background:#fff;border:1px solid #aaa;border-radius:4px;font:var(--main-font);list-style:none;opacity:1;padding:0;position:absolute;transition:opacity .2s ease,visibility .2s ease;visibility:visible;white-space:nowrap}.ContextMenu__hidden{opacity:0;visibility:hidden}","",{version:3,sources:["webpack://./client/components/ContextMenu.css"],names:[],mappings:"AAAA,wBAKE,eAAgB,CAChB,qBAAsB,CAFtB,iBAAkB,CAHlB,qBAAsB,CAMtB,eAAgB,CAChB,SAAU,CALV,SAAU,CADV,iBAAkB,CASlB,+CAAiD,CADjD,kBAAmB,CADnB,kBAGF,CAEA,qBACE,SAAU,CACV,iBACF",sourcesContent:[".container {\n font: var(--main-font);\n position: absolute;\n padding: 0;\n border-radius: 4px;\n background: #fff;\n border: 1px solid #aaa;\n list-style: none;\n opacity: 1;\n white-space: nowrap;\n visibility: visible;\n transition: opacity .2s ease, visibility .2s ease;\n}\n\n.hidden {\n opacity: 0;\n visibility: hidden;\n}\n"],sourceRoot:""}]),a.locals={container:"ContextMenu__container",hidden:"ContextMenu__hidden"};const s=a},270:(e,t,n)=>{"use strict";n.d(t,{Z:()=>s});var i=n(15),r=n.n(i),o=n(645),a=n.n(o)()(r());a.push([e.id,".ContextMenuItem__item{cursor:pointer;margin:0;padding:8px 14px;-webkit-user-select:none;user-select:none}.ContextMenuItem__item:hover{background:#ffefd7}.ContextMenuItem__disabled{color:grey;cursor:default}.ContextMenuItem__item.ContextMenuItem__disabled:hover{background:transparent}","",{version:3,sources:["webpack://./client/components/ContextMenuItem.Line truncated
|
||||
/**
|
||||
* Carrot Search FoamTree HTML5 (demo variant)
|
||||
* v3.5.0, bugfix/3.5.x/e3b91c8e, build FOAMTREE-SOFTWARE5-DIST-3, Jan 18, 2021
|
||||
*
|
||||
* Carrot Search confidential.
|
||||
* Copyright 2002-2021, Carrot Search s.c, All Rights Reserved.
|
||||
*/
|
||||
!function(){var e,t=function(){var e=window.navigator.userAgent;try{window.localStorage.setItem("ftap5caavc","ftap5caavc"),window.localStorage.removeItem("ftap5caavc");var n=!0}catch(i){n=!1}return{Se:function(){return/webkit/i.test(e)},Lh:function(){return/Mac/.test(e)},Qe:function(){return/iPad|iPod|iPhone/.test(e)},Kh:function(){return/Android/.test(e)},Gh:function(){return"ontouchstart"in window||!!window.DocumentTouch&&document instanceof window.DocumentTouch},Fh:function(){return n},Eh:function(){var e=document.createElement("canvas");return!(!e.getContext||!e.getContext("2d"))},md:function(e,n){return[].forEach&&t.Eh()?e&&e():n&&n()}}}(),n=function(){function e(){return window.performance&&(window.performance.now||window.performance.mozNow||window.performance.msNow||window.performance.oNow||window.performance.webkitNow)||Date.now}var t=e();return{create:function(){return{now:function(){var t=e();return function(){return t.call(window.performance)}}()}},now:function(){return t.call(window.performance)}}}();function i(){function i(){if(!u)throw"AF0";var e=n.now();0!==l&&(o.sd=e-l),l=e,s=s.filter((function(e){return null!==e})),o.frames++;for(var t=0;t<s.length;t++){var i=s[t];null!==i&&(!0===i.ee.call(i.context)?s[t]=null:y.zc(i.repeat)&&(i.repeat=i.repeat-1,0>=i.repeat&&(s[t]=null)))}s=s.filter((function(e){return null!==e})),u=!1,r(),0!==(e=n.now()-e)&&(o.rd=e),o.totalTime+=e,o.ue=1e3*o.frames/o.totalTime,l=0===s.length?0:n.now()}function r(){0<s.length&&!u&&(u=!0,a(i))}var o=this.Wf={frames:0,totalTime:0,rd:0,sd:0,ue:0};e=o;var a=t.Qe()?function(e){window.setTimeout(e,0)}:window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(){var e=n.create();return function(t){var n=0;window.setTimeout((function(){var i=e.now();t(),n=e.now()-i}),16>n?16-n:0)}}(),s=[],u=!1,l=0;this.repeat=function(e,t,n){this.cancel(e),s.push({ee:e,context:n,repeat:t}),r()},this.once=function(e,t){this.repeat(e,1,t)},this.cancel=function(e){for(var t=0;t<s.length;t++){var n=s[t];null!==n&&n.ee===e&&(s[t]=null)}},this.i=function(){s=[]}}var r=t.md((function(){function e(){this.buffer=[],this.ma=0,this.current=y.extend({},s)}function t(e){return function(){var t,n=this.buffer,i=this.ma;for(n[i++]="call",n[i++]=e,n[i++]=arguments.length,t=0;t<arguments.length;t++)n[i++]=arguments[t];this.ma=i}}function n(e){return function(){return o[e].apply(o,arguments)}}var i=document.createElement("canvas");i.width=1,i.height=1;var o=i.getContext("2d");i=["font"];var a="fillStyle globalAlpha globalCompositeOperation lineCap lineDashOffset lineJoin lineWidth miterLimit shadowBlur shadowColor shadowOffsetX shadowOffsetY strokeStyle textAlign textBaseline".split(" "),s={};return a.concat(i).forEach((function(e){s[e]=o[e]})),e.prototype.clear=function(){this.ma=0},e.prototype.Ga=function(){return 0===this.ma},e.prototype.Na=function(e){e instanceof r?function(e,t,n){for(var i=0,r=e.ma,o=e.buffer;i<n;)o[r++]=t[i++];e.ma=r}(e,this.buffer,this.ma):function(e,t,n,i){for(var r=0;r<n;)switch(t[r++]){case"set":e[t[r++]]=t[r++];break;case"setGlobalAlpha":e[t[r++]]=t[r++]*i;break;case"call":var o=t[r++];switch(t[r++]){case 0:e[o]();break;case 1:e[o](t[r++]);break;case 2:e[o](t[r++],t[r++]);break;case 3:e[o](t[r++],t[r++],t[r++]);break;case 4:e[o](t[r++],t[r++],t[r++],t[r++]);break;case 5:e[o](t[r++],t[r++],t[r++],t[r++],t[r++]);break;case 6:e[o](t[r++],t[r++],t[r++],t[r++],t[r++],t[r++]);break;case 7:e[o](t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++]);break;case 8:e[o](t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++]);break;case 9:e[o](t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++],t[r++]);break;default:throw"CB0"}}}(e,this.buffer,this.ma,y.I(e.globalAlpha,1))},e.prototype.replay=e.prototype.Na,e.prototype.i=function(){return new e},e.prototype.scratch=e.prototype.i,"arc arcTo beginPath bezierCurveTo clearRect clip closePath drawImage fill fillRect fillText lineTo moveTo putImageData quadraticCurveTo rect rotate scale setLineDash setTransform stroke strokeRect strokeText transform translate".split(" ").forEach((function(n){e.prototype[n]=t(n)})),["measureText","createLinearGradient","createRadialGradient","createPattern","getLineDash"].forEach((function(t){e.prototype[t]=n(t)})),["save","restore"].forEach((function(i){var r=n(i),o=t(i);e.prototype[i]=function(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}(o,r)})),i.forEach((function(t){Object.defineProperty(e.prototype,t,{set:function(e){o[t]=e,this.current[t]=e;var n=this.buffer;n[this.ma++]="set",n[this.ma++]=t,n[this.ma++]=e},get:function(){return this.current[t]}})})),a.forEach((function(t){Object.defineProperty(e.prototype,t,{set:function(e){this.current[t]=e;var n=this.buffer;n[this.ma++]="globalAlpha"===t?"setGlobalAlpha":"set",n[this.ma++]=t,n[this.ma++]=e},get:function(){return this.current[t]}})})),e.prototype.roundRect=function(e,t,n,i,r){Line truncated
|
||||
//# sourceMappingURL=viewer.js.map</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.chartData = [{"label":"readability.min.js","isAsset":true,"statSize":156970,"parsedSize":55954,"gzipSize":18947,"groups":[{"label":"node_modules","path":"./node_modules","statSize":155558,"groups":[{"label":"@mozilla/readability","path":"./node_modules/@mozilla/readability","statSize":88421,"groups":[{"id":804,"label":"Readability-readerable.js","path":"./node_modules/@mozilla/readability/Readability-readerable.js","statSize":4162},{"id":238,"label":"Readability.js","path":"./node_modules/@mozilla/readability/Readability.js","statSize":84033},{"id":396,"label":"index.js","path":"./node_modules/@mozilla/readability/index.js","statSize":226}],"parsedSize":0,"gzipSize":0},{"label":"dompurify/dist","path":"./node_modules/dompurify/dist","statSize":67137,"groups":[{"id":838,"label":"purify.js","path":"./node_modules/dompurify/dist/purify.js","statSize":67137}],"parsedSize":0,"gzipSize":0}],"parsedSize":0,"gzipSize":0},{"label":"src","path":"./src","statSize":1412,"groups":[{"id":954,"label":"index.js","path":"./src/index.js","statSize":1412,"parsedSize":55946,"gzipSize":18947}],"parsedSize":55946,"gzipSize":18947}],"isInitialByEntrypoint":{"main":true}}];
|
||||
window.entrypoints = ["main"];
|
||||
window.defaultSizes = "parsed";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Vendored
+1362
File diff suppressed because it is too large.
Load diff
Generated
+4537
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "readability",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"dompurify": "^3.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.24.7",
|
||||
"@babel/preset-env": "^7.24.7",
|
||||
"babel-loader": "^9.1.3",
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"compression-webpack-plugin": "^11.1.0",
|
||||
"terser-webpack-plugin": "^5.3.10",
|
||||
"webpack": "^5.92.1",
|
||||
"webpack-bundle-analyzer": "^4.10.2",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Readability, isProbablyReaderable } from '@mozilla/readability';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
function isReaderable() {
|
||||
return isProbablyReaderable(document);
|
||||
}
|
||||
|
||||
function parseReaderable(doc) {
|
||||
const reader = new Readability(doc);
|
||||
const article = reader.parse();
|
||||
return article;
|
||||
}
|
||||
|
||||
function applyReaderable() {
|
||||
const clonedDoc = document.cloneNode(true);
|
||||
const article = parseReaderable(clonedDoc);
|
||||
const markup = DOMPurify.sanitize(article.content);
|
||||
|
||||
// console.log('article title: ', parsed.title);
|
||||
// console.log('HTML string of processed article content: ', parsed.content);
|
||||
// console.log('text content of the article, with all the HTML tags removed: ', parsed.textContent);
|
||||
// console.log('length of an article, in characters: ', parsed.length);
|
||||
// console.log('article description, or short excerpt from the content: ', parsed.excerpt);
|
||||
// console.log('author metadata: ', parsed.byline);
|
||||
// console.log('content direction: ', parsed.dir);
|
||||
// console.log('name of the site: ', parsed.siteName);
|
||||
// console.log('content language: ', parsed.lang);
|
||||
// console.log('published time: ', parsed.publishedTime);
|
||||
|
||||
if (markup) {
|
||||
document.body.innerHTML = '<div style="margin: 4pt;">' + markup + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Attach functions to the window object
|
||||
window.isReaderable = isReaderable;
|
||||
window.applyReaderable = applyReaderable;
|
||||
|
||||
export { isReaderable, applyReaderable };
|
||||
@@ -0,0 +1,54 @@
|
||||
const path = require('path');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
const CompressionPlugin = require('compression-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'readability.min.js',
|
||||
library: 'ReadabilityBundle',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false
|
||||
})
|
||||
],
|
||||
usedExports: true,
|
||||
sideEffects: true
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
statsOptions: { source: false }
|
||||
}),
|
||||
new CompressionPlugin({
|
||||
algorithm: 'gzip',
|
||||
test: /\.js$/
|
||||
})
|
||||
]
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bang_navigator/features/about/data/repositories/package_info_repository.dart';
|
||||
import 'package:bang_navigator/features/bangs/data/models/bang.dart';
|
||||
import 'package:bang_navigator/features/bangs/domain/repositories/sync.dart';
|
||||
@@ -6,6 +8,7 @@ import 'package:bang_navigator/features/content_block/domain/repositories/sync.d
|
||||
import 'package:bang_navigator/features/search_browser/domain/services/session.dart';
|
||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:bang_navigator/features/web_view/domain/providers.dart';
|
||||
import 'package:exceptions/exceptions.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -90,6 +93,8 @@ class AppInitializationService extends _$AppInitializationService {
|
||||
final settings = await ref.read(settingsRepositoryProvider.future);
|
||||
final errors = <ErrorMessage>[];
|
||||
|
||||
unawaited(ref.read(readerabilityScriptProvider.future));
|
||||
|
||||
await _initPackageInfo();
|
||||
|
||||
final bangSyncResults = await _initBangs();
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'app_initialization.dart';
|
||||
// **************************************************************************
|
||||
|
||||
String _$appInitializationServiceHash() =>
|
||||
r'33b432bd7a2f72f83d0b22771348ebf6e4934a92';
|
||||
r'55484697ec5aadc60a8d92b5b7cea9e39457c67a';
|
||||
|
||||
/// See also [AppInitializationService].
|
||||
@ProviderFor(AppInitializationService)
|
||||
|
||||
@@ -15,15 +15,15 @@ import 'package:bang_navigator/features/search_browser/presentation/widgets/tabs
|
||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:bang_navigator/features/web_view/domain/repositories/web_view.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/readerability.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/switch_new_tab.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/widgets/web_page_dialog.dart';
|
||||
import 'package:bang_navigator/presentation/hooks/listenable_callback.dart';
|
||||
import 'package:bang_navigator/presentation/hooks/overlay_portal_controller.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/animate_gradient_shader.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/animated_indexed_stack.dart';
|
||||
import 'package:bang_navigator/utils/ui_helper.dart' as ui_helper;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -68,7 +68,6 @@ class KagiScreen extends HookConsumerWidget {
|
||||
final menuController = useMemoized(() => MenuController());
|
||||
|
||||
final lastBackButtonPress = useRef<DateTime?>(null);
|
||||
final webViewController = useRef<InAppWebViewController?>(null);
|
||||
|
||||
final overlayController = useOverlayPortalController();
|
||||
|
||||
@@ -111,7 +110,7 @@ class KagiScreen extends HookConsumerWidget {
|
||||
ref.read(overlayDialogProvider.notifier).show(
|
||||
WebPageDialog(
|
||||
page: page,
|
||||
webViewController: webViewController.value,
|
||||
webViewController: page.controller,
|
||||
onDismiss: ref
|
||||
.read(overlayDialogProvider.notifier)
|
||||
.dismiss,
|
||||
@@ -181,6 +180,92 @@ class KagiScreen extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
if (activeWebView != null)
|
||||
HookConsumer(
|
||||
builder: (context, ref, child) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
final controller =
|
||||
useListenable(activeWebView.page).value.controller;
|
||||
final readerabilityState = ref.watch(
|
||||
readerabilityControllerProvider(controller),
|
||||
);
|
||||
|
||||
final isReaderable = useValueListenable(
|
||||
activeWebView.isReaderable,
|
||||
);
|
||||
|
||||
final readerableApplied = useValueListenable(
|
||||
activeWebView.readerableApplied,
|
||||
);
|
||||
|
||||
final icon = useMemoized(
|
||||
() => readerableApplied
|
||||
? Icon(
|
||||
MdiIcons.bookOpen,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
)
|
||||
: const Icon(
|
||||
MdiIcons.bookOpenOutline,
|
||||
color: Colors.white,
|
||||
),
|
||||
[readerableApplied],
|
||||
);
|
||||
|
||||
return Visibility(
|
||||
visible: isReaderable == true || readerableApplied,
|
||||
child: InkWell(
|
||||
onTap: readerabilityState.isLoading
|
||||
? null
|
||||
: () async {
|
||||
final controller =
|
||||
activeWebView.currentController;
|
||||
|
||||
if (controller != null) {
|
||||
final readabilityNotifier = ref.read(
|
||||
readerabilityControllerProvider(
|
||||
controller,
|
||||
).notifier,
|
||||
);
|
||||
|
||||
if (readerableApplied) {
|
||||
await activeWebView
|
||||
.updateReaderableApplied(false);
|
||||
} else {
|
||||
await readabilityNotifier.applyReaderable();
|
||||
await activeWebView
|
||||
.updateReaderableApplied(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 15.0,
|
||||
horizontal: 8.0,
|
||||
),
|
||||
child: readerabilityState.when(
|
||||
data: (_) => icon,
|
||||
error: (error, stackTrace) => SizedBox.shrink(),
|
||||
loading: () => AnimateGradientShader(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
primaryEnd: Alignment.bottomLeft,
|
||||
secondaryEnd: Alignment.topRight,
|
||||
primaryColors: [
|
||||
colorScheme.primary,
|
||||
colorScheme.primaryContainer,
|
||||
],
|
||||
secondaryColors: [
|
||||
colorScheme.secondary,
|
||||
colorScheme.secondaryContainer,
|
||||
],
|
||||
child: icon,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (activeWebView != null && quickAction != null)
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
@@ -319,7 +404,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
final url = await webViewController.value?.getUrl();
|
||||
final url =
|
||||
await activeWebView?.currentController?.getUrl();
|
||||
if (url != null) {
|
||||
// ignore: use_build_context_synchronously
|
||||
await ui_helper.launchUrlFeedback(context, url);
|
||||
@@ -330,7 +416,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
final url = await webViewController.value?.getUrl();
|
||||
final url =
|
||||
await activeWebView?.currentController?.getUrl();
|
||||
if (url != null) {
|
||||
await Share.shareUri(url);
|
||||
}
|
||||
@@ -341,7 +428,7 @@ class KagiScreen extends HookConsumerWidget {
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await webViewController.value?.reload();
|
||||
await activeWebView?.currentController?.reload();
|
||||
},
|
||||
leadingIcon: const Icon(Icons.refresh),
|
||||
child: const Text('Reload'),
|
||||
@@ -362,7 +449,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
child: IconButton(
|
||||
onPressed: (history.canGoBack)
|
||||
? () async {
|
||||
await webViewController.value?.goBack();
|
||||
await activeWebView?.currentController
|
||||
?.goBack();
|
||||
menuController.close();
|
||||
}
|
||||
: null,
|
||||
@@ -374,7 +462,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
child: IconButton(
|
||||
onPressed: (history.canGoForward)
|
||||
? () async {
|
||||
await webViewController.value?.goForward();
|
||||
await activeWebView?.currentController
|
||||
?.goForward();
|
||||
menuController.close();
|
||||
}
|
||||
: null,
|
||||
@@ -404,9 +493,6 @@ class KagiScreen extends HookConsumerWidget {
|
||||
child: HookConsumer(
|
||||
builder: (context, ref, child) {
|
||||
final webViews = ref.watch(webViewRepositoryProvider);
|
||||
useListenableCallback(activeWebView?.page, () {
|
||||
webViewController.value = activeWebView?.page.value.controller;
|
||||
});
|
||||
|
||||
return BackButtonListener(
|
||||
onBackButtonPressed: () async {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:bang_navigator/features/content_block/domain/repositories/host.dart';
|
||||
import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@@ -28,3 +33,13 @@ Stream<Set<String>?> blockContentHosts(BlockContentHostsRef ref) {
|
||||
.watchHosts(sources: enableHostList)
|
||||
.map((hosts) => hosts.toSet());
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<String> readerabilityScript(ReaderabilityScriptRef ref) {
|
||||
return rootBundle.load('assets/scripts/readability.min.js.gz').then(
|
||||
(value) => compute(
|
||||
(message) => utf8.decode(gzip.decode(message)),
|
||||
value.buffer.asUint8List(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -21,5 +21,21 @@ final blockContentHostsProvider = StreamProvider<Set<String>?>.internal(
|
||||
);
|
||||
|
||||
typedef BlockContentHostsRef = StreamProviderRef<Set<String>?>;
|
||||
String _$readerabilityScriptHash() =>
|
||||
r'6fdd1aa920bc58c35ef9888158e572e25793870a';
|
||||
|
||||
/// See also [readerabilityScript].
|
||||
@ProviderFor(readerabilityScript)
|
||||
final readerabilityScriptProvider = FutureProvider<String>.internal(
|
||||
readerabilityScript,
|
||||
name: r'readerabilityScriptProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityScriptHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef ReaderabilityScriptRef = FutureProviderRef<String>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:bang_navigator/features/web_view/presentation/services/readerability_script.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'readerability.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ReaderabilityController extends _$ReaderabilityController {
|
||||
late ReaderabilityScriptService _service;
|
||||
|
||||
@override
|
||||
FutureOr<void> build(InAppWebViewController? controller) async {
|
||||
_service =
|
||||
ref.watch(readerabilityScriptServiceProvider(controller).notifier);
|
||||
}
|
||||
|
||||
Future<bool> isReaderable() async {
|
||||
state = const AsyncLoading();
|
||||
final result = await AsyncValue.guard(() async {
|
||||
return await _service.isReaderable();
|
||||
});
|
||||
state = result;
|
||||
|
||||
return result.valueOrNull ?? false;
|
||||
}
|
||||
|
||||
Future<void> applyReaderable() async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
await _service.applyReaderable();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'readerability.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$readerabilityControllerHash() =>
|
||||
r'1260623c58d23511c3e4f58f97e18663be354ced';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _$ReaderabilityController
|
||||
extends BuildlessAutoDisposeAsyncNotifier<void> {
|
||||
late final InAppWebViewController? controller;
|
||||
|
||||
FutureOr<void> build(
|
||||
InAppWebViewController? controller,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
@ProviderFor(ReaderabilityController)
|
||||
const readerabilityControllerProvider = ReaderabilityControllerFamily();
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
class ReaderabilityControllerFamily extends Family<AsyncValue<void>> {
|
||||
/// See also [ReaderabilityController].
|
||||
const ReaderabilityControllerFamily();
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
ReaderabilityControllerProvider call(
|
||||
InAppWebViewController? controller,
|
||||
) {
|
||||
return ReaderabilityControllerProvider(
|
||||
controller,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ReaderabilityControllerProvider getProviderOverride(
|
||||
covariant ReaderabilityControllerProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.controller,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'readerabilityControllerProvider';
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityController].
|
||||
class ReaderabilityControllerProvider
|
||||
extends AutoDisposeAsyncNotifierProviderImpl<ReaderabilityController,
|
||||
void> {
|
||||
/// See also [ReaderabilityController].
|
||||
ReaderabilityControllerProvider(
|
||||
InAppWebViewController? controller,
|
||||
) : this._internal(
|
||||
() => ReaderabilityController()..controller = controller,
|
||||
from: readerabilityControllerProvider,
|
||||
name: r'readerabilityControllerProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityControllerHash,
|
||||
dependencies: ReaderabilityControllerFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ReaderabilityControllerFamily._allTransitiveDependencies,
|
||||
controller: controller,
|
||||
);
|
||||
|
||||
ReaderabilityControllerProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.controller,
|
||||
}) : super.internal();
|
||||
|
||||
final InAppWebViewController? controller;
|
||||
|
||||
@override
|
||||
FutureOr<void> runNotifierBuild(
|
||||
covariant ReaderabilityController notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
controller,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(ReaderabilityController Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ReaderabilityControllerProvider._internal(
|
||||
() => create()..controller = controller,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
controller: controller,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeAsyncNotifierProviderElement<ReaderabilityController, void>
|
||||
createElement() {
|
||||
return _ReaderabilityControllerProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ReaderabilityControllerProvider &&
|
||||
other.controller == controller;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, controller.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin ReaderabilityControllerRef on AutoDisposeAsyncNotifierProviderRef<void> {
|
||||
/// The parameter `controller` of this provider.
|
||||
InAppWebViewController? get controller;
|
||||
}
|
||||
|
||||
class _ReaderabilityControllerProviderElement
|
||||
extends AutoDisposeAsyncNotifierProviderElement<ReaderabilityController,
|
||||
void> with ReaderabilityControllerRef {
|
||||
_ReaderabilityControllerProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
InAppWebViewController? get controller =>
|
||||
(origin as ReaderabilityControllerProvider).controller;
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:bang_navigator/features/web_view/domain/providers.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'readerability_script.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ReaderabilityScriptService extends _$ReaderabilityScriptService {
|
||||
late Future<String> _readerabilityScript;
|
||||
|
||||
@override
|
||||
Future<void> build(InAppWebViewController? controller) async {
|
||||
_readerabilityScript = ref.watch(readerabilityScriptProvider.future);
|
||||
}
|
||||
|
||||
Future<void> _injectScript() async {
|
||||
if (controller != null) {
|
||||
await _readerabilityScript
|
||||
.then((script) => controller!.evaluateJavascript(source: script));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> ensureScriptInjected() async {
|
||||
if (controller != null) {
|
||||
final injected = await controller!.evaluateJavascript(
|
||||
source:
|
||||
"(typeof window !== 'undefined' && typeof window.isReaderable === 'function')",
|
||||
) as bool;
|
||||
|
||||
if (!injected) {
|
||||
await _injectScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> isReaderable() async {
|
||||
await ensureScriptInjected();
|
||||
|
||||
if (controller != null) {
|
||||
return await controller!.evaluateJavascript(
|
||||
source: 'isReaderable();',
|
||||
) as bool;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> applyReaderable() async {
|
||||
await ensureScriptInjected();
|
||||
|
||||
if (controller != null) {
|
||||
await controller!.evaluateJavascript(source: 'applyReaderable();');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'readerability_script.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$readerabilityScriptServiceHash() =>
|
||||
r'780980e6771d8d860e261fb4bc41236a60e0aaab';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _$ReaderabilityScriptService
|
||||
extends BuildlessAutoDisposeAsyncNotifier<void> {
|
||||
late final InAppWebViewController? controller;
|
||||
|
||||
FutureOr<void> build(
|
||||
InAppWebViewController? controller,
|
||||
);
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
@ProviderFor(ReaderabilityScriptService)
|
||||
const readerabilityScriptServiceProvider = ReaderabilityScriptServiceFamily();
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
class ReaderabilityScriptServiceFamily extends Family<AsyncValue<void>> {
|
||||
/// See also [ReaderabilityScriptService].
|
||||
const ReaderabilityScriptServiceFamily();
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
ReaderabilityScriptServiceProvider call(
|
||||
InAppWebViewController? controller,
|
||||
) {
|
||||
return ReaderabilityScriptServiceProvider(
|
||||
controller,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ReaderabilityScriptServiceProvider getProviderOverride(
|
||||
covariant ReaderabilityScriptServiceProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.controller,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'readerabilityScriptServiceProvider';
|
||||
}
|
||||
|
||||
/// See also [ReaderabilityScriptService].
|
||||
class ReaderabilityScriptServiceProvider
|
||||
extends AutoDisposeAsyncNotifierProviderImpl<ReaderabilityScriptService,
|
||||
void> {
|
||||
/// See also [ReaderabilityScriptService].
|
||||
ReaderabilityScriptServiceProvider(
|
||||
InAppWebViewController? controller,
|
||||
) : this._internal(
|
||||
() => ReaderabilityScriptService()..controller = controller,
|
||||
from: readerabilityScriptServiceProvider,
|
||||
name: r'readerabilityScriptServiceProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$readerabilityScriptServiceHash,
|
||||
dependencies: ReaderabilityScriptServiceFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ReaderabilityScriptServiceFamily._allTransitiveDependencies,
|
||||
controller: controller,
|
||||
);
|
||||
|
||||
ReaderabilityScriptServiceProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.controller,
|
||||
}) : super.internal();
|
||||
|
||||
final InAppWebViewController? controller;
|
||||
|
||||
@override
|
||||
FutureOr<void> runNotifierBuild(
|
||||
covariant ReaderabilityScriptService notifier,
|
||||
) {
|
||||
return notifier.build(
|
||||
controller,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Override overrideWith(ReaderabilityScriptService Function() create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ReaderabilityScriptServiceProvider._internal(
|
||||
() => create()..controller = controller,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
controller: controller,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeAsyncNotifierProviderElement<ReaderabilityScriptService, void>
|
||||
createElement() {
|
||||
return _ReaderabilityScriptServiceProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ReaderabilityScriptServiceProvider &&
|
||||
other.controller == controller;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, controller.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin ReaderabilityScriptServiceRef
|
||||
on AutoDisposeAsyncNotifierProviderRef<void> {
|
||||
/// The parameter `controller` of this provider.
|
||||
InAppWebViewController? get controller;
|
||||
}
|
||||
|
||||
class _ReaderabilityScriptServiceProviderElement
|
||||
extends AutoDisposeAsyncNotifierProviderElement<ReaderabilityScriptService,
|
||||
void> with ReaderabilityScriptServiceRef {
|
||||
_ReaderabilityScriptServiceProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
InAppWebViewController? get controller =>
|
||||
(origin as ReaderabilityScriptServiceProvider).controller;
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -13,6 +13,7 @@ import 'package:bang_navigator/features/settings/data/models/settings.dart';
|
||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:bang_navigator/features/web_view/domain/entities/web_view_page.dart';
|
||||
import 'package:bang_navigator/features/web_view/domain/providers.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/readerability.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/controllers/switch_new_tab.dart';
|
||||
import 'package:bang_navigator/features/web_view/presentation/widgets/web_page_dialog.dart';
|
||||
import 'package:bang_navigator/features/web_view/utils/download_helper.dart';
|
||||
@@ -36,16 +37,45 @@ const _webViewSupportedSchemes = [
|
||||
];
|
||||
|
||||
class WebView extends StatefulHookConsumerWidget {
|
||||
final ValueNotifier<WebViewPage> _valueNotifier;
|
||||
final ValueNotifier<WebViewPage> _pageNotifier;
|
||||
|
||||
ValueListenable<WebViewPage> get page => _valueNotifier;
|
||||
final ValueNotifier<bool?> _isReaderable;
|
||||
final ValueNotifier<bool> _readerableApplied;
|
||||
|
||||
ValueListenable<WebViewPage> get page => _pageNotifier;
|
||||
|
||||
/// Don't cache this value as it depends on current value of a ValueListenable
|
||||
InAppWebViewController? get currentController =>
|
||||
_pageNotifier.value.controller;
|
||||
|
||||
ValueListenable<bool?> get isReaderable => _isReaderable;
|
||||
ValueListenable<bool> get readerableApplied => _readerableApplied;
|
||||
|
||||
void updatePage(WebViewPage Function(WebViewPage page) update) {
|
||||
_valueNotifier.value = update(_valueNotifier.value);
|
||||
_pageNotifier.value = update(_pageNotifier.value);
|
||||
}
|
||||
|
||||
void resetReaderable() {
|
||||
_isReaderable.value = null;
|
||||
_readerableApplied.value = false;
|
||||
}
|
||||
|
||||
Future<void> updateReaderableApplied(bool value) async {
|
||||
if (value == false) {
|
||||
await _pageNotifier.value.controller?.reload();
|
||||
}
|
||||
|
||||
_readerableApplied.value = value;
|
||||
}
|
||||
|
||||
void updateIsReaderable(bool value) {
|
||||
_isReaderable.value = value;
|
||||
}
|
||||
|
||||
WebView({required WebViewPage tab})
|
||||
: _valueNotifier = ValueNotifier(tab),
|
||||
: _pageNotifier = ValueNotifier(tab),
|
||||
_isReaderable = ValueNotifier(null),
|
||||
_readerableApplied = ValueNotifier(false),
|
||||
super(key: tab.key);
|
||||
|
||||
@override
|
||||
@@ -128,7 +158,10 @@ class _WebViewState extends ConsumerState<WebView> {
|
||||
_onLoadStopDebounce?.cancel();
|
||||
_periodicScreenshotUpdate?.cancel();
|
||||
|
||||
widget._valueNotifier.dispose();
|
||||
widget._pageNotifier.dispose();
|
||||
widget._isReaderable.dispose();
|
||||
widget._readerableApplied.dispose();
|
||||
|
||||
logger.i('Disposed ${widget.key} (${widget.page.value.title})');
|
||||
}
|
||||
|
||||
@@ -340,8 +373,10 @@ class _WebViewState extends ConsumerState<WebView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
widget.resetReaderable();
|
||||
},
|
||||
onLoadStop: (controller, url) {
|
||||
onLoadStop: (controller, url) async {
|
||||
if (url != null) {
|
||||
widget.updatePage((page) => page.copyWith.url(url));
|
||||
}
|
||||
@@ -365,6 +400,12 @@ class _WebViewState extends ConsumerState<WebView> {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
final readabilityNotifier = ref.read(
|
||||
readerabilityControllerProvider(controller).notifier,
|
||||
);
|
||||
|
||||
widget.updateIsReaderable(await readabilityNotifier.isReaderable());
|
||||
},
|
||||
onUpdateVisitedHistory: (controller, url, isReload) async {
|
||||
if (isReload != true) {
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnimateGradientShader extends StatefulWidget {
|
||||
const AnimateGradientShader({
|
||||
super.key,
|
||||
required this.primaryColors,
|
||||
required this.secondaryColors,
|
||||
this.child,
|
||||
this.primaryBegin = Alignment.topLeft,
|
||||
this.primaryEnd = Alignment.topRight,
|
||||
this.secondaryBegin = Alignment.bottomLeft,
|
||||
this.secondaryEnd = Alignment.bottomRight,
|
||||
this.primaryBeginGeometry,
|
||||
this.primaryEndGeometry,
|
||||
this.secondaryBeginGeometry,
|
||||
this.secondaryEndGeometry,
|
||||
this.textDirectionForGeometry = TextDirection.ltr,
|
||||
this.controller,
|
||||
this.duration = const Duration(seconds: 4),
|
||||
this.animateAlignments = true,
|
||||
this.reverse = true,
|
||||
}) : assert(primaryColors.length >= 2),
|
||||
assert(primaryColors.length == secondaryColors.length);
|
||||
|
||||
/// [controller]: pass this to have a fine control over the [Animation]
|
||||
final AnimationController? controller;
|
||||
|
||||
/// [duration]: Time to switch between [Gradient].
|
||||
/// By default its value is [Duration(seconds:4)]
|
||||
final Duration duration;
|
||||
|
||||
/// [primaryColors]: These will be the starting colors of the [Animation].
|
||||
final List<Color> primaryColors;
|
||||
|
||||
/// [secondaryColors]: These Colors are those in which the [primaryColors] will transition into.
|
||||
final List<Color> secondaryColors;
|
||||
|
||||
/// [primaryBegin]: This is begin [Alignment] for [primaryColors].
|
||||
/// By default its value is [Alignment.topLeft]
|
||||
final Alignment primaryBegin;
|
||||
|
||||
/// [primaryBegin]: This is end [Alignment] for [primaryColors].
|
||||
/// By default its value is [Alignment.topRight]
|
||||
final Alignment primaryEnd;
|
||||
|
||||
/// [secondaryBegin]: This is begin [Alignment] for [secondaryColors].
|
||||
/// By default its value is [Alignment.bottomLeft]
|
||||
final Alignment secondaryBegin;
|
||||
|
||||
/// [secondaryEnd]: This is end [Alignment] for [secondaryColors].
|
||||
/// By default its value is [Alignment.bottomRight]
|
||||
final Alignment secondaryEnd;
|
||||
|
||||
/// Alternatively you can use [primaryBeginGeometry] over [primaryBegin] for better control over alignments
|
||||
/// These are really useful for when you are builing an [rtl] app.
|
||||
/// [primaryBeginGeometry] will have higher priority than [primaryBegin]
|
||||
final AlignmentGeometry? primaryBeginGeometry;
|
||||
|
||||
/// Alternatively you can use [primaryEndGeometry] over [primaryEnd] for better control over alignments
|
||||
/// These are really useful for when you are builing an [rtl] app.
|
||||
/// [primaryEndGeometry] will have higher priority than [primaryEnd]
|
||||
final AlignmentGeometry? primaryEndGeometry;
|
||||
|
||||
/// Alternatively you can use [secondaryBeginGeometry] over [secondaryBegin] for better control over alignments
|
||||
/// These are really useful for when you are builing an [rtl] app.
|
||||
/// [secondaryBeginGeometry] will have higher priority than [secondaryBegin]
|
||||
final AlignmentGeometry? secondaryBeginGeometry;
|
||||
|
||||
/// Alternatively you can use [secondaryEndGeometry] over [secondaryEnd] for better control over alignments
|
||||
/// These are really useful for when you are builing an [rtl] app.
|
||||
/// [secondaryEndGeometry] will have higher priority than [secondaryEnd]
|
||||
final AlignmentGeometry? secondaryEndGeometry;
|
||||
|
||||
/// This is the [TextDirection] which is gonna be used to resolve [AlignmentGeometry] passed through
|
||||
/// [primaryBeginGeometry], [primaryEndGeometry], [secondaryBeginGeometry], [secondaryEndGeometry]
|
||||
final TextDirection textDirectionForGeometry;
|
||||
|
||||
/// [animateAlignments]: set to false if you don't want to animate the alignments.
|
||||
/// This can provide you way cooler animations
|
||||
final bool animateAlignments;
|
||||
|
||||
/// [reverse]: set it to false if you don't want to reverse the animation.
|
||||
/// using that it will go into one direction only
|
||||
final bool reverse;
|
||||
|
||||
final Widget? child;
|
||||
|
||||
@override
|
||||
State<AnimateGradientShader> createState() => _AnimateGradientShaderState();
|
||||
}
|
||||
|
||||
class _AnimateGradientShaderState extends State<AnimateGradientShader>
|
||||
with TickerProviderStateMixin {
|
||||
late Animation<double> _animation;
|
||||
late AnimationController _controller;
|
||||
|
||||
late List<ColorTween> _colorTween;
|
||||
|
||||
late AlignmentTween begin;
|
||||
late AlignmentTween end;
|
||||
List<Color> primaryColors = [];
|
||||
List<Color> secondaryColors = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_initialize();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AnimateGradientShader oldWidget) {
|
||||
_initialize();
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
void _initialize() {
|
||||
primaryColors = widget.primaryColors;
|
||||
secondaryColors = widget.secondaryColors;
|
||||
_colorTween = _getColorTweens();
|
||||
if (widget.animateAlignments) _setAlignmentTweens();
|
||||
_setAnimations();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
final gradient = LinearGradient(
|
||||
begin: widget.animateAlignments
|
||||
? begin.evaluate(_animation)
|
||||
: widget.primaryBegin,
|
||||
end: widget.animateAlignments
|
||||
? end.evaluate(_animation)
|
||||
: widget.primaryEnd,
|
||||
colors: _evaluateColors(_animation),
|
||||
);
|
||||
|
||||
return ShaderMask(
|
||||
shaderCallback: (Rect bounds) {
|
||||
return gradient
|
||||
.createShader(Rect.fromLTWH(0, 0, bounds.width, bounds.height));
|
||||
},
|
||||
child: widget.child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<ColorTween> _getColorTweens() {
|
||||
if (widget.primaryColors.length != widget.secondaryColors.length) {
|
||||
throw Exception('primaryColors.length != secondaryColors.length');
|
||||
}
|
||||
|
||||
final List<ColorTween> colorTweens = [];
|
||||
|
||||
for (int i = 0; i < primaryColors.length; i++) {
|
||||
colorTweens.add(
|
||||
ColorTween(
|
||||
begin: primaryColors[i],
|
||||
end: secondaryColors[i],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return colorTweens;
|
||||
}
|
||||
|
||||
List<Color> _evaluateColors(Animation<double> animation) {
|
||||
final List<Color> colors = [];
|
||||
for (int i = 0; i < _colorTween.length; i++) {
|
||||
colors.add(_colorTween[i].evaluate(animation)!);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
void _setAlignmentTweens() {
|
||||
final primaryBeginGeometry = widget.primaryBeginGeometry?.resolve(
|
||||
widget.textDirectionForGeometry,
|
||||
);
|
||||
final primaryEndGeometry = widget.primaryEndGeometry?.resolve(
|
||||
widget.textDirectionForGeometry,
|
||||
);
|
||||
final secondaryBeginGeometry = widget.secondaryBeginGeometry?.resolve(
|
||||
widget.textDirectionForGeometry,
|
||||
);
|
||||
final secondaryEndGeometry = widget.secondaryEndGeometry?.resolve(
|
||||
widget.textDirectionForGeometry,
|
||||
);
|
||||
|
||||
begin = AlignmentTween(
|
||||
begin: primaryBeginGeometry ?? widget.primaryBegin,
|
||||
end: primaryEndGeometry ?? widget.primaryEnd,
|
||||
);
|
||||
end = AlignmentTween(
|
||||
begin: secondaryBeginGeometry ?? widget.secondaryBegin,
|
||||
end: secondaryEndGeometry ?? widget.secondaryEnd,
|
||||
);
|
||||
}
|
||||
|
||||
void _setAnimations() {
|
||||
_controller = widget.controller ??
|
||||
AnimationController(
|
||||
vsync: this,
|
||||
duration: widget.duration,
|
||||
)
|
||||
..repeat(reverse: widget.reverse);
|
||||
_animation = CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -71,9 +71,10 @@ dev_dependencies:
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- assets/icon/icon.png
|
||||
- assets/icon/
|
||||
- assets/landing/
|
||||
- assets/fonts/
|
||||
- assets/scripts/
|
||||
|
||||
flutter_launcher_icons:
|
||||
android: "launcher_icon"
|
||||
|
||||
Reference in new issue
Block a user