diff options
| author | Marijn Besseling <njirambem@gmail.com> | 2025-09-07 20:56:09 +0200 |
|---|---|---|
| committer | Marijn Besseling <njirambem@gmail.com> | 2025-09-07 20:56:09 +0200 |
| commit | 9ab322751a732d8cbc1ddf4f2ecf5022d7242baa (patch) | |
| tree | 49abc49c7d148b2f575aa5daef32875d44729561 /Blog/wwwroot/lz-string.module.js | |
WIP migration
Diffstat (limited to 'Blog/wwwroot/lz-string.module.js')
| -rw-r--r-- | Blog/wwwroot/lz-string.module.js | 425 |
1 files changed, 425 insertions, 0 deletions
diff --git a/Blog/wwwroot/lz-string.module.js b/Blog/wwwroot/lz-string.module.js new file mode 100644 index 0000000..6167fd2 --- /dev/null +++ b/Blog/wwwroot/lz-string.module.js | |||
| @@ -0,0 +1,425 @@ | |||
| 1 | // Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net> | ||
| 2 | // This work is free. You can redistribute it and/or modify it | ||
| 3 | // under the terms of the WTFPL, Version 2 | ||
| 4 | // For more information see LICENSE.txt or http://www.wtfpl.net/ | ||
| 5 | // | ||
| 6 | // For more information, the home page: | ||
| 7 | // http://pieroxy.net/blog/pages/lz-string/testing.html | ||
| 8 | // | ||
| 9 | // LZ-based compression algorithm, version 1.4.5 | ||
| 10 | var LzStringModule = (function() { | ||
| 11 | |||
| 12 | // private property | ||
| 13 | var f = String.fromCharCode; | ||
| 14 | var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$"; | ||
| 15 | var baseReverseDic = {}; | ||
| 16 | |||
| 17 | function getBaseValue(alphabet, character) { | ||
| 18 | if (!baseReverseDic[alphabet]) { | ||
| 19 | baseReverseDic[alphabet] = {}; | ||
| 20 | for (var i=0 ; i<alphabet.length ; i++) { | ||
| 21 | baseReverseDic[alphabet][alphabet.charAt(i)] = i; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | return baseReverseDic[alphabet][character]; | ||
| 25 | } | ||
| 26 | |||
| 27 | var LZString = { | ||
| 28 | //compress into a string that is already URI encoded | ||
| 29 | compressToEncodedURIComponent: function (input) { | ||
| 30 | if (input == null) return ""; | ||
| 31 | return LZString._compress(input, 6, function(a){return keyStrUriSafe.charAt(a);}); | ||
| 32 | }, | ||
| 33 | |||
| 34 | //decompress from an output of compressToEncodedURIComponent | ||
| 35 | decompressFromEncodedURIComponent:function (input) { | ||
| 36 | if (input == null) return ""; | ||
| 37 | if (input == "") return null; | ||
| 38 | input = input.replace(/ /g, "+"); | ||
| 39 | return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrUriSafe, input.charAt(index)); }); | ||
| 40 | }, | ||
| 41 | |||
| 42 | _compress: function (uncompressed, bitsPerChar, getCharFromInt) { | ||
| 43 | if (uncompressed == null) return ""; | ||
| 44 | var i, value, | ||
| 45 | context_dictionary= {}, | ||
| 46 | context_dictionaryToCreate= {}, | ||
| 47 | context_c="", | ||
| 48 | context_wc="", | ||
| 49 | context_w="", | ||
| 50 | context_enlargeIn= 2, // Compensate for the first entry which should not count | ||
| 51 | context_dictSize= 3, | ||
| 52 | context_numBits= 2, | ||
| 53 | context_data=[], | ||
| 54 | context_data_val=0, | ||
| 55 | context_data_position=0, | ||
| 56 | ii; | ||
| 57 | |||
| 58 | for (ii = 0; ii < uncompressed.length; ii += 1) { | ||
| 59 | context_c = uncompressed.charAt(ii); | ||
| 60 | if (!Object.prototype.hasOwnProperty.call(context_dictionary,context_c)) { | ||
| 61 | context_dictionary[context_c] = context_dictSize++; | ||
| 62 | context_dictionaryToCreate[context_c] = true; | ||
| 63 | } | ||
| 64 | |||
| 65 | context_wc = context_w + context_c; | ||
| 66 | if (Object.prototype.hasOwnProperty.call(context_dictionary,context_wc)) { | ||
| 67 | context_w = context_wc; | ||
| 68 | } else { | ||
| 69 | if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) { | ||
| 70 | if (context_w.charCodeAt(0)<256) { | ||
| 71 | for (i=0 ; i<context_numBits ; i++) { | ||
| 72 | context_data_val = (context_data_val << 1); | ||
| 73 | if (context_data_position == bitsPerChar-1) { | ||
| 74 | context_data_position = 0; | ||
| 75 | context_data.push(getCharFromInt(context_data_val)); | ||
| 76 | context_data_val = 0; | ||
| 77 | } else { | ||
| 78 | context_data_position++; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | value = context_w.charCodeAt(0); | ||
| 82 | for (i=0 ; i<8 ; i++) { | ||
| 83 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 84 | if (context_data_position == bitsPerChar-1) { | ||
| 85 | context_data_position = 0; | ||
| 86 | context_data.push(getCharFromInt(context_data_val)); | ||
| 87 | context_data_val = 0; | ||
| 88 | } else { | ||
| 89 | context_data_position++; | ||
| 90 | } | ||
| 91 | value = value >> 1; | ||
| 92 | } | ||
| 93 | } else { | ||
| 94 | value = 1; | ||
| 95 | for (i=0 ; i<context_numBits ; i++) { | ||
| 96 | context_data_val = (context_data_val << 1) | value; | ||
| 97 | if (context_data_position ==bitsPerChar-1) { | ||
| 98 | context_data_position = 0; | ||
| 99 | context_data.push(getCharFromInt(context_data_val)); | ||
| 100 | context_data_val = 0; | ||
| 101 | } else { | ||
| 102 | context_data_position++; | ||
| 103 | } | ||
| 104 | value = 0; | ||
| 105 | } | ||
| 106 | value = context_w.charCodeAt(0); | ||
| 107 | for (i=0 ; i<16 ; i++) { | ||
| 108 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 109 | if (context_data_position == bitsPerChar-1) { | ||
| 110 | context_data_position = 0; | ||
| 111 | context_data.push(getCharFromInt(context_data_val)); | ||
| 112 | context_data_val = 0; | ||
| 113 | } else { | ||
| 114 | context_data_position++; | ||
| 115 | } | ||
| 116 | value = value >> 1; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | context_enlargeIn--; | ||
| 120 | if (context_enlargeIn == 0) { | ||
| 121 | context_enlargeIn = Math.pow(2, context_numBits); | ||
| 122 | context_numBits++; | ||
| 123 | } | ||
| 124 | delete context_dictionaryToCreate[context_w]; | ||
| 125 | } else { | ||
| 126 | value = context_dictionary[context_w]; | ||
| 127 | for (i=0 ; i<context_numBits ; i++) { | ||
| 128 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 129 | if (context_data_position == bitsPerChar-1) { | ||
| 130 | context_data_position = 0; | ||
| 131 | context_data.push(getCharFromInt(context_data_val)); | ||
| 132 | context_data_val = 0; | ||
| 133 | } else { | ||
| 134 | context_data_position++; | ||
| 135 | } | ||
| 136 | value = value >> 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | } | ||
| 141 | context_enlargeIn--; | ||
| 142 | if (context_enlargeIn == 0) { | ||
| 143 | context_enlargeIn = Math.pow(2, context_numBits); | ||
| 144 | context_numBits++; | ||
| 145 | } | ||
| 146 | // Add wc to the dictionary. | ||
| 147 | context_dictionary[context_wc] = context_dictSize++; | ||
| 148 | context_w = String(context_c); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | // Output the code for w. | ||
| 153 | if (context_w !== "") { | ||
| 154 | if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) { | ||
| 155 | if (context_w.charCodeAt(0)<256) { | ||
| 156 | for (i=0 ; i<context_numBits ; i++) { | ||
| 157 | context_data_val = (context_data_val << 1); | ||
| 158 | if (context_data_position == bitsPerChar-1) { | ||
| 159 | context_data_position = 0; | ||
| 160 | context_data.push(getCharFromInt(context_data_val)); | ||
| 161 | context_data_val = 0; | ||
| 162 | } else { | ||
| 163 | context_data_position++; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | value = context_w.charCodeAt(0); | ||
| 167 | for (i=0 ; i<8 ; i++) { | ||
| 168 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 169 | if (context_data_position == bitsPerChar-1) { | ||
| 170 | context_data_position = 0; | ||
| 171 | context_data.push(getCharFromInt(context_data_val)); | ||
| 172 | context_data_val = 0; | ||
| 173 | } else { | ||
| 174 | context_data_position++; | ||
| 175 | } | ||
| 176 | value = value >> 1; | ||
| 177 | } | ||
| 178 | } else { | ||
| 179 | value = 1; | ||
| 180 | for (i=0 ; i<context_numBits ; i++) { | ||
| 181 | context_data_val = (context_data_val << 1) | value; | ||
| 182 | if (context_data_position == bitsPerChar-1) { | ||
| 183 | context_data_position = 0; | ||
| 184 | context_data.push(getCharFromInt(context_data_val)); | ||
| 185 | context_data_val = 0; | ||
| 186 | } else { | ||
| 187 | context_data_position++; | ||
| 188 | } | ||
| 189 | value = 0; | ||
| 190 | } | ||
| 191 | value = context_w.charCodeAt(0); | ||
| 192 | for (i=0 ; i<16 ; i++) { | ||
| 193 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 194 | if (context_data_position == bitsPerChar-1) { | ||
| 195 | context_data_position = 0; | ||
| 196 | context_data.push(getCharFromInt(context_data_val)); | ||
| 197 | context_data_val = 0; | ||
| 198 | } else { | ||
| 199 | context_data_position++; | ||
| 200 | } | ||
| 201 | value = value >> 1; | ||
| 202 | } | ||
| 203 | } | ||
| 204 | context_enlargeIn--; | ||
| 205 | if (context_enlargeIn == 0) { | ||
| 206 | context_enlargeIn = Math.pow(2, context_numBits); | ||
| 207 | context_numBits++; | ||
| 208 | } | ||
| 209 | delete context_dictionaryToCreate[context_w]; | ||
| 210 | } else { | ||
| 211 | value = context_dictionary[context_w]; | ||
| 212 | for (i=0 ; i<context_numBits ; i++) { | ||
| 213 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 214 | if (context_data_position == bitsPerChar-1) { | ||
| 215 | context_data_position = 0; | ||
| 216 | context_data.push(getCharFromInt(context_data_val)); | ||
| 217 | context_data_val = 0; | ||
| 218 | } else { | ||
| 219 | context_data_position++; | ||
| 220 | } | ||
| 221 | value = value >> 1; | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | } | ||
| 226 | context_enlargeIn--; | ||
| 227 | if (context_enlargeIn == 0) { | ||
| 228 | context_enlargeIn = Math.pow(2, context_numBits); | ||
| 229 | context_numBits++; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | |||
| 233 | // Mark the end of the stream | ||
| 234 | value = 2; | ||
| 235 | for (i=0 ; i<context_numBits ; i++) { | ||
| 236 | context_data_val = (context_data_val << 1) | (value&1); | ||
| 237 | if (context_data_position == bitsPerChar-1) { | ||
| 238 | context_data_position = 0; | ||
| 239 | context_data.push(getCharFromInt(context_data_val)); | ||
| 240 | context_data_val = 0; | ||
| 241 | } else { | ||
| 242 | context_data_position++; | ||
| 243 | } | ||
| 244 | value = value >> 1; | ||
| 245 | } | ||
| 246 | |||
| 247 | // Flush the last char | ||
| 248 | while (true) { | ||
| 249 | context_data_val = (context_data_val << 1); | ||
| 250 | if (context_data_position == bitsPerChar-1) { | ||
| 251 | context_data.push(getCharFromInt(context_data_val)); | ||
| 252 | break; | ||
| 253 | } | ||
| 254 | else context_data_position++; | ||
| 255 | } | ||
| 256 | return context_data.join(''); | ||
| 257 | }, | ||
| 258 | |||
| 259 | _decompress: function (length, resetValue, getNextValue) { | ||
| 260 | var dictionary = [], | ||
| 261 | next, | ||
| 262 | enlargeIn = 4, | ||
| 263 | dictSize = 4, | ||
| 264 | numBits = 3, | ||
| 265 | entry = "", | ||
| 266 | result = [], | ||
| 267 | i, | ||
| 268 | w, | ||
| 269 | bits, resb, maxpower, power, | ||
| 270 | c, | ||
| 271 | data = {val:getNextValue(0), position:resetValue, index:1}; | ||
| 272 | |||
| 273 | for (i = 0; i < 3; i += 1) { | ||
| 274 | dictionary[i] = i; | ||
| 275 | } | ||
| 276 | |||
| 277 | bits = 0; | ||
| 278 | maxpower = Math.pow(2,2); | ||
| 279 | power=1; | ||
| 280 | while (power!=maxpower) { | ||
| 281 | resb = data.val & data.position; | ||
| 282 | data.position >>= 1; | ||
| 283 | if (data.position == 0) { | ||
| 284 | data.position = resetValue; | ||
| 285 | data.val = getNextValue(data.index++); | ||
| 286 | } | ||
| 287 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 288 | power <<= 1; | ||
| 289 | } | ||
| 290 | |||
| 291 | switch (next = bits) { | ||
| 292 | case 0: | ||
| 293 | bits = 0; | ||
| 294 | maxpower = Math.pow(2,8); | ||
| 295 | power=1; | ||
| 296 | while (power!=maxpower) { | ||
| 297 | resb = data.val & data.position; | ||
| 298 | data.position >>= 1; | ||
| 299 | if (data.position == 0) { | ||
| 300 | data.position = resetValue; | ||
| 301 | data.val = getNextValue(data.index++); | ||
| 302 | } | ||
| 303 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 304 | power <<= 1; | ||
| 305 | } | ||
| 306 | c = f(bits); | ||
| 307 | break; | ||
| 308 | case 1: | ||
| 309 | bits = 0; | ||
| 310 | maxpower = Math.pow(2,16); | ||
| 311 | power=1; | ||
| 312 | while (power!=maxpower) { | ||
| 313 | resb = data.val & data.position; | ||
| 314 | data.position >>= 1; | ||
| 315 | if (data.position == 0) { | ||
| 316 | data.position = resetValue; | ||
| 317 | data.val = getNextValue(data.index++); | ||
| 318 | } | ||
| 319 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 320 | power <<= 1; | ||
| 321 | } | ||
| 322 | c = f(bits); | ||
| 323 | break; | ||
| 324 | case 2: | ||
| 325 | return ""; | ||
| 326 | } | ||
| 327 | dictionary[3] = c; | ||
| 328 | w = c; | ||
| 329 | result.push(c); | ||
| 330 | while (true) { | ||
| 331 | if (data.index > length) { | ||
| 332 | return ""; | ||
| 333 | } | ||
| 334 | |||
| 335 | bits = 0; | ||
| 336 | maxpower = Math.pow(2,numBits); | ||
| 337 | power=1; | ||
| 338 | while (power!=maxpower) { | ||
| 339 | resb = data.val & data.position; | ||
| 340 | data.position >>= 1; | ||
| 341 | if (data.position == 0) { | ||
| 342 | data.position = resetValue; | ||
| 343 | data.val = getNextValue(data.index++); | ||
| 344 | } | ||
| 345 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 346 | power <<= 1; | ||
| 347 | } | ||
| 348 | |||
| 349 | switch (c = bits) { | ||
| 350 | case 0: | ||
| 351 | bits = 0; | ||
| 352 | maxpower = Math.pow(2,8); | ||
| 353 | power=1; | ||
| 354 | while (power!=maxpower) { | ||
| 355 | resb = data.val & data.position; | ||
| 356 | data.position >>= 1; | ||
| 357 | if (data.position == 0) { | ||
| 358 | data.position = resetValue; | ||
| 359 | data.val = getNextValue(data.index++); | ||
| 360 | } | ||
| 361 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 362 | power <<= 1; | ||
| 363 | } | ||
| 364 | |||
| 365 | dictionary[dictSize++] = f(bits); | ||
| 366 | c = dictSize-1; | ||
| 367 | enlargeIn--; | ||
| 368 | break; | ||
| 369 | case 1: | ||
| 370 | bits = 0; | ||
| 371 | maxpower = Math.pow(2,16); | ||
| 372 | power=1; | ||
| 373 | while (power!=maxpower) { | ||
| 374 | resb = data.val & data.position; | ||
| 375 | data.position >>= 1; | ||
| 376 | if (data.position == 0) { | ||
| 377 | data.position = resetValue; | ||
| 378 | data.val = getNextValue(data.index++); | ||
| 379 | } | ||
| 380 | bits |= (resb>0 ? 1 : 0) * power; | ||
| 381 | power <<= 1; | ||
| 382 | } | ||
| 383 | dictionary[dictSize++] = f(bits); | ||
| 384 | c = dictSize-1; | ||
| 385 | enlargeIn--; | ||
| 386 | break; | ||
| 387 | case 2: | ||
| 388 | return result.join(''); | ||
| 389 | } | ||
| 390 | |||
| 391 | if (enlargeIn == 0) { | ||
| 392 | enlargeIn = Math.pow(2, numBits); | ||
| 393 | numBits++; | ||
| 394 | } | ||
| 395 | |||
| 396 | if (dictionary[c]) { | ||
| 397 | entry = dictionary[c]; | ||
| 398 | } else { | ||
| 399 | if (c === dictSize) { | ||
| 400 | entry = w + w.charAt(0); | ||
| 401 | } else { | ||
| 402 | return null; | ||
| 403 | } | ||
| 404 | } | ||
| 405 | result.push(entry); | ||
| 406 | |||
| 407 | // Add w+entry[0] to the dictionary. | ||
| 408 | dictionary[dictSize++] = w + entry.charAt(0); | ||
| 409 | enlargeIn--; | ||
| 410 | |||
| 411 | w = entry; | ||
| 412 | |||
| 413 | if (enlargeIn == 0) { | ||
| 414 | enlargeIn = Math.pow(2, numBits); | ||
| 415 | numBits++; | ||
| 416 | } | ||
| 417 | |||
| 418 | } | ||
| 419 | } | ||
| 420 | }; | ||
| 421 | return LZString; | ||
| 422 | })(); | ||
| 423 | |||
| 424 | |||
| 425 | export default LzStringModule; \ No newline at end of file | ||