chore(playground): use base64-js from npm

closes #12471
This commit is contained in:
Joao Dias 2016-11-02 21:20:46 +01:00 committed by Victor Berchet
parent 3d9d839c6c
commit 44a142fc02
9 changed files with 95 additions and 225 deletions

View File

@ -63,7 +63,7 @@ if [[ ${BUILD_ALL} == true ]]; then
ln -s ../../../../node_modules/zone.js/dist/zone.js .
ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js .
ln -s ../../../../node_modules/systemjs/dist/system.src.js .
ln -s ../../../../node_modules/base64-js/lib/b64.js .
ln -s ../../../../node_modules/base64-js .
ln -s ../../../../node_modules/reflect-metadata/Reflect.js .
ln -s ../../../../node_modules/rxjs .
ln -s ../../../../node_modules/angular/angular.js .
@ -79,7 +79,6 @@ if [[ ${BUILD_ALL} == true ]]; then
ln -s ../../../../node_modules/zone.js/dist/zone.js .
ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js .
ln -s ../../../../node_modules/systemjs/dist/system.src.js .
ln -s ../../../../node_modules/base64-js/lib/b64.js .
ln -s ../../../../node_modules/reflect-metadata/Reflect.js .
ln -s ../../../../node_modules/rxjs .
ln -s ../../../../node_modules/angular/angular.js .

View File

@ -1,14 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
declare namespace base64js {
function fromByteArray(arr: Uint8Array): string;
function toByteArray(str: string): Uint8Array;
}
export = base64js;

View File

@ -1,125 +0,0 @@
// clang-format off
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
;(function (exports) {
'use strict';
var Arr = (typeof Uint8Array !== 'undefined')
? Uint8Array
: Array
var PLUS = '+'.charCodeAt(0)
var SLASH = '/'.charCodeAt(0)
var NUMBER = '0'.charCodeAt(0)
var LOWER = 'a'.charCodeAt(0)
var UPPER = 'A'.charCodeAt(0)
var PLUS_URL_SAFE = '-'.charCodeAt(0)
var SLASH_URL_SAFE = '_'.charCodeAt(0)
function decode (elt) {
var code = elt.charCodeAt(0)
if (code === PLUS ||
code === PLUS_URL_SAFE)
return 62 // '+'
if (code === SLASH ||
code === SLASH_URL_SAFE)
return 63 // '/'
if (code < NUMBER)
return -1 //no match
if (code < NUMBER + 10)
return code - NUMBER + 26 + 26
if (code < UPPER + 26)
return code - UPPER
if (code < LOWER + 26)
return code - LOWER + 26
}
function b64ToByteArray (b64) {
var i, j, l, tmp, placeHolders, arr
if (b64.length % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
var len = b64.length
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
// base64 is 4/3 + up to two characters of the original data
arr = new Arr(b64.length * 3 / 4 - placeHolders)
// if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? b64.length - 4 : b64.length
var L = 0
function push (v) {
arr[L++] = v
}
for (i = 0, j = 0; i < l; i += 4, j += 3) {
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
push((tmp & 0xFF0000) >> 16)
push((tmp & 0xFF00) >> 8)
push(tmp & 0xFF)
}
if (placeHolders === 2) {
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
push(tmp & 0xFF)
} else if (placeHolders === 1) {
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
push((tmp >> 8) & 0xFF)
push(tmp & 0xFF)
}
return arr
}
function uint8ToBase64 (uint8) {
var i,
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
output = "",
temp, length
function encode (num) {
return lookup.charAt(num)
}
function tripletToBase64 (num) {
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
}
// go through the array every three bytes, we'll deal with trailing stuff later
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
output += tripletToBase64(temp)
}
// pad the end with zeros, but make sure to not forget the extra bytes
switch (extraBytes) {
case 1:
temp = uint8[uint8.length - 1]
output += encode(temp >> 2)
output += encode((temp << 4) & 0x3F)
output += '=='
break
case 2:
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
output += encode(temp >> 10)
output += encode((temp >> 4) & 0x3F)
output += encode((temp << 2) & 0x3F)
output += '='
break
}
return output
}
exports.toByteArray = b64ToByteArray
exports.fromByteArray = uint8ToBase64
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))

View File

@ -9,13 +9,16 @@
importScripts(
'../../../vendor/core.js', '../../../vendor/zone.js',
'../../../vendor/long-stack-trace-zone.js', '../../../vendor/system.src.js',
'../../../vendor/Reflect.js', 'b64.js');
'../../../vendor/Reflect.js');
System.config({
baseURL: '/all',
map: {'rxjs': '/all/playground/vendor/rxjs'},
map: {
'rxjs': '/all/playground/vendor/rxjs',
'base64-js': '/all/playground/vendor/base64-js',
},
packages: {
'@angular/core': {main: 'index.js', defaultExtension: 'js'},
@ -27,6 +30,7 @@ System.config({
'@angular/platform-webworker-dynamic': {main: 'index.js', defaultExtension: 'js'},
'@angular/router': {main: 'index.js', defaultExtension: 'js'},
'rxjs': {defaultExtension: 'js'},
'base64-js': {main: 'index.js', defaultExtension: 'js'},
},
defaultJSExtensions: true

View File

@ -7,7 +7,7 @@
*/
import {Injectable} from '@angular/core';
import * as base64js from '../b64';
import {fromByteArray} from 'base64-js';
// This class is based on the Bitmap examples at:
// http://www.i-programmer.info/projects/36-web/6234-reading-a-bmp-file-in-javascript.html
@ -35,12 +35,12 @@ export class BitmapService {
toDataUri(imageData: ImageData): string {
const header = this._createBMPHeader(imageData);
imageData = this._imageDataToBMP(imageData);
return 'data:image/bmp;base64,' + btoa(header) + base64js.fromByteArray(imageData.data);
return 'data:image/bmp;base64,' + btoa(header) + fromByteArray(imageData.data);
}
// converts a .bmp file ArrayBuffer to a dataURI
arrayBufferToDataUri(data: Uint8Array): string {
return 'data:image/bmp;base64,' + base64js.fromByteArray(data);
return 'data:image/bmp;base64,' + fromByteArray(data);
}
// returns a UInt8Array in BMP order (starting from the bottom)

View File

@ -2,13 +2,12 @@
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="image_demo.css" />
<script type="text/javascript" src="b64.js"></script>
</head>
<body>
<image-demo>
</image-demo>
<script src="../bootstrap.js"></script>
<script src="../../bootstrap.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/css/materialize.min.css">

View File

@ -6,6 +6,10 @@
"version": "1.5.13-alpha",
"dev": true
},
"@types/base64-js": {
"version": "1.2.5",
"dev": true
},
"@types/fs-extra": {
"version": "0.0.22-alpha",
"dev": true
@ -205,7 +209,7 @@
"dev": true
},
"assert": {
"version": "1.3.0",
"version": "1.4.1",
"dev": true
},
"assert-plus": {
@ -249,7 +253,7 @@
"dev": true
},
"base64-js": {
"version": "0.0.8",
"version": "1.2.0",
"dev": true
},
"base64-url": {
@ -1801,7 +1805,7 @@
"dev": true
},
"buffer": {
"version": "3.6.0",
"version": "4.9.1",
"dev": true,
"dependencies": {
"isarray": {
@ -2153,6 +2157,10 @@
"version": "2.0.5",
"dev": true
},
"crypto-browserify": {
"version": "3.2.8",
"dev": true
},
"csrf": {
"version": "3.0.0",
"dev": true
@ -2405,7 +2413,7 @@
"dev": true
},
"events": {
"version": "1.0.2",
"version": "1.1.1",
"dev": true
},
"exit": {
@ -3556,6 +3564,10 @@
}
}
},
"https-browserify": {
"version": "0.0.0",
"dev": true
},
"https-proxy-agent": {
"version": "1.0.0",
"dev": true
@ -3565,7 +3577,7 @@
"dev": true
},
"ieee754": {
"version": "1.1.6",
"version": "1.1.8",
"dev": true
},
"incremental-dom": {
@ -4423,26 +4435,8 @@
"dev": true
},
"node-libs-browser": {
"version": "0.5.3",
"dev": true,
"dependencies": {
"crypto-browserify": {
"version": "3.2.8",
"dev": true
},
"https-browserify": {
"version": "0.0.0",
"dev": true
},
"ripemd160": {
"version": "0.2.0",
"dev": true
},
"sha.js": {
"version": "2.2.6",
"dev": true
}
}
"version": "0.6.0",
"dev": true
},
"node-source-walk": {
"version": "1.4.2",
@ -4651,7 +4645,7 @@
"dev": true
},
"process": {
"version": "0.11.2",
"version": "0.11.9",
"dev": true
},
"process-nextick-args": {
@ -4761,7 +4755,7 @@
}
},
"punycode": {
"version": "1.4.0",
"version": "1.4.1",
"dev": true
},
"q": {
@ -4981,6 +4975,10 @@
}
}
},
"ripemd160": {
"version": "0.2.0",
"dev": true
},
"rndm": {
"version": "1.1.1",
"dev": true
@ -5134,6 +5132,10 @@
"version": "1.0.4",
"dev": true
},
"sha.js": {
"version": "2.2.6",
"dev": true
},
"sigmund": {
"version": "1.0.1",
"dev": true

102
npm-shrinkwrap.json generated
View File

@ -8,6 +8,12 @@
"resolved": "https://registry.npmjs.org/@types/angularjs/-/angularjs-1.5.13-alpha.tgz",
"dev": true
},
"@types/base64-js": {
"version": "1.2.5",
"from": "@types/base64-js@latest",
"resolved": "https://registry.npmjs.org/@types/base64-js/-/base64-js-1.2.5.tgz",
"dev": true
},
"@types/fs-extra": {
"version": "0.0.22-alpha",
"from": "@types/fs-extra@latest",
@ -301,9 +307,9 @@
"dev": true
},
"assert": {
"version": "1.3.0",
"from": "assert@>=1.3.0 <1.4.0",
"resolved": "https://registry.npmjs.org/assert/-/assert-1.3.0.tgz",
"version": "1.4.1",
"from": "assert@>=1.1.1 <2.0.0",
"resolved": "https://registry.npmjs.org/assert/-/assert-1.4.1.tgz",
"dev": true
},
"assert-plus": {
@ -367,9 +373,9 @@
"dev": true
},
"base64-js": {
"version": "0.0.8",
"from": "base64-js@>=0.0.8 <0.0.9",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.8.tgz",
"version": "1.2.0",
"from": "base64-js@latest",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.0.tgz",
"dev": true
},
"base64-url": {
@ -2581,9 +2587,9 @@
"dev": true
},
"buffer": {
"version": "3.6.0",
"from": "buffer@>=3.0.0 <4.0.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-3.6.0.tgz",
"version": "4.9.1",
"from": "buffer@>=4.9.0 <5.0.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
"dev": true,
"dependencies": {
"isarray": {
@ -3099,6 +3105,12 @@
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz",
"dev": true
},
"crypto-browserify": {
"version": "3.2.8",
"from": "crypto-browserify@>=3.2.6 <3.3.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.2.8.tgz",
"dev": true
},
"csrf": {
"version": "3.0.0",
"from": "csrf@>=3.0.0 <3.1.0",
@ -3469,9 +3481,9 @@
"dev": true
},
"events": {
"version": "1.0.2",
"from": "events@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/events/-/events-1.0.2.tgz",
"version": "1.1.1",
"from": "events@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
"dev": true
},
"exit": {
@ -5162,6 +5174,12 @@
}
}
},
"https-browserify": {
"version": "0.0.0",
"from": "https-browserify@0.0.0",
"resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-0.0.0.tgz",
"dev": true
},
"https-proxy-agent": {
"version": "1.0.0",
"from": "https-proxy-agent@>=1.0.0 <2.0.0",
@ -5175,9 +5193,9 @@
"dev": true
},
"ieee754": {
"version": "1.1.6",
"version": "1.1.8",
"from": "ieee754@>=1.1.4 <2.0.0",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.6.tgz",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
"dev": true
},
"incremental-dom": {
@ -6433,36 +6451,10 @@
"dev": true
},
"node-libs-browser": {
"version": "0.5.3",
"from": "node-libs-browser@>=0.4.0 <=0.6.0",
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-0.5.3.tgz",
"dev": true,
"dependencies": {
"crypto-browserify": {
"version": "3.2.8",
"from": "crypto-browserify@>=3.2.6 <3.3.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.2.8.tgz",
"dev": true
},
"https-browserify": {
"version": "0.0.0",
"from": "https-browserify@0.0.0",
"resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-0.0.0.tgz",
"dev": true
},
"ripemd160": {
"version": "0.2.0",
"from": "ripemd160@0.2.0",
"resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-0.2.0.tgz",
"dev": true
},
"sha.js": {
"version": "2.2.6",
"from": "sha.js@2.2.6",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.2.6.tgz",
"dev": true
}
}
"version": "0.6.0",
"from": "node-libs-browser@0.6.0",
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-0.6.0.tgz",
"dev": true
},
"node-source-walk": {
"version": "1.4.2",
@ -6771,9 +6763,9 @@
"dev": true
},
"process": {
"version": "0.11.2",
"version": "0.11.9",
"from": "process@>=0.11.0 <0.12.0",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.2.tgz",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.9.tgz",
"dev": true
},
"process-nextick-args": {
@ -6933,9 +6925,9 @@
}
},
"punycode": {
"version": "1.4.0",
"from": "punycode@>=1.3.2 <2.0.0",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.0.tgz",
"version": "1.4.1",
"from": "punycode@>=1.2.4 <2.0.0",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"dev": true
},
"q": {
@ -7259,6 +7251,12 @@
}
}
},
"ripemd160": {
"version": "0.2.0",
"from": "ripemd160@0.2.0",
"resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-0.2.0.tgz",
"dev": true
},
"rndm": {
"version": "1.1.1",
"from": "rndm@>=1.1.0 <1.2.0",
@ -7484,6 +7482,12 @@
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.4.tgz",
"dev": true
},
"sha.js": {
"version": "2.2.6",
"from": "sha.js@2.2.6",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.2.6.tgz",
"dev": true
},
"sigmund": {
"version": "1.0.1",
"from": "sigmund@>=1.0.0 <1.1.0",

View File

@ -25,6 +25,7 @@
},
"devDependencies": {
"@types/angularjs": "^1.5.13-alpha",
"@types/base64-js": "^1.2.5",
"@types/fs-extra": "0.0.22-alpha",
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "^2.2.22-alpha",
@ -34,7 +35,7 @@
"angular": "^1.5.0",
"angular-animate": "^1.5.0",
"angular-mocks": "^1.5.0",
"base64-js": "^0.0.8",
"base64-js": "^1.2.0",
"bower": "^1.3.12",
"browserstacktunnel-wrapper": "^1.4.2",
"chokidar": "^1.1.0",