Skip to content

Commit

Permalink
Merge pull request #241 from karasjs/performance
Browse files Browse the repository at this point in the history
Performance
  • Loading branch information
army8735 authored Aug 3, 2022
2 parents a659fff + 1398607 commit 6186d37
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 69 deletions.
75 changes: 52 additions & 23 deletions index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,29 @@ var STYLE_KEY$5 = {
var STYLE2LOWER_MAP = {};

function style2Lower(s) {
STYLE2LOWER_MAP[s] = STYLE2LOWER_MAP[s] || s.toLowerCase().replace(/_([a-z])/g, function ($0, $1) {
return $1.toUpperCase();
});
return STYLE2LOWER_MAP[s];
var res = STYLE2LOWER_MAP[s];

if (!res) {
res = STYLE2LOWER_MAP[s] = s.toLowerCase().replace(/_([a-z])/g, function ($0, $1) {
return $1.toUpperCase();
});
}

return res;
}

var STYLE2UPPER_MAP = {};

function style2Upper$2(s) {
STYLE2UPPER_MAP[s] = STYLE2UPPER_MAP[s] || s.replace(/([a-z\d_])([A-Z])/g, function ($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();
return STYLE2UPPER_MAP[s];
var res = STYLE2UPPER_MAP[s];

if (!res) {
res = STYLE2UPPER_MAP[s] = s.replace(/([a-z\d_])([A-Z])/g, function ($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();
}

return res;
}

var STYLE_R_KEY = {};
Expand Down Expand Up @@ -1141,17 +1151,26 @@ function rgba2int$3(color) {

function int2rgba$4(color) {
if (Array.isArray(color)) {
if (color.length === 4) {
color = color.map(function (c, i) {
return i === 3 ? c : Math.floor(Math.max(0, c));
});
return 'rgba(' + joinArr$3(color, ',') + ')';
} else if (color.length === 3) {
color = color.map(function (c) {
return Math.floor(c);
});
return 'rgba(' + joinArr$3(color, ',') + ',1)';
}
if (color.length === 3 || color.length === 4) {
color[0] = Math.floor(Math.max(color[0], 0));
color[1] = Math.floor(Math.max(color[1], 0));
color[2] = Math.floor(Math.max(color[2], 0));

if (color.length === 4) {
color[3] = Math.max(color[3], 0);
return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',' + color[3] + ')';
}

return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',1)';
} // if(color.length === 4) {
// color = color.map((c, i) => i === 3 ? c : Math.floor(Math.max(0, c)));
// return 'rgba(' + joinArr(color, ',') + ')';
// }
// else if(color.length === 3) {
// color = color.map(c => Math.floor(c));
// return 'rgba(' + joinArr(color, ',') + ',1)';
// }

}

return color || 'rgba(0,0,0,0)';
Expand Down Expand Up @@ -14992,7 +15011,7 @@ var ENUM = {
REBUILD: 1024 // 10000000000

};
var TRANSFORMS = (_TRANSFORMS = {}, _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_3D, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM_ORIGIN, true), _TRANSFORMS);
var TRANSFORMS = (_TRANSFORMS = {}, _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_3D, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM_ORIGIN, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSLATE_PATH, true), _TRANSFORMS);
var o$1 = Object.assign({
contain: function contain(lv, value) {
return (lv & value) > 0;
Expand Down Expand Up @@ -32414,8 +32433,18 @@ var Controller = /*#__PURE__*/function () {
if (list2.length && onList.length) {
list2.forEach(function (item) {
onList.forEach(function (arr) {
var cb = function cb() {
var time = item.timestamp;

if (time !== _this.__lastTime[arr[0]]) {
_this.__lastTime[arr[0]] = time;
arr[1] && arr[1]();
}
};

cb.__karasEventCb = arr[1];
item.off(arr[0], arr[1]);
item.on(arr[0], arr[1]);
item.on(arr[0], cb);
});
});
}
Expand Down Expand Up @@ -32591,7 +32620,7 @@ var Controller = /*#__PURE__*/function () {

if (time !== _this2.__lastTime[id]) {
_this2.__lastTime[id] = time;
handle();
handle && handle();
}
};

Expand Down Expand Up @@ -41889,7 +41918,7 @@ var refresh = {
Cache: Cache
};

var version = "0.78.1";
var version = "0.78.2";

Geom.register('$line', Line);
Geom.register('$polyline', Polyline);
Expand Down
2 changes: 1 addition & 1 deletion index.es.js.map

Large diffs are not rendered by default.

75 changes: 52 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,29 @@
var STYLE2LOWER_MAP = {};

function style2Lower(s) {
STYLE2LOWER_MAP[s] = STYLE2LOWER_MAP[s] || s.toLowerCase().replace(/_([a-z])/g, function ($0, $1) {
return $1.toUpperCase();
});
return STYLE2LOWER_MAP[s];
var res = STYLE2LOWER_MAP[s];

if (!res) {
res = STYLE2LOWER_MAP[s] = s.toLowerCase().replace(/_([a-z])/g, function ($0, $1) {
return $1.toUpperCase();
});
}

return res;
}

var STYLE2UPPER_MAP = {};

function style2Upper$2(s) {
STYLE2UPPER_MAP[s] = STYLE2UPPER_MAP[s] || s.replace(/([a-z\d_])([A-Z])/g, function ($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();
return STYLE2UPPER_MAP[s];
var res = STYLE2UPPER_MAP[s];

if (!res) {
res = STYLE2UPPER_MAP[s] = s.replace(/([a-z\d_])([A-Z])/g, function ($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();
}

return res;
}

var STYLE_R_KEY = {};
Expand Down Expand Up @@ -1147,17 +1157,26 @@

function int2rgba$4(color) {
if (Array.isArray(color)) {
if (color.length === 4) {
color = color.map(function (c, i) {
return i === 3 ? c : Math.floor(Math.max(0, c));
});
return 'rgba(' + joinArr$3(color, ',') + ')';
} else if (color.length === 3) {
color = color.map(function (c) {
return Math.floor(c);
});
return 'rgba(' + joinArr$3(color, ',') + ',1)';
}
if (color.length === 3 || color.length === 4) {
color[0] = Math.floor(Math.max(color[0], 0));
color[1] = Math.floor(Math.max(color[1], 0));
color[2] = Math.floor(Math.max(color[2], 0));

if (color.length === 4) {
color[3] = Math.max(color[3], 0);
return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',' + color[3] + ')';
}

return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',1)';
} // if(color.length === 4) {
// color = color.map((c, i) => i === 3 ? c : Math.floor(Math.max(0, c)));
// return 'rgba(' + joinArr(color, ',') + ')';
// }
// else if(color.length === 3) {
// color = color.map(c => Math.floor(c));
// return 'rgba(' + joinArr(color, ',') + ',1)';
// }

}

return color || 'rgba(0,0,0,0)';
Expand Down Expand Up @@ -14998,7 +15017,7 @@
REBUILD: 1024 // 10000000000

};
var TRANSFORMS = (_TRANSFORMS = {}, _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_3D, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM_ORIGIN, true), _TRANSFORMS);
var TRANSFORMS = (_TRANSFORMS = {}, _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SCALE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_Z, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_X, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.SKEW_Y, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.ROTATE_3D, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSFORM_ORIGIN, true), _defineProperty(_TRANSFORMS, STYLE_KEY$1.TRANSLATE_PATH, true), _TRANSFORMS);
var o$1 = Object.assign({
contain: function contain(lv, value) {
return (lv & value) > 0;
Expand Down Expand Up @@ -32420,8 +32439,18 @@
if (list2.length && onList.length) {
list2.forEach(function (item) {
onList.forEach(function (arr) {
var cb = function cb() {
var time = item.timestamp;

if (time !== _this.__lastTime[arr[0]]) {
_this.__lastTime[arr[0]] = time;
arr[1] && arr[1]();
}
};

cb.__karasEventCb = arr[1];
item.off(arr[0], arr[1]);
item.on(arr[0], arr[1]);
item.on(arr[0], cb);
});
});
}
Expand Down Expand Up @@ -32597,7 +32626,7 @@

if (time !== _this2.__lastTime[id]) {
_this2.__lastTime[id] = time;
handle();
handle && handle();
}
};

Expand Down Expand Up @@ -41895,7 +41924,7 @@
Cache: Cache
};

var version = "0.78.1";
var version = "0.78.2";

Geom.register('$line', Line);
Geom.register('$polyline', Polyline);
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karas",
"version": "0.78.1",
"version": "0.78.2",
"description": "A flexible JavaScript framework for RIA on Canvas/Svg/Webgl.",
"maintainers": [
{
Expand Down
12 changes: 10 additions & 2 deletions src/animate/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ class Controller {
if(list2.length && onList.length) {
list2.forEach(item => {
onList.forEach(arr => {
let cb = () => {
let time = item.timestamp;
if(time !== this.__lastTime[arr[0]]) {
this.__lastTime[arr[0]] = time;
arr[1] && arr[1]();
}
};
cb.__karasEventCb = arr[1];
item.off(arr[0], arr[1]);
item.on(arr[0], arr[1]);
item.on(arr[0], cb);
});
});
}
Expand Down Expand Up @@ -208,7 +216,7 @@ class Controller {
let time = item.timestamp;
if(time !== this.__lastTime[id]) {
this.__lastTime[id] = time;
handle();
handle && handle();
}
};
cb.__karasEventCb = handle;
Expand Down
1 change: 1 addition & 0 deletions src/refresh/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const TRANSFORMS = {
[STYLE_KEY.ROTATE_3D]: true,
[STYLE_KEY.TRANSFORM]: true,
[STYLE_KEY.TRANSFORM_ORIGIN]: true,
[STYLE_KEY.TRANSLATE_PATH]: true,
};

let o = Object.assign({
Expand Down
24 changes: 14 additions & 10 deletions src/util/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,24 @@ const STYLE_KEY = {

const STYLE2LOWER_MAP = {};
function style2Lower(s) {
STYLE2LOWER_MAP[s] = STYLE2LOWER_MAP[s] || s.toLowerCase().replace(/_([a-z])/g, function($0, $1) {
return $1.toUpperCase();
});

return STYLE2LOWER_MAP[s];
let res = STYLE2LOWER_MAP[s];
if(!res) {
res = STYLE2LOWER_MAP[s] = s.toLowerCase().replace(/_([a-z])/g, function($0, $1) {
return $1.toUpperCase();
});
}
return res;
}

const STYLE2UPPER_MAP = {};
function style2Upper(s) {
STYLE2UPPER_MAP[s] = STYLE2UPPER_MAP[s] || s.replace(/([a-z\d_])([A-Z])/g, function($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();

return STYLE2UPPER_MAP[s];
let res = STYLE2UPPER_MAP[s];
if(!res) {
res = STYLE2UPPER_MAP[s] = s.replace(/([a-z\d_])([A-Z])/g, function($0, $1, $2) {
return $1 + '_' + $2;
}).toUpperCase();
}
return res;
}

const STYLE_R_KEY = {};
Expand Down
24 changes: 17 additions & 7 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,24 @@ function rgba2int(color) {

function int2rgba(color) {
if(Array.isArray(color)) {
if(color.length === 4) {
color = color.map((c, i) => i === 3 ? c : Math.floor(Math.max(0, c)));
return 'rgba(' + joinArr(color, ',') + ')';
}
else if(color.length === 3) {
color = color.map(c => Math.floor(c));
return 'rgba(' + joinArr(color, ',') + ',1)';
if(color.length === 3 || color.length === 4) {
color[0] = Math.floor(Math.max(color[0], 0));
color[1] = Math.floor(Math.max(color[1], 0));
color[2] = Math.floor(Math.max(color[2], 0));
if(color.length === 4) {
color[3] = Math.max(color[3], 0);
return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',' + color[3] + ')';
}
return 'rgba(' + color[0] + ',' + color[1] + ',' + color[2] + ',1)';
}
// if(color.length === 4) {
// color = color.map((c, i) => i === 3 ? c : Math.floor(Math.max(0, c)));
// return 'rgba(' + joinArr(color, ',') + ')';
// }
// else if(color.length === 3) {
// color = color.map(c => Math.floor(c));
// return 'rgba(' + joinArr(color, ',') + ',1)';
// }
}
return color || 'rgba(0,0,0,0)';
}
Expand Down
2 changes: 1 addition & 1 deletion test/group1/animate-gotostop-fill-svg/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
.url('file://' + path.join(__dirname, 'index.html'))
.waitForElementVisible('body', 1000)
.pause(300)
.assert.value('input', '[{"k":"linear","d":180,"v":[[[127.5,127.5,0,1]],[[0,0,255,1]]]}]')
.assert.value('input', '[{"k":"linear","d":180,"v":[[[127,127,0,1]],[[0,0,255,1]]]}]')
.end();
}
};

0 comments on commit 6186d37

Please sign in to comment.