Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit d7c3575

Browse files
committed
es6, npm, pluginified
1 parent 6d708e7 commit d7c3575

18 files changed

+3228
-250
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {
4+
"targets": {
5+
"browsers": ["last 2 versions"]
6+
}
7+
}]
8+
]
9+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.eslintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "airbnb",
3+
"env": {
4+
"browser": true,
5+
"node": false
6+
},
7+
"rules": {
8+
"indent": ["warn", 4],
9+
"no-restricted-syntax": 0,
10+
"guard-for-in": 0,
11+
"func-names": 0,
12+
"class-methods-use-this": 0,
13+
"no-debugger": 0,
14+
"no-param-reassign": 0
15+
}
16+
}

.gitignore

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
# Logs
2-
logs
1+
*.com
2+
*.class
3+
*.dll
4+
*.exe
5+
*.o
6+
*.so
7+
*.7z
8+
*.dmg
9+
*.gz
10+
*.iso
11+
*.jar
12+
*.rar
13+
*.tar
14+
*.zip
315
*.log
4-
5-
# Runtime data
6-
pids
7-
*.pid
8-
*.seed
9-
10-
# Directory for instrumented libs generated by jscoverage/JSCover
11-
lib-cov
12-
13-
# Coverage directory used by tools like istanbul
14-
coverage
15-
16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17-
.grunt
18-
19-
# Compiled binary addons (http://nodejs.org/api/addons.html)
20-
build/Release
21-
22-
# Dependency directory
23-
# Deployed apps should consider commenting this line out:
24-
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
16+
*.sql
17+
*.sqlite
18+
.DS_Store
19+
.DS_Store?
20+
._*
21+
.Spotlight-V100
22+
.Trashes
23+
ehthumbs.db
24+
Thumbs.db
2525
node_modules
26-
27-
bower_components
26+
prepros.cfg

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 jQueryKeyframes
3+
Copyright (c) 2018 Keyframes (https://github.com/Keyframes/Keyframes.Spritesheet)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
Keyframes.Spritesheet
22
=====================
3-
Keyframes.Spritesheet is a plugin for jQuery.Keyframes that easily generates css3 keyframes for elements using animated spritesheets.
4-
5-
Installation
6-
------------
7-
8-
```
9-
bower install keyframesspritesheet
10-
```
3+
Keyframes.Spritesheet is a plugin for Keyframes that easily generates css3 keyframes for elements using animated spritesheets.
114

125
Usage
136
-----

bower.json

Lines changed: 0 additions & 15 deletions
This file was deleted.
File renamed without changes.

example/example.dist.js

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2+
"use strict";
3+
4+
var _core = _interopRequireDefault(require("@keyframes/core"));
5+
6+
var _keyframes = _interopRequireDefault(require("../src/keyframes.spritesheet"));
7+
8+
function _interopRequireDefault(obj) {
9+
return obj && obj.__esModule ? obj : {
10+
default: obj
11+
};
12+
}
13+
14+
_core.default.plugin(_keyframes.default);
15+
16+
window.onload = function () {
17+
var ss = _core.default.spriteSheet({
18+
name: 'gem',
19+
rows: 6,
20+
cols: 7,
21+
width: 210,
22+
height: 180,
23+
offsetX: 0,
24+
offsetY: 0,
25+
count: 39
26+
});
27+
28+
var container = new _core.default(document.querySelectorAll('.spriteContainer')[0]);
29+
container.playSpriteSheet('gem', '3s', -1, ss);
30+
};
31+
32+
},{"../src/keyframes.spritesheet":3,"@keyframes/core":2}],2:[function(require,module,exports){
33+
"use strict";
34+
35+
Object.defineProperty(exports, "__esModule", {
36+
value: true
37+
});
38+
exports.default = void 0;
39+
40+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
41+
42+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
43+
44+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
45+
46+
var Keyframes =
47+
/*#__PURE__*/
48+
function () {
49+
function Keyframes(elem) {
50+
_classCallCheck(this, Keyframes);
51+
52+
this.elem = elem;
53+
}
54+
55+
_createClass(Keyframes, [{
56+
key: "isSupported",
57+
value: function isSupported() {
58+
return document.body.style.animationName !== undefined;
59+
}
60+
}, {
61+
key: "reset",
62+
value: function reset(callback) {
63+
this.elem.style.animationPlayState = 'running';
64+
this.elem.style.animation = 'none';
65+
66+
if (callback) {
67+
setTimeout(callback, 0);
68+
}
69+
}
70+
}, {
71+
key: "pause",
72+
value: function pause() {
73+
this.elem.style.animationPlayState = 'paused';
74+
}
75+
}, {
76+
key: "resume",
77+
value: function resume() {
78+
this.elem.style.animationPlayState = 'running';
79+
}
80+
}, {
81+
key: "play",
82+
value: function play(frameOptions, callback) {
83+
var _this = this;
84+
85+
var animObjToStr = function animObjToStr(obj) {
86+
var newObj = Object.assign({}, {
87+
duration: '0s',
88+
timingFunction: 'ease',
89+
delay: '0s',
90+
iterationCount: 1,
91+
direction: 'normal',
92+
fillMode: 'forwards'
93+
}, obj);
94+
return [newObj.name, newObj.duration, newObj.timingFunction, newObj.delay, newObj.iterationCount, newObj.direction, newObj.fillMode].join(' ');
95+
};
96+
97+
var animationcss = '';
98+
99+
if (frameOptions.constructor === Array) {
100+
var frameOptionsStrings = [];
101+
102+
for (var i = 0; i < frameOptions.length; i += 1) {
103+
frameOptionsStrings.push(typeof frameOptions[i] === 'string' ? frameOptions[i] : animObjToStr(frameOptions[i]));
104+
}
105+
106+
animationcss = frameOptionsStrings.join(', ');
107+
} else if (typeof frameOptions === 'string') {
108+
animationcss = frameOptions;
109+
} else {
110+
animationcss = animObjToStr(frameOptions);
111+
}
112+
113+
var addEvent = function addEvent(type, eventCallback) {
114+
var listenerName = "".concat(type, "Listener");
115+
116+
_this.elem.removeEventListener(type, _this[listenerName]);
117+
118+
_this[listenerName] = eventCallback;
119+
120+
_this.elem.addEventListener(type, _this[listenerName]);
121+
};
122+
123+
this.elem.style.animationPlayState = 'running';
124+
this.elem.style.animation = animationcss;
125+
this.frameOptions = frameOptions;
126+
addEvent('animationiteration', callback || frameOptions.complete);
127+
addEvent('animationend', callback || frameOptions.complete);
128+
}
129+
}], [{
130+
key: "createKeyframeTag",
131+
value: function createKeyframeTag(id, css) {
132+
var elem = document.createElement('style');
133+
elem.innerHTML = css;
134+
elem.setAttribute('class', 'keyframe-style');
135+
elem.setAttribute('id', id);
136+
elem.setAttribute('type', 'text/css');
137+
document.getElementsByTagName('head')[0].appendChild(elem);
138+
}
139+
}, {
140+
key: "generate",
141+
value: function generate(frameData) {
142+
var frameName = frameData.name || '';
143+
var css = "@keyframes ".concat(frameName, " {");
144+
145+
for (var key in frameData) {
146+
if (key !== 'name' && key !== 'media' && key !== 'complete') {
147+
css += "".concat(key, " {");
148+
149+
for (var property in frameData[key]) {
150+
css += "".concat(property, ":").concat(frameData[key][property], ";");
151+
}
152+
153+
css += '}';
154+
}
155+
}
156+
157+
if (frameData.media) {
158+
css = "@media ".concat(frameData.media, "{").concat(css, "}");
159+
}
160+
161+
var frameStyle = document.getElementById(frameName);
162+
163+
if (frameStyle) {
164+
frameStyle.innerHTML = css;
165+
} else {
166+
Keyframes.createKeyframeTag(frameName, css);
167+
}
168+
}
169+
}, {
170+
key: "define",
171+
value: function define(frameData) {
172+
if (frameData.length) {
173+
for (var i = 0; i < frameData.length; i += 1) {
174+
this.generate(frameData[i]);
175+
}
176+
} else {
177+
this.generate(frameData);
178+
}
179+
}
180+
}, {
181+
key: "plugin",
182+
value: function plugin(pluginFunc) {
183+
pluginFunc(Keyframes);
184+
}
185+
}]);
186+
187+
return Keyframes;
188+
}();
189+
190+
exports.default = Keyframes;
191+
192+
},{}],3:[function(require,module,exports){
193+
"use strict";
194+
195+
Object.defineProperty(exports, "__esModule", {
196+
value: true
197+
});
198+
exports.default = void 0;
199+
200+
var _default = function _default(Keyframes) {
201+
Keyframes.spriteSheets = {};
202+
203+
Keyframes.spriteSheet = function (opts) {
204+
var defaults = {
205+
name: '',
206+
rows: 1,
207+
cols: 1,
208+
height: 0,
209+
width: 0,
210+
offsetX: 0,
211+
offsetY: 0,
212+
count: opts.rows * opts.cols,
213+
spriteWidth: opts.width / opts.cols,
214+
spriteHeight: opts.height / opts.rows,
215+
loop: true
216+
};
217+
opts = Object.assign({}, defaults, opts);
218+
Keyframes.spriteSheets[opts.name] = opts;
219+
var spriteStep = 100 / opts.count;
220+
var spriteFrames = {};
221+
var x = opts.offsetX;
222+
var y = opts.offsetY;
223+
224+
for (var i = 0; i < opts.count; i += 1) {
225+
spriteFrames["".concat(Math.round(spriteStep * i), "%")] = {
226+
'background-position': "-".concat(x, "px -").concat(y, "px")
227+
};
228+
229+
if (x >= opts.width - opts.spriteWidth) {
230+
y += opts.spriteHeight;
231+
x = opts.offsetX;
232+
} else {
233+
x += opts.spriteWidth;
234+
}
235+
}
236+
237+
return Object.assign({}, {
238+
name: opts.name
239+
}, spriteFrames);
240+
};
241+
242+
Keyframes.prototype.playSpriteSheet = function (name, time, loops, keyframes) {
243+
if (keyframes) {
244+
Keyframes.define(keyframes);
245+
}
246+
247+
if (loops) {
248+
if (loops < 0) {
249+
loops = 'infinite';
250+
}
251+
} else {
252+
loops = 'infinite';
253+
}
254+
255+
var animate = "".concat(name, " ").concat(time, " steps(1) ").concat(loops);
256+
var existingAnimation = this.elem.style.animation;
257+
258+
if (existingAnimation && existingAnimation.split(' ')[0] !== 'none') {
259+
animate = "".concat(existingAnimation, ", ").concat(animate);
260+
}
261+
262+
this.elem.style.animation = animate;
263+
return this;
264+
};
265+
};
266+
267+
exports.default = _default;
268+
269+
},{}]},{},[1]);

0 commit comments

Comments
 (0)