UNPKG

@lynx-js/web-core

Version:

This is an internal experimental package, do not use

549 lines (517 loc) 18.3 kB
/* @ts-self-types="./encode.d.ts" */ export class RawStyleInfo { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; RawStyleInfoFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_rawstyleinfo_free(ptr, 0); } /** * * * Appends an import to the stylesheet identified by `css_id`. * * If the stylesheet does not exist, it is created. * * @param css_id - The ID of the CSS file. * * @param import_css_id - The ID of the imported CSS file. * * @param {number} css_id * @param {number} import_css_id */ append_import(css_id, import_css_id) { wasm.rawstyleinfo_append_import(this.__wbg_ptr, css_id, import_css_id); } /** * * * Encodes the RawStyleInfo into a Uint8Array using rkyv serialization. * * @returns A Uint8Array containing the serialized RawStyleInfo. * * @returns {Uint8Array} */ encode() { const ret = wasm.rawstyleinfo_encode(this.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return takeFromExternrefTable0(ret[0]); } constructor() { const ret = wasm.rawstyleinfo_new(); this.__wbg_ptr = ret >>> 0; RawStyleInfoFinalization.register(this, this.__wbg_ptr, this); return this; } /** * * * Pushes a rule to the stylesheet identified by `css_id`. * * If the stylesheet does not exist, it is created. * * @param css_id - The ID of the CSS file. * * @param rule - The rule to append. * * @param {number} css_id * @param {Rule} rule */ push_rule(css_id, rule) { _assertClass(rule, Rule); var ptr0 = rule.__destroy_into_raw(); wasm.rawstyleinfo_push_rule(this.__wbg_ptr, css_id, ptr0); } } if (Symbol.dispose) RawStyleInfo.prototype[Symbol.dispose] = RawStyleInfo.prototype.free; export class Rule { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; RuleFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_rule_free(ptr, 0); } /** * * * Creates a new Rule with the specified type. * * @param rule_type - The type of the rule (e.g., "StyleRule", "FontFaceRule", "KeyframesRule"). * * @param {string} rule_type */ constructor(rule_type) { const ptr0 = passStringToWasm0(rule_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.rule_new(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; RuleFinalization.register(this, this.__wbg_ptr, this); return this; } /** * * * Pushes a declaration to the rule's declaration block. * * LynxJS doesn't support !important * * @param property_name - The property name. * * @param value - The property value. * * @param {string} property_name * @param {string} value */ push_declaration(property_name, value) { const ptr0 = passStringToWasm0(property_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; wasm.rule_push_declaration(this.__wbg_ptr, ptr0, len0, ptr1, len1); } /** * * * Pushes a nested rule to the rule. * * @param rule - The nested rule to add. * * @param {Rule} rule */ push_rule_children(rule) { _assertClass(rule, Rule); var ptr0 = rule.__destroy_into_raw(); wasm.rule_push_rule_children(this.__wbg_ptr, ptr0); } /** * * * Sets the prelude for the rule. * * @param prelude - The prelude to set (SelectorList or KeyFramesPrelude). * * @param {RulePrelude} prelude */ set_prelude(prelude) { _assertClass(prelude, RulePrelude); var ptr0 = prelude.__destroy_into_raw(); wasm.rule_set_prelude(this.__wbg_ptr, ptr0); } } if (Symbol.dispose) Rule.prototype[Symbol.dispose] = Rule.prototype.free; /** * * * Either SelectorList or KeyFramesPrelude * * Depending on the RuleType * * If it is SelectorList, then selectors is a list of Selector * * If it is KeyFramesPrelude, then selectors has only one selector which is Prelude text, its simple_selectors is empty * * If the parent is FontFace, then selectors is empty * */ export class RulePrelude { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; RulePreludeFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ruleprelude_free(ptr, 0); } constructor() { const ret = wasm.ruleprelude_new(); this.__wbg_ptr = ret >>> 0; RulePreludeFinalization.register(this, this.__wbg_ptr, this); return this; } /** * * * Pushes a selector to the list. * * @param selector - The selector to add. * * @param {Selector} selector */ push_selector(selector) { _assertClass(selector, Selector); var ptr0 = selector.__destroy_into_raw(); wasm.ruleprelude_push_selector(this.__wbg_ptr, ptr0); } } if (Symbol.dispose) RulePrelude.prototype[Symbol.dispose] = RulePrelude.prototype.free; export class Selector { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; SelectorFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_selector_free(ptr, 0); } constructor() { const ret = wasm.ruleprelude_new(); this.__wbg_ptr = ret >>> 0; SelectorFinalization.register(this, this.__wbg_ptr, this); return this; } /** * * * Pushes a selector section to the selector. * * @param selector_type - The type of the selector section (e.g., "ClassSelector", "IdSelector"). * * @param value - The value of the selector section. * * @param {string} selector_type * @param {string} value */ push_one_selector_section(selector_type, value) { const ptr0 = passStringToWasm0(selector_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.selector_push_one_selector_section(this.__wbg_ptr, ptr0, len0, ptr1, len1); if (ret[1]) { throw takeFromExternrefTable0(ret[0]); } } } if (Symbol.dispose) Selector.prototype[Symbol.dispose] = Selector.prototype.free; export class StyleInfoDecoder { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; StyleInfoDecoderFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_styleinfodecoder_free(ptr, 0); } } if (Symbol.dispose) StyleInfoDecoder.prototype[Symbol.dispose] = StyleInfoDecoder.prototype.free; /** * @param {Uint8Array} buffer * @param {string | null | undefined} entry_name * @param {boolean} config_enable_css_selector * @param {boolean} transform_vw * @param {boolean} transform_vh * @param {boolean} transform_rem * @returns {Uint8Array} */ export function decode_style_info(buffer, entry_name, config_enable_css_selector, transform_vw, transform_vh, transform_rem) { var ptr0 = isLikeNone(entry_name) ? 0 : passStringToWasm0(entry_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; const ret = wasm.decode_style_info(buffer, ptr0, len0, config_enable_css_selector, transform_vw, transform_vh, transform_rem); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return takeFromExternrefTable0(ret[0]); } /** * @param {RawStyleInfo} raw_style_info * @param {boolean} config_enable_css_selector * @param {string | null | undefined} entry_name * @param {boolean} transform_vw * @param {boolean} transform_vh * @param {boolean} transform_rem * @returns {Uint8Array} */ export function encode_legacy_json_generated_raw_style_info(raw_style_info, config_enable_css_selector, entry_name, transform_vw, transform_vh, transform_rem) { _assertClass(raw_style_info, RawStyleInfo); var ptr0 = raw_style_info.__destroy_into_raw(); var ptr1 = isLikeNone(entry_name) ? 0 : passStringToWasm0(entry_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; const ret = wasm.encode_legacy_json_generated_raw_style_info(ptr0, config_enable_css_selector, ptr1, len1, transform_vw, transform_vh, transform_rem); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return takeFromExternrefTable0(ret[0]); } /** * @param {Uint8Array} buffer * @returns {string} */ export function get_font_face_content(buffer) { let deferred2_0; let deferred2_1; try { const ret = wasm.get_font_face_content(buffer); var ptr1 = ret[0]; var len1 = ret[1]; if (ret[3]) { ptr1 = 0; len1 = 0; throw takeFromExternrefTable0(ret[2]); } deferred2_0 = ptr1; deferred2_1 = len1; return getStringFromWasm0(ptr1, len1); } finally { wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); } } /** * @param {Uint8Array} buffer * @returns {string} */ export function get_style_content(buffer) { let deferred2_0; let deferred2_1; try { const ret = wasm.get_style_content(buffer); var ptr1 = ret[0]; var len1 = ret[1]; if (ret[3]) { ptr1 = 0; len1 = 0; throw takeFromExternrefTable0(ret[2]); } deferred2_0 = ptr1; deferred2_1 = len1; return getStringFromWasm0(ptr1, len1); } finally { wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); } } function __wbg_get_imports() { const import0 = { __proto__: null, __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) { const ret = Error(getStringFromWasm0(arg0, arg1)); return ret; }, __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) { const ret = debugString(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); }, __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }, __wbg_length_32ed9a279acd054c: function(arg0) { const ret = arg0.length; return ret; }, __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) { const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1)); return ret; }, __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) { Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2); }, __wbindgen_init_externref_table: function() { const table = wasm.__wbindgen_externrefs; const offset = table.grow(4); table.set(0, undefined); table.set(offset + 0, undefined); table.set(offset + 1, null); table.set(offset + 2, true); table.set(offset + 3, false); }, }; return { __proto__: null, "./encode_bg.js": import0, }; } const RawStyleInfoFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_rawstyleinfo_free(ptr >>> 0, 1)); const RuleFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_rule_free(ptr >>> 0, 1)); const RulePreludeFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ruleprelude_free(ptr >>> 0, 1)); const SelectorFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_selector_free(ptr >>> 0, 1)); const StyleInfoDecoderFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_styleinfodecoder_free(ptr >>> 0, 1)); function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } function debugString(val) { // primitive types 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'; } } // objects 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; } // Test for built-in const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); let className; if (builtInMatches && builtInMatches.length > 1) { className = builtInMatches[1]; } else { // Failed to match the standard '[object ClassName]' return toString.call(val); } if (className == 'Object') { // we're a user defined class or Object // JSON.stringify avoids problems with cycles, and is generally much // easier than looping through ownProperties of `val`. try { return 'Object(' + JSON.stringify(val) + ')'; } catch (_) { return 'Object'; } } // errors if (val instanceof Error) { return `${val.name}: ${val.message}\n${val.stack}`; } // TODO we could test for more things here, like `Set`s and `Map`s. return className; } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return decodeText(ptr, len); } let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } function isLikeNone(x) { return x === undefined || x === null; } function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } 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 > 0x7F) 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 = cachedTextEncoder.encodeInto(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } function takeFromExternrefTable0(idx) { const value = wasm.__wbindgen_externrefs.get(idx); wasm.__externref_table_dealloc(idx); return value; } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); function decodeText(ptr, len) { return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } const cachedTextEncoder = new TextEncoder(); if (!('encodeInto' in cachedTextEncoder)) { cachedTextEncoder.encodeInto = function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }; } let WASM_VECTOR_LEN = 0; import { readFileSync } from 'node:fs'; const wasmUrl = new URL('encode_bg.wasm', import.meta.url); const wasmBytes = readFileSync(wasmUrl); const wasmModule = new WebAssembly.Module(wasmBytes); const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports; wasm.__wbindgen_start();