Set this line to choose the behavior:
constexpr SafetyLevel kConfiguredLevel =
SafetyLevel::ClosedMouseOnly;| // Normalize canonical (5-byte) LEB128 encodings to minimal form | |
| // WebAssemblyText uses canonical LEB encodings with padding, watr uses minimal | |
| // This function converts canonical LEBs to minimal to allow byte-level comparison | |
| function normalizeLebs(bytes) { | |
| const result = []; | |
| let i = 0; | |
| // Helper to read a LEB128 (any size) | |
| function readLeb(start) { |
| let mediaElement = new Audio('data:audio/wav;base64,UklGRmgAAABXQVZFZm10IBAAAAABAAEAgLsAAAB3AQACABAAZGF0YQIAAABpNUxJU1Q6AAAASU5GT0lTRlQUAAAAcHJvYmUuYXVkaW90b29sLmNvbQBJQ1JEEQAAADIwMjMtMDMtMDIgMDctNDQAAA==') | |
| mediaElement.preload = "metadata" | |
| mediaElement.load() | |
| mediaElement.volume = 0 | |
| // Measure latency of audio file between first 'playing' event and actual first sample | |
| export async function measureLatency() { | |
| return new Promise(ok => { | |
| mediaElement.play() | |
| let start |
| /** | |
| * Play clip of audio/video, possibly with loop. | |
| * Based on https://github.com/muxinc/media-offset | |
| * Extracted from wavearea v0 | |
| * | |
| * @param {HTMLMediaElement} media - An audio/video/etc element | |
| * @param {object} clip - Object with `{start, end?}` signature, indicating clip to play | |
| * @returns | |
| */ | |
| export default function playClip (media, clip) { |
Set this line to choose the behavior:
constexpr SafetyLevel kConfiguredLevel =
SafetyLevel::ClosedMouseOnly;| // test some performance parts | |
| // wasm is surprizingly not as fast, even in full version | |
| import t from 'tst' | |
| import watr from 'watr' | |
| const f64pow = `(func $f64pow (param f64 f64)(result f64)(local f64 i64 i64 i64 f64 f64 f64 f64 f64 f64)(local.set 2(f64.const 0x1p+0))(block(br_if 0(f64.eq(local.get 1)(f64.const 0x0p+0)))(local.set 3(i64.const 0))(block(br_if 0(i64.gt_s(i64.reinterpret_f64(local.get 0))(i64.const -1)))(br_if 0(f64.ne(f64.nearest(local.get 1))(local.get 1)))(local.set 3(i64.shl(i64.extend_i32_u(f64.ne(f64.nearest(local.tee 2(f64.mul(local.get 1)(f64.const 0x1p-1))))(local.get 2)))(i64.const 63)))(local.set 0(f64.neg(local.get 0))))(local.set 2(f64.const 0x1p+0))(block(br_if 0(f64.eq(local.get 0)(f64.const 0x1p+0)))(block(br_if 0(f64.ne(local.get 0)(f64.const 0x0p+0)))(local.set 2(select(f64.const inf)(f64.const 0x0p+0)(i64.lt_s(i64.reinterpret_f64(local.get 1))(i64.const 0))))(br 1))(block(br_if 0(f64.ne(f64.abs(local.get 0))(f64.const inf)))(local.set 2(select(f64.const 0x0p+0)(f64.const inf) |
| function constructFloat64(sign, exp, sig) { | |
| // Constants | |
| const EXPONENT_BIAS = 1023n; | |
| const EXPONENT_MASK = 0x7FFn; | |
| const SIGNIFICAND_MASK = 0xFFFFFFFFFFFFFn; | |
| console.log(sign, exp, sig, BigInt(sig) & SIGNIFICAND_MASK) | |
| // Mask and adjust the components | |
| sign = sign < 0 ? 1n : 0n; |
| // based on https://observablehq.com/@jrus/hexfloat | |
| const flt_arr = new Float64Array([1]); | |
| const int_arr = new Int32Array(flt_arr.buffer); | |
| const SIGN_MASK = 0x7fffffff; // 0111 1111 1111 1111 1111 1111 1111 1111 | |
| const EXP_MASK = 0x7ff00000; // 0111 1111 1111 0000 0000 0000 0000 0000 | |
| // HI = 1 on little endian platforms, 0 on big-endian platforms. | |
| const HI = 1, LO = 0; | |
| const floathex = (x) => { |
Here’s a minimal and organized markdown structure, focusing on word transformations with examples, excluding duplicates:
| // @preact/signals compatible wrapper for signal proposal | |
| import { Signal } from 'signal-polyfill' | |
| const { untrack, Watcher } = Signal.subtle | |
| export const signal = v => wrap(new Signal.State(v)) | |
| export const computed = fn => wrap(new Signal.Computed(fn)) | |
| export { untrack as untracked } |
from https://x.com/_developit/status/1722346883568357856?s=20
function untracked(fn) { computed(fn).peek()}function bump (s) {let _ = s.value; s.value = undefined; s.value = _ }const s = signal(0), c = 0; const trigger = () => (s!=c?s.value++:c=s.value); effect(trigger)