UNPKG

@webpage-quality-analyzer/core

Version:

High-performance webpage quality analyzer with 115 comprehensive metrics - powered by Rust + WebAssembly

1,504 lines (1,424 loc) 53.6 kB
let wasm; export function __wbg_set_wasm(val) { wasm = val; } let WASM_VECTOR_LEN = 0; let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; let cachedTextEncoder = new lTextEncoder('utf-8'); const 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 === 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 = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } 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 addToExternrefTable0(obj) { const idx = wasm.__externref_table_alloc(); wasm.__wbindgen_export_4.set(idx, obj); return idx; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { const idx = addToExternrefTable0(e); wasm.__wbindgen_exn_store(idx); } } const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function isLikeNone(x) { return x === undefined || x === null; } const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(state => { wasm.__wbindgen_export_6.get(state.dtor)(state.a, state.b) }); function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { // First up with a closure we increment the internal reference // count. This ensures that the Rust closure environment won't // be deallocated while we're invoking it. state.cnt++; const a = state.a; state.a = 0; try { return f(a, state.b, ...args); } finally { if (--state.cnt === 0) { wasm.__wbindgen_export_6.get(state.dtor)(a, state.b); CLOSURE_DTORS.unregister(state); } else { state.a = a; } } }; real.original = state; CLOSURE_DTORS.register(real, state, state); return real; } function takeFromExternrefTable0(idx) { const value = wasm.__wbindgen_export_4.get(idx); wasm.__externref_table_dealloc(idx); return value; } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getDataViewMemory0(); const result = []; for (let i = ptr; i < ptr + 4 * len; i += 4) { result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true))); } wasm.__externref_drop_slice(ptr, len); return result; } function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; for (let i = 0; i < array.length; i++) { const add = addToExternrefTable0(array[i]); getDataViewMemory0().setUint32(ptr + 4 * i, add, true); } WASM_VECTOR_LEN = array.length; return ptr; } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } /** * Initialize the WASM module (call this once when loading) * * Sets up panic hooks and other initialization */ export function init() { wasm.init(); } function __wbg_adapter_30(arg0, arg1, arg2) { wasm.closure380_externref_shim(arg0, arg1, arg2); } function __wbg_adapter_130(arg0, arg1, arg2, arg3) { wasm.closure1116_externref_shim(arg0, arg1, arg2, arg3); } const __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"]; const WasmAnalyzerFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_wasmanalyzer_free(ptr >>> 0, 1)); /** * WASM wrapper for the webpage quality analyzer * * This provides a JavaScript-friendly interface to the full Rust analyzer, * bridging async Rust to JavaScript Promises via wasm-bindgen-futures. */ export class WasmAnalyzer { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(WasmAnalyzer.prototype); obj.__wbg_ptr = ptr; WasmAnalyzerFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; WasmAnalyzerFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_wasmanalyzer_free(ptr, 0); } /** * Create a new analyzer with default configuration */ constructor() { const ret = wasm.wasmanalyzer_new(); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; WasmAnalyzerFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Create analyzer with custom configuration * * # Arguments * * `profile` - Optional profile name ("default", "news", "blog", etc.) * * `enable_nlp` - Enable NLP features (default: true) * * `add_report` - Include detailed report sections (default: true) * @param {string | null} [profile] * @param {boolean | null} [enable_nlp] * @param {boolean | null} [add_report] * @returns {WasmAnalyzer} */ static withConfig(profile, enable_nlp, add_report) { var ptr0 = isLikeNone(profile) ? 0 : passStringToWasm0(profile, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_withConfig(ptr0, len0, isLikeNone(enable_nlp) ? 0xFFFFFF : enable_nlp ? 1 : 0, isLikeNone(add_report) ? 0xFFFFFF : add_report ? 1 : 0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } /** * Analyze HTML content * * # Arguments * * `html` - HTML content as string * * # Returns * Promise that resolves to a PageQualityReport JSON object * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzer(); * const report = await analyzer.analyze('<html>...</html>'); * console.log(`Score: ${report.score}, Quality: ${report.verdict}`); * ``` * @param {string} html * @returns {Promise<any>} */ analyze(html) { const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_analyze(this.__wbg_ptr, ptr0, len0); return ret; } /** * Analyze HTML with a specific URL context * * # Arguments * * `url` - URL of the page (used for context, not fetched) * * `html` - HTML content as string * * # Returns * Promise that resolves to a PageQualityReport JSON object * @param {string} url * @param {string} html * @returns {Promise<any>} */ analyzeWithUrl(url, html) { const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_analyzeWithUrl(this.__wbg_ptr, ptr0, len0, ptr1, len1); return ret; } /** * Fetch and analyze a URL using browser's fetch API * * # Arguments * * `url` - URL to fetch and analyze * * # Returns * Promise that resolves to a PageQualityReport JSON object * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzer(); * const report = await analyzer.fetchAndAnalyze('https://example.com'); * ``` * @param {string} url * @returns {Promise<any>} */ fetchAndAnalyze(url) { const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_fetchAndAnalyze(this.__wbg_ptr, ptr0, len0); return ret; } /** * Get available profile names * * # Returns * Array of profile names as strings (from enhanced_profiles.json) * @returns {string[]} */ static getAvailableProfiles() { const ret = wasm.wasmanalyzer_getAvailableProfiles(); var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 4, 4); return v1; } /** * Get version information * @returns {string} */ static getVersion() { let deferred1_0; let deferred1_1; try { const ret = wasm.wasmanalyzer_getVersion(); deferred1_0 = ret[0]; deferred1_1 = ret[1]; return getStringFromWasm0(ret[0], ret[1]); } finally { wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); } } /** * Analyze HTML with custom field selection * * This method allows you to select only specific fields from the analysis * report, reducing bandwidth usage by 60-70% for production deployments. * * # Arguments * * `html` - HTML content to analyze * * `fields` - Array of field names to include (e.g., ['url', 'score', 'metadata']) * * # Returns * Promise that resolves to a filtered PageQualityReport with only requested fields * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzer(); * const report = await analyzer.analyzeWithFields(html, [ * 'url', * 'score', * 'metadata', * 'processed_document' * ]); * // Returns only these 4 fields (60-70% smaller JSON) * ``` * @param {string} html * @param {string[]} fields * @returns {Promise<any>} */ analyzeWithFields(html, fields) { const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArrayJsValueToWasm0(fields, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_analyzeWithFields(this.__wbg_ptr, ptr0, len0, ptr1, len1); return ret; } /** * Analyze HTML with advanced field selector * * Provides full control over field selection including sections, * include/exclude rules, and nested field access. * * # Arguments * * `html` - HTML content to analyze * * `selector` - WasmFieldSelector with custom rules * * # Returns * Promise that resolves to a filtered PageQualityReport * * # Example (JavaScript) * ```js * const selector = new WasmFieldSelector() * .includeFields(['url', 'score']) * .includeSections(['metadata']) * .excludeFields(['metadata.og_tags']); * * const report = await analyzer.analyzeWithSelector(html, selector); * ``` * @param {string} html * @param {WasmFieldSelector} selector * @returns {Promise<any>} */ analyzeWithSelector(html, selector) { const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(selector, WasmFieldSelector); const ret = wasm.wasmanalyzer_analyzeWithSelector(this.__wbg_ptr, ptr0, len0, selector.__wbg_ptr); return ret; } /** * Create analyzer from JSON configuration * * Since WASM cannot directly read files, pass the config as a JSON string. * In browser environments, fetch the config file and pass its content. * * # Arguments * * `config_json` - JSON string containing profile configuration * * # Returns * New WasmAnalyzer configured with the provided settings * * # Example (JavaScript - Browser) * ```js * const configJson = await fetch('/configs/my-config.json').then(r => r.text()); * const analyzer = WasmAnalyzer.fromConfig(configJson); * ``` * * # Example (JavaScript - Node.js) * ```js * const fs = require('fs'); * const configJson = fs.readFileSync('config.json', 'utf-8'); * const analyzer = WasmAnalyzer.fromConfig(configJson); * ``` * @param {string} config_json * @returns {WasmAnalyzer} */ static fromConfig(config_json) { const ptr0 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzer_fromConfig(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } /** * Get the current profile configuration as JSON string * * Returns the active profile configuration, which can be: * - Saved to a file * - Modified and reloaded * - Shared across team members * * # Returns * JSON string of the current ProfileConfig * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzer(); * const configJson = analyzer.getConfig(); * console.log('Current config:', JSON.parse(configJson)); * * // Save to file or modify * localStorage.setItem('analyzer-config', configJson); * ``` * @returns {string} */ getConfig() { let deferred2_0; let deferred2_1; try { const ret = wasm.wasmanalyzer_getConfig(this.__wbg_ptr); 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); } } /** * Create a builder for advanced analyzer configuration * * # Returns * WasmAnalyzerBuilder for fluent configuration * * # Example (JavaScript) * ```js * const analyzer = WasmAnalyzer.builder() * .withProfile('news') * .disableMetric('grammar_score') * .build(); * ``` * @returns {WasmAnalyzerBuilder} */ static builder() { const ret = wasm.wasmanalyzer_builder(); return WasmAnalyzerBuilder.__wrap(ret); } } const WasmAnalyzerBuilderFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_wasmanalyzerbuilder_free(ptr >>> 0, 1)); /** * WASM Analyzer Builder for advanced configuration * * Provides a fluent API for customizing analyzer behavior including: * - Profile selection * - Metric toggling (enable/disable specific metrics) * - Custom thresholds per metric * - NLP and grammar features * * # Example (JavaScript) * ```js * const analyzer = WasmAnalyzer.builder() * .withProfile('news') * .disableMetric('grammar_score') // Skip expensive grammar checking * .setThreshold('word_count', 500, 2000, 5000) * .enableNlp(true) * .build(); * ``` */ export class WasmAnalyzerBuilder { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(WasmAnalyzerBuilder.prototype); obj.__wbg_ptr = ptr; WasmAnalyzerBuilderFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; WasmAnalyzerBuilderFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_wasmanalyzerbuilder_free(ptr, 0); } /** * Create a new builder with default settings */ constructor() { const ret = wasm.wasmanalyzer_builder(); this.__wbg_ptr = ret >>> 0; WasmAnalyzerBuilderFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Set the profile to use (chainable) * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .withProfile('news'); * ``` * @param {string} profile * @returns {WasmAnalyzerBuilder} */ withProfile(profile) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(profile, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_withProfile(ptr, ptr0, len0); return WasmAnalyzerBuilder.__wrap(ret); } /** * Enable a specific metric (chainable) * * By default, all metrics in the profile are enabled. Use this to * explicitly enable a metric that might be disabled in the profile. * * # Arguments * * `metric_name` - Name of metric (e.g., "word_count", "image_count") * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .enableMetric('word_count') * .enableMetric('readability_score'); * ``` * @param {string} metric_name * @returns {WasmAnalyzerBuilder} */ enableMetric(metric_name) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(metric_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_enableMetric(ptr, ptr0, len0); return WasmAnalyzerBuilder.__wrap(ret); } /** * Disable a specific metric (chainable) * * Disabling metrics can improve performance by skipping expensive * calculations you don't need. * * # Arguments * * `metric_name` - Name of metric to disable * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .disableMetric('grammar_score') // Skip grammar checking * .disableMetric('link_check'); // Skip external link validation * ``` * @param {string} metric_name * @returns {WasmAnalyzerBuilder} */ disableMetric(metric_name) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(metric_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_disableMetric(ptr, ptr0, len0); return WasmAnalyzerBuilder.__wrap(ret); } /** * Set custom threshold for a metric (chainable) * * Customize the thresholds used for scoring a metric with full control * over the scoring curve. * * Thresholds define the scoring curve: * - `min`: Below this value, score is 0 * - `optimal_min`: Start of optimal range (100% score) * - `optimal_max`: End of optimal range (100% score) * - `max`: Above this value, score doesn't improve * * # Arguments * * `metric_name` - Name of the metric * * `min` - Minimum acceptable value * * `optimal_min` - Start of optimal range * * `optimal_max` - End of optimal range * * `max` - Maximum useful value * * # Validation * Thresholds must satisfy: min < optimal_min <= optimal_max < max * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .setThreshold( * 'word_count', * 100, // min - articles < 100 words score poorly * 500, // optimal_min - ideal range starts * 2000, // optimal_max - ideal range ends * 5000 // max - diminishing returns after this * ); * ``` * @param {string} metric_name * @param {number} min * @param {number} optimal_min * @param {number} optimal_max * @param {number} max * @returns {WasmAnalyzerBuilder} */ setThreshold(metric_name, min, optimal_min, optimal_max, max) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(metric_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_setThreshold(ptr, ptr0, len0, min, optimal_min, optimal_max, max); return WasmAnalyzerBuilder.__wrap(ret); } /** * Set simple threshold for a metric (chainable) * * Convenience method for metrics with a single optimal value rather than a range. * This creates optimal_min == optimal_max. * * # Arguments * * `metric_name` - Name of the metric * * `min` - Minimum acceptable value * * `optimal` - Single optimal value (100% score) * * `max` - Maximum useful value * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .setSimpleThreshold( * 'title_len', * 30, // min - titles < 30 chars are poor * 60, // optimal - 60 chars is perfect * 120 // max - longer titles don't help * ); * ``` * @param {string} metric_name * @param {number} min * @param {number} optimal * @param {number} max * @returns {WasmAnalyzerBuilder} */ setSimpleThreshold(metric_name, min, optimal, max) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(metric_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_setSimpleThreshold(ptr, ptr0, len0, min, optimal, max); return WasmAnalyzerBuilder.__wrap(ret); } /** * Set custom weight for a metric (chainable) * * Weights control the relative importance of metrics in scoring. * Default weight is 1.0. Use >1.0 to increase importance, <1.0 to decrease. * * # Arguments * * `metric_name` - Name of the metric to adjust * * `weight` - Multiplier for metric's contribution (0.0-10.0, typically 0.1-3.0) * * # Weight Guidelines * * 0.0 - Disables the metric * * 0.1-0.5 - Significantly reduce importance * * 0.5-0.9 - Moderately reduce importance * * 1.0 - Default (unchanged) * * 1.1-2.0 - Moderately increase importance * * 2.0-3.0 - Significantly increase importance * * >3.0 - Extreme emphasis (use sparingly) * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .setMetricWeight('seo_title_quality', 2.0) // Double SEO importance * .setMetricWeight('grammar_score', 0.5); // Reduce grammar weight * ``` * @param {string} metric_name * @param {number} weight * @returns {WasmAnalyzerBuilder} */ setMetricWeight(metric_name, weight) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(metric_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_setMetricWeight(ptr, ptr0, len0, weight); return WasmAnalyzerBuilder.__wrap(ret); } /** * Add a penalty that reduces score when metric falls below threshold * * Penalties help enforce content quality standards by automatically reducing * scores when important metrics don't meet expectations. * * # Parameters * - `penalty_id`: Unique identifier for this penalty * - `metric`: Metric name to monitor (e.g., "word_count", "heading_depth") * - `threshold`: Trigger penalty when metric value is below this * - `penalty_points`: Number of points to subtract (0-100) * - `description`: Human-readable explanation * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .withProfile('content_article') * .addPenaltyBelow('short_content', 'word_count', 300, 10, 'Content too short') * .addPenaltyBelow('shallow_structure', 'heading_depth', 2, 5, 'Insufficient headings'); * ``` * @param {string} penalty_id * @param {string} metric * @param {number} threshold * @param {number} penalty_points * @param {string} description * @returns {WasmAnalyzerBuilder} */ addPenaltyBelow(penalty_id, metric, threshold, penalty_points, description) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(penalty_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(metric, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passStringToWasm0(description, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_addPenaltyBelow(ptr, ptr0, len0, ptr1, len1, threshold, penalty_points, ptr2, len2); return WasmAnalyzerBuilder.__wrap(ret); } /** * Add a penalty that reduces score when metric exceeds threshold * * Useful for penalizing excessive values (e.g., too many links, overly long titles). * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .addPenaltyAbove('title_too_long', 'title_len', 70, 5, 'Title too long for SEO'); * ``` * @param {string} penalty_id * @param {string} metric * @param {number} threshold * @param {number} penalty_points * @param {string} description * @returns {WasmAnalyzerBuilder} */ addPenaltyAbove(penalty_id, metric, threshold, penalty_points, description) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(penalty_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(metric, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passStringToWasm0(description, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_addPenaltyAbove(ptr, ptr0, len0, ptr1, len1, threshold, penalty_points, ptr2, len2); return WasmAnalyzerBuilder.__wrap(ret); } /** * Add a bonus that increases score when metric exceeds excellence threshold * * Bonuses reward exceptional quality, comprehensiveness, or excellence. * * # Parameters * - `bonus_id`: Unique identifier for this bonus * - `metric`: Metric name to monitor * - `threshold`: Grant bonus when metric value exceeds this * - `bonus_points`: Number of points to add (0-50 recommended) * - `description`: Human-readable explanation * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .withProfile('content_article') * .addBonusAbove('comprehensive', 'word_count', 2000, 5, 'Comprehensive content') * .addBonusAbove('deep_structure', 'heading_depth', 4, 3, 'Excellent organization'); * ``` * @param {string} bonus_id * @param {string} metric * @param {number} threshold * @param {number} bonus_points * @param {string} description * @returns {WasmAnalyzerBuilder} */ addBonusAbove(bonus_id, metric, threshold, bonus_points, description) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(bonus_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(metric, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passStringToWasm0(description, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_addBonusAbove(ptr, ptr0, len0, ptr1, len1, threshold, bonus_points, ptr2, len2); return WasmAnalyzerBuilder.__wrap(ret); } /** * Add a bonus when multiple metrics are all above thresholds * * Creates a synergy bonus that rewards consistent quality across metrics. * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .addBonusMultiple( * 'seo_excellence', * ['title_len', 'meta_desc_len', 'heading_depth'], * 50, * 5, * 'Excellent SEO across the board' * ); * ``` * @param {string} bonus_id * @param {string[]} metrics * @param {number} threshold * @param {number} bonus_points * @param {string} description * @returns {WasmAnalyzerBuilder} */ addBonusMultiple(bonus_id, metrics, threshold, bonus_points, description) { const ptr = this.__destroy_into_raw(); const ptr0 = passStringToWasm0(bonus_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArrayJsValueToWasm0(metrics, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ptr2 = passStringToWasm0(description, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len2 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_addBonusMultiple(ptr, ptr0, len0, ptr1, len1, threshold, bonus_points, ptr2, len2); return WasmAnalyzerBuilder.__wrap(ret); } /** * Enable or disable NLP features (chainable) * * NLP features include language detection and keyword extraction. * * # Example (JavaScript) * ```js * const builder = new WasmAnalyzerBuilder() * .enableNlp(false); // Disable for faster processing * ``` * @param {boolean} enable * @returns {WasmAnalyzerBuilder} */ enableNlp(enable) { const ptr = this.__destroy_into_raw(); const ret = wasm.wasmanalyzerbuilder_enableNlp(ptr, enable); return WasmAnalyzerBuilder.__wrap(ret); } /** * Enable or disable link checking (chainable) * * Note: Link checking in WASM uses browser fetch API and may be subject * to CORS restrictions. Only works when 'linkcheck' feature is enabled. * * # Example * ```js * const builder = new WasmAnalyzerBuilder() * .enableLinkCheck(true); // Enable link validation * ``` * @param {boolean} enable * @returns {WasmAnalyzerBuilder} */ enableLinkCheck(enable) { const ptr = this.__destroy_into_raw(); const ret = wasm.wasmanalyzerbuilder_enableLinkCheck(ptr, enable); return WasmAnalyzerBuilder.__wrap(ret); } /** * Enable or disable detailed report sections (chainable) * @param {boolean} add * @returns {WasmAnalyzerBuilder} */ addReport(add) { const ptr = this.__destroy_into_raw(); const ret = wasm.wasmanalyzerbuilder_addReport(ptr, add); return WasmAnalyzerBuilder.__wrap(ret); } /** * Load configuration from JSON string (WASM alternative to from_config_file) * * Since WASM doesn't have file system access, use this method to load * configuration from a JSON string instead. You can fetch the config via * HTTP or embed it in your JavaScript code. * * # Parameters * - `config_json`: JSON string containing the configuration * * # Returns * New WasmAnalyzer instance configured from the JSON * * # Example (JavaScript) * ```js * // Fetch config from server * const configResponse = await fetch('/config/analyzer-config.json'); * const configJson = await configResponse.text(); * const analyzer = WasmAnalyzerBuilder.fromConfigJson(configJson); * * // Or use embedded config * const config = JSON.stringify({ * active_profile: "news", * presets: { * news: { * category_weights: { content: 2.0, seo: 1.5 } * } * } * }); * const analyzer = WasmAnalyzerBuilder.fromConfigJson(config); * ``` * @param {string} config_json * @returns {WasmAnalyzer} */ static fromConfigJson(config_json) { const ptr0 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_fromConfigJson(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } /** * Load configuration from YAML string (WASM alternative to from_config_file) * * Since WASM doesn't have file system access, use this method to load * configuration from a YAML string instead. * * # Parameters * - `config_yaml`: YAML string containing the configuration * * # Returns * New WasmAnalyzer instance configured from the YAML * * # Example (JavaScript) * ```js * const configYaml = ` * active_profile: content_article * presets: * content_article: * category_weights: * content: 2.0 * seo: 1.5 * `; * const analyzer = WasmAnalyzerBuilder.fromConfigYaml(configYaml); * ``` * @param {string} config_yaml * @returns {WasmAnalyzer} */ static fromConfigYaml(config_yaml) { const ptr0 = passStringToWasm0(config_yaml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_fromConfigYaml(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } /** * Load configuration from TOML string (WASM alternative to from_config_file) * * Since WASM doesn't have file system access, use this method to load * configuration from a TOML string instead. * * # Parameters * - `config_toml`: TOML string containing the configuration * * # Returns * New WasmAnalyzer instance configured from the TOML * * # Example (JavaScript) * ```js * const configToml = ` * active_profile = "blog" * * [presets.blog] * [presets.blog.category_weights] * content = 2.0 * seo = 1.5 * `; * const analyzer = WasmAnalyzerBuilder.fromConfigToml(configToml); * ``` * @param {string} config_toml * @returns {WasmAnalyzer} */ static fromConfigToml(config_toml) { const ptr0 = passStringToWasm0(config_toml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmanalyzerbuilder_fromConfigToml(ptr0, len0); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } /** * Build the analyzer with configured settings * * # Returns * WasmAnalyzer instance with custom configuration * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzerBuilder() * .withProfile('news') * .disableMetric('grammar_score') * .setThreshold('word_count', 500, 2000, 5000) * .build(); * * const report = await analyzer.analyze(html); * ``` * @returns {WasmAnalyzer} */ build() { const ptr = this.__destroy_into_raw(); const ret = wasm.wasmanalyzerbuilder_build(ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return WasmAnalyzer.__wrap(ret[0]); } } const WasmBatchAnalyzerFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_wasmbatchanalyzer_free(ptr >>> 0, 1)); /** * Batch analyzer for processing multiple HTML documents */ export class WasmBatchAnalyzer { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; WasmBatchAnalyzerFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_wasmbatchanalyzer_free(ptr, 0); } /** * Create new batch analyzer */ constructor() { const ret = wasm.wasmbatchanalyzer_new(); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } this.__wbg_ptr = ret[0] >>> 0; WasmBatchAnalyzerFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Analyze multiple HTML documents in batch * * # Arguments * * `html_documents` - Array of HTML strings * * # Returns * Promise that resolves to WasmBatchResult * * # Example (JavaScript) * ```js * const batch = new WasmBatchAnalyzer(); * const result = await batch.analyzeBatch([ * '<html>page 1</html>', * '<html>page 2</html>', * ]); * console.log(`${result.getSuccessCount()} succeeded`); * const reports = result.getResults(); * ``` * @param {string[]} html_documents * @returns {Promise<WasmBatchResult>} */ analyzeBatch(html_documents) { const ptr0 = passArrayJsValueToWasm0(html_documents, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmbatchanalyzer_analyzeBatch(this.__wbg_ptr, ptr0, len0); return ret; } /** * Analyze batch with custom field selection * * Analyze multiple HTML documents and return only selected fields, * optimizing bandwidth for production batch processing. * * # Arguments * * `html_documents` - Array of HTML strings * * `fields` - Array of field names to include * * # Returns * Promise that resolves to array of filtered reports * @param {string[]} html_documents * @param {string[]} fields * @returns {Promise<any>} */ analyzeBatchWithFields(html_documents, fields) { const ptr0 = passArrayJsValueToWasm0(html_documents, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passArrayJsValueToWasm0(fields, wasm.__wbindgen_malloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.wasmbatchanalyzer_analyzeBatchWithFields(this.__wbg_ptr, ptr0, len0, ptr1, len1); return ret; } } const WasmBatchResultFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_wasmbatchresult_free(ptr >>> 0, 1)); /** * Batch analysis result container */ export class WasmBatchResult { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(WasmBatchResult.prototype); obj.__wbg_ptr = ptr; WasmBatchResultFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; WasmBatchResultFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_wasmbatchresult_free(ptr, 0); } /** * Get number of results * @returns {number} */ getCount() { const ret = wasm.wasmbatchresult_getCount(this.__wbg_ptr); return ret >>> 0; } /** * Get number of successful analyses * @returns {number} */ getSuccessCount() { const ret = wasm.wasmbatchresult_getSuccessCount(this.__wbg_ptr); return ret >>> 0; } /** * Get number of failed analyses * @returns {number} */ getFailureCount() { const ret = wasm.wasmbatchresult_getFailureCount(this.__wbg_ptr); return ret >>> 0; } /** * Get all results as JSON array * * Each element is either: * - `{ success: true, report: PageQualityReport }` * - `{ success: false, error: string }` * @returns {any} */ getResults() { const ret = wasm.wasmbatchresult_getResults(this.__wbg_ptr); if (ret[2]) { throw takeFromExternrefTable0(ret[1]); } return takeFromExternrefTable0(ret[0]); } } const WasmFieldSelectorFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_wasmfieldselector_free(ptr >>> 0, 1)); /** * WASM wrapper for FieldSelector - enables custom output field filtering * * This allows JavaScript/TypeScript to select only specific fields from the * analysis report, reducing JSON payload size by 60-70% for production use. * * # Example (JavaScript) * ```js * const analyzer = new WasmAnalyzer(); * const report = await analyzer.analyzeWithFields(html, ['url', 'score', 'metadata']); * // Returns only the 3 requested fields * ``` */ export class WasmFieldSelector { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(WasmFieldSelector.prototype); obj.__wbg_ptr = ptr; WasmFieldSelectorFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; WasmFieldSelectorFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_wasmfieldselector_free(ptr, 0); } /** * Create a new empty field selector */ constructor() { const ret = wasm.wasmfieldselector_new(); this.__wbg_ptr = ret >>> 0; WasmFieldSelectorFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Add fields to include (chainable) * * # Example (JavaScript) * ```js * const selector = new WasmFieldSelector() * .includeFields(['url', 'score', 'metadata']); * ``` * @param {string[]} fields * @returns {WasmFieldSelector} */ includeFields(fields) { const ptr = this.__destroy_into_raw(); const ptr0 = passArrayJsValueToWasm0(fields, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmfieldselector_includeFields(ptr, ptr0, len0); return WasmFieldSelector.__wrap(ret); } /** * Add fields to exclude (chainable) * @param {string[]} fields * @returns {WasmFieldSelector} */ excludeFields(fields) { const ptr = this.__destroy_into_raw(); const ptr0 = passArrayJsValueToWasm0(fields, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmfieldselector_excludeFields(ptr, ptr0, len0); return WasmFieldSelector.__wrap(ret); } /** * Add sections to include (chainable) * @param {string[]} sections * @returns {WasmFieldSelector} */ includeSections(sections) { const ptr = this.__destroy_into_raw(); const ptr0 = passArrayJsValueToWasm0(sections, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmfieldselector_includeSections(ptr, ptr0, len0); return WasmFieldSelector.__wrap(ret); } /** * Add sections to exclude (chainable) * @param {string[]} sections * @returns {WasmFieldSelector} */ excludeSections(sections) { const ptr = this.__destroy_into_raw(); const ptr0 = passArrayJsValueToWasm0(sections, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.wasmfieldselector_excludeSections(ptr, ptr0, len0); return WasmFieldSelector.__wrap(ret); } } export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) { const ret = String(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); }; export function __wbg_call_672a4d21634d4a24() { return handleError(function (arg0, arg1) { const ret = arg0.call(arg1); return ret; }, arguments) }; export function __wbg_call_7cccdd69e0791ae2() { return handleError(function (arg0, arg1, arg2) { const ret = arg0.call(arg1, arg2); return ret; }, arguments) }; export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) { let deferred0_0; let deferred0_1; try { deferred0_0 = arg0; deferred0_1 = arg1; console.error(getStringFromWasm0(arg0, arg1)); } finally { wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); } }; export function __wbg_fetch_b7bf320f681242d2(arg0, arg1) { const ret = arg0.fetch(arg1); return ret; }; export function __wbg_getTime_46267b1c24877e30(arg0) { const ret = arg0.getTime(); return ret; }; export function __wbg_headers_9cb51cfd2ac780a4(arg0) { const ret = arg0.headers; return ret; }; export function __wbg_instanceof_Response_f2cc20d9f7dfd644(arg0) { let result; try { result = arg0 instanceof Response; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_instanceof_Window_def73ea0955fc569(arg0) { let result; try { result = arg0 instanceof Window; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_new0_f788a2397c7ca929() { const ret = new Date(); return ret; }; export function __wbg_new_23a2665fac83c611(arg0, arg1) { try { var state0 = {a: arg0, b: arg1}; var cb0 = (arg0, arg1) => { const a = state0.a; state0.a = 0; try { return __wbg_adapter_130(a, state0.b, arg0, arg1); } finally { state0.a = a; } }; const ret = new Promise(cb0); return ret; } finally { state0.a = state0.b = 0; } }; export function __wbg_new_405e22f390576ce2() { const ret = new Object(); return ret; }; export function __wbg_new_5e0be73521bc8c17() { const ret = new Map(); return ret; }; export function __wbg_new_78feb108b6472713() { const ret = new Array(); return ret; }; export function __wbg_new_8a6f238a6ece86ea() { const ret = new Error(); return ret; }; export function __wbg_newnoargs_105ed471475aaf50(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return ret; }; export function __wbg_newwithstrandinit_06c535e0a867c635() { return handleError(function (arg0, arg1, arg2) { const ret = new Request(getStringFromWasm0(arg0, arg1), arg2); return ret; }, arguments) }; export function __wbg_ok_3aaf32d069979723(arg0) { const ret = arg0.ok; return ret; }; export function __wbg_queueMicrotask_97d92b4fcc8a61c5(arg0) { queueMicrotask(arg0); }; export function __wbg_queueMicrotask_d3219def82552485(arg0) { const ret = arg0.queueMicrotask; return ret; }; export function __wbg_resolve_4851785c9c5f573d(arg0) { const ret = Promise.resolve(arg0); return ret; }; export function __wbg_set_37837023f3d740e8(arg0, arg1, arg2) { arg0[arg1 >>> 0] = arg2; }; export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) { arg0[arg1] = arg2; }; export function __wbg_set_8fc6bf8a5b1071d1(arg0, arg1, arg2) { const ret = arg0.set(arg1, arg2); return ret; }; export function __wbg_setmethod_3c5280fe5d890842(arg0, arg1, arg2) { arg0.method = getStringFromWasm0(arg1, arg2); }; export function __wbg_setmode_5dc300b865044b65(arg0, arg1) { arg0.mode = __wbindgen_enum_RequestMode[arg1]; }; export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) { const ret = arg1.stack; const ptr1 = p