fetch-css 4.1.4 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -12
- package/dist/index.js +2 -2
- package/package.json +21 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { FetchOpts } from "fetch-enhanced";
|
|
2
|
-
|
|
3
2
|
//#region index.d.ts
|
|
4
3
|
/** A single CSS source to fetch from a website, file or browser extension. */
|
|
5
|
-
type Source = {
|
|
6
|
-
/** An absolute URL pointing to a website or directly to a CSS or JS file, or an array of such URLs. */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export type Source = {
|
|
5
|
+
/** An absolute URL pointing to a website or directly to a CSS or JS file, or an array of such URLs. */
|
|
6
|
+
url?: string | Array<string>;
|
|
7
|
+
/** Options passed to `fetch`. */
|
|
8
|
+
fetchOpts?: FetchOpts;
|
|
9
|
+
/** A Chrome extension id. */
|
|
10
|
+
crx?: string;
|
|
11
|
+
/** Whether to pull only content scripts from an extension. Default: `false`. */
|
|
12
|
+
contentScriptsOnly?: boolean;
|
|
13
|
+
/** Whether to throw an error if a fetch fails. Default: `false`. */
|
|
14
|
+
strict?: boolean;
|
|
15
|
+
/** The extracted CSS, present on the resolved sources. */
|
|
16
|
+
css?: string;
|
|
17
|
+
/** The resolved stylesheet URLs, present on the resolved sources. */
|
|
18
|
+
urls?: Array<string>;
|
|
19
|
+
/** The extracted inline `<style>` tag contents, present on the resolved sources. */
|
|
13
20
|
styleTags?: Array<string>;
|
|
14
21
|
};
|
|
15
22
|
/**
|
|
@@ -17,6 +24,5 @@ type Source = {
|
|
|
17
24
|
*
|
|
18
25
|
* Returns the given `sources` array with an additional `css` property present on each source.
|
|
19
26
|
*/
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
export { Source, fetchCss as default };
|
|
27
|
+
export default function fetchCss(sources: Array<Source>): Promise<Array<Source>>;
|
|
28
|
+
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{parse as e}from"acorn";import t from"rfdc";import n from"postcss";import{parseFragment as r}from"parse5";import i from"unzipper";import a from"url-toolkit";import o
|
|
1
|
+
import{parse as e}from"acorn";import t from"rfdc";import n from"postcss";import{parseFragment as r}from"parse5";import i from"unzipper";import a from"url-toolkit";import{createHash as o}from"node:crypto";import{fetch as s}from"undici";import c from"fetch-enhanced";function l(e,t,n,r){let i=0;return i+=e,i+=t<<8,i+=n<<16,i+=r<<24>>>0,i}function u(e,t,n){let r=``;for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function d(e){let t=new Uint8Array(e);if(t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4)throw Error(`Input is not a CRX file, but a ZIP file.`);if(t[0]!==67||t[1]!==114||t[2]!==50||t[3]!==52)throw p(t)?Error(`Input is not a CRX file, but possibly a ZIP file.`):Error(`Invalid header: Does not start with Cr24.`);if(t[4]!==2&&t[4]!==3||t[5]||t[6]||t[7])throw Error(`Unexpected crx format version number.`);let n;if(t[4]===2){let e=l(t[8],t[9],t[10],t[11]),r=l(t[12],t[13],t[14],t[15]);n=16+e+r,btoa(u(t,16,16+e))}else n=12+l(t[8],t[9],t[10],t[11]),f(t,12,n);return e.slice(n)}function f(e,t,n){function r(){let n=e[t]&127;if(e[t++]<128||(n|=(e[t]&127)<<7,e[t++]<128)||(n|=(e[t]&127)<<14,e[t++]<128)||(n|=(e[t]&127)<<21,e[t++]<128))return n;if(n=(n|(e[t]&15)<<28)>>>0,e[t++]&128)throw Error(`proto: not a uint32`);return n}let i=[],a;for(;t<n;){let o=r(),s=r();if(o===80002){let n=r(),i=r();if(n!==10)throw Error(`proto: Unexpected key in signed_header_data: ${n}`);if(i!==16)throw Error(`proto: Unexpected signed_header_data length ${s}`);if(a)throw Error(`proto: Unexpected duplicate signed_header_data`);a=e.subarray(t,t+16),t+=i;continue}if(o!==18){if(o!==26)throw Error(`proto: Unexpected key: ${o}`);t+=s;continue}let c=t+s,l=r(),d=r();if(l===18){if(t+=d,t>=c)continue;l=r(),d=r()}if(l!==10)throw t+=d,Error(`proto: Unexpected key in AsymmetricKeyProof: ${l}`);if(t+d>n)throw Error(`proto: size of public_key field is too large`);i.push(u(e,t,t+d)),t=c}if(!i.length)throw Error(`proto: Did not find any public key`);if(!a)throw Error(`proto: Did not find crx_id`);let s=Buffer.from(a).toString(`hex`);for(let e of i)if(o(`sha256`).update(e,`latin1`).digest(`hex`).slice(0,32)===s)return btoa(e);throw Error(`proto: None of the public keys matched with crx_id`)}function p(e){for(let t=e.length-22,n=Math.max(0,t-65535);t>=n;--t)if(e[t]===80&&e[t+1]===75&&e[t+2]===5&&e[t+3]===6)return!0;return!1}const m=c(s,{undici:!0}),h=t();async function g(e,t){try{return await m(e,t)}catch(t){throw t.message=`${t.message} (${e})`,t}}async function _(e){let t=[],n=[],r=await e.text();for(let n of y(r))t.push(a.buildAbsoluteURL(e.url,n));for(let e of b(r))n.push(e);return[t,n]}function v(e,t,n){if(e.status===200)return;let r=`Failed to fetch ${t}: ${e.status} ${e.statusText}`;if(n)throw Error(r);console.warn(`(fetch-css) Warning: ${r}`)}function y(e){return(e.match(/<link.+?>/g)||[]).map(e=>{let t={};for(let n of r(e).childNodes[0].attrs)t[n.name]=n.value;return t.href&&t.rel===`stylesheet`||t.href&&/\.css$/i.test(t.href.replace(/\?.+/,`undefined`))?t.href:null}).filter(Boolean)}function b(e){return Array.from((e||``).matchAll(/<style.*?>([\s\S]*?)<\/style>/g)||[]).map(e=>e[1]).map(e=>e.trim()).filter(Boolean)}function x(e){try{let t=n.parse(e);if(t&&t.type===`root`&&Array.isArray(t.nodes)&&t.nodes.length>=1&&t.nodes.every(e=>e.type===`rule`))return!0}catch{}return!1}function S(e){let t=Buffer.alloc(e.byteLength),n=new Uint8Array(e);for(let e=0;e<t.length;++e)t[e]=n[e];return t}function C(t){let n=``;return e(t,{ecmaVersion:`latest`,onToken:e=>{if(e.type.label===`string`){let t=e.value.trim().replace(/\n/g,``).replace(/^\);\}/,``);t.length>25&&x(t)&&(n+=`${t}\n`)}}}),n.trim()}async function w({crx:e,contentScriptsOnly:t,strict:n}){let r=`https://clients2.google.com/service/update2/crx`;r+=`?response=redirect`,r+=`&os=linux`,r+=`&arch=x86-64`,r+=`&os_arch=x86-64`,r+=`&acceptformat=crx3`,r+=`&prod=chromiumcrx`,r+=`&prodchannel=unknown`,r+=`&prodversion=9999.0.9999.0`,r+=`&x=id%3D${e}`,r+=`%26uc`;let a=await g(r);v(a,r,n);let o=S(await a.arrayBuffer()),s=Buffer.from(d(o)),c={};for(let e of(await i.Open.buffer(s)||{files:[]}).files)c[e.path]=e;if(!c[`manifest.json`])throw Error(`manifest.json not found in extension ${e}`);let l=[],u=[];if(!t)for(let e of Object.keys(c))e.endsWith(`.css`)&&l.push(e),e.endsWith(`.js`)&&u.push(e);let f=JSON.parse(String(await c[`manifest.json`].buffer()));for(let{css:e,js:t}of f.content_scripts||[])Array.isArray(e)&&e.length&&l.push(...e),Array.isArray(t)&&t.length&&u.push(...t);l=Array.from(new Set(l)),u=Array.from(new Set(u)),l=l.map(e=>e.replace(/^\//,``)),u=u.map(e=>e.replace(/^\//,``));let p=``;for(let e of l)p+=`${String(await c[e].buffer())}\n`;for(let e of u){let t=String(await c[e].buffer());p+=C(t)}return p}async function T(e){e=h(e);let t=[];for(let n of e)if(`url`in n&&Array.isArray(n.url))for(let e of n.url)t.push({...n,url:e});else t.push(n);e=t;let n=await Promise.all(e.map(e=>{if(!e.url)return Promise.resolve(null);let{pathname:t}=new URL(e.url);return t.endsWith(`.css`)||t.endsWith(`.js`)?Promise.resolve(null):g(e.url,e.fetchOpts)}));for(let[t,r]of n.entries()){let n=e[t];if(n.urls=[],n.styleTags=[],r){v(r,n.url,n.strict);let[e,t]=await _(r);n.urls.push(...e),n.styleTags.push(...t)}else n.url&&(n.urls=[n.url])}let r=await Promise.all(e.map(e=>e.url?Promise.all(e.urls.map(async e=>(await g(e)).text())):Promise.resolve(null)));for(let[t,n]of r.entries()){let r=e[t];r.crx?r.css=await w(r):r.url.endsWith(`.js`)?r.css=C(n.join(`
|
|
2
2
|
`)):(r.css=n.join(`
|
|
3
3
|
`),r.styleTags?.length&&(r.css+=`\n${r.styleTags.join(`
|
|
4
|
-
`)}`))}return e}export{
|
|
4
|
+
`)}`))}return e}export{T as default};
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-css",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Extract CSS from websites and browser extensions",
|
|
5
5
|
"author": "silverwind",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/silverwind/fetch-css.git"
|
|
9
|
+
},
|
|
7
10
|
"license": "BSD-2-Clause",
|
|
8
11
|
"type": "module",
|
|
9
12
|
"sideEffects": false,
|
|
@@ -11,7 +14,7 @@
|
|
|
11
14
|
"exports": "./dist/index.js",
|
|
12
15
|
"types": "./dist/index.d.ts",
|
|
13
16
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
17
|
+
"node": ">=24",
|
|
15
18
|
"bun": "*"
|
|
16
19
|
},
|
|
17
20
|
"keywords": [
|
|
@@ -25,29 +28,27 @@
|
|
|
25
28
|
"dist"
|
|
26
29
|
],
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"acorn": "8.
|
|
29
|
-
"
|
|
30
|
-
"fetch-enhanced": "13.0.0",
|
|
31
|
+
"acorn": "8.18.0",
|
|
32
|
+
"fetch-enhanced": "13.0.1",
|
|
31
33
|
"parse5": "8.0.1",
|
|
32
|
-
"postcss": "8.5.
|
|
34
|
+
"postcss": "8.5.28",
|
|
33
35
|
"rfdc": "1.4.1",
|
|
34
|
-
"undici": "8.2
|
|
35
|
-
"unzipper": "0.12.
|
|
36
|
+
"undici": "8.11.2",
|
|
37
|
+
"unzipper": "0.12.5",
|
|
36
38
|
"url-toolkit": "2.2.5"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/node": "25.8.0",
|
|
41
|
+
"@types/node": "26.6.2",
|
|
41
42
|
"@types/unzipper": "0.10.11",
|
|
42
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
43
|
-
"eslint": "10.
|
|
44
|
-
"eslint-config-silverwind": "
|
|
45
|
-
"tsdown": "0.
|
|
46
|
-
"tsdown-config-silverwind": "
|
|
43
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
44
|
+
"eslint": "10.11.0",
|
|
45
|
+
"eslint-config-silverwind": "151.0.0",
|
|
46
|
+
"tsdown": "0.23.0",
|
|
47
|
+
"tsdown-config-silverwind": "4.1.1",
|
|
47
48
|
"typescript": "6.0.3",
|
|
48
|
-
"typescript-config-silverwind": "
|
|
49
|
-
"updates": "
|
|
50
|
-
"updates-config-silverwind": "
|
|
51
|
-
"versions": "15.0
|
|
49
|
+
"typescript-config-silverwind": "21.0.0",
|
|
50
|
+
"updates": "19.0.0",
|
|
51
|
+
"updates-config-silverwind": "4.0.6",
|
|
52
|
+
"versions": "15.5.0"
|
|
52
53
|
}
|
|
53
54
|
}
|