diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 0000000..52b639c --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +css-inline.org diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..1c870cf --- /dev/null +++ b/docs/README.md @@ -0,0 +1,24 @@ +# css-inline + +## @css-inline/css-inline-wasm + +[build status](https://github.com/Stranger6667/css-inline/actions/workflows/build.yml) +[npm](https://www.npmjs.com/package/@css-inline/css-inline-wasm) +[codecov.io](https://app.codecov.io/github/Stranger6667/css-inline) +[gitter](https://gitter.im/Stranger6667/css-inline) + +`css-inline` is a high-performance library for inlining CSS into HTML 'style' attributes. + +This is the **WebAssembly** module for [`css-inline`](https://github.com/Stranger6667/css-inline) + +## Playground + +If you'd like to try `css-inline`, you can check the WebAssembly-powered [playground](https://css-inline.org/) to see the results instantly. + +## Restrictions + +WASM module currently lacks support for fetching stylesheets from network or filesystem. + +## License + +This project is licensed under the terms of the [MIT license](https://opensource.org/licenses/MIT). diff --git a/docs/index.d.ts b/docs/index.d.ts new file mode 100644 index 0000000..ba0b354 --- /dev/null +++ b/docs/index.d.ts @@ -0,0 +1,25 @@ +// Generated by dts-bundle-generator v9.1.0 + +/* tslint:disable */ +/* eslint-disable */ +export interface InlineOptions { + inlineStyleTags?: boolean; + keepStyleTags?: boolean; + keepLinkTags?: boolean; + baseUrl?: string; + loadRemoteStylesheets?: boolean; + extraCss?: string; + preallocateNodeCapacity?: number; +} +export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; +/** + * Initialize Wasm module + * @param module_or_path WebAssembly Module or .wasm url + * + */ +export declare const initWasm: (module_or_path: Promise | InitInput) => Promise; +export declare function inline(html: string, options?: InlineOptions): string; +export declare function inlineFragment(html: string, css: string, options?: InlineOptions): string; +export declare function version(): string; + +export {}; diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..3b7a9be --- /dev/null +++ b/docs/index.html @@ -0,0 +1,224 @@ + + + + + + + + CSS Inline | High-performance CSS inlining + + + + + + +
+ +
+ +
+

+ High-performance library for inlining CSS into HTML 'style' attributes +

+

+ css-inline leverages Mozilla's Servo project components and works with + Rust, Python, Ruby, JavaScript, and C. The playground below is powered + by WebAssembly allows direct browser interaction with the library. Edit + the HTML in the text area and click "Inline" to view the results + instantly. +

+
+ +
+ +
+ +
+ +
+ + + + + +
+
+
+
+

+ © css-inline.org by + Dmitry Dygalo +

+
+
+

+ ... +

+
+
+
+ + diff --git a/docs/index.js b/docs/index.js new file mode 100644 index 0000000..2b33d26 --- /dev/null +++ b/docs/index.js @@ -0,0 +1,446 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// wasm-binding.ts +var wasm_binding_exports = {}; +__export(wasm_binding_exports, { + initWasm: () => initWasm, + inline: () => inline2, + inlineFragment: () => inlineFragment2, + version: () => version2 +}); +module.exports = __toCommonJS(wasm_binding_exports); + +// wasm/dist/index.js +var wasm; +var heap = new Array(128).fill(void 0); +heap.push(void 0, null, true, false); +function getObject(idx) { + return heap[idx]; +} +var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => { + throw Error("TextDecoder not available"); +} }; +if (typeof TextDecoder !== "undefined") { + cachedTextDecoder.decode(); +} +var cachedUint8ArrayMemory0 = null; +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} +var heap_next = heap.length; +function addHeapObject(obj) { + if (heap_next === heap.length) + heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + heap[idx] = obj; + return idx; +} +function dropObject(idx) { + if (idx < 132) + return; + heap[idx] = heap_next; + heap_next = idx; +} +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} +var WASM_VECTOR_LEN = 0; +var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => { + throw Error("TextEncoder not available"); +} }; +var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} : function(arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}; +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === void 0) { + const buf = cachedTextEncoder.encode(arg); + const ptr2 = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr2; + } + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + const mem = getUint8ArrayMemory0(); + let offset = 0; + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 127) + break; + mem[ptr + offset] = code; + } + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + WASM_VECTOR_LEN = offset; + return ptr; +} +function isLikeNone(x) { + return x === void 0 || x === null; +} +var cachedDataViewMemory0 = null; +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} +function debugString(val) { + const type = typeof val; + if (type == "number" || type == "boolean" || val == null) { + return `${val}`; + } + if (type == "string") { + return `"${val}"`; + } + if (type == "symbol") { + const description = val.description; + if (description == null) { + return "Symbol"; + } else { + return `Symbol(${description})`; + } + } + if (type == "function") { + const name = val.name; + if (typeof name == "string" && name.length > 0) { + return `Function(${name})`; + } else { + return "Function"; + } + } + if (Array.isArray(val)) { + const length = val.length; + let debug = "["; + if (length > 0) { + debug += debugString(val[0]); + } + for (let i = 1; i < length; i++) { + debug += ", " + debugString(val[i]); + } + debug += "]"; + return debug; + } + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + return toString.call(val); + } + if (className == "Object") { + try { + return "Object(" + JSON.stringify(val) + ")"; + } catch (_) { + return "Object"; + } + } + if (val instanceof Error) { + return `${val.name}: ${val.message} +${val.stack}`; + } + return className; +} +function inline(html, options) { + let deferred3_0; + let deferred3_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.inline(retptr, ptr0, len0, addHeapObject(options)); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); + var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true); + var ptr2 = r0; + var len2 = r1; + if (r3) { + ptr2 = 0; + len2 = 0; + throw takeObject(r2); + } + deferred3_0 = ptr2; + deferred3_1 = len2; + return getStringFromWasm0(ptr2, len2); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); + } +} +function inlineFragment(html, css, options) { + let deferred4_0; + let deferred4_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passStringToWasm0(css, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + wasm.inlineFragment(retptr, ptr0, len0, ptr1, len1, addHeapObject(options)); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); + var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true); + var ptr3 = r0; + var len3 = r1; + if (r3) { + ptr3 = 0; + len3 = 0; + throw takeObject(r2); + } + deferred4_0 = ptr3; + deferred4_1 = len3; + return getStringFromWasm0(ptr3, len3); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred4_0, deferred4_1, 1); + } +} +function version() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.version(retptr); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } +} +async function __wbg_load(module2, imports) { + if (typeof Response === "function" && module2 instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === "function") { + try { + return await WebAssembly.instantiateStreaming(module2, imports); + } catch (e) { + if (module2.headers.get("Content-Type") != "application/wasm") { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + } else { + throw e; + } + } + } + const bytes = await module2.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + } else { + const instance = await WebAssembly.instantiate(module2, imports); + if (instance instanceof WebAssembly.Instance) { + return { instance, module: module2 }; + } else { + return instance; + } + } +} +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = getObject(arg0) === void 0; + return ret; + }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_object = function(arg0) { + const val = getObject(arg0); + const ret = typeof val === "object" && val !== null; + return ret; + }; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) { + const ret = getObject(arg0)[getObject(arg1)]; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_in = function(arg0, arg1) { + const ret = getObject(arg0) in getObject(arg1); + return ret; + }; + imports.wbg.__wbg_isSafeInteger_7f1ed56200d90674 = function(arg0) { + const ret = Number.isSafeInteger(getObject(arg0)); + return ret; + }; + imports.wbg.__wbindgen_as_number = function(arg0) { + const ret = +getObject(arg0); + return ret; + }; + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + imports.wbg.__wbindgen_boolean_get = function(arg0) { + const v = getObject(arg0); + const ret = typeof v === "boolean" ? v ? 1 : 0 : 2; + return ret; + }; + imports.wbg.__wbindgen_string_get = function(arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "string" ? obj : void 0; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_length_8339fcf5d8ecd12e = function(arg0) { + const ret = getObject(arg0).length; + return ret; + }; + imports.wbg.__wbindgen_memory = function() { + const ret = wasm.memory; + return addHeapObject(ret); + }; + imports.wbg.__wbg_buffer_b7b08af79b0b0974 = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_ea1883e1e5e86686 = function(arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_d1e79e2388520f18 = function(arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbindgen_error_new = function(arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { + const ret = getObject(arg0) == getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_number_get = function(arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "number" ? obj : void 0; + getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); + }; + imports.wbg.__wbg_instanceof_Uint8Array_247a91427532499e = function(arg0) { + let result; + try { + result = getObject(arg0) instanceof Uint8Array; + } catch (_) { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_instanceof_ArrayBuffer_61dfc3198373c902 = function(arg0) { + let result; + try { + result = getObject(arg0) instanceof ArrayBuffer; + } catch (_) { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_debug_string = function(arg0, arg1) { + const ret = debugString(getObject(arg1)); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + return imports; +} +function __wbg_init_memory(imports, memory) { +} +function __wbg_finalize_init(instance, module2) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module2; + cachedDataViewMemory0 = null; + cachedUint8ArrayMemory0 = null; + return wasm; +} +async function __wbg_init(module_or_path) { + if (wasm !== void 0) + return wasm; + if (typeof module_or_path !== "undefined" && Object.getPrototypeOf(module_or_path) === Object.prototype) + ({ module_or_path } = module_or_path); + else + console.warn("using deprecated parameters for the initialization function; pass a single object instead"); + if (typeof module_or_path === "undefined") { + module_or_path = new URL("index_bg.wasm", void 0); + } + const imports = __wbg_get_imports(); + if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) { + module_or_path = fetch(module_or_path); + } + __wbg_init_memory(imports); + const { instance, module: module2 } = await __wbg_load(await module_or_path, imports); + return __wbg_finalize_init(instance, module2); +} +var dist_default = __wbg_init; + +// wasm-binding.ts +var initialized = false; +var initWasm = async (module_or_path) => { + if (initialized) { + throw new Error( + "Already initialized. The `initWasm()` function can be used only once." + ); + } + await dist_default(await module_or_path); + initialized = true; +}; +function inline2(html, options) { + return inline(html, options); +} +function inlineFragment2(html, css, options) { + return inlineFragment(html, css, options); +} +function version2() { + return version(); +} diff --git a/docs/index.min.js b/docs/index.min.js new file mode 100644 index 0000000..e8599bf --- /dev/null +++ b/docs/index.min.js @@ -0,0 +1,2 @@ +"use strict";var cssInline=(()=>{var S=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var V=(e,n)=>{for(var t in n)S(e,t,{get:n[t],enumerable:!0})},q=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of B(n))!P.call(e,i)&&i!==t&&S(e,i,{get:()=>n[i],enumerable:!(r=z(n,i))||r.enumerable});return e};var C=e=>q(S({},"__esModule",{value:!0}),e);var ne={};V(ne,{initWasm:()=>X,inline:()=>Y,inlineFragment:()=>Z,version:()=>ee});var o,d=new Array(128).fill(void 0);d.push(void 0,null,!0,!1);function c(e){return d[e]}var T=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&T.decode();var h=null;function j(){return(h===null||h.byteLength===0)&&(h=new Uint8Array(o.memory.buffer)),h}function m(e,n){return e=e>>>0,T.decode(j().subarray(e,e+n))}var I=d.length;function g(e){I===d.length&&d.push(d.length+1);let n=I;return I=d[n],d[n]=e,n}function H(e){e<132||(d[e]=I,I=e)}function E(e){let n=c(e);return H(e),n}var p=0,x=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},J=typeof x.encodeInto=="function"?function(e,n){return x.encodeInto(e,n)}:function(e,n){let t=x.encode(e);return n.set(t),{read:e.length,written:t.length}};function A(e,n,t){if(t===void 0){let u=x.encode(e),a=n(u.length,1)>>>0;return j().subarray(a,a+u.length).set(u),p=u.length,a}let r=e.length,i=n(r,1)>>>0,_=j(),s=0;for(;s127)break;_[i+s]=u}if(s!==r){s!==0&&(e=e.slice(s)),i=t(i,r,r=s+e.length*3,1)>>>0;let u=j().subarray(i+s,i+r),a=J(e,u);s+=a.written,i=t(i,r,s,1)>>>0}return p=s,i}function W(e){return e==null}var y=null;function f(){return(y===null||y.buffer.detached===!0||y.buffer.detached===void 0&&y.buffer!==o.memory.buffer)&&(y=new DataView(o.memory.buffer)),y}function v(e){let n=typeof e;if(n=="number"||n=="boolean"||e==null)return`${e}`;if(n=="string")return`"${e}"`;if(n=="symbol"){let i=e.description;return i==null?"Symbol":`Symbol(${i})`}if(n=="function"){let i=e.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(e)){let i=e.length,_="[";i>0&&(_+=v(e[0]));for(let s=1;s1)r=t[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message} +${e.stack}`:r}function k(e,n){let t,r;try{let b=o.__wbindgen_add_to_stack_pointer(-16),w=A(e,o.__wbindgen_malloc,o.__wbindgen_realloc),O=p;o.inline(b,w,O,g(n));var i=f().getInt32(b+4*0,!0),_=f().getInt32(b+4*1,!0),s=f().getInt32(b+4*2,!0),u=f().getInt32(b+4*3,!0),a=i,l=_;if(u)throw a=0,l=0,E(s);return t=a,r=l,m(a,l)}finally{o.__wbindgen_add_to_stack_pointer(16),o.__wbindgen_free(t,r,1)}}function F(e,n,t){let r,i;try{let w=o.__wbindgen_add_to_stack_pointer(-16),O=A(e,o.__wbindgen_malloc,o.__wbindgen_realloc),$=p,L=A(n,o.__wbindgen_malloc,o.__wbindgen_realloc),N=p;o.inlineFragment(w,O,$,L,N,g(t));var _=f().getInt32(w+4*0,!0),s=f().getInt32(w+4*1,!0),u=f().getInt32(w+4*2,!0),a=f().getInt32(w+4*3,!0),l=_,b=s;if(a)throw l=0,b=0,E(u);return r=l,i=b,m(l,b)}finally{o.__wbindgen_add_to_stack_pointer(16),o.__wbindgen_free(r,i,1)}}function M(){let e,n;try{let i=o.__wbindgen_add_to_stack_pointer(-16);o.version(i);var t=f().getInt32(i+4*0,!0),r=f().getInt32(i+4*1,!0);return e=t,n=r,m(t,r)}finally{o.__wbindgen_add_to_stack_pointer(16),o.__wbindgen_free(e,n,1)}}async function G(e,n){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,n)}catch(r){if(e.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}let t=await e.arrayBuffer();return await WebAssembly.instantiate(t,n)}else{let t=await WebAssembly.instantiate(e,n);return t instanceof WebAssembly.Instance?{instance:t,module:e}:t}}function K(){let e={};return e.wbg={},e.wbg.__wbindgen_is_undefined=function(n){return c(n)===void 0},e.wbg.__wbindgen_string_new=function(n,t){let r=m(n,t);return g(r)},e.wbg.__wbindgen_is_object=function(n){let t=c(n);return typeof t=="object"&&t!==null},e.wbg.__wbindgen_object_clone_ref=function(n){let t=c(n);return g(t)},e.wbg.__wbg_getwithrefkey_edc2c8960f0f1191=function(n,t){let r=c(n)[c(t)];return g(r)},e.wbg.__wbindgen_in=function(n,t){return c(n)in c(t)},e.wbg.__wbg_isSafeInteger_7f1ed56200d90674=function(n){return Number.isSafeInteger(c(n))},e.wbg.__wbindgen_as_number=function(n){return+c(n)},e.wbg.__wbindgen_object_drop_ref=function(n){E(n)},e.wbg.__wbindgen_boolean_get=function(n){let t=c(n);return typeof t=="boolean"?t?1:0:2},e.wbg.__wbindgen_string_get=function(n,t){let r=c(t),i=typeof r=="string"?r:void 0;var _=W(i)?0:A(i,o.__wbindgen_malloc,o.__wbindgen_realloc),s=p;f().setInt32(n+4*1,s,!0),f().setInt32(n+4*0,_,!0)},e.wbg.__wbg_length_8339fcf5d8ecd12e=function(n){return c(n).length},e.wbg.__wbindgen_memory=function(){let n=o.memory;return g(n)},e.wbg.__wbg_buffer_b7b08af79b0b0974=function(n){let t=c(n).buffer;return g(t)},e.wbg.__wbg_new_ea1883e1e5e86686=function(n){let t=new Uint8Array(c(n));return g(t)},e.wbg.__wbg_set_d1e79e2388520f18=function(n,t,r){c(n).set(c(t),r>>>0)},e.wbg.__wbindgen_error_new=function(n,t){let r=new Error(m(n,t));return g(r)},e.wbg.__wbindgen_jsval_loose_eq=function(n,t){return c(n)==c(t)},e.wbg.__wbindgen_number_get=function(n,t){let r=c(t),i=typeof r=="number"?r:void 0;f().setFloat64(n+8*1,W(i)?0:i,!0),f().setInt32(n+4*0,!W(i),!0)},e.wbg.__wbg_instanceof_Uint8Array_247a91427532499e=function(n){let t;try{t=c(n)instanceof Uint8Array}catch{t=!1}return t},e.wbg.__wbg_instanceof_ArrayBuffer_61dfc3198373c902=function(n){let t;try{t=c(n)instanceof ArrayBuffer}catch{t=!1}return t},e.wbg.__wbindgen_throw=function(n,t){throw new Error(m(n,t))},e.wbg.__wbindgen_debug_string=function(n,t){let r=v(c(t)),i=A(r,o.__wbindgen_malloc,o.__wbindgen_realloc),_=p;f().setInt32(n+4*1,_,!0),f().setInt32(n+4*0,i,!0)},e}function Q(e,n){return o=e.exports,U.__wbindgen_wasm_module=n,y=null,h=null,o}async function U(e){if(o!==void 0)return o;typeof e<"u"&&Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead"),typeof e>"u"&&(e=new URL("index_bg.wasm",void 0));let n=K();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:t,module:r}=await G(await e,n);return Q(t,r)}var D=U;var R=!1,X=async e=>{if(R)throw new Error("Already initialized. The `initWasm()` function can be used only once.");await D(await e),R=!0};function Y(e,n){return k(e,n)}function Z(e,n,t){return F(e,n,t)}function ee(){return M()}return C(ne);})(); diff --git a/docs/index.mjs b/docs/index.mjs new file mode 100644 index 0000000..51a5c9a --- /dev/null +++ b/docs/index.mjs @@ -0,0 +1,423 @@ +// wasm/dist/index.js +var wasm; +var heap = new Array(128).fill(void 0); +heap.push(void 0, null, true, false); +function getObject(idx) { + return heap[idx]; +} +var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => { + throw Error("TextDecoder not available"); +} }; +if (typeof TextDecoder !== "undefined") { + cachedTextDecoder.decode(); +} +var cachedUint8ArrayMemory0 = null; +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} +var heap_next = heap.length; +function addHeapObject(obj) { + if (heap_next === heap.length) + heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + heap[idx] = obj; + return idx; +} +function dropObject(idx) { + if (idx < 132) + return; + heap[idx] = heap_next; + heap_next = idx; +} +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} +var WASM_VECTOR_LEN = 0; +var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => { + throw Error("TextEncoder not available"); +} }; +var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} : function(arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}; +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === void 0) { + const buf = cachedTextEncoder.encode(arg); + const ptr2 = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr2; + } + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + const mem = getUint8ArrayMemory0(); + let offset = 0; + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 127) + break; + mem[ptr + offset] = code; + } + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + WASM_VECTOR_LEN = offset; + return ptr; +} +function isLikeNone(x) { + return x === void 0 || x === null; +} +var cachedDataViewMemory0 = null; +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} +function debugString(val) { + const type = typeof val; + if (type == "number" || type == "boolean" || val == null) { + return `${val}`; + } + if (type == "string") { + return `"${val}"`; + } + if (type == "symbol") { + const description = val.description; + if (description == null) { + return "Symbol"; + } else { + return `Symbol(${description})`; + } + } + if (type == "function") { + const name = val.name; + if (typeof name == "string" && name.length > 0) { + return `Function(${name})`; + } else { + return "Function"; + } + } + if (Array.isArray(val)) { + const length = val.length; + let debug = "["; + if (length > 0) { + debug += debugString(val[0]); + } + for (let i = 1; i < length; i++) { + debug += ", " + debugString(val[i]); + } + debug += "]"; + return debug; + } + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + return toString.call(val); + } + if (className == "Object") { + try { + return "Object(" + JSON.stringify(val) + ")"; + } catch (_) { + return "Object"; + } + } + if (val instanceof Error) { + return `${val.name}: ${val.message} +${val.stack}`; + } + return className; +} +function inline(html, options) { + let deferred3_0; + let deferred3_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.inline(retptr, ptr0, len0, addHeapObject(options)); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); + var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true); + var ptr2 = r0; + var len2 = r1; + if (r3) { + ptr2 = 0; + len2 = 0; + throw takeObject(r2); + } + deferred3_0 = ptr2; + deferred3_1 = len2; + return getStringFromWasm0(ptr2, len2); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); + } +} +function inlineFragment(html, css, options) { + let deferred4_0; + let deferred4_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passStringToWasm0(css, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + wasm.inlineFragment(retptr, ptr0, len0, ptr1, len1, addHeapObject(options)); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); + var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true); + var ptr3 = r0; + var len3 = r1; + if (r3) { + ptr3 = 0; + len3 = 0; + throw takeObject(r2); + } + deferred4_0 = ptr3; + deferred4_1 = len3; + return getStringFromWasm0(ptr3, len3); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred4_0, deferred4_1, 1); + } +} +function version() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.version(retptr); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } +} +async function __wbg_load(module, imports) { + if (typeof Response === "function" && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === "function") { + try { + return await WebAssembly.instantiateStreaming(module, imports); + } catch (e) { + if (module.headers.get("Content-Type") != "application/wasm") { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + } else { + throw e; + } + } + } + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + } else { + const instance = await WebAssembly.instantiate(module, imports); + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + } else { + return instance; + } + } +} +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = getObject(arg0) === void 0; + return ret; + }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_object = function(arg0) { + const val = getObject(arg0); + const ret = typeof val === "object" && val !== null; + return ret; + }; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) { + const ret = getObject(arg0)[getObject(arg1)]; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_in = function(arg0, arg1) { + const ret = getObject(arg0) in getObject(arg1); + return ret; + }; + imports.wbg.__wbg_isSafeInteger_7f1ed56200d90674 = function(arg0) { + const ret = Number.isSafeInteger(getObject(arg0)); + return ret; + }; + imports.wbg.__wbindgen_as_number = function(arg0) { + const ret = +getObject(arg0); + return ret; + }; + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + imports.wbg.__wbindgen_boolean_get = function(arg0) { + const v = getObject(arg0); + const ret = typeof v === "boolean" ? v ? 1 : 0 : 2; + return ret; + }; + imports.wbg.__wbindgen_string_get = function(arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "string" ? obj : void 0; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_length_8339fcf5d8ecd12e = function(arg0) { + const ret = getObject(arg0).length; + return ret; + }; + imports.wbg.__wbindgen_memory = function() { + const ret = wasm.memory; + return addHeapObject(ret); + }; + imports.wbg.__wbg_buffer_b7b08af79b0b0974 = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_ea1883e1e5e86686 = function(arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_d1e79e2388520f18 = function(arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbindgen_error_new = function(arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { + const ret = getObject(arg0) == getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_number_get = function(arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "number" ? obj : void 0; + getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); + }; + imports.wbg.__wbg_instanceof_Uint8Array_247a91427532499e = function(arg0) { + let result; + try { + result = getObject(arg0) instanceof Uint8Array; + } catch (_) { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_instanceof_ArrayBuffer_61dfc3198373c902 = function(arg0) { + let result; + try { + result = getObject(arg0) instanceof ArrayBuffer; + } catch (_) { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_debug_string = function(arg0, arg1) { + const ret = debugString(getObject(arg1)); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + return imports; +} +function __wbg_init_memory(imports, memory) { +} +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedDataViewMemory0 = null; + cachedUint8ArrayMemory0 = null; + return wasm; +} +async function __wbg_init(module_or_path) { + if (wasm !== void 0) + return wasm; + if (typeof module_or_path !== "undefined" && Object.getPrototypeOf(module_or_path) === Object.prototype) + ({ module_or_path } = module_or_path); + else + console.warn("using deprecated parameters for the initialization function; pass a single object instead"); + if (typeof module_or_path === "undefined") { + module_or_path = new URL("index_bg.wasm", void 0); + } + const imports = __wbg_get_imports(); + if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) { + module_or_path = fetch(module_or_path); + } + __wbg_init_memory(imports); + const { instance, module } = await __wbg_load(await module_or_path, imports); + return __wbg_finalize_init(instance, module); +} +var dist_default = __wbg_init; + +// wasm-binding.ts +var initialized = false; +var initWasm = async (module_or_path) => { + if (initialized) { + throw new Error( + "Already initialized. The `initWasm()` function can be used only once." + ); + } + await dist_default(await module_or_path); + initialized = true; +}; +function inline2(html, options) { + return inline(html, options); +} +function inlineFragment2(html, css, options) { + return inlineFragment(html, css, options); +} +function version2() { + return version(); +} +export { + initWasm, + inline2 as inline, + inlineFragment2 as inlineFragment, + version2 as version +}; diff --git a/docs/index_bg.wasm b/docs/index_bg.wasm new file mode 100644 index 0000000..9622f62 Binary files /dev/null and b/docs/index_bg.wasm differ diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000..fd484e3 --- /dev/null +++ b/docs/package.json @@ -0,0 +1,51 @@ +{ + "name": "@css-inline/css-inline-wasm", + "version": "0.14.3", + "description": "High-performance library for inlining CSS into HTML 'style' attributes", + "keywords": [ + "css", + "html", + "email", + "stylesheet", + "inlining" + ], + "repository": "https://github.com/Stranger6667/css-inline", + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "public" + }, + "main": "index.js", + "unpkg": "index.min.js", + "types": "index.d.ts", + "exports": { + ".": { + "import": "./index.mjs", + "default": "./index.js" + }, + "./index_bg.wasm": "./index_bg.wasm" + }, + "files": [ + "index_bg.wasm", + "index.js", + "index.mjs", + "index.min.js", + "index.d.ts" + ], + "license": "MIT", + "engines": { + "node": ">= 10" + }, + "ava": { + "require": [ + "@swc-node/register" + ], + "typescript": { + "rewritePaths": { + "src/": "build/" + }, + "compile": false + }, + "timeout": "3m" + }, + "sideEffects": false +}