keyframekit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/dist/KeyframeKit.d.ts +139 -0
  4. package/dist/KeyframeKit.d.ts.map +1 -0
  5. package/dist/KeyframeKit.js +294 -0
  6. package/dist/KeyframeKit.js.map +1 -0
  7. package/docs/.vitepress/components/Playground/Playground.js +243 -0
  8. package/docs/.vitepress/components/Playground/Playground.vue +206 -0
  9. package/docs/.vitepress/components/Playground/defaultExample.js +175 -0
  10. package/docs/.vitepress/components/Playground/interFont.js +14 -0
  11. package/docs/.vitepress/components/Playground/themes/githubDark.js +402 -0
  12. package/docs/.vitepress/components/Playground/themes/githubLight.js +399 -0
  13. package/docs/.vitepress/components/Playground/themes.js +24 -0
  14. package/docs/.vitepress/config.ts +64 -0
  15. package/docs/.vitepress/referenceNavigation.ts +37 -0
  16. package/docs/.vitepress/theme/base-styles.css +91 -0
  17. package/docs/.vitepress/theme/env.d.ts +5 -0
  18. package/docs/.vitepress/theme/index.ts +40 -0
  19. package/docs/docs/index.md +136 -0
  20. package/docs/docs/public/icon.png +0 -0
  21. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.d.ts +139 -0
  22. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.d.ts.map +1 -0
  23. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.js +294 -0
  24. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.js.map +1 -0
  25. package/docs/docs/reference/_media/LICENSE +21 -0
  26. package/docs/docs/reference/classes/KeyframeEffectParameters.md +95 -0
  27. package/docs/docs/reference/classes/ParsedKeyframes.md +49 -0
  28. package/docs/docs/reference/index.md +20 -0
  29. package/docs/docs/reference/interfaces/KeyframesFactory.md +151 -0
  30. package/docs/docs/reference/navigation.json +64 -0
  31. package/docs/docs/reference/type-aliases/KeyframeArgument.md +9 -0
  32. package/docs/docs/reference/type-aliases/KeyframesFactorySource.md +9 -0
  33. package/docs/docs/reference/type-aliases/ParsedKeyframesRules.md +15 -0
  34. package/docs/docs/reference/variables/default.md +7 -0
  35. package/docs/package.json +25 -0
  36. package/docs/typedoc/plugin-param-names.js +52 -0
  37. package/docs/typedoc.json +63 -0
  38. package/package.json +37 -0
  39. package/src/KeyframeKit.ts +508 -0
  40. package/tsconfig.json +47 -0
  41. package/vercel.json +13 -0
@@ -0,0 +1,243 @@
1
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
2
+
3
+ import { themes } from './themes.js'
4
+ //import * as monaco from 'monaco-editor'
5
+
6
+
7
+ import loader from '@monaco-editor/loader'
8
+
9
+
10
+ const langMap = { HTML: 'html', CSS: 'css', JS: 'javascript' }
11
+
12
+ export function playground(props, previewFrame, getDefaultExample, interFontDec) {
13
+ const tabs = ['JS', 'CSS', 'HTML']
14
+ const activeTab = ref('JS')
15
+ const code = ref({ HTML: '', CSS: '', JS: '' })
16
+ const isLoaded = ref(false);
17
+
18
+ const libCode = {
19
+ decLibSrc: '',
20
+ libImportMap: ''
21
+ };
22
+
23
+ const editorRefs = {}
24
+ const editorInstances = {}
25
+
26
+ const models = {}
27
+
28
+ function setEditorRef(tab, el) {
29
+ if (el) editorRefs[tab] = el
30
+ }
31
+
32
+ let updateTimer = null
33
+ function scheduleUpdate() {
34
+ if (updateTimer !== null) clearTimeout(updateTimer)
35
+ updateTimer = setTimeout(updatePreview, 300)
36
+ }
37
+
38
+ function updatePreview() {
39
+
40
+ if (!previewFrame.value) return;
41
+
42
+ const doc = `
43
+ <!DOCTYPE html>
44
+ <html>
45
+ <head>
46
+ <base href="${window.location.href}">
47
+ <style>${code.value.CSS}</style>
48
+ <link rel="stylesheet" href="${interFontDec}">
49
+ </head>
50
+ <body>
51
+ ${code.value.HTML}
52
+ ${libCode.libImportMap}
53
+ <script type="module">${code.value.JS}<\/script>
54
+ </body>
55
+ </html>`
56
+ const blob = new Blob([doc], { type: 'text/html' })
57
+ previewFrame.value.src = URL.createObjectURL(blob)
58
+ }
59
+
60
+ function addLibrary(monaco) {
61
+
62
+ // validation settings
63
+ monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
64
+ noSemanticValidation: false,
65
+ noSyntaxValidation: false
66
+ });
67
+
68
+ // compiler options
69
+ monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
70
+ target: 'esnext',
71
+ module: 'esnext',
72
+ allowNonTsExtensions: true,
73
+ allowImportingTsExtensions: true,
74
+ paths: {
75
+ "keyframekit": ["file:///KeyframeKit"]
76
+ },
77
+ baseUrl: './',
78
+ });
79
+
80
+ const decLibModel = createModel(
81
+ libCode.decLibSrc,
82
+ 'typescript',
83
+ 'file:///KeyframeKit.d.ts',
84
+ monaco
85
+ );
86
+
87
+ }
88
+
89
+ function createModel(srcStr, language, uriStr, monaco) {
90
+
91
+ const uri = monaco.Uri.parse(uriStr);
92
+
93
+ const existing = monaco.editor.getModel(uri)
94
+
95
+ if (existing) existing.dispose()
96
+
97
+ const model = monaco.editor.createModel(srcStr, language, uri);
98
+
99
+ models[uriStr] = model;
100
+
101
+ return model;
102
+
103
+ }
104
+
105
+ function applyTheme(monaco) {
106
+ const dark = document.documentElement.classList.contains('dark')
107
+ monaco.editor.setTheme(dark ? 'vp-dark' : 'vp-light')
108
+ }
109
+
110
+ function watchTheme(monaco) {
111
+ applyTheme(monaco)
112
+ new MutationObserver(() => applyTheme(monaco))
113
+ .observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
114
+ }
115
+
116
+ onMounted(async () => {
117
+
118
+ const isTouchDevice = window.matchMedia('(hover: none)').matches;
119
+
120
+ code.value = getDefaultExample({ isTouchDevice });
121
+
122
+
123
+ // note: the absolute URLs here are important, because if they were relative,
124
+ // they would return an invalid response when navigating from another page due to a vue bug.
125
+
126
+ libCode.decLibSrc = await (await fetch('/playground/KeyframeKit/dist/KeyframeKit.d.ts')).text();
127
+
128
+ const jsLibSrc = await (await fetch('/playground/KeyframeKit/dist/KeyframeKit.js')).text();
129
+
130
+ libCode.libImportMap = `
131
+ <script type="importmap">
132
+ {
133
+ "imports": {
134
+ "keyframekit": "data:text/javascript;base64,${btoa(jsLibSrc)}"
135
+ }
136
+ }
137
+ </script>
138
+ `;
139
+
140
+
141
+ updatePreview()
142
+
143
+
144
+ //const monaco = await import('monaco-editor')
145
+
146
+ loader.config({
147
+ paths: {
148
+ vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs'
149
+ }
150
+ })
151
+
152
+ const monaco = await loader.init()
153
+
154
+
155
+ const config = {
156
+ fontSize: 16,
157
+ fontFamily: 'var(--vp-font-family-mono)',
158
+ minimap: { enabled: false },
159
+ scrollBeyondLastLine: false,
160
+ padding: { top: 20, bottom: 20 },
161
+ automaticLayout: true,
162
+ fixedOverflowWidgets: true,
163
+ renderLineHighlightOnlyWhenFocus: true,
164
+
165
+ inertialScroll: isTouchDevice,
166
+ mouseWheelScrollSensitivity: isTouchDevice ? 10 : 1,
167
+ scrollPredominantAxis: !isTouchDevice,
168
+ smoothScrolling: isTouchDevice,
169
+ contextmenu: !isTouchDevice,
170
+
171
+ tabSize: 2,
172
+ lineNumbers: "off",
173
+ scrollbar: {
174
+ ignoreHorizontalScrollbarInContentHeight: true
175
+ },
176
+ lightbulb: {
177
+ enabled: 'off'
178
+ }
179
+ };
180
+
181
+ monaco.editor.defineTheme('vp-dark', themes.dark);
182
+ monaco.editor.defineTheme('vp-light', themes.light);
183
+
184
+ watchTheme(monaco);
185
+
186
+ addLibrary(monaco);
187
+
188
+ tabs.forEach(tab => {
189
+
190
+ let instance;
191
+
192
+ if (langMap[tab] === 'javascript') {
193
+
194
+ // Mark as lang: typescript so we can see the full type annotations on hover,
195
+ // but prefix the file with .js so as to not allow actual type annotations in the file's code.
196
+ const mainModel = createModel(
197
+ code.value[tab],
198
+ 'typescript',
199
+ 'file:///main.js',
200
+ monaco
201
+ );
202
+
203
+ instance = monaco.editor.create(editorRefs[tab], {
204
+ model: mainModel,
205
+ ...config
206
+ });
207
+
208
+ } else {
209
+
210
+ instance = monaco.editor.create(editorRefs[tab], {
211
+ value: code.value[tab],
212
+ language: langMap[tab],
213
+ ...config
214
+ })
215
+
216
+ }
217
+
218
+ instance.onDidChangeModelContent(() => {
219
+ code.value[tab] = instance.getValue()
220
+ scheduleUpdate()
221
+ })
222
+
223
+ editorInstances[tab] = instance
224
+
225
+ })
226
+
227
+
228
+ isLoaded.value = true;
229
+
230
+ })
231
+
232
+ onBeforeUnmount(() => {
233
+
234
+ Object.values(editorInstances).forEach(e => e.dispose())
235
+
236
+ Object.values(models).forEach(e => e.dispose())
237
+
238
+ if (updateTimer) clearTimeout(updateTimer)
239
+
240
+ })
241
+
242
+ return { tabs, activeTab, setEditorRef, isLoaded }
243
+ }
@@ -0,0 +1,206 @@
1
+ <template>
2
+ <div class="playground" :class="{ loaded: isLoaded === true }">
3
+ <div class="editor-pane">
4
+ <div class="tabs">
5
+ <button
6
+ v-for="tab in tabs"
7
+ :key="tab"
8
+ class="tab"
9
+ :class="{ active: activeTab === tab }"
10
+ @click="activeTab = tab"
11
+ >
12
+ {{ tab }}
13
+ </button>
14
+ </div>
15
+ <div class="editor-container">
16
+
17
+ <div
18
+ v-for="tab in tabs"
19
+ :key="tab"
20
+ :ref="el => setEditorRef(tab, el)"
21
+ class="editor-mount"
22
+ :style="{ visibility: activeTab === tab ? 'visible' : 'hidden' }"
23
+ />
24
+
25
+ <svg class="loader" width="18" height="18" viewBox="0 0 100 100"><rect fill="#555555" height="10" opacity="0" rx="5" ry="5" transform="rotate(-90 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.125" rx="5" ry="5" transform="rotate(-45 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.25" rx="5" ry="5" transform="rotate(0 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.375" rx="5" ry="5" transform="rotate(45 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.5" rx="5" ry="5" transform="rotate(90 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.625" rx="5" ry="5" transform="rotate(135 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.75" rx="5" ry="5" transform="rotate(180 50 50)" width="28" x="67" y="45"></rect><rect fill="#555555" height="10" opacity="0.875" rx="5" ry="5" transform="rotate(225 50 50)" width="28" x="67" y="45"></rect></svg>
26
+
27
+ </div>
28
+ </div>
29
+
30
+ <div class="preview-pane">
31
+ <iframe ref="previewFrame" class="preview-frame" sandbox="allow-scripts" />
32
+ </div>
33
+ </div>
34
+ </template>
35
+
36
+ <script setup>
37
+ import { ref } from 'vue'
38
+ import { playground } from './Playground.js'
39
+
40
+ import { getDefaultExample } from './defaultExample.js';
41
+ //import * as libCode from './libCode.js';
42
+
43
+ import { interFontDec } from './interFont.js';
44
+
45
+ const props = defineProps({
46
+ //initialHtml: { type: String, default: defaultExample.html },
47
+ //initialCss: { type: String, default: defaultExample.css },
48
+ //initialJs: { type: String, default: defaultExample.js },
49
+
50
+ //decLibSrc: { type: String, default: libCode.decLibSrc },
51
+ //libImportMap: { type: String, default: libCode.libImportMap }
52
+ })
53
+
54
+ const previewFrame = ref(null)
55
+ const { tabs, activeTab, isLoaded, setEditorRef } = playground(props, previewFrame, getDefaultExample, interFontDec)
56
+ </script>
57
+
58
+ <style scoped>
59
+ .playground {
60
+ display: flex;
61
+ height: 500px;
62
+ --border-radius: 8px;
63
+ border-radius: var(--border-radius);
64
+ overflow: hidden;
65
+ margin-bottom: 48px;
66
+ }
67
+
68
+ @media (max-width: 1000px) {
69
+ .playground {
70
+ flex-flow: column-reverse;
71
+ }
72
+ .playground .preview-pane {
73
+ border-bottom-width: 0;
74
+ border-left-width: 1px;
75
+ border-radius: var(--border-radius) var(--border-radius) 0 0;
76
+ }
77
+ }
78
+
79
+ @media (max-width: 640px) {
80
+ .playground {
81
+ margin-left: -24px;
82
+ margin-right: -24px;
83
+ --border-radius: 0;
84
+ }
85
+ .playground .preview-pane {
86
+ border-right-width: 0;
87
+ border-left-width: 0;
88
+ }
89
+ }
90
+
91
+ @media (min-width: 640px) {
92
+ .playground {
93
+ margin-bottom: 64px;
94
+ }
95
+ }
96
+
97
+ .editor-pane {
98
+ display: flex;
99
+ flex-direction: column;
100
+ background: var(--vp-code-block-bg);
101
+ flex: 1;
102
+ }
103
+
104
+ .tabs {
105
+ display: flex;
106
+ flex-shrink: 0;
107
+ padding: 0 12px;
108
+ background-color: var(--vp-code-tab-bg);
109
+ box-shadow: inset 0 -1px var(--vp-code-tab-divider);
110
+ }
111
+
112
+ .tab {
113
+ position: relative;
114
+ display: inline-block;
115
+ border-bottom: 1px solid transparent;
116
+ padding: 0 12px;
117
+ line-height: 48px;
118
+ font-size: 14px;
119
+ font-weight: 500;
120
+ color: var(--vp-code-tab-text-color);
121
+ white-space: nowrap;
122
+ cursor: pointer;
123
+ transition: color 0.25s;
124
+ }
125
+ .tab:hover {
126
+ color: var(--vp-code-tab-hover-text-color);
127
+ }
128
+ .tab.active {
129
+ color: var(--vp-code-tab-active-text-color);
130
+ }
131
+
132
+ .tab::after {
133
+ position: absolute;
134
+ right: 8px;
135
+ bottom: -1px;
136
+ left: 8px;
137
+ z-index: 1;
138
+ height: 2px;
139
+ border-radius: 2px;
140
+ content: '';
141
+ background-color: transparent;
142
+ /* transition: background-color 0.25s; */
143
+ }
144
+ .tab.active::after {
145
+ background-color: var(--vp-code-tab-active-bar-color);
146
+ }
147
+
148
+ .editor-container {
149
+ flex: 1;
150
+ /* overflow: hidden; */
151
+ position: relative;
152
+ }
153
+ .editor-mount {
154
+ width: 100%;
155
+ height: 100%;
156
+ position: absolute;
157
+ }
158
+
159
+ .editor-container .loader {
160
+ translate: -50% -50%;
161
+ left: 50%;
162
+ top: 50%;
163
+ position: relative;
164
+ color: var(--vp-c-text-2);
165
+ pointer-events: none;
166
+ animation: spin8 0.8s steps(8) infinite;
167
+ transition: .18s ease-in-out .18s opacity;
168
+
169
+ @starting-style {
170
+ opacity: 0;
171
+ }
172
+ }
173
+
174
+ .editor-container .loader rect {
175
+ fill: currentColor;
176
+ }
177
+
178
+ .playground.loaded .loader {
179
+ display: none;
180
+ }
181
+
182
+ @keyframes spin8 {
183
+ from {
184
+ transform: rotate(180deg);
185
+ }
186
+ to {
187
+ transform: rotate(540deg);
188
+ }
189
+ }
190
+
191
+ .preview-pane {
192
+ border: 1px solid var(--vp-code-block-bg);
193
+ border-left-width: 0;
194
+ flex: 1;
195
+ display: flex;
196
+ border-radius: 0 var(--border-radius) var(--border-radius) 0;
197
+ overflow: hidden;
198
+ background: #f0f7ff;
199
+ }
200
+
201
+ .preview-frame {
202
+ flex: 1;
203
+ width: 100%;
204
+ border: none;
205
+ }
206
+ </style>
@@ -0,0 +1,175 @@
1
+
2
+ // const isTouchDevice = window.matchMedia('(hover: none)').matches;
3
+ export function getDefaultExample({ isTouchDevice }) {
4
+
5
+ const jsAnimActivateEvent = isTouchDevice ? 'touchstart' : 'mouseenter';
6
+ const jsAnimDeactivateEvent = isTouchDevice ? 'touchend' : 'mouseleave';
7
+
8
+ const js = `import KeyframeKit from 'keyframekit';
9
+
10
+ const documentStyleSheets = await KeyframeKit.getDocumentStyleSheetsOnLoad();
11
+
12
+ // get animation keyframes from stylesheet
13
+ const rotateAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
14
+ of: 'rotate',
15
+ in: documentStyleSheets
16
+ });
17
+
18
+ // then, define your animation
19
+ const rotateAnim = rotateAnimKeyframes.toKeyframeEffect({
20
+ duration: 700,
21
+ easing: 'ease'
22
+ });
23
+
24
+ // finally, attach it to your elements:
25
+
26
+ let attachedAnims = [];
27
+ let animDelay = 0;
28
+
29
+ const spans = document.querySelectorAll('.text-anim span');
30
+
31
+ for (const span of spans) {
32
+
33
+ const attachedAnim = rotateAnim.toAnimation({
34
+ target: span,
35
+ options: {
36
+ delay: animDelay * 1000,
37
+ endDelay: -animDelay * 1000
38
+ }
39
+ });
40
+
41
+ attachedAnims.push(attachedAnim);
42
+
43
+ animDelay += .02;
44
+
45
+ }
46
+
47
+ attachedAnims.forEach(anim => anim.play());
48
+
49
+
50
+ // the primary reason to play your animation with JS
51
+ // is because you get way more control over its playback:
52
+
53
+ const textAnimEl = document.querySelector('.text-anim');
54
+
55
+ textAnimEl.addEventListener('${jsAnimActivateEvent}', () => {
56
+ attachedAnims.forEach(anim => {
57
+ anim.playbackRate = 1;
58
+ anim.play();
59
+ });
60
+ updateProgressBar();
61
+ });
62
+
63
+ textAnimEl.addEventListener('${jsAnimDeactivateEvent}', () => {
64
+ // reverse the animation
65
+ attachedAnims.forEach(anim => {
66
+ anim.playbackRate = -1;
67
+ });
68
+ updateProgressBar();
69
+ });
70
+
71
+
72
+ const progressBar = document.querySelector('.progress-bar');
73
+
74
+ function updateProgressBar() {
75
+ let progress = 0;
76
+ for (const anim of attachedAnims) {
77
+ progress += anim.overallProgress;
78
+ }
79
+ progress = progress / attachedAnims.length * 100;
80
+ progressBar.style.setProperty(
81
+ '--progress', progress + '%'
82
+ );
83
+
84
+ const isPlaying = attachedAnims.some(anim =>
85
+ anim.playState === 'running'
86
+ );
87
+ if (!isPlaying) return;
88
+ requestAnimationFrame(updateProgressBar);
89
+ }`;
90
+
91
+
92
+ const css = `@keyframes rotate {
93
+ from {
94
+ clip-path: inset(0 0 0 0);
95
+ translate: 0 0;
96
+ }
97
+ 49.99% {
98
+ clip-path: inset(100% 0 0 0);
99
+ translate: 0 -50px;
100
+ }
101
+ 50% {
102
+ clip-path: inset(0 0 100% 0);
103
+ translate: 0 50px;
104
+ }
105
+ to {
106
+ clip-path: inset(0 0 0 0);
107
+ translate: 0 0;
108
+ }
109
+ }
110
+
111
+
112
+ .text-anim {
113
+ display: flex;
114
+ font-size: 85px;
115
+ font-weight: 600;
116
+ color: #7ab6ff;
117
+ cursor: pointer;
118
+ }
119
+
120
+ .progress-bar {
121
+ width: ${isTouchDevice ? '180px' : '232px'};
122
+ height: 3px;
123
+ border-radius: 3px;
124
+ background: #82868942;
125
+ position: relative;
126
+ }
127
+
128
+ .progress-bar::before {
129
+ content: '';
130
+ height: 100%;
131
+ width: var(--progress, 0%);
132
+ border-radius: inherit;
133
+ position: absolute;
134
+ background: #7ab6ff;
135
+ }
136
+
137
+ body {
138
+ font-family: 'Inter', system-ui;
139
+ background: #f0f7ff;
140
+ height: 100vh;
141
+ margin: 0;
142
+ display: flex;
143
+ align-items: center;
144
+ justify-content: center;
145
+ flex-flow: column;
146
+ user-select: none;
147
+ -webkit-user-select: none;
148
+ }`;
149
+
150
+
151
+ const htmlDesktop = `<div class="text-anim">
152
+ <span>H</span>
153
+ <span>o</span>
154
+ <span>v</span>
155
+ <span>e</span>
156
+ <span>r</span>
157
+ </div>
158
+
159
+ <div class="progress-bar"></div>`;
160
+
161
+ const htmlMobile = `<div class="text-anim">
162
+ <span>H</span>
163
+ <span>o</span>
164
+ <span>l</span>
165
+ <span>d</span>
166
+ </div>
167
+
168
+ <div class="progress-bar"></div>`;
169
+
170
+ const html = isTouchDevice ? htmlMobile : htmlDesktop;
171
+
172
+
173
+ return { JS: js, CSS: css, HTML: html };
174
+
175
+ }