kempo-ui 0.0.2 → 0.0.4
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/.github/copilot-instructions.md +149 -149
- package/.github/workflows/publish-major.yml +39 -0
- package/.github/workflows/publish-minor.yml +39 -0
- package/.github/workflows/{publish-npm.yml → publish-patch.yml} +44 -44
- package/.vscode/settings.json +2 -0
- package/CONTRIBUTING.md +149 -149
- package/README.md +0 -0
- package/dist/kempo-hljs.css +1 -0
- package/dist/kempo-vars.css +0 -0
- package/dist/src/components/Accordion.js +36 -0
- package/dist/src/components/Card.js +37 -0
- package/dist/src/components/Collapsible.js +41 -0
- package/dist/src/components/ContentSlider.js +44 -0
- package/dist/src/components/Dialog.js +113 -0
- package/dist/src/components/FocusCapture.js +7 -0
- package/dist/src/components/Icon.js +10 -0
- package/dist/src/components/Import.js +1 -0
- package/dist/src/components/PersistantCollapsible.js +1 -0
- package/dist/src/components/PhotoViewer.js +135 -0
- package/dist/src/components/Resize.js +96 -0
- package/dist/src/components/ShadowComponent.js +1 -0
- package/dist/src/components/ShowMore.js +42 -0
- package/dist/src/components/SideMenu.js +97 -0
- package/dist/src/components/Split.js +84 -0
- package/dist/src/components/Tabs.js +155 -0
- package/dist/src/components/Tags.js +69 -0
- package/dist/src/components/ThemeSwitcher.js +23 -0
- package/dist/src/components/Timestamp.js +1 -0
- package/dist/src/lit-all.min.js +120 -0
- package/dist/src/utils/debounce.js +1 -0
- package/dist/src/utils/drag.js +1 -0
- package/dist/src/utils/formatTimestamp.js +1 -0
- package/dist/src/utils/propConverters.js +1 -0
- package/dist/src/utils/watchWindowSize.js +1 -0
- package/docs/components/accordion.html +166 -0
- package/docs/components/card.html +92 -0
- package/docs/components/collapsible.html +198 -0
- package/docs/components/content-slider.html +223 -0
- package/docs/components/dialog.html +251 -0
- package/docs/components/focus-capture.html +67 -0
- package/docs/components/icon.html +158 -0
- package/docs/components/import.html +73 -0
- package/docs/components/persistant-collapsible.html +123 -0
- package/docs/components/photo-viewer.html +226 -0
- package/docs/components/resize.html +178 -0
- package/docs/components/show-more.html +129 -0
- package/docs/components/side-menu.html +159 -0
- package/docs/components/split.html +147 -0
- package/docs/components/table.html +312 -0
- package/docs/components/tableControls.html +77 -0
- package/docs/components/tableCustomFields.html +113 -0
- package/docs/components/tableFetchRecords.html +114 -0
- package/docs/components/tableFieldSortHide.html +75 -0
- package/docs/components/tablePagination.html +100 -0
- package/docs/components/tableRecordEditing.html +144 -0
- package/docs/components/tableRecordFiltering.html +88 -0
- package/docs/components/tableRecordHiding.html +80 -0
- package/docs/components/tableRecordSearching.html +75 -0
- package/docs/components/tableRecordSelection.html +75 -0
- package/docs/components/tableRowControls.html +78 -0
- package/docs/components/tableSorting.html +73 -0
- package/docs/components/tabs.html +180 -0
- package/docs/components/tags.html +110 -0
- package/docs/components/theme-switcher.html +126 -0
- package/docs/components/timestamp.html +82 -0
- package/docs/components/toast.html +319 -0
- package/docs/components/toggle.html +156 -0
- package/docs/dev.config.json +20 -0
- package/docs/icons/add.svg +1 -0
- package/docs/icons/arrow-back.svg +1 -0
- package/docs/icons/arrow-down-double.svg +1 -0
- package/docs/icons/arrow-down.svg +1 -0
- package/docs/icons/arrow-forward.svg +1 -0
- package/docs/icons/arrow-up-double.svg +1 -0
- package/docs/icons/arrow-up.svg +1 -0
- package/docs/icons/cards.svg +1 -0
- package/docs/icons/check.svg +1 -0
- package/docs/icons/chevron-left.svg +1 -0
- package/docs/icons/chevron-right.svg +1 -0
- package/docs/icons/close.svg +2 -0
- package/docs/icons/compare.svg +1 -0
- package/docs/icons/delete.svg +1 -0
- package/docs/icons/drag-handle.svg +1 -0
- package/docs/icons/drawing2.svg +124 -0
- package/docs/icons/edit.svg +1 -0
- package/docs/icons/error.svg +1 -0
- package/docs/icons/export-file.svg +1 -0
- package/docs/icons/file-text.svg +1 -0
- package/docs/icons/file.svg +1 -0
- package/docs/icons/filter-off.svg +1 -0
- package/docs/icons/filter.svg +1 -0
- package/docs/icons/first.svg +1 -0
- package/docs/icons/folder-clear.svg +1 -0
- package/docs/icons/folder-create.svg +1 -0
- package/docs/icons/folder-open.svg +1 -0
- package/docs/icons/folder.svg +1 -0
- package/docs/icons/hide.svg +1 -0
- package/docs/icons/image.svg +1 -0
- package/docs/icons/label-add.svg +1 -0
- package/docs/icons/label.svg +1 -0
- package/docs/icons/last.svg +1 -0
- package/docs/icons/menu.svg +1 -0
- package/docs/icons/mode-auto.svg +1 -0
- package/docs/icons/mode-dark.svg +1 -0
- package/docs/icons/mode-light.svg +1 -0
- package/docs/icons/open-in-browser.svg +1 -0
- package/docs/icons/pause.svg +1 -0
- package/docs/icons/play.svg +1 -0
- package/docs/icons/refresh.svg +1 -0
- package/docs/icons/remove.svg +1 -0
- package/docs/icons/save.svg +1 -0
- package/docs/icons/search.svg +1 -0
- package/docs/icons/settings.svg +1 -0
- package/docs/icons/show.svg +1 -0
- package/docs/icons/storage.svg +1 -0
- package/docs/icons/table-visibility.svg +1 -0
- package/docs/icons/tag.svg +1 -0
- package/docs/icons/tools.svg +1 -0
- package/docs/icons/trash-x.svg +1 -0
- package/docs/icons/warning.svg +1 -0
- package/docs/index.html +28 -21
- package/docs/kempo-hljs.css +1 -0
- package/docs/media/civic.jpg +0 -0
- package/docs/media/corvette.jpg +0 -0
- package/docs/media/evo.jpg +0 -0
- package/docs/media/gtr.jpg +0 -0
- package/docs/media/nsx.jpg +0 -0
- package/docs/nav.inc.html +67 -0
- package/docs/nav.inc.js +4 -0
- package/{config/production.json → docs/prod.config.json} +20 -16
- package/docs/src/components/Accordion.js +36 -0
- package/docs/src/components/Card.js +37 -0
- package/docs/src/components/Collapsible.js +41 -0
- package/docs/src/components/ContentSlider.js +44 -0
- package/docs/src/components/Dialog.js +113 -0
- package/docs/src/components/FocusCapture.js +7 -0
- package/docs/src/components/HybridComponent.js +1 -0
- package/docs/src/components/Icon.js +10 -0
- package/docs/src/components/Import.js +1 -0
- package/docs/src/components/LightComponent.js +1 -0
- package/docs/src/components/PersistantCollapsible.js +1 -0
- package/docs/src/components/PhotoViewer.js +135 -0
- package/docs/src/components/Resize.js +96 -0
- package/docs/src/components/ShadowComponent.js +1 -0
- package/docs/src/components/ShowMore.js +42 -0
- package/docs/src/components/SideMenu.js +97 -0
- package/docs/src/components/Split.js +84 -0
- package/docs/src/components/Tabs.js +155 -0
- package/docs/src/components/Tags.js +69 -0
- package/docs/src/components/ThemeSwitcher.js +23 -0
- package/docs/src/components/Timestamp.js +1 -0
- package/docs/src/lit-all.min.js +120 -0
- package/docs/src/utils/debounce.js +1 -0
- package/docs/src/utils/drag.js +1 -0
- package/docs/src/utils/formatTimestamp.js +1 -0
- package/docs/src/utils/propConverters.js +1 -0
- package/docs/src/utils/watchWindowSize.js +1 -0
- package/docs/styles.css +6 -0
- package/docs/utils/debounce.html +78 -0
- package/docs/utils/drag.html +104 -0
- package/docs/utils/formatTimestamp.html +114 -0
- package/docs/utils/propConverters.html +132 -0
- package/docs/utils/watchWindowSize.html +166 -0
- package/icons/add.svg +1 -0
- package/icons/arrow-back.svg +1 -0
- package/icons/arrow-down-double.svg +1 -0
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-forward.svg +1 -0
- package/icons/arrow-up-double.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/cards.svg +1 -0
- package/icons/check.svg +1 -0
- package/icons/chevron-left.svg +1 -0
- package/icons/chevron-right.svg +1 -0
- package/icons/close.svg +2 -0
- package/icons/compare.svg +1 -0
- package/icons/delete.svg +1 -0
- package/icons/drag-handle.svg +1 -0
- package/icons/drawing2.svg +124 -0
- package/icons/edit.svg +1 -0
- package/icons/error.svg +1 -0
- package/icons/export-file.svg +1 -0
- package/icons/file-text.svg +1 -0
- package/icons/file.svg +1 -0
- package/icons/filter-off.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/first.svg +1 -0
- package/icons/folder-clear.svg +1 -0
- package/icons/folder-create.svg +1 -0
- package/icons/folder-open.svg +1 -0
- package/icons/folder.svg +1 -0
- package/icons/hide.svg +1 -0
- package/icons/image.svg +1 -0
- package/icons/label-add.svg +1 -0
- package/icons/label.svg +1 -0
- package/icons/last.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/mode-auto.svg +1 -0
- package/icons/mode-dark.svg +1 -0
- package/icons/mode-light.svg +1 -0
- package/icons/open-in-browser.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/remove.svg +1 -0
- package/icons/save.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/show.svg +1 -0
- package/icons/storage.svg +1 -0
- package/icons/table-visibility.svg +1 -0
- package/icons/tag.svg +1 -0
- package/icons/tools.svg +1 -0
- package/icons/trash-x.svg +1 -0
- package/icons/warning.svg +1 -0
- package/package.json +2 -2
- package/scripts/build.js +109 -138
- package/scripts/docs.js +62 -60
- package/src/components/Accordion.js +229 -0
- package/src/components/Card.js +66 -0
- package/src/components/Collapsible.js +109 -0
- package/src/components/ContentSlider.js +205 -0
- package/src/components/Dialog.js +368 -0
- package/src/components/FocusCapture.js +23 -0
- package/src/components/HybridComponent.js +40 -40
- package/src/components/Icon.js +155 -0
- package/src/components/Import.js +104 -0
- package/src/components/LightComponent.js +32 -32
- package/src/components/PersistantCollapsible.js +69 -0
- package/src/components/PhotoViewer.js +368 -0
- package/src/components/Resize.js +210 -0
- package/src/components/ShadowComponent.js +32 -17
- package/src/components/ShowMore.js +109 -0
- package/src/components/SideMenu.js +167 -0
- package/src/components/Sortable.js +193 -0
- package/src/components/Split.js +192 -0
- package/src/components/Table.js +1202 -0
- package/src/components/Tabs.js +428 -0
- package/src/components/Tags.js +253 -0
- package/src/components/ThemeSwitcher.js +108 -0
- package/src/components/Timestamp.js +31 -0
- package/src/components/Toast.js +454 -0
- package/src/components/Toggle.js +173 -0
- package/src/components/tableControls/DeleteRecord.js +29 -0
- package/src/components/tableControls/Edit.js +88 -0
- package/src/components/tableControls/ExportCSV.js +71 -0
- package/src/components/tableControls/ExportJson.js +55 -0
- package/src/components/tableControls/FieldSortHide.js +76 -0
- package/src/components/tableControls/Filters.js +114 -0
- package/src/components/tableControls/FirstPage.js +65 -0
- package/src/components/tableControls/HiddenCount.js +45 -0
- package/src/components/tableControls/Hide.js +34 -0
- package/src/components/tableControls/LastPage.js +65 -0
- package/src/components/tableControls/NextPage.js +65 -0
- package/src/components/tableControls/PageSelect.js +109 -0
- package/src/components/tableControls/PageSize.js +68 -0
- package/src/components/tableControls/PrevPage.js +65 -0
- package/src/components/tableControls/Search.js +58 -0
- package/src/components/tableControls/ShowAll.js +34 -0
- package/src/components/tableControls/TableControl.js +105 -0
- package/src/kempo-hljs.css +146 -0
- package/src/utils/debounce.js +9 -0
- package/src/utils/drag.js +80 -0
- package/src/utils/formatTimestamp.js +27 -0
- package/src/utils/propConverters.js +11 -0
- package/src/utils/toTitleCase.js +9 -0
- package/src/utils/watchWindowSize.js +16 -0
- package/tests/HybridComponent.browser-test.js +214 -214
- package/tests/LightComponent.browser-test.js +169 -169
- package/tests/ShadowComponent.browser-test.js +130 -130
- package/config/development.json +0 -14
- package/docs/components/ShadowComponent.js +0 -1
- package/src/utils/cli.js +0 -43
- package/src/utils/fs-utils.js +0 -41
- /package/{docs → dist/src}/components/HybridComponent.js +0 -0
- /package/{docs → dist/src}/components/LightComponent.js +0 -0
- /package/docs/{utils → src/utils}/cli.js +0 -0
- /package/docs/{utils → src/utils}/fs-utils.js +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import LightComponent from './LightComponent.js';
|
|
2
|
+
import { html, render, unsafeHTML } from '../lit-all.min.js';
|
|
3
|
+
|
|
4
|
+
export default class Import extends LightComponent {
|
|
5
|
+
/*
|
|
6
|
+
Properties
|
|
7
|
+
*/
|
|
8
|
+
static properties = {
|
|
9
|
+
src: {
|
|
10
|
+
type: String,
|
|
11
|
+
reflect: true
|
|
12
|
+
},
|
|
13
|
+
content: {
|
|
14
|
+
type: String
|
|
15
|
+
},
|
|
16
|
+
scripts: {
|
|
17
|
+
type: Array
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static replacements = {}
|
|
22
|
+
constructor(){
|
|
23
|
+
super();
|
|
24
|
+
this.src = '';
|
|
25
|
+
this.content = '';
|
|
26
|
+
this.scripts = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
Lifecycle Callbacks
|
|
31
|
+
*/
|
|
32
|
+
updated(changedProperties){
|
|
33
|
+
super.updated(); // Important: call super for LightComponent
|
|
34
|
+
|
|
35
|
+
if(changedProperties.has('src')){
|
|
36
|
+
this.fetch();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if(changedProperties.has('content') && this.scripts.length > 0){
|
|
40
|
+
// Execute scripts after DOM content is rendered
|
|
41
|
+
setTimeout(() => this.executeScripts(), 0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
Methods
|
|
47
|
+
*/
|
|
48
|
+
async fetch(){
|
|
49
|
+
let contents = await (await fetch(this.src)).text();
|
|
50
|
+
for (const [name, value] of Object.entries(Import.replacements)) {
|
|
51
|
+
contents = contents.replace(new RegExp(`%%${name}%%`, 'g'), value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Parse the HTML to extract scripts
|
|
55
|
+
const parser = new DOMParser();
|
|
56
|
+
const doc = parser.parseFromString(contents, 'text/html');
|
|
57
|
+
const scriptElements = doc.querySelectorAll('script');
|
|
58
|
+
|
|
59
|
+
// Extract script sources and inline code
|
|
60
|
+
this.scripts = Array.from(scriptElements).map(script => ({
|
|
61
|
+
src: script.src,
|
|
62
|
+
text: script.textContent,
|
|
63
|
+
type: script.type || 'text/javascript'
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
// Remove script tags from the content
|
|
67
|
+
scriptElements.forEach(script => script.remove());
|
|
68
|
+
|
|
69
|
+
// Serialize back to string without scripts - use the entire body content
|
|
70
|
+
this.content = doc.body ? doc.body.innerHTML : contents;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
executeScripts(){
|
|
74
|
+
this.scripts.forEach(script => {
|
|
75
|
+
const scriptElement = document.createElement('script');
|
|
76
|
+
scriptElement.type = script.type;
|
|
77
|
+
|
|
78
|
+
if (script.src) {
|
|
79
|
+
scriptElement.src = script.src;
|
|
80
|
+
} else if (script.text) {
|
|
81
|
+
scriptElement.textContent = script.text;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Append to head to execute
|
|
85
|
+
document.head.appendChild(scriptElement);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Clear scripts after execution to avoid re-execution
|
|
89
|
+
this.scripts = [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
Rendering
|
|
94
|
+
*/
|
|
95
|
+
renderLightDom() {
|
|
96
|
+
if (!this.content) {
|
|
97
|
+
return html``;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Use unsafeHTML to render the actual HTML content
|
|
101
|
+
return html`${unsafeHTML(this.content)}`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
window.customElements.define('k-import', Import);
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { LitElement, html, render } from '../lit-all.min.js';
|
|
2
|
-
|
|
3
|
-
export default class LightComponent extends LitElement {
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Light DOM Setup
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
createRenderRoot() {
|
|
10
|
-
this.lightRoot = document.createElement('div');
|
|
11
|
-
this.lightRoot.style.display = 'contents';
|
|
12
|
-
this.appendChild(this.lightRoot);
|
|
13
|
-
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
Lifecycle Callbacks
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
updated() {
|
|
22
|
-
render(this.renderLightDom(), this.lightRoot);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
Rendering
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
renderLightDom() {
|
|
30
|
-
return html``;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { LitElement, html, render } from '../lit-all.min.js';
|
|
2
|
+
|
|
3
|
+
export default class LightComponent extends LitElement {
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Light DOM Setup
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
createRenderRoot() {
|
|
10
|
+
this.lightRoot = document.createElement('div');
|
|
11
|
+
this.lightRoot.style.display = 'contents';
|
|
12
|
+
this.appendChild(this.lightRoot);
|
|
13
|
+
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
Lifecycle Callbacks
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
updated() {
|
|
22
|
+
render(this.renderLightDom(), this.lightRoot);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
Rendering
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
renderLightDom() {
|
|
30
|
+
return html``;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import Collapsible from './Collapsible.js';
|
|
2
|
+
|
|
3
|
+
export default class PersistantCollapsible extends Collapsible {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.storageKey = '';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Lifecycle Callbacks
|
|
11
|
+
*/
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
super.connectedCallback();
|
|
14
|
+
this.updateStorageKey();
|
|
15
|
+
this.loadFromStorage();
|
|
16
|
+
window.addEventListener('storage', this.handleStorageChange);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
disconnectedCallback() {
|
|
20
|
+
super.disconnectedCallback();
|
|
21
|
+
window.removeEventListener('storage', this.handleStorageChange);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
updated(changedProperties) {
|
|
25
|
+
super.updated(changedProperties);
|
|
26
|
+
|
|
27
|
+
if(changedProperties.has('opened')) {
|
|
28
|
+
this.saveToStorage();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if(changedProperties.has('id')) {
|
|
32
|
+
this.updateStorageKey();
|
|
33
|
+
this.loadFromStorage();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
Event Handlers
|
|
39
|
+
*/
|
|
40
|
+
handleStorageChange = event => {
|
|
41
|
+
if(event.key === this.storageKey) {
|
|
42
|
+
this.loadFromStorage();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
Private Methods
|
|
48
|
+
*/
|
|
49
|
+
updateStorageKey() {
|
|
50
|
+
this.storageKey = this.id ? `PersistantCollapsible-${this.id}` : '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
loadFromStorage() {
|
|
54
|
+
if(this.storageKey) {
|
|
55
|
+
const stored = localStorage.getItem(this.storageKey);
|
|
56
|
+
if(stored !== null) {
|
|
57
|
+
this.opened = stored === 'true';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
saveToStorage() {
|
|
63
|
+
if(this.storageKey) {
|
|
64
|
+
localStorage.setItem(this.storageKey, this.opened.toString());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
customElements.define('k-p-collapsible', PersistantCollapsible);
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import ShadowComponent from './ShadowComponent.js';
|
|
2
|
+
import { html, css } from '../lit-all.min.js';
|
|
3
|
+
import { boolExists } from '../utils/propConverters.js';
|
|
4
|
+
import './Icon.js';
|
|
5
|
+
|
|
6
|
+
export default class PhotoViewer extends ShadowComponent {
|
|
7
|
+
/*
|
|
8
|
+
Properties
|
|
9
|
+
*/
|
|
10
|
+
static properties = {
|
|
11
|
+
src: { type: String, reflect: true },
|
|
12
|
+
alt: { type: String, reflect: true },
|
|
13
|
+
fullscreen: { type: Boolean, reflect: true, converter: boolExists },
|
|
14
|
+
keyboardControls: { type: Boolean, reflect: true, attribute: 'keyboard-controls', converter: boolExists },
|
|
15
|
+
global: { type: Boolean, reflect: true, converter: boolExists }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.src = '';
|
|
21
|
+
this.alt = '';
|
|
22
|
+
this.fullscreen = false;
|
|
23
|
+
this.keyboardControls = true;
|
|
24
|
+
this.global = false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
Event Handlers
|
|
29
|
+
*/
|
|
30
|
+
handleImageClick = () => {
|
|
31
|
+
this.open();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
handleImageKeydown = event => {
|
|
35
|
+
if(event.key === 'Enter' && !this.fullscreen) {
|
|
36
|
+
this.open();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
handleCloseClick = () => {
|
|
41
|
+
this.close();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
handleOverlayClick = event => {
|
|
45
|
+
if(event.target === event.currentTarget) {
|
|
46
|
+
this.close();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
handlePrevClick = event => {
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
const prev = this.getPrevSibling();
|
|
53
|
+
if(prev) {
|
|
54
|
+
this.close();
|
|
55
|
+
prev.open();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
handleNextClick = event => {
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
const next = this.getNextSibling();
|
|
62
|
+
if(next) {
|
|
63
|
+
this.close();
|
|
64
|
+
next.open();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
handleKeydown = event => {
|
|
69
|
+
if(event.key === 'Escape') {
|
|
70
|
+
this.close();
|
|
71
|
+
} else if(event.key === 'ArrowLeft') {
|
|
72
|
+
const prev = this.getPrevSibling();
|
|
73
|
+
if(prev) {
|
|
74
|
+
this.close();
|
|
75
|
+
prev.open();
|
|
76
|
+
}
|
|
77
|
+
} else if(event.key === 'ArrowRight') {
|
|
78
|
+
const next = this.getNextSibling();
|
|
79
|
+
if(next) {
|
|
80
|
+
this.close();
|
|
81
|
+
next.open();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
Lifecycle Callbacks
|
|
88
|
+
*/
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
super.connectedCallback();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
disconnectedCallback() {
|
|
94
|
+
super.disconnectedCallback();
|
|
95
|
+
if(this.keyboardControls) {
|
|
96
|
+
document.removeEventListener('keydown', this.handleKeydown);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
updated(changedProperties) {
|
|
101
|
+
super.updated(changedProperties);
|
|
102
|
+
|
|
103
|
+
if(changedProperties.has('fullscreen')) {
|
|
104
|
+
this.dispatchEvent(new CustomEvent(`fullscreenchange`, {
|
|
105
|
+
detail: { fullscreen: this.fullscreen }
|
|
106
|
+
}));
|
|
107
|
+
this.dispatchEvent(new CustomEvent(this.fullscreen ? 'fullscreen' : 'fullscreenclose'));
|
|
108
|
+
this.updateNavigationState();
|
|
109
|
+
|
|
110
|
+
if(this.keyboardControls) {
|
|
111
|
+
if(this.fullscreen) {
|
|
112
|
+
document.addEventListener('keydown', this.handleKeydown);
|
|
113
|
+
} else {
|
|
114
|
+
document.removeEventListener('keydown', this.handleKeydown);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if(changedProperties.has('src') || changedProperties.has('alt')) {
|
|
120
|
+
this.handleFullscreenCaption();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
firstUpdated() {
|
|
125
|
+
this.handleFullscreenCaption();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
Public Methods
|
|
130
|
+
*/
|
|
131
|
+
open() {
|
|
132
|
+
this.fullscreen = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
close() {
|
|
136
|
+
this.fullscreen = false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
toggle() {
|
|
140
|
+
this.fullscreen = !this.fullscreen;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
Private Methods
|
|
145
|
+
*/
|
|
146
|
+
getPrevSibling() {
|
|
147
|
+
if(this.global) {
|
|
148
|
+
const viewers = Array.from(document.getElementsByTagName('k-photo-viewer'));
|
|
149
|
+
const index = viewers.indexOf(this);
|
|
150
|
+
if(index === -1) return null;
|
|
151
|
+
return viewers[index === 0 ? viewers.length - 1 : index - 1];
|
|
152
|
+
} else {
|
|
153
|
+
let prev = this.previousElementSibling;
|
|
154
|
+
while(prev && prev.tagName !== 'K-PHOTO-VIEWER') {
|
|
155
|
+
prev = prev.previousElementSibling;
|
|
156
|
+
}
|
|
157
|
+
if(!prev && this.hasPhotoSiblings()) {
|
|
158
|
+
prev = this.parentElement.lastElementChild;
|
|
159
|
+
while(prev && prev.tagName !== 'K-PHOTO-VIEWER') {
|
|
160
|
+
prev = prev.previousElementSibling;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return prev;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
getNextSibling() {
|
|
168
|
+
if(this.global) {
|
|
169
|
+
const viewers = Array.from(document.getElementsByTagName('k-photo-viewer'));
|
|
170
|
+
const index = viewers.indexOf(this);
|
|
171
|
+
if(index === -1) return null;
|
|
172
|
+
return viewers[index === viewers.length - 1 ? 0 : index + 1];
|
|
173
|
+
} else {
|
|
174
|
+
let next = this.nextElementSibling;
|
|
175
|
+
while(next && next.tagName !== 'K-PHOTO-VIEWER') {
|
|
176
|
+
next = next.nextElementSibling;
|
|
177
|
+
}
|
|
178
|
+
if(!next && this.hasPhotoSiblings()) {
|
|
179
|
+
next = this.parentElement.firstElementChild;
|
|
180
|
+
while(next && next.tagName !== 'K-PHOTO-VIEWER') {
|
|
181
|
+
next = next.nextElementSibling;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return next;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
hasPhotoSiblings() {
|
|
189
|
+
if(this.global) {
|
|
190
|
+
return document.getElementsByTagName('k-photo-viewer').length > 1;
|
|
191
|
+
}
|
|
192
|
+
return Array.from(this.parentElement.children)
|
|
193
|
+
.filter(el => el !== this && el.tagName === 'K-PHOTO-VIEWER')
|
|
194
|
+
.length > 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
updateNavigationState() {
|
|
198
|
+
const hasNavigation = this.fullscreen && this.hasPhotoSiblings();
|
|
199
|
+
const navButtons = this.shadowRoot.querySelectorAll('.nav-btn');
|
|
200
|
+
navButtons.forEach(btn => {
|
|
201
|
+
btn.style.display = hasNavigation ? '' : 'none';
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async handleFullscreenCaption() {
|
|
206
|
+
await this.updateComplete;
|
|
207
|
+
const fullscreenSlot = this.shadowRoot.querySelector('slot[name="fullscreen-caption"]');
|
|
208
|
+
if(fullscreenSlot && !fullscreenSlot.assignedNodes().length) {
|
|
209
|
+
const defaultSlot = this.shadowRoot.querySelector('slot:not([name])');
|
|
210
|
+
const contents = defaultSlot ? defaultSlot.assignedNodes() : [];
|
|
211
|
+
contents.forEach(node => {
|
|
212
|
+
if(node.nodeType === Node.ELEMENT_NODE) {
|
|
213
|
+
const clone = node.cloneNode(true);
|
|
214
|
+
clone.slot = 'fullscreen-caption';
|
|
215
|
+
this.appendChild(clone);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
Styles
|
|
223
|
+
*/
|
|
224
|
+
static styles = css`
|
|
225
|
+
:host {
|
|
226
|
+
display: block;
|
|
227
|
+
}
|
|
228
|
+
#wrapper {
|
|
229
|
+
position: relative;
|
|
230
|
+
width: 100%;
|
|
231
|
+
height: 100%;
|
|
232
|
+
}
|
|
233
|
+
#img {
|
|
234
|
+
max-width: 100%;
|
|
235
|
+
height: auto;
|
|
236
|
+
cursor: pointer;
|
|
237
|
+
outline: none;
|
|
238
|
+
border-radius: var(--img_radius, 0);
|
|
239
|
+
}
|
|
240
|
+
#img:focus {
|
|
241
|
+
box-shadow: var(--focus_shadow);
|
|
242
|
+
}
|
|
243
|
+
#fullscreen-overlay {
|
|
244
|
+
position: fixed;
|
|
245
|
+
top: 0;
|
|
246
|
+
left: 0;
|
|
247
|
+
right: 0;
|
|
248
|
+
bottom: 0;
|
|
249
|
+
z-index: 9999;
|
|
250
|
+
background: rgba(0,0,0,0.9);
|
|
251
|
+
padding: 2rem;
|
|
252
|
+
display: none;
|
|
253
|
+
}
|
|
254
|
+
:host([fullscreen]) #fullscreen-overlay {
|
|
255
|
+
display: flex;
|
|
256
|
+
align-items: center;
|
|
257
|
+
justify-content: center;
|
|
258
|
+
}
|
|
259
|
+
.content {
|
|
260
|
+
position: relative;
|
|
261
|
+
max-width: 100%;
|
|
262
|
+
max-height: 90vh;
|
|
263
|
+
}
|
|
264
|
+
#fullscreen-img {
|
|
265
|
+
max-height: 75vh;
|
|
266
|
+
max-width: 100%;
|
|
267
|
+
object-fit: contain;
|
|
268
|
+
cursor: default;
|
|
269
|
+
}
|
|
270
|
+
#close {
|
|
271
|
+
position: absolute;
|
|
272
|
+
top: 1rem;
|
|
273
|
+
right: 1rem;
|
|
274
|
+
z-index: 1;
|
|
275
|
+
background: none;
|
|
276
|
+
border: none;
|
|
277
|
+
color: white;
|
|
278
|
+
cursor: pointer;
|
|
279
|
+
}
|
|
280
|
+
.nav-btn {
|
|
281
|
+
position: fixed;
|
|
282
|
+
top: 50%;
|
|
283
|
+
transform: translateY(-50%);
|
|
284
|
+
z-index: 1;
|
|
285
|
+
background: none;
|
|
286
|
+
border: none;
|
|
287
|
+
color: white;
|
|
288
|
+
cursor: pointer;
|
|
289
|
+
padding: 1rem;
|
|
290
|
+
opacity: 0.7;
|
|
291
|
+
font-size: 3rem;
|
|
292
|
+
-webkit-text-stroke: 1px black;
|
|
293
|
+
text-stroke: 1px black;
|
|
294
|
+
text-shadow: 0 0 3px rgba(0,0,0,0.8);
|
|
295
|
+
}
|
|
296
|
+
.nav-btn::slotted(*),
|
|
297
|
+
.nav-btn k-icon {
|
|
298
|
+
filter: drop-shadow(0 0 2px rgba(0,0,0,1)) drop-shadow(0 0 2px rgba(0,0,0,1));
|
|
299
|
+
}
|
|
300
|
+
.nav-btn:hover {
|
|
301
|
+
opacity: 1;
|
|
302
|
+
}
|
|
303
|
+
#prev {
|
|
304
|
+
left: 1rem;
|
|
305
|
+
}
|
|
306
|
+
#next {
|
|
307
|
+
right: 1rem;
|
|
308
|
+
}
|
|
309
|
+
.caption {
|
|
310
|
+
text-align: center;
|
|
311
|
+
max-width: 600px;
|
|
312
|
+
width: fit-content;
|
|
313
|
+
margin: 1rem auto 0;
|
|
314
|
+
}
|
|
315
|
+
#fullscreen-overlay .caption {
|
|
316
|
+
color: white;
|
|
317
|
+
}
|
|
318
|
+
:host([fullscreen]) .caption {
|
|
319
|
+
color: white;
|
|
320
|
+
}
|
|
321
|
+
`;
|
|
322
|
+
|
|
323
|
+
/*
|
|
324
|
+
Rendering
|
|
325
|
+
*/
|
|
326
|
+
render() {
|
|
327
|
+
return html`
|
|
328
|
+
<div id="wrapper">
|
|
329
|
+
<img
|
|
330
|
+
id="img"
|
|
331
|
+
src="${this.src}"
|
|
332
|
+
alt="${this.alt}"
|
|
333
|
+
tabindex="0"
|
|
334
|
+
@click=${this.handleImageClick}
|
|
335
|
+
@keydown=${this.handleImageKeydown}
|
|
336
|
+
/>
|
|
337
|
+
<div class="caption">
|
|
338
|
+
<slot></slot>
|
|
339
|
+
</div>
|
|
340
|
+
<div id="fullscreen-overlay" @click=${this.handleOverlayClick}>
|
|
341
|
+
<button id="close" class="no-btn" @click=${this.handleCloseClick}>
|
|
342
|
+
<slot name="close">
|
|
343
|
+
<k-icon name="close"></k-icon>
|
|
344
|
+
</slot>
|
|
345
|
+
</button>
|
|
346
|
+
<button id="prev" class="nav-btn no-btn" @click=${this.handlePrevClick}>
|
|
347
|
+
<slot name="prev">
|
|
348
|
+
<k-icon name="chevron-left"></k-icon>
|
|
349
|
+
</slot>
|
|
350
|
+
</button>
|
|
351
|
+
<button id="next" class="nav-btn no-btn" @click=${this.handleNextClick}>
|
|
352
|
+
<slot name="next">
|
|
353
|
+
<k-icon name="chevron-right"></k-icon>
|
|
354
|
+
</slot>
|
|
355
|
+
</button>
|
|
356
|
+
<div class="content">
|
|
357
|
+
<img id="fullscreen-img" src="${this.src}" alt="${this.alt}" />
|
|
358
|
+
<div class="caption">
|
|
359
|
+
<slot name="fullscreen-caption"></slot>
|
|
360
|
+
</div>
|
|
361
|
+
</div>
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
customElements.define('k-photo-viewer', PhotoViewer);
|