Commit f4df8017 authored by rockyl's avatar rockyl

init

parents
Pipeline #254544 failed with stages
in 0 seconds
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
/debug/
/dist/
{"id":"svga","url":"svga.bbb584f45f3ee647d0611653cb854c5d5bb8fb47.js"}
\ No newline at end of file
module.exports = {
region: 'oss-cn-hangzhou',
id: 'LTAI4Fw25WcfcGv7FvcHoiHK',
secret: 'NZk1NtT9J5HFaAolNbtQdzTzLLvLYm',
bucket: 'duiba',
output: '/editor/zeroing/libs'
};
{
"name": "renderingengine-svga",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5. 2.0",
"rollup-plugin-progress": "^1.1.1",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-uglify": "^6.0.4"
},
"dependencies": {
"protobufjs": "^6.8.8",
"tslib": "^1.10.0",
"typescript": "^3.7.3"
},
"scripts": {
"declare": "node scripts/declare.js src/svga/index.ts",
"rollup": "rollup -c -o dist/svga.js",
"rollup:prod": "rollup -c -o dist/svga.js --environment BUILD:production",
"rollup:debug": "rollup -c -m ",
"preprocess": "node scripts/pre-process.js svga dist/svga.js",
"build": "rm -rf dist&&yarn rollup:prod && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"build:debug": "rm -rf dist&&yarn rollup && yarn preprocess && ali-oss-publish -c oss.config.js -e dist"
}
}
/**
* Created by rockyl on 2018/11/16.
*/
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const progress = require('rollup-plugin-progress');
const typescript = require('rollup-plugin-typescript');
const {uglify} = require('rollup-plugin-uglify');
const options = {
input: 'src/index.ts',
output: [
{
file: `debug/engine-svga.js`,
format: 'umd',
name: 'svga',
globals: {
tslib: 'tslib'
},
}
],
plugins: [
progress(),
resolve({}),
typescript({
//useTsconfigDeclarationDir: true,
}),
commonjs(),
],
external: ['tslib'],
};
if(process.env.BUILD === 'production'){
options.plugins.push(uglify({}));
}
export default options;
/**
* Created by rockyl on 2020-01-11.
*/
const fs = require('fs');
const ts = require("typescript");
const regLine = /(export|declare)((?!from).)*/g;
function compile(fileNames, options) {
const host = ts.createCompilerHost(options);
const exports = [];
host.writeFile = (fileName, fileContent) => {
console.log(fileName);
const result = fileContent.match(regLine);
for (let line of result) {
if(line.match(/export (default)? \w+;/)){
continue;
}
if(line.endsWith(';')){
if(!line.startsWith('_') && !line.startsWith('export default function')){
exports.push(line);
}
}else {
if(line.endsWith('{')){
let start = fileContent.indexOf(line);
const block = fileContent.substring(start, fileContent.indexOf('\n}', start) + 2);
if(!block.startsWith('_')){
exports.push(block);
}
}
}
}
};
const program = ts.createProgram(fileNames, options, host);
program.emit();
let allExports = exports.join('\n\n')
.replace(/export default _default;/g, '')
.replace(/export declare/g, 'export ')
.replace(/export default/g, 'export ')
.replace(/declare /g, 'export ')
;
const content = `
declare module svga{
${allExports}
}
`;
fs.writeFileSync('debug/svga.d.ts', content);
}
compile(process.argv.slice(2), {
allowJs: true,
declaration: true,
emitDeclarationOnly: true,
});
/**
* Created by rockyl on 2019-11-22.
*/
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const [_, __, id, fileName] = process.argv;
const stream = fs.createReadStream(fileName);
const fsHash = crypto.createHash('sha1');
stream.on('data', function (d) {
fsHash.update(d);
});
stream.on('end', function () {
const md5 = fsHash.digest('hex');
loadComplete(md5);
});
function loadComplete(md5) {
const extIndex = fileName.lastIndexOf('.');
const newFileName = fileName.substr(0, extIndex + 1) + md5 + fileName.substr(extIndex);
fs.renameSync(fileName, newFileName);
let manifest = {
id,
url: path.basename(newFileName),
};
fs.writeFileSync('manifest.json', JSON.stringify(manifest));
}
export * from "./svga/index";
\ No newline at end of file
This diff is collapsed.
import {SpriteEntity} from './spriteEntity'
import {ProtoMovieEntity} from "./proto";
const {HashObject} = engine;
export class VideoEntity extends HashObject {
/**
* SVGA 文件版本
*/
version = "";
/**
* 影片尺寸
*/
videoSize = {
width: 0.0,
height: 0.0,
};
/**
* 帧率
*/
FPS = 20;
/**
* 帧数
*/
frames = 0;
/**
* Bitmaps
*/
images = {};
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached: boolean = false;
/**
* SpriteEntity[]
*/
sprites: SpriteEntity[] = []
/**
* AudioEntity[]
*/
audios = []
constructor(spec, images) {
super();
this._instanceType = "VideoEntity";
if (typeof spec === "object" && spec.$type == ProtoMovieEntity) {
if (typeof spec.params === "object") {
this.version = spec.ver;
this.videoSize.width = spec.params.viewBoxWidth || 0.0;
this.videoSize.height = spec.params.viewBoxHeight || 0.0;
this.FPS = spec.params.fps || 20;
this.frames = spec.params.frames || 0;
}
this.resetSprites(spec)
this.audios = spec.audios
} else if (spec) {
if (spec.movie) {
if (spec.movie.viewBox) {
this.videoSize.width = parseFloat(spec.movie.viewBox.width) || 0.0;
this.videoSize.height = parseFloat(spec.movie.viewBox.height) || 0.0;
}
this.version = spec.ver;
this.FPS = parseInt(spec.movie.fps) || 20;
this.frames = parseInt(spec.movie.frames) || 0;
}
this.resetSprites(spec)
}
if (images) {
this.images = images
}
}
resetSprites(spec) {
if (spec.sprites instanceof Array) {
this.sprites = spec.sprites.map((obj) => {
return new SpriteEntity(obj)
})
}
}
destroy() {
}
}
\ No newline at end of file
export class BezierPath {
_d;
_transform;
_styles;
_shape;
constructor(d?, transform?, styles?) {
this._d = d;
this._transform = transform;
this._styles = styles;
}
}
\ No newline at end of file
import {BezierPath} from './bezierPath'
export class EllipsePath extends BezierPath {
_x;
_y;
_radiusX;
_radiusY;
_transform;
_styles;
constructor(x, y, radiusX, radiusY, transform, styles) {
super();
this._x = x;
this._y = y;
this._radiusX = radiusX;
this._radiusY = radiusY;
this._transform = transform;
this._styles = styles;
}
}
\ No newline at end of file
import {BezierPath} from './bezierPath'
export class FrameEntity {
alpha = 0.0;
transform = {
a: 1.0,
b: 0.0,
c: 0.0,
d: 1.0,
tx: 0.0,
ty: 0.0,
};
layout = {
x: 0.0,
y: 0.0,
width: 0.0,
height: 0.0,
}
nx = 0.0;
ny = 0.0;
/**
* BezierPath
*/
maskPath = null;
/**
* Object[]
*/
shapes = [];
constructor(spec) {
this.alpha = parseFloat(spec.alpha) || 0.0;
if (spec.layout) {
this.layout.x = parseFloat(spec.layout.x) || 0.0;
this.layout.y = parseFloat(spec.layout.y) || 0.0;
this.layout.width = parseFloat(spec.layout.width) || 0.0;
this.layout.height = parseFloat(spec.layout.height) || 0.0;
}
if (spec.transform) {
this.transform.a = parseFloat(spec.transform.a) || 1.0;
this.transform.b = parseFloat(spec.transform.b) || 0.0;
this.transform.c = parseFloat(spec.transform.c) || 0.0;
this.transform.d = parseFloat(spec.transform.d) || 1.0;
this.transform.tx = parseFloat(spec.transform.tx) || 0.0;
this.transform.ty = parseFloat(spec.transform.ty) || 0.0;
}
if (spec.clipPath && spec.clipPath.length > 0) {
this.maskPath = new BezierPath(spec.clipPath, undefined, {fill: "#000000"});
}
if (spec.shapes) {
if (spec.shapes instanceof Array) {
spec.shapes.forEach(shape => {
shape.pathArgs = shape.args;
switch (shape.type) {
case 0:
shape.type = "shape";
shape.pathArgs = shape.shape;
break;
case 1:
shape.type = "rect";
shape.pathArgs = shape.rect;
break;
case 2:
shape.type = "ellipse";
shape.pathArgs = shape.ellipse;
break;
case 3:
shape.type = "keep";
break;
}
if (shape.styles) {
if (shape.styles.fill) {
if (typeof shape.styles.fill["r"] === "number") shape.styles.fill[0] = shape.styles.fill["r"];
if (typeof shape.styles.fill["g"] === "number") shape.styles.fill[1] = shape.styles.fill["g"];
if (typeof shape.styles.fill["b"] === "number") shape.styles.fill[2] = shape.styles.fill["b"];
if (typeof shape.styles.fill["a"] === "number") shape.styles.fill[3] = shape.styles.fill["a"];
}
if (shape.styles.stroke) {
if (typeof shape.styles.stroke["r"] === "number") shape.styles.stroke[0] = shape.styles.stroke["r"];
if (typeof shape.styles.stroke["g"] === "number") shape.styles.stroke[1] = shape.styles.stroke["g"];
if (typeof shape.styles.stroke["b"] === "number") shape.styles.stroke[2] = shape.styles.stroke["b"];
if (typeof shape.styles.stroke["a"] === "number") shape.styles.stroke[3] = shape.styles.stroke["a"];
}
let lineDash = shape.styles.lineDash || []
if (shape.styles.lineDashI > 0) {
lineDash.push(shape.styles.lineDashI)
}
if (shape.styles.lineDashII > 0) {
if (lineDash.length < 1) {
lineDash.push(0)
}
lineDash.push(shape.styles.lineDashII)
lineDash.push(0)
}
if (shape.styles.lineDashIII > 0) {
if (lineDash.length < 2) {
lineDash.push(0);
lineDash.push(0);
}
lineDash[2] = shape.styles.lineDashIII
}
shape.styles.lineDash = lineDash
switch (shape.styles.lineJoin) {
case 0:
shape.styles.lineJoin = "miter";
break;
case 1:
shape.styles.lineJoin = "round";
break;
case 2:
shape.styles.lineJoin = "bevel";
break;
}
switch (shape.styles.lineCap) {
case 0:
shape.styles.lineCap = "butt";
break;
case 1:
shape.styles.lineCap = "round";
break;
case 2:
shape.styles.lineCap = "square";
break;
}
}
})
}
if (spec.shapes[0] && spec.shapes[0].type === "keep") {
this.shapes = FrameEntity.lastShapes;
} else {
this.shapes = spec.shapes
FrameEntity.lastShapes = spec.shapes;
}
}
let llx = this.transform.a * this.layout.x + this.transform.c * this.layout.y + this.transform.tx;
let lrx = this.transform.a * (this.layout.x + this.layout.width) + this.transform.c * this.layout.y + this.transform.tx;
let lbx = this.transform.a * this.layout.x + this.transform.c * (this.layout.y + this.layout.height) + this.transform.tx;
let rbx = this.transform.a * (this.layout.x + this.layout.width) + this.transform.c * (this.layout.y + this.layout.height) + this.transform.tx;
let lly = this.transform.b * this.layout.x + this.transform.d * this.layout.y + this.transform.ty;
let lry = this.transform.b * (this.layout.x + this.layout.width) + this.transform.d * this.layout.y + this.transform.ty;
let lby = this.transform.b * this.layout.x + this.transform.d * (this.layout.y + this.layout.height) + this.transform.ty;
let rby = this.transform.b * (this.layout.x + this.layout.width) + this.transform.d * (this.layout.y + this.layout.height) + this.transform.ty;
this.nx = Math.min(Math.min(lbx, rbx), Math.min(llx, lrx));
this.ny = Math.min(Math.min(lby, rby), Math.min(lly, lry));
}
static lastShapes
}
\ No newline at end of file
export {VideoEntity} from "./VideoEntity";
export {Parser} from "./parser";
export {MovieClip} from "./MovieClip";
export * from "./svga-wrapper";
import './svga-wrapper'
/**
* 删除了很多东西,需要webgl3d项目中看
*/
import {ProtoMovieEntity} from "./proto";
import {utils} from './pako/utils/common';
import inflate from "./pako/inflate";
const pako = {}
utils.assign(pako, inflate);
const Uint8ToString = function (u8a) {
var CHUNK_SZ = 0x8000;
var c = [];
for (var i = 0; i < u8a.length; i += CHUNK_SZ) {
c.push(String.fromCharCode.apply(null, u8a.subarray(i, i + CHUNK_SZ)));
}
return c.join("");
}
const actions = {
loadAssets: (url, cb, failure) => {
const req = new XMLHttpRequest()
req.open("GET", url, true);
req.responseType = "arraybuffer"
req.onloadend = () => {
actions.load_viaProto(req.response, cb, failure);
}
req.send()
},
load_viaProto: (arraybuffer, cb, failure) => {
try {
const inflatedData = pako["inflate"](arraybuffer);
const movieData = ProtoMovieEntity.decode(inflatedData);
let images = {};
actions._loadImages(images, undefined, movieData, function () {
movieData["ver"] = "2.0";
cb({
movie: movieData,
images,
})
})
} catch (err) {
failure && failure(err);
console.error(err);
throw err;
}
},
_loadImages: function (images, zip, movieData, imagesLoadedBlock) {
if (typeof movieData === "object" && movieData.$type == ProtoMovieEntity) {
var finished = true;
if (!zip) {
for (const key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) {
const element = movieData.images[key];
const value = Uint8ToString(element);
images[key] = btoa(value)
}
}
} else {
for (const key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) {
const element = movieData.images[key];
const value = Uint8ToString(element);
if (images.hasOwnProperty(key)) {
continue;
}
finished = false;
zip.file(value + ".png").async("base64").then(function (data) {
images[key] = data;
actions._loadImages(images, zip, movieData, imagesLoadedBlock);
}.bind(this))
break;
}
}
}
finished && imagesLoadedBlock.call(this)
} else {
var finished = true;
for (var key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) {
var element = movieData.images[key];
if (images.hasOwnProperty(key)) {
continue;
}
finished = false;
zip.file(element + ".png").async("base64").then(function (data) {
images[key] = data;
actions._loadImages(images, zip, movieData, imagesLoadedBlock);
}.bind(this))
break;
}
}
finished && imagesLoadedBlock.call(this)
}
},
}
export default (data, cb, failure) => {
actions['loadAssets'](data, cb, failure);
}
This diff is collapsed.
'use strict';
var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
(typeof Uint16Array !== 'undefined') &&
(typeof Int32Array !== 'undefined');
function _has(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
function assign(obj, objO) {
// var sources = Array.prototype.slice.call(arguments, 1);
// while (sources.length) {
// var source = sources.shift();
// if (!source) { continue; }
// if (typeof source !== 'object') {
// throw new TypeError(source + 'must be non-object');
// }
// for (var p in source) {
// if (_has(source, p)) {
// obj[p] = source[p];
// }
// }
// }
for (var p in objO) {
if (_has(objO, p)) {
obj[p] = objO[p];
}
}
return obj;
};
// reduce buffer size, avoiding mem copy
function shrinkBuf(buf, size) {
if (buf.length === size) {
return buf;
}
if (buf.subarray) {
return buf.subarray(0, size);
}
buf.length = size;
return buf;
};
var fnTyped = {
arraySet: function (dest, src, src_offs, len, dest_offs) {
if (src.subarray && dest.subarray) {
dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
return;
}
// Fallback to ordinary array
for (var i = 0; i < len; i++) {
dest[dest_offs + i] = src[src_offs + i];
}
},
// Join array of chunks to single array.
flattenChunks: function (chunks) {
var i, l, len, pos, chunk, result;
// calculate data length
len = 0;
for (i = 0, l = chunks.length; i < l; i++) {
len += chunks[i].length;
}
// join chunks
result = new Uint8Array(len);
pos = 0;
for (i = 0, l = chunks.length; i < l; i++) {
chunk = chunks[i];
result.set(chunk, pos);
pos += chunk.length;
}
return result;
}
};
var fnUntyped = {
arraySet: function (dest, src, src_offs, len, dest_offs) {
for (var i = 0; i < len; i++) {
dest[dest_offs + i] = src[src_offs + i];
}
},
// Join array of chunks to single array.
flattenChunks: function (chunks) {
return [].concat.apply([], chunks);
}
};
// Enable/Disable typed arrays use, for testing
let Buf8, Buf16, Buf32, arraySet, flattenChunks
if (TYPED_OK) {
Buf8 = Uint8Array;
Buf16 = Uint16Array;
Buf32 = Int32Array;
arraySet = fnTyped.arraySet;
flattenChunks = fnTyped.flattenChunks
} else {
Buf8 = Array;
Buf16 = Array;
Buf32 = Array;
arraySet = fnUntyped.arraySet;
flattenChunks = fnUntyped.flattenChunks
}
export const utils = {
assign,
shrinkBuf,
Buf8,
Buf16,
Buf32,
arraySet,
flattenChunks
};
// String encode/decode helpers
'use strict';
import {utils} from "./common"
// Quick check if we can use fast array to bin string conversion
//
// - apply(Array) can fail on Android 2.2
// - apply(Uint8Array) can fail on iOS 5.1 Safari
//
var STR_APPLY_OK = true;
var STR_APPLY_UIA_OK = true;
try {
String.fromCharCode.apply(null, [0]);
} catch (__) {
STR_APPLY_OK = false;
}
try {
String.fromCharCode.apply(null, new Uint8Array(1));
} catch (__) {
STR_APPLY_UIA_OK = false;
}
// Table with utf8 lengths (calculated by first byte of sequence)
// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
// because max possible codepoint is 0x10ffff
var _utf8len = new utils.Buf8(256);
for (var q = 0; q < 256; q++) {
_utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
}
_utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
// convert string to array (typed, when possible)
function string2buf(str) {
var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
// count binary size
for (m_pos = 0; m_pos < str_len; m_pos++) {
c = str.charCodeAt(m_pos);
if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
c2 = str.charCodeAt(m_pos + 1);
if ((c2 & 0xfc00) === 0xdc00) {
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
m_pos++;
}
}
buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
}
// allocate buffer
buf = new utils.Buf8(buf_len);
// convert
for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
c = str.charCodeAt(m_pos);
if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
c2 = str.charCodeAt(m_pos + 1);
if ((c2 & 0xfc00) === 0xdc00) {
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
m_pos++;
}
}
if (c < 0x80) {
/* one byte */
buf[i++] = c;
} else if (c < 0x800) {
/* two bytes */
buf[i++] = 0xC0 | (c >>> 6);
buf[i++] = 0x80 | (c & 0x3f);
} else if (c < 0x10000) {
/* three bytes */
buf[i++] = 0xE0 | (c >>> 12);
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
buf[i++] = 0x80 | (c & 0x3f);
} else {
/* four bytes */
buf[i++] = 0xf0 | (c >>> 18);
buf[i++] = 0x80 | (c >>> 12 & 0x3f);
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
buf[i++] = 0x80 | (c & 0x3f);
}
}
return buf;
};
// Helper (used in 2 places)
function buf2binstring(buf, len?) {
// On Chrome, the arguments in a function call that are allowed is `65534`.
// If the length of the buffer is smaller than that, we can use this optimization,
// otherwise we will take a slower path.
len = len || buf.length;
if (len < 65534) {
if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
}
}
var result = '';
for (var i = 0; i < len; i++) {
result += String.fromCharCode(buf[i]);
}
return result;
}
// Convert binary string (typed, when possible)
function binstring2buf(str) {
var buf = new utils.Buf8(str.length);
for (var i = 0, len = buf.length; i < len; i++) {
buf[i] = str.charCodeAt(i);
}
return buf;
};
// convert array to string
function buf2string(buf, max) {
var i, out, c, c_len;
var len = max || buf.length;
// Reserve max possible length (2 words per char)
// NB: by unknown reasons, Array is significantly faster for
// String.fromCharCode.apply than Uint16Array.
var utf16buf = new Array(len * 2);
for (out = 0, i = 0; i < len;) {
c = buf[i++];
// quick process ascii
if (c < 0x80) {
utf16buf[out++] = c;
continue;
}
c_len = _utf8len[c];
// skip 5 & 6 byte codes
if (c_len > 4) {
utf16buf[out++] = 0xfffd;
i += c_len - 1;
continue;
}
// apply mask on first byte
c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
// join the rest
while (c_len > 1 && i < len) {
c = (c << 6) | (buf[i++] & 0x3f);
c_len--;
}
// terminated by end of string?
if (c_len > 1) {
utf16buf[out++] = 0xfffd;
continue;
}
if (c < 0x10000) {
utf16buf[out++] = c;
} else {
c -= 0x10000;
utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
utf16buf[out++] = 0xdc00 | (c & 0x3ff);
}
}
return buf2binstring(utf16buf, out);
};
// Calculate max possible position in utf8 buffer,
// that will not break sequence. If that's not possible
// - (very small limits) return max size as is.
//
// buf[] - utf8 bytes array
// max - length limit (mandatory);
function utf8border(buf, max) {
var pos;
max = max || buf.length;
if (max > buf.length) {
max = buf.length;
}
// go back from last position, until start of sequence found
pos = max - 1;
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
pos--;
}
// Very small and broken sequence,
// return max, because we should return something anyway.
if (pos < 0) {
return max;
}
// If we came to start of buffer - that means buffer is too small,
// return max too.
if (pos === 0) {
return max;
}
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
};
export const strings = {
utf8border,
buf2string,
binstring2buf,
buf2binstring,
string2buf
}
'use strict';
// Note: adler32 takes 12% for level 0 and 2% for level 6.
// It isn't worth it to make additional optimizations as in original.
// Small size is preferable.
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
function adler32(adler, buf, len, pos) {
var s1 = (adler & 0xffff) | 0,
s2 = ((adler >>> 16) & 0xffff) | 0,
n = 0;
while (len !== 0) {
// Set limit ~ twice less than 5552, to keep
// s2 in 31-bits, because we force signed ints.
// in other case %= will fail.
n = len > 2000 ? 2000 : len;
len -= n;
do {
s1 = (s1 + buf[pos++]) | 0;
s2 = (s2 + s1) | 0;
} while (--n);
s1 %= 65521;
s2 %= 65521;
}
return (s1 | (s2 << 16)) | 0;
}
export default adler32;
'use strict';
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
export default {
/* Allowed flush values; see deflate() and inflate() below for details */
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_TREES: 6,
/* Return codes for the compression/decompression functions. Negative values
* are errors, positive values are used for special but normal events.
*/
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
//Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
//Z_VERSION_ERROR: -6,
/* compression levels */
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
/* Possible values of the data_type field (though see inflate()) */
Z_BINARY: 0,
Z_TEXT: 1,
//Z_ASCII: 1, // = Z_TEXT (deprecated)
Z_UNKNOWN: 2,
/* The deflate compression method */
Z_DEFLATED: 8
//Z_NULL: null // Use -1 or null inline, depending on var type
};
'use strict';
// Note: we can't get significant speed boost here.
// So write code to minimize size - no pregenerated tables
// and array tools dependencies.
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
// Use ordinary array, since untyped makes no boost here
function makeTable() {
var c, table = [];
for (var n = 0; n < 256; n++) {
c = n;
for (var k = 0; k < 8; k++) {
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
table[n] = c;
}
return table;
}
// Create table on load. Just 255 signed longs. Not a problem.
var crcTable = makeTable();
function crc32(crc, buf, len, pos) {
var t = crcTable,
end = pos + len;
crc ^= -1;
for (var i = pos; i < end; i++) {
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
}
return (crc ^ (-1)); // >>> 0;
}
export default crc32;
This diff is collapsed.
'use strict';
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
function GZheader() {
/* true if compressed data believed to be text */
this.text = 0;
/* modification time */
this.time = 0;
/* extra flags (not used when writing a gzip file) */
this.xflags = 0;
/* operating system */
this.os = 0;
/* pointer to extra field or Z_NULL if none */
this.extra = null;
/* extra field length (valid if extra != Z_NULL) */
this.extra_len = 0; // Actually, we don't need it in JS,
// but leave for few code modifications
//
// Setup limits is not necessary because in js we should not preallocate memory
// for inflate use constant limit in 65536 bytes
//
/* space at extra (only when reading header) */
// this.extra_max = 0;
/* pointer to zero-terminated file name or Z_NULL */
this.name = '';
/* space at name (only when reading header) */
// this.name_max = 0;
/* pointer to zero-terminated comment or Z_NULL */
this.comment = '';
/* space at comment (only when reading header) */
// this.comm_max = 0;
/* true if there was or will be a header crc */
this.hcrc = 0;
/* true when done reading gzip header (not used when writing a gzip file) */
this.done = false;
}
export default GZheader;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// import * as protobuf from "protobufjs/light";
import protobuf from "./protobuf"
// import * as protobuf from "./protobufjs/light";
const svgaDescriptor = JSON.parse(`{"nested":{"com":{"nested":{"opensource":{"nested":{"svga":{"options":{"objc_class_prefix":"SVGAProto","java_package":"com.opensource.svgaplayer.proto"},"nested":{"MovieParams":{"fields":{"viewBoxWidth":{"type":"float","id":1},"viewBoxHeight":{"type":"float","id":2},"fps":{"type":"int32","id":3},"frames":{"type":"int32","id":4}}},"SpriteEntity":{"fields":{"imageKey":{"type":"string","id":1},"frames":{"rule":"repeated","type":"FrameEntity","id":2},"matteKey":{"type":"string","id":3}}},"AudioEntity":{"fields":{"audioKey":{"type":"string","id":1},"startFrame":{"type":"int32","id":2},"endFrame":{"type":"int32","id":3},"startTime":{"type":"int32","id":4},"totalTime":{"type":"int32","id":5}}},"Layout":{"fields":{"x":{"type":"float","id":1},"y":{"type":"float","id":2},"width":{"type":"float","id":3},"height":{"type":"float","id":4}}},"Transform":{"fields":{"a":{"type":"float","id":1},"b":{"type":"float","id":2},"c":{"type":"float","id":3},"d":{"type":"float","id":4},"tx":{"type":"float","id":5},"ty":{"type":"float","id":6}}},"ShapeEntity":{"oneofs":{"args":{"oneof":["shape","rect","ellipse"]}},"fields":{"type":{"type":"ShapeType","id":1},"shape":{"type":"ShapeArgs","id":2},"rect":{"type":"RectArgs","id":3},"ellipse":{"type":"EllipseArgs","id":4},"styles":{"type":"ShapeStyle","id":10},"transform":{"type":"Transform","id":11}},"nested":{"ShapeType":{"values":{"SHAPE":0,"RECT":1,"ELLIPSE":2,"KEEP":3}},"ShapeArgs":{"fields":{"d":{"type":"string","id":1}}},"RectArgs":{"fields":{"x":{"type":"float","id":1},"y":{"type":"float","id":2},"width":{"type":"float","id":3},"height":{"type":"float","id":4},"cornerRadius":{"type":"float","id":5}}},"EllipseArgs":{"fields":{"x":{"type":"float","id":1},"y":{"type":"float","id":2},"radiusX":{"type":"float","id":3},"radiusY":{"type":"float","id":4}}},"ShapeStyle":{"fields":{"fill":{"type":"RGBAColor","id":1},"stroke":{"type":"RGBAColor","id":2},"strokeWidth":{"type":"float","id":3},"lineCap":{"type":"LineCap","id":4},"lineJoin":{"type":"LineJoin","id":5},"miterLimit":{"type":"float","id":6},"lineDashI":{"type":"float","id":7},"lineDashII":{"type":"float","id":8},"lineDashIII":{"type":"float","id":9}},"nested":{"RGBAColor":{"fields":{"r":{"type":"float","id":1},"g":{"type":"float","id":2},"b":{"type":"float","id":3},"a":{"type":"float","id":4}}},"LineCap":{"values":{"LineCap_BUTT":0,"LineCap_ROUND":1,"LineCap_SQUARE":2}},"LineJoin":{"values":{"LineJoin_MITER":0,"LineJoin_ROUND":1,"LineJoin_BEVEL":2}}}}}},"FrameEntity":{"fields":{"alpha":{"type":"float","id":1},"layout":{"type":"Layout","id":2},"transform":{"type":"Transform","id":3},"clipPath":{"type":"string","id":4},"shapes":{"rule":"repeated","type":"ShapeEntity","id":5}}},"MovieEntity":{"fields":{"version":{"type":"string","id":1},"params":{"type":"MovieParams","id":2},"images":{"keyType":"string","type":"bytes","id":3},"sprites":{"rule":"repeated","type":"SpriteEntity","id":4},"audios":{"rule":"repeated","type":"AudioEntity","id":5}}}}}}}}}}}`)
export const proto = protobuf.Root.fromJSON(svgaDescriptor);
export const ProtoMovieEntity = proto.lookupType("com.opensource.svga.MovieEntity");
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment