1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/extensions/shumway/content/shumway-worker.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,6180 @@ 1.4 +/* 1.5 + * Copyright 2013 Mozilla Foundation 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +// This file is automatically generated 1.21 + 1.22 +(function (global) { 1.23 + if (global.DataView) 1.24 + return; 1.25 + if (!global.ArrayBuffer) 1.26 + fail('ArrayBuffer not supported'); 1.27 + if (!Object.defineProperties) 1.28 + fail('This module requires ECMAScript 5'); 1.29 + var nativele = new Int8Array(new Int32Array([ 1.30 + 1 1.31 + ]).buffer)[0] === 1; 1.32 + var temp = new Uint8Array(8); 1.33 + global.DataView = function DataView(buffer, offset, length) { 1.34 + if (!(buffer instanceof ArrayBuffer)) 1.35 + fail('Bad ArrayBuffer'); 1.36 + offset = offset || 0; 1.37 + length = length || buffer.byteLength - offset; 1.38 + if (offset < 0 || length < 0 || offset + length > buffer.byteLength) 1.39 + fail('Illegal offset and/or length'); 1.40 + Object.defineProperties(this, { 1.41 + buffer: { 1.42 + value: buffer, 1.43 + enumerable: false, 1.44 + writable: false, 1.45 + configurable: false 1.46 + }, 1.47 + byteOffset: { 1.48 + value: offset, 1.49 + enumerable: false, 1.50 + writable: false, 1.51 + configurable: false 1.52 + }, 1.53 + byteLength: { 1.54 + value: length, 1.55 + enumerable: false, 1.56 + writable: false, 1.57 + configurable: false 1.58 + }, 1.59 + _bytes: { 1.60 + value: new Uint8Array(buffer, offset, length), 1.61 + enumerable: false, 1.62 + writable: false, 1.63 + configurable: false 1.64 + } 1.65 + }); 1.66 + }; 1.67 + global.DataView.prototype = { 1.68 + constructor: DataView, 1.69 + getInt8: function getInt8(offset) { 1.70 + return get(this, Int8Array, 1, offset); 1.71 + }, 1.72 + getUint8: function getUint8(offset) { 1.73 + return get(this, Uint8Array, 1, offset); 1.74 + }, 1.75 + getInt16: function getInt16(offset, le) { 1.76 + return get(this, Int16Array, 2, offset, le); 1.77 + }, 1.78 + getUint16: function getUint16(offset, le) { 1.79 + return get(this, Uint16Array, 2, offset, le); 1.80 + }, 1.81 + getInt32: function getInt32(offset, le) { 1.82 + return get(this, Int32Array, 4, offset, le); 1.83 + }, 1.84 + getUint32: function getUint32(offset, le) { 1.85 + return get(this, Uint32Array, 4, offset, le); 1.86 + }, 1.87 + getFloat32: function getFloat32(offset, le) { 1.88 + return get(this, Float32Array, 4, offset, le); 1.89 + }, 1.90 + getFloat64: function getFloat32(offset, le) { 1.91 + return get(this, Float64Array, 8, offset, le); 1.92 + }, 1.93 + setInt8: function setInt8(offset, value) { 1.94 + set(this, Int8Array, 1, offset, value); 1.95 + }, 1.96 + setUint8: function setUint8(offset, value) { 1.97 + set(this, Uint8Array, 1, offset, value); 1.98 + }, 1.99 + setInt16: function setInt16(offset, value, le) { 1.100 + set(this, Int16Array, 2, offset, value, le); 1.101 + }, 1.102 + setUint16: function setUint16(offset, value, le) { 1.103 + set(this, Uint16Array, 2, offset, value, le); 1.104 + }, 1.105 + setInt32: function setInt32(offset, value, le) { 1.106 + set(this, Int32Array, 4, offset, value, le); 1.107 + }, 1.108 + setUint32: function setUint32(offset, value, le) { 1.109 + set(this, Uint32Array, 4, offset, value, le); 1.110 + }, 1.111 + setFloat32: function setFloat32(offset, value, le) { 1.112 + set(this, Float32Array, 4, offset, value, le); 1.113 + }, 1.114 + setFloat64: function setFloat64(offset, value, le) { 1.115 + set(this, Float64Array, 8, offset, value, le); 1.116 + } 1.117 + }; 1.118 + function get(view, type, size, offset, le) { 1.119 + if (offset === undefined) 1.120 + fail('Missing required offset argument'); 1.121 + if (offset < 0 || offset + size > view.byteLength) 1.122 + fail('Invalid index: ' + offset); 1.123 + if (size === 1 || !(!le) === nativele) { 1.124 + if ((view.byteOffset + offset) % size === 0) 1.125 + return new type(view.buffer, view.byteOffset + offset, 1)[0]; 1.126 + else { 1.127 + for (var i = 0; i < size; i++) 1.128 + temp[i] = view._bytes[offset + i]; 1.129 + return new type(temp.buffer)[0]; 1.130 + } 1.131 + } else { 1.132 + for (var i = 0; i < size; i++) 1.133 + temp[size - i - 1] = view._bytes[offset + i]; 1.134 + return new type(temp.buffer)[0]; 1.135 + } 1.136 + } 1.137 + function set(view, type, size, offset, value, le) { 1.138 + if (offset === undefined) 1.139 + fail('Missing required offset argument'); 1.140 + if (value === undefined) 1.141 + fail('Missing required value argument'); 1.142 + if (offset < 0 || offset + size > view.byteLength) 1.143 + fail('Invalid index: ' + offset); 1.144 + if (size === 1 || !(!le) === nativele) { 1.145 + if ((view.byteOffset + offset) % size === 0) { 1.146 + new type(view.buffer, view.byteOffset + offset, 1)[0] = value; 1.147 + } else { 1.148 + new type(temp.buffer)[0] = value; 1.149 + for (var i = 0; i < size; i++) 1.150 + view._bytes[i + offset] = temp[i]; 1.151 + } 1.152 + } else { 1.153 + new type(temp.buffer)[0] = value; 1.154 + for (var i = 0; i < size; i++) 1.155 + view._bytes[offset + i] = temp[size - 1 - i]; 1.156 + } 1.157 + } 1.158 + function fail(msg) { 1.159 + throw new Error(msg); 1.160 + } 1.161 +}(this)); 1.162 +var create = Object.create; 1.163 +var defineProperty = Object.defineProperty; 1.164 +var keys = Object.keys; 1.165 +var isArray = Array.isArray; 1.166 +var fromCharCode = String.fromCharCode; 1.167 +var logE = Math.log; 1.168 +var max = Math.max; 1.169 +var min = Math.min; 1.170 +var pow = Math.pow; 1.171 +var push = Array.prototype.push; 1.172 +var slice = Array.prototype.slice; 1.173 +var splice = Array.prototype.splice; 1.174 +function fail(msg, context) { 1.175 + throw new Error((context ? context + ': ' : '') + msg); 1.176 +} 1.177 +function assert(cond, msg, context) { 1.178 + if (!cond) 1.179 + fail(msg, context); 1.180 +} 1.181 +function scriptProperties(namespace, props) { 1.182 + return props.reduce(function (o, p) { 1.183 + o[p] = namespace + ' ' + p; 1.184 + return o; 1.185 + }, {}); 1.186 +} 1.187 +function cloneObject(obj) { 1.188 + var clone = Object.create(null); 1.189 + for (var prop in obj) 1.190 + clone[prop] = obj[prop]; 1.191 + return clone; 1.192 +} 1.193 +function sortNumeric(a, b) { 1.194 + return a - b; 1.195 +} 1.196 +function sortByZindex(a, b) { 1.197 + return a._zindex - b._zindex; 1.198 +} 1.199 +function rgbaObjToStr(color) { 1.200 + return 'rgba(' + color.red + ',' + color.green + ',' + color.blue + ',' + color.alpha / 255 + ')'; 1.201 +} 1.202 +function rgbIntAlphaToStr(color, alpha) { 1.203 + color |= 0; 1.204 + if (alpha >= 1) { 1.205 + var colorStr = color.toString(16); 1.206 + while (colorStr.length < 6) { 1.207 + colorStr = '0' + colorStr; 1.208 + } 1.209 + return '#' + colorStr; 1.210 + } 1.211 + var red = color >> 16 & 255; 1.212 + var green = color >> 8 & 255; 1.213 + var blue = color & 255; 1.214 + return 'rgba(' + red + ',' + green + ',' + blue + ',' + alpha + ')'; 1.215 +} 1.216 +function argbUintToStr(argb) { 1.217 + return 'rgba(' + (argb >>> 16 & 255) + ',' + (argb >>> 8 & 255) + ',' + (argb & 255) + ',' + (argb >>> 24 & 255) / 255 + ')'; 1.218 +} 1.219 +(function functionNameSupport() { 1.220 + if (eval('function t() {} t.name === \'t\'')) { 1.221 + return; 1.222 + } 1.223 + Object.defineProperty(Function.prototype, 'name', { 1.224 + get: function () { 1.225 + if (this.__name) { 1.226 + return this.__name; 1.227 + } 1.228 + var m = /function\s([^\(]+)/.exec(this.toString()); 1.229 + var name = m && m[1] !== 'anonymous' ? m[1] : null; 1.230 + this.__name = name; 1.231 + return name; 1.232 + }, 1.233 + configurable: true, 1.234 + enumerable: false 1.235 + }); 1.236 +}()); 1.237 +var randomStyleCache; 1.238 +var nextStyle = 0; 1.239 +function randomStyle() { 1.240 + if (!randomStyleCache) { 1.241 + randomStyleCache = [ 1.242 + '#ff5e3a', 1.243 + '#ff9500', 1.244 + '#ffdb4c', 1.245 + '#87fc70', 1.246 + '#52edc7', 1.247 + '#1ad6fd', 1.248 + '#c644fc', 1.249 + '#ef4db6', 1.250 + '#4a4a4a', 1.251 + '#dbddde', 1.252 + '#ff3b30', 1.253 + '#ff9500', 1.254 + '#ffcc00', 1.255 + '#4cd964', 1.256 + '#34aadc', 1.257 + '#007aff', 1.258 + '#5856d6', 1.259 + '#ff2d55', 1.260 + '#8e8e93', 1.261 + '#c7c7cc', 1.262 + '#5ad427', 1.263 + '#c86edf', 1.264 + '#d1eefc', 1.265 + '#e0f8d8', 1.266 + '#fb2b69', 1.267 + '#f7f7f7', 1.268 + '#1d77ef', 1.269 + '#d6cec3', 1.270 + '#55efcb', 1.271 + '#ff4981', 1.272 + '#ffd3e0', 1.273 + '#f7f7f7', 1.274 + '#ff1300', 1.275 + '#1f1f21', 1.276 + '#bdbec2', 1.277 + '#ff3a2d' 1.278 + ]; 1.279 + } 1.280 + return randomStyleCache[nextStyle++ % randomStyleCache.length]; 1.281 +} 1.282 +(function PromiseClosure() { 1.283 + var global = Function('return this')(); 1.284 + if (global.Promise) { 1.285 + if (typeof global.Promise.all !== 'function') { 1.286 + global.Promise.all = function (iterable) { 1.287 + var count = 0, results = [], resolve, reject; 1.288 + var promise = new global.Promise(function (resolve_, reject_) { 1.289 + resolve = resolve_; 1.290 + reject = reject_; 1.291 + }); 1.292 + iterable.forEach(function (p, i) { 1.293 + count++; 1.294 + p.then(function (result) { 1.295 + results[i] = result; 1.296 + count--; 1.297 + if (count === 0) { 1.298 + resolve(results); 1.299 + } 1.300 + }, reject); 1.301 + }); 1.302 + if (count === 0) { 1.303 + resolve(results); 1.304 + } 1.305 + return promise; 1.306 + }; 1.307 + } 1.308 + if (typeof global.Promise.resolve !== 'function') { 1.309 + global.Promise.resolve = function (x) { 1.310 + return new global.Promise(function (resolve) { 1.311 + resolve(x); 1.312 + }); 1.313 + }; 1.314 + } 1.315 + return; 1.316 + } 1.317 + function getDeferred(C) { 1.318 + if (typeof C !== 'function') { 1.319 + throw new TypeError('Invalid deferred constructor'); 1.320 + } 1.321 + var resolver = createDeferredConstructionFunctions(); 1.322 + var promise = new C(resolver); 1.323 + var resolve = resolver.resolve; 1.324 + if (typeof resolve !== 'function') { 1.325 + throw new TypeError('Invalid resolve construction function'); 1.326 + } 1.327 + var reject = resolver.reject; 1.328 + if (typeof reject !== 'function') { 1.329 + throw new TypeError('Invalid reject construction function'); 1.330 + } 1.331 + return { 1.332 + promise: promise, 1.333 + resolve: resolve, 1.334 + reject: reject 1.335 + }; 1.336 + } 1.337 + function updateDeferredFromPotentialThenable(x, deferred) { 1.338 + if (typeof x !== 'object' || x === null) { 1.339 + return false; 1.340 + } 1.341 + try { 1.342 + var then = x.then; 1.343 + if (typeof then !== 'function') { 1.344 + return false; 1.345 + } 1.346 + var thenCallResult = then.call(x, deferred.resolve, deferred.reject); 1.347 + } catch (e) { 1.348 + var reject = deferred.reject; 1.349 + reject(e); 1.350 + } 1.351 + return true; 1.352 + } 1.353 + function isPromise(x) { 1.354 + return typeof x === 'object' && x !== null && typeof x.promiseStatus !== 'undefined'; 1.355 + } 1.356 + function rejectPromise(promise, reason) { 1.357 + if (promise.promiseStatus !== 'unresolved') { 1.358 + return; 1.359 + } 1.360 + var reactions = promise.rejectReactions; 1.361 + promise.result = reason; 1.362 + promise.resolveReactions = undefined; 1.363 + promise.rejectReactions = undefined; 1.364 + promise.promiseStatus = 'has-rejection'; 1.365 + triggerPromiseReactions(reactions, reason); 1.366 + } 1.367 + function resolvePromise(promise, resolution) { 1.368 + if (promise.promiseStatus !== 'unresolved') { 1.369 + return; 1.370 + } 1.371 + var reactions = promise.resolveReactions; 1.372 + promise.result = resolution; 1.373 + promise.resolveReactions = undefined; 1.374 + promise.rejectReactions = undefined; 1.375 + promise.promiseStatus = 'has-resolution'; 1.376 + triggerPromiseReactions(reactions, resolution); 1.377 + } 1.378 + function triggerPromiseReactions(reactions, argument) { 1.379 + for (var i = 0; i < reactions.length; i++) { 1.380 + queueMicrotask({ 1.381 + reaction: reactions[i], 1.382 + argument: argument 1.383 + }); 1.384 + } 1.385 + } 1.386 + function queueMicrotask(task) { 1.387 + if (microtasksQueue.length === 0) { 1.388 + setTimeout(handleMicrotasksQueue, 0); 1.389 + } 1.390 + microtasksQueue.push(task); 1.391 + } 1.392 + function executePromiseReaction(reaction, argument) { 1.393 + var deferred = reaction.deferred; 1.394 + var handler = reaction.handler; 1.395 + var handlerResult, updateResult; 1.396 + try { 1.397 + handlerResult = handler(argument); 1.398 + } catch (e) { 1.399 + var reject = deferred.reject; 1.400 + return reject(e); 1.401 + } 1.402 + if (handlerResult === deferred.promise) { 1.403 + var reject = deferred.reject; 1.404 + return reject(new TypeError('Self resolution')); 1.405 + } 1.406 + try { 1.407 + updateResult = updateDeferredFromPotentialThenable(handlerResult, deferred); 1.408 + if (!updateResult) { 1.409 + var resolve = deferred.resolve; 1.410 + return resolve(handlerResult); 1.411 + } 1.412 + } catch (e) { 1.413 + var reject = deferred.reject; 1.414 + return reject(e); 1.415 + } 1.416 + } 1.417 + var microtasksQueue = []; 1.418 + function handleMicrotasksQueue() { 1.419 + while (microtasksQueue.length > 0) { 1.420 + var task = microtasksQueue[0]; 1.421 + try { 1.422 + executePromiseReaction(task.reaction, task.argument); 1.423 + } catch (e) { 1.424 + if (typeof Promise.onerror === 'function') { 1.425 + Promise.onerror(e); 1.426 + } 1.427 + } 1.428 + microtasksQueue.shift(); 1.429 + } 1.430 + } 1.431 + function throwerFunction(e) { 1.432 + throw e; 1.433 + } 1.434 + function identityFunction(x) { 1.435 + return x; 1.436 + } 1.437 + function createRejectPromiseFunction(promise) { 1.438 + return function (reason) { 1.439 + rejectPromise(promise, reason); 1.440 + }; 1.441 + } 1.442 + function createResolvePromiseFunction(promise) { 1.443 + return function (resolution) { 1.444 + resolvePromise(promise, resolution); 1.445 + }; 1.446 + } 1.447 + function createDeferredConstructionFunctions() { 1.448 + var fn = function (resolve, reject) { 1.449 + fn.resolve = resolve; 1.450 + fn.reject = reject; 1.451 + }; 1.452 + return fn; 1.453 + } 1.454 + function createPromiseResolutionHandlerFunctions(promise, fulfillmentHandler, rejectionHandler) { 1.455 + return function (x) { 1.456 + if (x === promise) { 1.457 + return rejectionHandler(new TypeError('Self resolution')); 1.458 + } 1.459 + var cstr = promise.promiseConstructor; 1.460 + if (isPromise(x)) { 1.461 + var xConstructor = x.promiseConstructor; 1.462 + if (xConstructor === cstr) { 1.463 + return x.then(fulfillmentHandler, rejectionHandler); 1.464 + } 1.465 + } 1.466 + var deferred = getDeferred(cstr); 1.467 + var updateResult = updateDeferredFromPotentialThenable(x, deferred); 1.468 + if (updateResult) { 1.469 + var deferredPromise = deferred.promise; 1.470 + return deferredPromise.then(fulfillmentHandler, rejectionHandler); 1.471 + } 1.472 + return fulfillmentHandler(x); 1.473 + }; 1.474 + } 1.475 + function createPromiseAllCountdownFunction(index, values, deferred, countdownHolder) { 1.476 + return function (x) { 1.477 + values[index] = x; 1.478 + countdownHolder.countdown--; 1.479 + if (countdownHolder.countdown === 0) { 1.480 + deferred.resolve(values); 1.481 + } 1.482 + }; 1.483 + } 1.484 + function Promise(resolver) { 1.485 + if (typeof resolver !== 'function') { 1.486 + throw new TypeError('resolver is not a function'); 1.487 + } 1.488 + var promise = this; 1.489 + if (typeof promise !== 'object') { 1.490 + throw new TypeError('Promise to initialize is not an object'); 1.491 + } 1.492 + promise.promiseStatus = 'unresolved'; 1.493 + promise.resolveReactions = []; 1.494 + promise.rejectReactions = []; 1.495 + promise.result = undefined; 1.496 + var resolve = createResolvePromiseFunction(promise); 1.497 + var reject = createRejectPromiseFunction(promise); 1.498 + try { 1.499 + var result = resolver(resolve, reject); 1.500 + } catch (e) { 1.501 + rejectPromise(promise, e); 1.502 + } 1.503 + promise.promiseConstructor = Promise; 1.504 + return promise; 1.505 + } 1.506 + Promise.all = function (iterable) { 1.507 + var deferred = getDeferred(this); 1.508 + var values = []; 1.509 + var countdownHolder = { 1.510 + countdown: 0 1.511 + }; 1.512 + var index = 0; 1.513 + iterable.forEach(function (nextValue) { 1.514 + var nextPromise = this.cast(nextValue); 1.515 + var fn = createPromiseAllCountdownFunction(index, values, deferred, countdownHolder); 1.516 + nextPromise.then(fn, deferred.reject); 1.517 + index++; 1.518 + countdownHolder.countdown++; 1.519 + }, this); 1.520 + if (index === 0) { 1.521 + deferred.resolve(values); 1.522 + } 1.523 + return deferred.promise; 1.524 + }; 1.525 + Promise.cast = function (x) { 1.526 + if (isPromise(x)) { 1.527 + return x; 1.528 + } 1.529 + var deferred = getDeferred(this); 1.530 + deferred.resolve(x); 1.531 + return deferred.promise; 1.532 + }; 1.533 + Promise.reject = function (r) { 1.534 + var deferred = getDeferred(this); 1.535 + var rejectResult = deferred.reject(r); 1.536 + return deferred.promise; 1.537 + }; 1.538 + Promise.resolve = function (x) { 1.539 + var deferred = getDeferred(this); 1.540 + var rejectResult = deferred.resolve(x); 1.541 + return deferred.promise; 1.542 + }; 1.543 + Promise.prototype = { 1.544 + 'catch': function (onRejected) { 1.545 + this.then(undefined, onRejected); 1.546 + }, 1.547 + then: function (onFulfilled, onRejected) { 1.548 + var promise = this; 1.549 + if (!isPromise(promise)) { 1.550 + throw new TypeError('this is not a Promises'); 1.551 + } 1.552 + var cstr = promise.promiseConstructor; 1.553 + var deferred = getDeferred(cstr); 1.554 + var rejectionHandler = typeof onRejected === 'function' ? onRejected : throwerFunction; 1.555 + var fulfillmentHandler = typeof onFulfilled === 'function' ? onFulfilled : identityFunction; 1.556 + var resolutionHandler = createPromiseResolutionHandlerFunctions(promise, fulfillmentHandler, rejectionHandler); 1.557 + var resolveReaction = { 1.558 + deferred: deferred, 1.559 + handler: resolutionHandler 1.560 + }; 1.561 + var rejectReaction = { 1.562 + deferred: deferred, 1.563 + handler: rejectionHandler 1.564 + }; 1.565 + switch (promise.promiseStatus) { 1.566 + case 'unresolved': 1.567 + promise.resolveReactions.push(resolveReaction); 1.568 + promise.rejectReactions.push(rejectReaction); 1.569 + break; 1.570 + case 'has-resolution': 1.571 + var resolution = promise.result; 1.572 + queueMicrotask({ 1.573 + reaction: resolveReaction, 1.574 + argument: resolution 1.575 + }); 1.576 + break; 1.577 + case 'has-rejection': 1.578 + var rejection = promise.result; 1.579 + queueMicrotask({ 1.580 + reaction: rejectReaction, 1.581 + argument: rejection 1.582 + }); 1.583 + break; 1.584 + } 1.585 + return deferred.promise; 1.586 + } 1.587 + }; 1.588 + global.Promise = Promise; 1.589 +}()); 1.590 +var QuadTree = function (x, y, width, height, parent) { 1.591 + this.x = x | 0; 1.592 + this.y = y | 0; 1.593 + this.width = width | 0; 1.594 + this.height = height | 0; 1.595 + if (parent) { 1.596 + this.root = parent.root; 1.597 + this.parent = parent; 1.598 + this.level = parent.level + 1; 1.599 + } else { 1.600 + this.root = this; 1.601 + this.parent = null; 1.602 + this.level = 0; 1.603 + } 1.604 + this.reset(); 1.605 +}; 1.606 +QuadTree.prototype.reset = function () { 1.607 + this.stuckObjects = null; 1.608 + this.objects = null; 1.609 + this.nodes = []; 1.610 +}; 1.611 +QuadTree.prototype._findIndex = function (xMin, xMax, yMin, yMax) { 1.612 + var midX = this.x + (this.width / 2 | 0); 1.613 + var midY = this.y + (this.height / 2 | 0); 1.614 + var top = yMin < midY && yMax < midY; 1.615 + var bottom = yMin > midY; 1.616 + if (xMin < midX && xMax < midX) { 1.617 + if (top) { 1.618 + return 1; 1.619 + } else if (bottom) { 1.620 + return 2; 1.621 + } 1.622 + } else if (xMin > midX) { 1.623 + if (top) { 1.624 + return 0; 1.625 + } else if (bottom) { 1.626 + return 3; 1.627 + } 1.628 + } 1.629 + return -1; 1.630 +}; 1.631 +QuadTree.prototype.insert = function (obj) { 1.632 + var nodes = this.nodes; 1.633 + if (nodes.length) { 1.634 + var index = this._findIndex(obj.xMin, obj.xMax, obj.yMin, obj.yMax); 1.635 + if (index > -1) { 1.636 + nodes[index].insert(obj); 1.637 + } else { 1.638 + obj.prev = null; 1.639 + if (this.stuckObjects) { 1.640 + obj.next = this.stuckObjects; 1.641 + this.stuckObjects.prev = obj; 1.642 + } else { 1.643 + obj.next = null; 1.644 + } 1.645 + this.stuckObjects = obj; 1.646 + obj.parent = this; 1.647 + } 1.648 + return; 1.649 + } 1.650 + var numChildren = 1; 1.651 + var item = this.objects; 1.652 + if (!item) { 1.653 + obj.prev = null; 1.654 + obj.next = null; 1.655 + this.objects = obj; 1.656 + } else { 1.657 + while (item.next) { 1.658 + numChildren++; 1.659 + item = item.next; 1.660 + } 1.661 + obj.prev = item; 1.662 + obj.next = null; 1.663 + item.next = obj; 1.664 + } 1.665 + if (numChildren > 4 && this.level < 10) { 1.666 + this._subdivide(); 1.667 + item = this.objects; 1.668 + while (item) { 1.669 + var next = item.next; 1.670 + this.insert(item); 1.671 + item = next; 1.672 + } 1.673 + this.objects = null; 1.674 + return; 1.675 + } 1.676 + obj.parent = this; 1.677 +}; 1.678 +QuadTree.prototype.update = function (obj) { 1.679 + var node = obj.parent; 1.680 + if (node) { 1.681 + if (obj.xMin >= node.x && obj.xMax <= node.x + node.width && obj.yMin >= node.y && obj.yMax <= node.y + node.height) { 1.682 + if (node.nodes.length) { 1.683 + var index = this._findIndex(obj.xMin, obj.xMax, obj.yMin, obj.yMax); 1.684 + if (index > -1) { 1.685 + node.remove(obj); 1.686 + node = this.nodes[index]; 1.687 + node.insert(obj); 1.688 + } 1.689 + } else { 1.690 + node.remove(obj); 1.691 + node.insert(obj); 1.692 + } 1.693 + return; 1.694 + } 1.695 + node.remove(obj); 1.696 + } 1.697 + this.root.insert(obj); 1.698 +}; 1.699 +QuadTree.prototype.remove = function (obj) { 1.700 + var prev = obj.prev; 1.701 + var next = obj.next; 1.702 + if (prev) { 1.703 + prev.next = next; 1.704 + obj.prev = null; 1.705 + } else { 1.706 + var node = obj.parent; 1.707 + if (node.objects === obj) { 1.708 + node.objects = next; 1.709 + } else if (node.stuckObjects === obj) { 1.710 + node.stuckObjects = next; 1.711 + } 1.712 + } 1.713 + if (next) { 1.714 + next.prev = prev; 1.715 + obj.next = null; 1.716 + } 1.717 + obj.parent = null; 1.718 +}; 1.719 +QuadTree.prototype.retrieve = function (xMin, xMax, yMin, yMax) { 1.720 + var stack = []; 1.721 + var out = []; 1.722 + var node = this; 1.723 + do { 1.724 + if (node.nodes.length) { 1.725 + var index = node._findIndex(xMin, xMax, yMin, yMax); 1.726 + if (index > -1) { 1.727 + stack.push(node.nodes[index]); 1.728 + } else { 1.729 + stack.push.apply(stack, node.nodes); 1.730 + } 1.731 + } 1.732 + var item = node.objects; 1.733 + for (var i = 0; i < 2; i++) { 1.734 + while (item) { 1.735 + if (!(item.xMin > xMax || item.xMax < xMin || item.yMin > yMax || item.yMax < yMin)) { 1.736 + out.push(item); 1.737 + } 1.738 + item = item.next; 1.739 + } 1.740 + item = node.stuckObjects; 1.741 + } 1.742 + node = stack.pop(); 1.743 + } while (node); 1.744 + return out; 1.745 +}; 1.746 +QuadTree.prototype._subdivide = function () { 1.747 + var halfWidth = this.width / 2 | 0; 1.748 + var halfHeight = this.height / 2 | 0; 1.749 + var midX = this.x + halfWidth; 1.750 + var midY = this.y + halfHeight; 1.751 + this.nodes[0] = new QuadTree(midX, this.y, halfWidth, halfHeight, this); 1.752 + this.nodes[1] = new QuadTree(this.x, this.y, halfWidth, halfHeight, this); 1.753 + this.nodes[2] = new QuadTree(this.x, midY, halfWidth, halfHeight, this); 1.754 + this.nodes[3] = new QuadTree(midX, midY, halfWidth, halfHeight, this); 1.755 +}; 1.756 +var RegionCluster = function () { 1.757 + this.regions = []; 1.758 +}; 1.759 +RegionCluster.prototype.reset = function () { 1.760 + this.regions.length = 0; 1.761 +}; 1.762 +RegionCluster.prototype.insert = function (region) { 1.763 + var regions = this.regions; 1.764 + if (regions.length < 3) { 1.765 + regions.push({ 1.766 + xMin: region.xMin, 1.767 + xMax: region.xMax, 1.768 + yMin: region.yMin, 1.769 + yMax: region.yMax 1.770 + }); 1.771 + return; 1.772 + } 1.773 + var a = region; 1.774 + var b = regions[0]; 1.775 + var c = regions[1]; 1.776 + var d = regions[2]; 1.777 + var ab = (max(a.xMax, b.xMax) - min(a.xMin, b.xMin)) * (max(a.yMax, b.yMax) - min(a.yMin, b.yMin)); 1.778 + var rb = regions[0]; 1.779 + var ac = (max(a.xMax, c.xMax) - min(a.xMin, c.xMin)) * (max(a.yMax, c.yMax) - min(a.yMin, c.yMin)); 1.780 + var ad = (max(a.xMax, d.xMax) - min(a.xMin, d.xMin)) * (max(a.yMax, d.yMax) - min(a.yMin, d.yMin)); 1.781 + if (ac < ab) { 1.782 + ab = ac; 1.783 + rb = c; 1.784 + } 1.785 + if (ad < ab) { 1.786 + ab = ad; 1.787 + rb = d; 1.788 + } 1.789 + var bc = (max(b.xMax, c.xMax) - min(b.xMin, c.xMin)) * (max(b.yMax, c.yMax) - min(b.yMin, c.yMin)); 1.790 + var bd = (max(b.xMax, d.xMax) - min(b.xMin, d.xMin)) * (max(b.yMax, d.yMax) - min(b.yMin, d.yMin)); 1.791 + var cd = (max(c.xMax, d.xMax) - min(c.xMin, d.xMin)) * (max(c.yMax, d.yMax) - min(c.yMin, d.yMin)); 1.792 + if (ab < bc && ab < bd && ab < cd) { 1.793 + if (a.xMin < rb.xMin) { 1.794 + rb.xMin = a.xMin; 1.795 + } 1.796 + if (a.xMax > rb.xMax) { 1.797 + rb.xMax = a.xMax; 1.798 + } 1.799 + if (a.yMin < rb.yMin) { 1.800 + rb.yMin = a.yMin; 1.801 + } 1.802 + if (a.yMax > rb.yMax) { 1.803 + rb.yMax = a.yMax; 1.804 + } 1.805 + return; 1.806 + } 1.807 + rb = regions[0]; 1.808 + var rc = regions[1]; 1.809 + if (bd < bc) { 1.810 + bc = bd; 1.811 + rc = regions[2]; 1.812 + } 1.813 + if (cd < bc) { 1.814 + rb = regions[1]; 1.815 + rc = regions[2]; 1.816 + } 1.817 + if (rc.xMin < rb.xMin) { 1.818 + rb.xMin = rc.xMin; 1.819 + } 1.820 + if (rc.xMax > rb.xMax) { 1.821 + rb.xMax = rc.xMax; 1.822 + } 1.823 + if (rc.yMin < rb.yMin) { 1.824 + rb.yMin = rc.yMin; 1.825 + } 1.826 + if (rc.yMax > rb.yMax) { 1.827 + rb.yMax = rc.yMax; 1.828 + } 1.829 + rc.xMin = a.xMin; 1.830 + rc.xMax = a.xMax; 1.831 + rc.yMin = a.yMin; 1.832 + rc.yMax = a.yMax; 1.833 +}; 1.834 +RegionCluster.prototype.retrieve = function () { 1.835 + return this.regions; 1.836 +}; 1.837 +var EXTERNAL_INTERFACE_FEATURE = 1; 1.838 +var CLIPBOARD_FEATURE = 2; 1.839 +var SHAREDOBJECT_FEATURE = 3; 1.840 +var VIDEO_FEATURE = 4; 1.841 +var SOUND_FEATURE = 5; 1.842 +var NETCONNECTION_FEATURE = 6; 1.843 +if (!this.performance) { 1.844 + this.performance = {}; 1.845 +} 1.846 +if (!this.performance.now) { 1.847 + this.performance.now = Date.now; 1.848 +} 1.849 +var SWF_TAG_CODE_CSM_TEXT_SETTINGS = 74; 1.850 +var SWF_TAG_CODE_DEFINE_BINARY_DATA = 87; 1.851 +var SWF_TAG_CODE_DEFINE_BITS = 6; 1.852 +var SWF_TAG_CODE_DEFINE_BITS_JPEG2 = 21; 1.853 +var SWF_TAG_CODE_DEFINE_BITS_JPEG3 = 35; 1.854 +var SWF_TAG_CODE_DEFINE_BITS_JPEG4 = 90; 1.855 +var SWF_TAG_CODE_DEFINE_BITS_LOSSLESS = 20; 1.856 +var SWF_TAG_CODE_DEFINE_BITS_LOSSLESS2 = 36; 1.857 +var SWF_TAG_CODE_DEFINE_BUTTON = 7; 1.858 +var SWF_TAG_CODE_DEFINE_BUTTON2 = 34; 1.859 +var SWF_TAG_CODE_DEFINE_BUTTON_CXFORM = 23; 1.860 +var SWF_TAG_CODE_DEFINE_BUTTON_SOUND = 17; 1.861 +var SWF_TAG_CODE_DEFINE_EDIT_TEXT = 37; 1.862 +var SWF_TAG_CODE_DEFINE_FONT = 10; 1.863 +var SWF_TAG_CODE_DEFINE_FONT2 = 48; 1.864 +var SWF_TAG_CODE_DEFINE_FONT3 = 75; 1.865 +var SWF_TAG_CODE_DEFINE_FONT4 = 91; 1.866 +var SWF_TAG_CODE_DEFINE_FONT_ALIGN_ZONES = 73; 1.867 +var SWF_TAG_CODE_DEFINE_FONT_INFO = 13; 1.868 +var SWF_TAG_CODE_DEFINE_FONT_INFO2 = 62; 1.869 +var SWF_TAG_CODE_DEFINE_FONT_NAME = 88; 1.870 +var SWF_TAG_CODE_DEFINE_MORPH_SHAPE = 46; 1.871 +var SWF_TAG_CODE_DEFINE_MORPH_SHAPE2 = 84; 1.872 +var SWF_TAG_CODE_DEFINE_SCALING_GRID = 78; 1.873 +var SWF_TAG_CODE_DEFINE_SCENE_AND_FRAME_LABEL_DATA = 86; 1.874 +var SWF_TAG_CODE_DEFINE_SHAPE = 2; 1.875 +var SWF_TAG_CODE_DEFINE_SHAPE2 = 22; 1.876 +var SWF_TAG_CODE_DEFINE_SHAPE3 = 32; 1.877 +var SWF_TAG_CODE_DEFINE_SHAPE4 = 83; 1.878 +var SWF_TAG_CODE_DEFINE_SOUND = 14; 1.879 +var SWF_TAG_CODE_DEFINE_SPRITE = 39; 1.880 +var SWF_TAG_CODE_DEFINE_TEXT = 11; 1.881 +var SWF_TAG_CODE_DEFINE_TEXT2 = 33; 1.882 +var SWF_TAG_CODE_DEFINE_VIDEO_STREAM = 60; 1.883 +var SWF_TAG_CODE_DO_ABC = 82; 1.884 +var SWF_TAG_CODE_DO_ABC_ = 72; 1.885 +var SWF_TAG_CODE_DO_ACTION = 12; 1.886 +var SWF_TAG_CODE_DO_INIT_ACTION = 59; 1.887 +var SWF_TAG_CODE_ENABLE_DEBUGGER = 58; 1.888 +var SWF_TAG_CODE_ENABLE_DEBUGGER2 = 64; 1.889 +var SWF_TAG_CODE_END = 0; 1.890 +var SWF_TAG_CODE_EXPORT_ASSETS = 56; 1.891 +var SWF_TAG_CODE_FILE_ATTRIBUTES = 69; 1.892 +var SWF_TAG_CODE_FRAME_LABEL = 43; 1.893 +var SWF_TAG_CODE_IMPORT_ASSETS = 57; 1.894 +var SWF_TAG_CODE_IMPORT_ASSETS2 = 71; 1.895 +var SWF_TAG_CODE_JPEG_TABLES = 8; 1.896 +var SWF_TAG_CODE_METADATA = 77; 1.897 +var SWF_TAG_CODE_PLACE_OBJECT = 4; 1.898 +var SWF_TAG_CODE_PLACE_OBJECT2 = 26; 1.899 +var SWF_TAG_CODE_PLACE_OBJECT3 = 70; 1.900 +var SWF_TAG_CODE_PROTECT = 24; 1.901 +var SWF_TAG_CODE_REMOVE_OBJECT = 5; 1.902 +var SWF_TAG_CODE_REMOVE_OBJECT2 = 28; 1.903 +var SWF_TAG_CODE_SCRIPT_LIMITS = 65; 1.904 +var SWF_TAG_CODE_SET_BACKGROUND_COLOR = 9; 1.905 +var SWF_TAG_CODE_SET_TAB_INDEX = 66; 1.906 +var SWF_TAG_CODE_SHOW_FRAME = 1; 1.907 +var SWF_TAG_CODE_SOUND_STREAM_BLOCK = 19; 1.908 +var SWF_TAG_CODE_SOUND_STREAM_HEAD = 18; 1.909 +var SWF_TAG_CODE_SOUND_STREAM_HEAD2 = 45; 1.910 +var SWF_TAG_CODE_START_SOUND = 15; 1.911 +var SWF_TAG_CODE_START_SOUND2 = 89; 1.912 +var SWF_TAG_CODE_SYMBOL_CLASS = 76; 1.913 +var SWF_TAG_CODE_VIDEO_FRAME = 61; 1.914 +self.SWF = {}; 1.915 +var FORMAT_COLORMAPPED = 3; 1.916 +var FORMAT_15BPP = 4; 1.917 +var FORMAT_24BPP = 5; 1.918 +var FACTOR_5BBP = 255 / 31; 1.919 +var crcTable = []; 1.920 +for (var i = 0; i < 256; i++) { 1.921 + var c = i; 1.922 + for (var h = 0; h < 8; h++) { 1.923 + if (c & 1) 1.924 + c = 3988292384 ^ c >> 1 & 2147483647; 1.925 + else 1.926 + c = c >> 1 & 2147483647; 1.927 + } 1.928 + crcTable[i] = c; 1.929 +} 1.930 +function crc32(data, start, end) { 1.931 + var crc = -1; 1.932 + for (var i = start; i < end; i++) { 1.933 + var a = (crc ^ data[i]) & 255; 1.934 + var b = crcTable[a]; 1.935 + crc = crc >>> 8 ^ b; 1.936 + } 1.937 + return crc ^ -1; 1.938 +} 1.939 +function createPngChunk(type, data) { 1.940 + var chunk = new Uint8Array(12 + data.length); 1.941 + var p = 0; 1.942 + var len = data.length; 1.943 + chunk[p] = len >> 24 & 255; 1.944 + chunk[p + 1] = len >> 16 & 255; 1.945 + chunk[p + 2] = len >> 8 & 255; 1.946 + chunk[p + 3] = len & 255; 1.947 + chunk[p + 4] = type.charCodeAt(0) & 255; 1.948 + chunk[p + 5] = type.charCodeAt(1) & 255; 1.949 + chunk[p + 6] = type.charCodeAt(2) & 255; 1.950 + chunk[p + 7] = type.charCodeAt(3) & 255; 1.951 + if (data instanceof Uint8Array) 1.952 + chunk.set(data, 8); 1.953 + p = 8 + len; 1.954 + var crc = crc32(chunk, 4, p); 1.955 + chunk[p] = crc >> 24 & 255; 1.956 + chunk[p + 1] = crc >> 16 & 255; 1.957 + chunk[p + 2] = crc >> 8 & 255; 1.958 + chunk[p + 3] = crc & 255; 1.959 + return chunk; 1.960 +} 1.961 +function adler32(data, start, end) { 1.962 + var a = 1; 1.963 + var b = 0; 1.964 + for (var i = start; i < end; ++i) { 1.965 + a = (a + (data[i] & 255)) % 65521; 1.966 + b = (b + a) % 65521; 1.967 + } 1.968 + return b << 16 | a; 1.969 +} 1.970 +function defineBitmap(tag) { 1.971 + var width = tag.width; 1.972 + var height = tag.height; 1.973 + var hasAlpha = tag.hasAlpha; 1.974 + var plte = ''; 1.975 + var trns = ''; 1.976 + var literals; 1.977 + var bmpData = tag.bmpData; 1.978 + switch (tag.format) { 1.979 + case FORMAT_COLORMAPPED: 1.980 + var colorType = 3; 1.981 + var bytesPerLine = width + 3 & ~3; 1.982 + var colorTableSize = tag.colorTableSize + 1; 1.983 + var paletteSize = colorTableSize * (tag.hasAlpha ? 4 : 3); 1.984 + var datalen = paletteSize + bytesPerLine * height; 1.985 + var stream = createInflatedStream(bmpData, datalen); 1.986 + var bytes = stream.bytes; 1.987 + var pos = 0; 1.988 + stream.ensure(paletteSize); 1.989 + if (hasAlpha) { 1.990 + var palette = new Uint8Array(paletteSize / 4 * 3); 1.991 + var pp = 0; 1.992 + var alphaValues = new Uint8Array(paletteSize / 4); 1.993 + var pa = 0; 1.994 + while (pos < paletteSize) { 1.995 + palette[pp++] = bytes[pos]; 1.996 + palette[pp++] = bytes[pos + 1]; 1.997 + palette[pp++] = bytes[pos + 2]; 1.998 + alphaValues[pa++] = bytes[pos + 3]; 1.999 + pos += 4; 1.1000 + } 1.1001 + plte = createPngChunk('PLTE', palette); 1.1002 + trns = createPngChunk('tRNS', alphaValues); 1.1003 + } else { 1.1004 + plte = createPngChunk('PLTE', bytes.subarray(pos, pos + paletteSize)); 1.1005 + pos += paletteSize; 1.1006 + } 1.1007 + literals = new Uint8Array(width * height + height); 1.1008 + var pl = 0; 1.1009 + while (pos < datalen) { 1.1010 + stream.ensure(bytesPerLine); 1.1011 + var begin = pos; 1.1012 + var end = begin + width; 1.1013 + pl++; 1.1014 + literals.set(bytes.subarray(begin, end), pl); 1.1015 + pl += end - begin; 1.1016 + stream.pos = pos += bytesPerLine; 1.1017 + } 1.1018 + break; 1.1019 + case FORMAT_15BPP: 1.1020 + var colorType = 2; 1.1021 + var bytesPerLine = width * 2 + 3 & ~3; 1.1022 + var stream = createInflatedStream(bmpData, bytesPerLine * height); 1.1023 + var pos = 0; 1.1024 + literals = new Uint8Array(width * height * 3 + height); 1.1025 + var pl = 0; 1.1026 + for (var y = 0; y < height; ++y) { 1.1027 + pl++; 1.1028 + stream.ensure(bytesPerLine); 1.1029 + for (var x = 0; x < width; ++x) { 1.1030 + var word = stream.getUint16(pos); 1.1031 + pos += 2; 1.1032 + literals[pl++] = 0 | FACTOR_5BBP * (word >> 10 & 31); 1.1033 + literals[pl++] = 0 | FACTOR_5BBP * (word >> 5 & 31); 1.1034 + literals[pl++] = 0 | FACTOR_5BBP * (word & 31); 1.1035 + } 1.1036 + stream.pos = pos += bytesPerLine; 1.1037 + } 1.1038 + break; 1.1039 + case FORMAT_24BPP: 1.1040 + var padding; 1.1041 + if (hasAlpha) { 1.1042 + var colorType = 6; 1.1043 + padding = 0; 1.1044 + literals = new Uint8Array(width * height * 4 + height); 1.1045 + } else { 1.1046 + var colorType = 2; 1.1047 + padding = 1; 1.1048 + literals = new Uint8Array(width * height * 3 + height); 1.1049 + } 1.1050 + var bytesPerLine = width * 4; 1.1051 + var stream = createInflatedStream(bmpData, bytesPerLine * height); 1.1052 + var bytes = stream.bytes; 1.1053 + var pos = 0; 1.1054 + var pl = 0; 1.1055 + for (var y = 0; y < height; ++y) { 1.1056 + stream.ensure(bytesPerLine); 1.1057 + pl++; 1.1058 + for (var x = 0; x < width; ++x) { 1.1059 + pos += padding; 1.1060 + if (hasAlpha) { 1.1061 + var alpha = bytes[pos]; 1.1062 + if (alpha) { 1.1063 + var opacity = alpha / 255; 1.1064 + literals[pl++] = 0 | bytes[pos + 1] / opacity; 1.1065 + literals[pl++] = 0 | bytes[pos + 2] / opacity; 1.1066 + literals[pl++] = 0 | bytes[pos + 3] / opacity; 1.1067 + literals[pl++] = alpha; 1.1068 + } else { 1.1069 + pl += 4; 1.1070 + } 1.1071 + } else { 1.1072 + literals[pl++] = bytes[pos]; 1.1073 + literals[pl++] = bytes[pos + 1]; 1.1074 + literals[pl++] = bytes[pos + 2]; 1.1075 + } 1.1076 + pos += 4 - padding; 1.1077 + } 1.1078 + stream.pos = pos; 1.1079 + } 1.1080 + break; 1.1081 + default: 1.1082 + fail('invalid format', 'bitmap'); 1.1083 + } 1.1084 + var ihdr = new Uint8Array([ 1.1085 + width >> 24 & 255, 1.1086 + width >> 16 & 255, 1.1087 + width >> 8 & 255, 1.1088 + width & 255, 1.1089 + height >> 24 & 255, 1.1090 + height >> 16 & 255, 1.1091 + height >> 8 & 255, 1.1092 + height & 255, 1.1093 + 8, 1.1094 + colorType, 1.1095 + 0, 1.1096 + 0, 1.1097 + 0 1.1098 + ]); 1.1099 + var len = literals.length; 1.1100 + var maxBlockLength = 65535; 1.1101 + var idat = new Uint8Array(2 + len + Math.ceil(len / maxBlockLength) * 5 + 4); 1.1102 + var pi = 0; 1.1103 + idat[pi++] = 120; 1.1104 + idat[pi++] = 156; 1.1105 + var pos = 0; 1.1106 + while (len > maxBlockLength) { 1.1107 + idat[pi++] = 0; 1.1108 + idat[pi++] = 255; 1.1109 + idat[pi++] = 255; 1.1110 + idat[pi++] = 0; 1.1111 + idat[pi++] = 0; 1.1112 + idat.set(literals.subarray(pos, pos + maxBlockLength), pi); 1.1113 + pi += maxBlockLength; 1.1114 + pos += maxBlockLength; 1.1115 + len -= maxBlockLength; 1.1116 + } 1.1117 + idat[pi++] = 1; 1.1118 + idat[pi++] = len & 255; 1.1119 + idat[pi++] = len >> 8 & 255; 1.1120 + idat[pi++] = ~len & 65535 & 255; 1.1121 + idat[pi++] = (~len & 65535) >> 8 & 255; 1.1122 + idat.set(literals.subarray(pos), pi); 1.1123 + pi += literals.length - pos; 1.1124 + var adler = adler32(literals, 0, literals.length); 1.1125 + idat[pi++] = adler >> 24 & 255; 1.1126 + idat[pi++] = adler >> 16 & 255; 1.1127 + idat[pi++] = adler >> 8 & 255; 1.1128 + idat[pi++] = adler & 255; 1.1129 + var chunks = [ 1.1130 + new Uint8Array([ 1.1131 + 137, 1.1132 + 80, 1.1133 + 78, 1.1134 + 71, 1.1135 + 13, 1.1136 + 10, 1.1137 + 26, 1.1138 + 10 1.1139 + ]), 1.1140 + createPngChunk('IHDR', ihdr), 1.1141 + plte, 1.1142 + trns, 1.1143 + createPngChunk('IDAT', idat), 1.1144 + createPngChunk('IEND', '') 1.1145 + ]; 1.1146 + return { 1.1147 + type: 'image', 1.1148 + id: tag.id, 1.1149 + width: width, 1.1150 + height: height, 1.1151 + mimeType: 'image/png', 1.1152 + data: new Blob(chunks, { 1.1153 + type: 'image/png' 1.1154 + }) 1.1155 + }; 1.1156 +} 1.1157 +function defineButton(tag, dictionary) { 1.1158 + var characters = tag.characters; 1.1159 + var states = { 1.1160 + up: {}, 1.1161 + over: {}, 1.1162 + down: {}, 1.1163 + hitTest: {} 1.1164 + }; 1.1165 + var i = 0, character; 1.1166 + while (character = characters[i++]) { 1.1167 + if (character.eob) 1.1168 + break; 1.1169 + var characterItem = dictionary[character.symbolId]; 1.1170 + var entry = { 1.1171 + symbolId: characterItem.id, 1.1172 + hasMatrix: !(!character.matrix), 1.1173 + matrix: character.matrix 1.1174 + }; 1.1175 + if (character.stateUp) 1.1176 + states.up[character.depth] = entry; 1.1177 + if (character.stateOver) 1.1178 + states.over[character.depth] = entry; 1.1179 + if (character.stateDown) 1.1180 + states.down[character.depth] = entry; 1.1181 + if (character.stateHitTest) 1.1182 + states.hitTest[character.depth] = entry; 1.1183 + } 1.1184 + var button = { 1.1185 + type: 'button', 1.1186 + id: tag.id, 1.1187 + buttonActions: tag.buttonActions, 1.1188 + states: states 1.1189 + }; 1.1190 + return button; 1.1191 +} 1.1192 +var nextFontId = 1; 1.1193 +function maxPower2(num) { 1.1194 + var maxPower = 0; 1.1195 + var val = num; 1.1196 + while (val >= 2) { 1.1197 + val /= 2; 1.1198 + ++maxPower; 1.1199 + } 1.1200 + return pow(2, maxPower); 1.1201 +} 1.1202 +function toString16(val) { 1.1203 + return fromCharCode(val >> 8 & 255, val & 255); 1.1204 +} 1.1205 +function toString32(val) { 1.1206 + return toString16(val >> 16) + toString16(val); 1.1207 +} 1.1208 +function defineFont(tag, dictionary) { 1.1209 + var tables = {}; 1.1210 + var codes = []; 1.1211 + var glyphIndex = {}; 1.1212 + var ranges = []; 1.1213 + var glyphs = tag.glyphs; 1.1214 + var glyphCount = glyphs.length; 1.1215 + if (tag.codes) { 1.1216 + codes = codes.concat(tag.codes); 1.1217 + for (var i = 0, code; code = codes[i]; ++i) 1.1218 + glyphIndex[code] = i; 1.1219 + codes.sort(function (a, b) { 1.1220 + return a - b; 1.1221 + }); 1.1222 + var i = 0; 1.1223 + var code; 1.1224 + while (code = codes[i++]) { 1.1225 + var start = code; 1.1226 + var end = start; 1.1227 + var indices = [ 1.1228 + i - 1 1.1229 + ]; 1.1230 + while ((code = codes[i]) && end + 1 === code) { 1.1231 + ++end; 1.1232 + indices.push(i); 1.1233 + ++i; 1.1234 + } 1.1235 + ranges.push([ 1.1236 + start, 1.1237 + end, 1.1238 + indices 1.1239 + ]); 1.1240 + } 1.1241 + } else { 1.1242 + var indices = []; 1.1243 + var UAC_OFFSET = 57344; 1.1244 + for (var i = 0; i < glyphCount; i++) { 1.1245 + var code = UAC_OFFSET + i; 1.1246 + codes.push(code); 1.1247 + glyphIndex[code] = i; 1.1248 + indices.push(i); 1.1249 + } 1.1250 + ranges.push([ 1.1251 + UAC_OFFSET, 1.1252 + UAC_OFFSET + glyphCount - 1, 1.1253 + indices 1.1254 + ]); 1.1255 + } 1.1256 + var resolution = tag.resolution || 1; 1.1257 + var ascent = Math.ceil(tag.ascent / resolution) || 1024; 1.1258 + var descent = -Math.ceil(tag.descent / resolution) | 0; 1.1259 + var leading = tag.leading / resolution | 0; 1.1260 + tables['OS/2'] = '\0\x01\0\0' + toString16(tag.bold ? 700 : 400) + '\0\x05' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0\0\0\0\0\0\0\0\0' + '\0\0\0\0' + '\0\0\0\0' + '\0\0\0\0' + '\0\0\0\0' + 'ALF ' + toString16((tag.italic ? 1 : 0) | (tag.bold ? 32 : 0)) + toString16(codes[0]) + toString16(codes[codes.length - 1]) + toString16(ascent) + toString16(descent) + toString16(leading) + toString16(ascent) + toString16(-descent) + '\0\0\0\0' + '\0\0\0\0'; 1.1261 + ; 1.1262 + var startCount = ''; 1.1263 + var endCount = ''; 1.1264 + var idDelta = ''; 1.1265 + var idRangeOffset = ''; 1.1266 + var i = 0; 1.1267 + var range; 1.1268 + while (range = ranges[i++]) { 1.1269 + var start = range[0]; 1.1270 + var end = range[1]; 1.1271 + var code = range[2][0]; 1.1272 + startCount += toString16(start); 1.1273 + endCount += toString16(end); 1.1274 + idDelta += toString16(code - start + 1 & 65535); 1.1275 + idRangeOffset += toString16(0); 1.1276 + } 1.1277 + endCount += '\xff\xff'; 1.1278 + startCount += '\xff\xff'; 1.1279 + idDelta += '\0\x01'; 1.1280 + idRangeOffset += '\0\0'; 1.1281 + var segCount = ranges.length + 1; 1.1282 + var searchRange = maxPower2(segCount) * 2; 1.1283 + var rangeShift = 2 * segCount - searchRange; 1.1284 + var format314 = '\0\0' + toString16(segCount * 2) + toString16(searchRange) + toString16(logE(segCount) / logE(2)) + toString16(rangeShift) + endCount + '\0\0' + startCount + idDelta + idRangeOffset; 1.1285 + ; 1.1286 + tables['cmap'] = '\0\0\0\x01\0\x03\0\x01\0\0\0\f\0\x04' + toString16(format314.length + 4) + format314; 1.1287 + ; 1.1288 + var glyf = '\0\x01\0\0\0\0\0\0\0\0\0\0\0\x001\0'; 1.1289 + var loca = '\0\0'; 1.1290 + var offset = 16; 1.1291 + var maxPoints = 0; 1.1292 + var xMins = []; 1.1293 + var xMaxs = []; 1.1294 + var yMins = []; 1.1295 + var yMaxs = []; 1.1296 + var maxContours = 0; 1.1297 + var i = 0; 1.1298 + var code; 1.1299 + while (code = codes[i++]) { 1.1300 + var glyph = glyphs[glyphIndex[code]]; 1.1301 + var records = glyph.records; 1.1302 + var numberOfContours = 1; 1.1303 + var endPoint = 0; 1.1304 + var endPtsOfContours = ''; 1.1305 + var flags = ''; 1.1306 + var xCoordinates = ''; 1.1307 + var yCoordinates = ''; 1.1308 + var x = 0; 1.1309 + var y = 0; 1.1310 + var xMin = 1024; 1.1311 + var xMax = -1024; 1.1312 + var yMin = 1024; 1.1313 + var yMax = -1024; 1.1314 + for (var j = 0, record; record = records[j]; ++j) { 1.1315 + if (record.type) { 1.1316 + if (record.isStraight) { 1.1317 + if (record.isGeneral) { 1.1318 + flags += '\x01'; 1.1319 + var dx = record.deltaX / resolution; 1.1320 + var dy = -record.deltaY / resolution; 1.1321 + xCoordinates += toString16(dx); 1.1322 + yCoordinates += toString16(dy); 1.1323 + x += dx; 1.1324 + y += dy; 1.1325 + } else if (record.isVertical) { 1.1326 + flags += '\x11'; 1.1327 + var dy = -record.deltaY / resolution; 1.1328 + yCoordinates += toString16(dy); 1.1329 + y += dy; 1.1330 + } else { 1.1331 + flags += '!'; 1.1332 + var dx = record.deltaX / resolution; 1.1333 + xCoordinates += toString16(dx); 1.1334 + x += dx; 1.1335 + } 1.1336 + } else { 1.1337 + flags += '\0'; 1.1338 + var cx = record.controlDeltaX / resolution; 1.1339 + var cy = -record.controlDeltaY / resolution; 1.1340 + xCoordinates += toString16(cx); 1.1341 + yCoordinates += toString16(cy); 1.1342 + flags += '\x01'; 1.1343 + var dx = record.anchorDeltaX / resolution; 1.1344 + var dy = -record.anchorDeltaY / resolution; 1.1345 + xCoordinates += toString16(dx); 1.1346 + yCoordinates += toString16(dy); 1.1347 + ++endPoint; 1.1348 + x += cx + dx; 1.1349 + y += cy + dy; 1.1350 + } 1.1351 + if (x < xMin) 1.1352 + xMin = x; 1.1353 + if (x > xMax) 1.1354 + xMax = x; 1.1355 + if (y < yMin) 1.1356 + yMin = y; 1.1357 + if (y > yMax) 1.1358 + yMax = y; 1.1359 + ++endPoint; 1.1360 + } else { 1.1361 + if (record.eos) 1.1362 + break; 1.1363 + if (record.move) { 1.1364 + if (endPoint) { 1.1365 + ++numberOfContours; 1.1366 + endPtsOfContours += toString16(endPoint - 1); 1.1367 + } 1.1368 + flags += '\x01'; 1.1369 + var moveX = record.moveX / resolution; 1.1370 + var moveY = -record.moveY / resolution; 1.1371 + var dx = moveX - x; 1.1372 + var dy = moveY - y; 1.1373 + xCoordinates += toString16(dx); 1.1374 + yCoordinates += toString16(dy); 1.1375 + x = moveX; 1.1376 + y = moveY; 1.1377 + if (endPoint > maxPoints) 1.1378 + maxPoints = endPoint; 1.1379 + if (x < xMin) 1.1380 + xMin = x; 1.1381 + if (x > xMax) 1.1382 + xMax = x; 1.1383 + if (y < yMin) 1.1384 + yMin = y; 1.1385 + if (y > yMax) 1.1386 + yMax = y; 1.1387 + ++endPoint; 1.1388 + } 1.1389 + } 1.1390 + } 1.1391 + endPtsOfContours += toString16((endPoint || 1) - 1); 1.1392 + if (!j) { 1.1393 + xMin = xMax = yMin = yMax = 0; 1.1394 + flags += '1'; 1.1395 + } 1.1396 + var entry = toString16(numberOfContours) + toString16(xMin) + toString16(yMin) + toString16(xMax) + toString16(yMax) + endPtsOfContours + '\0\0' + flags + xCoordinates + yCoordinates; 1.1397 + ; 1.1398 + if (entry.length & 1) 1.1399 + entry += '\0'; 1.1400 + glyf += entry; 1.1401 + loca += toString16(offset / 2); 1.1402 + offset += entry.length; 1.1403 + xMins.push(xMin); 1.1404 + xMaxs.push(xMax); 1.1405 + yMins.push(yMin); 1.1406 + yMaxs.push(yMax); 1.1407 + if (numberOfContours > maxContours) 1.1408 + maxContours = numberOfContours; 1.1409 + if (endPoint > maxPoints) 1.1410 + maxPoints = endPoint; 1.1411 + } 1.1412 + loca += toString16(offset / 2); 1.1413 + tables['glyf'] = glyf; 1.1414 + tables['head'] = '\0\x01\0\0\0\x01\0\0\0\0\0\0_\x0f<\xf5\0\v\x04\0\0\0\0\0' + toString32(Date.now()) + '\0\0\0\0' + toString32(Date.now()) + toString16(min.apply(null, xMins)) + toString16(min.apply(null, yMins)) + toString16(max.apply(null, xMaxs)) + toString16(max.apply(null, yMaxs)) + toString16((tag.italic ? 2 : 0) | (tag.bold ? 1 : 0)) + '\0\b' + '\0\x02' + '\0\0' + '\0\0'; 1.1415 + ; 1.1416 + var advance = tag.advance; 1.1417 + tables['hhea'] = '\0\x01\0\0' + toString16(ascent) + toString16(descent) + toString16(leading) + toString16(advance ? max.apply(null, advance) : 1024) + '\0\0' + '\0\0' + '\x03\xb8' + '\0\x01' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + toString16(glyphCount + 1); 1.1418 + ; 1.1419 + var hmtx = '\0\0\0\0'; 1.1420 + for (var i = 0; i < glyphCount; ++i) 1.1421 + hmtx += toString16(advance ? advance[i] / resolution : 1024) + '\0\0'; 1.1422 + tables['hmtx'] = hmtx; 1.1423 + if (tag.kerning) { 1.1424 + var kerning = tag.kerning; 1.1425 + var nPairs = kerning.length; 1.1426 + var searchRange = maxPower2(nPairs) * 2; 1.1427 + var kern = '\0\0\0\x01\0\0' + toString16(14 + nPairs * 6) + '\0\x01' + toString16(nPairs) + toString16(searchRange) + toString16(logE(nPairs) / logE(2)) + toString16(2 * nPairs - searchRange); 1.1428 + ; 1.1429 + var i = 0; 1.1430 + var record; 1.1431 + while (record = kerning[i++]) { 1.1432 + kern += toString16(glyphIndex[record.code1]) + toString16(glyphIndex[record.code2]) + toString16(record.adjustment); 1.1433 + ; 1.1434 + } 1.1435 + tables['kern'] = kern; 1.1436 + } 1.1437 + tables['loca'] = loca; 1.1438 + tables['maxp'] = '\0\x01\0\0' + toString16(glyphCount + 1) + toString16(maxPoints) + toString16(maxContours) + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0' + '\0\0'; 1.1439 + ; 1.1440 + var uniqueId = 'swf-font-' + nextFontId++; 1.1441 + var fontName = tag.name || uniqueId; 1.1442 + var psName = fontName.replace(/ /g, ''); 1.1443 + var strings = [ 1.1444 + tag.copyright || 'Original licence', 1.1445 + fontName, 1.1446 + 'Unknown', 1.1447 + uniqueId, 1.1448 + fontName, 1.1449 + '1.0', 1.1450 + psName, 1.1451 + 'Unknown', 1.1452 + 'Unknown', 1.1453 + 'Unknown' 1.1454 + ]; 1.1455 + var count = strings.length; 1.1456 + var name = '\0\0' + toString16(count) + toString16(count * 12 + 6); 1.1457 + var offset = 0; 1.1458 + var i = 0; 1.1459 + var str; 1.1460 + while (str = strings[i++]) { 1.1461 + name += '\0\x01\0\0\0\0' + toString16(i - 1) + toString16(str.length) + toString16(offset); 1.1462 + offset += str.length; 1.1463 + } 1.1464 + tables['name'] = name + strings.join(''); 1.1465 + tables['post'] = '\0\x03\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'; 1.1466 + ; 1.1467 + var names = keys(tables); 1.1468 + var numTables = names.length; 1.1469 + var header = '\0\x01\0\0' + toString16(numTables) + '\0\x80' + '\0\x03' + '\0 '; 1.1470 + ; 1.1471 + var data = ''; 1.1472 + var offset = numTables * 16 + header.length; 1.1473 + var i = 0; 1.1474 + var name; 1.1475 + while (name = names[i++]) { 1.1476 + var table = tables[name]; 1.1477 + var length = table.length; 1.1478 + header += name + '\0\0\0\0' + toString32(offset) + toString32(length); 1.1479 + ; 1.1480 + while (length & 3) { 1.1481 + table += '\0'; 1.1482 + ++length; 1.1483 + } 1.1484 + data += table; 1.1485 + while (offset & 3) 1.1486 + ++offset; 1.1487 + offset += length; 1.1488 + } 1.1489 + var otf = header + data; 1.1490 + var unitPerEm = 1024; 1.1491 + var metrics = { 1.1492 + ascent: ascent / unitPerEm, 1.1493 + descent: -descent / unitPerEm, 1.1494 + leading: leading / unitPerEm 1.1495 + }; 1.1496 + return { 1.1497 + type: 'font', 1.1498 + id: tag.id, 1.1499 + name: fontName, 1.1500 + uniqueName: psName + uniqueId, 1.1501 + codes: codes, 1.1502 + metrics: metrics, 1.1503 + bold: tag.bold === 1, 1.1504 + italic: tag.italic === 1, 1.1505 + data: otf 1.1506 + }; 1.1507 +} 1.1508 +function getUint16(buff, pos) { 1.1509 + return buff[pos] << 8 | buff[pos + 1]; 1.1510 +} 1.1511 +function parseJpegChunks(imgDef, bytes) { 1.1512 + var i = 0; 1.1513 + var n = bytes.length; 1.1514 + var chunks = []; 1.1515 + var code; 1.1516 + do { 1.1517 + var begin = i; 1.1518 + while (i < n && bytes[i] !== 255) 1.1519 + ++i; 1.1520 + while (i < n && bytes[i] === 255) 1.1521 + ++i; 1.1522 + code = bytes[i++]; 1.1523 + if (code === 218) { 1.1524 + i = n; 1.1525 + } else if (code === 217) { 1.1526 + i += 2; 1.1527 + continue; 1.1528 + } else if (code < 208 || code > 216) { 1.1529 + var length = getUint16(bytes, i); 1.1530 + if (code >= 192 && code <= 195) { 1.1531 + imgDef.height = getUint16(bytes, i + 3); 1.1532 + imgDef.width = getUint16(bytes, i + 5); 1.1533 + } 1.1534 + i += length; 1.1535 + } 1.1536 + chunks.push(bytes.subarray(begin, i)); 1.1537 + } while (i < n); 1.1538 + return chunks; 1.1539 +} 1.1540 +function defineImage(tag, dictionary) { 1.1541 + var img = { 1.1542 + type: 'image', 1.1543 + id: tag.id, 1.1544 + mimeType: tag.mimeType 1.1545 + }; 1.1546 + var imgData = tag.imgData; 1.1547 + var chunks; 1.1548 + if (tag.mimeType === 'image/jpeg') { 1.1549 + chunks = parseJpegChunks(img, imgData); 1.1550 + var alphaData = tag.alphaData; 1.1551 + if (alphaData) { 1.1552 + img.mask = createInflatedStream(alphaData, img.width * img.height).bytes; 1.1553 + } 1.1554 + if (tag.incomplete) { 1.1555 + var tables = dictionary[0]; 1.1556 + var header = tables.data; 1.1557 + if (header && header.size) { 1.1558 + chunks[0] = chunks[0].subarray(2); 1.1559 + chunks.unshift(header.slice(0, header.size - 2)); 1.1560 + } 1.1561 + } 1.1562 + } else { 1.1563 + chunks = [ 1.1564 + imgData 1.1565 + ]; 1.1566 + } 1.1567 + img.data = new Blob(chunks, { 1.1568 + type: tag.mimeType 1.1569 + }); 1.1570 + return img; 1.1571 +} 1.1572 +function defineLabel(tag, dictionary) { 1.1573 + var records = tag.records; 1.1574 + var m = tag.matrix; 1.1575 + var cmds = [ 1.1576 + 'c.save()', 1.1577 + 'c.transform(' + [ 1.1578 + m.a, 1.1579 + m.b, 1.1580 + m.c, 1.1581 + m.d, 1.1582 + m.tx / 20, 1.1583 + m.ty / 20 1.1584 + ].join(',') + ')', 1.1585 + 'c.scale(0.05, 0.05)' 1.1586 + ]; 1.1587 + var dependencies = []; 1.1588 + var x = 0; 1.1589 + var y = 0; 1.1590 + var i = 0; 1.1591 + var record; 1.1592 + var codes; 1.1593 + while (record = records[i++]) { 1.1594 + if (record.eot) 1.1595 + break; 1.1596 + if (record.hasFont) { 1.1597 + var font = dictionary[record.fontId]; 1.1598 + codes = font.codes; 1.1599 + cmds.push('c.font="' + record.fontHeight + 'px \'' + font.uniqueName + '\'"'); 1.1600 + dependencies.push(font.id); 1.1601 + } 1.1602 + if (record.hasColor) { 1.1603 + cmds.push('ct.setFillStyle(c,"' + rgbaObjToStr(record.color) + '")'); 1.1604 + cmds.push('ct.setAlpha(c)'); 1.1605 + } else { 1.1606 + cmds.push('ct.setAlpha(c,true)'); 1.1607 + } 1.1608 + if (record.hasMoveX) 1.1609 + x = record.moveX; 1.1610 + if (record.hasMoveY) 1.1611 + y = record.moveY; 1.1612 + var entries = record.entries; 1.1613 + var j = 0; 1.1614 + var entry; 1.1615 + while (entry = entries[j++]) { 1.1616 + var code = codes[entry.glyphIndex]; 1.1617 + var text = code >= 32 && code != 34 && code != 92 ? fromCharCode(code) : '\\u' + (code + 65536).toString(16).substring(1); 1.1618 + cmds.push('c.fillText("' + text + '",' + x + ',' + y + ')'); 1.1619 + x += entry.advance; 1.1620 + } 1.1621 + } 1.1622 + cmds.push('c.restore()'); 1.1623 + var label = { 1.1624 + type: 'label', 1.1625 + id: tag.id, 1.1626 + bbox: tag.bbox, 1.1627 + data: cmds.join('\n') 1.1628 + }; 1.1629 + if (dependencies.length) 1.1630 + label.require = dependencies; 1.1631 + return label; 1.1632 +} 1.1633 +var GRAPHICS_FILL_CLIPPED_BITMAP = 65; 1.1634 +var GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT = 19; 1.1635 +var GRAPHICS_FILL_LINEAR_GRADIENT = 16; 1.1636 +var GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP = 67; 1.1637 +var GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP = 66; 1.1638 +var GRAPHICS_FILL_RADIAL_GRADIENT = 18; 1.1639 +var GRAPHICS_FILL_REPEATING_BITMAP = 64; 1.1640 +var GRAPHICS_FILL_SOLID = 0; 1.1641 +function applySegmentToStyles(segment, styles, linePaths, fillPaths, isMorph) { 1.1642 + if (!segment) { 1.1643 + return; 1.1644 + } 1.1645 + var commands = segment.commands; 1.1646 + var data = segment.data; 1.1647 + var morphData = segment.morphData; 1.1648 + if (morphData) { 1.1649 + } 1.1650 + var path; 1.1651 + var targetSegment; 1.1652 + var command; 1.1653 + var i; 1.1654 + if (styles.fill0) { 1.1655 + path = fillPaths[styles.fill0 - 1]; 1.1656 + if (!(styles.fill1 || styles.line)) { 1.1657 + targetSegment = path.head(); 1.1658 + targetSegment.commands = []; 1.1659 + targetSegment.data = []; 1.1660 + targetSegment.morphData = isMorph ? [] : null; 1.1661 + } else { 1.1662 + targetSegment = path.addSegment([], [], isMorph ? [] : null); 1.1663 + } 1.1664 + var targetCommands = targetSegment.commands; 1.1665 + var targetData = targetSegment.data; 1.1666 + var targetMorphData = targetSegment.morphData; 1.1667 + targetCommands.push(SHAPE_MOVE_TO); 1.1668 + var j = data.length - 2; 1.1669 + targetData.push(data[j], data[j + 1]); 1.1670 + if (isMorph) { 1.1671 + targetMorphData.push(morphData[j], morphData[j + 1]); 1.1672 + } 1.1673 + for (i = commands.length; i-- > 1; j -= 2) { 1.1674 + command = commands[i]; 1.1675 + targetCommands.push(command); 1.1676 + targetData.push(data[j - 2], data[j - 1]); 1.1677 + if (isMorph) { 1.1678 + targetMorphData.push(morphData[j - 2], morphData[j - 1]); 1.1679 + } 1.1680 + if (command === SHAPE_CURVE_TO) { 1.1681 + targetData.push(data[j - 4], data[j - 3]); 1.1682 + if (isMorph) { 1.1683 + targetMorphData.push(morphData[j - 4], morphData[j - 3]); 1.1684 + } 1.1685 + j -= 2; 1.1686 + } 1.1687 + } 1.1688 + if (isMorph) { 1.1689 + } 1.1690 + } 1.1691 + if (styles.line && styles.fill1) { 1.1692 + path = linePaths[styles.line - 1]; 1.1693 + path.addSegment(commands, data, morphData); 1.1694 + } 1.1695 +} 1.1696 +function convertRecordsToStyledPaths(records, fillPaths, linePaths, dictionary, dependencies, recordsMorph, transferables) { 1.1697 + var isMorph = recordsMorph !== null; 1.1698 + var styles = { 1.1699 + fill0: 0, 1.1700 + fill1: 0, 1.1701 + line: 0 1.1702 + }; 1.1703 + var segment = null; 1.1704 + var allPaths; 1.1705 + var defaultPath; 1.1706 + var numRecords = records.length - 1; 1.1707 + var x = 0; 1.1708 + var y = 0; 1.1709 + var morphX = 0; 1.1710 + var morphY = 0; 1.1711 + var path; 1.1712 + for (var i = 0, j = 0; i < numRecords; i++) { 1.1713 + var record = records[i]; 1.1714 + var morphRecord; 1.1715 + if (isMorph) { 1.1716 + morphRecord = recordsMorph[j++]; 1.1717 + } 1.1718 + if (record.type === 0) { 1.1719 + if (segment) { 1.1720 + applySegmentToStyles(segment, styles, linePaths, fillPaths, isMorph); 1.1721 + } 1.1722 + if (record.hasNewStyles) { 1.1723 + if (!allPaths) { 1.1724 + allPaths = []; 1.1725 + } 1.1726 + push.apply(allPaths, fillPaths); 1.1727 + fillPaths = createPathsList(record.fillStyles, false, dictionary, dependencies); 1.1728 + push.apply(allPaths, linePaths); 1.1729 + linePaths = createPathsList(record.lineStyles, true, dictionary, dependencies); 1.1730 + if (defaultPath) { 1.1731 + allPaths.push(defaultPath); 1.1732 + defaultPath = null; 1.1733 + } 1.1734 + styles = { 1.1735 + fill0: 0, 1.1736 + fill1: 0, 1.1737 + line: 0 1.1738 + }; 1.1739 + } 1.1740 + if (record.hasFillStyle0) { 1.1741 + styles.fill0 = record.fillStyle0; 1.1742 + } 1.1743 + if (record.hasFillStyle1) { 1.1744 + styles.fill1 = record.fillStyle1; 1.1745 + } 1.1746 + if (record.hasLineStyle) { 1.1747 + styles.line = record.lineStyle; 1.1748 + } 1.1749 + if (styles.fill1) { 1.1750 + path = fillPaths[styles.fill1 - 1]; 1.1751 + } else if (styles.line) { 1.1752 + path = linePaths[styles.line - 1]; 1.1753 + } else if (styles.fill0) { 1.1754 + path = fillPaths[styles.fill0 - 1]; 1.1755 + } 1.1756 + if (record.move) { 1.1757 + x = record.moveX | 0; 1.1758 + y = record.moveY | 0; 1.1759 + } 1.1760 + if (path) { 1.1761 + segment = path.addSegment([], [], isMorph ? [] : null); 1.1762 + segment.commands.push(SHAPE_MOVE_TO); 1.1763 + segment.data.push(x, y); 1.1764 + if (isMorph) { 1.1765 + if (morphRecord.type === 0) { 1.1766 + morphX = morphRecord.moveX | 0; 1.1767 + morphY = morphRecord.moveY | 0; 1.1768 + } else { 1.1769 + morphX = x; 1.1770 + morphY = y; 1.1771 + j--; 1.1772 + } 1.1773 + segment.morphData.push(morphX, morphY); 1.1774 + } 1.1775 + } 1.1776 + } else { 1.1777 + if (!segment) { 1.1778 + if (!defaultPath) { 1.1779 + var style = { 1.1780 + color: { 1.1781 + red: 0, 1.1782 + green: 0, 1.1783 + blue: 0, 1.1784 + alpha: 255 1.1785 + }, 1.1786 + width: 20 1.1787 + }; 1.1788 + defaultPath = new SegmentedPath(null, processStyle(style, true)); 1.1789 + } 1.1790 + segment = defaultPath.addSegment([], [], isMorph ? [] : null); 1.1791 + segment.commands.push(SHAPE_MOVE_TO); 1.1792 + segment.data.push(x, y); 1.1793 + if (isMorph) { 1.1794 + segment.morphData.push(morphX, morphY); 1.1795 + } 1.1796 + } 1.1797 + if (isMorph) { 1.1798 + while (morphRecord && morphRecord.type === 0) { 1.1799 + morphRecord = recordsMorph[j++]; 1.1800 + } 1.1801 + if (!morphRecord) { 1.1802 + morphRecord = record; 1.1803 + } 1.1804 + } 1.1805 + if (record.isStraight && (!isMorph || morphRecord.isStraight)) { 1.1806 + x += record.deltaX | 0; 1.1807 + y += record.deltaY | 0; 1.1808 + segment.commands.push(SHAPE_LINE_TO); 1.1809 + segment.data.push(x, y); 1.1810 + if (isMorph) { 1.1811 + morphX += morphRecord.deltaX | 0; 1.1812 + morphY += morphRecord.deltaY | 0; 1.1813 + segment.morphData.push(morphX, morphY); 1.1814 + } 1.1815 + } else { 1.1816 + var cx, cy; 1.1817 + var deltaX, deltaY; 1.1818 + if (!record.isStraight) { 1.1819 + cx = x + record.controlDeltaX | 0; 1.1820 + cy = y + record.controlDeltaY | 0; 1.1821 + x = cx + record.anchorDeltaX | 0; 1.1822 + y = cy + record.anchorDeltaY | 0; 1.1823 + } else { 1.1824 + deltaX = record.deltaX | 0; 1.1825 + deltaY = record.deltaY | 0; 1.1826 + cx = x + (deltaX >> 1); 1.1827 + cy = y + (deltaY >> 1); 1.1828 + x += deltaX; 1.1829 + y += deltaY; 1.1830 + } 1.1831 + segment.commands.push(SHAPE_CURVE_TO); 1.1832 + segment.data.push(cx, cy, x, y); 1.1833 + if (isMorph) { 1.1834 + if (!morphRecord.isStraight) { 1.1835 + cx = morphX + morphRecord.controlDeltaX | 0; 1.1836 + cy = morphY + morphRecord.controlDeltaY | 0; 1.1837 + morphX = cx + morphRecord.anchorDeltaX | 0; 1.1838 + morphY = cy + morphRecord.anchorDeltaY | 0; 1.1839 + } else { 1.1840 + deltaX = morphRecord.deltaX | 0; 1.1841 + deltaY = morphRecord.deltaY | 0; 1.1842 + cx = morphX + (deltaX >> 1); 1.1843 + cy = morphY + (deltaY >> 1); 1.1844 + morphX += deltaX; 1.1845 + morphY += deltaY; 1.1846 + } 1.1847 + segment.morphData.push(cx, cy, morphX, morphY); 1.1848 + } 1.1849 + } 1.1850 + } 1.1851 + } 1.1852 + applySegmentToStyles(segment, styles, linePaths, fillPaths, isMorph); 1.1853 + if (allPaths) { 1.1854 + push.apply(allPaths, fillPaths); 1.1855 + } else { 1.1856 + allPaths = fillPaths; 1.1857 + } 1.1858 + push.apply(allPaths, linePaths); 1.1859 + if (defaultPath) { 1.1860 + allPaths.push(defaultPath); 1.1861 + } 1.1862 + var removeCount = 0; 1.1863 + for (i = 0; i < allPaths.length; i++) { 1.1864 + path = allPaths[i]; 1.1865 + if (!path.head()) { 1.1866 + removeCount++; 1.1867 + continue; 1.1868 + } 1.1869 + allPaths[i - removeCount] = segmentedPathToShapePath(path, isMorph, transferables); 1.1870 + } 1.1871 + allPaths.length -= removeCount; 1.1872 + return allPaths; 1.1873 +} 1.1874 +function segmentedPathToShapePath(path, isMorph, transferables) { 1.1875 + var start = path.head(); 1.1876 + var end = start; 1.1877 + var finalRoot = null; 1.1878 + var finalHead = null; 1.1879 + var skippedMoves = 0; 1.1880 + var current = start.prev; 1.1881 + while (start) { 1.1882 + while (current) { 1.1883 + if (path.segmentsConnect(current, start)) { 1.1884 + if (current.next !== start) { 1.1885 + path.removeSegment(current); 1.1886 + path.insertSegment(current, start); 1.1887 + } 1.1888 + start = current; 1.1889 + current = start.prev; 1.1890 + skippedMoves++; 1.1891 + continue; 1.1892 + } 1.1893 + if (path.segmentsConnect(end, current)) { 1.1894 + path.removeSegment(current); 1.1895 + end.next = current; 1.1896 + current = current.prev; 1.1897 + end.next.prev = end; 1.1898 + end.next.next = null; 1.1899 + end = end.next; 1.1900 + skippedMoves++; 1.1901 + continue; 1.1902 + } 1.1903 + current = current.prev; 1.1904 + } 1.1905 + current = start.prev; 1.1906 + if (!finalRoot) { 1.1907 + finalRoot = start; 1.1908 + finalHead = end; 1.1909 + } else { 1.1910 + finalHead.next = start; 1.1911 + start.prev = finalHead; 1.1912 + finalHead = end; 1.1913 + finalHead.next = null; 1.1914 + } 1.1915 + if (!current) { 1.1916 + break; 1.1917 + } 1.1918 + start = end = current; 1.1919 + current = start.prev; 1.1920 + } 1.1921 + var totalCommandsLength = -skippedMoves; 1.1922 + var totalDataLength = -skippedMoves << 1; 1.1923 + current = finalRoot; 1.1924 + while (current) { 1.1925 + totalCommandsLength += current.commands.length; 1.1926 + totalDataLength += current.data.length; 1.1927 + current = current.next; 1.1928 + } 1.1929 + var shape = new ShapePath(path.fillStyle, path.lineStyle, totalCommandsLength, totalDataLength, isMorph, transferables); 1.1930 + var allCommands = shape.commands; 1.1931 + var allData = shape.data; 1.1932 + var allMorphData = shape.morphData; 1.1933 + var commandsIndex = 0; 1.1934 + var dataIndex = 0; 1.1935 + current = finalRoot; 1.1936 + while (current) { 1.1937 + var commands = current.commands; 1.1938 + var data = current.data; 1.1939 + var morphData = current.morphData; 1.1940 + var offset = +(data[0] === allData[dataIndex - 2] && data[1] === allData[dataIndex - 1]); 1.1941 + for (var i = offset; i < commands.length; i++, commandsIndex++) { 1.1942 + allCommands[commandsIndex] = commands[i]; 1.1943 + } 1.1944 + for (i = offset << 1; i < data.length; i++, dataIndex++) { 1.1945 + allData[dataIndex] = data[i]; 1.1946 + if (isMorph) { 1.1947 + allMorphData[dataIndex] = morphData[i]; 1.1948 + } 1.1949 + } 1.1950 + current = current.next; 1.1951 + } 1.1952 + return shape; 1.1953 +} 1.1954 +var CAPS_STYLE_TYPES = [ 1.1955 + 'round', 1.1956 + 'none', 1.1957 + 'square' 1.1958 + ]; 1.1959 +var JOIN_STYLE_TYPES = [ 1.1960 + 'round', 1.1961 + 'bevel', 1.1962 + 'miter' 1.1963 + ]; 1.1964 +function processStyle(style, isLineStyle, dictionary, dependencies) { 1.1965 + if (isLineStyle) { 1.1966 + style.lineCap = CAPS_STYLE_TYPES[style.endCapStyle | 0]; 1.1967 + style.lineJoin = JOIN_STYLE_TYPES[style.joinStyle | 0]; 1.1968 + style.miterLimit = (style.miterLimitFactor || 1.5) * 2; 1.1969 + if (!style.color && style.hasFill) { 1.1970 + var fillStyle = processStyle(style.fillStyle, false, dictionary, dependencies); 1.1971 + style.style = fillStyle.style; 1.1972 + style.type = fillStyle.type; 1.1973 + style.transform = fillStyle.transform; 1.1974 + style.records = fillStyle.records; 1.1975 + style.focalPoint = fillStyle.focalPoint; 1.1976 + style.bitmapId = fillStyle.bitmapId; 1.1977 + style.repeat = fillStyle.repeat; 1.1978 + style.fillStyle = null; 1.1979 + return style; 1.1980 + } 1.1981 + } 1.1982 + var color; 1.1983 + if (style.type === undefined || style.type === GRAPHICS_FILL_SOLID) { 1.1984 + color = style.color; 1.1985 + style.style = 'rgba(' + color.red + ',' + color.green + ',' + color.blue + ',' + color.alpha / 255 + ')'; 1.1986 + style.color = null; 1.1987 + return style; 1.1988 + } 1.1989 + var scale; 1.1990 + switch (style.type) { 1.1991 + case GRAPHICS_FILL_LINEAR_GRADIENT: 1.1992 + case GRAPHICS_FILL_RADIAL_GRADIENT: 1.1993 + case GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT: 1.1994 + scale = 819.2; 1.1995 + break; 1.1996 + case GRAPHICS_FILL_REPEATING_BITMAP: 1.1997 + case GRAPHICS_FILL_CLIPPED_BITMAP: 1.1998 + case GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP: 1.1999 + case GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP: 1.2000 + if (dictionary[style.bitmapId]) { 1.2001 + dependencies.push(dictionary[style.bitmapId].id); 1.2002 + scale = 0.05; 1.2003 + } 1.2004 + break; 1.2005 + default: 1.2006 + fail('invalid fill style', 'shape'); 1.2007 + } 1.2008 + if (!style.matrix) { 1.2009 + return style; 1.2010 + } 1.2011 + var matrix = style.matrix; 1.2012 + style.transform = { 1.2013 + a: matrix.a * scale, 1.2014 + b: matrix.b * scale, 1.2015 + c: matrix.c * scale, 1.2016 + d: matrix.d * scale, 1.2017 + e: matrix.tx, 1.2018 + f: matrix.ty 1.2019 + }; 1.2020 + style.matrix = null; 1.2021 + return style; 1.2022 +} 1.2023 +function createPathsList(styles, isLineStyle, dictionary, dependencies) { 1.2024 + var paths = []; 1.2025 + for (var i = 0; i < styles.length; i++) { 1.2026 + var style = processStyle(styles[i], isLineStyle, dictionary, dependencies); 1.2027 + if (!isLineStyle) { 1.2028 + paths[i] = new SegmentedPath(style, null); 1.2029 + } else { 1.2030 + paths[i] = new SegmentedPath(null, style); 1.2031 + } 1.2032 + } 1.2033 + return paths; 1.2034 +} 1.2035 +function defineShape(tag, dictionary) { 1.2036 + var dependencies = []; 1.2037 + var transferables = []; 1.2038 + var fillPaths = createPathsList(tag.fillStyles, false, dictionary, dependencies); 1.2039 + var linePaths = createPathsList(tag.lineStyles, true, dictionary, dependencies); 1.2040 + var paths = convertRecordsToStyledPaths(tag.records, fillPaths, linePaths, dictionary, dependencies, tag.recordsMorph || null, transferables); 1.2041 + if (tag.bboxMorph) { 1.2042 + var mbox = tag.bboxMorph; 1.2043 + extendBoundsByPoint(tag.bbox, mbox.xMin, mbox.yMin); 1.2044 + extendBoundsByPoint(tag.bbox, mbox.xMax, mbox.yMax); 1.2045 + mbox = tag.strokeBboxMorph; 1.2046 + if (mbox) { 1.2047 + extendBoundsByPoint(tag.strokeBbox, mbox.xMin, mbox.yMin); 1.2048 + extendBoundsByPoint(tag.strokeBbox, mbox.xMax, mbox.yMax); 1.2049 + } 1.2050 + } 1.2051 + return { 1.2052 + type: 'shape', 1.2053 + id: tag.id, 1.2054 + strokeBbox: tag.strokeBbox, 1.2055 + strokeBboxMorph: tag.strokeBboxMorph, 1.2056 + bbox: tag.bbox, 1.2057 + bboxMorph: tag.bboxMorph, 1.2058 + isMorph: tag.isMorph, 1.2059 + paths: paths, 1.2060 + require: dependencies.length ? dependencies : null, 1.2061 + transferables: transferables 1.2062 + }; 1.2063 +} 1.2064 +function logShape(paths, bbox) { 1.2065 + var output = '{"bounds":' + JSON.stringify(bbox) + ',"paths":[' + paths.map(function (path) { 1.2066 + return path.serialize(); 1.2067 + }).join() + ']}'; 1.2068 + console.log(output); 1.2069 +} 1.2070 +function SegmentedPath(fillStyle, lineStyle) { 1.2071 + this.fillStyle = fillStyle; 1.2072 + this.lineStyle = lineStyle; 1.2073 + this._head = null; 1.2074 +} 1.2075 +SegmentedPath.prototype = { 1.2076 + addSegment: function (commands, data, morphData) { 1.2077 + var segment = { 1.2078 + commands: commands, 1.2079 + data: data, 1.2080 + morphData: morphData, 1.2081 + prev: this._head, 1.2082 + next: null 1.2083 + }; 1.2084 + if (this._head) { 1.2085 + this._head.next = segment; 1.2086 + } 1.2087 + this._head = segment; 1.2088 + return segment; 1.2089 + }, 1.2090 + removeSegment: function (segment) { 1.2091 + if (segment.prev) { 1.2092 + segment.prev.next = segment.next; 1.2093 + } 1.2094 + if (segment.next) { 1.2095 + segment.next.prev = segment.prev; 1.2096 + } 1.2097 + }, 1.2098 + insertSegment: function (segment, next) { 1.2099 + var prev = next.prev; 1.2100 + segment.prev = prev; 1.2101 + segment.next = next; 1.2102 + if (prev) { 1.2103 + prev.next = segment; 1.2104 + } 1.2105 + next.prev = segment; 1.2106 + }, 1.2107 + head: function () { 1.2108 + return this._head; 1.2109 + }, 1.2110 + segmentsConnect: function (first, second) { 1.2111 + var firstLength = first.data.length; 1.2112 + return first.data[firstLength - 2] === second.data[0] && first.data[firstLength - 1] === second.data[1]; 1.2113 + } 1.2114 +}; 1.2115 +var SHAPE_MOVE_TO = 1; 1.2116 +var SHAPE_LINE_TO = 2; 1.2117 +var SHAPE_CURVE_TO = 3; 1.2118 +var SHAPE_WIDE_MOVE_TO = 4; 1.2119 +var SHAPE_WIDE_LINE_TO = 5; 1.2120 +var SHAPE_CUBIC_CURVE_TO = 6; 1.2121 +var SHAPE_CIRCLE = 7; 1.2122 +var SHAPE_ELLIPSE = 8; 1.2123 +function ShapePath(fillStyle, lineStyle, commandsCount, dataLength, isMorph, transferables) { 1.2124 + this.fillStyle = fillStyle; 1.2125 + this.lineStyle = lineStyle; 1.2126 + if (commandsCount) { 1.2127 + this.commands = new Uint8Array(commandsCount); 1.2128 + this.data = new Int32Array(dataLength); 1.2129 + this.morphData = isMorph ? new Int32Array(dataLength) : null; 1.2130 + } else { 1.2131 + this.commands = []; 1.2132 + this.data = []; 1.2133 + } 1.2134 + this.bounds = null; 1.2135 + this.strokeBounds = null; 1.2136 + this.isMorph = !(!isMorph); 1.2137 + this.fullyInitialized = false; 1.2138 + if (inWorker) { 1.2139 + this.buffers = [ 1.2140 + this.commands.buffer, 1.2141 + this.data.buffer 1.2142 + ]; 1.2143 + transferables.push(this.commands.buffer, this.data.buffer); 1.2144 + if (isMorph) { 1.2145 + this.buffers.push(this.morphData.buffer); 1.2146 + transferables.push(this.morphData.buffer); 1.2147 + } 1.2148 + } else { 1.2149 + this.buffers = null; 1.2150 + } 1.2151 +} 1.2152 +ShapePath.prototype = { 1.2153 + get isEmpty() { 1.2154 + return this.commands.length === 0; 1.2155 + }, 1.2156 + moveTo: function (x, y) { 1.2157 + if (this.commands[this.commands.length - 1] === SHAPE_MOVE_TO) { 1.2158 + this.data[this.data.length - 2] = x; 1.2159 + this.data[this.data.length - 1] = y; 1.2160 + return; 1.2161 + } 1.2162 + this.commands.push(SHAPE_MOVE_TO); 1.2163 + this.data.push(x, y); 1.2164 + }, 1.2165 + lineTo: function (x, y) { 1.2166 + this.commands.push(SHAPE_LINE_TO); 1.2167 + this.data.push(x, y); 1.2168 + }, 1.2169 + curveTo: function (controlX, controlY, anchorX, anchorY) { 1.2170 + this.commands.push(SHAPE_CURVE_TO); 1.2171 + this.data.push(controlX, controlY, anchorX, anchorY); 1.2172 + }, 1.2173 + cubicCurveTo: function (control1X, control1Y, control2X, control2Y, anchorX, anchorY) { 1.2174 + this.commands.push(SHAPE_CUBIC_CURVE_TO); 1.2175 + this.data.push(control1X, control1Y, control2X, control2Y, anchorX, anchorY); 1.2176 + }, 1.2177 + rect: function (x, y, w, h) { 1.2178 + var x2 = x + w; 1.2179 + var y2 = y + h; 1.2180 + this.commands.push(SHAPE_MOVE_TO, SHAPE_LINE_TO, SHAPE_LINE_TO, SHAPE_LINE_TO, SHAPE_LINE_TO); 1.2181 + this.data.push(x, y, x2, y, x2, y2, x, y2, x, y); 1.2182 + }, 1.2183 + circle: function (x, y, radius) { 1.2184 + this.commands.push(SHAPE_CIRCLE); 1.2185 + this.data.push(x, y, radius); 1.2186 + }, 1.2187 + ellipse: function (x, y, radiusX, radiusY) { 1.2188 + this.commands.push(SHAPE_ELLIPSE); 1.2189 + this.data.push(x, y, radiusX, radiusY); 1.2190 + }, 1.2191 + draw: function (ctx, clip, ratio, colorTransform) { 1.2192 + if (clip && !this.fillStyle) { 1.2193 + return; 1.2194 + } 1.2195 + ctx.beginPath(); 1.2196 + var commands = this.commands; 1.2197 + var data = this.data; 1.2198 + var morphData = this.morphData; 1.2199 + var formOpen = false; 1.2200 + var formOpenX = 0; 1.2201 + var formOpenY = 0; 1.2202 + if (!this.isMorph) { 1.2203 + for (var j = 0, k = 0; j < commands.length; j++) { 1.2204 + switch (commands[j]) { 1.2205 + case SHAPE_MOVE_TO: 1.2206 + formOpen = true; 1.2207 + formOpenX = data[k++] / 20; 1.2208 + formOpenY = data[k++] / 20; 1.2209 + ctx.moveTo(formOpenX, formOpenY); 1.2210 + break; 1.2211 + case SHAPE_WIDE_MOVE_TO: 1.2212 + ctx.moveTo(data[k++] / 20, data[k++] / 20); 1.2213 + k += 2; 1.2214 + break; 1.2215 + case SHAPE_LINE_TO: 1.2216 + ctx.lineTo(data[k++] / 20, data[k++] / 20); 1.2217 + break; 1.2218 + case SHAPE_WIDE_LINE_TO: 1.2219 + ctx.lineTo(data[k++] / 20, data[k++] / 20); 1.2220 + k += 2; 1.2221 + break; 1.2222 + case SHAPE_CURVE_TO: 1.2223 + ctx.quadraticCurveTo(data[k++] / 20, data[k++] / 20, data[k++] / 20, data[k++] / 20); 1.2224 + break; 1.2225 + case SHAPE_CUBIC_CURVE_TO: 1.2226 + ctx.bezierCurveTo(data[k++] / 20, data[k++] / 20, data[k++] / 20, data[k++] / 20, data[k++] / 20, data[k++] / 20); 1.2227 + break; 1.2228 + case SHAPE_CIRCLE: 1.2229 + if (formOpen) { 1.2230 + ctx.lineTo(formOpenX, formOpenY); 1.2231 + formOpen = false; 1.2232 + } 1.2233 + ctx.moveTo((data[k] + data[k + 2]) / 20, data[k + 1] / 20); 1.2234 + ctx.arc(data[k++] / 20, data[k++] / 20, data[k++] / 20, 0, Math.PI * 2, false); 1.2235 + break; 1.2236 + case SHAPE_ELLIPSE: 1.2237 + if (formOpen) { 1.2238 + ctx.lineTo(formOpenX, formOpenY); 1.2239 + formOpen = false; 1.2240 + } 1.2241 + var x = data[k++]; 1.2242 + var y = data[k++]; 1.2243 + var rX = data[k++]; 1.2244 + var rY = data[k++]; 1.2245 + var radius; 1.2246 + if (rX !== rY) { 1.2247 + ctx.save(); 1.2248 + var ellipseScale; 1.2249 + if (rX > rY) { 1.2250 + ellipseScale = rX / rY; 1.2251 + radius = rY; 1.2252 + x /= ellipseScale; 1.2253 + ctx.scale(ellipseScale, 1); 1.2254 + } else { 1.2255 + ellipseScale = rY / rX; 1.2256 + radius = rX; 1.2257 + y /= ellipseScale; 1.2258 + ctx.scale(1, ellipseScale); 1.2259 + } 1.2260 + } 1.2261 + ctx.moveTo((x + radius) / 20, y / 20); 1.2262 + ctx.arc(x / 20, y / 20, radius / 20, 0, Math.PI * 2, false); 1.2263 + if (rX !== rY) { 1.2264 + ctx.restore(); 1.2265 + } 1.2266 + break; 1.2267 + default: 1.2268 + if (commands[j] === 0 && j === commands.length - 1) { 1.2269 + break; 1.2270 + } 1.2271 + console.warn('Unknown drawing command encountered: ' + commands[j]); 1.2272 + } 1.2273 + } 1.2274 + } else { 1.2275 + for (var j = 0, k = 0; j < commands.length; j++) { 1.2276 + switch (commands[j]) { 1.2277 + case SHAPE_MOVE_TO: 1.2278 + ctx.moveTo(morph(data[k] / 20, morphData[k++] / 20, ratio), morph(data[k] / 20, morphData[k++] / 20, ratio)); 1.2279 + break; 1.2280 + case SHAPE_LINE_TO: 1.2281 + ctx.lineTo(morph(data[k] / 20, morphData[k++] / 20, ratio), morph(data[k] / 20, morphData[k++] / 20, ratio)); 1.2282 + break; 1.2283 + case SHAPE_CURVE_TO: 1.2284 + ctx.quadraticCurveTo(morph(data[k] / 20, morphData[k++] / 20, ratio), morph(data[k] / 20, morphData[k++] / 20, ratio), morph(data[k] / 20, morphData[k++] / 20, ratio), morph(data[k] / 20, morphData[k++] / 20, ratio)); 1.2285 + break; 1.2286 + default: 1.2287 + console.warn('Drawing command not supported for morph shapes: ' + commands[j]); 1.2288 + } 1.2289 + } 1.2290 + } 1.2291 + if (!clip) { 1.2292 + var fillStyle = this.fillStyle; 1.2293 + if (fillStyle) { 1.2294 + colorTransform.setFillStyle(ctx, fillStyle.style); 1.2295 + ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = fillStyle.smooth; 1.2296 + var m = fillStyle.transform; 1.2297 + ctx.save(); 1.2298 + colorTransform.setAlpha(ctx); 1.2299 + if (m) { 1.2300 + ctx.transform(m.a, m.b, m.c, m.d, m.e / 20, m.f / 20); 1.2301 + } 1.2302 + ctx.fill(); 1.2303 + ctx.restore(); 1.2304 + } 1.2305 + var lineStyle = this.lineStyle; 1.2306 + if (lineStyle) { 1.2307 + colorTransform.setStrokeStyle(ctx, lineStyle.style); 1.2308 + ctx.save(); 1.2309 + colorTransform.setAlpha(ctx); 1.2310 + ctx.lineWidth = Math.max(lineStyle.width / 20, 1); 1.2311 + ctx.lineCap = lineStyle.lineCap; 1.2312 + ctx.lineJoin = lineStyle.lineJoin; 1.2313 + ctx.miterLimit = lineStyle.miterLimit; 1.2314 + ctx.stroke(); 1.2315 + ctx.restore(); 1.2316 + } 1.2317 + } else { 1.2318 + ctx.fill(); 1.2319 + } 1.2320 + ctx.closePath(); 1.2321 + }, 1.2322 + isPointInPath: function (x, y) { 1.2323 + if (!(this.fillStyle || this.lineStyle)) { 1.2324 + return false; 1.2325 + } 1.2326 + var bounds = this.strokeBounds || this.bounds || this._calculateBounds(); 1.2327 + if (x < bounds.xMin || x > bounds.xMax || y < bounds.yMin || y > bounds.yMax) { 1.2328 + return false; 1.2329 + } 1.2330 + if (this.fillStyle && this.isPointInFill(x, y)) { 1.2331 + return true; 1.2332 + } 1.2333 + return this.lineStyle && this.lineStyle.width !== undefined && this.isPointInStroke(x, y); 1.2334 + }, 1.2335 + isPointInFill: function (x, y) { 1.2336 + var commands = this.commands; 1.2337 + var data = this.data; 1.2338 + var length = commands.length; 1.2339 + var inside = false; 1.2340 + var fromX = 0; 1.2341 + var fromY = 0; 1.2342 + var toX = 0; 1.2343 + var toY = 0; 1.2344 + var localX; 1.2345 + var localY; 1.2346 + var cpX; 1.2347 + var cpY; 1.2348 + var rX; 1.2349 + var rY; 1.2350 + var formOpen = false; 1.2351 + var formOpenX = 0; 1.2352 + var formOpenY = 0; 1.2353 + for (var commandIndex = 0, dataIndex = 0; commandIndex < length; commandIndex++) { 1.2354 + switch (commands[commandIndex]) { 1.2355 + case SHAPE_WIDE_MOVE_TO: 1.2356 + dataIndex += 2; 1.2357 + case SHAPE_MOVE_TO: 1.2358 + toX = data[dataIndex++]; 1.2359 + toY = data[dataIndex++]; 1.2360 + if (formOpen && intersectsLine(x, y, fromX, fromY, formOpenX, formOpenY)) { 1.2361 + inside = !inside; 1.2362 + } 1.2363 + formOpen = true; 1.2364 + formOpenX = toX; 1.2365 + formOpenY = toY; 1.2366 + break; 1.2367 + case SHAPE_WIDE_LINE_TO: 1.2368 + dataIndex += 2; 1.2369 + case SHAPE_LINE_TO: 1.2370 + toX = data[dataIndex++]; 1.2371 + toY = data[dataIndex++]; 1.2372 + if (intersectsLine(x, y, fromX, fromY, toX, toY)) { 1.2373 + inside = !inside; 1.2374 + } 1.2375 + break; 1.2376 + case SHAPE_CURVE_TO: 1.2377 + cpX = data[dataIndex++]; 1.2378 + cpY = data[dataIndex++]; 1.2379 + toX = data[dataIndex++]; 1.2380 + toY = data[dataIndex++]; 1.2381 + if (cpY > y === fromY > y && toY > y === fromY > y) { 1.2382 + break; 1.2383 + } 1.2384 + if (fromX >= x && cpX >= x && toX >= x) { 1.2385 + inside = !inside; 1.2386 + break; 1.2387 + } 1.2388 + var a = fromY - 2 * cpY + toY; 1.2389 + var c = fromY - y; 1.2390 + var b = 2 * (cpY - fromY); 1.2391 + var d = b * b - 4 * a * c; 1.2392 + if (d < 0) { 1.2393 + break; 1.2394 + } 1.2395 + d = Math.sqrt(d); 1.2396 + a = 1 / (a + a); 1.2397 + var t1 = (d - b) * a; 1.2398 + var t2 = (-b - d) * a; 1.2399 + if (t1 >= 0 && t1 <= 1 && quadraticBezier(fromX, cpX, toX, t1) > x) { 1.2400 + inside = !inside; 1.2401 + } 1.2402 + if (t2 >= 0 && t2 <= 1 && quadraticBezier(fromX, cpX, toX, t2) > x) { 1.2403 + inside = !inside; 1.2404 + } 1.2405 + break; 1.2406 + case SHAPE_CUBIC_CURVE_TO: 1.2407 + cpX = data[dataIndex++]; 1.2408 + cpY = data[dataIndex++]; 1.2409 + var cp2X = data[dataIndex++]; 1.2410 + var cp2Y = data[dataIndex++]; 1.2411 + toX = data[dataIndex++]; 1.2412 + toY = data[dataIndex++]; 1.2413 + if (cpY > y === fromY > y && cp2Y > y === fromY > y && toY > y === fromY > y) { 1.2414 + break; 1.2415 + } 1.2416 + if (fromX >= x && cpX >= x && cp2X >= x && toX >= x) { 1.2417 + inside = !inside; 1.2418 + break; 1.2419 + } 1.2420 + var roots = cubicXAtY(fromX, fromY, cpX, cpY, cp2X, cp2Y, toX, toY, y); 1.2421 + for (var i = roots.length; i--;) { 1.2422 + if (roots[i] >= x) { 1.2423 + inside = !inside; 1.2424 + } 1.2425 + } 1.2426 + break; 1.2427 + case SHAPE_CIRCLE: 1.2428 + toX = data[dataIndex++]; 1.2429 + toY = data[dataIndex++]; 1.2430 + var r = data[dataIndex++]; 1.2431 + localX = x - toX; 1.2432 + localY = y - toY; 1.2433 + if (localX * localX + localY * localY < r * r) { 1.2434 + inside = !inside; 1.2435 + } 1.2436 + toX += r; 1.2437 + break; 1.2438 + case SHAPE_ELLIPSE: 1.2439 + cpX = data[dataIndex++]; 1.2440 + cpY = data[dataIndex++]; 1.2441 + rX = data[dataIndex++]; 1.2442 + rY = data[dataIndex++]; 1.2443 + localX = x - cpX; 1.2444 + localY = y - cpY; 1.2445 + if (localX * localX / (rX * rX) + localY * localY / (rY * rY) <= 1) { 1.2446 + inside = !inside; 1.2447 + } 1.2448 + toX = cpX + rX; 1.2449 + toY = cpY; 1.2450 + break; 1.2451 + default: 1.2452 + if (!inWorker) { 1.2453 + console.warn('Drawing command not handled in isPointInPath: ' + commands[commandIndex]); 1.2454 + } 1.2455 + } 1.2456 + fromX = toX; 1.2457 + fromY = toY; 1.2458 + } 1.2459 + if (formOpen && intersectsLine(x, y, fromX, fromY, formOpenX, formOpenY)) { 1.2460 + inside = !inside; 1.2461 + } 1.2462 + return inside; 1.2463 + }, 1.2464 + isPointInStroke: function (x, y) { 1.2465 + var commands = this.commands; 1.2466 + var data = this.data; 1.2467 + var length = commands.length; 1.2468 + var width = this.lineStyle.width; 1.2469 + var halfWidth = width / 2; 1.2470 + var halfWidthSq = halfWidth * halfWidth; 1.2471 + var minX = x - halfWidth; 1.2472 + var maxX = x + halfWidth; 1.2473 + var minY = y - halfWidth; 1.2474 + var maxY = y + halfWidth; 1.2475 + var fromX = 0; 1.2476 + var fromY = 0; 1.2477 + var toX = 0; 1.2478 + var toY = 0; 1.2479 + var localX; 1.2480 + var localY; 1.2481 + var cpX; 1.2482 + var cpY; 1.2483 + var rX; 1.2484 + var rY; 1.2485 + var curveX; 1.2486 + var curveY; 1.2487 + var t; 1.2488 + for (var commandIndex = 0, dataIndex = 0; commandIndex < length; commandIndex++) { 1.2489 + switch (commands[commandIndex]) { 1.2490 + case SHAPE_WIDE_MOVE_TO: 1.2491 + dataIndex += 2; 1.2492 + case SHAPE_MOVE_TO: 1.2493 + toX = data[dataIndex++]; 1.2494 + toY = data[dataIndex++]; 1.2495 + break; 1.2496 + case SHAPE_WIDE_LINE_TO: 1.2497 + dataIndex += 2; 1.2498 + case SHAPE_LINE_TO: 1.2499 + toX = data[dataIndex++]; 1.2500 + toY = data[dataIndex++]; 1.2501 + if (fromX === toX && fromY === toY) { 1.2502 + break; 1.2503 + } 1.2504 + if (maxX < fromX && maxX < toX || minX > fromX && minX > toX || maxY < fromY && maxY < toY || minY > fromY && minY > toY) { 1.2505 + break; 1.2506 + } 1.2507 + if (toX === fromX || toY === fromY) { 1.2508 + return true; 1.2509 + } 1.2510 + t = ((x - fromX) * (toX - fromX) + (y - fromY) * (toY - fromY)) / distanceSq(fromX, fromY, toX, toY); 1.2511 + if (t < 0) { 1.2512 + if (distanceSq(x, y, fromX, fromY) <= halfWidthSq) { 1.2513 + return true; 1.2514 + } 1.2515 + break; 1.2516 + } 1.2517 + if (t > 1) { 1.2518 + if (distanceSq(x, y, toX, toY) <= halfWidthSq) { 1.2519 + return true; 1.2520 + } 1.2521 + break; 1.2522 + } 1.2523 + if (distanceSq(x, y, fromX + t * (toX - fromX), fromY + t * (toY - fromY)) <= halfWidthSq) { 1.2524 + return true; 1.2525 + } 1.2526 + break; 1.2527 + case SHAPE_CURVE_TO: 1.2528 + cpX = data[dataIndex++]; 1.2529 + cpY = data[dataIndex++]; 1.2530 + toX = data[dataIndex++]; 1.2531 + toY = data[dataIndex++]; 1.2532 + var extremeX = quadraticBezierExtreme(fromX, cpX, toX); 1.2533 + if (maxX < fromX && maxX < extremeX && maxX < toX || minX > fromX && minX > extremeX && minX > toX) { 1.2534 + break; 1.2535 + } 1.2536 + var extremeY = quadraticBezierExtreme(fromY, cpY, toY); 1.2537 + if (maxY < fromY && maxY < extremeY && maxY < toY || minY > fromY && minY > extremeY && minY > toY) { 1.2538 + break; 1.2539 + } 1.2540 + for (t = 0; t < 1; t += 0.02) { 1.2541 + curveX = quadraticBezier(fromX, cpX, toX, t); 1.2542 + if (curveX < minX || curveX > maxX) { 1.2543 + continue; 1.2544 + } 1.2545 + curveY = quadraticBezier(fromY, cpY, toY, t); 1.2546 + if (curveY < minY || curveY > maxY) { 1.2547 + continue; 1.2548 + } 1.2549 + if ((x - curveX) * (x - curveX) + (y - curveY) * (y - curveY) < halfWidthSq) { 1.2550 + return true; 1.2551 + } 1.2552 + } 1.2553 + break; 1.2554 + case SHAPE_CUBIC_CURVE_TO: 1.2555 + cpX = data[dataIndex++]; 1.2556 + cpY = data[dataIndex++]; 1.2557 + var cp2X = data[dataIndex++]; 1.2558 + var cp2Y = data[dataIndex++]; 1.2559 + toX = data[dataIndex++]; 1.2560 + toY = data[dataIndex++]; 1.2561 + var extremesX = cubicBezierExtremes(fromX, cpX, cp2X, toX); 1.2562 + while (extremesX.length < 2) { 1.2563 + extremesX.push(toX); 1.2564 + } 1.2565 + if (maxX < fromX && maxX < toX && maxX < extremesX[0] && maxX < extremesX[1] || minX > fromX && minX > toX && minX > extremesX[0] && minX > extremesX[1]) { 1.2566 + break; 1.2567 + } 1.2568 + var extremesY = cubicBezierExtremes(fromY, cpY, cp2Y, toY); 1.2569 + while (extremesY.length < 2) { 1.2570 + extremesY.push(toY); 1.2571 + } 1.2572 + if (maxY < fromY && maxY < toY && maxY < extremesY[0] && maxY < extremesY[1] || minY > fromY && minY > toY && minY > extremesY[0] && minY > extremesY[1]) { 1.2573 + break; 1.2574 + } 1.2575 + for (t = 0; t < 1; t += 0.02) { 1.2576 + curveX = cubicBezier(fromX, cpX, cp2X, toX, t); 1.2577 + if (curveX < minX || curveX > maxX) { 1.2578 + continue; 1.2579 + } 1.2580 + curveY = cubicBezier(fromY, cpY, cp2Y, toY, t); 1.2581 + if (curveY < minY || curveY > maxY) { 1.2582 + continue; 1.2583 + } 1.2584 + if ((x - curveX) * (x - curveX) + (y - curveY) * (y - curveY) < halfWidthSq) { 1.2585 + return true; 1.2586 + } 1.2587 + } 1.2588 + break; 1.2589 + case SHAPE_CIRCLE: 1.2590 + cpX = data[dataIndex++]; 1.2591 + cpY = data[dataIndex++]; 1.2592 + var r = data[dataIndex++]; 1.2593 + toX = cpX + r; 1.2594 + toY = cpY; 1.2595 + if (maxX < cpX - r || minX > cpX + r || maxY < cpY - r || minY > cpY + r) { 1.2596 + break; 1.2597 + } 1.2598 + localX = x - cpX; 1.2599 + localY = y - cpY; 1.2600 + var rMin = r - halfWidth; 1.2601 + var rMax = r + halfWidth; 1.2602 + var distSq = localX * localX + localY * localY; 1.2603 + if (distSq >= rMin * rMin && distSq <= rMax * rMax) { 1.2604 + return true; 1.2605 + } 1.2606 + break; 1.2607 + case SHAPE_ELLIPSE: 1.2608 + cpX = data[dataIndex++]; 1.2609 + cpY = data[dataIndex++]; 1.2610 + rX = data[dataIndex++]; 1.2611 + rY = data[dataIndex++]; 1.2612 + toX = cpX + rX; 1.2613 + toY = cpY; 1.2614 + localX = Math.abs(x - cpX); 1.2615 + localY = Math.abs(y - cpY); 1.2616 + localX -= halfWidth; 1.2617 + localY -= halfWidth; 1.2618 + if (localX * localX / (rX * rX) + localY * localY / (rY * rY) > 1) { 1.2619 + break; 1.2620 + } 1.2621 + localX += width; 1.2622 + localY += width; 1.2623 + if (localX * localX / (rX * rX) + localY * localY / (rY * rY) > 1) { 1.2624 + return true; 1.2625 + } 1.2626 + break; 1.2627 + default: 1.2628 + if (!inWorker) { 1.2629 + console.warn('Drawing command not handled in isPointInPath: ' + commands[commandIndex]); 1.2630 + } 1.2631 + } 1.2632 + fromX = toX; 1.2633 + fromY = toY; 1.2634 + } 1.2635 + return false; 1.2636 + }, 1.2637 + getBounds: function (includeStroke) { 1.2638 + var bounds = includeStroke ? this.strokeBounds : this.bounds; 1.2639 + if (!bounds) { 1.2640 + this._calculateBounds(); 1.2641 + bounds = includeStroke ? this.strokeBounds : this.bounds; 1.2642 + } 1.2643 + return bounds; 1.2644 + }, 1.2645 + _calculateBounds: function () { 1.2646 + var commands = this.commands; 1.2647 + var data = this.data; 1.2648 + var length = commands.length; 1.2649 + var bounds; 1.2650 + if (commands[0] === SHAPE_MOVE_TO || commands[0] > SHAPE_CUBIC_CURVE_TO) { 1.2651 + bounds = { 1.2652 + xMin: data[0], 1.2653 + yMin: data[1] 1.2654 + }; 1.2655 + } else { 1.2656 + bounds = { 1.2657 + xMin: 0, 1.2658 + yMin: 0 1.2659 + }; 1.2660 + } 1.2661 + bounds.xMax = bounds.xMin; 1.2662 + bounds.yMax = bounds.yMin; 1.2663 + var fromX = bounds.xMin; 1.2664 + var fromY = bounds.yMin; 1.2665 + for (var commandIndex = 0, dataIndex = 0; commandIndex < length; commandIndex++) { 1.2666 + var toX; 1.2667 + var toY; 1.2668 + var cpX; 1.2669 + var cpY; 1.2670 + switch (commands[commandIndex]) { 1.2671 + case SHAPE_WIDE_MOVE_TO: 1.2672 + dataIndex += 2; 1.2673 + case SHAPE_MOVE_TO: 1.2674 + toX = data[dataIndex++]; 1.2675 + toY = data[dataIndex++]; 1.2676 + extendBoundsByPoint(bounds, toX, toY); 1.2677 + break; 1.2678 + case SHAPE_WIDE_LINE_TO: 1.2679 + dataIndex += 2; 1.2680 + case SHAPE_LINE_TO: 1.2681 + toX = data[dataIndex++]; 1.2682 + toY = data[dataIndex++]; 1.2683 + extendBoundsByPoint(bounds, toX, toY); 1.2684 + break; 1.2685 + case SHAPE_CURVE_TO: 1.2686 + cpX = data[dataIndex++]; 1.2687 + cpY = data[dataIndex++]; 1.2688 + toX = data[dataIndex++]; 1.2689 + toY = data[dataIndex++]; 1.2690 + extendBoundsByPoint(bounds, toX, toY); 1.2691 + if (cpX < fromX || cpX > toX) { 1.2692 + extendBoundsByX(bounds, quadraticBezierExtreme(fromX, cpX, toX)); 1.2693 + } 1.2694 + if (cpY < fromY || cpY > toY) { 1.2695 + extendBoundsByY(bounds, quadraticBezierExtreme(fromY, cpY, toY)); 1.2696 + } 1.2697 + break; 1.2698 + case SHAPE_CUBIC_CURVE_TO: 1.2699 + cpX = data[dataIndex++]; 1.2700 + cpY = data[dataIndex++]; 1.2701 + var cp2X = data[dataIndex++]; 1.2702 + var cp2Y = data[dataIndex++]; 1.2703 + toX = data[dataIndex++]; 1.2704 + toY = data[dataIndex++]; 1.2705 + extendBoundsByPoint(bounds, toX, toY); 1.2706 + var extremes; 1.2707 + var i; 1.2708 + if (cpX < fromX || cp2X < fromX || cpX > toX || cp2X > toX) { 1.2709 + extremes = cubicBezierExtremes(fromX, cpX, cp2X, toX); 1.2710 + for (i = extremes.length; i--;) { 1.2711 + extendBoundsByX(bounds, extremes[i]); 1.2712 + } 1.2713 + } 1.2714 + if (cpY < fromY || cp2Y < fromY || cpY > toY || cp2Y > toY) { 1.2715 + extremes = cubicBezierExtremes(fromY, cpY, cp2Y, toY); 1.2716 + for (i = extremes.length; i--;) { 1.2717 + extendBoundsByY(bounds, extremes[i]); 1.2718 + } 1.2719 + } 1.2720 + break; 1.2721 + case SHAPE_CIRCLE: 1.2722 + toX = data[dataIndex++]; 1.2723 + toY = data[dataIndex++]; 1.2724 + var radius = data[dataIndex++]; 1.2725 + extendBoundsByPoint(bounds, toX - radius, toY - radius); 1.2726 + extendBoundsByPoint(bounds, toX + radius, toY + radius); 1.2727 + toX += radius; 1.2728 + break; 1.2729 + case SHAPE_ELLIPSE: 1.2730 + toX = data[dataIndex++]; 1.2731 + toY = data[dataIndex++]; 1.2732 + var radiusX = data[dataIndex++]; 1.2733 + var radiusY = data[dataIndex++]; 1.2734 + extendBoundsByPoint(bounds, toX - radiusX, toY - radiusY); 1.2735 + extendBoundsByPoint(bounds, toX + radiusX, toY + radiusY); 1.2736 + toX += radiusX; 1.2737 + break; 1.2738 + default: 1.2739 + if (!inWorker) { 1.2740 + console.warn('Drawing command not handled in bounds calculation: ' + commands[commandIndex]); 1.2741 + } 1.2742 + } 1.2743 + fromX = toX; 1.2744 + fromY = toY; 1.2745 + } 1.2746 + this.bounds = bounds; 1.2747 + if (this.lineStyle) { 1.2748 + var halfLineWidth = this.lineStyle.width / 2; 1.2749 + this.strokeBounds = { 1.2750 + xMin: bounds.xMin - halfLineWidth, 1.2751 + yMin: bounds.yMin - halfLineWidth, 1.2752 + xMax: bounds.xMax + halfLineWidth, 1.2753 + yMax: bounds.yMax + halfLineWidth 1.2754 + }; 1.2755 + return this.strokeBounds; 1.2756 + } else { 1.2757 + this.strokeBounds = bounds; 1.2758 + } 1.2759 + return bounds; 1.2760 + }, 1.2761 + serialize: function () { 1.2762 + var output = '{'; 1.2763 + if (this.fillStyle) { 1.2764 + output += '"fill":' + JSON.stringify(this.fillStyle) + ','; 1.2765 + } 1.2766 + if (this.lineStyle) { 1.2767 + output += '"stroke":' + JSON.stringify(this.lineStyle) + ','; 1.2768 + } 1.2769 + output += '"commands":[' + Array.apply([], this.commands).join() + '],'; 1.2770 + output += '"data":[' + Array.apply([], this.data).join() + ']'; 1.2771 + return output + '}'; 1.2772 + } 1.2773 +}; 1.2774 +ShapePath.fromPlainObject = function (obj) { 1.2775 + var path = new ShapePath(obj.fill || null, obj.stroke || null); 1.2776 + path.commands = new Uint8Array(obj.commands); 1.2777 + path.data = new Int32Array(obj.data); 1.2778 + if (!inWorker) { 1.2779 + finishShapePath(path); 1.2780 + } 1.2781 + return path; 1.2782 +}; 1.2783 +function distanceSq(x1, y1, x2, y2) { 1.2784 + var dX = x2 - x1; 1.2785 + var dY = y2 - y1; 1.2786 + return dX * dX + dY * dY; 1.2787 +} 1.2788 +function intersectsLine(x, y, x1, y1, x2, y2) { 1.2789 + return y2 > y !== y1 > y && x < (x1 - x2) * (y - y2) / (y1 - y2) + x2; 1.2790 +} 1.2791 +function quadraticBezier(from, cp, to, t) { 1.2792 + var inverseT = 1 - t; 1.2793 + return from * inverseT * inverseT + 2 * cp * inverseT * t + to * t * t; 1.2794 +} 1.2795 +function quadraticBezierExtreme(from, cp, to) { 1.2796 + var t = (from - cp) / (from - 2 * cp + to); 1.2797 + if (t < 0) { 1.2798 + return from; 1.2799 + } 1.2800 + if (t > 1) { 1.2801 + return to; 1.2802 + } 1.2803 + return quadraticBezier(from, cp, to, t); 1.2804 +} 1.2805 +function cubicBezier(from, cp, cp2, to, t) { 1.2806 + var tSq = t * t; 1.2807 + var inverseT = 1 - t; 1.2808 + var inverseTSq = inverseT * inverseT; 1.2809 + return from * inverseT * inverseTSq + 3 * cp * t * inverseTSq + 3 * cp2 * inverseT * tSq + to * t * tSq; 1.2810 +} 1.2811 +function cubicBezierExtremes(from, cp, cp2, to) { 1.2812 + var d1 = cp - from; 1.2813 + var d2 = cp2 - cp; 1.2814 + d2 *= 2; 1.2815 + var d3 = to - cp2; 1.2816 + if (d1 + d3 === d2) { 1.2817 + d3 *= 1.0001; 1.2818 + } 1.2819 + var fHead = 2 * d1 - d2; 1.2820 + var part1 = d2 - 2 * d1; 1.2821 + var fCenter = Math.sqrt(part1 * part1 - 4 * d1 * (d1 - d2 + d3)); 1.2822 + var fTail = 2 * (d1 - d2 + d3); 1.2823 + var t1 = (fHead + fCenter) / fTail; 1.2824 + var t2 = (fHead - fCenter) / fTail; 1.2825 + var result = []; 1.2826 + if (t1 >= 0 && t1 <= 1) { 1.2827 + result.push(cubicBezier(from, cp, cp2, to, t1)); 1.2828 + } 1.2829 + if (t2 >= 0 && t2 <= 1) { 1.2830 + result.push(cubicBezier(from, cp, cp2, to, t2)); 1.2831 + } 1.2832 + return result; 1.2833 +} 1.2834 +function cubicXAtY(x0, y0, cx, cy, cx1, cy1, x1, y1, y) { 1.2835 + var dX = 3 * (cx - x0); 1.2836 + var dY = 3 * (cy - y0); 1.2837 + var bX = 3 * (cx1 - cx) - dX; 1.2838 + var bY = 3 * (cy1 - cy) - dY; 1.2839 + var c3X = x1 - x0 - dX - bX; 1.2840 + var c3Y = y1 - y0 - dY - bY; 1.2841 + function f(t) { 1.2842 + return t * (dY + t * (bY + t * c3Y)) + y0 - y; 1.2843 + } 1.2844 + function pointAt(t) { 1.2845 + if (t < 0) { 1.2846 + t = 0; 1.2847 + } else if (t > 1) { 1.2848 + t = 1; 1.2849 + } 1.2850 + return x0 + t * (dX + t * (bX + t * c3X)); 1.2851 + } 1.2852 + function bisectCubicBezierRange(f, l, r, limit) { 1.2853 + if (Math.abs(r - l) <= limit) { 1.2854 + return; 1.2855 + } 1.2856 + var middle = 0.5 * (l + r); 1.2857 + if (f(l) * f(r) <= 0) { 1.2858 + left = l; 1.2859 + right = r; 1.2860 + return; 1.2861 + } 1.2862 + bisectCubicBezierRange(f, l, middle, limit); 1.2863 + bisectCubicBezierRange(f, middle, r, limit); 1.2864 + } 1.2865 + var left = 0; 1.2866 + var right = 1; 1.2867 + bisectCubicBezierRange(f, 0, 1, 0.05); 1.2868 + var t0 = findRoot(left, right, f, 50, 0.000001); 1.2869 + var evalResult = Math.abs(f(t0)); 1.2870 + if (evalResult > 0.00001) { 1.2871 + return []; 1.2872 + } 1.2873 + var result = []; 1.2874 + if (t0 <= 1) { 1.2875 + result.push(pointAt(t0)); 1.2876 + } 1.2877 + var a = c3Y; 1.2878 + var b = t0 * a + bY; 1.2879 + var c = t0 * b + dY; 1.2880 + var d = b * b - 4 * a * c; 1.2881 + if (d < 0) { 1.2882 + return result; 1.2883 + } 1.2884 + d = Math.sqrt(d); 1.2885 + a = 1 / (a + a); 1.2886 + var t1 = (d - b) * a; 1.2887 + var t2 = (-b - d) * a; 1.2888 + if (t1 >= 0 && t1 <= 1) { 1.2889 + result.push(pointAt(t1)); 1.2890 + } 1.2891 + if (t2 >= 0 && t2 <= 1) { 1.2892 + result.push(pointAt(t2)); 1.2893 + } 1.2894 + return result; 1.2895 +} 1.2896 +function findRoot(x0, x2, f, maxIterations, epsilon) { 1.2897 + var x1; 1.2898 + var y0; 1.2899 + var y1; 1.2900 + var y2; 1.2901 + var b; 1.2902 + var c; 1.2903 + var y10; 1.2904 + var y20; 1.2905 + var y21; 1.2906 + var xm; 1.2907 + var ym; 1.2908 + var temp; 1.2909 + var xmlast = x0; 1.2910 + y0 = f(x0); 1.2911 + if (y0 === 0) { 1.2912 + return x0; 1.2913 + } 1.2914 + y2 = f(x2); 1.2915 + if (y2 === 0) { 1.2916 + return x2; 1.2917 + } 1.2918 + if (y2 * y0 > 0) { 1.2919 + return x0; 1.2920 + } 1.2921 + var __iter = 0; 1.2922 + for (var i = 0; i < maxIterations; ++i) { 1.2923 + __iter++; 1.2924 + x1 = 0.5 * (x2 + x0); 1.2925 + y1 = f(x1); 1.2926 + if (y1 === 0) { 1.2927 + return x1; 1.2928 + } 1.2929 + if (Math.abs(x1 - x0) < epsilon) { 1.2930 + return x1; 1.2931 + } 1.2932 + if (y1 * y0 > 0) { 1.2933 + temp = x0; 1.2934 + x0 = x2; 1.2935 + x2 = temp; 1.2936 + temp = y0; 1.2937 + y0 = y2; 1.2938 + y2 = temp; 1.2939 + } 1.2940 + y10 = y1 - y0; 1.2941 + y21 = y2 - y1; 1.2942 + y20 = y2 - y0; 1.2943 + if (y2 * y20 < 2 * y1 * y10) { 1.2944 + x2 = x1; 1.2945 + y2 = y1; 1.2946 + } else { 1.2947 + b = (x1 - x0) / y10; 1.2948 + c = (y10 - y21) / (y21 * y20); 1.2949 + xm = x0 - b * y0 * (1 - c * y1); 1.2950 + ym = f(xm); 1.2951 + if (ym === 0) { 1.2952 + return xm; 1.2953 + } 1.2954 + if (Math.abs(xm - xmlast) < epsilon) { 1.2955 + return xm; 1.2956 + } 1.2957 + xmlast = xm; 1.2958 + if (ym * y0 < 0) { 1.2959 + x2 = xm; 1.2960 + y2 = ym; 1.2961 + } else { 1.2962 + x0 = xm; 1.2963 + y0 = ym; 1.2964 + x2 = x1; 1.2965 + y2 = y1; 1.2966 + } 1.2967 + } 1.2968 + } 1.2969 + return x1; 1.2970 +} 1.2971 +function extendBoundsByPoint(bounds, x, y) { 1.2972 + if (x < bounds.xMin) { 1.2973 + bounds.xMin = x; 1.2974 + } else if (x > bounds.xMax) { 1.2975 + bounds.xMax = x; 1.2976 + } 1.2977 + if (y < bounds.yMin) { 1.2978 + bounds.yMin = y; 1.2979 + } else if (y > bounds.yMax) { 1.2980 + bounds.yMax = y; 1.2981 + } 1.2982 +} 1.2983 +function extendBoundsByX(bounds, x) { 1.2984 + if (x < bounds.xMin) { 1.2985 + bounds.xMin = x; 1.2986 + } else if (x > bounds.xMax) { 1.2987 + bounds.xMax = x; 1.2988 + } 1.2989 +} 1.2990 +function extendBoundsByY(bounds, y) { 1.2991 + if (y < bounds.yMin) { 1.2992 + bounds.yMin = y; 1.2993 + } else if (y > bounds.yMax) { 1.2994 + bounds.yMax = y; 1.2995 + } 1.2996 +} 1.2997 +function morph(start, end, ratio) { 1.2998 + return start + (end - start) * ratio; 1.2999 +} 1.3000 +function finishShapePath(path, dictionaryResolved) { 1.3001 + if (path.fullyInitialized) { 1.3002 + return path; 1.3003 + } 1.3004 + if (!(path instanceof ShapePath)) { 1.3005 + var untypedPath = path; 1.3006 + path = new ShapePath(path.fillStyle, path.lineStyle, 0, 0, path.isMorph); 1.3007 + path.commands = new Uint8Array(untypedPath.buffers[0]); 1.3008 + path.data = new Int32Array(untypedPath.buffers[1]); 1.3009 + if (untypedPath.isMorph) { 1.3010 + path.morphData = new Int32Array(untypedPath.buffers[2]); 1.3011 + } 1.3012 + path.buffers = null; 1.3013 + } 1.3014 + path.fillStyle && initStyle(path.fillStyle, dictionaryResolved); 1.3015 + path.lineStyle && initStyle(path.lineStyle, dictionaryResolved); 1.3016 + path.fullyInitialized = true; 1.3017 + return path; 1.3018 +} 1.3019 +var inWorker = typeof window === 'undefined'; 1.3020 +var factoryCtx = !inWorker ? document.createElement('canvas').getContext('2d') : null; 1.3021 +function buildLinearGradientFactory(colorStops) { 1.3022 + var defaultGradient = factoryCtx.createLinearGradient(-1, 0, 1, 0); 1.3023 + for (var i = 0; i < colorStops.length; i++) { 1.3024 + defaultGradient.addColorStop(colorStops[i].ratio, colorStops[i].color); 1.3025 + } 1.3026 + var fn = function createLinearGradient(ctx, colorTransform) { 1.3027 + var gradient = ctx.createLinearGradient(-1, 0, 1, 0); 1.3028 + for (var i = 0; i < colorStops.length; i++) { 1.3029 + colorTransform.addGradientColorStop(gradient, colorStops[i].ratio, colorStops[i].color); 1.3030 + } 1.3031 + return gradient; 1.3032 + }; 1.3033 + fn.defaultFillStyle = defaultGradient; 1.3034 + return fn; 1.3035 +} 1.3036 +function buildRadialGradientFactory(focalPoint, colorStops) { 1.3037 + var defaultGradient = factoryCtx.createRadialGradient(focalPoint, 0, 0, 0, 0, 1); 1.3038 + for (var i = 0; i < colorStops.length; i++) { 1.3039 + defaultGradient.addColorStop(colorStops[i].ratio, colorStops[i].color); 1.3040 + } 1.3041 + var fn = function createRadialGradient(ctx, colorTransform) { 1.3042 + var gradient = ctx.createRadialGradient(focalPoint, 0, 0, 0, 0, 1); 1.3043 + for (var i = 0; i < colorStops.length; i++) { 1.3044 + colorTransform.addGradientColorStop(gradient, colorStops[i].ratio, colorStops[i].color); 1.3045 + } 1.3046 + return gradient; 1.3047 + }; 1.3048 + fn.defaultFillStyle = defaultGradient; 1.3049 + return fn; 1.3050 +} 1.3051 +function buildBitmapPatternFactory(img, repeat) { 1.3052 + var defaultPattern = factoryCtx.createPattern(img, repeat); 1.3053 + var cachedTransform, cachedTransformKey; 1.3054 + var fn = function createBitmapPattern(ctx, colorTransform) { 1.3055 + if (!colorTransform.mode) { 1.3056 + return defaultPattern; 1.3057 + } 1.3058 + var key = colorTransform.getTransformFingerprint(); 1.3059 + if (key === cachedTransformKey) { 1.3060 + return cachedTransform; 1.3061 + } 1.3062 + var canvas = document.createElement('canvas'); 1.3063 + canvas.width = img.width; 1.3064 + canvas.height = img.height; 1.3065 + var ctx = canvas.getContext('2d'); 1.3066 + colorTransform.setAlpha(ctx, true); 1.3067 + ctx.drawImage(img, 0, 0); 1.3068 + cachedTransform = ctx.createPattern(canvas, repeat); 1.3069 + cachedTransformKey = key; 1.3070 + return cachedTransform; 1.3071 + }; 1.3072 + fn.defaultFillStyle = defaultPattern; 1.3073 + return fn; 1.3074 +} 1.3075 +function initStyle(style, dictionaryResolved) { 1.3076 + if (style.type === undefined) { 1.3077 + return; 1.3078 + } 1.3079 + switch (style.type) { 1.3080 + case GRAPHICS_FILL_SOLID: 1.3081 + break; 1.3082 + case GRAPHICS_FILL_LINEAR_GRADIENT: 1.3083 + case GRAPHICS_FILL_RADIAL_GRADIENT: 1.3084 + case GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT: 1.3085 + var records = style.records, colorStops = []; 1.3086 + for (var j = 0, n = records.length; j < n; j++) { 1.3087 + var record = records[j]; 1.3088 + var colorStr = rgbaObjToStr(record.color); 1.3089 + colorStops.push({ 1.3090 + ratio: record.ratio / 255, 1.3091 + color: colorStr 1.3092 + }); 1.3093 + } 1.3094 + var gradientConstructor; 1.3095 + var isLinear = style.type === GRAPHICS_FILL_LINEAR_GRADIENT; 1.3096 + if (isLinear) { 1.3097 + gradientConstructor = buildLinearGradientFactory(colorStops); 1.3098 + } else { 1.3099 + gradientConstructor = buildRadialGradientFactory((style.focalPoint | 0) / 20, colorStops); 1.3100 + } 1.3101 + style.style = gradientConstructor; 1.3102 + break; 1.3103 + case GRAPHICS_FILL_REPEATING_BITMAP: 1.3104 + case GRAPHICS_FILL_CLIPPED_BITMAP: 1.3105 + case GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP: 1.3106 + case GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP: 1.3107 + var bitmap = dictionaryResolved[style.bitmapId]; 1.3108 + var repeat = style.type === GRAPHICS_FILL_REPEATING_BITMAP || style.type === GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP; 1.3109 + style.style = buildBitmapPatternFactory(bitmap.props.img, repeat ? 'repeat' : 'no-repeat'); 1.3110 + break; 1.3111 + default: 1.3112 + fail('invalid fill style', 'shape'); 1.3113 + } 1.3114 +} 1.3115 +var SOUND_SIZE_8_BIT = 0; 1.3116 +var SOUND_SIZE_16_BIT = 1; 1.3117 +var SOUND_TYPE_MONO = 0; 1.3118 +var SOUND_TYPE_STEREO = 1; 1.3119 +var SOUND_FORMAT_PCM_BE = 0; 1.3120 +var SOUND_FORMAT_ADPCM = 1; 1.3121 +var SOUND_FORMAT_MP3 = 2; 1.3122 +var SOUND_FORMAT_PCM_LE = 3; 1.3123 +var SOUND_FORMAT_NELLYMOSER_16 = 4; 1.3124 +var SOUND_FORMAT_NELLYMOSER_8 = 5; 1.3125 +var SOUND_FORMAT_NELLYMOSER = 6; 1.3126 +var SOUND_FORMAT_SPEEX = 11; 1.3127 +var SOUND_RATES = [ 1.3128 + 5512, 1.3129 + 11250, 1.3130 + 22500, 1.3131 + 44100 1.3132 + ]; 1.3133 +var WaveHeader = new Uint8Array([ 1.3134 + 82, 1.3135 + 73, 1.3136 + 70, 1.3137 + 70, 1.3138 + 0, 1.3139 + 0, 1.3140 + 0, 1.3141 + 0, 1.3142 + 87, 1.3143 + 65, 1.3144 + 86, 1.3145 + 69, 1.3146 + 102, 1.3147 + 109, 1.3148 + 116, 1.3149 + 32, 1.3150 + 16, 1.3151 + 0, 1.3152 + 0, 1.3153 + 0, 1.3154 + 1, 1.3155 + 0, 1.3156 + 2, 1.3157 + 0, 1.3158 + 68, 1.3159 + 172, 1.3160 + 0, 1.3161 + 0, 1.3162 + 16, 1.3163 + 177, 1.3164 + 2, 1.3165 + 0, 1.3166 + 4, 1.3167 + 0, 1.3168 + 16, 1.3169 + 0, 1.3170 + 100, 1.3171 + 97, 1.3172 + 116, 1.3173 + 97, 1.3174 + 0, 1.3175 + 0, 1.3176 + 0, 1.3177 + 0 1.3178 + ]); 1.3179 +function packageWave(data, sampleRate, channels, size, swapBytes) { 1.3180 + var sizeInBytes = size >> 3; 1.3181 + var sizePerSecond = channels * sampleRate * sizeInBytes; 1.3182 + var sizePerSample = channels * sizeInBytes; 1.3183 + var dataLength = data.length + (data.length & 1); 1.3184 + var buffer = new ArrayBuffer(WaveHeader.length + dataLength); 1.3185 + var bytes = new Uint8Array(buffer); 1.3186 + bytes.set(WaveHeader); 1.3187 + if (swapBytes) { 1.3188 + for (var i = 0, j = WaveHeader.length; i < data.length; i += 2, j += 2) { 1.3189 + bytes[j] = data[i + 1]; 1.3190 + bytes[j + 1] = data[i]; 1.3191 + } 1.3192 + } else { 1.3193 + bytes.set(data, WaveHeader.length); 1.3194 + } 1.3195 + var view = new DataView(buffer); 1.3196 + view.setUint32(4, dataLength + 36, true); 1.3197 + view.setUint16(22, channels, true); 1.3198 + view.setUint32(24, sampleRate, true); 1.3199 + view.setUint32(28, sizePerSecond, true); 1.3200 + view.setUint16(32, sizePerSample, true); 1.3201 + view.setUint16(34, size, true); 1.3202 + view.setUint32(40, dataLength, true); 1.3203 + return { 1.3204 + data: bytes, 1.3205 + mimeType: 'audio/wav' 1.3206 + }; 1.3207 +} 1.3208 +function defineSound(tag, dictionary) { 1.3209 + var channels = tag.soundType == SOUND_TYPE_STEREO ? 2 : 1; 1.3210 + var samplesCount = tag.samplesCount; 1.3211 + var sampleRate = SOUND_RATES[tag.soundRate]; 1.3212 + var data = tag.soundData; 1.3213 + var pcm, packaged; 1.3214 + switch (tag.soundFormat) { 1.3215 + case SOUND_FORMAT_PCM_BE: 1.3216 + pcm = new Float32Array(samplesCount * channels); 1.3217 + if (tag.soundSize == SOUND_SIZE_16_BIT) { 1.3218 + for (var i = 0, j = 0; i < pcm.length; i++, j += 2) 1.3219 + pcm[i] = (data[j] << 24 | data[j + 1] << 16) / 2147483648; 1.3220 + packaged = packageWave(data, sampleRate, channels, 16, true); 1.3221 + } else { 1.3222 + for (var i = 0; i < pcm.length; i++) 1.3223 + pcm[i] = (data[i] - 128) / 128; 1.3224 + packaged = packageWave(data, sampleRate, channels, 8, false); 1.3225 + } 1.3226 + break; 1.3227 + case SOUND_FORMAT_PCM_LE: 1.3228 + pcm = new Float32Array(samplesCount * channels); 1.3229 + if (tag.soundSize == SOUND_SIZE_16_BIT) { 1.3230 + for (var i = 0, j = 0; i < pcm.length; i++, j += 2) 1.3231 + pcm[i] = (data[j + 1] << 24 | data[j] << 16) / 2147483648; 1.3232 + packaged = packageWave(data, sampleRate, channels, 16, false); 1.3233 + } else { 1.3234 + for (var i = 0; i < pcm.length; i++) 1.3235 + pcm[i] = (data[i] - 128) / 128; 1.3236 + packaged = packageWave(data, sampleRate, channels, 8, false); 1.3237 + } 1.3238 + break; 1.3239 + case SOUND_FORMAT_MP3: 1.3240 + packaged = { 1.3241 + data: new Uint8Array(data.subarray(2)), 1.3242 + mimeType: 'audio/mpeg' 1.3243 + }; 1.3244 + break; 1.3245 + case SOUND_FORMAT_ADPCM: 1.3246 + var pcm16 = new Int16Array(samplesCount * channels); 1.3247 + decodeACPCMSoundData(data, pcm16, channels); 1.3248 + pcm = new Float32Array(samplesCount * channels); 1.3249 + for (var i = 0; i < pcm.length; i++) 1.3250 + pcm[i] = pcm16[i] / 32768; 1.3251 + packaged = packageWave(new Uint8Array(pcm16.buffer), sampleRate, channels, 16, !new Uint8Array(new Uint16Array([ 1.3252 + 1 1.3253 + ]).buffer)[0]); 1.3254 + break; 1.3255 + default: 1.3256 + throw new Error('Unsupported audio format: ' + tag.soundFormat); 1.3257 + } 1.3258 + var sound = { 1.3259 + type: 'sound', 1.3260 + id: tag.id, 1.3261 + sampleRate: sampleRate, 1.3262 + channels: channels, 1.3263 + pcm: pcm 1.3264 + }; 1.3265 + if (packaged) 1.3266 + sound.packaged = packaged; 1.3267 + return sound; 1.3268 +} 1.3269 +var ACPCMIndexTables = [ 1.3270 + [ 1.3271 + -1, 1.3272 + 2 1.3273 + ], 1.3274 + [ 1.3275 + -1, 1.3276 + -1, 1.3277 + 2, 1.3278 + 4 1.3279 + ], 1.3280 + [ 1.3281 + -1, 1.3282 + -1, 1.3283 + -1, 1.3284 + -1, 1.3285 + 2, 1.3286 + 4, 1.3287 + 6, 1.3288 + 8 1.3289 + ], 1.3290 + [ 1.3291 + -1, 1.3292 + -1, 1.3293 + -1, 1.3294 + -1, 1.3295 + -1, 1.3296 + -1, 1.3297 + -1, 1.3298 + -1, 1.3299 + 1, 1.3300 + 2, 1.3301 + 4, 1.3302 + 6, 1.3303 + 8, 1.3304 + 10, 1.3305 + 13, 1.3306 + 16 1.3307 + ] 1.3308 + ]; 1.3309 +var ACPCMStepSizeTable = [ 1.3310 + 7, 1.3311 + 8, 1.3312 + 9, 1.3313 + 10, 1.3314 + 11, 1.3315 + 12, 1.3316 + 13, 1.3317 + 14, 1.3318 + 16, 1.3319 + 17, 1.3320 + 19, 1.3321 + 21, 1.3322 + 23, 1.3323 + 25, 1.3324 + 28, 1.3325 + 31, 1.3326 + 34, 1.3327 + 37, 1.3328 + 41, 1.3329 + 45, 1.3330 + 50, 1.3331 + 55, 1.3332 + 60, 1.3333 + 66, 1.3334 + 73, 1.3335 + 80, 1.3336 + 88, 1.3337 + 97, 1.3338 + 107, 1.3339 + 118, 1.3340 + 130, 1.3341 + 143, 1.3342 + 157, 1.3343 + 173, 1.3344 + 190, 1.3345 + 209, 1.3346 + 230, 1.3347 + 253, 1.3348 + 279, 1.3349 + 307, 1.3350 + 337, 1.3351 + 371, 1.3352 + 408, 1.3353 + 449, 1.3354 + 494, 1.3355 + 544, 1.3356 + 598, 1.3357 + 658, 1.3358 + 724, 1.3359 + 796, 1.3360 + 876, 1.3361 + 963, 1.3362 + 1060, 1.3363 + 1166, 1.3364 + 1282, 1.3365 + 1411, 1.3366 + 1552, 1.3367 + 1707, 1.3368 + 1878, 1.3369 + 2066, 1.3370 + 2272, 1.3371 + 2499, 1.3372 + 2749, 1.3373 + 3024, 1.3374 + 3327, 1.3375 + 3660, 1.3376 + 4026, 1.3377 + 4428, 1.3378 + 4871, 1.3379 + 5358, 1.3380 + 5894, 1.3381 + 6484, 1.3382 + 7132, 1.3383 + 7845, 1.3384 + 8630, 1.3385 + 9493, 1.3386 + 10442, 1.3387 + 11487, 1.3388 + 12635, 1.3389 + 13899, 1.3390 + 15289, 1.3391 + 16818, 1.3392 + 18500, 1.3393 + 20350, 1.3394 + 22385, 1.3395 + 24623, 1.3396 + 27086, 1.3397 + 29794, 1.3398 + 32767 1.3399 + ]; 1.3400 +function decodeACPCMSoundData(data, pcm16, channels) { 1.3401 + function readBits(n, signed) { 1.3402 + while (dataBufferLength < n) { 1.3403 + dataBuffer = dataBuffer << 8 | data[dataPosition++]; 1.3404 + dataBufferLength += 8; 1.3405 + } 1.3406 + dataBufferLength -= n; 1.3407 + return dataBuffer >>> dataBufferLength & (1 << n) - 1; 1.3408 + } 1.3409 + var dataPosition = 0; 1.3410 + var dataBuffer = 0; 1.3411 + var dataBufferLength = 0; 1.3412 + var pcmPosition = 0; 1.3413 + var codeSize = readBits(2); 1.3414 + var indexTable = ACPCMIndexTables[codeSize]; 1.3415 + while (pcmPosition < pcm16.length) { 1.3416 + var x = pcm16[pcmPosition++] = readBits(16) << 16 >> 16, x2; 1.3417 + var stepIndex = readBits(6), stepIndex2; 1.3418 + if (channels > 1) { 1.3419 + x2 = pcm16[pcmPosition++] = readBits(16) << 16 >> 16; 1.3420 + stepIndex2 = readBits(6); 1.3421 + } 1.3422 + var signMask = 1 << codeSize + 1; 1.3423 + for (var i = 0; i < 4095; i++) { 1.3424 + var nibble = readBits(codeSize + 2); 1.3425 + var step = ACPCMStepSizeTable[stepIndex]; 1.3426 + var sum = 0; 1.3427 + for (var currentBit = signMask >> 1; currentBit; currentBit >>= 1, step >>= 1) { 1.3428 + if (nibble & currentBit) 1.3429 + sum += step; 1.3430 + } 1.3431 + x += (nibble & signMask ? -1 : 1) * (sum + step); 1.3432 + pcm16[pcmPosition++] = x = x < -32768 ? -32768 : x > 32767 ? 32767 : x; 1.3433 + stepIndex += indexTable[nibble & ~signMask]; 1.3434 + stepIndex = stepIndex < 0 ? 0 : stepIndex > 88 ? 88 : stepIndex; 1.3435 + if (channels > 1) { 1.3436 + nibble = readBits(codeSize + 2); 1.3437 + step = ACPCMStepSizeTable[stepIndex2]; 1.3438 + sum = 0; 1.3439 + for (var currentBit = signMask >> 1; currentBit; currentBit >>= 1, step >>= 1) { 1.3440 + if (nibble & currentBit) 1.3441 + sum += step; 1.3442 + } 1.3443 + x2 += (nibble & signMask ? -1 : 1) * (sum + step); 1.3444 + pcm16[pcmPosition++] = x2 = x2 < -32768 ? -32768 : x2 > 32767 ? 32767 : x2; 1.3445 + stepIndex2 += indexTable[nibble & ~signMask]; 1.3446 + stepIndex2 = stepIndex2 < 0 ? 0 : stepIndex2 > 88 ? 88 : stepIndex2; 1.3447 + } 1.3448 + } 1.3449 + } 1.3450 +} 1.3451 +var nextSoundStreamId = 0; 1.3452 +function SwfSoundStream(samplesCount, sampleRate, channels) { 1.3453 + this.streamId = nextSoundStreamId++; 1.3454 + this.samplesCount = samplesCount; 1.3455 + this.sampleRate = sampleRate; 1.3456 + this.channels = channels; 1.3457 + this.format = null; 1.3458 + this.currentSample = 0; 1.3459 +} 1.3460 +SwfSoundStream.prototype = { 1.3461 + get info() { 1.3462 + return { 1.3463 + samplesCount: this.samplesCount, 1.3464 + sampleRate: this.sampleRate, 1.3465 + channels: this.channels, 1.3466 + format: this.format, 1.3467 + streamId: this.streamId 1.3468 + }; 1.3469 + }, 1.3470 + decode: function (data) { 1.3471 + throw new Error('SwfSoundStream.decode: not implemented'); 1.3472 + } 1.3473 +}; 1.3474 +function SwfSoundStream_decode_PCM(data) { 1.3475 + var pcm = new Float32Array(data.length); 1.3476 + for (var i = 0; i < pcm.length; i++) 1.3477 + pcm[i] = (data[i] - 128) / 128; 1.3478 + this.currentSample += pcm.length / this.channels; 1.3479 + return { 1.3480 + streamId: this.streamId, 1.3481 + samplesCount: pcm.length / this.channels, 1.3482 + pcm: pcm 1.3483 + }; 1.3484 +} 1.3485 +function SwfSoundStream_decode_PCM_be(data) { 1.3486 + var pcm = new Float32Array(data.length / 2); 1.3487 + for (var i = 0, j = 0; i < pcm.length; i++, j += 2) 1.3488 + pcm[i] = (data[j] << 24 | data[j + 1] << 16) / 2147483648; 1.3489 + this.currentSample += pcm.length / this.channels; 1.3490 + return { 1.3491 + streamId: this.streamId, 1.3492 + samplesCount: pcm.length / this.channels, 1.3493 + pcm: pcm 1.3494 + }; 1.3495 +} 1.3496 +function SwfSoundStream_decode_PCM_le(data) { 1.3497 + var pcm = new Float32Array(data.length / 2); 1.3498 + for (var i = 0, j = 0; i < pcm.length; i++, j += 2) 1.3499 + pcm[i] = (data[j + 1] << 24 | data[j] << 16) / 2147483648; 1.3500 + this.currentSample += pcm.length / this.channels; 1.3501 + return { 1.3502 + streamId: this.streamId, 1.3503 + samplesCount: pcm.length / this.channels, 1.3504 + pcm: pcm 1.3505 + }; 1.3506 +} 1.3507 +function SwfSoundStream_decode_MP3(data) { 1.3508 + var samplesCount = data[1] << 8 | data[0]; 1.3509 + var seek = data[3] << 8 | data[2]; 1.3510 + this.currentSample += samplesCount; 1.3511 + return { 1.3512 + streamId: this.streamId, 1.3513 + samplesCount: samplesCount, 1.3514 + data: new Uint8Array(data.subarray(4)), 1.3515 + seek: seek 1.3516 + }; 1.3517 +} 1.3518 +function createSoundStream(tag) { 1.3519 + var channels = tag.streamType == SOUND_TYPE_STEREO ? 2 : 1; 1.3520 + var samplesCount = tag.samplesCount; 1.3521 + var sampleRate = SOUND_RATES[tag.streamRate]; 1.3522 + var stream = new SwfSoundStream(samplesCount, sampleRate, channels); 1.3523 + switch (tag.streamCompression) { 1.3524 + case SOUND_FORMAT_PCM_BE: 1.3525 + stream.format = 'wave'; 1.3526 + if (tag.soundSize == SOUND_SIZE_16_BIT) { 1.3527 + stream.decode = SwfSoundStream_decode_PCM_be; 1.3528 + } else { 1.3529 + stream.decode = SwfSoundStream_decode_PCM; 1.3530 + } 1.3531 + break; 1.3532 + case SOUND_FORMAT_PCM_LE: 1.3533 + stream.format = 'wave'; 1.3534 + if (tag.soundSize == SOUND_SIZE_16_BIT) { 1.3535 + stream.decode = SwfSoundStream_decode_PCM_le; 1.3536 + } else { 1.3537 + stream.decode = SwfSoundStream_decode_PCM; 1.3538 + } 1.3539 + break; 1.3540 + case SOUND_FORMAT_MP3: 1.3541 + stream.format = 'mp3'; 1.3542 + stream.decode = SwfSoundStream_decode_MP3; 1.3543 + break; 1.3544 + default: 1.3545 + throw new Error('Unsupported audio format: ' + tag.soundFormat); 1.3546 + } 1.3547 + return stream; 1.3548 +} 1.3549 +function defineText(tag, dictionary) { 1.3550 + var dependencies = []; 1.3551 + if (tag.hasFont) { 1.3552 + var font = dictionary[tag.fontId]; 1.3553 + tag.font = font.uniqueName; 1.3554 + dependencies.push(font.id); 1.3555 + } 1.3556 + var props = { 1.3557 + type: 'text', 1.3558 + id: tag.id, 1.3559 + variableName: tag.variableName, 1.3560 + tag: tag 1.3561 + }; 1.3562 + if (dependencies.length) 1.3563 + props.require = dependencies; 1.3564 + return props; 1.3565 +} 1.3566 +var $RELEASE = false; 1.3567 +var isWorker = typeof window === 'undefined'; 1.3568 +if (isWorker && !true) { 1.3569 + importScripts.apply(null, [ 1.3570 + '../../lib/DataView.js/DataView.js', 1.3571 + '../flash/util.js', 1.3572 + 'config.js', 1.3573 + 'swf.js', 1.3574 + 'types.js', 1.3575 + 'structs.js', 1.3576 + 'tags.js', 1.3577 + 'inflate.js', 1.3578 + 'stream.js', 1.3579 + 'templates.js', 1.3580 + 'generator.js', 1.3581 + 'handlers.js', 1.3582 + 'parser.js', 1.3583 + 'bitmap.js', 1.3584 + 'button.js', 1.3585 + 'font.js', 1.3586 + 'image.js', 1.3587 + 'label.js', 1.3588 + 'shape.js', 1.3589 + 'sound.js', 1.3590 + 'text.js' 1.3591 + ]); 1.3592 +} 1.3593 +function defineSymbol(swfTag, symbols) { 1.3594 + var symbol; 1.3595 + switch (swfTag.code) { 1.3596 + case SWF_TAG_CODE_DEFINE_BITS: 1.3597 + case SWF_TAG_CODE_DEFINE_BITS_JPEG2: 1.3598 + case SWF_TAG_CODE_DEFINE_BITS_JPEG3: 1.3599 + case SWF_TAG_CODE_DEFINE_BITS_JPEG4: 1.3600 + case SWF_TAG_CODE_JPEG_TABLES: 1.3601 + symbol = defineImage(swfTag, symbols); 1.3602 + break; 1.3603 + case SWF_TAG_CODE_DEFINE_BITS_LOSSLESS: 1.3604 + case SWF_TAG_CODE_DEFINE_BITS_LOSSLESS2: 1.3605 + symbol = defineBitmap(swfTag); 1.3606 + break; 1.3607 + case SWF_TAG_CODE_DEFINE_BUTTON: 1.3608 + case SWF_TAG_CODE_DEFINE_BUTTON2: 1.3609 + symbol = defineButton(swfTag, symbols); 1.3610 + break; 1.3611 + case SWF_TAG_CODE_DEFINE_EDIT_TEXT: 1.3612 + symbol = defineText(swfTag, symbols); 1.3613 + break; 1.3614 + case SWF_TAG_CODE_DEFINE_FONT: 1.3615 + case SWF_TAG_CODE_DEFINE_FONT2: 1.3616 + case SWF_TAG_CODE_DEFINE_FONT3: 1.3617 + case SWF_TAG_CODE_DEFINE_FONT4: 1.3618 + symbol = defineFont(swfTag, symbols); 1.3619 + break; 1.3620 + case SWF_TAG_CODE_DEFINE_MORPH_SHAPE: 1.3621 + case SWF_TAG_CODE_DEFINE_MORPH_SHAPE2: 1.3622 + case SWF_TAG_CODE_DEFINE_SHAPE: 1.3623 + case SWF_TAG_CODE_DEFINE_SHAPE2: 1.3624 + case SWF_TAG_CODE_DEFINE_SHAPE3: 1.3625 + case SWF_TAG_CODE_DEFINE_SHAPE4: 1.3626 + symbol = defineShape(swfTag, symbols); 1.3627 + break; 1.3628 + case SWF_TAG_CODE_DEFINE_SOUND: 1.3629 + symbol = defineSound(swfTag, symbols); 1.3630 + break; 1.3631 + case SWF_TAG_CODE_DEFINE_BINARY_DATA: 1.3632 + symbol = { 1.3633 + type: 'binary', 1.3634 + id: swfTag.id, 1.3635 + data: swfTag.data 1.3636 + }; 1.3637 + break; 1.3638 + case SWF_TAG_CODE_DEFINE_SPRITE: 1.3639 + var depths = {}; 1.3640 + var frame = { 1.3641 + type: 'frame' 1.3642 + }; 1.3643 + var frames = []; 1.3644 + var tags = swfTag.tags; 1.3645 + var frameScripts = null; 1.3646 + var frameIndex = 0; 1.3647 + var soundStream = null; 1.3648 + for (var i = 0, n = tags.length; i < n; i++) { 1.3649 + var tag = tags[i]; 1.3650 + switch (tag.code) { 1.3651 + case SWF_TAG_CODE_DO_ACTION: 1.3652 + if (!frameScripts) 1.3653 + frameScripts = []; 1.3654 + frameScripts.push(frameIndex); 1.3655 + frameScripts.push(tag.actionsData); 1.3656 + break; 1.3657 + case SWF_TAG_CODE_START_SOUND: 1.3658 + var startSounds = frame.startSounds || (frame.startSounds = []); 1.3659 + startSounds.push(tag); 1.3660 + break; 1.3661 + case SWF_TAG_CODE_SOUND_STREAM_HEAD: 1.3662 + try { 1.3663 + soundStream = createSoundStream(tag); 1.3664 + frame.soundStream = soundStream.info; 1.3665 + } catch (e) { 1.3666 + } 1.3667 + break; 1.3668 + case SWF_TAG_CODE_SOUND_STREAM_BLOCK: 1.3669 + if (soundStream) { 1.3670 + frame.soundStreamBlock = soundStream.decode(tag.data); 1.3671 + } 1.3672 + break; 1.3673 + case SWF_TAG_CODE_FRAME_LABEL: 1.3674 + frame.labelName = tag.name; 1.3675 + break; 1.3676 + case SWF_TAG_CODE_PLACE_OBJECT: 1.3677 + case SWF_TAG_CODE_PLACE_OBJECT2: 1.3678 + case SWF_TAG_CODE_PLACE_OBJECT3: 1.3679 + depths[tag.depth] = tag; 1.3680 + break; 1.3681 + case SWF_TAG_CODE_REMOVE_OBJECT: 1.3682 + case SWF_TAG_CODE_REMOVE_OBJECT2: 1.3683 + depths[tag.depth] = null; 1.3684 + break; 1.3685 + case SWF_TAG_CODE_SHOW_FRAME: 1.3686 + frameIndex += tag.repeat; 1.3687 + frame.repeat = tag.repeat; 1.3688 + frame.depths = depths; 1.3689 + frames.push(frame); 1.3690 + depths = {}; 1.3691 + frame = { 1.3692 + type: 'frame' 1.3693 + }; 1.3694 + break; 1.3695 + } 1.3696 + } 1.3697 + symbol = { 1.3698 + type: 'sprite', 1.3699 + id: swfTag.id, 1.3700 + frameCount: swfTag.frameCount, 1.3701 + frames: frames, 1.3702 + frameScripts: frameScripts 1.3703 + }; 1.3704 + break; 1.3705 + case SWF_TAG_CODE_DEFINE_TEXT: 1.3706 + case SWF_TAG_CODE_DEFINE_TEXT2: 1.3707 + symbol = defineLabel(swfTag, symbols); 1.3708 + break; 1.3709 + } 1.3710 + if (!symbol) { 1.3711 + return { 1.3712 + command: 'error', 1.3713 + message: 'unknown symbol type: ' + swfTag.code 1.3714 + }; 1.3715 + } 1.3716 + symbol.isSymbol = true; 1.3717 + symbols[swfTag.id] = symbol; 1.3718 + return symbol; 1.3719 +} 1.3720 +function createParsingContext(commitData) { 1.3721 + var depths = {}; 1.3722 + var symbols = {}; 1.3723 + var frame = { 1.3724 + type: 'frame' 1.3725 + }; 1.3726 + var tagsProcessed = 0; 1.3727 + var soundStream = null; 1.3728 + var lastProgressSent = 0; 1.3729 + return { 1.3730 + onstart: function (result) { 1.3731 + commitData({ 1.3732 + command: 'init', 1.3733 + result: result 1.3734 + }); 1.3735 + }, 1.3736 + onprogress: function (result) { 1.3737 + if (Date.now() - lastProgressSent > 1000 / 24 || result.bytesLoaded === result.bytesTotal) { 1.3738 + commitData({ 1.3739 + command: 'progress', 1.3740 + result: { 1.3741 + bytesLoaded: result.bytesLoaded, 1.3742 + bytesTotal: result.bytesTotal 1.3743 + } 1.3744 + }); 1.3745 + lastProgressSent = Date.now(); 1.3746 + } 1.3747 + var tags = result.tags; 1.3748 + for (var n = tags.length; tagsProcessed < n; tagsProcessed++) { 1.3749 + var tag = tags[tagsProcessed]; 1.3750 + if ('id' in tag) { 1.3751 + var symbol = defineSymbol(tag, symbols); 1.3752 + commitData(symbol, symbol.transferables); 1.3753 + continue; 1.3754 + } 1.3755 + switch (tag.code) { 1.3756 + case SWF_TAG_CODE_DEFINE_SCENE_AND_FRAME_LABEL_DATA: 1.3757 + frame.sceneData = tag; 1.3758 + break; 1.3759 + case SWF_TAG_CODE_DEFINE_SCALING_GRID: 1.3760 + var symbolUpdate = { 1.3761 + isSymbol: true, 1.3762 + id: tag.symbolId, 1.3763 + updates: { 1.3764 + scale9Grid: tag.splitter 1.3765 + } 1.3766 + }; 1.3767 + commitData(symbolUpdate); 1.3768 + break; 1.3769 + case SWF_TAG_CODE_DO_ABC: 1.3770 + case SWF_TAG_CODE_DO_ABC_: 1.3771 + var abcBlocks = frame.abcBlocks; 1.3772 + if (abcBlocks) 1.3773 + abcBlocks.push({ 1.3774 + data: tag.data, 1.3775 + flags: tag.flags 1.3776 + }); 1.3777 + else 1.3778 + frame.abcBlocks = [ 1.3779 + { 1.3780 + data: tag.data, 1.3781 + flags: tag.flags 1.3782 + } 1.3783 + ]; 1.3784 + break; 1.3785 + case SWF_TAG_CODE_DO_ACTION: 1.3786 + var actionBlocks = frame.actionBlocks; 1.3787 + if (actionBlocks) 1.3788 + actionBlocks.push(tag.actionsData); 1.3789 + else 1.3790 + frame.actionBlocks = [ 1.3791 + tag.actionsData 1.3792 + ]; 1.3793 + break; 1.3794 + case SWF_TAG_CODE_DO_INIT_ACTION: 1.3795 + var initActionBlocks = frame.initActionBlocks || (frame.initActionBlocks = []); 1.3796 + initActionBlocks.push({ 1.3797 + spriteId: tag.spriteId, 1.3798 + actionsData: tag.actionsData 1.3799 + }); 1.3800 + break; 1.3801 + case SWF_TAG_CODE_START_SOUND: 1.3802 + var startSounds = frame.startSounds; 1.3803 + if (!startSounds) 1.3804 + frame.startSounds = startSounds = []; 1.3805 + startSounds.push(tag); 1.3806 + break; 1.3807 + case SWF_TAG_CODE_SOUND_STREAM_HEAD: 1.3808 + try { 1.3809 + soundStream = createSoundStream(tag); 1.3810 + frame.soundStream = soundStream.info; 1.3811 + } catch (e) { 1.3812 + } 1.3813 + break; 1.3814 + case SWF_TAG_CODE_SOUND_STREAM_BLOCK: 1.3815 + if (soundStream) { 1.3816 + frame.soundStreamBlock = soundStream.decode(tag.data); 1.3817 + } 1.3818 + break; 1.3819 + case SWF_TAG_CODE_EXPORT_ASSETS: 1.3820 + var exports = frame.exports; 1.3821 + if (exports) 1.3822 + frame.exports = exports.concat(tag.exports); 1.3823 + else 1.3824 + frame.exports = tag.exports.slice(0); 1.3825 + break; 1.3826 + case SWF_TAG_CODE_SYMBOL_CLASS: 1.3827 + var symbolClasses = frame.symbolClasses; 1.3828 + if (symbolClasses) 1.3829 + frame.symbolClasses = symbolClasses.concat(tag.exports); 1.3830 + else 1.3831 + frame.symbolClasses = tag.exports.slice(0); 1.3832 + break; 1.3833 + case SWF_TAG_CODE_FRAME_LABEL: 1.3834 + frame.labelName = tag.name; 1.3835 + break; 1.3836 + case SWF_TAG_CODE_PLACE_OBJECT: 1.3837 + case SWF_TAG_CODE_PLACE_OBJECT2: 1.3838 + case SWF_TAG_CODE_PLACE_OBJECT3: 1.3839 + depths[tag.depth] = tag; 1.3840 + break; 1.3841 + case SWF_TAG_CODE_REMOVE_OBJECT: 1.3842 + case SWF_TAG_CODE_REMOVE_OBJECT2: 1.3843 + depths[tag.depth] = null; 1.3844 + break; 1.3845 + case SWF_TAG_CODE_SET_BACKGROUND_COLOR: 1.3846 + frame.bgcolor = tag.color; 1.3847 + break; 1.3848 + case SWF_TAG_CODE_SHOW_FRAME: 1.3849 + frame.repeat = tag.repeat; 1.3850 + frame.depths = depths; 1.3851 + frame.complete = !(!tag.finalTag); 1.3852 + commitData(frame); 1.3853 + depths = {}; 1.3854 + frame = { 1.3855 + type: 'frame' 1.3856 + }; 1.3857 + break; 1.3858 + } 1.3859 + } 1.3860 + }, 1.3861 + oncomplete: function (result) { 1.3862 + commitData(result); 1.3863 + var stats; 1.3864 + if (typeof result.swfVersion === 'number') { 1.3865 + var bbox = result.bbox; 1.3866 + stats = { 1.3867 + topic: 'parseInfo', 1.3868 + parseTime: result.parseTime, 1.3869 + bytesTotal: result.bytesTotal, 1.3870 + swfVersion: result.swfVersion, 1.3871 + frameRate: result.frameRate, 1.3872 + width: (bbox.xMax - bbox.xMin) / 20, 1.3873 + height: (bbox.yMax - bbox.yMin) / 20, 1.3874 + isAvm2: !(!result.fileAttributes.doAbc) 1.3875 + }; 1.3876 + } 1.3877 + commitData({ 1.3878 + command: 'complete', 1.3879 + stats: stats 1.3880 + }); 1.3881 + }, 1.3882 + onexception: function (e) { 1.3883 + commitData({ 1.3884 + type: 'exception', 1.3885 + message: e.message, 1.3886 + stack: e.stack 1.3887 + }); 1.3888 + } 1.3889 + }; 1.3890 +} 1.3891 +function parseBytes(bytes, commitData) { 1.3892 + SWF.parse(bytes, createParsingContext(commitData)); 1.3893 +} 1.3894 +function ResourceLoader(scope) { 1.3895 + this.subscription = null; 1.3896 + var self = this; 1.3897 + if (!isWorker) { 1.3898 + this.messenger = { 1.3899 + postMessage: function (data) { 1.3900 + self.onmessage({ 1.3901 + data: data 1.3902 + }); 1.3903 + } 1.3904 + }; 1.3905 + } else { 1.3906 + this.messenger = scope; 1.3907 + scope.onmessage = function (event) { 1.3908 + self.listener(event.data); 1.3909 + }; 1.3910 + } 1.3911 +} 1.3912 +ResourceLoader.prototype = { 1.3913 + terminate: function () { 1.3914 + this.messenger = null; 1.3915 + this.listener = null; 1.3916 + }, 1.3917 + onmessage: function (event) { 1.3918 + this.listener(event.data); 1.3919 + }, 1.3920 + postMessage: function (data) { 1.3921 + this.listener && this.listener(data); 1.3922 + }, 1.3923 + listener: function (data) { 1.3924 + if (this.subscription) { 1.3925 + this.subscription.callback(data.data, data.progress); 1.3926 + } else if (data === 'pipe:') { 1.3927 + this.subscription = { 1.3928 + subscribe: function (callback) { 1.3929 + this.callback = callback; 1.3930 + } 1.3931 + }; 1.3932 + this.parseLoadedData(this.messenger, this.subscription); 1.3933 + } else { 1.3934 + this.parseLoadedData(this.messenger, data); 1.3935 + } 1.3936 + }, 1.3937 + parseLoadedData: function (loader, request, context) { 1.3938 + function commitData(data, transferables) { 1.3939 + try { 1.3940 + loader.postMessage(data, transferables); 1.3941 + } catch (ex) { 1.3942 + if (ex != 'DataCloneError') { 1.3943 + throw ex; 1.3944 + } 1.3945 + loader.postMessage(data); 1.3946 + } 1.3947 + } 1.3948 + if (request instanceof ArrayBuffer) { 1.3949 + parseBytes(request, commitData); 1.3950 + } else if ('subscribe' in request) { 1.3951 + var pipe = SWF.parseAsync(createParsingContext(commitData)); 1.3952 + request.subscribe(function (data, progress) { 1.3953 + if (data) { 1.3954 + pipe.push(data, progress); 1.3955 + } else { 1.3956 + pipe.close(); 1.3957 + } 1.3958 + }); 1.3959 + } else if (typeof FileReaderSync !== 'undefined') { 1.3960 + var reader = new FileReaderSync(); 1.3961 + var buffer = reader.readAsArrayBuffer(request); 1.3962 + parseBytes(buffer, commitData); 1.3963 + } else { 1.3964 + var reader = new FileReader(); 1.3965 + reader.onload = function () { 1.3966 + parseBytes(this.result, commitData); 1.3967 + }; 1.3968 + reader.readAsArrayBuffer(request); 1.3969 + } 1.3970 + } 1.3971 +}; 1.3972 +if (isWorker) { 1.3973 + var loader = new ResourceLoader(this); 1.3974 +} 1.3975 +var codeLengthOrder = [ 1.3976 + 16, 1.3977 + 17, 1.3978 + 18, 1.3979 + 0, 1.3980 + 8, 1.3981 + 7, 1.3982 + 9, 1.3983 + 6, 1.3984 + 10, 1.3985 + 5, 1.3986 + 11, 1.3987 + 4, 1.3988 + 12, 1.3989 + 3, 1.3990 + 13, 1.3991 + 2, 1.3992 + 14, 1.3993 + 1, 1.3994 + 15 1.3995 + ]; 1.3996 +var distanceCodes = []; 1.3997 +var distanceExtraBits = []; 1.3998 +for (var i = 0, j = 0, code = 1; i < 30; ++i) { 1.3999 + distanceCodes[i] = code; 1.4000 + code += 1 << (distanceExtraBits[i] = ~(~((j += i > 2 ? 1 : 0) / 2))); 1.4001 +} 1.4002 +var bitLengths = []; 1.4003 +for (var i = 0; i < 32; ++i) 1.4004 + bitLengths[i] = 5; 1.4005 +var fixedDistanceTable = makeHuffmanTable(bitLengths); 1.4006 +var lengthCodes = []; 1.4007 +var lengthExtraBits = []; 1.4008 +for (var i = 0, j = 0, code = 3; i < 29; ++i) { 1.4009 + lengthCodes[i] = code - (i == 28 ? 1 : 0); 1.4010 + code += 1 << (lengthExtraBits[i] = ~(~((j += i > 4 ? 1 : 0) / 4 % 6))); 1.4011 +} 1.4012 +for (var i = 0; i < 288; ++i) 1.4013 + bitLengths[i] = i < 144 || i > 279 ? 8 : i < 256 ? 9 : 7; 1.4014 +var fixedLiteralTable = makeHuffmanTable(bitLengths); 1.4015 +function makeHuffmanTable(bitLengths) { 1.4016 + var maxBits = Math.max.apply(null, bitLengths); 1.4017 + var numLengths = bitLengths.length; 1.4018 + var size = 1 << maxBits; 1.4019 + var codes = new Uint32Array(size); 1.4020 + for (var code = 0, len = 1, skip = 2; len <= maxBits; code <<= 1, ++len, skip <<= 1) { 1.4021 + for (var val = 0; val < numLengths; ++val) { 1.4022 + if (bitLengths[val] === len) { 1.4023 + var lsb = 0; 1.4024 + for (var i = 0; i < len; ++i) 1.4025 + lsb = lsb * 2 + (code >> i & 1); 1.4026 + for (var i = lsb; i < size; i += skip) 1.4027 + codes[i] = len << 16 | val; 1.4028 + ++code; 1.4029 + } 1.4030 + } 1.4031 + } 1.4032 + return { 1.4033 + codes: codes, 1.4034 + maxBits: maxBits 1.4035 + }; 1.4036 +} 1.4037 +function verifyDeflateHeader(bytes) { 1.4038 + var header = bytes[0] << 8 | bytes[1]; 1.4039 +} 1.4040 +function createInflatedStream(bytes, outputLength) { 1.4041 + verifyDeflateHeader(bytes); 1.4042 + var stream = new Stream(bytes, 2); 1.4043 + var output = { 1.4044 + data: new Uint8Array(outputLength), 1.4045 + available: 0, 1.4046 + completed: false 1.4047 + }; 1.4048 + var state = { 1.4049 + header: null, 1.4050 + distanceTable: null, 1.4051 + literalTable: null, 1.4052 + sym: null, 1.4053 + len: null, 1.4054 + sym2: null 1.4055 + }; 1.4056 + do { 1.4057 + inflateBlock(stream, output, state); 1.4058 + } while (!output.completed && stream.pos < stream.end); 1.4059 + return new Stream(output.data, 0, output.available); 1.4060 +} 1.4061 +var InflateNoDataError = {}; 1.4062 +function inflateBlock(stream, output, state) { 1.4063 + var header = state.header !== null ? state.header : state.header = readBits(stream.bytes, stream, 3); 1.4064 + switch (header >> 1) { 1.4065 + case 0: 1.4066 + stream.align(); 1.4067 + var pos = stream.pos; 1.4068 + if (stream.end - pos < 4) { 1.4069 + throw InflateNoDataError; 1.4070 + } 1.4071 + var len = stream.getUint16(pos, true); 1.4072 + var nlen = stream.getUint16(pos + 2, true); 1.4073 + if (stream.end - pos < 4 + len) { 1.4074 + throw InflateNoDataError; 1.4075 + } 1.4076 + var begin = pos + 4; 1.4077 + var end = stream.pos = begin + len; 1.4078 + var sbytes = stream.bytes, dbytes = output.data; 1.4079 + dbytes.set(sbytes.subarray(begin, end), output.available); 1.4080 + output.available += len; 1.4081 + break; 1.4082 + case 1: 1.4083 + inflate(stream, output, fixedLiteralTable, fixedDistanceTable, state); 1.4084 + break; 1.4085 + case 2: 1.4086 + var distanceTable, literalTable; 1.4087 + if (state.distanceTable !== null) { 1.4088 + distanceTable = state.distanceTable; 1.4089 + literalTable = state.literalTable; 1.4090 + } else { 1.4091 + var sbytes = stream.bytes; 1.4092 + var savedBufferPos = stream.pos; 1.4093 + var savedBitBuffer = stream.bitBuffer; 1.4094 + var savedBitLength = stream.bitLength; 1.4095 + var bitLengths = []; 1.4096 + var numLiteralCodes, numDistanceCodes; 1.4097 + try { 1.4098 + numLiteralCodes = readBits(sbytes, stream, 5) + 257; 1.4099 + numDistanceCodes = readBits(sbytes, stream, 5) + 1; 1.4100 + var numCodes = numLiteralCodes + numDistanceCodes; 1.4101 + var numLengthCodes = readBits(sbytes, stream, 4) + 4; 1.4102 + for (var i = 0; i < 19; ++i) 1.4103 + bitLengths[codeLengthOrder[i]] = i < numLengthCodes ? readBits(sbytes, stream, 3) : 0; 1.4104 + var codeLengthTable = makeHuffmanTable(bitLengths); 1.4105 + bitLengths = []; 1.4106 + var i = 0; 1.4107 + var prev = 0; 1.4108 + while (i < numCodes) { 1.4109 + var j = 1; 1.4110 + var sym = readCode(sbytes, stream, codeLengthTable); 1.4111 + switch (sym) { 1.4112 + case 16: 1.4113 + j = readBits(sbytes, stream, 2) + 3; 1.4114 + sym = prev; 1.4115 + break; 1.4116 + case 17: 1.4117 + j = readBits(sbytes, stream, 3) + 3; 1.4118 + sym = 0; 1.4119 + break; 1.4120 + case 18: 1.4121 + j = readBits(sbytes, stream, 7) + 11; 1.4122 + sym = 0; 1.4123 + break; 1.4124 + default: 1.4125 + prev = sym; 1.4126 + } 1.4127 + while (j--) 1.4128 + bitLengths[i++] = sym; 1.4129 + } 1.4130 + } catch (e) { 1.4131 + stream.pos = savedBufferPos; 1.4132 + stream.bitBuffer = savedBitBuffer; 1.4133 + stream.bitLength = savedBitLength; 1.4134 + throw e; 1.4135 + } 1.4136 + distanceTable = state.distanceTable = makeHuffmanTable(bitLengths.splice(numLiteralCodes, numDistanceCodes)); 1.4137 + literalTable = state.literalTable = makeHuffmanTable(bitLengths); 1.4138 + } 1.4139 + inflate(stream, output, literalTable, distanceTable, state); 1.4140 + state.distanceTable = null; 1.4141 + state.literalTable = null; 1.4142 + break; 1.4143 + default: 1.4144 + fail('unknown block type', 'inflate'); 1.4145 + } 1.4146 + state.header = null; 1.4147 + output.completed = !(!(header & 1)); 1.4148 +} 1.4149 +function readBits(bytes, stream, size) { 1.4150 + var bitBuffer = stream.bitBuffer; 1.4151 + var bitLength = stream.bitLength; 1.4152 + if (size > bitLength) { 1.4153 + var pos = stream.pos; 1.4154 + var end = stream.end; 1.4155 + do { 1.4156 + if (pos >= end) { 1.4157 + stream.pos = pos; 1.4158 + stream.bitBuffer = bitBuffer; 1.4159 + stream.bitLength = bitLength; 1.4160 + throw InflateNoDataError; 1.4161 + } 1.4162 + bitBuffer |= bytes[pos++] << bitLength; 1.4163 + bitLength += 8; 1.4164 + } while (size > bitLength); 1.4165 + stream.pos = pos; 1.4166 + } 1.4167 + stream.bitBuffer = bitBuffer >>> size; 1.4168 + stream.bitLength = bitLength - size; 1.4169 + return bitBuffer & (1 << size) - 1; 1.4170 +} 1.4171 +function inflate(stream, output, literalTable, distanceTable, state) { 1.4172 + var pos = output.available; 1.4173 + var dbytes = output.data; 1.4174 + var sbytes = stream.bytes; 1.4175 + var sym = state.sym !== null ? state.sym : readCode(sbytes, stream, literalTable); 1.4176 + while (sym !== 256) { 1.4177 + if (sym < 256) { 1.4178 + dbytes[pos++] = sym; 1.4179 + } else { 1.4180 + state.sym = sym; 1.4181 + sym -= 257; 1.4182 + var len = state.len !== null ? state.len : state.len = lengthCodes[sym] + readBits(sbytes, stream, lengthExtraBits[sym]); 1.4183 + var sym2 = state.sym2 !== null ? state.sym2 : state.sym2 = readCode(sbytes, stream, distanceTable); 1.4184 + var distance = distanceCodes[sym2] + readBits(sbytes, stream, distanceExtraBits[sym2]); 1.4185 + var i = pos - distance; 1.4186 + while (len--) 1.4187 + dbytes[pos++] = dbytes[i++]; 1.4188 + state.sym2 = null; 1.4189 + state.len = null; 1.4190 + state.sym = null; 1.4191 + } 1.4192 + output.available = pos; 1.4193 + sym = readCode(sbytes, stream, literalTable); 1.4194 + } 1.4195 +} 1.4196 +function readCode(bytes, stream, codeTable) { 1.4197 + var bitBuffer = stream.bitBuffer; 1.4198 + var bitLength = stream.bitLength; 1.4199 + var maxBits = codeTable.maxBits; 1.4200 + if (maxBits > bitLength) { 1.4201 + var pos = stream.pos; 1.4202 + var end = stream.end; 1.4203 + do { 1.4204 + if (pos >= end) { 1.4205 + stream.pos = pos; 1.4206 + stream.bitBuffer = bitBuffer; 1.4207 + stream.bitLength = bitLength; 1.4208 + throw InflateNoDataError; 1.4209 + } 1.4210 + bitBuffer |= bytes[pos++] << bitLength; 1.4211 + bitLength += 8; 1.4212 + } while (maxBits > bitLength); 1.4213 + stream.pos = pos; 1.4214 + } 1.4215 + var code = codeTable.codes[bitBuffer & (1 << maxBits) - 1]; 1.4216 + var len = code >> 16; 1.4217 + stream.bitBuffer = bitBuffer >>> len; 1.4218 + stream.bitLength = bitLength - len; 1.4219 + return code & 65535; 1.4220 +} 1.4221 +(function (global) { 1.4222 + global['createInflatedStream'] = createInflatedStream; 1.4223 +}(this)); 1.4224 +var StreamNoDataError = {}; 1.4225 +var Stream = function StreamClosure() { 1.4226 + function Stream_align() { 1.4227 + this.bitBuffer = this.bitLength = 0; 1.4228 + } 1.4229 + function Stream_ensure(size) { 1.4230 + if (this.pos + size > this.end) { 1.4231 + throw StreamNoDataError; 1.4232 + } 1.4233 + } 1.4234 + function Stream_remaining() { 1.4235 + return this.end - this.pos; 1.4236 + } 1.4237 + function Stream_substream(begin, end) { 1.4238 + var stream = new Stream(this.bytes); 1.4239 + stream.pos = begin; 1.4240 + stream.end = end; 1.4241 + return stream; 1.4242 + } 1.4243 + function Stream_push(data) { 1.4244 + var bytes = this.bytes; 1.4245 + var newBytesLength = this.end + data.length; 1.4246 + if (newBytesLength > bytes.length) { 1.4247 + throw 'stream buffer overfow'; 1.4248 + } 1.4249 + bytes.set(data, this.end); 1.4250 + this.end = newBytesLength; 1.4251 + } 1.4252 + function Stream(buffer, offset, length, maxLength) { 1.4253 + if (offset === undefined) 1.4254 + offset = 0; 1.4255 + if (buffer.buffer instanceof ArrayBuffer) { 1.4256 + offset += buffer.byteOffset; 1.4257 + buffer = buffer.buffer; 1.4258 + } 1.4259 + if (length === undefined) 1.4260 + length = buffer.byteLength - offset; 1.4261 + if (maxLength === undefined) 1.4262 + maxLength = length; 1.4263 + var bytes = new Uint8Array(buffer, offset, maxLength); 1.4264 + var stream = new DataView(buffer, offset, maxLength); 1.4265 + stream.bytes = bytes; 1.4266 + stream.pos = 0; 1.4267 + stream.end = length; 1.4268 + stream.bitBuffer = 0; 1.4269 + stream.bitLength = 0; 1.4270 + stream.align = Stream_align; 1.4271 + stream.ensure = Stream_ensure; 1.4272 + stream.remaining = Stream_remaining; 1.4273 + stream.substream = Stream_substream; 1.4274 + stream.push = Stream_push; 1.4275 + return stream; 1.4276 + } 1.4277 + return Stream; 1.4278 + }(); 1.4279 +(function (global) { 1.4280 + global['Stream'] = Stream; 1.4281 +}(this)); 1.4282 +function readSi8($bytes, $stream) { 1.4283 + return $stream.getInt8($stream.pos++); 1.4284 +} 1.4285 +function readSi16($bytes, $stream) { 1.4286 + return $stream.getInt16($stream.pos, $stream.pos += 2); 1.4287 +} 1.4288 +function readSi32($bytes, $stream) { 1.4289 + return $stream.getInt32($stream.pos, $stream.pos += 4); 1.4290 +} 1.4291 +function readUi8($bytes, $stream) { 1.4292 + return $bytes[$stream.pos++]; 1.4293 +} 1.4294 +function readUi16($bytes, $stream) { 1.4295 + return $stream.getUint16($stream.pos, $stream.pos += 2); 1.4296 +} 1.4297 +function readUi32($bytes, $stream) { 1.4298 + return $stream.getUint32($stream.pos, $stream.pos += 4); 1.4299 +} 1.4300 +function readFixed($bytes, $stream) { 1.4301 + return $stream.getInt32($stream.pos, $stream.pos += 4) / 65536; 1.4302 +} 1.4303 +function readFixed8($bytes, $stream) { 1.4304 + return $stream.getInt16($stream.pos, $stream.pos += 2) / 256; 1.4305 +} 1.4306 +function readFloat16($bytes, $stream) { 1.4307 + var ui16 = $stream.getUint16($stream.pos); 1.4308 + $stream.pos += 2; 1.4309 + var sign = ui16 >> 15 ? -1 : 1; 1.4310 + var exponent = (ui16 & 31744) >> 10; 1.4311 + var fraction = ui16 & 1023; 1.4312 + if (!exponent) 1.4313 + return sign * pow(2, -14) * (fraction / 1024); 1.4314 + if (exponent === 31) 1.4315 + return fraction ? NaN : sign * Infinity; 1.4316 + return sign * pow(2, exponent - 15) * (1 + fraction / 1024); 1.4317 +} 1.4318 +function readFloat($bytes, $stream) { 1.4319 + return $stream.getFloat32($stream.pos, $stream.pos += 4); 1.4320 +} 1.4321 +function readDouble($bytes, $stream) { 1.4322 + return $stream.getFloat64($stream.pos, $stream.pos += 8); 1.4323 +} 1.4324 +function readEncodedU32($bytes, $stream) { 1.4325 + var val = $bytes[$stream.pos++]; 1.4326 + if (!(val & 128)) 1.4327 + return val; 1.4328 + val |= $bytes[$stream.pos++] << 7; 1.4329 + if (!(val & 16384)) 1.4330 + return val; 1.4331 + val |= $bytes[$stream.pos++] << 14; 1.4332 + if (!(val & 2097152)) 1.4333 + return val; 1.4334 + val |= $bytes[$stream.pos++] << 21; 1.4335 + if (!(val & 268435456)) 1.4336 + return val; 1.4337 + return val | $bytes[$stream.pos++] << 28; 1.4338 +} 1.4339 +function readBool($bytes, $stream) { 1.4340 + return !(!$bytes[$stream.pos++]); 1.4341 +} 1.4342 +function align($bytes, $stream) { 1.4343 + $stream.align(); 1.4344 +} 1.4345 +function readSb($bytes, $stream, size) { 1.4346 + return readUb($bytes, $stream, size) << 32 - size >> 32 - size; 1.4347 +} 1.4348 +var masks = new Uint32Array(33); 1.4349 +for (var i = 1, mask = 0; i <= 32; ++i) 1.4350 + masks[i] = mask = mask << 1 | 1; 1.4351 +function readUb($bytes, $stream, size) { 1.4352 + var buffer = $stream.bitBuffer; 1.4353 + var bitlen = $stream.bitLength; 1.4354 + while (size > bitlen) { 1.4355 + buffer = buffer << 8 | $bytes[$stream.pos++]; 1.4356 + bitlen += 8; 1.4357 + } 1.4358 + bitlen -= size; 1.4359 + var val = buffer >>> bitlen & masks[size]; 1.4360 + $stream.bitBuffer = buffer; 1.4361 + $stream.bitLength = bitlen; 1.4362 + return val; 1.4363 +} 1.4364 +function readFb($bytes, $stream, size) { 1.4365 + return readSb($bytes, $stream, size) / 65536; 1.4366 +} 1.4367 +function readString($bytes, $stream, length) { 1.4368 + var codes = []; 1.4369 + var pos = $stream.pos; 1.4370 + if (length) { 1.4371 + codes = slice.call($bytes, pos, pos += length); 1.4372 + } else { 1.4373 + length = 0; 1.4374 + for (var code; code = $bytes[pos++]; length++) 1.4375 + codes[length] = code; 1.4376 + } 1.4377 + $stream.pos = pos; 1.4378 + var numChunks = length / 65536; 1.4379 + var str = ''; 1.4380 + for (var i = 0; i < numChunks; ++i) { 1.4381 + var begin = i * 65536; 1.4382 + var end = begin + 65536; 1.4383 + var chunk = codes.slice(begin, end); 1.4384 + str += fromCharCode.apply(null, chunk); 1.4385 + } 1.4386 + return decodeURIComponent(escape(str.replace('\0', '', 'g'))); 1.4387 +} 1.4388 +function readBinary($bytes, $stream, size) { 1.4389 + return $bytes.subarray($stream.pos, $stream.pos = size ? $stream.pos + size : $stream.end); 1.4390 +} 1.4391 +(function (global) { 1.4392 + global['readSi8'] = readSi8; 1.4393 + global['readUi16'] = readUi16; 1.4394 + global['readUi32'] = readUi32; 1.4395 +}(this)); 1.4396 +var tagHandler = function (global) { 1.4397 + function defineShape($bytes, $stream, $, swfVersion, tagCode) { 1.4398 + $ || ($ = {}); 1.4399 + $.id = readUi16($bytes, $stream); 1.4400 + var $0 = $.bbox = {}; 1.4401 + bbox($bytes, $stream, $0, swfVersion, tagCode); 1.4402 + var isMorph = $.isMorph = tagCode === 46 || tagCode === 84; 1.4403 + if (isMorph) { 1.4404 + var $1 = $.bboxMorph = {}; 1.4405 + bbox($bytes, $stream, $1, swfVersion, tagCode); 1.4406 + } 1.4407 + var hasStrokes = $.hasStrokes = tagCode === 83 || tagCode === 84; 1.4408 + if (hasStrokes) { 1.4409 + var $2 = $.strokeBbox = {}; 1.4410 + bbox($bytes, $stream, $2, swfVersion, tagCode); 1.4411 + if (isMorph) { 1.4412 + var $3 = $.strokeBboxMorph = {}; 1.4413 + bbox($bytes, $stream, $3, swfVersion, tagCode); 1.4414 + } 1.4415 + var reserved = readUb($bytes, $stream, 5); 1.4416 + $.fillWinding = readUb($bytes, $stream, 1); 1.4417 + $.nonScalingStrokes = readUb($bytes, $stream, 1); 1.4418 + $.scalingStrokes = readUb($bytes, $stream, 1); 1.4419 + } 1.4420 + if (isMorph) { 1.4421 + $.offsetMorph = readUi32($bytes, $stream); 1.4422 + morphShapeWithStyle($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.4423 + } else { 1.4424 + shapeWithStyle($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.4425 + } 1.4426 + return $; 1.4427 + } 1.4428 + function placeObject($bytes, $stream, $, swfVersion, tagCode) { 1.4429 + var flags, hasEvents, clip, hasName, hasRatio, hasCxform, hasMatrix, place; 1.4430 + var move, hasBackgroundColor, hasVisibility, hasImage, hasClassName, cache; 1.4431 + var blend, hasFilters, eoe; 1.4432 + $ || ($ = {}); 1.4433 + if (tagCode > 4) { 1.4434 + if (tagCode > 26) { 1.4435 + flags = readUi16($bytes, $stream); 1.4436 + } else { 1.4437 + flags = readUi8($bytes, $stream); 1.4438 + } 1.4439 + hasEvents = $.hasEvents = flags >> 7 & 1; 1.4440 + clip = $.clip = flags >> 6 & 1; 1.4441 + hasName = $.hasName = flags >> 5 & 1; 1.4442 + hasRatio = $.hasRatio = flags >> 4 & 1; 1.4443 + hasCxform = $.hasCxform = flags >> 3 & 1; 1.4444 + hasMatrix = $.hasMatrix = flags >> 2 & 1; 1.4445 + place = $.place = flags >> 1 & 1; 1.4446 + move = $.move = flags & 1; 1.4447 + if (tagCode === 70) { 1.4448 + hasBackgroundColor = $.hasBackgroundColor = flags >> 15 & 1; 1.4449 + hasVisibility = $.hasVisibility = flags >> 14 & 1; 1.4450 + hasImage = $.hasImage = flags >> 12 & 1; 1.4451 + hasClassName = $.hasClassName = flags >> 11 & 1; 1.4452 + cache = $.cache = flags >> 10 & 1; 1.4453 + blend = $.blend = flags >> 9 & 1; 1.4454 + hasFilters = $.hasFilters = flags >> 8 & 1; 1.4455 + } else { 1.4456 + cache = $.cache = 0; 1.4457 + blend = $.blend = 0; 1.4458 + hasFilters = $.hasFilters = 0; 1.4459 + } 1.4460 + $.depth = readUi16($bytes, $stream); 1.4461 + if (hasClassName) { 1.4462 + $.className = readString($bytes, $stream, 0); 1.4463 + } 1.4464 + if (place) { 1.4465 + $.symbolId = readUi16($bytes, $stream); 1.4466 + } 1.4467 + if (hasMatrix) { 1.4468 + var $0 = $.matrix = {}; 1.4469 + matrix($bytes, $stream, $0, swfVersion, tagCode); 1.4470 + } 1.4471 + if (hasCxform) { 1.4472 + var $1 = $.cxform = {}; 1.4473 + cxform($bytes, $stream, $1, swfVersion, tagCode); 1.4474 + } 1.4475 + if (hasRatio) { 1.4476 + $.ratio = readUi16($bytes, $stream); 1.4477 + } 1.4478 + if (hasName) { 1.4479 + $.name = readString($bytes, $stream, 0); 1.4480 + } 1.4481 + if (clip) { 1.4482 + $.clipDepth = readUi16($bytes, $stream); 1.4483 + } 1.4484 + if (hasFilters) { 1.4485 + var count = readUi8($bytes, $stream); 1.4486 + var $2 = $.filters = []; 1.4487 + var $3 = count; 1.4488 + while ($3--) { 1.4489 + var $4 = {}; 1.4490 + anyFilter($bytes, $stream, $4, swfVersion, tagCode); 1.4491 + $2.push($4); 1.4492 + } 1.4493 + } 1.4494 + if (blend) { 1.4495 + $.blendMode = readUi8($bytes, $stream); 1.4496 + } 1.4497 + if (cache) { 1.4498 + $.bmpCache = readUi8($bytes, $stream); 1.4499 + } 1.4500 + if (hasEvents) { 1.4501 + var reserved = readUi16($bytes, $stream); 1.4502 + if (swfVersion >= 6) { 1.4503 + var allFlags = readUi32($bytes, $stream); 1.4504 + } else { 1.4505 + var allFlags = readUi16($bytes, $stream); 1.4506 + } 1.4507 + var $28 = $.events = []; 1.4508 + do { 1.4509 + var $29 = {}; 1.4510 + var temp = events($bytes, $stream, $29, swfVersion, tagCode); 1.4511 + eoe = temp.eoe; 1.4512 + $28.push($29); 1.4513 + } while (!eoe); 1.4514 + } 1.4515 + if (hasBackgroundColor) { 1.4516 + var $126 = $.backgroundColor = {}; 1.4517 + argb($bytes, $stream, $126, swfVersion, tagCode); 1.4518 + } 1.4519 + if (hasVisibility) { 1.4520 + $.visibility = readUi8($bytes, $stream); 1.4521 + } 1.4522 + } else { 1.4523 + $.place = 1; 1.4524 + $.symbolId = readUi16($bytes, $stream); 1.4525 + $.depth = readUi16($bytes, $stream); 1.4526 + $.hasMatrix = 1; 1.4527 + var $30 = $.matrix = {}; 1.4528 + matrix($bytes, $stream, $30, swfVersion, tagCode); 1.4529 + if ($stream.remaining()) { 1.4530 + $.hasCxform = 1; 1.4531 + var $31 = $.cxform = {}; 1.4532 + cxform($bytes, $stream, $31, swfVersion, tagCode); 1.4533 + } 1.4534 + } 1.4535 + return $; 1.4536 + } 1.4537 + function removeObject($bytes, $stream, $, swfVersion, tagCode) { 1.4538 + $ || ($ = {}); 1.4539 + if (tagCode === 5) { 1.4540 + $.symbolId = readUi16($bytes, $stream); 1.4541 + } 1.4542 + $.depth = readUi16($bytes, $stream); 1.4543 + return $; 1.4544 + } 1.4545 + function defineImage($bytes, $stream, $, swfVersion, tagCode) { 1.4546 + var imgData; 1.4547 + $ || ($ = {}); 1.4548 + $.id = readUi16($bytes, $stream); 1.4549 + if (tagCode > 21) { 1.4550 + var alphaDataOffset = readUi32($bytes, $stream); 1.4551 + if (tagCode === 90) { 1.4552 + $.deblock = readFixed8($bytes, $stream); 1.4553 + } 1.4554 + imgData = $.imgData = readBinary($bytes, $stream, alphaDataOffset); 1.4555 + $.alphaData = readBinary($bytes, $stream, 0); 1.4556 + } else { 1.4557 + imgData = $.imgData = readBinary($bytes, $stream, 0); 1.4558 + } 1.4559 + switch (imgData[0] << 8 | imgData[1]) { 1.4560 + case 65496: 1.4561 + case 65497: 1.4562 + $.mimeType = 'image/jpeg'; 1.4563 + break; 1.4564 + case 35152: 1.4565 + $.mimeType = 'image/png'; 1.4566 + break; 1.4567 + case 18249: 1.4568 + $.mimeType = 'image/gif'; 1.4569 + break; 1.4570 + default: 1.4571 + $.mimeType = 'application/octet-stream'; 1.4572 + } 1.4573 + if (tagCode === 6) { 1.4574 + $.incomplete = 1; 1.4575 + } 1.4576 + return $; 1.4577 + } 1.4578 + function defineButton($bytes, $stream, $, swfVersion, tagCode) { 1.4579 + var eob, hasFilters, count, blend; 1.4580 + $ || ($ = {}); 1.4581 + $.id = readUi16($bytes, $stream); 1.4582 + if (tagCode == 7) { 1.4583 + var $0 = $.characters = []; 1.4584 + do { 1.4585 + var $1 = {}; 1.4586 + var temp = button($bytes, $stream, $1, swfVersion, tagCode); 1.4587 + eob = temp.eob; 1.4588 + $0.push($1); 1.4589 + } while (!eob); 1.4590 + $.actionsData = readBinary($bytes, $stream, 0); 1.4591 + } else { 1.4592 + var trackFlags = readUi8($bytes, $stream); 1.4593 + $.trackAsMenu = trackFlags >> 7 & 1; 1.4594 + var actionOffset = readUi16($bytes, $stream); 1.4595 + var $28 = $.characters = []; 1.4596 + do { 1.4597 + var $29 = {}; 1.4598 + var flags = readUi8($bytes, $stream); 1.4599 + var eob = $29.eob = !flags; 1.4600 + if (swfVersion >= 8) { 1.4601 + blend = $29.blend = flags >> 5 & 1; 1.4602 + hasFilters = $29.hasFilters = flags >> 4 & 1; 1.4603 + } else { 1.4604 + blend = $29.blend = 0; 1.4605 + hasFilters = $29.hasFilters = 0; 1.4606 + } 1.4607 + $29.stateHitTest = flags >> 3 & 1; 1.4608 + $29.stateDown = flags >> 2 & 1; 1.4609 + $29.stateOver = flags >> 1 & 1; 1.4610 + $29.stateUp = flags & 1; 1.4611 + if (!eob) { 1.4612 + $29.symbolId = readUi16($bytes, $stream); 1.4613 + $29.depth = readUi16($bytes, $stream); 1.4614 + var $30 = $29.matrix = {}; 1.4615 + matrix($bytes, $stream, $30, swfVersion, tagCode); 1.4616 + if (tagCode === 34) { 1.4617 + var $31 = $29.cxform = {}; 1.4618 + cxform($bytes, $stream, $31, swfVersion, tagCode); 1.4619 + } 1.4620 + if (hasFilters) { 1.4621 + var count = readUi8($bytes, $stream); 1.4622 + var $2 = $.filters = []; 1.4623 + var $3 = count; 1.4624 + while ($3--) { 1.4625 + var $4 = {}; 1.4626 + anyFilter($bytes, $stream, $4, swfVersion, tagCode); 1.4627 + $2.push($4); 1.4628 + } 1.4629 + } 1.4630 + if (blend) { 1.4631 + $29.blendMode = readUi8($bytes, $stream); 1.4632 + } 1.4633 + } 1.4634 + $28.push($29); 1.4635 + } while (!eob); 1.4636 + if (!(!actionOffset)) { 1.4637 + var $56 = $.buttonActions = []; 1.4638 + do { 1.4639 + var $57 = {}; 1.4640 + buttonCondAction($bytes, $stream, $57, swfVersion, tagCode); 1.4641 + $56.push($57); 1.4642 + } while ($stream.remaining() > 0); 1.4643 + } 1.4644 + } 1.4645 + return $; 1.4646 + } 1.4647 + function defineJPEGTables($bytes, $stream, $, swfVersion, tagCode) { 1.4648 + $ || ($ = {}); 1.4649 + $.id = 0; 1.4650 + $.imgData = readBinary($bytes, $stream, 0); 1.4651 + $.mimeType = 'application/octet-stream'; 1.4652 + return $; 1.4653 + } 1.4654 + function setBackgroundColor($bytes, $stream, $, swfVersion, tagCode) { 1.4655 + $ || ($ = {}); 1.4656 + var $0 = $.color = {}; 1.4657 + rgb($bytes, $stream, $0, swfVersion, tagCode); 1.4658 + return $; 1.4659 + } 1.4660 + function defineBinaryData($bytes, $stream, $, swfVersion, tagCode) { 1.4661 + $ || ($ = {}); 1.4662 + $.id = readUi16($bytes, $stream); 1.4663 + var reserved = readUi32($bytes, $stream); 1.4664 + $.data = readBinary($bytes, $stream, 0); 1.4665 + return $; 1.4666 + } 1.4667 + function defineFont($bytes, $stream, $, swfVersion, tagCode) { 1.4668 + $ || ($ = {}); 1.4669 + $.id = readUi16($bytes, $stream); 1.4670 + var firstOffset = readUi16($bytes, $stream); 1.4671 + var glyphCount = $.glyphCount = firstOffset / 2; 1.4672 + var restOffsets = []; 1.4673 + var $0 = glyphCount - 1; 1.4674 + while ($0--) { 1.4675 + restOffsets.push(readUi16($bytes, $stream)); 1.4676 + } 1.4677 + $.offsets = [ 1.4678 + firstOffset 1.4679 + ].concat(restOffsets); 1.4680 + var $1 = $.glyphs = []; 1.4681 + var $2 = glyphCount; 1.4682 + while ($2--) { 1.4683 + var $3 = {}; 1.4684 + shape($bytes, $stream, $3, swfVersion, tagCode); 1.4685 + $1.push($3); 1.4686 + } 1.4687 + return $; 1.4688 + } 1.4689 + function defineLabel($bytes, $stream, $, swfVersion, tagCode) { 1.4690 + var eot; 1.4691 + $ || ($ = {}); 1.4692 + $.id = readUi16($bytes, $stream); 1.4693 + var $0 = $.bbox = {}; 1.4694 + bbox($bytes, $stream, $0, swfVersion, tagCode); 1.4695 + var $1 = $.matrix = {}; 1.4696 + matrix($bytes, $stream, $1, swfVersion, tagCode); 1.4697 + var glyphBits = $.glyphBits = readUi8($bytes, $stream); 1.4698 + var advanceBits = $.advanceBits = readUi8($bytes, $stream); 1.4699 + var $2 = $.records = []; 1.4700 + do { 1.4701 + var $3 = {}; 1.4702 + var temp = textRecord($bytes, $stream, $3, swfVersion, tagCode, glyphBits, advanceBits); 1.4703 + eot = temp.eot; 1.4704 + $2.push($3); 1.4705 + } while (!eot); 1.4706 + return $; 1.4707 + } 1.4708 + function doAction($bytes, $stream, $, swfVersion, tagCode) { 1.4709 + $ || ($ = {}); 1.4710 + if (tagCode === 59) { 1.4711 + $.spriteId = readUi16($bytes, $stream); 1.4712 + } 1.4713 + $.actionsData = readBinary($bytes, $stream, 0); 1.4714 + return $; 1.4715 + } 1.4716 + function defineSound($bytes, $stream, $, swfVersion, tagCode) { 1.4717 + $ || ($ = {}); 1.4718 + $.id = readUi16($bytes, $stream); 1.4719 + var soundFlags = readUi8($bytes, $stream); 1.4720 + $.soundFormat = soundFlags >> 4 & 15; 1.4721 + $.soundRate = soundFlags >> 2 & 3; 1.4722 + $.soundSize = soundFlags >> 1 & 1; 1.4723 + $.soundType = soundFlags & 1; 1.4724 + $.samplesCount = readUi32($bytes, $stream); 1.4725 + $.soundData = readBinary($bytes, $stream, 0); 1.4726 + return $; 1.4727 + } 1.4728 + function startSound($bytes, $stream, $, swfVersion, tagCode) { 1.4729 + $ || ($ = {}); 1.4730 + if (tagCode == 15) { 1.4731 + $.soundId = readUi16($bytes, $stream); 1.4732 + } 1.4733 + if (tagCode == 89) { 1.4734 + $.soundClassName = readString($bytes, $stream, 0); 1.4735 + } 1.4736 + var $0 = $.soundInfo = {}; 1.4737 + soundInfo($bytes, $stream, $0, swfVersion, tagCode); 1.4738 + return $; 1.4739 + } 1.4740 + function soundStreamHead($bytes, $stream, $, swfVersion, tagCode) { 1.4741 + $ || ($ = {}); 1.4742 + var playbackFlags = readUi8($bytes, $stream); 1.4743 + $.playbackRate = playbackFlags >> 2 & 3; 1.4744 + $.playbackSize = playbackFlags >> 1 & 1; 1.4745 + $.playbackType = playbackFlags & 1; 1.4746 + var streamFlags = readUi8($bytes, $stream); 1.4747 + var streamCompression = $.streamCompression = streamFlags >> 4 & 15; 1.4748 + $.streamRate = streamFlags >> 2 & 3; 1.4749 + $.streamSize = streamFlags >> 1 & 1; 1.4750 + $.streamType = streamFlags & 1; 1.4751 + $.samplesCount = readUi32($bytes, $stream); 1.4752 + if (streamCompression == 2) { 1.4753 + $.latencySeek = readSi16($bytes, $stream); 1.4754 + } 1.4755 + return $; 1.4756 + } 1.4757 + function soundStreamBlock($bytes, $stream, $, swfVersion, tagCode) { 1.4758 + $ || ($ = {}); 1.4759 + $.data = readBinary($bytes, $stream, 0); 1.4760 + return $; 1.4761 + } 1.4762 + function defineBitmap($bytes, $stream, $, swfVersion, tagCode) { 1.4763 + $ || ($ = {}); 1.4764 + $.id = readUi16($bytes, $stream); 1.4765 + var format = $.format = readUi8($bytes, $stream); 1.4766 + $.width = readUi16($bytes, $stream); 1.4767 + $.height = readUi16($bytes, $stream); 1.4768 + $.hasAlpha = tagCode === 36; 1.4769 + if (format === 3) { 1.4770 + $.colorTableSize = readUi8($bytes, $stream); 1.4771 + } 1.4772 + $.bmpData = readBinary($bytes, $stream, 0); 1.4773 + return $; 1.4774 + } 1.4775 + function defineText($bytes, $stream, $, swfVersion, tagCode) { 1.4776 + $ || ($ = {}); 1.4777 + $.id = readUi16($bytes, $stream); 1.4778 + var $0 = $.bbox = {}; 1.4779 + bbox($bytes, $stream, $0, swfVersion, tagCode); 1.4780 + var flags = readUi16($bytes, $stream); 1.4781 + var hasText = $.hasText = flags >> 7 & 1; 1.4782 + $.wordWrap = flags >> 6 & 1; 1.4783 + $.multiline = flags >> 5 & 1; 1.4784 + $.password = flags >> 4 & 1; 1.4785 + $.readonly = flags >> 3 & 1; 1.4786 + var hasColor = $.hasColor = flags >> 2 & 1; 1.4787 + var hasMaxLength = $.hasMaxLength = flags >> 1 & 1; 1.4788 + var hasFont = $.hasFont = flags & 1; 1.4789 + var hasFontClass = $.hasFontClass = flags >> 15 & 1; 1.4790 + $.autoSize = flags >> 14 & 1; 1.4791 + var hasLayout = $.hasLayout = flags >> 13 & 1; 1.4792 + $.noSelect = flags >> 12 & 1; 1.4793 + $.border = flags >> 11 & 1; 1.4794 + $.wasStatic = flags >> 10 & 1; 1.4795 + $.html = flags >> 9 & 1; 1.4796 + $.useOutlines = flags >> 8 & 1; 1.4797 + if (hasFont) { 1.4798 + $.fontId = readUi16($bytes, $stream); 1.4799 + } 1.4800 + if (hasFontClass) { 1.4801 + $.fontClass = readString($bytes, $stream, 0); 1.4802 + } 1.4803 + if (hasFont) { 1.4804 + $.fontHeight = readUi16($bytes, $stream); 1.4805 + } 1.4806 + if (hasColor) { 1.4807 + var $1 = $.color = {}; 1.4808 + rgba($bytes, $stream, $1, swfVersion, tagCode); 1.4809 + } 1.4810 + if (hasMaxLength) { 1.4811 + $.maxLength = readUi16($bytes, $stream); 1.4812 + } 1.4813 + if (hasLayout) { 1.4814 + $.align = readUi8($bytes, $stream); 1.4815 + $.leftMargin = readUi16($bytes, $stream); 1.4816 + $.rightMargin = readUi16($bytes, $stream); 1.4817 + $.indent = readSi16($bytes, $stream); 1.4818 + $.leading = readSi16($bytes, $stream); 1.4819 + } 1.4820 + $.variableName = readString($bytes, $stream, 0); 1.4821 + if (hasText) { 1.4822 + $.initialText = readString($bytes, $stream, 0); 1.4823 + } 1.4824 + return $; 1.4825 + } 1.4826 + function frameLabel($bytes, $stream, $, swfVersion, tagCode) { 1.4827 + $ || ($ = {}); 1.4828 + $.name = readString($bytes, $stream, 0); 1.4829 + return $; 1.4830 + } 1.4831 + function defineFont2($bytes, $stream, $, swfVersion, tagCode) { 1.4832 + $ || ($ = {}); 1.4833 + $.id = readUi16($bytes, $stream); 1.4834 + var hasLayout = $.hasLayout = readUb($bytes, $stream, 1); 1.4835 + if (swfVersion > 5) { 1.4836 + $.shiftJis = readUb($bytes, $stream, 1); 1.4837 + } else { 1.4838 + var reserved = readUb($bytes, $stream, 1); 1.4839 + } 1.4840 + $.smallText = readUb($bytes, $stream, 1); 1.4841 + $.ansi = readUb($bytes, $stream, 1); 1.4842 + var wideOffset = $.wideOffset = readUb($bytes, $stream, 1); 1.4843 + var wide = $.wide = readUb($bytes, $stream, 1); 1.4844 + $.italic = readUb($bytes, $stream, 1); 1.4845 + $.bold = readUb($bytes, $stream, 1); 1.4846 + if (swfVersion > 5) { 1.4847 + $.language = readUi8($bytes, $stream); 1.4848 + } else { 1.4849 + var reserved = readUi8($bytes, $stream); 1.4850 + $.language = 0; 1.4851 + } 1.4852 + var nameLength = readUi8($bytes, $stream); 1.4853 + $.name = readString($bytes, $stream, nameLength); 1.4854 + if (tagCode === 75) { 1.4855 + $.resolution = 20; 1.4856 + } 1.4857 + var glyphCount = $.glyphCount = readUi16($bytes, $stream); 1.4858 + if (wideOffset) { 1.4859 + var $0 = $.offsets = []; 1.4860 + var $1 = glyphCount; 1.4861 + while ($1--) { 1.4862 + $0.push(readUi32($bytes, $stream)); 1.4863 + } 1.4864 + $.mapOffset = readUi32($bytes, $stream); 1.4865 + } else { 1.4866 + var $2 = $.offsets = []; 1.4867 + var $3 = glyphCount; 1.4868 + while ($3--) { 1.4869 + $2.push(readUi16($bytes, $stream)); 1.4870 + } 1.4871 + $.mapOffset = readUi16($bytes, $stream); 1.4872 + } 1.4873 + var $4 = $.glyphs = []; 1.4874 + var $5 = glyphCount; 1.4875 + while ($5--) { 1.4876 + var $6 = {}; 1.4877 + shape($bytes, $stream, $6, swfVersion, tagCode); 1.4878 + $4.push($6); 1.4879 + } 1.4880 + if (wide) { 1.4881 + var $47 = $.codes = []; 1.4882 + var $48 = glyphCount; 1.4883 + while ($48--) { 1.4884 + $47.push(readUi16($bytes, $stream)); 1.4885 + } 1.4886 + } else { 1.4887 + var $49 = $.codes = []; 1.4888 + var $50 = glyphCount; 1.4889 + while ($50--) { 1.4890 + $49.push(readUi8($bytes, $stream)); 1.4891 + } 1.4892 + } 1.4893 + if (hasLayout) { 1.4894 + $.ascent = readUi16($bytes, $stream); 1.4895 + $.descent = readUi16($bytes, $stream); 1.4896 + $.leading = readSi16($bytes, $stream); 1.4897 + var $51 = $.advance = []; 1.4898 + var $52 = glyphCount; 1.4899 + while ($52--) { 1.4900 + $51.push(readSi16($bytes, $stream)); 1.4901 + } 1.4902 + var $53 = $.bbox = []; 1.4903 + var $54 = glyphCount; 1.4904 + while ($54--) { 1.4905 + var $55 = {}; 1.4906 + bbox($bytes, $stream, $55, swfVersion, tagCode); 1.4907 + $53.push($55); 1.4908 + } 1.4909 + var kerningCount = readUi16($bytes, $stream); 1.4910 + var $56 = $.kerning = []; 1.4911 + var $57 = kerningCount; 1.4912 + while ($57--) { 1.4913 + var $58 = {}; 1.4914 + kerning($bytes, $stream, $58, swfVersion, tagCode, wide); 1.4915 + $56.push($58); 1.4916 + } 1.4917 + } 1.4918 + return $; 1.4919 + } 1.4920 + function fileAttributes($bytes, $stream, $, swfVersion, tagCode) { 1.4921 + $ || ($ = {}); 1.4922 + var reserved = readUb($bytes, $stream, 1); 1.4923 + $.useDirectBlit = readUb($bytes, $stream, 1); 1.4924 + $.useGpu = readUb($bytes, $stream, 1); 1.4925 + $.hasMetadata = readUb($bytes, $stream, 1); 1.4926 + $.doAbc = readUb($bytes, $stream, 1); 1.4927 + $.noCrossDomainCaching = readUb($bytes, $stream, 1); 1.4928 + $.relativeUrls = readUb($bytes, $stream, 1); 1.4929 + $.network = readUb($bytes, $stream, 1); 1.4930 + var pad = readUb($bytes, $stream, 24); 1.4931 + return $; 1.4932 + } 1.4933 + function doABC($bytes, $stream, $, swfVersion, tagCode) { 1.4934 + $ || ($ = {}); 1.4935 + if (tagCode === 82) { 1.4936 + $.flags = readUi32($bytes, $stream); 1.4937 + } else { 1.4938 + $.flags = 0; 1.4939 + } 1.4940 + if (tagCode === 82) { 1.4941 + $.name = readString($bytes, $stream, 0); 1.4942 + } else { 1.4943 + $.name = ''; 1.4944 + } 1.4945 + $.data = readBinary($bytes, $stream, 0); 1.4946 + return $; 1.4947 + } 1.4948 + function exportAssets($bytes, $stream, $, swfVersion, tagCode) { 1.4949 + $ || ($ = {}); 1.4950 + var exportsCount = readUi16($bytes, $stream); 1.4951 + var $0 = $.exports = []; 1.4952 + var $1 = exportsCount; 1.4953 + while ($1--) { 1.4954 + var $2 = {}; 1.4955 + $2.symbolId = readUi16($bytes, $stream); 1.4956 + $2.className = readString($bytes, $stream, 0); 1.4957 + $0.push($2); 1.4958 + } 1.4959 + return $; 1.4960 + } 1.4961 + function symbolClass($bytes, $stream, $, swfVersion, tagCode) { 1.4962 + $ || ($ = {}); 1.4963 + var symbolCount = readUi16($bytes, $stream); 1.4964 + var $0 = $.exports = []; 1.4965 + var $1 = symbolCount; 1.4966 + while ($1--) { 1.4967 + var $2 = {}; 1.4968 + $2.symbolId = readUi16($bytes, $stream); 1.4969 + $2.className = readString($bytes, $stream, 0); 1.4970 + $0.push($2); 1.4971 + } 1.4972 + return $; 1.4973 + } 1.4974 + function defineScalingGrid($bytes, $stream, $, swfVersion, tagCode) { 1.4975 + $ || ($ = {}); 1.4976 + $.symbolId = readUi16($bytes, $stream); 1.4977 + var $0 = $.splitter = {}; 1.4978 + bbox($bytes, $stream, $0, swfVersion, tagCode); 1.4979 + return $; 1.4980 + } 1.4981 + function defineScene($bytes, $stream, $, swfVersion, tagCode) { 1.4982 + $ || ($ = {}); 1.4983 + var sceneCount = readEncodedU32($bytes, $stream); 1.4984 + var $0 = $.scenes = []; 1.4985 + var $1 = sceneCount; 1.4986 + while ($1--) { 1.4987 + var $2 = {}; 1.4988 + $2.offset = readEncodedU32($bytes, $stream); 1.4989 + $2.name = readString($bytes, $stream, 0); 1.4990 + $0.push($2); 1.4991 + } 1.4992 + var labelCount = readEncodedU32($bytes, $stream); 1.4993 + var $3 = $.labels = []; 1.4994 + var $4 = labelCount; 1.4995 + while ($4--) { 1.4996 + var $5 = {}; 1.4997 + $5.frame = readEncodedU32($bytes, $stream); 1.4998 + $5.name = readString($bytes, $stream, 0); 1.4999 + $3.push($5); 1.5000 + } 1.5001 + return $; 1.5002 + } 1.5003 + function bbox($bytes, $stream, $, swfVersion, tagCode) { 1.5004 + align($bytes, $stream); 1.5005 + var bits = readUb($bytes, $stream, 5); 1.5006 + var xMin = readSb($bytes, $stream, bits); 1.5007 + var xMax = readSb($bytes, $stream, bits); 1.5008 + var yMin = readSb($bytes, $stream, bits); 1.5009 + var yMax = readSb($bytes, $stream, bits); 1.5010 + $.xMin = xMin; 1.5011 + $.xMax = xMax; 1.5012 + $.yMin = yMin; 1.5013 + $.yMax = yMax; 1.5014 + align($bytes, $stream); 1.5015 + } 1.5016 + function rgb($bytes, $stream, $, swfVersion, tagCode) { 1.5017 + $.red = readUi8($bytes, $stream); 1.5018 + $.green = readUi8($bytes, $stream); 1.5019 + $.blue = readUi8($bytes, $stream); 1.5020 + $.alpha = 255; 1.5021 + return; 1.5022 + } 1.5023 + function rgba($bytes, $stream, $, swfVersion, tagCode) { 1.5024 + $.red = readUi8($bytes, $stream); 1.5025 + $.green = readUi8($bytes, $stream); 1.5026 + $.blue = readUi8($bytes, $stream); 1.5027 + $.alpha = readUi8($bytes, $stream); 1.5028 + return; 1.5029 + } 1.5030 + function argb($bytes, $stream, $, swfVersion, tagCode) { 1.5031 + $.alpha = readUi8($bytes, $stream); 1.5032 + $.red = readUi8($bytes, $stream); 1.5033 + $.green = readUi8($bytes, $stream); 1.5034 + $.blue = readUi8($bytes, $stream); 1.5035 + } 1.5036 + function fillSolid($bytes, $stream, $, swfVersion, tagCode, isMorph) { 1.5037 + if (tagCode > 22 || isMorph) { 1.5038 + var $125 = $.color = {}; 1.5039 + rgba($bytes, $stream, $125, swfVersion, tagCode); 1.5040 + } else { 1.5041 + var $126 = $.color = {}; 1.5042 + rgb($bytes, $stream, $126, swfVersion, tagCode); 1.5043 + } 1.5044 + if (isMorph) { 1.5045 + var $127 = $.colorMorph = {}; 1.5046 + rgba($bytes, $stream, $127, swfVersion, tagCode); 1.5047 + } 1.5048 + return; 1.5049 + } 1.5050 + function matrix($bytes, $stream, $, swfVersion, tagCode) { 1.5051 + align($bytes, $stream); 1.5052 + var hasScale = readUb($bytes, $stream, 1); 1.5053 + if (hasScale) { 1.5054 + var bits = readUb($bytes, $stream, 5); 1.5055 + $.a = readFb($bytes, $stream, bits); 1.5056 + $.d = readFb($bytes, $stream, bits); 1.5057 + } else { 1.5058 + $.a = 1; 1.5059 + $.d = 1; 1.5060 + } 1.5061 + var hasRotate = readUb($bytes, $stream, 1); 1.5062 + if (hasRotate) { 1.5063 + var bits = readUb($bytes, $stream, 5); 1.5064 + $.b = readFb($bytes, $stream, bits); 1.5065 + $.c = readFb($bytes, $stream, bits); 1.5066 + } else { 1.5067 + $.b = 0; 1.5068 + $.c = 0; 1.5069 + } 1.5070 + var bits = readUb($bytes, $stream, 5); 1.5071 + var e = readSb($bytes, $stream, bits); 1.5072 + var f = readSb($bytes, $stream, bits); 1.5073 + $.tx = e; 1.5074 + $.ty = f; 1.5075 + align($bytes, $stream); 1.5076 + } 1.5077 + function cxform($bytes, $stream, $, swfVersion, tagCode) { 1.5078 + align($bytes, $stream); 1.5079 + var hasOffsets = readUb($bytes, $stream, 1); 1.5080 + var hasMultipliers = readUb($bytes, $stream, 1); 1.5081 + var bits = readUb($bytes, $stream, 4); 1.5082 + if (hasMultipliers) { 1.5083 + $.redMultiplier = readSb($bytes, $stream, bits); 1.5084 + $.greenMultiplier = readSb($bytes, $stream, bits); 1.5085 + $.blueMultiplier = readSb($bytes, $stream, bits); 1.5086 + if (tagCode > 4) { 1.5087 + $.alphaMultiplier = readSb($bytes, $stream, bits); 1.5088 + } else { 1.5089 + $.alphaMultiplier = 256; 1.5090 + } 1.5091 + } else { 1.5092 + $.redMultiplier = 256; 1.5093 + $.greenMultiplier = 256; 1.5094 + $.blueMultiplier = 256; 1.5095 + $.alphaMultiplier = 256; 1.5096 + } 1.5097 + if (hasOffsets) { 1.5098 + $.redOffset = readSb($bytes, $stream, bits); 1.5099 + $.greenOffset = readSb($bytes, $stream, bits); 1.5100 + $.blueOffset = readSb($bytes, $stream, bits); 1.5101 + if (tagCode > 4) { 1.5102 + $.alphaOffset = readSb($bytes, $stream, bits); 1.5103 + } else { 1.5104 + $.alphaOffset = 0; 1.5105 + } 1.5106 + } else { 1.5107 + $.redOffset = 0; 1.5108 + $.greenOffset = 0; 1.5109 + $.blueOffset = 0; 1.5110 + $.alphaOffset = 0; 1.5111 + } 1.5112 + align($bytes, $stream); 1.5113 + } 1.5114 + function fillGradient($bytes, $stream, $, swfVersion, tagCode, isMorph, type) { 1.5115 + var $128 = $.matrix = {}; 1.5116 + matrix($bytes, $stream, $128, swfVersion, tagCode); 1.5117 + if (isMorph) { 1.5118 + var $129 = $.matrixMorph = {}; 1.5119 + matrix($bytes, $stream, $129, swfVersion, tagCode); 1.5120 + } 1.5121 + gradient($bytes, $stream, $, swfVersion, tagCode, isMorph, type); 1.5122 + } 1.5123 + function gradient($bytes, $stream, $, swfVersion, tagCode, isMorph, type) { 1.5124 + if (tagCode === 83) { 1.5125 + $.spreadMode = readUb($bytes, $stream, 2); 1.5126 + $.interpolationMode = readUb($bytes, $stream, 2); 1.5127 + } else { 1.5128 + var pad = readUb($bytes, $stream, 4); 1.5129 + } 1.5130 + var count = $.count = readUb($bytes, $stream, 4); 1.5131 + var $130 = $.records = []; 1.5132 + var $131 = count; 1.5133 + while ($131--) { 1.5134 + var $132 = {}; 1.5135 + gradientRecord($bytes, $stream, $132, swfVersion, tagCode, isMorph); 1.5136 + $130.push($132); 1.5137 + } 1.5138 + if (type === 19) { 1.5139 + $.focalPoint = readFixed8($bytes, $stream); 1.5140 + if (isMorph) { 1.5141 + $.focalPointMorph = readFixed8($bytes, $stream); 1.5142 + } 1.5143 + } 1.5144 + } 1.5145 + function gradientRecord($bytes, $stream, $, swfVersion, tagCode, isMorph) { 1.5146 + $.ratio = readUi8($bytes, $stream); 1.5147 + if (tagCode > 22) { 1.5148 + var $133 = $.color = {}; 1.5149 + rgba($bytes, $stream, $133, swfVersion, tagCode); 1.5150 + } else { 1.5151 + var $134 = $.color = {}; 1.5152 + rgb($bytes, $stream, $134, swfVersion, tagCode); 1.5153 + } 1.5154 + if (isMorph) { 1.5155 + $.ratioMorph = readUi8($bytes, $stream); 1.5156 + var $135 = $.colorMorph = {}; 1.5157 + rgba($bytes, $stream, $135, swfVersion, tagCode); 1.5158 + } 1.5159 + } 1.5160 + function morphShapeWithStyle($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes) { 1.5161 + var eos, bits; 1.5162 + var temp = styles($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.5163 + var lineBits = temp.lineBits; 1.5164 + var fillBits = temp.fillBits; 1.5165 + var $160 = $.records = []; 1.5166 + do { 1.5167 + var $161 = {}; 1.5168 + var temp = shapeRecord($bytes, $stream, $161, swfVersion, tagCode, isMorph, fillBits, lineBits, hasStrokes, bits); 1.5169 + var eos = temp.eos; 1.5170 + var flags = temp.flags; 1.5171 + var type = temp.type; 1.5172 + var fillBits = temp.fillBits; 1.5173 + var lineBits = temp.lineBits; 1.5174 + var bits = temp.bits; 1.5175 + $160.push($161); 1.5176 + } while (!eos); 1.5177 + var temp = styleBits($bytes, $stream, $, swfVersion, tagCode); 1.5178 + var fillBits = temp.fillBits; 1.5179 + var lineBits = temp.lineBits; 1.5180 + var $162 = $.recordsMorph = []; 1.5181 + do { 1.5182 + var $163 = {}; 1.5183 + var temp = shapeRecord($bytes, $stream, $163, swfVersion, tagCode, isMorph, fillBits, lineBits, hasStrokes, bits); 1.5184 + eos = temp.eos; 1.5185 + var flags = temp.flags; 1.5186 + var type = temp.type; 1.5187 + var fillBits = temp.fillBits; 1.5188 + var lineBits = temp.lineBits; 1.5189 + bits = temp.bits; 1.5190 + $162.push($163); 1.5191 + } while (!eos); 1.5192 + } 1.5193 + function shapeWithStyle($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes) { 1.5194 + var eos; 1.5195 + var temp = styles($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.5196 + var fillBits = temp.fillBits; 1.5197 + var lineBits = temp.lineBits; 1.5198 + var $160 = $.records = []; 1.5199 + do { 1.5200 + var $161 = {}; 1.5201 + var temp = shapeRecord($bytes, $stream, $161, swfVersion, tagCode, isMorph, fillBits, lineBits, hasStrokes, bits); 1.5202 + eos = temp.eos; 1.5203 + var flags = temp.flags; 1.5204 + var type = temp.type; 1.5205 + var fillBits = temp.fillBits; 1.5206 + var lineBits = temp.lineBits; 1.5207 + var bits = temp.bits; 1.5208 + $160.push($161); 1.5209 + } while (!eos); 1.5210 + } 1.5211 + function shapeRecord($bytes, $stream, $, swfVersion, tagCode, isMorph, fillBits, lineBits, hasStrokes, bits) { 1.5212 + var type = $.type = readUb($bytes, $stream, 1); 1.5213 + var flags = readUb($bytes, $stream, 5); 1.5214 + var eos = $.eos = !(type || flags); 1.5215 + if (type) { 1.5216 + var temp = shapeRecordEdge($bytes, $stream, $, swfVersion, tagCode, flags, bits); 1.5217 + var bits = temp.bits; 1.5218 + } else { 1.5219 + var temp = shapeRecordSetup($bytes, $stream, $, swfVersion, tagCode, flags, isMorph, fillBits, lineBits, hasStrokes, bits); 1.5220 + var fillBits = temp.fillBits; 1.5221 + var lineBits = temp.lineBits; 1.5222 + var bits = temp.bits; 1.5223 + } 1.5224 + return { 1.5225 + type: type, 1.5226 + flags: flags, 1.5227 + eos: eos, 1.5228 + fillBits: fillBits, 1.5229 + lineBits: lineBits, 1.5230 + bits: bits 1.5231 + }; 1.5232 + } 1.5233 + function shapeRecordEdge($bytes, $stream, $, swfVersion, tagCode, flags, bits) { 1.5234 + var isStraight = 0, tmp = 0, bits = 0, isGeneral = 0, isVertical = 0; 1.5235 + isStraight = $.isStraight = flags >> 4; 1.5236 + tmp = flags & 15; 1.5237 + bits = tmp + 2; 1.5238 + if (isStraight) { 1.5239 + isGeneral = $.isGeneral = readUb($bytes, $stream, 1); 1.5240 + if (isGeneral) { 1.5241 + $.deltaX = readSb($bytes, $stream, bits); 1.5242 + $.deltaY = readSb($bytes, $stream, bits); 1.5243 + } else { 1.5244 + isVertical = $.isVertical = readUb($bytes, $stream, 1); 1.5245 + if (isVertical) { 1.5246 + $.deltaY = readSb($bytes, $stream, bits); 1.5247 + } else { 1.5248 + $.deltaX = readSb($bytes, $stream, bits); 1.5249 + } 1.5250 + } 1.5251 + } else { 1.5252 + $.controlDeltaX = readSb($bytes, $stream, bits); 1.5253 + $.controlDeltaY = readSb($bytes, $stream, bits); 1.5254 + $.anchorDeltaX = readSb($bytes, $stream, bits); 1.5255 + $.anchorDeltaY = readSb($bytes, $stream, bits); 1.5256 + } 1.5257 + return { 1.5258 + bits: bits 1.5259 + }; 1.5260 + } 1.5261 + function shapeRecordSetup($bytes, $stream, $, swfVersion, tagCode, flags, isMorph, fillBits, lineBits, hasStrokes, bits) { 1.5262 + var hasNewStyles = 0, hasLineStyle = 0, hasFillStyle1 = 0; 1.5263 + var hasFillStyle0 = 0, move = 0; 1.5264 + if (tagCode > 2) { 1.5265 + hasNewStyles = $.hasNewStyles = flags >> 4; 1.5266 + } else { 1.5267 + hasNewStyles = $.hasNewStyles = 0; 1.5268 + } 1.5269 + hasLineStyle = $.hasLineStyle = flags >> 3 & 1; 1.5270 + hasFillStyle1 = $.hasFillStyle1 = flags >> 2 & 1; 1.5271 + hasFillStyle0 = $.hasFillStyle0 = flags >> 1 & 1; 1.5272 + move = $.move = flags & 1; 1.5273 + if (move) { 1.5274 + bits = readUb($bytes, $stream, 5); 1.5275 + $.moveX = readSb($bytes, $stream, bits); 1.5276 + $.moveY = readSb($bytes, $stream, bits); 1.5277 + } 1.5278 + if (hasFillStyle0) { 1.5279 + $.fillStyle0 = readUb($bytes, $stream, fillBits); 1.5280 + } 1.5281 + if (hasFillStyle1) { 1.5282 + $.fillStyle1 = readUb($bytes, $stream, fillBits); 1.5283 + } 1.5284 + if (hasLineStyle) { 1.5285 + $.lineStyle = readUb($bytes, $stream, lineBits); 1.5286 + } 1.5287 + if (hasNewStyles) { 1.5288 + var temp = styles($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.5289 + var lineBits = temp.lineBits; 1.5290 + var fillBits = temp.fillBits; 1.5291 + } 1.5292 + return { 1.5293 + lineBits: lineBits, 1.5294 + fillBits: fillBits, 1.5295 + bits: bits 1.5296 + }; 1.5297 + } 1.5298 + function styles($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes) { 1.5299 + fillStyleArray($bytes, $stream, $, swfVersion, tagCode, isMorph); 1.5300 + lineStyleArray($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes); 1.5301 + var temp = styleBits($bytes, $stream, $, swfVersion, tagCode); 1.5302 + var fillBits = temp.fillBits; 1.5303 + var lineBits = temp.lineBits; 1.5304 + return { 1.5305 + fillBits: fillBits, 1.5306 + lineBits: lineBits 1.5307 + }; 1.5308 + } 1.5309 + function fillStyleArray($bytes, $stream, $, swfVersion, tagCode, isMorph) { 1.5310 + var count; 1.5311 + var tmp = readUi8($bytes, $stream); 1.5312 + if (tagCode > 2 && tmp === 255) { 1.5313 + count = readUi16($bytes, $stream); 1.5314 + } else { 1.5315 + count = tmp; 1.5316 + } 1.5317 + var $4 = $.fillStyles = []; 1.5318 + var $5 = count; 1.5319 + while ($5--) { 1.5320 + var $6 = {}; 1.5321 + fillStyle($bytes, $stream, $6, swfVersion, tagCode, isMorph); 1.5322 + $4.push($6); 1.5323 + } 1.5324 + } 1.5325 + function lineStyleArray($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes) { 1.5326 + var count; 1.5327 + var tmp = readUi8($bytes, $stream); 1.5328 + if (tagCode > 2 && tmp === 255) { 1.5329 + count = readUi16($bytes, $stream); 1.5330 + } else { 1.5331 + count = tmp; 1.5332 + } 1.5333 + var $138 = $.lineStyles = []; 1.5334 + var $139 = count; 1.5335 + while ($139--) { 1.5336 + var $140 = {}; 1.5337 + lineStyle($bytes, $stream, $140, swfVersion, tagCode, isMorph, hasStrokes); 1.5338 + $138.push($140); 1.5339 + } 1.5340 + } 1.5341 + function styleBits($bytes, $stream, $, swfVersion, tagCode) { 1.5342 + align($bytes, $stream); 1.5343 + var fillBits = readUb($bytes, $stream, 4); 1.5344 + var lineBits = readUb($bytes, $stream, 4); 1.5345 + return { 1.5346 + fillBits: fillBits, 1.5347 + lineBits: lineBits 1.5348 + }; 1.5349 + } 1.5350 + function fillStyle($bytes, $stream, $, swfVersion, tagCode, isMorph) { 1.5351 + var type = $.type = readUi8($bytes, $stream); 1.5352 + switch (type) { 1.5353 + case 0: 1.5354 + fillSolid($bytes, $stream, $, swfVersion, tagCode, isMorph); 1.5355 + break; 1.5356 + case 16: 1.5357 + case 18: 1.5358 + case 19: 1.5359 + fillGradient($bytes, $stream, $, swfVersion, tagCode, isMorph, type); 1.5360 + break; 1.5361 + case 64: 1.5362 + case 65: 1.5363 + case 66: 1.5364 + case 67: 1.5365 + fillBitmap($bytes, $stream, $, swfVersion, tagCode, isMorph, type); 1.5366 + break; 1.5367 + default: 1.5368 + } 1.5369 + } 1.5370 + function lineStyle($bytes, $stream, $, swfVersion, tagCode, isMorph, hasStrokes) { 1.5371 + $.width = readUi16($bytes, $stream); 1.5372 + if (isMorph) { 1.5373 + $.widthMorph = readUi16($bytes, $stream); 1.5374 + } 1.5375 + if (hasStrokes) { 1.5376 + align($bytes, $stream); 1.5377 + $.startCapStyle = readUb($bytes, $stream, 2); 1.5378 + var joinStyle = $.joinStyle = readUb($bytes, $stream, 2); 1.5379 + var hasFill = $.hasFill = readUb($bytes, $stream, 1); 1.5380 + $.noHscale = readUb($bytes, $stream, 1); 1.5381 + $.noVscale = readUb($bytes, $stream, 1); 1.5382 + $.pixelHinting = readUb($bytes, $stream, 1); 1.5383 + var reserved = readUb($bytes, $stream, 5); 1.5384 + $.noClose = readUb($bytes, $stream, 1); 1.5385 + $.endCapStyle = readUb($bytes, $stream, 2); 1.5386 + if (joinStyle === 2) { 1.5387 + $.miterLimitFactor = readFixed8($bytes, $stream); 1.5388 + } 1.5389 + if (hasFill) { 1.5390 + var $141 = $.fillStyle = {}; 1.5391 + fillStyle($bytes, $stream, $141, swfVersion, tagCode, isMorph); 1.5392 + } else { 1.5393 + var $155 = $.color = {}; 1.5394 + rgba($bytes, $stream, $155, swfVersion, tagCode); 1.5395 + if (isMorph) { 1.5396 + var $156 = $.colorMorph = {}; 1.5397 + rgba($bytes, $stream, $156, swfVersion, tagCode); 1.5398 + } 1.5399 + } 1.5400 + } else { 1.5401 + if (tagCode > 22) { 1.5402 + var $157 = $.color = {}; 1.5403 + rgba($bytes, $stream, $157, swfVersion, tagCode); 1.5404 + } else { 1.5405 + var $158 = $.color = {}; 1.5406 + rgb($bytes, $stream, $158, swfVersion, tagCode); 1.5407 + } 1.5408 + if (isMorph) { 1.5409 + var $159 = $.colorMorph = {}; 1.5410 + rgba($bytes, $stream, $159, swfVersion, tagCode); 1.5411 + } 1.5412 + } 1.5413 + } 1.5414 + function fillBitmap($bytes, $stream, $, swfVersion, tagCode, isMorph, type) { 1.5415 + $.bitmapId = readUi16($bytes, $stream); 1.5416 + var $18 = $.matrix = {}; 1.5417 + matrix($bytes, $stream, $18, swfVersion, tagCode); 1.5418 + if (isMorph) { 1.5419 + var $19 = $.matrixMorph = {}; 1.5420 + matrix($bytes, $stream, $19, swfVersion, tagCode); 1.5421 + } 1.5422 + $.condition = type === 64 || type === 67; 1.5423 + } 1.5424 + function filterGlow($bytes, $stream, $, swfVersion, tagCode, type) { 1.5425 + var count; 1.5426 + if (type === 4 || type === 7) { 1.5427 + count = readUi8($bytes, $stream); 1.5428 + } else { 1.5429 + count = 1; 1.5430 + } 1.5431 + var $5 = $.colors = []; 1.5432 + var $6 = count; 1.5433 + while ($6--) { 1.5434 + var $7 = {}; 1.5435 + rgba($bytes, $stream, $7, swfVersion, tagCode); 1.5436 + $5.push($7); 1.5437 + } 1.5438 + if (type === 3) { 1.5439 + var $8 = $.higlightColor = {}; 1.5440 + rgba($bytes, $stream, $8, swfVersion, tagCode); 1.5441 + } 1.5442 + if (type === 4 || type === 7) { 1.5443 + var $9 = $.ratios = []; 1.5444 + var $10 = count; 1.5445 + while ($10--) { 1.5446 + $9.push(readUi8($bytes, $stream)); 1.5447 + } 1.5448 + } 1.5449 + $.blurX = readFixed($bytes, $stream); 1.5450 + $.blurY = readFixed($bytes, $stream); 1.5451 + if (type !== 2) { 1.5452 + $.angle = readFixed($bytes, $stream); 1.5453 + $.distance = readFixed($bytes, $stream); 1.5454 + } 1.5455 + $.strength = readFixed8($bytes, $stream); 1.5456 + $.innerShadow = readUb($bytes, $stream, 1); 1.5457 + $.knockout = readUb($bytes, $stream, 1); 1.5458 + $.compositeSource = readUb($bytes, $stream, 1); 1.5459 + if (type === 3) { 1.5460 + $.onTop = readUb($bytes, $stream, 1); 1.5461 + } else { 1.5462 + var reserved = readUb($bytes, $stream, 1); 1.5463 + } 1.5464 + if (type === 4 || type === 7) { 1.5465 + $.passes = readUb($bytes, $stream, 4); 1.5466 + } else { 1.5467 + var reserved = readUb($bytes, $stream, 4); 1.5468 + } 1.5469 + } 1.5470 + function filterBlur($bytes, $stream, $, swfVersion, tagCode) { 1.5471 + $.blurX = readFixed($bytes, $stream); 1.5472 + $.blurY = readFixed($bytes, $stream); 1.5473 + $.passes = readUb($bytes, $stream, 5); 1.5474 + var reserved = readUb($bytes, $stream, 3); 1.5475 + } 1.5476 + function filterConvolution($bytes, $stream, $, swfVersion, tagCode) { 1.5477 + var columns = $.columns = readUi8($bytes, $stream); 1.5478 + var rows = $.rows = readUi8($bytes, $stream); 1.5479 + $.divisor = readFloat($bytes, $stream); 1.5480 + $.bias = readFloat($bytes, $stream); 1.5481 + var $17 = $.weights = []; 1.5482 + var $18 = columns * rows; 1.5483 + while ($18--) { 1.5484 + $17.push(readFloat($bytes, $stream)); 1.5485 + } 1.5486 + var $19 = $.defaultColor = {}; 1.5487 + rgba($bytes, $stream, $19, swfVersion, tagCode); 1.5488 + var reserved = readUb($bytes, $stream, 6); 1.5489 + $.clamp = readUb($bytes, $stream, 1); 1.5490 + $.preserveAlpha = readUb($bytes, $stream, 1); 1.5491 + } 1.5492 + function filterColorMatrix($bytes, $stream, $, swfVersion, tagCode) { 1.5493 + var $20 = $.matrix = []; 1.5494 + var $21 = 20; 1.5495 + while ($21--) { 1.5496 + $20.push(readFloat($bytes, $stream)); 1.5497 + } 1.5498 + } 1.5499 + function anyFilter($bytes, $stream, $, swfVersion, tagCode) { 1.5500 + var type = $.type = readUi8($bytes, $stream); 1.5501 + switch (type) { 1.5502 + case 0: 1.5503 + case 2: 1.5504 + case 3: 1.5505 + case 4: 1.5506 + case 7: 1.5507 + filterGlow($bytes, $stream, $, swfVersion, tagCode, type); 1.5508 + break; 1.5509 + case 1: 1.5510 + filterBlur($bytes, $stream, $, swfVersion, tagCode); 1.5511 + break; 1.5512 + case 5: 1.5513 + filterConvolution($bytes, $stream, $, swfVersion, tagCode); 1.5514 + break; 1.5515 + case 6: 1.5516 + filterColorMatrix($bytes, $stream, $, swfVersion, tagCode); 1.5517 + break; 1.5518 + default: 1.5519 + } 1.5520 + } 1.5521 + function events($bytes, $stream, $, swfVersion, tagCode) { 1.5522 + var flags, keyPress; 1.5523 + if (swfVersion >= 6) { 1.5524 + flags = readUi32($bytes, $stream); 1.5525 + } else { 1.5526 + flags = readUi16($bytes, $stream); 1.5527 + } 1.5528 + var eoe = $.eoe = !flags; 1.5529 + $.onKeyUp = flags >> 7 & 1; 1.5530 + $.onKeyDown = flags >> 6 & 1; 1.5531 + $.onMouseUp = flags >> 5 & 1; 1.5532 + $.onMouseDown = flags >> 4 & 1; 1.5533 + $.onMouseMove = flags >> 3 & 1; 1.5534 + $.onUnload = flags >> 2 & 1; 1.5535 + $.onEnterFrame = flags >> 1 & 1; 1.5536 + $.onLoad = flags & 1; 1.5537 + if (swfVersion >= 6) { 1.5538 + $.onDragOver = flags >> 15 & 1; 1.5539 + $.onRollOut = flags >> 14 & 1; 1.5540 + $.onRollOver = flags >> 13 & 1; 1.5541 + $.onReleaseOutside = flags >> 12 & 1; 1.5542 + $.onRelease = flags >> 11 & 1; 1.5543 + $.onPress = flags >> 10 & 1; 1.5544 + $.onInitialize = flags >> 9 & 1; 1.5545 + $.onData = flags >> 8 & 1; 1.5546 + if (swfVersion >= 7) { 1.5547 + $.onConstruct = flags >> 18 & 1; 1.5548 + } else { 1.5549 + $.onConstruct = 0; 1.5550 + } 1.5551 + keyPress = $.keyPress = flags >> 17 & 1; 1.5552 + $.onDragOut = flags >> 16 & 1; 1.5553 + } 1.5554 + if (!eoe) { 1.5555 + var length = $.length = readUi32($bytes, $stream); 1.5556 + if (keyPress) { 1.5557 + $.keyCode = readUi8($bytes, $stream); 1.5558 + } 1.5559 + $.actionsData = readBinary($bytes, $stream, length - (keyPress ? 1 : 0)); 1.5560 + } 1.5561 + return { 1.5562 + eoe: eoe 1.5563 + }; 1.5564 + } 1.5565 + function kerning($bytes, $stream, $, swfVersion, tagCode, wide) { 1.5566 + if (wide) { 1.5567 + $.code1 = readUi16($bytes, $stream); 1.5568 + $.code2 = readUi16($bytes, $stream); 1.5569 + } else { 1.5570 + $.code1 = readUi8($bytes, $stream); 1.5571 + $.code2 = readUi8($bytes, $stream); 1.5572 + } 1.5573 + $.adjustment = readUi16($bytes, $stream); 1.5574 + } 1.5575 + function textEntry($bytes, $stream, $, swfVersion, tagCode, glyphBits, advanceBits) { 1.5576 + $.glyphIndex = readUb($bytes, $stream, glyphBits); 1.5577 + $.advance = readSb($bytes, $stream, advanceBits); 1.5578 + } 1.5579 + function textRecordSetup($bytes, $stream, $, swfVersion, tagCode, flags) { 1.5580 + var hasFont = $.hasFont = flags >> 3 & 1; 1.5581 + var hasColor = $.hasColor = flags >> 2 & 1; 1.5582 + var hasMoveY = $.hasMoveY = flags >> 1 & 1; 1.5583 + var hasMoveX = $.hasMoveX = flags & 1; 1.5584 + if (hasFont) { 1.5585 + $.fontId = readUi16($bytes, $stream); 1.5586 + } 1.5587 + if (hasColor) { 1.5588 + if (tagCode === 33) { 1.5589 + var $4 = $.color = {}; 1.5590 + rgba($bytes, $stream, $4, swfVersion, tagCode); 1.5591 + } else { 1.5592 + var $5 = $.color = {}; 1.5593 + rgb($bytes, $stream, $5, swfVersion, tagCode); 1.5594 + } 1.5595 + } 1.5596 + if (hasMoveX) { 1.5597 + $.moveX = readSi16($bytes, $stream); 1.5598 + } 1.5599 + if (hasMoveY) { 1.5600 + $.moveY = readSi16($bytes, $stream); 1.5601 + } 1.5602 + if (hasFont) { 1.5603 + $.fontHeight = readUi16($bytes, $stream); 1.5604 + } 1.5605 + } 1.5606 + function textRecord($bytes, $stream, $, swfVersion, tagCode, glyphBits, advanceBits) { 1.5607 + var glyphCount; 1.5608 + align($bytes, $stream); 1.5609 + var flags = readUb($bytes, $stream, 8); 1.5610 + var eot = $.eot = !flags; 1.5611 + textRecordSetup($bytes, $stream, $, swfVersion, tagCode, flags); 1.5612 + if (!eot) { 1.5613 + var tmp = readUi8($bytes, $stream); 1.5614 + if (swfVersion > 6) { 1.5615 + glyphCount = $.glyphCount = tmp; 1.5616 + } else { 1.5617 + glyphCount = $.glyphCount = tmp & 127; 1.5618 + } 1.5619 + var $6 = $.entries = []; 1.5620 + var $7 = glyphCount; 1.5621 + while ($7--) { 1.5622 + var $8 = {}; 1.5623 + textEntry($bytes, $stream, $8, swfVersion, tagCode, glyphBits, advanceBits); 1.5624 + $6.push($8); 1.5625 + } 1.5626 + } 1.5627 + return { 1.5628 + eot: eot 1.5629 + }; 1.5630 + } 1.5631 + function soundEnvelope($bytes, $stream, $, swfVersion, tagCode) { 1.5632 + $.pos44 = readUi32($bytes, $stream); 1.5633 + $.volumeLeft = readUi16($bytes, $stream); 1.5634 + $.volumeRight = readUi16($bytes, $stream); 1.5635 + } 1.5636 + function soundInfo($bytes, $stream, $, swfVersion, tagCode) { 1.5637 + var reserved = readUb($bytes, $stream, 2); 1.5638 + $.stop = readUb($bytes, $stream, 1); 1.5639 + $.noMultiple = readUb($bytes, $stream, 1); 1.5640 + var hasEnvelope = $.hasEnvelope = readUb($bytes, $stream, 1); 1.5641 + var hasLoops = $.hasLoops = readUb($bytes, $stream, 1); 1.5642 + var hasOutPoint = $.hasOutPoint = readUb($bytes, $stream, 1); 1.5643 + var hasInPoint = $.hasInPoint = readUb($bytes, $stream, 1); 1.5644 + if (hasInPoint) { 1.5645 + $.inPoint = readUi32($bytes, $stream); 1.5646 + } 1.5647 + if (hasOutPoint) { 1.5648 + $.outPoint = readUi32($bytes, $stream); 1.5649 + } 1.5650 + if (hasLoops) { 1.5651 + $.loopCount = readUi16($bytes, $stream); 1.5652 + } 1.5653 + if (hasEnvelope) { 1.5654 + var envelopeCount = $.envelopeCount = readUi8($bytes, $stream); 1.5655 + var $1 = $.envelopes = []; 1.5656 + var $2 = envelopeCount; 1.5657 + while ($2--) { 1.5658 + var $3 = {}; 1.5659 + soundEnvelope($bytes, $stream, $3, swfVersion, tagCode); 1.5660 + $1.push($3); 1.5661 + } 1.5662 + } 1.5663 + } 1.5664 + function button($bytes, $stream, $, swfVersion, tagCode) { 1.5665 + var hasFilters, blend; 1.5666 + var flags = readUi8($bytes, $stream); 1.5667 + var eob = $.eob = !flags; 1.5668 + if (swfVersion >= 8) { 1.5669 + blend = $.blend = flags >> 5 & 1; 1.5670 + hasFilters = $.hasFilters = flags >> 4 & 1; 1.5671 + } else { 1.5672 + blend = $.blend = 0; 1.5673 + hasFilters = $.hasFilters = 0; 1.5674 + } 1.5675 + $.stateHitTest = flags >> 3 & 1; 1.5676 + $.stateDown = flags >> 2 & 1; 1.5677 + $.stateOver = flags >> 1 & 1; 1.5678 + $.stateUp = flags & 1; 1.5679 + if (!eob) { 1.5680 + $.symbolId = readUi16($bytes, $stream); 1.5681 + $.depth = readUi16($bytes, $stream); 1.5682 + var $2 = $.matrix = {}; 1.5683 + matrix($bytes, $stream, $2, swfVersion, tagCode); 1.5684 + if (tagCode === 34) { 1.5685 + var $3 = $.cxform = {}; 1.5686 + cxform($bytes, $stream, $3, swfVersion, tagCode); 1.5687 + } 1.5688 + if (hasFilters) { 1.5689 + $.filterCount = readUi8($bytes, $stream); 1.5690 + var $4 = $.filters = {}; 1.5691 + anyFilter($bytes, $stream, $4, swfVersion, tagCode); 1.5692 + } 1.5693 + if (blend) { 1.5694 + $.blendMode = readUi8($bytes, $stream); 1.5695 + } 1.5696 + } 1.5697 + return { 1.5698 + eob: eob 1.5699 + }; 1.5700 + } 1.5701 + function buttonCondAction($bytes, $stream, $, swfVersion, tagCode) { 1.5702 + var buttonCondSize = readUi16($bytes, $stream); 1.5703 + var buttonConditions = readUi16($bytes, $stream); 1.5704 + $.idleToOverDown = buttonConditions >> 7 & 1; 1.5705 + $.outDownToIdle = buttonConditions >> 6 & 1; 1.5706 + $.outDownToOverDown = buttonConditions >> 5 & 1; 1.5707 + $.overDownToOutDown = buttonConditions >> 4 & 1; 1.5708 + $.overDownToOverUp = buttonConditions >> 3 & 1; 1.5709 + $.overUpToOverDown = buttonConditions >> 2 & 1; 1.5710 + $.overUpToIdle = buttonConditions >> 1 & 1; 1.5711 + $.idleToOverUp = buttonConditions & 1; 1.5712 + $.mouseEventFlags = buttonConditions & 511; 1.5713 + $.keyPress = buttonConditions >> 9 & 127; 1.5714 + $.overDownToIdle = buttonConditions >> 8 & 1; 1.5715 + if (!buttonCondSize) { 1.5716 + $.actionsData = readBinary($bytes, $stream, 0); 1.5717 + } else { 1.5718 + $.actionsData = readBinary($bytes, $stream, buttonCondSize - 4); 1.5719 + } 1.5720 + } 1.5721 + function shape($bytes, $stream, $, swfVersion, tagCode) { 1.5722 + var eos; 1.5723 + var temp = styleBits($bytes, $stream, $, swfVersion, tagCode); 1.5724 + var fillBits = temp.fillBits; 1.5725 + var lineBits = temp.lineBits; 1.5726 + var $4 = $.records = []; 1.5727 + do { 1.5728 + var $5 = {}; 1.5729 + var isMorph = false; 1.5730 + var hasStrokes = false; 1.5731 + var temp = shapeRecord($bytes, $stream, $5, swfVersion, tagCode, isMorph, fillBits, lineBits, hasStrokes, bits); 1.5732 + eos = temp.eos; 1.5733 + var fillBits = temp.fillBits; 1.5734 + var lineBits = temp.lineBits; 1.5735 + var bits = bits; 1.5736 + $4.push($5); 1.5737 + } while (!eos); 1.5738 + } 1.5739 + return { 1.5740 + 0: undefined, 1.5741 + 1: undefined, 1.5742 + 2: defineShape, 1.5743 + 4: placeObject, 1.5744 + 5: removeObject, 1.5745 + 6: defineImage, 1.5746 + 7: defineButton, 1.5747 + 8: defineJPEGTables, 1.5748 + 9: setBackgroundColor, 1.5749 + 10: defineFont, 1.5750 + 11: defineLabel, 1.5751 + 12: doAction, 1.5752 + 13: undefined, 1.5753 + 14: defineSound, 1.5754 + 15: startSound, 1.5755 + 17: undefined, 1.5756 + 18: soundStreamHead, 1.5757 + 19: soundStreamBlock, 1.5758 + 20: defineBitmap, 1.5759 + 21: defineImage, 1.5760 + 22: defineShape, 1.5761 + 23: undefined, 1.5762 + 24: undefined, 1.5763 + 26: placeObject, 1.5764 + 28: removeObject, 1.5765 + 32: defineShape, 1.5766 + 33: defineLabel, 1.5767 + 34: defineButton, 1.5768 + 35: defineImage, 1.5769 + 36: defineBitmap, 1.5770 + 37: defineText, 1.5771 + 39: undefined, 1.5772 + 43: frameLabel, 1.5773 + 45: soundStreamHead, 1.5774 + 46: defineShape, 1.5775 + 48: defineFont2, 1.5776 + 56: exportAssets, 1.5777 + 57: undefined, 1.5778 + 58: undefined, 1.5779 + 59: doAction, 1.5780 + 60: undefined, 1.5781 + 61: undefined, 1.5782 + 62: undefined, 1.5783 + 64: undefined, 1.5784 + 65: undefined, 1.5785 + 66: undefined, 1.5786 + 69: fileAttributes, 1.5787 + 70: placeObject, 1.5788 + 71: undefined, 1.5789 + 72: doABC, 1.5790 + 73: undefined, 1.5791 + 74: undefined, 1.5792 + 75: defineFont2, 1.5793 + 76: symbolClass, 1.5794 + 77: undefined, 1.5795 + 78: defineScalingGrid, 1.5796 + 82: doABC, 1.5797 + 83: defineShape, 1.5798 + 84: defineShape, 1.5799 + 86: defineScene, 1.5800 + 87: defineBinaryData, 1.5801 + 88: undefined, 1.5802 + 89: startSound, 1.5803 + 90: defineImage, 1.5804 + 91: undefined 1.5805 + }; 1.5806 + }(this); 1.5807 +var readHeader = function readHeader($bytes, $stream, $, swfVersion, tagCode) { 1.5808 + $ || ($ = {}); 1.5809 + var $0 = $.bbox = {}; 1.5810 + align($bytes, $stream); 1.5811 + var bits = readUb($bytes, $stream, 5); 1.5812 + var xMin = readSb($bytes, $stream, bits); 1.5813 + var xMax = readSb($bytes, $stream, bits); 1.5814 + var yMin = readSb($bytes, $stream, bits); 1.5815 + var yMax = readSb($bytes, $stream, bits); 1.5816 + $0.xMin = xMin; 1.5817 + $0.xMax = xMax; 1.5818 + $0.yMin = yMin; 1.5819 + $0.yMax = yMax; 1.5820 + align($bytes, $stream); 1.5821 + var frameRateFraction = readUi8($bytes, $stream); 1.5822 + $.frameRate = readUi8($bytes, $stream) + frameRateFraction / 256; 1.5823 + $.frameCount = readUi16($bytes, $stream); 1.5824 + return $; 1.5825 +}; 1.5826 +(function (global) { 1.5827 + global['tagHandler'] = tagHandler; 1.5828 + global['readHeader'] = readHeader; 1.5829 +}(this)); 1.5830 +function readTags(context, stream, swfVersion, final, onprogress, onexception) { 1.5831 + var tags = context.tags; 1.5832 + var bytes = stream.bytes; 1.5833 + var lastSuccessfulPosition; 1.5834 + var tag = null; 1.5835 + if (context._readTag) { 1.5836 + tag = context._readTag; 1.5837 + context._readTag = null; 1.5838 + } 1.5839 + try { 1.5840 + while (stream.pos < stream.end) { 1.5841 + lastSuccessfulPosition = stream.pos; 1.5842 + stream.ensure(2); 1.5843 + var tagCodeAndLength = readUi16(bytes, stream); 1.5844 + if (!tagCodeAndLength) { 1.5845 + final = true; 1.5846 + break; 1.5847 + } 1.5848 + var tagCode = tagCodeAndLength >> 6; 1.5849 + var length = tagCodeAndLength & 63; 1.5850 + if (length === 63) { 1.5851 + stream.ensure(4); 1.5852 + length = readUi32(bytes, stream); 1.5853 + } 1.5854 + if (tag) { 1.5855 + if (tagCode === 1 && tag.code === 1) { 1.5856 + tag.repeat++; 1.5857 + stream.pos += length; 1.5858 + continue; 1.5859 + } 1.5860 + tags.push(tag); 1.5861 + if (onprogress && tag.id !== undefined) { 1.5862 + onprogress(context); 1.5863 + } 1.5864 + tag = null; 1.5865 + } 1.5866 + stream.ensure(length); 1.5867 + var substream = stream.substream(stream.pos, stream.pos += length); 1.5868 + var subbytes = substream.bytes; 1.5869 + var nextTag = { 1.5870 + code: tagCode 1.5871 + }; 1.5872 + if (tagCode === 39) { 1.5873 + nextTag.type = 'sprite'; 1.5874 + nextTag.id = readUi16(subbytes, substream); 1.5875 + nextTag.frameCount = readUi16(subbytes, substream); 1.5876 + nextTag.tags = []; 1.5877 + readTags(nextTag, substream, swfVersion, true); 1.5878 + } else if (tagCode === 1) { 1.5879 + nextTag.repeat = 1; 1.5880 + } else { 1.5881 + var handler = tagHandler[tagCode]; 1.5882 + if (handler) { 1.5883 + handler(subbytes, substream, nextTag, swfVersion, tagCode); 1.5884 + } 1.5885 + } 1.5886 + tag = nextTag; 1.5887 + } 1.5888 + if (tag && final) { 1.5889 + tag.finalTag = true; 1.5890 + tags.push(tag); 1.5891 + if (onprogress) { 1.5892 + onprogress(context); 1.5893 + } 1.5894 + } else { 1.5895 + context._readTag = tag; 1.5896 + } 1.5897 + } catch (e) { 1.5898 + if (e !== StreamNoDataError) { 1.5899 + onexception && onexception(e); 1.5900 + throw e; 1.5901 + } 1.5902 + stream.pos = lastSuccessfulPosition; 1.5903 + context._readTag = tag; 1.5904 + } 1.5905 +} 1.5906 +function HeadTailBuffer(defaultSize) { 1.5907 + this.bufferSize = defaultSize || 16; 1.5908 + this.buffer = new Uint8Array(this.bufferSize); 1.5909 + this.pos = 0; 1.5910 +} 1.5911 +HeadTailBuffer.prototype = { 1.5912 + push: function (data, need) { 1.5913 + var bufferLengthNeed = this.pos + data.length; 1.5914 + if (this.bufferSize < bufferLengthNeed) { 1.5915 + var newBufferSize = this.bufferSize; 1.5916 + while (newBufferSize < bufferLengthNeed) { 1.5917 + newBufferSize <<= 1; 1.5918 + } 1.5919 + var newBuffer = new Uint8Array(newBufferSize); 1.5920 + if (this.bufferSize > 0) { 1.5921 + newBuffer.set(this.buffer); 1.5922 + } 1.5923 + this.buffer = newBuffer; 1.5924 + this.bufferSize = newBufferSize; 1.5925 + } 1.5926 + this.buffer.set(data, this.pos); 1.5927 + this.pos += data.length; 1.5928 + if (need) 1.5929 + return this.pos >= need; 1.5930 + }, 1.5931 + getHead: function (size) { 1.5932 + return this.buffer.subarray(0, size); 1.5933 + }, 1.5934 + getTail: function (offset) { 1.5935 + return this.buffer.subarray(offset, this.pos); 1.5936 + }, 1.5937 + removeHead: function (size) { 1.5938 + var tail = this.getTail(size); 1.5939 + this.buffer = new Uint8Array(this.bufferSize); 1.5940 + this.buffer.set(tail); 1.5941 + this.pos = tail.length; 1.5942 + }, 1.5943 + get arrayBuffer() { 1.5944 + return this.buffer.buffer; 1.5945 + }, 1.5946 + get length() { 1.5947 + return this.pos; 1.5948 + }, 1.5949 + createStream: function () { 1.5950 + return new Stream(this.arrayBuffer, 0, this.length); 1.5951 + } 1.5952 +}; 1.5953 +function CompressedPipe(target, length) { 1.5954 + this.target = target; 1.5955 + this.length = length; 1.5956 + this.initialize = true; 1.5957 + this.buffer = new HeadTailBuffer(8096); 1.5958 + this.state = { 1.5959 + bitBuffer: 0, 1.5960 + bitLength: 0, 1.5961 + compression: { 1.5962 + header: null, 1.5963 + distanceTable: null, 1.5964 + literalTable: null, 1.5965 + sym: null, 1.5966 + len: null, 1.5967 + sym2: null 1.5968 + } 1.5969 + }; 1.5970 + this.output = { 1.5971 + data: new Uint8Array(length), 1.5972 + available: 0, 1.5973 + completed: false 1.5974 + }; 1.5975 +} 1.5976 +CompressedPipe.prototype = { 1.5977 + push: function (data, progressInfo) { 1.5978 + var buffer = this.buffer; 1.5979 + if (this.initialize) { 1.5980 + if (!buffer.push(data, 2)) 1.5981 + return; 1.5982 + var headerBytes = buffer.getHead(2); 1.5983 + verifyDeflateHeader(headerBytes); 1.5984 + buffer.removeHead(2); 1.5985 + this.initialize = false; 1.5986 + } else { 1.5987 + buffer.push(data); 1.5988 + } 1.5989 + var stream = buffer.createStream(); 1.5990 + stream.bitBuffer = this.state.bitBuffer; 1.5991 + stream.bitLength = this.state.bitLength; 1.5992 + var output = this.output; 1.5993 + var lastAvailable = output.available; 1.5994 + try { 1.5995 + do { 1.5996 + inflateBlock(stream, output, this.state.compression); 1.5997 + } while (stream.pos < buffer.length && !output.completed); 1.5998 + } catch (e) { 1.5999 + if (e !== InflateNoDataError) 1.6000 + throw e; 1.6001 + } finally { 1.6002 + this.state.bitBuffer = stream.bitBuffer; 1.6003 + this.state.bitLength = stream.bitLength; 1.6004 + } 1.6005 + buffer.removeHead(stream.pos); 1.6006 + this.target.push(output.data.subarray(lastAvailable, output.available), progressInfo); 1.6007 + } 1.6008 +}; 1.6009 +function BodyParser(swfVersion, length, options) { 1.6010 + this.swf = { 1.6011 + swfVersion: swfVersion, 1.6012 + parseTime: 0 1.6013 + }; 1.6014 + this.buffer = new HeadTailBuffer(32768); 1.6015 + this.initialize = true; 1.6016 + this.totalRead = 0; 1.6017 + this.length = length; 1.6018 + this.options = options; 1.6019 +} 1.6020 +BodyParser.prototype = { 1.6021 + push: function (data, progressInfo) { 1.6022 + if (data.length === 0) 1.6023 + return; 1.6024 + var swf = this.swf; 1.6025 + var swfVersion = swf.swfVersion; 1.6026 + var buffer = this.buffer; 1.6027 + var options = this.options; 1.6028 + var stream; 1.6029 + if (this.initialize) { 1.6030 + var PREFETCH_SIZE = 27; 1.6031 + if (!buffer.push(data, PREFETCH_SIZE)) 1.6032 + return; 1.6033 + stream = buffer.createStream(); 1.6034 + var bytes = stream.bytes; 1.6035 + readHeader(bytes, stream, swf); 1.6036 + var nextTagHeader = readUi16(bytes, stream); 1.6037 + var FILE_ATTRIBUTES_LENGTH = 4; 1.6038 + if (nextTagHeader == (SWF_TAG_CODE_FILE_ATTRIBUTES << 6 | FILE_ATTRIBUTES_LENGTH)) { 1.6039 + stream.ensure(FILE_ATTRIBUTES_LENGTH); 1.6040 + var substream = stream.substream(stream.pos, stream.pos += FILE_ATTRIBUTES_LENGTH); 1.6041 + var handler = tagHandler[SWF_TAG_CODE_FILE_ATTRIBUTES]; 1.6042 + var fileAttributesTag = { 1.6043 + code: SWF_TAG_CODE_FILE_ATTRIBUTES 1.6044 + }; 1.6045 + handler(substream.bytes, substream, fileAttributesTag, swfVersion, SWF_TAG_CODE_FILE_ATTRIBUTES); 1.6046 + swf.fileAttributes = fileAttributesTag; 1.6047 + } else { 1.6048 + stream.pos -= 2; 1.6049 + swf.fileAttributes = {}; 1.6050 + } 1.6051 + if (options.onstart) 1.6052 + options.onstart(swf); 1.6053 + swf.tags = []; 1.6054 + this.initialize = false; 1.6055 + } else { 1.6056 + buffer.push(data); 1.6057 + stream = buffer.createStream(); 1.6058 + } 1.6059 + var finalBlock = false; 1.6060 + if (progressInfo) { 1.6061 + swf.bytesLoaded = progressInfo.bytesLoaded; 1.6062 + swf.bytesTotal = progressInfo.bytesTotal; 1.6063 + finalBlock = progressInfo.bytesLoaded >= progressInfo.bytesTotal; 1.6064 + } 1.6065 + var readStartTime = performance.now(); 1.6066 + readTags(swf, stream, swfVersion, finalBlock, options.onprogress, options.onexception); 1.6067 + swf.parseTime += performance.now() - readStartTime; 1.6068 + var read = stream.pos; 1.6069 + buffer.removeHead(read); 1.6070 + this.totalRead += read; 1.6071 + if (options.oncomplete && swf.tags[swf.tags.length - 1].finalTag) { 1.6072 + options.oncomplete(swf); 1.6073 + } 1.6074 + } 1.6075 +}; 1.6076 +SWF.parseAsync = function swf_parseAsync(options) { 1.6077 + var buffer = new HeadTailBuffer(); 1.6078 + var pipe = { 1.6079 + push: function (data, progressInfo) { 1.6080 + if (this.target !== undefined) { 1.6081 + return this.target.push(data, progressInfo); 1.6082 + } 1.6083 + if (!buffer.push(data, 8)) { 1.6084 + return null; 1.6085 + } 1.6086 + var bytes = buffer.getHead(8); 1.6087 + var magic1 = bytes[0]; 1.6088 + var magic2 = bytes[1]; 1.6089 + var magic3 = bytes[2]; 1.6090 + if ((magic1 === 70 || magic1 === 67) && magic2 === 87 && magic3 === 83) { 1.6091 + var swfVersion = bytes[3]; 1.6092 + var compressed = magic1 === 67; 1.6093 + parseSWF(compressed, swfVersion, progressInfo); 1.6094 + buffer = null; 1.6095 + return; 1.6096 + } 1.6097 + var isImage = false; 1.6098 + var imageType; 1.6099 + if (magic1 === 255 && magic2 === 216 && magic3 === 255) { 1.6100 + isImage = true; 1.6101 + imageType = 'image/jpeg'; 1.6102 + } else if (magic1 === 137 && magic2 === 80 && magic3 === 78) { 1.6103 + isImage = true; 1.6104 + imageType = 'image/png'; 1.6105 + } 1.6106 + if (isImage) { 1.6107 + parseImage(data, progressInfo.bytesTotal, imageType); 1.6108 + } 1.6109 + buffer = null; 1.6110 + }, 1.6111 + close: function () { 1.6112 + if (buffer) { 1.6113 + var symbol = { 1.6114 + command: 'empty', 1.6115 + data: buffer.buffer.subarray(0, buffer.pos) 1.6116 + }; 1.6117 + options.oncomplete && options.oncomplete(symbol); 1.6118 + } 1.6119 + if (this.target !== undefined && this.target.close) { 1.6120 + this.target.close(); 1.6121 + } 1.6122 + } 1.6123 + }; 1.6124 + function parseSWF(compressed, swfVersion, progressInfo) { 1.6125 + var stream = buffer.createStream(); 1.6126 + stream.pos += 4; 1.6127 + var fileLength = readUi32(null, stream); 1.6128 + var bodyLength = fileLength - 8; 1.6129 + var target = new BodyParser(swfVersion, bodyLength, options); 1.6130 + if (compressed) { 1.6131 + target = new CompressedPipe(target, bodyLength); 1.6132 + } 1.6133 + target.push(buffer.getTail(8), progressInfo); 1.6134 + pipe['target'] = target; 1.6135 + } 1.6136 + function parseImage(data, bytesTotal, type) { 1.6137 + var buffer = new Uint8Array(bytesTotal); 1.6138 + buffer.set(data); 1.6139 + var bufferPos = data.length; 1.6140 + pipe['target'] = { 1.6141 + push: function (data) { 1.6142 + buffer.set(data, bufferPos); 1.6143 + bufferPos += data.length; 1.6144 + }, 1.6145 + close: function () { 1.6146 + var props = {}; 1.6147 + var chunks; 1.6148 + if (type == 'image/jpeg') { 1.6149 + chunks = parseJpegChunks(props, buffer); 1.6150 + } else { 1.6151 + chunks = [ 1.6152 + buffer 1.6153 + ]; 1.6154 + } 1.6155 + var symbol = { 1.6156 + type: 'image', 1.6157 + props: props, 1.6158 + data: new Blob(chunks, { 1.6159 + type: type 1.6160 + }) 1.6161 + }; 1.6162 + options.oncomplete && options.oncomplete(symbol); 1.6163 + } 1.6164 + }; 1.6165 + } 1.6166 + return pipe; 1.6167 +}; 1.6168 +SWF.parse = function (buffer, options) { 1.6169 + if (!options) 1.6170 + options = {}; 1.6171 + var pipe = SWF.parseAsync(options); 1.6172 + var bytes = new Uint8Array(buffer); 1.6173 + var progressInfo = { 1.6174 + bytesLoaded: bytes.length, 1.6175 + bytesTotal: bytes.length 1.6176 + }; 1.6177 + pipe.push(bytes, progressInfo); 1.6178 + pipe.close(); 1.6179 +}; 1.6180 +(function (global) { 1.6181 + global['SWF']['parse'] = SWF.parse; 1.6182 + global['SWF']['parseAsync'] = SWF.parseAsync; 1.6183 +}(this));