├── .gitignore ├── .npmignore ├── dist ├── Numpy.js ├── PolySolve.js ├── Scipy.js └── ss.js ├── license.txt ├── package.json ├── readme.md ├── samples └── pyextjs │ └── index.html └── src ├── PyExtJS.js └── ss.js /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | Password: 4 | *.DS_Store 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | Password: 4 | *.DS_Store 5 | -------------------------------------------------------------------------------- /dist/Numpy.js: -------------------------------------------------------------------------------- 1 | // numpy javascript equivalent 2 | // https://github.com/fernandezajp/PyExtJS 3 | 4 | (function() { 5 | 6 | /** 7 | * Helper function for adding properties with Object.defineProperty 8 | * Copied from example on: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty 9 | */ 10 | function withValue(value) { 11 | var d = withValue.d || ( 12 | withValue.d = { 13 | enumerable: false, 14 | writable: true, 15 | configurable: false, 16 | value: null 17 | } 18 | ); 19 | d.value = value; 20 | return d; 21 | } 22 | 23 | window.numpy = function numpy() { 24 | } 25 | numpy.linspace = function numpy$linspace(start, stop, num) { 26 | if (num == null) { 27 | num = 50; 28 | } 29 | var tmp = []; 30 | var step = (stop - start) / (num - 1); 31 | var i = start; 32 | for (var c = 0; c < num - 1; c++) { 33 | tmp.add(i); 34 | i = i + step; 35 | } 36 | tmp.add(stop); 37 | var array = new Array(tmp.length); 38 | for (var c = 0; c < tmp.length; c++) { 39 | array[c] = tmp[c]; 40 | } 41 | return array; 42 | } 43 | numpy.logspace = function numpy$logspace(start, stop, num, endpoint, numericBase) { 44 | if (endpoint == null) { 45 | endpoint = true; 46 | } 47 | if (numericBase == null) { 48 | numericBase = 10; 49 | } 50 | var y = numpy.linspace(start, stop, num); 51 | return numpy.power(numericBase, y); 52 | } 53 | numpy.power = function numpy$power(bases, exponents) { 54 | var basesType = Type.getInstanceType(bases).get_name(); 55 | var exponentsType = Type.getInstanceType(exponents).get_name(); 56 | if (basesType === 'Array' && exponentsType === 'Array') { 57 | var basesArray = bases; 58 | var ret = new Array(basesArray.length); 59 | var baseArray = exponents; 60 | for (var i = 0; i < basesArray.length; i++) { 61 | ret[i] = Math.pow(basesArray[i], baseArray[i]); 62 | } 63 | return ret; 64 | } 65 | if (basesType === 'Array' && exponentsType === 'Number') { 66 | var basesArray = bases; 67 | var ret = new Array(basesArray.length); 68 | var bbase = exponents; 69 | for (var i = 0; i < basesArray.length; i++) { 70 | ret[i] = Math.pow(basesArray[i], bbase); 71 | } 72 | return ret; 73 | } 74 | if (basesType === 'Number' && exponentsType === 'Number') { 75 | var bbase = bases; 76 | var exponent = exponents; 77 | return Math.pow(bbase, exponent); 78 | } 79 | if (basesType === 'Number' && exponentsType === 'Array') { 80 | var bbase = bases; 81 | var exponentsArray = exponents; 82 | var ret = new Array(exponentsArray.length); 83 | for (var i = 0; i < exponentsArray.length; i++) { 84 | ret[i] = Math.pow(bbase, exponentsArray[i]); 85 | } 86 | return ret; 87 | } 88 | return 0; 89 | } 90 | numpy.exp = function numpy$exp(x) { 91 | var type = Type.getInstanceType(x).get_name(); 92 | switch (type) { 93 | case 'Array': 94 | var inputarray = x; 95 | var response = new Array(inputarray.length); 96 | for (var i = 0; i < inputarray.length; i++) { 97 | response[i] = Math.exp(inputarray[i]); 98 | } 99 | return response; 100 | default: 101 | var input = x; 102 | return Math.exp(input); 103 | } 104 | } 105 | numpy.arange = function numpy$arange(start, stop, step) { 106 | var tmp = []; 107 | if (stop == null && step == null) { 108 | for (var i = 0; i < start; i++) { 109 | tmp.add(i); 110 | } 111 | var opt1 = new Array(tmp.length); 112 | for (var i = 0; i < tmp.length; i++) { 113 | opt1[i] = tmp[i]; 114 | } 115 | return opt1; 116 | } 117 | if (step == null) { 118 | for (var i = start; i < stop; i++) { 119 | tmp.add(i); 120 | } 121 | var opt2 = new Array(tmp.length); 122 | for (var i = 0; i < tmp.length; i++) { 123 | opt2[i] = tmp[i]; 124 | } 125 | return opt2; 126 | } 127 | for (var i = start; i < stop; i = i + step) { 128 | tmp.add(i); 129 | } 130 | var opt3 = new Array(tmp.length); 131 | for (var i = 0; i < tmp.length; i++) { 132 | opt3[i] = tmp[i]; 133 | } 134 | return opt3; 135 | } 136 | numpy.zeros = function numpy$zeros(shape) { 137 | var type = Type.getInstanceType(shape).get_name(); 138 | switch (type) { 139 | case 'Array': 140 | var shapeArray = shape; 141 | var shapeObjectArray = shape; 142 | var mult = 1; 143 | for (var i = 0; i < shapeArray.length; i++) { 144 | mult *= shapeArray[i]; 145 | } 146 | var retArray = new Array(mult); 147 | for (var i = 0; i < mult; i++) { 148 | retArray[i] = 0; 149 | } 150 | return numpy._grouparray(numpy._inversearray(shapeObjectArray), retArray); 151 | default: 152 | var input = shape; 153 | var ret = new Array(input); 154 | for (var i = 0; i < input; i++) { 155 | ret[i] = 0; 156 | } 157 | return ret; 158 | } 159 | } 160 | numpy.ones = function numpy$ones(shape) { 161 | var type = Type.getInstanceType(shape).get_name(); 162 | switch (type) { 163 | case 'Array': 164 | var shapeArray = shape; 165 | var shapeObjectArray = shape; 166 | var mult = 1; 167 | for (var i = 0; i < shapeArray.length; i++) { 168 | mult *= shapeArray[i]; 169 | } 170 | var retArray = new Array(mult); 171 | for (var i = 0; i < mult; i++) { 172 | retArray[i] = 1; 173 | } 174 | return numpy._grouparray(numpy._inversearray(shapeObjectArray), retArray); 175 | default: 176 | var input = shape; 177 | var ret = new Array(input); 178 | for (var i = 0; i < input; i++) { 179 | ret[i] = 1; 180 | } 181 | return ret; 182 | } 183 | } 184 | numpy.polyfit = function numpy$polyfit(x, y, deg) { 185 | var data = new Array(x.length); 186 | for (var i = 0; i < x.length; i++) { 187 | data[i] = new PolyRegression.Pair(x[i], y[i]); 188 | } 189 | var polysolve = new PolyRegression.Matrix(); 190 | var coefs = polysolve.computeCoefficients(data, deg); 191 | var left = 0; 192 | var right = coefs.length - 1; 193 | while (left < right) { 194 | var temp = coefs[left]; 195 | coefs[left] = coefs[right]; 196 | coefs[right] = temp; 197 | left++; 198 | right--; 199 | } 200 | return coefs; 201 | } 202 | numpy.array = function numpy$array(a) { 203 | return a; 204 | } 205 | numpy.getShape = function numpy$getShape(a) { 206 | /// 207 | /// 208 | /// 209 | var obj = a.shape; 210 | return Array.toArray(obj); 211 | } 212 | numpy.reshape = function numpy$reshape(a, shape) { 213 | var assign = true; 214 | if (this.constructor.name !== 'Function') { 215 | if (Type.getInstanceType(a).get_name() === 'Array') { 216 | shape = Array.toArray(a); 217 | } 218 | else { 219 | if (arguments.length > 0) { 220 | shape = Array.toArray(arguments); 221 | } 222 | } 223 | a = this; 224 | assign = false; 225 | } 226 | var array = Array.toArray(a); 227 | var objlist = []; 228 | numpy._plainarray(objlist, array); 229 | var plain = new Array(objlist.length); 230 | for (var i = 0; i < objlist.length; i++) { 231 | plain[i] = objlist[i]; 232 | } 233 | var fixedshape = numpy._inversearray(Array.toArray(shape)); 234 | var response = numpy._grouparray(Array.toArray(fixedshape), plain); 235 | if (assign) { 236 | a.clear(); 237 | for (var i = 0; i < response.length; i++) { 238 | a.push(response[i]); 239 | } 240 | } 241 | return response; 242 | } 243 | numpy._isAligned = function numpy$_isAligned(a, b) { 244 | /// 245 | /// 246 | /// 247 | /// 248 | /// 249 | var A_shape = numpy.getShape(a); 250 | var B_shape = numpy.getShape(b); 251 | if (A_shape.length !== B_shape.length) { 252 | return false; 253 | } 254 | for (var i = A_shape.length - 1; i > 0; i = i - 2) { 255 | if (!i) { 256 | if (A_shape[i] !== B_shape[i]) { 257 | return false; 258 | } 259 | } 260 | if (A_shape[i] !== B_shape[i - 1]) { 261 | return false; 262 | } 263 | } 264 | return true; 265 | } 266 | numpy.ravel = function numpy$ravel(a) { 267 | var array = null; 268 | if (a == null) { 269 | array = this; 270 | } 271 | else { 272 | array = a; 273 | } 274 | var objlist = []; 275 | numpy._plainarray(objlist, array); 276 | var plain = new Array(objlist.length); 277 | for (var i = 0; i < objlist.length; i++) { 278 | plain[i] = objlist[i]; 279 | } 280 | return plain; 281 | } 282 | numpy.gettype = function numpy$gettype(obj) { 283 | var paramType = Type.getInstanceType(obj).get_name(); 284 | switch (paramType) { 285 | case 'Number': 286 | return paramType; 287 | case 'Array': 288 | var array = obj; 289 | var objlist = []; 290 | numpy._plainarray(objlist, array); 291 | return Type.getInstanceType(objlist[0]).get_name(); 292 | default: 293 | return 'undefined'; 294 | } 295 | } 296 | numpy._inversearray = function numpy$_inversearray(array) { 297 | var newarray = new Array(array.length); 298 | var j = array.length - 1; 299 | for (var i = 0; i < array.length; i++) { 300 | newarray[i] = array[j--]; 301 | } 302 | return newarray; 303 | } 304 | numpy._plainarray = function numpy$_plainarray(list, a) { 305 | var $enum1 = ss.IEnumerator.getEnumerator(a); 306 | while ($enum1.moveNext()) { 307 | var item = $enum1.current; 308 | if (Type.getInstanceType(item).get_name() === 'Array') { 309 | numpy._plainarray(list, item); 310 | } 311 | else { 312 | list.add(item); 313 | } 314 | } 315 | } 316 | numpy._grouparray = function numpy$_grouparray(group, array) { 317 | if (group.length > 1) { 318 | var objlist = []; 319 | var size = group[0]; 320 | for (var i = 0; i < array.length; ) { 321 | var tmp = new Array(size); 322 | for (var j = 0; j < size; j++) { 323 | tmp[j] = array[i++]; 324 | } 325 | objlist.add(tmp); 326 | } 327 | var newgroupcount = new Array(group.length - 1); 328 | for (var i = 1; i < group.length; i++) { 329 | newgroupcount[i - 1] = group[i]; 330 | } 331 | var newgroup = new Array(objlist.length); 332 | for (var i = 0; i < newgroup.length; i++) { 333 | newgroup[i] = objlist[i]; 334 | } 335 | return numpy._grouparray(newgroupcount, newgroup); 336 | } 337 | else { 338 | var size = group[0]; 339 | var newgroup = new Array(size); 340 | for (var i = 0; i < size; i++) { 341 | newgroup[i] = array[i]; 342 | } 343 | return newgroup; 344 | } 345 | } 346 | numpy.getrandom = function numpy$getrandom(size) { 347 | if (size == null) { 348 | return Math.random(); 349 | } 350 | var paramType = Type.getInstanceType(size).get_name(); 351 | switch (paramType) { 352 | case 'Number': 353 | var singlesize = size; 354 | var retsinglearray = new Array(singlesize); 355 | for (var i = 0; i < singlesize; i++) { 356 | retsinglearray[i] = Math.random(); 357 | } 358 | return retsinglearray; 359 | break; 360 | case 'Array': 361 | var sizeArray = size; 362 | var mult = 1; 363 | for (var i = 0; i < sizeArray.length; i++) { 364 | mult *= sizeArray[i]; 365 | } 366 | var ret = new Array(mult); 367 | for (var i = 0; i < mult; i++) { 368 | ret[i] = Math.random(); 369 | } 370 | return numpy._grouparray(sizeArray, ret); 371 | break; 372 | } 373 | return 0; 374 | } 375 | numpy.dot = function numpy$dot(a, b) { 376 | if (b == null) { 377 | b = a; 378 | a = this; 379 | } 380 | if (Type.getInstanceType(a).get_name() === 'Number' && Type.getInstanceType(b).get_name() === 'Array') { 381 | var b_ndim = numpy.getShape(b).length; 382 | if (b_ndim === 2) { 383 | var b_rows = numpy.getShape(b)[0]; 384 | var b_cols = numpy.getShape(b)[1]; 385 | var result = numpy.ones([ b_rows, b_cols ]); 386 | for (var br = 0; br < b_rows; br++) { 387 | for (var bc = 0; bc < b_cols; bc++) { 388 | result[br][bc] = ((Array.toArray((b)[br]))[bc]) * a; 389 | } 390 | } 391 | return result; 392 | } 393 | } 394 | if (Type.getInstanceType(a).get_name() === 'Array' && Type.getInstanceType(b).get_name() === 'Number') { 395 | var a_ndim = numpy.getShape(a).length; 396 | if (a_ndim === 2) { 397 | var a_rows = numpy.getShape(a)[0]; 398 | var a_cols = numpy.getShape(a)[1]; 399 | var result = numpy.ones([ a_rows, a_cols ]); 400 | for (var ar = 0; ar < a_rows; ar++) { 401 | for (var ac = 0; ac < a_cols; ac++) { 402 | result[ar][ac] = ((Array.toArray((a)[ar]))[ac]) * b; 403 | } 404 | } 405 | return result; 406 | } 407 | } 408 | if (Type.getInstanceType(a).get_name() === 'Array' && Type.getInstanceType(b).get_name() === 'Array') { 409 | var a_ndim = numpy.getShape(a).length; 410 | var b_ndim = numpy.getShape(b).length; 411 | if ((a_ndim === 2) && (b_ndim === 2)) { 412 | return numpy._dotMatrix(a, b); 413 | } 414 | else { 415 | return null; 416 | } 417 | } 418 | return null; 419 | } 420 | numpy.add = function numpy$add(a, b) { 421 | if (b == null) { 422 | b = a; 423 | a = this; 424 | } 425 | if (Type.getInstanceType(a).get_name() === 'Array' && Type.getInstanceType(b).get_name() === 'Array') { 426 | var a_ndim = numpy.getShape(a).length; 427 | var b_ndim = numpy.getShape(b).length; 428 | if ((a_ndim === 2) && (b_ndim === 2)) { 429 | return numpy._addMatrix(a, b); 430 | } 431 | } 432 | return null; 433 | } 434 | numpy._tupleCombination = function numpy$_tupleCombination(array) { 435 | var cardinality = 1; 436 | for (var i = 0; i < array.length; i++) { 437 | cardinality *= array[i]; 438 | } 439 | var result = new Array(cardinality); 440 | for (var i = 0; i < result.length; i++) { 441 | result[i] = new Array(array.length); 442 | } 443 | for (var j = array.length - 1; j >= 0; j--) { 444 | var each = 1; 445 | for (var e = j + 1; e < array.length; e++) { 446 | each *= array[e]; 447 | } 448 | var step = 0; 449 | var val = 0; 450 | for (var i = 0; i < cardinality; i++) { 451 | step++; 452 | var arrayValue = (Type.safeCast(result[i], Object)); 453 | arrayValue[j] = val; 454 | if (step === each) { 455 | val = (val + 1) % array[j]; 456 | step = 0; 457 | } 458 | } 459 | } 460 | return result; 461 | } 462 | numpy._getMatrixFromArray = function numpy$_getMatrixFromArray(matrix, positions, shape, numElements) { 463 | var m_shape = numpy.getShape(matrix); 464 | var Nx = m_shape[0]; 465 | var Ny = m_shape[1]; 466 | var plainarray = matrix.ravel(); 467 | var response = numpy.zeros(numElements); 468 | var value = 0; 469 | for (var i = 0; i < positions.length; i++) { 470 | var tmp = 1; 471 | for (var j = i + 1; j < shape.length; j++) { 472 | tmp *= shape[j]; 473 | } 474 | tmp *= numElements * positions[i]; 475 | value += tmp; 476 | } 477 | var pos = 0; 478 | for (var i = value; i < numElements + value; i++) { 479 | response[pos++] = plainarray[i]; 480 | } 481 | return response; 482 | } 483 | numpy._dotMatrix = function numpy$_dotMatrix(a, b) { 484 | if (numpy._isAligned(a, b)) { 485 | var nDimA = a.ndim; 486 | var nDimB = b.ndim; 487 | var a_rows = numpy.getShape(a)[0]; 488 | var a_cols = numpy.getShape(a)[1]; 489 | var b_rows = numpy.getShape(b)[0]; 490 | var b_cols = numpy.getShape(b)[1]; 491 | var c = numpy.zeros([ a_rows, b_cols + 1 ]); 492 | var matrixC = numpy.reshape(c, [ a_rows, b_cols ]); 493 | for (var ar = 0; ar < a_rows; ar++) { 494 | for (var bc = 0; bc < b_cols; bc++) { 495 | var value = 0; 496 | for (var ac = 0; ac < a_cols; ac++) { 497 | var A_ar_ac = (Array.toArray(a[ar]))[ac]; 498 | var B_ac_ar = (Array.toArray(b[ac]))[bc]; 499 | value += A_ar_ac * B_ac_ar; 500 | } 501 | matrixC[ar][bc] = value; 502 | } 503 | } 504 | return matrixC; 505 | } 506 | return null; 507 | } 508 | numpy._addMatrix = function numpy$_addMatrix(a, b) { 509 | if (numpy._isAligned(a, b)) { 510 | var nDimA = a.ndim; 511 | var nDimB = b.ndim; 512 | var a_rows = numpy.getShape(a)[0]; 513 | var a_cols = numpy.getShape(a)[1]; 514 | var b_rows = numpy.getShape(b)[0]; 515 | var b_cols = numpy.getShape(b)[1]; 516 | var zeros = numpy.zeros([ a_rows, b_cols + 1 ]); 517 | var matrixC = numpy.reshape(zeros, [ a_rows, b_cols ]); 518 | for (var r = 0; r < a_rows; r++) { 519 | for (var c = 0; c < b_cols; c++) { 520 | var A_ar_ac = (Array.toArray(a[r]))[c]; 521 | var B_br_bc = (Array.toArray(b[r]))[c]; 522 | matrixC[r][c] = A_ar_ac + B_br_bc; 523 | } 524 | } 525 | return matrixC; 526 | } 527 | return null; 528 | } 529 | numpy.concatenate = function numpy$concatenate(pparams) { 530 | if (arguments.length > 1) { 531 | var join = []; 532 | for (var i = 0; i < arguments.length; i++) { 533 | var obj = arguments[i]; 534 | switch (Type.getInstanceType(obj).get_name()) { 535 | case 'Array': 536 | var objArray = obj; 537 | for (var j = 0; j < objArray.length; j++) { 538 | join.add(objArray[j]); 539 | } 540 | break; 541 | default: 542 | join.add(obj); 543 | break; 544 | } 545 | } 546 | return join; 547 | } 548 | return pparams; 549 | } 550 | numpy.sin = function numpy$sin(value) { 551 | var type = Type.getInstanceType(value).get_name(); 552 | switch (type) { 553 | case 'Array': 554 | var shape = numpy.getShape(value); 555 | var data = value.ravel(); 556 | for (var i = 0; i < data.length; i++) { 557 | data[i] = Math.sin(data[i]); 558 | } 559 | return numpy.reshape(data, shape); 560 | default: 561 | return Math.sin(value); 562 | } 563 | } 564 | numpy.cos = function numpy$cos(value) { 565 | var type = Type.getInstanceType(value).get_name(); 566 | switch (type) { 567 | case 'Array': 568 | var shape = numpy.getShape(value); 569 | var data = value.ravel(); 570 | for (var i = 0; i < data.length; i++) { 571 | data[i] = Math.cos(data[i]); 572 | } 573 | return numpy.reshape(data, shape); 574 | default: 575 | return Math.cos(value); 576 | } 577 | } 578 | numpy.tan = function numpy$tan(value) { 579 | var type = Type.getInstanceType(value).get_name(); 580 | switch (type) { 581 | case 'Array': 582 | var shape = numpy.getShape(value); 583 | var data = value.ravel(); 584 | for (var i = 0; i < data.length; i++) { 585 | data[i] = Math.tan(data[i]); 586 | } 587 | return numpy.reshape(data, shape); 588 | default: 589 | return Math.tan(value); 590 | } 591 | } 592 | numpy.arcsin = function numpy$arcsin(value) { 593 | var type = Type.getInstanceType(value).get_name(); 594 | switch (type) { 595 | case 'Array': 596 | var shape = numpy.getShape(value); 597 | var data = value.ravel(); 598 | for (var i = 0; i < data.length; i++) { 599 | data[i] = Math.asin(data[i]); 600 | } 601 | return numpy.reshape(data, shape); 602 | default: 603 | return Math.asin(value); 604 | } 605 | } 606 | numpy.arccos = function numpy$arccos(value) { 607 | var type = Type.getInstanceType(value).get_name(); 608 | switch (type) { 609 | case 'Array': 610 | var shape = numpy.getShape(value); 611 | var data = value.ravel(); 612 | for (var i = 0; i < data.length; i++) { 613 | data[i] = Math.acos(data[i]); 614 | } 615 | return numpy.reshape(data, shape); 616 | default: 617 | return Math.acos(value); 618 | } 619 | } 620 | numpy.arctan = function numpy$arctan(value) { 621 | var type = Type.getInstanceType(value).get_name(); 622 | switch (type) { 623 | case 'Array': 624 | var shape = numpy.getShape(value); 625 | var data = value.ravel(); 626 | for (var i = 0; i < data.length; i++) { 627 | data[i] = Math.atan(data[i]); 628 | } 629 | return numpy.reshape(data, shape); 630 | default: 631 | return Math.atan(value); 632 | } 633 | } 634 | numpy.hypot = function numpy$hypot(x, y) { 635 | var xtype = Type.getInstanceType(x).get_name(); 636 | var ytype = Type.getInstanceType(y).get_name(); 637 | if ((xtype === 'Number') && (ytype === 'Number')) { 638 | return Math.sqrt((x) * (x) + (y) * (y)); 639 | } 640 | if ((xtype === 'Number') && (ytype === 'Array')) { 641 | var yshape = numpy.getShape(y); 642 | var data = y.ravel(); 643 | for (var i = 0; i < data.length; i++) { 644 | data[i] = Math.sqrt((x) * (x) + (data[i]) * (data[i])); 645 | } 646 | return numpy.reshape(data, yshape); 647 | } 648 | if ((xtype === 'Array') && (ytype === 'Number')) { 649 | var xshape = numpy.getShape(x); 650 | var data = x.ravel(); 651 | for (var i = 0; i < data.length; i++) { 652 | data[i] = Math.sqrt((data[i]) * (data[i]) + (y) * (y)); 653 | } 654 | return numpy.reshape(data, xshape); 655 | } 656 | if ((xtype === 'Array') && (ytype === 'Array')) { 657 | var xshape = numpy.getShape(x); 658 | var xdata = x.ravel(); 659 | var yshape = numpy.getShape(y); 660 | var ydata = y.ravel(); 661 | var data = numpy.arange(xdata.length); 662 | for (var i = 0; i < xdata.length; i++) { 663 | data[i] = Math.sqrt((xdata[i]) * (xdata[i]) + (ydata[i]) * (ydata[i])); 664 | } 665 | return numpy.reshape(Array.toArray(data), xshape); 666 | } 667 | return null; 668 | } 669 | numpy.arctan2 = function numpy$arctan2(x, y) { 670 | var xtype = Type.getInstanceType(x).get_name(); 671 | var ytype = Type.getInstanceType(y).get_name(); 672 | if ((xtype === 'Number') && (ytype === 'Number')) { 673 | return Math.atan2(x, y); 674 | } 675 | if ((xtype === 'Number') && (ytype === 'Array')) { 676 | var yshape = numpy.getShape(y); 677 | var data = y.ravel(); 678 | for (var i = 0; i < data.length; i++) { 679 | data[i] = Math.atan2(x, data[i]); 680 | } 681 | return numpy.reshape(data, yshape); 682 | } 683 | if ((xtype === 'Array') && (ytype === 'Number')) { 684 | var xshape = numpy.getShape(x); 685 | var data = x.ravel(); 686 | for (var i = 0; i < data.length; i++) { 687 | data[i] = Math.atan2(data[i], y); 688 | } 689 | return numpy.reshape(data, xshape); 690 | } 691 | if ((xtype === 'Array') && (ytype === 'Array')) { 692 | var xshape = numpy.getShape(x); 693 | var xdata = x.ravel(); 694 | var yshape = numpy.getShape(y); 695 | var ydata = y.ravel(); 696 | var data = numpy.arange(xdata.length); 697 | for (var i = 0; i < xdata.length; i++) { 698 | data[i] = Math.atan2(xdata[i], ydata[i]); 699 | } 700 | return numpy.reshape(Array.toArray(data), xshape); 701 | } 702 | return null; 703 | } 704 | numpy.degrees = function numpy$degrees(value) { 705 | var type = Type.getInstanceType(value).get_name(); 706 | switch (type) { 707 | case 'Array': 708 | var shape = numpy.getShape(value); 709 | var data = value.ravel(); 710 | for (var i = 0; i < data.length; i++) { 711 | data[i] = (data[i]) * (180 / Math.PI); 712 | } 713 | return numpy.reshape(data, shape); 714 | default: 715 | return (value) * (180 / Math.PI); 716 | } 717 | } 718 | numpy.radians = function numpy$radians(value) { 719 | var type = Type.getInstanceType(value).get_name(); 720 | switch (type) { 721 | case 'Array': 722 | var shape = numpy.getShape(value); 723 | var data = value.ravel(); 724 | for (var i = 0; i < data.length; i++) { 725 | data[i] = Math.PI * (data[i]) / 180; 726 | } 727 | return numpy.reshape(data, shape); 728 | default: 729 | return (value) * (180 / Math.PI); 730 | } 731 | } 732 | numpy.rad2deg = function numpy$rad2deg(value) { 733 | var type = Type.getInstanceType(value).get_name(); 734 | switch (type) { 735 | case 'Array': 736 | var shape = numpy.getShape(value); 737 | var data = value.ravel(); 738 | for (var i = 0; i < data.length; i++) { 739 | data[i] = (data[i]) * (180 / Math.PI); 740 | } 741 | return numpy.reshape(data, shape); 742 | default: 743 | return (value) * (180 / Math.PI); 744 | } 745 | } 746 | numpy.deg2rad = function numpy$deg2rad(value) { 747 | var type = Type.getInstanceType(value).get_name(); 748 | switch (type) { 749 | case 'Array': 750 | var shape = numpy.getShape(value); 751 | var data = value.ravel(); 752 | for (var i = 0; i < data.length; i++) { 753 | data[i] = Math.PI * (data[i]) / 180; 754 | } 755 | return numpy.reshape(data, shape); 756 | default: 757 | return (value) * (180 / Math.PI); 758 | } 759 | } 760 | 761 | numpy.registerClass('numpy'); 762 | Object.defineProperty(Array.prototype, "size", { 763 | get: function () { 764 | __$$tmP = this.shape; 765 | 766 | var thesize=1; 767 | for(var i=0;i<__$$tmP.length;i++) 768 | thesize*=__$$tmP[i]; 769 | return thesize; 770 | } 771 | }); 772 | Object.defineProperty(Array.prototype, "shape", { 773 | get: function () { 774 | __$$tmP = this; 775 | var dim = []; 776 | for (;;) { 777 | dim.push(__$$tmP.length); 778 | 779 | if (Array.isArray(__$$tmP[0])) { 780 | __$$tmP = __$$tmP[0]; 781 | } else { 782 | break; 783 | } 784 | } 785 | return dim; 786 | } 787 | }); 788 | Object.defineProperty(Array.prototype, "strides", { 789 | get: function () { 790 | var shp = this.shape; 791 | var dim = []; 792 | for (var i=1;i=0;i--){ 858 | if (start[i] 40 | this._x = x; 41 | this._y = y; 42 | }, 43 | 44 | eval: function interpolate$eval(valueTointerpolate) { 45 | var type = Type.getInstanceType(valueTointerpolate).get_name(); 46 | if (type === 'Array') { 47 | var inputarray = valueTointerpolate; 48 | var returns = new Array(inputarray.length); 49 | for (var i = 0; i < returns.length; i++) { 50 | returns[i] = this._f(inputarray[i]); 51 | } 52 | return returns; 53 | } 54 | else { 55 | var input = valueTointerpolate; 56 | return this._f(input); 57 | } 58 | }, 59 | 60 | _f: function interpolate$_f(valueTointerpolate) { 61 | var yval = 0; 62 | for (var i = 0; i < this._x.length - 1; i++) { 63 | if (valueTointerpolate >= this._x[i] && valueTointerpolate < this._x[i + 1]) { 64 | yval = this._y[i] + (valueTointerpolate - this._x[i]) * (this._y[i + 1] - this._y[i]) / (this._x[i + 1] - this._x[i]); 65 | return yval; 66 | } 67 | } 68 | return 0; 69 | } 70 | } 71 | 72 | 73 | stats.registerClass('stats'); 74 | interpolate.registerClass('interpolate'); 75 | })(); 76 | -------------------------------------------------------------------------------- /dist/ss.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | var globals = { 3 | isUndefined: function (o) { 4 | return (o === undefined); 5 | }, 6 | 7 | isNull: function (o) { 8 | return (o === null); 9 | }, 10 | 11 | isNullOrUndefined: function (o) { 12 | return (o === null) || (o === undefined); 13 | }, 14 | 15 | isValue: function (o) { 16 | return (o !== null) && (o !== undefined); 17 | } 18 | }; 19 | 20 | var started = false; 21 | var startCallbacks = []; 22 | 23 | function onStartup(cb) { 24 | startCallbacks ? startCallbacks.push(cb) : setTimeout(cb, 0); 25 | } 26 | function startup() { 27 | if (startCallbacks) { 28 | var callbacks = startCallbacks; 29 | startCallbacks = null; 30 | for (var i = 0, l = callbacks.length; i < l; i++) { 31 | callbacks[i](); 32 | } 33 | } 34 | } 35 | if (document.addEventListener) { 36 | document.readyState == 'complete' ? startup() : document.addEventListener('DOMContentLoaded', startup, false); 37 | } 38 | else if (window.attachEvent) { 39 | window.attachEvent('onload', function () { 40 | startup(); 41 | }); 42 | } 43 | 44 | var ss = window.ss; 45 | if (!ss) { 46 | window.ss = ss = { 47 | init: onStartup, 48 | ready: onStartup 49 | }; 50 | } 51 | for (var n in globals) { 52 | ss[n] = globals[n]; 53 | } 54 | })(); 55 | 56 | /** 57 | * Helper function for adding properties with Object.defineProperty 58 | * Copied from example on: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty 59 | */ 60 | function withValue(value) { 61 | var d = withValue.d || ( 62 | withValue.d = { 63 | enumerable: false, 64 | writable: false, 65 | configurable: false, 66 | value: null 67 | } 68 | ); 69 | d.value = value; 70 | return d; 71 | } 72 | 73 | Object.__typeName = 'Object'; 74 | Object.__baseType = null; 75 | 76 | Object.clearKeys = function Object$clearKeys(d) { 77 | for (var n in d) { 78 | delete d[n]; 79 | } 80 | } 81 | 82 | Object.keyExists = function Object$keyExists(d, key) { 83 | return d[key] !== undefined; 84 | } 85 | 86 | if (!Object.keys) { 87 | Object.keys = function Object$keys(d) { 88 | var keys = []; 89 | for (var n in d) { 90 | keys.push(n); 91 | } 92 | return keys; 93 | } 94 | 95 | Object.getKeyCount = function Object$getKeyCount(d) { 96 | var count = 0; 97 | for (var n in d) { 98 | count++; 99 | } 100 | return count; 101 | } 102 | } 103 | else { 104 | Object.getKeyCount = function Object$getKeyCount(d) { 105 | return Object.keys(d).length; 106 | } 107 | } 108 | 109 | Boolean.__typeName = 'Boolean'; 110 | 111 | Boolean.parse = function Boolean$parse(s) { 112 | return (s.toLowerCase() == 'true'); 113 | } 114 | 115 | Number.__typeName = 'Number'; 116 | 117 | Number.parse = function Number$parse(s) { 118 | if (!s || !s.length) { 119 | return 0; 120 | } 121 | if ((s.indexOf('.') >= 0) || (s.indexOf('e') >= 0) || 122 | s.endsWith('f') || s.endsWith('F')) { 123 | return parseFloat(s); 124 | } 125 | return parseInt(s, 10); 126 | } 127 | 128 | Number.prototype.format = function Number$format(format) { 129 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 130 | return this.toString(); 131 | } 132 | return this._netFormat(format, false); 133 | } 134 | 135 | Number.prototype.localeFormat = function Number$format(format) { 136 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 137 | return this.toLocaleString(); 138 | } 139 | return this._netFormat(format, true); 140 | } 141 | 142 | Number._commaFormat = function Number$_commaFormat(number, groups, decimal, comma) { 143 | var decimalPart = null; 144 | var decimalIndex = number.indexOf(decimal); 145 | if (decimalIndex > 0) { 146 | decimalPart = number.substr(decimalIndex); 147 | number = number.substr(0, decimalIndex); 148 | } 149 | 150 | var negative = number.startsWith('-'); 151 | if (negative) { 152 | number = number.substr(1); 153 | } 154 | 155 | var groupIndex = 0; 156 | var groupSize = groups[groupIndex]; 157 | if (number.length < groupSize) { 158 | return decimalPart ? number + decimalPart : number; 159 | } 160 | 161 | var index = number.length; 162 | var s = ''; 163 | var done = false; 164 | while (!done) { 165 | var length = groupSize; 166 | var startIndex = index - length; 167 | if (startIndex < 0) { 168 | groupSize += startIndex; 169 | length += startIndex; 170 | startIndex = 0; 171 | done = true; 172 | } 173 | if (!length) { 174 | break; 175 | } 176 | 177 | var part = number.substr(startIndex, length); 178 | if (s.length) { 179 | s = part + comma + s; 180 | } 181 | else { 182 | s = part; 183 | } 184 | index -= length; 185 | 186 | if (groupIndex < groups.length - 1) { 187 | groupIndex++; 188 | groupSize = groups[groupIndex]; 189 | } 190 | } 191 | 192 | if (negative) { 193 | s = '-' + s; 194 | } 195 | return decimalPart ? s + decimalPart : s; 196 | } 197 | 198 | Number.prototype._netFormat = function Number$_netFormat(format, useLocale) { 199 | var nf = useLocale ? ss.CultureInfo.CurrentCulture.numberFormat : ss.CultureInfo.InvariantCulture.numberFormat; 200 | 201 | var s = ''; 202 | var precision = -1; 203 | 204 | if (format.length > 1) { 205 | precision = parseInt(format.substr(1)); 206 | } 207 | 208 | var fs = format.charAt(0); 209 | switch (fs) { 210 | case 'd': case 'D': 211 | s = parseInt(Math.abs(this)).toString(); 212 | if (precision != -1) { 213 | s = s.padLeft(precision, '0'); 214 | } 215 | if (this < 0) { 216 | s = '-' + s; 217 | } 218 | break; 219 | case 'x': case 'X': 220 | s = parseInt(Math.abs(this)).toString(16); 221 | if (fs == 'X') { 222 | s = s.toUpperCase(); 223 | } 224 | if (precision != -1) { 225 | s = s.padLeft(precision, '0'); 226 | } 227 | break; 228 | case 'e': case 'E': 229 | if (precision == -1) { 230 | s = this.toExponential(); 231 | } 232 | else { 233 | s = this.toExponential(precision); 234 | } 235 | if (fs == 'E') { 236 | s = s.toUpperCase(); 237 | } 238 | break; 239 | case 'f': case 'F': 240 | case 'n': case 'N': 241 | if (precision == -1) { 242 | precision = nf.numberDecimalDigits; 243 | } 244 | s = this.toFixed(precision).toString(); 245 | if (precision && (nf.numberDecimalSeparator != '.')) { 246 | var index = s.indexOf('.'); 247 | s = s.substr(0, index) + nf.numberDecimalSeparator + s.substr(index + 1); 248 | } 249 | if ((fs == 'n') || (fs == 'N')) { 250 | s = Number._commaFormat(s, nf.numberGroupSizes, nf.numberDecimalSeparator, nf.numberGroupSeparator); 251 | } 252 | break; 253 | case 'c': case 'C': 254 | if (precision == -1) { 255 | precision = nf.currencyDecimalDigits; 256 | } 257 | s = Math.abs(this).toFixed(precision).toString(); 258 | if (precision && (nf.currencyDecimalSeparator != '.')) { 259 | var index = s.indexOf('.'); 260 | s = s.substr(0, index) + nf.currencyDecimalSeparator + s.substr(index + 1); 261 | } 262 | s = Number._commaFormat(s, nf.currencyGroupSizes, nf.currencyDecimalSeparator, nf.currencyGroupSeparator); 263 | if (this < 0) { 264 | s = String.format(nf.currencyNegativePattern, s); 265 | } 266 | else { 267 | s = String.format(nf.currencyPositivePattern, s); 268 | } 269 | break; 270 | case 'p': case 'P': 271 | if (precision == -1) { 272 | precision = nf.percentDecimalDigits; 273 | } 274 | s = (Math.abs(this) * 100.0).toFixed(precision).toString(); 275 | if (precision && (nf.percentDecimalSeparator != '.')) { 276 | var index = s.indexOf('.'); 277 | s = s.substr(0, index) + nf.percentDecimalSeparator + s.substr(index + 1); 278 | } 279 | s = Number._commaFormat(s, nf.percentGroupSizes, nf.percentDecimalSeparator, nf.percentGroupSeparator); 280 | if (this < 0) { 281 | s = String.format(nf.percentNegativePattern, s); 282 | } 283 | else { 284 | s = String.format(nf.percentPositivePattern, s); 285 | } 286 | break; 287 | } 288 | 289 | return s; 290 | } 291 | 292 | String.__typeName = 'String'; 293 | String.Empty = ''; 294 | 295 | String.compare = function String$compare(s1, s2, ignoreCase) { 296 | if (ignoreCase) { 297 | if (s1) { 298 | s1 = s1.toUpperCase(); 299 | } 300 | if (s2) { 301 | s2 = s2.toUpperCase(); 302 | } 303 | } 304 | s1 = s1 || ''; 305 | s2 = s2 || ''; 306 | 307 | if (s1 == s2) { 308 | return 0; 309 | } 310 | if (s1 < s2) { 311 | return -1; 312 | } 313 | return 1; 314 | } 315 | 316 | String.prototype.compareTo = function String$compareTo(s, ignoreCase) { 317 | return String.compare(this, s, ignoreCase); 318 | } 319 | 320 | String.concat = function String$concat() { 321 | if (arguments.length === 2) { 322 | return arguments[0] + arguments[1]; 323 | } 324 | return Array.prototype.join.call(arguments, ''); 325 | } 326 | 327 | String.prototype.endsWith = function String$endsWith(suffix) { 328 | if (!suffix.length) { 329 | return true; 330 | } 331 | if (suffix.length > this.length) { 332 | return false; 333 | } 334 | return (this.substr(this.length - suffix.length) == suffix); 335 | } 336 | 337 | String.equals = function String$equals1(s1, s2, ignoreCase) { 338 | return String.compare(s1, s2, ignoreCase) == 0; 339 | } 340 | 341 | String._format = function String$_format(format, values, useLocale) { 342 | if (!String._formatRE) { 343 | String._formatRE = /(\{[^\}^\{]+\})/g; 344 | } 345 | 346 | return format.replace(String._formatRE, 347 | function(str, m) { 348 | var index = parseInt(m.substr(1)); 349 | var value = values[index + 1]; 350 | if (ss.isNullOrUndefined(value)) { 351 | return ''; 352 | } 353 | if (value.format) { 354 | var formatSpec = null; 355 | var formatIndex = m.indexOf(':'); 356 | if (formatIndex > 0) { 357 | formatSpec = m.substring(formatIndex + 1, m.length - 1); 358 | } 359 | return useLocale ? value.localeFormat(formatSpec) : value.format(formatSpec); 360 | } 361 | else { 362 | return useLocale ? value.toLocaleString() : value.toString(); 363 | } 364 | }); 365 | } 366 | 367 | String.format = function String$format(format) { 368 | return String._format(format, arguments, /* useLocale */ false); 369 | } 370 | 371 | String.fromChar = function String$fromChar(ch, count) { 372 | var s = ch; 373 | for (var i = 1; i < count; i++) { 374 | s += ch; 375 | } 376 | return s; 377 | } 378 | 379 | String.prototype.htmlDecode = function String$htmlDecode() { 380 | var div = document.createElement('div'); 381 | div.innerHTML = this; 382 | return div.textContent || div.innerText; 383 | } 384 | 385 | String.prototype.htmlEncode = function String$htmlEncode() { 386 | var div = document.createElement('div'); 387 | div.appendChild(document.createTextNode(this)); 388 | return div.innerHTML.replace(/\"/g, '"'); 389 | } 390 | 391 | String.prototype.indexOfAny = function String$indexOfAny(chars, startIndex, count) { 392 | var length = this.length; 393 | if (!length) { 394 | return -1; 395 | } 396 | 397 | startIndex = startIndex || 0; 398 | count = count || length; 399 | 400 | var endIndex = startIndex + count - 1; 401 | if (endIndex >= length) { 402 | endIndex = length - 1; 403 | } 404 | 405 | for (var i = startIndex; i <= endIndex; i++) { 406 | if (chars.indexOf(this.charAt(i)) >= 0) { 407 | return i; 408 | } 409 | } 410 | return -1; 411 | } 412 | 413 | String.prototype.insert = function String$insert(index, value) { 414 | if (!value) { 415 | return this.valueOf(); 416 | } 417 | if (!index) { 418 | return value + this; 419 | } 420 | var s1 = this.substr(0, index); 421 | var s2 = this.substr(index); 422 | return s1 + value + s2; 423 | } 424 | 425 | String.isNullOrEmpty = function String$isNullOrEmpty(s) { 426 | return !s || !s.length; 427 | } 428 | 429 | String.isNullOrWhiteSpace = function String$isNullOrWhiteSpace(s) { 430 | return String.isNullOrEmpty(s) || s.trim() === ""; 431 | } 432 | 433 | String.prototype.lastIndexOfAny = function String$lastIndexOfAny(chars, startIndex, count) { 434 | var length = this.length; 435 | if (!length) { 436 | return -1; 437 | } 438 | 439 | startIndex = startIndex || length - 1; 440 | count = count || length; 441 | 442 | var endIndex = startIndex - count + 1; 443 | if (endIndex < 0) { 444 | endIndex = 0; 445 | } 446 | 447 | for (var i = startIndex; i >= endIndex; i--) { 448 | if (chars.indexOf(this.charAt(i)) >= 0) { 449 | return i; 450 | } 451 | } 452 | return -1; 453 | } 454 | 455 | String.localeFormat = function String$localeFormat(format) { 456 | return String._format(format, arguments, /* useLocale */ true); 457 | } 458 | 459 | String.prototype.padLeft = function String$padLeft(totalWidth, ch) { 460 | if (this.length < totalWidth) { 461 | ch = ch || ' '; 462 | return String.fromChar(ch, totalWidth - this.length) + this; 463 | } 464 | return this.valueOf(); 465 | } 466 | 467 | String.prototype.padRight = function String$padRight(totalWidth, ch) { 468 | if (this.length < totalWidth) { 469 | ch = ch || ' '; 470 | return this + String.fromChar(ch, totalWidth - this.length); 471 | } 472 | return this.valueOf(); 473 | } 474 | 475 | String.prototype.remove = function String$remove(index, count) { 476 | if (!count || ((index + count) > this.length)) { 477 | return this.substr(0, index); 478 | } 479 | return this.substr(0, index) + this.substr(index + count); 480 | } 481 | 482 | String.prototype.replaceAll = function String$replaceAll(oldValue, newValue) { 483 | newValue = newValue || ''; 484 | return this.split(oldValue).join(newValue); 485 | } 486 | 487 | String.prototype.startsWith = function String$startsWith(prefix) { 488 | if (!prefix.length) { 489 | return true; 490 | } 491 | if (prefix.length > this.length) { 492 | return false; 493 | } 494 | return (this.substr(0, prefix.length) == prefix); 495 | } 496 | 497 | if (!String.prototype.trim) { 498 | String.prototype.trim = function String$trim() { 499 | return this.trimEnd().trimStart(); 500 | } 501 | } 502 | 503 | String.prototype.trimEnd = function String$trimEnd() { 504 | return this.replace(/\s*$/, ''); 505 | } 506 | 507 | String.prototype.trimStart = function String$trimStart() { 508 | return this.replace(/^\s*/, ''); 509 | } 510 | 511 | Array.__typeName = 'Array'; 512 | Array.__interfaces = [ ss.IEnumerable ]; 513 | 514 | Object.defineProperty(Array.prototype, 'add', withValue(function Array$add(item) { 515 | this[this.length] = item; 516 | })); 517 | 518 | Object.defineProperty(Array.prototype, 'addRange', withValue(function Array$addRange(items) { 519 | this.push.apply(this, items); 520 | })); 521 | 522 | Object.defineProperty(Array.prototype, 'aggregate', withValue(function Array$aggregate(seed, callback, instance) { 523 | var length = this.length; 524 | for (var i = 0; i < length; i++) { 525 | if (i in this) { 526 | seed = callback.call(instance, seed, this[i], i, this); 527 | } 528 | } 529 | return seed; 530 | })); 531 | 532 | Object.defineProperty(Array.prototype, 'clear', withValue(function Array$clear() { 533 | this.length = 0; 534 | })); 535 | 536 | Object.defineProperty(Array.prototype, 'clone', withValue(function Array$clone() { 537 | if (this.length === 1) { 538 | return [this[0]]; 539 | } 540 | else { 541 | return Array.apply(null, this); 542 | } 543 | })); 544 | 545 | Object.defineProperty(Array.prototype, 'contains', withValue(function Array$contains(item) { 546 | var index = this.indexOf(item); 547 | return (index >= 0); 548 | })); 549 | 550 | Object.defineProperty(Array.prototype, 'dequeue', withValue(function Array$dequeue() { 551 | return this.shift(); 552 | })); 553 | 554 | Object.defineProperty(Array.prototype, 'enqueue', withValue(function Array$enqueue(item) { 555 | this._queue = true; 556 | this.push(item); 557 | })); 558 | 559 | Object.defineProperty(Array.prototype, 'peek', withValue(function Array$peek() { 560 | if (this.length) { 561 | var index = this._queue ? 0 : this.length - 1; 562 | return this[index]; 563 | } 564 | return null; 565 | })); 566 | 567 | if (!Array.prototype.every) { 568 | Object.defineProperty(Array.prototype, 'every', withValue(function Array$every(callback, instance) { 569 | var length = this.length; 570 | for (var i = 0; i < length; i++) { 571 | if (i in this && !callback.call(instance, this[i], i, this)) { 572 | return false; 573 | } 574 | } 575 | return true; 576 | })); 577 | } 578 | 579 | Object.defineProperty(Array.prototype, 'extract', withValue(function Array$extract(index, count) { 580 | if (!count) { 581 | return this.slice(index); 582 | } 583 | return this.slice(index, index + count); 584 | })); 585 | 586 | if (!Array.prototype.filter) { 587 | Object.defineProperty(Array.prototype, 'filter', withValue(function Array$filter(callback, instance) { 588 | var length = this.length; 589 | var filtered = []; 590 | for (var i = 0; i < length; i++) { 591 | if (i in this) { 592 | var val = this[i]; 593 | if (callback.call(instance, val, i, this)) { 594 | filtered.push(val); 595 | } 596 | } 597 | } 598 | return filtered; 599 | })); 600 | } 601 | 602 | if (!Array.prototype.forEach) { 603 | Object.defineProperty(Array.prototype, 'forEach', withValue(function Array$forEach(callback, instance) { 604 | var length = this.length; 605 | for (var i = 0; i < length; i++) { 606 | if (i in this) { 607 | callback.call(instance, this[i], i, this); 608 | } 609 | } 610 | })); 611 | } 612 | 613 | Object.defineProperty(Array.prototype, 'getEnumerator', withValue(function Array$getEnumerator() { 614 | return new ss.ArrayEnumerator(this); 615 | })); 616 | 617 | Object.defineProperty(Array.prototype, 'groupBy', withValue(function Array$groupBy(callback, instance) { 618 | var length = this.length; 619 | var groups = []; 620 | var keys = {}; 621 | for (var i = 0; i < length; i++) { 622 | if (i in this) { 623 | var key = callback.call(instance, this[i], i); 624 | if (String.isNullOrEmpty(key)) { 625 | continue; 626 | } 627 | var items = keys[key]; 628 | if (!items) { 629 | items = []; 630 | items.key = key; 631 | 632 | keys[key] = items; 633 | groups.add(items); 634 | } 635 | items.add(this[i]); 636 | } 637 | } 638 | return groups; 639 | })); 640 | 641 | Object.defineProperty(Array.prototype, 'index', withValue(function Array$index(callback, instance) { 642 | var length = this.length; 643 | var items = {}; 644 | for (var i = 0; i < length; i++) { 645 | if (i in this) { 646 | var key = callback.call(instance, this[i], i); 647 | if (String.isNullOrEmpty(key)) { 648 | continue; 649 | } 650 | items[key] = this[i]; 651 | } 652 | } 653 | return items; 654 | })); 655 | 656 | if (!Array.prototype.indexOf) { 657 | Object.defineProperty(Array.prototype, 'indexOf', withValue(function Array$indexOf(item, startIndex) { 658 | startIndex = startIndex || 0; 659 | var length = this.length; 660 | if (length) { 661 | for (var index = startIndex; index < length; index++) { 662 | if (this[index] === item) { 663 | return index; 664 | } 665 | } 666 | } 667 | return -1; 668 | })); 669 | } 670 | 671 | Object.defineProperty(Array.prototype, 'insert', withValue(function Array$insert(index, item) { 672 | this.splice(index, 0, item); 673 | })); 674 | 675 | Object.defineProperty(Array.prototype, 'insertRange', withValue(function Array$insertRange(index, items) { 676 | if (index === 0) { 677 | this.unshift.apply(this, items); 678 | } 679 | else { 680 | for (var i = 0; i < items.length; i++) { 681 | this.splice(index + i, 0, items[i]); 682 | } 683 | } 684 | })); 685 | 686 | if (!Array.prototype.map) { 687 | Object.defineProperty(Array.prototype, 'map', withValue(function Array$map(callback, instance) { 688 | var length = this.length; 689 | var mapped = new Array(length); 690 | for (var i = 0; i < length; i++) { 691 | if (i in this) { 692 | mapped[i] = callback.call(instance, this[i], i, this); 693 | } 694 | } 695 | return mapped; 696 | })); 697 | } 698 | 699 | Array.parse = function Array$parse(s) { 700 | return eval('(' + s + ')'); 701 | } 702 | 703 | Object.defineProperty(Array.prototype, 'remove', withValue(function Array$remove(item) { 704 | var index = this.indexOf(item); 705 | if (index >= 0) { 706 | this.splice(index, 1); 707 | return true; 708 | } 709 | return false; 710 | })); 711 | 712 | Object.defineProperty(Array.prototype, 'removeAt', withValue(function Array$removeAt(index) { 713 | this.splice(index, 1); 714 | })); 715 | 716 | Object.defineProperty(Array.prototype, 'removeRange', withValue(function Array$removeRange(index, count) { 717 | return this.splice(index, count); 718 | })); 719 | 720 | if (!Array.prototype.some) { 721 | Object.defineProperty(Array.prototype, 'some', withValue(function Array$some(callback, instance) { 722 | var length = this.length; 723 | for (var i = 0; i < length; i++) { 724 | if (i in this && callback.call(instance, this[i], i, this)) { 725 | return true; 726 | } 727 | } 728 | return false; 729 | })); 730 | } 731 | 732 | Array.toArray = function Array$toArray(obj) { 733 | return Array.prototype.slice.call(obj); 734 | } 735 | 736 | RegExp.__typeName = 'RegExp'; 737 | 738 | RegExp.parse = function RegExp$parse(s) { 739 | if (s.startsWith('/')) { 740 | var endSlashIndex = s.lastIndexOf('/'); 741 | if (endSlashIndex > 1) { 742 | var expression = s.substring(1, endSlashIndex); 743 | var flags = s.substr(endSlashIndex + 1); 744 | return new RegExp(expression, flags); 745 | } 746 | } 747 | 748 | return null; 749 | } 750 | 751 | Date.__typeName = 'Date'; 752 | 753 | Date.empty = null; 754 | 755 | Date.get_now = function Date$get_now() { 756 | return new Date(); 757 | } 758 | 759 | Date.get_today = function Date$get_today() { 760 | var d = new Date(); 761 | return new Date(d.getFullYear(), d.getMonth(), d.getDate()); 762 | } 763 | 764 | Date.isEmpty = function Date$isEmpty(d) { 765 | return (d === null) || (d.valueOf() === 0); 766 | } 767 | 768 | Date.prototype.format = function Date$format(format) { 769 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 770 | return this.toString(); 771 | } 772 | if (format == 'id') { 773 | return this.toDateString(); 774 | } 775 | if (format == 'it') { 776 | return this.toTimeString(); 777 | } 778 | 779 | return this._netFormat(format, false); 780 | } 781 | 782 | Date.prototype.localeFormat = function Date$localeFormat(format) { 783 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 784 | return this.toLocaleString(); 785 | } 786 | if (format == 'id') { 787 | return this.toLocaleDateString(); 788 | } 789 | if (format == 'it') { 790 | return this.toLocaleTimeString(); 791 | } 792 | 793 | return this._netFormat(format, true); 794 | } 795 | 796 | Date.prototype._netFormat = function Date$_netFormat(format, useLocale) { 797 | var dt = this; 798 | var dtf = useLocale ? ss.CultureInfo.CurrentCulture.dateFormat : ss.CultureInfo.InvariantCulture.dateFormat; 799 | 800 | if (format.length == 1) { 801 | switch (format) { 802 | case 'f': format = dtf.longDatePattern + ' ' + dtf.shortTimePattern; break; 803 | case 'F': format = dtf.dateTimePattern; break; 804 | 805 | case 'd': format = dtf.shortDatePattern; break; 806 | case 'D': format = dtf.longDatePattern; break; 807 | 808 | case 't': format = dtf.shortTimePattern; break; 809 | case 'T': format = dtf.longTimePattern; break; 810 | 811 | case 'g': format = dtf.shortDatePattern + ' ' + dtf.shortTimePattern; break; 812 | case 'G': format = dtf.shortDatePattern + ' ' + dtf.longTimePattern; break; 813 | 814 | case 'R': case 'r': 815 | dtf = ss.CultureInfo.InvariantCulture.dateFormat; 816 | format = dtf.gmtDateTimePattern; 817 | break; 818 | case 'u': format = dtf.universalDateTimePattern; break; 819 | case 'U': 820 | format = dtf.dateTimePattern; 821 | dt = new Date(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate(), 822 | dt.getUTCHours(), dt.getUTCMinutes(), dt.getUTCSeconds(), dt.getUTCMilliseconds()); 823 | break; 824 | 825 | case 's': format = dtf.sortableDateTimePattern; break; 826 | } 827 | } 828 | 829 | if (format.charAt(0) == '%') { 830 | format = format.substr(1); 831 | } 832 | 833 | if (!Date._formatRE) { 834 | Date._formatRE = /'.*?[^\\]'|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z/g; 835 | } 836 | 837 | var re = Date._formatRE; 838 | var sb = new ss.StringBuilder(); 839 | 840 | re.lastIndex = 0; 841 | while (true) { 842 | var index = re.lastIndex; 843 | var match = re.exec(format); 844 | 845 | sb.append(format.slice(index, match ? match.index : format.length)); 846 | if (!match) { 847 | break; 848 | } 849 | 850 | var fs = match[0]; 851 | var part = fs; 852 | switch (fs) { 853 | case 'dddd': 854 | part = dtf.dayNames[dt.getDay()]; 855 | break; 856 | case 'ddd': 857 | part = dtf.shortDayNames[dt.getDay()]; 858 | break; 859 | case 'dd': 860 | part = dt.getDate().toString().padLeft(2, '0'); 861 | break; 862 | case 'd': 863 | part = dt.getDate(); 864 | break; 865 | case 'MMMM': 866 | part = dtf.monthNames[dt.getMonth()]; 867 | break; 868 | case 'MMM': 869 | part = dtf.shortMonthNames[dt.getMonth()]; 870 | break; 871 | case 'MM': 872 | part = (dt.getMonth() + 1).toString().padLeft(2, '0'); 873 | break; 874 | case 'M': 875 | part = (dt.getMonth() + 1); 876 | break; 877 | case 'yyyy': 878 | part = dt.getFullYear(); 879 | break; 880 | case 'yy': 881 | part = (dt.getFullYear() % 100).toString().padLeft(2, '0'); 882 | break; 883 | case 'y': 884 | part = (dt.getFullYear() % 100); 885 | break; 886 | case 'h': case 'hh': 887 | part = dt.getHours() % 12; 888 | if (!part) { 889 | part = '12'; 890 | } 891 | else if (fs == 'hh') { 892 | part = part.toString().padLeft(2, '0'); 893 | } 894 | break; 895 | case 'HH': 896 | part = dt.getHours().toString().padLeft(2, '0'); 897 | break; 898 | case 'H': 899 | part = dt.getHours(); 900 | break; 901 | case 'mm': 902 | part = dt.getMinutes().toString().padLeft(2, '0'); 903 | break; 904 | case 'm': 905 | part = dt.getMinutes(); 906 | break; 907 | case 'ss': 908 | part = dt.getSeconds().toString().padLeft(2, '0'); 909 | break; 910 | case 's': 911 | part = dt.getSeconds(); 912 | break; 913 | case 't': case 'tt': 914 | part = (dt.getHours() < 12) ? dtf.amDesignator : dtf.pmDesignator; 915 | if (fs == 't') { 916 | part = part.charAt(0); 917 | } 918 | break; 919 | case 'fff': 920 | part = dt.getMilliseconds().toString().padLeft(3, '0'); 921 | break; 922 | case 'ff': 923 | part = dt.getMilliseconds().toString().padLeft(3).substr(0, 2); 924 | break; 925 | case 'f': 926 | part = dt.getMilliseconds().toString().padLeft(3).charAt(0); 927 | break; 928 | case 'z': 929 | part = dt.getTimezoneOffset() / 60; 930 | part = ((part >= 0) ? '-' : '+') + Math.floor(Math.abs(part)); 931 | break; 932 | case 'zz': case 'zzz': 933 | part = dt.getTimezoneOffset() / 60; 934 | part = ((part >= 0) ? '-' : '+') + Math.floor(Math.abs(part)).toString().padLeft(2, '0'); 935 | if (fs == 'zzz') { 936 | part += dtf.timeSeparator + Math.abs(dt.getTimezoneOffset() % 60).toString().padLeft(2, '0'); 937 | } 938 | break; 939 | default: 940 | if (part.charAt(0) == '\'') { 941 | part = part.substr(1, part.length - 2).replace(/\\'/g, '\''); 942 | } 943 | break; 944 | } 945 | sb.append(part); 946 | } 947 | 948 | return sb.toString(); 949 | } 950 | 951 | Date.parseDate = function Date$parse(s) { 952 | var t = Date.parse(s); 953 | return isNaN(t) ? t : new Date(t); 954 | } 955 | 956 | Error.__typeName = 'Error'; 957 | 958 | Error.prototype.popStackFrame = function Error$popStackFrame() { 959 | if (ss.isNullOrUndefined(this.stack) || 960 | ss.isNullOrUndefined(this.fileName) || 961 | ss.isNullOrUndefined(this.lineNumber)) { 962 | return; 963 | } 964 | 965 | var stackFrames = this.stack.split('\n'); 966 | var currentFrame = stackFrames[0]; 967 | var pattern = this.fileName + ':' + this.lineNumber; 968 | while (!ss.isNullOrUndefined(currentFrame) && 969 | currentFrame.indexOf(pattern) === -1) { 970 | stackFrames.shift(); 971 | currentFrame = stackFrames[0]; 972 | } 973 | 974 | var nextFrame = stackFrames[1]; 975 | if (isNullOrUndefined(nextFrame)) { 976 | return; 977 | } 978 | 979 | var nextFrameParts = nextFrame.match(/@(.*):(\d+)$/); 980 | if (ss.isNullOrUndefined(nextFrameParts)) { 981 | return; 982 | } 983 | 984 | stackFrames.shift(); 985 | this.stack = stackFrames.join("\n"); 986 | this.fileName = nextFrameParts[1]; 987 | this.lineNumber = parseInt(nextFrameParts[2]); 988 | } 989 | 990 | Error.createError = function Error$createError(message, errorInfo, innerException) { 991 | var e = new Error(message); 992 | if (errorInfo) { 993 | for (var v in errorInfo) { 994 | e[v] = errorInfo[v]; 995 | } 996 | } 997 | if (innerException) { 998 | e.innerException = innerException; 999 | } 1000 | 1001 | e.popStackFrame(); 1002 | return e; 1003 | } 1004 | 1005 | ss.Debug = window.Debug || function() {}; 1006 | ss.Debug.__typeName = 'Debug'; 1007 | 1008 | if (!ss.Debug.writeln) { 1009 | ss.Debug.writeln = function Debug$writeln(text) { 1010 | if (window.console) { 1011 | if (window.console.debug) { 1012 | window.console.debug(text); 1013 | return; 1014 | } 1015 | else if (window.console.log) { 1016 | window.console.log(text); 1017 | return; 1018 | } 1019 | } 1020 | else if (window.opera && 1021 | window.opera.postError) { 1022 | window.opera.postError(text); 1023 | return; 1024 | } 1025 | } 1026 | } 1027 | 1028 | ss.Debug._fail = function Debug$_fail(message) { 1029 | ss.Debug.writeln(message); 1030 | eval('debugger;'); 1031 | } 1032 | 1033 | ss.Debug.assert = function Debug$assert(condition, message) { 1034 | if (!condition) { 1035 | message = 'Assert failed: ' + message; 1036 | if (confirm(message + '\r\n\r\nBreak into debugger?')) { 1037 | ss.Debug._fail(message); 1038 | } 1039 | } 1040 | } 1041 | 1042 | ss.Debug.fail = function Debug$fail(message) { 1043 | ss.Debug._fail(message); 1044 | } 1045 | 1046 | window.Type = Function; 1047 | Type.__typeName = 'Type'; 1048 | 1049 | window.__Namespace = function(name) { 1050 | this.__typeName = name; 1051 | } 1052 | __Namespace.prototype = { 1053 | __namespace: true, 1054 | getName: function() { 1055 | return this.__typeName; 1056 | } 1057 | } 1058 | 1059 | Type.registerNamespace = function Type$registerNamespace(name) { 1060 | if (!window.__namespaces) { 1061 | window.__namespaces = {}; 1062 | } 1063 | if (!window.__rootNamespaces) { 1064 | window.__rootNamespaces = []; 1065 | } 1066 | 1067 | if (window.__namespaces[name]) { 1068 | return; 1069 | } 1070 | 1071 | var ns = window; 1072 | var nameParts = name.split('.'); 1073 | 1074 | for (var i = 0; i < nameParts.length; i++) { 1075 | var part = nameParts[i]; 1076 | var nso = ns[part]; 1077 | if (!nso) { 1078 | ns[part] = nso = new __Namespace(nameParts.slice(0, i + 1).join('.')); 1079 | if (i == 0) { 1080 | window.__rootNamespaces.add(nso); 1081 | } 1082 | } 1083 | ns = nso; 1084 | } 1085 | 1086 | window.__namespaces[name] = ns; 1087 | } 1088 | 1089 | Type.prototype.registerClass = function Type$registerClass(name, baseType, interfaceType) { 1090 | this.prototype.constructor = this; 1091 | this.__typeName = name; 1092 | this.__class = true; 1093 | this.__baseType = baseType || Object; 1094 | if (baseType) { 1095 | this.__basePrototypePending = true; 1096 | } 1097 | 1098 | if (interfaceType) { 1099 | this.__interfaces = []; 1100 | for (var i = 2; i < arguments.length; i++) { 1101 | interfaceType = arguments[i]; 1102 | this.__interfaces.add(interfaceType); 1103 | } 1104 | } 1105 | } 1106 | 1107 | Type.prototype.registerInterface = function Type$createInterface(name) { 1108 | this.__typeName = name; 1109 | this.__interface = true; 1110 | } 1111 | 1112 | Type.prototype.registerEnum = function Type$createEnum(name, flags) { 1113 | for (var field in this.prototype) { 1114 | this[field] = this.prototype[field]; 1115 | } 1116 | 1117 | this.__typeName = name; 1118 | this.__enum = true; 1119 | if (flags) { 1120 | this.__flags = true; 1121 | } 1122 | } 1123 | 1124 | Type.prototype.setupBase = function Type$setupBase() { 1125 | if (this.__basePrototypePending) { 1126 | var baseType = this.__baseType; 1127 | if (baseType.__basePrototypePending) { 1128 | baseType.setupBase(); 1129 | } 1130 | 1131 | for (var memberName in baseType.prototype) { 1132 | var memberValue = baseType.prototype[memberName]; 1133 | if (!this.prototype[memberName]) { 1134 | this.prototype[memberName] = memberValue; 1135 | } 1136 | } 1137 | 1138 | delete this.__basePrototypePending; 1139 | } 1140 | } 1141 | 1142 | if (!Type.prototype.resolveInheritance) { 1143 | Type.prototype.resolveInheritance = Type.prototype.setupBase; 1144 | } 1145 | 1146 | Type.prototype.initializeBase = function Type$initializeBase(instance, args) { 1147 | if (this.__basePrototypePending) { 1148 | this.setupBase(); 1149 | } 1150 | 1151 | if (!args) { 1152 | this.__baseType.apply(instance); 1153 | } 1154 | else { 1155 | this.__baseType.apply(instance, args); 1156 | } 1157 | } 1158 | 1159 | Type.prototype.callBaseMethod = function Type$callBaseMethod(instance, name, args) { 1160 | var baseMethod = this.__baseType.prototype[name]; 1161 | if (!args) { 1162 | return baseMethod.apply(instance); 1163 | } 1164 | else { 1165 | return baseMethod.apply(instance, args); 1166 | } 1167 | } 1168 | 1169 | Type.prototype.get_baseType = function Type$get_baseType() { 1170 | return this.__baseType || null; 1171 | } 1172 | 1173 | Type.prototype.get_fullName = function Type$get_fullName() { 1174 | return this.__typeName; 1175 | } 1176 | 1177 | Type.prototype.get_name = function Type$get_name() { 1178 | var fullName = this.__typeName; 1179 | var nsIndex = fullName.lastIndexOf('.'); 1180 | if (nsIndex > 0) { 1181 | return fullName.substr(nsIndex + 1); 1182 | } 1183 | return fullName; 1184 | } 1185 | 1186 | Type.prototype.getInterfaces = function Type$getInterfaces() { 1187 | return this.__interfaces; 1188 | } 1189 | 1190 | Type.prototype.isInstanceOfType = function Type$isInstanceOfType(instance) { 1191 | if (ss.isNullOrUndefined(instance)) { 1192 | return false; 1193 | } 1194 | if ((this == Object) || (instance instanceof this)) { 1195 | return true; 1196 | } 1197 | 1198 | var type = Type.getInstanceType(instance); 1199 | return this.isAssignableFrom(type); 1200 | } 1201 | 1202 | Type.prototype.isAssignableFrom = function Type$isAssignableFrom(type) { 1203 | if ((this == Object) || (this == type)) { 1204 | return true; 1205 | } 1206 | if (this.__class) { 1207 | var baseType = type.__baseType; 1208 | while (baseType) { 1209 | if (this == baseType) { 1210 | return true; 1211 | } 1212 | baseType = baseType.__baseType; 1213 | } 1214 | } 1215 | else if (this.__interface) { 1216 | var interfaces = type.__interfaces; 1217 | if (interfaces && interfaces.contains(this)) { 1218 | return true; 1219 | } 1220 | 1221 | var baseType = type.__baseType; 1222 | while (baseType) { 1223 | interfaces = baseType.__interfaces; 1224 | if (interfaces && interfaces.contains(this)) { 1225 | return true; 1226 | } 1227 | baseType = baseType.__baseType; 1228 | } 1229 | } 1230 | return false; 1231 | } 1232 | 1233 | Type.isClass = function Type$isClass(type) { 1234 | return (type.__class == true); 1235 | } 1236 | 1237 | Type.isEnum = function Type$isEnum(type) { 1238 | return (type.__enum == true); 1239 | } 1240 | 1241 | Type.isFlags = function Type$isFlags(type) { 1242 | return ((type.__enum == true) && (type.__flags == true)); 1243 | } 1244 | 1245 | Type.isInterface = function Type$isInterface(type) { 1246 | return (type.__interface == true); 1247 | } 1248 | 1249 | Type.isNamespace = function Type$isNamespace(object) { 1250 | return (object.__namespace == true); 1251 | } 1252 | 1253 | Type.canCast = function Type$canCast(instance, type) { 1254 | return type.isInstanceOfType(instance); 1255 | } 1256 | 1257 | Type.safeCast = function Type$safeCast(instance, type) { 1258 | if (type.isInstanceOfType(instance)) { 1259 | return instance; 1260 | } 1261 | return null; 1262 | } 1263 | 1264 | Type.getInstanceType = function Type$getInstanceType(instance) { 1265 | var ctor = null; 1266 | try { 1267 | ctor = instance.constructor; 1268 | } 1269 | catch (ex) { 1270 | } 1271 | if (!ctor || !ctor.__typeName) { 1272 | ctor = Object; 1273 | } 1274 | return ctor; 1275 | } 1276 | 1277 | Type.getType = function Type$getType(typeName) { 1278 | if (!typeName) { 1279 | return null; 1280 | } 1281 | 1282 | if (!Type.__typeCache) { 1283 | Type.__typeCache = {}; 1284 | } 1285 | 1286 | var type = Type.__typeCache[typeName]; 1287 | if (!type) { 1288 | type = eval(typeName); 1289 | Type.__typeCache[typeName] = type; 1290 | } 1291 | return type; 1292 | } 1293 | 1294 | Type.parse = function Type$parse(typeName) { 1295 | return Type.getType(typeName); 1296 | } 1297 | 1298 | ss.Delegate = function Delegate$() { 1299 | } 1300 | ss.Delegate.registerClass('Delegate'); 1301 | 1302 | ss.Delegate.empty = function() { } 1303 | 1304 | ss.Delegate._contains = function Delegate$_contains(targets, object, method) { 1305 | for (var i = 0; i < targets.length; i += 2) { 1306 | if (targets[i] === object && targets[i + 1] === method) { 1307 | return true; 1308 | } 1309 | } 1310 | return false; 1311 | } 1312 | 1313 | ss.Delegate._create = function Delegate$_create(targets) { 1314 | var delegate = function() { 1315 | if (targets.length == 2) { 1316 | return targets[1].apply(targets[0], arguments); 1317 | } 1318 | else { 1319 | var clone = targets.clone(); 1320 | for (var i = 0; i < clone.length; i += 2) { 1321 | if (ss.Delegate._contains(targets, clone[i], clone[i + 1])) { 1322 | clone[i + 1].apply(clone[i], arguments); 1323 | } 1324 | } 1325 | return null; 1326 | } 1327 | }; 1328 | delegate._targets = targets; 1329 | 1330 | return delegate; 1331 | } 1332 | 1333 | ss.Delegate.create = function Delegate$create(object, method) { 1334 | if (!object) { 1335 | return method; 1336 | } 1337 | return ss.Delegate._create([object, method]); 1338 | } 1339 | 1340 | ss.Delegate.combine = function Delegate$combine(delegate1, delegate2) { 1341 | if (!delegate1) { 1342 | if (!delegate2._targets) { 1343 | return ss.Delegate.create(null, delegate2); 1344 | } 1345 | return delegate2; 1346 | } 1347 | if (!delegate2) { 1348 | if (!delegate1._targets) { 1349 | return ss.Delegate.create(null, delegate1); 1350 | } 1351 | return delegate1; 1352 | } 1353 | 1354 | var targets1 = delegate1._targets ? delegate1._targets : [null, delegate1]; 1355 | var targets2 = delegate2._targets ? delegate2._targets : [null, delegate2]; 1356 | 1357 | return ss.Delegate._create(targets1.concat(targets2)); 1358 | } 1359 | 1360 | ss.Delegate.remove = function Delegate$remove(delegate1, delegate2) { 1361 | if (!delegate1 || (delegate1 === delegate2)) { 1362 | return null; 1363 | } 1364 | if (!delegate2) { 1365 | return delegate1; 1366 | } 1367 | 1368 | var targets = delegate1._targets; 1369 | var object = null; 1370 | var method; 1371 | if (delegate2._targets) { 1372 | object = delegate2._targets[0]; 1373 | method = delegate2._targets[1]; 1374 | } 1375 | else { 1376 | method = delegate2; 1377 | } 1378 | 1379 | for (var i = 0; i < targets.length; i += 2) { 1380 | if ((targets[i] === object) && (targets[i + 1] === method)) { 1381 | if (targets.length == 2) { 1382 | return null; 1383 | } 1384 | targets.splice(i, 2); 1385 | return ss.Delegate._create(targets); 1386 | } 1387 | } 1388 | 1389 | return delegate1; 1390 | } 1391 | 1392 | ss.Delegate.createExport = function Delegate$createExport(delegate, multiUse, name) { 1393 | name = name || '__' + (new Date()).valueOf(); 1394 | 1395 | window[name] = multiUse ? delegate : function() { 1396 | try { delete window[name]; } catch(e) { window[name] = undefined; } 1397 | delegate.apply(null, arguments); 1398 | }; 1399 | 1400 | return name; 1401 | } 1402 | 1403 | ss.Delegate.deleteExport = function Delegate$deleteExport(name) { 1404 | delete window[name]; 1405 | } 1406 | 1407 | ss.Delegate.clearExport = function Delegate$clearExport(name) { 1408 | window[name] = ss.Delegate.empty; 1409 | } 1410 | 1411 | ss.CultureInfo = function CultureInfo$(name, numberFormat, dateFormat) { 1412 | this.name = name; 1413 | this.numberFormat = numberFormat; 1414 | this.dateFormat = dateFormat; 1415 | } 1416 | ss.CultureInfo.registerClass('CultureInfo'); 1417 | 1418 | ss.CultureInfo.InvariantCulture = new ss.CultureInfo('en-US', 1419 | { 1420 | naNSymbol: 'NaN', 1421 | negativeSign: '-', 1422 | positiveSign: '+', 1423 | negativeInfinityText: '-Infinity', 1424 | positiveInfinityText: 'Infinity', 1425 | 1426 | percentSymbol: '%', 1427 | percentGroupSizes: [3], 1428 | percentDecimalDigits: 2, 1429 | percentDecimalSeparator: '.', 1430 | percentGroupSeparator: ',', 1431 | percentPositivePattern: '{0} %', 1432 | percentNegativePattern: '-{0} %', 1433 | 1434 | currencySymbol:'$', 1435 | currencyGroupSizes: [3], 1436 | currencyDecimalDigits: 2, 1437 | currencyDecimalSeparator: '.', 1438 | currencyGroupSeparator: ',', 1439 | currencyNegativePattern: '(${0})', 1440 | currencyPositivePattern: '${0}', 1441 | 1442 | numberGroupSizes: [3], 1443 | numberDecimalDigits: 2, 1444 | numberDecimalSeparator: '.', 1445 | numberGroupSeparator: ',' 1446 | }, 1447 | { 1448 | amDesignator: 'AM', 1449 | pmDesignator: 'PM', 1450 | 1451 | dateSeparator: '/', 1452 | timeSeparator: ':', 1453 | 1454 | gmtDateTimePattern: 'ddd, dd MMM yyyy HH:mm:ss \'GMT\'', 1455 | universalDateTimePattern: 'yyyy-MM-dd HH:mm:ssZ', 1456 | sortableDateTimePattern: 'yyyy-MM-ddTHH:mm:ss', 1457 | dateTimePattern: 'dddd, MMMM dd, yyyy h:mm:ss tt', 1458 | 1459 | longDatePattern: 'dddd, MMMM dd, yyyy', 1460 | shortDatePattern: 'M/d/yyyy', 1461 | 1462 | longTimePattern: 'h:mm:ss tt', 1463 | shortTimePattern: 'h:mm tt', 1464 | 1465 | firstDayOfWeek: 0, 1466 | dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'], 1467 | shortDayNames: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'], 1468 | minimizedDayNames: ['Su','Mo','Tu','We','Th','Fr','Sa'], 1469 | 1470 | monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December',''], 1471 | shortMonthNames: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',''] 1472 | }); 1473 | ss.CultureInfo.CurrentCulture = ss.CultureInfo.InvariantCulture; 1474 | 1475 | ss.IEnumerator = function IEnumerator$() { }; 1476 | ss.IEnumerator.prototype = { 1477 | get_current: null, 1478 | moveNext: null, 1479 | reset: null 1480 | } 1481 | 1482 | ss.IEnumerator.getEnumerator = function ss_IEnumerator$getEnumerator(enumerable) { 1483 | if (enumerable) { 1484 | return enumerable.getEnumerator ? enumerable.getEnumerator() : new ss.ArrayEnumerator(enumerable); 1485 | } 1486 | return null; 1487 | } 1488 | 1489 | ss.IEnumerator.registerInterface('IEnumerator'); 1490 | 1491 | ss.IEnumerable = function IEnumerable$() { }; 1492 | ss.IEnumerable.prototype = { 1493 | getEnumerator: null 1494 | } 1495 | ss.IEnumerable.registerInterface('IEnumerable'); 1496 | 1497 | ss.ArrayEnumerator = function ArrayEnumerator$(array) { 1498 | this._array = array; 1499 | this._index = -1; 1500 | this.current = null; 1501 | } 1502 | ss.ArrayEnumerator.prototype = { 1503 | moveNext: function ArrayEnumerator$moveNext() { 1504 | this._index++; 1505 | this.current = this._array[this._index]; 1506 | return (this._index < this._array.length); 1507 | }, 1508 | reset: function ArrayEnumerator$reset() { 1509 | this._index = -1; 1510 | this.current = null; 1511 | } 1512 | } 1513 | 1514 | ss.ArrayEnumerator.registerClass('ArrayEnumerator', null, ss.IEnumerator); 1515 | 1516 | ss.IDisposable = function IDisposable$() { }; 1517 | ss.IDisposable.prototype = { 1518 | dispose: null 1519 | } 1520 | ss.IDisposable.registerInterface('IDisposable'); 1521 | 1522 | ss.StringBuilder = function StringBuilder$(s) { 1523 | this._parts = ss.isNullOrUndefined(s) || s === '' ? [] : [s]; 1524 | this.isEmpty = this._parts.length == 0; 1525 | } 1526 | ss.StringBuilder.prototype = { 1527 | append: function StringBuilder$append(s) { 1528 | if (!ss.isNullOrUndefined(s) && s !== '') { 1529 | this._parts.add(s); 1530 | this.isEmpty = false; 1531 | } 1532 | return this; 1533 | }, 1534 | 1535 | appendLine: function StringBuilder$appendLine(s) { 1536 | this.append(s); 1537 | this.append('\r\n'); 1538 | this.isEmpty = false; 1539 | return this; 1540 | }, 1541 | 1542 | clear: function StringBuilder$clear() { 1543 | this._parts = []; 1544 | this.isEmpty = true; 1545 | }, 1546 | 1547 | toString: function StringBuilder$toString(s) { 1548 | return this._parts.join(s || ''); 1549 | } 1550 | }; 1551 | 1552 | ss.StringBuilder.registerClass('StringBuilder'); 1553 | 1554 | ss.EventArgs = function EventArgs$() { 1555 | } 1556 | ss.EventArgs.registerClass('EventArgs'); 1557 | 1558 | ss.EventArgs.Empty = new ss.EventArgs(); 1559 | 1560 | if (!window.XMLHttpRequest) { 1561 | window.XMLHttpRequest = function() { 1562 | var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ]; 1563 | 1564 | for (var i = 0; i < progIDs.length; i++) { 1565 | try { 1566 | var xmlHttp = new ActiveXObject(progIDs[i]); 1567 | return xmlHttp; 1568 | } 1569 | catch (ex) { 1570 | } 1571 | } 1572 | 1573 | return null; 1574 | } 1575 | } 1576 | 1577 | ss.parseXml = function(markup) { 1578 | try { 1579 | if (DOMParser) { 1580 | var domParser = new DOMParser(); 1581 | return domParser.parseFromString(markup, 'text/xml'); 1582 | } 1583 | else { 1584 | var progIDs = [ 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ]; 1585 | 1586 | for (var i = 0; i < progIDs.length; i++) { 1587 | var xmlDOM = new ActiveXObject(progIDs[i]); 1588 | xmlDOM.async = false; 1589 | xmlDOM.loadXML(markup); 1590 | xmlDOM.setProperty('SelectionLanguage', 'XPath'); 1591 | 1592 | return xmlDOM; 1593 | } 1594 | } 1595 | } 1596 | catch (ex) { 1597 | } 1598 | 1599 | return null; 1600 | } 1601 | 1602 | ss.CancelEventArgs = function CancelEventArgs$() { 1603 | ss.CancelEventArgs.initializeBase(this); 1604 | this.cancel = false; 1605 | } 1606 | ss.CancelEventArgs.registerClass('CancelEventArgs', ss.EventArgs); 1607 | 1608 | ss.Tuple = function (first, second, third) { 1609 | this.first = first; 1610 | this.second = second; 1611 | if (arguments.length == 3) { 1612 | this.third = third; 1613 | } 1614 | } 1615 | ss.Tuple.registerClass('Tuple'); 1616 | 1617 | ss.Observable = function(v) { 1618 | this._v = v; 1619 | this._observers = null; 1620 | } 1621 | ss.Observable.prototype = { 1622 | 1623 | getValue: function () { 1624 | this._observers = ss.Observable._captureObservers(this._observers); 1625 | return this._v; 1626 | }, 1627 | setValue: function (v) { 1628 | if (this._v !== v) { 1629 | this._v = v; 1630 | 1631 | var observers = this._observers; 1632 | if (observers) { 1633 | this._observers = null; 1634 | ss.Observable._invalidateObservers(observers); 1635 | } 1636 | } 1637 | } 1638 | }; 1639 | 1640 | ss.Observable._observerStack = []; 1641 | ss.Observable._observerRegistration = { 1642 | dispose: function () { 1643 | ss.Observable._observerStack.pop(); 1644 | } 1645 | } 1646 | ss.Observable.registerObserver = function (o) { 1647 | ss.Observable._observerStack.push(o); 1648 | return ss.Observable._observerRegistration; 1649 | } 1650 | ss.Observable._captureObservers = function (observers) { 1651 | var registeredObservers = ss.Observable._observerStack; 1652 | var observerCount = registeredObservers.length; 1653 | 1654 | if (observerCount) { 1655 | observers = observers || []; 1656 | for (var i = 0; i < observerCount; i++) { 1657 | var observer = registeredObservers[i]; 1658 | if (!observers.contains(observer)) { 1659 | observers.push(observer); 1660 | } 1661 | } 1662 | return observers; 1663 | } 1664 | return null; 1665 | } 1666 | ss.Observable._invalidateObservers = function (observers) { 1667 | for (var i = 0, len = observers.length; i < len; i++) { 1668 | observers[i].invalidateObserver(); 1669 | } 1670 | } 1671 | 1672 | ss.Observable.registerClass('Observable'); 1673 | 1674 | 1675 | ss.ObservableCollection = function (items) { 1676 | this._items = items || []; 1677 | this._observers = null; 1678 | } 1679 | ss.ObservableCollection.prototype = { 1680 | 1681 | get_item: function (index) { 1682 | this._observers = ss.Observable._captureObservers(this._observers); 1683 | return this._items[index]; 1684 | }, 1685 | set_item: function (index, item) { 1686 | this._items[index] = item; 1687 | this._updated(); 1688 | }, 1689 | get_length: function () { 1690 | this._observers = ss.Observable._captureObservers(this._observers); 1691 | return this._items.length; 1692 | }, 1693 | add: function (item) { 1694 | this._items.push(item); 1695 | this._updated(); 1696 | }, 1697 | clear: function () { 1698 | this._items.clear(); 1699 | this._updated(); 1700 | }, 1701 | contains: function (item) { 1702 | return this._items.contains(item); 1703 | }, 1704 | getEnumerator: function () { 1705 | this._observers = ss.Observable._captureObservers(this._observers); 1706 | return this._items.getEnumerator(); 1707 | }, 1708 | indexOf: function (item) { 1709 | return this._items.indexOf(item); 1710 | }, 1711 | insert: function (index, item) { 1712 | this._items.insert(index, item); 1713 | this._updated(); 1714 | }, 1715 | remove: function (item) { 1716 | if (this._items.remove(item)) { 1717 | this._updated(); 1718 | return true; 1719 | } 1720 | return false; 1721 | }, 1722 | removeAt: function (index) { 1723 | this._items.removeAt(index); 1724 | this._updated(); 1725 | }, 1726 | toArray: function () { 1727 | return this._items; 1728 | }, 1729 | _updated: function() { 1730 | var observers = this._observers; 1731 | if (observers) { 1732 | this._observers = null; 1733 | ss.Observable._invalidateObservers(observers); 1734 | } 1735 | } 1736 | } 1737 | ss.ObservableCollection.registerClass('ObservableCollection', null, ss.IEnumerable); 1738 | 1739 | ss.Task = function(result) { 1740 | this._continuations = ss.isValue(result) ? 1741 | (this.status = 'done', null) : 1742 | (this.status = 'pending', []); 1743 | this.result = result; 1744 | this.error = null; 1745 | } 1746 | ss.Task.prototype = { 1747 | get_completed: function() { 1748 | return this.status != 'pending'; 1749 | }, 1750 | continueWith: function(continuation) { 1751 | if (this._continuations) { 1752 | this._continuations.push(continuation); 1753 | } 1754 | else { 1755 | var self = this; 1756 | setTimeout(function() { continuation(self); }, 0); 1757 | } 1758 | return this; 1759 | }, 1760 | done: function(callback) { 1761 | return this.continueWith(function(t) { 1762 | if (t.status == 'done') { 1763 | callback(t.result); 1764 | } 1765 | }); 1766 | }, 1767 | fail: function(callback) { 1768 | return this.continueWith(function(t) { 1769 | if (t.status == 'failed') { 1770 | callback(t.error); 1771 | } 1772 | }); 1773 | }, 1774 | then: function(doneCallback, failCallback) { 1775 | return this.continueWith(function(t) { 1776 | t.status == 'done' ? doneCallback(t.result) : failCallback(t.error); 1777 | }); 1778 | }, 1779 | _update: function(result, error) { 1780 | if (this.status == 'pending') { 1781 | if (error) { 1782 | this.error = error; 1783 | this.status = 'failed'; 1784 | } 1785 | else { 1786 | this.result = result; 1787 | this.status = 'done'; 1788 | } 1789 | 1790 | var continuations = this._continuations; 1791 | this._continuations = null; 1792 | 1793 | for (var i = 0, c = continuations.length; i < c; i++) { 1794 | continuations[i](this); 1795 | } 1796 | } 1797 | } 1798 | }; 1799 | ss.Task._join = function(tasks, any) { 1800 | tasks = Array.toArray(tasks); 1801 | ss.Debug.assert(tasks.length > 1); 1802 | 1803 | var count = tasks.length; 1804 | 1805 | var interval = 0; 1806 | if ((count > 1) && (typeof tasks[0] == 'number')) { 1807 | interval = tasks[0]; 1808 | tasks = tasks.slice(1); 1809 | count--; 1810 | } 1811 | 1812 | var joinTask = new ss.Task(); 1813 | var seen = 0; 1814 | 1815 | function continuation(t) { 1816 | if (joinTask.status == 'pending') { 1817 | seen++; 1818 | if (any) { 1819 | joinTask._update(t); 1820 | } 1821 | else if (seen == count) { 1822 | joinTask._update(true); 1823 | } 1824 | } 1825 | } 1826 | 1827 | function timeout() { 1828 | if (joinTask.status == 'pending') { 1829 | if (any) { 1830 | joinTask._update(null); 1831 | } 1832 | else { 1833 | joinTask._update(false); 1834 | } 1835 | } 1836 | } 1837 | 1838 | if (interval != 0) { 1839 | setTimeout(timeout, interval); 1840 | } 1841 | 1842 | for (var i = 0; i < count; i++) { 1843 | tasks[i].continueWith(continuation); 1844 | } 1845 | 1846 | return joinTask; 1847 | } 1848 | ss.Task.all = function() { 1849 | return ss.Task._join(arguments, false); 1850 | } 1851 | ss.Task.any = function() { 1852 | return ss.Task._join(arguments, true); 1853 | } 1854 | ss.Task.delay = function(timeout) { 1855 | var timerTask = new ss.Task(); 1856 | 1857 | setTimeout(function() { 1858 | timerTask._update(true); 1859 | }, timeout); 1860 | 1861 | return timerTask; 1862 | } 1863 | 1864 | 1865 | ss.Deferred = function(result) { 1866 | this.task = new ss.Task(result); 1867 | } 1868 | ss.Deferred.prototype = { 1869 | resolve: function(result) { 1870 | this.task._update(result); 1871 | }, 1872 | reject: function(error) { 1873 | this.task._update(null, error || new Error()); 1874 | } 1875 | }; 1876 | 1877 | ss.Deferred.registerClass('Deferred'); 1878 | ss.Task.registerClass('Task'); 1879 | 1880 | ss.IApplication = function() { }; 1881 | ss.IApplication.registerInterface('IApplication'); 1882 | 1883 | ss.IContainer = function () { }; 1884 | ss.IContainer.registerInterface('IContainer'); 1885 | 1886 | ss.IObjectFactory = function () { }; 1887 | ss.IObjectFactory.registerInterface('IObjectFactory'); 1888 | 1889 | ss.IEventManager = function () { }; 1890 | ss.IEventManager.registerInterface('IEventManager'); 1891 | 1892 | ss.IInitializable = function () { }; 1893 | ss.IInitializable.registerInterface('IInitializable'); 1894 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The source code for this project is under the terms of the MIT License. 2 | The API documentation is licensed under the terms of the Creative 3 | Commons Attribution 4.0 International Public License. 4 | 5 | 6 | The Licenses 7 | ============ 8 | 9 | ### MIT X11 License 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining 12 | a copy of this software and associated documentation files (the 13 | "Software"), to deal in the Software without restriction, including 14 | without limitation the rights to use, copy, modify, merge, publish, 15 | distribute, sublicense, and/or sell copies of the Software, and to 16 | permit persons to whom the Software is furnished to do so, subject to 17 | the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be 20 | included in all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | 32 | ### Creative Commons Attribution 4.0 International Public License 33 | 34 | Attribution 4.0 International 35 | 36 | ======================================================================= 37 | 38 | Creative Commons Corporation ("Creative Commons") is not a law firm and 39 | does not provide legal services or legal advice. Distribution of 40 | Creative Commons public licenses does not create a lawyer-client or 41 | other relationship. Creative Commons makes its licenses and related 42 | information available on an "as-is" basis. Creative Commons gives no 43 | warranties regarding its licenses, any material licensed under their 44 | terms and conditions, or any related information. Creative Commons 45 | disclaims all liability for damages resulting from their use to the 46 | fullest extent possible. 47 | 48 | Using Creative Commons Public Licenses 49 | 50 | Creative Commons public licenses provide a standard set of terms and 51 | conditions that creators and other rights holders may use to share 52 | original works of authorship and other material subject to copyright 53 | and certain other rights specified in the public license below. The 54 | following considerations are for informational purposes only, are not 55 | exhaustive, and do not form part of our licenses. 56 | 57 | Considerations for licensors: Our public licenses are 58 | intended for use by those authorized to give the public 59 | permission to use material in ways otherwise restricted by 60 | copyright and certain other rights. Our licenses are 61 | irrevocable. Licensors should read and understand the terms 62 | and conditions of the license they choose before applying it. 63 | Licensors should also secure all rights necessary before 64 | applying our licenses so that the public can reuse the 65 | material as expected. Licensors should clearly mark any 66 | material not subject to the license. This includes other CC- 67 | licensed material, or material used under an exception or 68 | limitation to copyright. More considerations for licensors: 69 | wiki.creativecommons.org/Considerations_for_licensors 70 | 71 | Considerations for the public: By using one of our public 72 | licenses, a licensor grants the public permission to use the 73 | licensed material under specified terms and conditions. If 74 | the licensor's permission is not necessary for any reason--for 75 | example, because of any applicable exception or limitation to 76 | copyright--then that use is not regulated by the license. Our 77 | licenses grant only permissions under copyright and certain 78 | other rights that a licensor has authority to grant. Use of 79 | the licensed material may still be restricted for other 80 | reasons, including because others have copyright or other 81 | rights in the material. A licensor may make special requests, 82 | such as asking that all changes be marked or described. 83 | Although not required by our licenses, you are encouraged to 84 | respect those requests where reasonable. More_considerations 85 | for the public: 86 | wiki.creativecommons.org/Considerations_for_licensees 87 | 88 | ======================================================================= 89 | 90 | Creative Commons Attribution 4.0 International Public License 91 | 92 | By exercising the Licensed Rights (defined below), You accept and agree 93 | to be bound by the terms and conditions of this Creative Commons 94 | Attribution 4.0 International Public License ("Public License"). To the 95 | extent this Public License may be interpreted as a contract, You are 96 | granted the Licensed Rights in consideration of Your acceptance of 97 | these terms and conditions, and the Licensor grants You such rights in 98 | consideration of benefits the Licensor receives from making the 99 | Licensed Material available under these terms and conditions. 100 | 101 | 102 | Section 1 -- Definitions. 103 | 104 | a. Adapted Material means material subject to Copyright and Similar 105 | Rights that is derived from or based upon the Licensed Material 106 | and in which the Licensed Material is translated, altered, 107 | arranged, transformed, or otherwise modified in a manner requiring 108 | permission under the Copyright and Similar Rights held by the 109 | Licensor. For purposes of this Public License, where the Licensed 110 | Material is a musical work, performance, or sound recording, 111 | Adapted Material is always produced where the Licensed Material is 112 | synched in timed relation with a moving image. 113 | 114 | b. Adapter's License means the license You apply to Your Copyright 115 | and Similar Rights in Your contributions to Adapted Material in 116 | accordance with the terms and conditions of this Public License. 117 | 118 | c. Copyright and Similar Rights means copyright and/or similar rights 119 | closely related to copyright including, without limitation, 120 | performance, broadcast, sound recording, and Sui Generis Database 121 | Rights, without regard to how the rights are labeled or 122 | categorized. For purposes of this Public License, the rights 123 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 124 | Rights. 125 | 126 | d. Effective Technological Measures means those measures that, in the 127 | absence of proper authority, may not be circumvented under laws 128 | fulfilling obligations under Article 11 of the WIPO Copyright 129 | Treaty adopted on December 20, 1996, and/or similar international 130 | agreements. 131 | 132 | e. Exceptions and Limitations means fair use, fair dealing, and/or 133 | any other exception or limitation to Copyright and Similar Rights 134 | that applies to Your use of the Licensed Material. 135 | 136 | f. Licensed Material means the artistic or literary work, database, 137 | or other material to which the Licensor applied this Public 138 | License. 139 | 140 | g. Licensed Rights means the rights granted to You subject to the 141 | terms and conditions of this Public License, which are limited to 142 | all Copyright and Similar Rights that apply to Your use of the 143 | Licensed Material and that the Licensor has authority to license. 144 | 145 | h. Licensor means the individual(s) or entity(ies) granting rights 146 | under this Public License. 147 | 148 | i. Share means to provide material to the public by any means or 149 | process that requires permission under the Licensed Rights, such 150 | as reproduction, public display, public performance, distribution, 151 | dissemination, communication, or importation, and to make material 152 | available to the public including in ways that members of the 153 | public may access the material from a place and at a time 154 | individually chosen by them. 155 | 156 | j. Sui Generis Database Rights means rights other than copyright 157 | resulting from Directive 96/9/EC of the European Parliament and of 158 | the Council of 11 March 1996 on the legal protection of databases, 159 | as amended and/or succeeded, as well as other essentially 160 | equivalent rights anywhere in the world. 161 | 162 | k. You means the individual or entity exercising the Licensed Rights 163 | under this Public License. Your has a corresponding meaning. 164 | 165 | 166 | Section 2 -- Scope. 167 | 168 | a. License grant. 169 | 170 | 1. Subject to the terms and conditions of this Public License, 171 | the Licensor hereby grants You a worldwide, royalty-free, 172 | non-sublicensable, non-exclusive, irrevocable license to 173 | exercise the Licensed Rights in the Licensed Material to: 174 | 175 | a. reproduce and Share the Licensed Material, in whole or 176 | in part; and 177 | 178 | b. produce, reproduce, and Share Adapted Material. 179 | 180 | 2. Exceptions and Limitations. For the avoidance of doubt, where 181 | Exceptions and Limitations apply to Your use, this Public 182 | License does not apply, and You do not need to comply with 183 | its terms and conditions. 184 | 185 | 3. Term. The term of this Public License is specified in Section 186 | 6(a). 187 | 188 | 4. Media and formats; technical modifications allowed. The 189 | Licensor authorizes You to exercise the Licensed Rights in 190 | all media and formats whether now known or hereafter created, 191 | and to make technical modifications necessary to do so. The 192 | Licensor waives and/or agrees not to assert any right or 193 | authority to forbid You from making technical modifications 194 | necessary to exercise the Licensed Rights, including 195 | technical modifications necessary to circumvent Effective 196 | Technological Measures. For purposes of this Public License, 197 | simply making modifications authorized by this Section 2(a) 198 | (4) never produces Adapted Material. 199 | 200 | 5. Downstream recipients. 201 | 202 | a. Offer from the Licensor -- Licensed Material. Every 203 | recipient of the Licensed Material automatically 204 | receives an offer from the Licensor to exercise the 205 | Licensed Rights under the terms and conditions of this 206 | Public License. 207 | 208 | b. No downstream restrictions. You may not offer or impose 209 | any additional or different terms or conditions on, or 210 | apply any Effective Technological Measures to, the 211 | Licensed Material if doing so restricts exercise of the 212 | Licensed Rights by any recipient of the Licensed 213 | Material. 214 | 215 | 6. No endorsement. Nothing in this Public License constitutes or 216 | may be construed as permission to assert or imply that You 217 | are, or that Your use of the Licensed Material is, connected 218 | with, or sponsored, endorsed, or granted official status by, 219 | the Licensor or others designated to receive attribution as 220 | provided in Section 3(a)(1)(A)(i). 221 | 222 | b. Other rights. 223 | 224 | 1. Moral rights, such as the right of integrity, are not 225 | licensed under this Public License, nor are publicity, 226 | privacy, and/or other similar personality rights; however, to 227 | the extent possible, the Licensor waives and/or agrees not to 228 | assert any such rights held by the Licensor to the limited 229 | extent necessary to allow You to exercise the Licensed 230 | Rights, but not otherwise. 231 | 232 | 2. Patent and trademark rights are not licensed under this 233 | Public License. 234 | 235 | 3. To the extent possible, the Licensor waives any right to 236 | collect royalties from You for the exercise of the Licensed 237 | Rights, whether directly or through a collecting society 238 | under any voluntary or waivable statutory or compulsory 239 | licensing scheme. In all other cases the Licensor expressly 240 | reserves any right to collect such royalties. 241 | 242 | 243 | Section 3 -- License Conditions. 244 | 245 | Your exercise of the Licensed Rights is expressly made subject to the 246 | following conditions. 247 | 248 | a. Attribution. 249 | 250 | 1. If You Share the Licensed Material (including in modified 251 | form), You must: 252 | 253 | a. retain the following if it is supplied by the Licensor 254 | with the Licensed Material: 255 | 256 | i. identification of the creator(s) of the Licensed 257 | Material and any others designated to receive 258 | attribution, in any reasonable manner requested by 259 | the Licensor (including by pseudonym if 260 | designated); 261 | 262 | ii. a copyright notice; 263 | 264 | iii. a notice that refers to this Public License; 265 | 266 | iv. a notice that refers to the disclaimer of 267 | warranties; 268 | 269 | v. a URI or hyperlink to the Licensed Material to the 270 | extent reasonably practicable; 271 | 272 | b. indicate if You modified the Licensed Material and 273 | retain an indication of any previous modifications; and 274 | 275 | c. indicate the Licensed Material is licensed under this 276 | Public License, and include the text of, or the URI or 277 | hyperlink to, this Public License. 278 | 279 | 2. You may satisfy the conditions in Section 3(a)(1) in any 280 | reasonable manner based on the medium, means, and context in 281 | which You Share the Licensed Material. For example, it may be 282 | reasonable to satisfy the conditions by providing a URI or 283 | hyperlink to a resource that includes the required 284 | information. 285 | 286 | 3. If requested by the Licensor, You must remove any of the 287 | information required by Section 3(a)(1)(A) to the extent 288 | reasonably practicable. 289 | 290 | 4. If You Share Adapted Material You produce, the Adapter's 291 | License You apply must not prevent recipients of the Adapted 292 | Material from complying with this Public License. 293 | 294 | 295 | Section 4 -- Sui Generis Database Rights. 296 | 297 | Where the Licensed Rights include Sui Generis Database Rights that 298 | apply to Your use of the Licensed Material: 299 | 300 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 301 | to extract, reuse, reproduce, and Share all or a substantial 302 | portion of the contents of the database; 303 | 304 | b. if You include all or a substantial portion of the database 305 | contents in a database in which You have Sui Generis Database 306 | Rights, then the database in which You have Sui Generis Database 307 | Rights (but not its individual contents) is Adapted Material; and 308 | 309 | c. You must comply with the conditions in Section 3(a) if You Share 310 | all or a substantial portion of the contents of the database. 311 | 312 | For the avoidance of doubt, this Section 4 supplements and does not 313 | replace Your obligations under this Public License where the Licensed 314 | Rights include other Copyright and Similar Rights. 315 | 316 | 317 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 318 | 319 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 320 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 321 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 322 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 323 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 324 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 325 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 326 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 327 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 328 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 329 | 330 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 331 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 332 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 333 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 334 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 335 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 336 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 337 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 338 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 339 | 340 | c. The disclaimer of warranties and limitation of liability provided 341 | above shall be interpreted in a manner that, to the extent 342 | possible, most closely approximates an absolute disclaimer and 343 | waiver of all liability. 344 | 345 | 346 | Section 6 -- Term and Termination. 347 | 348 | a. This Public License applies for the term of the Copyright and 349 | Similar Rights licensed here. However, if You fail to comply with 350 | this Public License, then Your rights under this Public License 351 | terminate automatically. 352 | 353 | b. Where Your right to use the Licensed Material has terminated under 354 | Section 6(a), it reinstates: 355 | 356 | 1. automatically as of the date the violation is cured, provided 357 | it is cured within 30 days of Your discovery of the 358 | violation; or 359 | 360 | 2. upon express reinstatement by the Licensor. 361 | 362 | For the avoidance of doubt, this Section 6(b) does not affect any 363 | right the Licensor may have to seek remedies for Your violations 364 | of this Public License. 365 | 366 | c. For the avoidance of doubt, the Licensor may also offer the 367 | Licensed Material under separate terms or conditions or stop 368 | distributing the Licensed Material at any time; however, doing so 369 | will not terminate this Public License. 370 | 371 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 372 | License. 373 | 374 | 375 | Section 7 -- Other Terms and Conditions. 376 | 377 | a. The Licensor shall not be bound by any additional or different 378 | terms or conditions communicated by You unless expressly agreed. 379 | 380 | b. Any arrangements, understandings, or agreements regarding the 381 | Licensed Material not stated herein are separate from and 382 | independent of the terms and conditions of this Public License. 383 | 384 | 385 | Section 8 -- Interpretation. 386 | 387 | a. For the avoidance of doubt, this Public License does not, and 388 | shall not be interpreted to, reduce, limit, restrict, or impose 389 | conditions on any use of the Licensed Material that could lawfully 390 | be made without permission under this Public License. 391 | 392 | b. To the extent possible, if any provision of this Public License is 393 | deemed unenforceable, it shall be automatically reformed to the 394 | minimum extent necessary to make it enforceable. If the provision 395 | cannot be reformed, it shall be severed from this Public License 396 | without affecting the enforceability of the remaining terms and 397 | conditions. 398 | 399 | c. No term or condition of this Public License will be waived and no 400 | failure to comply consented to unless expressly agreed to by the 401 | Licensor. 402 | 403 | d. Nothing in this Public License constitutes or may be interpreted 404 | as a limitation upon, or waiver of, any privileges and immunities 405 | that apply to the Licensor or You, including from the legal 406 | processes of any jurisdiction or authority. 407 | 408 | 409 | ======================================================================= 410 | 411 | Creative Commons is not a party to its public 412 | licenses. Notwithstanding, Creative Commons may elect to apply one of 413 | its public licenses to material it publishes and in those instances 414 | will be considered the “Licensor.” The text of the Creative Commons 415 | public licenses is dedicated to the public domain under the CC0 Public 416 | Domain Dedication. Except for the limited purpose of indicating that 417 | material is shared under a Creative Commons public license or as 418 | otherwise permitted by the Creative Commons policies published at 419 | creativecommons.org/policies, Creative Commons does not authorize the 420 | use of the trademark "Creative Commons" or any other trademark or logo 421 | of Creative Commons without its prior written consent including, 422 | without limitation, in connection with any unauthorized modifications 423 | to any of its public licenses or any other arrangements, 424 | understandings, or agreements concerning use of licensed material. For 425 | the avoidance of doubt, this paragraph does not form part of the 426 | public licenses. 427 | 428 | Creative Commons may be contacted at creativecommons.org. 429 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pyextjs", 3 | "version": "0.1.3", 4 | "description": "Python Extension Packages in Javascript (Numpy, Scipy)", 5 | "main": "src/PyExtJS.js", 6 | "_id": "pyextjs@0.1.3", 7 | "keywords": [ 8 | "numpy", 9 | "scipy", 10 | "matrix", 11 | "linear", 12 | "algebra", 13 | "science", 14 | "numerical" 15 | ], 16 | "maintainers": [ 17 | { 18 | "name": "Alvaro Fernandez", 19 | "email": "fernandezajp@gmail.com", 20 | "web": "http://www.alvarofernandez.info" 21 | } 22 | ], 23 | "author": "Alvaro Fernandez", 24 | "bugs": { 25 | "web": "https://github.com/fernandezajp/PyExtJs/issues" 26 | }, 27 | "licenses": [ 28 | { 29 | "type": "MIT", 30 | "url": "https://opensource.org/licenses/MIT" 31 | } 32 | ], 33 | "readmeFilename": "README.md", 34 | "repositories": [ 35 | { 36 | "type": "git", 37 | "url": "https://github.com/fernandezajp/PyExtJS.git" 38 | } 39 | ], 40 | "dependencies": { 41 | "jsdom": ">=9.4.2", 42 | "cloneextend": ">=0.0.3" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | PyExtJS 2 | ======= 3 | (Python Extension Packages in Javascript) 4 | 5 | ### Contents 6 | 7 | - What is PyExtJs? 8 | - Installation 9 | - Latest source code 10 | - Bug reports 11 | - Getting Started 12 | * numpy 13 | * array 14 | * linspace 15 | * logspace 16 | * exp 17 | * arange 18 | * power 19 | * reshape 20 | * shape 21 | * size 22 | * ndim 23 | * strides 24 | * dtype 25 | * ravel 26 | * T / transpose 27 | * dot 28 | * zeros 29 | * ones 30 | * random 31 | * polyfit 32 | * scipy 33 | * interpolate 34 | * linregress 35 | 36 | ## What is PyExtJs? 37 | 38 | Python Extension Packages in Javascript is open-source implementation of some common libraries used 39 | in the scientific python programming. 40 | The main goal of this project is to improve migration of 41 | python language to javascript. 42 | 43 | ## License 44 | 45 | Copyright 2016 Alvaro Fernandez 46 | 47 | License: MIT/X11 48 | 49 | ## Installation 50 | 51 | Just include the following libraries in your html. 52 | 53 | 54 | 55 | 56 | 57 | 58 | ## Latest source code 59 | 60 |
61 | The latest development version of Scipy's sources are always available at: 62 | 63 | > [https://github.com/fernandezajp/PyExtJs](https://github.com/fernandezajp/PyExtJs) 64 | 65 | ## Bug reports 66 |
67 | To search for bugs or report them, please use the Scipy Bug Tracker at: 68 | 69 | > [https://github.com/fernandezajp/PyExtJs/issues](https://github.com/fernandezajp/PyExtJs/issues) 70 | 71 | ## Getting Started 72 | 73 | ### numpy 74 | 75 | importing a library 76 | 77 | Python 78 | 79 | >>> import numpy as np 80 | 81 |
82 | Javascript with PyExtJS 83 | 84 | > np = numpy; 85 |
86 | 87 | #### *Using array* 88 | 89 | Python 90 | 91 | >>> import numpy 92 | >>> numpy.array([[1,2],[3,4]]) 93 | array([[1, 2], [3, 4]]) 94 | 95 |
96 | Javascript with PyExtJS 97 | 98 | > numpy.array([[1,2],[3,4]]); 99 | [[1, 2], [3, 4]] 100 | 101 |
102 | 103 | #### *Using linspace* 104 | 105 | Python 106 | 107 | >>> import numpy 108 | >>> numpy.linspace(2.0, 3.0, 5) 109 | array([ 2. , 2.25, 2.5 , 2.75, 3. ]) 110 | 111 |
112 | Javascript with PyExtJS 113 | 114 | > numpy.linspace(2.0, 3.0, 5); 115 | [2, 2.25, 2.5, 2.75, 3] 116 | 117 |
118 | 119 | #### *Using logspace* 120 | 121 | Python 122 | 123 | >>> import numpy 124 | >>> numpy.logspace(2.0, 3.0, 5) 125 | array([100.,177.827941,316.22776602,562.34132519,1000.]) 126 | 127 |
128 | Javascript with PyExtJS 129 | 130 | > numpy.logspace(2.0, 3.0, 5); 131 | [100, 177.82794100389228, 316.22776601683796, 562.341325190349, 1000] 132 | 133 |
134 | 135 | #### *Using exp* 136 | 137 | Python 138 | 139 | >>> import numpy 140 | >>> numpy.exp(2.4) 141 | 11.023176380641601 142 | >>> numpy.exp([2.4, 3.1]) 143 | array([ 11.02317638, 22.19795128]) 144 | 145 |
146 | Javascript with PyExtJS 147 | 148 | > numpy.exp(2.4); 149 | 11.0231763806416 150 | > numpy.exp([2.4, 3.2]) 151 | [11.0231763806416, 24.53253019710935] 152 | 153 |
154 | 155 | #### *Using arange* 156 | 157 | Python 158 | 159 | >>> import numpy 160 | >>> numpy.arange(3) 161 | array([0, 1, 2]) 162 | >>> numpy.arange(3,7) 163 | array([3, 4, 5, 6]) 164 | >>> numpy.arange(3,7,2) 165 | array([3, 5]) 166 | 167 |
168 | Javascript with PyExtJS 169 | 170 | > numpy.arange(3); 171 | [0, 1, 2] 172 | > numpy.arange(3,7) 173 | [3, 4, 5, 6] 174 | > numpy.arange(3,7,2) 175 | [3, 5] 176 | 177 |
178 | #### *Using power* 179 | 180 | Python 181 | 182 | >>> import numpy 183 | >>> x1 = range(6) 184 | >>> numpy.power(x1, 3) 185 | array([ 0, 1, 8, 27, 64, 125]) 186 | >>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0] 187 | >>> np.power(x1, x2) 188 | array([ 0., 1., 8., 27., 16., 5.]) 189 | 190 |
191 | Javascript with PyExtJS 192 | 193 | > x1 = numpy.range(6); 194 | [0, 1, 2, 3, 4, 5] 195 | > numpy.power(x1, 3); 196 | [0, 1, 8, 27, 64, 125] 197 | > x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0]; 198 | [1, 2, 3, 3, 2, 1] 199 | > numpy.power(x1, x2); 200 | [0, 1, 8, 27, 16, 5] 201 | 202 |
203 | 204 | 205 |
206 | 207 | #### *Using shape* 208 | 209 | Python 210 | 211 | >>> import numpy 212 | >>> a = numpy.arange(6).reshape((3, 2)) 213 | >>> a.shape 214 | (3, 2) 215 | 216 |
217 | Javascript with PyExtJS 218 | 219 | > a = numpy.arange(6).reshape([3, 2]); 220 | [[0, 1], [2, 3], [4, 5]] 221 | > a.shape; 222 | [3, 2] 223 | 224 |
225 | 226 | #### *Using size* 227 | 228 | Python 229 | 230 | >>> import numpy 231 | >>> a = numpy.arange(6).reshape((3, 2)) 232 | >>> a.size 233 | 6 234 | 235 |
236 | Javascript with PyExtJS 237 | 238 | > a = numpy.arange(6).reshape([3, 2]); 239 | [[0, 1], [2, 3], [4, 5]] 240 | > a.size; 241 | 6 242 | 243 |
244 | 245 | #### *Using ndim* 246 | 247 | Python 248 | 249 | >>> import numpy 250 | >>> a = numpy.arange(6).reshape((3, 2)) 251 | >>> a.ndim 252 | 2 253 | 254 |
255 | Javascript with PyExtJS 256 | 257 | > a = numpy.arange(6).reshape([3, 2]); 258 | [[0, 1], [2, 3], [4, 5]] 259 | > a.ndim; 260 | 2 261 | 262 |
263 | 264 | #### *Using strides* 265 | 266 | Python 267 | 268 | >>> import numpy 269 | >>> a = numpy.arange(6).reshape((3, 2)) 270 | >>> a.strides 271 | (16, 8) 272 | 273 |
274 | Javascript with PyExtJS 275 | 276 | > a = numpy.arange(6).reshape([3, 2]); 277 | [[0, 1], [2, 3], [4, 5]] 278 | > a.strides; 279 | [2, 1] 280 | # Very important: in Javascript the element has 1 byte 281 | 282 |
283 | 284 | #### *Using dtype* 285 | 286 | Python 287 | 288 | >>> import numpy 289 | >>> a = numpy.arange(6).reshape((3, 2)) 290 | >>> a.dtype 291 | dtype('int64') 292 | 293 |
294 | Javascript with PyExtJS 295 | 296 | > a = numpy.arange(6).reshape([3, 2]); 297 | [[0, 1], [2, 3], [4, 5]] 298 | > a.dtype; 299 | "Number" 300 | 301 |
302 | 303 | #### *Using ravel* 304 | 305 | Python 306 | 307 | >>> import numpy 308 | >>> a = numpy.arange(6).reshape((3, 2)) 309 | >>> a.ravel() 310 | array([0, 1, 2, 3, 4, 5]) 311 | 312 |
313 | Javascript with PyExtJS 314 | 315 | > a = numpy.arange(6).reshape([3, 2]); 316 | [[0, 1], [2, 3], [4, 5]] 317 | > a.ravel(); 318 | [0, 1, 2, 3, 4, 5] 319 | 320 |
321 | 322 | #### *Using T or transpose* 323 | 324 | Python 325 | 326 | >>> import numpy 327 | >>> a = numpy.arange(6).reshape((3, 2)) 328 | >>> a.T 329 | array([[0, 2, 4], 330 | [1, 3, 5]]) 331 | >>> a.transpose() 332 | array([[0, 2, 4], 333 | [1, 3, 5]]) 334 | 335 |
336 | Javascript with PyExtJS 337 | 338 | > a = numpy.arange(6).reshape([3, 2]); 339 | [[0, 1], [2, 3], [4, 5]] 340 | > a.T; 341 | [[0, 2, 4], [1, 3, 5]] 342 | > a.transpose(); 343 | [[0, 2, 4], [1, 3, 5]] 344 | 345 |
346 | 347 | #### *Using dot* 348 | 349 | Python 350 | 351 | >>> import numpy 352 | >>> a = numpy.arange(6).reshape(3, 2) 353 | >>> b = numpy.arange(6,12).reshape(2, 3) 354 | >>> a.dot(b) 355 | array([[ 9, 10, 11], 356 | [39, 44, 49], 357 | [69, 78, 87]]) 358 | 359 |
360 | Javascript with PyExtJS 361 | 362 | > a = numpy.arange(6).reshape(3, 2); 363 | [[0, 1], [2, 3], [4, 5]] 364 | > b = numpy.arange(6,12).reshape(2, 3); 365 | [[6, 7, 8], [9, 10, 11]] 366 | > a.dot(b); 367 | [[9, 10, 11], [39, 44, 49], [69, 78, 87]] 368 | 369 |
370 | 371 | #### *Using zeros* 372 | 373 | Python 374 | 375 | >>> import numpy 376 | >>> numpy.zeros(5) 377 | array([ 0., 0., 0., 0., 0.]) 378 | >>> numpy.zeros((3, 2)) 379 | array([[ 0., 0.], 380 | [ 0., 0.], 381 | [ 0., 0.]]) 382 | 383 |
384 | Javascript with PyExtJS 385 | 386 | > numpy.zeros(5); 387 | [0, 0, 0, 0, 0] 388 | > numpy.zeros([3, 2]); 389 | [[0, 0],[0, 0],[0, 0]] 390 | 391 |
392 | 393 | #### *Using ones* 394 | 395 | Python 396 | 397 | >>> import numpy 398 | >>> numpy.ones(5) 399 | array([ 1., 1., 1., 1., 1.]) 400 | >>> numpy.ones((3, 2)) 401 | array([[ 1., 1.], 402 | [ 1., 1.], 403 | [ 1., 1.]]) 404 | 405 |
406 | Javascript with PyExtJS 407 | 408 | > numpy.ones(5); 409 | [1, 1, 1, 1, 1] 410 | > numpy.ones([3, 2]); 411 | [[1, 1],[1, 1],[1, 1]] 412 | 413 |
414 | 415 | #### *Using random* 416 | 417 | Python 418 | 419 | >>> import numpy 420 | >>> numpy.random.random() 421 | 0.298740136734731 422 | >>> numpy.random.random(2) 423 | array([ 0.05538307, 0.74942997]) 424 | >>> numpy.random.random([2,2]) 425 | array([[ 0.51655267, 0.57323634], 426 | [ 0.82552349, 0.10818737]]) 427 | 428 |
429 | Javascript with PyExtJS 430 | 431 | > numpy.random.random(); 432 | 0.298740136734731 433 | > numpy.random.random(2); 434 | [0.05538307, 0.74942997] 435 | > numpy.random.random([2,2]); 436 | [[0.51655267, 0.57323634], [0.82552349, 0.10818737]] 437 | 438 |
439 | 440 | #### *Using polyfit* 441 | 442 | Python 443 | 444 | >>> import numpy 445 | >>> x = numpy.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) 446 | >>> y = numpy.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) 447 | >>> numpy.polyfit(x, y, 3) 448 | array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) 449 | 450 |
451 | Javascript with PyExtJS 452 | 453 | > x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]; 454 | [0, 1, 2, 3, 4, 5] 455 | > y = [0.0, 0.8, 0.9, 0.1, -0.8, -1.0]; 456 | [0, 0.8, 0.9, 0.1, -0.8, -1] 457 | > numpy.polyfit(x, y, 3); 458 | [0.0870370370370341, -0.8134920634920405, 1.6931216931216477, -0.039682539682528106] 459 | 460 |
461 | 462 | ### *scipy* 463 | 464 | #### *Using interpolate* 465 | 466 | Python 467 | 468 | >>> import numpy 469 | >>> from scipy import interpolate 470 | >>> x = numpy.arange(0, 10) 471 | array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 472 | >>> y = numpy.exp(-x/3.0) 473 | array([ 1. , 0.71653131, 0.51341712, 0.36787944, 0.26359714, 474 | 0.1888756 , 0.13533528, 0.09697197, 0.06948345, 0.04978707]) 475 | >>> f = interpolate.interp1d(x, y) 476 | >>> f(2.4) 477 | array(0.4552020478881322) 478 |
479 | Javascript with PyExtJS 480 | 481 | > x = numpy.arange(0, 10); 482 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 483 | > tmp = x.map(function(v) { 484 | return -v/3.0; 485 | }); 486 | [-0, -0.3333333333333333, -0.6666666666666666, -1, -1.3333333333333333, -1.6666666666666667, -2, -2.3333333333333335, -2.6666666666666665, -3] 487 | > y = numpy.exp(tmp); 488 | [1, 0.7165313105737892, 0.513417119032592, 0.3678794411714424, 0.26359713811572677, 0.1888756028375618, 0.1353352832366127, 0.09697196786440504, 0.06948345122280153, 0.04978706836786395] 489 | > var interpolation = new interpolate(); 490 | undefined 491 | > interpolation.interp1d(x, y); 492 | undefined 493 | > interpolation.eval(2.4); 494 | 0.4552020478881322 495 | > interpolation.eval([3.1, 2.4]); 496 | [0.35745121086587084, 0.4552020478881322] 497 |
498 | 499 | #### *Using linregress* 500 | 501 | Python 502 | 503 | >>> from scipy import stats 504 | >>> x = [0.6,0.1,0.7,0.7,0.3,0.6,0.1,0.6,0.7,0.8] 505 | >>> y = [0.8,0.8,0.2,0.1,0.8,0.3,0.5,0.9,0.1,0.2] 506 | >>> slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) 507 | >>> slope 508 | -0.72818791946308714 509 | >>> intercept 510 | 0.84865771812080526 511 |
512 | Javascript with PyExtJS 513 | 514 | > var Stats = new stats(); 515 | undefined 516 | > x = [ 0.6, 0.1, 0.7, 0.7, 0.3, 0.6, 0.1, 0.6, 0.7, 0.8 ]; 517 | [0.6, 0.1, 0.7, 0.7, 0.3, 0.6, 0.1, 0.6, 0.7, 0.8] 518 | > y = [ 0.8, 0.8, 0.2, 0.1, 0.8, 0.3, 0.5, 0.9, 0.1, 0.2 ]; 519 | [0.8, 0.8, 0.2, 0.1, 0.8, 0.3, 0.5, 0.9, 0.1, 0.2] 520 | > Stats.linregress(x, y); 521 | undefined 522 | > Stats.get_slope(); 523 | -0.7281879194630861 524 | > Stats.get_intercept(); 525 | 0.8486577181208048 526 | 527 |
528 | 529 | Performance 530 | -------------------------------------- 531 | 532 | This is very important, the test was executed in a MacBookPro i5 533 | 534 | The python Code: 535 | 536 | import time 537 | import numpy 538 | 539 | def test(): 540 | x = numpy.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) 541 | y = numpy.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) 542 | 543 | start = time.time() 544 | for num in range(1,10000): 545 | numpy.polyfit(x, y, 3) 546 | end = time.time() 547 | 548 | microsecs = end - start 549 | print microsecs * 1000 550 | 551 | test() 552 | 553 |
554 | The Javascript Code: 555 | 556 | function test() { 557 | x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]; 558 | y = [0.0, 0.8, 0.9, 0.1, -0.8, -1.0]; 559 | 560 | var start = +new Date(); 561 | for (var i=0;i<10000;i++) 562 | numpy.polyfit(x, y, 3) 563 | var end = +new Date(); 564 | var diff = end - start; 565 | alert(diff); 566 | } 567 | 568 | test(); 569 | 570 |
571 | 572 | Python: 1604 milliseconds 573 | Javascript: 14 milliseconds 574 | 575 | Javascript! Very fast!!! 576 | PyExtJS 577 | ======= 578 | (Python Extension Packages in Javascript) 579 | 580 | ### Contents 581 | 582 | - What is PyExtJs? 583 | - Installation 584 | - Latest source code 585 | - Bug reports 586 | - Wiki 587 | * Array creation routines 588 | * Array manipulation routines 589 | * Mathematical functions 590 | - Performance 591 | 592 | ## What is PyExtJs? 593 | 594 | Python Extension Packages in Javascript is open-source implementation of some common libraries used 595 | in the scientific python programming. 596 | The main goal of this project is to improve migration of 597 | python language to javascript. 598 | 599 | ## License 600 | 601 | Copyright 2016 Alvaro Fernandez 602 | 603 | License: MIT/X11 604 | 605 | ## Installation 606 | 607 | ### on node.js 608 | 609 | $ npm install pyextjs 610 |
611 | 612 | > require('pyextjs'); 613 | 614 | > numpy.linspace(2.0,3.0,5); 615 |
616 | 617 | ### on the browser 618 | 619 | Just include the following libraries in your html. 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 637 | 638 | 639 | 640 | ## Latest source code 641 | 642 |
643 | The latest development version of Scipy's sources are always available at: 644 | 645 | > [https://github.com/fernandezajp/PyExtJs](https://github.com/fernandezajp/PyExtJs) 646 | 647 | ## Bug reports 648 |
649 | To search for bugs or report them, please use the Scipy Bug Tracker at: 650 | 651 | > [https://github.com/fernandezajp/PyExtJs/issues](https://github.com/fernandezajp/PyExtJs/issues) 652 | 653 | ##Performance 654 | 655 | This is very important, the test was executed in a MacBookPro i5 656 | 657 | The python Code: 658 | 659 | import time 660 | import numpy 661 | 662 | def test(): 663 | x = numpy.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) 664 | y = numpy.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) 665 | 666 | start = time.time() 667 | for num in range(1,10000): 668 | numpy.polyfit(x, y, 3) 669 | end = time.time() 670 | 671 | microsecs = end - start 672 | print microsecs * 1000 673 | 674 | test() 675 | 676 |
677 | The Javascript Code: 678 | 679 | function test() { 680 | x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]; 681 | y = [0.0, 0.8, 0.9, 0.1, -0.8, -1.0]; 682 | 683 | var start = +new Date(); 684 | for (var i=0;i<10000;i++) 685 | numpy.polyfit(x, y, 3) 686 | var end = +new Date(); 687 | var diff = end - start; 688 | alert(diff); 689 | } 690 | 691 | test(); 692 | 693 |
694 | 695 | Python: 1604 milliseconds 696 | Javascript: 14 milliseconds 697 | 698 | Javascript! Very fast!!! 699 | -------------------------------------------------------------------------------- /samples/pyextjs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 19 |

Testing linspace

20 |

numpy.linspace(2.0, 3.0, 5)

21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/PyExtJS.js: -------------------------------------------------------------------------------- 1 | var cloneextend = require('cloneextend'); 2 | cloneextend.extend(this, require('./ss')); 3 | cloneextend.extend(this, require('../dist/Numpy.js')); 4 | cloneextend.extend(this, require('../dist/PolySolve.js')); 5 | cloneextend.extend(this, require('../dist/Scipy.js')); 6 | -------------------------------------------------------------------------------- /src/ss.js: -------------------------------------------------------------------------------- 1 | var document = require("jsdom"); 2 | 3 | (function () { 4 | var globals = { 5 | version: '0.7.4.0', 6 | 7 | isUndefined: function (o) { 8 | return (o === undefined); 9 | }, 10 | 11 | isNull: function (o) { 12 | return (o === null); 13 | }, 14 | 15 | isNullOrUndefined: function (o) { 16 | return (o === null) || (o === undefined); 17 | }, 18 | 19 | isValue: function (o) { 20 | return (o !== null) && (o !== undefined); 21 | } 22 | }; 23 | 24 | var started = false; 25 | var startCallbacks = []; 26 | 27 | function onStartup(cb) { 28 | startCallbacks ? startCallbacks.push(cb) : setTimeout(cb, 0); 29 | } 30 | function startup() { 31 | if (startCallbacks) { 32 | var callbacks = startCallbacks; 33 | startCallbacks = null; 34 | for (var i = 0, l = callbacks.length; i < l; i++) { 35 | callbacks[i](); 36 | } 37 | } 38 | } 39 | if (document.addEventListener) { 40 | document.readyState == 'complete' ? startup() : document.addEventListener('DOMContentLoaded', startup, false); 41 | } 42 | /*else if (window.attachEvent) { 43 | window.attachEvent('onload', function () { 44 | startup(); 45 | }); 46 | }*/ 47 | 48 | if(global) window = global; 49 | 50 | var ss = window.ss; 51 | if (!ss) { 52 | window.ss = ss = { 53 | init: onStartup, 54 | ready: onStartup 55 | }; 56 | } 57 | for (var n in globals) { 58 | ss[n] = globals[n]; 59 | } 60 | })(); 61 | 62 | /** 63 | * Helper function for adding properties with Object.defineProperty 64 | * Copied from example on: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty 65 | */ 66 | function withValue(value) { 67 | var d = withValue.d || ( 68 | withValue.d = { 69 | enumerable: false, 70 | writable: false, 71 | configurable: false, 72 | value: null 73 | } 74 | ); 75 | d.value = value; 76 | return d; 77 | } 78 | 79 | Object.__typeName = 'Object'; 80 | Object.__baseType = null; 81 | 82 | Object.clearKeys = function Object$clearKeys(d) { 83 | for (var n in d) { 84 | delete d[n]; 85 | } 86 | } 87 | 88 | Object.keyExists = function Object$keyExists(d, key) { 89 | return d[key] !== undefined; 90 | } 91 | 92 | if (!Object.keys) { 93 | Object.keys = function Object$keys(d) { 94 | var keys = []; 95 | for (var n in d) { 96 | keys.push(n); 97 | } 98 | return keys; 99 | } 100 | 101 | Object.getKeyCount = function Object$getKeyCount(d) { 102 | var count = 0; 103 | for (var n in d) { 104 | count++; 105 | } 106 | return count; 107 | } 108 | } 109 | else { 110 | Object.getKeyCount = function Object$getKeyCount(d) { 111 | return Object.keys(d).length; 112 | } 113 | } 114 | 115 | Boolean.__typeName = 'Boolean'; 116 | 117 | Boolean.parse = function Boolean$parse(s) { 118 | return (s.toLowerCase() == 'true'); 119 | } 120 | 121 | Number.__typeName = 'Number'; 122 | 123 | Number.parse = function Number$parse(s) { 124 | if (!s || !s.length) { 125 | return 0; 126 | } 127 | if ((s.indexOf('.') >= 0) || (s.indexOf('e') >= 0) || 128 | s.endsWith('f') || s.endsWith('F')) { 129 | return parseFloat(s); 130 | } 131 | return parseInt(s, 10); 132 | } 133 | 134 | Number.prototype.format = function Number$format(format) { 135 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 136 | return this.toString(); 137 | } 138 | return this._netFormat(format, false); 139 | } 140 | 141 | Number.prototype.localeFormat = function Number$format(format) { 142 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 143 | return this.toLocaleString(); 144 | } 145 | return this._netFormat(format, true); 146 | } 147 | 148 | Number._commaFormat = function Number$_commaFormat(number, groups, decimal, comma) { 149 | var decimalPart = null; 150 | var decimalIndex = number.indexOf(decimal); 151 | if (decimalIndex > 0) { 152 | decimalPart = number.substr(decimalIndex); 153 | number = number.substr(0, decimalIndex); 154 | } 155 | 156 | var negative = number.startsWith('-'); 157 | if (negative) { 158 | number = number.substr(1); 159 | } 160 | 161 | var groupIndex = 0; 162 | var groupSize = groups[groupIndex]; 163 | if (number.length < groupSize) { 164 | return decimalPart ? number + decimalPart : number; 165 | } 166 | 167 | var index = number.length; 168 | var s = ''; 169 | var done = false; 170 | while (!done) { 171 | var length = groupSize; 172 | var startIndex = index - length; 173 | if (startIndex < 0) { 174 | groupSize += startIndex; 175 | length += startIndex; 176 | startIndex = 0; 177 | done = true; 178 | } 179 | if (!length) { 180 | break; 181 | } 182 | 183 | var part = number.substr(startIndex, length); 184 | if (s.length) { 185 | s = part + comma + s; 186 | } 187 | else { 188 | s = part; 189 | } 190 | index -= length; 191 | 192 | if (groupIndex < groups.length - 1) { 193 | groupIndex++; 194 | groupSize = groups[groupIndex]; 195 | } 196 | } 197 | 198 | if (negative) { 199 | s = '-' + s; 200 | } 201 | return decimalPart ? s + decimalPart : s; 202 | } 203 | 204 | Number.prototype._netFormat = function Number$_netFormat(format, useLocale) { 205 | var nf = useLocale ? ss.CultureInfo.CurrentCulture.numberFormat : ss.CultureInfo.InvariantCulture.numberFormat; 206 | 207 | var s = ''; 208 | var precision = -1; 209 | 210 | if (format.length > 1) { 211 | precision = parseInt(format.substr(1)); 212 | } 213 | 214 | var fs = format.charAt(0); 215 | switch (fs) { 216 | case 'd': case 'D': 217 | s = parseInt(Math.abs(this)).toString(); 218 | if (precision != -1) { 219 | s = s.padLeft(precision, '0'); 220 | } 221 | if (this < 0) { 222 | s = '-' + s; 223 | } 224 | break; 225 | case 'x': case 'X': 226 | s = parseInt(Math.abs(this)).toString(16); 227 | if (fs == 'X') { 228 | s = s.toUpperCase(); 229 | } 230 | if (precision != -1) { 231 | s = s.padLeft(precision, '0'); 232 | } 233 | break; 234 | case 'e': case 'E': 235 | if (precision == -1) { 236 | s = this.toExponential(); 237 | } 238 | else { 239 | s = this.toExponential(precision); 240 | } 241 | if (fs == 'E') { 242 | s = s.toUpperCase(); 243 | } 244 | break; 245 | case 'f': case 'F': 246 | case 'n': case 'N': 247 | if (precision == -1) { 248 | precision = nf.numberDecimalDigits; 249 | } 250 | s = this.toFixed(precision).toString(); 251 | if (precision && (nf.numberDecimalSeparator != '.')) { 252 | var index = s.indexOf('.'); 253 | s = s.substr(0, index) + nf.numberDecimalSeparator + s.substr(index + 1); 254 | } 255 | if ((fs == 'n') || (fs == 'N')) { 256 | s = Number._commaFormat(s, nf.numberGroupSizes, nf.numberDecimalSeparator, nf.numberGroupSeparator); 257 | } 258 | break; 259 | case 'c': case 'C': 260 | if (precision == -1) { 261 | precision = nf.currencyDecimalDigits; 262 | } 263 | s = Math.abs(this).toFixed(precision).toString(); 264 | if (precision && (nf.currencyDecimalSeparator != '.')) { 265 | var index = s.indexOf('.'); 266 | s = s.substr(0, index) + nf.currencyDecimalSeparator + s.substr(index + 1); 267 | } 268 | s = Number._commaFormat(s, nf.currencyGroupSizes, nf.currencyDecimalSeparator, nf.currencyGroupSeparator); 269 | if (this < 0) { 270 | s = String.format(nf.currencyNegativePattern, s); 271 | } 272 | else { 273 | s = String.format(nf.currencyPositivePattern, s); 274 | } 275 | break; 276 | case 'p': case 'P': 277 | if (precision == -1) { 278 | precision = nf.percentDecimalDigits; 279 | } 280 | s = (Math.abs(this) * 100.0).toFixed(precision).toString(); 281 | if (precision && (nf.percentDecimalSeparator != '.')) { 282 | var index = s.indexOf('.'); 283 | s = s.substr(0, index) + nf.percentDecimalSeparator + s.substr(index + 1); 284 | } 285 | s = Number._commaFormat(s, nf.percentGroupSizes, nf.percentDecimalSeparator, nf.percentGroupSeparator); 286 | if (this < 0) { 287 | s = String.format(nf.percentNegativePattern, s); 288 | } 289 | else { 290 | s = String.format(nf.percentPositivePattern, s); 291 | } 292 | break; 293 | } 294 | 295 | return s; 296 | } 297 | 298 | String.__typeName = 'String'; 299 | String.Empty = ''; 300 | 301 | String.compare = function String$compare(s1, s2, ignoreCase) { 302 | if (ignoreCase) { 303 | if (s1) { 304 | s1 = s1.toUpperCase(); 305 | } 306 | if (s2) { 307 | s2 = s2.toUpperCase(); 308 | } 309 | } 310 | s1 = s1 || ''; 311 | s2 = s2 || ''; 312 | 313 | if (s1 == s2) { 314 | return 0; 315 | } 316 | if (s1 < s2) { 317 | return -1; 318 | } 319 | return 1; 320 | } 321 | 322 | String.prototype.compareTo = function String$compareTo(s, ignoreCase) { 323 | return String.compare(this, s, ignoreCase); 324 | } 325 | 326 | String.concat = function String$concat() { 327 | if (arguments.length === 2) { 328 | return arguments[0] + arguments[1]; 329 | } 330 | return Array.prototype.join.call(arguments, ''); 331 | } 332 | 333 | String.prototype.endsWith = function String$endsWith(suffix) { 334 | if (!suffix.length) { 335 | return true; 336 | } 337 | if (suffix.length > this.length) { 338 | return false; 339 | } 340 | return (this.substr(this.length - suffix.length) == suffix); 341 | } 342 | 343 | String.equals = function String$equals1(s1, s2, ignoreCase) { 344 | return String.compare(s1, s2, ignoreCase) == 0; 345 | } 346 | 347 | String._format = function String$_format(format, values, useLocale) { 348 | if (!String._formatRE) { 349 | String._formatRE = /(\{[^\}^\{]+\})/g; 350 | } 351 | 352 | return format.replace(String._formatRE, 353 | function(str, m) { 354 | var index = parseInt(m.substr(1)); 355 | var value = values[index + 1]; 356 | if (ss.isNullOrUndefined(value)) { 357 | return ''; 358 | } 359 | if (value.format) { 360 | var formatSpec = null; 361 | var formatIndex = m.indexOf(':'); 362 | if (formatIndex > 0) { 363 | formatSpec = m.substring(formatIndex + 1, m.length - 1); 364 | } 365 | return useLocale ? value.localeFormat(formatSpec) : value.format(formatSpec); 366 | } 367 | else { 368 | return useLocale ? value.toLocaleString() : value.toString(); 369 | } 370 | }); 371 | } 372 | 373 | String.format = function String$format(format) { 374 | return String._format(format, arguments, /* useLocale */ false); 375 | } 376 | 377 | String.fromChar = function String$fromChar(ch, count) { 378 | var s = ch; 379 | for (var i = 1; i < count; i++) { 380 | s += ch; 381 | } 382 | return s; 383 | } 384 | 385 | String.prototype.htmlDecode = function String$htmlDecode() { 386 | var div = document.createElement('div'); 387 | div.innerHTML = this; 388 | return div.textContent || div.innerText; 389 | } 390 | 391 | String.prototype.htmlEncode = function String$htmlEncode() { 392 | var div = document.createElement('div'); 393 | div.appendChild(document.createTextNode(this)); 394 | return div.innerHTML.replace(/\"/g, '"'); 395 | } 396 | 397 | String.prototype.indexOfAny = function String$indexOfAny(chars, startIndex, count) { 398 | var length = this.length; 399 | if (!length) { 400 | return -1; 401 | } 402 | 403 | startIndex = startIndex || 0; 404 | count = count || length; 405 | 406 | var endIndex = startIndex + count - 1; 407 | if (endIndex >= length) { 408 | endIndex = length - 1; 409 | } 410 | 411 | for (var i = startIndex; i <= endIndex; i++) { 412 | if (chars.indexOf(this.charAt(i)) >= 0) { 413 | return i; 414 | } 415 | } 416 | return -1; 417 | } 418 | 419 | String.prototype.insert = function String$insert(index, value) { 420 | if (!value) { 421 | return this.valueOf(); 422 | } 423 | if (!index) { 424 | return value + this; 425 | } 426 | var s1 = this.substr(0, index); 427 | var s2 = this.substr(index); 428 | return s1 + value + s2; 429 | } 430 | 431 | String.isNullOrEmpty = function String$isNullOrEmpty(s) { 432 | return !s || !s.length; 433 | } 434 | 435 | String.prototype.lastIndexOfAny = function String$lastIndexOfAny(chars, startIndex, count) { 436 | var length = this.length; 437 | if (!length) { 438 | return -1; 439 | } 440 | 441 | startIndex = startIndex || length - 1; 442 | count = count || length; 443 | 444 | var endIndex = startIndex - count + 1; 445 | if (endIndex < 0) { 446 | endIndex = 0; 447 | } 448 | 449 | for (var i = startIndex; i >= endIndex; i--) { 450 | if (chars.indexOf(this.charAt(i)) >= 0) { 451 | return i; 452 | } 453 | } 454 | return -1; 455 | } 456 | 457 | String.localeFormat = function String$localeFormat(format) { 458 | return String._format(format, arguments, /* useLocale */ true); 459 | } 460 | 461 | String.prototype.padLeft = function String$padLeft(totalWidth, ch) { 462 | if (this.length < totalWidth) { 463 | ch = ch || ' '; 464 | return String.fromChar(ch, totalWidth - this.length) + this; 465 | } 466 | return this.valueOf(); 467 | } 468 | 469 | String.prototype.padRight = function String$padRight(totalWidth, ch) { 470 | if (this.length < totalWidth) { 471 | ch = ch || ' '; 472 | return this + String.fromChar(ch, totalWidth - this.length); 473 | } 474 | return this.valueOf(); 475 | } 476 | 477 | String.prototype.remove = function String$remove(index, count) { 478 | if (!count || ((index + count) > this.length)) { 479 | return this.substr(0, index); 480 | } 481 | return this.substr(0, index) + this.substr(index + count); 482 | } 483 | 484 | String.prototype.replaceAll = function String$replaceAll(oldValue, newValue) { 485 | newValue = newValue || ''; 486 | return this.split(oldValue).join(newValue); 487 | } 488 | 489 | String.prototype.startsWith = function String$startsWith(prefix) { 490 | if (!prefix.length) { 491 | return true; 492 | } 493 | if (prefix.length > this.length) { 494 | return false; 495 | } 496 | return (this.substr(0, prefix.length) == prefix); 497 | } 498 | 499 | if (!String.prototype.trim) { 500 | String.prototype.trim = function String$trim() { 501 | return this.trimEnd().trimStart(); 502 | } 503 | } 504 | 505 | String.prototype.trimEnd = function String$trimEnd() { 506 | return this.replace(/\s*$/, ''); 507 | } 508 | 509 | String.prototype.trimStart = function String$trimStart() { 510 | return this.replace(/^\s*/, ''); 511 | } 512 | 513 | Array.__typeName = 'Array'; 514 | Array.__interfaces = [ ss.IEnumerable ]; 515 | 516 | Object.defineProperty(Array.prototype, 'add', withValue(function Array$add(item) { 517 | this[this.length] = item; 518 | })); 519 | 520 | Object.defineProperty(Array.prototype, 'addRange', withValue(function Array$addRange(items) { 521 | this.push.apply(this, items); 522 | })); 523 | 524 | Object.defineProperty(Array.prototype, 'aggregate', withValue(function Array$aggregate(seed, callback, instance) { 525 | var length = this.length; 526 | for (var i = 0; i < length; i++) { 527 | if (i in this) { 528 | seed = callback.call(instance, seed, this[i], i, this); 529 | } 530 | } 531 | return seed; 532 | })); 533 | 534 | Object.defineProperty(Array.prototype, 'clear', withValue(function Array$clear() { 535 | this.length = 0; 536 | })); 537 | 538 | Object.defineProperty(Array.prototype, 'clone', withValue(function Array$clone() { 539 | if (this.length === 1) { 540 | return [this[0]]; 541 | } 542 | else { 543 | return Array.apply(null, this); 544 | } 545 | })); 546 | 547 | Object.defineProperty(Array.prototype, 'contains', withValue(function Array$contains(item) { 548 | var index = this.indexOf(item); 549 | return (index >= 0); 550 | })); 551 | 552 | Object.defineProperty(Array.prototype, 'dequeue', withValue(function Array$dequeue() { 553 | return this.shift(); 554 | })); 555 | 556 | Object.defineProperty(Array.prototype, 'enqueue', withValue(function Array$enqueue(item) { 557 | this._queue = true; 558 | this.push(item); 559 | })); 560 | 561 | Object.defineProperty(Array.prototype, 'peek', withValue(function Array$peek() { 562 | if (this.length) { 563 | var index = this._queue ? 0 : this.length - 1; 564 | return this[index]; 565 | } 566 | return null; 567 | })); 568 | 569 | if (!Array.prototype.every) { 570 | Object.defineProperty(Array.prototype, 'every', withValue(function Array$every(callback, instance) { 571 | var length = this.length; 572 | for (var i = 0; i < length; i++) { 573 | if (i in this && !callback.call(instance, this[i], i, this)) { 574 | return false; 575 | } 576 | } 577 | return true; 578 | })); 579 | } 580 | 581 | Object.defineProperty(Array.prototype, 'extract', withValue(function Array$extract(index, count) { 582 | if (!count) { 583 | return this.slice(index); 584 | } 585 | return this.slice(index, index + count); 586 | })); 587 | 588 | if (!Array.prototype.filter) { 589 | Object.defineProperty(Array.prototype, 'filter', withValue(function Array$filter(callback, instance) { 590 | var length = this.length; 591 | var filtered = []; 592 | for (var i = 0; i < length; i++) { 593 | if (i in this) { 594 | var val = this[i]; 595 | if (callback.call(instance, val, i, this)) { 596 | filtered.push(val); 597 | } 598 | } 599 | } 600 | return filtered; 601 | })); 602 | } 603 | 604 | if (!Array.prototype.forEach) { 605 | Object.defineProperty(Array.prototype, 'forEach', withValue(function Array$forEach(callback, instance) { 606 | var length = this.length; 607 | for (var i = 0; i < length; i++) { 608 | if (i in this) { 609 | callback.call(instance, this[i], i, this); 610 | } 611 | } 612 | })); 613 | } 614 | 615 | Object.defineProperty(Array.prototype, 'getEnumerator', withValue(function Array$getEnumerator() { 616 | return new ss.ArrayEnumerator(this); 617 | })); 618 | 619 | Object.defineProperty(Array.prototype, 'groupBy', withValue(function Array$groupBy(callback, instance) { 620 | var length = this.length; 621 | var groups = []; 622 | var keys = {}; 623 | for (var i = 0; i < length; i++) { 624 | if (i in this) { 625 | var key = callback.call(instance, this[i], i); 626 | if (String.isNullOrEmpty(key)) { 627 | continue; 628 | } 629 | var items = keys[key]; 630 | if (!items) { 631 | items = []; 632 | items.key = key; 633 | 634 | keys[key] = items; 635 | groups.add(items); 636 | } 637 | items.add(this[i]); 638 | } 639 | } 640 | return groups; 641 | })); 642 | 643 | Object.defineProperty(Array.prototype, 'index', withValue(function Array$index(callback, instance) { 644 | var length = this.length; 645 | var items = {}; 646 | for (var i = 0; i < length; i++) { 647 | if (i in this) { 648 | var key = callback.call(instance, this[i], i); 649 | if (String.isNullOrEmpty(key)) { 650 | continue; 651 | } 652 | items[key] = this[i]; 653 | } 654 | } 655 | return items; 656 | })); 657 | 658 | if (!Array.prototype.indexOf) { 659 | Object.defineProperty(Array.prototype, 'indexOf', withValue(function Array$indexOf(item, startIndex) { 660 | startIndex = startIndex || 0; 661 | var length = this.length; 662 | if (length) { 663 | for (var index = startIndex; index < length; index++) { 664 | if (this[index] === item) { 665 | return index; 666 | } 667 | } 668 | } 669 | return -1; 670 | })); 671 | } 672 | 673 | Object.defineProperty(Array.prototype, 'insert', withValue(function Array$insert(index, item) { 674 | this.splice(index, 0, item); 675 | })); 676 | 677 | Object.defineProperty(Array.prototype, 'insertRange', withValue(function Array$insertRange(index, items) { 678 | if (index === 0) { 679 | this.unshift.apply(this, items); 680 | } 681 | else { 682 | for (var i = 0; i < items.length; i++) { 683 | this.splice(index + i, 0, items[i]); 684 | } 685 | } 686 | })); 687 | 688 | if (!Array.prototype.map) { 689 | Object.defineProperty(Array.prototype, 'map', withValue(function Array$map(callback, instance) { 690 | var length = this.length; 691 | var mapped = new Array(length); 692 | for (var i = 0; i < length; i++) { 693 | if (i in this) { 694 | mapped[i] = callback.call(instance, this[i], i, this); 695 | } 696 | } 697 | return mapped; 698 | })); 699 | } 700 | 701 | Array.parse = function Array$parse(s) { 702 | return eval('(' + s + ')'); 703 | } 704 | 705 | Object.defineProperty(Array.prototype, 'remove', withValue(function Array$remove(item) { 706 | var index = this.indexOf(item); 707 | if (index >= 0) { 708 | this.splice(index, 1); 709 | return true; 710 | } 711 | return false; 712 | })); 713 | 714 | Object.defineProperty(Array.prototype, 'removeAt', withValue(function Array$removeAt(index) { 715 | this.splice(index, 1); 716 | })); 717 | 718 | Object.defineProperty(Array.prototype, 'removeRange', withValue(function Array$removeRange(index, count) { 719 | return this.splice(index, count); 720 | })); 721 | 722 | if (!Array.prototype.some) { 723 | Object.defineProperty(Array.prototype, 'some', withValue(function Array$some(callback, instance) { 724 | var length = this.length; 725 | for (var i = 0; i < length; i++) { 726 | if (i in this && callback.call(instance, this[i], i, this)) { 727 | return true; 728 | } 729 | } 730 | return false; 731 | })); 732 | } 733 | 734 | Array.toArray = function Array$toArray(obj) { 735 | return Array.prototype.slice.call(obj); 736 | } 737 | 738 | RegExp.__typeName = 'RegExp'; 739 | 740 | RegExp.parse = function RegExp$parse(s) { 741 | if (s.startsWith('/')) { 742 | var endSlashIndex = s.lastIndexOf('/'); 743 | if (endSlashIndex > 1) { 744 | var expression = s.substring(1, endSlashIndex); 745 | var flags = s.substr(endSlashIndex + 1); 746 | return new RegExp(expression, flags); 747 | } 748 | } 749 | 750 | return null; 751 | } 752 | 753 | Date.__typeName = 'Date'; 754 | 755 | Date.empty = null; 756 | 757 | Date.get_now = function Date$get_now() { 758 | return new Date(); 759 | } 760 | 761 | Date.get_today = function Date$get_today() { 762 | var d = new Date(); 763 | return new Date(d.getFullYear(), d.getMonth(), d.getDate()); 764 | } 765 | 766 | Date.isEmpty = function Date$isEmpty(d) { 767 | return (d === null) || (d.valueOf() === 0); 768 | } 769 | 770 | Date.prototype.format = function Date$format(format) { 771 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 772 | return this.toString(); 773 | } 774 | if (format == 'id') { 775 | return this.toDateString(); 776 | } 777 | if (format == 'it') { 778 | return this.toTimeString(); 779 | } 780 | 781 | return this._netFormat(format, false); 782 | } 783 | 784 | Date.prototype.localeFormat = function Date$localeFormat(format) { 785 | if (ss.isNullOrUndefined(format) || (format.length == 0) || (format == 'i')) { 786 | return this.toLocaleString(); 787 | } 788 | if (format == 'id') { 789 | return this.toLocaleDateString(); 790 | } 791 | if (format == 'it') { 792 | return this.toLocaleTimeString(); 793 | } 794 | 795 | return this._netFormat(format, true); 796 | } 797 | 798 | Date.prototype._netFormat = function Date$_netFormat(format, useLocale) { 799 | var dt = this; 800 | var dtf = useLocale ? ss.CultureInfo.CurrentCulture.dateFormat : ss.CultureInfo.InvariantCulture.dateFormat; 801 | 802 | if (format.length == 1) { 803 | switch (format) { 804 | case 'f': format = dtf.longDatePattern + ' ' + dtf.shortTimePattern; break; 805 | case 'F': format = dtf.dateTimePattern; break; 806 | 807 | case 'd': format = dtf.shortDatePattern; break; 808 | case 'D': format = dtf.longDatePattern; break; 809 | 810 | case 't': format = dtf.shortTimePattern; break; 811 | case 'T': format = dtf.longTimePattern; break; 812 | 813 | case 'g': format = dtf.shortDatePattern + ' ' + dtf.shortTimePattern; break; 814 | case 'G': format = dtf.shortDatePattern + ' ' + dtf.longTimePattern; break; 815 | 816 | case 'R': case 'r': 817 | dtf = ss.CultureInfo.InvariantCulture.dateFormat; 818 | format = dtf.gmtDateTimePattern; 819 | break; 820 | case 'u': format = dtf.universalDateTimePattern; break; 821 | case 'U': 822 | format = dtf.dateTimePattern; 823 | dt = new Date(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate(), 824 | dt.getUTCHours(), dt.getUTCMinutes(), dt.getUTCSeconds(), dt.getUTCMilliseconds()); 825 | break; 826 | 827 | case 's': format = dtf.sortableDateTimePattern; break; 828 | } 829 | } 830 | 831 | if (format.charAt(0) == '%') { 832 | format = format.substr(1); 833 | } 834 | 835 | if (!Date._formatRE) { 836 | Date._formatRE = /'.*?[^\\]'|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z/g; 837 | } 838 | 839 | var re = Date._formatRE; 840 | var sb = new ss.StringBuilder(); 841 | 842 | re.lastIndex = 0; 843 | while (true) { 844 | var index = re.lastIndex; 845 | var match = re.exec(format); 846 | 847 | sb.append(format.slice(index, match ? match.index : format.length)); 848 | if (!match) { 849 | break; 850 | } 851 | 852 | var fs = match[0]; 853 | var part = fs; 854 | switch (fs) { 855 | case 'dddd': 856 | part = dtf.dayNames[dt.getDay()]; 857 | break; 858 | case 'ddd': 859 | part = dtf.shortDayNames[dt.getDay()]; 860 | break; 861 | case 'dd': 862 | part = dt.getDate().toString().padLeft(2, '0'); 863 | break; 864 | case 'd': 865 | part = dt.getDate(); 866 | break; 867 | case 'MMMM': 868 | part = dtf.monthNames[dt.getMonth()]; 869 | break; 870 | case 'MMM': 871 | part = dtf.shortMonthNames[dt.getMonth()]; 872 | break; 873 | case 'MM': 874 | part = (dt.getMonth() + 1).toString().padLeft(2, '0'); 875 | break; 876 | case 'M': 877 | part = (dt.getMonth() + 1); 878 | break; 879 | case 'yyyy': 880 | part = dt.getFullYear(); 881 | break; 882 | case 'yy': 883 | part = (dt.getFullYear() % 100).toString().padLeft(2, '0'); 884 | break; 885 | case 'y': 886 | part = (dt.getFullYear() % 100); 887 | break; 888 | case 'h': case 'hh': 889 | part = dt.getHours() % 12; 890 | if (!part) { 891 | part = '12'; 892 | } 893 | else if (fs == 'hh') { 894 | part = part.toString().padLeft(2, '0'); 895 | } 896 | break; 897 | case 'HH': 898 | part = dt.getHours().toString().padLeft(2, '0'); 899 | break; 900 | case 'H': 901 | part = dt.getHours(); 902 | break; 903 | case 'mm': 904 | part = dt.getMinutes().toString().padLeft(2, '0'); 905 | break; 906 | case 'm': 907 | part = dt.getMinutes(); 908 | break; 909 | case 'ss': 910 | part = dt.getSeconds().toString().padLeft(2, '0'); 911 | break; 912 | case 's': 913 | part = dt.getSeconds(); 914 | break; 915 | case 't': case 'tt': 916 | part = (dt.getHours() < 12) ? dtf.amDesignator : dtf.pmDesignator; 917 | if (fs == 't') { 918 | part = part.charAt(0); 919 | } 920 | break; 921 | case 'fff': 922 | part = dt.getMilliseconds().toString().padLeft(3, '0'); 923 | break; 924 | case 'ff': 925 | part = dt.getMilliseconds().toString().padLeft(3).substr(0, 2); 926 | break; 927 | case 'f': 928 | part = dt.getMilliseconds().toString().padLeft(3).charAt(0); 929 | break; 930 | case 'z': 931 | part = dt.getTimezoneOffset() / 60; 932 | part = ((part >= 0) ? '-' : '+') + Math.floor(Math.abs(part)); 933 | break; 934 | case 'zz': case 'zzz': 935 | part = dt.getTimezoneOffset() / 60; 936 | part = ((part >= 0) ? '-' : '+') + Math.floor(Math.abs(part)).toString().padLeft(2, '0'); 937 | if (fs == 'zzz') { 938 | part += dtf.timeSeparator + Math.abs(dt.getTimezoneOffset() % 60).toString().padLeft(2, '0'); 939 | } 940 | break; 941 | default: 942 | if (part.charAt(0) == '\'') { 943 | part = part.substr(1, part.length - 2).replace(/\\'/g, '\''); 944 | } 945 | break; 946 | } 947 | sb.append(part); 948 | } 949 | 950 | return sb.toString(); 951 | } 952 | 953 | Date.parseDate = function Date$parse(s) { 954 | return new Date(Date.parse(s)); 955 | } 956 | 957 | Error.__typeName = 'Error'; 958 | 959 | Error.prototype.popStackFrame = function Error$popStackFrame() { 960 | if (ss.isNullOrUndefined(this.stack) || 961 | ss.isNullOrUndefined(this.fileName) || 962 | ss.isNullOrUndefined(this.lineNumber)) { 963 | return; 964 | } 965 | 966 | var stackFrames = this.stack.split('\n'); 967 | var currentFrame = stackFrames[0]; 968 | var pattern = this.fileName + ':' + this.lineNumber; 969 | while (!ss.isNullOrUndefined(currentFrame) && 970 | currentFrame.indexOf(pattern) === -1) { 971 | stackFrames.shift(); 972 | currentFrame = stackFrames[0]; 973 | } 974 | 975 | var nextFrame = stackFrames[1]; 976 | if (isNullOrUndefined(nextFrame)) { 977 | return; 978 | } 979 | 980 | var nextFrameParts = nextFrame.match(/@(.*):(\d+)$/); 981 | if (ss.isNullOrUndefined(nextFrameParts)) { 982 | return; 983 | } 984 | 985 | stackFrames.shift(); 986 | this.stack = stackFrames.join("\n"); 987 | this.fileName = nextFrameParts[1]; 988 | this.lineNumber = parseInt(nextFrameParts[2]); 989 | } 990 | 991 | Error.createError = function Error$createError(message, errorInfo, innerException) { 992 | var e = new Error(message); 993 | if (errorInfo) { 994 | for (var v in errorInfo) { 995 | e[v] = errorInfo[v]; 996 | } 997 | } 998 | if (innerException) { 999 | e.innerException = innerException; 1000 | } 1001 | 1002 | e.popStackFrame(); 1003 | return e; 1004 | } 1005 | 1006 | ss.Debug = window.Debug || function() {}; 1007 | ss.Debug.__typeName = 'Debug'; 1008 | 1009 | if (!ss.Debug.writeln) { 1010 | ss.Debug.writeln = function Debug$writeln(text) { 1011 | if (window.console) { 1012 | if (window.console.debug) { 1013 | window.console.debug(text); 1014 | return; 1015 | } 1016 | else if (window.console.log) { 1017 | window.console.log(text); 1018 | return; 1019 | } 1020 | } 1021 | else if (window.opera && 1022 | window.opera.postError) { 1023 | window.opera.postError(text); 1024 | return; 1025 | } 1026 | } 1027 | } 1028 | 1029 | ss.Debug._fail = function Debug$_fail(message) { 1030 | ss.Debug.writeln(message); 1031 | eval('debugger;'); 1032 | } 1033 | 1034 | ss.Debug.assert = function Debug$assert(condition, message) { 1035 | if (!condition) { 1036 | message = 'Assert failed: ' + message; 1037 | if (confirm(message + '\r\n\r\nBreak into debugger?')) { 1038 | ss.Debug._fail(message); 1039 | } 1040 | } 1041 | } 1042 | 1043 | ss.Debug.fail = function Debug$fail(message) { 1044 | ss.Debug._fail(message); 1045 | } 1046 | 1047 | window.Type = Function; 1048 | Type.__typeName = 'Type'; 1049 | 1050 | window.__Namespace = function(name) { 1051 | this.__typeName = name; 1052 | } 1053 | __Namespace.prototype = { 1054 | __namespace: true, 1055 | getName: function() { 1056 | return this.__typeName; 1057 | } 1058 | } 1059 | 1060 | Type.registerNamespace = function Type$registerNamespace(name) { 1061 | if (!window.__namespaces) { 1062 | window.__namespaces = {}; 1063 | } 1064 | if (!window.__rootNamespaces) { 1065 | window.__rootNamespaces = []; 1066 | } 1067 | 1068 | if (window.__namespaces[name]) { 1069 | return; 1070 | } 1071 | 1072 | var ns = window; 1073 | var nameParts = name.split('.'); 1074 | 1075 | for (var i = 0; i < nameParts.length; i++) { 1076 | var part = nameParts[i]; 1077 | var nso = ns[part]; 1078 | if (!nso) { 1079 | ns[part] = nso = new __Namespace(nameParts.slice(0, i + 1).join('.')); 1080 | if (i == 0) { 1081 | window.__rootNamespaces.add(nso); 1082 | } 1083 | } 1084 | ns = nso; 1085 | } 1086 | 1087 | window.__namespaces[name] = ns; 1088 | } 1089 | 1090 | Type.prototype.registerClass = function Type$registerClass(name, baseType, interfaceType) { 1091 | this.prototype.constructor = this; 1092 | this.__typeName = name; 1093 | this.__class = true; 1094 | this.__baseType = baseType || Object; 1095 | if (baseType) { 1096 | this.__basePrototypePending = true; 1097 | } 1098 | 1099 | if (interfaceType) { 1100 | this.__interfaces = []; 1101 | for (var i = 2; i < arguments.length; i++) { 1102 | interfaceType = arguments[i]; 1103 | this.__interfaces.add(interfaceType); 1104 | } 1105 | } 1106 | } 1107 | 1108 | Type.prototype.registerInterface = function Type$createInterface(name) { 1109 | this.__typeName = name; 1110 | this.__interface = true; 1111 | } 1112 | 1113 | Type.prototype.registerEnum = function Type$createEnum(name, flags) { 1114 | for (var field in this.prototype) { 1115 | this[field] = this.prototype[field]; 1116 | } 1117 | 1118 | this.__typeName = name; 1119 | this.__enum = true; 1120 | if (flags) { 1121 | this.__flags = true; 1122 | } 1123 | } 1124 | 1125 | Type.prototype.setupBase = function Type$setupBase() { 1126 | if (this.__basePrototypePending) { 1127 | var baseType = this.__baseType; 1128 | if (baseType.__basePrototypePending) { 1129 | baseType.setupBase(); 1130 | } 1131 | 1132 | for (var memberName in baseType.prototype) { 1133 | var memberValue = baseType.prototype[memberName]; 1134 | if (!this.prototype[memberName]) { 1135 | this.prototype[memberName] = memberValue; 1136 | } 1137 | } 1138 | 1139 | delete this.__basePrototypePending; 1140 | } 1141 | } 1142 | 1143 | if (!Type.prototype.resolveInheritance) { 1144 | Type.prototype.resolveInheritance = Type.prototype.setupBase; 1145 | } 1146 | 1147 | Type.prototype.initializeBase = function Type$initializeBase(instance, args) { 1148 | if (this.__basePrototypePending) { 1149 | this.setupBase(); 1150 | } 1151 | 1152 | if (!args) { 1153 | this.__baseType.apply(instance); 1154 | } 1155 | else { 1156 | this.__baseType.apply(instance, args); 1157 | } 1158 | } 1159 | 1160 | Type.prototype.callBaseMethod = function Type$callBaseMethod(instance, name, args) { 1161 | var baseMethod = this.__baseType.prototype[name]; 1162 | if (!args) { 1163 | return baseMethod.apply(instance); 1164 | } 1165 | else { 1166 | return baseMethod.apply(instance, args); 1167 | } 1168 | } 1169 | 1170 | Type.prototype.get_baseType = function Type$get_baseType() { 1171 | return this.__baseType || null; 1172 | } 1173 | 1174 | Type.prototype.get_fullName = function Type$get_fullName() { 1175 | return this.__typeName; 1176 | } 1177 | 1178 | Type.prototype.get_name = function Type$get_name() { 1179 | var fullName = this.__typeName; 1180 | var nsIndex = fullName.lastIndexOf('.'); 1181 | if (nsIndex > 0) { 1182 | return fullName.substr(nsIndex + 1); 1183 | } 1184 | return fullName; 1185 | } 1186 | 1187 | Type.prototype.getInterfaces = function Type$getInterfaces() { 1188 | return this.__interfaces; 1189 | } 1190 | 1191 | Type.prototype.isInstanceOfType = function Type$isInstanceOfType(instance) { 1192 | if (ss.isNullOrUndefined(instance)) { 1193 | return false; 1194 | } 1195 | if ((this == Object) || (instance instanceof this)) { 1196 | return true; 1197 | } 1198 | 1199 | var type = Type.getInstanceType(instance); 1200 | return this.isAssignableFrom(type); 1201 | } 1202 | 1203 | Type.prototype.isAssignableFrom = function Type$isAssignableFrom(type) { 1204 | if ((this == Object) || (this == type)) { 1205 | return true; 1206 | } 1207 | if (this.__class) { 1208 | var baseType = type.__baseType; 1209 | while (baseType) { 1210 | if (this == baseType) { 1211 | return true; 1212 | } 1213 | baseType = baseType.__baseType; 1214 | } 1215 | } 1216 | else if (this.__interface) { 1217 | var interfaces = type.__interfaces; 1218 | if (interfaces && interfaces.contains(this)) { 1219 | return true; 1220 | } 1221 | 1222 | var baseType = type.__baseType; 1223 | while (baseType) { 1224 | interfaces = baseType.__interfaces; 1225 | if (interfaces && interfaces.contains(this)) { 1226 | return true; 1227 | } 1228 | baseType = baseType.__baseType; 1229 | } 1230 | } 1231 | return false; 1232 | } 1233 | 1234 | Type.isClass = function Type$isClass(type) { 1235 | return (type.__class == true); 1236 | } 1237 | 1238 | Type.isEnum = function Type$isEnum(type) { 1239 | return (type.__enum == true); 1240 | } 1241 | 1242 | Type.isFlags = function Type$isFlags(type) { 1243 | return ((type.__enum == true) && (type.__flags == true)); 1244 | } 1245 | 1246 | Type.isInterface = function Type$isInterface(type) { 1247 | return (type.__interface == true); 1248 | } 1249 | 1250 | Type.isNamespace = function Type$isNamespace(object) { 1251 | return (object.__namespace == true); 1252 | } 1253 | 1254 | Type.canCast = function Type$canCast(instance, type) { 1255 | return type.isInstanceOfType(instance); 1256 | } 1257 | 1258 | Type.safeCast = function Type$safeCast(instance, type) { 1259 | if (type.isInstanceOfType(instance)) { 1260 | return instance; 1261 | } 1262 | return null; 1263 | } 1264 | 1265 | Type.getInstanceType = function Type$getInstanceType(instance) { 1266 | var ctor = null; 1267 | try { 1268 | ctor = instance.constructor; 1269 | } 1270 | catch (ex) { 1271 | } 1272 | if (!ctor || !ctor.__typeName) { 1273 | ctor = Object; 1274 | } 1275 | return ctor; 1276 | } 1277 | 1278 | Type.getType = function Type$getType(typeName) { 1279 | if (!typeName) { 1280 | return null; 1281 | } 1282 | 1283 | if (!Type.__typeCache) { 1284 | Type.__typeCache = {}; 1285 | } 1286 | 1287 | var type = Type.__typeCache[typeName]; 1288 | if (!type) { 1289 | type = eval(typeName); 1290 | Type.__typeCache[typeName] = type; 1291 | } 1292 | return type; 1293 | } 1294 | 1295 | Type.parse = function Type$parse(typeName) { 1296 | return Type.getType(typeName); 1297 | } 1298 | 1299 | ss.Delegate = function Delegate$() { 1300 | } 1301 | ss.Delegate.registerClass('Delegate'); 1302 | 1303 | ss.Delegate.empty = function() { } 1304 | 1305 | ss.Delegate._contains = function Delegate$_contains(targets, object, method) { 1306 | for (var i = 0; i < targets.length; i += 2) { 1307 | if (targets[i] === object && targets[i + 1] === method) { 1308 | return true; 1309 | } 1310 | } 1311 | return false; 1312 | } 1313 | 1314 | ss.Delegate._create = function Delegate$_create(targets) { 1315 | var delegate = function() { 1316 | if (targets.length == 2) { 1317 | return targets[1].apply(targets[0], arguments); 1318 | } 1319 | else { 1320 | var clone = targets.clone(); 1321 | for (var i = 0; i < clone.length; i += 2) { 1322 | if (ss.Delegate._contains(targets, clone[i], clone[i + 1])) { 1323 | clone[i + 1].apply(clone[i], arguments); 1324 | } 1325 | } 1326 | return null; 1327 | } 1328 | }; 1329 | delegate._targets = targets; 1330 | 1331 | return delegate; 1332 | } 1333 | 1334 | ss.Delegate.create = function Delegate$create(object, method) { 1335 | if (!object) { 1336 | return method; 1337 | } 1338 | return ss.Delegate._create([object, method]); 1339 | } 1340 | 1341 | ss.Delegate.combine = function Delegate$combine(delegate1, delegate2) { 1342 | if (!delegate1) { 1343 | if (!delegate2._targets) { 1344 | return ss.Delegate.create(null, delegate2); 1345 | } 1346 | return delegate2; 1347 | } 1348 | if (!delegate2) { 1349 | if (!delegate1._targets) { 1350 | return ss.Delegate.create(null, delegate1); 1351 | } 1352 | return delegate1; 1353 | } 1354 | 1355 | var targets1 = delegate1._targets ? delegate1._targets : [null, delegate1]; 1356 | var targets2 = delegate2._targets ? delegate2._targets : [null, delegate2]; 1357 | 1358 | return ss.Delegate._create(targets1.concat(targets2)); 1359 | } 1360 | 1361 | ss.Delegate.remove = function Delegate$remove(delegate1, delegate2) { 1362 | if (!delegate1 || (delegate1 === delegate2)) { 1363 | return null; 1364 | } 1365 | if (!delegate2) { 1366 | return delegate1; 1367 | } 1368 | 1369 | var targets = delegate1._targets; 1370 | var object = null; 1371 | var method; 1372 | if (delegate2._targets) { 1373 | object = delegate2._targets[0]; 1374 | method = delegate2._targets[1]; 1375 | } 1376 | else { 1377 | method = delegate2; 1378 | } 1379 | 1380 | for (var i = 0; i < targets.length; i += 2) { 1381 | if ((targets[i] === object) && (targets[i + 1] === method)) { 1382 | if (targets.length == 2) { 1383 | return null; 1384 | } 1385 | targets.splice(i, 2); 1386 | return ss.Delegate._create(targets); 1387 | } 1388 | } 1389 | 1390 | return delegate1; 1391 | } 1392 | 1393 | ss.Delegate.createExport = function Delegate$createExport(delegate, multiUse, name) { 1394 | name = name || '__' + (new Date()).valueOf(); 1395 | 1396 | window[name] = multiUse ? delegate : function() { 1397 | try { delete window[name]; } catch(e) { window[name] = undefined; } 1398 | delegate.apply(null, arguments); 1399 | }; 1400 | 1401 | return name; 1402 | } 1403 | 1404 | ss.Delegate.deleteExport = function Delegate$deleteExport(name) { 1405 | delete window[name]; 1406 | } 1407 | 1408 | ss.Delegate.clearExport = function Delegate$clearExport(name) { 1409 | window[name] = ss.Delegate.empty; 1410 | } 1411 | 1412 | ss.CultureInfo = function CultureInfo$(name, numberFormat, dateFormat) { 1413 | this.name = name; 1414 | this.numberFormat = numberFormat; 1415 | this.dateFormat = dateFormat; 1416 | } 1417 | ss.CultureInfo.registerClass('CultureInfo'); 1418 | 1419 | ss.CultureInfo.InvariantCulture = new ss.CultureInfo('en-US', 1420 | { 1421 | naNSymbol: 'NaN', 1422 | negativeSign: '-', 1423 | positiveSign: '+', 1424 | negativeInfinityText: '-Infinity', 1425 | positiveInfinityText: 'Infinity', 1426 | 1427 | percentSymbol: '%', 1428 | percentGroupSizes: [3], 1429 | percentDecimalDigits: 2, 1430 | percentDecimalSeparator: '.', 1431 | percentGroupSeparator: ',', 1432 | percentPositivePattern: '{0} %', 1433 | percentNegativePattern: '-{0} %', 1434 | 1435 | currencySymbol:'$', 1436 | currencyGroupSizes: [3], 1437 | currencyDecimalDigits: 2, 1438 | currencyDecimalSeparator: '.', 1439 | currencyGroupSeparator: ',', 1440 | currencyNegativePattern: '(${0})', 1441 | currencyPositivePattern: '${0}', 1442 | 1443 | numberGroupSizes: [3], 1444 | numberDecimalDigits: 2, 1445 | numberDecimalSeparator: '.', 1446 | numberGroupSeparator: ',' 1447 | }, 1448 | { 1449 | amDesignator: 'AM', 1450 | pmDesignator: 'PM', 1451 | 1452 | dateSeparator: '/', 1453 | timeSeparator: ':', 1454 | 1455 | gmtDateTimePattern: 'ddd, dd MMM yyyy HH:mm:ss \'GMT\'', 1456 | universalDateTimePattern: 'yyyy-MM-dd HH:mm:ssZ', 1457 | sortableDateTimePattern: 'yyyy-MM-ddTHH:mm:ss', 1458 | dateTimePattern: 'dddd, MMMM dd, yyyy h:mm:ss tt', 1459 | 1460 | longDatePattern: 'dddd, MMMM dd, yyyy', 1461 | shortDatePattern: 'M/d/yyyy', 1462 | 1463 | longTimePattern: 'h:mm:ss tt', 1464 | shortTimePattern: 'h:mm tt', 1465 | 1466 | firstDayOfWeek: 0, 1467 | dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'], 1468 | shortDayNames: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'], 1469 | minimizedDayNames: ['Su','Mo','Tu','We','Th','Fr','Sa'], 1470 | 1471 | monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December',''], 1472 | shortMonthNames: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',''] 1473 | }); 1474 | ss.CultureInfo.CurrentCulture = ss.CultureInfo.InvariantCulture; 1475 | 1476 | ss.IEnumerator = function IEnumerator$() { }; 1477 | ss.IEnumerator.prototype = { 1478 | get_current: null, 1479 | moveNext: null, 1480 | reset: null 1481 | } 1482 | 1483 | ss.IEnumerator.getEnumerator = function ss_IEnumerator$getEnumerator(enumerable) { 1484 | if (enumerable) { 1485 | return enumerable.getEnumerator ? enumerable.getEnumerator() : new ss.ArrayEnumerator(enumerable); 1486 | } 1487 | return null; 1488 | } 1489 | 1490 | ss.IEnumerator.registerInterface('IEnumerator'); 1491 | 1492 | ss.IEnumerable = function IEnumerable$() { }; 1493 | ss.IEnumerable.prototype = { 1494 | getEnumerator: null 1495 | } 1496 | ss.IEnumerable.registerInterface('IEnumerable'); 1497 | 1498 | ss.ArrayEnumerator = function ArrayEnumerator$(array) { 1499 | this._array = array; 1500 | this._index = -1; 1501 | this.current = null; 1502 | } 1503 | ss.ArrayEnumerator.prototype = { 1504 | moveNext: function ArrayEnumerator$moveNext() { 1505 | this._index++; 1506 | this.current = this._array[this._index]; 1507 | return (this._index < this._array.length); 1508 | }, 1509 | reset: function ArrayEnumerator$reset() { 1510 | this._index = -1; 1511 | this.current = null; 1512 | } 1513 | } 1514 | 1515 | ss.ArrayEnumerator.registerClass('ArrayEnumerator', null, ss.IEnumerator); 1516 | 1517 | ss.IDisposable = function IDisposable$() { }; 1518 | ss.IDisposable.prototype = { 1519 | dispose: null 1520 | } 1521 | ss.IDisposable.registerInterface('IDisposable'); 1522 | 1523 | ss.StringBuilder = function StringBuilder$(s) { 1524 | this._parts = ss.isNullOrUndefined(s) || s === '' ? [] : [s]; 1525 | this.isEmpty = this._parts.length == 0; 1526 | } 1527 | ss.StringBuilder.prototype = { 1528 | append: function StringBuilder$append(s) { 1529 | if (!ss.isNullOrUndefined(s) && s !== '') { 1530 | this._parts.add(s); 1531 | this.isEmpty = false; 1532 | } 1533 | return this; 1534 | }, 1535 | 1536 | appendLine: function StringBuilder$appendLine(s) { 1537 | this.append(s); 1538 | this.append('\r\n'); 1539 | this.isEmpty = false; 1540 | return this; 1541 | }, 1542 | 1543 | clear: function StringBuilder$clear() { 1544 | this._parts = []; 1545 | this.isEmpty = true; 1546 | }, 1547 | 1548 | toString: function StringBuilder$toString(s) { 1549 | return this._parts.join(s || ''); 1550 | } 1551 | }; 1552 | 1553 | ss.StringBuilder.registerClass('StringBuilder'); 1554 | 1555 | ss.EventArgs = function EventArgs$() { 1556 | } 1557 | ss.EventArgs.registerClass('EventArgs'); 1558 | 1559 | ss.EventArgs.Empty = new ss.EventArgs(); 1560 | 1561 | if (!window.XMLHttpRequest) { 1562 | window.XMLHttpRequest = function() { 1563 | var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ]; 1564 | 1565 | for (var i = 0; i < progIDs.length; i++) { 1566 | try { 1567 | var xmlHttp = new ActiveXObject(progIDs[i]); 1568 | return xmlHttp; 1569 | } 1570 | catch (ex) { 1571 | } 1572 | } 1573 | 1574 | return null; 1575 | } 1576 | } 1577 | 1578 | ss.parseXml = function(markup) { 1579 | try { 1580 | if (DOMParser) { 1581 | var domParser = new DOMParser(); 1582 | return domParser.parseFromString(markup, 'text/xml'); 1583 | } 1584 | else { 1585 | var progIDs = [ 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ]; 1586 | 1587 | for (var i = 0; i < progIDs.length; i++) { 1588 | var xmlDOM = new ActiveXObject(progIDs[i]); 1589 | xmlDOM.async = false; 1590 | xmlDOM.loadXML(markup); 1591 | xmlDOM.setProperty('SelectionLanguage', 'XPath'); 1592 | 1593 | return xmlDOM; 1594 | } 1595 | } 1596 | } 1597 | catch (ex) { 1598 | } 1599 | 1600 | return null; 1601 | } 1602 | 1603 | ss.CancelEventArgs = function CancelEventArgs$() { 1604 | ss.CancelEventArgs.initializeBase(this); 1605 | this.cancel = false; 1606 | } 1607 | ss.CancelEventArgs.registerClass('CancelEventArgs', ss.EventArgs); 1608 | 1609 | ss.Tuple = function (first, second, third) { 1610 | this.first = first; 1611 | this.second = second; 1612 | if (arguments.length == 3) { 1613 | this.third = third; 1614 | } 1615 | } 1616 | ss.Tuple.registerClass('Tuple'); 1617 | 1618 | ss.Observable = function(v) { 1619 | this._v = v; 1620 | this._observers = null; 1621 | } 1622 | ss.Observable.prototype = { 1623 | 1624 | getValue: function () { 1625 | this._observers = ss.Observable._captureObservers(this._observers); 1626 | return this._v; 1627 | }, 1628 | setValue: function (v) { 1629 | if (this._v !== v) { 1630 | this._v = v; 1631 | 1632 | var observers = this._observers; 1633 | if (observers) { 1634 | this._observers = null; 1635 | ss.Observable._invalidateObservers(observers); 1636 | } 1637 | } 1638 | } 1639 | }; 1640 | 1641 | ss.Observable._observerStack = []; 1642 | ss.Observable._observerRegistration = { 1643 | dispose: function () { 1644 | ss.Observable._observerStack.pop(); 1645 | } 1646 | } 1647 | ss.Observable.registerObserver = function (o) { 1648 | ss.Observable._observerStack.push(o); 1649 | return ss.Observable._observerRegistration; 1650 | } 1651 | ss.Observable._captureObservers = function (observers) { 1652 | var registeredObservers = ss.Observable._observerStack; 1653 | var observerCount = registeredObservers.length; 1654 | 1655 | if (observerCount) { 1656 | observers = observers || []; 1657 | for (var i = 0; i < observerCount; i++) { 1658 | var observer = registeredObservers[i]; 1659 | if (!observers.contains(observer)) { 1660 | observers.push(observer); 1661 | } 1662 | } 1663 | return observers; 1664 | } 1665 | return null; 1666 | } 1667 | ss.Observable._invalidateObservers = function (observers) { 1668 | for (var i = 0, len = observers.length; i < len; i++) { 1669 | observers[i].invalidateObserver(); 1670 | } 1671 | } 1672 | 1673 | ss.Observable.registerClass('Observable'); 1674 | 1675 | 1676 | ss.ObservableCollection = function (items) { 1677 | this._items = items || []; 1678 | this._observers = null; 1679 | } 1680 | ss.ObservableCollection.prototype = { 1681 | 1682 | get_item: function (index) { 1683 | this._observers = ss.Observable._captureObservers(this._observers); 1684 | return this._items[index]; 1685 | }, 1686 | set_item: function (index, item) { 1687 | this._items[index] = item; 1688 | this._updated(); 1689 | }, 1690 | get_length: function () { 1691 | this._observers = ss.Observable._captureObservers(this._observers); 1692 | return this._items.length; 1693 | }, 1694 | add: function (item) { 1695 | this._items.push(item); 1696 | this._updated(); 1697 | }, 1698 | clear: function () { 1699 | this._items.clear(); 1700 | this._updated(); 1701 | }, 1702 | contains: function (item) { 1703 | return this._items.contains(item); 1704 | }, 1705 | getEnumerator: function () { 1706 | this._observers = ss.Observable._captureObservers(this._observers); 1707 | return this._items.getEnumerator(); 1708 | }, 1709 | indexOf: function (item) { 1710 | return this._items.indexOf(item); 1711 | }, 1712 | insert: function (index, item) { 1713 | this._items.insert(index, item); 1714 | this._updated(); 1715 | }, 1716 | remove: function (item) { 1717 | if (this._items.remove(item)) { 1718 | this._updated(); 1719 | return true; 1720 | } 1721 | return false; 1722 | }, 1723 | removeAt: function (index) { 1724 | this._items.removeAt(index); 1725 | this._updated(); 1726 | }, 1727 | toArray: function () { 1728 | return this._items; 1729 | }, 1730 | _updated: function() { 1731 | var observers = this._observers; 1732 | if (observers) { 1733 | this._observers = null; 1734 | ss.Observable._invalidateObservers(observers); 1735 | } 1736 | } 1737 | } 1738 | ss.ObservableCollection.registerClass('ObservableCollection', null, ss.IEnumerable); 1739 | 1740 | ss.IApplication = function() { }; 1741 | ss.IApplication.registerInterface('IApplication'); 1742 | 1743 | ss.IContainer = function () { }; 1744 | ss.IContainer.registerInterface('IContainer'); 1745 | 1746 | ss.IObjectFactory = function () { }; 1747 | ss.IObjectFactory.registerInterface('IObjectFactory'); 1748 | 1749 | ss.IEventManager = function () { }; 1750 | ss.IEventManager.registerInterface('IEventManager'); 1751 | 1752 | ss.IInitializable = function () { }; 1753 | ss.IInitializable.registerInterface('IInitializable'); 1754 | --------------------------------------------------------------------------------