kempo 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.
- package/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/components/Card.js +1 -0
- package/dist/components/CodeEditor.js +1 -0
- package/dist/components/Component.js +1 -0
- package/dist/components/Dialog.js +1 -0
- package/dist/components/FocusCapture.js +1 -0
- package/dist/components/Icon.js +1 -0
- package/dist/components/Import.js +1 -0
- package/dist/components/LazyComponent.js +1 -0
- package/dist/components/ReactiveComponent.js +1 -0
- package/dist/components/ReactiveLazyComponent.js +1 -0
- package/dist/components/Resize.js +1 -0
- package/dist/components/Search.js +1 -0
- package/dist/components/ShowMore.js +1 -0
- package/dist/components/SideMenu.js +1 -0
- package/dist/components/Split.js +1 -0
- package/dist/components/Tabs.js +1 -0
- package/dist/components/ThemeSwitcher.js +1 -0
- package/dist/components/Timestamp.js +1 -0
- package/dist/components/WebSnippetEditor.js +1 -0
- package/dist/index.js +1 -0
- package/dist/kempo-hljs.css +1 -0
- package/dist/kempo-styles.css +1 -0
- package/dist/kempo-vars.css +1 -0
- package/dist/kempo.css +1 -0
- package/dist/kempo.js +1 -0
- package/dist/utils/cli.js +1 -0
- package/dist/utils/cookie.js +1 -0
- package/dist/utils/debounce.js +1 -0
- package/dist/utils/drag.js +1 -0
- package/dist/utils/element.js +1 -0
- package/dist/utils/formatTimestamp.js +1 -0
- package/dist/utils/fuzzyMatch.js +1 -0
- package/dist/utils/getPreferredTheme.js +1 -0
- package/dist/utils/loadCss.js +1 -0
- package/dist/utils/loadScript.js +1 -0
- package/dist/utils/object.js +1 -0
- package/dist/utils/string.js +1 -0
- package/dist/utils/toFunction.js +1 -0
- package/dist/utils/type.js +1 -0
- package/dist/utils/waitFrames.js +1 -0
- package/docs/components/_template.html +22 -0
- package/docs/components/card.html +35 -0
- package/docs/components/codeeditor.html +29 -0
- package/docs/components/component.html +88 -0
- package/docs/components/dialog.html +89 -0
- package/docs/components/icon.html +73 -0
- package/docs/components/import.html +34 -0
- package/docs/components/lazycomponent.html +50 -0
- package/docs/components/resize.html +107 -0
- package/docs/components/show-more.html +92 -0
- package/docs/components/sidemenu.html +97 -0
- package/docs/components/split.html +70 -0
- package/docs/components/tabs.html +33 -0
- package/docs/components/websnippeteditor.html +42 -0
- package/docs/index.html +17 -0
- package/docs/kempo/components/Card.js +1 -0
- package/docs/kempo/components/CodeEditor.js +1 -0
- package/docs/kempo/components/Collapse.js +1 -0
- package/docs/kempo/components/Component.js +1 -0
- package/docs/kempo/components/Dialog.js +1 -0
- package/docs/kempo/components/FocusCapture.js +1 -0
- package/docs/kempo/components/Icon.js +1 -0
- package/docs/kempo/components/Import.js +1 -0
- package/docs/kempo/components/LazyComponent.js +1 -0
- package/docs/kempo/components/ReactiveComponent.js +1 -0
- package/docs/kempo/components/ReactiveLazyComponent.js +1 -0
- package/docs/kempo/components/Resize.js +1 -0
- package/docs/kempo/components/Search.js +1 -0
- package/docs/kempo/components/ShowMore.js +1 -0
- package/docs/kempo/components/SideMenu.js +1 -0
- package/docs/kempo/components/Split.js +1 -0
- package/docs/kempo/components/Tabs.js +1 -0
- package/docs/kempo/components/ThemeSwitcher.js +1 -0
- package/docs/kempo/components/Timestamp.js +1 -0
- package/docs/kempo/components/WebSnippetEditor.js +1 -0
- package/docs/kempo/icons/arrow-down-double.svg +1 -0
- package/docs/kempo/icons/arrow-up-double.svg +1 -0
- package/docs/kempo/icons/close.svg +2 -0
- package/docs/kempo/icons/compare.svg +1 -0
- package/docs/kempo/icons/dark-mode.svg +1 -0
- package/docs/kempo/icons/delete.svg +1 -0
- package/docs/kempo/icons/filter-off.svg +1 -0
- package/docs/kempo/icons/filter.svg +1 -0
- package/docs/kempo/icons/light-mode.svg +1 -0
- package/docs/kempo/icons/menu.svg +1 -0
- package/docs/kempo/icons/pause.svg +1 -0
- package/docs/kempo/icons/play.svg +1 -0
- package/docs/kempo/icons/search.svg +1 -0
- package/docs/kempo/icons/settings.svg +1 -0
- package/docs/kempo/icons/storage.svg +1 -0
- package/docs/kempo/icons/trash-x.svg +1 -0
- package/docs/kempo/index.js +1 -0
- package/docs/kempo/kempo-hljs.css +1 -0
- package/docs/kempo/kempo-styles.css +1 -0
- package/docs/kempo/kempo-vars.css +1 -0
- package/docs/kempo/kempo.css +1 -0
- package/docs/kempo/kempo.js +1 -0
- package/docs/kempo/utils/cli.js +1 -0
- package/docs/kempo/utils/cookie.js +1 -0
- package/docs/kempo/utils/debounce.js +1 -0
- package/docs/kempo/utils/drag.js +1 -0
- package/docs/kempo/utils/element.js +1 -0
- package/docs/kempo/utils/formatTimestamp.js +1 -0
- package/docs/kempo/utils/fuzzyMatch.js +1 -0
- package/docs/kempo/utils/getPreferredTheme.js +1 -0
- package/docs/kempo/utils/loadCss.js +1 -0
- package/docs/kempo/utils/loadScript.js +1 -0
- package/docs/kempo/utils/object.js +1 -0
- package/docs/kempo/utils/string.js +1 -0
- package/docs/kempo/utils/toFunction.js +1 -0
- package/docs/kempo/utils/type.js +1 -0
- package/docs/kempo/utils/waitFrames.js +1 -0
- package/docs/nav-1.inc.html +66 -0
- package/docs/nav.inc.html +66 -0
- package/docs/search.json +94 -0
- package/docs/styles/_template.html +22 -0
- package/docs/styles/borders-spacing.html +193 -0
- package/docs/styles/buttons.html +113 -0
- package/docs/styles/colors.html +65 -0
- package/docs/styles/displays-layouts.html +156 -0
- package/docs/styles/embed-1.html +35 -0
- package/docs/styles/inputs.html +89 -0
- package/docs/styles/tables.html +143 -0
- package/docs/styles/typography.html +116 -0
- package/icons/arrow-down-double.svg +1 -0
- package/icons/arrow-up-double.svg +1 -0
- package/icons/close.svg +2 -0
- package/icons/compare.svg +1 -0
- package/icons/dark-mode.svg +1 -0
- package/icons/delete.svg +1 -0
- package/icons/filter-off.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/light-mode.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/storage.svg +1 -0
- package/icons/trash-x.svg +1 -0
- package/kempo/components/Card.js +65 -0
- package/kempo/components/CodeEditor.js +141 -0
- package/kempo/components/Component.js +109 -0
- package/kempo/components/Dialog.js +277 -0
- package/kempo/components/FocusCapture.js +30 -0
- package/kempo/components/Icon.js +60 -0
- package/kempo/components/Import.js +40 -0
- package/kempo/components/LazyComponent.js +40 -0
- package/kempo/components/ReactiveComponent.js +11 -0
- package/kempo/components/ReactiveLazyComponent.js +11 -0
- package/kempo/components/Resize.js +168 -0
- package/kempo/components/Search.js +136 -0
- package/kempo/components/ShowMore.js +82 -0
- package/kempo/components/SideMenu.js +156 -0
- package/kempo/components/Split.js +133 -0
- package/kempo/components/Tabs.js +254 -0
- package/kempo/components/ThemeSwitcher.js +77 -0
- package/kempo/components/Timestamp.js +25 -0
- package/kempo/components/WebSnippetEditor.js +159 -0
- package/kempo/kempo-hljs.css +145 -0
- package/kempo/kempo-styles.css +893 -0
- package/kempo/kempo-vars.css +154 -0
- package/kempo/kempo.js +48 -0
- package/kempo/utils/cli.js +54 -0
- package/kempo/utils/cookie.js +16 -0
- package/kempo/utils/debounce.js +9 -0
- package/kempo/utils/drag.js +74 -0
- package/kempo/utils/element.js +69 -0
- package/kempo/utils/formatTimestamp.js +11 -0
- package/kempo/utils/fuzzyMatch.js +55 -0
- package/kempo/utils/getPreferredTheme.js +1 -0
- package/kempo/utils/loadCss.js +10 -0
- package/kempo/utils/loadScript.js +10 -0
- package/kempo/utils/object.js +177 -0
- package/kempo/utils/string.js +54 -0
- package/kempo/utils/toFunction.js +24 -0
- package/kempo/utils/type.js +8 -0
- package/kempo/utils/waitFrames.js +17 -0
- package/package.json +33 -0
- package/scripts/build.js +131 -0
- package/scripts/docs.js +14 -0
- package/test/components/SuiteList.js +26 -0
- package/test/components/Test.js +357 -0
- package/test/index.html +49 -0
- package/test/index.js +25 -0
- package/test/suite.html +45 -0
- package/test/suites.inc.html +4 -0
- package/test/tests/components/Component.test.js +138 -0
- package/test/tests/utils/cli.test.js +113 -0
- package/test/tests/utils/cookie.test.js +87 -0
- package/test/tests/utils/debounce.test.js +71 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
import {
|
|
3
|
+
dispatchEvent
|
|
4
|
+
} from '../utils/element.js';
|
|
5
|
+
|
|
6
|
+
const clickHandler = Symbol();
|
|
7
|
+
export class Tab extends Component {
|
|
8
|
+
constructor(){
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
/* Private Methods */
|
|
12
|
+
this[clickHandler] = () => {
|
|
13
|
+
if(!this.active){
|
|
14
|
+
this.tabs.active = this.for;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Init */
|
|
19
|
+
this.slot = 'tabs';
|
|
20
|
+
this.registerAttribute('active', false);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connectedCallback(){
|
|
24
|
+
super.connectedCallback();
|
|
25
|
+
this.shadowRoot.getElementById('button').addEventListener('click', this[clickHandler]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get for(){
|
|
29
|
+
const forValue = this.getAttribute('for');
|
|
30
|
+
if(forValue) return forValue;
|
|
31
|
+
return this?.tabs.tabs.indexOf(this);
|
|
32
|
+
}
|
|
33
|
+
set for(v){
|
|
34
|
+
if(v){
|
|
35
|
+
this.setAttribute('for', v);
|
|
36
|
+
} else {
|
|
37
|
+
this.removeAttribute('for');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get tabs(){
|
|
42
|
+
return this.parentElement.tagName === 'K-TABS'?this.parentElement:null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get shadowTemplate(){
|
|
46
|
+
return /*html*/`
|
|
47
|
+
<button id="button">
|
|
48
|
+
${super.shadowTemplate}
|
|
49
|
+
</button>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
get shadowStyles(){
|
|
53
|
+
return /*css*/`
|
|
54
|
+
:host {
|
|
55
|
+
margin-bottom: -1px;
|
|
56
|
+
}
|
|
57
|
+
#button {
|
|
58
|
+
padding: var(--spacer_h);
|
|
59
|
+
background-color: transparent;
|
|
60
|
+
border: none;
|
|
61
|
+
cursor: inherit;
|
|
62
|
+
box-shadow: none;
|
|
63
|
+
color: inherit;
|
|
64
|
+
}
|
|
65
|
+
:host(:not([active])) #button {
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
}
|
|
68
|
+
:host([active]){
|
|
69
|
+
border-bottom: 2px solid var(--c_primary);
|
|
70
|
+
margin-bottom: -1px;
|
|
71
|
+
}
|
|
72
|
+
:host([active]) #button {
|
|
73
|
+
color: var(--tc_primary);
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
window.customElements.define('k-tab', Tab);
|
|
80
|
+
|
|
81
|
+
export class TabContent extends Component {
|
|
82
|
+
constructor(){
|
|
83
|
+
super();
|
|
84
|
+
|
|
85
|
+
this.registerAttribute('active', false);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get tabs(){
|
|
89
|
+
return this.parentElement.tagName === 'K-TABS'?this.parentElement:null;
|
|
90
|
+
}
|
|
91
|
+
get name(){
|
|
92
|
+
const name = this.getAttribute('name');
|
|
93
|
+
if(name) return name;
|
|
94
|
+
return this?.tabs.contents.indexOf(this);
|
|
95
|
+
}
|
|
96
|
+
set name(v){
|
|
97
|
+
if(v){
|
|
98
|
+
this.setAttribute('name', v);
|
|
99
|
+
} else {
|
|
100
|
+
this.removeAttribute('name');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get shadowStyles(){
|
|
105
|
+
return /*css*/`
|
|
106
|
+
${super.shadowStyles}
|
|
107
|
+
:host {
|
|
108
|
+
display: block;
|
|
109
|
+
height: 100%;
|
|
110
|
+
max-height: 100%;
|
|
111
|
+
flex: 1 1 auto;
|
|
112
|
+
overflow: hidden;
|
|
113
|
+
}
|
|
114
|
+
:host([active]) {
|
|
115
|
+
display: block;
|
|
116
|
+
}
|
|
117
|
+
:host(:not([active])) {
|
|
118
|
+
display: none;
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
window.customElements.define('k-tab-content', TabContent);
|
|
124
|
+
|
|
125
|
+
export class Tabs extends Component {
|
|
126
|
+
constructor(){
|
|
127
|
+
super();
|
|
128
|
+
this.registerAttribute('active', '');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async connectedCallback(){
|
|
132
|
+
await super.connectedCallback();
|
|
133
|
+
if(!this.active){
|
|
134
|
+
this.active = `${this.querySelectorAll('k-tab-content')[0].name}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
attributeChangedCallback(n, oV, nV){
|
|
138
|
+
if(n === 'active'){
|
|
139
|
+
const $activeTab = this.getActiveTab();
|
|
140
|
+
if($activeTab) $activeTab.active = false;
|
|
141
|
+
const $activeContent = this.getActiveContent();
|
|
142
|
+
if($activeContent) $activeContent.active = false;
|
|
143
|
+
const $tab = this.getTab(nV);
|
|
144
|
+
if($tab) $tab.active = true;
|
|
145
|
+
const $content = this.getContent(nV);
|
|
146
|
+
if($content) $content.active = true;
|
|
147
|
+
dispatchEvent(this, 'tab', { tab: nV });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get contents(){
|
|
152
|
+
return [...this.querySelectorAll(':scope > k-tab-content')];
|
|
153
|
+
}
|
|
154
|
+
get tabs(){
|
|
155
|
+
return [...this.querySelectorAll(':scope > k-tab')];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getTab(id){
|
|
159
|
+
let $tab;
|
|
160
|
+
if(typeof(id) === 'string'){
|
|
161
|
+
$tab = this.querySelector(`k-tab[for="${id}"]`);
|
|
162
|
+
}
|
|
163
|
+
if(!$tab){
|
|
164
|
+
let index = parseInt(id);
|
|
165
|
+
if(!index) index = 0;
|
|
166
|
+
$tab = this.querySelectorAll('k-tab')[index];
|
|
167
|
+
}
|
|
168
|
+
return $tab;
|
|
169
|
+
}
|
|
170
|
+
getActiveTab(){
|
|
171
|
+
return this.querySelector(':scope > k-tab[active="true"]');
|
|
172
|
+
}
|
|
173
|
+
getContent(id){
|
|
174
|
+
let $content;
|
|
175
|
+
if(typeof(id) === 'string'){
|
|
176
|
+
$content = this.querySelector(`k-tab-content[name="${id}"]`);
|
|
177
|
+
}
|
|
178
|
+
if(!$content){
|
|
179
|
+
let index = parseInt(id);
|
|
180
|
+
if(!index) index = 0;
|
|
181
|
+
$content = this.querySelectorAll('k-tab-content')[index];
|
|
182
|
+
}
|
|
183
|
+
return $content;
|
|
184
|
+
}
|
|
185
|
+
getActiveContent(){
|
|
186
|
+
return this.querySelector(':scope > k-tab-content[active="true"]');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
get shadowTemplate(){
|
|
191
|
+
return /*html*/`
|
|
192
|
+
<div id="wrapper">
|
|
193
|
+
<div id="tabs">
|
|
194
|
+
<slot name="tabs"></slot>
|
|
195
|
+
</div>
|
|
196
|
+
<div id="contents">
|
|
197
|
+
${super.shadowTemplate}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
get shadowStyles(){
|
|
204
|
+
return /*css*/`
|
|
205
|
+
${super.shadowStyles}
|
|
206
|
+
:host {
|
|
207
|
+
display: block;
|
|
208
|
+
overflow: hidden;
|
|
209
|
+
}
|
|
210
|
+
#wrapper {
|
|
211
|
+
display: flex;
|
|
212
|
+
flex-direction: column;
|
|
213
|
+
max-height: 100%;
|
|
214
|
+
height: 100%;
|
|
215
|
+
overflow: hidden;
|
|
216
|
+
}
|
|
217
|
+
#tabs {
|
|
218
|
+
display: flex;
|
|
219
|
+
border-bottom: 1px solid var(--c_border);
|
|
220
|
+
padding: 0;
|
|
221
|
+
margin-top: calc(0 - var(--spacer));
|
|
222
|
+
align-items: flex-start;
|
|
223
|
+
}
|
|
224
|
+
#contents {
|
|
225
|
+
display: flex;
|
|
226
|
+
flex-direction: column;
|
|
227
|
+
flex: 1;
|
|
228
|
+
max-height: 100%;
|
|
229
|
+
overflow: hidden
|
|
230
|
+
}
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static observedAttributes = [...super.observedAttributes, 'active'];
|
|
235
|
+
}
|
|
236
|
+
window.customElements.define('k-tabs', Tabs);
|
|
237
|
+
|
|
238
|
+
export class TabSpacer extends Component {
|
|
239
|
+
constructor(){
|
|
240
|
+
super();
|
|
241
|
+
this.slot = 'tabs';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
get shadowStyles(){
|
|
245
|
+
return /*css*/`
|
|
246
|
+
${super.shadowStyles}
|
|
247
|
+
:host {
|
|
248
|
+
flex: 1 1 auto;
|
|
249
|
+
height: 1px;
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
window.customElements.define('k-tab-spacer', TabSpacer);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
import {
|
|
3
|
+
onEvent,
|
|
4
|
+
dispatchEvent
|
|
5
|
+
} from '../utils/element.js';
|
|
6
|
+
|
|
7
|
+
const storageWatcher = Symbol('storageWatcher'),
|
|
8
|
+
clickHandler = Symbol('clickHandler');
|
|
9
|
+
export default class ThemeSwitcher extends Component {
|
|
10
|
+
constructor(){
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
this[storageWatcher] = () => {
|
|
14
|
+
this.currentTheme = ThemeSwitcher.getCurrentTheme();
|
|
15
|
+
}
|
|
16
|
+
this[clickHandler] = () => {
|
|
17
|
+
ThemeSwitcher.setTheme(ThemeSwitcher.getCurrentTheme()==='light'?'dark':'light');
|
|
18
|
+
}
|
|
19
|
+
this.registerAttribute('currentTheme', ThemeSwitcher.getCurrentTheme());
|
|
20
|
+
}
|
|
21
|
+
async render(force){
|
|
22
|
+
if(await super.render(force)){1
|
|
23
|
+
onEvent(window, 'storage', this[storageWatcher]);
|
|
24
|
+
onEvent(this.shadowRoot.getElementById('toggle'), 'click', this[clickHandler]);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get shadowTemplate(){
|
|
31
|
+
return /*html*/`
|
|
32
|
+
<button
|
|
33
|
+
id="toggle"
|
|
34
|
+
class="no-btn"
|
|
35
|
+
>
|
|
36
|
+
<k-icon
|
|
37
|
+
id="lightMode"
|
|
38
|
+
name="light-mode"
|
|
39
|
+
></k-icon>
|
|
40
|
+
<k-icon
|
|
41
|
+
id="darkMode"
|
|
42
|
+
name="dark-mode"
|
|
43
|
+
></k-icon>
|
|
44
|
+
</button>
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
get shadowStyles(){
|
|
48
|
+
return /*css*/`
|
|
49
|
+
:host {
|
|
50
|
+
--padding: var(--spacer);
|
|
51
|
+
|
|
52
|
+
display: flex;
|
|
53
|
+
}
|
|
54
|
+
#toggle {
|
|
55
|
+
padding: var(--padding);
|
|
56
|
+
}
|
|
57
|
+
:host([current-theme="dark"]) #darkMode,
|
|
58
|
+
:host([current-theme="light"]) #lightMode {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static setTheme(theme){
|
|
65
|
+
localStorage.setItem('theme', theme);
|
|
66
|
+
document.documentElement.setAttribute('theme', theme);
|
|
67
|
+
dispatchEvent(window, 'storage', { theme });
|
|
68
|
+
}
|
|
69
|
+
static getCurrentTheme(){
|
|
70
|
+
let theme = document.documentElement.getAttribute('theme');
|
|
71
|
+
if(!theme) theme = localStorage.getItem('theme');
|
|
72
|
+
if(!theme) theme = window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';
|
|
73
|
+
return theme;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ThemeSwitcher.setTheme(ThemeSwitcher.getCurrentTheme());
|
|
77
|
+
window.customElements.define('k-theme-switcher', ThemeSwitcher);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Component from './Component.js'
|
|
2
|
+
import formatTimestamp from '../utils/formatTimestamp.js';
|
|
3
|
+
|
|
4
|
+
export default class Timestamp extends Component {
|
|
5
|
+
constructor(timestamp){
|
|
6
|
+
super();
|
|
7
|
+
this.registerAttribute('timestamp', 0);
|
|
8
|
+
if(timestamp) this.timestamp = timestamp;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* Lifecycle Callbacks */
|
|
12
|
+
attributeChangedCallback(n, oV, nV){
|
|
13
|
+
if(n == 'timestamp'){
|
|
14
|
+
if(nV){
|
|
15
|
+
this.innerHTML = formatTimestamp(nV, 'en-US');
|
|
16
|
+
} else {
|
|
17
|
+
this.innerHTML = '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Static Members */
|
|
23
|
+
static observedAttributes = ['timestamp'];
|
|
24
|
+
}
|
|
25
|
+
window.customElements.define('k-timestamp', Timestamp);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
import {
|
|
3
|
+
escapeHTML,
|
|
4
|
+
unescapeHTML
|
|
5
|
+
} from '../utils/string.js';
|
|
6
|
+
import './Split.js';
|
|
7
|
+
import './Tabs.js';
|
|
8
|
+
import './CodeEditor.js';
|
|
9
|
+
|
|
10
|
+
const changeHandler = Symbol();
|
|
11
|
+
export default class WebSnippetEditor extends Component {
|
|
12
|
+
constructor(){
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
this[changeHandler] = () => {
|
|
16
|
+
this.renderResults();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.registerAttributes({
|
|
20
|
+
useKempo: false,
|
|
21
|
+
showHtml: true,
|
|
22
|
+
showCss: true,
|
|
23
|
+
showJs: true,
|
|
24
|
+
scripts: ''
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async render(){
|
|
29
|
+
await super.render();
|
|
30
|
+
|
|
31
|
+
const $htmlCode = this.querySelector('pre[for="html"]');
|
|
32
|
+
const $htmlEditor = this.shadowRoot.getElementById('html');
|
|
33
|
+
$htmlEditor.addEventListener('change', this[changeHandler]);
|
|
34
|
+
if($htmlCode){
|
|
35
|
+
$htmlEditor.value = escapeHTML($htmlCode.textContent);
|
|
36
|
+
} else {
|
|
37
|
+
$htmlEditor.value = escapeHTML(`<div>\n \n</div>`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const $cssCode = this.querySelector('pre[for="css"]');
|
|
41
|
+
const $cssEditor = this.shadowRoot.getElementById('css');
|
|
42
|
+
$cssEditor.addEventListener('change', this[changeHandler]);
|
|
43
|
+
if($cssCode){
|
|
44
|
+
$cssEditor.value = $cssCode.textContent;
|
|
45
|
+
} else {
|
|
46
|
+
$cssEditor.value = `div {\n \n}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const $jsCode = this.querySelector('pre[for="js"]');
|
|
50
|
+
const $jsEditor = this.shadowRoot.getElementById('js');
|
|
51
|
+
$jsEditor.addEventListener('change', this[changeHandler]);
|
|
52
|
+
if($jsCode){
|
|
53
|
+
$jsEditor.value = $jsCode.textContent;
|
|
54
|
+
} else {
|
|
55
|
+
$jsEditor.value = '';
|
|
56
|
+
}
|
|
57
|
+
this.renderResults();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
renderResults(){
|
|
61
|
+
const html = this.shadowRoot.getElementById('html').value;
|
|
62
|
+
const css = this.shadowRoot.getElementById('css').value;
|
|
63
|
+
const js = this.shadowRoot.getElementById('js').value;
|
|
64
|
+
|
|
65
|
+
const $results = this.shadowRoot.getElementById('results');
|
|
66
|
+
$results.innerHTML = '';
|
|
67
|
+
const $iframe = document.createElement('iframe');
|
|
68
|
+
$iframe.frameBorder = "0";
|
|
69
|
+
$results.appendChild($iframe);
|
|
70
|
+
const iframeDoc = $iframe.contentDocument || $iframe.contentWindow.document;
|
|
71
|
+
iframeDoc.body.innerHTML = `
|
|
72
|
+
${this.useKempo?`<link rel="stylesheet" href="../kempo/kempo-vars.css" /><link rel="stylesheet" href="../kempo/kempo-styles.css" />`:''}
|
|
73
|
+
<style>
|
|
74
|
+
body, html {
|
|
75
|
+
background-color: transparent;
|
|
76
|
+
}
|
|
77
|
+
body {
|
|
78
|
+
overflow-y: auto;
|
|
79
|
+
padding: var(--spacer_q, 4px);
|
|
80
|
+
}
|
|
81
|
+
${css}
|
|
82
|
+
</style>
|
|
83
|
+
${html}
|
|
84
|
+
`;
|
|
85
|
+
if(this.useKempo && this.scripts){
|
|
86
|
+
this.scripts.split(',').forEach( script => {
|
|
87
|
+
const $script = document.createElement('script');
|
|
88
|
+
$script.type = 'module';
|
|
89
|
+
$script.src = script;
|
|
90
|
+
iframeDoc.head.appendChild($script);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const $script = document.createElement('script');
|
|
94
|
+
$script.textContent = js;
|
|
95
|
+
iframeDoc.head.appendChild($script);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get shadowTemplate(){
|
|
99
|
+
return /*html*/`
|
|
100
|
+
<k-split id="split">
|
|
101
|
+
<k-tabs class="ml">
|
|
102
|
+
${this.showHtml?`<k-tab for="html">HTML</k-tab>`:''}
|
|
103
|
+
${this.showCss?`<k-tab for="css">CSS</k-tab>`:''}
|
|
104
|
+
${this.showJs?`<k-tab for="js">JS</k-tab>`:''}
|
|
105
|
+
<k-tab-content name="html">
|
|
106
|
+
<k-code-editor
|
|
107
|
+
id="html"
|
|
108
|
+
language="xml"
|
|
109
|
+
class="my"
|
|
110
|
+
></k-code-editor>
|
|
111
|
+
</k-tab-content>
|
|
112
|
+
<k-tab-content name="css">
|
|
113
|
+
<k-code-editor
|
|
114
|
+
id="css"
|
|
115
|
+
language="css"
|
|
116
|
+
class="my"
|
|
117
|
+
></k-code-editor>
|
|
118
|
+
</k-tab-content>
|
|
119
|
+
<k-tab-content name="js">
|
|
120
|
+
<k-code-editor
|
|
121
|
+
id="js"
|
|
122
|
+
language="js"
|
|
123
|
+
class="my"
|
|
124
|
+
></k-code-editor>
|
|
125
|
+
</k-tab-content>
|
|
126
|
+
</k-tabs>
|
|
127
|
+
<div
|
|
128
|
+
id="results"
|
|
129
|
+
slot="right"
|
|
130
|
+
></div>
|
|
131
|
+
</k-split>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
get shadowStyles(){
|
|
135
|
+
return /*css*/`
|
|
136
|
+
:host {
|
|
137
|
+
--min-height: auto;
|
|
138
|
+
--height: auto;
|
|
139
|
+
--max-height: auto;
|
|
140
|
+
display: block;
|
|
141
|
+
}
|
|
142
|
+
k-tab-content {
|
|
143
|
+
min-height: var(--min-height);
|
|
144
|
+
height: var(--height);
|
|
145
|
+
max-height: var(--max-height);
|
|
146
|
+
}
|
|
147
|
+
k-code-editor {
|
|
148
|
+
max-height: calc(100% - (2 * var(--spacer)));
|
|
149
|
+
}
|
|
150
|
+
#results,
|
|
151
|
+
iframe {
|
|
152
|
+
width: 100%;
|
|
153
|
+
height: 100%;
|
|
154
|
+
background-color: transparent;
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
window.customElements.define('k-web-snippet-editor', WebSnippetEditor);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
:root,
|
|
2
|
+
[theme="light"] {
|
|
3
|
+
--c_text: #000000;
|
|
4
|
+
--c_keyword: #0000ff;
|
|
5
|
+
--c_builtin: #00b0e8;
|
|
6
|
+
--c_number: #709756;
|
|
7
|
+
--c_string: #a31515;
|
|
8
|
+
--c_regex: #914525;
|
|
9
|
+
--c_function: inherit;
|
|
10
|
+
--c_comment: #008000;
|
|
11
|
+
--c_doc: #808080;
|
|
12
|
+
--c_tag: #7d7d7d;
|
|
13
|
+
--c_var: #b436bf;
|
|
14
|
+
--c_attr: #ff0000;
|
|
15
|
+
--c_section: #a31515;
|
|
16
|
+
--c_selector: #0000ff;
|
|
17
|
+
--c_addition: #a31515;
|
|
18
|
+
--c_deletion: #2b91af;
|
|
19
|
+
--c_caret: black;
|
|
20
|
+
}
|
|
21
|
+
[theme="dark"] {
|
|
22
|
+
--c_text: #DCDCDC;
|
|
23
|
+
--c_keyword: #569CD6;
|
|
24
|
+
--c_builtin: #4EC9B0;
|
|
25
|
+
--c_number: #B8D7A3;
|
|
26
|
+
--c_string: #D69D85;
|
|
27
|
+
--c_regex: #9A5334;
|
|
28
|
+
--c_function: inehrit;
|
|
29
|
+
--c_comment: #57A64A;
|
|
30
|
+
--c_doc: #608B4E;
|
|
31
|
+
--c_tag: #9B9B9B;
|
|
32
|
+
--c_var: #BD63C5;
|
|
33
|
+
--c_attr: #9CDCFE;
|
|
34
|
+
--c_section: #ffd700;
|
|
35
|
+
--c_selector: #569CD6;
|
|
36
|
+
--c_addition: #144212;
|
|
37
|
+
--c_deletion: #600;
|
|
38
|
+
--c_caret: white;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.hljs {
|
|
42
|
+
display: block;
|
|
43
|
+
overflow-x: auto;
|
|
44
|
+
color: var(--c_text);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.hljs-keyword,
|
|
48
|
+
.hljs-literal,
|
|
49
|
+
.hljs-symbol,
|
|
50
|
+
.hljs-name,
|
|
51
|
+
.hljs-link {
|
|
52
|
+
color: var(--c_keyword);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.hljs-link {
|
|
56
|
+
text-decoration: underline;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.hljs-built_in,
|
|
60
|
+
.hljs-type {
|
|
61
|
+
color: var(--c_builtin);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.hljs-number,
|
|
65
|
+
.hljs-class {
|
|
66
|
+
color: var(--c_number);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.hljs-string,
|
|
70
|
+
.hljs-meta-string {
|
|
71
|
+
color: var(--c_string);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.hljs-regexp,
|
|
75
|
+
.hljs-template-tag {
|
|
76
|
+
color: var(--c_regex);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.hljs-subst,
|
|
80
|
+
.hljs-function,
|
|
81
|
+
.hljs-title,
|
|
82
|
+
.hljs-params,
|
|
83
|
+
.hljs-formula {
|
|
84
|
+
color: var(--c_function);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.hljs-comment,
|
|
88
|
+
.hljs-quote {
|
|
89
|
+
color: var(--c_comment);
|
|
90
|
+
font-style: italic
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.hljs-doctag {
|
|
94
|
+
color: var(--c_doc);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.hljs-meta,
|
|
98
|
+
.hljs-meta-keyword,
|
|
99
|
+
.hljs-tag {
|
|
100
|
+
color: var(--c_tag);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.hljs-variable,
|
|
104
|
+
.hljs-template-variable {
|
|
105
|
+
color: var(--c_var);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.hljs-attr,
|
|
109
|
+
.hljs-attribute,
|
|
110
|
+
.hljs-builtin-name {
|
|
111
|
+
color: var(--c_attr);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.hljs-section {
|
|
115
|
+
color: var(--c_section);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.hljs-emphasis {
|
|
119
|
+
font-style: italic
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.hljs-strong {
|
|
123
|
+
font-weight: bold
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.hljs-bullet,
|
|
127
|
+
.hljs-selector-tag,
|
|
128
|
+
.hljs-selector-id,
|
|
129
|
+
.hljs-selector-class,
|
|
130
|
+
.hljs-selector-attr,
|
|
131
|
+
.hljs-selector-pseudo {
|
|
132
|
+
color: var(--c_selector);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.hljs-addition {
|
|
136
|
+
background-color: var(--c_addition);
|
|
137
|
+
display: inline-block;
|
|
138
|
+
width: 100%
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.hljs-deletion {
|
|
142
|
+
background-color: var(--c_deletion);
|
|
143
|
+
display: inline-block;
|
|
144
|
+
width: 100%
|
|
145
|
+
}
|